// 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.java
package com.weaver.seconddev.interfaces.workflow.action;

import java.util.HashMap;
import java.util.Map;
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoTable;
import com.weaver.common.i18n.tool.util.I18nContextUtil;
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.RecordSetTrans;
import com.weaver.verupgrade.general.BaseBean;
import com.weaver.verupgrade.interfaces.workflow.action.Action;

// Referenced classes of package weaver.interfaces.workflow.action:
// SAPConn, Action
@org.springframework.stereotype.Service("workflow_action_ZOA_FICO_COC_CHECK")
public class ZOA_FICO_COC_CHECK implements Action, EsbServerlessRpcRemoteInterface {

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

    public static final org.slf4j.Logger logger_6a128882 = LoggerFactory.getLogger(ZOA_FICO_COC_CHECK.class);

    private JCoDestination destination;

    public ZOA_FICO_COC_CHECK() {
        new SAPConn();
        destination = SAPConn.getJCoDestination();
    }

    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 {
            return WeaResult.success(getResultMapForAction(weaverResultMap, "result", "1", requestinfo.getRequestManager()));
        } catch (Exception e) {
            e.printStackTrace();
            logger_6a128882.error("ZOA_FICO_COC_CHECK e: {}", e.getMessage());
            return WeaResult.success(getResultMapForAction(weaverResultMap, "result", WeaResult.fail(500, "执行异常", getResultMapForAction(weaverResultMap, "result", e.getMessage(), requestinfo.getRequestManager())), requestinfo.getRequestManager()));
        }
    }

    public Map<String, String> Getexecute(String cbzxdm) {
        Map<String, String> map = new HashMap<String, String>();
        BaseBean base = new BaseBean();
        map.put("estatus", "E");
        try {
            RecordSetTrans recordsettrans = I18nContextUtil.getBean(RecordSetTrans.class);
            recordsettrans.setAutoCommit(false);
            JCoFunction jcofunction = destination.getRepository().getFunction("ZOA_FICO_COC_CHECK");
            if (jcofunction == null) {
                logger_6a128882.error(String.valueOf("ZOA_FICO_COC_CHECK not found in SAP."));
                map.put("emessage", "ZOA_FICO_COC_CHECK not found in SAP.");
            } else {
                // 成本中心编码
                jcofunction.getImportParameterList().setValue("I_KOSTL", cbzxdm);
                logger_6a128882.error(String.valueOf("ZOA_FICO_COC_CHECK接收KOSTL:" + cbzxdm));
                try {
                    jcofunction.execute(destination);
                    String stat = jcofunction.getExportParameterList().getValue("E_ISTAT").toString();
                    String msg = jcofunction.getExportParameterList().getValue("E_MESSAGE").toString();
                    map.put("estatus", stat);
                    map.put("emessage", msg);
                    if ("S".equals(stat)) {
                        JCoTable localJCoTable1 = jcofunction.getTableParameterList().getTable("E_OUT");
                        if (localJCoTable1.getNumRows() > 0) {
                            localJCoTable1.setRow(1);
                            // 开始生效日期
                            map.put("DATAB", localJCoTable1.getString("DATAB").trim());
                            // 一般姓名
                            map.put("KTEXT", localJCoTable1.getString("KTEXT").trim());
                            // 说明
                            map.put("LTEXT", localJCoTable1.getString("LTEXT").trim());
                            // 负责人
                            map.put("VERAK", localJCoTable1.getString("VERAK").trim());
                            // 成本中心类型
                            map.put("KOSAR", localJCoTable1.getString("KOSAR").trim());
                            // 标准层次结构区域
                            map.put("KHINR", localJCoTable1.getString("KHINR").trim());
                            // 公司代码
                            map.put("BUKRS", localJCoTable1.getString("BUKRS").trim());
                            // 功能范围
                            map.put("FKBER", localJCoTable1.getString("FKBER").trim());
                            // 利润中心
                            map.put("PRCTR", localJCoTable1.getString("PRCTR").trim());
                            // 工厂
                            map.put("ZZWERKS", localJCoTable1.getString("ZZWERKS").trim());
                            // 控制范围
                            map.put("KOKRS", localJCoTable1.getString("KOKRS").trim());
                            // 货币码
                            map.put("WAERS", localJCoTable1.getString("WAERS").trim());
                            // 成本中心
                            map.put("KOSTL", localJCoTable1.getString("KOSTL").trim());
                            // 层次结构
                            map.put("CCNAME", localJCoTable1.getString("CCNAME").trim());
                            // 成本中心类型
                            map.put("CBNAME", localJCoTable1.getString("CBNAME").trim());
                            // 功能范围的名称
                            map.put("GNNAME", localJCoTable1.getString("GNNAME").trim());
                            // 利润中心描述
                            map.put("LRNAME", localJCoTable1.getString("LRNAME").trim());
                            // 工厂描述
                            map.put("GCNAME", localJCoTable1.getString("GCNAME").trim());
                            // 货币描述
                            map.put("HBNAME", localJCoTable1.getString("HBNAME").trim());
                            // 公司描述
                            map.put("GSNAME", localJCoTable1.getString("GSNAME").trim());
                        }
                    }
                } catch (Exception e1) {
                    logger_6a128882.error("error1:" , e1);
                    map.put("emessage", e1.getMessage());
                }
            }
        } catch (Exception e2) {
            logger_6a128882.error("error2:" , e2);
            map.put("emessage", e2.getMessage());

        }
        return map;
    }

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