diff --git a/playlet-admin/src/main/java/com/playlet/web/controller/app/PublicDetailCommentAppController.java b/playlet-admin/src/main/java/com/playlet/web/controller/app/PublicDetailCommentAppController.java index ba98d53..4fc4d20 100644 --- a/playlet-admin/src/main/java/com/playlet/web/controller/app/PublicDetailCommentAppController.java +++ b/playlet-admin/src/main/java/com/playlet/web/controller/app/PublicDetailCommentAppController.java @@ -2,6 +2,7 @@ package com.playlet.web.controller.app; import com.github.pagehelper.PageInfo; import com.playlet.common.core.domain.Result; +import com.playlet.system.domain.PublicCommentStar; import com.playlet.system.domain.PublicDetailComment; import com.playlet.web.service.app.PublicDetailCommentAppService; import io.swagger.annotations.Api; @@ -31,6 +32,14 @@ public class PublicDetailCommentAppController { return Result.success(); } + @ResponseBody + @PostMapping("/delete") + @ApiOperation(value = "删除用户评论") + public Result delete(@RequestBody PublicDetailComment detailComment) { + detailCommentAppService.delete(detailComment); + return Result.success(); + } + @ResponseBody @PostMapping("/update") @ApiOperation(value = "更新用户评论(后续点赞使用)") @@ -49,4 +58,20 @@ public class PublicDetailCommentAppController { return Result.success(detailCommentAppService.query(detailComment, pageNum, pageSize)); } + @ResponseBody + @PostMapping("/start") + @ApiOperation(value = "点赞用户评论") + public Result start(@RequestBody PublicCommentStar publicCommentStar) { + detailCommentAppService.star(publicCommentStar); + return Result.success(); + } + + @ResponseBody + @PostMapping("/cancelStar") + @ApiOperation(value = "取消点赞用户评论") + public Result cancelStar(@RequestBody PublicCommentStar publicCommentStar) { + detailCommentAppService.cancelStar(publicCommentStar); + return Result.success(); + } + } diff --git a/playlet-admin/src/main/java/com/playlet/web/service/app/PublicDetailCommentAppService.java b/playlet-admin/src/main/java/com/playlet/web/service/app/PublicDetailCommentAppService.java index 2ef1e8c..e22ea5a 100644 --- a/playlet-admin/src/main/java/com/playlet/web/service/app/PublicDetailCommentAppService.java +++ b/playlet-admin/src/main/java/com/playlet/web/service/app/PublicDetailCommentAppService.java @@ -1,6 +1,7 @@ package com.playlet.web.service.app; import com.github.pagehelper.PageInfo; +import com.playlet.system.domain.PublicCommentStar; import com.playlet.system.domain.PublicDetailComment; public interface PublicDetailCommentAppService { @@ -12,4 +13,10 @@ public interface PublicDetailCommentAppService { PageInfo query(PublicDetailComment detailComment, Integer pageNum, Integer pageSize); + void star(PublicCommentStar publicCommentStar); + + void cancelStar(PublicCommentStar publicCommentStar); + + void delete(PublicDetailComment detailComment); + } diff --git a/playlet-admin/src/main/java/com/playlet/web/service/app/impl/PublicDetailCommentAppServiceImpl.java b/playlet-admin/src/main/java/com/playlet/web/service/app/impl/PublicDetailCommentAppServiceImpl.java index b52049e..1990a75 100644 --- a/playlet-admin/src/main/java/com/playlet/web/service/app/impl/PublicDetailCommentAppServiceImpl.java +++ b/playlet-admin/src/main/java/com/playlet/web/service/app/impl/PublicDetailCommentAppServiceImpl.java @@ -3,8 +3,10 @@ package com.playlet.web.service.app.impl; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.playlet.system.domain.PublicCommentResponse; +import com.playlet.system.domain.PublicCommentStar; import com.playlet.system.domain.PublicDetailComment; import com.playlet.system.service.IPublicCommentResponseService; +import com.playlet.system.service.IPublicCommentStarService; import com.playlet.system.service.IPublicDetailCommentService; import com.playlet.web.service.app.PublicDetailCommentAppService; import lombok.RequiredArgsConstructor; @@ -12,6 +14,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.Date; import java.util.List; @Slf4j @@ -23,6 +26,8 @@ public class PublicDetailCommentAppServiceImpl implements PublicDetailCommentApp private final IPublicCommentResponseService iPublicCommentResponseService; + private final IPublicCommentStarService iPublicCommentStarService; + @Override public void add(PublicDetailComment detailComment) { iPublicDetailCommentService.save(detailComment); @@ -36,11 +41,54 @@ public class PublicDetailCommentAppServiceImpl implements PublicDetailCommentApp @Override public PageInfo query(PublicDetailComment detailComment, Integer pageNum, Integer pageSize) { PageHelper.startPage(pageNum, pageSize); - List comments = iPublicDetailCommentService.selectPublicDetailCommentList(detailComment); + List comments = iPublicDetailCommentService.lambdaQuery() + .eq(PublicDetailComment::getDetailId, detailComment.getDetailId()) + .orderByDesc(PublicDetailComment::getStarCount) + .orderByDesc(PublicDetailComment::getCreateTime) + .list(); comments.forEach(model->{ model.setCommentResponse(iPublicCommentResponseService.lambdaQuery().eq(PublicCommentResponse::getCommentId, model.getId()).one()); + if(model.getUserId() != null){ + long star = iPublicCommentStarService.lambdaQuery() + .eq(PublicCommentStar::getCommentId, model.getId()) + .eq(PublicCommentStar::getUserId, detailComment.getUserId()) + .count(); + if(star > 0){ + model.setIsStar("02"); + }else { + model.setIsStar("01"); + } + } }); return PageInfo.of(comments); } + @Override + public void star(PublicCommentStar publicCommentStar) { + publicCommentStar.setCreateTime(new Date()); + iPublicCommentStarService.insertPublicCommentStar(publicCommentStar); + // 增加点赞数 + PublicDetailComment comment = iPublicDetailCommentService.getById(publicCommentStar.getCommentId()); + if(comment.getStarCount() == null){ + comment.setStarCount(1L); + }else { + comment.setStarCount(comment.getStarCount() + 1); + } + iPublicDetailCommentService.updateById(comment); + } + + @Override + public void cancelStar(PublicCommentStar publicCommentStar) { + iPublicCommentStarService.removeById(publicCommentStar.getId()); + // 增加点赞数 + PublicDetailComment comment = iPublicDetailCommentService.getById(publicCommentStar.getCommentId()); + comment.setStarCount(comment.getStarCount() - 1); + iPublicDetailCommentService.updateById(comment); + } + + @Override + public void delete(PublicDetailComment detailComment) { + iPublicDetailCommentService.removeById(detailComment.getId()); + } + } diff --git a/playlet-admin/src/main/resources/templates/system/playlet/detail/detail.html b/playlet-admin/src/main/resources/templates/system/playlet/detail/detail.html index c0b67f9..e001df7 100644 --- a/playlet-admin/src/main/resources/templates/system/playlet/detail/detail.html +++ b/playlet-admin/src/main/resources/templates/system/playlet/detail/detail.html @@ -112,7 +112,8 @@ }, { field: 'remark', - title: '备注' + title: '备注', + visible: false }, { title: '操作', diff --git a/playlet-system/src/main/java/com/playlet/system/domain/PublicCommentStar.java b/playlet-system/src/main/java/com/playlet/system/domain/PublicCommentStar.java new file mode 100644 index 0000000..8e00a2f --- /dev/null +++ b/playlet-system/src/main/java/com/playlet/system/domain/PublicCommentStar.java @@ -0,0 +1,36 @@ +package com.playlet.system.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.playlet.common.core.domain.BaseEntity; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import com.playlet.common.annotation.Excel; + +/** + * 用户评论点赞对象 public_comment_star + * + * @author ruoyi + * @date 2024-06-26 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName(value = "public_comment_star") +public class PublicCommentStar extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 主键 */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** 评论id */ + @Excel(name = "评论id") + private Long commentId; + + /** 用户id */ + @Excel(name = "用户id") + private Long userId; + +} diff --git a/playlet-system/src/main/java/com/playlet/system/domain/PublicDetailComment.java b/playlet-system/src/main/java/com/playlet/system/domain/PublicDetailComment.java index 55d6156..7832247 100644 --- a/playlet-system/src/main/java/com/playlet/system/domain/PublicDetailComment.java +++ b/playlet-system/src/main/java/com/playlet/system/domain/PublicDetailComment.java @@ -74,4 +74,8 @@ public class PublicDetailComment extends BaseEntity @ApiModelProperty(value = "是否回复 01.未回复 02.已回复") private String isResponse; + @TableField(exist = false) + @ApiModelProperty(value = "是否点赞 01.未点赞 02.已点赞") + private String isStar; + } diff --git a/playlet-system/src/main/java/com/playlet/system/mapper/PublicCommentStarMapper.java b/playlet-system/src/main/java/com/playlet/system/mapper/PublicCommentStarMapper.java new file mode 100644 index 0000000..1dc68e1 --- /dev/null +++ b/playlet-system/src/main/java/com/playlet/system/mapper/PublicCommentStarMapper.java @@ -0,0 +1,62 @@ +package com.playlet.system.mapper; + +import java.util.List; +import com.playlet.system.domain.PublicCommentStar; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + * 用户评论点赞Mapper接口 + * + * @author ruoyi + * @date 2024-06-26 + */ +public interface PublicCommentStarMapper extends BaseMapper +{ + /** + * 查询用户评论点赞 + * + * @param id 用户评论点赞主键 + * @return 用户评论点赞 + */ + public PublicCommentStar selectPublicCommentStarById(Long id); + + /** + * 查询用户评论点赞列表 + * + * @param publicCommentStar 用户评论点赞 + * @return 用户评论点赞集合 + */ + public List selectPublicCommentStarList(PublicCommentStar publicCommentStar); + + /** + * 新增用户评论点赞 + * + * @param publicCommentStar 用户评论点赞 + * @return 结果 + */ + public int insertPublicCommentStar(PublicCommentStar publicCommentStar); + + /** + * 修改用户评论点赞 + * + * @param publicCommentStar 用户评论点赞 + * @return 结果 + */ + public int updatePublicCommentStar(PublicCommentStar publicCommentStar); + + /** + * 删除用户评论点赞 + * + * @param id 用户评论点赞主键 + * @return 结果 + */ + public int deletePublicCommentStarById(Long id); + + /** + * 批量删除用户评论点赞 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deletePublicCommentStarByIds(String[] ids); +} diff --git a/playlet-system/src/main/java/com/playlet/system/service/IPublicCommentStarService.java b/playlet-system/src/main/java/com/playlet/system/service/IPublicCommentStarService.java new file mode 100644 index 0000000..624da7c --- /dev/null +++ b/playlet-system/src/main/java/com/playlet/system/service/IPublicCommentStarService.java @@ -0,0 +1,62 @@ +package com.playlet.system.service; + +import java.util.List; +import com.playlet.system.domain.PublicCommentStar; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + * 用户评论点赞Service接口 + * + * @author ruoyi + * @date 2024-06-26 + */ +public interface IPublicCommentStarService extends IService +{ + /** + * 查询用户评论点赞 + * + * @param id 用户评论点赞主键 + * @return 用户评论点赞 + */ + public PublicCommentStar selectPublicCommentStarById(Long id); + + /** + * 查询用户评论点赞列表 + * + * @param publicCommentStar 用户评论点赞 + * @return 用户评论点赞集合 + */ + public List selectPublicCommentStarList(PublicCommentStar publicCommentStar); + + /** + * 新增用户评论点赞 + * + * @param publicCommentStar 用户评论点赞 + * @return 结果 + */ + public int insertPublicCommentStar(PublicCommentStar publicCommentStar); + + /** + * 修改用户评论点赞 + * + * @param publicCommentStar 用户评论点赞 + * @return 结果 + */ + public int updatePublicCommentStar(PublicCommentStar publicCommentStar); + + /** + * 批量删除用户评论点赞 + * + * @param ids 需要删除的用户评论点赞主键集合 + * @return 结果 + */ + public int deletePublicCommentStarByIds(String ids); + + /** + * 删除用户评论点赞信息 + * + * @param id 用户评论点赞主键 + * @return 结果 + */ + public int deletePublicCommentStarById(Long id); +} diff --git a/playlet-system/src/main/java/com/playlet/system/service/impl/PublicCommentStarServiceImpl.java b/playlet-system/src/main/java/com/playlet/system/service/impl/PublicCommentStarServiceImpl.java new file mode 100644 index 0000000..8e7ab31 --- /dev/null +++ b/playlet-system/src/main/java/com/playlet/system/service/impl/PublicCommentStarServiceImpl.java @@ -0,0 +1,98 @@ +package com.playlet.system.service.impl; + +import java.util.List; +import com.playlet.common.utils.DateUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.playlet.system.mapper.PublicCommentStarMapper; +import com.playlet.system.domain.PublicCommentStar; +import com.playlet.system.service.IPublicCommentStarService; +import com.playlet.common.core.text.Convert; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + +/** + * 用户评论点赞Service业务层处理 + * + * @author ruoyi + * @date 2024-06-26 + */ +@Service +public class PublicCommentStarServiceImpl extends ServiceImpl implements IPublicCommentStarService +{ + @Autowired + private PublicCommentStarMapper publicCommentStarMapper; + + /** + * 查询用户评论点赞 + * + * @param id 用户评论点赞主键 + * @return 用户评论点赞 + */ + @Override + public PublicCommentStar selectPublicCommentStarById(Long id) + { + return publicCommentStarMapper.selectPublicCommentStarById(id); + } + + /** + * 查询用户评论点赞列表 + * + * @param publicCommentStar 用户评论点赞 + * @return 用户评论点赞 + */ + @Override + public List selectPublicCommentStarList(PublicCommentStar publicCommentStar) + { + return publicCommentStarMapper.selectPublicCommentStarList(publicCommentStar); + } + + /** + * 新增用户评论点赞 + * + * @param publicCommentStar 用户评论点赞 + * @return 结果 + */ + @Override + public int insertPublicCommentStar(PublicCommentStar publicCommentStar) + { + publicCommentStar.setCreateTime(DateUtils.getNowDate()); + return publicCommentStarMapper.insertPublicCommentStar(publicCommentStar); + } + + /** + * 修改用户评论点赞 + * + * @param publicCommentStar 用户评论点赞 + * @return 结果 + */ + @Override + public int updatePublicCommentStar(PublicCommentStar publicCommentStar) + { + publicCommentStar.setUpdateTime(DateUtils.getNowDate()); + return publicCommentStarMapper.updatePublicCommentStar(publicCommentStar); + } + + /** + * 批量删除用户评论点赞 + * + * @param ids 需要删除的用户评论点赞主键 + * @return 结果 + */ + @Override + public int deletePublicCommentStarByIds(String ids) + { + return publicCommentStarMapper.deletePublicCommentStarByIds(Convert.toStrArray(ids)); + } + + /** + * 删除用户评论点赞信息 + * + * @param id 用户评论点赞主键 + * @return 结果 + */ + @Override + public int deletePublicCommentStarById(Long id) + { + return publicCommentStarMapper.deletePublicCommentStarById(id); + } +} diff --git a/playlet-system/src/main/resources/mapper/system/PublicCommentStarMapper.xml b/playlet-system/src/main/resources/mapper/system/PublicCommentStarMapper.xml new file mode 100644 index 0000000..b54dafb --- /dev/null +++ b/playlet-system/src/main/resources/mapper/system/PublicCommentStarMapper.xml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + select id, comment_id, user_id, create_by, create_time, update_by, update_time, remark from public_comment_star + + + + + + + + insert into public_comment_star + + comment_id, + user_id, + create_by, + create_time, + update_by, + update_time, + remark, + + + #{commentId}, + #{userId}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + #{remark}, + + + + + update public_comment_star + + comment_id = #{commentId}, + user_id = #{userId}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + remark = #{remark}, + + where id = #{id} + + + + delete from public_comment_star where id = #{id} + + + + delete from public_comment_star where id in + + #{id} + + + + \ No newline at end of file