package cn.estsh.i3plus.ext.mes.pojo.bean;

import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtEnumUtil;
import cn.estsh.i3plus.pojo.base.annotation.AnnoOutputColumn;
import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.util.StringUtils;

import javax.persistence.*;
import java.io.Serializable;

/**
 * @Description:
 * @Author: wangjie
 * @Date: 2021/01/14 20:03
 * @Modify:
 */
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name = "MES_CAREER_CORRELATION_CFG", indexes = {
        @Index(columnList = "SYSTEM_SYNC_STATUS"),
        @Index(columnList = "CAREER_CODE"),
        @Index(columnList = "DATA_TYPE"),
        @Index(columnList = "DATA_KEY")
})
@Api("MES_事业别相关配置")
public class MesCareerCorrelationCfg extends BaseBean implements Serializable {

    private static final long serialVersionUID = -238417971254818534L;

    @Column(name = "SYSTEM_SYNC_STATUS")
    @ColumnDefault("2")
    @ApiParam(value = "系统同步标志")
    public Integer systemSyncStatus = 2;

    @Column(name = "DATA_DIMENSION")
    @ApiParam(value = "配置维度")
    @AnnoOutputColumn(refClass = MesExtEnumUtil.CAREER_CORRELATION_CFG_DATA_DIMENSION.class, refForeignKey = "value", value = "description")
    public String dataDimension;

    @Column(name = "CAREER_CODE")
    @ApiParam(value = "事业别")
    public String careerCode;

    @Column(name = "CATEGORY_CODE")
    @ApiParam(value = "产品别")
    public String categoryCode;

    @Column(name = "WORK_CENTER_CODE")
    @ApiParam(value = "产线别")
    public String workCenterCode;

    @Column(name = "DATA_TYPE")
    @ApiParam(value = "配置类型")
    public String dataType;

    @Column(name = "DATA_KEY")
    @ApiParam(value = "配置键")
    public String dataKey;

    @Column(name = "CFG_VALUE")
    @ApiParam("值")
    private String cfgValue;

    @Transient
    @ApiParam("ID")
    private String idStr;

    @Transient
    @ApiParam("事业别")
    private String careerName;

    @Transient
    @ApiParam(value = "产品别")
    public String categoryName;

    @Transient
    @ApiParam(value = "产线别")
    public String workCenterName;

    @Transient
    @ApiParam("值1")
    private String cfgValue1;

    @Transient
    @ApiParam("值2")
    private String cfgValue2;

    @Transient
    @ApiParam("值3")
    private String cfgValue3;

    public MesCareerCorrelationCfg splitValue() {
        String[] valueArr = !StringUtils.isEmpty(this.cfgValue) ? this.cfgValue.split(MesExtConstWords.COMMA) : null;
        this.cfgValue1 = null != valueArr && valueArr.length >= 1 ? valueArr[0] : MesExtConstWords.ZERO_STR;
        this.cfgValue2 = null != valueArr && valueArr.length >= 2 ? valueArr[1] : MesExtConstWords.ZERO_STR;
        this.cfgValue3 = null != valueArr && valueArr.length >= 3 ? valueArr[2] : MesExtConstWords.ZERO_STR;
        return this;
    }

}
