diff --git a/adc-da-report/src/main/java/com/adc/da/report/constant/PowerApplyConstants.java b/adc-da-report/src/main/java/com/adc/da/report/constant/PowerApplyConstants.java new file mode 100644 index 0000000..28cca1b --- /dev/null +++ b/adc-da-report/src/main/java/com/adc/da/report/constant/PowerApplyConstants.java @@ -0,0 +1,29 @@ +package com.adc.da.report.constant; + +/** + * @author: CaiHaohan + * @Date: 2023/5/9 14:50 + * @Description: power_apply表power字段对应的权限 + */ +public class PowerApplyConstants { + + /** + * 无权限 + */ + public static final Integer NONE = 0; + + /** + * 预览权限 + */ + public static final Integer PREVIEW = 1; + + /** + * 预览 + 下载 + */ + public static final Integer PREVIEW_DOWNLOAD = 2; + + /** + * 下载权限 + */ + public static final Integer DOWNLOAD = 3; +} diff --git a/adc-da-report/src/main/java/com/adc/da/report/constant/ReportConstants.java b/adc-da-report/src/main/java/com/adc/da/report/constant/ReportConstants.java index d1a2e3b..32ab008 100644 --- a/adc-da-report/src/main/java/com/adc/da/report/constant/ReportConstants.java +++ b/adc-da-report/src/main/java/com/adc/da/report/constant/ReportConstants.java @@ -13,4 +13,16 @@ public class ReportConstants { public static final String FILE_EXTENSIONS_PPTX = "pptx"; public static final String FILE_EXTENSIONS_PDF = "pdf"; + /** + * 公开报告(内部公开) + */ + public static final String PUBLIC_REPORT = "公开"; + + /** + * 不涉及用户隐私 + */ + public static final String NO_USER_PRIVACY_INVOLVED = "不涉及用户隐私"; + + + } diff --git a/adc-da-report/src/main/java/com/adc/da/report/controller/ReportLogBookController.java b/adc-da-report/src/main/java/com/adc/da/report/controller/ReportLogBookController.java index c74e02a..0759e92 100644 --- a/adc-da-report/src/main/java/com/adc/da/report/controller/ReportLogBookController.java +++ b/adc-da-report/src/main/java/com/adc/da/report/controller/ReportLogBookController.java @@ -124,7 +124,7 @@ public class ReportLogBookController { public ResponseMessage getThumbUpCount(String reportId){ //根据报告id和当前登录用户id获取点赞数 - ReportDetailThumbUpVo result = reportLogBookService.getThumbUpCount(reportId); + ReportDetailThumbUpVo result = reportLogBookService.thumbUpCount(reportId); return Result.success(result); } diff --git a/adc-da-report/src/main/java/com/adc/da/report/controller/ReportRatingController.java b/adc-da-report/src/main/java/com/adc/da/report/controller/ReportRatingController.java index cfe6281..b9ee310 100644 --- a/adc-da-report/src/main/java/com/adc/da/report/controller/ReportRatingController.java +++ b/adc-da-report/src/main/java/com/adc/da/report/controller/ReportRatingController.java @@ -35,7 +35,7 @@ public class ReportRatingController { /** * 获取报告评分 */ - @ApiOperation(value = "给报告评分") + @ApiOperation(value = "获取报告评分") @GetMapping("/rating") public ResponseMessage getRating(String reportId) { return reportUserRatingService.getRating(reportId); diff --git a/adc-da-report/src/main/java/com/adc/da/report/service/IReportLogBookService.java b/adc-da-report/src/main/java/com/adc/da/report/service/IReportLogBookService.java index 34dfb47..3f72548 100644 --- a/adc-da-report/src/main/java/com/adc/da/report/service/IReportLogBookService.java +++ b/adc-da-report/src/main/java/com/adc/da/report/service/IReportLogBookService.java @@ -32,7 +32,7 @@ public interface IReportLogBookService { * @param reportId * @return */ - ReportDetailThumbUpVo getThumbUpCount(String reportId); + ReportDetailThumbUpVo thumbUpCount(String reportId); /** * 点赞或者取消点赞 @@ -41,4 +41,34 @@ public interface IReportLogBookService { * @return */ ReportDetailThumbUpVo thumbUpOrDown(String reportId); + + + /** + * 获取点击量 + * @param reportId + * @return + */ + Integer getClickCount(String reportId); + + /** + * 获取下载量 + * @param reportId + * @return + */ + Integer getDownloadCount(String reportId); + + /** + * 获取预览量 + * @param reportId + * @return + */ + Integer getPreviewCount(String reportId); + + /** + * 获取点赞量 + * @param reportId + * @return + */ + Integer getThumbUpCount(String reportId); + } diff --git a/adc-da-report/src/main/java/com/adc/da/report/service/impl/IReportLogBookServiceImpl.java b/adc-da-report/src/main/java/com/adc/da/report/service/impl/IReportLogBookServiceImpl.java index 90b1b72..bebeb22 100644 --- a/adc-da-report/src/main/java/com/adc/da/report/service/impl/IReportLogBookServiceImpl.java +++ b/adc-da-report/src/main/java/com/adc/da/report/service/impl/IReportLogBookServiceImpl.java @@ -113,7 +113,7 @@ public class IReportLogBookServiceImpl extends ServiceImpl return list; } +// @Override +// public IPage page(ReportQueryVo vo) { +// IPage page = new Page<>(); +// page.setCurrent(vo.getPageNo()); +// page.setSize(vo.getPageSize()); +// //判断是不是管理员 +// boolean admin = false; +// List roleEOList = roleEODao.selectByuserId(UserUtils.getUserId()); +// for (RoleEO roleEO : roleEOList) { +// if ("管理员".equals(roleEO.getName())){ +// admin= !admin; +// } +// } +// if (admin) { +// vo.setUsid(null); +// } else { +// vo.setUsid(UserUtils.getUserId()); +// } +// +// //按照labelId筛选 +// Set idSet = new HashSet<>(); +// if (Objects.nonNull(vo.getLabelId()) && !vo.getLabelId().isEmpty()) { +// LambdaQueryWrapper reportLabelEntityWrapper = new LambdaQueryWrapper<>(); +// reportLabelEntityWrapper.in(ReportLabelEntity::getLabelId, vo.getLabelId()); +// List reportLabelEntities = reportLabelDao.selectList(reportLabelEntityWrapper); +// reportLabelEntities.forEach(reportLabelEntity -> { +// idSet.add(reportLabelEntity.getReportId()); +// }); +// idSet.add("1"); +// } +// +// +// IPage list = reportDao.page(page, vo,idSet); +// //获取所有报告的labelId +// list.getRecords().forEach((reportVo) -> { +// reportVo.setLabelList(findLabelList(reportVo.getId())); +// }); +// list.getRecords().forEach(c -> { +// FileEntity fileEntity = Optional.ofNullable(fileDao.selectById(c.getFileId())).orElse(new FileEntity()); +// if (StringUtils.isEmpty(fileEntity.getFileType())) { +// c.setFileType(null); +// } +// //ppt文件 +// else if (ReportConstants.FILE_EXTENSIONS_PPT.equalsIgnoreCase(fileEntity.getFileType()) || +// ReportConstants.FILE_EXTENSIONS_PPTX.equalsIgnoreCase(fileEntity.getFileType())) { +// c.setFileType("1"); +// } +// //excel文件 +// else if (ReportConstants.FILE_EXTENSIONS_XLS.equalsIgnoreCase(fileEntity.getFileType()) || +// ReportConstants.FILE_EXTENSIONS_XLSX.equalsIgnoreCase(fileEntity.getFileType())) { +// c.setFileType("2"); +// } +// //pdf文件 +// else if (ReportConstants.FILE_EXTENSIONS_PDF.equalsIgnoreCase(fileEntity.getFileType())) { +// c.setFileType("3"); +// } +// //word文件 +// else { +// c.setFileType("4"); +// } +// +// //文件大小 +// c.setFileSize(StringUtils.isNotEmpty(fileEntity.getFileSize()) +// ? String.valueOf(Integer.parseInt(fileEntity.getFileSize()) / 1024) + "kb" : "0kb"); +// c.setFileName(fileEntity.getFileName()); +// List userIdList = reportUserDao.selectList( +// new QueryWrapper().eq("reportId", c.getId())) +// .stream().map(ReportUserEntity::getUserId).collect(Collectors.toList()); +// }); +// return list; +// } + @Override public IPage page(ReportQueryVo vo) { IPage page = new Page<>(); page.setCurrent(vo.getPageNo()); page.setSize(vo.getPageSize()); - //判断是不是管理员 - boolean admin = false; - List roleEOList = roleEODao.selectByuserId(UserUtils.getUserId()); - for (RoleEO roleEO : roleEOList) { - if ("管理员".equals(roleEO.getName())){ - admin= !admin; - } - } - if (admin) { - vo.setUsid(null); - } else { - vo.setUsid(UserUtils.getUserId()); - } //按照labelId筛选 Set idSet = new HashSet<>(); @@ -409,12 +472,81 @@ public class IReportServiceImpl extends ServiceImpl idSet.add("1"); } - IPage list = reportDao.page(page, vo,idSet); - //获取所有报告的labelId - list.getRecords().forEach((reportVo) -> { - reportVo.setLabelList(findLabelList(reportVo.getId())); + + //查询下载量 + 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()); + String levelId = userEo.getLevelId() == null ? "1.0" : userEo.getLevelId(); + //用户级别 + double level = Double.parseDouble(levelId); + //总监拥有全部报告的预览和下载权力 + if (level <= 0.5) { + list.getRecords().forEach(reportVo -> { + reportVo.setPower(PREVIEW_DOWNLOAD); + }); + } else { + list.getRecords().forEach(reportVo -> { + //其余人员只能预览公开报告(涉密等级:公开(内部公开)、隐私等级:不涉及用户隐私) + if (reportVo.getConfidentialLevel().equals(PUBLIC_REPORT) && + reportVo.getPrivacyLevel().equals(NO_USER_PRIVACY_INVOLVED)) { + reportVo.setPower(PREVIEW); + } else { + reportVo.setPower(NONE); + } + }); + } + list.getRecords().forEach(c -> { FileEntity fileEntity = Optional.ofNullable(fileDao.selectById(c.getFileId())).orElse(new FileEntity()); if (StringUtils.isEmpty(fileEntity.getFileType())) { diff --git a/adc-da-report/src/main/java/com/adc/da/report/service/impl/IReportUserRatingServiceImpl.java b/adc-da-report/src/main/java/com/adc/da/report/service/impl/IReportUserRatingServiceImpl.java index bd17d6b..f758452 100644 --- a/adc-da-report/src/main/java/com/adc/da/report/service/impl/IReportUserRatingServiceImpl.java +++ b/adc-da-report/src/main/java/com/adc/da/report/service/impl/IReportUserRatingServiceImpl.java @@ -62,8 +62,12 @@ public class IReportUserRatingServiceImpl extends ServiceImpl wrapper = new QueryWrapper<>(); + wrapper.eq("report_id", reportId); wrapper.select("AVG(user_rating) as user_rating"); List> result = reportUserRatingDao.selectMaps(wrapper); + if (result.get(0) == null) { + return 0.0; + } BigDecimal userRating = (BigDecimal) result.get(0).get("user_rating"); return userRating.doubleValue(); } diff --git a/adc-da-report/src/main/java/com/adc/da/report/vo/ReportDetailVo.java b/adc-da-report/src/main/java/com/adc/da/report/vo/ReportDetailVo.java index 73cbb28..a70417c 100644 --- a/adc-da-report/src/main/java/com/adc/da/report/vo/ReportDetailVo.java +++ b/adc-da-report/src/main/java/com/adc/da/report/vo/ReportDetailVo.java @@ -1,8 +1,5 @@ package com.adc.da.report.vo; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -95,4 +92,9 @@ public class ReportDetailVo { * 下载权限(0没有1有) */ private Integer downPower; + + /** + * 用户权限级别 + */ + private Double levelId; } diff --git a/adc-da-report/src/main/java/com/adc/da/report/vo/ReportQueryVo.java b/adc-da-report/src/main/java/com/adc/da/report/vo/ReportQueryVo.java index 9bd774c..0023d07 100644 --- a/adc-da-report/src/main/java/com/adc/da/report/vo/ReportQueryVo.java +++ b/adc-da-report/src/main/java/com/adc/da/report/vo/ReportQueryVo.java @@ -21,31 +21,47 @@ public class ReportQueryVo { */ private int pageSize; - /** - * 报告名称 - */ - private String name; - /** * 全文模糊检索的关键词 */ private String keyContent; - /** - * 标签集合 - */ - private List labelId; - /** * 年 */ private List year; + /** + * 报告名称 + */ + private String name; + + /** + * 标签集合 + */ + private List labelId; + + /** + * 按时间排序(0代表最新发布的排名最前 1相反) + */ + private Integer orderByTime; + + /** + * 按点击量排序(0代表点击量最多的报告排序在最前 1相反) + */ + private Integer orderByClicks; + + /** + * 按下载量排序(0代表下载量最多的报告排名最前 1相反) + */ + private Integer orderByDownload; + /** * 用户id */ private String usid; + private List ids; // diff --git a/adc-da-report/src/main/java/com/adc/da/report/vo/ReportVo.java b/adc-da-report/src/main/java/com/adc/da/report/vo/ReportVo.java index e7cd7aa..f324e34 100644 --- a/adc-da-report/src/main/java/com/adc/da/report/vo/ReportVo.java +++ b/adc-da-report/src/main/java/com/adc/da/report/vo/ReportVo.java @@ -30,6 +30,7 @@ public class ReportVo { * 权限 */ private Integer power; + /** * 主要内容 */ @@ -94,4 +95,30 @@ public class ReportVo { * 文件大小 */ private String fileSize; + + /** + * 报告评级 + */ + private Integer reportRating; + + /** + * 点赞数 + */ + private Integer thumbUp; + + /** + * 点击量 + */ + private Integer clicks; + + /** + * 下载量 + */ + private Integer download; + + /** + * 报告评级 + */ + private Double rating; + } diff --git a/adc-da-report/src/main/resources/mybatis/mapper/mysql/ReportManageMapper.xml b/adc-da-report/src/main/resources/mybatis/mapper/mysql/ReportManageMapper.xml index 64cb910..0654f84 100644 --- a/adc-da-report/src/main/resources/mybatis/mapper/mysql/ReportManageMapper.xml +++ b/adc-da-report/src/main/resources/mybatis/mapper/mysql/ReportManageMapper.xml @@ -103,22 +103,21 @@ eo.fileid, eo.confidentialLevel, eo.privacyLevel, + eo.createUserId, + tu.USNAME, + eo.createDate, pa.report_id, pa.user_id, pa.power 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 WHERE eo.DEL_FLAG = 0 - - and (ru.userId = #{pageVO.usid} - or eo.id in ( - SELECT tt.report_id from power_apply tt WHERE tt.user_id = #{pageVO.usid}) - ) - + and name like CONCAT(CONCAT('%',#{pageVO.name}),'%') @@ -243,7 +242,7 @@ rm.confidentialLevel AS confidentialLevel, rm.privacyLevel AS privacyLevel FROM `tt_report_manage` AS rm - INNER JOIN ts_user AS u ON u.USID = rm.createUserId + LEFT JOIN ts_user AS u ON u.USID = rm.createUserId WHERE rm.id = #{reportId} AND rm.del_flag = 0