From d5bb894f9be2e0a3b62d475b60b44f2ab138528c Mon Sep 17 00:00:00 2001
From: guoyujie <guoyujie@ng.com>
Date: 星期四, 12 六月 2025 16:48:35 +0800
Subject: [PATCH] Merge branch 'master' of http://10.153.19.25:10101/r/ERP_override

---
 north-glass-erp/src/main/java/com/example/erp/service/mm/MaterialInventoryService.java |  556 ++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 485 insertions(+), 71 deletions(-)

diff --git a/north-glass-erp/src/main/java/com/example/erp/service/mm/MaterialInventoryService.java b/north-glass-erp/src/main/java/com/example/erp/service/mm/MaterialInventoryService.java
index d5f1231..46dc82b 100644
--- a/north-glass-erp/src/main/java/com/example/erp/service/mm/MaterialInventoryService.java
+++ b/north-glass-erp/src/main/java/com/example/erp/service/mm/MaterialInventoryService.java
@@ -1,24 +1,34 @@
 package com.example.erp.service.mm;
 
 import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.dynamic.datasource.annotation.DS;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.example.erp.common.Constants;
+import com.example.erp.dto.mm.FinishedOperateLogDTO;
 import com.example.erp.entity.mm.*;
-import com.example.erp.entity.pp.FlowCard;
-import com.example.erp.entity.pp.OptimizeUse;
+import com.example.erp.entity.pp.*;
 import com.example.erp.entity.sd.Delivery;
 import com.example.erp.entity.sd.DeliveryDetail;
 import com.example.erp.entity.sd.OrderDetail;
+import com.example.erp.entity.sd.OrderProcessDetail;
+import com.example.erp.entity.userInfo.Log;
 import com.example.erp.entity.userInfo.SysError;
+import com.example.erp.exception.ServiceException;
 import com.example.erp.mapper.mm.BasicWarehouseTypeMapper;
 import com.example.erp.mapper.mm.MaterialInventoryMapper;
+import com.example.erp.mapper.mm.MaterialLogMapper;
 import com.example.erp.mapper.mm.MaterialStoreMapper;
+import com.example.erp.service.userInfo.LogService;
 import com.example.erp.service.userInfo.SysErrorService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.interceptor.TransactionAspectSupport;
+
+import java.time.LocalDateTime;
 import java.util.List;
 import java.util.ArrayList;
 
@@ -40,9 +50,13 @@
     BasicWarehouseTypeMapper basicWarehouseTypeMapper;
     @Autowired
     SysErrorService sysErrorService;
+    @Autowired
+    LogService logService;
+    @Autowired
+    MaterialLogMapper materialLogMapper;
 
