Explorar o código

feat(message): message crud

huey %!s(int64=2) %!d(string=hai) anos
pai
achega
5c28e11c09

+ 15 - 0
src/main/java/com/dragon/tj/portal/common/convert/mesage/MessageInfoVOConvert.java

@@ -0,0 +1,15 @@
+package com.dragon.tj.portal.common.convert.mesage;
+
+import com.dragon.tj.portal.common.vo.message.MessageInfoParam;
+import com.dragon.tj.portal.common.vo.message.MessageInfoVO;
+import com.dragon.tj.portal.entity.MessageInfo;
+import org.mapstruct.Mapper;
+import org.mapstruct.MappingConstants;
+
+@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
+public interface MessageInfoVOConvert {
+
+    MessageInfoVO toVo(MessageInfo messageInfo);
+
+    MessageInfo paramTo(MessageInfoParam messageInfoParam);
+}

+ 1 - 0
src/main/java/com/dragon/tj/portal/common/enums/MessageInfoErrorEnums.java

@@ -27,6 +27,7 @@ public interface MessageInfoErrorEnums extends FrameResultError {
 
         MESSAGE_CONTRACTS_EMPTY(201001, "信息交流的联系人不能为空!"),
         MESSAGE_DEPT_EMPTY(201002, "当前信息类型部门名称不能为空!"),
+        MESSAGE_READ_ALREADY(201002, "当前信息已读"),
 
 
         ;

+ 24 - 0
src/main/java/com/dragon/tj/portal/common/enums/message/ReadStatusEnum.java

@@ -0,0 +1,24 @@
+package com.dragon.tj.portal.common.enums.message;
+
+/**
+ * @author huey China.
+ * @Description : 消息读状态
+ * @Date Created in 2023/6/28 15:48
+ */
+public enum ReadStatusEnum {
+
+    NO(0, "未读"),
+    YES(1, "已读");
+
+    private final Integer value;
+    private final String name;
+
+    ReadStatusEnum(Integer value, String name) {
+        this.value = value;
+        this.name = name;
+    }
+
+    public Integer value() {
+        return this.value;
+    }
+}

+ 78 - 0
src/main/java/com/dragon/tj/portal/common/vo/message/MessageInfoParam.java

@@ -0,0 +1,78 @@
+package com.dragon.tj.portal.common.vo.message;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+
+import java.time.LocalDateTime;
+
+/**
+ * @author huey China.
+ * @Description : vo
+ * @Date Created in 2023/6/28 15:19
+ */
+@ToString
+@Getter
+@Setter
+public class MessageInfoParam {
+
+
+    /**
+     * 主键
+     */
+
+    private Long id;
+
+    /**
+     * 信息类型 1 通知公告 2信息交流 3 标准规范
+     */
+    private Integer messageType;
+
+    /**
+     * 阅读状态 默认0未读 1已读
+     */
+    private Integer readStatus;
+
+    /**
+     * 信息标题
+     */
+    private String title;
+
+    /**
+     * 信息内容
+     */
+    private String content;
+
+    /**
+     * 附件地址
+     */
+    private String attachmentPath;
+
+    /**
+     * 创建人
+     */
+    private String createBy;
+    private String createUser;
+
+    /**
+     * 修改人
+     */
+    private String updateBy;
+    private String updateUser;
+
+    /**
+     * 创建时间
+     */
+    private LocalDateTime createTime;
+
+    /**
+     * 更新时间
+     */
+    private LocalDateTime updateTime;
+
+
+    /**
+     * 版本号
+     */
+    private Integer version;
+}

+ 78 - 0
src/main/java/com/dragon/tj/portal/common/vo/message/MessageInfoVO.java

@@ -0,0 +1,78 @@
+package com.dragon.tj.portal.common.vo.message;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+
+import java.time.LocalDateTime;
+
+/**
+ * @author huey China.
+ * @Description : vo
+ * @Date Created in 2023/6/28 15:19
+ */
+@ToString
+@Getter
+@Setter
+public class MessageInfoVO {
+
+
+    /**
+     * 主键
+     */
+
+    private Long id;
+
+    /**
+     * 信息类型 1 通知公告 2信息交流 3 标准规范
+     */
+    private Integer messageType;
+
+    /**
+     * 阅读状态 默认0未读 1已读
+     */
+    private Integer readStatus;
+
+    /**
+     * 信息标题
+     */
+    private String title;
+
+    /**
+     * 信息内容
+     */
+    private String content;
+
+    /**
+     * 附件地址
+     */
+    private String attachmentPath;
+
+    /**
+     * 创建人
+     */
+    private String createBy;
+    private String createUser;
+
+    /**
+     * 修改人
+     */
+    private String updateBy;
+    private String updateUser;
+
+    /**
+     * 创建时间
+     */
+    private LocalDateTime createTime;
+
+    /**
+     * 更新时间
+     */
+    private LocalDateTime updateTime;
+
+
+    /**
+     * 版本号
+     */
+    private Integer version;
+}

+ 28 - 8
src/main/java/com/dragon/tj/portal/controller/MessageInfoController.java

@@ -1,8 +1,14 @@
 package com.dragon.tj.portal.controller;
 
 
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import com.dragon.tj.portal.common.base.R;
+import com.dragon.tj.portal.common.vo.message.MessageInfoParam;
+import com.dragon.tj.portal.common.vo.message.MessageInfoVO;
+import com.dragon.tj.portal.component.log.annotation.SysLog;
+import com.dragon.tj.portal.service.MessageInfoService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
 
 /**
  * <p>
@@ -16,19 +22,33 @@ import org.springframework.web.bind.annotation.RestController;
 @RequestMapping("/messageInfo")
 public class MessageInfoController {
 
+    @Autowired
+    private MessageInfoService messageInfoService;
+
     /**
-     *
-     *详情
+     * 详情
      */
+    @GetMapping("detail")
+    public R detail(Long id) {
+        MessageInfoVO messageInfoVO = messageInfoService.detail(id);
+        return R.ok(messageInfoVO);
+    }
 
     /**
-     *
-     *修改
+     * 修改
      */
+    @SysLog("信息更新")
+    @PostMapping("update")
+    public R update(@Validated @RequestBody MessageInfoParam messageInfoParam) {
+        return R.ok(messageInfoService.update(messageInfoParam));
+    }
 
     /**
-     *
-     *批阅
+     * 批阅
      */
+    @GetMapping("read")
+    public R read(Long id) {
+        return R.ok(messageInfoService.read(id));
+    }
 }
 

