BarCodeApiService.java
8.72 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
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.BusinessException;
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){
boolean result = false;
BarCodeHeader header = barCodeDomain.getBarCodeHeader();
//原料批次
String materialBatch = header.getMaterialBatch();
if(materialBatch ==null){
return AjaxResult.error("包装信息头错误:原料批次不存在");
}
String barCodeHeaderCode = header.getCode();
String fbillno = header.getFbillno();
if(barCodeHeaderCode == null || "".equals(barCodeHeaderCode)){
return AjaxResult.error("主码不存在 code");
}
String code = barCodeHeaderService.createCode("BZXXRK");
BarCodeHeader barCodeHeader = barCodeHeaderService.getOne(new LambdaQueryWrapper<BarCodeHeader>()
.eq(BarCodeHeader::getBarCodeHeaderCode,barCodeHeaderCode)
.eq(BarCodeHeader::getFbillno,fbillno));
if(barCodeHeader != null){
return AjaxResult.error("包装信息头错误:主条码重复【"+barCodeHeaderCode+"】。");
}
barCodeHeader = new BarCodeHeader();
barCodeHeader.setCode(code);
barCodeHeader.setMaterialBatch(materialBatch);
barCodeHeader.setReceiptType("BZXXRK");
barCodeHeader.setWarehouseCode(QuantityConstant.DEFAULT_WAREHOUSE);
barCodeHeader.setCompanyCode(QuantityConstant.DEFAULT_COMPANYCODE);
barCodeHeader.setFbillno(fbillno);
barCodeHeader.setCreatedBy(QuantityConstant.PLATFORM_MES);
barCodeHeader.setBarCodeHeaderCode(barCodeHeaderCode);
barCodeHeader.setReceiptNote(header.getReceiptNote());
barCodeHeader.setTotalQty(BigDecimal.ZERO);
barCodeHeader.setTotalLines(0);
barCodeHeader.setTotalWeight(BigDecimal.ZERO);
result = barCodeHeaderService.save(barCodeHeader);
if(!result){
throw new ServiceException("保存 包装头信息插入失败");
}
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);
barCodeDetail.setReceiptId(barCodeHeader.getId());
barCodeDetail.setCode(detail.getCode());
barCodeDetail.setPower(detail.getPower());
barCodeDetail.setReceiptCode(barCodeHeader.getCode());
String materialCode = detail.getMaterialCode();
String materialUnit = detail.getMaterialUnit();
BigDecimal qty = detail.getQty();
BigDecimal weight = detail.getWeight();
if(weight == null){
return AjaxResult.error("包装信息入库子明细,重量不能为空");
}
if(qty == null || qty.compareTo(BigDecimal.ZERO) <= 0){
return AjaxResult.error("数量不存在 qty");
}
String sn = detail.getSn();
totalQty.add(qty);
totalWeight.add(weight);
LambdaQueryWrapper<Material> queryWrapper1 = Wrappers.lambdaQuery();
queryWrapper1.eq(Material::getCode,materialCode)
.eq(Material::getUnit,materialUnit);
Material material = materialService.getOne(queryWrapper1);
if(material == null){
return AjaxResult.error("没改物料编码:"+barCodeDetail.getMaterialCode());
}
barCodeDetail.setMaterialCode(material.getCode());
barCodeDetail.setMaterialName(material.getName());
barCodeDetail.setMaterialSpec(material.getSpec());
barCodeDetail.setMaterialUnit(material.getUnit());
barCodeDetail.setQty(BigDecimal.ONE);
barCodeDetail.setSn(sn);
barCodeDetail.setWeight(weight);
result = barCodeDetailService.save(barCodeDetail);
if(!result){
throw new ServiceException("包装子信息插入失败");
}
}
barCodeHeader.setTotalQty(barCodeHeader.getTotalQty().add(totalQty));
barCodeHeader.setTotalWeight(barCodeHeader.getTotalWeight().add(totalWeight));
barCodeHeader.setTotalLines(totalLines);
result = barCodeHeaderService.updateById(barCodeHeader);
if(!result){
throw new ServiceException("更新包装入库头信息失败。");
}
return AjaxResult.success();
}
}