package cn.ibizlab.core.extensions.dto;
 
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Timestamp;


@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
@ApiModel("执行结果")
public class BuildResult  implements Serializable {


    /**
     * 属性 [RU_EXECRESULTID]
     *
     */
    @JSONField(name = "id")
    @JsonProperty("id")
    @ApiModelProperty("规则执行结果标识")
    private String id;

    /**
     * 属性 [RU_EXECRESULTNAME]
     *
     */
    @JSONField(name = "name")
    @JsonProperty("name")
    @ApiModelProperty("规则执行结果描述")
    private String name;

    /**
     * 属性 [RULEID]
     *
     */
    @JSONField(name = "rule_id")
    @JsonProperty("rule_id")
    @ApiModelProperty("规则标识")
    private String ruleId;

    /**
     * 属性 [RULENAME]
     *
     */
    @JSONField(name = "rule_name")
    @JsonProperty("rule_name")
    @ApiModelProperty("规则标识")
    private String ruleName;

    /**
     * 属性 [RETVALUE]
     *
     */
    @JSONField(name = "ret_value")
    @JsonProperty("ret_value")
    @ApiModelProperty("是否匹配")
    private Integer retValue;

    /**
     * 属性 [BUSINESSCAT]
     *
     */
    @JSONField(name = "business_cat")
    @JsonProperty("business_cat")
    @ApiModelProperty("业务类别")
    private String businessCat;

    /**
     * 属性 [KEYVALUEFIELD]
     *
     */
    @JSONField(name = "key_value_field")
    @JsonProperty("key_value_field")
    @ApiModelProperty("标识属性")
    private String keyValueField;

    /**
     * 属性 [DOMAINSFIELD]
     *
     */
    @JSONField(name = "domains_field")
    @JsonProperty("domains_field")
    @ApiModelProperty("分区字段")
    private String domainsField;

    /**
     * 属性 [TIMEFIELD]
     *
     */
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss", locale = "zh" , timezone="GMT+8")
    @JSONField(name = "time_field" , format="yyyy-MM-dd HH:mm:ss")
    @JsonProperty("time_field")
    @ApiModelProperty("时间属性")
    private Timestamp timeField;

    /**
     * 属性 [DIMFIELD]
     *
     */
    @JSONField(name = "dim_field")
    @JsonProperty("dim_field")
    @ApiModelProperty("维度属性")
    private String dimField;

    /**
     * 属性 [METRICFIELD]
     *
     */
    @JSONField(name = "metric_field")
    @JsonProperty("metric_field")
    @ApiModelProperty("指标属性")
    private BigDecimal metricField;

    /**
     * 属性 [CREATEDATE]
     *
     */
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss", locale = "zh" , timezone="GMT+8")
    @JSONField(name = "createdate" , format="yyyy-MM-dd HH:mm:ss")
    @JsonProperty("createdate")
    @ApiModelProperty("建立时间")
    private Timestamp createdate;


    /**
     * 属性 [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;

    /**
     * 属性 [EXT1FIELD]
     *
     */
    @JSONField(name = "ext1_field")
    @JsonProperty("ext1_field")
    @ApiModelProperty("扩展属性1")
    private String ext1Field;

    /**
     * 属性 [EXT2FIELD]
     *
     */
    @JSONField(name = "ext2_field")
    @JsonProperty("ext2_field")
    @ApiModelProperty("扩展属性2")
    private String ext2Field;

    /**
     * 属性 [SYSTEMID]
     *
     */
    @JSONField(name = "system_id")
    @JsonProperty("system_id")
    @ApiModelProperty("系统标识")
    private String systemId;



    public cn.ibizlab.core.extensions.cql.ExecResult getCqlResult()
    {
        cn.ibizlab.core.extensions.cql.ExecResult result=new cn.ibizlab.core.extensions.cql.ExecResult();
        result.setDimfield(dimField);
        result.setDomainsfield(domainsField);
        result.setKeyvaluefield(keyValueField);
        result.setRetvalue(retValue);
        result.setRuleid(ruleId);
        if(timeField!=null)
            result.setTimefieldLV(timeField.getTime());
        result.setBusinesscat(businessCat);
        result.setExt1field(ext1Field);
        result.setExt2field(ext2Field);
        result.setMetricfield(metricField!=null?metricField.doubleValue():1d);
        result.setRuexecresultname(name);
        result.setRulename(ruleName);
        if(updatedate!=null)
            result.setUpdatedateLV(updatedate.getTime());
        return result;
    }

