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 org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

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

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

@org.springframework.stereotype.Service("workflow_action_ZOA_FI_CUSTOMER_MAINTAIN_ACTION")
@Slf4j
public class ZOA_FI_CUSTOMER_MAINTAIN_ACTION implements EsbServerlessRpcRemoteInterface {

    @Autowired
    private RequestInfo requestInfoTemp;
    public WeaResult<Map<String, Object>> execute(Map<String, Object> requestInfoMap) {
        log.error("ZOA_FI_CUSTOMER_MAINTAIN_ACTION execute start");
        log.error("ZOA_FI_CUSTOMER_MAINTAIN_ACTION execute params : " + requestInfoMap);
        try {
            String edit_flag = null2String(requestInfoMap.get("edit_flag")); //动作类型
            String bukrs = null2String(requestInfoMap.get("bukrs")); //公司代码
            String kunnr = null2String(requestInfoMap.get("kunnr")); //客户编号
            String ktokd = null2String(requestInfoMap.get("ktokd")); //科目组
            String anred = null2String(requestInfoMap.get("anred")); //称谓
            String name1 = null2String(requestInfoMap.get("name1")); //名称
            String sortl = null2String(requestInfoMap.get("sortl")); //简称-搜索项
            String telf1 = null2String(requestInfoMap.get("telf1")); //电话
            String smtp_addr = null2String(requestInfoMap.get("smtp_addr")); //邮件
            String telf2 = null2String(requestInfoMap.get("telf2")); //手机
            String telfx = null2String(requestInfoMap.get("telfx")); //传真
            String land1 = null2String(requestInfoMap.get("land1")); //国家
            String regio = null2String(requestInfoMap.get("regio")); //地区
            String spras = null2String(requestInfoMap.get("spras")); //语言
            String ort01 = null2String(requestInfoMap.get("ort01")); //城市
            String stras = null2String(requestInfoMap.get("stras")); //地址
            String pstlz = null2String(requestInfoMap.get("pstlz"));//邮政编号
            String bankl = null2String(requestInfoMap.get("bankl")); //开户行行号
            String banka = null2String(requestInfoMap.get("banka"));//开户行名称
            String banks = null2String(requestInfoMap.get("banks"));//开户行国家
            String koinh = null2String(requestInfoMap.get("koinh")); //开户行账号
            String stcd5 = null2String(requestInfoMap.get("stcd5"));//纳税登记证代码

            String akont = null2String(requestInfoMap.get("akont")); //统驭科目
            String zterm = null2String(requestInfoMap.get("zterm"));//付款条件
            String zuawa = null2String(requestInfoMap.get("zuawa")); //排序码
            String zwels = null2String(requestInfoMap.get("zwels"));//付款方式
            String frgrp = null2String(requestInfoMap.get("frgrp"));//批准组
            String zahls = null2String(requestInfoMap.get("zahls")); //付款冻结



            String estatus = "E";
            String emessage = "";
            String[] prdetail = new String[38];
            prdetail[0] = edit_flag; //动作类型
            prdetail[1] = bukrs; //公司代码
            prdetail[2] = kunnr; //客户编号
            prdetail[3] = ktokd; //科目组
            prdetail[4] = anred; //称谓
            prdetail[5] = name1; //名称
            prdetail[6] = sortl; //简称-搜索项
            prdetail[7] = telf1; //电话
            prdetail[8] = smtp_addr; //邮件
            prdetail[9] = telf2; //手机
            prdetail[10] = telfx; //传真
            prdetail[11] = land1; //国家
            prdetail[12] = regio; //地区
            prdetail[13] = spras; //语言
            prdetail[14] = ort01; //城市
            prdetail[15] = stras; //地址
            prdetail[16] = pstlz;//邮政编号
            prdetail[17] = bankl; //开户行行号
            prdetail[18] = banka;//开户行名称
            prdetail[19] = banks;//开户行国家
            prdetail[20] = koinh; //开户行账号
            prdetail[21] = stcd5;//纳税登记证代码

            prdetail[22] = akont;//统驭科目
            prdetail[23] = zterm;//付款条件
            prdetail[24] = zuawa; //排序码
            prdetail[25] = zwels;//付款方式
            prdetail[26] = frgrp;//批准组

            //付款冻结
            if(zahls.equals("X")){
                prdetail[27] = zahls;
            }else{
                prdetail[27] = "";
            }

            ZOA_FI_CUSTOMER_MAINTAIN po=new ZOA_FI_CUSTOMER_MAINTAIN();
            String[][] fhz = po.Getexecute(prdetail);
            if(fhz[0][0].equals("S")){
                estatus = fhz[0][0];
            }
            emessage = fhz[0][1];
            Map<String,Object> result = new HashMap<>();
            result.put("estatus",estatus);
            result.put("emessage",emessage);
            result.put("kunnr",fhz[1][0]);
            result.put("bukrs",fhz[1][1]);
            result.put("ktokd",fhz[1][2]);
            result.put("txt30",fhz[1][3]);
            result.put("anred",fhz[1][4]);
            result.put("name1",fhz[1][5]);
            result.put("sortl",fhz[1][6]);
            result.put("telf1",fhz[1][7]);
            result.put("smtp_addr",fhz[1][8]);
            result.put("telf2",fhz[1][9]);
            result.put("telfx",fhz[1][10]);
            result.put("land1",fhz[1][11]);
            result.put("landx50",fhz[1][12]);
            result.put("bland",fhz[1][13]);
            result.put("bezei",fhz[1][14]);
            result.put("spras",fhz[1][15]);
            result.put("sptxt",fhz[1][16]);
            result.put("ort01",fhz[1][17]);
            result.put("stras",fhz[1][18]);
            result.put("pstlz",fhz[1][19]);
            result.put("bankl",fhz[1][20]);
            result.put("banka",fhz[1][21]);
            result.put("banks",fhz[1][22]);
            result.put("landx",fhz[1][23]);
            result.put("koinh",fhz[1][24]);
            result.put("stcd5",fhz[1][25]);
            result.put("akont",fhz[1][26]);
            result.put("txt20",fhz[1][27]);
            result.put("zterm",fhz[1][28]);
            result.put("text1",fhz[1][29]);
            result.put("zuawa",fhz[1][30]);
            result.put("ttext",fhz[1][31]);
            result.put("zwels",fhz[1][32]);
            result.put("text2",fhz[1][33]);
            result.put("frgrp",fhz[1][34]);
            result.put("frgrt",fhz[1][35]);
            result.put("zahls",fhz[1][36]);
            return WeaResult.success(result);
        }catch (Exception e){
            log.error("ZOA_FI_CUSTOMER_MAINTAIN_ACTION execute error : " ,e);
            return WeaResult.fail(500, "ZOA_FI_CUSTOMER_MAINTAIN_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;
    }
}
