feat:报表评论
This commit is contained in:
@@ -0,0 +1,57 @@
|
|||||||
|
package com.adc.da.report.controller;
|
||||||
|
|
||||||
|
import com.adc.da.report.dto.ReportCommentDTO;
|
||||||
|
import com.adc.da.report.dto.ReportRatingDTO;
|
||||||
|
import com.adc.da.report.service.IReportUserCommentService;
|
||||||
|
import com.adc.da.report.service.IReportUserRatingService;
|
||||||
|
import com.adc.da.report.vo.ReportCommentVo;
|
||||||
|
import com.adc.da.util.http.ResponseMessage;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.validation.Valid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author CaiHaohan
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@Api(tags = "报告评论")
|
||||||
|
@RequestMapping("/${restPath}/report-comment")
|
||||||
|
public class ReportCommentController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IReportUserCommentService reportUserCommentService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页获取报表下的评论
|
||||||
|
*/
|
||||||
|
@ApiOperation(value = "分页获取报表下的评论")
|
||||||
|
@GetMapping("/page")
|
||||||
|
public ResponseMessage rating(@Valid ReportCommentDTO reportCommentDTO) {
|
||||||
|
return reportUserCommentService.commentPage(reportCommentDTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加评论
|
||||||
|
*/
|
||||||
|
@ApiOperation(value = "添加评论")
|
||||||
|
@PostMapping("/add")
|
||||||
|
public ResponseMessage rating(@Valid @RequestBody ReportCommentVo reportCommentVO) {
|
||||||
|
return reportUserCommentService.addComment(reportCommentVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除评论
|
||||||
|
*/
|
||||||
|
@ApiOperation(value = "删除评论")
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public ResponseMessage deleteComment(@PathVariable String id) {
|
||||||
|
return reportUserCommentService.deleteComment(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.adc.da.report.dao.mysql;
|
||||||
|
|
||||||
|
import com.adc.da.report.dto.ReportCommentDTO;
|
||||||
|
import com.adc.da.report.eo.ReportUserCommentEntity;
|
||||||
|
import com.adc.da.report.vo.ReportCommentVo;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ThinkBook
|
||||||
|
* @description 针对表【ts_report_user_comment】的数据库操作Mapper
|
||||||
|
* @createDate 2023-05-08 09:44:12
|
||||||
|
* @Entity com.adc.da.report.eo.ReportUserComment
|
||||||
|
*/
|
||||||
|
public interface ReportUserCommentDao extends BaseMapper<ReportUserCommentEntity> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评论列表
|
||||||
|
*
|
||||||
|
* @param page
|
||||||
|
* @param reportCommentDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
IPage<ReportCommentVo> page(IPage<ReportUserCommentEntity> page, @Param("dto") ReportCommentDTO reportCommentDTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.adc.da.report.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Min;
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: CaiHaohan
|
||||||
|
* @Date: 2023/5/8 11:13
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ReportCommentDTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报告id
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "报告id不能为空")
|
||||||
|
private String reportId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 页数
|
||||||
|
*/
|
||||||
|
@Min(1)
|
||||||
|
private Integer pageNo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每页数量
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
private Integer pageSize;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package com.adc.da.report.eo;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author CaiHaohan
|
||||||
|
* @TableName ts_report_user_comment
|
||||||
|
*/
|
||||||
|
@TableName(value ="ts_report_user_comment")
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class ReportUserCommentEntity implements Serializable {
|
||||||
|
/**
|
||||||
|
* 主键id
|
||||||
|
*/
|
||||||
|
@TableId(value = "id")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报告id
|
||||||
|
*/
|
||||||
|
@TableField(value = "report_id")
|
||||||
|
private String reportId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户id
|
||||||
|
*/
|
||||||
|
@TableField(value = "user_id")
|
||||||
|
private String userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评论
|
||||||
|
*/
|
||||||
|
@TableField(value = "comment")
|
||||||
|
private String comment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评论时间
|
||||||
|
*/
|
||||||
|
@TableField(value = "create_time")
|
||||||
|
private Date createTime;
|
||||||
|
/**
|
||||||
|
* 评论时间
|
||||||
|
*/
|
||||||
|
@TableField(value = "update_time")
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除标志(0 未删除 1 已删除)
|
||||||
|
*/
|
||||||
|
@TableField(value = "del_flag")
|
||||||
|
private Integer delFlag;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package com.adc.da.report.service;
|
||||||
|
|
||||||
|
import com.adc.da.report.dto.ReportCommentDTO;
|
||||||
|
import com.adc.da.report.eo.ReportUserCommentEntity;
|
||||||
|
import com.adc.da.report.vo.ReportCommentVo;
|
||||||
|
import com.adc.da.util.http.ResponseMessage;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ThinkBook
|
||||||
|
* @description 针对表【ts_report_user_comment】的数据库操作Service
|
||||||
|
* @createDate 2023-05-08 09:44:12
|
||||||
|
*/
|
||||||
|
public interface IReportUserCommentService extends IService<ReportUserCommentEntity> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页获取报表下的评论
|
||||||
|
* @param reportCommentDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ResponseMessage commentPage(ReportCommentDTO reportCommentDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加评论
|
||||||
|
* @param reportCommentVO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ResponseMessage addComment(ReportCommentVo reportCommentVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除评论
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ResponseMessage deleteComment(String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据评论id判断评论是否有效
|
||||||
|
* @param commentId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
boolean isCommentValid(String commentId);
|
||||||
|
}
|
||||||
+122
@@ -0,0 +1,122 @@
|
|||||||
|
package com.adc.da.report.service.impl;
|
||||||
|
|
||||||
|
import com.adc.da.login.util.UserUtils;
|
||||||
|
import com.adc.da.report.dao.mysql.ReportDao;
|
||||||
|
import com.adc.da.report.dto.ReportCommentDTO;
|
||||||
|
import com.adc.da.report.eo.ReportEntity;
|
||||||
|
import com.adc.da.report.vo.ReportCommentVo;
|
||||||
|
import com.adc.da.sys.util.BeanCopyUtils;
|
||||||
|
import com.adc.da.util.http.ResponseMessage;
|
||||||
|
import com.adc.da.util.http.Result;
|
||||||
|
import com.adc.da.util.utils.UUID;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.adc.da.report.eo.ReportUserCommentEntity;
|
||||||
|
import com.adc.da.report.service.IReportUserCommentService;
|
||||||
|
import com.adc.da.report.dao.mysql.ReportUserCommentDao;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ThinkBook
|
||||||
|
* @description 针对表【ts_report_user_comment】的数据库操作Service实现
|
||||||
|
* @createDate 2023-05-08 09:44:12
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class IReportUserCommentServiceImpl extends ServiceImpl<ReportUserCommentDao, ReportUserCommentEntity>
|
||||||
|
implements IReportUserCommentService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ReportDao reportDao;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ReportUserCommentDao reportUserCommentDao;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseMessage commentPage(ReportCommentDTO reportCommentDTO) {
|
||||||
|
//分页查询所需数据
|
||||||
|
IPage<ReportUserCommentEntity> page = new Page<>();
|
||||||
|
page.setCurrent(reportCommentDTO.getPageNo());
|
||||||
|
page.setSize(reportCommentDTO.getPageSize());
|
||||||
|
IPage<ReportCommentVo> list = reportUserCommentDao.page(page, reportCommentDTO);
|
||||||
|
|
||||||
|
//设置是否有删除权限
|
||||||
|
//报告上传者有所有评论的删除权限
|
||||||
|
boolean isUploader = false;
|
||||||
|
String curUserId = UserUtils.getUserId();
|
||||||
|
//查询报告的上传者
|
||||||
|
ReportEntity report = reportDao.selectById(reportCommentDTO.getReportId());
|
||||||
|
if (curUserId.equals(report.getCreateUserId())) {
|
||||||
|
isUploader = true;
|
||||||
|
}
|
||||||
|
//评论这只有自己评论的删除权限
|
||||||
|
if (isUploader) {
|
||||||
|
list.getRecords().forEach(reportCommentVo -> {
|
||||||
|
reportCommentVo.setDelPower(1);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
list.getRecords().forEach(reportCommentVo -> {
|
||||||
|
if (reportCommentVo.getUserId().equals(curUserId)) {
|
||||||
|
reportCommentVo.setDelPower(1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseMessage addComment(ReportCommentVo reportCommentVO) {
|
||||||
|
String curUserId = UserUtils.getUserId();
|
||||||
|
//不能重复评论
|
||||||
|
ReportUserCommentEntity comment = query().eq("del_flag", 0)
|
||||||
|
.eq("report_id", reportCommentVO.getReportId())
|
||||||
|
.eq("user_id", curUserId).one();
|
||||||
|
if (comment != null) {
|
||||||
|
return Result.error("无法重复评论");
|
||||||
|
}
|
||||||
|
ReportUserCommentEntity reportUserCommentEntity = BeanCopyUtils.copyBean(reportCommentVO, ReportUserCommentEntity.class);
|
||||||
|
reportUserCommentEntity.setUserId(curUserId)
|
||||||
|
.setId(UUID.randomUUID10())
|
||||||
|
.setCreateTime(new Date())
|
||||||
|
.setUpdateTime(new Date())
|
||||||
|
.setDelFlag(0);
|
||||||
|
save(reportUserCommentEntity);
|
||||||
|
return Result.success("评论成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseMessage deleteComment(String commentId) {
|
||||||
|
if (!isCommentValid(commentId)) {
|
||||||
|
return Result.error("刪除失败,id无效或评论已删除");
|
||||||
|
}
|
||||||
|
|
||||||
|
ReportUserCommentEntity comment = query().eq("del_flag", 0).eq("id", commentId).one();
|
||||||
|
ReportEntity report = reportDao.selectById(comment.getReportId());
|
||||||
|
//判断是否有权限删除
|
||||||
|
String currentUserId = UserUtils.getUserId();
|
||||||
|
if (!currentUserId.equals(comment.getUserId()) && !currentUserId.equals(report.getCreateUserId())) {
|
||||||
|
return Result.error("无权删除");
|
||||||
|
}
|
||||||
|
comment.setDelFlag(1);
|
||||||
|
updateById(comment);
|
||||||
|
return Result.success("删除成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据评论id判断评论是否有效
|
||||||
|
* @param commentId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isCommentValid(String commentId) {
|
||||||
|
ReportUserCommentEntity comment = query().eq("del_flag", 0).eq("id", commentId).one();
|
||||||
|
return comment != null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package com.adc.da.report.vo;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: CaiHaohan
|
||||||
|
* @Date: 2023/5/8 11:13
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class ReportCommentVo {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键id
|
||||||
|
*/
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报告id
|
||||||
|
*/
|
||||||
|
private String reportId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户id
|
||||||
|
*/
|
||||||
|
private String userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户id
|
||||||
|
*/
|
||||||
|
private String userName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门id
|
||||||
|
*/
|
||||||
|
private String orgId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门名
|
||||||
|
*/
|
||||||
|
private String orgName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评论
|
||||||
|
*/
|
||||||
|
private String comment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评论时间
|
||||||
|
*/
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除权限 0代表没有删除权限 1代表有
|
||||||
|
*/
|
||||||
|
private Integer delPower;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?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.adc.da.report.dao.mysql.ReportUserCommentDao">
|
||||||
|
|
||||||
|
<select id="page" resultType="com.adc.da.report.vo.ReportCommentVo">
|
||||||
|
SELECT
|
||||||
|
ruc.user_id AS userId,
|
||||||
|
u.USNAME AS userName,
|
||||||
|
ruc.comment AS comment,
|
||||||
|
ruc.create_time AS createTime,
|
||||||
|
o.ORG_NAME AS orgName
|
||||||
|
FROM
|
||||||
|
`ts_report_user_comment` AS ruc
|
||||||
|
INNER JOIN ts_user AS u ON u.USID = ruc.user_id
|
||||||
|
LEFT JOIN tr_user_org AS uo ON uo.USER_ID = ruc.user_id
|
||||||
|
LEFT JOIN ts_org AS o ON uo.ORG_ID = o.ID
|
||||||
|
WHERE
|
||||||
|
ruc.del_flag = 0
|
||||||
|
AND
|
||||||
|
ruc.report_id = #{dto.reportId}
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
Reference in New Issue
Block a user