feat(resource): 评论通知功能

master
yang 2025-02-15 18:01:24 +08:00
parent 461b75cce2
commit 7e40833bb7
19 changed files with 472 additions and 140 deletions

View File

@ -1,15 +1,22 @@
package com.mcwl.web.controller.system; package com.mcwl.web.controller.system;
import com.mcwl.common.core.domain.AjaxResult; import com.mcwl.common.core.domain.R;
import com.mcwl.system.domain.vo.AdviceVo; import com.mcwl.resource.domain.vo.AdviceVo;
import com.mcwl.system.service.ISysAdviceService; import com.mcwl.resource.domain.vo.CommentAdviceVo;
import com.mcwl.resource.service.ISysAdviceService;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List; import java.util.List;
/**
*
*/
@RestController @RestController
@RequestMapping("system/advice") @RequestMapping("system/advice")
@RequiredArgsConstructor @RequiredArgsConstructor
@ -18,39 +25,52 @@ public class SysAdviceController {
private final ISysAdviceService sysAdviceService; private final ISysAdviceService sysAdviceService;
/** /**
* *
*/ */
@GetMapping("getUserNewMsg") @GetMapping("getUserNewMsg")
public AjaxResult getUserNewMsg() { public R<List<AdviceVo>> getUserNewMsg() {
List<AdviceVo> adviceVo = sysAdviceService.getUserNewMsg(); List<AdviceVo> adviceVo = sysAdviceService.getUserNewMsg();
return AjaxResult.success(adviceVo); return R.ok(adviceVo);
} }
/** /**
* *
*/ */
@GetMapping("getUserSystemNotice") @GetMapping("getUserSystemNotice")
public AjaxResult getUserSystemNotice() { public R<List<AdviceVo>> getUserSystemNotice() {
List<AdviceVo> adviceVo = sysAdviceService.getUserSystemNotice(); List<AdviceVo> adviceVo = sysAdviceService.getUserSystemNotice();
return AjaxResult.success(adviceVo); return R.ok(adviceVo);
} }
/** /**
* *
*/ */
@GetMapping("getUserAllMsg") @GetMapping("getUserAllMsg")
public AjaxResult getUserAllMsg() { public R<List<AdviceVo>> getUserAllMsg() {
List<AdviceVo> adviceVo = sysAdviceService.getUserAllMsg(); List<AdviceVo> adviceVo = sysAdviceService.getUserAllMsg();
return AjaxResult.success(adviceVo); return R.ok(adviceVo);
} }
/** /**
* *
*/ */
@GetMapping("getAllMsg") @GetMapping("getAllMsg")
public AjaxResult getAllMsg() { public R<List<AdviceVo>> getAllMsg() {
List<AdviceVo> adviceVo = sysAdviceService.getAllMsg(); List<AdviceVo> adviceVo = sysAdviceService.getAllMsg();
return AjaxResult.success(adviceVo); return R.ok(adviceVo);
}
/**
*
*/
@GetMapping("getCommentMsg")
public R<List<CommentAdviceVo>> getCommentMsg(@Valid
@NotNull(message = "类型不能为空")
@ApiParam(value = "类型 0模型 1工作流 2图片 3全部", required = true)
Integer productType) {
List<CommentAdviceVo> adviceVo = sysAdviceService.getCommentMsg(productType);
return R.ok(adviceVo);
} }

View File

@ -45,6 +45,12 @@
<artifactId>spring-boot-starter-amqp</artifactId> <artifactId>spring-boot-starter-amqp</artifactId>
<version>3.1.2</version> <version>3.1.2</version>
</dependency> </dependency>
<dependency>
<groupId>com.mcwl</groupId>
<artifactId>mcwl-resource</artifactId>
<version>3.8.8</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -2,12 +2,10 @@ package com.mcwl.memberCenter.consumer;
import com.mcwl.common.constant.QueueConstants; import com.mcwl.common.constant.QueueConstants;
import com.mcwl.common.core.domain.entity.SysUser; import com.mcwl.common.core.domain.entity.SysUser;
import com.mcwl.common.utils.SecurityUtils;
import com.mcwl.memberCenter.domain.Member; import com.mcwl.memberCenter.domain.Member;
import com.mcwl.memberCenter.service.MemberService; import com.mcwl.resource.domain.SysAdvice;
import com.mcwl.system.domain.SysAdvice; import com.mcwl.resource.service.ISysAdviceService;
import com.mcwl.system.domain.enums.AdviceEnum; import com.mcwl.system.domain.enums.AdviceEnum;
import com.mcwl.system.service.ISysAdviceService;
import com.mcwl.system.service.ISysUserService; import com.mcwl.system.service.ISysUserService;
import com.rabbitmq.client.Channel; import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message; import org.springframework.amqp.core.Message;

View File

@ -3,9 +3,9 @@ package com.mcwl.memberCenter.consumer;
import com.mcwl.common.constant.QueueConstants; import com.mcwl.common.constant.QueueConstants;
import com.mcwl.common.core.domain.entity.SysUser; import com.mcwl.common.core.domain.entity.SysUser;
import com.mcwl.memberCenter.domain.Member; import com.mcwl.memberCenter.domain.Member;
import com.mcwl.system.domain.SysAdvice; import com.mcwl.resource.domain.SysAdvice;
import com.mcwl.system.domain.enums.AdviceEnum; import com.mcwl.system.domain.enums.AdviceEnum;
import com.mcwl.system.service.ISysAdviceService; import com.mcwl.resource.service.ISysAdviceService;
import com.mcwl.system.service.ISysUserService; import com.mcwl.system.service.ISysUserService;
import com.rabbitmq.client.Channel; import com.rabbitmq.client.Channel;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;

View File

@ -32,5 +32,12 @@
<artifactId>mcwl-system</artifactId> <artifactId>mcwl-system</artifactId>
</dependency> </dependency>
<!-- rabbitmq依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
<version>3.1.2</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,4 +1,4 @@
package com.mcwl.system.domain; package com.mcwl.resource.domain;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
@ -28,11 +28,6 @@ public class SysAdvice extends BaseEntity {
*/ */
private Long receiverId; private Long receiverId;
/**
*
*/
private AdviceEnum type;
/** /**
* *
*/ */
@ -44,9 +39,24 @@ public class SysAdvice extends BaseEntity {
private String content; private String content;
/** /**
* 0 1 * id
*/ */
private String isRead; private Long productId;
/**
* 0 1 2
*/
private Integer productType;
/**
* 0 1
*/
private Integer isRead;
/**
*
*/
private AdviceEnum type;

View File

@ -33,7 +33,7 @@ public class ModelCommentRes {
/** /**
* *
*/ */
@ApiModelProperty(value = "回复人") @ApiModelProperty(value = "回复人", required = true)
private Long replyUserId; private Long replyUserId;
} }

View File

@ -1,4 +1,4 @@
package com.mcwl.system.domain.vo; package com.mcwl.resource.domain.vo;
import com.mcwl.system.domain.enums.AdviceEnum; import com.mcwl.system.domain.enums.AdviceEnum;
import lombok.Data; import lombok.Data;
@ -22,7 +22,7 @@ public class AdviceVo {
private String content; private String content;
/** /**
* 0 1 * 0 1
*/ */
private String isRead; private String isRead;

View File

@ -0,0 +1,62 @@
package com.mcwl.resource.domain.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
@Data
@ApiModel(description = "评论回复消息")
public class CommentAdviceVo {
/**
* id
*/
@ApiModelProperty(value = "通知id")
private Long id;
/**
*
*/
@ApiModelProperty(value = "评论用户头像")
private String userAvatar;
/**
*
*/
@ApiModelProperty(value = "内容")
private String content;
/**
* id
*/
@ApiModelProperty(value = "评论的商品id")
private Long productId;
/**
*
*/
@ApiModelProperty(value = "商品图片")
private String productImag;
/**
* 0 1 2
*/
@ApiModelProperty(value = "评论的商品类型 0模型 1工作流 2图片")
private Integer productType;
/**
* 0 1
*/
@ApiModelProperty(value = "是否已读 0否 1是")
private Integer isRead;
/**
*
*/
@ApiModelProperty(value = "创建时间")
private Date createTime;
}

View File

@ -1,12 +1,9 @@
package com.mcwl.system.mapper; package com.mcwl.resource.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mcwl.system.domain.SysAdvice; import com.mcwl.resource.domain.SysAdvice;
import com.mcwl.system.domain.SysConfig;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/** /**
* *
*/ */

View File

@ -1,9 +1,9 @@
package com.mcwl.system.service; package com.mcwl.resource.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.mcwl.system.domain.SysAdvice; import com.mcwl.resource.domain.SysAdvice;
import com.mcwl.system.domain.SysConfig; import com.mcwl.resource.domain.vo.AdviceVo;
import com.mcwl.system.domain.vo.AdviceVo; import com.mcwl.resource.domain.vo.CommentAdviceVo;
import java.util.List; import java.util.List;
@ -21,4 +21,6 @@ public interface ISysAdviceService extends IService<SysAdvice> {
List<AdviceVo> getUserAllMsg(); List<AdviceVo> getUserAllMsg();
List<AdviceVo> getAllMsg(); List<AdviceVo> getAllMsg();
List<CommentAdviceVo> getCommentMsg(Integer productType);
} }

View File

@ -3,20 +3,27 @@ package com.mcwl.resource.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mcwl.common.constant.QueueConstants;
import com.mcwl.common.core.domain.entity.SysUser; import com.mcwl.common.core.domain.entity.SysUser;
import com.mcwl.common.utils.SecurityUtils; import com.mcwl.common.utils.SecurityUtils;
import com.mcwl.common.utils.StringUtils;
import com.mcwl.resource.domain.ModelComment; import com.mcwl.resource.domain.ModelComment;
import com.mcwl.resource.domain.ModelCommentLike; import com.mcwl.resource.domain.ModelCommentLike;
import com.mcwl.resource.domain.SysAdvice;
import com.mcwl.resource.domain.WorkFlowComment; import com.mcwl.resource.domain.WorkFlowComment;
import com.mcwl.resource.domain.dto.ModelCommentRes; import com.mcwl.resource.domain.dto.ModelCommentRes;
import com.mcwl.resource.domain.vo.ModelCommentVo; import com.mcwl.resource.domain.vo.ModelCommentVo;
import com.mcwl.resource.mapper.ModelCommentMapper; import com.mcwl.resource.mapper.ModelCommentMapper;
import com.mcwl.resource.mapper.ModelImageMapper; import com.mcwl.resource.mapper.ModelImageMapper;
import com.mcwl.resource.service.ISysAdviceService;
import com.mcwl.resource.service.ModelCommentLikeService; import com.mcwl.resource.service.ModelCommentLikeService;
import com.mcwl.resource.service.ModelCommentService; import com.mcwl.resource.service.ModelCommentService;
import com.mcwl.system.domain.enums.AdviceEnum;
import com.mcwl.system.service.ISysUserService; import com.mcwl.system.service.ISysUserService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
@ -37,10 +44,15 @@ public class ModelCommentServiceImpl extends ServiceImpl<ModelCommentMapper, Mod
@Autowired @Autowired
private ModelCommentLikeService modelCommentLikeService; private ModelCommentLikeService modelCommentLikeService;
@Autowired
private ISysAdviceService sysAdviceService;
@Autowired @Autowired
private ModelImageMapper modelImageMapper; private ModelImageMapper modelImageMapper;
@Override @Override
@Transactional(rollbackFor = Exception.class)
public void comment(ModelCommentRes modelCommentRes) { public void comment(ModelCommentRes modelCommentRes) {
Long parentId = modelCommentRes.getParentId(); Long parentId = modelCommentRes.getParentId();
@ -52,9 +64,42 @@ public class ModelCommentServiceImpl extends ServiceImpl<ModelCommentMapper, Mod
} }
ModelComment modelComment = new ModelComment(); ModelComment modelComment = new ModelComment();
BeanUtil.copyProperties(modelCommentRes, modelComment); BeanUtil.copyProperties(modelCommentRes, modelComment);
modelComment.setUserId(SecurityUtils.getUserId()); Long userId = SecurityUtils.getUserId();
modelComment.setUserId(userId);
modelCommentMapper.insert(modelComment); modelCommentMapper.insert(modelComment);
Long replyUserId = modelCommentRes.getReplyUserId();
if (Objects.isNull(replyUserId)) {
return;
}
ModelComment mc = modelCommentMapper.selectById(replyUserId);
if (Objects.isNull(mc)) {
return;
}
if (Objects.equals(userId, mc.getUserId())) {
return;
}
String content = StringUtils.format("{}给您的模型发了一条评论:{}",
SecurityUtils.getUsername(), modelCommentRes.getContent());
// 向通知表中插入一条记录
SysAdvice sysAdvice = new SysAdvice();
sysAdvice.setSenderId(userId);
sysAdvice.setReceiverId(mc.getUserId());
sysAdvice.setContent(content);
sysAdvice.setProductId(modelCommentRes.getModelId());
sysAdvice.setProductType(0);
sysAdvice.setIsRead(0);
sysAdvice.setType(AdviceEnum.COMMENT_REMIND);
sysAdviceService.save(sysAdvice);
} }
/** /**

View File

@ -5,18 +5,19 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mcwl.common.core.domain.entity.SysUser; import com.mcwl.common.core.domain.entity.SysUser;
import com.mcwl.common.utils.SecurityUtils; import com.mcwl.common.utils.SecurityUtils;
import com.mcwl.resource.domain.ModelComment; import com.mcwl.common.utils.StringUtils;
import com.mcwl.resource.domain.ModelImageComment; import com.mcwl.resource.domain.*;
import com.mcwl.resource.domain.ModelImageCommentLike;
import com.mcwl.resource.domain.WorkFlowComment;
import com.mcwl.resource.domain.dto.ModelImageCommentRes; import com.mcwl.resource.domain.dto.ModelImageCommentRes;
import com.mcwl.resource.domain.vo.ModelImageCommentVo; import com.mcwl.resource.domain.vo.ModelImageCommentVo;
import com.mcwl.resource.mapper.ModelImageCommentMapper; import com.mcwl.resource.mapper.ModelImageCommentMapper;
import com.mcwl.resource.service.ISysAdviceService;
import com.mcwl.resource.service.ModelImageCommentLikeService; import com.mcwl.resource.service.ModelImageCommentLikeService;
import com.mcwl.resource.service.ModelImageCommentService; import com.mcwl.resource.service.ModelImageCommentService;
import com.mcwl.system.domain.enums.AdviceEnum;
import com.mcwl.system.service.ISysUserService; import com.mcwl.system.service.ISysUserService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
@ -33,7 +34,10 @@ public class ModelImageCommentServiceImpl extends ServiceImpl<ModelImageCommentM
private final ModelImageCommentLikeService modelImageCommentLikeService; private final ModelImageCommentLikeService modelImageCommentLikeService;
private final ISysAdviceService sysAdviceService;
@Override @Override
@Transactional(rollbackFor = Exception.class)
public void comment(ModelImageCommentRes modelImageCommentRes) { public void comment(ModelImageCommentRes modelImageCommentRes) {
Long parentId = modelImageCommentRes.getParentId(); Long parentId = modelImageCommentRes.getParentId();
@ -46,9 +50,42 @@ public class ModelImageCommentServiceImpl extends ServiceImpl<ModelImageCommentM
ModelImageComment modelImageComment = new ModelImageComment(); ModelImageComment modelImageComment = new ModelImageComment();
BeanUtil.copyProperties(modelImageCommentRes, modelImageComment); BeanUtil.copyProperties(modelImageCommentRes, modelImageComment);
modelImageComment.setUserId(SecurityUtils.getUserId()); Long userId = SecurityUtils.getUserId();
modelImageComment.setUserId(userId);
baseMapper.insert(modelImageComment); baseMapper.insert(modelImageComment);
Long replyUserId = modelImageCommentRes.getReplyUserId();
if (Objects.isNull(replyUserId)) {
return;
}
ModelImageComment mic = baseMapper.selectById(replyUserId);
if (Objects.isNull(mic)) {
return;
}
if (Objects.equals(userId, mic.getUserId())) {
return;
}
String content = StringUtils.format("{}给您的图片发了一条评论:{}",
SecurityUtils.getUsername(), modelImageCommentRes.getContent());
// 向通知表中插入一条记录
SysAdvice sysAdvice = new SysAdvice();
sysAdvice.setSenderId(userId);
sysAdvice.setReceiverId(mic.getUserId());
sysAdvice.setContent(content);
sysAdvice.setProductId(modelImageCommentRes.getModelImageId());
sysAdvice.setProductType(0);
sysAdvice.setIsRead(0);
sysAdvice.setType(AdviceEnum.COMMENT_REMIND);
sysAdviceService.save(sysAdvice);
} }
/** /**

View File

@ -1,6 +1,7 @@
package com.mcwl.resource.service.impl; package com.mcwl.resource.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem; import com.baomidou.mybatisplus.core.metadata.OrderItem;
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;
@ -26,10 +27,7 @@ import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.*;
import java.util.Date;
import java.util.List;
import java.util.Objects;
/** /**
* *
@ -162,14 +160,23 @@ public class ModelImageLikeServiceImpl extends ServiceImpl<ModelImageLikeMapper,
pageHelper.startPage(pageVo.getPageNumber(),pageVo.getPageSize()); pageHelper.startPage(pageVo.getPageNumber(),pageVo.getPageSize());
List<ResponseModelImage> responseModelImageList = modelImageMapper.imageList(pageVo); List<ResponseModelImage> responseModelImageList = modelImageMapper.imageList(pageVo);
List<Long> modelImageLikeIds = new ArrayList<>();
List<ModelImageLike> modelImageLikes = baseMapper.selectList(new LambdaQueryWrapper<ModelImageLike>()
.eq(ModelImageLike::getUserId, SecurityUtils.getUserId()));
for (ModelImageLike modelImageLike : modelImageLikes) {
modelImageLikeIds.add(modelImageLike.getModelImageId());
}
for (ResponseModelImage responseModelImage : responseModelImageList) { for (ResponseModelImage responseModelImage : responseModelImageList) {
String[] split = responseModelImage.getImagePaths().split(","); String[] split = responseModelImage.getImagePaths().split(",");
responseModelImage.setPath(split[0]); responseModelImage.setPath(split[0]);
//查询模型是否点赞 //查询是否点赞
ModelImageLike likeImage = baseMapper.getLikeImage(SecurityUtils.getUserId(), responseModelImage.getId()); if (!modelImageLikeIds.contains(responseModelImage.getId())){
if (likeImage == null){
responseModelImage.setIsLike(0); responseModelImage.setIsLike(0);
}else { }else {
responseModelImage.setIsLike(1); responseModelImage.setIsLike(1);

View File

@ -0,0 +1,164 @@
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.service.impl.ServiceImpl;
import com.mcwl.common.core.domain.entity.SysUser;
import com.mcwl.common.utils.SecurityUtils;
import com.mcwl.resource.domain.ModelImage;
import com.mcwl.resource.domain.ModelProduct;
import com.mcwl.resource.domain.WorkFlow;
import com.mcwl.resource.service.ModelImageService;
import com.mcwl.resource.service.ModelService;
import com.mcwl.resource.service.WorkFlowService;
import com.mcwl.resource.domain.SysAdvice;
import com.mcwl.system.domain.enums.AdviceEnum;
import com.mcwl.resource.domain.vo.AdviceVo;
import com.mcwl.resource.domain.vo.CommentAdviceVo;
import com.mcwl.resource.mapper.SysAdviceMapper;
import com.mcwl.resource.service.ISysAdviceService;
import com.mcwl.system.service.ISysUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
/**
*
*/
@Service
@RequiredArgsConstructor
public class SysAdviceServiceImpl extends ServiceImpl<SysAdviceMapper, SysAdvice> implements ISysAdviceService {
private final ISysUserService sysUserService;
private final ModelService modelService;
private final WorkFlowService workFlowService;
private final ModelImageService modelImageService;
private final Map<Long, ModelProduct> modelProductMap = new ConcurrentHashMap<>();
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);
return BeanUtil.copyToList(sysAdvices, AdviceVo.class);
}
@Override
public List<CommentAdviceVo> getCommentMsg(Integer productType) {
this.postConstruct();
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));
List<CommentAdviceVo> commentAdviceVoList = new ArrayList<>();
for (SysAdvice sysAdvice : sysAdviceList) {
CommentAdviceVo commentAdviceVo = BeanUtil.copyProperties(sysAdvice, CommentAdviceVo.class);
Long senderId = sysAdvice.getSenderId();
SysUser senderUser = sysUserService.selectUserById(senderId);
commentAdviceVo.setUserAvatar(senderUser.getAvatar());
if (productType == 0) {
ModelProduct modelProduct = modelProductMap.get(sysAdvice.getProductId());
if (Objects.nonNull(modelProduct)) {
commentAdviceVo.setProductImag(modelProduct.getSurfaceUrl());
}
} else if (productType == 1) {
WorkFlow workFlow = workFlowMap.get(sysAdvice.getProductId());
if (Objects.nonNull(workFlow)) {
commentAdviceVo.setProductImag(workFlow.getCoverPath());
}
} else if (productType == 2) {
ModelImage modelImage = modelImageMap.get(sysAdvice.getProductId());
if (Objects.nonNull(modelImage)) {
commentAdviceVo.setProductImag(modelImage.getImagePaths().split(",")[0]);
}
}
commentAdviceVoList.add(commentAdviceVo);
}
return commentAdviceVoList;
}
public void postConstruct() {
Long userId = SecurityUtils.getUserId();
// 并行加载数据
CompletableFuture<List<ModelProduct>> productsFuture = CompletableFuture.supplyAsync(() ->
modelService.lambdaQuery().eq(ModelProduct::getUserId, userId).list()
);
CompletableFuture<List<WorkFlow>> workflowsFuture = CompletableFuture.supplyAsync(() ->
workFlowService.lambdaQuery().eq(WorkFlow::getUserId, userId).list()
);
CompletableFuture<List<ModelImage>> imagesFuture = CompletableFuture.supplyAsync(() ->
modelImageService.lambdaQuery().eq(ModelImage::getUserId, userId).list()
);
// 等待所有任务完成
CompletableFuture.allOf(productsFuture, workflowsFuture, imagesFuture).join();
// 更新缓存
modelProductMap.clear();
productsFuture.join().forEach(p -> modelProductMap.put(p.getId(), p));
workFlowMap.clear();
workflowsFuture.join().forEach(w -> workFlowMap.put(w.getId(), w));
modelImageMap.clear();
imagesFuture.join().forEach(i -> modelImageMap.put(i.getId(), i));
}
}

