package com.weaver.seconddev.interfaces.workflow.action;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.weaver.common.distribution.genid.IdGenerator;
import com.weaver.common.hrm.util.HrmContextUtil;
import com.weaver.ebuilder.form.client.ebform.data.EbFormDataDubboService;
import com.weaver.framework.rpc.annotation.RpcReference;
import com.weaver.seconddev.interfaces.workflow.util.CommonDevUtil;
import com.weaver.teams.domain.user.SimpleEmployee;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.weaver.common.i18n.tool.util.I18nContextUtil;
import com.weaver.verupgrade.conn.CONN_TYPE;
import com.weaver.verupgrade.general.Util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.weaver.verupgrade.conn.RecordSet;
import com.weaver.verupgrade.docs.docs.DocViewer;
import com.weaver.verupgrade.formmode.setup.ModeRightInfo;
import com.weaver.verupgrade.soa.workflow.request.Property;
import com.weaver.verupgrade.soa.workflow.request.RequestInfo;
import com.weaver.verupgrade.workflow.webservices.WorkflowBaseInfo;
import com.weaver.verupgrade.workflow.webservices.WorkflowMainTableInfo;
import com.weaver.verupgrade.workflow.webservices.WorkflowRequestInfo;
import com.weaver.verupgrade.workflow.webservices.WorkflowRequestTableField;
import com.weaver.verupgrade.workflow.webservices.WorkflowRequestTableRecord;
import com.weaver.verupgrade.workflow.webservices.WorkflowServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;

public class DoTheActionNew {

    private static final Logger logger_5105ad43 = LoggerFactory.getLogger(DoTheActionNew.class);

    private Log log = LogFactory.getLog(DoTheActionNew.class.getName());

    @Autowired
    private CommonDevUtil commonDevUtil;

    @RpcReference(group = "ebuilderform")
    private EbFormDataDubboService ebFormDataDubboService;

