From f41ab7b89972b8ffe1c9826a70ec726702306c4f Mon Sep 17 00:00:00 2001 From: Diyu0904 <1819728964@qq.com> Date: Wed, 15 Jan 2025 15:21:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=82=B9=E8=B5=9E/=E5=8F=96?= =?UTF-8?q?=E6=B6=88=E5=B7=A5=E4=BD=9C=E6=B5=81=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=8F=91=E5=B8=83=E5=B7=A5=E4=BD=9C=E6=B5=81=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=20=E6=96=B0=E5=A2=9E=E7=82=B9=E8=B5=9E/=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E6=B5=81=E8=AF=84=E8=AE=BA=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=88=A0=E9=99=A4=E5=B7=A5=E4=BD=9C=E6=B5=81=E8=AF=84?= =?UTF-8?q?=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resource/WorkFlowCommentController.java | 87 +++++++++++ .../mcwl/resource/domain/WorkFlowComment.java | 47 ++++++ .../resource/domain/WorkFlowCommentLike.java | 33 +++++ .../mcwl/resource/domain/WorkFlowLike.java | 33 +++++ .../resource/domain/vo/WorkFlowCommentVo.java | 66 +++++++++ .../mapper/WorkFlowCommentLikeMapper.java | 20 +++ .../mapper/WorkFlowCommentMapper.java | 17 +++ .../resource/mapper/WorkFlowLikeMapper.java | 20 +++ .../service/WorkFlowCommentLikeService.java | 18 +++ .../service/WorkFlowCommentService.java | 28 ++++ .../resource/service/WorkFlowLikeService.java | 20 +++ .../impl/WorkFlowCommentLikeServiceImpl.java | 70 +++++++++ .../impl/WorkFlowCommentServiceImpl.java | 140 ++++++++++++++++++ .../service/impl/WorkFlowLikeServiceImpl.java | 72 +++++++++ .../resource/WorkFlowCommentLikeMapper.xml | 21 +++ .../mapper/resource/WorkFlowLikeMapper.xml | 21 +++ .../service/impl/SysUserServiceImpl.java | 1 + 17 files changed, 714 insertions(+) create mode 100644 mcwl-admin/src/main/java/com/mcwl/web/controller/resource/WorkFlowCommentController.java create mode 100644 mcwl-resource/src/main/java/com/mcwl/resource/domain/WorkFlowComment.java create mode 100644 mcwl-resource/src/main/java/com/mcwl/resource/domain/WorkFlowCommentLike.java create mode 100644 mcwl-resource/src/main/java/com/mcwl/resource/domain/WorkFlowLike.java create mode 100644 mcwl-resource/src/main/java/com/mcwl/resource/domain/vo/WorkFlowCommentVo.java create mode 100644 mcwl-resource/src/main/java/com/mcwl/resource/mapper/WorkFlowCommentLikeMapper.java create mode 100644 mcwl-resource/src/main/java/com/mcwl/resource/mapper/WorkFlowCommentMapper.java create mode 100644 mcwl-resource/src/main/java/com/mcwl/resource/mapper/WorkFlowLikeMapper.java create mode 100644 mcwl-resource/src/main/java/com/mcwl/resource/service/WorkFlowCommentLikeService.java create mode 100644 mcwl-resource/src/main/java/com/mcwl/resource/service/WorkFlowCommentService.java create mode 100644 mcwl-resource/src/main/java/com/mcwl/resource/service/WorkFlowLikeService.java create mode 100644 mcwl-resource/src/main/java/com/mcwl/resource/service/impl/WorkFlowCommentLikeServiceImpl.java create mode 100644 mcwl-resource/src/main/java/com/mcwl/resource/service/impl/WorkFlowCommentServiceImpl.java create mode 100644 mcwl-resource/src/main/java/com/mcwl/resource/service/impl/WorkFlowLikeServiceImpl.java create mode 100644 mcwl-resource/src/main/resources/mapper/resource/WorkFlowCommentLikeMapper.xml create mode 100644 mcwl-resource/src/main/resources/mapper/resource/WorkFlowLikeMapper.xml diff --git a/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/WorkFlowCommentController.java b/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/WorkFlowCommentController.java new file mode 100644 index 0000000..b6e450a --- /dev/null +++ b/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/WorkFlowCommentController.java @@ -0,0 +1,87 @@ +package com.mcwl.web.controller.resource; + +import com.mcwl.common.core.domain.AjaxResult; +import com.mcwl.resource.domain.WorkFlowComment; +import com.mcwl.resource.domain.vo.WorkFlowCommentVo; +import com.mcwl.resource.service.WorkFlowCommentLikeService; +import com.mcwl.resource.service.WorkFlowCommentService; +import com.mcwl.resource.service.WorkFlowLikeService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.validation.constraints.NotNull; +import java.util.List; + +/** + * 工作流评论 + * @Author:ChenYan + * @Project:McWl + * @Package:com.mcwl.web.controller.resource + * @Filename:ModelCommentcontroller + * @Description TODO + * @Date:2025/1/12 11:36 + */ +@RequestMapping("/WorkFlowComment") +@RestController +public class WorkFlowCommentController { + + @Autowired + private WorkFlowLikeService workFlowLikeService; + @Autowired + private WorkFlowCommentService workFlowCommentService; + @Autowired + private WorkFlowCommentLikeService workFlowCommentLikeService; + + + + /** + * 工作流点赞/取消 + */ + @GetMapping("/like/{workFlowId}") + public AjaxResult like(@PathVariable Long workFlowId) { + workFlowLikeService.like(workFlowId); + return AjaxResult.success(); + } + + + /** + * 工作流评论发布 + */ + @PostMapping("/comment") + public AjaxResult comment(@RequestBody WorkFlowComment modelComment) { + workFlowCommentService.comment(modelComment); + return AjaxResult.success(); + } + + /** + * 工作流评论点赞/取消 + */ + @GetMapping("/commentLike/{commentId}") + public AjaxResult commentLike(@PathVariable Long commentId) { + workFlowCommentLikeService.like(commentId); + return AjaxResult.error(); + } + + + + /** + * 获取工作流评论 + */ + @GetMapping("/comment/{modelId}") + public AjaxResult getComment(@PathVariable @NotNull(message = "模型id不能为空") Long modelId) { + List modelCommentList = workFlowCommentService.getComment(modelId); + return AjaxResult.success(modelCommentList); + } + + + /** + * 删除工作流评论 + */ + @GetMapping("/commentDelete/{commentId}") + public AjaxResult commentDelete(@PathVariable @NotNull(message = "评论id不能为空") Long commentId) { + workFlowCommentService.removeById(commentId); + return AjaxResult.success(); + } + + +} diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/domain/WorkFlowComment.java b/mcwl-resource/src/main/java/com/mcwl/resource/domain/WorkFlowComment.java new file mode 100644 index 0000000..6a897a8 --- /dev/null +++ b/mcwl-resource/src/main/java/com/mcwl/resource/domain/WorkFlowComment.java @@ -0,0 +1,47 @@ +package com.mcwl.resource.domain; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.mcwl.common.core.domain.BaseEntity; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 工作流评论 + */ +@AllArgsConstructor +@NoArgsConstructor +@Data +@TableName("work_flow_comment") +public class WorkFlowComment extends BaseEntity { + + @TableId + private Long id; + + /** + * 用户id + */ + private Long userId; + + /** + * 工作流id + */ + private Long workFlowId; + + /** + * 评论内容 + */ + private String content; + + /** + * 父评论id + */ + private Long parentId; + + /** + * 点赞数 + */ + private Integer likeNum; + +} diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/domain/WorkFlowCommentLike.java b/mcwl-resource/src/main/java/com/mcwl/resource/domain/WorkFlowCommentLike.java new file mode 100644 index 0000000..9217934 --- /dev/null +++ b/mcwl-resource/src/main/java/com/mcwl/resource/domain/WorkFlowCommentLike.java @@ -0,0 +1,33 @@ +package com.mcwl.resource.domain; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.mcwl.common.core.domain.BaseEntity; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 工作流评论点赞 + */ +@AllArgsConstructor +@NoArgsConstructor +@Data +@TableName("work_flow_comment_like") +public class WorkFlowCommentLike extends BaseEntity { + + @TableId + private Long id; + + /** + * 用户id + */ + private Long userId; + + /** + * 工作流评论id + */ + private Long workFlowCommentId; + + +} diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/domain/WorkFlowLike.java b/mcwl-resource/src/main/java/com/mcwl/resource/domain/WorkFlowLike.java new file mode 100644 index 0000000..236d4c4 --- /dev/null +++ b/mcwl-resource/src/main/java/com/mcwl/resource/domain/WorkFlowLike.java @@ -0,0 +1,33 @@ +package com.mcwl.resource.domain; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.mcwl.common.core.domain.BaseEntity; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 模型点赞表 + */ + +@AllArgsConstructor +@NoArgsConstructor +@Data +@TableName("work_flow_like") +public class WorkFlowLike extends BaseEntity { + + @TableId + private Long id; + + /** + * 用户id + */ + private Long userId; + + /** + * 模型id + */ + private Long workFlowId; + +} diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/domain/vo/WorkFlowCommentVo.java b/mcwl-resource/src/main/java/com/mcwl/resource/domain/vo/WorkFlowCommentVo.java new file mode 100644 index 0000000..faaf811 --- /dev/null +++ b/mcwl-resource/src/main/java/com/mcwl/resource/domain/vo/WorkFlowCommentVo.java @@ -0,0 +1,66 @@ +package com.mcwl.resource.domain.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * 工作流评论区评论 + */ + +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Data +public class WorkFlowCommentVo { + + /** + * 用户id + */ + private Long userId; + + /** + * 用户名 + */ + private String userName; + + /** + * 用户头像 + */ + private String userAvatar; + + /** + * 评论id + */ + private Long commentId; + + /** + * 评论内容 + */ + private String content; + + /** + * 子评论 + */ + private List contentList = new ArrayList<>(); + + /** + * 评论点赞数 + */ + private Integer likeNum; + + /** + * 评论时间 + */ + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date createTime; + +} diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/mapper/WorkFlowCommentLikeMapper.java b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/WorkFlowCommentLikeMapper.java new file mode 100644 index 0000000..29f06fb --- /dev/null +++ b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/WorkFlowCommentLikeMapper.java @@ -0,0 +1,20 @@ +package com.mcwl.resource.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.mcwl.resource.domain.WorkFlowCommentLike; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + * @Author:ChenYan + * @Project:McWl + * @Package:com.mcwl.resource.mapper + * @Filename:ModelCommentLikeMapper + * @Description TODO + * @Date:2025/1/12 12:02 + */ +@Mapper +public interface WorkFlowCommentLikeMapper extends BaseMapper { + WorkFlowCommentLike getLikeComment(@Param("userId") Long userId, @Param("commentId") Long commentId); + +} diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/mapper/WorkFlowCommentMapper.java b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/WorkFlowCommentMapper.java new file mode 100644 index 0000000..22d8c88 --- /dev/null +++ b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/WorkFlowCommentMapper.java @@ -0,0 +1,17 @@ +package com.mcwl.resource.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.mcwl.resource.domain.WorkFlowComment; +import org.apache.ibatis.annotations.Mapper; + +/** + * @Author:ChenYan + * @Project:McWl + * @Package:com.mcwl.resource.mapper + * @Filename:ModelCommentMapper + * @Description TODO + * @Date:2025/1/12 12:04 + */ +@Mapper +public interface WorkFlowCommentMapper extends BaseMapper { +} diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/mapper/WorkFlowLikeMapper.java b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/WorkFlowLikeMapper.java new file mode 100644 index 0000000..2664d26 --- /dev/null +++ b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/WorkFlowLikeMapper.java @@ -0,0 +1,20 @@ +package com.mcwl.resource.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.mcwl.resource.domain.WorkFlowLike; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + * @Author:ChenYan + * @Project:McWl + * @Package:com.mcwl.resource.mapper + * @Filename:ModelLikeMapper + * @Description TODO + * @Date:2025/1/12 12:05 + */ +@Mapper +public interface WorkFlowLikeMapper extends BaseMapper { + WorkFlowLike getLike(@Param("userId") Long userId, @Param("modelId") Long modelId); + +} diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/WorkFlowCommentLikeService.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/WorkFlowCommentLikeService.java new file mode 100644 index 0000000..aac543f --- /dev/null +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/WorkFlowCommentLikeService.java @@ -0,0 +1,18 @@ +package com.mcwl.resource.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.mcwl.resource.domain.WorkFlowCommentLike; + +/** + * 工作流评论点赞 + * @Author:ChenYan + * @Project:McWl + * @Package:com.mcwl.resource.service + * @Filename:ModelCommentLikeService + * @Description TODO + * @Date:2025/1/12 11:58 + */ +public interface WorkFlowCommentLikeService extends IService { + void like(Long commentId); + +} diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/WorkFlowCommentService.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/WorkFlowCommentService.java new file mode 100644 index 0000000..867005c --- /dev/null +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/WorkFlowCommentService.java @@ -0,0 +1,28 @@ +package com.mcwl.resource.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.mcwl.resource.domain.WorkFlowComment; +import com.mcwl.resource.domain.vo.WorkFlowCommentVo; + +import java.util.List; + +/** + * 工作流评论 业务层 + * @Author:ChenYan + * @Project:McWl + * @Package:com.mcwl.resource.service + * @Filename:ModelCommentService + * @Description TODO + * @Date:2025/1/12 11:58 + */ +public interface WorkFlowCommentService extends IService { + void comment(WorkFlowComment modelComment); + + /** + * 获取评论 + * @param imageId 图片id + * @return 评论区 + */ + List getComment(Long imageId); + +} diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/WorkFlowLikeService.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/WorkFlowLikeService.java new file mode 100644 index 0000000..e1ac8e7 --- /dev/null +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/WorkFlowLikeService.java @@ -0,0 +1,20 @@ +package com.mcwl.resource.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.mcwl.resource.domain.WorkFlowLike; + +/** + * 工作流点赞 业务层 + * @Author:ChenYan + * @Project:McWl + * @Package:com.mcwl.resource.service + * @Filename:ModelLikeService + * @Description TODO + * @Date:2025/1/12 11:57 + */ +public interface WorkFlowLikeService extends IService { + + + void like(Long imageId); + +} diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/WorkFlowCommentLikeServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/WorkFlowCommentLikeServiceImpl.java new file mode 100644 index 0000000..24561db --- /dev/null +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/WorkFlowCommentLikeServiceImpl.java @@ -0,0 +1,70 @@ +package com.mcwl.resource.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.mcwl.common.exception.ServiceException; +import com.mcwl.common.utils.SecurityUtils; +import com.mcwl.resource.domain.WorkFlowComment; +import com.mcwl.resource.domain.WorkFlowCommentLike; +import com.mcwl.resource.mapper.WorkFlowCommentLikeMapper; +import com.mcwl.resource.mapper.WorkFlowCommentMapper; +import com.mcwl.resource.service.WorkFlowCommentLikeService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Date; +import java.util.Objects; + +/** + * @Author:ChenYan + * @Project:McWl + * @Package:com.mcwl.resource.service.impl + * @Filename:ModelCommentLikeServiceImpl + * @Description TODO + * @Date:2025/1/12 12:01 + */ +@Service +public class WorkFlowCommentLikeServiceImpl extends ServiceImpl implements WorkFlowCommentLikeService { + + @Autowired + private WorkFlowCommentMapper workFlowCommentMapper; + + @Override + @Transactional + public void like(Long commentId) { + WorkFlowComment workFlowComment = workFlowCommentMapper.selectById(commentId); + if (Objects.isNull(workFlowComment)) { + throw new ServiceException("该评论不存在"); + } + Long userId = SecurityUtils.getUserId(); + WorkFlowCommentLike workFlowCommentLike = baseMapper.getLikeComment(userId, commentId); + if (Objects.nonNull(workFlowCommentLike)) { + if (Objects.equals(workFlowComment.getDelFlag(), "0")) { + workFlowCommentLike.setDelFlag("1"); + workFlowComment.setLikeNum(workFlowComment.getLikeNum() - 1); + } else { + workFlowCommentLike.setDelFlag("0"); + workFlowComment.setLikeNum(workFlowComment.getLikeNum() + 1); + } + // 更新点赞记录 + baseMapper.updateById(workFlowCommentLike); + // 更新图片评论点赞数 + workFlowCommentMapper.updateById(workFlowComment); + return; + } + + // 添加点赞记录 + workFlowCommentLike = new WorkFlowCommentLike(); + workFlowCommentLike.setUserId(userId); + workFlowCommentLike.setWorkFlowCommentId(commentId); + workFlowCommentLike.setCreateBy(SecurityUtils.getUsername()); + workFlowCommentLike.setUpdateBy(SecurityUtils.getUsername()); + workFlowCommentLike.setUpdateTime(new Date()); + baseMapper.insert(workFlowCommentLike); + + // 更新模型点赞数 + workFlowComment.setLikeNum(workFlowComment.getLikeNum() + 1); + workFlowCommentMapper.updateById(workFlowComment); + } + +} diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/WorkFlowCommentServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/WorkFlowCommentServiceImpl.java new file mode 100644 index 0000000..efc85c7 --- /dev/null +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/WorkFlowCommentServiceImpl.java @@ -0,0 +1,140 @@ +package com.mcwl.resource.service.impl; + +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.WorkFlowComment; +import com.mcwl.resource.domain.vo.WorkFlowCommentVo; +import com.mcwl.resource.mapper.WorkFlowCommentMapper; +import com.mcwl.resource.service.WorkFlowCommentService; +import com.mcwl.system.service.ISysUserService; +import org.jetbrains.annotations.NotNull; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Objects; + +/** + * 工作流评论 实现层 + * @Author:ChenYan + * @Project:McWl + * @Package:com.mcwl.resource.service.impl + * @Filename:ModelCommentServiceImpl + * @Description TODO + * @Date:2025/1/12 12:03 + */ +@Service +public class WorkFlowCommentServiceImpl extends ServiceImpl implements WorkFlowCommentService { + + @Autowired + private ISysUserService sysUserService; + + @Autowired + private WorkFlowCommentMapper workFlowCommentMapper; + + + @Override + public void comment(WorkFlowComment workFlowComment) { + Long parentId = workFlowComment.getParentId(); + WorkFlowComment mic = workFlowCommentMapper.selectById(parentId); + + if (Objects.nonNull(parentId) && Objects.isNull(mic)) { + return; + } + workFlowComment.setUserId(SecurityUtils.getUserId()); + workFlowComment.setCreateBy(SecurityUtils.getUsername()); + workFlowComment.setUpdateBy(SecurityUtils.getUsername()); + workFlowComment.setUpdateTime(new Date()); + workFlowCommentMapper.insert(workFlowComment); + + } + + @Override + public List getComment(Long imageId) { + List workFlowCommentVos = new ArrayList<>(); + + // 查询所有父评论 + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.eq(WorkFlowComment::getWorkFlowId, imageId) + .isNull(WorkFlowComment::getParentId) + .orderByDesc(WorkFlowComment::getCreateTime); + // 添加父评论 + List workFlowComments = workFlowCommentMapper.selectList(lqw); + for (WorkFlowComment workFlowComment : workFlowComments) { + WorkFlowCommentVo workFlowCommentVo = getModelCommentVo(workFlowComment); + workFlowCommentVos.add(workFlowCommentVo); + } + + return workFlowCommentVos; + } + + + /** + * 构建ModelCommentVo对象 + * + * @param workFlowComment 父评论对象 + * @return WorkFlowCommentVo + */ + @NotNull + private WorkFlowCommentVo getModelCommentVo(WorkFlowComment workFlowComment) { + Long userId = workFlowComment.getUserId(); + SysUser sysUser = sysUserService.selectUserById(userId); + + // 构建WorkFlowCommentVo对象 + WorkFlowCommentVo workFlowCommentVo = new WorkFlowCommentVo(); + workFlowCommentVo.setUserId(userId); + workFlowCommentVo.setUserName(sysUser.getUserName()); + workFlowCommentVo.setUserAvatar(sysUser.getAvatar()); + workFlowCommentVo.setCommentId(workFlowComment.getId()); + workFlowCommentVo.setContent(workFlowComment.getContent()); + // 查询子评论 + workFlowCommentVo.setContentList(getContentList(workFlowComment.getId())); + workFlowCommentVo.setLikeNum(workFlowComment.getLikeNum()); + workFlowCommentVo.setCreateTime(workFlowComment.getCreateTime()); + return workFlowCommentVo; + } + + + /** + * 递归查询子评论 + * + * @param modelCommentId 父评论id + * @return List + */ + private List getContentList(Long modelCommentId) { + List modelCommentVoList = new ArrayList<>(); + if (Objects.isNull(modelCommentId)) { + return modelCommentVoList; + } + + // 查询子评论 + LambdaQueryWrapper lqw = new LambdaQueryWrapper() + .eq(WorkFlowComment::getParentId, modelCommentId) + .orderByDesc(WorkFlowComment::getCreateTime); + + List modelCommentList = workFlowCommentMapper.selectList(lqw); + + for (WorkFlowComment modelComment : modelCommentList) { + Long userId = modelComment.getUserId(); + SysUser sysUser = sysUserService.selectUserById(userId); + WorkFlowCommentVo modelCommentVo = new WorkFlowCommentVo(); + modelCommentVo.setUserId(userId); + modelCommentVo.setUserName(sysUser.getUserName()); + modelCommentVo.setUserAvatar(sysUser.getAvatar()); + modelCommentVo.setCommentId(modelComment.getId()); + modelCommentVo.setContent(modelComment.getContent()); + modelCommentVo.setLikeNum(modelComment.getLikeNum()); + modelCommentVo.setCreateTime(modelComment.getCreateTime()); + + + modelCommentVoList.add(modelCommentVo); + } + return modelCommentVoList; + } + + +} diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/WorkFlowLikeServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/WorkFlowLikeServiceImpl.java new file mode 100644 index 0000000..f42355c --- /dev/null +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/WorkFlowLikeServiceImpl.java @@ -0,0 +1,72 @@ +package com.mcwl.resource.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.mcwl.common.exception.ServiceException; +import com.mcwl.common.utils.SecurityUtils; +import com.mcwl.resource.domain.WorkFlow; +import com.mcwl.resource.domain.WorkFlowLike; +import com.mcwl.resource.mapper.WorkFlowLikeMapper; +import com.mcwl.resource.mapper.WorkFlowMapper; +import com.mcwl.resource.service.WorkFlowLikeService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Date; +import java.util.Objects; + +/** + * 工作流点赞 + * @Author:ChenYan + * @Project:McWl + * @Package:com.mcwl.resource.service.impl + * @Filename:ModelLikeServiceImpl + * @Description TODO + * @Date:2025/1/12 12:05 + */ +@Service +public class WorkFlowLikeServiceImpl extends ServiceImpl implements WorkFlowLikeService { + + + @Autowired + private WorkFlowMapper workFlowMapper; + + @Override + @Transactional + public void like(Long modelId) { + WorkFlow workFlow = workFlowMapper.selectById(modelId); + if (Objects.isNull(workFlow)) { + throw new ServiceException("该工作流不存在或已下架"); + } + Long userId = SecurityUtils.getUserId(); + WorkFlowLike workFlowLike = baseMapper.getLike(userId, modelId); + if (Objects.nonNull(workFlowLike)) { + if (Objects.equals(workFlowLike.getDelFlag(), "0")) { + workFlowLike.setDelFlag("1"); + workFlow.setLikeCount(workFlow.getLikeCount() - 1); + } else { + workFlowLike.setDelFlag("0"); + workFlow.setLikeCount(workFlow.getLikeCount() + 1); + } + // 更新点赞记录 + baseMapper.updateById(workFlowLike); + // 更新图片点赞数 + workFlowMapper.updateById(workFlow); + return; + } + + // 添加点赞记录 + workFlowLike = new WorkFlowLike(); + workFlowLike.setUserId(userId); + workFlowLike.setWorkFlowId(modelId); + workFlowLike.setCreateBy(SecurityUtils.getUsername()); + workFlowLike.setUpdateBy(SecurityUtils.getUsername()); + workFlowLike.setUpdateTime(new Date()); + baseMapper.insert(workFlowLike); + + // 更新图片点赞数 + workFlow.setLikeCount(workFlow.getLikeCount() + 1); + workFlowMapper.updateById(workFlow); + } + +} diff --git a/mcwl-resource/src/main/resources/mapper/resource/WorkFlowCommentLikeMapper.xml b/mcwl-resource/src/main/resources/mapper/resource/WorkFlowCommentLikeMapper.xml new file mode 100644 index 0000000..a3bc305 --- /dev/null +++ b/mcwl-resource/src/main/resources/mapper/resource/WorkFlowCommentLikeMapper.xml @@ -0,0 +1,21 @@ + + + + + + + diff --git a/mcwl-resource/src/main/resources/mapper/resource/WorkFlowLikeMapper.xml b/mcwl-resource/src/main/resources/mapper/resource/WorkFlowLikeMapper.xml new file mode 100644 index 0000000..c8d918b --- /dev/null +++ b/mcwl-resource/src/main/resources/mapper/resource/WorkFlowLikeMapper.xml @@ -0,0 +1,21 @@ + + + + + + + diff --git a/mcwl-system/src/main/java/com/mcwl/system/service/impl/SysUserServiceImpl.java b/mcwl-system/src/main/java/com/mcwl/system/service/impl/SysUserServiceImpl.java index be8aaf2..35629da 100644 --- a/mcwl-system/src/main/java/com/mcwl/system/service/impl/SysUserServiceImpl.java +++ b/mcwl-system/src/main/java/com/mcwl/system/service/impl/SysUserServiceImpl.java @@ -100,6 +100,7 @@ public class SysUserServiceImpl implements ISysUserService /** * 根据条件分页查询已分配用户角色列表 * + * * @param user 用户信息 * @return 用户信息集合信息 */