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

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

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

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

    private static final Logger logger_dc53f02f = LoggerFactory.getLogger(ZOA_FICO_ANLA_CHANGE.class);

    public ZOA_FICO_ANLA_CHANGE() {
        new SAPConn();
        destination = SAPConn.getJCoDestination();
        retstr = null;
    }

    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_dc53f02f.error("ZOA_FICO_ANLA_CHANGE e: {}", e.getMessage());
            return  WeaResult.fail(500, "ZOA_FICO_ANLA_CHANGE e {}"+ e, getResultMapForAction(weaverResultMap, "result",e.getMessage(), requestinfo.getRequestManager()));
        }
    }

    public String[] Getexecute(Map<String, String> map) {
        retstr = new String[3];
        try {
            RecordSetTrans recordsettrans = I18nContextUtil.getBean(RecordSetTrans.class);
            recordsettrans.setAutoCommit(false);
            JCoFunction jcofunction = destination.getRepository().getFunction("ZOA_FICO_ANLA_CHANGE");
            if (jcofunction == null) {
                System.out.println("ZOA_FICO_ANLA_CHANGE not found in SAP.");
                retstr[2] = "ZOA_FICO_ANLA_CHANGE not found in SAP.";
            } else {
                JCoStructure stru = jcofunction.getImportParameterList().getStructure("I_INPUT");
                // 资产描述
                stru.setValue("TXT50", map.get("ZCMSGH"));
                // 附加资产描述
                stru.setValue("TXA50", map.get("FJZCMSGH"));
                // 主资产号
                stru.setValue("ANLN1", map.get("ZCBHXZ"));
                // 资产主号说明
                stru.setValue("ANLHTXT", map.get("ZCBHSMGH"));
                // 序列号
                stru.setValue("SERNR", map.get("XLHGH"));
                // 存货号
                stru.setValue("INVNR", map.get("CHHGH"));
                // 成本中心
                stru.setValue("KOSTL", map.get("SYCBZXGH"));
                // 成本中心对资产负责
                stru.setValue("KOSTLV", map.get("GLCBZXGH"));
                // 内部订单
                stru.setValue("CAUFN", map.get("NBDDGH"));
                // 工厂
                stru.setValue("WERKS", map.get("GCGH"));
                logger_dc53f02f.error(String.valueOf("ZOA_FICO_ANLA_CHANGE--工厂改后：" + map.get("GCGH")));
                // 房间
                stru.setValue("RAUMN", map.get("ZRRGH"));
                // 公司代码
                stru.setValue("BUKR", map.get("GS"));
                jcofunction.getImportParameterList().setValue("I_INPUT", stru);
                try {
                    jcofunction.execute(destination);
                    retstr[0] = jcofunction.getExportParameterList().getValue("E_ISTAT").toString();
                    retstr[1] = jcofunction.getExportParameterList().getValue("E_MESSAGE").toString();
                } catch (Exception exception1) {
                    retstr[2] = exception1.toString();
                }
            }
            return retstr;
        } catch (Exception exception) {
            retstr[2] = exception.getMessage();
        }
        return retstr;
    }

    private JCoDestination destination;

    private String[] retstr;

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