From a93fe53d6312d055fb09e115c37059fa12c64f08 Mon Sep 17 00:00:00 2001
From: lty <1179749281@qq.com>
Date: Sun, 29 Jan 2023 12:23:52 +0800
Subject: [PATCH] 库位监控后端移植

---
 huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/location/entity/Location.java                                |  18 ++++++++++++++++++
 huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/locationMonitor/controller/LocationMonitorController.java    | 194 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/locationMonitor/entity/LocationStatus.java                   |  36 ++++++++++++++++++++++++++++++++++++
 huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/locationMonitor/service/LocationMonitorService.java          |  12 ++++++++++++
 huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/locationMonitor/service/impl/LocationMonitorServiceImpl.java |  16 ++++++++++++++++
 5 files changed, 276 insertions(+), 0 deletions(-)
 create mode 100644 huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/locationMonitor/controller/LocationMonitorController.java
 create mode 100644 huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/locationMonitor/entity/LocationStatus.java
 create mode 100644 huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/locationMonitor/service/LocationMonitorService.java
 create mode 100644 huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/locationMonitor/service/impl/LocationMonitorServiceImpl.java

diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/location/entity/Location.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/location/entity/Location.java
index da5561a..e55d612 100644
--- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/location/entity/Location.java
+++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/location/entity/Location.java
@@ -4,7 +4,10 @@ import java.io.Serializable;
 import java.io.UnsupportedEncodingException;
 import java.util.Date;
 import java.math.BigDecimal;
+import java.util.List;
+
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
@@ -123,4 +126,19 @@ public class Location implements Serializable {
     /** 更新日期 */
     @ApiModelProperty(value = "更新日期")
     private Date updateTime;
+    /** 物料编码 */
+    @TableField(exist = false)
+    private List<String> materialCode;
+    /** 物料名称 */
+    @TableField(exist = false)
+    private List<String> materialName;
+    /** 批次 */
+    @TableField(exist = false)
+    private List<String> batch;
+    /** 数量 */
+    @TableField(exist = false)
+    private List<BigDecimal> qty;
+    /** 库存所在库位状态 */
+    @TableField(exist = false)
+    private String locationAttribute;
 }
diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/locationMonitor/controller/LocationMonitorController.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/locationMonitor/controller/LocationMonitorController.java
new file mode 100644
index 0000000..0962ed2
--- /dev/null
+++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/locationMonitor/controller/LocationMonitorController.java
@@ -0,0 +1,194 @@
+package org.jeecg.modules.wms.config.locationMonitor.controller;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.stream.Collectors;
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.modules.wms.config.container.entity.Container;
+import org.jeecg.modules.wms.config.container.service.IContainerService;
+import org.jeecg.modules.wms.config.location.entity.Location;
+import org.jeecg.modules.wms.config.location.service.ILocationService;
+import lombok.extern.slf4j.Slf4j;
+
+import org.jeecg.modules.wms.inventory.inventoryHeader.entity.InventoryDetail;
+import org.jeecg.modules.wms.inventory.inventoryHeader.service.IInventoryDetailService;
+import org.jeecg.modules.wms.config.locationMonitor.entity.LocationStatus;
+import org.jeecg.utils.HuahengJwtUtil;
+import org.jeecg.utils.StringUtils;
+import org.jeecg.utils.constant.QuantityConstant;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import io.swagger.annotations.Api;
+
+ /**
+ * @Description: 库存监控
+ * @Author: lty
+ * @Date:   2023/1/29
+ */
+@Api(tags="库存监控")
+@RestController
+@RequestMapping("/location/locationMonitor")
+@Slf4j
+public class LocationMonitorController{
+	@Autowired
+	private IContainerService containerService;
+	@Resource
+	private ILocationService locationService;
+	@Resource
+	private IInventoryDetailService inventoryDetailService;
+
+
+	 /**
+	  * 库存概括
+	  */
+	 @GetMapping("/getStatus")
+	 @ResponseBody
+	 public Result getStatus(String zoneCode) {
+		 HashMap<String, Integer> map = new HashMap<>();
+		 LambdaQueryWrapper<Location> queryWrapper = Wrappers.lambdaQuery();
+		 queryWrapper.eq(Location::getZoneCode,zoneCode);
+		 List<Location> locationList = locationService.list(queryWrapper);
+		 map.put("location", locationList.size());
+		 queryWrapper = Wrappers.lambdaQuery();
+		 queryWrapper.and(wrapper->wrapper.isNull(Location::getContainerCode).or().eq(Location::getContainerCode,""))
+				 .eq(Location::getZoneCode,zoneCode);
+		 List<Location> emptyLocationList = locationService.list(queryWrapper);
+		 map.put("emptyLocation", emptyLocationList.size());
+		 LambdaQueryWrapper<Container> containerLambdaQueryWrapper2 = Wrappers.lambdaQuery();
+		 containerLambdaQueryWrapper2.eq(Container::getStatus, QuantityConstant.STATUS_CONTAINER_EMPTY);
+		 List<Container> containerList2 = containerService.list(containerLambdaQueryWrapper2);
+		 List<String> containerCodeList2 = containerList2.stream().map(Container::getCode).collect(Collectors.toList());
+		 LambdaQueryWrapper<Location> locationLambdaQueryWrapper2 = Wrappers.lambdaQuery();
+		 locationLambdaQueryWrapper2.in(Location::getContainerCode, containerCodeList2);
+		 locationLambdaQueryWrapper2.eq(Location::getZoneCode, zoneCode);
+		 List<Location> haveEmptyContainLocation = locationService.list(locationLambdaQueryWrapper2);
+		 map.put("haveContainLocation", haveEmptyContainLocation.size());
+		 LambdaQueryWrapper<Container> containerLambdaQueryWrapper = Wrappers.lambdaQuery();
+		 containerLambdaQueryWrapper.eq(Container::getStatus, QuantityConstant.STATUS_CONTAINER_SOME);
+		 List<Container> containerList = containerService.list(containerLambdaQueryWrapper);
+		 int containerListSize = containerList.size();
+		 List<String> containerCodeList = containerList.stream().map(Container::getCode).collect(Collectors.toList());
+		 LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
+		 locationLambdaQueryWrapper.in(containerListSize !=0, Location::getContainerCode, containerCodeList);
+		 locationLambdaQueryWrapper.eq(Location::getZoneCode, zoneCode);
+		 List<Location> haveInventoryLocation = locationService.list(locationLambdaQueryWrapper);
+		 map.put("haveInventoryLocation", haveInventoryLocation.size());
+		 return Result.ok(map);
+	 }
+
+	 /**
+	  * 查询库位列表
+	  */
+	 @PostMapping("/getLocationInfo")
+	 @ResponseBody
+	 public Result getLocationInfo (String type, String row, String line, String layer, String grid, HttpServletRequest req) {
+		 if(StringUtils.isEmpty(type)) {
+			 return Result.error("type不能为空");
+		 }
+		 String warehouseCode = HuahengJwtUtil.getWarehouseCodeByToken(req);
+		 /* 查询库位信息*/
+		 LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
+		 locationLambdaQueryWrapper.eq(StringUtils.isNotEmpty(row), Location::getRow, row)
+				 .eq(StringUtils.isNotEmpty(line), Location::getIcolumn, line)
+				 .eq(StringUtils.isNotEmpty(layer), Location::getLayer, layer)
+				 .eq(StringUtils.isNotEmpty(grid),Location::getGrid, grid)
+				 .eq(Location::getWarehouseCode, warehouseCode)
+				 .eq(StringUtils.isNotEmpty(type), Location::getZoneCode, type);
+		 List<Location> locations = locationService.list(locationLambdaQueryWrapper);
+		 List<Location> locationList = new ArrayList<>();
+
+		 /* 查询库存明细*/
+		 LambdaQueryWrapper<InventoryDetail> inventoryDetailLambda = Wrappers.lambdaQuery();
+		 inventoryDetailLambda.eq(InventoryDetail::getWarehouseCode, warehouseCode);
+		 List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambda);
+
+		 for (Location location1 : locations) {
+			 InventoryDetail inventoryDetail = null;
+			 String materialName = null;
+			 for (InventoryDetail inventoryDetail2 : inventoryDetailList) {
+				 if(location1.getCode().equals(inventoryDetail2.getLocationCode())) {
+					 inventoryDetail = inventoryDetail2;
+				 }
+			 }
+			 List<InventoryDetail> inventoryDetails = inventoryDetailList.stream().filter(inventoryDetail1 ->
+					 inventoryDetail1.getLocationCode().equals(location1.getCode())).collect(Collectors.toList());
+
+			 int locationAttribute = 0;
+			 String status = location1.getStatus();
+			 String containerCode = location1.getContainerCode();
+			 List<String> materialNameList = inventoryDetails.stream().map(InventoryDetail::getMaterialName).collect(Collectors.toList());
+			 List<String> batchList = inventoryDetails.stream().map(InventoryDetail::getBatch).collect(Collectors.toList());
+			 List<String> materialCodeList = inventoryDetails.stream().map(InventoryDetail::getMaterialCode).collect(Collectors.toList());
+			 List<BigDecimal> qtyList = inventoryDetails.stream().map(InventoryDetail::getQty).collect(Collectors.toList());
+			 if(QuantityConstant.STATUS_LOCATION_EMPTY.equals(status)) {
+				 if(StringUtils.isEmpty(containerCode)) {
+					 locationAttribute = LocationStatus.IDLE_EMPTY_LOCATION;
+				 } else {
+					 if(inventoryDetail == null) {
+						 locationAttribute = LocationStatus.IDLE_EMPTY_CONTAINER;
+					 } else {
+						 location1.setMaterialName(materialNameList);
+						 location1.setMaterialCode(materialCodeList);
+						 location1.setBatch(batchList);
+						 location1.setQty(qtyList);
+						 locationAttribute = LocationStatus.IDLE_FULL_CONTAINER;
+					 }
+				 }
+			 } else if(QuantityConstant.STATUS_LOCATION_LOCK.equals(status)) {
+				 if(StringUtils.isEmpty(containerCode)) {
+					 locationAttribute = LocationStatus.LOCK_EMPTY_LOCATION;
+				 } else {
+					 if(inventoryDetail == null) {
+						 locationAttribute = LocationStatus.LOCK_EMPTY_CONTAINER;
+					 } else {
+						 location1.setMaterialName(materialNameList);
+						 location1.setMaterialCode(materialCodeList);
+						 location1.setBatch(batchList);
+						 location1.setQty(qtyList);
+						 locationAttribute = LocationStatus.LOCK_FULL_CONTAINER;
+					 }
+				 }
+			 }
+
+//			 if(location1.getDeleted()) {
+//				 if(StringUtils.isEmpty(containerCode)) {
+//					 locationAttribute = LocationStatus.DISABLE_EMPTY_LOCATION;
+//				 } else {
+//					 if(inventoryDetail == null) {
+//						 locationAttribute = LocationStatus.DISABLE_EMPTY_CONTAINER;
+//					 } else {
+//						 location1.setMaterialName(materialNameList);
+//						 location1.setMaterialCode(materialCodeList);
+//						 location1.setBatch(batchList);
+//						 location1.setQty(qtyList);
+//						 locationAttribute = LocationStatus.DISABLE_FULL_CONTAINER;
+//					 }
+//				 }
+//			 }
+
+			 location1.setLocationAttribute(String.valueOf(locationAttribute));
+			 locationList.add(location1);
+		 }
+		 return Result.ok(locations);
+	 }
+
+
+	 /**
+	  * 查询库位列表
+	  */
+	 @PostMapping("/getAllLocation")
+	 @ResponseBody
+	 public Result getAllLocation (String type) {
+		 if(StringUtils.isEmpty(type)) {
+			 return Result.error("type不能为空");
+		 }
+		 return Result.ok(locationService.getAllLocation(type));
+	 }
+
+ }
diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/locationMonitor/entity/LocationStatus.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/locationMonitor/entity/LocationStatus.java
new file mode 100644
index 0000000..4ecbd58
--- /dev/null
+++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/locationMonitor/entity/LocationStatus.java
@@ -0,0 +1,36 @@
+package org.jeecg.modules.wms.config.locationMonitor.entity;
+
+/**
+ *
+ * @author lty
+ * @date 2023/1/29
+ */
+public class LocationStatus {
+
+    /** 空柜丢失 */
+    public static final int IDLE_EMPTY_LOST = 0;
+    /** 空柜空闲 */
+    public static final int IDLE_EMPTY_LOCATION = 1;
+    /** 空盘空闲 */
+    public static final int IDLE_EMPTY_CONTAINER = 2;
+    /** 半盘空闲 */
+    public static final int IDLE_HALF_CONTAINER = 3;
+    /** 满盘空闲 */
+    public static final int IDLE_FULL_CONTAINER = 4;
+    /** 空柜锁定 */
+    public static final int LOCK_EMPTY_LOCATION = 5;
+    /** 空盘锁定 */
+    public static final int LOCK_EMPTY_CONTAINER = 6;
+    /** 半盘锁定 */
+    public static final int LOCK_HALF_CONTAINER = 7;
+    /** 满盘锁定 */
+    public static final int LOCK_FULL_CONTAINER = 8;
+    /** 空柜禁用 */
+    public static final int DISABLE_EMPTY_LOCATION = 9;
+    /** 空盘禁用 */
+    public static final int DISABLE_EMPTY_CONTAINER = 10;
+    /** 半盘禁用 */
+    public static final int DISABLE_HALF_CONTAINER = 11;
+    /** 满盘禁用 */
+    public static final int DISABLE_FULL_CONTAINER = 12;
+}
diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/locationMonitor/service/LocationMonitorService.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/locationMonitor/service/LocationMonitorService.java
new file mode 100644
index 0000000..aa08e79
--- /dev/null
+++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/locationMonitor/service/LocationMonitorService.java
@@ -0,0 +1,12 @@
+package org.jeecg.modules.wms.config.locationMonitor.service;
+
+
+/**
+ * @Description: 库存交易记录
+ * @Author: jeecg-boot
+ * @Date:   2022-11-17
+ * @Version: V1.0
+ */
+public interface LocationMonitorService {
+
+}
diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/locationMonitor/service/impl/LocationMonitorServiceImpl.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/locationMonitor/service/impl/LocationMonitorServiceImpl.java
new file mode 100644
index 0000000..8041236
--- /dev/null
+++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/locationMonitor/service/impl/LocationMonitorServiceImpl.java
@@ -0,0 +1,16 @@
+package org.jeecg.modules.wms.config.locationMonitor.service.impl;
+
+
+import org.jeecg.modules.wms.config.locationMonitor.service.LocationMonitorService;
+import org.springframework.stereotype.Service;
+
+/**
+ * @Description: 库存交易记录
+ * @Author: jeecg-boot
+ * @Date:   2022-11-17
+ * @Version: V1.0
+ */
+@Service
+public class LocationMonitorServiceImpl implements LocationMonitorService {
+
+}
--
libgit2 0.22.2