package org.jeecg.module.custom.ocr.dataobject;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.jeecg.module.custom.ocr.common.dto.BaseDto;
import org.jeecg.module.custom.ocr.common.dto.HistoricTaskInstanceDto;
import org.jeecg.module.custom.ocr.common.dto.UserapproveDto;
import org.jeecg.module.custom.ocr.common.vo.FlowModelVO;
import org.jeecg.module.custom.ocr.utils.requestFormat.SearchQuery;

import java.util.AbstractMap.SimpleEntry;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;


@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "任务信息", description = "任务信息")
@TableName(value = "ocr_taskchild_picture")
public class OcrTaskchildPicture implements BaseDto, java.io.Serializable {

    private static final long serialVersionUID = -8018660053527763810L;
    @ApiModelProperty(value = "主键")
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    @JsonSerialize(using = ToStringSerializer.class)
    @TableField(value = "ID")
    private Long id;

    @ApiModelProperty(value = "比对图片主键，多个数据使用英文逗号分隔")
    @TableField(value = "OCPICTUREID")
    private String ocpictureid;

    @ApiModelProperty(value = "图片比对结果,与图片主键一一对应，记录比对结果，使用英文逗号分隔，例如99.6,98.1,97.2")
    @TableField(value = "PICTURERESULT")
    private String pictureresult;

    @ApiModelProperty(value = "只记录主图，如果存在历史图片，不在这里记录")
    @TableField(value = "PICTURECOMPARE")
    private String picturecompare;

    @ApiModelProperty(value = "所属部门")
    @TableField(value = "DEPTID")
    private String deptid;

    @ApiModelProperty(value = "租户ID")
    @TableField(value = "TENANTID")
    private Long tenantid;

    @ApiModelProperty(value = "任务包主键")
    @TableField(value = "PACKAGEID")
    private Long packageid;

    @ApiModelProperty(value = "原图片主键")
    @TableField(value = "PICTUREID")
    private Long pictureid;

    @ApiModelProperty(value = "类型名称")
    @TableField(value = "CATEGORY")
    private String category;

    @ApiModelProperty(value = "项目ID")
    @TableField(value = "CATEGORYID")
    private Long categoryid;

    @ApiModelProperty(value = "明细单")
    @TableField(value = "SPECIFICATION")
    private String specification;

    @ApiModelProperty(value = "业务编码")
    @TableField(value = "BUESSINESSNO")
    private String buessinessno;

    @ApiModelProperty(value = "状态，审批状态 1:未提交 2:审批中 3:审批通过 ，5：拒绝")
    @TableField(value = "STATES")
    private Integer states;

    @ApiModelProperty(value = "流程实例IdprocessInstanceId")
    @TableField(value = "PROCESSINSTANCEID")
    private String processinstanceid;

    @ApiModelProperty(value = "流程定义id")
    @TableField(value = "PROCESSDEFINITIONID")
    private String processdefinitionid;

    @ApiModelProperty(value = "流程部署id")
    @TableField(value = "DEPLOYMENTID")
    private String deploymentid;

    @ApiModelProperty(value = "审批人姓名")
    @TableField(value = "ASSIGNEENAME")
    private String assigneename;

    @ApiModelProperty(value = "审批人")
    @TableField(value = "ASSIGNEE")
    private String assignee;

    @ApiModelProperty(value = "修改人，记录创建人的帐号")
    @TableField(value = "UPDATEUSER")
    private String updateuser;

    @ApiModelProperty(value = "更新时间")
    @TableField(value = "UPDATETIME")
    private Long updatetime;

    @ApiModelProperty(value = "附件")
    @TableField(value = "FILEANNEX")
    private String fileannex;

    @ApiModelProperty(value = "是否归档，0：未归档，1：归档")
    @TableField(value = "GUIDANG")
    private Integer guidang;

    @ApiModelProperty(value = "创建人")
    @TableField(value = "CREATEUSER")
    private String createuser;

    @ApiModelProperty(value = "创建人姓名")
    @TableField(value = "CREATEUSERNAME")
    private String createusername;

    @ApiModelProperty(value = "创建时间")
    @TableField(value = "CREATEDATE")
    private Long createdate;

    @ApiModelProperty(value = "员工主键")
    @TableField(value = "USERID")
    private Long userid;

    @ApiModelProperty(value = "员工姓名")
    @TableField(value = "USERNAME")
    private String username;

    @ApiModelProperty(value = "任务id,来源于图片表")
    @TableField(value = "FROMTASKID")
    private String fromtaskid;

