package cn.ibizlab.core.analysis.domain;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.math.BigInteger;
import java.util.HashMap;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.util.ObjectUtils;
import org.springframework.util.DigestUtils;
import cn.ibizlab.util.domain.EntityBase;
import cn.ibizlab.util.annotation.DEField;
import cn.ibizlab.util.enums.DEPredefinedFieldType;
import cn.ibizlab.util.enums.DEFieldDefaultValueType;
import cn.ibizlab.util.helper.DataObject;
import cn.ibizlab.util.enums.DupCheck;
import java.io.Serializable;
import lombok.*;
import org.springframework.data.annotation.Transient;
import cn.ibizlab.util.annotation.Audit;


import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.baomidou.mybatisplus.annotation.*;
import cn.ibizlab.util.domain.EntityMP;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;

/**
 * 实体[分析]
 */
@Getter
@Setter
@NoArgsConstructor
@JsonIgnoreProperties(value = "handler")
@TableName(value = "IBZDABUILD", resultMap = "DABuildResultMap")
public class DABuild extends EntityMP implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 标识
     */
    @DEField(isKeyField = true)
    @TableId(value = "buildid", type = IdType.ASSIGN_UUID)
    @JSONField(name = "build_id")
    @JsonProperty("build_id")
    private String buildId;
    /**
     * 名称
     */
    @TableField(value = "buildname")
    @JSONField(name = "build_name")
    @JsonProperty("build_name")
    private String buildName;
    /**
     * 上次执行时间
     */
    @TableField(value = "lastruntime")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
    @JSONField(name = "last_runtime", format = "yyyy-MM-dd HH:mm:ss")
    @JsonProperty("last_runtime")
    private Timestamp lastRuntime;
    /**
     * 模型标识
     */
    @TableField(value = "modelid")
    @JSONField(name = "model_id")
    @JsonProperty("model_id")
    private String modelId;
    /**
     * 模型名称
     */
    @TableField(value = "modelname")
    @JSONField(name = "model_name")
    @JsonProperty("model_name")
    private String modelName;
    /**
     * 状态
     */
    @DEField(name = "buildstate")
    @TableField(value = "buildstate")
    @JSONField(name = "state")
    @JsonProperty("state")
    private String state;
    /**
     * 总数
     */
    @TableField(value = "total")
    @JSONField(name = "total")
    @JsonProperty("total")
    private Integer total;
    /**
     * 已处理数
     */
    @TableField(value = "processed")
    @JSONField(name = "processed")
    @JsonProperty("processed")
    private Integer processed;
    /**
     * 扩展参数
     */
    @TableField(value = "extparams")
    @JSONField(name = "ext_params")
    @JsonProperty("ext_params")
    private String extParams;
    /**
     * 系统标识
     */
    @TableField(exist = false)
    @JSONField(name = "system_id")
    @JsonProperty("system_id")
    private String systemId;

    /**
     * 模型
     */
    @JsonIgnore
    @JSONField(serialize = false)
    @TableField(exist = false)
    private cn.ibizlab.core.lite.domain.MetaModel model;


    /**
     * 维度
     */
    @JSONField(name = "dadimensions")
    @JsonProperty("dadimensions")
    @TableField(value = "dadimension" , typeHandler = cn.ibizlab.core.analysis.domain.handlers.DADimensionTypeHandler.class)
    private List<cn.ibizlab.core.analysis.domain.DADimension> dadimension;

    /**
     * 设置 [维度]
     */
    public void setDadimension(List<cn.ibizlab.core.analysis.domain.DADimension> dadimension) {
        this.dadimension = dadimension;
        this.modify("dadimension", (dadimension!=null)?dadimension:(new ArrayList()));
    }
    /**
     * 指标
     */
    @JsonIgnore
    @JSONField(serialize = false)
    @TableField(exist = false)
    private List<cn.ibizlab.core.analysis.domain.DAMetric> metrics;


    /**
     * 设置 [名称]
     */
    public void setBuildName(String buildName) {
        this.buildName = buildName;
        this.modify("buildname", buildName);
    }

    /**
     * 设置 [上次执行时间]
     */
    public void setLastRuntime(Timestamp lastRuntime) {
        this.lastRuntime = lastRuntime;
        this.modify("lastruntime", lastRuntime);
    }

    /**
     * 格式化日期 [上次执行时间]
     */
    public String formatLastRuntime() {
        if (this.lastRuntime == null) {
            return null;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(lastRuntime);
    }
    /**
     * 设置 [模型标识]
     */
    public void setModelId(String modelId) {
        this.modelId = modelId;
        this.modify("modelid", modelId);
    }

    /**
     * 设置 [模型名称]
     */
    public void setModelName(String modelName) {
        this.modelName = modelName;
        this.modify("modelname", modelName);
    }

    /**
     * 设置 [状态]
     */
    public void setState(String state) {
        this.state = state;
        this.modify("buildstate", state);
    }

    /**
     * 设置 [总数]
     */
    public void setTotal(Integer total) {
        this.total = total;
        this.modify("total", total);
    }

    /**
     * 设置 [已处理数]
     */
    public void setProcessed(Integer processed) {
        this.processed = processed;
        this.modify("processed", processed);
    }

    /**
     * 设置 [扩展参数]
     */
    public void setExtParams(String extParams) {
        this.extParams = extParams;
        this.modify("extparams", extParams);
    }


    /**
     * 复制当前对象数据到目标对象(粘贴重置)
     * @param targetEntity 目标数据对象
     * @param bIncEmpty  是否包括空值
     * @param <T>
     * @return
     */
    @Override
    public <T> T copyTo(T targetEntity, boolean bIncEmpty) {
        this.reset("buildid");
        return super.copyTo(targetEntity, bIncEmpty);
    }
}


