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

This commit is contained in:
2023-05-10 11:05:38 +08:00
parent 78b5c3ba19
commit df0f813b52
3 changed files with 41 additions and 72 deletions
@@ -472,58 +472,7 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
idSet.add("1");
}
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));
}
}
IPage<ReportVo> list = reportDao.page(page, vo, idSet);
//设置权限
UserEO userEo = userEODao.selectById(UserUtils.getUserId());
@@ -117,8 +117,13 @@ public class ReportVo {
private Integer download;
/**
* 报告评级
* 创建人id
*/
private Double rating;
private String createUserId;
/**
* 创建人
*/
private String uploader;
}
@@ -94,27 +94,33 @@
<select id="page" resultType="com.adc.da.report.vo.ReportVo">
SELECT
eo.id,
eo.NAME,
eo.keycontent,
eo.maincontent,
eo.DEPARTMENT,
eo.YEAR,
eo.fileid,
eo.confidentialLevel,
eo.privacyLevel,
eo.createUserId,
tu.USNAME,
eo.createDate,
pa.report_id,
pa.user_id,
pa.power
eo.id AS id,
eo.`NAME` AS NAME,
eo.keycontent AS keyContent,
eo.maincontent AS mainContent,
eo.DEPARTMENT AS department,
eo.`YEAR` AS `year`,
eo.fileid AS fileId,
eo.confidentialLevel AS confidentialLevel,
eo.privacyLevel AS privacyLevel,
eo.createUserId AS createUserId,
tu.USNAME AS uploader,
eo.createDate AS createDate,
pa.power AS power,
thumbUpCount.thumbUp AS thumbUp,
clicksCount.clicks AS clicks,
downloadCount.download AS download,
AVG( trur.user_rating ) AS reportRating
FROM
TT_REPORT_MANAGE eo
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 tr_report_user ru ON eo.id = ru.reportId
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
eo.DEL_FLAG = 0
@@ -147,9 +153,18 @@
</if>
GROUP BY
eo.id
ORDER BY
eo.updateDate DESC
<if test="pageVO.orderByTime == 1">
ORDER BY
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 id="reportManagerPage" parameterType="com.adc.da.report.vo.ReportQueryVo" resultType="com.adc.da.report.vo.ReportVo">