mirror of https://gitee.com/stylefeng/roses
【message】系统消息后台接口
parent
cc65953d31
commit
c48f973e6b
|
@ -43,7 +43,7 @@ public class GunsLogAutoConfiguration {
|
||||||
* @date 2020/12/28 22:09
|
* @date 2020/12/28 22:09
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(SysLogServiceImpl.class)
|
@ConditionalOnMissingBean(SysLogService.class)
|
||||||
@ConditionalOnProperty(prefix = SYS_LOG_PREFIX, name = "type", havingValue = "db")
|
@ConditionalOnProperty(prefix = SYS_LOG_PREFIX, name = "type", havingValue = "db")
|
||||||
public SysLogService sysLogService() {
|
public SysLogService sysLogService() {
|
||||||
return new SysLogServiceImpl();
|
return new SysLogServiceImpl();
|
||||||
|
|
|
@ -37,6 +37,14 @@ public interface MessageApi {
|
||||||
*/
|
*/
|
||||||
void updateReadFlag(MessageParam messageParam);
|
void updateReadFlag(MessageParam messageParam);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 全部更新阅读状态
|
||||||
|
*
|
||||||
|
* @author liuhanqing
|
||||||
|
* @date 2021/1/2 22:15
|
||||||
|
*/
|
||||||
|
void allMessageReadFlag();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量更新阅读状态
|
* 批量更新阅读状态
|
||||||
*
|
*
|
||||||
|
@ -74,14 +82,14 @@ public interface MessageApi {
|
||||||
MessageResponse messageDetail(MessageParam messageParam);
|
MessageResponse messageDetail(MessageParam messageParam);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询系统消息
|
* 查询分页系统消息
|
||||||
*
|
*
|
||||||
* @param messageParam 查询参数
|
* @param messageParam 查询参数
|
||||||
* @return 查询分页结果
|
* @return 查询分页结果
|
||||||
* @author liuhanqing
|
* @author liuhanqing
|
||||||
* @date 2021/1/2 21:21
|
* @date 2021/1/2 21:21
|
||||||
*/
|
*/
|
||||||
PageResult<MessageResponse> queryMessagePage(MessageParam messageParam);
|
PageResult<MessageResponse> queryPage(MessageParam messageParam);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询系统消息
|
* 查询系统消息
|
||||||
|
@ -91,6 +99,26 @@ public interface MessageApi {
|
||||||
* @author liuhanqing
|
* @author liuhanqing
|
||||||
* @date 2021/1/2 21:21
|
* @date 2021/1/2 21:21
|
||||||
*/
|
*/
|
||||||
List<MessageResponse> queryMessageList(MessageParam messageParam);
|
List<MessageResponse> queryList(MessageParam messageParam);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询分页系统消息 当前登录用户
|
||||||
|
*
|
||||||
|
* @param messageParam 查询参数
|
||||||
|
* @return 查询分页结果
|
||||||
|
* @author liuhanqing
|
||||||
|
* @date 2021/1/2 21:21
|
||||||
|
*/
|
||||||
|
PageResult<MessageResponse> queryPageCurrentUser(MessageParam messageParam);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询系统消息 当前登录用户
|
||||||
|
*
|
||||||
|
* @param messageParam 查询参数
|
||||||
|
* @return 系统消息列表
|
||||||
|
* @author liuhanqing
|
||||||
|
* @date 2021/1/2 21:21
|
||||||
|
*/
|
||||||
|
List<MessageResponse> queryListCurrentUser(MessageParam messageParam);
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
package cn.stylefeng.roses.kernel.message.api.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息优先级
|
||||||
|
*
|
||||||
|
* @author liuhanqing
|
||||||
|
* @date 2021/1/8 13:26
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum MessageProrityLevelEnum {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 高
|
||||||
|
*/
|
||||||
|
HIGH("high", "高"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 中
|
||||||
|
*/
|
||||||
|
MIDDLE("middle", "中"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 低
|
||||||
|
*/
|
||||||
|
LOW("low", "低");
|
||||||
|
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
MessageProrityLevelEnum(String code, String name) {
|
||||||
|
this.code = code;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getName(String code) {
|
||||||
|
if (code == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (MessageProrityLevelEnum flagEnum : MessageProrityLevelEnum.values()) {
|
||||||
|
if (flagEnum.getCode().equals(code)) {
|
||||||
|
return flagEnum.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -21,13 +21,25 @@ public enum MessageReadFlagEnum {
|
||||||
*/
|
*/
|
||||||
READ(1, "已读");
|
READ(1, "已读");
|
||||||
|
|
||||||
private final Integer code;
|
private Integer code;
|
||||||
|
|
||||||
private final String name;
|
private String name;
|
||||||
|
|
||||||
MessageReadFlagEnum(Integer code, String name) {
|
MessageReadFlagEnum(Integer code, String name) {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getName(Integer code) {
|
||||||
|
if (code == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (MessageReadFlagEnum flagEnum : MessageReadFlagEnum.values()) {
|
||||||
|
if (flagEnum.getCode().equals(code)) {
|
||||||
|
return flagEnum.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class MessageParam extends BaseRequest {
|
||||||
/**
|
/**
|
||||||
* 消息id
|
* 消息id
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "messageId不能为空", groups = {edit.class, delete.class, detail.class})
|
@NotNull(message = "messageId不能为空", groups = {edit.class, delete.class, detail.class, updateStatus.class})
|
||||||
private Long messageId;
|
private Long messageId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -71,6 +71,7 @@ public class MessageParam extends BaseRequest {
|
||||||
/**
|
/**
|
||||||
* 阅读状态:0-未读,1-已读
|
* 阅读状态:0-未读,1-已读
|
||||||
*/
|
*/
|
||||||
|
@NotNull(message = "阅读状态不能为空", groups = {updateStatus.class})
|
||||||
private Integer readFlag;
|
private Integer readFlag;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,16 @@
|
||||||
package cn.stylefeng.roses.kernel.message.modular.manage.controller;
|
package cn.stylefeng.roses.kernel.message.modular.manage.controller;
|
||||||
|
|
||||||
import cn.stylefeng.roses.kernel.message.api.MessageApi;
|
import cn.stylefeng.roses.kernel.message.api.MessageApi;
|
||||||
|
import cn.stylefeng.roses.kernel.message.api.pojo.MessageParam;
|
||||||
|
import cn.stylefeng.roses.kernel.message.api.pojo.MessageSendParam;
|
||||||
import cn.stylefeng.roses.kernel.resource.api.annotation.ApiResource;
|
import cn.stylefeng.roses.kernel.resource.api.annotation.ApiResource;
|
||||||
|
import cn.stylefeng.roses.kernel.resource.api.annotation.GetResource;
|
||||||
|
import cn.stylefeng.roses.kernel.resource.api.annotation.PostResource;
|
||||||
|
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
||||||
|
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,5 +29,75 @@ public class SysMessageController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private MessageApi messageApi;
|
private MessageApi messageApi;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送系统消息
|
||||||
|
*
|
||||||
|
* @author liuhanqing
|
||||||
|
* @date 2021/1/8 13:50
|
||||||
|
*/
|
||||||
|
@PostResource(name = "发送系统消息", path = "/sysMessage/sendMessage")
|
||||||
|
public ResponseData sendMessage(@RequestBody @Validated(MessageSendParam.add.class) MessageSendParam messageSendParam) {
|
||||||
|
messageApi.sendMessage(messageSendParam);
|
||||||
|
return new SuccessResponseData();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统消息全部修改已读
|
||||||
|
*
|
||||||
|
* @author liuhanqing
|
||||||
|
* @date 2021/1/8 13:50
|
||||||
|
*/
|
||||||
|
@GetResource(name = "系统消息全部修改已读", path = "/sysMessage/allMessageReadFlag")
|
||||||
|
public ResponseData allMessageReadFlag() {
|
||||||
|
messageApi.allMessageReadFlag();
|
||||||
|
return new SuccessResponseData();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除系统消息
|
||||||
|
*
|
||||||
|
* @author liuhanqing
|
||||||
|
* @date 2021/1/8 13:50
|
||||||
|
*/
|
||||||
|
@PostResource(name = "删除系统消息", path = "/sysMessage/delete")
|
||||||
|
public ResponseData delete(@RequestBody @Validated(MessageParam.delete.class) MessageParam messageParam) {
|
||||||
|
messageApi.deleteByMessageId(messageParam.getMessageId());
|
||||||
|
return new SuccessResponseData();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查看系统消息
|
||||||
|
*
|
||||||
|
* @author liuhanqing
|
||||||
|
* @date 2021/1/8 13:50
|
||||||
|
*/
|
||||||
|
@GetResource(name = "查看系统消息", path = "/sysMessage/detail")
|
||||||
|
public ResponseData detail(@Validated(MessageParam.detail.class) MessageParam messageParam) {
|
||||||
|
return new SuccessResponseData(messageApi.messageDetail(messageParam));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询系统消息列表
|
||||||
|
*
|
||||||
|
* @author liuhanqing
|
||||||
|
* @date 2021/1/8 13:50
|
||||||
|
*/
|
||||||
|
@GetResource(name = "分页查询系统消息列表", path = "/sysMessage/page")
|
||||||
|
public ResponseData page(MessageParam messageParam) {
|
||||||
|
return new SuccessResponseData(messageApi.queryPageCurrentUser(messageParam));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统消息列表
|
||||||
|
*
|
||||||
|
* @author liuhanqing
|
||||||
|
* @date 2021/1/8 13:50
|
||||||
|
*/
|
||||||
|
@GetResource(name = "系统消息列表", path = "/sysMessage/list")
|
||||||
|
public ResponseData list(MessageParam messageParam) {
|
||||||
|
return new SuccessResponseData(messageApi.queryListCurrentUser(messageParam));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package cn.stylefeng.roses.kernel.message.db;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
||||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
||||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||||
|
@ -14,11 +15,14 @@ import cn.stylefeng.roses.kernel.message.api.pojo.MessageResponse;
|
||||||
import cn.stylefeng.roses.kernel.message.api.pojo.MessageSendParam;
|
import cn.stylefeng.roses.kernel.message.api.pojo.MessageSendParam;
|
||||||
import cn.stylefeng.roses.kernel.message.db.entity.SysMessage;
|
import cn.stylefeng.roses.kernel.message.db.entity.SysMessage;
|
||||||
import cn.stylefeng.roses.kernel.message.db.service.SysMessageService;
|
import cn.stylefeng.roses.kernel.message.db.service.SysMessageService;
|
||||||
|
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||||
import cn.stylefeng.roses.kernel.system.UserServiceApi;
|
import cn.stylefeng.roses.kernel.system.UserServiceApi;
|
||||||
import cn.stylefeng.roses.kernel.system.exception.SystemModularException;
|
import cn.stylefeng.roses.kernel.system.exception.SystemModularException;
|
||||||
import cn.stylefeng.roses.kernel.system.pojo.user.request.SysUserRequest;
|
import cn.stylefeng.roses.kernel.system.pojo.user.request.SysUserRequest;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -41,12 +45,13 @@ public class MessageDbServiceImpl implements MessageApi {
|
||||||
private SysMessageService sysMessageService;
|
private SysMessageService sysMessageService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void sendMessage(MessageSendParam messageSendParam) {
|
public void sendMessage(MessageSendParam messageSendParam) {
|
||||||
String receiveUserIds = messageSendParam.getReceiveUserIds();
|
String receiveUserIds = messageSendParam.getReceiveUserIds();
|
||||||
// 获取当前登录人
|
// 获取当前登录人
|
||||||
LoginUser loginUser = LoginContext.me().getLoginUser();
|
LoginUser loginUser = LoginContext.me().getLoginUser();
|
||||||
List<SysMessage> sendMsgList = new ArrayList<>();
|
List<SysMessage> sendMsgList = new ArrayList<>();
|
||||||
List<Long> userIds = new ArrayList<>();
|
List<Long> userIds;
|
||||||
// 发送所有人判断
|
// 发送所有人判断
|
||||||
if (MessageConstants.RECEIVE_ALL_USER_FLAG.equals(receiveUserIds)) {
|
if (MessageConstants.RECEIVE_ALL_USER_FLAG.equals(receiveUserIds)) {
|
||||||
// 查询所有用户
|
// 查询所有用户
|
||||||
|
@ -79,37 +84,110 @@ public class MessageDbServiceImpl implements MessageApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void updateReadFlag(MessageParam messageParam) {
|
public void updateReadFlag(MessageParam messageParam) {
|
||||||
|
Long messageId = messageParam.getMessageId();
|
||||||
|
SysMessage sysMessage = sysMessageService.getById(messageId);
|
||||||
|
Optional.ofNullable(sysMessage).ifPresent(msg -> {
|
||||||
|
msg.setReadFlag(messageParam.getReadFlag());
|
||||||
|
sysMessageService.updateById(msg);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
public void allMessageReadFlag() {
|
||||||
|
// 获取当前登录人
|
||||||
|
LoginUser loginUser = LoginContext.me().getLoginUser();
|
||||||
|
Long userId = loginUser.getUserId();
|
||||||
|
LambdaUpdateWrapper<SysMessage> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
updateWrapper.set(SysMessage::getReadFlag, MessageReadFlagEnum.READ.getCode())
|
||||||
|
.eq(SysMessage::getReadFlag, MessageReadFlagEnum.UNREAD.getCode())
|
||||||
|
.eq(SysMessage::getReceiveUserId, userId)
|
||||||
|
.set(SysMessage::getDelFlag, YesOrNotEnum.N.getCode());
|
||||||
|
sysMessageService.update(updateWrapper);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void batchReadFlagByMessageIds(String messageIds, MessageReadFlagEnum flagEnum) {
|
public void batchReadFlagByMessageIds(String messageIds, MessageReadFlagEnum flagEnum) {
|
||||||
|
LambdaUpdateWrapper<SysMessage> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
updateWrapper.inSql(SysMessage::getMessageId, messageIds).set(SysMessage::getReadFlag, flagEnum.getCode());
|
||||||
|
sysMessageService.update(updateWrapper);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void deleteByMessageId(Long messageId) {
|
public void deleteByMessageId(Long messageId) {
|
||||||
|
LambdaUpdateWrapper<SysMessage> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
// 修改为逻辑删除
|
||||||
|
updateWrapper.eq(SysMessage::getMessageId, messageId)
|
||||||
|
.set(SysMessage::getDelFlag, YesOrNotEnum.Y.getCode());
|
||||||
|
sysMessageService.update(updateWrapper);
|
||||||
|
// sysMessageService.remove(updateWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void batchDeleteByMessageIds(String messageIds) {
|
public void batchDeleteByMessageIds(String messageIds) {
|
||||||
|
LambdaUpdateWrapper<SysMessage> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
updateWrapper.inSql(SysMessage::getMessageId, messageIds)
|
||||||
|
.set(SysMessage::getDelFlag, YesOrNotEnum.Y.getCode());
|
||||||
|
sysMessageService.update(updateWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessageResponse messageDetail(MessageParam messageParam) {
|
public MessageResponse messageDetail(MessageParam messageParam) {
|
||||||
return null;
|
SysMessage sysMessage = sysMessageService.getById(messageParam.getMessageId());
|
||||||
|
// 判断消息为未读状态更新为已读
|
||||||
|
Optional.ofNullable(sysMessage).ifPresent(msg -> {
|
||||||
|
if(MessageReadFlagEnum.UNREAD.getCode().equals(sysMessage.getReadFlag())){
|
||||||
|
msg.setReadFlag(MessageReadFlagEnum.READ.getCode());
|
||||||
|
sysMessageService.updateById(msg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
MessageResponse messageResponse = new MessageResponse();
|
||||||
|
BeanUtil.copyProperties(sysMessage, messageResponse);
|
||||||
|
return messageResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<MessageResponse> queryMessagePage(MessageParam messageParam) {
|
public PageResult<MessageResponse> queryPage(MessageParam messageParam) {
|
||||||
return null;
|
PageResult<SysMessage> pageResult = sysMessageService.page(messageParam);
|
||||||
|
PageResult<MessageResponse> result = new PageResult<>();
|
||||||
|
BeanUtil.copyProperties(pageResult, result);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MessageResponse> queryMessageList(MessageParam messageParam) {
|
public List<MessageResponse> queryList(MessageParam messageParam) {
|
||||||
return null;
|
List<SysMessage> messageList = sysMessageService.list(messageParam);
|
||||||
|
List<MessageResponse> resultList = new ArrayList<>();
|
||||||
|
BeanUtil.copyProperties(messageList, resultList);
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<MessageResponse> queryPageCurrentUser(MessageParam messageParam) {
|
||||||
|
if (ObjectUtil.isEmpty(messageParam)) {
|
||||||
|
messageParam = new MessageParam();
|
||||||
|
}
|
||||||
|
// 获取当前登录人
|
||||||
|
LoginUser loginUser = LoginContext.me().getLoginUser();
|
||||||
|
messageParam.setReceiveUserId(loginUser.getUserId());
|
||||||
|
return this.queryPage(messageParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MessageResponse> queryListCurrentUser(MessageParam messageParam) {
|
||||||
|
if (ObjectUtil.isEmpty(messageParam)) {
|
||||||
|
messageParam = new MessageParam();
|
||||||
|
}
|
||||||
|
// 获取当前登录人
|
||||||
|
LoginUser loginUser = LoginContext.me().getLoginUser();
|
||||||
|
messageParam.setReceiveUserId(loginUser.getUserId());
|
||||||
|
return this.queryList(messageParam);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
package cn.stylefeng.roses.kernel.message.db.service;
|
package cn.stylefeng.roses.kernel.message.db.service;
|
||||||
|
|
||||||
|
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||||
|
import cn.stylefeng.roses.kernel.message.api.pojo.MessageParam;
|
||||||
import cn.stylefeng.roses.kernel.message.db.entity.SysMessage;
|
import cn.stylefeng.roses.kernel.message.db.entity.SysMessage;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统消息 service接口
|
* 系统消息 service接口
|
||||||
*
|
*
|
||||||
|
@ -10,5 +14,21 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
* @date 2020/12/31 20:09
|
* @date 2020/12/31 20:09
|
||||||
*/
|
*/
|
||||||
public interface SysMessageService extends IService<SysMessage> {
|
public interface SysMessageService extends IService<SysMessage> {
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
*
|
||||||
|
* @param messageParam 参数
|
||||||
|
* @author liuhanqing
|
||||||
|
* @date 2021/1/2 15:21
|
||||||
|
*/
|
||||||
|
PageResult<SysMessage> page(MessageParam messageParam);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列表查询
|
||||||
|
*
|
||||||
|
* @param messageParam 参数
|
||||||
|
* @author liuhanqing
|
||||||
|
* @date 2021/1/8 15:21
|
||||||
|
*/
|
||||||
|
List<SysMessage> list(MessageParam messageParam);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,21 @@
|
||||||
package cn.stylefeng.roses.kernel.message.db.service.impl;
|
package cn.stylefeng.roses.kernel.message.db.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
|
||||||
|
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
|
||||||
|
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||||
|
import cn.stylefeng.roses.kernel.message.api.pojo.MessageParam;
|
||||||
import cn.stylefeng.roses.kernel.message.db.entity.SysMessage;
|
import cn.stylefeng.roses.kernel.message.db.entity.SysMessage;
|
||||||
import cn.stylefeng.roses.kernel.message.db.mapper.SysMessageMapper;
|
import cn.stylefeng.roses.kernel.message.db.mapper.SysMessageMapper;
|
||||||
import cn.stylefeng.roses.kernel.message.db.service.SysMessageService;
|
import cn.stylefeng.roses.kernel.message.db.service.SysMessageService;
|
||||||
|
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统消息 service接口实现类
|
* 系统消息 service接口实现类
|
||||||
*
|
*
|
||||||
|
@ -15,4 +25,56 @@ import org.springframework.stereotype.Service;
|
||||||
@Service
|
@Service
|
||||||
public class SysMessageServiceImpl extends ServiceImpl<SysMessageMapper, SysMessage> implements SysMessageService {
|
public class SysMessageServiceImpl extends ServiceImpl<SysMessageMapper, SysMessage> implements SysMessageService {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<SysMessage> page(MessageParam messageParam) {
|
||||||
|
LambdaQueryWrapper<SysMessage> wrapper = createWrapper(messageParam);
|
||||||
|
Page<SysMessage> page = this.page(PageFactory.defaultPage(), wrapper);
|
||||||
|
return PageResultFactory.createPageResult(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SysMessage> list(MessageParam messageParam) {
|
||||||
|
LambdaQueryWrapper<SysMessage> wrapper = createWrapper(messageParam);
|
||||||
|
return this.list(wrapper);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 创建wrapper
|
||||||
|
*
|
||||||
|
* @author liuhanqing
|
||||||
|
* @date 2021/1/8 14:16
|
||||||
|
*/
|
||||||
|
private LambdaQueryWrapper<SysMessage> createWrapper(MessageParam messageParam) {
|
||||||
|
LambdaQueryWrapper<SysMessage> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
|
||||||
|
if (ObjectUtil.isNotNull(messageParam)) {
|
||||||
|
|
||||||
|
// 拼接消息标题
|
||||||
|
if (ObjectUtil.isNotEmpty(messageParam.getMessageTitle())) {
|
||||||
|
queryWrapper.like(SysMessage::getMessageTitle, messageParam.getMessageTitle());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 拼接接收人id查询条件
|
||||||
|
if (ObjectUtil.isNotEmpty(messageParam.getReceiveUserId())) {
|
||||||
|
queryWrapper.eq(SysMessage::getReceiveUserId, messageParam.getReceiveUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 拼接消息类型
|
||||||
|
if (ObjectUtil.isNotEmpty(messageParam.getMessageType())) {
|
||||||
|
queryWrapper.eq(SysMessage::getMessageType, messageParam.getMessageType());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 拼接阅读状态
|
||||||
|
if (ObjectUtil.isNotEmpty(messageParam.getReadFlag())) {
|
||||||
|
queryWrapper.eq(SysMessage::getReadFlag, messageParam.getReadFlag());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 查询未删除的
|
||||||
|
queryWrapper.ne(SysMessage::getDelFlag, YesOrNotEnum.Y.getCode());
|
||||||
|
|
||||||
|
// 按发送事件倒序
|
||||||
|
queryWrapper.orderByDesc(SysMessage::getMessageSendTime);
|
||||||
|
|
||||||
|
return queryWrapper;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue