Blame view

src/main/java/com/huaheng/api/utils/SAPUtils.java 4.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package com.huaheng.api.utils;

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;
tongzhonghao authored
18
19
20
    /**
     * 通过SAP仓库编码 获取WMS库区编码
tongzhonghao authored
21
     *
22
23
     * @return
     */
tongzhonghao authored
24
    public static String getZoneCode(Zarsh zarsh) {
25
        return getZoneCode(zarsh.getWerks(), zarsh.getLgort(), zarsh.getLgnum(), zarsh.getCrnIn(), "SAP录入参数错误");
26
27
28
29
    }

    /**
     * 通过SAP仓库编码 获取WMS库区编码
tongzhonghao authored
30
     *
31
32
33
34
35
     * @param werks SAP工厂
     * @param lgort SAP库存地点
     * @param lgnum SAP仓库号
     * @return
     */
tongzhonghao authored
36
37
    public static String getZoneCode(String werks, String lgort, String lgnum) {
        return getZoneCode(werks, lgort, lgnum, "SAP录入参数错误");
38
39
    }
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
    public static String getArea(Zarsh zarsh) {
        return getArea(zarsh.getWerks(), zarsh.getLgort(), zarsh.getLgnum(), "SAP录入参数错误");
    }

    public static String getArea(String werks, String lgort, String lgnum) {
        return getArea(werks, lgort, lgnum, "SAP录入参数错误");
    }

    public static String getArea(String werks, String lgort, String lgnum, String errorMsg) {
        String area = null;
        Map<String, String> map = new HashMap<>();
        map.put("BBC", "1");
        map.put("SP2", "2");
        map.put("TBC", "3");
        map.put("PPC", "4");
        map.put("PLC", "5");
        map.put("WJC", "6");
        map.put("BC2", "7");
        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":
                area = map.get(lgnum);
                break;
            default:
                throw new SecurityException(errorMsg);
        }
        return area;
    }
tongzhonghao authored
77
    public static String getZoneCode(String werks, String lgort, String lgnum, String errorMsg) {
78
79
80
81
        return getZoneCode(werks, lgort, lgnum, null, errorMsg);
    }

    public static String getZoneCode(String werks, String lgort, String lgnum, String crnIn, String errorMsg) {
82
        String zoneCode = null;
tongzhonghao authored
83
84
85
86
87
88
89
90
        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");
91
92
93
94
95
96
97
        map.put("AX", "AX");
        map.put("BX", "BX");
        map.put("CX", "CX");
        map.put("DX", "DX");
        map.put("EX", "EX");
        map.put("FX", "FX");
        map.put("GX", "GX");
tongzhonghao authored
98
        if (StringUtils.isEmpty(werks) || StringUtils.isEmpty(lgort) || StringUtils.isEmpty(lgnum)) {
99
100
            throw new SecurityException(errorMsg);
        }
tongzhonghao authored
101
        if (!"SC00".equals(werks)) {
102
103
            throw new SecurityException(errorMsg);
        }
104
105
106
        if (StringUtils.isNotEmpty(crnIn)) {
            lgnum = crnIn;
        }
tongzhonghao authored
107
        switch (lgort) {
108
109
110
111
            case "SF28":
            case "SC01":
            case "SF22":
            case "SF21":
tongzhonghao authored
112
                zoneCode = map.get(lgnum);
113
114
115
116
117
118
119
                break;
            default:
                throw new SecurityException(errorMsg);
        }
        return zoneCode;
    }
tongzhonghao authored
120
    public static String convertSAPByZoneCode(String zoneCode) {
tongzhonghao authored
121
        String lgort = null;
tongzhonghao authored
122
123
124
        switch (zoneCode) {
            case "A":
            case "C":
tongzhonghao authored
125
126
                lgort = "SF28";
                break;
tongzhonghao authored
127
            case "G":
128
            case "B":
tongzhonghao authored
129
130
                lgort = "SC01";
                break;
tongzhonghao authored
131
            case "D":
tongzhonghao authored
132
            case "E":
tongzhonghao authored
133
                lgort = "SF22";
tongzhonghao authored
134
135
                break;
            case "F":
tongzhonghao authored
136
                lgort = "SF21";
tongzhonghao authored
137
                break;
tongzhonghao authored
138
139
140
        }
        return lgort;
    }
tongzhonghao authored
141
142

    public static String convertSAPByPort(String zoneCode) {
tongzhonghao authored
143
        String port = null;
tongzhonghao authored
144
145
146
147
148
149
150
151
152
        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) {
tongzhonghao authored
153
154
155
156
157
158
159
            case "A":
            case "B":
            case "C":
            case "D":
            case "E":
            case "F":
            case "G":
tongzhonghao authored
160
                port = map.get(zoneCode);
tongzhonghao authored
161
162
163
164
                break;
        }
        return port;
    }
165
}