+ 8 - 0
src/main/java/com/dragon/tj/portal/service/MessageInfoService.java

@@ -3,6 +3,8 @@ package com.dragon.tj.portal.service;
 import com.dragon.tj.portal.auth.model.LoginUser;
 import com.dragon.tj.portal.common.base.R;
 import com.dragon.tj.portal.common.dto.message.MessageInfoReq;
+import com.dragon.tj.portal.common.vo.message.MessageInfoParam;
+import com.dragon.tj.portal.common.vo.message.MessageInfoVO;
 import com.dragon.tj.portal.entity.MessageInfo;
 import com.baomidou.mybatisplus.extension.service.IService;
 
@@ -17,4 +19,10 @@ import com.baomidou.mybatisplus.extension.service.IService;
 public interface MessageInfoService extends IService<MessageInfo> {
 
     R push(MessageInfoReq messag, LoginUser loginUser);
+
+    MessageInfoVO detail(Long id);
+
+    boolean update(MessageInfoParam messageInfoParam);
+
+    boolean read(Long id);
 }

+ 41 - 10
src/main/java/com/dragon/tj/portal/service/impl/MessageInfoServiceImpl.java

@@ -8,10 +8,14 @@ import com.dragon.tj.portal.auth.web.service.SysDeptService;
 import com.dragon.tj.portal.common.base.R;
 import com.dragon.tj.portal.common.constants.BusinessConstants;
 import com.dragon.tj.portal.common.convert.MessageReqConvert;
