refactor(resource): 调整消息通知

master
yang 2025-02-17 10:06:09 +08:00
parent afc35ca586
commit 2efdbfe773
10 changed files with 68 additions and 96 deletions

View File

@ -6,6 +6,8 @@ import com.mcwl.resource.domain.vo.AttentionAdviceVo;
import com.mcwl.resource.domain.vo.CommentAdviceVo;
import com.mcwl.resource.domain.vo.LikeAdviceVo;
import com.mcwl.resource.service.ISysAdviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
@ -22,41 +24,16 @@ import java.util.List;
@RestController
@RequestMapping("system/advice")
@RequiredArgsConstructor
@Api(tags = "消息通知")
public class SysAdviceController {
private final ISysAdviceService sysAdviceService;
/**
*
*/
@GetMapping("getUserNewMsg")
public R<List<AdviceVo>> getUserNewMsg() {
List<AdviceVo> adviceVo = sysAdviceService.getUserNewMsg();
return R.ok(adviceVo);
}
/**
*
*/
@GetMapping("getUserSystemNotice")
public R<List<AdviceVo>> getUserSystemNotice() {
List<AdviceVo> adviceVo = sysAdviceService.getUserSystemNotice();
return R.ok(adviceVo);
}
/**
*
*/
@GetMapping("getUserAllMsg")
public R<List<AdviceVo>> getUserAllMsg() {
List<AdviceVo> adviceVo = sysAdviceService.getUserAllMsg();
return R.ok(adviceVo);
}
/**
*
*/
@GetMapping("getAllMsg")
@ApiOperation(value = "获取所有通知")
public R<List<AdviceVo>> getAllMsg() {
List<AdviceVo> adviceVo = sysAdviceService.getAllMsg();
return R.ok(adviceVo);
@ -67,6 +44,7 @@ public class SysAdviceController {
*
*/
@GetMapping("getCommentMsg")
@ApiOperation(value = "获取评论通知")
public R<List<CommentAdviceVo>> getCommentMsg(@Valid
@NotNull(message = "类型不能为空")
@ApiParam(value = "类型 0模型 1工作流 2图片 3全部", required = true)
@ -79,6 +57,7 @@ public class SysAdviceController {
*
*/
@GetMapping("getLikeMsg")
@ApiOperation(value = "获取点赞通知")
public R<List<LikeAdviceVo>> getLikeMsg(@Valid
@NotNull(message = "类型不能为空")
@ApiParam(value = "类型 0模型 1工作流 2图片 3评论 4全部", required = true)
@ -92,6 +71,7 @@ public class SysAdviceController {
*
*/
@GetMapping("getAttentionMsg")
@ApiOperation(value = "获取关注通知")
public R<List<AttentionAdviceVo>> getAttentionMsg() {
List<AttentionAdviceVo> attentionAdviceVoList = sysAdviceService.getAttentionMsg();
return R.ok(attentionAdviceVoList);

View File

@ -1,29 +1,46 @@
package com.mcwl.resource.domain.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mcwl.system.domain.enums.AdviceEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
@Data
@ApiModel(description = "消息通知")
public class AdviceVo {
/**
*
* id
*/
private AdviceEnum type;
@ApiModelProperty(value = "id")
private Long id;
/**
*
*/
@ApiModelProperty(value = "标题")
private String title;
/**
*
*/
@ApiModelProperty(value = "内容")
private String content;
/**
* 0 1
*/
@ApiModelProperty(value = "是否已读 0否 1是")
private String isRead;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建时间")
private Date createTime;
}

View File

@ -1,5 +1,6 @@
package com.mcwl.resource.domain.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -37,6 +38,7 @@ public class AttentionAdviceVo {
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建时间")
private Date createTime;

View File

@ -1,5 +1,6 @@
package com.mcwl.resource.domain.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -56,6 +57,7 @@ public class CommentAdviceVo {
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建时间")
private Date createTime;

View File

@ -16,12 +16,6 @@ import java.util.List;
*/
public interface ISysAdviceService extends IService<SysAdvice> {
List<AdviceVo> getUserNewMsg();
List<AdviceVo> getUserSystemNotice();
List<AdviceVo> getUserAllMsg();
List<AdviceVo> getAllMsg();
List<CommentAdviceVo> getCommentMsg(Integer productType);

View File

@ -2,6 +2,7 @@ package com.mcwl.resource.service.impl;
import cn.hutool.core.bean.BeanUtil;
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.mcwl.common.core.domain.entity.SysUser;
import com.mcwl.common.utils.SecurityUtils;
@ -46,44 +47,24 @@ public class SysAdviceServiceImpl extends ServiceImpl<SysAdviceMapper, SysAdvice
private final Map<Long, WorkFlow> workFlowMap = new ConcurrentHashMap<>();
private final Map<Long, ModelImage> modelImageMap = new ConcurrentHashMap<>();
@Override
public List<AdviceVo> getUserNewMsg() {
Long userId = SecurityUtils.getUserId();
List<SysAdvice> sysAdvices = baseMapper.selectList(lambdaQuery()
.eq(SysAdvice::getReceiverId, userId)
.eq(SysAdvice::getType, AdviceEnum.NEW_MESSAGE_REMIND));
return BeanUtil.copyToList(sysAdvices, AdviceVo.class);
}
@Override
public List<AdviceVo> getUserSystemNotice() {
Long userId = SecurityUtils.getUserId();
List<SysAdvice> sysAdvices = baseMapper.selectList(lambdaQuery()
.eq(SysAdvice::getReceiverId, userId)
.eq(SysAdvice::getType, AdviceEnum.SYSTEM_NOTICE));
return BeanUtil.copyToList(sysAdvices, AdviceVo.class);
}
@Override
public List<AdviceVo> getUserAllMsg() {
Long userId = SecurityUtils.getUserId();
List<SysAdvice> sysAdvices = baseMapper.selectList(lambdaQuery()
.eq(SysAdvice::getReceiverId, userId));
return BeanUtil.copyToList(sysAdvices, AdviceVo.class);
}
@Override
public List<AdviceVo> getAllMsg() {
List<SysAdvice> sysAdvices = baseMapper.selectList(null);
// 创建分页对象
Page<SysAdvice> page = new Page<>(1, 20);
LambdaQueryWrapper<SysAdvice> lqw = new LambdaQueryWrapper<SysAdvice>()
.and(wrapper -> wrapper
.eq(SysAdvice::getReceiverId, SecurityUtils.getUserId())
.or()
.isNull(SysAdvice::getReceiverId)
)
.orderByDesc(SysAdvice::getCreateTime);
Page<SysAdvice> sysAdvicePage = baseMapper.selectPage(page, lqw);
List<SysAdvice> sysAdvices = sysAdvicePage.getRecords();
return BeanUtil.copyToList(sysAdvices, AdviceVo.class);
}
@ -96,14 +77,15 @@ public class SysAdviceServiceImpl extends ServiceImpl<SysAdviceMapper, SysAdvice
List<SysAdvice> sysAdviceList = baseMapper.selectList(new LambdaQueryWrapper<SysAdvice>()
.eq(SysAdvice::getType, AdviceEnum.COMMENT_REMIND)
.eq(SysAdvice::getReceiverId, SecurityUtils.getUserId())
.eq(productType != 3, SysAdvice::getProductType, productType));
.eq(productType != 3, SysAdvice::getProductType, productType)
.orderByDesc(SysAdvice::getCreateTime));
List<Long> commentUserIdList = new ArrayList<>();
for (SysAdvice sysAdvice : sysAdviceList) {
commentUserIdList.add(sysAdvice.getSenderId());
}
List<SysUser> sysUsers = sysUserService.selectUserByIds(commentUserIdList);
List<SysUser> sysUsers = sysUserService.listByIds(commentUserIdList);
Map<Long, SysUser> commentUserMap = new HashMap<>();
for (SysUser sysUser : sysUsers) {
@ -116,7 +98,9 @@ public class SysAdviceServiceImpl extends ServiceImpl<SysAdviceMapper, SysAdvice
Long senderId = sysAdvice.getSenderId();
SysUser senderUser = commentUserMap.get(senderId);
commentAdviceVo.setUserAvatar(senderUser.getAvatar());
if (Objects.nonNull(senderUser)) {
commentAdviceVo.setUserAvatar(senderUser.getAvatar());
}
if (productType == 0) {
ModelProduct modelProduct = modelProductMap.get(sysAdvice.getProductId());
if (Objects.nonNull(modelProduct)) {
@ -148,19 +132,21 @@ public class SysAdviceServiceImpl extends ServiceImpl<SysAdviceMapper, SysAdvice
sysAdviceList = baseMapper.selectList(new LambdaQueryWrapper<SysAdvice>()
.eq(SysAdvice::getType, AdviceEnum.LIKE_REMIND)
.eq(SysAdvice::getReceiverId, SecurityUtils.getUserId())
.isNotNull(SysAdvice::getCommentId));
.isNotNull(SysAdvice::getCommentId)
.orderByDesc(SysAdvice::getCreateTime));
} else {
sysAdviceList = baseMapper.selectList(new LambdaQueryWrapper<SysAdvice>()
.eq(SysAdvice::getType, AdviceEnum.LIKE_REMIND)
.eq(SysAdvice::getReceiverId, SecurityUtils.getUserId())
.eq(productType != 4, SysAdvice::getProductType, productType));
.eq(productType != 4, SysAdvice::getProductType, productType)
.orderByDesc(SysAdvice::getCreateTime));
}
List<Long> likeUserIdList = new ArrayList<>();
for (SysAdvice sysAdvice : sysAdviceList) {
likeUserIdList.add(sysAdvice.getSenderId());
}
List<SysUser> sysUsers = sysUserService.selectUserByIds(likeUserIdList);
List<SysUser> sysUsers = sysUserService.listByIds(likeUserIdList);
Map<Long, SysUser> likeUserMap = new HashMap<>();
for (SysUser sysUser : sysUsers) {
@ -174,7 +160,9 @@ public class SysAdviceServiceImpl extends ServiceImpl<SysAdviceMapper, SysAdvice
Long senderId = sysAdvice.getSenderId();
SysUser senderUser = likeUserMap.get(senderId);
likeAdviceVo.setUserAvatar(senderUser.getAvatar());
if (Objects.nonNull(senderUser)) {
likeAdviceVo.setUserAvatar(senderUser.getAvatar());
}
if (productType == 0) {
ModelProduct modelProduct = modelProductMap.get(sysAdvice.getProductId());
if (Objects.nonNull(modelProduct)) {
@ -202,7 +190,8 @@ public class SysAdviceServiceImpl extends ServiceImpl<SysAdviceMapper, SysAdvice
public List<AttentionAdviceVo> getAttentionMsg() {
List<SysAdvice> sysAdviceList = baseMapper.selectList(new LambdaQueryWrapper<SysAdvice>()
.eq(SysAdvice::getType, AdviceEnum.FANS_REMIND)
.eq(SysAdvice::getReceiverId, SecurityUtils.getUserId()));
.eq(SysAdvice::getReceiverId, SecurityUtils.getUserId())
.orderByDesc(SysAdvice::getCreateTime));
List<AttentionAdviceVo> attentionAdviceVoList = new ArrayList<>();
List<Long> atentUserIdList = new ArrayList<>();
@ -225,7 +214,9 @@ public class SysAdviceServiceImpl extends ServiceImpl<SysAdviceMapper, SysAdvice
AttentionAdviceVo attentionAdviceVo = BeanUtil.copyProperties(sysAdvice, AttentionAdviceVo.class);
Long senderId = sysAdvice.getSenderId();
SysUser attentionUser = attentionUserMap.get(senderId);
attentionAdviceVo.setUserAvatar(attentionUser.getAvatar());
if (Objects.nonNull(attentionUser)) {
attentionAdviceVo.setUserAvatar(attentionUser.getAvatar());
}
attentionAdviceVoList.add(attentionAdviceVo);
}

View File

@ -138,8 +138,6 @@ public interface SysUserMapper
List<SysUser> listByIds(List<Long> userIdList);
List<SysUser> selectUserByIds(@Param("userIds") List<Long> userIds);
List<SysUser> selectUserPage(@Param("userId") Long userId);
List<SysUser> selectToUserPage(@Param("userId") Long userId);

View File

@ -217,6 +217,4 @@ public interface ISysUserService
AjaxResult updateIdCard(SysUser sysUser);
List<SysUser> listByIds(List<Long> userIdList);
List<SysUser> selectUserByIds(List<Long> userIds);
}

View File

@ -653,6 +653,9 @@ public class SysUserServiceImpl implements ISysUserService
@Override
public List<SysUser> listByIds(List<Long> userIdList) {
if (userIdList == null || userIdList.isEmpty()) {
return Collections.emptyList();
}
return userMapper.listByIds(userIdList);
}
@ -675,9 +678,4 @@ public class SysUserServiceImpl implements ISysUserService
return sb.toString();
}
@Override
public List<SysUser> selectUserByIds(List<Long> userIds) {
return userMapper.selectUserByIds(userIds);
}
}

View File

@ -167,14 +167,6 @@
</select>
<select id="selectUserByIds" resultType="com.mcwl.common.core.domain.entity.SysUser">
<include refid="selectUserVo"/>
where u.user_id in
<foreach collection="userIds" item="userId" open="(" separator="," close=")">
#{userId}
</foreach>
</select>
<select id="selectUserPage" resultType="com.mcwl.common.core.domain.entity.SysUser">
select u.user_id,nick_name,avatar FROM sys_user_attention as a
LEFT JOIN sys_user as u