    public boolean doAction(RequestInfo paramRequestInfo, int actionType) throws Exception {
        RecordSet rs = I18nContextUtil.getBean(RecordSet.class);
        String workflowid = paramRequestInfo.getWorkflowid();
        Map<String, String> mainMap = new HashMap<String, String>();
        Property[] properties = paramRequestInfo.getMainTableInfo().getProperty();
        String requestId = paramRequestInfo.getRequestid();
        for (int i = 0; i < properties.length; i++) {
            String name = properties[i].getName();
            String value = Util.null2String(properties[i].getValue());
            mainMap.put(name, value);
        }
        boolean isr = true;
        if ((workflowid.equals("1108")) || (workflowid.equals("1833")) || (workflowid.equals("1113")) || (workflowid.equals("1115")) || (workflowid.equals("1832")) || (workflowid.equals("1112"))) {
            String mxid = Util.null2String((String) mainMap.get("mxid"));
            String fklx = "";
            String tjzt = "";
            String gdzt = "";
            String thzt = "";
            switch(Util.getIntValue(workflowid, 0)) {
                case // 任务变更
                1108:
                    if (actionType == 2) {
                        String xgzrw = Util.null2String((String) mainMap.get("xgzrw"));
                        String xzrr = Util.null2String((String) mainMap.get("xzzr"));
                        if (!"".equals(mxid)) {
                            if (!"".equals(xgzrw)) {
                                String poolname = CONN_TYPE.workflow.getType();
                                // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
                                boolean b = rs.executeSql("update e10_common.dbo.uf_plantask set gzrw='" + xgzrw + "' where id=" + mxid, poolname);
                                logger_5105ad43.error("b--"+b);
                            }
                            if (!"".equals(xzrr)) {
                                String poolname_1d = CONN_TYPE.workflow.getType();
                                // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
                                boolean b = rs.executeSql("update e10_common.dbo.uf_plantask set zrr='" + xzrr + "' where id=" + mxid, poolname_1d);
                                logger_5105ad43.error("b--"+b);
                            }
                        }
                        gdzt = "执行中";
                    } else if (actionType == 1) {
                        tjzt = "变更审批中";
                    } else if (actionType == 3) {
                        thzt = "执行中";
                    }
                    fklx = "变更申请";
                    break;
                case // 任务反馈
                1833:
                    fklx = "处理过程反馈";
                    gdzt = "执行中";
                    // 反馈信息添加至反馈信息表
                    Long tbr = Util.getLongValue((String) mainMap.get("tbr"));
                    String sm = (String) mainMap.get("yqsm");
                    String fjsc = (String) mainMap.get("fjsc");
                    String wjrq = (String) mainMap.get("wjrq");
                    String zrr = (String) mainMap.get("zrr");
                    String phr = (String) mainMap.get("phr");
                    String csr = (String) mainMap.get("csr");
                    String ddr = (String) mainMap.get("ddr");
                    String qrr = (String) mainMap.get("qrr");
                    Object[] array = new Object[11];
                    array[0] = requestId;
                    array[1] = sm;
                    array[2] = fjsc;
                    array[3] = wjrq;
                    array[4] = mxid;
                    array[5] = zrr;
                    array[6] = ddr;
                    array[7] = csr;
                    array[8] = phr;
                    array[9] = qrr;
                    array[10] = tbr;
                    // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
//                    String sql = "insert into dbo.uf_zqjhrqfkxx (requestId,fksm,fj,fkrq,pid,zrr,ddr,csr,phr,qrr,formmodeid,modedatacreater) values (?,?,?,?,?,?,?,?,?,?,97,?)";
//                    rs.executeSql(sql, false, poolname, array);
                    String poolname = CONN_TYPE.hrm.getType();
                    SimpleEmployee currentEmployee = HrmContextUtil.getCurrentUser();
                    Long uf_CustomFlow_formId = commonDevUtil.getObjId("By_Worktaskfankui");
                    logger_5105ad43.error("uf_CustomFlow_formId = " + uf_CustomFlow_formId);
                    Long recodId = ebFormDataDubboService.addEmptyData(uf_CustomFlow_formId, currentEmployee);
                    String sql = "update e10_common.dbo.uf_zqjhrqfkxx set requestId='" + array[0]+"',fksm='"+ array[1]+"',fj='"+ array[2]+"',fkrq='"+ array[3]+"',pid='"+ array[4]+"',zrr='"+ array[5]+"',ddr='"+ array[6]+"',csr='"+ array[7]+"',phr='"+ array[8]+"',qrr='"+ array[9]+"',formmodeid='97',modedatacreater='"+array[10]+"' where id  =  " + recodId + " and delete_type = 0 ";
                    boolean b = rs.executeSql(sql, poolname);
                    if (b) {
                        logger_5105ad43.error("添加反馈信息成功");
                    } else {
                        logger_5105ad43.error("添加反馈信息失败");
                    }
                    String sql2 = "select * from e10_common.dbo.uf_zqjhrqfkxx where pid = " + mxid;
                    RecordSet rs3 = I18nContextUtil.getBean(RecordSet.class);
                    ModeRightInfo info = I18nContextUtil.getBean(ModeRightInfo.class);
                    // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
                    boolean b1 = rs3.executeSql(sql2, poolname);
                    logger_5105ad43.error("b1--"+b1);
                    while (rs3.next()) {
                        // id
                        //TODO custom 已处理 类型转换
                        Long id =  Long.parseLong(rs3.getString("id"));
                        /* TODO 方法参数:tbr 类型发生变化 e9类型:int e10类型:long
 TODO 方法参数:97 类型发生变化 e9类型:int e10类型:long
 TODO 方法参数:id 类型发生变化 e9类型:int e10类型:long
 TODO  e10 添加数据共享默认删除文档共享，此处直接调用权限重构*/
                        info.addDocShare(tbr, 97, id);
                        /* TODO 方法参数:tbr 类型发生变化 e9类型:int e10类型:long
 TODO 方法参数:97 类型发生变化 e9类型:int e10类型:long
 TODO 方法参数:id 类型发生变化 e9类型:int e10类型:long
 TODO // 创建人字段已废弃 默认是用billid 数据对应的数据创建人*/
                        info.rebuildModeDataShareByEdit(tbr, 97, id);
                    }
                    break;
                case // 任务取消
                1113:
                    if (actionType == 2) {
                        if (!"".equals(mxid)) {
                            String poolname_6k = CONN_TYPE.workflow.getType();
                            // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
                            boolean b2 = rs.executeSql("update e10_common.dbo.uf_plantask set rwzt='已取消' where id=" + mxid, poolname_6k);
                            logger_5105ad43.error("b2--"+b2);
                            jhrwDate("qxjsrq", mxid);
                            String poolname_mz = CONN_TYPE.workflow.getType();
                            // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
                            boolean b3 = rs.executeSql("select qxsqrq,qxjsrq from e10_common.dbo.uf_plantask where id='" + mxid + "'", poolname_mz);
                            logger_5105ad43.error("b3--"+b3);
                            if (rs.next()) {
                                String ksrq = Util.null2String(rs.getString("qxsqrq"));
                                String jsrq = Util.null2String(rs.getString("qxjsrq"));
                                qxRw(mxid, ksrq, jsrq);
                            }
                        }
                        gdzt = "已取消";
                    } else if (actionType == 1) {
                        tjzt = "取消审批中";
                        jhrwDate("qxsqrq", mxid);
                    } else if (actionType == 3) {
                        String poolname_2z = CONN_TYPE.workflow.getType();
                        // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
                        boolean b2 = rs.executeSql("update e10_common.dbo.uf_plantask set qxjsrq='',qxsqrq='' where id=" + mxid, poolname_2z);
                        logger_5105ad43.error("b2--"+b2);
                        thzt = "执行中";
                    }
                    fklx = "取消申请";
                    break;
                case // 审批退回
                1115:
                    if (actionType == 2) {
                        if (!"".equals(mxid)) {
                            String poolname_og = CONN_TYPE.workflow.getType();
                            // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
                            boolean b2 = rs.executeSql("update e10_common.dbo.uf_plantask set rwzt='执行中',wcjsrq='',wcsqrq='' where id=" + mxid, poolname_og);
                            logger_5105ad43.error("b2--"+b2);
                        }
                        gdzt = "执行中";
                    } else if (actionType == 3) {
                        thzt = "执行中";
                    }
                    fklx = "审批回退";
                    break;
                case // 任务完结
                1832:
                    if (actionType == 2) {
                        if (!"".equals(mxid)) {
                            String poolname_nf = CONN_TYPE.workflow.getType();
                            // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
                            boolean b2 = rs.executeSql("update e10_common.dbo.uf_plantask set rwzt='已完成' where id=" + mxid, poolname_nf);
                            logger_5105ad43.error("b2--"+b2);
                            jhrwDate("wcjsrq", mxid);
                            String ypid = "";
                            String poolname_ml = CONN_TYPE.workflow.getType();
                            // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
                            boolean b3 = rs.executeSql("select pid from e10_common.dbo.uf_plantask where id=" + mxid, poolname_ml);
                            logger_5105ad43.error("b3--"+b3);
                            if (rs.next()) {
                                ypid = Util.null2String(rs.getString("pid"));
                                logger_5105ad43.error("ypid：" + ypid);
                            }
                            String sqlaa = "select count(*) as cnum from e10_common.dbo.uf_plantask where  pid=" + ypid;
                            String poolname_bj = CONN_TYPE.workflow.getType();
                            // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
                            boolean b4 = rs.executeSql(sqlaa, poolname_bj);
                            logger_5105ad43.error("b4--"+b4);
                            logger_5105ad43.error("sqlaa：" + sqlaa);
                            if (rs.next()) {
                                logger_5105ad43.error("cnum：" + rs.getString("cnum"));
                                if (Util.getIntValue(rs.getString("cnum")) == 1) {
                                    String poolname_vc = CONN_TYPE.workflow.getType();
                                    // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
                                    boolean b5 = rs.executeSql("select rwlx,rwjb from e10_common.dbo.uf_plantask where pid=" + ypid, poolname_vc);
                                    logger_5105ad43.error("b5--"+b5);
                                    if (rs.next()) {
                                        String rwlx = rs.getString("rwlx");
                                        String rwjb = rs.getString("rwjb");
                                        if ((rwlx != "0") || (rwjb != "4")) {
                                            logger_5105ad43.error("ypid1：" + ypid);
                                            update_upworkflow(ypid);
                                        }
                                    }
                                }
                            }
                        }
                        gdzt = "已完成";
                    } else if (actionType == 1) {
                        tjzt = "结案审批中";
                        jhrwDate("wcsqrq", mxid);
                    } else if (actionType == 3) {
                        thzt = "执行中";
                    }
                    fklx = "结案申请";
                    break;
                case // 任务延期
                1112:
                    if (actionType == 2) {
                        String xyqrq = Util.null2String((String) mainMap.get("xyqrq"));
                        if (!"".equals(mxid)) {
                            String poolname_zl = CONN_TYPE.workflow.getType();
                            // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
                            boolean b2 = rs.executeSql("update e10_common.dbo.uf_plantask set yqrq='" + xyqrq + "' where id=" + mxid, poolname_zl);
                            logger_5105ad43.error("b2--"+b2);
                        }
                        jhrwDate("yqjsrq", mxid);
                        gdzt = "执行中";
                    } else if (actionType == 1) {
                        jhrwDate("yqsqrq", mxid);
                        tjzt = "延期审批中";
                    } else if (actionType == 3) {
                        String poolname_t8 = CONN_TYPE.workflow.getType();
                        // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
                        boolean b2 = rs.executeSql("update e10_common.dbo.uf_plantask set yqsqrq='',yqjsrq='' where id='" + mxid + "' ", poolname_t8);
                        logger_5105ad43.error("b2--"+b2);
                        thzt = "执行中";
                    }
                    fklx = "延期申请";
            }
            if (actionType == 2) {
                String poolname_qa = CONN_TYPE.workflow.getType();
                // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
                boolean b = rs.executeSql("update e10_common.dbo.uf_plantask set rwzt='" + gdzt + "' where id=" + mxid, poolname_qa);
                logger_5105ad43.error("b--"+b);
            } else if (actionType == 1) {
                String poolname_ef = CONN_TYPE.workflow.getType();
                // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
                boolean b = rs.executeSql("update e10_common.dbo.uf_plantask set rwzt='" + tjzt + "' where id=" + mxid, poolname_ef);
                logger_5105ad43.error("b--"+b);
            } else if (actionType == 3) {
                String poolname_sr = CONN_TYPE.workflow.getType();
                // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
                boolean b = rs.executeSql("update e10_common.dbo.uf_plantask set rwzt='" + thzt + "' where id=" + mxid, poolname_sr);
                logger_5105ad43.error("b--"+b);
            }
            yjxr(mainMap, workflowid, fklx, paramRequestInfo);
        }
        return isr;
    }

