package cn.ibizlab.core.rule.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 = "IBZRULEENGINE", resultMap = "RuleEngineResultMap")
public class RuleEngine extends EntityMP implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 标识
     */
    @DEField(isKeyField = true)
    @TableId(value = "engineid", type = IdType.ASSIGN_UUID)
    @JSONField(name = "engine_id")
    @JsonProperty("engine_id")
    private String engineId;
    /**
     * 名称
     */
    @TableField(value = "enginename")
    @JSONField(name = "engine_name")
    @JsonProperty("engine_name")
    private String engineName;
    /**
     * 规则分组
     */
    @DEField(name = "rulegroup")
    @TableField(value = "rulegroup")
    @JSONField(name = "group")
    @JsonProperty("group")
    private String group;
    /**
     * 模型标识
     */
    @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 = "execstate")
    @TableField(value = "execstate")
    @JSONField(name = "state")
    @JsonProperty("state")
    private String state;
    /**
     * 上次执行时间
     */
    @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(exist = false)
    @JSONField(name = "system_id")
    @JsonProperty("system_id")
    private String systemId;
    /**
     * 总数
     */
    @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;

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



    /**
     * 设置 [名称]
     */
    public void setEngineName(String engineName) {
        this.engineName = engineName;
        this.modify("enginename", engineName);
    }

    /**
     * 设置 [规则分组]
     */
    public void setGroup(String group) {
        this.group = group;
        this.modify("rulegroup", group);
    }

    /**
     * 设置 [模型标识]
     */
    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("execstate", state);
    }

    /**
     * 设置 [上次执行时间]
     */
    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 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("engineid");
        return super.copyTo(targetEntity, bIncEmpty);
    }
}


