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

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
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.prop.ConfigProp;
import com.weaver.seconddev.interfaces.workflow.util.CommonDevUtil;
import com.weaver.teams.domain.user.SimpleEmployee;
import corp.openapicalls.contract.setapproval.request.PassengerDetail;
import com.weaver.seconddev.interfaces.htjt.util.LogUtil;
import com.weaver.seconddev.interfaces.htjt.util.WebApi;
import com.weaver.seconddev.interfaces.htjt.workflow.hr.HrUtil;
import org.apache.commons.lang.StringUtils;
// import  com.weaver.seconddev.interfaces.easoa.CallTravelApplyService;
// import  com.weaver.seconddev.interfaces.easoa.SI_BusinessTripApplicationSync_OUTServiceStub;
import  com.weaver.seconddev.interfaces.easoa.CallTravelApplyService;
import  com.weaver.seconddev.interfaces.easoa.SI_BusinessTripApplicationSync_OUTServiceStub;
import  com.weaver.seconddev.interfaces.oactrip.OaCtrip;
import  com.weaver.seconddev.interfaces.swfa.BillFieldUtil;
import  com.weaver.seconddev.interfaces.swfa.sl.CallDTtripService;

import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
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.Property;
import com.weaver.verupgrade.interfaces.workflow.action.Action;

/**
 * 出差申请接口--国内出差申请--qingf20160921
 * 同步出差申请单到EAS 提交OA流程requestId：1362923
 *
 * @author Administrator
 */
@org.springframework.stereotype.Service("workflow_action_ZOA_SL_GNCC_Action")
public class ZOA_SL_GNCC_Action extends BaseBean implements Action, EsbServerlessRpcRemoteInterface {

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

    @Autowired
    private CallTravelApplyService callTravelApply;

    @Autowired
    private OaCtrip oactrip ;

    @Autowired
    private CommonDevUtil commonDevUtil;

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


//    @Autowired
//    private CallSLServices callServices;
    @Autowired
    private CallDTtripService dTtripService;
    private static final Logger logger_5e8d517a = LoggerFactory.getLogger(ZOA_SL_GNCC_Action.class);

