// 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 com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoFunction;
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.Map;
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_ZITF_OA_DELETE")
public class ZITF_OA_DELETE implements Action, EsbServerlessRpcRemoteInterface {

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

    private static final Logger logger_89fa22b9 = LoggerFactory.getLogger(ZITF_OA_DELETE.class);

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

    /**
     * @param guid
     * @param sqlx 申请类型
     * @param hh 行号
     * @return
     */
    public String[] Getexecute(String guid, String sqlx, String hh) {
        logger_89fa22b9.error("ZITF_OA_DELETE Getexecute start");
        retstr = new String[2];
        String functionName = "";
        if ("0".equals(sqlx)) {
            functionName = "ZITF_OA_DELETE";
        } else if ("1".equals(sqlx)) {
            functionName = "ZITF_OA_262TOZ64";
        } else if ("2".equals(sqlx)) {
            functionName = "ZITF_OA_DELETE_ITEM";
        } else if ("3".equals(sqlx)) {
            functionName = "ZITF_OA_SO_DELETE";
        }
        try {
            RecordSetTrans recordsettrans = I18nContextUtil.getBean(RecordSetTrans.class);
            BaseBean base = new BaseBean();
            recordsettrans.setAutoCommit(false);
            JCoFunction jcofunction = destination.getRepository().getFunction(functionName);
            if (jcofunction == null) {
                logger_89fa22b9.error(String.valueOf(functionName + " not found in SAP."));
                retstr[0] = "E";
                retstr[1] = functionName + " not found in SAP.";
            } else {
                if (!"0".equals(sqlx)) {
                    jcofunction.getImportParameterList().setValue("GUID", guid);
                    if ("2".equals(sqlx)) {
                        jcofunction.getImportParameterList().setValue("ZMESLN", hh);
                    }
                    logger_89fa22b9.error(String.valueOf(functionName + "接收guid:" + guid));
                    try {
                        jcofunction.execute(destination);
                        retstr[0] = jcofunction.getExportParameterList().getValue("ISTAT").toString();
                        retstr[1] = jcofunction.getExportParameterList().getValue("MESSAGE").toString();
                        logger_89fa22b9.error(String.valueOf(functionName + "执行success,得到返回值 [ISTAT=" + retstr[0] + "][MESSAGE=" + retstr[1] + "]"));
                    } catch (Exception exception1) {
                        retstr[0] = "E";
                        retstr[1] = exception1.getMessage();
                    }
                } else {
                    String[] str = guid.split(";");
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < str.length; i++) {
                        jcofunction.getImportParameterList().clear();
                        jcofunction.getImportParameterList().setValue("GUID", str[i]);
                        logger_89fa22b9.error(String.valueOf(functionName + "接收guid:" + str[i]));
                        String status = "";
                        String message = "";
                        try {
                            jcofunction.execute(destination);
                            status = jcofunction.getExportParameterList().getValue("ISTAT").toString();
                            message = jcofunction.getExportParameterList().getValue("MESSAGE").toString();
                            logger_89fa22b9.error(String.valueOf(functionName + "执行success,得到返回值 [ISTAT=" + status + "][MESSAGE=" + message + "]"));
                            if ("E".equals(status)) {
                                sb.append(str[i] + "--" + message + "；");
                            }
                        } catch (Exception exception2) {
                            retstr[0] = "E";
                            retstr[1] = exception2.getMessage();
                            return retstr;
                        }
                    }
                    retstr[0] = sb.length() > 0 ? "E" : "S";
                    retstr[1] = sb.length() > 0 ? sb.toString() : "标记删除成功";
                }
            }

            return retstr;
        } catch (Exception exception) {
            retstr[0] = "E";
            retstr[1] = 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;
    }
}
