|
1
2
3
4
|
package com.huaheng.api.general.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
5
|
import com.huaheng.common.utils.Wrappers;
|
|
6
|
import com.huaheng.api.erp.service.TaskReturnService;
|
|
7
8
9
|
import com.huaheng.api.general.domain.BarCodeDomain;
import com.huaheng.api.wcs.service.taskInfo.TaskInfoService;
import com.huaheng.common.constant.QuantityConstant;
|
|
10
|
import com.huaheng.common.constant.Res;
|
|
11
|
import com.huaheng.common.exception.BusinessException;
|
|
12
|
import com.huaheng.common.exception.service.ServiceException;
|
|
13
|
import com.huaheng.common.utils.DateUtils;
|
|
14
15
|
import com.huaheng.common.utils.bean.BeanUtils;
import com.huaheng.common.utils.security.ShiroUtils;
|
|
16
|
import com.huaheng.common.utils.spring.SpringUtils;
|
|
17
18
19
20
21
22
23
24
|
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.barcode.barcodeDetail.domain.BarCodeDetail;
import com.huaheng.pc.barcode.barcodeDetail.service.BarCodeDetailService;
import com.huaheng.pc.barcode.barcodeHeader.domain.BarCodeHeader;
import com.huaheng.pc.barcode.barcodeHeader.service.BarCodeHeaderService;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.config.station.domain.Station;
|
|
25
26
27
28
|
import com.huaheng.pc.receipt.receiptContainerHeader.service.ReceiptContainerHeaderService;
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
|
|
29
30
31
32
33
34
35
36
37
|
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.ReceiptTaskService;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
|
|
38
|
import java.math.BigDecimal;
|
|
39
|
import java.util.*;
|
|
40
41
42
43
44
45
46
47
48
49
50
|
@Component
@Transactional
public class BarCodeApiService {
@Resource
private BarCodeHeaderService barCodeHeaderService;
@Resource
private MaterialService materialService;
@Resource
private BarCodeDetailService barCodeDetailService;
@Resource
|
|
51
|
private ReceiptHeaderService receiptHeaderService;
|
|
52
|
@Resource
|
|
53
|
private ReceiptContainerHeaderService receiptContainerHeaderService;
|
|
54
55
|
|
|
56
|
@Transactional(rollbackFor = Exception.class)
|
|
57
|
public AjaxResult addBarCodeApi(BarCodeDomain barCodeDomain){
|
|
58
59
60
61
62
|
AjaxResult ajaxResult = checkBarCode(barCodeDomain);
if (ajaxResult.getCode()!=200) {
return AjaxResult.error(ajaxResult.getMsg());
}
|
|
63
|
boolean result;
|
|
64
|
BarCodeHeader header = barCodeDomain.getBarCodeHeader();
|
|
65
|
BarCodeHeader barCodeHeader = new BarCodeHeader();
|
|
66
67
68
69
70
71
72
73
|
BarCodeDetail codeDetail = barCodeDomain.getBarCodeDetails().get(0);
if (codeDetail != null) {
Material material = materialService.getOne(new LambdaQueryWrapper<Material>().eq(Material::getCode,codeDetail.getMaterialCode()));
barCodeHeader.setMaterialCode(material.getCode());
barCodeHeader.setMaterialName(material.getName());
barCodeHeader.setMaterialUnit(material.getUnit());
barCodeHeader.setMaterialSpec(material.getSpec());
}
|
|
74
|
barCodeHeader.setTotalWeight(codeDetail.getWeight());
|
|
75
|
barCodeHeader.setLocked(QuantityConstant.BARCODEHEADER_LOCKED_DEFAULT);
|
|
76
77
|
barCodeHeader.setCode(barCodeHeaderService.createCode("BZXXRK"));
barCodeHeader.setMaterialBatch(header.getMaterialBatch());
|
|
78
79
80
|
barCodeHeader.setReceiptType("BZXXRK");
barCodeHeader.setWarehouseCode(QuantityConstant.DEFAULT_WAREHOUSE);
barCodeHeader.setCompanyCode(QuantityConstant.DEFAULT_COMPANYCODE);
|
|
81
82
|
if(header.getFbillno() == null || "".equals(header.getFbillno())){
//生产订单号为空就不回传ERP
|
|
83
|
barCodeHeader.setFbillno("MES自建");
|
|
84
85
86
|
}else{
barCodeHeader.setFbillno(header.getFbillno());
}
|
|
87
88
89
90
91
|
if(header.getEchelon()==null){
barCodeHeader.setProType("2");//拆解
}else {
barCodeHeader.setProType("1");//装配
}
|
|
92
|
barCodeHeader.setCreatedBy(QuantityConstant.PLATFORM_MES);
|
|
93
|
barCodeHeader.setBarCodeHeaderCode(header.getCode());
|
|
94
|
barCodeHeader.setEchelon(header.getEchelon());
|
|
95
96
97
|
//barCodeHeader.setTotalQty(BigDecimal.ZERO);
//barCodeHeader.setTotalLines(0);
//barCodeHeader.setTotalWeight(BigDecimal.ZERO);
|
|
98
99
|
result = barCodeHeaderService.save(barCodeHeader);
if(!result){
|
|
100
|
throw new ServiceException("头表创建失败");
|
|
101
|
}
|
|
102
103
104
105
|
List<BarCodeDetail> barCodeDetails = barCodeDomain.getBarCodeDetails();
BigDecimal totalQty = BigDecimal.ZERO;
BigDecimal totalWeight = BigDecimal.ZERO;
int totalLines = barCodeDetails.size();
|
|
106
|
List<BarCodeDetail> bardetaillist=new ArrayList<>();
|
|
107
108
109
110
|
for (BarCodeDetail detail : barCodeDetails) {
BarCodeDetail barCodeDetail = new BarCodeDetail();
barCodeDetail.setWarehouseCode(QuantityConstant.DEFAULT_WAREHOUSE);
barCodeDetail.setCompanyCode(QuantityConstant.DEFAULT_COMPANYCODE);
|
|
111
|
barCodeDetail.setReceiptId(barCodeHeader.getId());
|
|
112
|
barCodeDetail.setCode(detail.getCode());
|
|
113
114
115
116
|
barCodeDetail.setDayShift("day");
AjaxResult ajaxResultCode = barCodeDetailService.createRegenerationCode(1);
String regenerationCode = (String)ajaxResultCode.getData();
barCodeDetail.setRegenerationCode(regenerationCode);
|
|
117
|
barCodeDetail.setReceiptCode(barCodeHeader.getCode());
|
|
118
119
|
String materialCode = detail.getMaterialCode();
BigDecimal qty = detail.getQty();
|
|
120
|
BigDecimal weight = detail.getWeight();
|
|
121
|
|
|
122
123
|
//没有子条码,属于拆解中的散装,只有重量没有数量,重量赋值给数量
if (detail.getCode()==null || "".equals(detail.getCode())) {
|
|
124
|
qty=weight;
|
|
125
|
}
|
|
126
127
128
129
130
131
132
133
134
|
try {
//ReceiptNote不为空,就把值给数量
if (header.getReceiptNote().trim().length()>0 || header.getReceiptNote()==null) {
qty=new BigDecimal(header.getReceiptNote());
}
}catch (Exception e) {
throw new ServiceException("ReceiptNote字段非法异常:"+header.getReceiptNote());
}
|
|
135
136
|
totalQty=totalQty.add(qty);
//totalWeight=totalWeight.add(weight);
|
|
137
|
Material material = materialService.getOne(new LambdaQueryWrapper<Material>().eq(Material::getCode,materialCode));
|
|
138
139
140
141
|
barCodeDetail.setMaterialCode(material.getCode());
barCodeDetail.setMaterialName(material.getName());
barCodeDetail.setMaterialSpec(material.getSpec());
barCodeDetail.setMaterialUnit(material.getUnit());
|
|
142
|
barCodeDetail.setTotalQty(qty);
|
|
143
|
barCodeDetail.setSn(detail.getSn());
|
|
144
|
barCodeDetail.setWeight(weight);
|
|
145
|
if(barCodeDetail.getCode().length() == 17 || barCodeDetail.getCode().length() == 19){
|
|
146
147
148
149
150
|
String code = barCodeDetail.getCode();
String productType = code.substring(3,4);
if(exist(productType)){
barCodeDetail = addAttr(barCodeDetail.getCode(),barCodeDetail,header);
}
|
|
151
|
}
|
|
152
|
bardetaillist.add(barCodeDetail);
|
|
153
|
}
|
|
154
|
barCodeHeader.setTotalQty(totalQty);
|
|
155
|
barCodeHeader.setTotalLines(totalLines);
|
|
156
|
barCodeHeader.setLocked(QuantityConstant.BARCODEHEADER_LOCKED);
|
|
157
158
159
160
161
|
if(!barCodeDetailService.saveBatch(bardetaillist)){
throw new ServiceException("包装子信息创建失败");
}
if(!barCodeHeaderService.updateById(barCodeHeader)){
throw new ServiceException("更新入库头信息失败。");
|
|
162
|
}
|
|
163
164
|
//保存原料入库信息
saveReceiptHeader(barCodeHeader,bardetaillist);
|
|
165
|
return AjaxResult.toAjax(true);
|
|
166
167
|
}
|
|
168
169
170
171
172
173
174
175
176
177
178
179
|
public ReceiptDetail createReceiptDetail(ReceiptHeader receiptHeader){
ReceiptDetail receiptDetail=new ReceiptDetail();
receiptDetail.setReceiptId(receiptHeader.getId());
receiptDetail.setReceiptCode(receiptHeader.getCode());
receiptDetail.setWarehouseCode(receiptHeader.getWarehouseCode());
receiptDetail.setCompanyCode(receiptHeader.getCompanyCode());
receiptDetail.setCreated(receiptHeader.getCreated());
receiptDetail.setLastUpdatedBy(receiptHeader.getLastUpdatedBy());
receiptDetail.setLastUpdated(receiptHeader.getLastUpdated());
return receiptDetail;
}
|
|
180
181
182
183
184
185
186
|
/**
* 1.先查找主条码有没有未完成的单据
* 2.有则不新增ReceiptHeader,直接添加明细
* @param barCodeHeader
* @param bardetaillist
* @return
*/
|
|
187
|
public ReceiptHeader saveReceiptHeader(BarCodeHeader barCodeHeader,List<BarCodeDetail> bardetaillist){
|
|
188
189
|
LambdaQueryWrapper<ReceiptHeader> receiptHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
receiptHeaderLambdaQueryWrapper.eq(ReceiptHeader::getBarCodeHeaderCode, barCodeHeader.getBarCodeHeaderCode());
|
|
190
|
receiptHeaderLambdaQueryWrapper.lt(ReceiptHeader::getFirstStatus, QuantityConstant.RECEIPT_HEADER_POSTING);
|
|
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
receiptHeaderLambdaQueryWrapper.orderByDesc(ReceiptHeader::getId);
List<ReceiptHeader> receiptHeaderList=receiptHeaderService.list(receiptHeaderLambdaQueryWrapper);
ReceiptHeader receiptHeader=null;
int totalQty=0;
int totalLines=0;
if(receiptHeaderList!=null&&receiptHeaderList.size()>0){
receiptHeader=receiptHeaderList.get(0);
totalQty=receiptHeader.getTotalQty().intValue();
totalLines=receiptHeader.getTotalLines();
}else{
receiptHeader=new ReceiptHeader();
BeanUtils.copyBeanProp(receiptHeader,barCodeHeader);
receiptHeader.setReceiptType("CPRK");
receiptHeader.setId(null);
String receiptCode = receiptHeaderService.createCode(receiptHeader.getReceiptType());
receiptHeader.setCode(receiptCode);
receiptHeader.setBarCodeHeaderId(barCodeHeader.getId());
receiptHeader.setBarCodeHeaderCode(barCodeHeader.getBarCodeHeaderCode());
receiptHeader.setFirstStatus(QuantityConstant.RECEIPT_HEADER_BUILD);
receiptHeader.setLastStatus(QuantityConstant.RECEIPT_HEADER_BUILD);
|
|
211
|
|
|
212
213
214
215
|
receiptHeader.setCreatedBy(ShiroUtils.getLoginName());
receiptHeader.setCreated(new Date());
receiptHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
receiptHeader.setLastUpdated(new Date());
|
|
216
|
|
|
217
218
|
receiptHeaderService.save(receiptHeader);
}
|
|
219
220
221
|
ReceiptDetail receiptDetail=createReceiptDetail(receiptHeader);
//保存详情
receiptContainerHeaderService.saveReceiptDetail(bardetaillist,receiptDetail,false);
|
|
222
223
224
|
receiptHeader.setTotalQty(new BigDecimal(totalQty+barCodeHeader.getTotalQty().intValue()));
receiptHeader.setTotalLines(totalLines+barCodeHeader.getTotalLines());
|
|
225
|
receiptHeaderService.updateById(receiptHeader);
|
|
226
227
228
229
|
return receiptHeader;
}
|
|
230
231
232
233
|
public AjaxResult checkBarCode(BarCodeDomain barCodeDomain) {
BarCodeHeader barCodeHeader = barCodeDomain.getBarCodeHeader();
String barCodeHeaderCode = barCodeHeader.getCode();
if(barCodeHeaderCode == null || "".equals(barCodeHeaderCode)){
|
|
234
|
return AjaxResult.error("没有托盘号!");
|
|
235
236
|
}
|
|
237
238
239
|
// if(barCodeHeader.getFbillno() == null || "".equals(barCodeHeader.getFbillno())){
// return AjaxResult.error("没有生产订单编号");
// }
|
|
240
241
242
243
244
|
BarCodeHeader one = barCodeHeaderService.getOne(new LambdaQueryWrapper<BarCodeHeader>()
.eq(BarCodeHeader::getBarCodeHeaderCode,barCodeHeaderCode)
.eq(BarCodeHeader::getFbillno,barCodeHeader.getFbillno()));
if(one != null){
|
|
245
|
return AjaxResult.error("包装信息头错误:托盘号【"+barCodeHeaderCode+"】和生产订单号都重复了 "+barCodeHeader.getFbillno());
|
|
246
247
248
249
250
251
252
|
}
List<BarCodeDetail> barCodeDetailList = barCodeDomain.getBarCodeDetails();
for (BarCodeDetail barCodeDetail : barCodeDetailList) {
String materialCode = barCodeDetail.getMaterialCode();
if(materialCode == null){
|
|
253
|
return AjaxResult.error("物料编码为空");
|
|
254
255
256
257
258
259
260
261
262
|
}
Material material = materialService.getOne(new LambdaQueryWrapper<Material>().eq(Material::getCode,barCodeDetail.getMaterialCode()));
if(material == null){
return AjaxResult.error("没有该物料编码:"+materialCode);
}
}
return AjaxResult.success();
}
|
|
263
|
private BarCodeDetail addAttr(String barCode,BarCodeDetail detail,BarCodeHeader header){
|
|
264
|
String type = "";
|
|
265
|
if(barCode.length()==17){
|
|
266
|
detail.setCode(barCode+"RC");
|
|
267
|
type = "RC";
|
|
268
|
}else if(barCode.length()==19){
|
|
269
|
type = barCode.substring(17,19);
|
|
270
|
}else if("1".equals(header.getEchelon())){
|
|
271
|
type = "RM";
|
|
272
|
}
|
|
273
|
String productType = barCode.substring(3,4);
|
|
274
275
276
277
278
|
String batteryType = barCode.substring(4,5);
String productDate = barCode.substring(7,10);
String year = productDate.substring(0, 1);
String month = productDate.substring(1, 2);
String day = productDate.substring(2, 3);
|
|
279
|
|
|
280
|
String days = Res.string().dateKey(day);
|
|
281
|
String months = Res.string().dateKey(month);
|
|
282
|
String years = Res.string().yearKey(year);
|
|
283
|
Date inTime = DateUtils.dateTime("yyyy-MM-dd", years + "-" + months + "-" + days);
|
|
284
|
|
|
285
286
287
|
//默认都是 1 梯级利用 (0是再生利用 再生利用需要填type)
detail.setStorageType("1");
// detail.setType("1");
|
|
288
|
detail.setConstitute(Res.string().batteryKey(type));
|
|
289
|
detail.setProductType(Res.string().batteryKey(productType+"1"));
|
|
290
291
292
293
294
|
detail.setBatteryModel(Res.string().batteryKey(batteryType));
detail.setWarehouseInTime(inTime);
return detail;
}
|
|
295
|
private Boolean exist(String proTypeStr){
|
|
296
|
if(StringUtils.isNotEmpty(proTypeStr)){
|
|
297
298
299
300
301
302
303
304
305
306
307
308
|
if(proTypeStr.contains("P")){
return true;
}
if(proTypeStr.contains("M")){
return true;
}
if(proTypeStr.contains("C")){
return true;
}
}
return false;
}
|
|
309
|
}
|