-    public Boolean saveMaterialOutbound(Map<String,Object> object) {
-        boolean saveState = true;
+    public String saveMaterialOutbound(Map<String,Object> object) {
+        String saveState = "true";
         //璁剧疆鍥炴粴鐐�
         Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint();
         String materialOutboundId = "";
@@ -50,6 +64,10 @@
         if (object.get("materialOutboundId") != null) {
             materialOutboundId = object.get("materialOutboundId").toString();
         }
+        Log log = new Log();
+        log.setOperatorId(object.get("userId").toString());
+        log.setOperator(object.get("userName").toString());
+        log.setContent(object.toString());
         try {
             MaterialOutbound materialOutbound = JSONObject.parseObject(JSONObject.toJSONString(object.get("title")), MaterialOutbound.class);
             List<MaterialOutboundDetail> materialOutboundDetailList = JSONArray.parseArray(JSONObject.toJSONString(object.get("materialOutboundDetail")), MaterialOutboundDetail.class);
@@ -61,11 +79,11 @@
                 if (!materialOutboundDetailLists.isEmpty()) {
                     for (MaterialOutboundDetail materialOutboundDetail : materialOutboundDetailLists) {
                         //杩樺師鐗╂枡搴撳瓨鏁�
-                        materialInventoryMapper.updateMaterialInventoryAvailableInt(materialOutboundDetail.getId(), materialOutboundDetail.getOutboundQuantity());
-                        /*if(materialOutboundDetail.getUseId()!=null){
+                        materialInventoryMapper.updateMaterialInventoryAvailableInt(materialOutboundDetail.getInventoryId(), materialOutboundDetail.getOutboundQuantity());
+                        if(materialOutboundDetail.getUseId()!=null){
                             //杩樺師浼樺寲宸ョ▼搴撳瓨鏁�
                             materialInventoryMapper.updateMaterialInventoryAvailableOptInt(materialOutboundDetail.getUseId(), materialOutboundDetail.getOutboundQuantity());
-                        }else{
+                        }/*else{
                             //杩樺師鐗╂枡搴撳瓨鏁�
                             materialInventoryMapper.updateMaterialInventoryAvailableInt(materialOutboundDetail.getId(), materialOutboundDetail.getOutboundQuantity());
                         }*/
@@ -74,36 +92,74 @@
                 }
                 //鍒犻櫎鏉愭枡鍑哄簱鏄庣粏鐨勬暟鎹�
                 materialInventoryMapper.deleteMaterialOutboundDetail(materialOutboundId);
+                materialInventoryMapper.updateMaterialOutbound(materialOutbound, materialOutboundId);
+                materialInventoryMapper.deleteMaterialLog(materialOutboundId);
                 oddNumber = materialOutboundId;
+                log.setFunction("saveMaterialOutbound淇敼:"+oddNumber);
             } else {
                 //鑾峰彇鍗曞彿
                 oddNumber = orderNumberSetting("鍑哄簱");
                 //鏂板鏉愭枡鍑哄簱琛ㄦ暟鎹�
                 materialInventoryMapper.insertMaterialOutbound(materialOutbound, oddNumber);
+                log.setFunction("saveMaterialOutbound鏂板:"+oddNumber);
             }
 
             //鑾峰彇瀵硅薄闆嗗悎寰幆杩涜鏂板淇敼
 
             if (!materialOutboundDetailList.isEmpty()) {
                 for (MaterialOutboundDetail materialOutboundDetail : materialOutboundDetailList) {
-
-                    Integer materialOutboundDetailMaximum = materialInventoryMapper.getMaterialOutboundDetailMaximum(oddNumber);
-                    //鏂板鏉愭枡鍑哄簱鏄庣粏鏁版嵁
-                    materialInventoryMapper.insertMaterialOutboundDetail(materialOutboundDetail, oddNumber, materialOutboundDetailMaximum + 1);
-                    //淇敼鐗╂枡搴撳瓨琛ㄥ嚭搴撴暟閲�
-                    materialInventoryMapper.updateMaterialInventoryAvailableOut(materialOutboundDetail.getId(), materialOutboundDetail.getOutboundQuantity());
-                    /*if(materialOutboundDetail.getUseId()!=null){
-                        //淇敼浼樺寲宸ョ▼琛ㄥ嚭搴撴暟閲�
-                        materialInventoryMapper.updateMaterialInventoryAvailableOptOut(materialOutboundDetail.getUseId(), materialOutboundDetail.getOutboundQuantity());
-                    }else{
+                    MaterialInventory materialInventory = materialInventoryMapper.getMaterialInventoryById(materialOutboundDetail.getId());
+                    if(materialInventory.getAvailableQuantity()>=materialOutboundDetail.getOutboundQuantity()){
+                        Integer materialOutboundDetailMaximum = materialInventoryMapper.getMaterialOutboundDetailMaximum(oddNumber);
+                        //鏂板鏉愭枡鍑哄簱鏄庣粏鏁版嵁
+                        materialInventoryMapper.insertMaterialOutboundDetail(materialOutboundDetail, oddNumber, materialOutboundDetailMaximum + 1);
                         //淇敼鐗╂枡搴撳瓨琛ㄥ嚭搴撴暟閲�
                         materialInventoryMapper.updateMaterialInventoryAvailableOut(materialOutboundDetail.getId(), materialOutboundDetail.getOutboundQuantity());
-                    }*/
+                        String projectNo="";
+                        if(materialOutboundDetail.getUseId()!=null){
+                            projectNo = materialInventoryMapper.selectProjectNo(materialOutboundDetail.getUseId());
+                            //淇敼浼樺寲宸ョ▼琛ㄥ嚭搴撴暟閲�
+                            materialInventoryMapper.updateMaterialInventoryAvailableOptOut(materialOutboundDetail.getUseId(), materialOutboundDetail.getOutboundQuantity());
+
+                        }/*else{
+                        //淇敼鐗╂枡搴撳瓨琛ㄥ嚭搴撴暟閲�
+                        materialInventoryMapper.updateMaterialInventoryAvailableOut(materialOutboundDetail.getId(), materialOutboundDetail.getOutboundQuantity());
+                        }*/
+                        String json="";
+                        MaterialStore materialStore=materialStoreMapper.getSelectMaterialStoreById(Long.valueOf(materialOutboundDetail.getMaterialCode()));
+                        json=materialStore.getJson().substring(1, materialStore.getJson().length() - 1);
+                        MaterialLog materialLog=new MaterialLog();
+                        materialLog.setOperationOrderNumber(oddNumber);
+                        materialLog.setOperationNumber(materialOutboundDetailMaximum + 1);
+                        materialLog.setOperateType("鐗╂枡鍑哄簱");
+                        materialLog.setMaterialCode(Long.valueOf(materialOutboundDetail.getMaterialCode()));
+                        materialLog.setMaterialName(convertString(json,"\"name\""));
+                        materialLog.setProducer(materialInventory.getProducer());
+                        materialLog.setUnit(convertString(json,"\"unit\""));
+                        materialLog.setWidth(convertDouble(json,"\"width\""));
+                        materialLog.setHeight(convertDouble(json,"\"height\""));
+                        materialLog.setThickness(convertDouble(json,"\"thickness\""));
+                        materialLog.setQuantity(materialOutboundDetail.getOutboundQuantity());
+                        materialLog.setSinglePieceArea(materialOutboundDetail.getSinglePieceArea());
+                        materialLog.setInventoryId(materialOutboundDetail.getId());
+                        materialLog.setInventoryArea(materialInventory.getInventoryArea());
+                        materialLog.setRemarks(materialOutboundDetail.getRemarks());
+                        materialLog.setProjectNo(projectNo);
+                        materialLog.setOperator(object.get("userName").toString());
+                        materialLog.setOperateTime(LocalDate.now());
+                        materialLogMapper.insert(materialLog);
+                    }else{
+                        TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint);
+                        return "false1";
+                    }
+
+
 
 
                 }
 
             }
+            logService.saveLog(log);
 
         } catch (Exception e) {
             TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint);
