From caf451f76ac30aa222230e0bc2d0d7cb9f420bdf Mon Sep 17 00:00:00 2001
From: 杨凯 <398860375@qq.com>
Date: 星期三, 18 十月 2023 21:54:42 +0800
Subject: [PATCH] 新增部门出入库

---
 consum-base/src/main/java/com/consum/base/core/WarehouseCoreService.java |  148 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 148 insertions(+), 0 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..5946a9f 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
@@ -7,6 +7,7 @@
 import com.walker.jdbc.service.BaseServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
+import org.springframework.security.core.parameters.P;
 import org.springframework.stereotype.Service;
 import org.springframework.util.Assert;
 
@@ -30,6 +31,38 @@
         WhGoods_mapper mapper = new WhGoods_mapper(goods);
         System.out.println(mapper.getInsertSql_().getParameters());
         System.out.println(mapper.getInsertSql_().getSql());
+    }
+
+
+
+    /**
+     * 缁熶竴鍑哄叆搴�
+     */
+    public List<CheckUsingResult> unifyUsingCheck(CheckUsingParam param) {
+        // TODO: 10/10/2023 姝ゅ鍔犱簡鍞竴閿侊紝浼氬奖鍝嶆�ц兘锛屾�濊�冩槸鍚︽湁鏇村悎閫傜殑鍔炴硶
+        try {
+
+            List<CheckUsingResult> results;
+
+
+            String key = param.getLending_id();
+
+            /**
+             * 姝ゅ灏嗗悓涓�涓粨搴撲笅鐨勫悓涓�涓瀷鍙蜂笂閿侊紝涓嶅悓浠撳簱銆佷笉鍚屽瀷鍙蜂笉鍙楀奖鍝嶃��
+             */
+            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());
+        }
+
     }
 
     /**
@@ -64,6 +97,121 @@
     }
 
     /**
+     * 鍦ㄧ敤鐗╁搧鍑哄簱
+     * @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 (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) {

--
Gitblit v1.9.1