    // E就是否 是否传商旅
    public String sfcsl = "";

    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 request = requestInfoTemp.getRequestInfo(requestIdTemp, userIdTemp);
        try {
            // 流程请求ID
            String reid = request.getRequestid();
            String requestname = request.getRequestManager().getRequestname();
            String workflowid = request.getWorkflowid();
            try {
                // 主体信息
                String sourceType = "";
                String sourceKey = "";
                String applyEmpNum = "";
                String errandEmpNum = "";
                String projectCode = "";
                String journeyType = "";
                String corporation = "";
                String costCentre = "";
                String contactName = "";
                String contactPhone = "";
                String contactEmail = "";
                String trafficExpense = "";
                String hotelExpense = "";
                String otherExpense = "";
                String reason = "";
                // 行程信息
                String seqNo = "";
                String fromCity = "";
                String toCity = "";
                String journeyType1 = "";
                String areaType = "";
                String trafficTool = "other";
                String startDate = "";
                String endDate = "";
                // 同行人信息
                String personnelType = "";
                String empNum = "";
                String personnelName = "";
                String passName = "";
                String passType = "";
                String passNum = "";
                String mobilePhone = "";
                String email = "";
                // 扩展信息
                String attribute2 = "";
                String attribute3 = "";
                String attribute4 = "";
                String attribute5 = "";
                String attribute6 = "";
                String attribute7 = "";
                String attribute8 = "";
                String attribute9 = "";
                String attribute10 = "08:00";
                String attribute11 = "";
                String attribute12 = "17:30";
                String attribute13 = "";
                String attribute14 = "";
                String attribute15 = "";
                String attribute16 = "";
                String attribute17 = "";
                String attribute18 = "";
                String attribute19 = "";
                String attribute20 = "";
                // 携程信息
                List<String> listNumber = new ArrayList<String>();
                // 审批单号请求ID
                String approvalnumber = "";
                // 员工编号
                String employeeid = "";
                // 申请日期
                String expiredtime = "";
                // 开始日期时间
                Date begindate = new Date();
                // 开始日期时间
                Date enddate = new Date();
                ArrayList<PassengerDetail> passengerdetails = new ArrayList<PassengerDetail>();
                String sqr = "";
                // 流程请求ID
                approvalnumber = reid;
                logger_5e8d517a.error(String.valueOf("ZOA_SL_GNCC_Action-Request: " + reid + "开始 sfcsl:" + sfcsl));
                RecordSet rs1 = I18nContextUtil.getBean(RecordSet.class);
                ResourceComInfo hr = I18nContextUtil.getBean(ResourceComInfo.class);
                BillFieldUtil unit = new BillFieldUtil();
                // 流程请求ID
                attribute2 = reid;
                // applyEmpNum = unit.getWorkcode(request.getCreatorid());//经办人工号
                // 行程类型INLAND国内、OVERSEAS国际
                journeyType = "INLAND";
                // 所属项目
                projectCode = "OA";
                // 系统标识
                sourceType = "OA";
                // 原因
                reason = "";
                // 出差类型
                attribute7 = "国内";
                // EMPLOYEE员工,RELATIVE亲友
                personnelType = "EMPLOYEE";
                seqNo = "1";
                fromCity = "公司";
                toCity = "";
                // OW单程，RT往返
                journeyType1 = "RT";
                startDate = "";
                endDate = "";
                // 出差随行人员
                String ccsxry = "";
                // 出差类型0国内，1国外
                String cclx = "0";
                // 申请部门
                String sqbm = "0";
                // 申请单位
                String sqdw = "0";
                // 是否已推送hr
                String sfytshr = "";
                // 调用商旅接口
//                CallSLServices callServices = new CallSLServices();
                // 定义单据主信息
                HashMap errandBill = new HashMap();
                // 定义单据扩展信息
                HashMap mapStrings = new HashMap();
                // 定义同行人信息
                ArrayList<HashMap> companionInfos = new ArrayList<HashMap>();
                HashMap companionInfo = new HashMap();
                // 定义行程信息
                ArrayList<HashMap> journeys = new ArrayList<HashMap>();
                HashMap journey = new HashMap();
                // 封装表单信息
                // 获取表单主字段信息
                Property[] properties = request.getMainTableInfo().getProperty();
                for (int i = 0; i < properties.length; i++) {
                    // 主表数据
                    // 字段名
                    String name = properties[i].getName().toLowerCase();
                    // 值
                    String value = Util.null2String(properties[i].getValue());
                    // 单据主信息使用
                    if (name.equals("lcbh")) {
                        // 流程编号
                        sourceKey = value;
                    }
                    if (name.equals("sfytshr")) {
                        // 
                        sfytshr = value;
                    }
                    if (name.equals("jbr")) {
                        // 经办人
                        String jbr = value;
                        if (!jbr.equals("")) {
                            // 经办人工号
                            applyEmpNum = unit.getWorkcode(jbr);
                        }
                    }
                    if (name.equals("sqr")) {
                        // 出差人
                        sqr = value;
                        // 出差人工号
                        errandEmpNum = unit.getWorkcode(sqr);
                        // applyEmpNum = errandEmpNum;//经办人工号
                        // 出差人工号
                        empNum = errandEmpNum;
                        // 出差人姓名
                        attribute3 = hr.getResourcename(sqr);
                        // 出差人姓名
                        personnelName = attribute3;
                    }
                    if (name.equals("sqbm")) {
                        // 部门
                        sqbm = value;
                        // 部门名称
                        attribute4 = unit.getDepartmentname(sqbm);
                    }
                    if (name.equals("sqdw")) {
                        // 分部
                        sqdw = value;
                        // 分部名称
                        attribute5 = unit.getSubcompanyname(sqdw);
                    }
                    if (name.equals("cclx")) {
                        // 出差类型
                        cclx = value;
                        if (cclx.equals("1")) {
                            // 出差类型
                            attribute7 = "国外";
                            // 行程类型INLAND国内、OVERSEAS国际
                            journeyType = "OVERSEAS";
                        }
                    }
                    if (name.equals("ccsy")) {
                        // 出差事由
                        reason = value;
                    }
                    if (name.equals("sqrq")) {
                        // 申请日期
                        attribute6 = value;
                        // 申请日期
                        expiredtime = value;
                    }
                    if (name.equals("cfdd")) {
                        if (!value.equals("")) {
                            // 出发地点
                            fromCity = value;
                        }
                    }
                    if (name.equals("ccdd")) {
                        // 出差地点
                        attribute8 = value;
                        // 出差地点
                        toCity = value;
                    }
                    if (name.equals("ksrq")) {
                        // 开始日期
                        attribute9 = value;
                        // 出发日期
                        startDate = value;
                    }
                    if (name.equals("kssj")) {
                        // 开始时间
                        attribute10 = value;
                    }
                    if (name.equals("jsrq")) {
                        // 结束日期
                        attribute11 = value;
                        // 结束日期
                        endDate = value;
                    }
                    if (name.equals("jssj")) {
                        // 结束时间
                        attribute12 = value;
                    }
                    if (name.equals("ccsxry")) {
                        // 出差随行人员
                        ccsxry = value;
                    }
                }
                if (applyEmpNum.length() < 10) {
                    // 经办人工号
                    applyEmpNum = errandEmpNum;
                }
                // 写入携程系统的开始结束日期时间拼接
                if (attribute10.equals("")) {
                    attribute10 = "00:00";
                }
                if (attribute12.equals("")) {
                    attribute12 = "23:59";
                }
                employeeid = applyEmpNum;
                DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                begindate = dateFormat.parse(attribute9 + " " + attribute10 + ":00");
                enddate = dateFormat.parse(attribute11 + " " + attribute12 + ":59");
                // 出差申请写入HR系统
                String beginDateTime = attribute9 + " " + attribute10;
                String endDateTime = attribute11 + " " + attribute12;
                double qjss = 1.00;
                DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                try {
                    Date d1 = df.parse(beginDateTime);
                    Date d2 = df.parse(endDateTime);
                    double diff = d2.getTime() - d1.getTime();
                    double xs = diff / (1000 * 60 * 60);
                    DecimalFormat ss = new DecimalFormat("#.00");
                    String strss = ss.format(xs);
                    qjss = Double.parseDouble(strss);
                } catch (Exception e) {
                    System.err.println(e.toString());
                }
                // 推送E-HR
                // ChuChaiShenQing po = new ChuChaiShenQing();
                // po.Getexecute(reid, errandEmpNum, "A11", beginDateTime, endDateTime, qjss);
                LogUtil logUtil = new LogUtil();
                logUtil.setJklm("ZOA_SL_GNCC_Action");
                logUtil.setLx("1");
                logUtil.setBt(requestname);
                logUtil.setLcid(reid);
                logUtil.setLclxid(workflowid);
                HrUtil hu = new HrUtil();
                BaseBean log = new BaseBean();
                Map<String, String> xtpz = hu.getHrurl(errandEmpNum, rs1);
                String hrapiurl = xtpz.get("hrapiurl");
                String hrtoken = xtpz.get("hrtoken");
                String hrloginname = xtpz.get("hrloginname");
                String hrygwcid = xtpz.get("hrygwcid");
                logger_5e8d517a.error(String.valueOf(reid + " hrapiurl:" + hrapiurl));
                JSONObject hrparam = new JSONObject();
                hrparam.put("AccessToken", hrtoken);
                JSONObject data = new JSONObject();
                data.put("formno", getForm(reid));
                JSONArray detail = new JSONArray();
                JSONObject jo = new JSONObject();
                jo.put("Employeeid", errandEmpNum);
                jo.put("leavetypeid", hrygwcid);
                jo.put("begindate", beginDateTime.substring(0, 10));
                jo.put("begintime", beginDateTime.substring(11, 16));
                jo.put("enddate", endDateTime.substring(0, 10));
                jo.put("endtime", endDateTime.substring(11, 16));
                detail.add(jo);
                logger_5e8d517a.error(String.valueOf("传递出差单据信息"));
                errandBill.put("sourceType", sourceType);
                errandBill.put("sourceKey", sourceKey);
                errandBill.put("applyEmpNum", applyEmpNum);
                errandBill.put("errandEmpNum", errandEmpNum);
                errandBill.put("projectCode", projectCode);
                errandBill.put("journeyType", journeyType);
                errandBill.put("corporation", corporation);
                errandBill.put("costCentre", costCentre);
                errandBill.put("contactName", contactName);
                errandBill.put("contactPhone", contactPhone);
                errandBill.put("contactEmail", contactEmail);
                errandBill.put("trafficExpense", trafficExpense);
                errandBill.put("hotelExpense", hotelExpense);
                errandBill.put("otherExpense", otherExpense);
                errandBill.put("reason", reason);
                companionInfo.put("personnelType", personnelType);
                companionInfo.put("empNum", empNum);
                companionInfo.put("personnelName", personnelName);
                companionInfo.put("passName", passName);
                companionInfo.put("passType", passType);
                companionInfo.put("passNum", passNum);
                companionInfo.put("mobilePhone", mobilePhone);
                companionInfo.put("email", email);
                // 向arrayList中添加对象 循环中处理
                companionInfos.add(companionInfo);
                // 携程接口出行人信息
                PassengerDetail passengerdetail = new PassengerDetail();
                passengerdetail.setName(personnelName);
                String sfzh = unit.getCredentialsNumber(sqr);
                if (sfzh.equals("")) {
                    passengerdetail.setCredentialsNumber("null");
                } else {
                    passengerdetail.setCredentialsNumber(sfzh);
                }
                passengerdetails.add(passengerdetail);
                String synergeticNumbers = "";
                String synergeticNames = "";
                // 同程差旅人信息
                List<Map<String, Object>> personList = new ArrayList<Map<String, Object>>();
                Map<String, Object> person = new HashMap<String, Object>();
                person.put("name", personnelName);
                person.put("relation", 0);
                person.put("passengerType", 0);
                person.put("outEmployeeId", errandEmpNum);
                personList.add(person);
                if (!ccsxry.equals("")) {
                    String[] aa = ccsxry.split(",");
                    String[] sxrgh = new String[aa.length];
                    String[] sxrxm = new String[aa.length];
                    for (int i = 0; i < aa.length; i++) {
                        String ccr = aa[i];
                        String ccrgh = unit.getWorkcode(ccr);
                        sxrgh[i] = ccrgh;
                        sxrxm[i] = hr.getResourcename(ccr);
                        HashMap companionInfo1 = new HashMap();
                        companionInfo1.put("personnelType", personnelType);
                        companionInfo1.put("empNum", ccrgh);
                        companionInfo1.put("personnelName", hr.getResourcename(ccr));
                        companionInfo1.put("passName", passName);
                        companionInfo1.put("passType", passType);
                        companionInfo1.put("passNum", passNum);
                        companionInfo1.put("mobilePhone", mobilePhone);
                        companionInfo1.put("email", email);
                        // 向arrayList中添加对象 循环中处理
                        companionInfos.add(companionInfo1);
                        listNumber.add(ccrgh);
                        // hr
                        // po.Getexecute(reid, ccrgh, "A11", beginDateTime, endDateTime, qjss);//出差申请写入HR系统
                        if (!ccrgh.equals(errandEmpNum)) {
                            jo = new JSONObject();
                            jo.put("Employeeid", ccrgh);
                            jo.put("leavetypeid", hrygwcid);
                            jo.put("begindate", beginDateTime.substring(0, 10));
                            jo.put("begintime", beginDateTime.substring(11, 16));
                            jo.put("enddate", endDateTime.substring(0, 10));
                            jo.put("endtime", endDateTime.substring(11, 16));
                            detail.add(jo);
                        }
                        // 携程接口出差人信息
                        PassengerDetail passengerdetail2 = new PassengerDetail();
                        passengerdetail2.setName(hr.getResourcename(ccr));
                        sfzh = unit.getCredentialsNumber(ccr);
                        if (sfzh.equals("")) {
                            passengerdetail2.setCredentialsNumber("null");
                        } else {
                            passengerdetail2.setCredentialsNumber(sfzh);
                        }
                        passengerdetails.add(passengerdetail2);
                        // 同程差旅人信息
                        if (ccr != sqr) {
                            Map<String, Object> person1 = new HashMap<String, Object>();
                            person1.put("name", hr.getResourcename(ccr));
                            person1.put("relation", 0);
                            person1.put("passengerType", 0);
                            person1.put("outEmployeeId", unit.getWorkcode(ccr));
                            personList.add(person1);
                        }
                    }
                    synergeticNumbers = StringUtils.join(sxrgh, ",");
                    synergeticNames = StringUtils.join(sxrxm, ",");
                }
                // 推送hr系统
                RecordSet rs = I18nContextUtil.getBean(RecordSet.class);
                String str = "failed";
                String hrstate = "E";
                if ("0".equals(sfytshr)) {
                    hrparam.put("LogonInfo", "LoginName=" + hrloginname + "&BusinessUnit=0&LogonRegion=zh-CN&ExpiredDate=" + hu.getExpiredDate() + "&ServiceCode=applyformleave");
                    data = new JSONObject();
                    data.put("formno", getForm(reid));
                    data.put("reason", "审批完成归档");
                    hrparam.put("Data", data);
                } else {
                    hrparam.put("LogonInfo", "LoginName=" + hrloginname + "&BusinessUnit=0&LogonRegion=zh-CN&ExpiredDate=" + hu.getExpiredDate() + "&ServiceCode=createleave");
                    data.put("detail", detail);
                    hrparam.put("Data", data);
                }
                logger_5e8d517a.error(reid + " ZOA_SL_GNCC_Action param:" + hrparam.toJSONString());
                logUtil.setTscs(hrparam.toJSONString());
                try {
                    String result = WebApi.postConnection(hrapiurl, hrparam.toJSONString(), "POST");
                    logger_5e8d517a.error(String.valueOf(reid + " result:" + result));
                    logUtil.setFhxx(result);
                    JSONObject json = JSON.parseObject(result);
                    boolean IsSuccess = json.getBoolean("IsSuccess");
                    String Message = json.getString("Message");
                    if (!IsSuccess) {
                        logUtil.setJkzt("1");
                        logUtil.insertLog();
                        str = Message;
                    } else {
                        str = "SUCCESS";
                        hrstate = "S";
                    }
                } catch (Exception e) {
                    logUtil.setFhxx("异常信息：" + e.getMessage());
                    logUtil.setJkzt("2");
                    logUtil.insertLog();
                    logger_5e8d517a.error(String.valueOf(reid + " ZOA_SL_GNCC_Action error:" + e.getMessage()));
                    logger_5e8d517a.error(String.valueOf(e));
                    str = e.toString();
                }
                if (str.length() > 150) {
                    str = str.substring(0, 150);
                }
                long generate = IdGenerator.generate();
                String sql = "insert into e10_common.dbo.chuchai_qingjia_log(id,requestId,gh,lbbh,kssj,jssj,message,state,qjss) values("+generate + ",'" + reid + "','','A11','" + beginDateTime + "','" + endDateTime + "','" + str + "','" + hrstate + "','" + qjss + "')";
//                String poolname = 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(sql, poolname,generate);
//                Long uf_CustomFlow_formId1 = commonDevUtil.getObjId("chuchai_qingjia_log");
//                logger_5e8d517a.error("uf_CustomFlow_formId = " + uf_CustomFlow_formId1);
//                SimpleEmployee currentEmployee = HrmContextUtil.getCurrentUser();
//                Long recodId = ebFormDataDubboService.addEmptyData(uf_CustomFlow_formId1, currentEmployee);// 获取插入的空的建模id
                String poolname1 = CONN_TYPE.workflow.getType();
//                String sql = "update e10_common.dbo.sync_eas_log set requestId = '" + reid + "',gh = '',lbbh='A11',kssj='" + beginDateTime + "',jssj='" + endDateTime + "',message='" + str + "',state='" + hrstate + "',qjss='" + qjss + "' where id  =  " + recodId + " and delete_type = 0 ";
                boolean b = rs.executeSql(sql, poolname1);
                logger_5e8d517a.error("sql3 = " + sql);
                logger_5e8d517a.error("添加 = " + b);
                // 推送结束
                logger_5e8d517a.error(String.valueOf("传递出差单据信息3"));
                journey.put("seqNo", seqNo);
                journey.put("fromCity", fromCity);
                journey.put("toCity", toCity);
                journey.put("journeyType", journeyType1);
                journey.put("areaType", areaType);
                journey.put("trafficTool", trafficTool);
                journey.put("startDate", startDate);
                journey.put("endDate", endDate);
                // 向arrayList中添加对象 循环中处理
                journeys.add(journey);
                mapStrings.put("attribute2", attribute2);
                mapStrings.put("attribute3", attribute3);
                mapStrings.put("attribute4", attribute4);
                mapStrings.put("attribute5", attribute5);
                mapStrings.put("attribute6", attribute6);
                mapStrings.put("attribute7", attribute7);
                mapStrings.put("attribute8", attribute8);
                mapStrings.put("attribute9", attribute9);
                mapStrings.put("attribute10", attribute10);
                mapStrings.put("attribute11", attribute11);
                mapStrings.put("attribute12", attribute12);
                mapStrings.put("attribute13", attribute13);
                mapStrings.put("attribute14", attribute14);
                mapStrings.put("attribute15", attribute15);
                mapStrings.put("attribute16", attribute16);
                mapStrings.put("attribute17", attribute17);
                mapStrings.put("attribute18", attribute18);
                mapStrings.put("attribute19", attribute19);
                mapStrings.put("attribute20", attribute20);
                // 传递出差单据信息
//                callServices.setErrandBillInfo(errandBill);
//                // writeLog("errandBill完成 ");
//                // 传递单据扩展信息
//                callServices.setMapString(mapStrings);
//                // writeLog("mapStrings完成 ");
//                // 传递同行人信息
//                // writeLog("companionInfos 长度为 "+companionInfos.size());
//                callServices.setCompanionInfo(companionInfos);
//                // writeLog("companionInfos完成 ");
//                // 传递行程信息
//                callServices.setJourneyInfo(journeys);
                // writeLog("journeys完成 ");
                // writeLog("传递出差单据信息完成");
                String tablename = "";
                String status = "E";
                String message = "";
                String returnCode = "";
                String wfid = request.getWorkflowid();
//                tablename = unit.getTablename(wfid);
                tablename = request.getRequestManager().getBillTableName();
//                String isneedxzsl = I18nContextUtilcus.getBean(Environment.class).getProperty("htctripmt.isneedxzsl");
//                String isneedxzsl = configProp.getIsneedxzsl();
//                if ("1".equals(isneedxzsl)) {
//                    // 是否需要推送中兴商旅 1是 0否
//                    try {
//                        logger_5e8d517a.error(String.valueOf("调用中兴接口开始"));
//                        String[] strResult = callServices.call();
//                        // writeLog("ReturnCode:"+strResult[0]);
//                        // writeLog("ReturnERRORMessage:"+strResult[1]);
//                        // writeLog("ReturnPassword:"+strResult[2]);
//                        // writeLog("ReturnBillNum:"+strResult[3]);
//                        returnCode = strResult[0];
//                        if (returnCode.equals("0000") || returnCode.equals("1304")) {
//                            status = "S";
//                        }
//                        message = "--商旅接口回写说明--ReturnCode:" + strResult[0] + "；ReturnERRORMessage:" + strResult[1] + "；ReturnPassword:" + strResult[2] + "；ReturnBillNum:" + strResult[3];
//                        message = message.replace("'", "’");
//                        if (!tablename.equals("")) {
//                            String logsql = "update " + tablename + " set status ='" + status + "', message = isnull(cast(message as varchar(8000)),'') + '" + message + "' where requestId = " + reid;
//                            logger_5e8d517a.error(String.valueOf("logsql:" + logsql));
//                            String poolname_bl = CONN_TYPE.workflow.getType();
//                            // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
//                            rs1.executeSql(logsql, poolname_bl);
//                        }
//                    } catch (Exception e) {
//                        logger_5e8d517a.error(String.valueOf(reid + "商旅接口Exception:" + e.getMessage()));
//                        // e.printStackTrace();
//                    }
//                }
                if (!"E".equals(sfcsl)) {
                    try {
                        logger_5e8d517a.error(String.valueOf("调用携程接口开始 "));
//                        OaCtrip oactrip = new OaCtrip();
                        oactrip.setPassengerDetails(passengerdetails);
                        oactrip.setGWPassengerDetails(passengerdetails);
                        employeeid = unit.getEmployeeId("ZOA_SL_GNCC_Action", employeeid, listNumber);
                        String[] strreturn = oactrip.call(approvalnumber, employeeid, expiredtime, begindate, enddate, cclx);
                        if (status.equals("S")) {
                            status = strreturn[0];
                        }
                        message = "--携程接口回写说明--ReturnStatus:" + strreturn[0] + "；ReturnERRORMessage:" + strreturn[1] + "；ReturnErrorCode:" + strreturn[2];
                        message = message.replace("'", "’");
                        if (!tablename.equals("")) {
                            String logsql2 = "update e10_core_business.dbo." + tablename + " set status ='" + status + "', message = isnull(cast(message as varchar(8000)),'') + '" + message + "' where id = " + reid;
                            logger_5e8d517a.error(String.valueOf("logsql2:" + logsql2));
                            String poolname_yg = CONN_TYPE.workflow.getType();
                            // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
                            boolean b1 = rs1.executeSql(logsql2, poolname_yg);
                            logger_5e8d517a.error(String.valueOf("b1:" + b1));
                        }
                    } catch (Exception e) {
                        logger_5e8d517a.error(String.valueOf(reid + "携程接口Exception:" + e.getMessage()));
                        // e.printStackTrace();
                    }
                }
                /*try {
                writeLog("调用亨通商旅接口开始 ");
                errandBill.remove("costCentre");
                journey.put("seqNo", reid);
                journey.remove("areaType");
                journey.remove("trafficTool");
                errandBill.put("sourceType", "");
                errandBill.put("sourceKey", "");
                errandBill.put("journeyInfo", journey);
                errandBill.put("companionInfos", companionInfos);
                List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
                list.add(errandBill);
                Map<String, Object> billInfo = new HashMap<String, Object>();
                billInfo.put("errandBillInfos", list);
                JSONObject jsonObject = new JSONObject(billInfo);
                CreateBill create = new CreateBill();
                String[] ret = create.call(jsonObject);
                writeLog("传亨通商旅接口数据：" + jsonObject.toJSONString());
                if (status.equals("S")) {
                    status = ret[0];
                }
                message = "--亨通商旅接口回写说明--ReturnStatus:" + ret[0] + "；ReturnERRORMessage:" + ret[1];
                message = message.replace("'", "’");
                if (!tablename.equals("")) {
                    String logsql3 = "update " + tablename + " set status ='" + status + "', message = isnull(cast(message as varchar(8000)),'') + '" + message + "' where requestId = " + reid;
                    writeLog("logsql3:" + logsql3);
                    rs1.execute(logsql3);
                }
            } catch (Exception e) {
                writeLog(reid+"亨通商旅接口Exception:" + e.getMessage());
            }*/
                if (!"E".equals(sfcsl)) {
                    try {
                        logger_5e8d517a.error(String.valueOf("调用同程商旅接口开始 "));
                        Map<String, Object> map = new HashMap<String, Object>();
                        map.put("outTravelApplyNo", reid);
                        map.put("travelApplyType", 1);
                        String travelApplyTime = dateFormat.format(new Date());
                        map.put("travelApplyTime", travelApplyTime);
                        map.put("travelUpdateTime", travelApplyTime);
                        map.put("operationType", 1);
                        map.put("outEmployeeId", errandEmpNum);
                        map.put("travelDescription", reason);
                        map.put("bookableProducts", "1,3,5");
                        map.put("status", 1);
                        // 差旅内容
                        List<Map<String, String>> itemList = new ArrayList<Map<String, String>>();
                        Map<String, String> item = new HashMap<String, String>();
                        item.put("startDate", startDate.replaceAll("-", "/"));
                        item.put("endDate", endDate.replaceAll("-", "/"));
                        item.put("departCity", fromCity);
                        item.put("arriveCity", toCity);
                        itemList.add(item);
                        map.put("itemList", itemList);
                        map.put("personList", personList);
                        /*                List<Map<String,Object>> preTravelPolicyList = new ArrayList<Map<String,Object>>();
                Map<String,Object> preTravelPolicy = new HashMap<String,Object>();
                preTravelPolicy.put("approveRuleType",0);
                preTravelPolicyList.add(preTravelPolicy);
                map.put("preTravelPolicyList",preTravelPolicyList);*/
//                        CallDTtripService dTtripService = new CallDTtripService();
                        String[] dTtrip = dTtripService.optForDTtrip(map);
                        if (status.equals("S")) {
                            status = dTtrip[0];
                        }
                        message = "--同程接口回写说明--ReturnStatus:" + dTtrip[0] + "；ReturnMessage:" + dTtrip[1] + "；出差单号:" + dTtrip[2];
                        message = message.replace("'", "’");
                        String logsql4 = "update e10_core_business.dbo." + tablename + " set status ='" + dTtrip[0] + "', message = isnull(cast(message as varchar(8000)),'') + '" + message + "' where id = " + reid;
                        logger_5e8d517a.error(String.valueOf("logsql4:" + logsql4));
                        String poolname_m6 = CONN_TYPE.workflow.getType();
                        // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
                        boolean b1 = rs1.executeSql(logsql4, poolname_m6);
                        logger_5e8d517a.error(String.valueOf("b1:" + b1));
                    } catch (Exception e) {
                        e.printStackTrace();
                        logger_5e8d517a.error(String.valueOf(reid + "同程商旅接口Exception:" + e.getMessage()));
                    }
                    logger_5e8d517a.error(String.valueOf("调用接口完成 "));
                }
                String kssj = attribute9 + " " + attribute10 + ":00";
                String jssj = attribute11 + " " + attribute12 + ":59";
                String sqrq = attribute6 + " 00:00:00";
                String sta = "F";
                String title = request.getRequestManager().getRequestname();
                try {
                    logger_5e8d517a.error(String.valueOf("ZOA_SL_GNCC_Action开始调用EAS出差申请接口"));
                    SI_BusinessTripApplicationSync_OUTServiceStub.SyncTravelApplyService input = new SI_BusinessTripApplicationSync_OUTServiceStub.SyncTravelApplyService();
                    SI_BusinessTripApplicationSync_OUTServiceStub.SyncTravelApplyInfo infos = new SI_BusinessTripApplicationSync_OUTServiceStub.SyncTravelApplyInfo();
                    SI_BusinessTripApplicationSync_OUTServiceStub.TravelApply param = new SI_BusinessTripApplicationSync_OUTServiceStub.TravelApply();
                    param.setFlowId(reid);
                    param.setFlowCode(sourceKey);
                    param.setStartDate(kssj);
                    param.setEndDate(jssj);
                    param.setApplyTime(sqrq);
                    param.setToAddress(attribute8);
                    param.setApplyerNumber(errandEmpNum);
                    param.setApplyerName(attribute3);
                    param.setSynergeticNumbers(synergeticNumbers);
                    param.setSynergeticNames(synergeticNames);
                    param.setReason(reason);
                    param.setTitle(title);
                    param.setApplyerDept(attribute4);
                    param.setApplyerCompany(attribute5);
                    infos.addApplyInfos(param);
                    infos.setITFID("HT01BZ020");
                    infos.setSENDID("");
                    infos.setSYSID("SYS005");
                    input.setSyncInfo(infos);
                    logger_5e8d517a.error(String.valueOf(reid + "往EAS传输数据封装完成"));
//                    CallTravelApplyService callTravelApply = new CallTravelApplyService();
                    callTravelApply.setInput(input);
                    String[] result = callTravelApply.call();
                    sta = result[0];
                    message = result[1];

                    String poolname_ui = CONN_TYPE.workflow.getType();
                    //generate过长 新id=获取id最大值+1
                    String newIdSql = "SELECT ISNULL((SELECT TOP 1 id FROM e10_common.dbo.sync_eas_log ORDER BY id DESC), 0) + 1 AS id";
                    boolean flag = rs.executeSql(newIdSql, poolname_ui);
                    logger_5e8d517a.error("flag---"+flag);
                    long newId = 0;
                    if (rs.next()) {
                        newId = Long.parseLong(rs.getString("id"));
                    }
                    String sql3 = "insert into e10_common.dbo.sync_eas_log(id,requestId,lcbh,kssj,jssj,sqrq,ccmdd,gh,name,sxrgh,sxrxm,reason,title,sqbm,sqdw,status,message) " + "values(" + newId + ",'" + reid + "','" + sourceKey + "','" + kssj + "','" + jssj + "','" + sqrq + "','" + attribute8 + "','" + errandEmpNum + "','" + attribute3 + "','" + synergeticNumbers + "'" + ",'" + synergeticNames + "','" + reason + "','" + title + "','" + attribute4 + "','" + attribute5 + "','" + sta + "','" + message + "')";
//                    /* *TODO  检测到insert语句 -> E9插入sql迁移到E10需要特殊处理请参考文档进行调整  https://www.e-cology.com.cn/sp/doc/docShare/1027709301045985331?tenantKey=t7akvdnf84
// TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源*/

//                    generate = IdGenerator.generate();
//                    rs1.executeSql(sql_log, poolname_ui,generate);
//                    Long uf_CustomFlow_formId = commonDevUtil.getObjId("sync_eas_log");
//                    logger_5e8d517a.error("uf_CustomFlow_formId = " + uf_CustomFlow_formId);
//                    String poolname_5v = CONN_TYPE.workflow.getType();
//                    Long recodId1 = ebFormDataDubboService.addEmptyData(uf_CustomFlow_formId, currentEmployee);// 获取插入的空的建模id
//                    String sql3 = "update e10_common.dbo.sync_eas_log set requestId = '" + reid + "',lcbh = '" + sourceKey + "',kssj='" + kssj + "',jssj='" + jssj + "',sqrq='" + sqrq + "',ccmdd='" + attribute8 + "',gh='" + errandEmpNum + "',name='" + attribute3 + "',sxrgh='" + synergeticNumbers + "' " + ",sxrxm='" + synergeticNames + "',reason='" + reason + "',title='" + title + "',sqbm='" + attribute4 + "',sqdw='" + attribute5 + "',status='" + sta + "',message='" + message + "' where id  =  " + recodId1 + " and delete_type = 0 ";
                    boolean b1 = rs.executeSql(sql3, poolname_ui);
                    logger_5e8d517a.error("rs = " + rs.getExecuteResult());
                    logger_5e8d517a.error("sql3 = " + sql3);
                    logger_5e8d517a.error(String.valueOf("b1:" + b1));
                    logger_5e8d517a.error(String.valueOf(reid + "同步数据到EAS完成"));
                } catch (Exception e) {
                    message = e.getMessage();
                    String poolname_5v = CONN_TYPE.workflow.getType();
                    //generate过长 新id=获取id最大值+1
                    String newIdSql = "SELECT ISNULL((SELECT TOP 1 id FROM e10_common.dbo.sync_eas_log ORDER BY id DESC), 0) + 1 AS id";
                    boolean flag = rs.executeSql(newIdSql, poolname_5v);
                    logger_5e8d517a.error("flag---"+flag);
                    long newId = 0;
                    if (rs.next()) {
                        newId = Long.parseLong(rs.getString("id"));
                    }

                    String sql3 = "insert into e10_common.dbo.sync_eas_log(id,requestId,lcbh,kssj,jssj,sqrq,ccmdd,gh,name,sxrgh,sxrxm,reason,title,sqbm,sqdw,status,message) " + "values(" + newId + ",'" + reid + "','" + sourceKey + "','" + kssj + "','" + jssj + "','" + sqrq + "','" + attribute8 + "','" + errandEmpNum + "','" + attribute3 + "','" + synergeticNumbers + "'" + ",'" + synergeticNames + "','" + reason + "','" + title + "','" + attribute4 + "','" + attribute5 + "','" + sta + "','" + message + "')";
//                    String poolname_5v = CONN_TYPE.workflow.getType();
//                    /* *TODO  检测到insert语句 -> E9插入sql迁移到E10需要特殊处理请参考文档进行调整  https://www.e-cology.com.cn/sp/doc/docShare/1027709301045985331?tenantKey=t7akvdnf84
// TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源*/

//                    generate = IdGenerator.generate();
//                    rs1.executeSql(sql_log, poolname_5v,generate);
//                    Long uf_CustomFlow_formId = commonDevUtil.getObjId("sync_eas_log");
//                    logger_5e8d517a.error("uf_CustomFlow_formId = " + uf_CustomFlow_formId);
//                    String poolname_5v = CONN_TYPE.workflow.getType();
//                    Long recodId2 = ebFormDataDubboService.addEmptyData(uf_CustomFlow_formId, currentEmployee);// 获取插入的空的建模id
//                    String sql3 = "update e10_common.dbo.sync_eas_log set requestId = '" + reid + "',lcbh = '" + sourceKey + "',kssj='" + kssj + "',jssj='" + jssj + "',sqrq='" + sqrq + "',ccmdd='" + attribute8 + "',gh='" + errandEmpNum + "',name='" + attribute3 + "',sxrgh='" + synergeticNumbers + "' " + ",sxrxm='" + synergeticNames + "',reason='" + reason + "',title='" + title + "',sqbm='" + attribute4 + "',sqdw='" + attribute5 + "',status='" + sta + "',message='" + message + "' where id  =  " + recodId2 + " and delete_type = 0 ";
                    boolean b1 = rs.executeSql(sql3, poolname_5v);
                    logger_5e8d517a.error("rs = " + rs.getExecuteResult());
                    logger_5e8d517a.error("sql3 = " + sql3);
                    logger_5e8d517a.error("添加 = " + b1);
                    logger_5e8d517a.error(String.valueOf(reid + "同步数据到EAS异常:" + e.toString()));
                    return  WeaResult.fail(500, reid + "同步数据到EAS异常:" + e.toString(), getResultMapForAction(weaverResultMap, "result", "", request.getRequestManager()));

                }
            } catch (Exception e) {
                logger_5e8d517a.error(String.valueOf(reid + "Exception:" + e.toString()));
                return  WeaResult.fail(500, reid + "Exception:" + e.toString(), getResultMapForAction(weaverResultMap, "result", "", request.getRequestManager()));

                // e.printStackTrace();
            }
            return WeaResult.success(getResultMapForAction(weaverResultMap, "result", Action.SUCCESS, request.getRequestManager()));
        } catch (Exception e) {
            e.printStackTrace();
            logger_5e8d517a.error("ZOA_SL_GNCC_Action e: {}", e.getMessage());
            return  WeaResult.fail(500, "ZOA_SL_GNCC_Action e: {}" + e, getResultMapForAction(weaverResultMap, "result", "", request.getRequestManager()));
        }
    }

    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;
    }

    private static String getForm(String requestid){
        String newform = "";
        if(requestid.length()>8){
            newform = "1"+requestid.substring(requestid.length()-8);
        }
        return newform;
    }
}
