Browse Source

review 部分站内信的实现

YunaiV 2 years ago
parent
commit
e8dd66c6f8
10 changed files with 30 additions and 133 deletions
  1. 1 26
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java
  2. 5 10
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java
  3. 7 1
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java
  4. 0 15
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageCreateReqVO.java
  5. 9 4
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessagePageReqVO.java
  6. 0 20
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageUpdateReqVO.java
  7. 0 25
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java
  8. 1 26
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java
  9. 7 5
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateService.java
  10. 0 1
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java

+ 1 - 26
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java

@@ -2,10 +2,8 @@ package cn.iocoder.yudao.module.system.controller.admin.notify;
 
 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageCreateReqVO;
 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO;
 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageRespVO;
-import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageUpdateReqVO;
 import cn.iocoder.yudao.module.system.convert.notify.NotifyMessageConvert;
 import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
 import cn.iocoder.yudao.module.system.service.notify.NotifyMessageService;
@@ -30,30 +28,6 @@ public class NotifyMessageController {
     @Resource
     private NotifyMessageService notifyMessageService;
 
-    @PostMapping("/create")
-    @ApiOperation("创建站内信")
-    @PreAuthorize("@ss.hasPermission('system:notify-message:create')")
-    public CommonResult<Long> createNotifyMessage(@Valid @RequestBody NotifyMessageCreateReqVO createReqVO) {
-        return success(notifyMessageService.createNotifyMessage(createReqVO));
-    }
-
-    @PutMapping("/update")
-    @ApiOperation("更新站内信")
-    @PreAuthorize("@ss.hasPermission('system:notify-message:update')")
-    public CommonResult<Boolean> updateNotifyMessage(@Valid @RequestBody NotifyMessageUpdateReqVO updateReqVO) {
-        notifyMessageService.updateNotifyMessage(updateReqVO);
-        return success(true);
-    }
-
-    @DeleteMapping("/delete")
-    @ApiOperation("删除站内信")
-    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
-    @PreAuthorize("@ss.hasPermission('system:notify-message:delete')")
-    public CommonResult<Boolean> deleteNotifyMessage(@RequestParam("id") Long id) {
-        notifyMessageService.deleteNotifyMessage(id);
-        return success(true);
-    }
-
     @GetMapping("/get")
     @ApiOperation("获得站内信")
     @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
@@ -70,4 +44,5 @@ public class NotifyMessageController {
         PageResult<NotifyMessageDO> pageResult = notifyMessageService.getNotifyMessagePage(pageVO);
         return success(NotifyMessageConvert.INSTANCE.convertPage(pageResult));
     }
+
 }

+ 5 - 10
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java

@@ -19,12 +19,12 @@ import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
 import java.io.IOException;
-import java.util.Collection;
 import java.util.List;
 
 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
 
+// TODO 芋艿:VO 类上的 swagger 注解完善下,例如说 swagger,枚举等等
 @Api(tags = "管理后台 - 站内信模版")
 @RestController
 @RequestMapping("/system/notify-template")
@@ -67,15 +67,6 @@ public class NotifyTemplateController {
         return success(NotifyTemplateConvert.INSTANCE.convert(notifyTemplate));
     }
 
-    @GetMapping("/list")
-    @ApiOperation("获得站内信模版列表")
-    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
-    @PreAuthorize("@ss.hasPermission('system:notify-template:query')")
-    public CommonResult<List<NotifyTemplateRespVO>> getNotifyTemplateList(@RequestParam("ids") Collection<Long> ids) {
-        List<NotifyTemplateDO> list = notifyTemplateService.getNotifyTemplateList(ids);
-        return success(NotifyTemplateConvert.INSTANCE.convertList(list));
-    }
-
     @GetMapping("/page")
     @ApiOperation("获得站内信模版分页")
     @PreAuthorize("@ss.hasPermission('system:notify-template:query')")
@@ -96,4 +87,8 @@ public class NotifyTemplateController {
         ExcelUtils.write(response, "站内信模版.xls", "数据", NotifyTemplateExcelVO.class, datas);
     }
 
+    // TODO @芋艿:参考 SmsTemplateController 的 sendNotify 写一个发送站内信的接口
+
+    // TODO @芋艿:参考 SmsSendServiceImpl,新建一个 NotifySendServiceImpl,用于提供出来给发送消息。注意,不要考虑异步发送,直接 insert 就可以了。也不用考虑发送后的回调
+
 }

