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 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 = "IBZCOMPONENT",resultMap = "DstComponentResultMap")
public class DstComponent extends EntityMP implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 部件标识
     */
    @DEField(name = "cid" , isKeyField=true)
    @TableId(value= "cid",type=IdType.ASSIGN_UUID)
    @JSONField(name = "id")
    @JsonProperty("id")
    private String id;
    /**
     * 名称
     */
    @DEField(name = "cname")
    @TableField(value = "cname")
    @JSONField(name = "name")
    @JsonProperty("name")
    private String name;
    /**
     * 代码名称
     */
    @TableField(value = "codename")
    @JSONField(name = "code_name")
    @JsonProperty("code_name")
    private String codeName;
    /**
     * 系统标识
     */
    @TableField(value = "systemid")
    @JSONField(name = "system_id")
    @JsonProperty("system_id")
    private String systemId;
    /**
     * 应用标识
     */
    @TableField(value = "appid")
    @JSONField(name = "app_id")
    @JsonProperty("app_id")
    private String appId;
    /**
     * 类型
     */
    @DEField(name = "ctype")
    @TableField(value = "ctype")
    @JSONField(name = "type")
    @JsonProperty("type")
    private String type;
    /**
     * 配置
     */
    @DEField(name = "cfg")
    @TableField(value = "cfg")
    @JSONField(name = "config")
    @JsonProperty("config")
    private String config;

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

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



    /**
     * 设置 [名称]
     */
    public void setName(String name){
        this.name = name ;
        this.modify("cname",name);
    }

    /**
     * 设置 [代码名称]
     */
    public void setCodeName(String codeName){
        this.codeName = codeName ;
        this.modify("codename",codeName);
    }

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

    /**
     * 设置 [应用标识]
     */
    public void setAppId(String appId){
        this.appId = appId ;
        this.modify("appid",appId);
    }

    /**
     * 设置 [类型]
     */
    public void setType(String type){
        this.type = type ;
        this.modify("ctype",type);
    }

    /**
     * 设置 [配置]
     */
    public void setConfig(String config){
        this.config = config ;
        this.modify("cfg",config);
    }


    /**
     * 获取 [部件标识]
     */
    public String getId(){
        if(ObjectUtils.isEmpty(id)){
            id=(String)getDefaultKey(true);
        }
        return id;
    }

    @Override
    public Serializable getDefaultKey(boolean gen) {
        if((!ObjectUtils.isEmpty(this.getSystemId()))&&(!ObjectUtils.isEmpty(this.getAppId()))&&(!ObjectUtils.isEmpty(this.getCodeName())))
            return DigestUtils.md5DigestAsHex(String.format("%s||%s||%s" ,this.getSystemId(),this.getAppId(),this.getCodeName()).getBytes());
        return null;
    }
    /**
     * 复制当前对象数据到目标对象(粘贴重置)
     * @param targetEntity 目标数据对象
     * @param bIncEmpty  是否包括空值
     * @param <T>
     * @return
     */
    @Override
    public <T> T copyTo(T targetEntity, boolean bIncEmpty) {
        this.reset("cid");
        return super.copyTo(targetEntity,bIncEmpty);
    }
}


