Commit 6255e51d4312c37bbf9ff7e07c0807d14e42faef

Authored by 谭毅彬
1 parent 9c6efa90

消息通知接口封装优化

Signed-off-by: TanYibin <5491541@qq.com>
ant-design-vue-jeecg/src/components/tools/ShowAnnouncement.vue
... ... @@ -9,71 +9,66 @@
9 9 >
10 10 <template slot="footer">
11 11 <a-button key="back" @click="handleCancel">关闭</a-button>
12   - <a-button v-if="record.openType==='url'" type="primary" @click="toHandle">去处理</a-button>
  12 + <a-button v-if="record.openType === 'url'" type="primary" @click="toHandle">去处理</a-button>
13 13 </template>
14 14 <a-card class="daily-article" :loading="loading">
15   - <a-card-meta
16   - :title="record.titile"
17   - :description="'发布人:'+record.sender + ' 发布时间: ' + record.sendTime">
18   - </a-card-meta>
19   - <a-divider/>
  15 + <a-card-meta :title="record.titile" :description="'发布时间: ' + record.sendTime + ',发布人:' + record.sender"/>
  16 + <!-- <a-divider/> -->
20 17 <span v-html="record.msgContent" class="article-content"></span>
21 18 </a-card>
22 19 </j-modal>
23 20 </template>
24 21  
25 22 <script>
26   -import {getUserList} from '@/api/api'
  23 +import { getUserList } from '@/api/api'
27 24  
28 25 export default {
29   - name: "SysAnnouncementModal",
  26 + name: 'SysAnnouncementModal',
30 27 components: {},
31 28 data() {
32 29 return {
33   - title: "通知消息",
  30 + title: '通知消息',
34 31 record: {},
35 32 labelCol: {
36   - xs: {span: 24},
37   - sm: {span: 5},
  33 + xs: { span: 24 },
  34 + sm: { span: 5 }
38 35 },
39 36 wrapperCol: {
40   - xs: {span: 24},
41   - sm: {span: 16},
  37 + xs: { span: 24 },
  38 + sm: { span: 16 }
42 39 },
43 40 visible: false,
44 41 switchFullscreen: true,
45 42 loading: false,
46 43 bodyStyle: {
47   - padding: "0",
48   - height: (window.innerHeight * 0.8) + "px",
49   - "overflow-y": "auto",
50   -
  44 + padding: '5',
  45 + height: window.innerHeight * 0.6 + 'px',
  46 + 'overflow-y': 'auto'
51 47 },
52 48 modelStyle: {
53 49 width: '60%',
54   - style: {top: '20px'},
  50 + style: { top: '20px' },
55 51 fullScreen: false
56 52 }
57 53 }
58 54 },
59   - created() {
60   - },
  55 + created() {},
61 56 methods: {
62 57 detail(record) {
63 58 //update-begin---author:wangshuai ---date:20220107 for:将其它页面传递过来的用户名改成用户真实姓名
64 59 if (record.sender) {
65   - getUserList({"username": record.sender}).then((res) => {
  60 + getUserList({ username: record.sender }).then(res => {
66 61 if (res.success && res.result.records.length > 0) {
67 62 record.sender = res.result.records[0].realname
68 63 }
69 64 })
70 65 }
71 66 //update-end---author:wangshuai ---date:20220107 for:将其它页面传递过来的用户名改成用户真实姓名
72   - this.visible = true;
73   - this.record = record;
  67 + this.visible = true
  68 + this.record = record
74 69 },
75 70 handleCancel() {
76   - this.visible = false;
  71 + this.visible = false
77 72 },
78 73 /** 切换全屏显示 */
79 74 handleClickToggleFullScreen() {
... ... @@ -89,11 +84,11 @@ export default {
89 84 },
90 85 toHandle() {
91 86 if (this.record.openType === 'url') {
92   - this.visible = false;
  87 + this.visible = false
93 88 //链接跳转
94   - this.$router.push({path: this.record.openPage})
  89 + this.$router.push({ path: this.record.openPage })
95 90 }
96   - },
  91 + }
97 92 }
98 93 }
99 94 </script>
... ... @@ -147,8 +142,8 @@ export default {
147 142 word-break: break-all;
148 143 text-overflow: initial;
149 144 white-space: normal;
150   - font-size: .9rem !important;
151   - margin-bottom: .8rem;
  145 + font-size: 0.9rem !important;
  146 + margin-bottom: 0.8rem;
152 147 }
153 148 }
154 149 }
... ...
huaheng-wms-core/src/main/java/org/jeecg/JeecgSystemApplication.java
... ... @@ -17,6 +17,7 @@ import org.springframework.context.ConfigurableApplicationContext;
17 17 import org.springframework.context.annotation.ComponentScan;
18 18 import org.springframework.context.annotation.ComponentScan.Filter;
19 19 import org.springframework.context.annotation.FilterType;
  20 +import org.springframework.context.annotation.Import;