+ 7 - 1
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java

@@ -38,7 +38,7 @@ public class UserNotifyMessageController {
     @Resource
     private NotifyMessageService notifyMessageService;
 
-
+    // TODO 芋艿:和 NotifyMessageController 的 page 合并
     @GetMapping("/page")
     @ApiOperation("获得站内信分页")
     public CommonResult<PageResult<NotifyMessageRespVO>> getNotifyMessagePage(@Valid NotifyMessagePageReqVO pageVO) {
@@ -48,6 +48,7 @@ public class UserNotifyMessageController {
         return success(NotifyMessageConvert.INSTANCE.convertPage(pageResult));
     }
 
+    // TODO @芋艿:url 改成 get-recent-list;方法名也改下。默认传入 size = 10;
     @GetMapping("/latest/list")
     @ApiOperation("获得最新10站内信列表")
     public CommonResult<List<NotifyMessageRespVO>> getNotifyLatestMessageList() {
@@ -56,6 +57,7 @@ public class UserNotifyMessageController {
         reqVO.setUserType(UserTypeEnum.ADMIN.getValue());
         reqVO.setPageNo(1);
         reqVO.setPageSize(10);
+        // TODO 芋艿:不要用分页写;
         PageResult<NotifyMessageDO> pageResult = notifyMessageService.getNotifyMessagePage(reqVO);
         if (CollUtil.isNotEmpty(pageResult.getList())) {
             return success(NotifyMessageConvert.INSTANCE.convertList(pageResult.getList()));
@@ -63,12 +65,14 @@ public class UserNotifyMessageController {
         return success(Collections.emptyList());
     }
 
+    // TODO @芋艿:get-unread-count
     @GetMapping("/unread/count")
     @ApiOperation("获得未读站内信数量")
     public CommonResult<Long> getUnreadNotifyMessageCount() {
         return success(notifyMessageService.getUnreadNotifyMessageCount(getLoginUserId(), UserTypeEnum.ADMIN.getValue()));
     }
 
+    // TODO @芋艿:把 get 站内信,和更新站内信已经读分开。其中更新单条和多条,使用一个接口就好列
     @GetMapping("/read")
     @ApiOperation("获得站内信")
     @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
@@ -79,6 +83,7 @@ public class UserNotifyMessageController {
         return success(NotifyMessageConvert.INSTANCE.convert(notifyMessage));
     }
 
+    // TODO @芋艿:PutMapping;update-list-read
     @GetMapping("/read/list")
     @ApiOperation("批量标记已读")
     @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
@@ -87,6 +92,7 @@ public class UserNotifyMessageController {
         return success(Boolean.TRUE);
     }
 
+    // TODO @芋艿:PutMapping:update-all-read
     @GetMapping("/read/all")
     @ApiOperation("所有未读消息标记已读")
     public CommonResult<Boolean> batchUpdateAllNotifyMessageReadStatus() {

+ 0 - 15
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageCreateReqVO.java

@@ -1,15 +0,0 @@
-package cn.iocoder.yudao.module.system.controller.admin.notify.vo.message;
-
-import lombok.*;
-import io.swagger.annotations.*;
-
-@ApiModel("管理后台 - 站内信创建 Request VO")
-@Data
-@EqualsAndHashCode(callSuper = true)
-@ToString(callSuper = true)
-public class NotifyMessageCreateReqVO extends NotifyMessageBaseVO {
-
-    @ApiModelProperty(value = "站内信模版编号")
-    private Long templateId;
-
-}

+ 9 - 4
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessagePageReqVO.java

@@ -1,11 +1,15 @@
 package cn.iocoder.yudao.module.system.controller.admin.notify.vo.message;
 
-import lombok.*;
-import java.util.*;
-import io.swagger.annotations.*;
 import cn.iocoder.yudao.framework.common.pojo.PageParam;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.ToString;
 import org.springframework.format.annotation.DateTimeFormat;
 
+import java.util.Date;
+
 import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
 
 @ApiModel("管理后台 - 站内信分页 Request VO")
@@ -18,12 +22,13 @@ public class NotifyMessagePageReqVO extends PageParam {
     private String title;
 
     @ApiModelProperty(value = "是否已读 0-未读  1-已读")
-    private Integer readStatus;
+    private Boolean readStatus;
 
     @ApiModelProperty(value = "创建时间")
     @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
     private Date[] createTime;
 
+    // TODO 芋艿:去掉 userId 和 userType,不要在 VO 里
 
     @ApiModelProperty(value = "用户编号", hidden = true)
     private Long userId;

+ 0 - 20
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageUpdateReqVO.java

@@ -1,20 +0,0 @@
-package cn.iocoder.yudao.module.system.controller.admin.notify.vo.message;
-
-import lombok.*;
-import io.swagger.annotations.*;
-import javax.validation.constraints.*;
-
-@ApiModel("管理后台 - 站内信更新 Request VO")
-@Data
-@EqualsAndHashCode(callSuper = true)
-@ToString(callSuper = true)
-public class NotifyMessageUpdateReqVO extends NotifyMessageBaseVO {
-
-    @ApiModelProperty(value = "ID", required = true)
-    @NotNull(message = "ID不能为空")
-    private Long id;
-
-    @ApiModelProperty(value = "站内信模版编号")
-    private Long templateId;
-
-}

+ 0 - 25
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java

@@ -1,12 +1,9 @@
 package cn.iocoder.yudao.module.system.service.notify;
 
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageCreateReqVO;
 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO;
-import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageUpdateReqVO;
 import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
 
-import javax.validation.Valid;
 import java.util.Collection;
 import java.util.List;
 
@@ -17,28 +14,6 @@ import java.util.List;
  */
 public interface NotifyMessageService {
 
-    /**
-     * 创建站内信
-     *
-     * @param createReqVO 创建信息
-     * @return 编号
-     */
-    Long createNotifyMessage(@Valid NotifyMessageCreateReqVO createReqVO);
-
-    /**
-     * 更新站内信
-     *
-     * @param updateReqVO 更新信息
-     */
-    void updateNotifyMessage(@Valid NotifyMessageUpdateReqVO updateReqVO);
-
-    /**
-     * 删除站内信
-     *
-     * @param id 编号
-     */
-    void deleteNotifyMessage(Long id);
-
     /**
      * 获得站内信
      *

+ 1 - 26
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java

@@ -71,32 +71,6 @@ public class NotifyMessageServiceImpl implements NotifyMessageService {
         }).collect(Collectors.toList());
     }
 
-    @Override
-    public Long createNotifyMessage(NotifyMessageCreateReqVO createReqVO) {
-        // 插入
-        NotifyMessageDO notifyMessage = NotifyMessageConvert.INSTANCE.convert(createReqVO);
-        notifyMessageMapper.insert(notifyMessage);
-        // 返回
-        return notifyMessage.getId();
-    }
-
-    @Override
-    public void updateNotifyMessage(NotifyMessageUpdateReqVO updateReqVO) {
-        // 校验存在
-        this.validateNotifyMessageExists(updateReqVO.getId());
-        // 更新
-        NotifyMessageDO updateObj = NotifyMessageConvert.INSTANCE.convert(updateReqVO);
-        notifyMessageMapper.updateById(updateObj);
-    }
-
-    @Override
-    public void deleteNotifyMessage(Long id) {
-        // 校验存在
-        this.validateNotifyMessageExists(id);
-        // 删除
-        notifyMessageMapper.deleteById(id);
-    }
-
     private void validateNotifyMessageExists(Long id) {
         if (notifyMessageMapper.selectById(id) == null) {
             throw exception(NOTIFY_MESSAGE_NOT_EXISTS);
@@ -185,6 +159,7 @@ public class NotifyMessageServiceImpl implements NotifyMessageService {
         }
     }
 
+    // TODO 芋艿:批量更新,不要单条遍历哈。
     private void batchUpdateReadStatus(Collection<Long> ids) {
         if (CollUtil.isNotEmpty(ids)) {
             for (Long id : ids) {

+ 7 - 5
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateService.java

@@ -1,21 +1,23 @@
 package cn.iocoder.yudao.module.system.service.notify;
 
-import java.util.*;
-import javax.validation.*;
-
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateCreateReqVO;
 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateExportReqVO;
 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplatePageReqVO;
 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateUpdateReqVO;
 import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO;
-import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO;
+
+import javax.validation.Valid;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
 
 /**
  * 站内信模版 Service 接口
  *
  * @author xrcoder
  */
+// TODO 芋艿:缺少单测,可以参考 SmsTemplateServiceTest 写下
 public interface NotifyTemplateService {
 
     /**

+ 0 - 1
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java

@@ -114,7 +114,6 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService {
         initLocalCache();
     }
 
-
     /**
      * 获得站内信模板,从缓存中
      *