    public void update_upworkflow(String mxid) {
        WorkflowRequestTableField[] wrti = new WorkflowRequestTableField[16];
        Map<String, String> map = new HashMap<String, String>();
        RecordSet rs = I18nContextUtil.getBean(RecordSet.class);
        String sql = "select * from e10_common.dbo.uf_plantask where id=" + mxid;
        String poolname_fv = CONN_TYPE.workflow.getType();
        // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
        boolean b = rs.executeSql(sql, poolname_fv);
        logger_5105ad43.error("b--"+b);
        if (rs.next()) {
            String[] names = rs.getColumnName();
            for (String name : names) {
                map.put(name, Util.null2String(rs.getString(name)));
            }
        }
        wrti[0] = new WorkflowRequestTableField();
        wrti[0].setFieldName("mxid");
        wrti[0].setFieldValue((String) map.get("MXID"));
        wrti[0].setView(true);
        wrti[0].setEdit(true);
        wrti[1] = new WorkflowRequestTableField();
        wrti[1].setFieldName("qrr");
        wrti[1].setFieldValue((String) map.get("QRR"));
        wrti[1].setView(true);
        wrti[1].setEdit(true);
        wrti[2] = new WorkflowRequestTableField();
        wrti[2].setFieldName("ddr");
        wrti[2].setFieldValue((String) map.get("DDR"));
        wrti[2].setView(true);
        wrti[2].setEdit(true);
        wrti[3] = new WorkflowRequestTableField();
        wrti[3].setFieldName("rwbh");
        wrti[3].setFieldValue((String) map.get("RWBH"));
        wrti[3].setView(true);
        wrti[3].setEdit(true);
        wrti[4] = new WorkflowRequestTableField();
        wrti[4].setFieldName("rwlx");
        wrti[4].setFieldValue((String) map.get("RWLX"));
        wrti[4].setView(true);
        wrti[4].setEdit(true);
        wrti[5] = new WorkflowRequestTableField();
        wrti[5].setFieldName("rwjb");
        wrti[5].setFieldValue((String) map.get("RWJB"));
        wrti[5].setView(true);
        wrti[5].setEdit(true);
        wrti[6] = new WorkflowRequestTableField();
        wrti[6].setFieldName("tdsj");
        wrti[6].setFieldValue((String) map.get("TDSJ"));
        wrti[6].setView(true);
        wrti[6].setEdit(true);
        wrti[7] = new WorkflowRequestTableField();
        wrti[7].setFieldName("lxsj");
        wrti[7].setFieldValue((String) map.get("LXSJ"));
        wrti[7].setView(true);
        wrti[7].setEdit(true);
        wrti[8] = new WorkflowRequestTableField();
        wrti[8].setFieldName("xmkp");
        wrti[8].setFieldValue((String) map.get("XMKP"));
        wrti[8].setView(true);
        wrti[8].setEdit(true);
        wrti[9] = new WorkflowRequestTableField();
        wrti[9].setFieldName("shr");
        wrti[9].setFieldValue((String) map.get("SHR"));
        wrti[9].setView(true);
        wrti[9].setEdit(true);
        wrti[10] = new WorkflowRequestTableField();
        wrti[10].setFieldName("tbr");
        wrti[10].setFieldValue((String) map.get("TBR"));
        wrti[10].setView(true);
        wrti[10].setEdit(true);
        wrti[11] = new WorkflowRequestTableField();
        wrti[11].setFieldName("tbgs");
        wrti[11].setFieldValue((String) map.get("TBGS"));
        wrti[11].setView(true);
        wrti[11].setEdit(true);
        wrti[12] = new WorkflowRequestTableField();
        wrti[12].setFieldName("tbbm");
        wrti[12].setFieldValue((String) map.get("TBBM"));
        wrti[12].setView(true);
        wrti[12].setEdit(true);
        wrti[13] = new WorkflowRequestTableField();
        wrti[13].setFieldName("wjrq");
        wrti[13].setFieldValue((String) map.get("WJRQ"));
        wrti[13].setView(true);
        wrti[13].setEdit(true);
        wrti[14] = new WorkflowRequestTableField();
        wrti[14].setFieldName("yqsm");
        wrti[14].setFieldValue((String) map.get("YQSM"));
        wrti[14].setView(true);
        wrti[14].setEdit(true);
        WorkflowRequestTableRecord[] wrtri = new WorkflowRequestTableRecord[1];
        wrtri[0] = new WorkflowRequestTableRecord();
        wrtri[0].setWorkflowRequestTableFields(wrti);
        WorkflowMainTableInfo wmi = new WorkflowMainTableInfo();
        wmi.setRequestRecords(wrtri);
        WorkflowBaseInfo wbi = new WorkflowBaseInfo();
        wbi.setWorkflowId("1832");
        WorkflowRequestInfo wri = new WorkflowRequestInfo();
        wri.setCreatorId((String) map.get("ZRR"));
        wri.setRequestLevel("0");
        wri.setRequestName("完成流程触发");
        wri.setWorkflowMainTableInfo(wmi);
        wri.setWorkflowBaseInfo(wbi);
        WorkflowServiceImpl WorkflowServicePortTypeProxy = I18nContextUtil.getBean(WorkflowServiceImpl.class);
        // TODO 方法参数:1 类型发生变化 e9类型:int e10类型:Long
        //TODO custom 已处理 管理员id
//        String requestid = WorkflowServicePortTypeProxy.doCreateWorkflowRequest(wri, 1);
        String requestid = WorkflowServicePortTypeProxy.doCreateWorkflowRequest(wri, 1046285013082546176L);
        logger_5105ad43.error("流程触发：" + requestid);
    }

