From 8e16903f4b9d8430852ebf58ed0d6b8dacf6ac75 Mon Sep 17 00:00:00 2001 From: cuijian <cuijian@xalxzn.com> Date: 星期二, 29 八月 2023 17:34:23 +0800 Subject: [PATCH] 备件库存消息预警 --- lxzn-module-eam/src/main/java/org/jeecg/modules/spare/service/impl/SparePartOutboundDetailServiceImpl.java | 68 +++++++++++++++++++++++++++++++++ 1 files changed, 67 insertions(+), 1 deletions(-) diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/spare/service/impl/SparePartOutboundDetailServiceImpl.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/spare/service/impl/SparePartOutboundDetailServiceImpl.java index 09c1260..8ec89cf 100644 --- a/lxzn-module-eam/src/main/java/org/jeecg/modules/spare/service/impl/SparePartOutboundDetailServiceImpl.java +++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/spare/service/impl/SparePartOutboundDetailServiceImpl.java @@ -1,14 +1,24 @@ 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 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.SparePartOutboundDetailMapper; import org.jeecg.modules.spare.service.ISparePartOutboundDetailService; import org.jeecg.modules.spare.service.ISparePartOutboundService; import org.jeecg.modules.spare.service.ISparePartService; import org.jeecg.modules.spare.service.ISparesPartInventoryService; +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; @@ -17,6 +27,9 @@ 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; @@ -40,6 +53,22 @@ @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 public List<Map<String, Object>> getSparePartOutboundDeatilList(String sparePartOutboundId) { @@ -107,8 +136,45 @@ sparePartOutbound.setStatus("4"); sparePartOutboundService.updateById(sparePartOutbound); } + + //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