View File

@ -5,13 +5,18 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mcwl.common.core.domain.entity.SysUser; import com.mcwl.common.core.domain.entity.SysUser;
import com.mcwl.common.utils.SecurityUtils; import com.mcwl.common.utils.SecurityUtils;
import com.mcwl.common.utils.StringUtils;
import com.mcwl.resource.domain.ModelImageComment;
import com.mcwl.resource.domain.SysAdvice;
import com.mcwl.resource.domain.WorkFlowComment; import com.mcwl.resource.domain.WorkFlowComment;
import com.mcwl.resource.domain.WorkFlowCommentLike; import com.mcwl.resource.domain.WorkFlowCommentLike;
import com.mcwl.resource.domain.dto.WorkFlowCommentRes; import com.mcwl.resource.domain.dto.WorkFlowCommentRes;
import com.mcwl.resource.domain.vo.WorkFlowCommentVo; import com.mcwl.resource.domain.vo.WorkFlowCommentVo;
import com.mcwl.resource.mapper.WorkFlowCommentMapper; import com.mcwl.resource.mapper.WorkFlowCommentMapper;
import com.mcwl.resource.service.ISysAdviceService;
import com.mcwl.resource.service.WorkFlowCommentLikeService; import com.mcwl.resource.service.WorkFlowCommentLikeService;
import com.mcwl.resource.service.WorkFlowCommentService; import com.mcwl.resource.service.WorkFlowCommentService;
import com.mcwl.system.domain.enums.AdviceEnum;
import com.mcwl.system.service.ISysUserService; import com.mcwl.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -43,6 +48,10 @@ public class WorkFlowCommentServiceImpl extends ServiceImpl<WorkFlowCommentMappe
private WorkFlowCommentLikeService workFlowCommentLikeService; private WorkFlowCommentLikeService workFlowCommentLikeService;
@Autowired
private ISysAdviceService sysAdviceService;
@Override @Override
public void comment(WorkFlowCommentRes workFlowCommentRes) { public void comment(WorkFlowCommentRes workFlowCommentRes) {
Long parentId = workFlowCommentRes.getParentId(); Long parentId = workFlowCommentRes.getParentId();
@ -55,9 +64,43 @@ public class WorkFlowCommentServiceImpl extends ServiceImpl<WorkFlowCommentMappe
} }
WorkFlowComment workFlowComment = new WorkFlowComment(); WorkFlowComment workFlowComment = new WorkFlowComment();
BeanUtil.copyProperties(workFlowCommentRes, workFlowComment); BeanUtil.copyProperties(workFlowCommentRes, workFlowComment);
workFlowComment.setUserId(SecurityUtils.getUserId()); Long userId = SecurityUtils.getUserId();
workFlowComment.setUserId(userId);
workFlowCommentMapper.insert(workFlowComment); workFlowCommentMapper.insert(workFlowComment);
Long replyUserId = workFlowCommentRes.getReplyUserId();
if (Objects.isNull(replyUserId)) {
return;
}
WorkFlowComment wfc = workFlowCommentMapper.selectById(replyUserId);
if (Objects.isNull(wfc)) {
return;
}
if (Objects.equals(userId, wfc.getUserId())) {
return;
}
String content = StringUtils.format("{}给您的图片发了一条评论:{}",
SecurityUtils.getUsername(), workFlowCommentRes.getContent());
// 向通知表中插入一条记录
SysAdvice sysAdvice = new SysAdvice();
sysAdvice.setSenderId(userId);
sysAdvice.setReceiverId(wfc.getUserId());
sysAdvice.setContent(content);
sysAdvice.setProductId(workFlowCommentRes.getWorkFlowId());
sysAdvice.setProductType(0);
sysAdvice.setIsRead(0);
sysAdvice.setType(AdviceEnum.COMMENT_REMIND);
sysAdviceService.save(sysAdvice);
} }
@Override @Override

