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_COC_CHECK动作流调用
 */

@org.springframework.stereotype.Service("workflow_action_ZOA_FICO_COC_CHECK_ACTION")
@Slf4j
public class ZOA_FICO_COC_CHECK_ACTION implements EsbServerlessRpcRemoteInterface {

    @Autowired
    private RequestInfo requestInfoTemp;
    @Override
    public WeaResult<Map<String, Object>> execute(Map<String, Object> requestInfoMap) {
        log.error("ZOA_FICO_COC_CHECK_ACTION execute start");
        log.error("ZOA_FICO_COC_CHECK_ACTION execute params : " + requestInfoMap);
        try {
            String cbzxdm = null2String(requestInfoMap.get("cbzxdm")); //成本中心代码

            String estatus = "E";
            String emessage = "";

            ZOA_FICO_COC_CHECK po=new ZOA_FICO_COC_CHECK();
            Map<String,String> map = po.Getexecute(cbzxdm);
            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("DATAB",null2String(map.get("DATAB")));
                result.put("KTEXT",null2String(map.get("KTEXT")));
                result.put("LTEXT",null2String(map.get("LTEXT")));
                result.put("VERAK",null2String(map.get("VERAK")));
                result.put("KOSAR",null2String(map.get("KOSAR")));
                result.put("KHINR",null2String(map.get("KHINR")));
                result.put("BUKRS",null2String(map.get("BUKRS")));
                result.put("FKBER",null2String(map.get("FKBER")));
                result.put("WAERS",null2String(map.get("WAERS")));
                result.put("PRCTR",null2String(map.get("PRCTR")));
                result.put("ZZWERKS",null2String(map.get("ZZWERKS")));
                result.put("KOKRS",null2String(map.get("KOKRS")));
                result.put("KOSTL",null2String(map.get("KOSTL")));
                result.put("CCNAME",null2String(map.get("CCNAME")));
                result.put("CBNAME",null2String(map.get("CBNAME")));
                result.put("LRNAME",null2String(map.get("LRNAME")));
                result.put("GCNAME",null2String(map.get("GCNAME")));
                result.put("HBNAME",null2String(map.get("HBNAME")));
                result.put("GSNAME",null2String(map.get("GSNAME")));
                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_COC_CHECK_ACTION execute error : " , e);
            return WeaResult.fail(500, "ZOA_FICO_COC_CHECK_ACTION execute error : "+e , 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;
    }

}