20 21 import org.springframework.core.env.Environment;
21 22 import org.springframework.scheduling.annotation.EnableScheduling;
22 23  
... ... @@ -31,6 +32,7 @@ import lombok.extern.slf4j.Slf4j;
31 32 //@EnableSchedulerLock(defaultLockAtMostFor = "PT30S") // 默认最长等待时间30秒
32 33 @SpringBootApplication
33 34 @EnableAutoConfiguration(exclude = {MongoAutoConfiguration.class})
  35 +@Import(cn.hutool.extra.spring.SpringUtil.class)
34 36 @ComponentScan(excludeFilters = {@Filter(type = FilterType.REGEX, pattern = {"org.jeecg.config.mybatis.MybatisInterceptor", "org.jeecg.config.Swagger2Config"})})
35 37 public class JeecgSystemApplication extends SpringBootServletInitializer {
36 38  
... ...
huaheng-wms-core/src/main/java/org/jeecg/modules/system/mapper/SysUserMapper.java
... ... @@ -59,7 +59,7 @@ public interface SysUserMapper extends BaseMapper&lt;SysUser&gt; {
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[]);
  62 + List<SysUser> getUserByRoleNameArray(@Param("names") List<String> roleNameArr);
63 63  
64 64 /**
65 65 * 根据用户名设置部门ID
... ...
huaheng-wms-core/src/main/java/org/jeecg/modules/system/mapper/xml/SysUserMapper.xml
... ... @@ -198,12 +198,12 @@
198 198 <select id="getUserByRoleNameArray" resultType="org.jeecg.modules.system.entity.SysUser">
199 199 SELECT * FROM sys_user WHERE id IN (
200 200 SELECT user_id FROM sys_user_role WHERE role_id IN (
201   - SELECT id FROM sys_role WHERE role_name IN
  201 + SELECT id FROM sys_role WHERE role_code IN
202 202 <foreach collection="names" item="name" index="index" open="(" close=")" separator=",">
203 203 #{name}
204 204 </foreach>
205 205 )
206   - ) or realname in
  206 + ) or username in
207 207 <foreach collection="names" item="name" index="index" open="(" close=")" separator=",">
208 208 #{name}
209 209 </foreach>
... ...
huaheng-wms-core/src/main/java/org/jeecg/modules/system/service/ISysAnnouncementService.java
... ... @@ -26,8 +26,16 @@ public interface ISysAnnouncementService extends IService&lt;SysAnnouncement&gt; {
26 26  
27 27 public Page<SysAnnouncement> querySysCementPageByUserId(Page<SysAnnouncement> page, String userId, String msgCategory);
28 28  
  29 + /**
  30 + * 快速发送系统消息
  31 + * @param userList 目标用户, 为null时发送广播消息
  32 + * @param title 消息标题
  33 + * @param msg 消息内容
  34 + * @param endTime 消息有效期
  35 + * @param level 消息级别,H M L
  36 + */
29 37 public void quickAnnouncementToUser(List<SysUser> userList, String title, String msg, Date endTime, String level);
30 38  
31   - public void quickAnnouncementToRole(List<SysRole> roleList, String title, String msg, Date endTime, String level);
  39 + public void quickAnnouncementToUserOrRole(List<String> userOrRoleList, String title, String msg, Date endTime, String level);
32 40  
33 41 }
... ...
huaheng-wms-core/src/main/java/org/jeecg/modules/system/service/ISysUserService.java
... ... @@ -253,5 +253,5 @@ public interface ISysUserService extends IService&lt;SysUser&gt; {
253 253  
254 254 public SysUser getUserByRealName(String realName);
255 255  
256   - public List<SysUser> getUserByRoleNameArray(String[] roleNameArr);
  256 + public List<SysUser> getUserByRoleNameArray(List<String> roleNameArr);
257 257 }
... ...
huaheng-wms-core/src/main/java/org/jeecg/modules/system/service/impl/SysAnnouncementServiceImpl.java
... ... @@ -20,6 +20,7 @@ import org.jeecg.modules.system.mapper.SysAnnouncementSendMapper;
20 20 import org.jeecg.modules.system.service.ISysAnnouncementService;
21 21 import org.springframework.stereotype.Service;
22 22 import org.springframework.transaction.annotation.Transactional;
  23 +import org.springframework.util.CollectionUtils;
