|
@@ -0,0 +1,106 @@
|
|
|
|
|
+package com.sckw.message.service;
|
|
|
|
|
+
|
|
|
|
|
+import com.sckw.core.utils.CollectionUtils;
|
|
|
|
|
+import com.sckw.message.model.KwmMessage;
|
|
|
|
|
+import com.sckw.message.model.KwmMessageUser;
|
|
|
|
|
+import com.sckw.message.model.vo.req.DeleteMessagesReqVO;
|
|
|
|
|
+import com.sckw.message.model.vo.req.FindMessagesReqVO;
|
|
|
|
|
+import com.sckw.message.model.vo.req.ReadMessagesReqVO;
|
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.Collections;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @desc: 消息相关service
|
|
|
|
|
+ * @author: yzc
|
|
|
|
|
+ * @date: 2023-06-09 10:58
|
|
|
|
|
+ */
|
|
|
|
|
+@Service
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+@RequiredArgsConstructor
|
|
|
|
|
+public class MessageService {
|
|
|
|
|
+
|
|
|
|
|
+ private final KwmMessageService kwmMessageService;
|
|
|
|
|
+ private final KwmMessageUserService kwmMessageUserService;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @desc: 查询消息列表
|
|
|
|
|
+ * @author: yzc
|
|
|
|
|
+ * @date: 2023-06-09 14:21
|
|
|
|
|
+ * @param params
|
|
|
|
|
+ * @return java.util.List<com.sckw.message.model.KwmMessage>
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<KwmMessage> selectMessages(FindMessagesReqVO params) {
|
|
|
|
|
+ //TODO 当前线程获取用户id
|
|
|
|
|
+ List<Long> msgIds = kwmMessageUserService.getMsgIdsByUserId(1L);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(msgIds)) {
|
|
|
|
|
+ return Collections.emptyList();
|
|
|
|
|
+ }
|
|
|
|
|
+ return kwmMessageService.getList(msgIds, params.getCategory(), params.getType(), null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @desc: 更新消息已读
|
|
|
|
|
+ * @author: yzc
|
|
|
|
|
+ * @date: 2023-06-09 14:20
|
|
|
|
|
+ * @param reqVO
|
|
|
|
|
+ * @return void
|
|
|
|
|
+ */
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public void read(ReadMessagesReqVO reqVO) {
|
|
|
|
|
+ //TODO 当前线程获取用户id
|
|
|
|
|
+ List<Long> msgIds = kwmMessageUserService.getMsgIdsByUserId(1L);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(msgIds)){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<Long> ids = reqVO.getMsgIds();
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(ids)) {
|
|
|
|
|
+ List<Long> list = ids.stream().filter(msgIds::contains).toList();
|
|
|
|
|
+ kwmMessageUserService.readByUserAndMsgIds(1L, list);
|
|
|
|
|
+ kwmMessageService.readByMsgIds(list);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ List<KwmMessage> messageList = kwmMessageService.getList(msgIds, reqVO.getCategory(), reqVO.getType(), 0);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(messageList)){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<Long> updateMsgIds = messageList.stream().map(KwmMessage::getId).toList();
|
|
|
|
|
+ kwmMessageUserService.readByUserAndMsgIds(1L, updateMsgIds);
|
|
|
|
|
+ kwmMessageService.readByMsgIds(updateMsgIds);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @desc: 删除消息
|
|
|
|
|
+ * @author: yzc
|
|
|
|
|
+ * @date: 2023-06-09 14:20
|
|
|
|
|
+ * @param reqVO
|
|
|
|
|
+ * @return void
|
|
|
|
|
+ */
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public void delete(DeleteMessagesReqVO reqVO) {
|
|
|
|
|
+ //TODO 当前线程获取用户id
|
|
|
|
|
+ List<Long> msgIds = kwmMessageUserService.getMsgIdsByUserId(1L);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(msgIds)){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<Long> ids = reqVO.getMsgIds();
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(ids)) {
|
|
|
|
|
+ List<Long> list = ids.stream().filter(msgIds::contains).toList();
|
|
|
|
|
+ kwmMessageUserService.delByUserAndMsgIds(1L, list);
|
|
|
|
|
+ kwmMessageService.delByMsgIds(list);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ List<KwmMessage> messageList = kwmMessageService.getList(msgIds, reqVO.getCategory(), reqVO.getType(), null);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(messageList)){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<Long> delMsgIds = messageList.stream().map(KwmMessage::getId).toList();
|
|
|
|
|
+ kwmMessageUserService.delByUserAndMsgIds(1L, delMsgIds);
|
|
|
|
|
+ kwmMessageService.delByMsgIds(delMsgIds);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|