    public void qxRw(String mxid, String ksrq, String jsrq) {
        RecordSet rs = I18nContextUtil.getBean(RecordSet.class);
        RecordSet rs1 = I18nContextUtil.getBean(RecordSet.class);
        String sql = "select mxid from e10_common.dbo.uf_plantask where pid='" + mxid + "'";
        String poolname_2f = CONN_TYPE.workflow.getType();
        // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
        boolean b = rs.executeSql(sql, poolname_2f);
        logger_5105ad43.error("b--"+b);
        while (rs.next()) {
            String mxid2 = Util.null2String(rs.getString("mxid"));
            String poolname_j2 = CONN_TYPE.workflow.getType();
            // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
            boolean b1 = rs1.executeSql("update e10_common.dbo.uf_plantask set rwzt='已取消',yqsqrq='" + ksrq + "',yqjsrq='" + jsrq + "' where id='" + mxid2 + "' ", poolname_j2);
            logger_5105ad43.error("b1--"+b1);
            qxRw(mxid2, ksrq, jsrq);
        }
    }

    public void jhrwDate(String zd, String mxid) {
        Date nowDate = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String nowDateStr = sdf.format(nowDate);
        RecordSet rs = I18nContextUtil.getBean(RecordSet.class);
        String poolname_gd = CONN_TYPE.workflow.getType();
        // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
        boolean b = rs.executeSql("update e10_common.dbo.uf_plantask set " + zd + "='" + nowDateStr + "' where id='" + mxid + "' ", poolname_gd);
        logger_5105ad43.error("b--" + b);
    }

