mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-24 16:05:08 +08:00
站内信开发
This commit is contained in:
@ -0,0 +1,54 @@
|
||||
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.log.NotifyLogBaseVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notify.vo.log.NotifyLogPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.convert.notify.NotifyLogConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
|
||||
import cn.iocoder.yudao.module.system.service.notify.NotifyLogService;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import io.swagger.annotations.Api;
|
||||
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.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author LuoWenFeng
|
||||
*/
|
||||
@Api(tags = "管理后台 - 站内信发送日志")
|
||||
@RestController
|
||||
@RequestMapping("/system/notify-log")
|
||||
@Validated
|
||||
public class NotifyLogController {
|
||||
|
||||
@Resource
|
||||
private NotifyLogService notifyLogService;
|
||||
|
||||
@Resource
|
||||
private AdminUserService userService;
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("获得发送站内信日志分页")
|
||||
public CommonResult<PageResult<NotifyLogBaseVO>> getNotifyLogPage(@Valid NotifyLogPageReqVO pageVO) {
|
||||
PageResult<NotifyMessageDO> pageResult = notifyLogService.getNotifyMessageSendPage(pageVO);
|
||||
PageResult<NotifyLogBaseVO> result = NotifyLogConvert.INSTANCE.convertPage(pageResult);
|
||||
result.getList().forEach(v -> {
|
||||
v.setReceiveUserName(userService.getUser(v.getUserId()).getNickname());
|
||||
});
|
||||
return success(result);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -18,15 +18,13 @@ 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 = "管理后台 - 站内信")
|
||||
@Api(tags = "管理后台 - 我的站内信")
|
||||
@RestController
|
||||
@RequestMapping("/system/notify-message")
|
||||
@Validated
|
||||
@ -48,8 +46,6 @@ 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));
|
||||
}
|
||||
@ -59,9 +55,6 @@ public class NotifyMessageController {
|
||||
@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));
|
||||
@ -75,19 +68,20 @@ public class NotifyMessageController {
|
||||
return success(notifyMessageService.getUnreadNotifyMessageCount(getLoginUserId(), UserTypeEnum.ADMIN.getValue()));
|
||||
}
|
||||
|
||||
@GetMapping("/update-list-read")
|
||||
@PutMapping("/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) {
|
||||
public CommonResult<Boolean> batchUpdateNotifyMessageReadStatus(@RequestBody List<Long> ids) {
|
||||
notifyMessageService.batchUpdateNotifyMessageReadStatus(ids, getLoginUserId());
|
||||
return success(Boolean.TRUE);
|
||||
}
|
||||
|
||||
@GetMapping("/update-all-read")
|
||||
@PutMapping("/update-all-read")
|
||||
@ApiOperation("所有未读消息标记已读")
|
||||
public CommonResult<Boolean> batchUpdateAllNotifyMessageReadStatus() {
|
||||
notifyMessageService.batchUpdateAllNotifyMessageReadStatus(getLoginUserId(), UserTypeEnum.ADMIN.getValue());
|
||||
return success(Boolean.TRUE);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -95,6 +95,6 @@ public class NotifyTemplateController {
|
||||
@ApiOperation("发送站内信")
|
||||
public CommonResult<Long> sendNotify(@Valid @RequestBody NotifyTemplateSendReqVO sendReqVO) {
|
||||
return success(notifySendService.sendSingleNotifyToAdmin(sendReqVO.getUserId(),
|
||||
sendReqVO.getTemplateId(), sendReqVO.getTemplateParams()));
|
||||
sendReqVO.getTemplateCode(), sendReqVO.getTemplateParams()));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.notify.vo.log;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 站内信 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
*/
|
||||
@Data
|
||||
public class NotifyLogBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "模版编码")
|
||||
private String templateCode;
|
||||
|
||||
@ApiModelProperty(value = "标题")
|
||||
private String title;
|
||||
|
||||
@ApiModelProperty(value = "内容", required = true)
|
||||
private String content;
|
||||
|
||||
@ApiModelProperty(value = "发送时间", required = true)
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date sendTime;
|
||||
|
||||
@ApiModelProperty(value = "芋艿", required = true)
|
||||
private String receiveUserName;
|
||||
|
||||
@ApiModelProperty(value = "1", required = true)
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty(value = "是否已读 false-未读 true-已读")
|
||||
private Boolean readStatus;
|
||||
|
||||
@ApiModelProperty(value = "阅读时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date readTime;
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.notify.vo.log;
|
||||
|
||||
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")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class NotifyLogPageReqVO extends PageParam {
|
||||
|
||||
@ApiModelProperty(value = "模版编码")
|
||||
private String templateCode;
|
||||
|
||||
@ApiModelProperty(value = "标题")
|
||||
private String title;
|
||||
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date[] sendTime;
|
||||
}
|
@ -1,39 +1,33 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.notify.vo.message;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Date;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
/**
|
||||
* 站内信 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
*/
|
||||
* 站内信 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
*/
|
||||
@Data
|
||||
public class NotifyMessageBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "用户编号", required = true)
|
||||
@NotNull(message = "用户编号不能为空")
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty(value = "用户类型", required = true)
|
||||
@NotNull(message = "用户类型不能为空")
|
||||
@InEnum(value = UserTypeEnum.class, message = "用户类型必须是 {value}")
|
||||
private Integer userType;
|
||||
|
||||
@ApiModelProperty(value = "标题")
|
||||
private String title;
|
||||
|
||||
@ApiModelProperty(value = "内容", required = true)
|
||||
@NotNull(message = "内容不能为空")
|
||||
@ApiModelProperty(value = "内容")
|
||||
private String content;
|
||||
|
||||
@ApiModelProperty(value = "发送时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date sendTime;
|
||||
|
||||
@ApiModelProperty(value = "芋艿")
|
||||
private String sendUserName;
|
||||
|
||||
@ApiModelProperty(value = "是否已读 false-未读 true-已读")
|
||||
private Boolean readStatus;
|
||||
|
||||
|
@ -28,11 +28,4 @@ public class NotifyMessagePageReqVO extends PageParam {
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date[] createTime;
|
||||
|
||||
// TODO 芋艿:去掉 userId 和 userType,不要在 VO 里
|
||||
|
||||
@ApiModelProperty(value = "用户编号", hidden = true)
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty(value = "用户类型", hidden = true)
|
||||
private Integer userType;
|
||||
}
|
||||
|
@ -13,7 +13,4 @@ public class NotifyMessageRespVO extends NotifyMessageBaseVO {
|
||||
@ApiModelProperty(value = "ID", required = true)
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "创建时间", required = true)
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
|
@ -15,9 +15,9 @@ public class NotifyTemplateSendReqVO {
|
||||
@NotNull(message = "用户id不能为空")
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty(value = "模板Id", required = true, example = "01")
|
||||
@NotNull(message = "模板Id不能为空")
|
||||
private Long templateId;
|
||||
@ApiModelProperty(value = "模板编码", required = true, example = "01")
|
||||
@NotNull(message = "模板编码不能为空")
|
||||
private String templateCode;
|
||||
|
||||
@ApiModelProperty(value = "模板参数")
|
||||
private Map<String, Object> templateParams;
|
||||
|
@ -0,0 +1,23 @@
|
||||
package cn.iocoder.yudao.module.system.convert.notify;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notify.vo.log.NotifyLogBaseVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author LuoWenFeng
|
||||
*/
|
||||
@Mapper
|
||||
public interface NotifyLogConvert {
|
||||
|
||||
NotifyLogConvert INSTANCE = Mappers.getMapper(NotifyLogConvert.class);
|
||||
|
||||
PageResult<NotifyLogBaseVO> convertPage(PageResult<NotifyMessageDO> page);
|
||||
|
||||
}
|
@ -1,13 +1,12 @@
|
||||
package cn.iocoder.yudao.module.system.convert.notify;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageRespVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 站内信 Convert
|
||||
@ -25,4 +24,5 @@ public interface NotifyMessageConvert {
|
||||
|
||||
PageResult<NotifyMessageRespVO> convertPage(PageResult<NotifyMessageDO> page);
|
||||
|
||||
|
||||
}
|
||||
|
@ -35,6 +35,12 @@ public class NotifyMessageDO extends BaseDO {
|
||||
* 关联 {@link NotifyTemplateDO#getId()}
|
||||
*/
|
||||
private Long templateId;
|
||||
/**
|
||||
* 站内信模版编码
|
||||
*
|
||||
* 关联 {@link NotifyTemplateDO#getCode()}
|
||||
*/
|
||||
private String templateCode;
|
||||
/**
|
||||
* 用户编号
|
||||
*
|
||||
@ -55,6 +61,18 @@ public class NotifyMessageDO extends BaseDO {
|
||||
* 内容
|
||||
*/
|
||||
private String content;
|
||||
/**
|
||||
* 发送时间
|
||||
*/
|
||||
private Date sendTime;
|
||||
/**
|
||||
* 发送用户id
|
||||
*/
|
||||
private Long sendUserId;
|
||||
/**
|
||||
* 发送用户名
|
||||
*/
|
||||
private String sendUserName;
|
||||
/**
|
||||
* 是否已读
|
||||
*/
|
||||
|
@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.dal.mysql.notify;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
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.log.NotifyLogPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@ -17,23 +18,31 @@ import java.util.List;
|
||||
@Mapper
|
||||
public interface NotifyMessageMapper extends BaseMapperX<NotifyMessageDO> {
|
||||
|
||||
default PageResult<NotifyMessageDO> selectPage(NotifyMessagePageReqVO reqVO) {
|
||||
default PageResult<NotifyMessageDO> selectPage(NotifyMessagePageReqVO reqVO, Long userId, Integer userType) {
|
||||
return selectPage(reqVO, 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())
|
||||
.eq(NotifyMessageDO::getUserId, userId)
|
||||
.eq(NotifyMessageDO::getUserType, userType)
|
||||
.orderByDesc(NotifyMessageDO::getId));
|
||||
}
|
||||
|
||||
default List<NotifyMessageDO> selectList(NotifyMessagePageReqVO reqVO, Integer size) {
|
||||
default PageResult<NotifyMessageDO> selectSendPage(NotifyLogPageReqVO reqVO, Long userId) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<NotifyMessageDO>()
|
||||
.likeIfPresent(NotifyMessageDO::getTitle, reqVO.getTitle())
|
||||
.betweenIfPresent(NotifyMessageDO::getSendTime, reqVO.getSendTime())
|
||||
.eq(NotifyMessageDO::getSendUserId, userId)
|
||||
.orderByDesc(NotifyMessageDO::getId));
|
||||
}
|
||||
|
||||
default List<NotifyMessageDO> selectList(NotifyMessagePageReqVO reqVO, Integer size, Long userId, Integer userType) {
|
||||
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())
|
||||
.eqIfPresent(NotifyMessageDO::getUserId, userId)
|
||||
.eqIfPresent(NotifyMessageDO::getUserType, userType)
|
||||
.orderByDesc(NotifyMessageDO::getId)
|
||||
.last("limit " + size));
|
||||
}
|
||||
@ -51,4 +60,5 @@ public interface NotifyMessageMapper extends BaseMapperX<NotifyMessageDO> {
|
||||
.eq(NotifyMessageDO::getUserId, userId)
|
||||
.eq(NotifyMessageDO::getUserType, userType));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
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.log.NotifyLogPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 站内信日志 Service 接口
|
||||
* </p>
|
||||
*
|
||||
* @author LuoWenFeng
|
||||
*/
|
||||
public interface NotifyLogService {
|
||||
|
||||
|
||||
/**
|
||||
* 获得站内信发送分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 站内信分页
|
||||
*/
|
||||
PageResult<NotifyMessageDO> getNotifyMessageSendPage(NotifyLogPageReqVO pageReqVO);
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
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.log.NotifyLogPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyMessageMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 站内信日志 Service 实现类
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author LuoWenFeng
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class NotifyLogServiceImpl implements NotifyLogService {
|
||||
|
||||
@Resource
|
||||
private NotifyMessageMapper notifyMessageMapper;
|
||||
|
||||
@Override
|
||||
public PageResult<NotifyMessageDO> getNotifyMessageSendPage(NotifyLogPageReqVO pageReqVO) {
|
||||
return notifyMessageMapper.selectSendPage(pageReqVO, getLoginUserId());
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -49,7 +49,7 @@ public interface NotifyMessageService {
|
||||
/**
|
||||
* 统计用户未读站内信条数
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param userId 用户ID
|
||||
* @param userType 用户类型
|
||||
* @return 返回未读站内信条数
|
||||
*/
|
||||
@ -58,7 +58,7 @@ public interface NotifyMessageService {
|
||||
/**
|
||||
* 修改站内信阅读状态
|
||||
*
|
||||
* @param id 站内信编号
|
||||
* @param id 站内信编号
|
||||
* @param status 状态
|
||||
*/
|
||||
void updateNotifyMessageReadStatus(Long id, Boolean status);
|
||||
@ -66,7 +66,7 @@ public interface NotifyMessageService {
|
||||
/**
|
||||
* 批量修改站内信阅读状态
|
||||
*
|
||||
* @param ids 站内信编号集合
|
||||
* @param ids 站内信编号集合
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
void batchUpdateNotifyMessageReadStatus(Collection<Long> ids, Long userId);
|
||||
@ -74,8 +74,9 @@ public interface NotifyMessageService {
|
||||
/**
|
||||
* 批量修改用户所有未读消息标记已读
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param userId 用户ID
|
||||
* @param userType 用户类型
|
||||
*/
|
||||
void batchUpdateAllNotifyMessageReadStatus(Long userId, Integer userType);
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.service.notify;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.iocoder.yudao.framework.common.core.KeyValue;
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
@ -16,11 +17,13 @@ import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
@ -86,12 +89,12 @@ public class NotifyMessageServiceImpl implements NotifyMessageService {
|
||||
|
||||
@Override
|
||||
public List<NotifyMessageDO> getNotifyMessageList(NotifyMessagePageReqVO pageReqVO, Integer size) {
|
||||
return notifyMessageMapper.selectList(pageReqVO, size);
|
||||
return notifyMessageMapper.selectList(pageReqVO, size, getLoginUserId(), UserTypeEnum.ADMIN.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<NotifyMessageDO> getNotifyMessagePage(NotifyMessagePageReqVO pageReqVO) {
|
||||
return notifyMessageMapper.selectPage(pageReqVO);
|
||||
return notifyMessageMapper.selectPage(pageReqVO, getLoginUserId(), UserTypeEnum.ADMIN.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -160,9 +163,15 @@ public class NotifyMessageServiceImpl implements NotifyMessageService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量修改阅读状态为已读
|
||||
* @param ids
|
||||
*/
|
||||
private void batchUpdateReadStatus(Collection<Long> ids) {
|
||||
NotifyMessageDO updateObj = new NotifyMessageDO();
|
||||
updateObj.setReadStatus(false);
|
||||
updateObj.setReadStatus(true);
|
||||
updateObj.setReadTime(new Date());
|
||||
notifyMessageMapper.update(updateObj, new LambdaQueryWrapperX<NotifyMessageDO>().in(NotifyMessageDO::getId, ids));
|
||||
}
|
||||
}
|
||||
|
@ -12,36 +12,36 @@ public interface NotifySendService {
|
||||
* 在 mobile 为空时,使用 userId 加载对应管理员的手机号
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @param templateId 短信模板编号
|
||||
* @param templateCode 短信模板编号
|
||||
* @param templateParams 短信模板参数
|
||||
* @return 发送日志编号
|
||||
*/
|
||||
Long sendSingleNotifyToAdmin(Long userId,
|
||||
Long templateId, Map<String, Object> templateParams);
|
||||
String templateCode, Map<String, Object> templateParams);
|
||||
/**
|
||||
* 发送单条站内信给用户 APP 的用户
|
||||
*
|
||||
* 在 mobile 为空时,使用 userId 加载对应会员的手机号
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @param templateId 站内信模板编号
|
||||
* @param templateCode 站内信模板编号
|
||||
* @param templateParams 站内信模板参数
|
||||
* @return 发送日志编号
|
||||
*/
|
||||
Long sendSingleNotifyToMember(Long userId,
|
||||
Long templateId, Map<String, Object> templateParams);
|
||||
String templateCode, Map<String, Object> templateParams);
|
||||
|
||||
/**
|
||||
* 发送单条站内信给用户
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @param userType 用户类型
|
||||
* @param templateId 站内信模板编号
|
||||
* @param templateCode 站内信模板编号
|
||||
* @param templateParams 站内信模板参数
|
||||
* @return 发送日志编号
|
||||
*/
|
||||
Long sendSingleNotify( Long userId, Integer userType,
|
||||
Long templateId, Map<String, Object> templateParams);
|
||||
String templateCode, Map<String, Object> templateParams);
|
||||
|
||||
default void sendBatchNotify(List<String> mobiles, List<Long> userIds, Integer userType,
|
||||
String templateCode, Map<String, Object> templateParams) {
|
||||
|
@ -3,7 +3,9 @@ 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.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyMessageMapper;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -14,6 +16,7 @@ import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTICE_NOT_FOUND;
|
||||
|
||||
/**
|
||||
@ -32,41 +35,48 @@ public class NotifySendServiceImpl implements NotifySendService {
|
||||
@Resource
|
||||
private NotifyMessageMapper notifyMessageMapper;
|
||||
|
||||
@Override
|
||||
public Long sendSingleNotifyToAdmin(Long userId, Long templateId, Map<String, Object> templateParams) {
|
||||
@Resource
|
||||
private AdminUserService userService;
|
||||
|
||||
return sendSingleNotify(userId, UserTypeEnum.ADMIN.getValue(), templateId, templateParams);
|
||||
@Override
|
||||
public Long sendSingleNotifyToAdmin(Long userId, String templateCode, Map<String, Object> templateParams) {
|
||||
|
||||
return sendSingleNotify(userId, UserTypeEnum.ADMIN.getValue(), templateCode, templateParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long sendSingleNotifyToMember(Long userId, Long templateId, Map<String, Object> templateParams) {
|
||||
return sendSingleNotify(userId, UserTypeEnum.MEMBER.getValue(), templateId, templateParams);
|
||||
public Long sendSingleNotifyToMember(Long userId, String templateCode, Map<String, Object> templateParams) {
|
||||
return sendSingleNotify(userId, UserTypeEnum.MEMBER.getValue(), templateCode, templateParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long sendSingleNotify(Long userId, Integer userType, Long templateId, Map<String, Object> templateParams) {
|
||||
public Long sendSingleNotify(Long userId, Integer userType, String templateCode, Map<String, Object> templateParams) {
|
||||
// 校验短信模板是否合法
|
||||
NotifyTemplateDO template = this.checkNotifyTemplateValid(templateId);
|
||||
NotifyTemplateDO template = this.checkNotifyTemplateValid(templateCode);
|
||||
String content = notifyTemplateService.formatNotifyTemplateContent(template.getContent(), templateParams);
|
||||
AdminUserDO sendUser = userService.getUser(getLoginUserId());
|
||||
|
||||
// todo 模板状态未开启时的业务
|
||||
NotifyMessageDO notifyMessageDO = new NotifyMessageDO();
|
||||
notifyMessageDO.setContent(content);
|
||||
notifyMessageDO.setTitle(template.getTitle());
|
||||
notifyMessageDO.setReadStatus(false);
|
||||
notifyMessageDO.setReadTime(new Date());
|
||||
notifyMessageDO.setTemplateId(templateId);
|
||||
notifyMessageDO.setTemplateId(template.getId());
|
||||
notifyMessageDO.setTemplateCode(templateCode);
|
||||
notifyMessageDO.setUserId(userId);
|
||||
notifyMessageDO.setUserType(userType);
|
||||
notifyMessageDO.setSendTime(new Date());
|
||||
notifyMessageDO.setSendUserId(sendUser.getId());
|
||||
notifyMessageDO.setSendUserName(sendUser.getUsername());
|
||||
notifyMessageMapper.insert(notifyMessageDO);
|
||||
return notifyMessageDO.getId();
|
||||
}
|
||||
|
||||
// 此注解的含义
|
||||
@VisibleForTesting
|
||||
public NotifyTemplateDO checkNotifyTemplateValid(Long templateId) {
|
||||
public NotifyTemplateDO checkNotifyTemplateValid(String templateCode) {
|
||||
// 获得短信模板。考虑到效率,从缓存中获取
|
||||
NotifyTemplateDO template = notifyTemplateService.getNotifyTemplate(templateId);
|
||||
NotifyTemplateDO template = notifyTemplateService.getNotifyTemplateByCodeFromCache(templateCode);
|
||||
// 短信模板不存在
|
||||
if (template == null) {
|
||||
throw exception(NOTICE_NOT_FOUND);
|
||||
|
@ -109,7 +109,7 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService {
|
||||
return notifyTemplateMapper.selectList();
|
||||
}
|
||||
|
||||
@Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD)
|
||||
@Scheduled(fixedDelay = SCHEDULER_PERIOD)
|
||||
public void schedulePeriodicRefresh() {
|
||||
initLocalCache();
|
||||
}
|
||||
|
Reference in New Issue
Block a user