Commit cd858e5f444040711795646fadbcee4de26539a8

Authored by 谭毅彬
2 parents e8833f85 3ef07daa

Merge branch 'develop4' of http://172.16.29.40:8010/wms/wms4.git into develop4

huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/locationMonitor/controller/LocationMonitorController.java
1 package org.jeecg.modules.wms.config.locationMonitor.controller; 1 package org.jeecg.modules.wms.config.locationMonitor.controller;
  2 +
2 import java.math.BigDecimal; 3 import java.math.BigDecimal;
3 import java.util.ArrayList; 4 import java.util.ArrayList;
4 import java.util.HashMap; 5 import java.util.HashMap;
5 import java.util.List; 6 import java.util.List;
6 import java.util.stream.Collectors; 7 import java.util.stream.Collectors;
  8 +import java.util.stream.Stream;
7 import javax.annotation.Resource; 9 import javax.annotation.Resource;
8 import javax.servlet.http.HttpServletRequest; 10 import javax.servlet.http.HttpServletRequest;
9 11
@@ -26,169 +28,147 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -26,169 +28,147 @@ import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.web.bind.annotation.*; 28 import org.springframework.web.bind.annotation.*;
27 import io.swagger.annotations.Api; 29 import io.swagger.annotations.Api;
28 30
29 - /** 31 +/**
30 * @Description: 库存监控 32 * @Description: 库存监控
31 * @Author: lty 33 * @Author: lty
32 - * @Date: 2023/1/29 34 + * @Date: 2023/1/29
33 */ 35 */
34 -@Api(tags="库存监控") 36 +@Api(tags = "库存监控")
35 @RestController 37 @RestController
36 @RequestMapping("/location/locationMonitor") 38 @RequestMapping("/location/locationMonitor")
37 @Slf4j 39 @Slf4j
38 -public class LocationMonitorController{  
39 - @Autowired  
40 - private IContainerService containerService;  
41 - @Resource  
42 - private ILocationService locationService;  
43 - @Resource  
44 - private IInventoryDetailService inventoryDetailService; 40 +public class LocationMonitorController {
  41 + @Autowired
  42 + private IContainerService containerService;
  43 + @Resource
  44 + private ILocationService locationService;
  45 + @Resource
  46 + private IInventoryDetailService inventoryDetailService;
45 47
46 48
47 - /**  
48 - * 库存概括  
49 - */  
50 - @GetMapping("/getStatus")  
51 - @ResponseBody  
52 - public Result getStatus(String zoneCode) {  
53 - HashMap<String, Integer> map = new HashMap<>();  
54 - LambdaQueryWrapper<Location> queryWrapper = Wrappers.lambdaQuery();  
55 - queryWrapper.eq(Location::getZoneCode,zoneCode);  
56 - List<Location> locationList = locationService.list(queryWrapper);  
57 - map.put("location", locationList.size());  
58 - queryWrapper = Wrappers.lambdaQuery();  
59 - queryWrapper.and(wrapper->wrapper.isNull(Location::getContainerCode).or().eq(Location::getContainerCode,""))  
60 - .eq(Location::getZoneCode,zoneCode);  
61 - List<Location> emptyLocationList = locationService.list(queryWrapper);  
62 - map.put("emptyLocation", emptyLocationList.size());  
63 - LambdaQueryWrapper<Container> containerLambdaQueryWrapper2 = Wrappers.lambdaQuery();  
64 - containerLambdaQueryWrapper2.eq(Container::getStatus, QuantityConstant.STATUS_CONTAINER_EMPTY);  
65 - List<Container> containerList2 = containerService.list(containerLambdaQueryWrapper2);  
66 - List<String> containerCodeList2 = containerList2.stream().map(Container::getCode).collect(Collectors.toList());  
67 - LambdaQueryWrapper<Location> locationLambdaQueryWrapper2 = Wrappers.lambdaQuery();  
68 - locationLambdaQueryWrapper2.in(Location::getContainerCode, containerCodeList2);  
69 - locationLambdaQueryWrapper2.eq(Location::getZoneCode, zoneCode);  
70 - List<Location> haveEmptyContainLocation = locationService.list(locationLambdaQueryWrapper2);  
71 - map.put("haveContainLocation", haveEmptyContainLocation.size());  
72 - LambdaQueryWrapper<Container> containerLambdaQueryWrapper = Wrappers.lambdaQuery();  
73 - containerLambdaQueryWrapper.eq(Container::getStatus, QuantityConstant.STATUS_CONTAINER_SOME);  
74 - List<Container> containerList = containerService.list(containerLambdaQueryWrapper);  
75 - int containerListSize = containerList.size();  
76 - List<String> containerCodeList = containerList.stream().map(Container::getCode).collect(Collectors.toList());  
77 - LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();  
78 - locationLambdaQueryWrapper.in(containerListSize !=0, Location::getContainerCode, containerCodeList);  
79 - locationLambdaQueryWrapper.eq(Location::getZoneCode, zoneCode);  
80 - List<Location> haveInventoryLocation = locationService.list(locationLambdaQueryWrapper);  
81 - map.put("haveInventoryLocation", haveInventoryLocation.size());  
82 - return Result.ok(map);  
83 - } 49 + /**
  50 + * 库存概括
  51 + */
  52 + @GetMapping("/getStatus")
  53 + @ResponseBody
  54 + public Result getStatus(String zoneCode) {
  55 + HashMap<String, Integer> map = new HashMap<>();
  56 + LambdaQueryWrapper<Location> queryWrapper = Wrappers.lambdaQuery();
  57 + queryWrapper.select(Location::getStatus,Location::getContainerCode).eq(Location::getZoneCode, zoneCode);
  58 + List<Location> locationList = locationService.list(queryWrapper);
  59 + map.put("location", locationList.size());
  60 + //换stream进行数据拣选速度更快
  61 + List<Location> emptyLocationList = locationList.stream().filter(
  62 + t -> StringUtils.isEmpty(t.getContainerCode())).collect(Collectors.toList());
  63 + map.put("emptyLocation", emptyLocationList.size());
  64 + LambdaQueryWrapper<Container> containerLambdaQueryWrapper = Wrappers.lambdaQuery();
  65 + containerLambdaQueryWrapper.select(Container::getCode, Container::getStatus);
  66 + List<Container> containerList = containerService.list();
  67 + List<String> containerCodeList = containerList.stream().filter(t -> t.getStatus().equals(QuantityConstant.STATUS_CONTAINER_EMPTY)).map(Container::getCode).collect(Collectors.toList());
  68 + List<Location> haveEmptyContainLocation = locationList.stream().filter(
  69 + t -> t.getStatus().equals(QuantityConstant.STATUS_CONTAINER_EMPTY) && StringUtils.isNotEmpty(t.getContainerCode())
  70 + && containerCodeList.contains(t.getContainerCode())).collect(Collectors.toList());
  71 + map.put("haveContainLocation", haveEmptyContainLocation.size());
  72 + List<String> containerCodeList1 = containerList.stream().filter(t -> t.getStatus().equals(QuantityConstant.STATUS_CONTAINER_SOME)).map(Container::getCode).collect(Collectors.toList());
  73 + List<Location> haveInventoryLocationList = locationList.stream().filter(
  74 + t -> t.getStatus().equals(QuantityConstant.STATUS_CONTAINER_EMPTY) && StringUtils.isNotEmpty(t.getContainerCode())
  75 + && containerCodeList1.contains(t.getContainerCode())).collect(Collectors.toList());
  76 + map.put("haveInventoryLocation", haveInventoryLocationList.size());
  77 + return Result.ok(map);
  78 + }
84 79
85 - /**  
86 - * 查询库位列表  
87 - */  
88 - @PostMapping("/getLocationInfo")  
89 - @ResponseBody  
90 - public Result getLocationInfo (String type, String row, String line, String layer, String grid, HttpServletRequest req) {  
91 - if(StringUtils.isEmpty(type)) {  
92 - return Result.error("type不能为空");  
93 - }  
94 - String warehouseCode = HuahengJwtUtil.getWarehouseCodeByToken(req);  
95 - /* 查询库位信息*/  
96 - LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();  
97 - locationLambdaQueryWrapper.eq(StringUtils.isNotEmpty(row), Location::getRow, row)  
98 - .eq(StringUtils.isNotEmpty(line), Location::getIcolumn, line)  
99 - .eq(StringUtils.isNotEmpty(layer), Location::getLayer, layer)  
100 - .eq(StringUtils.isNotEmpty(grid),Location::getGrid, grid)  
101 - .eq(Location::getWarehouseCode, warehouseCode)  
102 - .eq(StringUtils.isNotEmpty(type), Location::getZoneCode, type);  
103 - List<Location> locations = locationService.list(locationLambdaQueryWrapper);  
104 - List<Location> locationList = new ArrayList<>(); 80 + /**
  81 + * 查询库位列表
  82 + */
  83 + @PostMapping("/getLocationInfo")
  84 + @ResponseBody
  85 + public Result getLocationInfo(String type, String row, String line, String layer, String grid, HttpServletRequest req) {
  86 + if (StringUtils.isEmpty(type)) {
  87 + return Result.error("type不能为空");
  88 + }
  89 + String warehouseCode = HuahengJwtUtil.getWarehouseCodeByToken(req);
  90 + /* 查询库位信息*/
  91 + LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
  92 + locationLambdaQueryWrapper.eq(StringUtils.isNotEmpty(row), Location::getRow, row)
  93 + .eq(StringUtils.isNotEmpty(line), Location::getIcolumn, line)
  94 + .eq(StringUtils.isNotEmpty(layer), Location::getLayer, layer)
  95 + .eq(StringUtils.isNotEmpty(grid), Location::getGrid, grid)
  96 + .eq(Location::getWarehouseCode, warehouseCode)
  97 + .eq(StringUtils.isNotEmpty(type), Location::getZoneCode, type);
  98 + List<Location> locations = locationService.list(locationLambdaQueryWrapper);
  99 + List<Location> locationList = new ArrayList<>();
105 100
106 - /* 查询库存明细*/  
107 - LambdaQueryWrapper<InventoryDetail> inventoryDetailLambda = Wrappers.lambdaQuery();  
108 - inventoryDetailLambda.eq(InventoryDetail::getWarehouseCode, warehouseCode);  
109 - List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambda); 101 + /* 查询库存明细*/
  102 + LambdaQueryWrapper<InventoryDetail> inventoryDetailLambda = Wrappers.lambdaQuery();
  103 + inventoryDetailLambda.eq(InventoryDetail::getWarehouseCode, warehouseCode);
  104 + List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambda);
110 105
111 - for (Location location1 : locations) {  
112 - InventoryDetail inventoryDetail = null;  
113 - String materialName = null;  
114 - for (InventoryDetail inventoryDetail2 : inventoryDetailList) {  
115 - if(location1.getCode().equals(inventoryDetail2.getLocationCode())) {  
116 - inventoryDetail = inventoryDetail2;  
117 - }  
118 - }  
119 - List<InventoryDetail> inventoryDetails = inventoryDetailList.stream().filter(inventoryDetail1 ->  
120 - inventoryDetail1.getLocationCode().equals(location1.getCode())).collect(Collectors.toList()); 106 + for (Location location1 : locations) {
  107 + InventoryDetail inventoryDetail = null;
  108 + String materialName = null;
  109 + for (InventoryDetail inventoryDetail2 : inventoryDetailList) {
  110 + if (location1.getCode().equals(inventoryDetail2.getLocationCode())) {
  111 + inventoryDetail = inventoryDetail2;
  112 + }
  113 + }
  114 + List<InventoryDetail> inventoryDetails = inventoryDetailList.stream().filter(inventoryDetail1 ->
  115 + inventoryDetail1.getLocationCode().equals(location1.getCode())).collect(Collectors.toList());
121 116
122 - int locationAttribute = 0;  
123 - String status = location1.getStatus();  
124 - String containerCode = location1.getContainerCode();  
125 - List<String> materialNameList = inventoryDetails.stream().map(InventoryDetail::getMaterialName).collect(Collectors.toList());  
126 - List<String> batchList = inventoryDetails.stream().map(InventoryDetail::getBatch).collect(Collectors.toList());  
127 - List<String> materialCodeList = inventoryDetails.stream().map(InventoryDetail::getMaterialCode).collect(Collectors.toList());  
128 - List<BigDecimal> qtyList = inventoryDetails.stream().map(InventoryDetail::getQty).collect(Collectors.toList());  
129 - if(QuantityConstant.STATUS_LOCATION_EMPTY.equals(status)) {  
130 - if(StringUtils.isEmpty(containerCode)) {  
131 - locationAttribute = LocationStatus.IDLE_EMPTY_LOCATION;  
132 - } else {  
133 - if(inventoryDetail == null) {  
134 - locationAttribute = LocationStatus.IDLE_EMPTY_CONTAINER;  
135 - } else {  
136 - location1.setMaterialName(materialNameList);  
137 - location1.setMaterialCode(materialCodeList);  
138 - location1.setBatch(batchList);  
139 - location1.setQty(qtyList);  
140 - locationAttribute = LocationStatus.IDLE_FULL_CONTAINER;  
141 - }  
142 - }  
143 - } else if(QuantityConstant.STATUS_LOCATION_LOCK.equals(status)) {  
144 - if(StringUtils.isEmpty(containerCode)) {  
145 - locationAttribute = LocationStatus.LOCK_EMPTY_LOCATION;  
146 - } else {  
147 - if(inventoryDetail == null) {  
148 - locationAttribute = LocationStatus.LOCK_EMPTY_CONTAINER;  
149 - } else {  
150 - location1.setMaterialName(materialNameList);  
151 - location1.setMaterialCode(materialCodeList);  
152 - location1.setBatch(batchList);  
153 - location1.setQty(qtyList);  
154 - locationAttribute = LocationStatus.LOCK_FULL_CONTAINER;  
155 - }  
156 - }  
157 - } 117 + int locationAttribute = 0;
  118 + String status = location1.getStatus();
  119 + String containerCode = location1.getContainerCode();
  120 + List<String> materialNameList = inventoryDetails.stream().map(InventoryDetail::getMaterialName).collect(Collectors.toList());
  121 + List<String> batchList = inventoryDetails.stream().map(InventoryDetail::getBatch).collect(Collectors.toList());
  122 + List<String> materialCodeList = inventoryDetails.stream().map(InventoryDetail::getMaterialCode).collect(Collectors.toList());
  123 + List<BigDecimal> qtyList = inventoryDetails.stream().map(InventoryDetail::getQty).collect(Collectors.toList());
  124 + if (QuantityConstant.STATUS_LOCATION_EMPTY.equals(status)) {
  125 + if (StringUtils.isEmpty(containerCode)) {
  126 + locationAttribute = LocationStatus.IDLE_EMPTY_LOCATION;
  127 + } else {
  128 + if (inventoryDetail == null) {
  129 + locationAttribute = LocationStatus.IDLE_EMPTY_CONTAINER;
  130 + } else {
  131 + location1.setMaterialName(materialNameList);
  132 + location1.setMaterialCode(materialCodeList);
  133 + location1.setBatch(batchList);
  134 + location1.setQty(qtyList);
  135 + locationAttribute = LocationStatus.IDLE_FULL_CONTAINER;
  136 + }
  137 + }
  138 + } else if (QuantityConstant.STATUS_LOCATION_LOCK.equals(status)) {
  139 + if (StringUtils.isEmpty(containerCode)) {
  140 + locationAttribute = LocationStatus.LOCK_EMPTY_LOCATION;
  141 + } else {
  142 + if (inventoryDetail == null) {
  143 + locationAttribute = LocationStatus.LOCK_EMPTY_CONTAINER;
  144 + } else {
  145 + location1.setMaterialName(materialNameList);
  146 + location1.setMaterialCode(materialCodeList);
  147 + location1.setBatch(batchList);
  148 + location1.setQty(qtyList);
  149 + locationAttribute = LocationStatus.LOCK_FULL_CONTAINER;
  150 + }
  151 + }
  152 + }
158 153
159 -// if(location1.getDeleted()) {  
160 -// if(StringUtils.isEmpty(containerCode)) {  
161 -// locationAttribute = LocationStatus.DISABLE_EMPTY_LOCATION;  
162 -// } else {  
163 -// if(inventoryDetail == null) {  
164 -// locationAttribute = LocationStatus.DISABLE_EMPTY_CONTAINER;  
165 -// } else {  
166 -// location1.setMaterialName(materialNameList);  
167 -// location1.setMaterialCode(materialCodeList);  
168 -// location1.setBatch(batchList);  
169 -// location1.setQty(qtyList);  
170 -// locationAttribute = LocationStatus.DISABLE_FULL_CONTAINER;  
171 -// }  
172 -// }  
173 -// }  
174 154
175 - location1.setLocationAttribute(String.valueOf(locationAttribute));  
176 - locationList.add(location1);  
177 - }  
178 - return Result.ok(locations);  
179 - } 155 + location1.setLocationAttribute(String.valueOf(locationAttribute));
  156 + locationList.add(location1);
  157 + }
  158 + return Result.ok(locations);
  159 + }
180 160
181 161
182 - /**  
183 - * 查询库位列表  
184 - */  
185 - @PostMapping("/getAllLocation")  
186 - @ResponseBody  
187 - public Result getAllLocation (@RequestParam(name = "type")String type) {  
188 - if(StringUtils.isEmpty(type)) {  
189 - return Result.error("type不能为空");  
190 - }  
191 - return Result.ok(locationService.getAllLocation(type));  
192 - } 162 + /**
  163 + * 查询库位列表
  164 + */
  165 + @PostMapping("/getAllLocation")
  166 + @ResponseBody
  167 + public Result getAllLocation(@RequestParam(name = "type") String type) {
  168 + if (StringUtils.isEmpty(type)) {
  169 + return Result.error("type不能为空");
  170 + }
  171 + return Result.ok(locationService.getAllLocation(type));
  172 + }
193 173
194 - } 174 +}