package cn.ibizlab.core.lite.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 io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;


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

/**
 * 实体[ETL表同步]
 */
@Getter
@Setter
@NoArgsConstructor
@JsonIgnoreProperties(value = "handler")
@TableName(value = "IBZTABLESYNC", resultMap = "TableSyncResultMap")
@ApiModel("ETL表同步")
public class TableSync extends EntityMP implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 标识
     */
    @DEField(name = "syncid", isKeyField = true)
    @TableId(value = "syncid", type = IdType.ASSIGN_UUID)
    @JSONField(name = "id")
    @JsonProperty("id")
    @ApiModelProperty("标识")
    private String id;
    /**
     * 标题
     */
    @DEField(name = "syncname")
    @TableField(value = "syncname")
    @JSONField(name = "name")
    @JsonProperty("name")
    @ApiModelProperty("标题")
    private String name;
    /**
     * 源实体标识
     */
    @DEField(name = "srcentityid")
    @TableField(value = "srcentityid")
    @JSONField(name = "source_entity_id")
    @JsonProperty("source_entity_id")
    @ApiModelProperty("源实体标识")
    private String sourceEntityId;
    /**
     * 源实体名称
     */
    @DEField(name = "srcentityname")
    @TableField(value = "srcentityname")
    @JSONField(name = "source_entity_name")
    @JsonProperty("source_entity_name")
    @ApiModelProperty("源实体名称")
    private String sourceEntityName;
    /**
     * 源实体数据源
     */
    @DEField(name = "srcdsid")
    @TableField(value = "srcdsid")
    @JSONField(name = "source_ds_id")
    @JsonProperty("source_ds_id")
    @ApiModelProperty("源实体数据源")
    private String sourceDsId;
    /**
     * 源实体系统标识
     */
    @DEField(name = "srcsystemid")
    @TableField(value = "srcsystemid")
    @JSONField(name = "source_system_id")
    @JsonProperty("source_system_id")
    @ApiModelProperty("源实体系统标识")
    private String sourceSystemId;
    /**
     * 源数据表达式
     */
    @DEField(name = "srcexp")
    @TableField(value = "srcexp")
    @JSONField(name = "source_expression")
    @JsonProperty("source_expression")
    @ApiModelProperty("源数据表达式")
    private String sourceExpression;
    /**
     * 目标实体标识
     */
    @TableField(value = "entityid")
    @JSONField(name = "entity_id")
    @JsonProperty("entity_id")
    @ApiModelProperty("目标实体标识")
    private String entityId;
    /**
     * 目标实体
     */
    @TableField(value = "entityname")
    @JSONField(name = "entity_name")
    @JsonProperty("entity_name")
    @ApiModelProperty("目标实体")
    private String entityName;
    /**
     * 目标数据源
     */
    @TableField(value = "dsid")
    @JSONField(name = "ds_id")
    @JsonProperty("ds_id")
    @ApiModelProperty("目标数据源")
    private String dsId;
    /**
     * 系统标识
     */
    @TableField(value = "systemid")
    @JSONField(name = "system_id")
    @JsonProperty("system_id")
    @ApiModelProperty("系统标识")
    private String systemId;
    /**
     * 映射配置
     */
    @DEField(name = "mappingcfg")
    @TableField(value = "mappingcfg")
    @JSONField(name = "mapping_config")
    @JsonProperty("mapping_config")
    @ApiModelProperty("映射配置")
    private String mappingConfig;
    /**
     * 分组
     */
    @DEField(name = "syncgroup")
    @TableField(value = "syncgroup")
    @JSONField(name = "group")
    @JsonProperty("group")
    @ApiModelProperty("分组")
    private String group;
    /**
     * 排序
     */
    @TableField(value = "runorder")
    @JSONField(name = "run_order")
    @JsonProperty("run_order")
    @ApiModelProperty("排序")
    private Integer runOrder;
    /**
     * 定时器cron
     */
    @TableField(value = "runcron")
    @JSONField(name = "run_cron")
    @JsonProperty("run_cron")
    @ApiModelProperty("定时器cron")
    private String runCron;
    /**
     * 时间戳
     */
    @TableField(value = "etltimestamp")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
    @JSONField(name = "etl_timestamp", format = "yyyy-MM-dd HH:mm:ss")
    @JsonProperty("etl_timestamp")
    @ApiModelProperty("时间戳")
    private Timestamp etlTimestamp;
    /**
     * 上次运行开始时间
     */
    @TableField(value = "lastruntime")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
    @JSONField(name = "last_run_time", format = "yyyy-MM-dd HH:mm:ss")
    @JsonProperty("last_run_time")
    @ApiModelProperty("上次运行开始时间")
    private Timestamp lastRunTime;
    /**
     * 上次运行结束时间
     */
    @TableField(value = "lastendtime")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
    @JSONField(name = "last_end_time", format = "yyyy-MM-dd HH:mm:ss")
    @JsonProperty("last_end_time")
    @ApiModelProperty("上次运行结束时间")
    private Timestamp lastEndTime;
    /**
     * 上次运行结果
     */
    @TableField(value = "lastrunresult")
    @JSONField(name = "last_run_result")
    @JsonProperty("last_run_result")
    @ApiModelProperty("上次运行结果")
    private String lastRunResult;
    /**
     * 上次运行读取行
     */
    @TableField(value = "lastread")
    @JSONField(name = "last_read")
    @JsonProperty("last_read")
    @ApiModelProperty("上次运行读取行")
    private Long lastRead;
    /**
     * 上次运行写入行
     */
    @TableField(value = "lastwrite")
    @JSONField(name = "last_write")
    @JsonProperty("last_write")
    @ApiModelProperty("上次运行写入行")
    private Long lastWrite;
    /**
     * 是否启用
     */
    @DEField(defaultValue = "1")
    @TableField(value = "isenable")
    @JSONField(name = "is_enable")
    @JsonProperty("is_enable")
    @ApiModelProperty("是否启用")
    private Integer isEnable;
    /**
     * 最后修改时间
     */
    @DEField(preType = DEPredefinedFieldType.UPDATEDATE)
    @TableField(value = "updatedate")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
    @JSONField(name = "updatedate", format = "yyyy-MM-dd HH:mm:ss")
    @JsonProperty("updatedate")
    @ApiModelProperty("最后修改时间")
    private Timestamp updatedate;

    /**
     * 
     */
    @JsonIgnore
    @JSONField(serialize = false)
    @TableField(exist = false)
    private cn.ibizlab.core.lite.domain.MetaEntity entity;

    /**
     * 
     */
    @JsonIgnore
    @JSONField(serialize = false)
    @TableField(exist = false)
    private cn.ibizlab.core.lite.domain.MetaEntity sourceentity;



    /**
     * 设置 [标题]
     */
    public void setName(String name) {
        this.name = name;
        this.modify("syncname", name);
    }

    /**
     * 设置 [源实体标识]
     */
    public void setSourceEntityId(String sourceEntityId) {
        this.sourceEntityId = sourceEntityId;
        this.modify("srcentityid", sourceEntityId);
    }

    /**
     * 设置 [源实体名称]
     */
    public void setSourceEntityName(String sourceEntityName) {
        this.sourceEntityName = sourceEntityName;
        this.modify("srcentityname", sourceEntityName);
    }

    /**
     * 设置 [源实体数据源]
     */
    public void setSourceDsId(String sourceDsId) {
        this.sourceDsId = sourceDsId;
        this.modify("srcdsid", sourceDsId);
    }

    /**
     * 设置 [源实体系统标识]
     */
    public void setSourceSystemId(String sourceSystemId) {
        this.sourceSystemId = sourceSystemId;
        this.modify("srcsystemid", sourceSystemId);
    }

    /**
     * 设置 [源数据表达式]
     */
    public void setSourceExpression(String sourceExpression) {
        this.sourceExpression = sourceExpression;
        this.modify("srcexp", sourceExpression);
    }

    /**
     * 设置 [目标实体标识]
     */
    public void setEntityId(String entityId) {
        this.entityId = entityId;
        this.modify("entityid", entityId);
    }

    /**
     * 设置 [目标实体]
     */
    public void setEntityName(String entityName) {
        this.entityName = entityName;
        this.modify("entityname", entityName);
    }

    /**
     * 设置 [目标数据源]
     */
    public void setDsId(String dsId) {
        this.dsId = dsId;
        this.modify("dsid", dsId);
    }

    /**
     * 设置 [系统标识]
     */
    public void setSystemId(String systemId) {
        this.systemId = systemId;
        this.modify("systemid", systemId);
    }

    /**
     * 设置 [映射配置]
     */
    public void setMappingConfig(String mappingConfig) {
        this.mappingConfig = mappingConfig;
        this.modify("mappingcfg", mappingConfig);
    }

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

    /**
     * 设置 [排序]
     */
    public void setRunOrder(Integer runOrder) {
        this.runOrder = runOrder;
        this.modify("runorder", runOrder);
    }

    /**
     * 设置 [定时器cron]
     */
    public void setRunCron(String runCron) {
        this.runCron = runCron;
        this.modify("runcron", runCron);
    }

    /**
     * 设置 [时间戳]
     */
    public void setEtlTimestamp(Timestamp etlTimestamp) {
        this.etlTimestamp = etlTimestamp;
        this.modify("etltimestamp", etlTimestamp);
    }

    /**
     * 格式化日期 [时间戳]
     */
    public String formatEtlTimestamp() {
        if (this.etlTimestamp == null) {
            return null;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(etlTimestamp);
    }
    /**
     * 设置 [上次运行开始时间]
     */
    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 setLastEndTime(Timestamp lastEndTime) {
        this.lastEndTime = lastEndTime;
        this.modify("lastendtime", lastEndTime);
    }

    /**
     * 格式化日期 [上次运行结束时间]
     */
    public String formatLastEndTime() {
        if (this.lastEndTime == null) {
            return null;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(lastEndTime);
    }
    /**
     * 设置 [上次运行结果]
     */
    public void setLastRunResult(String lastRunResult) {
        this.lastRunResult = lastRunResult;
        this.modify("lastrunresult", lastRunResult);
    }

    /**
     * 设置 [上次运行读取行]
     */
    public void setLastRead(Long lastRead) {
        this.lastRead = lastRead;
        this.modify("lastread", lastRead);
    }

    /**
     * 设置 [上次运行写入行]
     */
    public void setLastWrite(Long lastWrite) {
        this.lastWrite = lastWrite;
        this.modify("lastwrite", lastWrite);
    }

    /**
     * 设置 [是否启用]
     */
    public void setIsEnable(Integer isEnable) {
        this.isEnable = isEnable;
        this.modify("isenable", isEnable);
    }


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