    @ApiModelProperty(value = "任务名称,来源于图片表")
    @TableField(value = "FROMTASKNAME")
    private String fromtaskname;

    @ApiModelProperty(value = "提报人")
    @TableField(value = "FROMUSERID")
    private String fromuserid;

    @ApiModelProperty(value = "提报人名称")
    @TableField(value = "FROMUSERNAME")
    private String fromusername;

    @ApiModelProperty(value = "所属项目")
    @TableField(value = "FROMPROJECTID")
    private String fromprojectid;

    @ApiModelProperty(value = "所属项目名称")
    @TableField(value = "FROMPROJECTNAME")
    private String fromprojectname;

    @ApiModelProperty(value = "所属计划")
    @TableField(value = "FROMPLANID")
    private String fromplanid;

    @ApiModelProperty(value = "提报时间")
    @TableField(value = "FROMUPTIME")
    private Long fromuptime;

    @ApiModelProperty(value = "任务来源")
    @TableField(value = "FROMSOURCEID")
    private String fromsourceid;

    @ApiModelProperty(value = "是否为相似图片，与其他图片对比为百分百的，记录为1，0：不相似，1：相似")
    @TableField(value = "HAVEPOINTS")
    private Integer havepoints;

    @ApiModelProperty(value = "当前节点名称")
    @TableField(value = "TASKNAME")
    private String taskname;

    @ApiModelProperty(value = "当前节点名称")
    @TableField(value = "TASKNODE")
    private String taskNode;

    @ApiModelProperty(value = "当前节点id")
    @TableField(value = "TASKID")
    private String taskId;

    @ApiModelProperty(value = "完成时间")
    @TableField(value = "FINISHTIME")
    private Long finishtime;

    @ApiModelProperty(value = "是否终审")
    @TableField(value = "ISFINAIL")
    private Integer isFinal;

    @ApiModelProperty(value = "是否小结重复,1重复，0不重复")
    @TableField(value = "is_repeated_nodules")
    private Integer isRepeatedNodules;

    @ApiModelProperty(value = "无量云回调结果")
    @TableField(value = "send_result")
    private Integer sendResult;

    @ApiModelProperty(value = "项目对象")
    @TableField(exist = false)
    private Category categoryDto;

    //节点描述
    @ApiModelProperty(value = "节点描述")
    @TableField(exist = false)
    private String documentation;

    // 关联 任务的流程记录
    @ApiModelProperty(value = "审批记录")
    @TableField(exist = false)
    private List<HistoricTaskInstanceDto> transferRecords;

    @ApiModelProperty(value = "是否为历史图片，true：是历史图片，false：非历史图片")
    @TableField(exist = false)
    private boolean izHistory;

    @ApiModelProperty(value = "图片真假 0:假，1：真，其他表示没有设置")
    @TableField(exist = false)
    private Integer iztrueorfalse;

    @ApiModelProperty(value = "是否已经审批，0：未审批，1：审批中，2：已审批")
    @TableField(exist = false)
    private String workStatus;

    @ApiModelProperty(value = "图片对象")
    @TableField(exist = false)
    private OcrPicture ocrPicture;

    @ApiModelProperty(value = "提报时间")
    @TableField(exist = false)
    private String reporttime;

    @ApiModelProperty(value = "相似度数值")
    @TableField(exist = false)
    private Integer similarityscore;

    @ApiModelProperty(value = "本人审查日志")
    @TableField(exist = false)
    private Userapprove userapprove;

    @ApiModelProperty(value = "拜访终端")
    @TableField(exist = false)
    private String field3;

    @ApiModelProperty(value = "子计划名称")
    @TableField(exist = false)
    private String planchildname;

    @ApiModelProperty(value = "是否重复")
    @TableField(exist = false)
    private String field14;

    @ApiModelProperty(value = "是否图片重复")
    @TableField(exist = false)
    private Integer isRepeat;

    @ApiModelProperty(value = "历史状态")
    @TableField(exist = false)
    private Integer historyStates;

    @ApiModelProperty(value = "审查日志")
    @TableField(exist = false)
    private List<UserapproveDto> userapproveList;

    @ApiModelProperty(value = "定位")
    @TableField(exist = false)
    private String location;

    @ApiModelProperty(value = "图片信息")
    @TableField(exist = false)
    private String imgUrl;

    //保存当前登录用户的数据权限范围的搜索条件
    @TableField(exist = false)
    @JsonIgnore
    private SearchQuery searchQueryrolesShowleave;

