// 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.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import  com.weaver.seconddev.interfaces.workflow.entity.GeneralEntity;
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoStructure;
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  com.weaver.seconddev.interfaces.workflow.action:
// SAPConn, Action
@org.springframework.stereotype.Service("workflow_action_ZOA_MM_PR_RELEASE")
public class ZOA_MM_PR_RELEASE implements Action, EsbServerlessRpcRemoteInterface {

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

    private static final Logger logger_6bd19017 = LoggerFactory.getLogger(ZOA_MM_PR_RELEASE.class);

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

    public Map<String, Object> Getexecute(String no, List<String> list) {
        BaseBean baseBean = new BaseBean();
        Map<String, Object> map = new HashMap<String, Object>();
        // 存放每一个采购申请单号和返回的状态
        List<GeneralEntity> list2 = new ArrayList<GeneralEntity>();
        try {
            RecordSetTrans recordsettrans = I18nContextUtil.getBean(RecordSetTrans.class);
            recordsettrans.setAutoCommit(false);
            JCoFunction jcofunction = destination.getRepository().getFunction("ZOA_MM_PR_RELEASE");
            if (jcofunction == null) {
                logger_6bd19017.error(String.valueOf("ZOA_MM_PR_RELEASE not found in SAP."));
                map.put("msg", "ZOA_MM_PR_RELEASE not found in SAP.");
            } else {
                JCoStructure stru = jcofunction.getImportParameterList().getStructure("IN");
                stru.setValue("PR_GRPNO", no);
                stru.setValue("STATUS", "A");
                jcofunction.getImportParameterList().setValue("IN", stru);
                if (list != null && list.size() > 0) {
                    logger_6bd19017.error(String.valueOf("ZOA_MM_PR_RELEASE ----- list的个数(" + list.size() + ")"));
                    JCoTable jcotable = jcofunction.getTableParameterList().getTable("DATA");
                    for (int i = 0; i < list.size(); i++) {
                        jcotable.appendRow();
                        jcotable.setValue("BANFN", list.get(i));
                    }
                }
                jcofunction.execute(destination);
                JCoStructure outData = jcofunction.getExportParameterList().getStructure("OUT");
                map.put("E_STATUS", outData.getString("E_STATUS"));
                map.put("E_MESSAGE", outData.getString("E_MESSAGE"));
                logger_6bd19017.error("ZOA_MM_PR_RELEASE ----- E_STATUS(" + outData.getString("E_STATUS") + ")-----E_MESSAGE(" + outData.getString("E_MESSAGE") + ")");
                JCoTable jcotable1 = jcofunction.getTableParameterList().getTable("DATA");
                for (int i = 0; i < list.size(); i++) {
                    jcotable1.setRow(i);
                    String cgdh = jcotable1.getString("BANFN");
                    String status = jcotable1.getString("E_STATUS");
                    String msg = jcotable1.getString("E_MESSAGE");
                    GeneralEntity entity = new GeneralEntity();
                    entity.setExt01(cgdh);
                    entity.setExt02(status);
                    entity.setExt03(msg);
                    list2.add(entity);
                }
                map.put("mx", list2);
                map.put("msg", "ok");
            }
        } catch (Exception e) {
            logger_6bd19017.error(String.valueOf("error:" + e.getMessage()));
            map.put("msg", e.getMessage());
        }
        return map;
    }

    private JCoDestination destination;

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