ReceiptContainerDetailServiceImpl.java
16.9 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
package com.huaheng.pc.receipt.receiptContainerDetail.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.common.utils.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.http.HttpUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.mobile.receipt.ReceiptBill;
import com.huaheng.pc.config.address.domain.Address;
import com.huaheng.pc.config.address.service.AddressService;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.inventory.inventoryClear.domain.InventorySearch;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
import com.huaheng.pc.inventory.inventoryTransaction.domain.InventoryTransaction;
import com.huaheng.pc.inventory.inventoryTransaction.service.InventoryTransactionService;
import com.huaheng.pc.receipt.receiptContainerDetail.domain.ReceiptContainerDetail;
import com.huaheng.pc.receipt.receiptContainerDetail.mapper.ReceiptContainerDetailMapper;
import com.huaheng.pc.receipt.receiptContainerHeader.domain.ReceiptContainerHeader;
import com.huaheng.pc.receipt.receiptContainerHeader.domain.ReceiptContainerView;
import com.huaheng.pc.receipt.receiptContainerHeader.service.ReceiptContainerHeaderService;
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
import com.huaheng.pc.system.role.domain.Role;
import com.huaheng.pc.system.user.domain.User;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.huaheng.pc.receipt.receiptContainerHeader.domain.ReceiptContainerHeader;
import com.huaheng.pc.receipt.receiptContainerHeader.service.ReceiptContainerHeaderService;
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@Service
public class ReceiptContainerDetailServiceImpl extends ServiceImpl<ReceiptContainerDetailMapper, ReceiptContainerDetail> implements ReceiptContainerDetailService{
@Resource
private ReceiptDetailService receiptDetailService;
@Resource
private ReceiptHeaderService receiptHeaderService;
@Resource
private ReceiptContainerHeaderService receiptContainerHeaderService;
@Resource
private MaterialService materialService;
@Resource
private LocationService locationService;
@Resource
private AddressService addressService;
@Resource
private ReceiptContainerDetailMapper receiptContainerDetailMapper;
@Resource
private ContainerService containerService;
@Resource
private InventoryDetailService inventoryDetailService;
@Resource
private InventoryTransactionService inventoryTransactionService;
/**
* 根据入库单编码查询入库组盘明细
* @param receiptCode 入库单编码
* @return AjaxResult
*/
@Override
public AjaxResult<List<Map<String, Object>>> getReceiptInfoByBill(String receiptCode) {
LambdaQueryWrapper<ReceiptContainerDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(ReceiptContainerDetail::getReceiptCode, receiptCode)
.eq(ReceiptContainerDetail::getWarehouseCode, ShiroUtils.getWarehouseCode());
List<Map<String, Object>> detail = this.listMaps(lambdaQueryWrapper);
return AjaxResult.success(detail);
}
/**
* 撤销入库组盘明细
* @param idList
* @return
*/
@Override
public Boolean detailRemove(List<Integer> idList) {
for (Integer id : idList){
ReceiptContainerDetail receiptContainerDetail = this.getById(id);
//如果已生成任务不允许撤销
if (receiptContainerDetail.getStatus() < QuantityConstant.RECEIPT_CONTAINER_TASK){
//回滚入库单明细收货数量
ReceiptDetail receiptDetail = receiptDetailService.getById(receiptContainerDetail.getReceiptDetailId());
receiptDetail.setTaskQty(receiptDetail.getTaskQty().subtract(receiptContainerDetail.getQty()));
//如果为临时容器,则删除
receiptContainerDetail.getContainerCode();
if (!receiptDetailService.updateById(receiptDetail)){throw new SecurityException("回滚入库单明细失败");}
//删除组盘明细
if (!this.removeById(id)){ throw new ServiceException("回滚入库组盘失败");}
LambdaQueryWrapper<ReceiptContainerDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(ReceiptContainerDetail::getReceiptContainerId, receiptContainerDetail.getReceiptContainerId());
List<ReceiptContainerDetail> list = this.list(lambdaQueryWrapper);
if (list.size() == 0){
String locationCode = receiptContainerDetail.getLocationCode();
if(StringUtils.isNotEmpty(locationCode)) {
locationService.updateStatus(locationCode, QuantityConstant.STATUS_LOCATION_EMPTY);
}
if (!receiptContainerHeaderService.removeById(receiptContainerDetail.getReceiptContainerId())){
throw new ServiceException("删除入库组盘头失败");
}
}
//查询入库头表
LambdaQueryWrapper<ReceiptContainerDetail> containerDetailLambda = Wrappers.lambdaQuery();
containerDetailLambda.eq(ReceiptContainerDetail::getReceiptId, receiptContainerDetail.getReceiptId());
List<ReceiptContainerDetail> containerDetailList = this.list(containerDetailLambda);
//如果入库组盘没有该入库单的组盘信息,回滚入库单状态
if (containerDetailList.size() == 0){
ReceiptHeader receiptHeader = new ReceiptHeader();
receiptHeader.setId(receiptContainerDetail.getReceiptId());
receiptHeader.setFirstStatus(QuantityConstant.RECEIPT_HEADER_RECEIVING);
receiptHeader.setLastStatus(QuantityConstant.RECEIPT_HEADER_RECEIVING);
receiptHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
if (!receiptHeaderService.updateById(receiptHeader)){ throw new ServiceException("回滚头表状态失败"); }
}
} else {
throw new SecurityException("已生成任务,不允许取消");
}
}
return true;
}
// /**
// * 移动端收货
// *
// * @param code
// * @return
// */
// @Override
// public AjaxResult scanReceiptCode(String code) {
// LambdaQueryWrapper<ReceiptDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
// lambdaQueryWrapper.eq(ReceiptDetail::getReceiptCode, code);
// List<ReceiptDetail> receiptContainerDetails = list(lambdaQueryWrapper);
// return AjaxResult.success(receiptContainerDetails);
// }
/**保存到组盘详细*/
@Override
public List<Integer> insertTodayReceiptcContainerDetail(int headerId, int receiptId, List<Integer> receiptDetailId, List<ReceiptBill> receiptBills) {
List<Integer> mReceiptContainerIds = new ArrayList<>();
ReceiptHeader receiptHeader = receiptHeaderService.getById(receiptId);
if(receiptHeader == null) {
throw new ServiceException("没有找到入库单表头!");
}
for(int i=0; i<receiptBills.size(); i++) {
ReceiptBill receiptBill = receiptBills.get(i);
Material condition2 = new Material();
condition2.setCode(receiptBill.getMaterialCode());
condition2.setWarehouseCode(ShiroUtils.getWarehouseCode());
condition2.setDeleted(false);
condition2.setEnable(true);
LambdaQueryWrapper<Material> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(Material::getCode, receiptBill.getMaterialCode())
.eq(Material::getWarehouseCode, ShiroUtils.getWarehouseCode());
Material material = materialService.getOne(lambdaQueryWrapper);
ReceiptContainerDetail record = new ReceiptContainerDetail();
record.setReceiptContainerId(headerId);
record.setReceiptCode(receiptHeader.getCode());
record.setReceiptId(receiptId);
record.setReceiptDetailId(receiptDetailId.get(i));
record.setMaterialCode(receiptBill.getMaterialCode());
record.setMaterialName(material.getName());
record.setMaterialSpec(material.getSpec());
record.setInventorySts("good");
record.setQty(receiptBill.getQty());
record.setContainerCode(receiptBills.get(0).getReceiptContainerCode());
if(receiptBill.getWeight() != null) {
record.setWeight(receiptBill.getWeight());
}
record.setCreatedBy(ShiroUtils.getLoginName());
record.setLastUpdatedBy(ShiroUtils.getLoginName());
LambdaQueryWrapper<ReceiptContainerDetail> detailyWrapper = Wrappers.lambdaQuery();
detailyWrapper.eq(ReceiptContainerDetail::getReceiptContainerId, headerId)
.eq(ReceiptContainerDetail::getReceiptCode, receiptHeader.getCode());
ReceiptContainerDetail receiptContainerDetail = getOne(detailyWrapper);
if(receiptContainerDetail == null) {
save(record);
mReceiptContainerIds.add(record.getId());
} else {
mReceiptContainerIds.add(receiptContainerDetail.getId());
}
}
return mReceiptContainerIds;
}
@Override
public void autoSendMmsByReceiptContainer(ReceiptContainerDetail receiptContainerDetail){
//调用mms更改采购状态
Address address = addressService.getAddressByUrl(QuantityConstant.ADDRESS_MMS,receiptContainerDetail.getWarehouseCode());
try{
String url=address.getUrl();
JSONObject json=new JSONObject();
json.put("code",receiptContainerDetail.getReceiptCode().trim());
json.put("materialCode",receiptContainerDetail.getMaterialCode().trim());
json.put("status","2");
json.put("inQty",receiptContainerDetail.getQty());
String workNo=receiptDetailService.getWorkNo(receiptContainerDetail.getReceiptDetailId());
json.put("workNo",workNo);
String JsonParam = JSON.toJSONString(json);
String result2 = HttpUtils.bodypost(url, JsonParam,receiptContainerDetail.getWarehouseCode());
if(result2!=null){
receiptContainerDetail.setSyncMms(2);
}else{
receiptContainerDetail.setSyncMmsNum(receiptContainerDetail.getSyncMmsNum()+1);
}
this.updateById(receiptContainerDetail);
}catch(Exception e) {
e.printStackTrace();
}
}
@Override
public List<ReceiptContainerDetail> getReceiptContainerDetailByHeaderId(int receiptContainerHeaderId){
//查询入库组盘明细
LambdaQueryWrapper<ReceiptContainerDetail> containerDetailLambda = Wrappers.lambdaQuery();
containerDetailLambda.eq(ReceiptContainerDetail::getReceiptContainerId, receiptContainerHeaderId);
List<ReceiptContainerDetail> list = this.list(containerDetailLambda);
return list;
}
@Override
public ReceiptContainerDetail selectFirstEntity(ReceiptContainerDetail domain){
LambdaQueryWrapper<ReceiptContainerDetail> containerDetailLambda = Wrappers.lambdaQuery();
containerDetailLambda.eq(StringUtils.isNotNull(domain.getReceiptContainerId()),ReceiptContainerDetail::getReceiptContainerId, domain.getReceiptContainerId());
containerDetailLambda.eq(StringUtils.isNotNull(domain.getReceiptDetailId()),ReceiptContainerDetail::getReceiptDetailId, domain.getReceiptDetailId());
containerDetailLambda.last("limit 1");
return this.getOne(containerDetailLambda);
}
@Override
public List<ReceiptContainerView> selectOfView(ReceiptContainerView receiptContainerView) {
return receiptContainerDetailMapper.selectOfView(receiptContainerView);
}
@Override
public AjaxResult getReceiptInfoByBillKS(String code,Integer id) {
//找到主单的账套和u8仓库
ReceiptHeader receiptHeader=new ReceiptHeader();
receiptHeader.setCode(code);
receiptHeader=receiptHeaderService.selectFirstEntity(receiptHeader);
if(receiptHeader==null){
throw new ServiceException("找不到主单");
}
//找到子单物料
ReceiptDetail receiptDetail = receiptDetailService.getOne(new LambdaQueryWrapper<ReceiptDetail>().eq(ReceiptDetail::getId, id).eq(ReceiptDetail::getReceiptCode, code));
if(receiptDetail==null){
throw new ServiceException("找不到子单");
}
LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper=Wrappers.lambdaQuery();
inventoryDetailLambdaQueryWrapper.eq(InventoryDetail::getWarehouseCode,receiptHeader.getWarehouseCode());
inventoryDetailLambdaQueryWrapper.eq((StringUtils.isNotEmpty(receiptHeader.getCompanyCode())),InventoryDetail::getCompanyCode,receiptHeader.getCompanyCode());
inventoryDetailLambdaQueryWrapper.eq((StringUtils.isNotEmpty(receiptHeader.getUWarehouseCode())),InventoryDetail::getUWarehouseCode,receiptHeader.getUWarehouseCode());
inventoryDetailLambdaQueryWrapper.eq((StringUtils.isNotEmpty(receiptDetail.getMaterialCode())),InventoryDetail::getMaterialCode,receiptDetail.getMaterialCode());
List<InventoryDetail> list = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
LambdaQueryWrapper<InventoryTransaction> inventoryTransactionLambdaQueryWrapper=Wrappers.lambdaQuery();
inventoryTransactionLambdaQueryWrapper.eq(InventoryTransaction::getWarehouseCode,receiptHeader.getWarehouseCode());
inventoryTransactionLambdaQueryWrapper.eq((StringUtils.isNotEmpty(receiptHeader.getCompanyCode())),InventoryTransaction::getCompanyCode,receiptHeader.getCompanyCode());
inventoryTransactionLambdaQueryWrapper.eq((StringUtils.isNotEmpty(receiptHeader.getUWarehouseCode())),InventoryTransaction::getUWarehouseCode,receiptHeader.getUWarehouseCode());
inventoryTransactionLambdaQueryWrapper.eq((StringUtils.isNotEmpty(receiptDetail.getMaterialCode())),InventoryTransaction::getMaterialCode,receiptDetail.getMaterialCode());
List<InventoryTransaction> transactionList = inventoryTransactionService.list(inventoryTransactionLambdaQueryWrapper);
LambdaQueryWrapper<Container> lambdaQueryWrapper=Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(Container::getWarehouseCode,receiptHeader.getWarehouseCode());
lambdaQueryWrapper.eq((StringUtils.isNotEmpty(receiptHeader.getCompanyCode())),Container::getCompanyCode,receiptHeader.getCompanyCode());
lambdaQueryWrapper.eq((StringUtils.isNotEmpty(receiptHeader.getUWarehouseCode())),Container::getUWarehouseCode,receiptHeader.getUWarehouseCode());
lambdaQueryWrapper.eq(Container::getStatus,QuantityConstant.STATUS_CONTAINER_EMPTY);
lambdaQueryWrapper.last("and containerType in ('X','D')");
List<Container> containers = containerService.list(lambdaQueryWrapper);
Map map=new ModelMap();
map.put("list",list);
map.put("transactionList",transactionList);
map.put("containers",containers);
return AjaxResult.success(map);
}
}