    public void yjxr(Map<String, String> mainMap, String workflowid, String fklx, RequestInfo paramRequestInfo) throws Exception {
        RecordSet rs2 = I18nContextUtil.getBean(RecordSet.class);
        RecordSet rs1 = I18nContextUtil.getBean(RecordSet.class);
        String requestid = paramRequestInfo.getRequestid();
        String mxid = Util.null2String((String) mainMap.get("mxid"));
        Calendar cal = Calendar.getInstance();
        String currDate = Util.add0(cal.get(1), 4) + "-" + Util.add0(cal.get(2) + 1, 2) + "-" + Util.add0(cal.get(5), 2);
        String currTime = Util.add0(cal.getTime().getHours(), 2) + ":" + Util.add0(cal.getTime().getMinutes(), 2);
        String remark = paramRequestInfo.getRequestManager().getRemark();
        String userid = paramRequestInfo.getLastoperator();
        String fjid = "";
        /*
	String sql11="SELECT top 1 ANNEXDOCIDS FROM workflow_requestlog WHERE REQUESTID='"+requestid+"' AND  OPERATOR='"+userid+"'"+ " order by operatedate desc,operatetime desc ";
	rs2.execute(sql11);
	logger_5105ad43.error("sql11:" + sql11);
	if(rs2.next())
	{
		fjid = Util.null2String(rs2.getString("ANNEXDOCIDS")).replace(" ", "");
	}
	BaseBean bb = new BaseBean();
	bb.writeLog("getSigndocids--"+ paramRequestInfo.getRequestManager().getSigndocids());
	bb.writeLog("sql11--fjid--"+ sql11);
	bb.writeLog("sql11--fjid--"+ requestid + "----" + fjid + "----");
	*/
        remark = remark.replace("&nbsp;", "");
        remark = remark.replace("'", "''");
        if (!"".equals(remark) || !"".equals(fjid)) {
//            String sql1 = "insert into By_Worktaskfankui(worktaskid,begindate,Begintime,resourceid,description,Createrid,Requestid,fj,title) values('" + mxid + "'," + "'" + currDate + "'," + "'" + currTime + "'," + "'" + userid + "'," + "'" + remark + "'," + "'" + userid + "'," + "'" + requestid + "'," + "'" + fjid + "'," + "'" + fklx + "审批'" + ")";
//            String poolname_yt = CONN_TYPE.workflow.getType();
//            /* *TODO  检测到insert语句 -> E9插入sql迁移到E10需要特殊处理请参考文档进行调整  https://www.e-cology.com.cn/sp/doc/docShare/1027709301045985331?tenantKey=t7akvdnf84
// TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源*/
//            long generate = IdGenerator.generate();
//            rs2.executeSql(sql1, poolname_yt,generate);
//            logger_5105ad43.error("sql1:" + sql1);
            String poolname = CONN_TYPE.hrm.getType();
            SimpleEmployee currentEmployee = HrmContextUtil.getCurrentUser();
            Long uf_CustomFlow_formId = commonDevUtil.getObjId("By_Worktaskfankui");
            logger_5105ad43.error("uf_CustomFlow_formId = " + uf_CustomFlow_formId);
            Long recodId = ebFormDataDubboService.addEmptyData(uf_CustomFlow_formId, currentEmployee);
            String sql3 = "update e10_common.dbo.By_Worktaskfankui set worktaskid='" + mxid + "',begindate=" + " '" + currDate + "',Begintime=" + " '" + currTime + "',resourceid=" + " '" + userid + "',description=" + " '" + remark + "',Createrid=" + " '" + userid + "',Requestid=" + " '" + requestid + "',fj=" + " '" + fjid + "',title="+ " '" + fklx + "审批' " + " where id  = " + recodId + " and delete_type = 0 ";
            boolean b1 = rs2.executeSql(sql3, poolname);
            logger_5105ad43.error("sql3 = " + sql3);
            logger_5105ad43.error("添加 = " + b1);
            if (!fjid.equals("")) {
                logger_5105ad43.error("SET_WD_QX:");
                SET_WD_QX(fjid, mxid);
            }
        }
        String sql = "select id from e10_common.dbo.By_Worktaskfankui where worktaskid='" + mxid + "' and requestid = '" + requestid + "' and title like '" + fklx + "'";
        String poolname_ui = CONN_TYPE.workflow.getType();
        // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
        boolean b = rs1.executeSql(sql, poolname_ui);
        logger_5105ad43.error("b--" + b);
        logger_5105ad43.error("sql:" + sql);
        if (!rs1.next()) {
            xrfksj(mainMap, fklx, paramRequestInfo);
        }
    }

