BarCodeApiService.java
10.1 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
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;
import com.huaheng.api.general.domain.BarCodeDomain;
import com.huaheng.api.wcs.service.taskInfo.TaskInfoService;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.spring.SpringUtils;
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;
import java.math.BigDecimal;
import java.util.List;
@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;
@Transactional(rollbackFor = Exception.class)
public AjaxResult checkBarCode(BarCodeDomain barCodeDomain) {
BarCodeHeader barCodeHeader = barCodeDomain.getBarCodeHeader();
String barCodeHeaderCode = barCodeHeader.getCode();
if(barCodeHeaderCode == null){
return AjaxResult.error("主码不存在 code");
}
barCodeHeader.setBarCodeHeaderCode(barCodeHeaderCode);
LambdaQueryWrapper<BarCodeHeader> barCodeHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
barCodeHeaderLambdaQueryWrapper.eq(BarCodeHeader::getBarCodeHeaderCode,barCodeHeader.getBarCodeHeaderCode());
List<BarCodeHeader> barCodeHeaderList = barCodeHeaderService.list(barCodeHeaderLambdaQueryWrapper);
if(barCodeHeaderList.size()>0){
return AjaxResult.error("主码重复 code");
}
List<BarCodeDetail> barCodeDetailList = barCodeDomain.getBarCodeDetails();
for (BarCodeDetail barCodeDetail : barCodeDetailList) {
String barCodeDetailReceiptCode = barCodeDetail.getCode();
if(barCodeDetailReceiptCode == null){
return AjaxResult.error("子条码不存在 code");
}
barCodeDetail.setReceiptCode(barCodeDetailReceiptCode);
String materialCode = barCodeDetail.getMaterialCode();
if(materialCode == null){
return AjaxResult.error("物料编码不存在 materialCode");
}
// String materialUnit = barCodeDetail.getMaterialUnit();
// if(materialUnit == null){
// return AjaxResult.error("物料单位不存在 materialUnit");
// }
BigDecimal qty = barCodeDetail.getQty();
if(qty == null){
return AjaxResult.error("数量不存在 qty");
}
String sn = barCodeDetail.getSn();
if(sn == null){
return AjaxResult.error("序列号不存在 sn");
}
}
return AjaxResult.success();
}
@Transactional(rollbackFor = Exception.class)
public AjaxResult addBarCodeApi(BarCodeDomain barCodeDomain){
AjaxResult ajaxResult = checkBarCode(barCodeDomain);
if(ajaxResult.getCode()!=200){
return AjaxResult.error(ajaxResult.getMsg());
}
BarCodeHeader barCodeHeader = barCodeDomain.getBarCodeHeader();
barCodeHeader.setReceiptType("BZXXRK");
if(StringUtils.isNotEmpty(barCodeHeader.getReceiptNote())){
barCodeHeader.setReceiptNote(barCodeHeader.getReceiptNote());
}
barCodeHeader.setBarCodeHeaderCode(barCodeHeader.getCode());
//获得入库单据
String code = barCodeHeaderService.createCode("BZXXRK");
//重新覆盖值
barCodeHeader.setCode(code);
barCodeHeader.setWarehouseCode("CS0001");
barCodeHeader.setCompanyCode("BHF");
barCodeHeader.setFbillno(barCodeDomain.getBarCodeHeader().getFbillno());
boolean savebarCodeHeader = barCodeHeaderService.save(barCodeHeader);
if(!savebarCodeHeader){
return AjaxResult.error("包装头信息插入失败");
}
List<BarCodeDetail> barCodeDetailList = barCodeDomain.getBarCodeDetails();
for (BarCodeDetail barCodeDetail : barCodeDetailList) {
barCodeDetail.setWarehouseCode("CS0001");
barCodeDetail.setCompanyCode("BHF");
barCodeDetail.setReceiptId(barCodeHeader.getId());
barCodeDetail.setCode(barCodeDetail.getCode());
barCodeDetail.setReceiptCode(barCodeHeader.getCode());
// barCodeDetail.setMaterialCode(barCodeDetail.getMaterialCode());
if(barCodeDetail.getMaterialName() == null){
LambdaQueryWrapper<Material> materialLambdaQueryWrapper = Wrappers.lambdaQuery();
materialLambdaQueryWrapper.eq(Material::getCode,barCodeDetail.getMaterialCode())
.eq(Material::getUnit,barCodeDetail.getMaterialUnit());
Material materialServiceOne = materialService.getOne(materialLambdaQueryWrapper);
if(materialServiceOne == null){
return AjaxResult.error("没改物料编码:"+barCodeDetail.getMaterialCode());
}
String materialName = materialServiceOne.getName();
barCodeDetail.setMaterialName(materialName);
}
// barCodeDetail.setMaterialName(barCodeDetail.getMaterialName());
if(StringUtils.isNotEmpty(barCodeDetail.getMaterialUnit())){
barCodeDetail.setMaterialUnit(barCodeDetail.getMaterialUnit());
}
boolean savebarCodeDetail = barCodeDetailService.save(barCodeDetail);
if(!savebarCodeDetail){
return AjaxResult.error("包装子信息插入失败");
}
//
// LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper2 = Wrappers.lambdaQuery();
// taskHeaderLambdaQueryWrapper2.eq(TaskHeader::getPort, barCodeDomain.getPort())
// .eq(TaskHeader::getArea, barCodeDomain.getArea())
// .in(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT,
// QuantityConstant.TASK_TYPE_WHOLERECEIPT)
// .eq(TaskHeader::getMaterialCode, barCodeDetail.getMaterialCode())
//// .eq(TaskHeader::getBack, 0)
// .lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
// TaskHeader taskHeader = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper2);
// if(taskHeader != null) {
// LambdaQueryWrapper<TaskDetail> taskDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
// taskDetailLambdaQueryWrapper.eq(TaskDetail::getTaskId, taskHeader.getId());
// List<TaskDetail> taskDetailList = taskDetailService.list(taskDetailLambdaQueryWrapper);
// if (taskDetailList != null && taskDetailList.size() >= 0) {
// int size = taskDetailList.size();
// if (size == 0) {
// return AjaxResult.error("不要重复请求入库");
// }
// taskHeaderService.updateById(taskHeader);
// }
// } else {
// LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper3 = Wrappers.lambdaQuery();
// taskHeaderLambdaQueryWrapper3.eq(TaskHeader::getPort, barCodeDomain.getPort())
// .eq(TaskHeader::getArea, barCodeDomain.getArea())
// .in(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT,
// QuantityConstant.TASK_TYPE_WHOLERECEIPT)
// .eq(TaskHeader::getMaterialCode, barCodeDetail.getMaterialCode())
// // .eq(TaskHeader::getBack, 0)
// .lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
// List<TaskHeader> taskHeaderList = taskHeaderService.list(taskHeaderLambdaQueryWrapper3);
// if(taskHeaderList.size() > 1) {
// taskHeader = taskHeaderList.get(0);
// if (taskHeader != null) {
// taskHeaderService.updateById(taskHeader);
// }
// } else {
// taskHeader = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper3);
// if (taskHeader != null) {
// taskHeaderService.updateById(taskHeader);
// }
// }
// }
}
// String stationCode = barCodeDomain.getPort();
//
//// String containerCode = taskInfoService.getStationPallet(stationCode, area);
// String containerCode = barCodeDomain.getContainerCode();
// if(containerCode != null){
// return receiptTaskService.createWholeReceiptTask(containerCode,
// "2022202240001", "CS0001", stationCode, barCodeDomain.getArea(),barCodeDetailList);
// }
return AjaxResult.success();
}
}