WcsServiceImpl.java
7.33 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
package com.huaheng.api.wcs.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.api.wcs.domain.WcsTask;
import com.huaheng.api.wcs.service.warecellAllocation.LocationAllocationService;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.service.ConfigService;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.containerType.domain.ContainerType;
import com.huaheng.pc.config.containerType.service.ContainerTypeService;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.config.locationType.domain.LocationType;
import com.huaheng.pc.config.locationType.service.LocationTypeService;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.config.zone.domain.Zone;
import com.huaheng.pc.config.zone.service.ZoneService;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
import com.huaheng.pc.inventory.inventoryHeader.domain.InventoryHeader;
import com.huaheng.pc.inventory.inventoryHeader.service.InventoryHeaderService;
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.TaskHeaderService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.toList;
/**
* @author 游杰
*/
@Service
public class WcsServiceImpl implements WcsService {
@Resource
private TaskHeaderService taskheaderService;
@Resource
private InventoryDetailService inventoryDetailService;
@Resource
private InventoryHeaderService inventoryHeaderService;
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private TaskDetailService taskDetailService;
@Resource
private MaterialService materialService;
/**
*
* @param wcsTask
* @return
*/
@Override
public AjaxResult innerBack(WcsTask wcsTask) {
String containerCode = wcsTask.getContainerCode();
LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
//根据容器号查找
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getContainerCode, containerCode);
taskHeaderLambdaQueryWrapper.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
TaskHeader taskHeader = taskheaderService.getOne(taskHeaderLambdaQueryWrapper);
if(taskHeader == null) {
return AjaxResult.error("没有找到任务,不允许回库");
}
int back = taskHeader.getBack();
LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery();;
inventoryDetailLambdaQueryWrapper.eq(InventoryDetail::getContainerCode, containerCode);
List<InventoryDetail> inventoryDetailList =
inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
int flag = 0;
int size = inventoryDetailList.size();
if(size > 0) {
flag = 1;
}
if(back == 1) {
return AjaxResult.success("允许回库").setData(flag);
}
return AjaxResult.error("任务ID:" + taskHeader.getId() + "不允许回库");
}
@Override
public AjaxResult calculateWeight(String taskNo, String weight1) {
BigDecimal bigDecimal = new BigDecimal(weight1);
TaskHeader taskHeader = taskHeaderService.getById(taskNo);
if(taskHeader == null) {
return AjaxResult.error("没有找到对应任务:" + taskNo);
}
String materialCode = taskHeader.getMaterialCode();
if(StringUtils.isEmpty(materialCode)) {
return AjaxResult.error("物料信息为空");
}
String warehouseCode = taskHeader.getWarehouseCode();
LambdaQueryWrapper<TaskDetail> taskDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
taskDetailLambdaQueryWrapper.eq(TaskDetail::getTaskId, taskNo);
List<TaskDetail> taskDetailList = taskDetailService.list(taskDetailLambdaQueryWrapper);
int qty = taskDetailList.size();
Material material = materialService.getMaterialByCode(materialCode, warehouseCode);
BigDecimal pieceWeight = material.getPieceWeight();
// 四舍五入
BigDecimal totalQty = bigDecimal.divide(pieceWeight, BigDecimal.ROUND_HALF_UP);
int abs = totalQty.intValue() - qty;
if(abs == 0) {
return AjaxResult.success("称重符合数量");
}
return AjaxResult.error("称重数量为" + totalQty + " 系统数量为" + qty);
}
@Override
public AjaxResult decreaseInventory(String containerCode, String boxCode) {
LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_SORTINGSHIPMENT)
.eq(TaskHeader::getContainerCode, containerCode)
.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
TaskHeader taskHeader = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper);
if(taskHeader == null) {
return AjaxResult.error("扣减库存 没有找到出库任务,托盘号" + containerCode);
}
LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
inventoryDetailLambdaQueryWrapper.eq(InventoryDetail::getContainerCode, containerCode)
.eq(InventoryDetail::getBoxCode, boxCode);
List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
if(inventoryDetailList.size() == 0) {
return AjaxResult.error("扣减库存 没有找到对应库存,托盘号" + containerCode + "箱码" + boxCode);
}
List<Integer> ids = inventoryDetailList.stream().map(InventoryDetail::getId).collect(Collectors.toList());
inventoryDetailService.removeByIds(ids);
LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper1 = Wrappers.lambdaQuery();
inventoryDetailLambdaQueryWrapper1.eq(InventoryDetail::getContainerCode, containerCode);
List<InventoryDetail> leaveInventoryDetailList =
inventoryDetailService.list(inventoryDetailLambdaQueryWrapper1);
if(leaveInventoryDetailList.size() == 0) {
LambdaQueryWrapper<InventoryHeader> inventoryHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
inventoryHeaderLambdaQueryWrapper.eq(InventoryHeader::getContainerCode, containerCode);
inventoryHeaderService.remove(inventoryHeaderLambdaQueryWrapper);
}
return AjaxResult.success("扣减库存成功");
}
}