From a3cb768d958e64625786857e0db69335875f5d8e Mon Sep 17 00:00:00 2001
From: hyingbo <1363390067@qq.com>
Date: 星期五, 06 六月 2025 13:43:55 +0800
Subject: [PATCH] 消息类型更新

---
 lxzn-module-eam/src/main/java/org/jeecg/modules/spare/service/impl/SparePartCancellingStocksDetailServiceImpl.java |   89 +++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 79 insertions(+), 10 deletions(-)

diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/spare/service/impl/SparePartCancellingStocksDetailServiceImpl.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/spare/service/impl/SparePartCancellingStocksDetailServiceImpl.java
index ae3c2b2..e1a889f 100644
--- a/lxzn-module-eam/src/main/java/org/jeecg/modules/spare/service/impl/SparePartCancellingStocksDetailServiceImpl.java
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/spare/service/impl/SparePartCancellingStocksDetailServiceImpl.java
@@ -1,20 +1,31 @@
 package org.jeecg.modules.spare.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.jeecg.common.constant.CommonConstant;
+import org.jeecg.common.system.api.ISysBaseAPI;
+import org.jeecg.common.system.vo.DictModel;
 import org.jeecg.modules.spare.entity.*;
 import org.jeecg.modules.spare.mapper.SparePartCancellingStocksDetailMapper;
-import org.jeecg.modules.spare.service.ISparePartCancellingStocksDetailService;
-import org.jeecg.modules.spare.service.ISparePartCancellingStocksService;
-import org.jeecg.modules.spare.service.ISparePartService;
-import org.jeecg.modules.spare.service.ISparesPartInventoryService;
+import org.jeecg.modules.spare.service.*;
+import org.jeecg.modules.system.entity.SysRole;
+import org.jeecg.modules.system.entity.SysUser;
+import org.jeecg.modules.system.service.ISysDictService;
+import org.jeecg.modules.system.service.ISysRoleService;
+import org.jeecg.modules.system.service.ISysUserService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -39,6 +50,26 @@
 
     @Autowired
     private ISparePartService sparePartService;
+
+    @Autowired
+    @Lazy
+    private ISparePartOutboundService sparePartOutboundService;
+
+    @Autowired
+    @Lazy
+    private ISysDictService sysDictService;
+
+    @Autowired
+    @Lazy
+    private ISysRoleService sysRoleService;
+
+    @Autowired
+    @Lazy
+    private ISysUserService sysUserService;
+
+    @Autowired
+    @Lazy
+    private ISysBaseAPI sysBaseAPI;
 
 
     @Override
@@ -74,29 +105,29 @@
 
         //3.鑾峰彇涓� 杈呭崟浣嶈浆鎹㈡瘮渚�
         SparePart sparePart = sparePartService.getById(sparePartId);
-        String conversionRatio = sparePart.getConversionRatio();
+  /*      String conversionRatio = sparePart.getConversionRatio();
         double conversionRatioD = 0;
         if (StringUtils.isBlank(conversionRatio)) {
             conversionRatioD = Double.parseDouble("0");
         } else {
             conversionRatioD = Double.parseDouble(conversionRatio);
         }
-        BigDecimal conversionRatioB = new BigDecimal(conversionRatioD);
+        BigDecimal conversionRatioB = new BigDecimal(conversionRatioD);*/
 
         //4.璁$畻鍑哄簱鏁伴噺鏇存柊搴撳瓨鏁伴噺(搴撳瓨)
         Double mainQuantity = sparesPartInventory.getMainQuantity();
         BigDecimal mainQuantityB = new BigDecimal(mainQuantity);
         /*浠撳簱杈呮暟閲�*/
         Double auxiliaryQuantity = sparesPartInventory.getAuxiliaryQuantity();
-        BigDecimal auxiliaryQuantityB = new BigDecimal(auxiliaryQuantity);
+     /*   BigDecimal auxiliaryQuantityB = new BigDecimal(auxiliaryQuantity);*/
 
         BigDecimal mainQuantitySubtract = mainQuantityB.add(outboundMainQuantityB);//鍔犲悗鐨勫簱瀛樹富鏁伴噺
-        BigDecimal outboundAuxiliaryQuantity = outboundMainQuantityB.multiply(conversionRatioB);//鍑哄簱杈呮暟閲�
+       /* BigDecimal outboundAuxiliaryQuantity = outboundMainQuantityB.multiply();*///鍑哄簱杈呮暟閲�
 
         /*杈呮暟閲�=浠撳簱杈呮暟閲�+鍑哄簱鐨勮緟鏁伴噺锛堝嚭搴撴暟閲�*璁$畻姣斾緥锛�*/