23 24  
24 25 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
25 26 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
... ... @@ -73,17 +74,16 @@ public class SysAnnouncementServiceImpl extends ServiceImpl&lt;SysAnnouncementMappe
73 74 }
74 75 }
75 76  
76   -
77 77 /**
78 78 * 快速发送系统消息
79   - * @param userList 目标用户, 为null时发送广播消息
80   - * @param title 消息标题
81   - * @param msg 消息内容
82   - * @param endTime 消息有效期
83   - * @param level 消息级别,H M L
  79 + * @param userList 目标用户, 为null时发送广播消息
  80 + * @param title 消息标题
  81 + * @param msg 消息内容
  82 + * @param endTime 消息有效期
  83 + * @param level 消息级别,H M L
84 84 */
85 85 @Override
86   - public void quickAnnouncementToUser(List<SysUser> userList, String title, String msg, Date endTime, String level){
  86 + public void quickAnnouncementToUser(List<SysUser> userList, String title, String msg, Date endTime, String level) {
87 87 SysAnnouncement sysAnnouncement = new SysAnnouncement();
88 88 sysAnnouncement.setTitile(title);
89 89 sysAnnouncement.setMsgContent(msg);
... ... @@ -97,49 +97,48 @@ public class SysAnnouncementServiceImpl extends ServiceImpl&lt;SysAnnouncementMappe
97 97 sysAnnouncement.setDelFlag(CommonConstant.DEL_FLAG_0.toString());
98 98 sysAnnouncement.setSendStatus(CommonSendStatus.PUBLISHED_STATUS_1);
99 99 saveAnnouncement(sysAnnouncement);
100   -
101   - if(userList == null) {
102   - //发送广播消息
  100 + if (userList == null) {
  101 + // 发送广播消息
103 102 webSocket.sendMessage(sysAnnouncement);
104   - }else if (userList.size() == 0){
  103 + }
  104 + if (userList.size() == 0) {
105 105 throw new JeecgBootException("发送系统消息时,用户列表为空");
106   - } else {
107   - //发送给指定用户
108   - // 2.插入用户通告阅读标记表记录
109   - sysAnnouncement.setMsgType(CommonConstant.MSG_TYPE_UESR);
110   - List<String> userIds = userList.stream().map(SysUser::getId).distinct().map(Object::toString).collect(Collectors.toList());
111   - sysAnnouncement.setUserIds(String.join(",", userIds));
112   - webSocket.sendMessage(userList, sysAnnouncement);
113 106 }
  107 + // 发送给指定用户
  108 + // 2.插入用户通告阅读标记表记录
  109 + sysAnnouncement.setMsgType(CommonConstant.MSG_TYPE_UESR);
  110 + List<String> userIds = userList.stream().map(SysUser::getId).distinct().map(Object::toString).collect(Collectors.toList());
  111 + sysAnnouncement.setUserIds(String.join(",", userIds));
  112 + webSocket.sendMessage(userList, sysAnnouncement);
114 113 updateById(sysAnnouncement);
115 114 }
116 115  
117 116 /**
118 117 * 快速发送系统消息
119   - * @param roleList 目标角色
120   - * @param title 消息标题
121   - * @param msg 消息内容
122   - * @param endTime 消息有效期
123   - * @param level 消息级别,H M L
  118 + * @param roleList 目标角色
  119 + * @param title 消息标题
  120 + * @param msg 消息内容
  121 + * @param endTime 消息有效期
  122 + * @param level 消息级别,H M L
124 123 */
125 124 @Override
126   - public void quickAnnouncementToRole(List<SysRole> roleList, String title, String msg, Date endTime, String level){
127   - List<SysUser> userList = new ArrayList<>();
128   - roleList.forEach(sysRole -> {
129   - Page<SysUser> page = new Page<SysUser>(1, 9999);
130   - String roleId = String.valueOf(sysRole.getId());
131   - IPage<SysUser> pageList = sysUserService.getUserByRoleId(page, roleId, null);
132   - userList.addAll(pageList.getRecords());
133   - });
  125 + public void quickAnnouncementToUserOrRole(List<String> userOrRoleList, String title, String msg, Date endTime, String level) {
  126 + if (CollectionUtils.isEmpty(userOrRoleList)) {
  127 + quickAnnouncementToUser(null, title, msg, endTime, level);
  128 + }
  129 + List<SysUser> userList = sysUserService.getUserByRoleNameArray(userOrRoleList);
  130 + if (CollectionUtils.isEmpty(userList)) {
  131 + return;
  132 + }
134 133 quickAnnouncementToUser(userList, title, msg, endTime, level);
135 134 }
136 135  
137 136 /**
138 137 * 获取用户的新的通知消息,生成未读的消息记录
139   - * @param sysUser
  138 + * @param sysUser
140 139 * @return
141 140 */
142   - public List<SysAnnouncement> getNewAnnouncementOfUser(SysUser sysUser){
  141 + public List<SysAnnouncement> getNewAnnouncementOfUser(SysUser sysUser) {
143 142 String userId = String.valueOf(sysUser.getId());
144 143 LambdaQueryWrapper<SysAnnouncement> querySaWrapper = new LambdaQueryWrapper<SysAnnouncement>();
145 144 // 未删除
... ... @@ -150,8 +149,8 @@ public class SysAnnouncementServiceImpl extends ServiceImpl&lt;SysAnnouncementMappe
150 149 querySaWrapper.ge(SysAnnouncement::getEndTime, new Date());
151 150 querySaWrapper.notInSql(SysAnnouncement::getId, "select annt_id from sys_announcement_send where user_id ='" + sysUser.getId() + "' and read_flag='1'");
152 151 List<SysAnnouncement> announcements = list(querySaWrapper);
153   - announcements = announcements.stream().filter(a-> CommonConstant.MSG_TYPE_ALL.equals(a.getMsgType())
154   - || (a.getUserIds() != null && Arrays.stream(a.getUserIds().split(",")).anyMatch(i->i.equals(userId)))).collect(Collectors.toList());
  152 + announcements = announcements.stream().filter(a -> CommonConstant.MSG_TYPE_ALL.equals(a.getMsgType())
  153 + || (a.getUserIds() != null && Arrays.stream(a.getUserIds().split(",")).anyMatch(i -> i.equals(userId)))).collect(Collectors.toList());
155 154  
156 155 if (announcements.size() > 0) {
157 156 for (int i = 0; i < announcements.size(); i++) {
... ...
huaheng-wms-core/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java
... ... @@ -318,7 +318,7 @@ public class SysUserServiceImpl extends ServiceImpl&lt;SysUserMapper, SysUser&gt; impl
318 318 }
319 319  
320 320 @Override
321   - public List<SysUser> getUserByRoleNameArray(String[] roleNameArr){
  321 + public List<SysUser> getUserByRoleNameArray(List<String> roleNameArr) {
322 322 return userMapper.getUserByRoleNameArray(roleNameArr);
323 323 }
324 324  
... ...
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/controller/TestController.java
... ... @@ -9,6 +9,8 @@ import javax.servlet.http.HttpServletRequest;
9 9  
10 10 import org.jeecg.common.api.vo.Result;
11 11 import org.jeecg.modules.system.service.ISysDataLogService;
  12 +import org.jeecg.modules.system.service.impl.SysAnnouncementServiceImpl;
  13 +import org.jeecg.modules.wms.api.wcs.service.WcsService;
12 14 import org.jeecg.modules.wms.receipt.receiptContainerHeader.entity.ReceiptContainerDetail;
13 15 import org.jeecg.utils.HuahengRedisUtil;
14 16 import org.jeecg.utils.config.ApplicationConfig;
... ... @@ -45,6 +47,9 @@ public class TestController extends HuahengBaseController {
45 47  
46 48 @Autowired
47 49 private ApplicationConfig applicationConfig;
  50 +
  51 + @Autowired
  52 + private WcsService wcsService;
48 53  
49 54 @AccessLimit(seconds = 10, maxCount = 2)
50 55 @PostMapping(value = "/testLimiter")
... ... @@ -66,17 +71,20 @@ public class TestController extends HuahengBaseController {
66 71 @PostMapping(value = "/testRedis")
67 72 public Result<?> testRedis(@RequestBody Map<String, String> paramMap, HttpServletRequest request) throws InterruptedException {
68 73 Result result = new Result<>();
69   - System.out.println(applicationConfig.getArtifactId());
70   - List<ReceiptContainerDetail> receiptContainerDetailList = new ArrayList<>();
71   - ReceiptContainerDetail receiptContainerDetail = new ReceiptContainerDetail();
72   - receiptContainerDetail.setReceiptCode("SDH10101");
73   - receiptContainerDetail.setContainerCode("M00061");
74   - receiptContainerDetail.setMaterialCode("EH812736");
75   - receiptContainerDetail.setQty(BigDecimal.valueOf(10));
76   - receiptContainerDetailList.add(receiptContainerDetail);
77   - LogRecordContext.putVariable("locationCode", "100001");// 操作日志收集
78   - LogRecordContext.putVariable("receiptContainerDetailList", receiptContainerDetailList);// 操作日志收集
79   - LogRecordContext.putVariable("extraJsonString", JSON.toJSONString(receiptContainerDetailList));// 操作日志收集
  74 +
  75 + return wcsService.getAvailableRowdway("L");
  76 +
  77 +// System.out.println(applicationConfig.getArtifactId());
  78 +// List<ReceiptContainerDetail> receiptContainerDetailList = new ArrayList<>();
  79 +// ReceiptContainerDetail receiptContainerDetail = new ReceiptContainerDetail();
  80 +// receiptContainerDetail.setReceiptCode("SDH10101");
  81 +// receiptContainerDetail.setContainerCode("M00061");
  82 +// receiptContainerDetail.setMaterialCode("EH812736");
  83 +// receiptContainerDetail.setQty(BigDecimal.valueOf(10));
  84 +// receiptContainerDetailList.add(receiptContainerDetail);
  85 +// LogRecordContext.putVariable("locationCode", "100001");// 操作日志收集
  86 +// LogRecordContext.putVariable("receiptContainerDetailList", receiptContainerDetailList);// 操作日志收集
  87 +// LogRecordContext.putVariable("extraJsonString", JSON.toJSONString(receiptContainerDetailList));// 操作日志收集
80 88  
81 89 // String testString = "我是testString1";
82 90 // LogRecordContext.putVariable("testString1", testString);
... ... @@ -98,7 +106,7 @@ public class TestController extends HuahengBaseController {
98 106  
99 107 // Thread.sleep(2000l);
100 108 // throw new RuntimeException("自定义失败");
101   - return result;
  109 +// return result;
102 110 // receiptHeaderMap = redisUtil.get(key, new TypeReference<Map<String, ReceiptHeader>>() {});
103 111 // rxpireTime = redisUtil.getExpire(key);
104 112 // log.info("redisUtil.get {} sleep 2s -> {} rxpireTime -> {}", key, JSON.toJSONString(value), rxpireTime);
... ...
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/monitor/job/MaterialLevelAlarmTask.java
1 1 package org.jeecg.modules.wms.monitor.job;
2 2  
3 3 import cn.hutool.core.date.DateUtil;
  4 +import cn.hutool.core.text.StrSpliter;
4 5 import cn.hutool.core.util.StrUtil;
5 6 import lombok.extern.slf4j.Slf4j;
6 7 import org.apache.ibatis.session.SqlSession;
... ... @@ -24,7 +25,6 @@ import java.util.stream.Collectors;
24 25  
25 26 /**
26 27 * 水位预警通知
27   - *
28 28 * @author 游杰
29 29 */
30 30  
... ... @@ -68,12 +68,11 @@ public class MaterialLevelAlarmTask implements Job {
68 68 List<String> list = alarmList.stream().map(MaterialLevelAlarm::toString).collect(Collectors.toList());
69 69 String msg = String.join("\n", list);
70 70  
71   -
72 71 List<SysUser> userList;
73 72 try {
74   - String[] userOrRoleArr = this.parameter.split(",");
  73 + List<String> userOrRoleArr = StrSpliter.split(this.parameter, ",", true, true);
75 74 userList = sysUserService.getUserByRoleNameArray(userOrRoleArr);
76   - if(userList.size() == 0){
  75 + if (userList.size() == 0) {
77 76 userList = null;
78 77 }
79 78 sysAnnouncementService.quickAnnouncementToUser(userList, "物料水位预警", msg, DateUtil.offsetDay(new Date(), 1), "H");
... ...
huaheng-wms-core/src/main/java/org/jeecg/utils/OkHttpUtils.java
1 1 package org.jeecg.utils;
2 2  
3 3 import java.io.IOException;
  4 +import java.net.SocketTimeoutException;
  5 +import java.util.Date;
4 6 import java.util.HashMap;
5 7 import java.util.Map;
6 8 import java.util.Objects;
... ... @@ -9,6 +11,8 @@ import java.util.concurrent.TimeUnit;
9 11 import javax.validation.constraints.NotNull;
10 12  
11 13 import org.jeecg.common.exception.JeecgBootException;
  14 +import org.jeecg.modules.system.service.ISysAnnouncementService;
  15 +import org.jeecg.modules.system.service.impl.SysAnnouncementServiceImpl;
12 16 import org.jeecg.modules.wms.monitor.apiLog.entity.ApiLog;
13 17 import org.jeecg.utils.aspect.ApiLoggerAspect;
14 18 import org.jeecg.utils.constant.QuantityConstant;
... ... @@ -18,8 +22,11 @@ import org.slf4j.LoggerFactory;
18 22 import com.alibaba.fastjson.JSON;
19 23 import com.alibaba.fastjson.TypeReference;
20 24  
  25 +import cn.hutool.core.collection.CollUtil;
  26 +import cn.hutool.core.date.DateUtil;
21 27 import cn.hutool.core.exceptions.ExceptionUtil;
22 28 import cn.hutool.core.util.StrUtil;
  29 +import cn.hutool.extra.spring.SpringUtil;
23 30 import okhttp3.ConnectionPool;
24 31 import okhttp3.FormBody;
25 32 import okhttp3.Interceptor;
... ... @@ -216,6 +223,13 @@ public class OkHttpUtils {
216 223 ApiLoggerAspect.initApiLog(apiLog, request, jsonString);
217 224 response = HTTP_CLIENT_FAST.newCall(request).execute();
218 225 result = response.body().string();
  226 + } catch (SocketTimeoutException e) {
  227 + String errorString = StrUtil.format("执行POST请求异常,url: {},{}", url, ExceptionUtil.getMessage(e));
  228 + log.error(errorString, e);
  229 + ApiLoggerAspect.setApiLogException(apiLog, e);
  230 + ISysAnnouncementService sysAnnouncementService = SpringUtil.getBean(ISysAnnouncementService.class);
  231 + sysAnnouncementService.quickAnnouncementToUserOrRole(CollUtil.newArrayList("tanyibin"), "接口访问超时告警", errorString, DateUtil.offsetDay(new Date(), 1), "H");
  232 + throw new JeecgBootException(errorString, e);
219 233 } catch (Exception e) {
220 234 String errorString = StrUtil.format("执行POST请求异常,url: {},{}", url, ExceptionUtil.getMessage(e));
221 235 log.error(errorString, e);
... ...