// 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 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 com.weaver.verupgrade.conn.CONN_TYPE;
import java.lang.*;
import java.util.*;

import com.weaver.verupgrade.conn.RecordSetTrans;
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.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_ZOA_FICO_ANLA_CHANGEAction")
public class ZOA_FICO_ANLA_CHANGEAction extends BaseBean implements Action, EsbServerlessRpcRemoteInterface {

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

    private static final Logger logger_14793b45 = LoggerFactory.getLogger(ZOA_FICO_ANLA_CHANGEAction.class);

    public ZOA_FICO_ANLA_CHANGEAction() {
    }

    public WeaResult<Map<String, Object>> execute(Map<String, Object> requestInfoMap) {
        logger_14793b45.error("ZOA_FICO_ANLA_CHANGEAction start");
        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 {
            try {
                String requestId = requestinfo.getRequestid();
                String tablename = requestinfo.getRequestManager().getBillTableName();
                Map<String, String> map = new HashMap<String, String>();
                RecordSet rs = I18nContextUtil.getBean(RecordSet.class);
                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);
                    if ("GCGH".equals(name)) {
                        logger_14793b45.error(String.valueOf("ZOA_FICO_ANLA_CHANGEAction--工厂改后" + value));
                    }
                }
                String[] returnStr = Getexecute(map);
                if (returnStr != null && returnStr.length > 0) {
                    String e_istat = String.valueOf(returnStr[0]);
                    String e_message = String.valueOf(returnStr[1]);
                    if ("S".equals(e_istat)) {
                        String sql = "update e10_core_business.dbo." + tablename + " set sta ='" + e_istat + "', meg = '" + e_message + "' where id = " + requestId;
                        String poolname = CONN_TYPE.workflow.getType();
                        // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
                        boolean b = rs.executeSql(sql, poolname);
                        logger_14793b45.error("b--"+b);
                    } else {
                        requestinfo.getRequestManager().setMessageid(e_istat);
                        requestinfo.getRequestManager().setMessagecontent(e_message);
                        return  WeaResult.fail(500, "ZOA_FICO_ANLA_CHANGEAction e_message"+ e_message, getResultMapForAction(weaverResultMap, "result",e_message, requestinfo.getRequestManager()));
                    }
                } else {
                    requestinfo.getRequestManager().setMessageid("ERROR");
                    requestinfo.getRequestManager().setMessagecontent("调用接口返回信息为空");
                    return  WeaResult.fail(500, "调用接口返回信息为空" , getResultMapForAction(weaverResultMap, "result","调用接口返回信息为空", requestinfo.getRequestManager()));
                }
            } catch (Exception exception) {
                logger_14793b45.error(String.valueOf("ZOA_FICO_ANLA_CHANGEAction error:" + exception.getMessage()));
                requestinfo.getRequestManager().setMessageid("ERROR");
                requestinfo.getRequestManager().setMessagecontent(exception.getMessage());
                return  WeaResult.fail(500, "ZOA_FICO_ANLA_CHANGEAction err"+ exception, getResultMapForAction(weaverResultMap, "result",exception.getMessage(), requestinfo.getRequestManager()));
            }
            return WeaResult.success(getResultMapForAction(weaverResultMap, "result", Action.SUCCESS, requestinfo.getRequestManager()));
        } catch (Exception e) {
            e.printStackTrace();
            logger_14793b45.error("ZOA_FICO_ANLA_CHANGEAction e: {}", e.getMessage());
            return  WeaResult.fail(500, "ZOA_FICO_ANLA_CHANGEAction 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;
    }

    public String[] Getexecute(Map<String, String> map) {
        String[] retstr = new String[3];
        JCoDestination destination = SAPConn.getJCoDestination();;
        try {
            logger_14793b45.error("map--" + map);
            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("GS"));
                logger_14793b45.error(String.valueOf("ZOA_FICO_ANLA_CHANGE--工厂改后：" + map.get("GS")));
                // 房间
                stru.setValue("RAUMN", map.get("ZRRGH"));
                // 公司代码
                stru.setValue("BUKR", map.get("GS"));
                jcofunction.getImportParameterList().setValue("I_INPUT", stru);
                try {
                    jcofunction.execute(destination);
                    logger_14793b45.error("ZOA_FICO_ANLA_CHANGE--返回值：" + jcofunction.getExportParameterList().getValue("E_ISTAT").toString());
                    logger_14793b45.error("ZOA_FICO_ANLA_CHANGE--返回值：" + jcofunction.getExportParameterList().getValue("E_MESSAGE").toString());
                    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;
    }
}
