// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
// Source File Name:   ZOA_MM_PR_CREATE_BpAction.java
package com.weaver.seconddev.interfaces.workflow.action;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import  com.weaver.seconddev.interfaces.oames.ReturnMesWLPS_SYService;
import  com.weaver.seconddev.interfaces.oames.SI_OA_HTOAApproFlowSync_OUTServiceStub.ArrayOfWLPS_SY_Main;
import  com.weaver.seconddev.interfaces.oames.SI_OA_HTOAApproFlowSync_OUTServiceStub.WLPS_SY_Main;
import  com.weaver.seconddev.interfaces.oames.SI_OA_HTOAApproFlowSync_OUTServiceStub.WLPS_SY_Request;
import  com.weaver.seconddev.interfaces.swfa.BillFieldUtil;
import com.weaver.common.i18n.tool.util.I18nContextUtil;
import com.weaver.verupgrade.conn.CONN_TYPE;
import java.lang.*;
import java.util.*;
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 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;

// Referenced classes of package  com.weaver.seconddev.interfaces.workflow.action:
// ZOA_MM_PR_CREATE, Action
@org.springframework.stereotype.Service("workflow_action_SY_WLPS_RETURNNewAction")
public class SY_WLPS_RETURNNewAction extends BaseBean implements Action, EsbServerlessRpcRemoteInterface {

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

    @Autowired
    private ReturnMesWLPS_SYService service;
    private static final Logger logger_4dd7c639 = LoggerFactory.getLogger(SY_WLPS_RETURNNewAction.class);

    public SY_WLPS_RETURNNewAction() {
    }

    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 {
            String requestId = requestinfo.getRequestid();
            logger_4dd7c639.error(String.valueOf("SY_WLPS_RETURNAction--" + requestId + "开始执行"));
            // 工作流ID
            String workFlowId = requestinfo.getWorkflowid();
            BillFieldUtil util = new BillFieldUtil();
//            String tablename = util.getTablename(workFlowId);
            String tablename = requestinfo.getRequestManager().getBillTableName();
            try {
                String requestName = requestinfo.getRequestManager().getRequestname();
                String creatorId = requestinfo.getCreatorid();
                Map<String, String> map = new HashMap<String, String>();
                Property[] aproperty = requestinfo.getMainTableInfo().getProperty();
                for (int j = 0; j < aproperty.length; j++) {
                    String name = aproperty[j].getName().toUpperCase();
                    String value = Util.null2String(aproperty[j].getValue());
                    map.put(name, value);
                }
                ResourceComInfo rsCom = I18nContextUtil.getBean(ResourceComInfo.class);
                String fxzt = map.get("FXZT");
                String zzpdjg = map.get("ZZPDJG");
                String sysid = map.get("SYSID");
                String uuid = UUID.randomUUID().toString();
//                ReturnMesWLPS_SYService service = new ReturnMesWLPS_SYService();
                WLPS_SY_Request req = new WLPS_SY_Request();
                ArrayOfWLPS_SY_Main mainData = new ArrayOfWLPS_SY_Main();
                WLPS_SY_Main param = new WLPS_SY_Main();
                param.setZzpdjg(zzpdjg);
                param.setWorkflowid(workFlowId);
                param.setFxzt(fxzt);
                param.setRequestName(requestName);
                param.setRequestid(requestId);
                param.setCreator(rsCom.getWorkcode(creatorId));
                mainData.addWLPS_SY_Main(param);
                req.setSYSID(sysid);
                req.setSENDID(uuid);
                req.setITFID("HT01ETS009");
                req.setDATAS(mainData);
                String[] ret = service.returnRes(req);
                if ("E".equals(ret[0])) {
                    RecordSet rs = I18nContextUtil.getBean(RecordSet.class);
                    String sql = "update e10_core_business.dbo." + tablename + " set state='" + ret[0] + "',message='" + ret[1] + "' where id=" + requestId;
                    logger_4dd7c639.error("sql--" + sql);
                    String poolname_2y = CONN_TYPE.workflow.getType();
                    // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
                    boolean b = rs.executeSql(sql, poolname_2y);
                    logger_4dd7c639.error("b -----"+ b);
                    return  WeaResult.fail(500, "SY_WLPS_RETURNNewAction ret[0]"+ret[0], getResultMapForAction(weaverResultMap, "result",ret[0], requestinfo.getRequestManager()));
                }else if ("S".equals(ret[0])) {
                    RecordSet rs = I18nContextUtil.getBean(RecordSet.class);
                    String sql = "update e10_core_business.dbo." + tablename + " set state='" + ret[0] + "',message='" + ret[1] + "' where id=" + requestId;
                    logger_4dd7c639.error("sql--" + sql);
                    String poolname_2y = CONN_TYPE.workflow.getType();
                    // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
                    boolean b = rs.executeSql(sql, poolname_2y);
                    logger_4dd7c639.error("c -----"+ b);
                }
                logger_4dd7c639.error(String.valueOf("SY_WLPS_RETURNAction--" + requestId + "state"+ret[0]+",ret"+ Arrays.toString(ret)));
                logger_4dd7c639.error(String.valueOf("SY_WLPS_RETURNAction--" + requestId + "执行结束"));
            } catch (Exception exception) {
                logger_4dd7c639.error(String.valueOf("SY_WLPS_RETURNAction--" + requestId + "执行出错：" + exception.getMessage()));
                RecordSet rs = I18nContextUtil.getBean(RecordSet.class);
                String sql = "update e10_core_business.dbo." + tablename + " set state='E',message='" + exception.getMessage() + "' where id=" + requestId;
                logger_4dd7c639.error("sql--" + sql);
                String poolname = CONN_TYPE.workflow.getType();
                // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
                boolean b = rs.executeSql(sql, poolname);
                logger_4dd7c639.error("b -----"+ b);
                return  WeaResult.fail(500, "SY_WLPS_RETURNNewAction e {}"+exception, getResultMapForAction(weaverResultMap, "result",exception.getMessage(), requestinfo.getRequestManager()));
            }
            return WeaResult.success(getResultMapForAction(weaverResultMap, "result", Action.SUCCESS, requestinfo.getRequestManager()));
        } catch (Exception e) {
            e.printStackTrace();
            logger_4dd7c639.error("SY_WLPS_RETURNNewAction e: {}", e.getMessage());
            return  WeaResult.fail(500, "SY_WLPS_RETURNNewAction e {}"+ e, getResultMapForAction(weaverResultMap, "result",e.getMessage(), requestinfo.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;
    }
}