-        BigDecimal auxiliaryQuantitySubtract = auxiliaryQuantityB.add(outboundAuxiliaryQuantity);//鍔犲悗鐨勫簱瀛樿緟鏁伴噺
+       /* BigDecimal auxiliaryQuantitySubtract = auxiliaryQuantityB.add(outboundAuxiliaryQuantity);//鍔犲悗鐨勫簱瀛樿緟鏁伴噺*/
         sparesPartInventory.setMainQuantity(mainQuantitySubtract.doubleValue());
-        sparesPartInventory.setAuxiliaryQuantity(auxiliaryQuantitySubtract.doubleValue());
+    /*    sparesPartInventory.setAuxiliaryQuantity(auxiliaryQuantitySubtract.doubleValue());*/
 
         boolean b = sparesPartInventoryService.updateById(sparesPartInventory);
         if (!b) {
@@ -115,6 +146,44 @@
             sparePartCancellingStocks.setStatus("4");
             sparePartCancellingStocksService.updateById(sparePartCancellingStocks);
         }
+
+        //6.鍒ゆ柇鍑哄簱鍚庡簱瀛樻槸鍚︿綆浜庡畨鍏ㄥ簱瀛樻垨鍑虹幇绉帇鎯呭喌
+        List roleList = new ArrayList<>();
+        List<DictModel> dictModelList = sysDictService.getDictItems("warehouse_message");
+        for(DictModel dictModel : dictModelList){
+            roleList.add(dictModel.getText());
+        }
+        QueryWrapper<SysRole> queryWrapper = Wrappers.query();
+        queryWrapper.in("role_code", roleList);
+        List<SysRole> sysRoleList = sysRoleService.list(queryWrapper);
+        List<SysUser> sysUsers = new ArrayList<>();
+        for (SysRole sysRole : sysRoleList) {
+            sysUsers.addAll(sysUserService.getAllUsersByRoleId(sysRole.getId()));
+        }
+        double quantity = 0.0;
+        List<SparesPartInventory> sparesPartInventoryList = sparesPartInventoryService.lambdaQuery().eq(SparesPartInventory::getSparePartId,sparesPartInventory.getSparePartId()).eq(SparesPartInventory::getDelFlag, CommonConstant.DEL_FLAG_0).list();
+        for(SparesPartInventory sparesPartInventory1 : sparesPartInventoryList){
+            quantity = quantity + sparesPartInventory1.getMainQuantity();
+        }
+        if(quantity < sparePart.getInventoryLowerLimit()){
+            String messageTitle;
+            String messageContent;
+            String sysTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+            messageTitle = "绯荤粺娑堟伅锛氬浠剁紪鐮佷负 " + sparePart.getNum() + " 鐨勫浠跺簱瀛橀噺涓嶈冻锛岃鍙婃椂澶勭悊!";
+            messageContent = "绯荤粺娑堟伅锛氬浠剁紪鐮侊細" + sparePart.getNum()  + " 鐨勫浠跺簱瀛橀噺宸蹭綆浜庡畨鍏ㄥ簱瀛�!" + "\n" + "娑堟伅鏃堕棿:" + sysTime + "\n";
+            for (SysUser sysUser : sysUsers) {
+                sysBaseAPI.sendAnnouncement("admin", sysUser.getUsername(), messageTitle, messageContent, "澶囦欢搴撳瓨閲忎笉瓒�");
+            }
+        }else if(quantity > sparePart.getInventoryUpperLimit()){
+            String messageTitle;
+            String messageContent;
+            String sysTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+            messageTitle = "绯荤粺娑堟伅锛氬浠剁紪鐮佷负 " + sparePart.getNum() + " 鐨勫浠跺嚭鐜扮Н鍘嬫儏鍐碉紝璇峰強鏃跺鐞�!";
+            messageContent = "绯荤粺娑堟伅锛氬浠剁紪鐮佷负 " + sparePart.getNum() + " 鐨勫浠跺簱瀛橀噺宸查珮浜庡簱瀛樹笂闄愬�硷紝鍑虹幇绉帇鎯呭喌!" + "\n" + "娑堟伅鏃堕棿:" + sysTime + "\n";
+            for (SysUser sysUser : sysUsers) {
+                sysBaseAPI.sendAnnouncement("admin", sysUser.getUsername(), messageTitle, messageContent, "澶囦欢绉帇");
+            }
+        }
         return true;
     }
 

--
Gitblit v1.9.3