From 24fc98301c0b38a76b7d5aa704fe79a2e385e584 Mon Sep 17 00:00:00 2001
From: 石广澎 <shiguangpeng@163.com>
Date: 星期三, 29 十一月 2023 14:20:41 +0800
Subject: [PATCH] feat: 1、物品分发部门查询 2、分发新增数量校验

---
 consum-base/src/main/java/com/consum/base/core/WarehouseCoreService.java |  167 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 162 insertions(+), 5 deletions(-)

diff --git a/consum-base/src/main/java/com/consum/base/core/WarehouseCoreService.java b/consum-base/src/main/java/com/consum/base/core/WarehouseCoreService.java
index 30ba8b7..96d5f9f 100644
--- a/consum-base/src/main/java/com/consum/base/core/WarehouseCoreService.java
+++ b/consum-base/src/main/java/com/consum/base/core/WarehouseCoreService.java
@@ -1,13 +1,16 @@
 package com.consum.base.core;
 
-import com.consum.base.core.tools.SqlParameter;
-import com.consum.base.core.util.DateUtil;
+import com.consum.base.core.param.BaseWarehouseParam;
+import com.consum.base.core.utils.DateUtil;
+import com.consum.base.core.utils.SqlParameter;
 import com.consum.model.po.*;
 import com.walker.infrastructure.utils.NumberGenerator;
 import com.walker.jdbc.service.BaseServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.Assert;
 
 import java.util.ArrayList;
@@ -19,6 +22,7 @@
  */
 @Service
 @Slf4j
