fix(站内信功能调整): 接口fix

This commit is contained in:
luowenfeng 2022-11-23 12:26:51 +08:00
parent e8dd66c6f8
commit f77522980f
15 changed files with 248 additions and 140 deletions

View File

@ -1,5 +1,7 @@
package cn.iocoder.yudao.module.system.controller.admin.notify;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
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.NotifyMessagePageReqVO;
@ -17,7 +19,12 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@Api(tags = "管理后台 - 站内信")
@RestController
@ -41,8 +48,46 @@ public class NotifyMessageController {
@ApiOperation("获得站内信分页")
@PreAuthorize("@ss.hasPermission('system:notify-message:query')")
public CommonResult<PageResult<NotifyMessageRespVO>> getNotifyMessagePage(@Valid NotifyMessagePageReqVO pageVO) {
pageVO.setUserId(getLoginUserId());
pageVO.setUserType(UserTypeEnum.ADMIN.getValue());
PageResult<NotifyMessageDO> pageResult = notifyMessageService.getNotifyMessagePage(pageVO);
return success(NotifyMessageConvert.INSTANCE.convertPage(pageResult));
}
@GetMapping("/get-recent-list")
@ApiOperation("获取当前用户最新站内信默认10条")
@ApiImplicitParam(name = "size", value = "10", defaultValue = "10", dataTypeClass = Integer.class)
public CommonResult<List<NotifyMessageRespVO>> getRecentList(@RequestParam(name = "size", defaultValue = "10") Integer size) {
NotifyMessagePageReqVO reqVO = new NotifyMessagePageReqVO();
reqVO.setUserId(getLoginUserId());
reqVO.setUserType(UserTypeEnum.ADMIN.getValue());
List<NotifyMessageDO> pageResult = notifyMessageService.getNotifyMessageList(reqVO, size);
if (CollUtil.isNotEmpty(pageResult)) {
return success(NotifyMessageConvert.INSTANCE.convertList(pageResult));
}
return success(Collections.emptyList());
}
@GetMapping("/get-unread-count")
@ApiOperation("获得未读站内信数量")
public CommonResult<Long> getUnreadCount() {
return success(notifyMessageService.getUnreadNotifyMessageCount(getLoginUserId(), UserTypeEnum.ADMIN.getValue()));
}
@GetMapping("/update-list-read")
@ApiOperation("批量标记已读")
@ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
public CommonResult<Boolean> batchUpdateNotifyMessageReadStatus(@RequestParam("ids") Collection<Long> ids) {
notifyMessageService.batchUpdateNotifyMessageReadStatus(ids, getLoginUserId());
return success(Boolean.TRUE);
}
@GetMapping("/update-all-read")
@ApiOperation("所有未读消息标记已读")
public CommonResult<Boolean> batchUpdateAllNotifyMessageReadStatus() {
notifyMessageService.batchUpdateAllNotifyMessageReadStatus(getLoginUserId(), UserTypeEnum.ADMIN.getValue());
return success(Boolean.TRUE);
}
}

View File

@ -7,6 +7,7 @@ import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.*;
import cn.iocoder.yudao.module.system.convert.notify.NotifyTemplateConvert;
import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO;
import cn.iocoder.yudao.module.system.service.notify.NotifySendService;
import cn.iocoder.yudao.module.system.service.notify.NotifyTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
@ -24,7 +25,6 @@ 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")
@ -34,6 +34,10 @@ public class NotifyTemplateController {
@Resource
private NotifyTemplateService notifyTemplateService;
@Resource
private NotifySendService notifySendService;
@PostMapping("/create")
@ApiOperation("创建站内信模版")
@PreAuthorize("@ss.hasPermission('system:notify-template:create')")
@ -87,8 +91,10 @@ public class NotifyTemplateController {
ExcelUtils.write(response, "站内信模版.xls", "数据", NotifyTemplateExcelVO.class, datas);
}
// TODO @芋艿参考 SmsTemplateController sendNotify 写一个发送站内信的接口
// TODO @芋艿参考 SmsSendServiceImpl新建一个 NotifySendServiceImpl用于提供出来给发送消息注意不要考虑异步发送直接 insert 就可以了也不用考虑发送后的回调
@PostMapping("/send-notify")
@ApiOperation("发送站内信")
public CommonResult<Long> sendNotify(@Valid @RequestBody NotifyTemplateSendReqVO sendReqVO) {
return success(notifySendService.sendSingleNotifyToAdmin(sendReqVO.getUserId(),
sendReqVO.getTemplateId(), sendReqVO.getTemplateParams()));
}
}

