TvSCService.java
8.85 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
package com.huaheng.api.tv.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.utils.DateUtils;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
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.domain.InventoryTransactionReport;
import com.huaheng.pc.inventory.inventoryTransaction.service.InventoryTransactionService;
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.report.excelReport.mapper.ExcelReportMapper;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class TvSCService {
@Autowired
protected RedisTemplate<String, Object> redisTemplate;
private static final Logger logger = LoggerFactory.getLogger(TvSCService.class);
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private ReceiptDetailService receiptDetailService;
@Resource
private ShipmentDetailService shipmentDetailService;
@Resource
private InventoryDetailService inventoryDetailService;
@Resource
private ReceiptHeaderService receiptHeaderService;
@Resource
private ShipmentHeaderService shipmentHeaderService;
@Resource
private InventoryTransactionService inventoryTransactionService;
@Resource
private LocationService locationService;
@Resource
ExcelReportMapper mapper;
public AjaxResult getTopData(String warehouseCode){
ArrayList<Object> result = new ArrayList<>();
LambdaQueryWrapper<InventoryTransaction> receiptLambdaQueryWrapper = Wrappers.lambdaQuery();
receiptLambdaQueryWrapper.eq(InventoryTransaction::getWarehouseCode, warehouseCode);
receiptLambdaQueryWrapper.ge(InventoryTransaction::getCreated, DateUtils.getNowPreDays("yyyy-MM-dd 00:00:00", 30));
receiptLambdaQueryWrapper.eq(InventoryTransaction::getTransactionType, QuantityConstant.INVENTORY_TRANSACTION_RECEIPT);
List<InventoryTransaction> receiptlist = inventoryTransactionService.list(receiptLambdaQueryWrapper);
LambdaQueryWrapper<InventoryTransaction> shipmentLambdaQueryWrapper = Wrappers.lambdaQuery();
shipmentLambdaQueryWrapper.eq(InventoryTransaction::getWarehouseCode, warehouseCode);
shipmentLambdaQueryWrapper.ge(InventoryTransaction::getCreated, DateUtils.getNowPreDays("yyyy-MM-dd 00:00:00", 30));
shipmentLambdaQueryWrapper.eq(InventoryTransaction::getTransactionType, QuantityConstant.INVENTORY_TRANSACTION_SHIPMENT);
List<InventoryTransaction> shipmentlist = inventoryTransactionService.list(shipmentLambdaQueryWrapper);
HashMap<String, Integer> resultMap = new HashMap<>();
List<Map<String, Object>> list=inventoryDetailService.csMaterialWarningMax(warehouseCode);
//库存预警-最大
List<Map<String, Object>> list1=inventoryDetailService.csMaterialWarningMin(warehouseCode);
//库存预警-最小
resultMap.put("warningMaterial",list.size()+list1.size());
if (CollectionUtils.isNotEmpty(receiptlist)) {
//统计receiptlist中taskQty(bigdecimal)总和
BigDecimal total = receiptlist.stream()
.map(InventoryTransaction::getTaskQty)
.reduce(BigDecimal.ZERO, BigDecimal::add);
resultMap.put("receiptNum", total.intValue());
} else {
resultMap.put("receiptNum", 0);
}
if (CollectionUtils.isNotEmpty(shipmentlist)) {
BigDecimal total = shipmentlist.stream()
.map(InventoryTransaction::getTaskQty)
.reduce(BigDecimal.ZERO, BigDecimal::add);
resultMap.put("shipmentNum", total.intValue());
} else {
resultMap.put("shipmentNum", 0);
}
LambdaQueryWrapper<Location> headerLambdaQueryWrapper = new LambdaQueryWrapper<>();
headerLambdaQueryWrapper.eq(Location::getWarehouseCode, warehouseCode);
headerLambdaQueryWrapper.eq(Location::getZoneCode, "LK");
List<Location> locationList = locationService.list(headerLambdaQueryWrapper);
if (CollectionUtils.isNotEmpty(locationList)) {
resultMap.put("locationNum", locationList.size());
//过滤locationList中containerCode为空的数据
List<Location> locationList1 = locationList.stream().filter(location -> location.getContainerCode().equals("")).collect(Collectors.toList());
resultMap.put("emptylocationNum", locationList1.size());
} else {
resultMap.put("locationNum", 0);
resultMap.put("emptylocationNum", 0);
}
LambdaQueryWrapper<InventoryDetail> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(InventoryDetail::getWarehouseCode, warehouseCode);
wrapper.eq(InventoryDetail::getZoneCode, "LK");
List<InventoryDetail> inventoryDetails = inventoryDetailService.list(wrapper);
if (CollectionUtils.isNotEmpty(inventoryDetails)) {
//统计receiptlist中taskQty(bigdecimal)总和
BigDecimal total = inventoryDetails.stream()
.map(InventoryDetail::getQty)
.reduce(BigDecimal.ZERO, BigDecimal::add);
resultMap.put("inventoryNum", total.intValue());
} else {
resultMap.put("inventoryNum", 0);
}
result.add(resultMap);
return AjaxResult.success(result);
}
public AjaxResult taskOfWeek(String warehouseCode) {
String startTime= DateUtils.getNowPreDays("yyyy-MM-dd", 8);
String endTime= DateUtils.getNowPreDays("yyyy-MM-dd", 1);
String endTimes=endTime+" 23:59:59";
String zoneCodes="LK";
List<Map<String, Object>> shipmentList=taskHeaderService.tvTaskHistoryDetail(startTime,endTimes,warehouseCode,zoneCodes,QuantityConstant.TASK_INTENERTYPE_SHIPMENT,null);
List<Map<String, Object>> receiptList=taskHeaderService.tvTaskHistoryDetail(startTime,endTimes,warehouseCode,zoneCodes,QuantityConstant.TASK_INTENERTYPE_RECEIPT,null);
List<LocalDate> datelist=DateUtils.getDayList(startTime,endTime);
HashMap<String, Map<String, Object>> resultMap = new HashMap<>();
Map<String, Object> shipmentResult=new HashMap<>();
Map<String, Object> receiptResult=new HashMap<>();
for (int a=0;a<datelist.size();a++){
String days=datelist.get(a).toString();
Map<String, Object> map=new HashMap<>();
List<Map<String, Object>> shipmentList1 = shipmentList.stream().filter(maps -> maps.get("days").equals(days)).collect(Collectors.toList());
if(shipmentList1!=null&&shipmentList1.size()>0){
map=shipmentList1.get(0);
shipmentResult.put(days,map.get("taskNum").toString());
}else{
shipmentResult.put(days,"0");
}
List<Map<String, Object>> receiptList1 = receiptList.stream().filter(maps -> maps.get("days").equals(days)).collect(Collectors.toList());
if(receiptList1!=null&&receiptList1.size()>0){
map=receiptList1.get(0);
receiptResult.put(days,map.get("taskNum").toString());
}else{
receiptResult.put(days,"0");
}
}
resultMap.put("receipt",receiptResult);
resultMap.put("shipment",shipmentResult);
return AjaxResult.success(resultMap);
}
}