@@ -112,15 +168,15 @@
             sysError.setError(e+Arrays.toString(e.getStackTrace()));
             sysError.setFunc("saveMaterialOutbound");
             sysErrorService.insert(sysError);
-            saveState = false;
+            saveState = "false";
 
         }
         return saveState;
 
     }
 
-    public Boolean saveMaterialInventory(Map<String,Object> object) {
-        boolean saveState = true;
+    public String saveMaterialInventory(Map<String,Object> object) {
+        String saveState = "true";
         //璁剧疆鍥炴粴鐐�
         Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint();
         try {
@@ -136,17 +192,61 @@
             if (object.get("materialCode") != null) {
                 materialCode = Long.valueOf(object.get("materialCode").toString());
             }
+            Log log = new Log();
+            log.setOperatorId(object.get("userId").toString());
+            log.setOperator(object.get("userName").toString());
+            log.setContent(object.toString());
 
             MaterialInventory materialInventory = JSONObject.parseObject(JSONObject.toJSONString(object.get("title")), MaterialInventory.class);
 
-            //鏌ヨ鐗╂枡鏄惁瀛樺湪
-            Integer MaterialInventoryCount = materialInventoryMapper.getMaterialInventoryCount(materialCode,materialInventory.getDateOfManufacture());
 
-            if(MaterialInventoryCount>0){
-                materialInventoryMapper.updateMaterialInventory(materialCode,singlePieceArea,totalArea,materialInventory);
-            }else {
-                materialInventoryMapper.insertMaterialInventory(materialCode,singlePieceArea,totalArea,materialInventory);
+            //鏌ヨ鐗╂枡鏄惁瀛樺湪
+            List<MaterialInventory> MaterialInventoryCount;
+            if (materialInventory.getDateOfManufacture()!=null){
+                MaterialInventoryCount = materialInventoryMapper.getMaterialInventoryCount(materialCode,materialInventory.getDateOfManufacture());
+            }else{
+                MaterialInventoryCount = materialInventoryMapper.getMaterialInventoryCountNull(materialCode);
             }
+
+            if(MaterialInventoryCount.size()==1){
+                materialInventory.setId(MaterialInventoryCount.get(0).getId());
+                if (materialInventory.getDateOfManufacture()!=null){
+                    materialInventoryMapper.updateMaterialInventory(materialCode,singlePieceArea,totalArea,materialInventory);
+                }else{
+                    materialInventoryMapper.updateMaterialInventoryNull(materialCode,singlePieceArea,totalArea,materialInventory);
+                }
+                log.setFunction("saveMaterialInventory淇敼");
+            }else if(MaterialInventoryCount.isEmpty()) {
+                materialInventoryMapper.insertMaterialInventory(materialCode,singlePieceArea,totalArea,materialInventory);
+                log.setFunction("saveMaterialInventory鏂板");
+            }else {
+                return "false1";
+            }
+
+            String json="";
+            MaterialStore materialStore=materialStoreMapper.getSelectMaterialStoreById(materialCode);
+            json=materialStore.getJson().substring(1, materialStore.getJson().length() - 1);
+            MaterialLog materialLog=new MaterialLog();
+            if(materialInventory.getDateOfManufacture()!=null){
+                materialLog.setOperationOrderNumber(materialInventory.getDateOfManufacture().toString());
+            }
+            materialLog.setOperateType("鐗╂枡鏂板");
+            materialLog.setMaterialCode(materialCode);
+            materialLog.setMaterialName(convertString(json,"\"name\""));
+            materialLog.setProducer(materialInventory.getProducer());
+            materialLog.setUnit(convertString(json,"\"unit\""));
+            materialLog.setWidth(convertDouble(json,"\"width\""));
+            materialLog.setHeight(convertDouble(json,"\"height\""));
+            materialLog.setThickness(convertDouble(json,"\"thickness\""));
+            materialLog.setQuantity(materialInventory.getInventoryQuantity());
+            materialLog.setSinglePieceArea(singlePieceArea);
+            materialLog.setInventoryId(materialInventory.getId());
+            materialLog.setInventoryArea(materialInventory.getInventoryArea());
+            materialLog.setRemarks(materialInventory.getRemarks());
+            materialLog.setOperator(object.get("userName").toString());
+            materialLog.setOperateTime(LocalDate.now());
+            materialLogMapper.insert(materialLog);
+            logService.saveLog(log);
         } catch (Exception e) {
             TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint);
             //灏嗗紓甯镐紶鍏ユ暟鎹簱
@@ -154,7 +254,7 @@
             sysError.setError(e+Arrays.toString(e.getStackTrace()));
             sysError.setFunc("saveMaterialInventory");
             sysErrorService.insert(sysError);
-            saveState = false;
+            saveState = "false";
 
         }
         return saveState;
@@ -242,10 +342,73 @@
                 materialOutboundId = object.get("materialOutboundId").toString();
             }
             if(materialOutboundId!=null){
+                List<MaterialOutboundDetail> materialOutboundDetailLists = materialInventoryMapper.getIsNotMaterialOutboundDetail(materialOutboundId);
+                if (!materialOutboundDetailLists.isEmpty()) {
+                    for (MaterialOutboundDetail materialOutboundDetail : materialOutboundDetailLists) {
+                        //杩樺師鐗╂枡搴撳瓨鏁�
+                        materialInventoryMapper.updateMaterialInventoryAvailableInt(materialOutboundDetail.getInventoryId(), materialOutboundDetail.getOutboundQuantity());
+                        if(materialOutboundDetail.getUseId()!=null){
+                            //杩樺師浼樺寲宸ョ▼搴撳瓨鏁�
+                            materialInventoryMapper.updateMaterialInventoryAvailableOptInt(materialOutboundDetail.getUseId(), materialOutboundDetail.getOutboundQuantity());
+                        }
+                    }
+                }
+
                 materialInventoryMapper.deleteMaterialOutboundDetail(materialOutboundId);
                 materialInventoryMapper.deleteMaterialOutbound(materialOutboundId);
+                materialInventoryMapper.deleteMaterialLog(materialOutboundId);
             }
+            Log log = new Log();
+            log.setContent(object.toString());
+            log.setOperatorId(object.get("userId").toString());
+            log.setOperator(object.get("userName").toString());
+            log.setFunction("deleteMaterialOutbound鍒犻櫎:"+materialOutboundId);
+            logService.saveLog(log);
 
+
+        } catch (Exception e) {
+            TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint);
+            //灏嗗紓甯镐紶鍏ユ暟鎹簱
+            SysError sysError = new SysError();
+            sysError.setError(e+Arrays.toString(e.getStackTrace()));
+            sysError.setFunc("deleteMaterialOutbound");
+            sysErrorService.insert(sysError);
+            saveState = false;
+
+        }
+        return saveState;
+
+    }
+
+    public Boolean deleteReturnToStorage(Map<String,Object> object) {
+        boolean saveState = true;
+        //璁剧疆鍥炴粴鐐�
+        Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint();
+        try {
+            String returningId = "";
+            if (object.get("returningId") != null) {
+                returningId = object.get("returningId").toString();
+            }
+            if(returningId!=null){
+
+                List<ReturningWarehouseDetail> returningWarehouseDetailLists = materialInventoryMapper.getIsNotReturningWarehouseDetail(returningId);
+                if (!returningWarehouseDetailLists.isEmpty()) {
+                    for (ReturningWarehouseDetail returningWarehouseDetail : returningWarehouseDetailLists) {
+                        //杩樺師鐗╂枡搴撳瓨鏁�
+                        materialInventoryMapper.updateMaterialInventoryAvailableOut(returningWarehouseDetail.getInventoryId(), returningWarehouseDetail.getReturnQuantity());
+                    }
+                }
+
+                materialInventoryMapper.deleteReturningWarehouseDetail(returningId);
+                materialInventoryMapper.deleteReturningWarehouse(returningId);
+                materialInventoryMapper.deleteMaterialLog(returningId);
+            }
+            Log log = new Log();
+            log.setContent(object.toString());
+            log.setOperatorId(object.get("userId").toString());
+            log.setOperator(object.get("userName").toString());
+            log.setFunction("deleteReturnToStorage:"+returningId);
+            logService.saveLog(log);
 
 
         } catch (Exception e) {
@@ -321,15 +484,22 @@
             if (object.get("reviewed") != null) {
                 reviewed = object.get("reviewed").toString();
             }
+            Log log = new Log();
+            log.setOperator(reviewed);
+            log.setContent(object.toString());
+            log.setFunction("updateMaterialOutboundToExamine锛�"+type);
+            logService.saveLog(log);
 
             if (type==1){
                 List<MaterialOutboundDetail> materialOutboundDetailList = materialInventoryMapper.getIsNotMaterialOutboundDetail(materialOutboundId);
                 if (!materialOutboundDetailList.isEmpty()) {
                     for (MaterialOutboundDetail materialOutboundDetail : materialOutboundDetailList) {
-
+                        if(materialOutboundDetail.getUseId()!=null){
                             //淇敼鐗╂枡搴撳瓨鏁伴噺
+                            materialInventoryMapper.updateMaterialInventoryInventoryPlanQuantityOut(materialOutboundDetail.getInventoryId(), materialOutboundDetail.getOutboundQuantity());
+                        }else{
                             materialInventoryMapper.updateMaterialInventoryInventoryOut(materialOutboundDetail.getInventoryId(), materialOutboundDetail.getOutboundQuantity());
-
+                        }
 
                     }
                 }
@@ -338,9 +508,13 @@
                 List<MaterialOutboundDetail> materialOutboundDetailList = materialInventoryMapper.getIsNotMaterialOutboundDetail(materialOutboundId);
                 if (!materialOutboundDetailList.isEmpty()) {
                     for (MaterialOutboundDetail materialOutboundDetail : materialOutboundDetailList) {
-
+                        if(materialOutboundDetail.getUseId()!=null){
                             //淇敼鐗╂枡搴撳瓨鏁伴噺
+                            materialInventoryMapper.updateMaterialInventoryInventoryPlanQuantityInt(materialOutboundDetail.getInventoryId(), materialOutboundDetail.getOutboundQuantity());
+                        }else{
                             materialInventoryMapper.updateMaterialInventoryInventoryInt(materialOutboundDetail.getInventoryId(), materialOutboundDetail.getOutboundQuantity());
+                        }
+
 
 
                     }
@@ -374,6 +548,11 @@
             if (object.get("returningId") != null) {
                 returningId = object.get("returningId").toString();
             }
+            Log log = new Log();
+            log.setOperatorId(object.get("userId").toString());
+            log.setOperator(object.get("userName").toString());
+            log.setContent(object.toString());
+
             ReturningWarehouse returningWarehouse = JSONObject.parseObject(JSONObject.toJSONString(object.get("title")), ReturningWarehouse.class);
             List<ReturningWarehouseDetail> returningWarehouseDetailList = JSONArray.parseArray(JSONObject.toJSONString(object.get("returningWarehouseDetail")), ReturningWarehouseDetail.class);
             //鏌ヨ鍑哄簱鍗曟槸鍚﹀瓨鍦�
@@ -390,11 +569,13 @@
                 //鍒犻櫎鏉愭枡鍑哄簱鏄庣粏鐨勬暟鎹�
                 materialInventoryMapper.deleteReturningWarehouseDetail(returningId);
                 oddNumber = returningId;
+                log.setFunction("saveReturningWarehouse淇敼锛�"+oddNumber);
             } else {
                 //鑾峰彇鍗曞彿
                 oddNumber = orderNumberSetting("杩斿簱");
                 //鏂板鏉愭枡鍑哄簱琛ㄦ暟鎹�
                 materialInventoryMapper.insertReturningWarehouse(returningWarehouse, oddNumber);
+                log.setFunction("saveReturningWarehouse鏂板锛�"+oddNumber);
             }
 
 
@@ -413,15 +594,15 @@
                     json=materialStore.getJson().substring(1, materialStore.getJson().length() - 1);
 
 
-                    double width= convert(json,"\"width\"");
-                    double height=convert(json,"\"height\"");
+                    double width= convertDouble(json,"\"width\"");
+                    double height= convertDouble(json,"\"height\"");
                     DecimalFormat decimalFormat = new DecimalFormat("#0.00");
                     singlePieceArea= Double.parseDouble(decimalFormat.format(width * height / 100000));
                     totalArea= Double.parseDouble(decimalFormat.format(singlePieceArea * returningWarehouseDetail.getReturnQuantity()));
 
 
                     //鏌ヨ鐗╂枡鏄惁瀛樺湪
-                    Integer MaterialInventoryCount=0;
+                    List<MaterialInventory> MaterialInventoryCount;
                     if (returningWarehouseDetail.getDateOfManufacture()!=null){
                         MaterialInventoryCount = materialInventoryMapper.getMaterialInventoryCount(returningWarehouseDetail.getId(),returningWarehouseDetail.getDateOfManufacture());
                     }else{
@@ -429,7 +610,7 @@
                     }
 
 
-                    if(MaterialInventoryCount>0){
+                    if(!MaterialInventoryCount.isEmpty()){
                         if (returningWarehouseDetail.getDateOfManufacture()!=null){
                             materialInventoryMapper.updateMaterialInventoryReturning(returningWarehouseDetail.getId(),singlePieceArea,totalArea,returningWarehouseDetail);
                         }else{
@@ -451,9 +632,29 @@
 
 
 
+                    MaterialLog materialLog=new MaterialLog();
+                    materialLog.setOperationOrderNumber(oddNumber);
+                    materialLog.setOperationNumber(returningWarehouseDetailMaximum + 1);
+                    materialLog.setOperateType("鐗╂枡杩斿簱");
+                    materialLog.setMaterialCode(returningWarehouseDetail.getId());
+                    materialLog.setMaterialName(convertString(json,"\"name\""));
+                    materialLog.setProducer(returningWarehouseDetail.getProducer());
+                    materialLog.setUnit(convertString(json,"\"unit\""));
+                    materialLog.setWidth(convertDouble(json,"\"width\""));
+                    materialLog.setHeight(convertDouble(json,"\"height\""));
+                    materialLog.setThickness(convertDouble(json,"\"thickness\""));
+                    materialLog.setQuantity(returningWarehouseDetail.getReturnQuantity());
+                    materialLog.setSinglePieceArea(singlePieceArea);
+                    materialLog.setInventoryArea(returningWarehouseDetail.getInventoryArea());
+                    materialLog.setRemarks(returningWarehouseDetail.getRemarks());
+                    materialLog.setOperator(object.get("userName").toString());
+                    materialLog.setOperateTime(LocalDate.now());
+                    materialLogMapper.insert(materialLog);
+
                 }
 
             }
+            logService.saveLog(log);
 
         } catch (Exception e) {
             TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint);
@@ -498,6 +699,11 @@
             if (object.get("reviewed") != null) {
                 reviewed = object.get("reviewed").toString();
             }
+            Log log = new Log();
+            log.setOperator(reviewed);
+            log.setContent(object.toString());
+            log.setFunction("updateReturningWarehouseToExamine锛�"+type);
+            logService.saveLog(log);
 
             if (type==1){
                 List<ReturningWarehouseDetail> returningWarehouseDetailList = materialInventoryMapper.getIsNotReturningWarehouseDetail(returningId);
@@ -585,43 +791,46 @@
         //璁剧疆鍥炴粴鐐�
         Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint();
 
-            String creator = "";
-            if (object.get("creator") != null) {
-                creator = object.get("creator").toString();
-            }
-            String type = "";
-            if (object.get("type") != null) {
-                type = object.get("type").toString();
-            }
-            int state = 0;
-            if (object.get("state") != null) {
-                state = Integer.parseInt(object.get("state").toString());
-            }
+        String creator = "";
+        if (object.get("creator") != null) {
+            creator = object.get("creator").toString();
+        }
+        String type = "";
+        if (object.get("type") != null) {
+            type = object.get("type").toString();
+        }
+        int state = 0;
+        if (object.get("state") != null) {
+            state = Integer.parseInt(object.get("state").toString());
+        }
+        Log log = new Log();
+        log.setOperator(creator);
+        log.setContent(object.toString());
+        log.setFunction("addSelectSurplusMaterialsDate锛�"+state);
+        logService.saveLog(log);
 
-
-            if(state==1){
-                SurplusMaterials surplusMaterials = JSONObject.parseObject(JSONObject.toJSONString(object.get("surplusMaterials")), SurplusMaterials.class);
-                if(surplusMaterials!=null){
-                    SurplusMaterials surplusMaterials1=materialInventoryMapper.selectSurplusMaterialsCount(surplusMaterials);
-                    if(surplusMaterials1!=null){
-                        System.out.println(surplusMaterials1);
-                        materialInventoryMapper.updateSurplusMaterialsIntQuantity(surplusMaterials1);
-                        materialInventoryMapper.insertSurplusMaterialsLog(surplusMaterials1,creator,type);
-                    }else{
-                        materialInventoryMapper.insertSurplusMaterials(surplusMaterials);
-                        materialInventoryMapper.insertSurplusMaterialsLog(surplusMaterials,creator,type);
-                    }
-                }
-            } else if (state==2) {
-                List<SurplusMaterials> surplusMaterialsList = JSONArray.parseArray(JSONObject.toJSONString(object.get("surplusMaterials")), SurplusMaterials.class);
-                if(!surplusMaterialsList.isEmpty()){
-                    for(SurplusMaterials surplusMaterials:surplusMaterialsList){
-                        materialInventoryMapper.updateSurplusMaterialsOutQuantity(surplusMaterials);
-                        materialInventoryMapper.insertSurplusMaterialsLog(surplusMaterials,creator,type);
-                    }
-
+        if(state==1){
+            SurplusMaterials surplusMaterials = JSONObject.parseObject(JSONObject.toJSONString(object.get("surplusMaterials")), SurplusMaterials.class);
+            if(surplusMaterials!=null){
+                SurplusMaterials surplusMaterials1=materialInventoryMapper.selectSurplusMaterialsCount(surplusMaterials);
+                if(surplusMaterials1!=null){
+                    materialInventoryMapper.updateSurplusMaterialsIntQuantity(surplusMaterials1);
+                    materialInventoryMapper.insertSurplusMaterialsLog(surplusMaterials1,creator,type);
+                }else{
+                    materialInventoryMapper.insertSurplusMaterials(surplusMaterials);
+                    materialInventoryMapper.insertSurplusMaterialsLog(surplusMaterials,creator,type);
                 }
             }
+        } else if (state==2) {
+            List<SurplusMaterials> surplusMaterialsList = JSONArray.parseArray(JSONObject.toJSONString(object.get("surplusMaterials")), SurplusMaterials.class);
+            if(!surplusMaterialsList.isEmpty()){
+                for(SurplusMaterials surplusMaterials:surplusMaterialsList){
+                    materialInventoryMapper.updateSurplusMaterialsOutQuantity(surplusMaterials);
+                    materialInventoryMapper.insertSurplusMaterialsLog(surplusMaterials,creator,type);
+                }
+
+            }
+        }
 
 
 
@@ -631,6 +840,63 @@
 
     }
 
+    public Map<String, Object> printCreateOutbound(String materialOutboundId) {
+        Map<String, Object> map = new HashMap<>();
+        map.put("createOutbound", materialInventoryMapper.getPrintCreateOutbound(materialOutboundId));
+        map.put("createOutboundDetail", materialInventoryMapper.getPrintCreateOutboundDetail(materialOutboundId));
+        return map;
+    }
+
+    public Map<String, Object> getMaterialLogReport(String type,Integer pageNum, Integer pageSize, List<String> selectDate, MaterialLog materialLog) {
+        Integer offset = (pageNum-1)*pageSize;
+        String endDate = LocalDate.now().toString();
+        String startDate = LocalDate.now().minusDays(15).toString();
+        if(selectDate !=null && selectDate.size()==2){
+            if(!selectDate.get(0).isEmpty()){
+                startDate = selectDate.get(0);
+            }
+            if(!selectDate.get(1).isEmpty()){
+                endDate = selectDate.get(1);
+            }
+        }
+
+        Map<String, Object> map = new HashMap<>();
+        map.put("data", materialInventoryMapper.getMaterialLogReport(offset, pageSize,startDate, endDate, materialLog,type));
+        map.put("total", materialInventoryMapper.getMaterialLogReportTotal(offset, pageSize,startDate, endDate, materialLog,type));
+        List<String> list = new ArrayList<>();
+        list.add(startDate);
+        list.add(endDate);
+        map.put("selectDate",list);
+        return map;
+    }
+
+    public List<MaterialLog> exportMaterialLogReport(List<LocalDate> dates, String type) {
+        return materialInventoryMapper.exportMaterialLogReport(dates,type);
+    }
+
+
+    public Boolean deleteMaterialInventory(Map<String,Object> object) {
+        String creator = "";
+        if (object.get("creator") != null) {
+            creator = object.get("creator").toString();
+        }
+        String ids = "";
+        if (object.get("ids") != null) {
+            ids = object.get("ids").toString();
+        }
+        List<Long> id=new ArrayList<>();
+        if(!ids.isEmpty()){
+            List<String> result = StrUtil.split(ids, '|');
+            id=result.stream().map(Long::valueOf).collect(Collectors.toList());
+        }
+        materialInventoryMapper.deleteMaterialInventory(id);
+        Log log = new Log();
+        log.setOperator(creator);
+        log.setContent(object.toString());
+        log.setFunction("deleteMaterialInventory锛�"+ids);
+        logService.saveLog(log);
+        return true;
+    }
 
 
 
@@ -660,7 +926,7 @@
     }
 
 
-    public double convert(String json,String string) {
+    public String convertString(String json,String string) {
         Map<String, Object> map = new HashMap<>();
         String[] keyValues = json.split(",");
         for (String keyValue : keyValues) {
@@ -669,7 +935,19 @@
                 map.put(pair[0], pair[1]);
             }
         }
-        double number=0.0;
+        return map.get(string).toString().replace("\"","");
+    }
+
+    public Double convertDouble(String json,String string) {
+        Map<String, Object> map = new HashMap<>();
+        String[] keyValues = json.split(",");
+        for (String keyValue : keyValues) {
+            String[] pair = keyValue.split(":");
+            if (pair.length == 2) {
+                map.put(pair[0], pair[1]);
+            }
+        }
+        Double number=0.0;
         if(map.get(string)!=null){
             String[] widthStrings = map.get(string).toString().split("\\D+");
             for (String numberString : widthStrings) {
@@ -685,9 +963,145 @@
 
 
 
+    @Transactional(rollbackFor = Exception.class)
+    public boolean mesMaterialOutbound(Map<String, Object> reportingWorkMap) {
+        boolean saveState=true;
+        Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint();
+        try {
+            //鎺ユ敹瑙f瀽涓婚檮琛ㄤ俊鎭�
+            JSONObject reportingWorkJson = new JSONObject(reportingWorkMap);
+            String projectNo=reportingWorkJson.get("projectNo").toString();
+            Double width= Double.valueOf(reportingWorkJson.get("width").toString());
+            Double height= Double.valueOf(reportingWorkJson.get("height").toString());
+            Integer quantity= Integer.valueOf(reportingWorkJson.get("quantity").toString());
+
+            List<MaterialOutbound> materialOutboundList=materialInventoryMapper.getSelectMaterialOutboundProjectNo(projectNo);
+            OptimizeUse optimizeUses=materialInventoryMapper.getSelectOptimizeUses(projectNo,width,height);
 
 
+            MaterialInventory materialInventory=materialInventoryMapper.getMaterialInventoryById(Long.valueOf(optimizeUses.getRawStockCode()));
+            if(materialOutboundList.size()==1){
+                List<MaterialOutboundDetail> materialOutboundDetailList=materialInventoryMapper.getSelectMaterialOutboundOptimizeUses(materialOutboundList.get(0).getMaterialOutboundId(),optimizeUses.getId());
+                List<MaterialOutboundDetail> materialOutboundDetailList1=materialInventoryMapper.getSelectMaterialOutboundOptimizeUses(materialOutboundList.get(0).getMaterialOutboundId(),null);
+                if(materialOutboundDetailList.size()==1){
+                    materialInventoryMapper.updateMaterialOutboundOptimizeUses(optimizeUses.getId(),quantity);
+                }else{
+                    materialInventoryMapper.insertMaterialOutboundDetailOptimizeUses(materialOutboundList.get(0).getMaterialOutboundId(),
+                            materialOutboundDetailList1.size()+1,Long.valueOf(optimizeUses.getRawStockCode()),materialInventory.getMaterialCode(),materialInventory.getInventoryArea(),
+                            optimizeUses.getId(),quantity,materialInventory.getSinglePieceArea(),materialInventory.getDateOfManufacture());
+                }
+            }else if(materialOutboundList.isEmpty()){
+                String oddNumber = orderNumberSetting("鍑哄簱");
+                materialInventoryMapper.insertMaterialOutboundOptimizeUses(oddNumber,projectNo,reportingWorkJson.get("userName").toString());
+                materialInventoryMapper.insertMaterialOutboundDetailOptimizeUses(oddNumber, 1,Long.valueOf(optimizeUses.getRawStockCode()),materialInventory.getMaterialCode(),materialInventory.getInventoryArea(),
+                        optimizeUses.getId(),quantity,materialInventory.getSinglePieceArea(),materialInventory.getDateOfManufacture());
+            }else{
+                return false;
+            }
+            materialInventoryMapper.updateMaterialInventoryAvailableInventoryOutMes(Long.valueOf(optimizeUses.getRawStockCode()),quantity);
+            materialInventoryMapper.updateOptimizeUsesMes(optimizeUses.getId(),quantity);
+
+            //淇濆瓨鏃ュ織
+            Log log = new Log();
+            log.setContent(reportingWorkMap.toString());
+            log.setFunction("mesMaterialOutbound鎶ュ伐鏂板");
+            log.setOperatorId((String) reportingWorkJson.get("userId"));
+            log.setOperator((String) reportingWorkJson.get("userName"));
+            logService.saveLog(log);
+        } catch (Exception e) {
+            TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint);
+            //灏嗗紓甯镐紶鍏ユ暟鎹簱
+            SysError sysError = new SysError();
+            sysError.setError(e+Arrays.toString(e.getStackTrace()));
+            sysError.setFunc("mesMaterialOutbound鎶ュ伐鏂板");
+            sysErrorService.insert(sysError);
+            saveState = false;
+
+        }
+        return saveState;
+    }
 
 
+    public String cancelMaterialAdditionRecord(Map<String,Object> object) {
+        String saveState = "true";
+        //璁剧疆鍥炴粴鐐�
+        Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint();
+        try {
+            Log log = new Log();
+            log.setOperatorId(object.get("userId").toString());
+            log.setOperator(object.get("userName").toString());
+            log.setFunction("cancelMaterialAdditionRecord鐗╂枡鏂板鎾ら攢");
+            log.setContent(object.toString());
+            //鑾峰彇瀵硅薄闆嗗悎寰幆杩涜鏂板淇敼
+            List<MaterialLog> materialLoglist = JSONArray.parseArray(JSONObject.toJSONString(object.get("materialAdd")), MaterialLog.class);
+            if (!materialLoglist.isEmpty()){
+                for (MaterialLog materialLog : materialLoglist) {
 
+                    //鏌ヨ鐗╂枡鏄惁瀛樺湪
+                    List<MaterialInventory> MaterialInventoryList;
+                    if (materialLog.getOperationOrderNumber()!=null){
+                        MaterialInventoryList = materialInventoryMapper.getMaterialInventoryCount(materialLog.getMaterialCode(), LocalDate.parse(materialLog.getOperationOrderNumber()));
+                    }else{
+                        MaterialInventoryList = materialInventoryMapper.getMaterialInventoryCountNull(materialLog.getMaterialCode());
+                    }
+
+                    if(MaterialInventoryList.size()==1){
+                        if(MaterialInventoryList.get(0).getAvailableQuantity()>=materialLog.getQuantity()){
+                            if (materialLog.getOperationOrderNumber()!=null){
+                                materialInventoryMapper.updateMaterialInventoryOut(materialLog.getMaterialCode(),materialLog.getQuantity(),materialLog.getOperationOrderNumber());
+                            }else{
+                                materialInventoryMapper.updateMaterialInventoryNullOut(materialLog.getMaterialCode(),materialLog.getQuantity());
+                            }
+                            materialInventoryMapper.deleteMaterialLogById(materialLog.getId());
+                        }else{
+                            return "false1";
+                        }
+
+                    }else{
+                        return "false2";
+                    }
+
+
+                }
+
+            }
+            logService.saveLog(log);
+
+        } catch (Exception e) {
+            TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint);
+            //灏嗗紓甯镐紶鍏ユ暟鎹簱
+            SysError sysError = new SysError();
+            sysError.setError(e+Arrays.toString(e.getStackTrace()));
+            sysError.setFunc("cancelFinishedGoodsInventoryStorage");
+            sysErrorService.insert(sysError);
+            saveState = "false";
+
+        }
+        return saveState;
+
+    }
+
+
+    public Map<String, Object> getOptimizeOutboundReport(String type, Integer pageNum, Integer pageSize, List<String> selectDate, MaterialLog materialLog) {
+        Integer offset = (pageNum-1)*pageSize;
+        String endDate = LocalDate.now().toString();
+        String startDate = LocalDate.now().minusDays(15).toString();
+        if(selectDate !=null && selectDate.size()==2){
+            if(!selectDate.get(0).isEmpty()){
+                startDate = selectDate.get(0);
+            }
+            if(!selectDate.get(1).isEmpty()){
+                endDate = selectDate.get(1);
+            }
+        }
+
+        Map<String, Object> map = new HashMap<>();
+        map.put("data", materialInventoryMapper.getOptimizeOutboundReport(offset, pageSize,startDate, endDate, materialLog,type));
+        map.put("total", materialInventoryMapper.getOptimizeOutboundReportTotal(offset, pageSize,startDate, endDate, materialLog,type));
+        List<String> list = new ArrayList<>();
+        list.add(startDate);
+        list.add(endDate);
+        map.put("selectDate",list);
+        return map;
+    }
 }

--
Gitblit v1.8.0