From bd71a0bfd6b1cb1916bf2fef235e247a3aacfff1 Mon Sep 17 00:00:00 2001 From: wanggeng <450292408@qq.com> Date: Fri, 23 Jul 2021 21:23:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=88=A0=E9=99=A4=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E9=80=9A=E7=9F=A5=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apis/message/MessageController.java | 12 ++++++ .../message/MessageResourceController.java | 12 ++++++ .../java/com/cm/websocket/dao/INoticeDao.java | 8 ++++ .../vos/message/NoticeDeleteServiceVO.java | 42 +++++++++++++++++++ .../cm/websocket/service/IMessageService.java | 8 ++++ .../cm/websocket/service/INoticeService.java | 14 +++++++ .../service/impl/MessageServiceImpl.java | 39 +++++++++++++++++ .../service/impl/NoticeServiceImpl.java | 14 +++++++ .../mybatis/mapper/notice-mapper.xml | 24 +++++++++++ 9 files changed, 173 insertions(+) create mode 100644 cloud-common-websocket/src/main/java/com/cm/websocket/pojo/vos/message/NoticeDeleteServiceVO.java 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 a5d95a3..0a527a6 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 @@ -10,6 +10,8 @@ import io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.Arrays; + /** * When you feel like quitting. Think about why you started * 当你想要放弃的时候,想想当初你为何开始 @@ -65,4 +67,14 @@ public class MessageController { return messageService.saveNoticeWithTarget(noticeVO, true); } + @ApiOperation(value = "删除通知", notes = "删除通知接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "serviceIds", value = "业务ID", paramType = "path"), + }) + @DeleteMapping("delete/{serviceIds}") + public SuccessResult delete(@PathVariable("serviceIds") String serviceIds) { + messageService.delete(Arrays.asList(serviceIds.split("\\_"))); + return new SuccessResult(); + } + } diff --git a/cloud-common-websocket/src/main/java/com/cm/websocket/controller/resource/message/MessageResourceController.java b/cloud-common-websocket/src/main/java/com/cm/websocket/controller/resource/message/MessageResourceController.java index a95556e..51f88b7 100644 --- a/cloud-common-websocket/src/main/java/com/cm/websocket/controller/resource/message/MessageResourceController.java +++ b/cloud-common-websocket/src/main/java/com/cm/websocket/controller/resource/message/MessageResourceController.java @@ -4,6 +4,7 @@ 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.NoticeDeleteServiceVO; import com.cm.websocket.pojo.vos.message.NoticeVO; import com.cm.websocket.service.IMessageService; import io.swagger.annotations.*; @@ -53,4 +54,15 @@ public class MessageResourceController { return messageService.saveNoticeWithTarget(noticeVO, true); } + @ApiOperation(value = "删除通知", notes = "删除通知接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "serviceIds", value = "业务ID", paramType = "path"), + }) + @PostMapping("delete") + @CheckRequestBodyAnnotation + public SuccessResult delete(@RequestBody NoticeDeleteServiceVO noticeDeleteServiceVO) { + messageService.delete(noticeDeleteServiceVO.getServiceIds()); + return new SuccessResult(); + } + } 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 index f23e93b..0473c3d 100644 --- 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 @@ -1,5 +1,6 @@ package com.cm.websocket.dao; +import com.cm.common.exception.RemoveException; import com.cm.common.exception.SaveException; import com.cm.common.exception.SearchException; import com.cm.common.exception.UpdateException; @@ -92,4 +93,11 @@ public interface INoticeDao { */ Integer count(Map params) throws SearchException; + /** + * 删除 + * + * @param params + * @throws RemoveException + */ + void delete(Map params) throws RemoveException; } diff --git a/cloud-common-websocket/src/main/java/com/cm/websocket/pojo/vos/message/NoticeDeleteServiceVO.java b/cloud-common-websocket/src/main/java/com/cm/websocket/pojo/vos/message/NoticeDeleteServiceVO.java new file mode 100644 index 0000000..0389926 --- /dev/null +++ b/cloud-common-websocket/src/main/java/com/cm/websocket/pojo/vos/message/NoticeDeleteServiceVO.java @@ -0,0 +1,42 @@ +package com.cm.websocket.pojo.vos.message; + +import com.cm.common.annotation.CheckListAnnotation; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.List; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: NoticeMessageVO + * @Description: 通知消息 + * @Author: wanggeng + * @Date: 2021/1/19 5:04 下午 + * @Version: 1.0 + */ +@ApiModel +public class NoticeDeleteServiceVO { + + @ApiModelProperty(name = "serviceIds", value = "业务ID列表") + @CheckListAnnotation(name = "业务ID列表") + private List serviceIds; + + public List getServiceIds() { + return serviceIds; + } + + public void setServiceIds(List serviceIds) { + this.serviceIds = serviceIds; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("{"); + sb.append("\"serviceIds\":") + .append(serviceIds); + sb.append('}'); + return sb.toString(); + } +} 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 b1e12ee..e59c6be 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 @@ -7,6 +7,7 @@ import com.cm.websocket.pojo.AppSocketMessage; import com.cm.websocket.pojo.vos.message.NoticeVO; import javax.websocket.Session; +import java.util.List; /** * When you feel like quitting. Think about why you started @@ -53,4 +54,11 @@ public interface IMessageService { * @param appSocketMessage */ void sendGroupTextMessage(Session fromSession, AppSocketMessage appSocketMessage) throws SessionException; + + /** + * 删除通知 + * + * @param serviceIds + */ + void delete(List serviceIds); } 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 index 9295bf1..77f5d90 100644 --- 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 @@ -153,4 +153,18 @@ public interface INoticeService { */ Integer count(Map params); + /** + * 删除 + * + * @param serviceIds + */ + void deleteByServiceIds(List serviceIds); + + /** + * 通知列表 + * + * @param serviceIds + * @return + */ + List listPO(List serviceIds); } 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 d7ce5e4..cf8128b 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 @@ -14,6 +14,7 @@ import com.cm.websocket.exception.SessionException; import com.cm.websocket.manager.AppSocketSessionManager; import com.cm.websocket.pojo.AppSocketMessage; import com.cm.websocket.pojo.AppSocketSession; +import com.cm.websocket.pojo.pos.NoticePO; import com.cm.websocket.pojo.vos.message.NoticeVO; import com.cm.websocket.service.IMessageService; import com.cm.websocket.service.INoticeService; @@ -23,7 +24,9 @@ import org.springframework.stereotype.Service; import javax.websocket.Session; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -166,4 +169,40 @@ public class MessageServiceImpl extends AbstractService implements IMessageServi WebSocket.send(socketSession.getSession(), appSocketMessage); } } + + @Override + public void delete(List serviceIds) { + List noticePOs = noticeService.listPO(serviceIds); + Set noticeUserIdSet = new HashSet<>(); + noticePOs.forEach(noticePO -> { + noticeUserIdSet.add(noticePO.getUserId()); + }); + // 删除通知 + noticeService.deleteByServiceIds(serviceIds); + // 重新推送数量 + List appSocketSessions = AppSocketSessionManager.getInstance().listSessionByUserIds(new ArrayList<>(noticeUserIdSet)); + // 3s后通知,保证事务提交 + scheduledExecutorService.schedule(() -> { + // 更新状态待办 + for (AppSocketSession appSocketSession : appSocketSessions) { + for (NoticePO noticePO : noticePOs) { + if (StringUtils.equals(appSocketSession.getUserId(), noticePO.getUserId())) { + Session session = appSocketSession.getSession(); + AppSocketMessage.CountNeedToDealWithBody countNeedToDealWithBody = new AppSocketMessage.CountNeedToDealWithBody(); + countNeedToDealWithBody.setSystem(noticePO.getNoticeSystem()); + // 查询待办状态 + List counts = noticeService.listNoticeCount(appSocketSession.getUserId(), countNeedToDealWithBody); + AppSocketMessage appSocketMessage = new AppSocketMessage(AppSocketTypeEnum.SEARCH_COUNT_NEED_TO_DEALT_WITH.getValue(), + true, + AppSocketSessionManager.FORM_SYSTEM, + appSocketSession.getUserId(), + JSONArray.toJSONString(counts)); + WebSocket.send(session, appSocketMessage); + break; + } + } + + } + }, 3, TimeUnit.SECONDS); + } } 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 index 74e5ab3..6acb53b 100644 --- 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 @@ -228,6 +228,20 @@ public class NoticeServiceImpl extends AbstractService implements INoticeService return count == null ? 0 : count; } + @Override + public void deleteByServiceIds(List serviceIds) { + Map params = getHashMap(2); + params.put("serviceIds", serviceIds); + noticeDao.delete(params); + } + + @Override + public List listPO(List serviceIds) { + Map params = getHashMap(2); + params.put("serviceIds", serviceIds); + return listPO(params); + } + /** * 系统列表 * 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 index f3a3c90..b1d963f 100644 --- a/cloud-common-websocket/src/main/resources/mybatis/mapper/notice-mapper.xml +++ b/cloud-common-websocket/src/main/resources/mybatis/mapper/notice-mapper.xml @@ -72,6 +72,19 @@ notice_service_id = #{noticeServiceId} + + + DELETE FROM + socket_notice + WHERE + + notice_service_id IN + + #{serviceIds[${index}]} + + + +