    public void qzyjxr(Map<String, String> mainMap, String fklx, RequestInfo paramRequestInfo) {
        RecordSet rs2 = I18nContextUtil.getBean(RecordSet.class);
        RecordSet rs1 = I18nContextUtil.getBean(RecordSet.class);
        String requestid = paramRequestInfo.getRequestid();
        String mxid = Util.null2String((String) mainMap.get("mxid"));
        String sql2 = "select remark,annexdocids,operatedatetime,operatetime,creator from e10_common.dbo.wfc_requestlog as  workflow_requestlog where remark is not null and requestid='" + requestid + "'";
        String poolname_84 = CONN_TYPE.workflow.getType();
        // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
        boolean b = rs1.executeSql(sql2, poolname_84);
        logger_5105ad43.error("b:" + b);
        while (rs1.next()) {
            String remark = Util.null2String(rs1.getString("remark"));
            remark = remark.replace("&nbsp;", "");
            String fjid = Util.null2String(rs1.getString("annexdocids"));
            String date = Util.null2String(rs1.getString("operatedate"));
            String time = Util.null2String(rs1.getString("operatetime"));
            String userid = Util.null2String(rs1.getString("operator"));
//            String sql1 = "insert into By_Worktaskfankui(id,worktaskid,begindate,Begintime,resourceid,description,Createrid,Requestid,fj,title) values(By_Worktaskfankuid.Nextval,'" + mxid + "'," + "'" + date + "'," + "'" + time + "'," + "'" + userid + "'," + "'" + remark + "'," + "'" + userid + "'," + "'" + requestid + "'," + "'" + fjid + "'," + "'" + fklx + "签字意见'" + ")";
//            String poolname_j4 = CONN_TYPE.workflow.getType();
//            /* *TODO  检测到insert语句 -> E9插入sql迁移到E10需要特殊处理请参考文档进行调整  https://www.e-cology.com.cn/sp/doc/docShare/1027709301045985331?tenantKey=t7akvdnf84
// TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源*/
//            long generate = IdGenerator.generate();
//            rs2.executeSql(sql1, poolname_j4,generate);
            String poolname = CONN_TYPE.hrm.getType();
            SimpleEmployee currentEmployee = HrmContextUtil.getCurrentUser();
            Long uf_CustomFlow_formId = commonDevUtil.getObjId("By_Worktaskfankui");
            logger_5105ad43.error("uf_CustomFlow_formId = " + uf_CustomFlow_formId);
            Long recodId = ebFormDataDubboService.addEmptyData(uf_CustomFlow_formId, currentEmployee);
            String sql3 = "update e10_common.dbo.By_Worktaskfankui set worktaskid='" + mxid + "',begindate=" + " '" + date + "',Begintime=" + " '" + time + "',resourceid=" + " '" + userid + "',description=" + " '" + remark + "',Createrid=" + " '" + userid + "',Requestid=" + " '" + requestid + "',fj=" + " '" + fjid + "',title="+ " '" +fklx + "签字意见' " + " where id  = " + recodId + " and delete_type = 0 ";
            boolean b1 = rs2.executeSql(sql3, poolname);
            logger_5105ad43.error("sql3 = " + sql3);
            logger_5105ad43.error("添加 = " + b1);
        }
        Calendar cal = Calendar.getInstance();
        String currDate = Util.add0(cal.get(1), 4) + "-" + Util.add0(cal.get(2) + 1, 2) + "-" + Util.add0(cal.get(5), 2);
        String currTime = Util.add0(cal.getTime().getHours(), 2) + ":" + Util.add0(cal.getTime().getMinutes(), 2);
        String remark = paramRequestInfo.getRequestManager().getRemark();
        remark = remark.replace("&nbsp;", "");
        String fjid = "";
        String userid = paramRequestInfo.getLastoperator();
//        String sql1 = "insert into By_Worktaskfankui(id,worktaskid,begindate,Begintime,resourceid,description,Createrid,Requestid,fj,title) values(By_Worktaskfankuid.Nextval,'" + mxid + "'," + "'" + currDate + "'," + "'" + currTime + "'," + "'" + userid + "'," + "'" + remark + "'," + "'" + userid + "'," + "'" + requestid + "'," + "'" + fjid + "'," + "'" + fklx + "签字意见'" + ")";
//        String poolname_j5 = CONN_TYPE.workflow.getType();
//        /* *TODO  检测到insert语句 -> E9插入sql迁移到E10需要特殊处理请参考文档进行调整  https://www.e-cology.com.cn/sp/doc/docShare/1027709301045985331?tenantKey=t7akvdnf84
// TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源*/
//        long generate = IdGenerator.generate();
//        rs2.executeSql(sql1, poolname_j5,generate);
        String poolname = CONN_TYPE.hrm.getType();
        SimpleEmployee currentEmployee = HrmContextUtil.getCurrentUser();
        Long uf_CustomFlow_formId = commonDevUtil.getObjId("By_Worktaskfankui");
        logger_5105ad43.error("uf_CustomFlow_formId = " + uf_CustomFlow_formId);
        Long recodId = ebFormDataDubboService.addEmptyData(uf_CustomFlow_formId, currentEmployee);
        String sql3 = "update e10_common.dbo.By_Worktaskfankui set worktaskid='" + mxid + "',begindate=" + " '" + currDate + "',Begintime=" + " '" + currTime + "',resourceid=" + " '" + userid + "',description=" + " '" + remark + "',Createrid=" + " '" + userid + "',Requestid=" + " '" + requestid + "',fj=" + " '" + fjid + "',title="+ " '" + fklx + "签字意见' " + " where id  = " + recodId + " and delete_type = 0 ";
        boolean b1 = rs2.executeSql(sql3, poolname);
        logger_5105ad43.error("sql3 = " + sql3);
        logger_5105ad43.error("添加 = " + b1);
    }

