WmsCreateTaskApiService.java
8.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
package com.huaheng.api.sap.service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.huaheng.api.sap.domain.ReceiptQuick;
import com.huaheng.api.sap.domain.ZarDomain;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.BusinessException;
import com.huaheng.common.utils.DataUtils;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.zone.domain.Zone;
import com.huaheng.pc.config.zone.service.ZoneService;
import com.huaheng.pc.sap.domain.Zarsh;
import com.huaheng.pc.sap.domain.Zarsi;
import com.huaheng.pc.sap.service.ZarshService;
import com.huaheng.pc.sap.service.ZarsiService;
@Service
public class WmsCreateTaskApiService {
@Resource
private ZarshService zarshService;
@Resource
private ZarsiService zarsiService;
@Resource
private ZoneService zoneService;
@Resource
private ZarApiService zarApiService;
@Resource
private ContainerService containerService;
/**
* 创建sap下发任务domain
* pda wms的pc页面
* @param receiptQuicks
*/
public AjaxResult createZarshBywms(List<ReceiptQuick> receiptQuicks) {
ZarDomain zarDomain = new ZarDomain();
ReceiptQuick receiptQuick = receiptQuicks.get(0);
String zoneCode = receiptQuick.getZoneCode();
if (StringUtils.isEmpty(zoneCode)) {
zoneCode = ShiroUtils.getZoneCode();
}
// if (StringUtils.isEmpty(zoneCode)) {
// return AjaxResult.error("请选择仓库");
// }
Zone zone = zoneService.getZoneByCode(zoneCode);
Zarsh zarsh = new Zarsh();
zarsh.setUniqueId(DataUtils.createUniqueIdV1());
zarsh.setCreateBy("WMS");
zarsh.setMandt("600");
zarsh.setWerks("SC00");
zarsh.setLgnum(zone.getNickName());
zarsh.setLgort(zone.getUserDef1());
zarsh.setDrumId(receiptQuick.getDrumId());
zarsh.setMFlag("2");
zarsh.setFromPos(receiptQuick.getFromPos());
zarsh.setHFlag(receiptQuick.getHFlag());
zarsh.setRlFlag(receiptQuick.getRlFlag());
zarsh.setInKind(1);
zarsh.setPlType(1);
String splitStr = receiptQuick.getSplitStr();
String rollNumber = receiptQuick.getRollNumber();
if (StringUtils.isEmpty(splitStr) && StringUtils.isEmpty(rollNumber)) {
zarsh.setInKind(0);
}
String containercode = receiptQuick.getDrumId();
if (StringUtils.isNotEmpty(containercode)) {
Container container = containerService.getContainerByCode(containercode, QuantityConstant.WAREHOUSECODE);
if (container != null) {
zarsh.setPlType(container.getPlType());
}
}
AjaxResult zarsiAjax = createZarsiBywms(receiptQuicks, zoneCode, zarsh);
if (zarsiAjax.hasErr()) {
return zarsiAjax;
}
List<Zarsi> zarsiList = (List<Zarsi>)zarsiAjax.getData();
zarDomain.setZarsh(zarsh);
zarDomain.setZarsiList(zarsiList);
return AjaxResult.success().setData(zarDomain);
}
public AjaxResult createZarsiBywms(List<ReceiptQuick> receiptQuicks, String zoneCode, Zarsh zarsh) {
List<Zarsi> list = new ArrayList<>();
for (ReceiptQuick receiptQuick : receiptQuicks) {
String splitStr = receiptQuick.getSplitStr();
String rollNumber = receiptQuick.getRollNumber();
if (StringUtils.isEmpty(splitStr) && StringUtils.isEmpty(rollNumber)) {
continue;
}
Zarsi zarsi = new Zarsi();
zarsi.setMandt(zarsh.getMandt());
zarsi.setWerks(zarsh.getWerks());
zarsi.setLgnum(zarsh.getLgnum());
zarsi.setLgort(zarsh.getLgort());
zarsi.setDrumId(zarsh.getDrumId());
zarsi.setUniqueId(zarsh.getUniqueId());
zarsi.setPosnr(receiptQuick.getPosnr());
if (StringUtils.isNotEmpty(splitStr)) {
// 解析批号、卷号、数量
zarsi = parseMatnr(splitStr, zoneCode, zarsi);
if (zarsi.getVerme().compareTo(new BigDecimal(0)) == 0) {
zarsi.setVerme(new BigDecimal(1));
}
if (zoneCode.equals("F")) {
if (StringUtils.isEmpty(receiptQuick.getLot())) {
return AjaxResult.error("请输入外观批号");
}
zarsi.setCharg(receiptQuick.getLot());
}
} else if (StringUtils.isNotEmpty(rollNumber)) {
// pc端
if (StringUtils.isEmpty(receiptQuick.getMatnr())) {
return AjaxResult.error("请输入物料code");
}
zarsi.setMatnr(receiptQuick.getMatnr());
zarsi.setCharg(receiptQuick.getRollNumber());
zarsi.setVerme(new BigDecimal(1));
if (zoneCode.equals("F")) {
zarsi.setWjffh(receiptQuick.getWjffh());
}
}
list.add(zarsi);
}
return AjaxResult.success().setData(list);
}
public Zarsi parseMatnr(String matnr, String zoneCode, Zarsi zarsi) {
String[] ls = matnr.split(" ");
BigDecimal qtybigdecimal = new BigDecimal(0);
String rollNumber = null;
String materialCode = null;
String wjffh = null;
if (zoneCode.equals("E") || zoneCode.contains("D")) {
if (ls.length < 4) {
throw new BusinessException("物料二维码扫码错误");
}
if (ls.length == 4) {
materialCode = ls[1];
String qty = ls[2];
boolean tag = DataUtils.isDigit(qty);
if (!tag) {
throw new BusinessException("请确认物料二维码数据或站台或用户是否对应");
}
qtybigdecimal = new BigDecimal(qty);
rollNumber = ls[3];
} else {
materialCode = ls[0];
rollNumber = ls[1];
}
} else if (zoneCode.equals("B")) {
if (ls.length < 4) {
throw new BusinessException("物料二维码扫码错误");
}
// 商片仓
materialCode = ls[1];
String qty = ls[2];
boolean tag = DataUtils.isDigit(qty);
if (!tag) {
throw new BusinessException("请确认物料二维码数据或站台或用户是否对应");
}
qtybigdecimal = new BigDecimal(qty);
rollNumber = ls[3];
} else if (zoneCode.contains("C") || zoneCode.contains("A")) {
if (ls.length < 3) {
throw new BusinessException("物料二维码扫码错误");
}
// 铜箔 玻璃布
materialCode = ls[0];
String qty = ls[1];
boolean tag = DataUtils.isDigit(qty);
if (!tag) {
throw new BusinessException("请确认物料二维码数据或站台或用户是否对应");
}
qtybigdecimal = new BigDecimal(qty);
rollNumber = ls[2];
} else if (zoneCode.contains("G")) {
if (ls.length < 3) {
throw new BusinessException("物料二维码扫码错误");
}
// 成品
materialCode = ls[0];
String qty = ls[1];
boolean tag = DataUtils.isDigit(qty);
if (!tag) {
throw new BusinessException("请确认物料二维码数据或站台或用户是否对应");
}
qtybigdecimal = new BigDecimal(qty);
rollNumber = ls[2];
} else if (zoneCode.contains("F")) {
if (ls.length < 6) {
throw new BusinessException("物料二维码扫码错误");
}
// 外观
materialCode = ls[4];
String qty = ls[3];
boolean tag = DataUtils.isDigit(qty);
if (!tag) {
throw new BusinessException("请确认二维码数据或站台或用户是否对应");
}
qtybigdecimal = new BigDecimal(qty);
wjffh = ls[5];
// rollNumber = ls[5];
// rollNumber = ls[0].substring(1, ls[0].length()) + " " + ls[1] + " " + ls[2];
}
zarsi.setMatnr(materialCode);
zarsi.setCharg(rollNumber);
zarsi.setWjffh(wjffh);
zarsi.setVerme(qtybigdecimal.stripTrailingZeros());
return zarsi;
}
}