Revert "perf:报告查询接口性能提升"

This reverts commit df0f813b52.
This commit is contained in:
2023-05-10 15:42:29 +08:00
parent 5bbd264ff3
commit fe3213946f
3 changed files with 72 additions and 41 deletions
@@ -472,7 +472,58 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
idSet.add("1"); idSet.add("1");
} }
IPage<ReportVo> list = reportDao.page(page, vo, idSet); IPage<ReportVo> list = reportDao.page(page, vo,idSet);
//查询下载量
list.getRecords().forEach(c -> {
Integer downloadCount = reportLogBookService.getDownloadCount(c.getId());
c.setDownload(downloadCount);
});
//查询点击量
list.getRecords().forEach(c -> {
Integer clickCount = reportLogBookService.getClickCount(c.getId());
c.setClicks(clickCount);
});
//查询点赞量
list.getRecords().forEach(c -> {
Integer thumbUpCount = reportLogBookService.getThumbUpCount(c.getId());
c.setThumbUp(thumbUpCount);
});
//查询报告评级
list.getRecords().forEach(c -> {
Double ratingAvg = reportUserRatingService.getRatingAvg(c.getId());
c.setRating(ratingAvg);
});
//按查询条件排序
//按时间排序
if (vo.getOrderByTime() != null) {
if (vo.getOrderByTime().equals(0)) {
list.getRecords().sort(Comparator.comparing(ReportVo::getCreateDate).reversed());
}
if (vo.getOrderByTime().equals(1)) {
list.getRecords().sort(Comparator.comparing(ReportVo::getCreateDate));
}
}
//按点击量排序
if (vo.getOrderByClicks() != null) {
if (vo.getOrderByClicks().equals(0)) {
list.getRecords().sort(Comparator.comparing(ReportVo::getClicks).reversed());
}
if (vo.getOrderByClicks().equals(1)) {
list.getRecords().sort(Comparator.comparing(ReportVo::getClicks));
}
}
//按下载量排序
if (vo.getOrderByDownload() != null) {
if (vo.getOrderByDownload().equals(0)) {
list.getRecords().sort(Comparator.comparing(ReportVo::getDownload).reversed());
}
if (vo.getOrderByDownload().equals(1)) {
list.getRecords().sort(Comparator.comparing(ReportVo::getDownload));
}
}
//设置权限 //设置权限
UserEO userEo = userEODao.selectById(UserUtils.getUserId()); UserEO userEo = userEODao.selectById(UserUtils.getUserId());
@@ -117,13 +117,8 @@ public class ReportVo {
private Integer download; private Integer download;
/** /**
* 创建人id * 报告评级
*/ */
private String createUserId; private Double rating;
/**
* 创建人
*/
private String uploader;
} }
@@ -94,33 +94,27 @@
<select id="page" resultType="com.adc.da.report.vo.ReportVo"> <select id="page" resultType="com.adc.da.report.vo.ReportVo">
SELECT SELECT
eo.id AS id, eo.id,
eo.`NAME` AS NAME, eo.NAME,
eo.keycontent AS keyContent, eo.keycontent,
eo.maincontent AS mainContent, eo.maincontent,
eo.DEPARTMENT AS department, eo.DEPARTMENT,
eo.`YEAR` AS `year`, eo.YEAR,
eo.fileid AS fileId, eo.fileid,
eo.confidentialLevel AS confidentialLevel, eo.confidentialLevel,
eo.privacyLevel AS privacyLevel, eo.privacyLevel,
eo.createUserId AS createUserId, eo.createUserId,
tu.USNAME AS uploader, tu.USNAME,
eo.createDate AS createDate, eo.createDate,
pa.power AS power, pa.report_id,
thumbUpCount.thumbUp AS thumbUp, pa.user_id,
clicksCount.clicks AS clicks, pa.power
downloadCount.download AS download,
AVG( trur.user_rating ) AS reportRating
FROM FROM
TT_REPORT_MANAGE eo TT_REPORT_MANAGE eo
INNER JOIN ts_report_label AS trl ON eo.id = trl.report_id INNER JOIN ts_report_label AS trl ON eo.id = trl.report_id
LEFT JOIN ts_user tu ON tu.USID = eo.createUserId LEFT JOIN ts_user tu ON tu.USID = eo.createUserId
LEFT JOIN tr_report_user ru ON eo.id = ru.reportId LEFT JOIN tr_report_user ru ON eo.id = ru.reportId
LEFT JOIN power_apply pa ON pa.report_id = eo.id LEFT JOIN power_apply pa ON pa.report_id = eo.id
LEFT JOIN (SELECT report_id, COUNT(id) AS thumbUp FROM report_log_book WHERE type = 3 GROUP BY report_id) AS thumbUpCount ON eo.id = thumbUpCount.report_id
LEFT JOIN (SELECT report_id, COUNT(id) AS clicks FROM report_log_book WHERE type = 4 GROUP BY report_id) AS clicksCount ON eo.id = clicksCount.report_id
LEFT JOIN (SELECT report_id, COUNT(id) AS download FROM report_log_book WHERE type = 2 GROUP BY report_id) AS downloadCount ON eo.id = downloadCount.report_id
LEFT JOIN ts_report_user_rating AS trur ON eo.id = trur.report_id
WHERE WHERE
eo.DEL_FLAG = 0 eo.DEL_FLAG = 0
@@ -153,18 +147,9 @@
</if> </if>
GROUP BY GROUP BY
eo.id eo.id
<if test="pageVO.orderByTime == 1"> ORDER BY
ORDER BY eo.updateDate DESC
eo.createDate DESC
</if>
<if test="pageVO.orderByClicks == 1">
ORDER BY
clicksCount.clicks DESC
</if>
<if test="pageVO.orderByDownload == 1">
ORDER BY
downloadCount.download DESC
</if>
</select> </select>
<select id="reportManagerPage" parameterType="com.adc.da.report.vo.ReportQueryVo" resultType="com.adc.da.report.vo.ReportVo"> <select id="reportManagerPage" parameterType="com.adc.da.report.vo.ReportQueryVo" resultType="com.adc.da.report.vo.ReportVo">