    @TableField(exist = false)
    private OcrPictureInfo pictureInfo;

    @TableField(exist = false)
    private String maxSimilarity;

    @TableField(exist = false)
    private String serverThumbnailUrl;


    public FlowModelVO getFlowModelVO() {
        FlowModelVO flowModelVO = new FlowModelVO();
        flowModelVO.setFormid(this.getId());
        flowModelVO.setAssignee(this.getAssignee());
        flowModelVO.setAssigneename(this.getAssigneename());
        flowModelVO.setProcessdefinitionid(this.getProcessdefinitionid());
        flowModelVO.setUserid(this.getUserid());
        flowModelVO.setUsername(this.getUsername());
        flowModelVO.setCategoryid(this.getCategoryid());
        flowModelVO.setStates(this.getStates());
        flowModelVO.setDeploymentid(this.getDeploymentid());
        flowModelVO.setCreateuser(this.getCreateuser());
        flowModelVO.setCreatedate(this.getCreatedate());
        flowModelVO.setProcessInstanceId(this.getProcessdefinitionid());
        flowModelVO.setGuidang(this.getGuidang());
        flowModelVO.setFileannex(this.getFileannex());
        flowModelVO.setCreateusername(this.getCreateusername());
        flowModelVO.setProcessInstanceId(this.getProcessinstanceid());
        flowModelVO.setTenantid(this.getTenantid());
        flowModelVO.setTaskId(this.getTaskId());
        return flowModelVO;
    }

    @TableField(exist = false)
    @JsonIgnore
    private final Map<String, String> query = Stream.of(
                    new SimpleEntry<>("ID", "id"),
                    new SimpleEntry<>("OCPICTUREID", "ocpictureid"),
                    new SimpleEntry<>("PICTURERESULT", "pictureresult"),
                    new SimpleEntry<>("PICTURECOMPARE", "picturecompare"),
                    new SimpleEntry<>("DEPTID", "deptid"),
                    new SimpleEntry<>("TENANTID", "tenantid"),
                    new SimpleEntry<>("PACKAGEID", "packageid"),
                    new SimpleEntry<>("PICTUREID", "pictureid"),
                    new SimpleEntry<>("CATEGORY", "category"),
                    new SimpleEntry<>("CATEGORYID", "categoryid"),
                    new SimpleEntry<>("SPECIFICATION", "specification"),
                    new SimpleEntry<>("BUESSINESSNO", "buessinessno"),
                    new SimpleEntry<>("STATES", "states"),
                    new SimpleEntry<>("PROCESSINSTANCEID", "processinstanceid"),
                    new SimpleEntry<>("PROCESSDEFINITIONID", "processdefinitionid"),
                    new SimpleEntry<>("DEPLOYMENTID", "deploymentid"),
                    new SimpleEntry<>("ASSIGNEENAME", "assigneename"),
                    new SimpleEntry<>("ASSIGNEE", "assignee"),
                    new SimpleEntry<>("UPDATEUSER", "updateuser"),
                    new SimpleEntry<>("UPDATETIME", "updatetime"),
                    new SimpleEntry<>("FILEANNEX", "fileannex"),
                    new SimpleEntry<>("GUIDANG", "guidang"),
                    new SimpleEntry<>("CREATEUSER", "createuser"),
                    new SimpleEntry<>("CREATEUSERNAME", "createusername"),
                    new SimpleEntry<>("CREATEDATE", "createdate"),
                    new SimpleEntry<>("USERID", "userid"),
                    new SimpleEntry<>("USERNAME", "username"),
                    new SimpleEntry<>("FROMTASKID", "fromtaskid"),
                    new SimpleEntry<>("FROMTASKNAME", "fromtaskname"),
                    new SimpleEntry<>("FROMUSERID", "fromuserid"),
                    new SimpleEntry<>("FROMPROJECTID", "fromprojectid"),
                    new SimpleEntry<>("FROMPLANID", "fromplanid"),
                    new SimpleEntry<>("FROMUPTIME", "fromuptime"),
                    new SimpleEntry<>("FROMSOURCEID", "fromsourceid"),
                    new SimpleEntry<>("HAVEPOINTS", "havepoints"),
                    new SimpleEntry<>("TASKNAME", "taskname")
            )
            .collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue));

    @Override
    public String getQueryFiled(String filedname) {
        String obj = null;
        if (null != query && query.size() > 0) {
            obj = query.get(filedname);
        }
        return obj;
    }
}
