TvController.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
package com.huaheng.api.tv.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.api.tv.domain.*;
import com.huaheng.api.wcs.domain.WcsTask;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.domain.Result;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.location.domain.Location;
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.pc.config.materialType.domain.MaterialType;
import com.huaheng.pc.config.materialType.service.MaterialTypeService;
import com.huaheng.pc.config.zone.domain.Zone;
import com.huaheng.pc.config.zone.service.ZoneService;
import com.huaheng.pc.inventory.InventoryMaterialSummary.domain.InventoryMaterialSummary;
import com.huaheng.pc.inventory.InventoryMaterialSummary.service.InventoryMaterialSummaryService;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
import com.huaheng.pc.system.dict.domain.DictData;
import com.huaheng.pc.system.dict.service.IDictDataService;
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 io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/API/WMS/v2")
public class TvController extends BaseController {
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private ContainerService containerService;
@Resource
private LocationService locationService;
@Resource
private ZoneService zoneService;
@Resource
private InventoryDetailService inventoryDetailService;
@Resource
private InventoryMaterialSummaryService inventoryMaterialSummaryService;
@Resource
private MaterialService materialService;
@Resource
private MaterialTypeService materialTypeService;
@Resource
private IDictDataService dictDataService;
@PostMapping("/getTvView")
@ApiOperation("获取电视信息")
@ResponseBody
public AjaxResult getTvView(@RequestBody WcsTask wcsTask) {
String area = wcsTask.getArea();
LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getArea, area)
.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED)
.orderByDesc(TaskHeader::getId);
List<TaskHeader> taskHeaderList = taskHeaderService.list(taskHeaderLambdaQueryWrapper);
if (taskHeaderList != null && taskHeaderList.size() > 0) {
for (TaskHeader taskHeader : taskHeaderList) {
String materialCode = taskHeader.getMaterialCode();
String warehouseCode = taskHeader.getWarehouseCode();
Material material = materialService.getMaterialByCode(materialCode, warehouseCode);
if (material != null) {
taskHeader.setMaterialCode(material.getName());
}
}
}
LambdaQueryWrapper<Container> containerEmptyLambdaQueryWrapper = Wrappers.lambdaQuery();
containerEmptyLambdaQueryWrapper.eq(Container::getArea, area)
.eq(Container::getStatus, QuantityConstant.STATUS_CONTAINER_EMPTY)
.ne(Container::getLocationCode, "");
List<Container> containerEmptyList = containerService.list(containerEmptyLambdaQueryWrapper);
int containerEmptySize = containerEmptyList.size();
LambdaQueryWrapper<Container> containerManyLambdaQueryWrapper = Wrappers.lambdaQuery();
containerManyLambdaQueryWrapper.eq(Container::getArea, area)
.eq(Container::getStatus, QuantityConstant.STATUS_CONTAINER_MANY)
.ne(Container::getLocationCode, "");
List<Container> manyEmptyList = containerService.list(containerManyLambdaQueryWrapper);
int manyEmptyListSize = manyEmptyList.size();
containerEmptySize = containerEmptySize + manyEmptyListSize * 6;
LambdaQueryWrapper<Container> containerSomeLambdaQueryWrapper = Wrappers.lambdaQuery();
containerSomeLambdaQueryWrapper.eq(Container::getArea, area)
.eq(Container::getStatus, QuantityConstant.STATUS_CONTAINER_SOME)
.ne(Container::getLocationCode, "");
List<Container> containerSomeList = containerService.list(containerSomeLambdaQueryWrapper);
int containerSomeSize = containerSomeList.size();
LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
locationLambdaQueryWrapper.eq(Location::getArea, area);
List<Location> locationList = locationService.list(locationLambdaQueryWrapper);
int totalLocationSize = locationList.size();
LambdaQueryWrapper<Zone> zoneLambdaQueryWrapper = Wrappers.lambdaQuery();
zoneLambdaQueryWrapper.eq(Zone::getArea, area);
Zone zone = zoneService.getOne(zoneLambdaQueryWrapper);
LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
inventoryDetailLambdaQueryWrapper.eq(InventoryDetail::getZoneCode, zone.getCode());
List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
int inventorySize = inventoryDetailList.size();
LambdaQueryWrapper<InventoryMaterialSummary> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(InventoryMaterialSummary::getZoneCode, zone.getCode());
List<InventoryMaterialSummary> list = inventoryMaterialSummaryService.list(lambdaQueryWrapper);
if (list == null) {
list = Collections.emptyList();
}
//筛选库存汇总数据的专用方法
List<InventoryMaterialSummary> details = inventoryMaterialSummaryService.duplicateRemoval(list);
TvBean tvBean = new TvBean();
tvBean.setDetails(details);
tvBean.setContainerEmptySize(containerEmptySize);
tvBean.setContainerSomeSize(containerSomeSize);
tvBean.setTotalLocationSize(totalLocationSize);
tvBean.setTaskHeaderList(taskHeaderList);
tvBean.setInventorySize(inventorySize);
return AjaxResult.success(tvBean);
}
@Resource
private TaskDetailService taskDetailService;
/**
* 获取出库任务详情
*
* @return
*/
@GetMapping("importExcel")
@CrossOrigin
public AjaxResult importExcel(String code) {
List<String> stationList = new ArrayList<>();
if (StringUtils.isNotEmpty(code)) {
stationList = Arrays.asList(code.split(","));
}
HashMap<String, String> typeMap = new HashMap<>();
typeMap.put("100", "整盘入库");
typeMap.put("200", "补充入库");
typeMap.put("300", "整盘出库");
typeMap.put("400", "分拣出库");
typeMap.put("500", "空容器入库");
typeMap.put("600", "空容器出库");
typeMap.put("700", "盘点");
typeMap.put("800", "移库");
typeMap.put("900", "出库查看");
typeMap.put("1000", "换站");
typeMap.put("1100", "空托盘组入库");
typeMap.put("1200", "空托盘组出库");
typeMap.put("1300", "空托盘组换站");
HashMap<String, String> statusMap = new HashMap<>();
statusMap.put("1", "生成任务");
statusMap.put("10", "下发任务");
statusMap.put("50", "到达拣选台");
statusMap.put("100", "任务完成");
List<Integer> taskTypes = new ArrayList<>();
// 只显示补充入库、整盘出库、分拣出库、出库查看
taskTypes.add(QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT);
taskTypes.add(QuantityConstant.TASK_TYPE_WHOLESHIPMENT);
taskTypes.add(QuantityConstant.TASK_TYPE_SORTINGSHIPMENT);
taskTypes.add(QuantityConstant.TASK_TYPE_VIEW);
LambdaQueryWrapper<TaskHeader> hQuery = Wrappers.lambdaQuery();
// hQuery.eq(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_ARRIVED_STATION)
hQuery.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED).in(TaskHeader::getTaskType, taskTypes)
.in(stationList.size() > 0, TaskHeader::getPort, stationList);
List<TaskHeader> headers = taskHeaderService.list(hQuery);
List results = new ArrayList<>();
for (TaskHeader header : headers) {
header.setUserDef1(typeMap.get(String.valueOf(header.getTaskType())));
header.setUserDef2(statusMap.get(String.valueOf(header.getStatus())));
TvTaskVo vo = new TvTaskVo();
LambdaQueryWrapper<TaskDetail> dQuery = Wrappers.lambdaQuery();
dQuery.eq(TaskDetail::getTaskId, header.getId());
List<TaskDetail> details = taskDetailService.list(dQuery);
if (details.size() > 0) {
for (TaskDetail taskDetail : details) {
taskDetail.setCreatedBy(header.getCreatedBy());
}
}
vo.setTaskHeader(header);
vo.setTaskDetailList(details);
results.add(vo);
}
return AjaxResult.success(results);
}
@ResponseBody
@CrossOrigin
@GetMapping("/getManagementInformation")
public Result getManagementInformation() {
ManagementInformationVo managementInformationVo = new ManagementInformationVo();
// 获取所有立库库存
LambdaQueryWrapper<InventoryDetail> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(InventoryDetail::getZoneCode, QuantityConstant.ZONE_LK);
List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(queryWrapper);
// 1、批次统计
List<ManagementInformationBatchVo> batchVoList = new ArrayList<>();
// 根据批次分组
Map<String, List<InventoryDetail>> invGroupByBatchMap = inventoryDetailList.stream().collect(Collectors.groupingBy(InventoryDetail::getUserDef2));
for (Map.Entry<String, List<InventoryDetail>> entry : invGroupByBatchMap.entrySet()) {
String batch = entry.getKey();
List<InventoryDetail> invDetailList = entry.getValue();
// 求和
BigDecimal qtySum = invDetailList.stream().map(InventoryDetail::getQty).reduce(BigDecimal.ZERO, BigDecimal::add);
// 组装数据
ManagementInformationBatchVo batchVo = new ManagementInformationBatchVo();
batchVo.setBatch(batch);
batchVo.setQty(qtySum);
batchVoList.add(batchVo);
}
managementInformationVo.setBatchVoList(batchVoList);
// 2、分类统计
List<String> typeList = Arrays.asList("CP", "BCP", "GZ", "MP");
ManagementInformationTypeBatchVo typeBatchVo = new ManagementInformationTypeBatchVo();
List<ManagementInformationProjectNoMaterialVo> projectNoMaterialVoList = new ArrayList<>();
// 根据物料类别分组
Map<String, List<InventoryDetail>> invGroupByTypeMap = inventoryDetailList.stream().collect(Collectors.groupingBy(x -> {
Material material = materialService.getMaterialByCode(x.getMaterialCode());
return material.getType();
}));
List<ManagementInformationTypeVo> typeVoList = new ArrayList<>();
for (Map.Entry<String, List<InventoryDetail>> entry : invGroupByTypeMap.entrySet()) {
String type = entry.getKey();
if (!typeList.contains(type)) {
continue;
}
List<InventoryDetail> invDetailList = entry.getValue();
MaterialType materialType = materialTypeService.getByCode(type);
// 求和
BigDecimal qtySum = invDetailList.stream().map(InventoryDetail::getQty).reduce(BigDecimal.ZERO, BigDecimal::add);
// 组装数据
ManagementInformationTypeVo typeVo = new ManagementInformationTypeVo();
typeVo.setQty(qtySum);
typeVo.setType(materialType.getName());
typeVoList.add(typeVo);
// 3、分类批次统计
// 再根据批次分组
List<ManagementInformationBatchVo> batchVoList2 = new ArrayList<>();
Map<String, List<InventoryDetail>> invGroupByTypeBatchMap = invDetailList.stream().collect(Collectors.groupingBy(InventoryDetail::getUserDef2));
for (Map.Entry<String, List<InventoryDetail>> entry2 : invGroupByTypeBatchMap.entrySet()) {
String batch = entry2.getKey();
List<InventoryDetail> inventoryDetailList2 = entry2.getValue();
// 求和
BigDecimal qtySum2 = inventoryDetailList2.stream().map(InventoryDetail::getQty).reduce(BigDecimal.ZERO, BigDecimal::add);
// 组装数据
ManagementInformationBatchVo batchVo = new ManagementInformationBatchVo();
batchVo.setBatch(batch);
batchVo.setQty(qtySum2);
batchVoList2.add(batchVo);
// 4、班组产品统计
// 只统计 成品 和 半成品
if ("CP".equals(type) || "BCP".equals(type)) {
// 再根据班组、物料分组
Map<String, List<InventoryDetail>> invGroupByTypeBatchProjectNoMaterialCodeMap =
inventoryDetailList2.stream().collect(Collectors.groupingBy(inv -> inv.getProjectNo() + StringUtils.SEPARATOR + inv.getMaterialCode() + StringUtils.SEPARATOR + inv.getUserDef8()));
for (Map.Entry<String, List<InventoryDetail>> entry3 : invGroupByTypeBatchProjectNoMaterialCodeMap.entrySet()) {
String projectNoMaterialCode = entry3.getKey();
List<InventoryDetail> inventoryDetailList3 = entry3.getValue();
// 求和
BigDecimal qtySum3 = inventoryDetailList3.stream().map(InventoryDetail::getQty).reduce(BigDecimal.ZERO, BigDecimal::add);
// 组装数据
ManagementInformationProjectNoMaterialVo projectNoMaterialVo = new ManagementInformationProjectNoMaterialVo();
projectNoMaterialVo.setMaterialName(inventoryDetailList3.get(0).getMaterialName());
// 班组转换 1 -> 一班,2 -> 二班 ......
String projectNo1 = projectNoMaterialCode.split(String.valueOf(StringUtils.SEPARATOR))[0];
List<DictData> dictDataList = dictDataService.selectDictDataByType("team_group");
DictData dictData = dictDataList.stream().
filter(data -> data.getDictValue().equals(projectNo1))
.findFirst().orElse(null);
projectNoMaterialVo.setProjectNo(dictData == null ? projectNo1 : dictData.getDictLabel());
projectNoMaterialVo.setBatch(batch);
projectNoMaterialVo.setQty(qtySum3);
projectNoMaterialVo.setMaterialType(materialType.getName());
// 类型、工序 用"/"拼接返回
String process = materialType.getName() +
(StringUtils.isEmpty(projectNoMaterialCode.split(String.valueOf(StringUtils.SEPARATOR), -1)[2]) ? "" : "/" + projectNoMaterialCode.split(String.valueOf(StringUtils.SEPARATOR), -1)[2]);
projectNoMaterialVo.setProcess(process);
projectNoMaterialVoList.add(projectNoMaterialVo);
}
}
}
switch (type) {
case "CP":
typeBatchVo.setCpList(batchVoList2);
break;
case "BCP":
typeBatchVo.setBcpList(batchVoList2);
break;
case "GZ":
typeBatchVo.setGzList(batchVoList2);
break;
case "MP":
typeBatchVo.setMpList(batchVoList2);
break;
default:
break;
}
}
managementInformationVo.setTypeBatchVo(typeBatchVo);
managementInformationVo.setTypeVoList(typeVoList);
// 半成品、成品 各取20条数量最多的
Map<String, List<ManagementInformationProjectNoMaterialVo>> projectNoMaterialMap = projectNoMaterialVoList.stream()
.collect(Collectors.groupingBy(ManagementInformationProjectNoMaterialVo::getMaterialType));
projectNoMaterialVoList = new ArrayList<>();
for (Map.Entry<String, List<ManagementInformationProjectNoMaterialVo>> entry : projectNoMaterialMap.entrySet()) {
List<ManagementInformationProjectNoMaterialVo> value = entry.getValue();
List<ManagementInformationProjectNoMaterialVo> newProjectNoMaterialVoList = value.stream().sorted(Comparator.comparing(ManagementInformationProjectNoMaterialVo::getQty)).limit(20).collect(Collectors.toList());
projectNoMaterialVoList.addAll(newProjectNoMaterialVoList);
}
managementInformationVo.setProjectNoMaterialVoList(projectNoMaterialVoList);
return Result.success(managementInformationVo);
}
}