Commit a4e4cdf20cf0b517fbe994c308ab4e9c1a9043e0
1 parent
6aabeaec
定时任务统计物料预警信息,弹窗通知用户
Showing
12 changed files
with
253 additions
and
7 deletions
huaheng-wms-core/src/main/java/org/jeecg/modules/message/websocket/WebSocket.java
1 | 1 | package org.jeecg.modules.message.websocket; |
2 | 2 | |
3 | 3 | import java.util.HashMap; |
4 | +import java.util.List; | |
4 | 5 | import java.util.Map; |
5 | 6 | import java.util.concurrent.CopyOnWriteArraySet; |
6 | 7 | |
... | ... | @@ -167,4 +168,7 @@ public class WebSocket { |
167 | 168 | } |
168 | 169 | } |
169 | 170 | |
171 | + public void sendMessage(List<String> userIds, String message) { | |
172 | + userIds.forEach(id -> sendMessage(id, message)); | |
173 | + } | |
170 | 174 | } |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/system/mapper/SysUserMapper.java
... | ... | @@ -59,6 +59,8 @@ public interface SysUserMapper extends BaseMapper<SysUser> { |
59 | 59 | */ |
60 | 60 | IPage<SysUser> getUserByRoleId(Page page, @Param("roleId") String roleId, @Param("username") String username); |
61 | 61 | |
62 | + List<SysUser> getUserByRoleNameArray(@Param("names") String roleNameArr[]); | |
63 | + | |
62 | 64 | /** |
63 | 65 | * 根据用户名设置部门ID |
64 | 66 | * @param username |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/system/mapper/xml/SysUserMapper.xml
... | ... | @@ -195,4 +195,17 @@ |
195 | 195 | WHERE r.enable = 1 |
196 | 196 | </select> |
197 | 197 | |
198 | + <select id="getUserByRoleNameArray" resultType="org.jeecg.modules.system.entity.SysUser"> | |
199 | + SELECT * FROM sys_user WHERE id IN ( | |
200 | + SELECT user_id FROM sys_user_role WHERE role_id IN ( | |
201 | + SELECT id FROM sys_role WHERE role_name IN | |
202 | + <foreach collection="names" item="name" index="index" open="(" close=")" separator=","> | |
203 | + #{name} | |
204 | + </foreach> | |
205 | + ) | |
206 | + ) or realname in | |
207 | + <foreach collection="names" item="name" index="index" open="(" close=")" separator=","> | |
208 | + #{name} | |
209 | + </foreach> | |
210 | + </select> | |
198 | 211 | </mapper> |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/system/service/ISysUserService.java
... | ... | @@ -252,4 +252,6 @@ public interface ISysUserService extends IService<SysUser> { |
252 | 252 | public List<Map<String, Object>> getWarehouseByUserCode(String userCode); |
253 | 253 | |
254 | 254 | public SysUser getUserByRealName(String realName); |
255 | + | |
256 | + public List<SysUser> getUserByRoleNameArray(String[] roleNameArr); | |
255 | 257 | } |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java
... | ... | @@ -315,6 +315,11 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl |
315 | 315 | } |
316 | 316 | |
317 | 317 | @Override |
318 | + public List<SysUser> getUserByRoleNameArray(String[] roleNameArr){ | |
319 | + return userMapper.getUserByRoleNameArray(roleNameArr); | |
320 | + } | |
321 | + | |
322 | + @Override | |
318 | 323 | @CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, key = "#username") |
319 | 324 | public void updateUserDepart(String username, String orgCode) { |
320 | 325 | baseMapper.updateUserDepart(username, orgCode); |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/materialWarning/controller/MaterialWarningController.java
... | ... | @@ -10,6 +10,8 @@ import java.net.URLDecoder; |
10 | 10 | import javax.servlet.http.HttpServletRequest; |
11 | 11 | import javax.servlet.http.HttpServletResponse; |
12 | 12 | |
13 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |
14 | +import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |
13 | 15 | import org.apache.shiro.authz.annotation.RequiresPermissions; |
14 | 16 | import org.jeecg.common.api.vo.Result; |
15 | 17 | import org.jeecg.common.system.query.QueryGenerator; |
... | ... | @@ -68,7 +70,9 @@ public class MaterialWarningController extends JeecgController<MaterialWarning, |
68 | 70 | public Result<IPage<MaterialWarning>> queryPageList(MaterialWarning materialWarning, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, |
69 | 71 | @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) { |
70 | 72 | HuahengJwtUtil.setWarehouseCode(req, materialWarning); |
71 | - QueryWrapper<MaterialWarning> queryWrapper = QueryGenerator.initQueryWrapper(materialWarning, req.getParameterMap()); | |
73 | + LambdaQueryWrapper<MaterialWarning> queryWrapper = Wrappers.lambdaQuery(); | |
74 | + queryWrapper.eq(StringUtils.isNotEmpty(materialWarning.getMaterialCode()), MaterialWarning::getMaterialCode, materialWarning.getMaterialCode()); | |
75 | + queryWrapper.eq(StringUtils.isNotEmpty(materialWarning.getMaterialName()), MaterialWarning::getMaterialName, materialWarning.getMaterialName()); | |
72 | 76 | Page<MaterialWarning> page = new Page<MaterialWarning>(pageNo, pageSize); |
73 | 77 | IPage<MaterialWarning> pageList = materialWarningService.page(page, queryWrapper); |
74 | 78 | return Result.OK(pageList); |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/materialWarning/entity/MaterialLevelAlarm.java
0 → 100644
1 | +package org.jeecg.modules.wms.config.materialWarning.entity; | |
2 | + | |
3 | +import lombok.Data; | |
4 | + | |
5 | +import java.math.BigDecimal; | |
6 | + | |
7 | +@Data | |
8 | +public class MaterialLevelAlarm extends MaterialWarning { | |
9 | + private int qtySum; | |
10 | + //小于等于下线预警 | |
11 | + private boolean inLower; | |
12 | + //小于等于上线预警 | |
13 | + private boolean inUpper; | |
14 | + | |
15 | + //小于等于最小值 | |
16 | + private boolean inMin; | |
17 | + //大于等于最大值 | |
18 | + private boolean inMax; | |
19 | + | |
20 | + /**构造预警数据**/ | |
21 | + public MaterialLevelAlarm(MaterialWarning warning, BigDecimal qtySum) { | |
22 | + org.springframework.beans.BeanUtils.copyProperties(warning, this); | |
23 | + this.qtySum = qtySum.intValue(); | |
24 | + if (getLower() > 0) { | |
25 | + inLower = this.qtySum <= getLower(); | |
26 | + } | |
27 | + if (getUpper() > 0) { | |
28 | + inUpper = this.qtySum >= getUpper(); | |
29 | + } | |
30 | + | |
31 | + if (getMin() > 0) { | |
32 | + inMin = this.qtySum <= getMin(); | |
33 | + } | |
34 | + | |
35 | + if (getMax() > 0) { | |
36 | + inMax = this.qtySum >= getMax(); | |
37 | + } | |
38 | + } | |
39 | + | |
40 | + /**判断是否有预警**/ | |
41 | + public Boolean needAlarm(){ | |
42 | + return inLower || inUpper || inMin || inMax; | |
43 | + } | |
44 | + | |
45 | + @Override | |
46 | + public String toString() { | |
47 | + String str = getMaterialName() + " " + getMaterialCode() + " 库存数=" + qtySum + " "; | |
48 | + if (inLower) { | |
49 | + str = str + " < " + getLower(); | |
50 | + } else if (inUpper) { | |
51 | + str = str + " > " + getUpper(); | |
52 | + } else if (inMin){ | |
53 | + str = str + " < " + getMin(); | |
54 | + } else if (inMax) { | |
55 | + str = str + " > " + getMax(); | |
56 | + } | |
57 | + | |
58 | + return str; | |
59 | + } | |
60 | +} | |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/materialWarning/entity/MaterialWarning.java
... | ... | @@ -66,11 +66,11 @@ public class MaterialWarning implements Serializable { |
66 | 66 | /** 最大 */ |
67 | 67 | @Excel(name = "最大", width = 15) |
68 | 68 | @ApiModelProperty(value = "最大") |
69 | - private String max; | |
69 | + private int max; | |
70 | 70 | /** 最小 */ |
71 | 71 | @Excel(name = "最小", width = 15) |
72 | 72 | @ApiModelProperty(value = "最小") |
73 | - private String min; | |
73 | + private int min; | |
74 | 74 | /** 上限预警值 */ |
75 | 75 | @Excel(name = "上限预警值", width = 15) |
76 | 76 | @ApiModelProperty(value = "上限预警值") |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/materialWarning/service/IMaterialWarningService.java
1 | 1 | package org.jeecg.modules.wms.config.materialWarning.service; |
2 | 2 | |
3 | 3 | import com.baomidou.mybatisplus.extension.service.IService; |
4 | +import org.jeecg.modules.wms.config.materialWarning.entity.MaterialLevelAlarm; | |
4 | 5 | import org.jeecg.modules.wms.config.materialWarning.entity.MaterialWarning; |
5 | 6 | |
7 | +import java.util.List; | |
8 | + | |
6 | 9 | /** |
7 | 10 | * @Description: 物料预警 |
8 | 11 | * @Author: jeecg-boot |
... | ... | @@ -11,4 +14,5 @@ import org.jeecg.modules.wms.config.materialWarning.entity.MaterialWarning; |
11 | 14 | */ |
12 | 15 | public interface IMaterialWarningService extends IService<MaterialWarning> { |
13 | 16 | |
17 | + List<MaterialLevelAlarm> getLevelAlarm(String materialCode); | |
14 | 18 | } |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/materialWarning/service/impl/MaterialWarningServiceImpl.java
1 | 1 | package org.jeecg.modules.wms.config.materialWarning.service.impl; |
2 | 2 | |
3 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |
4 | +import org.jeecg.modules.wms.config.materialWarning.entity.MaterialLevelAlarm; | |
3 | 5 | import org.jeecg.modules.wms.config.materialWarning.entity.MaterialWarning; |
4 | 6 | import org.jeecg.modules.wms.config.materialWarning.mapper.MaterialWarningMapper; |
5 | 7 | import org.jeecg.modules.wms.config.materialWarning.service.IMaterialWarningService; |
8 | +import org.jeecg.modules.wms.inventory.inventoryHeader.entity.InventoryDetail; | |
9 | +import org.jeecg.modules.wms.inventory.inventoryHeader.service.impl.InventoryDetailServiceImpl; | |
10 | +import org.jeecg.utils.StringUtils; | |
11 | +import org.jeecg.utils.constant.QuantityConstant; | |
6 | 12 | import org.springframework.stereotype.Service; |
7 | 13 | |
8 | 14 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
9 | 15 | |
16 | +import javax.annotation.Resource; | |
17 | +import java.math.BigDecimal; | |
18 | +import java.util.ArrayList; | |
19 | +import java.util.List; | |
20 | +import java.util.stream.Collectors; | |
21 | + | |
10 | 22 | /** |
11 | 23 | * @Description: 物料预警 |
12 | - * @Author: jeecg-boot | |
13 | - * @Date: 2022-10-24 | |
14 | - * @Version: V1.0 | |
24 | + * @Author: jeecg-boot | |
25 | + * @Date: 2022-10-24 | |
26 | + * @Version: V1.0 | |
15 | 27 | */ |
16 | 28 | @Service |
17 | 29 | public class MaterialWarningServiceImpl extends ServiceImpl<MaterialWarningMapper, MaterialWarning> implements IMaterialWarningService { |
18 | 30 | |
31 | + @Resource | |
32 | + InventoryDetailServiceImpl inventoryDetailService; | |
33 | + | |
34 | + @Override | |
35 | + public List<MaterialLevelAlarm> getLevelAlarm(String materialCode) { | |
36 | + LambdaQueryWrapper<MaterialWarning> query = new LambdaQueryWrapper<>(); | |
37 | + query.eq(StringUtils.isNotEmpty(materialCode), MaterialWarning::getMaterialCode, materialCode); | |
38 | + List<MaterialWarning> warningList = list(query); | |
39 | + | |
40 | + List<MaterialLevelAlarm> alarmList = new ArrayList<>(); | |
41 | + warningList.forEach(w -> { | |
42 | + InventoryDetail d = new InventoryDetail(); | |
43 | + d.setMaterialCode(w.getMaterialCode()); | |
44 | + d.setCompanyCode(w.getCompanyCode()); | |
45 | + d.setWarehouseCode(w.getWarehouseCode()); | |
46 | + d.setInventoryStatus(QuantityConstant.QUALITY_GOOD); | |
47 | + BigDecimal sum = inventoryDetailService.getInventorySumQty(d); | |
48 | + alarmList.add(new MaterialLevelAlarm(w, sum)); | |
49 | + }); | |
50 | + | |
51 | + return alarmList.stream().filter(it -> it.needAlarm() ).collect(Collectors.toList()); | |
52 | + } | |
19 | 53 | } |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/monitor/job/MaterialLevelAlarmTask.java
0 → 100644
1 | +package org.jeecg.modules.wms.monitor.job; | |
2 | + | |
3 | +import cn.hutool.core.util.StrUtil; | |
4 | +import com.alibaba.fastjson.JSONObject; | |
5 | +import com.baomidou.mybatisplus.core.metadata.IPage; | |
6 | +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |
7 | +import lombok.extern.slf4j.Slf4j; | |
8 | +import org.apache.ibatis.session.SqlSession; | |
9 | +import org.jeecg.common.constant.CommonConstant; | |
10 | +import org.jeecg.common.constant.CommonSendStatus; | |
11 | +import org.jeecg.common.constant.WebsocketConst; | |
12 | +import org.jeecg.common.util.DateUtils; | |
13 | +import org.jeecg.modules.message.websocket.WebSocket; | |
14 | +import org.jeecg.modules.system.controller.SysAnnouncementController; | |
15 | +import org.jeecg.modules.system.entity.SysAnnouncement; | |
16 | +import org.jeecg.modules.system.entity.SysUser; | |
17 | +import org.jeecg.modules.system.mapper.SysUserMapper; | |
18 | +import org.jeecg.modules.system.service.impl.SysAnnouncementServiceImpl; | |
19 | +import org.jeecg.modules.system.service.impl.SysRoleServiceImpl; | |
20 | +import org.jeecg.modules.system.service.impl.SysUserServiceImpl; | |
21 | +import org.jeecg.modules.wms.config.materialWarning.entity.MaterialLevelAlarm; | |
22 | +import org.jeecg.modules.wms.config.materialWarning.service.impl.MaterialWarningServiceImpl; | |
23 | +import org.jeecg.utils.SpringUtils; | |
24 | +import org.quartz.*; | |
25 | +import org.springframework.beans.factory.annotation.Autowired; | |
26 | + | |
27 | +import javax.annotation.Resource; | |
28 | +import java.util.ArrayList; | |
29 | +import java.util.List; | |
30 | +import java.util.stream.Collectors; | |
31 | + | |
32 | +/** | |
33 | + * 水位预警通知 | |
34 | + * | |
35 | + * @author 游杰 | |
36 | + */ | |
37 | + | |
38 | +@Slf4j | |
39 | +@PersistJobDataAfterExecution | |
40 | +@DisallowConcurrentExecution | |
41 | +public class MaterialLevelAlarmTask implements Job { | |
42 | + private String parameter; | |
43 | + | |
44 | + @Resource | |
45 | + private WebSocket webSocket; | |
46 | + | |
47 | + @Resource | |
48 | + private SysUserServiceImpl sysUserService; | |
49 | + | |
50 | + @Resource | |
51 | + private SysRoleServiceImpl sysRoleService; | |
52 | + | |
53 | + @Autowired | |
54 | + private SqlSession sqlSession; | |
55 | + | |
56 | + @Autowired | |
57 | + private SysAnnouncementServiceImpl sysAnnouncementService; | |
58 | + | |
59 | + @Autowired | |
60 | + private MaterialWarningServiceImpl materialWarningService; | |
61 | + | |
62 | + public void setParameter(String parameter) { | |
63 | + this.parameter = parameter; | |
64 | + } | |
65 | + | |
66 | + @Override | |
67 | + public void execute(JobExecutionContext context) throws JobExecutionException { | |
68 | + log.info(StrUtil.format("定时任务 MaterialLevelAlarmTask 参数:{},执行时间:{}", this.parameter, DateUtils.getTimestamp())); | |
69 | + List<MaterialLevelAlarm> alarmList = materialWarningService.getLevelAlarm(null); | |
70 | + if (alarmList == null && alarmList.size() == 0) { | |
71 | + return; | |
72 | + } | |
73 | + | |
74 | + List<String> list = alarmList.stream().map(MaterialLevelAlarm::toString).collect(Collectors.toList()); | |
75 | + String msg = String.join("\n", list); | |
76 | + | |
77 | + SysAnnouncement sysAnnouncement = new SysAnnouncement(); | |
78 | + String title = "物料水位预警" + DateUtils.now(); | |
79 | + sysAnnouncement.setTitile(title); | |
80 | + sysAnnouncement.setMsgContent(msg); | |
81 | + sysAnnouncement.setMsgCategory(CommonConstant.MSG_CATEGORY_2); | |
82 | + sysAnnouncement.setMsgType(CommonConstant.MSG_TYPE_ALL); | |
83 | + sysAnnouncement.setMsgAbstract(title); | |
84 | + sysAnnouncement.setDelFlag(CommonConstant.DEL_FLAG_0.toString()); | |
85 | + sysAnnouncement.setSendStatus(CommonSendStatus.PUBLISHED_STATUS_1); | |
86 | + sysAnnouncementService.saveAnnouncement(sysAnnouncement); | |
87 | + | |
88 | + List<SysUser> userList = new ArrayList<>(); | |
89 | + try { | |
90 | + String[] userOrRoleArr = this.parameter.split(","); | |
91 | + userList = sysUserService.getUserByRoleNameArray(userOrRoleArr); | |
92 | + } catch (Exception e) { | |
93 | + log.error("获取预警通知用户出错", e); | |
94 | + } | |
95 | + | |
96 | + if (userList.size() == 0) { | |
97 | + sysAnnouncement.setMsgType(CommonConstant.MSG_TYPE_ALL); | |
98 | + JSONObject obj = new JSONObject(); | |
99 | + obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_TOPIC); | |
100 | + obj.put(WebsocketConst.MSG_ID, sysAnnouncement.getId()); | |
101 | + obj.put(WebsocketConst.MSG_TXT, sysAnnouncement.getTitile()); | |
102 | + webSocket.sendMessage(obj.toJSONString()); | |
103 | + } else { | |
104 | + // 2.插入用户通告阅读标记表记录 | |
105 | + sysAnnouncement.setMsgType(CommonConstant.MSG_TYPE_UESR); | |
106 | + List<String> userIds = userList.stream().map(SysUser::getId).map(Object::toString).collect(Collectors.toList()); | |
107 | + sysAnnouncement.setUserIds(String.join(",", userIds)); | |
108 | + | |
109 | + JSONObject obj = new JSONObject(); | |
110 | + obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_USER); | |
111 | + obj.put(WebsocketConst.MSG_ID, sysAnnouncement.getId()); | |
112 | + obj.put(WebsocketConst.MSG_TXT, sysAnnouncement.getTitile()); | |
113 | + webSocket.sendMessage(userIds, obj.toJSONString()); | |
114 | + } | |
115 | + | |
116 | + sysAnnouncementService.updateById(sysAnnouncement); | |
117 | + } | |
118 | +} | |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/receipt/receiptHeader/service/impl/ReceiptDetailServiceImpl.java
... | ... | @@ -100,7 +100,7 @@ public class ReceiptDetailServiceImpl extends ServiceImpl<ReceiptDetailMapper, R |
100 | 100 | throw new JeecgBootException("添加失败, 保存入库单详失败"); |
101 | 101 | } |
102 | 102 | LogRecordContext.putVariable("extraJsonString", JSON.toJSONString(Collections.singletonList(receiptDetail)));// 操作日志收集 |
103 | - return Result.OK("添加成功!"); | |
103 | + return Result.OK("添加成功!", receiptDetail); | |
104 | 104 | } |
105 | 105 | |
106 | 106 | @Override |
... | ... |