feat:报表评分
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package com.adc.da.report.controller;
|
||||
|
||||
import com.adc.da.report.dto.ReportRatingDTO;
|
||||
import com.adc.da.report.service.IReportUserRatingService;
|
||||
import com.adc.da.util.http.ResponseMessage;
|
||||
import com.adc.da.util.http.Result;
|
||||
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-rating")
|
||||
public class ReportRatingController {
|
||||
|
||||
@Resource
|
||||
private IReportUserRatingService reportUserRatingService;
|
||||
|
||||
/**
|
||||
* 给报告评分
|
||||
*/
|
||||
@ApiOperation(value = "给报告评分")
|
||||
@PutMapping("/rating")
|
||||
public ResponseMessage rating(@Valid ReportRatingDTO reportRatingDTO) {
|
||||
return reportUserRatingService.rating(reportRatingDTO);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.adc.da.report.dao.mysql;
|
||||
|
||||
import com.adc.da.report.eo.ReportUserRatingEntity;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author ThinkBook
|
||||
* @description 针对表【ts_report_user_rating】的数据库操作Mapper
|
||||
* @createDate 2023-05-06 17:03:31
|
||||
* @Entity com.adc.da.report.eo.ReportUserRating
|
||||
*/
|
||||
public interface ReportUserRatingDao extends BaseMapper<ReportUserRatingEntity> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.adc.da.report.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
/**
|
||||
* @author: CaiHaohan
|
||||
* @Date: 2023/5/6 17:18
|
||||
* @Description:
|
||||
*/
|
||||
@Data
|
||||
public class ReportRatingDTO {
|
||||
|
||||
@NotBlank(message = "报表Id不能为空")
|
||||
private String reportId;
|
||||
|
||||
@Min(value = 1, message = "最小评分为1分")
|
||||
@Max(value = 10, message = "最大评分为10分")
|
||||
private Integer userRating;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.adc.da.report.eo;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* @author CaiHaohan
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
@TableName("ts_report_user_rating")
|
||||
public class ReportUserRatingEntity implements Serializable {
|
||||
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.INPUT)
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 报告id
|
||||
*/
|
||||
@TableField("report_id")
|
||||
private String reportId;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@TableField("user_id")
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 评分(1-5)
|
||||
*/
|
||||
@TableField("user_rating")
|
||||
private Integer userRating;
|
||||
|
||||
private static final long serialVersionUID = 12314234142312314L;
|
||||
}
|
||||
@@ -51,4 +51,12 @@ public interface IReportService {
|
||||
IPage<ReportVo> reportManagerPage(ReportQueryVo vo);
|
||||
|
||||
List<String> isAct(ReportQueryVo vo);
|
||||
|
||||
/**
|
||||
* 判断报告是否删除
|
||||
*
|
||||
* @param reportId
|
||||
* @return
|
||||
*/
|
||||
boolean isReportValid(String reportId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.adc.da.report.service;
|
||||
|
||||
|
||||
import com.adc.da.report.dto.ReportRatingDTO;
|
||||
import com.adc.da.report.eo.ReportUserRatingEntity;
|
||||
import com.adc.da.util.http.ResponseMessage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author ThinkBook
|
||||
* @description 针对表【ts_report_user_rating】的数据库操作Service
|
||||
* @createDate 2023-05-06 17:03:31
|
||||
*/
|
||||
public interface IReportUserRatingService extends IService<ReportUserRatingEntity> {
|
||||
|
||||
/**
|
||||
* 评分
|
||||
* @param reportRatingDTO
|
||||
* @return
|
||||
*/
|
||||
ResponseMessage rating(ReportRatingDTO reportRatingDTO);
|
||||
|
||||
/**
|
||||
* 获取报告的平均分
|
||||
* @param reportId
|
||||
* @return
|
||||
*/
|
||||
Double getRatingAvg(String reportId);
|
||||
}
|
||||
@@ -526,6 +526,12 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
|
||||
return act;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReportValid(String reportId) {
|
||||
ReportEntity report = query().eq("del_flag", 0).eq("id", reportId).one();
|
||||
return report != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建htmlstring
|
||||
*
|
||||
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
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.ReportRatingDTO;
|
||||
import com.adc.da.report.eo.ReportUserRatingEntity;
|
||||
import com.adc.da.report.service.IReportService;
|
||||
import com.adc.da.report.service.IReportUserRatingService;
|
||||
import com.adc.da.report.dao.mysql.ReportUserRatingDao;
|
||||
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.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author ThinkBook
|
||||
* @description 针对表【ts_report_user_rating】的数据库操作Service实现
|
||||
* @createDate 2023-05-06 17:03:31
|
||||
*/
|
||||
@Service
|
||||
public class IReportUserRatingServiceImpl extends ServiceImpl<ReportUserRatingDao, ReportUserRatingEntity>
|
||||
implements IReportUserRatingService {
|
||||
|
||||
@Resource
|
||||
private ReportUserRatingDao reportUserRatingDao;
|
||||
|
||||
@Resource
|
||||
private IReportService reportService;
|
||||
|
||||
@Override
|
||||
public ResponseMessage rating(ReportRatingDTO reportRatingDTO) {
|
||||
if(!reportService.isReportValid(reportRatingDTO.getReportId())){
|
||||
return Result.error("此报告已失效");
|
||||
}
|
||||
//查询是否是初次评分
|
||||
ReportUserRatingEntity one = query().eq("report_id", reportRatingDTO.getReportId())
|
||||
.eq("user_id", UserUtils.getUserId())
|
||||
.one();
|
||||
ReportUserRatingEntity reportUserRatingEntity = BeanCopyUtils.copyBean(reportRatingDTO, ReportUserRatingEntity.class);
|
||||
//初次评分
|
||||
if (one == null) {
|
||||
reportUserRatingEntity
|
||||
.setId(UUID.randomUUID10())
|
||||
.setUserId(UserUtils.getUserId());
|
||||
save(reportUserRatingEntity);
|
||||
return Result.success("操作成功");
|
||||
}
|
||||
reportUserRatingEntity.setId(one.getId());
|
||||
updateById(reportUserRatingEntity);
|
||||
return Result.success("操作成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getRatingAvg(String reportId) {
|
||||
QueryWrapper<ReportUserRatingEntity> wrapper = new QueryWrapper<>();
|
||||
wrapper.select("AVG(user_rating) as user_rating");
|
||||
List<Map<String, Object>> result = reportUserRatingDao.selectMaps(wrapper);
|
||||
BigDecimal userRating = (BigDecimal) result.get(0).get("user_rating");
|
||||
return userRating.doubleValue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user