refactor(resource): 调整评论和点赞功能
parent
dd16eb0106
commit
89ff879055
|
@ -76,7 +76,7 @@ public class ModelCommentController {
|
||||||
@ApiParam(value = "评论id", required = true)
|
@ApiParam(value = "评论id", required = true)
|
||||||
Long commentId) {
|
Long commentId) {
|
||||||
modelCommentLikeService.like(commentId);
|
modelCommentLikeService.like(commentId);
|
||||||
return AjaxResult.error();
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -86,11 +86,13 @@ public class ModelCommentController {
|
||||||
@ApiOperation(value = "获取模型评论")
|
@ApiOperation(value = "获取模型评论")
|
||||||
@GetMapping("/comment")
|
@GetMapping("/comment")
|
||||||
@Valid
|
@Valid
|
||||||
public AjaxResult getComment(@NotNull(message = "模型id不能为空")
|
public AjaxResult getComment(@Valid
|
||||||
|
@NotNull(message = "模型id不能为空")
|
||||||
@ApiParam(value = "模型id", required = true)
|
@ApiParam(value = "模型id", required = true)
|
||||||
Long modelId,
|
Long modelId,
|
||||||
|
@Valid
|
||||||
@NotNull(message = "排序方式不能为空")
|
@NotNull(message = "排序方式不能为空")
|
||||||
@ApiParam(value = "排序方式", required = true)
|
@ApiParam(value = "排序方式 0最热 1最新", required = true)
|
||||||
Integer sortType) {
|
Integer sortType) {
|
||||||
List<ModelCommentVo> modelCommentList = modelCommentService.getComment(modelId, sortType);
|
List<ModelCommentVo> modelCommentList = modelCommentService.getComment(modelId, sortType);
|
||||||
return AjaxResult.success(modelCommentList);
|
return AjaxResult.success(modelCommentList);
|
||||||
|
|
|
@ -75,11 +75,13 @@ public class ModelImageCommentController {
|
||||||
@ApiOperation(value = "获取图片评论")
|
@ApiOperation(value = "获取图片评论")
|
||||||
@GetMapping("/comment")
|
@GetMapping("/comment")
|
||||||
@Valid
|
@Valid
|
||||||
public AjaxResult getComment(@NotNull(message = "图片id不能为空")
|
public AjaxResult getComment(@Valid
|
||||||
|
@NotNull(message = "图片id不能为空")
|
||||||
@ApiParam(value = "评论id", required = true)
|
@ApiParam(value = "评论id", required = true)
|
||||||
Long imageId,
|
Long imageId,
|
||||||
|
@Valid
|
||||||
@NotNull(message = "排序方式不能为空")
|
@NotNull(message = "排序方式不能为空")
|
||||||
@ApiParam(value = "排序方式", required = true)
|
@ApiParam(value = "排序方式 0最热 1最新", required = true)
|
||||||
Integer sortType) {
|
Integer sortType) {
|
||||||
List<ModelImageCommentVo> modelImageCommentVoList = modelImageCommentService.getComment(imageId, sortType);
|
List<ModelImageCommentVo> modelImageCommentVoList = modelImageCommentService.getComment(imageId, sortType);
|
||||||
return AjaxResult.success(modelImageCommentVoList);
|
return AjaxResult.success(modelImageCommentVoList);
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class WorkFlowCommentController {
|
||||||
@ApiParam(value = "评论id", required = true)
|
@ApiParam(value = "评论id", required = true)
|
||||||
Long commentId) {
|
Long commentId) {
|
||||||
workFlowCommentLikeService.like(commentId);
|
workFlowCommentLikeService.like(commentId);
|
||||||
return AjaxResult.error();
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -84,12 +84,13 @@ public class WorkFlowCommentController {
|
||||||
*/
|
*/
|
||||||
@ApiOperation(value = "获取工作流评论")
|
@ApiOperation(value = "获取工作流评论")
|
||||||
@GetMapping("/comment")
|
@GetMapping("/comment")
|
||||||
@Valid
|
public AjaxResult getComment(@Valid
|
||||||
public AjaxResult getComment(@NotNull(message = "模型id不能为空")
|
@NotNull(message = "模型id不能为空")
|
||||||
@ApiParam(value = "模型id", required = true)
|
@ApiParam(value = "模型id", required = true)
|
||||||
Long commentId,
|
Long commentId,
|
||||||
|
@Valid
|
||||||
@NotNull(message = "排序方式不能为空")
|
@NotNull(message = "排序方式不能为空")
|
||||||
@ApiParam(value = "排序方式", required = true)
|
@ApiParam(value = "排序方式 0最热 1最新", required = true)
|
||||||
Integer sortType) {
|
Integer sortType) {
|
||||||
List<WorkFlowCommentVo> modelCommentList = workFlowCommentService.getComment(commentId, sortType);
|
List<WorkFlowCommentVo> modelCommentList = workFlowCommentService.getComment(commentId, sortType);
|
||||||
return AjaxResult.success(modelCommentList);
|
return AjaxResult.success(modelCommentList);
|
||||||
|
@ -117,8 +118,8 @@ public class WorkFlowCommentController {
|
||||||
public AjaxResult getCommentCount(@Valid
|
public AjaxResult getCommentCount(@Valid
|
||||||
@NotNull(message = "工作流id不能为空")
|
@NotNull(message = "工作流id不能为空")
|
||||||
@ApiParam(value = "工作流id", required = true)
|
@ApiParam(value = "工作流id", required = true)
|
||||||
Long imageId) {
|
Long workFlowId) {
|
||||||
Integer commentCount = workFlowCommentService.getCommentCount(imageId);
|
Integer commentCount = workFlowCommentService.getCommentCount(workFlowId);
|
||||||
return AjaxResult.success(commentCount);
|
return AjaxResult.success(commentCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,4 +17,5 @@ import org.apache.ibatis.annotations.Param;
|
||||||
public interface ModelCommentLikeMapper extends BaseMapper<ModelCommentLike> {
|
public interface ModelCommentLikeMapper extends BaseMapper<ModelCommentLike> {
|
||||||
ModelCommentLike getLikeComment(@Param("userId") Long userId, @Param("commentId") Long commentId);
|
ModelCommentLike getLikeComment(@Param("userId") Long userId, @Param("commentId") Long commentId);
|
||||||
|
|
||||||
|
void updateDelFlagById(ModelCommentLike modelCommentLike);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,5 +10,5 @@ import org.apache.ibatis.annotations.Param;
|
||||||
public interface ModelImageCommentLikeMapper extends BaseMapper<ModelImageCommentLike> {
|
public interface ModelImageCommentLikeMapper extends BaseMapper<ModelImageCommentLike> {
|
||||||
ModelImageCommentLike getLikeImageComment(@Param("userId") Long userId, @Param("commentId") Long commentId);
|
ModelImageCommentLike getLikeImageComment(@Param("userId") Long userId, @Param("commentId") Long commentId);
|
||||||
|
|
||||||
void updateDelFlagById(@Param("userId") Long userId, @Param("commentId") Long commentId);
|
void updateDelFlagById(ModelImageCommentLike modelImageCommentLike);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,4 +17,5 @@ import org.apache.ibatis.annotations.Param;
|
||||||
public interface WorkFlowCommentLikeMapper extends BaseMapper<WorkFlowCommentLike> {
|
public interface WorkFlowCommentLikeMapper extends BaseMapper<WorkFlowCommentLike> {
|
||||||
WorkFlowCommentLike getLikeComment(@Param("userId") Long userId, @Param("commentId") Long commentId);
|
WorkFlowCommentLike getLikeComment(@Param("userId") Long userId, @Param("commentId") Long commentId);
|
||||||
|
|
||||||
|
void updateDelFlagById(WorkFlowCommentLike workFlowCommentLike);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,10 +20,10 @@ public interface ModelCommentService extends IService<ModelComment> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取评论
|
* 获取评论
|
||||||
* @param imageId 图片id
|
* @param modelId 模型id
|
||||||
* @return 评论区
|
* @return 评论区
|
||||||
*/
|
*/
|
||||||
List<ModelCommentVo> getComment(Long imageId, Integer sortType);
|
List<ModelCommentVo> getComment(Long modelId, Integer sortType);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取评论数量
|
* 获取评论数量
|
||||||
|
|
|
@ -23,10 +23,10 @@ public interface WorkFlowCommentService extends IService<WorkFlowComment> {
|
||||||
/**
|
/**
|
||||||
* 获取评论
|
* 获取评论
|
||||||
*
|
*
|
||||||
* @param imageId 图片id
|
* @param workFLowId 工作流id
|
||||||
* @return 评论区
|
* @return 评论区
|
||||||
*/
|
*/
|
||||||
List<WorkFlowCommentVo> getComment(Long imageId, Integer sortType);
|
List<WorkFlowCommentVo> getComment(Long workFLowId, Integer sortType);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -43,14 +43,16 @@ public class ModelCommentLikeServiceImpl extends ServiceImpl<ModelCommentLikeMap
|
||||||
ModelCommentLike modelCommentLike = baseMapper.getLikeComment(userId, commentId);
|
ModelCommentLike modelCommentLike = baseMapper.getLikeComment(userId, commentId);
|
||||||
if (Objects.nonNull(modelCommentLike)) {
|
if (Objects.nonNull(modelCommentLike)) {
|
||||||
if (Objects.equals(modelCommentLike.getDelFlag(), "0")) {
|
if (Objects.equals(modelCommentLike.getDelFlag(), "0")) {
|
||||||
modelCommentLike.setDelFlag("1");
|
modelCommentLike.setDelFlag("2");
|
||||||
modelComment.setLikeNum(modelComment.getLikeNum() - 1);
|
int likeNum = modelComment.getLikeNum() - 1;
|
||||||
|
likeNum = Math.max(likeNum, 0);
|
||||||
|
modelComment.setLikeNum(likeNum);
|
||||||
} else {
|
} else {
|
||||||
modelCommentLike.setDelFlag("0");
|
modelCommentLike.setDelFlag("0");
|
||||||
modelComment.setLikeNum(modelComment.getLikeNum() + 1);
|
modelComment.setLikeNum(modelComment.getLikeNum() + 1);
|
||||||
}
|
}
|
||||||
// 更新点赞记录
|
// 更新点赞记录
|
||||||
baseMapper.updateById(modelCommentLike);
|
baseMapper.updateDelFlagById(modelCommentLike);
|
||||||
// 更新图片评论点赞数
|
// 更新图片评论点赞数
|
||||||
modelCommentMapper.updateById(modelComment);
|
modelCommentMapper.updateById(modelComment);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -7,6 +7,7 @@ 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.resource.domain.ModelComment;
|
||||||
import com.mcwl.resource.domain.ModelCommentLike;
|
import com.mcwl.resource.domain.ModelCommentLike;
|
||||||
|
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;
|
||||||
|
@ -59,20 +60,24 @@ public class ModelCommentServiceImpl extends ServiceImpl<ModelCommentMapper, Mod
|
||||||
/**
|
/**
|
||||||
* 获取评论
|
* 获取评论
|
||||||
*
|
*
|
||||||
* @param imageId 图片id
|
* @param modelId 模型id
|
||||||
* @return 评论区
|
* @return 评论区
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<ModelCommentVo> getComment(Long imageId, Integer sortType) {
|
public List<ModelCommentVo> getComment(Long modelId, Integer sortType) {
|
||||||
|
|
||||||
// 1. 查询所有父评论
|
// 1. 查询所有父评论
|
||||||
List<ModelComment> parentComments = baseMapper.selectList(
|
LambdaQueryWrapper<ModelComment> lqw = new LambdaQueryWrapper<ModelComment>()
|
||||||
new LambdaQueryWrapper<ModelComment>()
|
.eq(ModelComment::getModelId, modelId)
|
||||||
.eq(ModelComment::getModelId, imageId)
|
.isNull(ModelComment::getParentId);
|
||||||
.isNull(ModelComment::getParentId)
|
if (sortType == 0) {
|
||||||
.orderByDesc(sortType != 1, ModelComment::getLikeNum)
|
// 按点赞数降序,创建时间升序
|
||||||
.orderByAsc(ModelComment::getCreateTime)
|
lqw.orderByAsc(ModelComment::getLikeNum)
|
||||||
);
|
.orderByAsc(ModelComment::getCreateTime);
|
||||||
|
} else {
|
||||||
|
lqw.orderByDesc(ModelComment::getCreateTime);
|
||||||
|
}
|
||||||
|
List<ModelComment> parentComments = baseMapper.selectList(lqw);
|
||||||
|
|
||||||
// 无评论直接返回空列表
|
// 无评论直接返回空列表
|
||||||
if (parentComments.isEmpty()) {
|
if (parentComments.isEmpty()) {
|
||||||
|
@ -124,8 +129,11 @@ public class ModelCommentServiceImpl extends ServiceImpl<ModelCommentMapper, Mod
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
// 获取所有子评论
|
// 获取所有子评论
|
||||||
List<ModelComment> childCommentList = baseMapper.selectList(new LambdaQueryWrapper<ModelComment>()
|
List<ModelComment> childCommentList = new ArrayList<>();
|
||||||
.in(ModelComment::getParentId, parentIds));
|
if (!parentIds.isEmpty()) {
|
||||||
|
childCommentList = baseMapper.selectList(new LambdaQueryWrapper<ModelComment>()
|
||||||
|
.in(ModelComment::getParentId, parentIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return parentIds.size() + childCommentList.size();
|
return parentIds.size() + childCommentList.size();
|
||||||
|
|
|
@ -39,12 +39,16 @@ public class ModelImageCommentLikeServiceImpl extends ServiceImpl<ModelImageComm
|
||||||
ModelImageCommentLike modelImageCommentLike = baseMapper.getLikeImageComment(userId, commentId);
|
ModelImageCommentLike modelImageCommentLike = baseMapper.getLikeImageComment(userId, commentId);
|
||||||
if (Objects.nonNull(modelImageCommentLike)) {
|
if (Objects.nonNull(modelImageCommentLike)) {
|
||||||
if (Objects.equals(modelImageCommentLike.getDelFlag(), "0")) {
|
if (Objects.equals(modelImageCommentLike.getDelFlag(), "0")) {
|
||||||
modelImageComment.setLikeNum(modelImageComment.getLikeNum() - 1);
|
modelImageCommentLike.setDelFlag("2");
|
||||||
|
int likeNum = modelImageComment.getLikeNum() - 1;
|
||||||
|
likeNum = Math.max(likeNum, 0);
|
||||||
|
modelImageComment.setLikeNum(likeNum);
|
||||||
} else {
|
} else {
|
||||||
|
modelImageCommentLike.setDelFlag("0");
|
||||||
modelImageComment.setLikeNum(modelImageComment.getLikeNum() + 1);
|
modelImageComment.setLikeNum(modelImageComment.getLikeNum() + 1);
|
||||||
}
|
}
|
||||||
// 更新点赞记录
|
// 更新点赞记录
|
||||||
baseMapper.updateDelFlagById(userId, commentId);
|
baseMapper.updateDelFlagById(modelImageCommentLike);
|
||||||
// 更新图片评论点赞数
|
// 更新图片评论点赞数
|
||||||
modelImageCommentMapper.updateById(modelImageComment);
|
modelImageCommentMapper.updateById(modelImageComment);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -7,6 +7,7 @@ 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.ModelImageComment;
|
import com.mcwl.resource.domain.ModelImageComment;
|
||||||
import com.mcwl.resource.domain.ModelImageCommentLike;
|
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;
|
||||||
|
@ -58,13 +59,17 @@ public class ModelImageCommentServiceImpl extends ServiceImpl<ModelImageCommentM
|
||||||
@Override
|
@Override
|
||||||
public List<ModelImageCommentVo> getComment(Long imageId, Integer sortType) {
|
public List<ModelImageCommentVo> getComment(Long imageId, Integer sortType) {
|
||||||
// 1. 查询所有父评论
|
// 1. 查询所有父评论
|
||||||
List<ModelImageComment> parentComments = baseMapper.selectList(
|
LambdaQueryWrapper<ModelImageComment> lqw = new LambdaQueryWrapper<ModelImageComment>()
|
||||||
new LambdaQueryWrapper<ModelImageComment>()
|
.eq(ModelImageComment::getModelImageId, imageId)
|
||||||
.eq(ModelImageComment::getModelImageId, imageId)
|
.isNull(ModelImageComment::getParentId);
|
||||||
.isNull(ModelImageComment::getParentId)
|
if (sortType == 0) {
|
||||||
.orderByDesc(sortType != 1, ModelImageComment::getLikeNum)
|
// 按点赞数降序,创建时间升序
|
||||||
.orderByAsc(ModelImageComment::getCreateTime)
|
lqw.orderByAsc(ModelImageComment::getLikeNum)
|
||||||
);
|
.orderByAsc(ModelImageComment::getCreateTime);
|
||||||
|
} else {
|
||||||
|
lqw.orderByDesc(ModelImageComment::getCreateTime);
|
||||||
|
}
|
||||||
|
List<ModelImageComment> parentComments = baseMapper.selectList(lqw);
|
||||||
|
|
||||||
// 无评论直接返回空列表
|
// 无评论直接返回空列表
|
||||||
if (parentComments.isEmpty()) {
|
if (parentComments.isEmpty()) {
|
||||||
|
@ -111,8 +116,11 @@ public class ModelImageCommentServiceImpl extends ServiceImpl<ModelImageCommentM
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
// 获取所有子评论
|
// 获取所有子评论
|
||||||
List<ModelImageComment> childCommentList = baseMapper.selectList(new LambdaQueryWrapper<ModelImageComment>()
|
List<ModelImageComment> childCommentList = new ArrayList<>();
|
||||||
.in(ModelImageComment::getParentId, parentIds));
|
if (!parentIds.isEmpty()) {
|
||||||
|
childCommentList = baseMapper.selectList(new LambdaQueryWrapper<ModelImageComment>()
|
||||||
|
.in(ModelImageComment::getParentId, parentIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return parentIds.size() + childCommentList.size();
|
return parentIds.size() + childCommentList.size();
|
||||||
|
|
|
@ -49,8 +49,12 @@ public class ModelImageLikeServiceImpl extends ServiceImpl<ModelImageLikeMapper,
|
||||||
ModelImageLike modelImageLike = baseMapper.getLikeImage(userId, imageId);
|
ModelImageLike modelImageLike = baseMapper.getLikeImage(userId, imageId);
|
||||||
if (Objects.nonNull(modelImageLike)) {
|
if (Objects.nonNull(modelImageLike)) {
|
||||||
if (Objects.equals(modelImageLike.getDelFlag(), "0")) {
|
if (Objects.equals(modelImageLike.getDelFlag(), "0")) {
|
||||||
modelImage.setLikeNum(modelImage.getLikeNum() - 1);
|
modelImageLike.setDelFlag("2");
|
||||||
|
int likeNum = modelImage.getLikeNum() - 1;
|
||||||
|
likeNum = Math.max(likeNum, 0);
|
||||||
|
modelImage.setLikeNum(likeNum);
|
||||||
} else {
|
} else {
|
||||||
|
modelImageLike.setDelFlag("0");
|
||||||
modelImage.setLikeNum(modelImage.getLikeNum() + 1);
|
modelImage.setLikeNum(modelImage.getLikeNum() + 1);
|
||||||
}
|
}
|
||||||
// 更新点赞记录
|
// 更新点赞记录
|
||||||
|
|
|
@ -52,7 +52,9 @@ public class ModelLikeServiceImpl extends ServiceImpl<ModelLikeMapper, ModelLike
|
||||||
if (Objects.nonNull(modelLike)) {
|
if (Objects.nonNull(modelLike)) {
|
||||||
if (Objects.equals(modelLike.getDelFlag(), "0")) {
|
if (Objects.equals(modelLike.getDelFlag(), "0")) {
|
||||||
modelLike.setDelFlag("2");
|
modelLike.setDelFlag("2");
|
||||||
model.setLikeNum(model.getLikeNum() - 1);
|
int likeNum = model.getLikeNum() - 1;
|
||||||
|
likeNum = Math.max(likeNum, 0);
|
||||||
|
model.setLikeNum(likeNum);
|
||||||
} else {
|
} else {
|
||||||
modelLike.setDelFlag("0");
|
modelLike.setDelFlag("0");
|
||||||
model.setLikeNum(model.getLikeNum() + 1);
|
model.setLikeNum(model.getLikeNum() + 1);
|
||||||
|
|
|
@ -40,14 +40,16 @@ public class WorkFlowCommentLikeServiceImpl extends ServiceImpl<WorkFlowCommentL
|
||||||
WorkFlowCommentLike workFlowCommentLike = baseMapper.getLikeComment(userId, commentId);
|
WorkFlowCommentLike workFlowCommentLike = baseMapper.getLikeComment(userId, commentId);
|
||||||
if (Objects.nonNull(workFlowCommentLike)) {
|
if (Objects.nonNull(workFlowCommentLike)) {
|
||||||
if (Objects.equals(workFlowComment.getDelFlag(), "0")) {
|
if (Objects.equals(workFlowComment.getDelFlag(), "0")) {
|
||||||
workFlowCommentLike.setDelFlag("1");
|
workFlowCommentLike.setDelFlag("2");
|
||||||
workFlowComment.setLikeNum(workFlowComment.getLikeNum() - 1);
|
int likeNum = workFlowComment.getLikeNum() - 1;
|
||||||
|
likeNum = Math.max(likeNum, 0);
|
||||||
|
workFlowComment.setLikeNum(likeNum);
|
||||||
} else {
|
} else {
|
||||||
workFlowCommentLike.setDelFlag("0");
|
workFlowCommentLike.setDelFlag("0");
|
||||||
workFlowComment.setLikeNum(workFlowComment.getLikeNum() + 1);
|
workFlowComment.setLikeNum(workFlowComment.getLikeNum() + 1);
|
||||||
}
|
}
|
||||||
// 更新点赞记录
|
// 更新点赞记录
|
||||||
baseMapper.updateById(workFlowCommentLike);
|
baseMapper.updateDelFlagById(workFlowCommentLike);
|
||||||
// 更新图片评论点赞数
|
// 更新图片评论点赞数
|
||||||
workFlowCommentMapper.updateById(workFlowComment);
|
workFlowCommentMapper.updateById(workFlowComment);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -61,16 +61,20 @@ public class WorkFlowCommentServiceImpl extends ServiceImpl<WorkFlowCommentMappe
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<WorkFlowCommentVo> getComment(Long imageId, Integer sortType) {
|
public List<WorkFlowCommentVo> getComment(Long workFLowId, Integer sortType) {
|
||||||
|
|
||||||
// 查询所有父评论
|
// 查询所有父评论
|
||||||
List<WorkFlowComment> parentComments = baseMapper.selectList(
|
LambdaQueryWrapper<WorkFlowComment> lqw = new LambdaQueryWrapper<WorkFlowComment>()
|
||||||
new LambdaQueryWrapper<WorkFlowComment>()
|
.eq(WorkFlowComment::getWorkFlowId, workFLowId)
|
||||||
.eq(WorkFlowComment::getWorkFlowId, imageId)
|
.isNull(WorkFlowComment::getParentId);
|
||||||
.isNull(WorkFlowComment::getParentId)
|
if (sortType == 0) {
|
||||||
.orderByDesc(sortType != 1, WorkFlowComment::getLikeNum)
|
// 按点赞数降序,创建时间升序
|
||||||
.orderByAsc(WorkFlowComment::getCreateTime)
|
lqw.orderByAsc(WorkFlowComment::getLikeNum)
|
||||||
);
|
.orderByAsc(WorkFlowComment::getCreateTime);
|
||||||
|
} else {
|
||||||
|
lqw.orderByDesc(WorkFlowComment::getCreateTime);
|
||||||
|
}
|
||||||
|
List<WorkFlowComment> parentComments = baseMapper.selectList(lqw);
|
||||||
|
|
||||||
// 无评论直接返回空列表
|
// 无评论直接返回空列表
|
||||||
if (parentComments.isEmpty()) {
|
if (parentComments.isEmpty()) {
|
||||||
|
@ -116,8 +120,11 @@ public class WorkFlowCommentServiceImpl extends ServiceImpl<WorkFlowCommentMappe
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
// 获取所有子评论
|
// 获取所有子评论
|
||||||
List<WorkFlowComment> childCommentList = baseMapper.selectList(new LambdaQueryWrapper<WorkFlowComment>()
|
List<WorkFlowComment> childCommentList = new ArrayList<>();
|
||||||
.in(WorkFlowComment::getParentId, parentIds));
|
if (!parentIds.isEmpty()) {
|
||||||
|
childCommentList = baseMapper.selectList(new LambdaQueryWrapper<WorkFlowComment>()
|
||||||
|
.in(WorkFlowComment::getParentId, parentIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return parentIds.size() + childCommentList.size();
|
return parentIds.size() + childCommentList.size();
|
||||||
|
@ -189,9 +196,9 @@ public class WorkFlowCommentServiceImpl extends ServiceImpl<WorkFlowCommentMappe
|
||||||
* 构建树形VO结构
|
* 构建树形VO结构
|
||||||
*/
|
*/
|
||||||
private List<WorkFlowCommentVo> buildCommentTree(List<WorkFlowComment> parentComments,
|
private List<WorkFlowCommentVo> buildCommentTree(List<WorkFlowComment> parentComments,
|
||||||
List<WorkFlowComment> childComments,
|
List<WorkFlowComment> childComments,
|
||||||
Map<Long, SysUser> userMap,
|
Map<Long, SysUser> userMap,
|
||||||
Map<Long, Integer> likeStatusMap) {
|
Map<Long, Integer> likeStatusMap) {
|
||||||
Map<Long, List<WorkFlowComment>> childMap = new HashMap<>();
|
Map<Long, List<WorkFlowComment>> childMap = new HashMap<>();
|
||||||
for (WorkFlowComment child : childComments) {
|
for (WorkFlowComment child : childComments) {
|
||||||
childMap.computeIfAbsent(child.getParentId(), k -> new ArrayList<>()).add(child);
|
childMap.computeIfAbsent(child.getParentId(), k -> new ArrayList<>()).add(child);
|
||||||
|
@ -246,5 +253,4 @@ public class WorkFlowCommentServiceImpl extends ServiceImpl<WorkFlowCommentMappe
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,8 +60,10 @@ public class WorkFlowLikeServiceImpl extends ServiceImpl<WorkFlowLikeMapper, Wor
|
||||||
WorkFlowLike workFlowLike = baseMapper.getLike(userId, modelId);
|
WorkFlowLike workFlowLike = baseMapper.getLike(userId, modelId);
|
||||||
if (Objects.nonNull(workFlowLike)) {
|
if (Objects.nonNull(workFlowLike)) {
|
||||||
if (Objects.equals(workFlowLike.getDelFlag(), "0")) {
|
if (Objects.equals(workFlowLike.getDelFlag(), "0")) {
|
||||||
workFlowLike.setDelFlag("1");
|
workFlowLike.setDelFlag("2");
|
||||||
workFlow.setLikeCount(workFlow.getLikeCount() - 1);
|
int likeCount = workFlow.getLikeCount() - 1;
|
||||||
|
likeCount = Math.max(likeCount, 0);
|
||||||
|
workFlow.setLikeCount(likeCount);
|
||||||
} else {
|
} else {
|
||||||
workFlowLike.setDelFlag("0");
|
workFlowLike.setDelFlag("0");
|
||||||
workFlow.setLikeCount(workFlow.getLikeCount() + 1);
|
workFlow.setLikeCount(workFlow.getLikeCount() + 1);
|
||||||
|
|
|
@ -3,6 +3,11 @@
|
||||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.mcwl.resource.mapper.ModelCommentLikeMapper">
|
<mapper namespace="com.mcwl.resource.mapper.ModelCommentLikeMapper">
|
||||||
|
<update id="updateDelFlagById">
|
||||||
|
update model_comment_like
|
||||||
|
set del_flag = #{delFlag}
|
||||||
|
where user_id = #{userId} and model_comment_id = #{modelCommentId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
|
||||||
<select id="getLikeComment" resultType="com.mcwl.resource.domain.ModelCommentLike">
|
<select id="getLikeComment" resultType="com.mcwl.resource.domain.ModelCommentLike">
|
||||||
|
@ -14,6 +19,8 @@
|
||||||
update_by,
|
update_by,
|
||||||
update_time,
|
update_time,
|
||||||
del_flag,
|
del_flag,
|
||||||
remark where user_id = #{userId} and model_comment_id = #{commentId}
|
remark
|
||||||
|
from model_comment_like
|
||||||
|
where user_id = #{userId} and model_comment_id = #{commentId}
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
@ -30,9 +30,9 @@
|
||||||
from model_image_comment_like
|
from model_image_comment_like
|
||||||
</sql>
|
</sql>
|
||||||
<update id="updateDelFlagById">
|
<update id="updateDelFlagById">
|
||||||
update model_image_comment_like
|
UPDATE model_image_comment_like
|
||||||
set del_flag = !del_flag
|
SET del_flag = #{delFlag}
|
||||||
where user_id = #{userId} and model_image_comment_id = #{commentId}
|
WHERE user_id = #{userId} and model_image_comment_id = #{modelImageCommentId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,11 @@
|
||||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.mcwl.resource.mapper.WorkFlowCommentLikeMapper">
|
<mapper namespace="com.mcwl.resource.mapper.WorkFlowCommentLikeMapper">
|
||||||
|
<update id="updateDelFlagById">
|
||||||
|
update work_flow_comment_like
|
||||||
|
set del_flag = #{delFlag}
|
||||||
|
where user_id = #{userId} and work_flow_comment_id = #{workFlowCommentId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
|
||||||
<select id="getLikeComment" resultType="com.mcwl.resource.domain.WorkFlowCommentLike">
|
<select id="getLikeComment" resultType="com.mcwl.resource.domain.WorkFlowCommentLike">
|
||||||
|
|
|
@ -6,14 +6,8 @@
|
||||||
|
|
||||||
<update id="updateStatus">
|
<update id="updateStatus">
|
||||||
UPDATE work_flow_like
|
UPDATE work_flow_like
|
||||||
SET user_id = #{userId},
|
SET del_flag = #{delFlag}
|
||||||
work_flow_id = #{workFlowId},
|
WHERE user_id = #{userId} and work_flow_id = #{workFlowId}
|
||||||
create_by = #{createBy},
|
|
||||||
create_time = #{createTime},
|
|
||||||
update_by = #{updateBy},
|
|
||||||
update_time = #{updateTime},
|
|
||||||
del_flag = #{delFlag}
|
|
||||||
WHERE id = #{id}
|
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue