|
1
2
3
4
5
|
package com.huaheng.api.general.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.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
|
import com.huaheng.common.utils.spring.SpringUtils;
|
|
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
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;
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;
|
|
32
|
import java.math.BigDecimal;
|
|
33
|
import java.util.*;
|
|
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
@Component
@Transactional
public class BarCodeApiService {
@Resource
private BarCodeHeaderService barCodeHeaderService;
@Resource
private MaterialService materialService;
@Resource
private BarCodeDetailService barCodeDetailService;
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private TaskDetailService taskDetailService;
@Resource
private TaskInfoService taskInfoService;
@Resource
private ReceiptTaskService receiptTaskService;
|
|
52
53
|
@Resource
private TaskReturnService taskReturnService;
|
|
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
64
|
boolean result = false;
BarCodeHeader header = barCodeDomain.getBarCodeHeader();
|
|
65
|
BarCodeHeader barCodeHeader = new BarCodeHeader();
|
|
66
|
barCodeHeader.setLocked(QuantityConstant.BARCODEHEADER_LOCKED_DEFAULT);
|
|
67
68
|
barCodeHeader.setCode(barCodeHeaderService.createCode("BZXXRK"));
barCodeHeader.setMaterialBatch(header.getMaterialBatch());
|
|
69
70
71
|
barCodeHeader.setReceiptType("BZXXRK");
barCodeHeader.setWarehouseCode(QuantityConstant.DEFAULT_WAREHOUSE);
barCodeHeader.setCompanyCode(QuantityConstant.DEFAULT_COMPANYCODE);
|
|
72
|
barCodeHeader.setFbillno(header.getFbillno());
|
|
73
|
barCodeHeader.setCreatedBy(QuantityConstant.PLATFORM_MES);
|
|
74
|
barCodeHeader.setBarCodeHeaderCode(header.getCode());
|
|
75
76
77
78
79
80
|
barCodeHeader.setReceiptNote(header.getReceiptNote());
barCodeHeader.setTotalQty(BigDecimal.ZERO);
barCodeHeader.setTotalLines(0);
barCodeHeader.setTotalWeight(BigDecimal.ZERO);
result = barCodeHeaderService.save(barCodeHeader);
if(!result){
|
|
81
|
throw new ServiceException("包装头信息创建失败");
|
|
82
|
}
|
|
83
84
85
86
87
88
89
90
91
|
List<BarCodeDetail> barCodeDetails = barCodeDomain.getBarCodeDetails();
BigDecimal totalQty = BigDecimal.ZERO;
BigDecimal totalWeight = BigDecimal.ZERO;
int totalLines = barCodeDetails.size();
for (BarCodeDetail detail : barCodeDetails) {
BarCodeDetail barCodeDetail = new BarCodeDetail();
barCodeDetail.setWarehouseCode(QuantityConstant.DEFAULT_WAREHOUSE);
barCodeDetail.setCompanyCode(QuantityConstant.DEFAULT_COMPANYCODE);
|
|
92
|
barCodeDetail.setReceiptId(barCodeHeader.getId());
|
|
93
|
barCodeDetail.setCode(detail.getCode());
|
|
94
95
96
97
|
barCodeDetail.setDayShift("day");
AjaxResult ajaxResultCode = barCodeDetailService.createRegenerationCode(1);
String regenerationCode = (String)ajaxResultCode.getData();
barCodeDetail.setRegenerationCode(regenerationCode);
|
|
98
|
barCodeDetail.setReceiptCode(barCodeHeader.getCode());
|
|
99
100
|
String materialCode = detail.getMaterialCode();
BigDecimal qty = detail.getQty();
|
|
101
|
BigDecimal weight = detail.getWeight();
|
|
102
|
BarCodeHeader oneBarCodeHeader = barCodeHeaderService.getOne(new LambdaQueryWrapper<BarCodeHeader>().eq(BarCodeHeader::getId, barCodeHeader.getId()));
|
|
103
104
|
if(header.getEchelon()==null){
oneBarCodeHeader.setProType("2");//拆解
|
|
105
|
}else {
|
|
106
|
oneBarCodeHeader.setProType("1");//装配
|
|
107
|
}
|
|
108
|
barCodeHeaderService.updateById(oneBarCodeHeader);
|
|
109
|
|
|
110
|
if (detail.getCode()==null || "".equals(detail.getCode())) { //没有子条码,属于拆解中的散装,只有重量没有数量,重量赋值给数量
|
|
111
|
qty=weight;
|
|
112
|
}
|
|
113
114
|
totalQty.add(qty);
totalWeight.add(weight);
|
|
115
|
Material material = materialService.getOne(new LambdaQueryWrapper<Material>().eq(Material::getCode,materialCode));
|
|
116
117
118
119
|
barCodeDetail.setMaterialCode(material.getCode());
barCodeDetail.setMaterialName(material.getName());
barCodeDetail.setMaterialSpec(material.getSpec());
barCodeDetail.setMaterialUnit(material.getUnit());
|
|
120
|
barCodeDetail.setTotalQty(qty);
|
|
121
|
barCodeDetail.setSn(detail.getSn());
|
|
122
|
barCodeDetail.setWeight(weight);
|
|
123
|
if(barCodeDetail.getCode().length() == 17 || barCodeDetail.getCode().length() == 24 || barCodeDetail.getCode().length() == 19){
|
|
124
125
126
127
128
|
String code = barCodeDetail.getCode();
String productType = code.substring(3,4);
if(exist(productType)){
barCodeDetail = addAttr(barCodeDetail.getCode(),barCodeDetail,header);
}
|
|
129
|
}
|
|
130
131
132
133
134
|
// barCodeDetail.setStorageType(detail.getStorageType());
// barCodeDetail.setConstitute(detail.getConstitute());
// barCodeDetail.setProductType(detail.getProductType());
// barCodeDetail.setBatteryModel(detail.getBatteryModel());
// barCodeDetail.setWarehouseInTime(detail.getWarehouseInTime());
|
|
135
136
|
result = barCodeDetailService.save(barCodeDetail);
if(!result){
|
|
137
|
result=false;
|
|
138
|
throw new ServiceException("包装子信息创建失败");
|
|
139
|
}
|
|
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
// if(barCodeDetail.getCode()!=null && !"".equals(barCodeDetail.getCode())){
// Map<String, Object> dataByBarCode = taskReturnService.getDataByBarCode(barCodeDetail.getCode());
// /**
// * Barcode 拆解物码
// * MaterialType 产品类型
// * PreviousBarcode 源电池包/模组/电芯码
// * SuperiorBarcode 拆解上级码 例如 电芯码的上级码(模组码)
// * BatteryType 电池类型
// * BatteryPackSource 来源公司编号
// */
// String previousBarcode = (String) dataByBarCode.get("PreviousBarcode");
// String superiorBarcode = (String) dataByBarCode.get("SuperiorBarcode");
// String batteryPackSource = (String) dataByBarCode.get("BatteryPackSource");
// barCodeDetail.setPreviousBarcode(previousBarcode);
// barCodeDetail.setSuperiorBarcode(superiorBarcode);
// barCodeDetail.setBatteryPackSource(batteryPackSource);
// barCodeDetail = addAttr(barCodeDetail.getCode(), barCodeDetail);
// barCodeDetailService.updateById(barCodeDetail);
// if(!result){
// throw new ServiceException("包装子信息创建失败");
// }
// }
|
|
162
|
}
|
|
163
164
165
166
167
168
169
|
barCodeHeader.setTotalQty(barCodeHeader.getTotalQty().add(totalQty));
barCodeHeader.setTotalWeight(barCodeHeader.getTotalWeight().add(totalWeight));
barCodeHeader.setTotalLines(totalLines);
result = barCodeHeaderService.updateById(barCodeHeader);
if(!result){
throw new ServiceException("更新包装入库头信息失败。");
}
|
|
170
|
return AjaxResult.toAjax(result);
|
|
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
|
@Transactional(rollbackFor = Exception.class)
public AjaxResult checkBarCode(BarCodeDomain barCodeDomain) {
BarCodeHeader barCodeHeader = barCodeDomain.getBarCodeHeader();
String barCodeHeaderCode = barCodeHeader.getCode();
if(barCodeHeaderCode == null || "".equals(barCodeHeaderCode)){
return AjaxResult.error("没有主条码");
}
if(barCodeHeader.getFbillno() == null || "".equals(barCodeHeader.getFbillno())){
return AjaxResult.error("没有生产订单编号");
}
BarCodeHeader one = barCodeHeaderService.getOne(new LambdaQueryWrapper<BarCodeHeader>()
.eq(BarCodeHeader::getBarCodeHeaderCode,barCodeHeaderCode)
.eq(BarCodeHeader::getFbillno,barCodeHeader.getFbillno()));
if(one != null){
return AjaxResult.error("包装信息头错误:主条码【"+barCodeHeaderCode+"】和生产订单号都重复了 "+barCodeHeader.getFbillno());
}
List<BarCodeDetail> barCodeDetailList = barCodeDomain.getBarCodeDetails();
for (BarCodeDetail barCodeDetail : barCodeDetailList) {
String materialCode = barCodeDetail.getMaterialCode();
if(materialCode == null){
|
|
197
|
return AjaxResult.error("物料编码为空");
|
|
198
199
200
201
202
203
204
205
206
|
}
Material material = materialService.getOne(new LambdaQueryWrapper<Material>().eq(Material::getCode,barCodeDetail.getMaterialCode()));
if(material == null){
return AjaxResult.error("没有该物料编码:"+materialCode);
}
}
return AjaxResult.success();
}
|
|
207
|
private BarCodeDetail addAttr(String barCode,BarCodeDetail detail,BarCodeHeader header){
|
|
208
|
String type = "";
|
|
209
|
if(barCode.length()==17){
|
|
210
|
type = "RC";
|
|
211
|
}else if(barCode.length()==19){
|
|
212
|
type = barCode.substring(17,19);
|
|
213
|
}else if("1".equals(header.getEchelon())){
|
|
214
|
type = "RM";
|
|
215
|
}
|
|
216
|
String productType = barCode.substring(3,4);
|
|
217
218
219
220
221
|
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);
|
|
222
|
|
|
223
224
225
226
|
String days = Res.string().dateKey(day);
String years = Res.string().yearKey(year);
Date inTime = DateUtils.dateTime("yyyy-MM-dd", years + "-" + month + "-" + days);
|
|
227
228
229
|
//默认都是 1 梯级利用 (0是再生利用 再生利用需要填type)
detail.setStorageType("1");
// detail.setType("1");
|
|
230
|
detail.setConstitute(Res.string().batteryKey(type));
|
|
231
|
detail.setProductType(Res.string().batteryKey(productType+"1"));
|
|
232
233
234
235
236
|
detail.setBatteryModel(Res.string().batteryKey(batteryType));
detail.setWarehouseInTime(inTime);
return detail;
}
|
|
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
private Boolean exist(String proTypeStr){
if(StringUtils.isEmpty(proTypeStr)){
if(proTypeStr.contains("P")){
return true;
}
if(proTypeStr.contains("M")){
return true;
}
if(proTypeStr.contains("C")){
return true;
}
}
return false;
}
|
|
251
|
}
|