From bed74a0c68230ff5385eeb4c0726c83c84a01d9b Mon Sep 17 00:00:00 2001
From: 廖井涛 <2265517004@qq.com>
Date: 星期三, 17 九月 2025 08:53:05 +0800
Subject: [PATCH] 玻璃料架修改

---
 north-glass-erp/src/main/java/com/example/erp/service/mm/MaterialInventoryService.java |  454 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 429 insertions(+), 25 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 41cb646..86fc231 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,18 +1,22 @@
 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;
@@ -23,6 +27,8 @@
 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;
 
@@ -74,10 +80,10 @@
                     for (MaterialOutboundDetail materialOutboundDetail : materialOutboundDetailLists) {
                         //杩樺師鐗╂枡搴撳瓨鏁�
                         materialInventoryMapper.updateMaterialInventoryAvailableInt(materialOutboundDetail.getInventoryId(), materialOutboundDetail.getOutboundQuantity());
-                        /*if(materialOutboundDetail.getUseId()!=null){
+                        if(materialOutboundDetail.getUseId()!=null){
                             //杩樺師浼樺寲宸ョ▼搴撳瓨鏁�
                             materialInventoryMapper.updateMaterialInventoryAvailableOptInt(materialOutboundDetail.getUseId(), materialOutboundDetail.getOutboundQuantity());
-                        }else{
+                        }/*else{
                             //杩樺師鐗╂枡搴撳瓨鏁�
                             materialInventoryMapper.updateMaterialInventoryAvailableInt(materialOutboundDetail.getId(), materialOutboundDetail.getOutboundQuantity());
                         }*/
@@ -87,6 +93,7 @@
                 //鍒犻櫎鏉愭枡鍑哄簱鏄庣粏鐨勬暟鎹�
                 materialInventoryMapper.deleteMaterialOutboundDetail(materialOutboundId);
                 materialInventoryMapper.updateMaterialOutbound(materialOutbound, materialOutboundId);
+                materialInventoryMapper.deleteMaterialLog(materialOutboundId);
                 oddNumber = materialOutboundId;
                 log.setFunction("saveMaterialOutbound淇敼:"+oddNumber);
             } else {
@@ -108,13 +115,16 @@
                         materialInventoryMapper.insertMaterialOutboundDetail(materialOutboundDetail, oddNumber, materialOutboundDetailMaximum + 1);
                         //淇敼鐗╂枡搴撳瓨琛ㄥ嚭搴撴暟閲�
                         materialInventoryMapper.updateMaterialInventoryAvailableOut(materialOutboundDetail.getId(), materialOutboundDetail.getOutboundQuantity());
-                    /*if(materialOutboundDetail.getUseId()!=null){
-                        //淇敼浼樺寲宸ョ▼琛ㄥ嚭搴撴暟閲�
-                        materialInventoryMapper.updateMaterialInventoryAvailableOptOut(materialOutboundDetail.getUseId(), materialOutboundDetail.getOutboundQuantity());
-                    }else{
+                        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);
@@ -134,6 +144,7 @@
                         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);
@@ -157,7 +168,7 @@
             sysError.setError(e+Arrays.toString(e.getStackTrace()));
             sysError.setFunc("saveMaterialOutbound");
             sysErrorService.insert(sysError);
-            saveState = "false1";
+            saveState = "false";
 
         }
         return saveState;
@@ -188,23 +199,26 @@
 
             MaterialInventory materialInventory = JSONObject.parseObject(JSONObject.toJSONString(object.get("title")), MaterialInventory.class);
 
-
+            if(materialInventory.getProducer()==null){
+                materialInventory.setProducer("");
+            }
             //鏌ヨ鐗╂枡鏄惁瀛樺湪
-            Integer MaterialInventoryCount=0;
+            List<MaterialInventory> MaterialInventoryCount;
             if (materialInventory.getDateOfManufacture()!=null){
-                MaterialInventoryCount = materialInventoryMapper.getMaterialInventoryCount(materialCode,materialInventory.getDateOfManufacture());
+                MaterialInventoryCount = materialInventoryMapper.getMaterialInventoryCount(materialCode,materialInventory.getDateOfManufacture(),materialInventory.getProducer());
             }else{
-                MaterialInventoryCount = materialInventoryMapper.getMaterialInventoryCountNull(materialCode);
+                MaterialInventoryCount = materialInventoryMapper.getMaterialInventoryCountNull(materialCode,materialInventory.getProducer());
             }
 
-            if(MaterialInventoryCount==1){
+            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==0) {
+            }else if(MaterialInventoryCount.isEmpty()) {
                 materialInventoryMapper.insertMaterialInventory(materialCode,singlePieceArea,totalArea,materialInventory);
                 log.setFunction("saveMaterialInventory鏂板");
             }else {
@@ -215,6 +229,9 @@
             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\""));
@@ -327,6 +344,18 @@
                 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);
@@ -363,6 +392,15 @@
                 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);
@@ -458,10 +496,12 @@
                 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());
-
+                        }
 
                     }
                 }
@@ -470,9 +510,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());
+                        }
+
 
 
                     }
@@ -559,16 +603,19 @@
                     totalArea= Double.parseDouble(decimalFormat.format(singlePieceArea * returningWarehouseDetail.getReturnQuantity()));
 
 
+                    if(returningWarehouseDetail.getProducer()==null){
+                        returningWarehouseDetail.setProducer("");
+                    }
                     //鏌ヨ鐗╂枡鏄惁瀛樺湪
-                    Integer MaterialInventoryCount=0;
+                    List<MaterialInventory> MaterialInventoryCount;
                     if (returningWarehouseDetail.getDateOfManufacture()!=null){
-                        MaterialInventoryCount = materialInventoryMapper.getMaterialInventoryCount(returningWarehouseDetail.getId(),returningWarehouseDetail.getDateOfManufacture());
+                        MaterialInventoryCount = materialInventoryMapper.getMaterialInventoryCount(returningWarehouseDetail.getId(),returningWarehouseDetail.getDateOfManufacture(),returningWarehouseDetail.getProducer());
                     }else{
-                        MaterialInventoryCount = materialInventoryMapper.getMaterialInventoryCountNull(returningWarehouseDetail.getId());
+                        MaterialInventoryCount = materialInventoryMapper.getMaterialInventoryCountNull(returningWarehouseDetail.getId(),returningWarehouseDetail.getProducer());
                     }
 
 
-                    if(MaterialInventoryCount>0){
+                    if(!MaterialInventoryCount.isEmpty()){
                         if (returningWarehouseDetail.getDateOfManufacture()!=null){
                             materialInventoryMapper.updateMaterialInventoryReturning(returningWarehouseDetail.getId(),singlePieceArea,totalArea,returningWarehouseDetail);
                         }else{
@@ -582,9 +629,9 @@
                     //鑾峰彇搴撳瓨缂栧彿娣诲姞鍒拌繑搴撴槑缁嗚〃
                     List<MaterialInventory> MaterialInventoryId;
                     if (returningWarehouseDetail.getDateOfManufacture()!=null){
-                        MaterialInventoryId = materialInventoryMapper.getMaterialInventoryCountId(returningWarehouseDetail.getId(),returningWarehouseDetail.getDateOfManufacture());
+                        MaterialInventoryId = materialInventoryMapper.getMaterialInventoryCountId(returningWarehouseDetail.getId(),returningWarehouseDetail.getDateOfManufacture(),returningWarehouseDetail.getProducer());
                     }else{
-                        MaterialInventoryId = materialInventoryMapper.getMaterialInventoryCountNullId(returningWarehouseDetail.getId());
+                        MaterialInventoryId = materialInventoryMapper.getMaterialInventoryCountNullId(returningWarehouseDetail.getId(),returningWarehouseDetail.getProducer());
                     }
                     materialInventoryMapper.updateReturningWarehouseDetail(oddNumber, returningWarehouseDetailMaximum + 1,MaterialInventoryId.get(0).getId());
 
@@ -833,6 +880,29 @@
     }
 
 
+    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;
+    }
+
 
 
 
@@ -898,9 +968,343 @@
 
 
 
+    @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);
+
+            if(optimizeUses.getNotUseCount()>0){
+                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);
+            }else{
+                return false;
+            }
+
+            //淇濆瓨鏃ュ織
+            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) {
+
+                    if(materialLog.getProducer()==null){
+                        materialLog.setProducer("");
+                    }
+                    //鏌ヨ鐗╂枡鏄惁瀛樺湪
+                    List<MaterialInventory> MaterialInventoryList;
+                    if (materialLog.getOperationOrderNumber()!=null){
+                        MaterialInventoryList = materialInventoryMapper.getMaterialInventoryCount(materialLog.getMaterialCode(), LocalDate.parse(materialLog.getOperationOrderNumber()),materialLog.getProducer());
+                    }else{
+                        MaterialInventoryList = materialInventoryMapper.getMaterialInventoryCountNull(materialLog.getMaterialCode(),materialLog.getProducer());
+                    }
+
+                    if(MaterialInventoryList.size()==1){
+                        if(MaterialInventoryList.get(0).getAvailableQuantity()>=materialLog.getQuantity()){
+                            if (materialLog.getOperationOrderNumber()!=null){
+                                materialInventoryMapper.updateMaterialInventoryOut(materialLog.getMaterialCode(),materialLog.getQuantity(),
+                                        materialLog.getOperationOrderNumber(),materialLog.getProducer());
+                            }else{
+                                materialInventoryMapper.updateMaterialInventoryNullOut(materialLog.getMaterialCode(),materialLog.getQuantity(),
+                                        materialLog.getProducer());
+                            }
+                            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;
+    }
+
+    public List<Map<String,Object>> mesOriginalSelect() {
+        return  materialInventoryMapper.getSelectMaterialInventoryMes();
+    }
+
+    public String saveToExamineMaterialOutbound(Map<String,Object> object) {
+        String saveState = "true";
+        //璁剧疆鍥炴粴鐐�
+        Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint();
+        String materialOutboundId = "";
+        String oddNumber;
+        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);
+            //鏌ヨ鍑哄簱鍗曟槸鍚﹀瓨鍦�
+            Integer MaterialOutboundConut = materialInventoryMapper.getMaterialOutboundCount(materialOutboundId);
+            if (MaterialOutboundConut != 0) {
+
+                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());
+                        }/*else{
+                            //杩樺師鐗╂枡搴撳瓨鏁�
+                            materialInventoryMapper.updateMaterialInventoryAvailableInt(materialOutboundDetail.getId(), materialOutboundDetail.getOutboundQuantity());
+                        }*/
+
+                    }
+                }
+                //鍒犻櫎鏉愭枡鍑哄簱鏄庣粏鐨勬暟鎹�
+                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) {
+                    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());
+                        }*/
+
+                        if(materialOutboundDetail.getUseId()!=null){
+                            //淇敼鐗╂枡搴撳瓨鏁伴噺
+                            materialInventoryMapper.updateMaterialInventoryInventoryPlanQuantityOut(materialOutboundDetail.getId(), materialOutboundDetail.getOutboundQuantity());
+                        }else{
+                            materialInventoryMapper.updateMaterialInventoryInventoryOut(materialOutboundDetail.getId(), materialOutboundDetail.getOutboundQuantity());
+                        }
+
+                        materialInventoryMapper.updateMaterialOutboundToExamine(oddNumber,1,object.get("userName").toString());
+                        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);
+            //灏嗗紓甯镐紶鍏ユ暟鎹簱
+            SysError sysError = new SysError();
+            sysError.setError(e+Arrays.toString(e.getStackTrace()));
+            sysError.setFunc("saveMaterialOutbound");
+            sysErrorService.insert(sysError);
+            saveState = "false";
+
+        }
+        return saveState;
+
+    }
+
+
+    public String updateMaterialInventory(Map<String,Object> object) {
+        String saveState = "true";
+        //璁剧疆鍥炴粴鐐�
+        Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint();
+        try {
+
+            long materialInventoryId = 0L;
+            if (object.get("materialInventoryId") != null) {
+                materialInventoryId = Long.parseLong(object.get("materialInventoryId").toString());
+            }
+            Log log = new Log();
+            log.setOperatorId(object.get("userId").toString());
+            log.setOperator(object.get("userName").toString());
+            log.setContent(object.toString());
+            log.setFunction("updateMaterialInventory鐗╂枡搴撳瓨淇敼");
+            MaterialInventory materialInventory = JSONObject.parseObject(JSONObject.toJSONString(object.get("title")), MaterialInventory.class);
+
+            if(materialInventory.getProducer()==null){
+                materialInventory.setProducer("");
+            }
+            //鏌ヨ鐗╂枡鏄惁瀛樺湪
+            List<MaterialInventory> MaterialInventoryCount;
+            if (materialInventory.getDateOfManufacture()!=null){
+                MaterialInventoryCount = materialInventoryMapper.getMaterialInventoryCount(materialInventory.getMaterialCode(),materialInventory.getDateOfManufacture(),materialInventory.getProducer());
+            }else{
+                MaterialInventoryCount = materialInventoryMapper.getMaterialInventoryCountNull(materialInventory.getMaterialCode(),materialInventory.getProducer());
+            }
+
+            if(MaterialInventoryCount.size()==1){
+                materialInventoryMapper.updateMaterialInventoryOne(MaterialInventoryCount.get(0).getId(),materialInventory);
+                List<Long> id=new ArrayList<>();
+                id.add(materialInventoryId);
+                materialInventoryMapper.deleteMaterialInventory(id);
+            }else{
+                materialInventoryMapper.updateMaterialInventoryAll(materialInventoryId,materialInventory);
+            }
+
+
+
+            logService.saveLog(log);
+        } catch (Exception e) {
+            TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint);
+            //灏嗗紓甯镐紶鍏ユ暟鎹簱
+            SysError sysError = new SysError();
+            sysError.setError(e+Arrays.toString(e.getStackTrace()));
+            sysError.setFunc("saveMaterialInventory");
+            sysErrorService.insert(sysError);
+            saveState = "false";
+
+        }
+        return saveState;
+
+    }
 
 }

--
Gitblit v1.8.0