View File

@ -1,102 +0,0 @@
package cn.iocoder.yudao.module.system.controller.admin.notify;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
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.NotifyMessagePageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageRespVO;
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.enums.notify.NotifyReadStatusEnum;
import cn.iocoder.yudao.module.system.service.notify.NotifyMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
// TODO 芋艿合并到 合并到 NotifyTemplateController
@Api(tags = "管理后台 - 站内信-消息中心")
@RestController
@RequestMapping("/system/user/notify-message")
@Validated
public class UserNotifyMessageController {
@Resource
private NotifyMessageService notifyMessageService;
// TODO 芋艿 NotifyMessageController page 合并
@GetMapping("/page")
@ApiOperation("获得站内信分页")
public CommonResult<PageResult<NotifyMessageRespVO>> getNotifyMessagePage(@Valid NotifyMessagePageReqVO pageVO) {
pageVO.setUserId(getLoginUserId());
pageVO.setUserType(UserTypeEnum.ADMIN.getValue());
PageResult<NotifyMessageDO> pageResult = notifyMessageService.getNotifyMessagePage(pageVO);
return success(NotifyMessageConvert.INSTANCE.convertPage(pageResult));
}
// TODO @芋艿url 改成 get-recent-list方法名也改下默认传入 size = 10
@GetMapping("/latest/list")
@ApiOperation("获得最新10站内信列表")
public CommonResult<List<NotifyMessageRespVO>> getNotifyLatestMessageList() {
NotifyMessagePageReqVO reqVO = new NotifyMessagePageReqVO();
reqVO.setUserId(getLoginUserId());
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()));
}
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)
public CommonResult<NotifyMessageRespVO> readNotifyMessage(@RequestParam("id") Long id) {
NotifyMessageDO notifyMessage = notifyMessageService.getNotifyMessage(id);
// 记录消息已读
notifyMessageService.updateNotifyMessageReadStatus(id, NotifyReadStatusEnum.READ.getStatus());
return success(NotifyMessageConvert.INSTANCE.convert(notifyMessage));
}
// TODO @芋艿PutMappingupdate-list-read
@GetMapping("/read/list")
@ApiOperation("批量标记已读")
@ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
public CommonResult<Boolean> batchUpdateNotifyMessageReadStatus(@RequestParam("ids") Collection<Long> ids) {
notifyMessageService.batchUpdateNotifyMessageReadStatus(ids, getLoginUserId());
return success(Boolean.TRUE);
}
// TODO @芋艿PutMappingupdate-all-read
@GetMapping("/read/all")
@ApiOperation("所有未读消息标记已读")
public CommonResult<Boolean> batchUpdateAllNotifyMessageReadStatus() {
notifyMessageService.batchUpdateAllNotifyMessageReadStatus(getLoginUserId(), UserTypeEnum.ADMIN.getValue());
return success(Boolean.TRUE);
}
}

View File