+@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
 public class WarehouseCoreService extends BaseServiceImpl {
 
     public static void main(String[] args) {
@@ -32,10 +36,42 @@
         System.out.println(mapper.getInsertSql_().getSql());
     }
 
+
+
     /**
      * 缁熶竴鍑哄叆搴�
      */
-    public List<CheckWarehouseResult> unifyCheck(CheckWarehouseParam param) {
+    public List<CheckUsingResult> unifyUsingCheck(CheckUsingParam param) {
+        // TODO: 10/10/2023 姝ゅ鍔犱簡鍞竴閿侊紝浼氬奖鍝嶆�ц兘锛屾�濊�冩槸鍚︽湁鏇村悎閫傜殑鍔炴硶
+        try {
+
+            List<CheckUsingResult> results;
+
+
+            String key = param.getLending_id().toString();
+
+            /**
+             * 姝ゅ灏嗗悓涓�涓粨搴撲笅鐨勫悓涓�涓瀷鍙蜂笂閿侊紝涓嶅悓浠撳簱銆佷笉鍚屽瀷鍙蜂笉鍙楀奖鍝嶃��
+             */
+            synchronized (key) {
+                if (param.getIsCheckIn()) {
+                    results = checkUsingIn(param);
+                } else {
+                    results = checkUsingOut(param);
+                }
+            }
+            return results;
+        } catch (Exception e) {
+            log.error(e.getMessage());
+            throw new RuntimeException(e.getMessage());
+        }
+
+    }
+
+    /**
+     * 缁熶竴鍑哄叆搴�
+     */
+    public List<CheckWarehouseResult> unifyCheck(BaseWarehouseParam param) {
         // TODO: 10/10/2023 姝ゅ鍔犱簡鍞竴閿侊紝浼氬奖鍝嶆�ц兘锛屾�濊�冩槸鍚︽湁鏇村悎閫傜殑鍔炴硶
         try {
             Assert.notNull(param, "wareHouse param can not null !");
@@ -64,9 +100,130 @@
     }
 
     /**
+     * 鍦ㄧ敤鐗╁搧鍑哄簱
+     * @param param
+     * @return
+     */
+    private List<CheckUsingResult> checkUsingOut(CheckUsingParam param){
+
+        String sql = "SELECT\n" +
+                "	* \n" +
+                "FROM\n" +
+                "	DEP_FORM_LENDING_MODEL a \n" +
+                "WHERE\n" +
+                "	a.BASE_GOODS_MODELS_ID =:MODEL_ID \n" +
+                "	AND DEP_FORM_LENDING_ID =:LENDING_ID \n" +
+                "	AND USING_COUNT > 0\n" +
+                "ORDER BY\n" +
+                "	PROCURE_DATE ASC PRICE DESC";
+
+        List<DepFormLendingModel>  modelsList = this.select(sql,new SqlParameter("MODEL_ID", param.getModel_id())
+                .put("LENDING_ID",param.getLending_id()),new DepFormLendingModel());
+
+        List<CheckUsingResult> resultList = new ArrayList<>();
+
+        int shengyu = param.getOutputCount();
+        for (DepFormLendingModel model : modelsList) {
+
+            CheckUsingResult result = new CheckUsingResult();
+
+            DepFormLendingGoods goods = get(new DepFormLendingGoods(),"id=?",new Object[]{model.getDepFormLendingGoodsId()});
+
+            //濡傛灉鏄疉绫荤墿鍝侊紝鍒欓渶瑕佷笌鎸佹湁浜虹瓑鍚�
+            if (goods.getClassification() == "A" && (goods.getGoodsUserName().equals(param.getUser_name()))) {
+                continue;
+            }
+
+            //濡傛灉褰撳墠鎸佹湁浜烘寔鏈夌墿鍝佹暟閲忓ぇ浜庡嚭搴撴暟閲忥紝鍒欑洿鎺ュ噺鎺夋暟閲忓嵆鍙��
+            if (model.getUsingCount() > shengyu){
+                result.setInitial_count(model.getUsingCount());
+                result.setLendingModel(model);
+                model.setUsingCount(model.getCounts() - param.getOutputCount());
+                result.setEnd_count(model.getUsingCount());
+                update(model);
+                resultList.add(result);
+
+                goods.setUsingCount(goods.getUsingCount() - param.getOutputCount());
+                update(goods);
+
+                return resultList;
+            }
+
+            shengyu = shengyu - model.getUsingCount();
+            goods.setUsingCount(goods.getUsingCount() - model.getUsingCount());
+
+            result.setInitial_count(model.getUsingCount());
+            result.setLendingModel(model);
+            model.setUsingCount(0);
+            result.setEnd_count(0);
+            update(model);
+            resultList.add(result);
+
+            update(goods);
+        }
+        return resultList;
+    }
+
+    /**
+     * 鍦ㄧ敤鐗╁搧鍏�
+     * @param param
+     * @return
+     */
+    private List<CheckUsingResult> checkUsingIn(CheckUsingParam param){
+
+        DepFormLending lending = get(new DepFormLending(),"id=?",new Object[]{param.getLending_id()});
+
+        String sql = "SELECT\n" +
+                "	* \n" +
+                "FROM\n" +
+                "	DEP_FORM_LENDING_GOODS A \n" +
+                "WHERE\n" +
+                "	A.DEP_FORM_LENDING_ID = :LENDING_ID";
+
+        List<DepFormLendingGoods>  goodsList = this.select(sql,new SqlParameter()
+                .put("LENDING_ID",lending.getId()),new DepFormLendingGoods());
+
+        List<CheckUsingResult> resultList = new ArrayList<>();
+
+        for (DepFormLendingGoods goods : goodsList) {
+            for (CheckWarehouseResult output : param.getOutputList()) {
+                //濡傛灉鍑哄簱鐨勫瀷鍙蜂笌鍒嗗彂鍗曢噷鐨勫瀷鍙风浉鍚�
+                if (goods.getBaseGoodsModelsId().longValue() == output.getWhGoods().getBaseGoodsModelsId().longValue()){
+                    DepFormLendingModel model = new DepFormLendingModel();
+                    model.setId(NumberGenerator.getLongSequenceNumber());
+                    model.setCounts(goods.getCounts());
+                    model.setDepFormLendingGoodsId(goods.getId());
+                    model.setDepFormLendingId(goods.getDepFormLendingId());
+                    model.setWhGoodsDetailsId(output.getWh_goods_detail_id());
+                    model.setNowUserName(goods.getGoodsUserName());
+                    model.setNowUserPhone(goods.getGoodsUserPhone());
+                    model.setWhGoodsId(output.getWhGoods().getId());
+                    //褰撳墠鍙娇鐢ㄦ暟閲�
+                    model.setUsingCount(model.getCounts());
+                    model.setWarehouseId(output.getWhGoods().getWarehouseId());
+                    model.setWarehouseName(output.getWhGoods().getWarehouseName());
+                    model.setAgencyId(lending.getAgencyId());
+                    model.setAgencyName(lending.getAgencyName());
+                    model.setDepartmentId(lending.getDepartmentId());
+                    model.setDepartmentName(lending.getDepartmentName());
+                    insert(model);
+
+                    CheckUsingResult result = new CheckUsingResult();
+                    result.setLendingModel(model);
+                    result.setInitial_count(0);
+                    result.setEnd_count(output.getInitial_count()-output.getEnd_count());
+                    resultList.add(result);
+                }
+            }
+        }
+
+        return resultList;
+    }
+
+    /**
      * 鍑哄簱
      */
-    private List<CheckWarehouseResult> checkout(CheckWarehouseParam param) {
+    private List<CheckWarehouseResult> checkout(BaseWarehouseParam param) {
         //鏌ヨ鍑烘寚瀹氫粨搴撱�佹寚瀹氬瀷鍙凤紝鐘舵�佷负姝e父鐨勭殑搴撳瓨鐗╁搧锛屾寜鐓ч噰璐椂闂村�掑彊銆佷环鏍煎�掑彊鎺掑垪
        String sql = "SELECT\n" +
                 "	* \n" +
@@ -155,7 +312,7 @@
     /**
      * 鍏ュ簱
      */
-    private CheckWarehouseResult checkin(CheckWarehouseParam param) throws RuntimeException {
+    private CheckWarehouseResult checkin(BaseWarehouseParam param) throws RuntimeException {
 
         //濡傛灉鏄噰璐叆搴�
         if (param.getFirst_input_type() ==1){

--
Gitblit v1.9.1