SrmDetailService.java
8.08 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
package com.huaheng.pc.srm.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.company.domain.Company;
import com.huaheng.pc.config.company.service.CompanyService;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
import com.huaheng.pc.srm.domain.*;
import com.huaheng.pc.srm.mapper.ICSASNMapper;
import com.huaheng.pc.srm.mapper.SrmDetailMapper;
import com.huaheng.pc.stompwebsocket.domain.StompMessage;
import com.huaheng.pc.stompwebsocket.mapper.StompMessageMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@Service
public class SrmDetailService extends ServiceImpl<SrmDetailMapper, SrmDetail> {
@Resource
private SrmHeaderService srmHeaderService;
@Resource
private ICSITEMLotService icsitemLotService;
@Resource
private CompanyService companyService;
@Resource
private ReceiptHeaderService receiptHeaderService;
public SrmDetail selectFirstModel(SrmDetail srmDetail){
LambdaQueryWrapper<SrmDetail> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(StringUtils.isNotEmpty(srmDetail.getLineCode()),SrmDetail::getLineCode,srmDetail.getLineCode());
queryWrapper.eq(StringUtils.isNotEmpty(srmDetail.getCode()),SrmDetail::getCode,srmDetail.getCode());
queryWrapper.last("limit 1");
return this.getOne(queryWrapper);
}
public List<SrmDetail> selectBySTNO(List<String> STNOS) {
if(STNOS!=null&&STNOS.size()>0){
String[] split=STNOS.toArray(new String[0]);
LambdaQueryWrapper<SrmDetail> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.in(SrmDetail::getCode,split);
return this.list(queryWrapper);
}
return null;
}
public List<SrmDetail> selectList(SrmDetail srmDetail) {
LambdaQueryWrapper<SrmDetail> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(StringUtils.isNotEmpty(srmDetail.getCode()),SrmDetail::getCode,srmDetail.getCode());
queryWrapper.eq(StringUtils.isNotNull(srmDetail.getEnable()),SrmDetail::getEnable,srmDetail.getEnable());
queryWrapper.eq(StringUtils.isNotNull(srmDetail.getCheckCode()),SrmDetail::getCheckCode,srmDetail.getCheckCode());
return this.list(queryWrapper);
}
@Transactional
public AjaxResult review(String code) {
ICSITEMLot queryIcsitemLot = new ICSITEMLot();
queryIcsitemLot.setLotNO(code);
ICSITEMLot icsitemLot = icsitemLotService.selectFirstModel(queryIcsitemLot);
if(icsitemLot == null){
return AjaxResult.error("没有此条码信息,SRM系统未下发或者条码错误");
}
SrmDetail srmDetail = new SrmDetail();
srmDetail.setLineCode(code);
srmDetail = this.selectFirstModel(srmDetail);
if(srmDetail == null){
return AjaxResult.error("没有此条码的送货单信息,SRM系统未下发或者条码错误");
}
Company company = new Company();
company.setCode(srmDetail.getCompanyCode());
List<Company> companylist =companyService.getByDomain(company);
if(companylist!=null&&companylist.size()>0){
company=companylist.get(0);
srmDetail.setCompanyName(company.getName());
}
srmDetail.setConfirmQty(icsitemLot.getLOTQTY());
return AjaxResult.success(srmDetail);
}
@Transactional
public AjaxResult reviewSrmModel(List<SrmDetail> srmDetails) {
Set<String> codes = new HashSet<>();
for (SrmDetail srmDetail : srmDetails) {
//该明细是否之前送过,送过则新生成一条明细
if(StringUtils.isEmpty(srmDetail.getUWarehouseCode())){
return AjaxResult.error("仓库为空");
}
SrmDetail model = new SrmDetail();
model.setId(srmDetail.getId());
model = this.selectFirstModel(model);
if(model.getEnable() == 1){
break;
}else {
srmDetail.setEnable(1);
srmDetail.setLastUpdate(new Date());
srmDetail.setLastUpdateBy(ShiroUtils.getLoginName());
this.updateById(srmDetail);
}
codes.add(model.getCode());
}
if(codes.isEmpty()){
return AjaxResult.success("该编码已通过扫描确认,无法再次扫描确认");
}
//判断送货单主表,是否全收货
for (String code : codes) {
Integer number = 0;
//查看该单据明细是否全收货
SrmDetail srmDetail = new SrmDetail();
srmDetail.setCode(code);
List<SrmDetail> srmDetailList = this.selectList(srmDetail);
srmDetail.setEnable(1);
List<SrmDetail> details = this.selectList(srmDetail);
if(srmDetailList.size() == details.size()){
number = 2;
}else {
number = 1;
}
SrmHeader srmHeader = new SrmHeader();
srmHeader.setCode(code);
srmHeader = srmHeaderService.selectFirstModel(srmHeader);
if(srmHeader != null){
srmHeader.setEnable(number);
srmHeaderService.updateById(srmHeader);
}
}
return AjaxResult.success("复核成功");
}
@Transactional
public AjaxResult checkDetail(SrmDetail srmDetail) {
SrmDetail model = new SrmDetail();
model.setId(srmDetail.getId());
model = this.selectFirstModel(model);
if(srmDetail.getUnqualifiedQty().compareTo(new BigDecimal(0))==1 && StringUtils.isEmpty(srmDetail.getReason())){
return AjaxResult.error("不合格原因未填写");
}
BigDecimal qty = srmDetail.getConfirmQty().subtract(srmDetail.getQualifiedQty()).subtract(srmDetail.getUnqualifiedQty());
if(qty.compareTo(new BigDecimal(0)) == -1){
return AjaxResult.error("条码为"+model.getLineCode()+"的物料质检后的总数量大于到货数量");
}
if(qty.compareTo(new BigDecimal(0)) == 1){
return AjaxResult.error("条码为"+model.getLineCode()+"的物料质检后的总数量小于到货数量");
}
srmDetail.setCheckCode(2);
srmDetail.setCheckUser(ShiroUtils.getLoginName());
srmDetail.setCheckTime(new Date());
this.updateById(srmDetail);
//判断子表是否全部质检完成
SrmDetail detail = new SrmDetail();
detail.setCode(model.getCode());
detail.setEnable(1);
List<SrmDetail> srmDetailList = this.selectList(detail);
detail.setCheckCode(2);
List<SrmDetail> srmDetails = this.selectList(detail);
//修改主表字段
SrmHeader srmHeader = new SrmHeader();
srmHeader.setCode(model.getCode());
srmHeader = srmHeaderService.selectFirstModel(srmHeader);
if(srmDetailList.size() == srmDetails.size()){
srmHeader.setCheckCode(2);
ReceiptHeader receiptHeader = new ReceiptHeader();
receiptHeader.setUserDef3(srmHeader.getCode());
List<ReceiptHeader> receiptHeaderlist = receiptHeaderService.getByDomain(receiptHeader);
if(receiptHeaderlist != null&&receiptHeaderlist.size()>0){
receiptHeader=receiptHeaderlist.get(0);
receiptHeader.setDeleted(false);
receiptHeaderService.updateById(receiptHeader);
}
}else {
srmHeader.setCheckCode(1);
}
srmHeaderService.updateById(srmHeader);
return AjaxResult.success("质检成功");
}
}