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

// package  com.weaver.seconddev.interfaces.oascf;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import  com.weaver.seconddev.interfaces.swfa.BillFieldUtil;
import java.math.BigDecimal;
import java.util.*;
import com.weaver.common.i18n.tool.util.I18nContextUtil;
import com.weaver.verupgrade.conn.CONN_TYPE;
import java.lang.*;
import com.weaver.verupgrade.workflow.request.RequestManager;
import com.weaver.esb.api.rpc.EsbServerlessRpcRemoteInterface;
import com.weaver.common.base.entity.result.WeaResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.weaver.verupgrade.soa.workflow.request.RequestInfo;
import java.util.Map;
import java.util.HashMap;
import com.weaver.verupgrade.conn.RecordSet;
import com.weaver.verupgrade.general.BaseBean;
import com.weaver.verupgrade.general.Util;
import com.weaver.verupgrade.hrm.resource.ResourceComInfo;
import com.weaver.verupgrade.soa.workflow.request.*;
import com.weaver.verupgrade.soa.workflow.request.Property;
import com.weaver.verupgrade.soa.workflow.request.DetailTable;
import com.weaver.verupgrade.soa.workflow.request.Row;
import com.weaver.verupgrade.soa.workflow.request.Cell;
import com.weaver.verupgrade.interfaces.workflow.action.Action;

/**
 * 投资类合同登记提交校验
 */
@org.springframework.stereotype.Service("workflow_action_EasTzlhtSubmitAction")
public class EasTzlhtSubmitAction extends BaseBean implements Action, EsbServerlessRpcRemoteInterface {

    // 对应E9的请求信息对象
    @Autowired
    private RequestInfo requestInfoTemp;

    @Autowired
    private EasTzlhtApplyResult mGetResult;
    // public String getFKFname(String var1) {
    // String var2 = "";
    // RecordSet var3 = new RecordSet();
    // var3.executeSql("select selectname from workflow_SelectItem where fieldid=59629 and selectvalue = " + var1);
    // if (var3.next()) {
    // var2 = Util.null2String(var3.getString("selectname"));
    // }
    // 
    // return var2;
    // }
    private static final Logger logger_1cc47ce8 = LoggerFactory.getLogger(EasTzlhtSubmitAction.class);