+import com.dragon.tj.portal.common.convert.mesage.MessageInfoVOConvert;
 import com.dragon.tj.portal.common.dto.message.MessageInfoReq;
 import com.dragon.tj.portal.common.dto.message.MessageInfoSend;
 import com.dragon.tj.portal.common.enums.MessageInfoErrorEnums;
 import com.dragon.tj.portal.common.enums.ScopeEnums;
+import com.dragon.tj.portal.common.enums.message.ReadStatusEnum;
+import com.dragon.tj.portal.common.vo.message.MessageInfoParam;
+import com.dragon.tj.portal.common.vo.message.MessageInfoVO;
 import com.dragon.tj.portal.component.exception.message.MessageInfoException;
 import com.dragon.tj.portal.component.message.KafkaInitialConfiguration;
 import com.dragon.tj.portal.component.message.MessageProducer;
@@ -51,22 +55,38 @@ public class MessageInfoServiceImpl extends ServiceImpl<MessageInfoMapper, Messa
     @Autowired
     private MessageReqConvert messageReqConvert;
 
+    @Autowired
+    private MessageInfoVOConvert messageInfoVOConvert;
+
     @Override
     public R push(MessageInfoReq messageInfoReq, LoginUser loginUser) {
-        return R.ok(this.doMessage(messageInfoReq,loginUser));
+        return R.ok(this.doMessage(messageInfoReq, loginUser));
     }
 
-    /**
-     * @author huey China.
-     * @Description : 预先处理 TODO message 没走字典
-     * @Date Created in 2023/6/16 11:25
-     */
-    private boolean doMessage(MessageInfoReq messageInfoReq, LoginUser loginUser) {
+    @Override
+    public MessageInfoVO detail(Long id) {
+        MessageInfo messageInfo = this.getById(id);
+        return messageInfoVOConvert.toVo(messageInfo);
+    }
 
-        this.validate(messageInfoReq);
-        return this.transferIds(messageInfoReq,loginUser);
+    @Override
+    public boolean update(MessageInfoParam messageInfoParam) {
+        MessageInfo messageInfo = messageInfoVOConvert.paramTo(messageInfoParam);
+        return this.updateById(messageInfo);
     }
 
+    @Override
+    public boolean read(Long id) {
+        MessageInfo messageInfo = this.getById(id);
+        Integer readStatus = messageInfo.getReadStatus();
+        if (ReadStatusEnum.YES.value().equals(readStatus)) {
+            throw new MessageInfoException(MessageInfoErrorEnums.Code.MESSAGE_READ_ALREADY);
+        }
+        messageInfo.setReadStatus(ReadStatusEnum.YES.value());
+        return this.updateById(messageInfo);
+    }
+
+
     /**
      * @author huey China.
      * @Description :
@@ -81,7 +101,7 @@ public class MessageInfoServiceImpl extends ServiceImpl<MessageInfoMapper, Messa
         Set<String> messageClientIds = this.getMessageClientIds(messageType, scopeIds);
 
         if (CollUtil.isNotEmpty(messageClientIds)) {
-            MessageInfoSend messageInfoSend = this.doSaveMessageInfo(messageInfoReq, messageClientIds,loginUser);
+            MessageInfoSend messageInfoSend = this.doSaveMessageInfo(messageInfoReq, messageClientIds, loginUser);
             isSend = producer.send(KafkaInitialConfiguration.sseTopic, JSON.toJSONString(messageInfoSend));
         }
         return isSend;
@@ -152,6 +172,17 @@ public class MessageInfoServiceImpl extends ServiceImpl<MessageInfoMapper, Messa
     }
 
 
+    /**
+     * @author huey China.
+     * @Description : 预先处理 TODO message 没走字典
+     * @Date Created in 2023/6/16 11:25
+     */
+    private boolean doMessage(MessageInfoReq messageInfoReq, LoginUser loginUser) {
+
+        this.validate(messageInfoReq);
+        return this.transferIds(messageInfoReq, loginUser);
+    }
+
     /**
      * @author huey China.
      * @Description : md5 验证消息唯一性