Blame view

src/main/java/com/huaheng/api/utils/SAPUtils.java 6.67 KB
1
2
package com.huaheng.api.utils;
3
import java.util.ArrayList;
周鸿 authored
4
import java.util.HashMap;
5
import java.util.List;
周鸿 authored
6
7
8
9
import java.util.Map;

import javax.annotation.Resource;
10
import com.huaheng.common.utils.StringUtils;
11
import com.huaheng.pc.sap.domain.*;
12
13
14
15
16
17
18
19
20
import com.huaheng.pc.sap.service.ZarshService;
import com.huaheng.pc.sap.service.ZarsiService;

public class SAPUtils {

    @Resource
    private ZarshService zarshService;
    @Resource
    private ZarsiService zarsiService;
tongzhonghao authored
21
22
23
    /**
     * 通过SAP仓库编码 获取WMS库区编码
24
25
     * @return
     */
tongzhonghao authored
26
    public static String getZoneCode(Zarsh zarsh) {
27
        return getZoneCode(zarsh.getWerks(), zarsh.getLgort(), zarsh.getLgnum(), zarsh.getCrnIn(), "SAP录入参数错误");
28
29
30
31
    }

    /**
     * 通过SAP仓库编码 获取WMS库区编码
周鸿 authored
32
33
34
     * @param  werks SAP工厂
     * @param  lgort SAP库存地点
     * @param  lgnum SAP仓库号
35
36
     * @return
     */
tongzhonghao authored
37
38
    public static String getZoneCode(String werks, String lgort, String lgnum) {
        return getZoneCode(werks, lgort, lgnum, "SAP录入参数错误");
39
40
    }
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
    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");
59
        map.put("XBK", "4");
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
        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
79
    public static String getZoneCode(String werks, String lgort, String lgnum, String errorMsg) {
80
81
82
83
        return getZoneCode(werks, lgort, lgnum, null, errorMsg);
    }

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

    public static String convertSAPByPort(String zoneCode) {
tongzhonghao authored
142
        String port = null;
tongzhonghao authored
143
144
        Map<String, String> map = new HashMap<>();
        map.put("A", "BBC");
周鸿 authored
145
        map.put("AX", "BBC");
tongzhonghao authored
146
147
        map.put("B", "SP2");
        map.put("C", "TBC");
周鸿 authored
148
        map.put("CX", "TBC");
tongzhonghao authored
149
        map.put("D", "PPC");
周鸿 authored
150
        map.put("DX", "PPC");
tongzhonghao authored
151
152
153
154
        map.put("E", "PLC");
        map.put("F", "WJC");
        map.put("G", "BC2");
        switch (zoneCode) {
tongzhonghao authored
155
156
157
158
159
160
161
            case "A":
            case "B":
            case "C":
            case "D":
            case "E":
            case "F":
            case "G":
周鸿 authored
162
163
164
            case "AX":
            case "CX":
            case "DX":
tongzhonghao authored
165
                port = map.get(zoneCode);
tongzhonghao authored
166
167
168
169
                break;
        }
        return port;
    }
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205

    public static Piarsh createPiarshData(SapReceiptData receiptData, List<SapReceiptDetailData> receiptDetails){
        Piarsh piarsh = new Piarsh();
        //托盘号
        piarsh.setDrumid(receiptData.getDrumId());
        //托架类型1->片状托架,0->卷状托架,2->特殊托架
        piarsh.setPltype(receiptData.getPlType().toString());
        //立库号/倉別(AS)
        piarsh.setWh(receiptData.getLgnum());
        //入库起点
        piarsh.setFrompos(receiptData.getFromPos());
        //出库起点
        piarsh.setTopos(receiptData.getToPos());
        //入库动作    动作标志(1->紧急出库,2-入库,3->出库,B->紧急入库)
        piarsh.setMflag(receiptData.getMFlag());
        //指定入库区
//        piarsh.setCrnin();
        //执行预命令
//        piarsh.setRunflag1();
        //执行命令
//        piarsh.setRunflag2();
        //成品仓的方向标签 R/L R右 L左
//        piarsh.setRlflag();
        //配料仓的高度   0/1 0低 1高
//        piarsh.setHflag();
        List<Piarsi> piarsis = new ArrayList<>();
        for (SapReceiptDetailData receiptDetail : receiptDetails) {
            Piarsi piarsi = new Piarsi();
            piarsi.setMandt("600");
            piarsi.setWerks(receiptDetail.getWerks());
            piarsi.setLgort(receiptDetail.getLgort());
            piarsi.setLgnum(receiptDetail.getLgnum());
            piarsi.setDrum_id(receiptDetail.getDrumId());
            piarsi.setMatnr(receiptDetail.getMatnr());
            piarsi.setCharg(receiptDetail.getCharg());
            piarsi.setVerme(receiptDetail.getVerme().toString());
206
            piarsi.setPosnr(Integer.valueOf(receiptDetail.getErrmsg()));
207
208
209
210
211
            piarsis.add(piarsi);
        }
        piarsh.setPiarsi(piarsis);
        return piarsh;
    }
212
}