    @Override
    public WeaResult<Map<String, Object>> execute(Map<String, Object> requestInfoMap) {
        Map<String, Object> weaverResultMap = new HashMap<>();
        Long requestIdTemp = Long.parseLong(String.valueOf(requestInfoMap.getOrDefault("requestid", -1)));
        Long userIdTemp = Long.parseLong(String.valueOf(requestInfoMap.getOrDefault("userid", -1)));
        RequestInfo requestInfo = requestInfoTemp.getRequestInfo(requestIdTemp, userIdTemp);
        try {
            /**
             * 请求ID*
             */
            String requestID = "";
            /**
             * 报账总金额*
             */
            BigDecimal totalMoney = new BigDecimal(0);
            /**
             * 系统标识*
             */
            String systemFlag = "OA";
            /**
             * 接口ID*
             */
            String ITFID = "ITFID";
            try {
                ResourceComInfo hr = I18nContextUtil.getBean(ResourceComInfo.class);
                BillFieldUtil unit = new BillFieldUtil();
                Property[] properties = requestInfo.getMainTableInfo().getProperty();
                requestID = requestInfo.getRequestid();
                logger_1cc47ce8.error(String.valueOf("EasTzlhtSubmitAction--start--" + requestID));
                logger_1cc47ce8.error("requestIdTemp == " +requestIdTemp);
                logger_1cc47ce8.error("userIdTemp == " +userIdTemp);
                Map<String, String> mMap = new HashMap<String, String>();
                for (int i = 0; i < properties.length; i++) {
                    String name = properties[i].getName().toUpperCase();
                    String value = Util.null2String(properties[i].getValue());
                    mMap.put(name, value);
                }
                String money = mMap.get("BZZJE");
                logger_1cc47ce8.error(String.valueOf("报账总金额:" + money));
                logger_1cc47ce8.error(String.valueOf("bzzje:" + money));
                if (money != null && !money.equals("")) {
                    // Float.parseFloat(money);
                    totalMoney = new BigDecimal(money);
                }
                // 申请人
                String sqr = mMap.get("SQR");
                String sqrcode = "";
                String sqrname = "";
                if (!sqr.equals("")) {
                    // 申请人工号
                    sqrcode = unit.getWorkcode(sqr);
                    // 申请人姓名
                    sqrname = hr.getResourcename(sqr);
                }
                String id_hsdw = mMap.get("HSDW");
                String companyId = "";
                String companyCode = "";
                String companyName = "";
                if (!id_hsdw.equals("")) {
                    companyId = gethsdwid(id_hsdw);
                    // 公司名称
                    companyName = gethsdwname(id_hsdw);
                    // 公司编码
                    companyCode = gethsdwcode(id_hsdw);
                }
                String deptId = mMap.get("SQBM");
                logger_1cc47ce8.error(String.valueOf("报账总金额:" + money));
                String deptCode = "";
                if (!"".equals(deptId)) {
                    deptCode = getDepartmentcode(deptId);
                }
                // String bz = mMap.get("BZ");
                // String currency = "";
                // if("0".equals(bz)){
                // currency = "CNY";
                // }else{
                // currency = "USD";
                // }
                String htlx = mMap.get("HTLX");
                String htlxname = "";
                if ("0".equals(htlx)) {
                    // 产业投资类
                    htlxname = "BOE_TYPE_IND";
                } else {
                    // 财务投资类
                    htlxname = "BOE_TYPE_FIN";
                }
                JSONObject mJson = new JSONObject();
                // 系统标识
                mJson.put("systemFlag", systemFlag);
                mJson.put("requestID", requestID);
                // oa合同号
                mJson.put("OANum", mMap.get("LCBH"));
                mJson.put("ITFID", ITFID);
                // 验证1就是提交，2就是归档
                mJson.put("operationFlag", "1");
                // 合同信息
                // 报账人工号
                mJson.put("employeeNumber", sqrcode);
                // 报账人姓名
                mJson.put("employeeName", sqrname);
                // 公司ID
                mJson.put("companyId", companyId);
                // 公司编码
                mJson.put("companyCode", companyCode);
                // 公司名称
                mJson.put("companyName", companyName);
                // 合同名称
                mJson.put("contractName", mMap.get("HTMC"));
                // 提报部门 deptCode   "33444"
                logger_1cc47ce8.error(String.valueOf(" deptCode:" +  deptCode));
                mJson.put("dept", deptCode);
                // 业务类型
                mJson.put("businessType", "");
                // mJson.put("currency",currency);//币种
                // mJson.put("contractNumber",mMap.get("HTBH"));//合同编号
                // 合同签订日期
                mJson.put("contractDate", mMap.get("HTQDRQ"));
                // 合同类型
                mJson.put("contractType", htlxname);
                // 金额
                mJson.put("amount", money);
                // 相关说明
                mJson.put("remarks", mMap.get("FYSM"));
                String projectCode = mMap.get("PROJECTCODE");
                String projectBudget = mMap.get("RELATIONPROJECTID");
                // 往来单位id mMap.get("WLDW") vendorid "123684"
                mJson.put("vendorName", mMap.get("VENDORID"));
                // 项目编号  mMap.get("XM")  projectCode "0000"
                mJson.put("project", mMap.get("PROJECTCODE"));
                // 项目预算 预算的relationProjectId
                mJson.put("budget", mMap.get("RELATIONPROJECTID"));
                // vendorNumber
                mJson.put("vendorNumber", mMap.get("VENDORNUMBER"));
                // 
                mJson.put("projectId", mMap.get("PROJECTID"));
                // 币种
                mJson.put("currency", mMap.get("CURRENCYCODE"));
                /**
                 * 测试环境表名字：formtable_main_2061  formtable_main_2232(165)
                 * 正式环境表名字：formtable_main_2605
                 * 控制合同金额不能超过剩余预算
                 */
                BigDecimal oldmoney = new BigDecimal(0);
                BigDecimal ysje = new BigDecimal(0);
                ;
                if (projectBudget != null && !projectBudget.equals("")) {
                    RecordSet rs = I18nContextUtil.getBean(RecordSet.class);
                    String poolname = CONN_TYPE.workflow.getType();
                    // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
                    rs.executeSql("select id,bzzje from e10_core_business.dbo.formtable_main_2605 where lcbh !='' and relationProjectId = " + projectBudget, poolname);
                    if (rs.next()) {
                        oldmoney = oldmoney.add(new BigDecimal(Util.null2String(rs.getString("bzzje"))));
                    }
                    RecordSet rs2 = I18nContextUtil.getBean(RecordSet.class);
                    String poolname_j5 = CONN_TYPE.workflow.getType();
                    // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
                    rs2.executeSql("select id,useAmount from e10_common.dbo.uf_eas_budget where relationProjectId = " + projectBudget, poolname_j5);
                    if (rs2.next()) {
                        ysje = new BigDecimal(Util.null2String(rs2.getString("useAmount")));
                    }
                }
                String fileIds = mMap.get("XGFJ");
                String fileNames = "";
                RecordSet rs = I18nContextUtil.getBean(RecordSet.class);
                if (fileIds != null && fileIds.contains(",")) {
                    String[] idArr = fileIds.split(",");
                    for (int i = 0; i < idArr.length; i++) {
                        String sql = "select id,name from e10_core_business.dbo.document as  docimagefile where id = " + idArr[i];
                        String poolname_98 = CONN_TYPE.workflow.getType();
                        // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
                        rs.executeSql(sql, poolname_98);
                        if (rs.next()) {
                            fileNames = fileNames + Util.null2String(rs.getString("imagefilename")) + ",";
                        }
                    }
                    if (fileNames.endsWith(",")) {
                        fileNames = fileNames.substring(0, fileNames.lastIndexOf(","));
                    }
                } else if (fileIds != null && !fileIds.equals("")) {
                    String sql = "select id,name from e10_core_business.dbo.document as  docimagefile where id = " + fileIds;
                    String poolname_ks = CONN_TYPE.workflow.getType();
                    // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
                    rs.executeSql(sql, poolname_ks);
                    if (rs.next()) {
                        fileNames = Util.null2String(rs.getString("imagefilename"));
                    }
                }
                // 附件id
                mJson.put("fileIds", fileIds);
                // 附件名字
                mJson.put("fileNames", fileNames);
                String errorMsg = "";
                logger_1cc47ce8.error(String.valueOf("明细表开始取值"));
                DetailTable[] detailtable = requestInfo.getDetailTableInfo().getDetailTable();
                // ===========付款条件明细==============//
                DetailTable dtq = detailtable[0];
                Row[] sq = dtq.getRow();
                JSONArray mJSONArray = new JSONArray();
                JSONArray mJSONArray1 = new JSONArray();
                ArrayList<Integer> jdslist = new ArrayList<Integer>();
                ArrayList<Integer> jdlist_fktj = new ArrayList<Integer>();
                ArrayList<Integer> jdlist_ystj = new ArrayList<Integer>();
                float totalScale = 0;
                BigDecimal totalItemMoney = new BigDecimal(0);
                for (int j = 0; j < sq.length; j++) {
                    // 指定行
                    Row rq = sq[j];
                    // 每行数据再按列存储
                    Cell[] cq = rq.getCell();
                    JSONObject item = new JSONObject();
                    float scale = 0;
                    BigDecimal itemMoney = new BigDecimal(0);
                    Map<String, String> mDetailMap = new HashMap<String, String>();
                    for (int k = 0; k < cq.length; k++) {
                        // 指定列
                        Cell cq1 = cq[k];
                        // 明细字段名称
                        String nameq = cq1.getName().toUpperCase();
                        String valueq = Util.null2String(cq1.getValue());
                        mDetailMap.put(nameq, valueq);
                    }
                    // 付款比例
                    String fkbl = mDetailMap.get("FKBL");
                    if (fkbl != null && !fkbl.equals("")) {
                        scale = Float.parseFloat(fkbl);
                        totalScale = totalScale + scale;
                    }
                    // 付款金额
                    String fkje = mDetailMap.get("FKJE");
                    logger_1cc47ce8.error(String.valueOf("fkje:" + fkje));
                    if (fkje != null && !fkje.equals("")) {
                        // Float.parseFloat(fkje);
                        itemMoney = new BigDecimal(fkje);
                        logger_1cc47ce8.error(String.valueOf("itemMoney:" + itemMoney));
                        totalItemMoney = totalItemMoney.add(itemMoney);
                        logger_1cc47ce8.error(String.valueOf("totalItemMoney:" + totalItemMoney));
                    }
                    // if(itemMoney*100 != totalMoney*scale){
                    // writeLog("总金额x付款行百分比与付款金额不相等！");
                    // errorMsg = "总金额x付款行百分比与付款金额不相等！</br>";
                    // }
                    // 付款阶段数
                    item.put("paymentNum", (Integer.parseInt(mDetailMap.get("FKJDS")) + 1) + "");
                    // 付款阶段
                    item.put("paymentStage", (Integer.parseInt(mDetailMap.get("FKJD")) + 1) + "");
                    // 付款方式  typename
                    item.put("paymentType", mDetailMap.get("PAYMENTNAME"));
                    // 付款行
                    item.put("paymentid", j);
                    // 付款比例
                    item.put("paymentPercent", mDetailMap.get("FKBL"));
                    // 付款日期
                    item.put("paymentDate", mDetailMap.get("FKRQ"));
                    // 付款金额
                    item.put("paymentAmount", mDetailMap.get("FKJE"));
                    // 期初已付金额
                    item.put("amountPaid", mDetailMap.get("QCYFKJE"));
                    mJSONArray1.add(item);
                    jdslist.add(Integer.parseInt(mDetailMap.get("FKJDS")) + 1);
                    jdlist_fktj.add(Integer.parseInt(mDetailMap.get("FKJD")) + 1);
                }
                if (totalScale != 100) {
                    logger_1cc47ce8.error(String.valueOf("所有付款行比例相加后不等于100%，请重新填写！"));
                    errorMsg = errorMsg + "所有付款行比例相加后不等于100%，请重新填写！</br>";
                    // requestInfo.getRequestManager().setMessagecontent("所有付款行比例相加后不等于100%，请重新填写！");
                    // return  FAILURE_AND_CONTINUE;
                }
                if (totalItemMoney.compareTo(totalMoney) != 0) {
                    logger_1cc47ce8.error(String.valueOf("所有付款行付款金额相加后不等于合同总金额，请重新填写！"));
                    errorMsg = errorMsg + "所有付款行付款金额相加后不等于合同总金额，请重新填写！</br>";
                }
                // 约束条件明细
                DetailTable dtq_ystj = detailtable[1];
                Row[] sq_ystj = dtq_ystj.getRow();
                Map<String, JSONArray> map = new HashMap<String, JSONArray>();
                for (int j = 0; j < sq_ystj.length; j++) {
                    // 指定行
                    Row rq = sq_ystj[j];
                    // 每行数据再按列存储
                    Cell[] cq = rq.getCell();
                    JSONObject item = new JSONObject();
                    Map<String, String> mDetailMap = new HashMap<String, String>();
                    for (int k = 0; k < cq.length; k++) {
                        // 指定列
                        Cell cq1 = cq[k];
                        // 明细字段名称
                        String nameq = cq1.getName().toUpperCase();
                        String valueq = Util.null2String(cq1.getValue());
                        mDetailMap.put(nameq, valueq);
                    }
                    String ystj_fkjd = (Integer.parseInt(mDetailMap.get("FKJD")) + 1) + "";
                    for (int m = 0; m < mJSONArray1.size(); m++) {
                        if (ystj_fkjd.equals(mJSONArray1.getJSONObject(m).getString("paymentStage"))) {
                            // 付款行id
                            item.put("paymentid", mJSONArray1.getJSONObject(m).getString("paymentid"));
                            break;
                        }
                    }
                    // item.put("paymentid",j);//付款行id
                    // 约束条件id
                    item.put("condition_id", j);
                    // 约束条件
                    item.put("condition", mDetailMap.get("YSTJ"));
                    logger_1cc47ce8.error(String.valueOf("阶段数======" + ystj_fkjd));
                    if (map.containsKey(ystj_fkjd)) {
                        map.get(ystj_fkjd).add(item);
                    } else {
                        JSONArray arr_new = new JSONArray();
                        arr_new.add(item);
                        map.put(ystj_fkjd, arr_new);
                    }
                    jdlist_ystj.add(Integer.parseInt(mDetailMap.get("FKJD")) + 1);
                }
                logger_1cc47ce8.error(String.valueOf("获取明细表数据结束"));
                for (int i = 0; i < mJSONArray1.size(); i++) {
                    JSONObject obj = mJSONArray1.getJSONObject(i);
                    String fkjd = obj.getString("paymentStage");
                    obj.put("conditions", map.get(fkjd));
                }
                mJson.put("contractLines", mJSONArray1);
                logger_1cc47ce8.error("调用投资类合同新增校验接口请求数据1：=====" + mJson.toString());
                // long count=jdslist.stream().distinct().count();
                long count = distinctBySetOrder(jdslist).size();
                logger_1cc47ce8.error("count == "+ count);
                if (count > 1) {
                    errorMsg = errorMsg + "付款条件明细表中只能选择一种阶段数！</br>";
                }
                // long count2=jdlist_fktj.stream().distinct().count();
                long count2 = distinctBySetOrder(jdlist_fktj).size();
                if (count2 < jdslist.size()) {
                    errorMsg = errorMsg + "付款条件明细表中付款阶段不能重复！</br>";
                }
                // long count3=jdlist_ystj.stream().distinct().count();
                long count3 = distinctBySetOrder(jdlist_ystj).size();
                if (count2 != count3) {
                    errorMsg = errorMsg + "约束条件明细表与付款条件明细表不匹配！</br>";
                }

                logger_1cc47ce8.error("errorMsg == "+ errorMsg);
                logger_1cc47ce8.error("projectCode == "+ projectCode);
                if ("0000".equals(projectCode) && (projectBudget != null && !projectBudget.equals(""))) {
                    requestInfo.getRequestManager().setMessageid("ERROR");
                    requestInfo.getRequestManager().setMessagecontent("项目选择无的时候，项目预算不选！");
                } else if (!"0000".equals(projectCode) && (projectBudget == null || projectBudget.equals(""))) {
                    requestInfo.getRequestManager().setMessageid("ERROR");
                    requestInfo.getRequestManager().setMessagecontent("请选择项目预算！");
                } else if ((totalMoney.compareTo(ysje.subtract(oldmoney)) == 1) && !"0000".equals(projectCode)) {
                    // (totalMoney > (ysje-oldmoney))&&!"0000".equals(projectCode)
                    logger_1cc47ce8.error(String.valueOf("预算金额：" + ysje));
                    logger_1cc47ce8.error(String.valueOf("已经使用金额：" + oldmoney));
                    requestInfo.getRequestManager().setMessageid("ERROR");
                    requestInfo.getRequestManager().setMessagecontent("合同金额大于预算可使用金额！");
                } else if (errorMsg != null && !errorMsg.equals("")) {
                    requestInfo.getRequestManager().setMessageid("ERROR");
                    requestInfo.getRequestManager().setMessagecontent(errorMsg);
                    // return  FAILURE_AND_CONTINUE;
                } else {
                    // 调用接口
//                    EasTzlhtApplyResult mGetResult = new EasTzlhtApplyResult();
                    String result = mGetResult.getApproveResult(mJson);
                    logger_1cc47ce8.error(String.valueOf("调用投资类合同新增校验接口返回值：" + result));
                    if (!"E".equals(result)) {
                        JSONObject jsonObject = JSONObject.parseObject(result);
                        // 接口处理状态 S-成功，E-失败
                        String isTat = jsonObject.getString("iSTAT");
                        // 处理消息
                        String srMessage = jsonObject.getString("sRMSAGE");
                        logger_1cc47ce8.error("报账系统返回数据：" + jsonObject.toString());
                        if (!"S".equals(isTat)) {
                            // 失败
                            logger_1cc47ce8.error(String.valueOf("报账系统返回错误信息：" + srMessage));
                            requestInfo.getRequestManager().setMessageid("ERROR");
                            requestInfo.getRequestManager().setMessagecontent("报账系统返回错误信息：" + srMessage);
                            return WeaResult.fail(500, "报账系统返回错误信息：" + srMessage, getResultMapForAction(weaverResultMap, "result", FAILURE_AND_CONTINUE, requestInfo.getRequestManager()));

                        }
                    } else {
                        logger_1cc47ce8.error(String.valueOf("调用报账系统投资类合同新增校验接口返回失败，请联系报账系统管理员！"));
                        requestInfo.getRequestManager().setMessageid("ERROR");
                        requestInfo.getRequestManager().setMessagecontent("调用报账系统投资类合同新增校验接口返回失败，请联系报账系统管理员！");
                        return WeaResult.fail(500, "调用报账系统投资类合同新增校验接口返回失败，请联系报账系统管理员！"+result, getResultMapForAction(weaverResultMap, "result", FAILURE_AND_CONTINUE, requestInfo.getRequestManager()));

                    }
                }
            } catch (Exception e) {
                logger_1cc47ce8.error(String.valueOf("提交失败！"));
                logger_1cc47ce8.error(String.valueOf("Error======" + e.getMessage()));
                requestInfo.getRequestManager().setMessageid("ERROR");
                requestInfo.getRequestManager().setMessagecontent("提交失败！");
                return  WeaResult.fail(500, "Error======"+ e, getResultMapForAction(weaverResultMap, "result", e.getMessage(), requestInfo.getRequestManager()));

            }
            return WeaResult.success(getResultMapForAction(weaverResultMap, "result", Action.SUCCESS, requestInfo.getRequestManager()));
        } catch (Exception e) {
            e.printStackTrace();
            logger_1cc47ce8.error("EasTzlhtSubmitAction e: {}", e.toString());
            return  WeaResult.fail(500, "EasTzlhtSubmitAction e: {}"+ e, getResultMapForAction(weaverResultMap, "result", e.getMessage(), requestInfo.getRequestManager()));
        }
    }