    public void xrfksj(Map mainMap, String fklx, RequestInfo paramRequestInfo) throws Exception {
        RecordSet rs = I18nContextUtil.getBean(RecordSet.class);
        String requestid = paramRequestInfo.getRequestid();
        String mxid = Util.null2String((String) mainMap.get("mxid"));
        String fksm = Util.null2String((String) mainMap.get("yqsm")).replace("'", "''");
        String fj = Util.null2String((String) mainMap.get("fjsc")).replace(" ", "");
        Calendar cal = Calendar.getInstance();
        String currDate = Util.add0(cal.get(1), 4) + "-" + Util.add0(cal.get(2) + 1, 2) + "-" + Util.add0(cal.get(5), 2);
        String currTime = Util.add0(cal.getTime().getHours(), 2) + ":" + Util.add0(cal.getTime().getMinutes(), 2);
        /* TODO 返回值:sql1 类型发生变化 e9类型:int  e10类型:long
 TODO 返回值:sql1 类型发生变化 e9类型:int  e10类型:long*/
//        String sql1 = "insert into By_Worktaskfankui(worktaskid,begindate,Begintime,resourceid,description,Createrid,Requestid,fj,title) values('" + mxid + "'," + "'" + currDate + "'," + "'" + currTime + "'," + "'" + paramRequestInfo.getRequestManager().getCreater() + "'," + "'" + fksm + "'," + "'" + paramRequestInfo.getRequestManager().getCreater() + "'," + "'" + requestid + "'," + "'" + fj + "'," + "'" + fklx + "'" + ")";
//        String poolname_ty = CONN_TYPE.workflow.getType();
//        /* *TODO  检测到insert语句 -> E9插入sql迁移到E10需要特殊处理请参考文档进行调整  https://www.e-cology.com.cn/sp/doc/docShare/1027709301045985331?tenantKey=t7akvdnf84
// TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源*/
//        long generate = IdGenerator.generate();
//        rs.executeSql(sql1, poolname_ty,generate);
//        logger_5105ad43.error("sql1:" + sql1);
        String poolname = CONN_TYPE.hrm.getType();
        SimpleEmployee currentEmployee = HrmContextUtil.getCurrentUser();
        Long uf_CustomFlow_formId = commonDevUtil.getObjId("By_Worktaskfankui");
        logger_5105ad43.error("uf_CustomFlow_formId = " + uf_CustomFlow_formId);
        Long recodId = ebFormDataDubboService.addEmptyData(uf_CustomFlow_formId, currentEmployee);
        String sql3 = "update e10_common.dbo.By_Worktaskfankui set worktaskid='" + mxid + "',begindate=" + " '" + currDate + "',Begintime=" + " '" + currTime + "',resourceid=" + " '" + paramRequestInfo.getRequestManager().getCreater() + "',description=" + " '" + fksm + "',Createrid=" + " '" + paramRequestInfo.getRequestManager().getCreater() + "',Requestid=" + "'" + requestid + "',fj=" + " '" + fj + "'," + "'" + fklx + "签字意见' " + " where id  = " + recodId + " and delete_type = 0 ";
        boolean b1 = rs.executeSql(sql3, poolname);
        logger_5105ad43.error("b1 = " + b1);
//        logger_5105ad43.error("SET_WD_QX:");
        if (!fj.equals("")) {
            SET_WD_QX(fj, mxid);
        }
    }

