feat: 完善消息接收设置

This commit is contained in:
fit2cloud-chenyw
2021-07-12 11:30:57 +08:00
parent ff82cffff4
commit b329f894d1
19 changed files with 206 additions and 59 deletions

View File

@@ -4,4 +4,5 @@ public class SysMsgConstants {
public final static String SYS_MSG_CHANNEL = "sys_msg_channel";
public final static String SYS_MSG_TYPE = "sys_msg_type";
public final static String SYS_MSG_USER_SUBSCRIBE = "sys_msg_user_subscribe";
}

View File

@@ -8,7 +8,6 @@ import io.dataease.base.domain.SysMsgType;
import io.dataease.commons.utils.AuthUtils;
import io.dataease.commons.utils.PageUtils;
import io.dataease.commons.utils.Pager;
import io.dataease.controller.handler.annotation.I18n;
import io.dataease.controller.message.dto.MsgGridDto;
import io.dataease.controller.message.dto.MsgRequest;
import io.dataease.controller.message.dto.MsgSettingRequest;
@@ -53,14 +52,12 @@ public class MsgController {
sysMsgService.batchDelete(msgIds);
}
@I18n
@PostMapping("/treeNodes")
public List<SettingTreeNode> treeNodes() {
return sysMsgService.treeNodes();
}
@I18n
@PostMapping("/channelList")
public List<SysMsgChannel> channelList() {
return sysMsgService.channelList();
@@ -73,10 +70,10 @@ public class MsgController {
@PostMapping("/updateSetting")
public void updateSetting(@RequestBody MsgSettingRequest request) {
sysMsgService.updateSetting(request);
Long userId = AuthUtils.getUser().getUserId();
sysMsgService.updateSetting(request, userId);
}
@I18n
@PostMapping("/types")
public List<SysMsgType> allTypes() {
List<SysMsgType> sysMsgTypes = sysMsgService.queryMsgTypes();

View File

@@ -0,0 +1,20 @@
package io.dataease.controller.message.dto;
import lombok.Data;
import java.io.Serializable;
@Data
public class SubscribeNode implements Serializable {
private static final long serialVersionUID = -1680823237289721438L;
private Long typeId;
private Long channelId;
public Boolean match(Long type, Long channel) {
return type == typeId && channel == channelId;
}
}

View File

@@ -1,6 +1,5 @@
package io.dataease.service.message;
import io.dataease.base.domain.SysMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -20,14 +19,14 @@ public class DeMsgutil {
public static void sendMsg(Long userId, Long typeId, Long channelId, String content, String param) {
SysMsg sysMsg = new SysMsg();
sysMsg.setUserId(userId);
sysMsg.setTypeId(typeId);
sysMsg.setContent(content);
sysMsg.setStatus(false);
sysMsg.setCreateTime(System.currentTimeMillis());
sysMsg.setParam(param);
sysMsgService.save(sysMsg);
// SysMsg sysMsg = new SysMsg();
// sysMsg.setUserId(userId);
// sysMsg.setTypeId(typeId);
// sysMsg.setContent(content);
// sysMsg.setStatus(false);
// sysMsg.setCreateTime(System.currentTimeMillis());
// sysMsg.setParam(param);
sysMsgService.sendMsg(userId, typeId, channelId, content, param);
}

View File

@@ -1,20 +1,25 @@
package io.dataease.service.message;
import io.dataease.base.domain.SysMsgSettingExample;
import io.dataease.base.mapper.SysMsgSettingMapper;
import io.dataease.controller.message.dto.SubscribeNode;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
@Aspect
@Component
public class MsgAop {
@Resource
private SysMsgSettingMapper sysMsgSettingMapper;
private SysMsgService sysMsgService;
@@ -24,7 +29,7 @@ public class MsgAop {
* 对sendMsg 切面拦截
* @param point
*/
@Around("(execution(* io.dataease.service.message.DeMsgutil.sendMsg(..)))")
@Around("(execution(* io.dataease.service.message.SysMsgService.sendMsg(..)))")
public Object cutPoint(ProceedingJoinPoint point) {
Object[] args = point.getArgs();
@@ -39,11 +44,11 @@ public class MsgAop {
Long typeId = (Long) arg1;
Long channelId = (Long) arg2;
SysMsgSettingExample example = new SysMsgSettingExample();
example.createCriteria().andChannelIdEqualTo(channelId).andUserIdEqualTo(userId).andTypeIdEqualTo(typeId).andEnableEqualTo(true);
List<SubscribeNode> subscribes = sysMsgService.subscribes(userId);
try {
if (sysMsgSettingMapper.countByExample(example) > 0)
// 如果已经订阅了这种类型的消息 直接发送 否则直接返回
if (CollectionUtils.isNotEmpty(subscribes) && subscribes.stream().anyMatch(item -> item.match(typeId, channelId)))
return point.proceed(args);
return null;
} catch (Throwable throwable) {

View File

@@ -7,16 +7,13 @@ import io.dataease.base.mapper.SysMsgMapper;
import io.dataease.base.mapper.SysMsgSettingMapper;
import io.dataease.base.mapper.SysMsgTypeMapper;
import io.dataease.base.mapper.ext.ExtSysMsgMapper;
import io.dataease.commons.constants.AuthConstants;
import io.dataease.commons.constants.SysMsgConstants;
import io.dataease.commons.utils.AuthUtils;
import io.dataease.commons.utils.CommonBeanFactory;
import io.dataease.controller.message.dto.MsgGridDto;
import io.dataease.controller.message.dto.MsgRequest;
import io.dataease.controller.message.dto.MsgSettingRequest;
import io.dataease.controller.message.dto.SettingTreeNode;
import io.dataease.controller.message.dto.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -179,11 +176,17 @@ public class SysMsgService {
return sysMsgSettings;
}
/**
* 修改了订阅信息 需要清除缓存
* @param request
* @param userId
*/
@Transactional
public void updateSetting(MsgSettingRequest request) {
@CacheEvict(value = SysMsgConstants.SYS_MSG_USER_SUBSCRIBE, key = "#userId")
public void updateSetting(MsgSettingRequest request, Long userId) {
Long typeId = request.getTypeId();
Long channelId = request.getChannelId();
Long userId = AuthUtils.getUser().getUserId();
// Long userId = AuthUtils.getUser().getUserId();
SysMsgSettingExample example = new SysMsgSettingExample();
example.createCriteria().andUserIdEqualTo(userId).andTypeIdEqualTo(typeId).andChannelIdEqualTo(channelId);
List<SysMsgSetting> sysMsgSettings = sysMsgSettingMapper.selectByExample(example);
@@ -202,5 +205,34 @@ public class SysMsgService {
sysMsgSettingMapper.insert(sysMsgSetting);
}
public void sendMsg(Long userId, Long typeId, Long channelId, String content, String param) {
SysMsg sysMsg = new SysMsg();
sysMsg.setUserId(userId);
sysMsg.setTypeId(typeId);
sysMsg.setContent(content);
sysMsg.setStatus(false);
sysMsg.setCreateTime(System.currentTimeMillis());
sysMsg.setParam(param);
save(sysMsg);
}
/**
* 查询用户订阅的消息 并缓存
* @param userId
* @return
*/
@Cacheable(value = SysMsgConstants.SYS_MSG_USER_SUBSCRIBE, key = "#userId")
public List<SubscribeNode> subscribes(Long userId) {
SysMsgSettingExample example = new SysMsgSettingExample();
example.createCriteria().andUserIdEqualTo(userId).andEnableEqualTo(true);
List<SysMsgSetting> sysMsgSettings = sysMsgSettingMapper.selectByExample(example);
List<SubscribeNode> resultLists = sysMsgSettings.stream().map(item -> {
SubscribeNode subscribeNode = new SubscribeNode();
subscribeNode.setTypeId(item.getTypeId());
subscribeNode.setChannelId(item.getChannelId());
return subscribeNode;
}).collect(Collectors.toList());
return resultLists;
}
}