SAPUtils.java 3.78 KB
package com.huaheng.api.utils;

import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.pc.sap.domain.Zarsh;
import com.huaheng.pc.sap.service.ZarshService;
import com.huaheng.pc.sap.service.ZarsiService;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

public class SAPUtils {

    @Resource
    private ZarshService zarshService;
    @Resource
    private ZarsiService zarsiService;

    /**
     * 通过SAP仓库编码 获取WMS库区编码
     *
     * @param werks SAP工厂
     * @param lgort SAP库存地点
     * @param lgnum SAP仓库号
     * @return
     */
    public static void checkSAPArea(String werks, String lgort, String lgnum) {
        String zoneCodeBySAP = getZoneCode(werks, lgort, lgnum);
        if (StringUtils.isEmpty(zoneCodeBySAP)) {
            throw new ServiceException("未找到对应库区 参数[" + werks + "," + lgort + "," + lgnum + "]");
        }

    }

    /**
     * 通过SAP仓库编码 获取WMS库区编码
     *
     * @return
     */
    public static String getZoneCode(Zarsh zarsh) {
        return getZoneCode(zarsh.getWerks(), zarsh.getLgort(), zarsh.getLgnum(), "SAP录入参数错误");
    }

    /**
     * 通过SAP仓库编码 获取WMS库区编码
     *
     * @param werks SAP工厂
     * @param lgort SAP库存地点
     * @param lgnum SAP仓库号
     * @return
     */
    public static String getZoneCode(String werks, String lgort, String lgnum) {
        return getZoneCode(werks, lgort, lgnum, "SAP录入参数错误");
    }

    public static String getZoneCode(String werks, String lgort, String lgnum, String errorMsg) {
        String zoneCode = null;
        Map<String, String> map = new HashMap<>();
        map.put("BBC", "A");
        map.put("SP2", "B");
        map.put("TBC", "C");
        map.put("PPC", "D");
        map.put("PLC", "E");
        map.put("WJC", "F");
        map.put("BC2", "G");
        if (StringUtils.isEmpty(werks) || StringUtils.isEmpty(lgort) || StringUtils.isEmpty(lgnum)) {
            throw new SecurityException(errorMsg);
        }
        if (!"SC00".equals(werks)) {
            throw new SecurityException(errorMsg);
        }
        switch (lgort) {
            case "SF28":
            case "SC01":
            case "SF22":
            case "SF21":
                zoneCode = map.get(lgnum);
                break;
            default:
                throw new SecurityException(errorMsg);
        }
        return zoneCode;
    }

    public static void checkTaskType(Zarsh zarsh) {

    }

    public static String checkTaskType(String mFlag) {
        return null;
    }

    public static String convertSAPByZoneCode(String zoneCode) {
        String lgort = null;
        switch (zoneCode) {
            case "A":
            case "C":
                lgort = "SF28";
                break;
            case "G":
            case "B":
                lgort = "SC01";
                break;
            case "D":
            case "E":
                lgort = "SF22";
                break;
            case "F":
                lgort = "SF21";
                break;
        }
        return lgort;
    }

    public static String convertSAPByPort(String zoneCode) {
        String port = null;
        Map<String, String> map = new HashMap<>();
        map.put("A", "BBC");
        map.put("B", "SP2");
        map.put("C", "TBC");
        map.put("D", "PPC");
        map.put("E", "PLC");
        map.put("F", "WJC");
        map.put("G", "BC2");
        switch (zoneCode) {
            case "A":
            case "B":
            case "C":
            case "D":
            case "E":
            case "F":
            case "G":
                port = map.get(zoneCode);
                break;
        }
        return port;
    }
}