package com.weaver.seconddev.interfaces.workflow.action;

import com.weaver.common.base.entity.result.WeaResult;
import com.weaver.esb.api.rpc.EsbServerlessRpcRemoteInterface;
import com.weaver.verupgrade.soa.workflow.request.RequestInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: calyrex
 * @CreateTime: 2025-01-13
 * @Description: ZOA_FICO_ANLA_CHECK动作流调用
 */

@org.springframework.stereotype.Service("workflow_action_ZOA_FICO_ANLA_CHECK_ACTION")
@Slf4j
public class ZOA_FICO_ANLA_CHECK_ACTION implements EsbServerlessRpcRemoteInterface {

    @Autowired
    private RequestInfo requestInfoTemp;
    public WeaResult<Map<String, Object>> execute(Map<String, Object> requestInfoMap) {
        log.error("ZOA_FICO_ANLA_CHECK_ACTION execute start");
        log.error("ZOA_FICO_ANLA_CHECK_ACTION execute params : " + requestInfoMap);
        try {
            String gdzcdm = null2String(requestInfoMap.get("gdzcdm")); //固定资产代码
            String gsdm = null2String(requestInfoMap.get("gsdm")); //公司
            String estatus = "E";
            String emessage = "";

            ZOA_FICO_ANLA_CHECK po=new ZOA_FICO_ANLA_CHECK();
            Map<String,String> map = po.Getexecute(gdzcdm , gsdm);
            if(map != null && map.size() > 0) {
                estatus = map.get("estatus");
                emessage = map.get("emessage");
                Map<String, Object> result = new HashMap<>();
                result.put("estatus", estatus);
                result.put("emessage", emessage);
                result.put("TXT50", "<![CDATA["+map.get("TXT50")+"]]>");
                result.put("TXA50", "<![CDATA["+map.get("TXA50")+"]]>");
                result.put("ANLN1", "<![CDATA["+map.get("ANLN1")+"]]>");
                result.put("ANLHTXT", "<![CDATA["+map.get("ANLHTXT")+"]]>");
                result.put("SERNR", "<![CDATA["+map.get("SERNR")+"]]>");
                result.put("INVNR", "<![CDATA["+map.get("INVNR")+"]]>");
                result.put("KOSTL", "<![CDATA["+map.get("KOSTL")+"]]>");
                result.put("KOSTLV", "<![CDATA["+map.get("KOSTLV")+"]]>");
                result.put("CAUFN", "<![CDATA["+map.get("CAUFN")+"]]>");
                result.put("WERKS", "<![CDATA["+map.get("WERKS")+"]]>");
                result.put("RAUMN", "<![CDATA["+map.get("RAUMN")+"]]>");
                result.put("BUKRS", "<![CDATA["+map.get("BUKRS")+"]]>");
                result.put("KTOGR", "<![CDATA["+map.get("KTOGR")+"]]>");
                result.put("MENGE", "<![CDATA["+map.get("MENGE")+"]]>");
                result.put("MEINS", "<![CDATA["+map.get("MEINS")+"]]>");
                result.put("AKTIV", "<![CDATA["+map.get("AKTIV")+"]]>");
                result.put("ZUGDT", "<![CDATA["+map.get("ZUGDT")+"]]>");
                result.put("ZUJHR", "<![CDATA["+map.get("ZUJHR")+"]]>");
                result.put("ZUPER", "<![CDATA["+map.get("ZUPER")+"]]>");
                result.put("DEAKT", "<![CDATA["+map.get("DEAKT")+"]]>");
                result.put("ORD41", "<![CDATA["+map.get("ORD41")+"]]>");
                result.put("ORD42", "<![CDATA["+map.get("ORD42")+"]]>");
                result.put("NDJAR", "<![CDATA["+map.get("NDJAR")+"]]>");
                result.put("NDPER", "<![CDATA["+map.get("NDPER")+"]]>");
                result.put("AFABG", "<![CDATA["+map.get("AFABG")+"]]>");
                result.put("NDABJ", "<![CDATA["+map.get("NDABJ")+"]]>");
                result.put("NDABP", "<![CDATA["+map.get("NDABP")+"]]>");
                result.put("ANLKL", "<![CDATA["+map.get("ANLKL")+"]]>");
                result.put("ANLN2", "<![CDATA["+map.get("ANLN2")+"]]>");
                return WeaResult.success(result);
            }else {
                estatus = map.get("estatus");
                emessage = map.get("emessage");
                Map<String, Object> result = new HashMap<>();
                result.put("estatus", estatus);
                result.put("emessage", emessage);
                return WeaResult.success(result);
            }
        }catch (Exception e){
            log.error("ZOA_FICO_ANLA_CHECK_ACTION execute error : " , e);
            return WeaResult.fail(500, "ZOA_FICO_ANLA_CHECK_ACTION execute error : " , e);
        }
    }

    public static String null2String(String s){
        return s == null ? "" : s;
    }

    public static String null2String(Object o){
        return o == null ? "" : o.toString();
    }

    public static String null2String(String s1,String s2){
        return s1 == null ? (s2 == null ? "" : s2) : s1;
    }
}