View File

@ -32,7 +32,7 @@
<update id="updateDelFlagById"> <update id="updateDelFlagById">
update model_image_like update model_image_like
set del_flag = #{delFlag} set del_flag = #{delFlag}
where user_id = #{userId} and model_image_id = #{imageId} where user_id = #{userId} and model_image_id = #{modelImageId}
</update> </update>
<select id="getLikeImage" resultMap="ModelImageLikeResult"> <select id="getLikeImage" resultMap="ModelImageLikeResult">

View File

@ -12,42 +12,46 @@ import lombok.Getter;
public enum AdviceEnum { public enum AdviceEnum {
/** /**
* *
*/ */
NEW_MESSAGE_REMIND("newMessageRemind", "新消息提醒"), NEW_MESSAGE_REMIND("newMessageRemind", "新消息通知"),
/** /**
* *
*/ */
SYSTEM_NOTICE("systemNotice", "系统公告"), SYSTEM_NOTICE("systemNotice", "系统通知"),
/** /**
* *
*/ */
EMAIL_REMIND("emailRemind", "邮件提醒"), EMAIL_REMIND("emailRemind", "邮件通知"),
/** /**
* *
*/ */
SMS_REMIND("smsRemind", "短信提醒"), SMS_REMIND("smsRemind", "短信通知"),
/** /**
* *
*/ */
PUSH_REMIND("pushRemind", "推送提醒"), PUSH_REMIND("pushRemind", "推送通知"),
/** /**
* *
*/ */
LIKE_REMIND("likeRemind", "点赞提醒"), LIKE_REMIND("likeRemind", "点赞通知"),
/** /**
* *
*/ */
COMMENT_REMIND("commentRemind", "评论提醒"), COMMENT_REMIND("commentRemind", "评论回复通知"),
/** /**
* *
*/ */
PRIVATE_MESSAGE_REMIND("privateMessageRemind", "私信提醒"); FANS_REMIND("fansRemind", "粉丝通知"),
/**
*
*/
PRIVATE_MESSAGE_REMIND("privateMessageRemind", "私信通知");
private final String name; private final String name;

View File

@ -1,70 +0,0 @@
package com.mcwl.system.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mcwl.common.utils.SecurityUtils;
import com.mcwl.system.domain.SysAdvice;
import com.mcwl.system.domain.SysUserThirdAccount;
import com.mcwl.system.domain.enums.AdviceEnum;
import com.mcwl.system.domain.vo.AdviceVo;
import com.mcwl.system.mapper.SysAdviceMapper;
import com.mcwl.system.service.ISysAdviceService;
import com.mcwl.system.service.IWXService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;
/**
*
*/
@Service
public class SysAdviceServiceImpl extends ServiceImpl<SysAdviceMapper, SysAdvice> implements ISysAdviceService {
@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);
return BeanUtil.copyToList(sysAdvices, AdviceVo.class);
}
}