From f95d05316d49bcdd31d022a11d0fc4fbafb040da Mon Sep 17 00:00:00 2001
From: cuilei <ray_tsu1@163.com>
Date: 星期一, 08 九月 2025 11:40:01 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 src/main/java/org/jeecg/modules/lsw/service/impl/LswMaterialInboundServiceImpl.java |  123 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 122 insertions(+), 1 deletions(-)

diff --git a/src/main/java/org/jeecg/modules/lsw/service/impl/LswMaterialInboundServiceImpl.java b/src/main/java/org/jeecg/modules/lsw/service/impl/LswMaterialInboundServiceImpl.java
index 9acc70f..6f444f9 100644
--- a/src/main/java/org/jeecg/modules/lsw/service/impl/LswMaterialInboundServiceImpl.java
+++ b/src/main/java/org/jeecg/modules/lsw/service/impl/LswMaterialInboundServiceImpl.java
@@ -1,18 +1,139 @@
 package org.jeecg.modules.lsw.service.impl;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.apache.commons.lang.StringUtils;
+import org.jeecg.common.constant.CommonConstant;
+import org.jeecg.common.exception.JeecgBootException;
+import org.jeecg.modules.base.entity.LineSideWarehouse;
+import org.jeecg.modules.base.service.ILineSideWarehouseService;
+import org.jeecg.modules.lsw.entity.LswMaterial;
 import org.jeecg.modules.lsw.entity.LswMaterialInbound;
+import org.jeecg.modules.lsw.entity.LswMaterialInventory;
+import org.jeecg.modules.lsw.entity.LswMaterialOutbound;
+import org.jeecg.modules.lsw.enums.MaterialInboundCategory;
+import org.jeecg.modules.lsw.enums.MaterialInventoryCategoryEnum;
+import org.jeecg.modules.lsw.enums.MaterialOutboundCategory;
 import org.jeecg.modules.lsw.mapper.LswMaterialInboundMapper;
 import org.jeecg.modules.lsw.service.ILswMaterialInboundService;
+import org.jeecg.modules.lsw.service.ILswMaterialInventoryService;
+import org.jeecg.modules.lsw.service.ILswMaterialOutboundService;
+import org.jeecg.modules.lsw.service.ILswMaterialService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * @Description: 鐗╂枡鍏ュ簱鍗�
  * @Author: jeecg-boot