@ -34,8 +34,8 @@ public class NotifyMessageBaseVO {
@NotNull(message = "内容不能为空")
private String content;
@ApiModelProperty(value = "是否已读 0-未读 1-已读")
private Integer readStatus;
@ApiModelProperty(value = "是否已读 false-未读 true-已读")
private Boolean readStatus;
@ApiModelProperty(value = "阅读时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)

View File

@ -29,7 +29,7 @@ public class NotifyTemplateBaseVO {
@ApiModelProperty(value = "状态1-启用 0-禁用", required = true)
@NotNull(message = "状态1-启用 0-禁用不能为空")
@InEnum(value = CommonStatusEnum.class, message = "状态必须是 {value}")
private String status;
private Integer status;
@ApiModelProperty(value = "备注")
private String remarks;

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.system.controller.admin.notify.vo.template;
import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
import lombok.*;
import java.util.*;
import io.swagger.annotations.*;
@ -30,8 +31,8 @@ public class NotifyTemplateExcelVO {
private String content;
@ExcelProperty(value = "状态1-启用 0-禁用", converter = DictConvert.class)
@DictFormat("common_status") // TODO 代码优化建议设置到对应的 XXXDictTypeConstants 枚举类中
private String status;
@DictFormat(DictTypeConstants.COMMON_STATUS)
private Integer status;
@ExcelProperty("备注")
private String remarks;

View File

@ -19,7 +19,7 @@ public class NotifyTemplateExportReqVO {
private String title;
@ApiModelProperty(value = "状态1-启用 0-禁用")
private String status;
private Integer status;
@ApiModelProperty(value = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)

View File

@ -0,0 +1,24 @@
package cn.iocoder.yudao.module.system.controller.admin.notify.vo.template;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.util.Map;
@ApiModel("管理后台 - 站内信模板的发送 Request VO")
@Data
public class NotifyTemplateSendReqVO {
@ApiModelProperty(value = "用户id", required = true, example = "01")
@NotNull(message = "用户id不能为空")
private Long userId;
@ApiModelProperty(value = "模板Id", required = true, example = "01")
@NotNull(message = "模板Id不能为空")
private Long templateId;
@ApiModelProperty(value = "模板参数")
private Map<String, Object> templateParams;
}

View File

@ -4,9 +4,7 @@ import java.util.*;
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.NotifyMessageRespVO;
import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageUpdateReqVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
@ -21,10 +19,6 @@ public interface NotifyMessageConvert {
NotifyMessageConvert INSTANCE = Mappers.getMapper(NotifyMessageConvert.class);
NotifyMessageDO convert(NotifyMessageCreateReqVO bean);
NotifyMessageDO convert(NotifyMessageUpdateReqVO bean);
NotifyMessageRespVO convert(NotifyMessageDO bean);
List<NotifyMessageRespVO> convertList(List<NotifyMessageDO> list);

View File

@ -53,7 +53,7 @@ public class NotifyTemplateDO extends BaseDO {
*
* 枚举 {@link CommonStatusEnum}
*/
private String status;
private Integer status;
/**
* 备注
*/

View File

@ -5,7 +5,6 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
import cn.iocoder.yudao.module.system.enums.notify.NotifyReadStatusEnum;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@ -28,16 +27,27 @@ public interface NotifyMessageMapper extends BaseMapperX<NotifyMessageDO> {
.orderByDesc(NotifyMessageDO::getId));
}
default List<NotifyMessageDO> selectList(NotifyMessagePageReqVO reqVO, Integer size) {
return selectList(new LambdaQueryWrapperX<NotifyMessageDO>()
.likeIfPresent(NotifyMessageDO::getTitle, reqVO.getTitle())
.eqIfPresent(NotifyMessageDO::getReadStatus, reqVO.getReadStatus())
.betweenIfPresent(NotifyMessageDO::getCreateTime, reqVO.getCreateTime())
.eqIfPresent(NotifyMessageDO::getUserId, reqVO.getUserId())
.eqIfPresent(NotifyMessageDO::getUserType, reqVO.getUserType())
.orderByDesc(NotifyMessageDO::getId)
.last("limit " + size));
}
default Long selectUnreadCountByUserIdAndUserType(Long userId, Integer userType) {
return selectCount(new LambdaQueryWrapperX<NotifyMessageDO>()
.eq(NotifyMessageDO::getReadStatus, NotifyReadStatusEnum.UNREAD.getStatus())
.eq(NotifyMessageDO::getReadStatus, false)
.eq(NotifyMessageDO::getUserId, userId)
.eq(NotifyMessageDO::getUserType, userType));
}
default List<NotifyMessageDO> selectUnreadListByUserIdAndUserType(Long userId, Integer userType) {
return selectList(new LambdaQueryWrapperX<NotifyMessageDO>()
.eq(NotifyMessageDO::getReadStatus, NotifyReadStatusEnum.UNREAD.getStatus())
.eq(NotifyMessageDO::getReadStatus, false)
.eq(NotifyMessageDO::getUserId, userId)
.eq(NotifyMessageDO::getUserType, userType));
}

View File

@ -30,6 +30,14 @@ public interface NotifyMessageService {
*/
List<NotifyMessageDO> getNotifyMessageList(Collection<Long> ids);
/**
* 获得站内信集合
*
* @param pageReqVO 分页查询
* @return 站内信分页
*/
List<NotifyMessageDO> getNotifyMessageList(NotifyMessagePageReqVO pageReqVO, Integer size);
/**
* 获得站内信分页
*
@ -53,7 +61,7 @@ public interface NotifyMessageService {
* @param id 站内信编号
* @param status 状态
*/
void updateNotifyMessageReadStatus(Long id, Integer status);
void updateNotifyMessageReadStatus(Long id, Boolean status);
/**
* 批量修改站内信阅读状态

View File

@ -5,14 +5,11 @@ import cn.hutool.core.util.NumberUtil;
import cn.iocoder.yudao.framework.common.core.KeyValue;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageCreateReqVO;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
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.convert.notify.NotifyMessageConvert;
import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO;
import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyMessageMapper;
import cn.iocoder.yudao.module.system.enums.notify.NotifyReadStatusEnum;
import com.google.common.annotations.VisibleForTesting;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@ -87,6 +84,11 @@ public class NotifyMessageServiceImpl implements NotifyMessageService {
return notifyMessageMapper.selectBatchIds(ids);
}
@Override
public List<NotifyMessageDO> getNotifyMessageList(NotifyMessagePageReqVO pageReqVO, Integer size) {
return notifyMessageMapper.selectList(pageReqVO, size);
}
@Override
public PageResult<NotifyMessageDO> getNotifyMessagePage(NotifyMessagePageReqVO pageReqVO) {
return notifyMessageMapper.selectPage(pageReqVO);
@ -111,7 +113,7 @@ public class NotifyMessageServiceImpl implements NotifyMessageService {
* @param status 状态
*/
@Override
public void updateNotifyMessageReadStatus(Long id, Integer status) {
public void updateNotifyMessageReadStatus(Long id, Boolean status) {
// 校验消息是否存在
this.validateNotifyMessageExists(id);
// 更新状态
@ -155,20 +157,12 @@ public class NotifyMessageServiceImpl implements NotifyMessageService {
List<NotifyMessageDO> list = notifyMessageMapper.selectUnreadListByUserIdAndUserType(userId, userType);
if (CollUtil.isNotEmpty(list)) {
batchUpdateReadStatus(CollectionUtils.convertList(list, NotifyMessageDO::getId));
}
}
// TODO 芋艿批量更新不要单条遍历哈
private void batchUpdateReadStatus(Collection<Long> ids) {
if (CollUtil.isNotEmpty(ids)) {
for (Long id : ids) {
NotifyMessageDO updateObj = new NotifyMessageDO();
updateObj.setId(id);
updateObj.setReadStatus(NotifyReadStatusEnum.READ.getStatus());
notifyMessageMapper.updateById(updateObj);
}
}
NotifyMessageDO updateObj = new NotifyMessageDO();
updateObj.setReadStatus(false);
notifyMessageMapper.update(updateObj, new LambdaQueryWrapperX<NotifyMessageDO>().in(NotifyMessageDO::getId, ids));
}
}

View File

@ -0,0 +1,51 @@
package cn.iocoder.yudao.module.system.service.notify;
import java.util.List;
import java.util.Map;
public interface NotifySendService {
/**
* 发送单条站内信给管理后台的用户
*
* mobile 为空时使用 userId 加载对应管理员的手机号
*
* @param userId 用户编号
* @param templateId 短信模板编号
* @param templateParams 短信模板参数
* @return 发送日志编号
*/
Long sendSingleNotifyToAdmin(Long userId,
Long templateId, Map<String, Object> templateParams);
/**
* 发送单条站内信给用户 APP 的用户
*
* mobile 为空时使用 userId 加载对应会员的手机号
*
* @param userId 用户编号
* @param templateId 站内信模板编号
* @param templateParams 站内信模板参数
* @return 发送日志编号
*/
Long sendSingleNotifyToMember(Long userId,
Long templateId, Map<String, Object> templateParams);
/**
* 发送单条站内信给用户
*
* @param userId 用户编号
* @param userType 用户类型
* @param templateId 站内信模板编号
* @param templateParams 站内信模板参数
* @return 发送日志编号
*/
Long sendSingleNotify( Long userId, Integer userType,
Long templateId, Map<String, Object> templateParams);
default void sendBatchNotify(List<String> mobiles, List<Long> userIds, Integer userType,
String templateCode, Map<String, Object> templateParams) {
throw new UnsupportedOperationException("暂时不支持该操作,感兴趣可以实现该功能哟!");
}
}

View File

@ -0,0 +1,77 @@
package cn.iocoder.yudao.module.system.service.notify;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO;
import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyMessageMapper;
import com.google.common.annotations.VisibleForTesting;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Date;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTICE_NOT_FOUND;
/**
* 站内信发送 Service 实现类
*
* @author xrcoder
*/
@Service
@Validated
@Slf4j
public class NotifySendServiceImpl implements NotifySendService {
@Resource
private NotifyTemplateService notifyTemplateService;
@Resource
private NotifyMessageMapper notifyMessageMapper;
@Override
public Long sendSingleNotifyToAdmin(Long userId, Long templateId, Map<String, Object> templateParams) {
return sendSingleNotify(userId, UserTypeEnum.ADMIN.getValue(), templateId, templateParams);
}
@Override
public Long sendSingleNotifyToMember(Long userId, Long templateId, Map<String, Object> templateParams) {
return sendSingleNotify(userId, UserTypeEnum.MEMBER.getValue(), templateId, templateParams);
}
@Override
public Long sendSingleNotify(Long userId, Integer userType, Long templateId, Map<String, Object> templateParams) {
// 校验短信模板是否合法
NotifyTemplateDO template = this.checkNotifyTemplateValid(templateId);
String content = notifyTemplateService.formatNotifyTemplateContent(template.getContent(), templateParams);
// todo 模板状态未开启时的业务
NotifyMessageDO notifyMessageDO = new NotifyMessageDO();
notifyMessageDO.setContent(content);
notifyMessageDO.setTitle(template.getTitle());
notifyMessageDO.setReadStatus(false);
notifyMessageDO.setReadTime(new Date());
notifyMessageDO.setTemplateId(templateId);
notifyMessageDO.setUserId(userId);
notifyMessageDO.setUserType(userType);
notifyMessageMapper.insert(notifyMessageDO);
return notifyMessageDO.getId();
}
// 此注解的含义
@VisibleForTesting
public NotifyTemplateDO checkNotifyTemplateValid(Long templateId) {
// 获得短信模板考虑到效率从缓存中获取
NotifyTemplateDO template = notifyTemplateService.getNotifyTemplate(templateId);
// 短信模板不存在
if (template == null) {
throw exception(NOTICE_NOT_FOUND);
}
return template;
}
}