ReceivingController.java
17.7 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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
package com.huaheng.pc.receipt.receiving.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.aspectj.lang.annotation.Log;
import com.huaheng.framework.aspectj.lang.constant.BusinessType;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
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.service.ReceiptContainerDetailService;
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.receipt.receiving.service.ReceivingService;
import com.huaheng.pc.shipment.shipmentContainerHeader.service.ShipmentContainerHeaderService;
import com.huaheng.pc.task.taskHeader.service.ReceiptTaskService;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* @author mahua
* @ClassName ReceivingController
* @projectName huaheng
* @description: 入库组盘
* @date 2019/8/31 15:51
*/
@Controller
@RequestMapping("/receipt/receiving")
public class ReceivingController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(ReceivingController.class);
private String prefix = "receipt/receiving";
@Resource
private ReceivingService receivingService;
@Resource
private ReceiptContainerDetailService receiptContainerDetailService;
@Resource
private ReceiptContainerHeaderService receiptContainerHeaderService;
@Resource
private ReceiptDetailService receiptDetailService;
@Resource
private ReceiptHeaderService receiptHeaderService;
@Resource
private ContainerService containerService;
@Resource
private InventoryDetailService inventoryDetailService;
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private ShipmentContainerHeaderService shipmentContainerHeaderService;
@Resource
private ReceiptTaskService receiptTaskService;
@Resource
private InventoryTransactionService inventoryTransactionService;
@RequiresPermissions("receipt:receiving:view")
@GetMapping()
public String receiving() {
if(ShiroUtils.getWarehouseCode().equals(QuantityConstant.WAREHOUSE_KS)){
return prefix + "/receiving-new";
}
return prefix + "/receiving";
}
@RequiresPermissions("receipt:receiving:view")
@GetMapping("/receivingSn")
public String receivingSn() {
return prefix + "/receiving-sn";
}
/**
* 获取订单明细
*/
@ResponseBody
@PostMapping("/scanBill")
@RequiresPermissions("receipt:receiving:receiving")
@Log(title = "入库-获取订单明细", operating ="PC端扫描收货单号", action = BusinessType.OTHER)
public AjaxResult scanBill(String code) {
AjaxResult result = receivingService.scanReceiptCode(code);
return result;
}
/**
* 获取订单明细
*/
@ResponseBody
@PostMapping("/scanReferCodeBill")
@RequiresPermissions("receipt:receiving:add")
@Log(title = "入库-入库单", operating ="PC端扫描收货单号", action = BusinessType.OTHER)
public AjaxResult scanReferCodeBill(String code,String receiptId) {
AjaxResult result = receivingService.scanReferCodeBill(code,receiptId);
return result;
}
/**
* 获取订单明细
*/
@ResponseBody
@PostMapping("/scanReferCodeBillList")
@RequiresPermissions("receipt:receiving:add")
@Log(title = "入库-入库单", operating ="PC端扫描收货单号", action = BusinessType.OTHER)
public AjaxResult scanReferCodeBillList(String code,String receiptId) {
AjaxResult result = receivingService.scanReferCodeBillList(code,receiptId);
return result;
}
/**
* 获取收货信息
*/
@ResponseBody
@PostMapping("/getReceiptInfoByBill")
@RequiresPermissions("receipt:receiving:receiving")
@Log(title = "入库-获取收货信息", operating ="获取收货信息", action = BusinessType.OTHER)
public AjaxResult getReceiptInfoByBill(String code) {
AjaxResult result = receiptContainerDetailService.getReceiptInfoByBill(code);
return result;
}
/**
* 获取收货信息
*/
@ResponseBody
@PostMapping("/getReceiptInfoByBillKS")
@RequiresPermissions("receipt:receiving:receiving")
@Log(title = "入库-获取收货信息", operating ="获取收货信息", action = BusinessType.OTHER)
public AjaxResult getReceiptInfoByBillKS(String code,Integer id) {
AjaxResult result = receiptContainerDetailService.getReceiptInfoByBillKS(code,id);
return result;
}
/**
* 获取收货信息
*/
@ResponseBody
@PostMapping("/getReceiptInfoByReferBillKS")
@RequiresPermissions("receipt:receiving:receiving")
@Log(title = "入库-获取收货信息", operating ="获取收货信息", action = BusinessType.OTHER)
public AjaxResult getReceiptInfoByReferBillKS(String code,Integer id) {
AjaxResult result = receiptContainerDetailService.getReceiptInfoByReferBillKS(code,id);
return result;
}
@ResponseBody
@PostMapping("/getSelectSomething")
public AjaxResult getSelectSomething(String materialCode,String companyCode,String uWarehouseCode) {
AjaxResult result = receiptContainerDetailService.getSelectSomething(materialCode,companyCode,uWarehouseCode);
return result;
}
@GetMapping("/add")
public String add(Long detailId, String containerCode, ModelMap modelMap) {
modelMap.put("containerCode", containerCode);
modelMap.put("receiptDetails", receiptDetailService.getById(detailId));
return prefix + "/add";
}
/**
* 保存收货
*/
@ApiOperation(value="保存收货 ", notes="保存收货 ", httpMethod = "POST")
@ResponseBody
@PostMapping("/save")
@RequiresPermissions("receipt:receiving:receiving")
@Log(title = "入库-保存收货", operating ="PC端保存收货", action = BusinessType.OTHER)
public AjaxResult save(ReceiptContainerView receivingDamain){
if(receivingDamain.getQty().compareTo(new BigDecimal(0)) <=0) {
return AjaxResult.error("配盘数量必须大于0");
}
AjaxResult ajaxResult = handleMultiProcessV2("receiptSave",new MultiProcessListener() {
@Override
public AjaxResult doProcess() {
AjaxResult ajaxResult = receiptContainerHeaderService.saveContainer(receivingDamain);
if(ajaxResult!=null&&!ajaxResult.hasErr()){
//创建任务
LambdaQueryWrapper<ReceiptContainerHeader> lambdaQueryWrapper= Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(ReceiptContainerHeader::getContainerCode,receivingDamain.getContainerCode());
lambdaQueryWrapper.le(ReceiptContainerHeader::getStatus,10);
List<ReceiptContainerHeader> receiptContainerHeaders=receiptContainerHeaderService.list(lambdaQueryWrapper);
for(ReceiptContainerHeader item:receiptContainerHeaders) {
String ids = item.getId().toString();
Integer[] idArray = Convert.toIntArray(ids);
List<Integer> islist= Arrays.asList(idArray);
try {
AjaxResult ajaxResult1=receiptTaskService.createReceiptTask(islist);
} catch (Exception e) {
e.printStackTrace();
logger.error("receipt/receiving/save:idArray="+idArray+"msg:"+e.getMessage());
}
}
}
return ajaxResult;
}
});
return ajaxResult;
}
/**
* 保存收货
*/
@ApiOperation(value="PDA保存收货 ", notes="保存收货 ", httpMethod = "POST")
@ResponseBody
@PostMapping("/listSave")
@RequiresPermissions("receipt:receiving:receiving")
@Log(title = "入库-PDA保存收货", operating ="PDA端保存收货", action = BusinessType.OTHER)
public AjaxResult listSave(@RequestBody List<ReceiptContainerView> receivingDamains){
AjaxResult result = handleMultiProcessV2("receiptSave",new MultiProcessListener() {
@Override
public AjaxResult doProcess() {
AjaxResult ajaxResult=null;
ajaxResult=receiptContainerHeaderService.saveList(receivingDamains);
// for (ReceiptContainerView receivingDamain:receivingDamains){
// if(receivingDamain.getQty().compareTo(new BigDecimal(0)) <=0) {
// throw new ServiceException("配盘数量必须大于0");
// }
// if(StringUtils.isNotEmpty(receivingDamain.getSn())){
// receivingDamain.setQty(new BigDecimal(1));
// }
// ajaxResult = receiptContainerHeaderService.saveContainer(receivingDamain);
// if(ajaxResult.hasErr()){
// throw new ServiceException("配盘数量必须大于0");
// }
// }
if(ajaxResult!=null&&!ajaxResult.hasErr()){
//创建任务
LambdaQueryWrapper<ReceiptContainerHeader> lambdaQueryWrapper= Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(ReceiptContainerHeader::getContainerCode,receivingDamains.get(0).getContainerCode());
lambdaQueryWrapper.le(ReceiptContainerHeader::getStatus,10);
List<ReceiptContainerHeader> receiptContainerHeaders=receiptContainerHeaderService.list(lambdaQueryWrapper);
for(ReceiptContainerHeader item:receiptContainerHeaders) {
String ids = item.getId().toString();
Integer[] idArray = Convert.toIntArray(ids);
List<Integer> islist= Arrays.asList(idArray);
try {
AjaxResult ajaxResult1=receiptTaskService.createReceiptTask(islist);
} catch (Exception e) {
e.printStackTrace();
logger.error("receipt/receiving/save:idArray="+idArray+"msg:"+e.getMessage());
}
}
}
return ajaxResult;
}
});
return result;
}
/**
* 获取库存信息
*/
@ResponseBody
@PostMapping("/getInventoryInfo")
@RequiresPermissions("receipt:receiving:add")
@Log(title = "入库-入库单", operating ="获取库存信息", action = BusinessType.OTHER)
public AjaxResult getInventoryInfo(String code,Integer id) throws Exception {
//找到主单的账套和仓库
LambdaQueryWrapper<ReceiptHeader> lambdaQueryWrapper= Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(ReceiptHeader::getCode,code)
.eq(ReceiptHeader::getWarehouseCode, ShiroUtils.getWarehouseCode());
ReceiptHeader receiptHeader=receiptHeaderService.getOne(lambdaQueryWrapper);
if(receiptHeader == null) {
throw new ServiceException("找不到主单");
}
//找到子单物料
LambdaQueryWrapper<ReceiptDetail> lambdaQuery=Wrappers.lambdaQuery();
lambdaQuery.eq(ReceiptDetail::getReceiptCode,code)
.eq(ReceiptDetail::getWarehouseCode, ShiroUtils.getWarehouseCode())
.eq(ReceiptDetail::getId,id);
ReceiptDetail receiptDetail=receiptDetailService.getOne(lambdaQuery);
if(receiptDetail == null) {
throw new ServiceException("找不到子单");
}
//本物料库存
LambdaQueryWrapper<InventoryDetail> inventoryDetailLambda = Wrappers.lambdaQuery();
inventoryDetailLambda.eq(InventoryDetail::getWarehouseCode,ShiroUtils.getWarehouseCode())
.eq(InventoryDetail::getCompanyCode,receiptHeader.getCompanyCode())
.eq(InventoryDetail::getMaterialCode,receiptDetail.getMaterialCode())
.eq((StringUtils.isNotEmpty(receiptDetail.getProjectNo())),InventoryDetail::getProjectNo,
receiptDetail.getProjectNo());
List<InventoryDetail> inventoryList = inventoryDetailService.list(inventoryDetailLambda);
List<InventoryDetail> removeInventoryList = new ArrayList<>();
//空容器
LambdaQueryWrapper<Container> container=Wrappers.lambdaQuery();
container.eq(Container::getWarehouseCode,ShiroUtils.getWarehouseCode())
.eq(Container::getCompanyCode,receiptHeader.getCompanyCode())
.eq(Container::getStatus, QuantityConstant.STATUS_CONTAINER_EMPTY);
List<Container> emptyContainerList=containerService.list(container);
List<Container> removeEmptyContainerList = new ArrayList<>();
inventoryList.removeAll(removeInventoryList);
emptyContainerList.removeAll(removeEmptyContainerList);
LambdaQueryWrapper<InventoryTransaction> wrapper=Wrappers.lambdaQuery();
wrapper.eq(InventoryTransaction::getWarehouseCode,receiptHeader.getWarehouseCode());
wrapper.eq(InventoryTransaction::getCompanyCode,receiptHeader.getCompanyCode());
wrapper.eq(InventoryTransaction::getMaterialCode,receiptDetail.getMaterialCode());
wrapper.orderByDesc(InventoryTransaction::getId);
List<InventoryTransaction> transactionList=inventoryTransactionService.list(wrapper);
Map map=new ModelMap();
map.put("inventoryList",inventoryList);
map.put("containerList",emptyContainerList);
map.put("transactionList",transactionList);
return AjaxResult.success(map);
}
/**
* 批量收货
*/
@ResponseBody
@PostMapping("/saveAll")
@RequiresPermissions("receipt:receiving:add")
@Log(title = "入库-入库单", operating ="PC端保存收货", action = BusinessType.OTHER)
public AjaxResult saveAll(String ids,String receiptContainerCode) throws Exception {
AjaxResult result = handleMultiProcessV2("receiptSaveAll",new MultiProcessListener() {
@Override
public AjaxResult doProcess() {
AjaxResult ajaxResult=null;
final List<String> list = Arrays.asList(ids.split(","));
for(String i:list){
final ReceiptDetail receiptDetail = receiptDetailService.getById(Integer.valueOf(i));
ReceiptContainerView receiptContainerView=new ReceiptContainerView();
receiptContainerView.setReceiptCode(receiptDetail.getReceiptCode());
receiptContainerView.setQty(receiptDetail.getQty());
receiptContainerView.setContainerCode(receiptContainerCode);
receiptContainerView.setReceiptDetailId(Integer.valueOf(i));
ajaxResult = receiptContainerHeaderService.saveContainer(receiptContainerView);
if(ajaxResult.hasErr()){
return ajaxResult;
}
}
//创建任务
LambdaQueryWrapper<ReceiptContainerHeader> lambdaQueryWrapper= Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(ReceiptContainerHeader::getContainerCode,receiptContainerCode);
lambdaQueryWrapper.le(ReceiptContainerHeader::getStatus,10);
List<ReceiptContainerHeader> receiptContainerHeaders=receiptContainerHeaderService.list(lambdaQueryWrapper);
for(ReceiptContainerHeader item:receiptContainerHeaders) {
String ids2 = item.getId().toString();
Integer[] idArray = Convert.toIntArray(ids2);
List<Integer> islist= Arrays.asList(idArray);
try {
AjaxResult ajaxResult1=receiptTaskService.createReceiptTask(islist);
} catch (Exception e) {
e.printStackTrace();
logger.error("receipt/receiving/save:idArray="+idArray+"msg:"+e.getMessage());
}
}
return AjaxResult.success("操作成功");
}
});
return result;
}
}