    public BuildResult setCqlResult(cn.ibizlab.core.extensions.cql.ExecResult result)
    {
        if(result!=null)
        {
            dimField=result.getDimfield();
            domainsField=result.getDomainsfield();
            keyValueField=result.getKeyvaluefield();
            retValue=result.getRetvalue();
            ruleId=result.getRuleid();
            if(result.getTimefield()!=null)
                timeField=new Timestamp(result.getTimefieldLV());
            businessCat=result.getBusinesscat();
            ext1Field=result.getExt1field();
            ext2Field=result.getExt2field();
            if(result.getMetricfield()!=null)
                metricField=new BigDecimal(result.getMetricfield()).setScale(2, BigDecimal.ROUND_HALF_UP);
            name=result.getRuexecresultname();
            ruleName=result.getRulename();
            if(result.getUpdatedate()!=null)
                updatedate=new Timestamp(result.getUpdatedateLV());
        }
        return this;
    }


    public cn.ibizlab.core.rule.domain.ExecResult getSqlResult()
    {
        cn.ibizlab.core.rule.domain.ExecResult execResult=new cn.ibizlab.core.rule.domain.ExecResult();
        if ( this.getName() != null ) {
            execResult.setName( this.getName() );
        }
        if ( this.getRuleId() != null ) {
            execResult.setRuleId( this.getRuleId() );
        }
        if ( this.getRuleName() != null ) {
            execResult.setRuleName( this.getRuleName() );
        }
        if ( this.getRetValue() != null ) {
            execResult.setRetValue( this.getRetValue() );
        }
        if ( this.getBusinessCat() != null ) {
            execResult.setBusinessCat( this.getBusinessCat() );
        }
        if ( this.getKeyValueField() != null ) {
            execResult.setKeyValueField( this.getKeyValueField() );
        }
        if ( this.getDomainsField() != null ) {
            execResult.setDomainsField( this.getDomainsField() );
        }
        if ( this.getTimeField() != null ) {
            execResult.setTimeField( this.getTimeField() );
        }
        if ( this.getDimField() != null ) {
            execResult.setDimField( this.getDimField() );
        }
        if ( this.getMetricField() != null ) {
            execResult.setMetricField( this.getMetricField() );
        }
        if ( this.getExt1Field() != null ) {
            execResult.setExt1Field( this.getExt1Field() );
        }
        if ( this.getExt2Field() != null ) {
            execResult.setExt2Field( this.getExt2Field() );
        }
        if ( this.getSystemId() != null ) {
            execResult.setSystemId( this.getSystemId() );
        }
        if ( this.getId() != null ) {
            execResult.setId( this.getId() );
        }
        if ( this.getCreatedate() != null ) {
            execResult.setCreatedate( this.getCreatedate() );
        }
        if ( this.getUpdatedate() != null ) {
            execResult.setUpdatedate( this.getUpdatedate() );
        }
        return execResult;
    }

    public BuildResult setSqlResult(cn.ibizlab.core.rule.domain.ExecResult entity)
    {
        if(entity!=null)
        {
            if ( entity.getName() != null ) {
                this.setName( entity.getName() );
            }
            if ( entity.getRuleId() != null ) {
                this.setRuleId( entity.getRuleId() );
            }
            if ( entity.getRuleName() != null ) {
                this.setRuleName( entity.getRuleName() );
            }
            if ( entity.getRetValue() != null ) {
                this.setRetValue( entity.getRetValue() );
            }
            if ( entity.getBusinessCat() != null ) {
                this.setBusinessCat( entity.getBusinessCat() );
            }
            if ( entity.getKeyValueField() != null ) {
                this.setKeyValueField( entity.getKeyValueField() );
            }
            if ( entity.getDomainsField() != null ) {
                this.setDomainsField( entity.getDomainsField() );
            }
            if ( entity.getTimeField() != null ) {
                this.setTimeField( entity.getTimeField() );
            }
            if ( entity.getDimField() != null ) {
                this.setDimField( entity.getDimField() );
            }
            if ( entity.getMetricField() != null ) {
                this.setMetricField( entity.getMetricField() );
            }
            if ( entity.getExt1Field() != null ) {
                this.setExt1Field( entity.getExt1Field() );
            }
            if ( entity.getExt2Field() != null ) {
                this.setExt2Field( entity.getExt2Field() );
            }
            if ( entity.getSystemId() != null ) {
                this.setSystemId( entity.getSystemId() );
            }
            if ( entity.getId() != null ) {
                this.setId( entity.getId() );
            }
            if ( entity.getCreatedate() != null ) {
                this.setCreatedate( entity.getCreatedate() );
            }
            if ( entity.getUpdatedate() != null ) {
                this.setUpdatedate( entity.getUpdatedate() );
            }
        }
        return this;
    }

}


