From 5bb0b3c789a0d611a5447c170d4e789effe4f240 Mon Sep 17 00:00:00 2001 From: wanggeng888 <450292408@qq.com> Date: Mon, 29 Mar 2021 22:38:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BE=85=E5=8A=9E=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/cm/websocket/WebSocket.java | 25 +++ .../apis/message/MessageController.java | 15 +- .../message/MessageResourceController.java | 4 +- .../java/com/cm/websocket/dao/INoticeDao.java | 85 +++++++ .../cm/websocket/enums/AppSocketTypeEnum.java | 6 +- .../cm/websocket/pojo/AppSocketMessage.java | 39 ++++ .../com/cm/websocket/pojo/pos/NoticePO.java | 198 +++++++++++++++++ .../websocket/pojo/vos/message/NoticeVO.java | 40 ++++ .../cm/websocket/service/IMessageService.java | 2 +- .../cm/websocket/service/INoticeService.java | 45 ++++ .../service/impl/MessageServiceImpl.java | 11 +- .../service/impl/NoticeServiceImpl.java | 152 +++++++++++++ .../websocket/startup/WebSocketStartUp.java | 5 + .../mybatis/mapper/notice-mapper.xml | 207 ++++++++++++++++++ 14 files changed, 824 insertions(+), 10 deletions(-) rename cloud-common-websocket/src/main/java/com/cm/websocket/controller/{ => resource}/message/MessageResourceController.java (95%) create mode 100644 cloud-common-websocket/src/main/java/com/cm/websocket/dao/INoticeDao.java create mode 100644 cloud-common-websocket/src/main/java/com/cm/websocket/pojo/pos/NoticePO.java create mode 100644 cloud-common-websocket/src/main/java/com/cm/websocket/service/INoticeService.java create mode 100644 cloud-common-websocket/src/main/java/com/cm/websocket/service/impl/NoticeServiceImpl.java create mode 100644 cloud-common-websocket/src/main/resources/mybatis/mapper/notice-mapper.xml diff --git a/cloud-common-websocket/src/main/java/com/cm/websocket/WebSocket.java b/cloud-common-websocket/src/main/java/com/cm/websocket/WebSocket.java index acf4c09..33b0cd8 100644 --- a/cloud-common-websocket/src/main/java/com/cm/websocket/WebSocket.java +++ b/cloud-common-websocket/src/main/java/com/cm/websocket/WebSocket.java @@ -10,9 +10,11 @@ import com.cm.websocket.handler.TextSendHandler; import com.cm.websocket.manager.AppSocketSessionManager; import com.cm.websocket.pojo.AppSocketMessage; import com.cm.websocket.pojo.AppSocketSession; +import com.cm.websocket.service.INoticeService; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; import javax.websocket.OnClose; @@ -38,6 +40,8 @@ import java.util.List; public class WebSocket { private static final Logger log = LoggerFactory.getLogger(WebSocket.class); + private static ApplicationContext applicationContext; + private ApplicationContext serviceContext = applicationContext; /** * 连接成功 @@ -97,6 +101,8 @@ public class WebSocket { listOnlineUser(session, appSocketMessage); } else if (AppSocketTypeEnum.SEARCH_ONLINE_USER_FRIEND.getValue() == appSocketMessage.getType()) { listOnlineUserFriend(session, appSocketMessage); + } else if (AppSocketTypeEnum.SEARCH_COUNT_NEED_TO_DEALT_WITH.getValue() == appSocketMessage.getType()) { + countNeedToDealWith(session, appSocketMessage); } } catch (SessionException e) { sendStatusBody = new AppSocketMessage.SendStatusBody(SendStatusEnum.SESSION_ERROR.getValue(), SendStatusEnum.SESSION_ERROR, e.getMessage()); @@ -119,6 +125,22 @@ public class WebSocket { } } + /** + * 待办总数 + * + * @param session + * @param appSocketMessage + */ + private void countNeedToDealWith(Session session, AppSocketMessage appSocketMessage) { + String userId = appSocketMessage.getFrom(); + appSocketMessage.setTo(userId); + AppSocketMessage.CountNeedToDealWithBody countNeedToDealWithBody = JSONObject.parseObject(appSocketMessage.getBody(), AppSocketMessage.CountNeedToDealWithBody.class); + INoticeService noticeService = serviceContext.getBean(INoticeService.class); + List counts = noticeService.listNoticeCount(userId, countNeedToDealWithBody); + + send(session, appSocketMessage); + } + /** * APP注册会话 * @@ -277,4 +299,7 @@ public class WebSocket { send(fromSession, appSocketMessage); } + public static void setApplicationContext(ApplicationContext applicationContext) { + WebSocket.applicationContext = applicationContext; + } } diff --git a/cloud-common-websocket/src/main/java/com/cm/websocket/controller/apis/message/MessageController.java b/cloud-common-websocket/src/main/java/com/cm/websocket/controller/apis/message/MessageController.java index e0061d0..ef3b941 100644 --- a/cloud-common-websocket/src/main/java/com/cm/websocket/controller/apis/message/MessageController.java +++ b/cloud-common-websocket/src/main/java/com/cm/websocket/controller/apis/message/MessageController.java @@ -1,15 +1,14 @@ package com.cm.websocket.controller.apis.message; +import com.cm.common.annotation.CheckRequestBodyAnnotation; import com.cm.common.constants.ISystemConstant; import com.cm.common.result.ErrorResult; import com.cm.common.result.SuccessResult; +import com.cm.websocket.pojo.vos.message.NoticeVO; import com.cm.websocket.service.IMessageService; import io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; /** * When you feel like quitting. Think about why you started @@ -50,4 +49,12 @@ public class MessageController { return messageService.sendByAppIdTarget(appId, target); } + @ApiOperation(value = "通知消息", notes = "通知消息接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PostMapping("noticewithtarget") + @CheckRequestBodyAnnotation + public SuccessResult saveNoticeWithTarget(@RequestBody NoticeVO noticeVO) throws Exception { + return messageService.saveNoticeWithTarget(noticeVO); + } + } diff --git a/cloud-common-websocket/src/main/java/com/cm/websocket/controller/message/MessageResourceController.java b/cloud-common-websocket/src/main/java/com/cm/websocket/controller/resource/message/MessageResourceController.java similarity index 95% rename from cloud-common-websocket/src/main/java/com/cm/websocket/controller/message/MessageResourceController.java rename to cloud-common-websocket/src/main/java/com/cm/websocket/controller/resource/message/MessageResourceController.java index 9dbfb21..114854d 100644 --- a/cloud-common-websocket/src/main/java/com/cm/websocket/controller/message/MessageResourceController.java +++ b/cloud-common-websocket/src/main/java/com/cm/websocket/controller/resource/message/MessageResourceController.java @@ -1,4 +1,4 @@ -package com.cm.websocket.controller.message; +package com.cm.websocket.controller.resource.message; import com.cm.common.annotation.CheckRequestBodyAnnotation; import com.cm.common.constants.ISystemConstant; @@ -38,7 +38,7 @@ public class MessageResourceController { @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @PostMapping("noticewithtarget") @CheckRequestBodyAnnotation - public SuccessResult saveNoticeWithTarget(@RequestBody NoticeVO noticeVO) { + public SuccessResult saveNoticeWithTarget(@RequestBody NoticeVO noticeVO) throws Exception { return messageService.saveNoticeWithTarget(noticeVO); } diff --git a/cloud-common-websocket/src/main/java/com/cm/websocket/dao/INoticeDao.java b/cloud-common-websocket/src/main/java/com/cm/websocket/dao/INoticeDao.java new file mode 100644 index 0000000..683071d --- /dev/null +++ b/cloud-common-websocket/src/main/java/com/cm/websocket/dao/INoticeDao.java @@ -0,0 +1,85 @@ +package com.cm.websocket.dao; + +import com.cm.common.exception.SaveException; +import com.cm.common.exception.SearchException; +import com.cm.common.exception.UpdateException; +import com.cm.websocket.pojo.pos.NoticePO; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Map; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: INoticeDao + * @Description: 消息通知 + * @Author: wanggeng + * @Date: 2021/3/29 4:37 下午 + * @Version: 1.0 + */ +@Repository +public interface INoticeDao { + + /** + * 保存 + * + * @param params + * @throws SaveException + */ + void save(Map params) throws SaveException; + + /** + * 修改已办 + * + * @param params + * @throws UpdateException + */ + void updateHandle(Map params) throws UpdateException; + + /** + * 列表 + * + * @param params + * @return + * @throws SearchException + */ + List listPO(Map params) throws SearchException; + + /** + * 系统列表 + * + * @param params + * @return + * @throws SearchException + */ + List listSystems(Map params) throws SearchException; + + /** + * 模块列表 + * + * @param params + * @return + * @throws SearchException + */ + List listModules(Map params) throws SearchException; + + /** + * 菜单列表 + * + * @param params + * @return + * @throws SearchException + */ + List listMenus(Map params) throws SearchException; + + /** + * 统计 + * + * @param params + * @return + * @throws SearchException + */ + Integer count(Map params) throws SearchException; +} diff --git a/cloud-common-websocket/src/main/java/com/cm/websocket/enums/AppSocketTypeEnum.java b/cloud-common-websocket/src/main/java/com/cm/websocket/enums/AppSocketTypeEnum.java index 6727629..58c8491 100644 --- a/cloud-common-websocket/src/main/java/com/cm/websocket/enums/AppSocketTypeEnum.java +++ b/cloud-common-websocket/src/main/java/com/cm/websocket/enums/AppSocketTypeEnum.java @@ -65,7 +65,7 @@ public enum AppSocketTypeEnum { */ NOTICE_GROUP_MESSAGE(107), /** - * 群目标通知 + * 目标通知,用于APP打开特定页面 */ NOTICE_TARGET_MESSAGE(108), /** @@ -76,6 +76,10 @@ public enum AppSocketTypeEnum { * 查询朋友在线用户,body 为查询用户的 userId */ SEARCH_ONLINE_USER_FRIEND(601), + /** + * 查询全部待办总数 + */ + SEARCH_COUNT_NEED_TO_DEALT_WITH(602), /** * 发送状态,body 为 BaseResult 的 JSON 字符串 */ diff --git a/cloud-common-websocket/src/main/java/com/cm/websocket/pojo/AppSocketMessage.java b/cloud-common-websocket/src/main/java/com/cm/websocket/pojo/AppSocketMessage.java index 5038373..88b0fe3 100644 --- a/cloud-common-websocket/src/main/java/com/cm/websocket/pojo/AppSocketMessage.java +++ b/cloud-common-websocket/src/main/java/com/cm/websocket/pojo/AppSocketMessage.java @@ -259,4 +259,43 @@ public class AppSocketMessage { } } + public static class CountNeedToDealWithBody { + private String system; + private String module; + private String menu; + private Integer count; + + public String getSystem() { + return system == null ? "" : system; + } + + public void setSystem(String system) { + this.system = system; + } + + public String getModule() { + return module == null ? "" : module; + } + + public void setModule(String module) { + this.module = module; + } + + public String getMenu() { + return menu == null ? "" : menu; + } + + public void setMenu(String menu) { + this.menu = menu; + } + + public Integer getCount() { + return count == null ? 0 : count; + } + + public void setCount(Integer count) { + this.count = count; + } + } + } diff --git a/cloud-common-websocket/src/main/java/com/cm/websocket/pojo/pos/NoticePO.java b/cloud-common-websocket/src/main/java/com/cm/websocket/pojo/pos/NoticePO.java new file mode 100644 index 0000000..fcb9026 --- /dev/null +++ b/cloud-common-websocket/src/main/java/com/cm/websocket/pojo/pos/NoticePO.java @@ -0,0 +1,198 @@ +package com.cm.websocket.pojo.pos; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: NoticePO + * @Description: 消息通知 + * @Author: wanggeng + * @Date: 2021/3/29 4:39 下午 + * @Version: 1.0 + */ +public class NoticePO { + + private Long id; + private String noticeId; + private String noticeTitle; + private String noticeMsg; + private String noticeTarget; + private String noticeSystem; + private String noticeModule; + private String noticeMenu; + private String noticeServiceId; + private String userId; + private Integer isHandle; + private String gmtCreate; + private String creator; + private String gmtModified; + private String modifier; + private Integer isDelete; + + public Long getId() { + return id == null ? 0 : id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getNoticeId() { + return noticeId == null ? "" : noticeId; + } + + public void setNoticeId(String noticeId) { + this.noticeId = noticeId; + } + + public String getNoticeTitle() { + return noticeTitle == null ? "" : noticeTitle; + } + + public void setNoticeTitle(String noticeTitle) { + this.noticeTitle = noticeTitle; + } + + public String getNoticeMsg() { + return noticeMsg == null ? "" : noticeMsg; + } + + public void setNoticeMsg(String noticeMsg) { + this.noticeMsg = noticeMsg; + } + + public String getNoticeTarget() { + return noticeTarget == null ? "" : noticeTarget; + } + + public void setNoticeTarget(String noticeTarget) { + this.noticeTarget = noticeTarget; + } + + public String getNoticeSystem() { + return noticeSystem == null ? "" : noticeSystem; + } + + public void setNoticeSystem(String noticeSystem) { + this.noticeSystem = noticeSystem; + } + + public String getNoticeModule() { + return noticeModule == null ? "" : noticeModule; + } + + public void setNoticeModule(String noticeModule) { + this.noticeModule = noticeModule; + } + + public String getNoticeMenu() { + return noticeMenu == null ? "" : noticeMenu; + } + + public void setNoticeMenu(String noticeMenu) { + this.noticeMenu = noticeMenu; + } + + public String getNoticeServiceId() { + return noticeServiceId == null ? "" : noticeServiceId; + } + + public void setNoticeServiceId(String noticeServiceId) { + this.noticeServiceId = noticeServiceId; + } + + public String getUserId() { + return userId == null ? "" : userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public Integer getIsHandle() { + return isHandle == null ? 0 : isHandle; + } + + public void setIsHandle(Integer isHandle) { + this.isHandle = isHandle; + } + + public String getGmtCreate() { + return gmtCreate == null ? "" : gmtCreate; + } + + public void setGmtCreate(String gmtCreate) { + this.gmtCreate = gmtCreate; + } + + public String getCreator() { + return creator == null ? "" : creator; + } + + public void setCreator(String creator) { + this.creator = creator; + } + + public String getGmtModified() { + return gmtModified == null ? "" : gmtModified; + } + + public void setGmtModified(String gmtModified) { + this.gmtModified = gmtModified; + } + + public String getModifier() { + return modifier == null ? "" : modifier; + } + + public void setModifier(String modifier) { + this.modifier = modifier; + } + + public Integer getIsDelete() { + return isDelete == null ? 0 : isDelete; + } + + public void setIsDelete(Integer isDelete) { + this.isDelete = isDelete; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("{"); + sb.append("\"id\":") + .append(id); + sb.append(",\"noticeId\":\"") + .append(noticeId).append('\"'); + sb.append(",\"noticeTitle\":\"") + .append(noticeTitle).append('\"'); + sb.append(",\"noticeMsg\":\"") + .append(noticeMsg).append('\"'); + sb.append(",\"noticeTarget\":\"") + .append(noticeTarget).append('\"'); + sb.append(",\"noticeSystem\":\"") + .append(noticeSystem).append('\"'); + sb.append(",\"noticeModule\":\"") + .append(noticeModule).append('\"'); + sb.append(",\"noticeMenu\":\"") + .append(noticeMenu).append('\"'); + sb.append(",\"noticeServiceId\":\"") + .append(noticeServiceId).append('\"'); + sb.append(",\"userId\":\"") + .append(userId).append('\"'); + sb.append(",\"isHandle\":") + .append(isHandle); + sb.append(",\"gmtCreate\":\"") + .append(gmtCreate).append('\"'); + sb.append(",\"creator\":\"") + .append(creator).append('\"'); + sb.append(",\"gmtModified\":\"") + .append(gmtModified).append('\"'); + sb.append(",\"modifier\":\"") + .append(modifier).append('\"'); + sb.append(",\"isDelete\":") + .append(isDelete); + sb.append('}'); + return sb.toString(); + } +} diff --git a/cloud-common-websocket/src/main/java/com/cm/websocket/pojo/vos/message/NoticeVO.java b/cloud-common-websocket/src/main/java/com/cm/websocket/pojo/vos/message/NoticeVO.java index bf4bfa2..ba69d1e 100644 --- a/cloud-common-websocket/src/main/java/com/cm/websocket/pojo/vos/message/NoticeVO.java +++ b/cloud-common-websocket/src/main/java/com/cm/websocket/pojo/vos/message/NoticeVO.java @@ -42,6 +42,14 @@ public class NoticeVO { private String msg; @ApiModelProperty(name = "target", value = "目标字符串") private String target; + @ApiModelProperty(name = "system", value = "系统") + private String system; + @ApiModelProperty(name = "module", value = "模块") + private String module; + @ApiModelProperty(name = "menu", value = "菜单") + private String menu; + @ApiModelProperty(name = "serviceId", value = "业务ID") + private String serviceId; public List getUserIds() { return userIds == null ? new ArrayList<>() : userIds; @@ -74,6 +82,38 @@ public class NoticeVO { public void setTarget(String target) { this.target = target; } + + public String getSystem() { + return system == null ? "" : system; + } + + public void setSystem(String system) { + this.system = system; + } + + public String getModule() { + return module == null ? "" : module; + } + + public void setModule(String module) { + this.module = module; + } + + public String getMenu() { + return menu == null ? "" : menu; + } + + public void setMenu(String menu) { + this.menu = menu; + } + + public String getServiceId() { + return serviceId == null ? "" : serviceId; + } + + public void setServiceId(String serviceId) { + this.serviceId = serviceId; + } } } diff --git a/cloud-common-websocket/src/main/java/com/cm/websocket/service/IMessageService.java b/cloud-common-websocket/src/main/java/com/cm/websocket/service/IMessageService.java index 6d64675..696706d 100644 --- a/cloud-common-websocket/src/main/java/com/cm/websocket/service/IMessageService.java +++ b/cloud-common-websocket/src/main/java/com/cm/websocket/service/IMessageService.java @@ -43,7 +43,7 @@ public interface IMessageService { * @return * @throws SearchException */ - SuccessResult saveNoticeWithTarget(NoticeVO noticeVO) throws SearchException; + SuccessResult saveNoticeWithTarget(NoticeVO noticeVO) throws Exception; /** * 群发文本消息 diff --git a/cloud-common-websocket/src/main/java/com/cm/websocket/service/INoticeService.java b/cloud-common-websocket/src/main/java/com/cm/websocket/service/INoticeService.java new file mode 100644 index 0000000..b3d435a --- /dev/null +++ b/cloud-common-websocket/src/main/java/com/cm/websocket/service/INoticeService.java @@ -0,0 +1,45 @@ +package com.cm.websocket.service; + +import com.cm.websocket.pojo.AppSocketMessage; +import com.cm.websocket.pojo.vos.message.NoticeVO; + +import java.util.List; +import java.util.Map; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: INoticeService + * @Description: 消息通知 + * @Author: wanggeng + * @Date: 2021/3/29 4:36 下午 + * @Version: 1.0 + */ +public interface INoticeService { + + /** + * 保存 + * + * @param userId + * @param notice + */ + void save(String userId, NoticeVO.Notice notice) throws Exception; + + /** + * 通知数量 + * + * @param userId + * @param countNeedToDealWithBody + * @return + */ + List listNoticeCount(String userId, AppSocketMessage.CountNeedToDealWithBody countNeedToDealWithBody); + + /** + * 统计 + * + * @param params + * @return + */ + Integer count(Map params); +} diff --git a/cloud-common-websocket/src/main/java/com/cm/websocket/service/impl/MessageServiceImpl.java b/cloud-common-websocket/src/main/java/com/cm/websocket/service/impl/MessageServiceImpl.java index 317cc02..82a5738 100644 --- a/cloud-common-websocket/src/main/java/com/cm/websocket/service/impl/MessageServiceImpl.java +++ b/cloud-common-websocket/src/main/java/com/cm/websocket/service/impl/MessageServiceImpl.java @@ -3,7 +3,6 @@ package com.cm.websocket.service.impl; import com.alibaba.fastjson.JSONObject; import com.cm.common.base.AbstractService; import com.cm.common.exception.SaveException; -import com.cm.common.exception.SearchException; import com.cm.common.plugin.interfaces.IUserImBaseService; import com.cm.common.plugin.pojo.bos.user.UserDepartmentResourceBO; import com.cm.common.result.SuccessResult; @@ -16,6 +15,7 @@ import com.cm.websocket.pojo.AppSocketMessage; import com.cm.websocket.pojo.AppSocketSession; import com.cm.websocket.pojo.vos.message.NoticeVO; import com.cm.websocket.service.IMessageService; +import com.cm.websocket.service.INoticeService; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -39,6 +39,8 @@ public class MessageServiceImpl extends AbstractService implements IMessageServi @Autowired private IUserImBaseService userImBaseService; + @Autowired + private INoticeService noticeService; @Override public SuccessResult sendByAppId(String appId) { @@ -79,7 +81,7 @@ public class MessageServiceImpl extends AbstractService implements IMessageServi } @Override - public SuccessResult saveNoticeWithTarget(NoticeVO noticeVO) throws SearchException { + public SuccessResult saveNoticeWithTarget(NoticeVO noticeVO) throws Exception { for (NoticeVO.Notice notice : noticeVO.getNoticies()) { if (notice.getUserIds() == null || notice.getUserIds().isEmpty()) { continue; @@ -101,6 +103,11 @@ public class MessageServiceImpl extends AbstractService implements IMessageServi JSONObject.toJSONString(noticeBody)); WebSocket.send(session, appSocketMessage); } + // 保存通知记录 + List userIds = notice.getUserIds(); + for (String userId : userIds) { + noticeService.save(userId, notice); + } } return new SuccessResult(); } diff --git a/cloud-common-websocket/src/main/java/com/cm/websocket/service/impl/NoticeServiceImpl.java b/cloud-common-websocket/src/main/java/com/cm/websocket/service/impl/NoticeServiceImpl.java new file mode 100644 index 0000000..036ba24 --- /dev/null +++ b/cloud-common-websocket/src/main/java/com/cm/websocket/service/impl/NoticeServiceImpl.java @@ -0,0 +1,152 @@ +package com.cm.websocket.service.impl; + +import com.cm.common.base.AbstractService; +import com.cm.common.utils.UUIDUtil; +import com.cm.websocket.dao.INoticeDao; +import com.cm.websocket.pojo.AppSocketMessage; +import com.cm.websocket.pojo.vos.message.NoticeVO; +import com.cm.websocket.service.INoticeService; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: NoticeServiceImpl + * @Description: 消息通知 + * @Author: wanggeng + * @Date: 2021/3/29 4:36 下午 + * @Version: 1.0 + */ +@Service +public class NoticeServiceImpl extends AbstractService implements INoticeService { + + @Autowired + private INoticeDao noticeDao; + + @Override + public void save(String userId, NoticeVO.Notice notice) throws Exception { + Map params = getHashMap(16); + params.put("noticeId", UUIDUtil.getUUID()); + params.put("userId", userId); + params.put("noticeTitle", notice.getTitle()); + params.put("noticeMsg", notice.getMsg()); + params.put("noticeTarget", notice.getTarget()); + params.put("noticeSystem", notice.getSystem()); + params.put("noticeModule", notice.getModule()); + params.put("noticeMenu", notice.getMenu()); + params.put("noticeServiceId", notice.getServiceId()); + params.put("isHandle", 0); + setSaveInfoByUserId(params, "1"); + noticeDao.save(params); + } + + @Override + public List listNoticeCount(String userId, AppSocketMessage.CountNeedToDealWithBody countNeedToDealWithBody) { + List noticeCounts = new ArrayList<>(); + Map params = getHashMap(10); + params.put("userId", userId); + params.put("isHandle", 0); + if (StringUtils.isBlank(countNeedToDealWithBody.getSystem())) { + // 系统为空,按系统统计 + List systems = listSystems(userId); + for (String system : systems) { + params.put("noticeSystem", system); + AppSocketMessage.CountNeedToDealWithBody systemCount = new AppSocketMessage.CountNeedToDealWithBody(); + systemCount.setSystem(system); + systemCount.setCount(count(params)); + noticeCounts.add(systemCount); + } + } else if (StringUtils.isBlank(countNeedToDealWithBody.getModule())) { + // 模块为空,按模块统计 + List modules = listModules(userId, countNeedToDealWithBody.getSystem()); + params.put("noticeSystem", countNeedToDealWithBody.getSystem()); + for (String module : modules) { + AppSocketMessage.CountNeedToDealWithBody systemCount = new AppSocketMessage.CountNeedToDealWithBody(); + systemCount.setSystem(countNeedToDealWithBody.getSystem()); + systemCount.setModule(countNeedToDealWithBody.getModule()); + params.put("noticeModule", module); + systemCount.setCount(count(params)); + noticeCounts.add(systemCount); + } + } else if (StringUtils.isBlank(countNeedToDealWithBody.getMenu())) { + // 菜单为空,按菜单统计 + List menus = listMenus(userId, countNeedToDealWithBody.getSystem(), countNeedToDealWithBody.getModule()); + params.put("noticeSystem", countNeedToDealWithBody.getSystem()); + params.put("noticeModule", countNeedToDealWithBody.getModule()); + for (String menu : menus) { + AppSocketMessage.CountNeedToDealWithBody systemCount = new AppSocketMessage.CountNeedToDealWithBody(); + systemCount.setSystem(countNeedToDealWithBody.getSystem()); + systemCount.setModule(countNeedToDealWithBody.getModule()); + params.put("noticeMenu", menu); + systemCount.setCount(count(params)); + noticeCounts.add(systemCount); + } + } else { + // 都不为空,具体菜单数量 + AppSocketMessage.CountNeedToDealWithBody systemCount = new AppSocketMessage.CountNeedToDealWithBody(); + systemCount.setSystem(countNeedToDealWithBody.getSystem()); + systemCount.setModule(countNeedToDealWithBody.getModule()); + systemCount.setMenu(countNeedToDealWithBody.getMenu()); + params.put("noticeSystem", countNeedToDealWithBody.getSystem()); + params.put("noticeModule", countNeedToDealWithBody.getModule()); + params.put("noticeModule", countNeedToDealWithBody.getModule()); + params.put("noticeMenu", countNeedToDealWithBody.getMenu()); + systemCount.setCount(count(params)); + noticeCounts.add(systemCount); + } + return noticeCounts; + } + + @Override + public Integer count(Map params) { + Integer count = noticeDao.count(params); + return count == null ? 0 : count; + } + + /** + * 系统列表 + * + * @param userId + * @return + */ + private List listSystems(String userId) { + Map params = getHashMap(2); + params.put("userId", userId); + return noticeDao.listSystems(params); + } + + /** + * 模块列表 + * + * @param userId + * @return + */ + private List listModules(String userId, String noticeSystem) { + Map params = getHashMap(4); + params.put("userId", userId); + params.put("noticeSystem", noticeSystem); + return noticeDao.listModules(params); + } + + /** + * 菜单列表 + * + * @param userId + * @return + */ + private List listMenus(String userId, String noticeSystem, String noticeModule) { + Map params = getHashMap(6); + params.put("userId", userId); + params.put("noticeSystem", noticeSystem); + params.put("noticeModule", noticeModule); + return noticeDao.listMenus(params); + } + +} diff --git a/cloud-common-websocket/src/main/java/com/cm/websocket/startup/WebSocketStartUp.java b/cloud-common-websocket/src/main/java/com/cm/websocket/startup/WebSocketStartUp.java index 333b844..96884c1 100644 --- a/cloud-common-websocket/src/main/java/com/cm/websocket/startup/WebSocketStartUp.java +++ b/cloud-common-websocket/src/main/java/com/cm/websocket/startup/WebSocketStartUp.java @@ -1,10 +1,12 @@ package com.cm.websocket.startup; +import com.cm.websocket.WebSocket; import com.cm.websocket.manager.AppSocketSessionManager; import com.cm.websocket.service.IMessageService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; /** @@ -22,10 +24,13 @@ public class WebSocketStartUp implements ApplicationRunner { @Autowired private IMessageService messageService; + @Autowired + private ApplicationContext applicationContext; @Override public void run(ApplicationArguments args) throws Exception { AppSocketSessionManager.getInstance().setMessageService(messageService); + WebSocket.setApplicationContext(applicationContext); } } diff --git a/cloud-common-websocket/src/main/resources/mybatis/mapper/notice-mapper.xml b/cloud-common-websocket/src/main/resources/mybatis/mapper/notice-mapper.xml new file mode 100644 index 0000000..02ab228 --- /dev/null +++ b/cloud-common-websocket/src/main/resources/mybatis/mapper/notice-mapper.xml @@ -0,0 +1,207 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + INSERT INTO socket_notice( + notice_id, + notice_title, + notice_msg, + notice_target, + notice_system, + notice_module, + notice_menu, + notice_service_id, + user_id, + is_handle, + gmt_create, + creator, + gmt_modified, + modifier, + is_delete + ) VALUES( + #{noticeId}, + #{noticeTitle}, + #{noticeMsg}, + #{noticeTarget}, + #{noticeSystem}, + #{noticeModule}, + #{noticeMenu}, + #{noticeServiceId}, + #{userId}, + #{isHandle}, + #{gmtCreate}, + #{creator}, + #{gmtModified}, + #{modifier}, + #{isDelete} + ) + + + + + UPDATE + socket_notice + SET + is_handle = #{isHandle}, + gmt_modified = #{gmtModified}, + modifier = #{modifier} + WHERE + notice_service_id = #{noticeServiceId} + + + + + + + + + + + + + + + + + + \ No newline at end of file