- * @Date:   2025-06-30
+ * @Date: 2025-06-30
  * @Version: V1.0
  */
 @Service
 public class LswMaterialInboundServiceImpl extends ServiceImpl<LswMaterialInboundMapper, LswMaterialInbound> implements ILswMaterialInboundService {
+    @Autowired
+    private ILswMaterialInventoryService inventoryService;
+    @Autowired
+    private ILswMaterialService materialService;
+    @Autowired
+    private ILineSideWarehouseService lineSideWarehouseService;
+    @Autowired
+    private ILswMaterialOutboundService materialOutboundService;
 
+    @Override
+    public IPage<Map<String, Object>> getlswMaterialInboundListData(Integer pageNo, Integer pageSize, HttpServletRequest req) {
+        IPage<Map> pageData = new Page<Map>(pageNo, pageSize);
+        Map<String, String> paramMap = new HashMap<String, String>();
+        Map<String, String[]> parameterMap = req.getParameterMap();
+        if (null != parameterMap) {
+            if (parameterMap.containsKey("materialNumber") && StringUtils.isNotBlank(parameterMap.get("materialNumber")[0])) {
+                paramMap.put("materialNumber", parameterMap.get("materialNumber")[0]);
+            }
+            if (parameterMap.containsKey("materialName") && StringUtils.isNotBlank(parameterMap.get("materialName")[0])) {
+                paramMap.put("materialName", parameterMap.get("materialName")[0].trim());
+            }
+            if (parameterMap.containsKey("batchNumber") && StringUtils.isNotBlank(parameterMap.get("batchNumber")[0])) {
+                paramMap.put("batchNumber", parameterMap.get("batchNumber")[0].trim());
+            }
+        }
+        return super.getBaseMapper().getlswMaterialInboundListData(pageData, paramMap);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean inboundMaterial(LswMaterialInbound materialInbound) {
+        if (StringUtils.isBlank(materialInbound.getMaterialNumber())
+                || StringUtils.isBlank(materialInbound.getFactoryId())
+                || StringUtils.isBlank(materialInbound.getWarehouseId())
+                || materialInbound.getQuantity() == null
+                || materialInbound.getQuantity().intValue() < 1
+                || StringUtils.isBlank(materialInbound.getBatchNumber())
+                || StringUtils.isBlank(materialInbound.getOriginalCode())
+                || StringUtils.isBlank(materialInbound.getOriginalName())
+                || StringUtils.isBlank(materialInbound.getInboundCategory())) {
+            throw new JeecgBootException("鍙傛暟閿欒锛�");
+        }
+        LswMaterial material = materialService.queryByMaterialNumber(materialInbound.getMaterialNumber());
+        if (material == null) {
+            throw new JeecgBootException("鐗╂枡缂栧彿涓嶅瓨鍦紒");
+        }
+        LineSideWarehouse warehouse = lineSideWarehouseService.getById(materialInbound.getWarehouseId());
+        if (warehouse == null) {
+            throw new JeecgBootException("绾胯竟搴撲笉瀛樺湪锛�");
+        }
+        String heatTreatmentFlag = CommonConstant.STATUS_0;
+        if (materialInbound.getInboundCategory().equals(MaterialInboundCategory.HEAT_TREATMENT_INBOUND.name())) {
+            heatTreatmentFlag = CommonConstant.STATUS_1;
+        }
+        //搴撳瓨绫诲瀷
+        String inventoryCategory = MaterialInventoryCategoryEnum.INBOUND.name();
+        if (materialInbound.getInboundCategory().equals(MaterialInboundCategory.MATERIAL_INNER_TRANSFER.name())) {
+            inventoryCategory = MaterialInventoryCategoryEnum.TRANSFER.name();
+            //鏌ヨ鏉ユ簮绾胯竟搴�
+            LineSideWarehouse lineSideWarehouse = lineSideWarehouseService.queryByWarehouseCode(materialInbound.getOriginalCode());
+            if (lineSideWarehouse == null) {
+                throw new JeecgBootException("鏈壘鍒版潵婧愮嚎杈瑰簱锛�");
+            }
+            //璋冩嫧 鍑哄簱鍘熷搴撳瓨
+            LswMaterialInventory originalInventory = inventoryService.queryByMaterialNumberAndBatchNumber(materialInbound.getMaterialNumber(), materialInbound.getBatchNumber(), lineSideWarehouse.getId());
+            if (originalInventory == null) {
+                throw new JeecgBootException("鏈壘鍒版潵婧愮嚎杈瑰簱搴撳瓨锛�");
+            }
+            if (materialInbound.getQuantity().compareTo(originalInventory.getQuantity()) != 0) {
+                throw new JeecgBootException("璋冩嫧鏁伴噺闇�瑕佺瓑浜庢潵婧愬簱瀛樻暟閲忥紒");
+            }
+            //鍑哄簱淇℃伅
+            LswMaterialOutbound outbound = new LswMaterialOutbound();
+            outbound.setWarehouseId(lineSideWarehouse.getId());
+            outbound.setFactoryId(lineSideWarehouse.getFactoryId());
+            outbound.setOutboundStaff(materialInbound.getReceiver());
+            outbound.setMaterialName(materialInbound.getMaterialName());
+            outbound.setMaterialNumber(materialInbound.getMaterialNumber());
+            outbound.setQuantity(originalInventory.getQuantity());
+            outbound.setBatchNumber(originalInventory.getBatchNumber());
+            outbound.setInventoryId(originalInventory.getId());
+            outbound.setOutboundCategory(MaterialOutboundCategory.MATERIAL_INNER_TRANSFER.name());
+            //璋冩嫧鍑哄簱
+            boolean b = materialOutboundService.outboundMaterial(outbound);
+            if (!b) {
+                throw new JeecgBootException("璋冩嫧鍑哄簱澶辫触锛�");
+            }
+        } else if (materialInbound.getInboundCategory().equals(MaterialInboundCategory.PRODUCTION_UNLOADING.name())) {
+            inventoryCategory = MaterialInventoryCategoryEnum.UNLOADING.name();
+        }
+        //淇濆瓨鍏ュ簱淇℃伅
+        materialInbound.setDelFlag(CommonConstant.DEL_FLAG_0);
+        materialInbound.setReceiveTime(new Date());
+        super.save(materialInbound);
+        //淇濆瓨搴撳瓨淇℃伅
+        LswMaterialInventory lswMaterialInventory = new LswMaterialInventory(materialInbound, material.getId(), inventoryCategory, heatTreatmentFlag);
+        inventoryService.save(lswMaterialInventory);
+        return true;
+    }
 }

--
Gitblit v1.9.3