    public void SET_WD_QX(String fj, String worktaskid) throws Exception {
        String ryid = "";
        RecordSet rs = I18nContextUtil.getBean(RecordSet.class);
        // String sql1 = " select ZRR||','||PHR||','||DDR||','||QRR||','||CSR||','||TBR as ryid from uf_plantask jh  start with jh.id = " + worktaskid + " connect   by   prior   jh.pid=jh.id ";
        String sql1 = "with temp (id,pid,zrr,phr,ddr,qrr,csr,tbr) as ( select id,pid,zrr,phr,ddr,qrr,csr,tbr from uf_plantask where id = " + worktaskid + " union all select a.id,a.pid,a.zrr,a.phr,a.ddr,a.qrr,a.csr,a.tbr from uf_plantask a inner join temp on a.id = temp.pid)" + " select (cast(zrr as varchar) + ','+ cast(phr as varchar) + ',' + cast(ddr as varchar) + ',' + cast(qrr as varchar) + ',' + cast(csr as varchar) + ',' + cast(tbr as varchar)) as ryid from temp ";
        String poolname_ab = CONN_TYPE.workflow.getType();
        // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
        boolean b = rs.executeSql(sql1, poolname_ab);
        logger_5105ad43.error("b:" + b);
        logger_5105ad43.error("sql1:" + sql1);
        while (rs.next()) {
            ryid = ryid + Util.null2String(rs.getString("ryid")) + ",";
        }
        logger_5105ad43.error("ryid:" + ryid);
        ryid = ryid.replace(" ", "");
        String[] strarray = ryid.split(",");
        ArrayList<String> List = new ArrayList();
        String temp = "";
        for (int n = 0; n < strarray.length - 1; n++) {
            temp = Util.null2String(strarray[n] + "");
            if (temp != "") {
                if (!List.contains(temp)) {
                    List.add(temp);
                }
            }
        }
        /*
    for (int i = 0; i <= List.size() - 1; i++)
    {
      for (int j = List.size() - 1; j > i; j--)
      {
        if (List.get(j).equals(List.get(i)))
        {
          List.remove(j);
        }

      }

    }
	*/
        RecordSet rs1 = I18nContextUtil.getBean(RecordSet.class);
        String sql2 = "";
        logger_5105ad43.error("fj:" + fj);
        String[] fjids = fj.split(",");
        String fjid = "";
        for (int n = 0; n < fjids.length; n++) {
            logger_5105ad43.error("fjid:" + fj);
            fjid = fjids[n].replace(" ", "");
            if (fjid != "") {
                logger_5105ad43.error("docid:" + fjid);
                for (int m = 0; m <= List.size() - 1; m++) {
                    if (!List.get(m).equals("")) {
                        logger_5105ad43.error("strarray1[m]:" + List.get(m));
//                        sql2 = "insert into document_ph_doc_s01(docid,sharetype,seclevel,rolelevel,sharelevel,userid,downloadlevel,roleid,foralluser)values( " + fjid + ",1 , 0, 0 ,1 ," + List.get(m) + ", 0 ,0 , 0)";
//                        String poolname_1n = CONN_TYPE.workflow.getType();
//                        // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
//                        rs1.executeSql(sql2, poolname_1n);
                        String poolname = CONN_TYPE.hrm.getType();
                        SimpleEmployee currentEmployee = HrmContextUtil.getCurrentUser();
                        Long uf_CustomFlow_formId = commonDevUtil.getObjId("By_Worktaskfankui");
                        logger_5105ad43.error("uf_CustomFlow_formId = " + uf_CustomFlow_formId);
                        Long recodId = ebFormDataDubboService.addEmptyData(uf_CustomFlow_formId, currentEmployee);// 获取插入的空的建模id
                        String sql3 = "update e10_common.dbo.By_Worktaskfankui set docid=" + fjid + ",sharetype=1,seclevel=0,rolelevel=0,sharelevel=1,userid=" + List.get(m) + ",downloadlevel=0,roleid=0,foralluser=0 where id  =  " + recodId + " and delete_type = 0 ";
                        boolean b1 = rs.executeSql(sql3, poolname);
                        logger_5105ad43.error("sql3 = " + sql3);
                        logger_5105ad43.error("添加 = " + b1);
                    }
                }
                DocViewer dv = I18nContextUtil.getBean(DocViewer.class);
                dv.setDocShareByDoc(fjid);
            }
        }
    }

    public void xrfksj2(Map mainMap, String fklx, RequestInfo paramRequestInfo, String id) {
        RecordSet rs = I18nContextUtil.getBean(RecordSet.class);
        String requestid = paramRequestInfo.getRequestid();
        String mxid = Util.null2String((String) mainMap.get("mxid"));
        String fksm = Util.null2String((String) mainMap.get("yqsm"));
        String fj = Util.null2String((String) mainMap.get("fjsc"));
        Calendar cal = Calendar.getInstance();
        String currDate = Util.add0(cal.get(1), 4) + "-" + Util.add0(cal.get(2) + 1, 2) + "-" + Util.add0(cal.get(5), 2);
        String currTime = Util.add0(cal.getTime().getHours(), 2) + ":" + Util.add0(cal.getTime().getMinutes(), 2);
        String sql1 = "update e10_common.dbo.By_Worktaskfankui set begindate='" + currDate + "'," + "Begintime='" + currTime + "'," + "description='" + fksm + "'," + "fj='" + fj + "' " + " where id='" + id + "'";
        String poolname_8h = CONN_TYPE.workflow.getType();
        // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
        boolean b = rs.executeSql(sql1, poolname_8h);
        logger_5105ad43.error("b:" + b);
    }
}
