Merge branch 'refs/heads/zcwy0813-yang' into dev0525

This commit is contained in:
yang
2024-09-12 19:08:37 +08:00
4 changed files with 41 additions and 6 deletions

View File

@@ -693,6 +693,16 @@ public class CasesApi extends ApiBaseController {
} }
/**
* 不同专业月热度榜查询所需时间检索数据
*/
@GetMapping("/queryAllTimePopularityOfMajor")
public JsonResponse<Map<Long, List<String>>> queryAllTimePopularityOfMajor() {
Map<Long, List<String>> time = casesService.queryAllTimePopularityOfMajor();
return success(time);
}
/** /**
* 查询推荐案例榜单 * 查询推荐案例榜单
* @return * @return

View File

@@ -4,6 +4,7 @@ import com.xboe.core.SysConstant;
import com.xboe.core.orm.BaseEntity; import com.xboe.core.orm.BaseEntity;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
@@ -16,6 +17,7 @@ import java.time.LocalDateTime;
* @TableName boe_cases_rank * @TableName boe_cases_rank
*/ */
@Data @Data
@NoArgsConstructor
@Entity @Entity
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
@Table(name = SysConstant.TABLE_PRE+"cases_rank") @Table(name = SysConstant.TABLE_PRE+"cases_rank")
@@ -52,6 +54,8 @@ public class CasesRank extends BaseEntity {
@Transient @Transient
private String majorName; private String majorName;
public CasesRank(Long majorId, LocalDateTime riseRankTime) {
this.majorId = majorId;
this.riseRankTime = riseRankTime;
}
} }

View File

@@ -15,6 +15,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Map;
public interface ICasesService{ public interface ICasesService{
/** /**
@@ -137,5 +138,7 @@ public interface ICasesService{
PageList<FavoriteCaseOfIndexVo> queryFavoriteCaseOfIndex(Integer pageIndex, Integer pageSize, String accountId); PageList<FavoriteCaseOfIndexVo> queryFavoriteCaseOfIndex(Integer pageIndex, Integer pageSize, String accountId);
PageList<CasesBrowsingHistoryVo> browsingHistory(Integer pageIndex, Integer pageSize, String accountId, HttpServletRequest request); PageList<CasesBrowsingHistoryVo> browsingHistory(Integer pageIndex, Integer pageSize, String accountId, HttpServletRequest request);
Map<Long, List<String>> queryAllTimePopularityOfMajor();
} }

View File

@@ -487,7 +487,7 @@ public class CasesServiceImpl implements ICasesService {
if (CollUtil.isNotEmpty(viewsRankRecords)) { if (CollUtil.isNotEmpty(viewsRankRecords)) {
// 拼接生成浏览量排行榜的标签 // 拼接生成浏览量排行榜的标签
List<CaseViewRankingItemVo> viewRankTags = viewsRankRecords.stream().map(casesRank -> { List<CaseViewRankingItemVo> viewRankTags = viewsRankRecords.stream().map(casesRank -> {
String pattern = casesRank.getRiseRankTime().getMonthValue() < 10 ? "yyyy年M月" : "yyyy年MM月"; String pattern = casesRank.getRiseRankTime().getMonthValue() < 10 ? "yy年M月" : "yy年MM月";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern); DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
String time = casesRank.getRiseRankTime().format(formatter); String time = casesRank.getRiseRankTime().format(formatter);
@@ -508,7 +508,7 @@ public class CasesServiceImpl implements ICasesService {
// 拼接生成年度最佳标签 // 拼接生成年度最佳标签
if (e.getExcellent()!=null && e.getExcellent()) { if (e.getExcellent()!=null && e.getExcellent()) {
e.setExcellentTag(e.getExcellentTime().format(DateTimeFormatter.ofPattern("yyyy"))+"度最佳"); e.setExcellentTag(e.getExcellentTime().format(DateTimeFormatter.ofPattern("yy年"))+"度最佳");
} }
List<String> authorTags = new ArrayList<>(); List<String> authorTags = new ArrayList<>();
@@ -1164,7 +1164,7 @@ public class CasesServiceImpl implements ICasesService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void refreshViewsRankOfMajor(){ public void refreshViewsRankOfMajor(){
// LocalDateTime riseRankTime = LocalDateTime.now().withDayOfMonth(1).minusDays(1).toLocalDate().atTime(23, 59, 59); // 上月最后一天的结束时间 // LocalDateTime riseRankTime = LocalDateTime.now().withDayOfMonth(1).minusDays(1).toLocalDate().atTime(23, 59, 59); // 上月最后一天的结束时间
LocalDateTime riseRankTime = LocalDateTime.now().minusMonths(2).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); int count = casesRankDao.sqlCount("SELECT count(1) FROM boe_cases_rank WHERE deleted=0 AND rise_rank_time = ?1", riseRankTime);
if (count > 0){ if (count > 0){
return; return;
@@ -1174,7 +1174,7 @@ public class CasesServiceImpl implements ICasesService {
String sql = String sql =
"SELECT bc.id,bcmt.major_id,bc.views - COALESCE(bc.last_month_views, 0) AS increment\n" + "SELECT bc.id,bcmt.major_id,bc.views - COALESCE(bc.last_month_views, 0) AS increment\n" +
"FROM boe_cases bc\n" + "FROM boe_cases bc\n" +
"JOIN boe_cases_major_type bcmt ON bcmt.case_id = bc.id and bc.deleted=0 and file_path is not null and file_path!=''"; "JOIN boe_cases_major_type bcmt ON bcmt.case_id = bc.id and bc.deleted=0 and file_path is not null and file_path!='' and bc.views - COALESCE(bc.last_month_views, 0)!=0";
List<Object> caseListOfObject = casesDao.sqlFindList(sql); List<Object> caseListOfObject = casesDao.sqlFindList(sql);
// 转为casesRank // 转为casesRank
@@ -1487,4 +1487,22 @@ public class CasesServiceImpl implements ICasesService {
return pageList; return pageList;
} }
@Override
public Map<Long, List<String>> queryAllTimePopularityOfMajor() {
QueryBuilder builder = QueryBuilder.from(CasesRank.class);
builder.addField("new CasesRank(majorId,riseRankTime)");
builder.addFilter(FieldFilters.eq("deleted",false));
builder.addGroupBy("majorId");
builder.addGroupBy("riseRankTime");
List<CasesRank> list = casesRankDao.findList(builder.builder());
// 定义日期时间的格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yy-MM");
Map<Long, List<String>> collect = list.stream().collect(Collectors.groupingBy
(CasesRank::getMajorId, Collectors.mapping(casesRank -> casesRank.getRiseRankTime().format(formatter), Collectors.toList())));
return collect;
}
} }