|
@@ -4,16 +4,22 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
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 com.kxs.common.security.util.SecurityUtils;
|
|
import com.kxs.common.security.util.SecurityUtils;
|
|
|
|
|
+import com.kxs.system.api.model.KxsSysMsgRead;
|
|
|
import com.kxs.system.api.vo.kxsapp.sysMsg.SysMsgPageVO;
|
|
import com.kxs.system.api.vo.kxsapp.sysMsg.SysMsgPageVO;
|
|
|
import com.kxs.system.api.vo.kxsapp.sysMsg.SysMsgVO;
|
|
import com.kxs.system.api.vo.kxsapp.sysMsg.SysMsgVO;
|
|
|
import com.kxs.system.biz.constant.SysConstants;
|
|
import com.kxs.system.biz.constant.SysConstants;
|
|
|
import com.kxs.system.biz.mapper.KxsSysMsgMapper;
|
|
import com.kxs.system.biz.mapper.KxsSysMsgMapper;
|
|
|
import com.kxs.system.api.model.KxsSysMsg;
|
|
import com.kxs.system.api.model.KxsSysMsg;
|
|
|
|
|
+import com.kxs.system.biz.mapper.KxsSysMsgReadMapper;
|
|
|
import com.kxs.system.biz.service.KxsSysMsgService;
|
|
import com.kxs.system.biz.service.KxsSysMsgService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 系统消息推送表(KxsSysMsg)表服务实现类
|
|
* 系统消息推送表(KxsSysMsg)表服务实现类
|
|
@@ -27,20 +33,30 @@ public class KxsSysMsgServiceImpl extends ServiceImpl<KxsSysMsgMapper, KxsSysMsg
|
|
|
|
|
|
|
|
private final RedisTemplate<String, Object> redisTemplate;
|
|
private final RedisTemplate<String, Object> redisTemplate;
|
|
|
|
|
|
|
|
|
|
+ private final KxsSysMsgReadMapper kxsSysMsgReadMapper;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public IPage<SysMsgPageVO> getByPage(Page<SysMsgPageVO> page) {
|
|
public IPage<SysMsgPageVO> getByPage(Page<SysMsgPageVO> page) {
|
|
|
|
|
+ Long userId = SecurityUtils.getUser().getId();
|
|
|
|
|
|
|
|
- return baseMapper.getByPage(page);
|
|
|
|
|
|
|
+ return baseMapper.getByPage(page, userId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void readAll() {
|
|
public void readAll() {
|
|
|
|
|
|
|
|
Long userId = SecurityUtils.getUser().getId();
|
|
Long userId = SecurityUtils.getUser().getId();
|
|
|
- //系统消息存储的key
|
|
|
|
|
- String key = SysConstants.KXS_SYS_MSG_PREFIX + userId;
|
|
|
|
|
|
|
|
|
|
- redisTemplate.delete(key);
|
|
|
|
|
|
|
+ List<SysMsgPageVO> list = baseMapper.getList(userId);
|
|
|
|
|
+
|
|
|
|
|
+ for (SysMsgPageVO sysMsgPageVO : list) {
|
|
|
|
|
+ KxsSysMsgRead kxsSysMsgRead = new KxsSysMsgRead();
|
|
|
|
|
+ kxsSysMsgRead.setMsgId(sysMsgPageVO.getId());
|
|
|
|
|
+ kxsSysMsgRead.setUserId(Math.toIntExact(userId));
|
|
|
|
|
+ kxsSysMsgReadMapper.insert(kxsSysMsgRead);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -52,14 +68,15 @@ public class KxsSysMsgServiceImpl extends ServiceImpl<KxsSysMsgMapper, KxsSysMsg
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Long userId = SecurityUtils.getUser().getId();
|
|
Long userId = SecurityUtils.getUser().getId();
|
|
|
- //系统消息存储的key
|
|
|
|
|
- String key = SysConstants.KXS_SYS_MSG_PREFIX + userId;
|
|
|
|
|
|
|
+ //已读消息
|
|
|
|
|
+ KxsSysMsgRead kxsSysMsgRead = new KxsSysMsgRead();
|
|
|
|
|
+ kxsSysMsgRead.setMsgId(kxsSysMsg.getId());
|
|
|
|
|
+ kxsSysMsgRead.setUserId(Math.toIntExact(userId));
|
|
|
|
|
+ kxsSysMsgReadMapper.insert(kxsSysMsgRead);
|
|
|
|
|
|
|
|
SysMsgVO sysMsgVO = new SysMsgVO();
|
|
SysMsgVO sysMsgVO = new SysMsgVO();
|
|
|
BeanUtils.copyProperties(kxsSysMsg, sysMsgVO);
|
|
BeanUtils.copyProperties(kxsSysMsg, sysMsgVO);
|
|
|
|
|
|
|
|
- //已读消息
|
|
|
|
|
- redisTemplate.opsForList().remove(key,1, id);
|
|
|
|
|
|
|
|
|
|
return sysMsgVO;
|
|
return sysMsgVO;
|
|
|
}
|
|
}
|