diff --git a/servers/boe-server-all/src/main/java/com/xboe/api/ThirdApi.java b/servers/boe-server-all/src/main/java/com/xboe/api/ThirdApi.java index ab24658d..91d9204b 100644 --- a/servers/boe-server-all/src/main/java/com/xboe/api/ThirdApi.java +++ b/servers/boe-server-all/src/main/java/com/xboe/api/ThirdApi.java @@ -281,7 +281,10 @@ public class ThirdApi { JSONUtil.toBean(resp, SyncExamScoreBean.class).success(); } - public UserDynamicResult getAllUserdynamicList2(UserdynamicParam userdynamicParam, String token) { + /** + * 获取案例浏览记录 + */ + public UserDynamicResult getAllUserdynamicListOfCaseRead(UserdynamicParam userdynamicParam, String token) { String s = buildFormData(userdynamicParam); String resp = Optional.ofNullable(HttpRequest .post(userdynamicListUrl) diff --git a/servers/boe-server-all/src/main/java/com/xboe/enums/CasesRankEnum.java b/servers/boe-server-all/src/main/java/com/xboe/enums/CasesRankEnum.java index 302f692d..ce570db2 100644 --- a/servers/boe-server-all/src/main/java/com/xboe/enums/CasesRankEnum.java +++ b/servers/boe-server-all/src/main/java/com/xboe/enums/CasesRankEnum.java @@ -5,7 +5,9 @@ import lombok.Getter; import static com.xboe.constants.CacheName.*; - +/** + * 案例排行榜类型 + */ @AllArgsConstructor @Getter public enum CasesRankEnum { diff --git a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/api/CasesApi.java b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/api/CasesApi.java index 4775b74c..441923e1 100644 --- a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/api/CasesApi.java +++ b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/api/CasesApi.java @@ -638,6 +638,7 @@ public class CasesApi extends ApiBaseController { /** * 不同专业分类下排行榜刷新 + * 注意!!!定时统计任务是在本月月初执行的,而上榜时间是在上个月最后一天23:59:59 */ @PostMapping("/refreshViewsRankOfMajor") public JsonResponse refreshViewsRankOfMajor() { @@ -694,7 +695,7 @@ public class CasesApi extends ApiBaseController { /** - * 不同专业月热度榜查询所需时间检索数据 + * 所有上榜的的(专业ID-时间), 用于下拉框.优化可将majorName一并查询,返回为List> todo by anyone */ @GetMapping("/queryAllTimePopularityOfMajor") public JsonResponse>> queryAllTimePopularityOfMajor() { diff --git a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/entity/Cases.java b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/entity/Cases.java index 9d1552e4..aa8fd353 100644 --- a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/entity/Cases.java +++ b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/entity/Cases.java @@ -418,7 +418,43 @@ public class Cases extends BaseEntity { this.title=title; } public Cases(String id,String title,String summary,String coverUrl,String authorId,String authorName,LocalDateTime sysCreateTime,Integer breCommend,Integer views,Integer comments,Integer praises,Integer shares,Integer favorites,Boolean deleted - ,String sysCreateBy,String sysCreateAid,String keyword1,String keyword2,String keyword3,String keyword4,String keyword5){ + ,String sysCreateBy,String sysCreateAid){ + this.title=title; + super.setId(id); + this.authorId=authorId; + this.authorName=authorName; + super.setSysCreateTime(sysCreateTime); + super.setSysCreateAid(sysCreateAid); + super.setSysCreateBy(sysCreateBy); + this.summary=summary; + this.coverUrl=coverUrl; + this.breCommend=breCommend; + this.views=views; + this.comments=comments; + this.praises=praises; + this.shares=shares; + this.favorites=favorites; + super.setDeleted(deleted); + } + public Cases(String title) { + this.title = title; + } + + public Cases(String title,String authorName, int comments, int views, int praises, int shares, int favorites, Long recommends1, int cites, String confidentialityLevel) { + this.title = title; + this.views = views; + this.praises = praises; + this.shares = shares; + this.favorites = favorites; + this.recommends1 = recommends1; + this.cites = cites; + this.comments = comments; + this.authorName = authorName; + this.confidentialityLevel = confidentialityLevel; + } + + public Cases(String id,String title,String summary,String coverUrl,String authorId,String authorName,LocalDateTime sysCreateTime,Integer breCommend,Integer views,Integer comments,Integer praises,Integer shares,Integer favorites,Boolean deleted + ,String sysCreateBy,String sysCreateAid,String keyword1,String keyword2,String keyword3,String keyword4,String keyword5){ this.title=title; super.setId(id); this.authorId=authorId; @@ -441,21 +477,4 @@ public class Cases extends BaseEntity { this.keyword5=keyword5; super.setDeleted(deleted); } - - public Cases(String title) { - this.title = title; - } - - public Cases(String title,String authorName, int comments, int views, int praises, int shares, int favorites, Long recommends1, int cites, String confidentialityLevel) { - this.title = title; - this.views = views; - this.praises = praises; - this.shares = shares; - this.favorites = favorites; - this.recommends1 = recommends1; - this.cites = cites; - this.comments = comments; - this.authorName = authorName; - this.confidentialityLevel = confidentialityLevel; - } } diff --git a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/entity/CasesRecommend.java b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/entity/CasesRecommend.java index 69ee2247..25dbcfdd 100644 --- a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/entity/CasesRecommend.java +++ b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/entity/CasesRecommend.java @@ -54,6 +54,12 @@ public class CasesRecommend extends BaseEntity { public CasesRecommend() { } + + public CasesRecommend(String id, String recommendOrgName) { + this.setId(id); + this.recommendOrgName = recommendOrgName; + } + public CasesRecommend(String id, String recommendOrgName,LocalDateTime recommendTime) { this.setId(id); this.recommendOrgName = recommendOrgName; diff --git a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/service/impl/CasesServiceImpl.java b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/service/impl/CasesServiceImpl.java index 846d152d..7a0b6034 100644 --- a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/service/impl/CasesServiceImpl.java +++ b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/service/impl/CasesServiceImpl.java @@ -30,7 +30,6 @@ import com.xboe.orm.CustomFieldInFilter; import com.xboe.school.vo.CasesVo; import com.xboe.standard.enums.BoedxResourceType; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; @@ -46,6 +45,7 @@ import javax.servlet.http.HttpServletRequest; import java.lang.reflect.Array; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.time.temporal.TemporalAdjusters; import java.util.*; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -1163,11 +1163,15 @@ public class CasesServiceImpl implements ICasesService { @Override @Transactional(rollbackFor = Exception.class) public void refreshViewsRankOfMajor(){ -// LocalDateTime riseRankTime = LocalDateTime.now().withDayOfMonth(1).minusDays(1).toLocalDate().atTime(23, 59, 59); // 上月最后一天的结束时间 - LocalDateTime riseRankTime = LocalDateTime.now().minusMonths(1).minusDays(1).toLocalDate().atTime(23, 59, 59); // 上月最后一天的结束时间 - int count = casesRankDao.sqlCount("SELECT count(1) FROM boe_cases_rank WHERE deleted=0 AND rise_rank_time = ?1", riseRankTime); + // 获取上个月的第一天的00:00 +// LocalDateTime firstDayOfLastMonth = LocalDateTime.now().minusMonths(1).with(TemporalAdjusters.firstDayOfMonth()).toLocalDate().atStartOfDay(); + // 获取上个月的最后一天的23:59:59,将其设置为上榜时间。注意,定时统计任务是在本月月初执行的,而上榜时间是在上个月最后一天23:59:59 + LocalDateTime lastDayOfLastMonth = LocalDateTime.now().minusMonths(1).with(TemporalAdjusters.lastDayOfMonth()).toLocalDate().atTime(23, 59, 59); // 设置为当天的几乎结束时刻 + + int count = casesRankDao.sqlCount("SELECT count(1) FROM boe_cases_rank WHERE deleted=0 AND rise_rank_time = ?1" , lastDayOfLastMonth); if (count > 0){ - return; + log.info("已生成上个月排行榜数据,本次不执行"); + throw new RuntimeException("已生成上个月排行榜数据,请将上月排行榜数据删除"); } //获取案例当月排名 @@ -1184,7 +1188,7 @@ public class CasesServiceImpl implements ICasesService { casesRank.setCaseId(Long.valueOf(Array.get(o, 0).toString())); casesRank.setMajorId(Long.valueOf(Array.get(o, 1).toString())); casesRank.setMonthlyIncrement(Integer.parseInt(Array.get(o, 2).toString())); - casesRank.setRiseRankTime(riseRankTime); + casesRank.setRiseRankTime(lastDayOfLastMonth); return casesRank; }).collect(Collectors.toList()); // 根据专业分类进行分组 @@ -1202,8 +1206,9 @@ public class CasesServiceImpl implements ICasesService { lastMonthRank.addAll(sortedCaseList); }); - casesRankDao.saveList(lastMonthRank); + casesRankDao.saveList(lastMonthRank); + // 重置上月观看量:last_month_views casesDao.sqlUpdate("update boe_cases set last_month_views=views where deleted=0"); } @@ -1446,35 +1451,25 @@ public class CasesServiceImpl implements ICasesService { if (StringUtils.isEmpty(token)) { token = request.getHeader("token"); } - UserDynamicResult userDynamicResult = thirdApi.getAllUserdynamicList2(userdynamicParam, token); + // 获取案例浏览记录 + UserDynamicResult userDynamicResult = thirdApi.getAllUserdynamicListOfCaseRead(userdynamicParam, token); List allUserdynamicList = userDynamicResult.getList(); List collect = allUserdynamicList.stream().map(UserDynamic::getContentId).distinct().collect(Collectors.toList()); + // 查询案例信息 List caseList = this.ids(collect, accountId); Map map = caseList.stream().collect(Collectors.toMap(Cases::getId, cases -> cases)); + // 组合案例信息与浏览记录 List batchHistoryVoList = allUserdynamicList.stream().map(userDynamic -> { CasesBrowsingHistoryVo browsingHistoryVo = new CasesBrowsingHistoryVo(); - // 注意,两者存在重名属性,如ID,会出现覆盖。CasesBrowsingHistoryVo中的ID是案例ID,browsingHistoryId是UserDynamic的ID browsingHistoryVo.setBrowsingHistoryId(userDynamic.getId()); browsingHistoryVo.setContentInfo(userDynamic.getContentInfo()); browsingHistoryVo.setEventTime(userDynamic.getEventTime()); browsingHistoryVo.setContentId(userDynamic.getContentId()); - browsingHistoryVo.setId(null); if (map.containsKey(userDynamic.getContentId())){ - // 确保copy案例时,不会覆盖数据 - try { - // 检查并复制第二次 - Map srcMap = PropertyUtils.describe(map.get(userDynamic.getContentId())); - for (String key : srcMap.keySet()) { - if (PropertyUtils.getProperty(browsingHistoryVo, key) == null) { // 只有当目标对象的属性为null时才复制 - PropertyUtils.setProperty(browsingHistoryVo, key, srcMap.get(key)); - } - } - } catch (Exception e){ - log.error("browsingHistoryVo copy error", e); - throw new RuntimeException(e); - } + // 重名属性,如ID,copy会出现覆盖。 + BeanUtils.copyProperties(map.get(userDynamic.getContentId()),browsingHistoryVo); } return browsingHistoryVo; }).collect(Collectors.toList()); @@ -1498,7 +1493,6 @@ public class CasesServiceImpl implements ICasesService { // 定义日期时间的格式 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yy-MM"); - Map> collect = list.stream().collect(Collectors.groupingBy (CasesRank::getMajorId, Collectors.mapping(casesRank -> casesRank.getRiseRankTime().format(formatter), Collectors.toList()))); diff --git a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/vo/CaseRankingVo.java b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/vo/CaseRankingVo.java index d5a3c5a6..d906144b 100644 --- a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/vo/CaseRankingVo.java +++ b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/vo/CaseRankingVo.java @@ -4,9 +4,14 @@ import lombok.Data; @Data public class CaseRankingVo { - + /** + * 案例id + */ private String caseId; + /** + * 案例标题 + */ private String caseTitle; } diff --git a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/vo/CaseViewRankingItemVo.java b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/vo/CaseViewRankingItemVo.java index a7657d6b..88191080 100644 --- a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/vo/CaseViewRankingItemVo.java +++ b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/vo/CaseViewRankingItemVo.java @@ -6,12 +6,24 @@ import java.time.LocalDateTime; @Data public class CaseViewRankingItemVo { + /** + * 分类id + */ private String majorId; + /** + * 分类名称 + */ private String majorName; + /** + * 上榜时间,目前默认为一月中的最后一天的23:59:59 + */ private LocalDateTime riseRankTime; + /** + * 标签名称 + */ private String tagName; } diff --git a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/vo/CasesBrowsingHistoryVo.java b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/vo/CasesBrowsingHistoryVo.java index a7592efa..93775a0f 100644 --- a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/vo/CasesBrowsingHistoryVo.java +++ b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/vo/CasesBrowsingHistoryVo.java @@ -8,17 +8,23 @@ import java.time.LocalDateTime; @Data public class CasesBrowsingHistoryVo extends Cases{ + /** + * 浏览记录id + * */ private String browsingHistoryId; /** - * 动态内容 + * 案例标题 * */ private String contentInfo; + /** + * 事件时间,查看案例时,有定时接口触发,名为send,eventTime为该时间 + * */ private LocalDateTime eventTime; /** - * 内容id + * 案例ID * */ private String contentId; diff --git a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/vo/CasesQueryRecommendRankVo.java b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/vo/CasesQueryRecommendRankVo.java index 5c59358a..5e6d5a27 100644 --- a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/vo/CasesQueryRecommendRankVo.java +++ b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/vo/CasesQueryRecommendRankVo.java @@ -18,6 +18,9 @@ public class CasesQueryRecommendRankVo { */ private String caseTitle; + /** + * 案例作者 + */ private String caseAuthor; /** diff --git a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/vo/FavoriteCaseOfIndexVo.java b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/vo/FavoriteCaseOfIndexVo.java index 54f3e052..bb59e316 100644 --- a/servers/boe-server-all/src/main/java/com/xboe/module/boecase/vo/FavoriteCaseOfIndexVo.java +++ b/servers/boe-server-all/src/main/java/com/xboe/module/boecase/vo/FavoriteCaseOfIndexVo.java @@ -9,9 +9,14 @@ import java.time.LocalDateTime; @Data public class FavoriteCaseOfIndexVo extends Cases{ - + /** + * 收藏id + */ private String favoriteId; + /** + * 收藏时间 + */ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private LocalDateTime favoriteTime;