package com.boman.domain.dto;


import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;

import java.util.*;

/**
 * @author shiqian
 * @date 2021年05月26日 15:29
 **/
@Data
public class ProcessDto {

    /**
     *
     */
    private  String dbname;

    private JSONObject businessObj;
    /**
     * 流程实例id
     */
    @JSONField
    private Long instanceId;

    /**
     * 流程实例id-多个
     */
    @JSONField
    private String instanceIds;

    /**
     * 流程实例版本
     */
    private Integer rev;

    @JSONField
    private Long initiator;

    /**
     * 发起人：称谓
     */
    @JSONField
    private String initiatorName;

    /**
     * 业务数据编号
     */
    @JSONField
    private Long businessCode;

    /**
     * 业务数据
     */
    @JSONField(serialize = false, deserialize = false)
    private JSONObject businessBody;

    /**
     * 业务回调路径
     */
    @JSONField
    private String businessUrl;

    /**
     * 业务回调路径
     */
    @JSONField
    private String formUrl;

    /**
     * 业务单据修改明细
     */
    @JSONField
    private JSONObject changeDetail;

    /**
     * 流程状态
     */
    @JSONField
    private Short status;

    /**
     * 检索开始时间
     */
    @JSONField(format = "yyyy-MM-dd HH:mm")
    private Date startTime;

    /**
     * 检索结束时间
     */
    @JSONField(format = "yyyy-MM-dd HH:mm")
    private Date endTime;

    @JSONField
    private Long moduleId;

    @JSONField(serialize = false, deserialize = false)
    private Long nodeId;

    @JSONField
    private Long businessType;

    @JSONField
    private Long changeUser;

    @JSONField
    private String userName;

    /**
     * 业务测单据id的集合
     */
    @JSONField(name = "businessCodes")
    private String businessCodes;

    /**
     * 业务测英文表名
     */
    @JSONField
    private String businessTypeName;

    /**
     * 业务系统需要校验的单对象id
     */
    @JSONField
    private List<Long> businessCheckData;

    /**
     * 异常编号
     */
    private String errorCode;

    /**
     * 索引信息
     */
    private String businessNumber;

    /**
     * 定制页面可能需要提交的业务数据体
     */
    @JSONField
    private JSONObject customizeBody;

    @JSONField(serialize = false, deserialize = false)
    private Set<Short> statusSets;

    @JSONField(serialize = false, deserialize = false)
    private List<Long> businessCodeList;

    @JSONField(serialize = false, deserialize = false)
    private Boolean async;

    /**
     * 强制终止
     */
    private Boolean hardShut;

    /**
     * 转储业务编号
     *
     * @return
     */
    public ProcessDto collectBusinessCodes() {
        Set<Long> businessCodeSet = new HashSet<>(1);
        if (businessCode != null) {
            businessCodeSet.add(businessCode);
        }
        if (businessCodes != null && businessCodes.trim().length() != 0) {
            String[] codeArray = businessCodes.trim().split(",");
            Arrays.stream(codeArray).forEach(code -> businessCodeSet.add(Long.parseLong(code)));
        }
        businessCodeList = new ArrayList<>(businessCodeSet);
        return this;
    }

}