    public String gethsdwcode(String var1) {
        String var2 = "";
        RecordSet var3 = I18nContextUtil.getBean(RecordSet.class);
        String poolname_9f = CONN_TYPE.workflow.getType();
        // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
        var3.executeSql("select companycode from e10_common.dbo.uf_eas_company where id = " + var1, poolname_9f);
        if (var3.next()) {
            var2 = Util.null2String(var3.getString("companycode"));
        }
        return var2;
    }

    public String gethsdwid(String var1) {
        String var2 = "";
        RecordSet var3 = I18nContextUtil.getBean(RecordSet.class);
        String poolname_du = CONN_TYPE.workflow.getType();
        // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
        var3.executeSql("select id,oid from e10_common.dbo.uf_eas_company where id = " + var1, poolname_du);
        if (var3.next()) {
            var2 = Util.null2String(var3.getString("oid"));
        }
        return var2;
    }

    public String gethsdwname(String var1) {
        String var2 = "";
        RecordSet var3 = I18nContextUtil.getBean(RecordSet.class);
        String poolname_0g = CONN_TYPE.workflow.getType();
        // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
        var3.executeSql("select id,companyname from e10_common.dbo.uf_eas_company where id = " + var1, poolname_0g);
        if (var3.next()) {
            var2 = Util.null2String(var3.getString("companyname"));
        }
        return var2;
    }

