package com.engine.htxc.workflow.create.business.contract.sign.service.impl;

import cn.hutool.core.date.DateTime;
import com.engine.htxc.commonutil.workflow.WorkflowCreate;
import com.engine.htxc.workflow.create.business.contract.init.ContractWorkflowData;
import com.engine.htxc.workflow.create.cinterface.CustomizeWorkflow;
import com.engine.integration.util.StringUtils;
import weaver.general.Util;
import weaver.interfaces.htsc.comInfo.PropBean;
import java.util.*;


/**
 * @author K1810015
 * @version 1.0.0
 * @ClassName ConstractDiscardServiceImpl.java
 * @createTime 2022年07月17日 19:59:00
 */
public class ConstracSignServiceImpl extends ContractWorkflowData implements CustomizeWorkflow {

    private PropBean pb=new PropBean();

    public ConstracSignServiceImpl(Map<String,Object> map) {
        super(map);
    }


    @Override
    public int create() {
        String  workflowid=Util.null2String(pb.getPropName("constract.sign.workflowid"));
        if(StringUtils.isBlank(requestid) || StringUtils.isBlank(requestname)){
            return -101;
        }
        String creatorid=Util.null2String(map.get("creatorid"));
        if(StringUtils.isBlank(creatorid)){
            return -102;
        }
        String requestnamevalue=requestname+"-"+DateTime.now().toString("yyyyMMdd");
        Map<String,String> retmap=initdata();
        if(retmap==null || retmap.size()<=0){
            return -103;
        }
        WorkflowCreate workflowCreate= WorkflowCreate.createWorkflow(p->{
            p.setCreatorId(creatorid);
            p.setWorkflowId(workflowid);
            p.setRequestName(requestnamevalue);
            p.setIsNextFlow("");
            p.setRequestMainMap(retmap);
        }).workflowCreateByRequestMap();
        if(StringUtils.isBlank(workflowCreate.requestid)){
            return -1;
        }
        List<Map<String,String>> list4= getdetailtable(4,null);
        List<Map<String,String>> list5 =getdetailtable(5,null);
        String value= workflowCreate.workflowCreatelist("4",list4).workflowCreatelist("5",list5).requestid;
        return Util.getIntValue(value,-100);
    }
    public Map<String,String> initdata(){
        Map<String,Object>maintable=getmaintable(null);
        Map<String,String> retmap=new HashMap<>(2);
        maintable.entrySet().forEach(p->{
            if(!StringUtils.isBlank(p.getKey()) &&
               !StringUtils.isBlank(Util.null2String(p.getValue())) ){
                retmap.put(p.getKey(),Util.null2String(p.getValue()));
            }
        });
        retmap.remove("id");
        retmap.remove("yzhqdcs");
        maintable.put("ngrq", DateTime.now().toString("yyyy-MM-dd hh:mm"));
        return retmap;
    }
}

