Merge branch 'feature/admin' into preview

feature/resource
Diyu0904 2025-01-15 15:23:03 +08:00
commit 5f6844dc29
17 changed files with 714 additions and 0 deletions

View File

@ -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;
/**
*
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.web.controller.resource
* @FilenameModelCommentcontroller
* @Description TODO
* @Date2025/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<WorkFlowCommentVo> 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();
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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<WorkFlowCommentVo> 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;
}

View File

@ -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;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.resource.mapper
* @FilenameModelCommentLikeMapper
* @Description TODO
* @Date2025/1/12 12:02
*/
@Mapper
public interface WorkFlowCommentLikeMapper extends BaseMapper<WorkFlowCommentLike> {
WorkFlowCommentLike getLikeComment(@Param("userId") Long userId, @Param("commentId") Long commentId);
}

View File

@ -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;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.resource.mapper
* @FilenameModelCommentMapper
* @Description TODO
* @Date2025/1/12 12:04
*/
@Mapper
public interface WorkFlowCommentMapper extends BaseMapper<WorkFlowComment> {
}

View File

@ -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;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.resource.mapper
* @FilenameModelLikeMapper
* @Description TODO
* @Date2025/1/12 12:05
*/
@Mapper
public interface WorkFlowLikeMapper extends BaseMapper<WorkFlowLike> {
WorkFlowLike getLike(@Param("userId") Long userId, @Param("modelId") Long modelId);
}

View File

@ -0,0 +1,18 @@
package com.mcwl.resource.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.mcwl.resource.domain.WorkFlowCommentLike;
/**
*
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.resource.service
* @FilenameModelCommentLikeService
* @Description TODO
* @Date2025/1/12 11:58
*/
public interface WorkFlowCommentLikeService extends IService<WorkFlowCommentLike> {
void like(Long commentId);
}

View File

@ -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;
/**
*
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.resource.service
* @FilenameModelCommentService
* @Description TODO
* @Date2025/1/12 11:58
*/
public interface WorkFlowCommentService extends IService<WorkFlowComment> {
void comment(WorkFlowComment modelComment);
/**
*
* @param imageId id
* @return
*/
List<WorkFlowCommentVo> getComment(Long imageId);
}

View File

@ -0,0 +1,20 @@
package com.mcwl.resource.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.mcwl.resource.domain.WorkFlowLike;
/**
*
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.resource.service
* @FilenameModelLikeService
* @Description TODO
* @Date2025/1/12 11:57
*/
public interface WorkFlowLikeService extends IService<WorkFlowLike> {
void like(Long imageId);
}

View File

@ -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;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.resource.service.impl
* @FilenameModelCommentLikeServiceImpl
* @Description TODO
* @Date2025/1/12 12:01
*/
@Service
public class WorkFlowCommentLikeServiceImpl extends ServiceImpl<WorkFlowCommentLikeMapper, WorkFlowCommentLike> 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);
}
}

View File

@ -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;
/**
*
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.resource.service.impl
* @FilenameModelCommentServiceImpl
* @Description TODO
* @Date2025/1/12 12:03
*/
@Service
public class WorkFlowCommentServiceImpl extends ServiceImpl<WorkFlowCommentMapper, WorkFlowComment> 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<WorkFlowCommentVo> getComment(Long imageId) {
List<WorkFlowCommentVo> workFlowCommentVos = new ArrayList<>();
// 查询所有父评论
LambdaQueryWrapper<WorkFlowComment> lqw = new LambdaQueryWrapper<>();
lqw.eq(WorkFlowComment::getWorkFlowId, imageId)
.isNull(WorkFlowComment::getParentId)
.orderByDesc(WorkFlowComment::getCreateTime);
// 添加父评论
List<WorkFlowComment> 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<ModelCommentVo>
*/
private List<WorkFlowCommentVo> getContentList(Long modelCommentId) {
List<WorkFlowCommentVo> modelCommentVoList = new ArrayList<>();
if (Objects.isNull(modelCommentId)) {
return modelCommentVoList;
}
// 查询子评论
LambdaQueryWrapper<WorkFlowComment> lqw = new LambdaQueryWrapper<WorkFlowComment>()
.eq(WorkFlowComment::getParentId, modelCommentId)
.orderByDesc(WorkFlowComment::getCreateTime);
List<WorkFlowComment> 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;
}
}

View File

@ -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;
/**
*
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.resource.service.impl
* @FilenameModelLikeServiceImpl
* @Description TODO
* @Date2025/1/12 12:05
*/
@Service
public class WorkFlowLikeServiceImpl extends ServiceImpl<WorkFlowLikeMapper, WorkFlowLike> 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);
}
}

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mcwl.resource.mapper.WorkFlowCommentLikeMapper">
<select id="getLikeComment" resultType="com.mcwl.resource.domain.WorkFlowCommentLike">
select id,
user_id,
work_flow_comment_id,
create_by,
create_time,
update_by,
update_time,
del_flag,
remark
from work_flow_comment_like
where user_id = #{userId} and work_flow_comment_id = #{commentId}
</select>
</mapper>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mcwl.resource.mapper.WorkFlowLikeMapper">
<select id="getLike" resultType="com.mcwl.resource.domain.WorkFlowLike">
select id,
user_id,
model_comment_id,
create_by,
create_time,
update_by,
update_time,
del_flag,
remark
from work_flow_like
where user_id = #{userId} and model_id = #{modelId}
</select>
</mapper>

View File

@ -100,6 +100,7 @@ public class SysUserServiceImpl implements ISysUserService
/**
*
*
*
* @param user
* @return
*/