    public String getDepartmentcode(String var1) {
        String var2 = "";
        RecordSet var3 = I18nContextUtil.getBean(RecordSet.class);
        String poolname_c3 = CONN_TYPE.workflow.getType();
        // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
        boolean b = var3.executeSql("select id, code as departmentcode from eteams.dbo.department as  HrmDepartment where id = " + var1, poolname_c3);
        if (!b) {
            logger_1cc47ce8.error(String.valueOf("查询部门信息失败！"));
        }
        if (var3.next()) {
            var2 = Util.null2String(var3.getString("departmentcode"));
        }
        return var2;
    }

    public ArrayList<Integer> distinctBySetOrder(ArrayList<Integer> list) {
        Set<Integer> set = new HashSet<Integer>();
        ArrayList<Integer> newList = new ArrayList<Integer>();
        for (Integer t : list) {
            if (set.add(t)) {
                newList.add(t);
            }
        }
        return newList;
    }

    Map<String, Object> getResultMapForAction(Map<String, Object> map, String key, Object value, RequestManager requestManager) {
        if (key != null && !key.isEmpty()) {
            map.put(key, value);
        }
        String msgContent = requestManager.getMessagecontent();
        if (msgContent != null && !msgContent.isEmpty()) {
            map.put("msgContent", msgContent);
        }
        String msgId = requestManager.getMessageid();
        if (msgId != null && !msgId.isEmpty()) {
            map.put("msgId", msgId);
        }
        return map;
    }
}
