package com.qmth.jkserver.model;

import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.qmth.jkserver.base.BaseEntity;
import com.qmth.jkserver.constant.SystemConstant;
import com.qmth.jkserver.dto.result.SysConfigResult;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;
import java.util.Objects;

/**
 * <p>
 * 参数表
 * </p>
 *
 * @author xf
 * @since 2021-03-23
 */
@TableName("sys_config")
public class SysConfig extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "学校id")
    @JsonSerialize(using = ToStringSerializer.class)
    @TableField("school_id")
    private Long schoolId;

    /**
     * 参数键值
     */
    @TableField("config_key")
    private String configKey;

    /**
     * 参数名称
     */
    @TableField("config_name")
    private String configName;
    /**
     * 参数键值
     */
    @TableField(value = "config_value", updateStrategy = FieldStrategy.IGNORED)
    private String configValue;

    private String remark;

    @ApiModelProperty(value = "启用/禁用，ture：启用，false：禁用，默认启用")
    private Boolean enable = true;

    @ApiModelProperty(value = "排序")
    private Integer sort = 1;

    public SysConfig() {

    }

    public SysConfig(SysConfigResult sysConfigResult) {
        if (Objects.isNull(sysConfigResult.getId())) {
            setId(SystemConstant.getDbUuid());
        } else {
            setId(sysConfigResult.getId());
        }
        this.configKey = sysConfigResult.getCode();
        this.configName = sysConfigResult.getName();
        this.configValue = String.valueOf(sysConfigResult.getValue());
        this.enable = sysConfigResult.getEnable();
        this.sort = sysConfigResult.getSort();
        setCreateId(1L);
        setCreateTime(System.currentTimeMillis());
    }

    public SysConfig(Long schoolId, SysConfigResult sysConfigResult) {
        if (Objects.isNull(sysConfigResult.getId())) {
            setId(SystemConstant.getDbUuid());
        } else {
            setId(sysConfigResult.getId());
        }
        this.schoolId = schoolId;
        this.configKey = sysConfigResult.getCode();
        this.configName = sysConfigResult.getName();
        this.configValue = String.valueOf(sysConfigResult.getValue());
        this.enable = sysConfigResult.getEnable();
        this.sort = sysConfigResult.getSort();
        setCreateId(1L);
        setCreateTime(System.currentTimeMillis());
    }

    public Boolean getEnable() {
        return enable;
    }

    public void setEnable(Boolean enable) {
        this.enable = enable;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public Long getSchoolId() {
        return schoolId;
    }

    public void setSchoolId(Long schoolId) {
        this.schoolId = schoolId;
    }

    public String getConfigKey() {
        return configKey;
    }

    public void setConfigKey(String configKey) {
        this.configKey = configKey;
    }

    public String getConfigName() {
        return configName;
    }

    public void setConfigName(String configName) {
        this.configName = configName;
    }

    public String getConfigValue() {
        return configValue;
    }

    public void setConfigValue(String configValue) {
        this.configValue = configValue;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }
}
