package weaver.interfaces.htxc.contract.action;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.htsc.comInfo.PropBean;
import weaver.interfaces.workflow.action.Action;
import weaver.interfaces.htsc.util.WfUtil;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;


/*
 * @Author      :wanxq
 * @Date        :2022年07月14日09:43:26
 * @Version 1.0 :
 * @Description : 合同签订，触发归档流程
 **/
public class CreateContratArchWfAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        String requestid = requestInfo.getRequestid();
        String tableName = requestInfo.getRequestManager().getBillTableName();
        int operator = requestInfo.getRequestManager().getLastoperator();

        try {



            String sql = " select xzhtlb,htbb,htlx,fhtlx,htzt from  "+tableName+" where requestid=? ";
            rs.executeQuery(sql,requestid);
            if(rs.next()){
                String xzhtlb = Util.null2String(rs.getString("xzhtlb"));
                String htbb = Util.null2String(rs.getString("htbb"));
                String htlx = Util.null2String(rs.getString("htlx"));
                String fhtlx = Util.null2String(rs.getString("fhtlx"));
                String htzt = Util.null2String(rs.getString("htzt"));


                Map<String,String> dataMap = new HashMap<String,String>();
                dataMap.put("xzhtlb",xzhtlb);
                dataMap.put("htbb",htbb);
                dataMap.put("htlx",htlx);
                dataMap.put("fhtlx",fhtlx);
                dataMap.put("htzt",htzt);

                PropBean propBean = new PropBean();
                String title = "合同归档-"+xzhtlb;
                int htqdWfid = Util.getIntValue(propBean.getActiveWorkflowIdByUnNumber("zbhtgd"));
                WfUtil.createWorkflow(htqdWfid,operator,title,false,dataMap,null);
            }

        } catch (Exception e) {
            writeLog("触发合同归档流程异常：",e);
            requestInfo.getRequestManager().setMessageid( "1001004" );
            requestInfo.getRequestManager().setMessagecontent("流程提交异常,请联系管理员!");
            return Action.FAILURE_AND_CONTINUE;
        }
        return Action.SUCCESS;
    }
}
