|
@@ -1,6 +1,8 @@
|
|
|
package com.redxun.knowledge.analysis.service;
|
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.redxun.common.base.entity.QueryData;
|
|
|
import com.redxun.common.tool.StringUtils;
|
|
|
import com.redxun.knowledge.album.mapper.AlbumCategoryMapper;
|
|
|
import com.redxun.knowledge.analysis.entity.vo.*;
|
|
@@ -8,6 +10,7 @@ import com.redxun.knowledge.analysis.mapper.AnalysisAlbumMapper;
|
|
|
import com.redxun.knowledge.analysis.mapper.PvLogMapper;
|
|
|
import com.redxun.knowledge.common.UserService;
|
|
|
import com.redxun.knowledge.utils.DateUtils;
|
|
|
+import com.redxun.knowledge.utils.PageListUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -35,9 +38,6 @@ public class AnalysisAlbumServiceImpl {
|
|
|
@Autowired
|
|
|
private AnalysisAlbumMapper analysisAlbumMapper;
|
|
|
|
|
|
- @Autowired
|
|
|
- private AlbumCategoryMapper albumCategoryMapper;
|
|
|
-
|
|
|
@Autowired
|
|
|
private UserService userService;
|
|
|
|
|
@@ -160,48 +160,52 @@ public class AnalysisAlbumServiceImpl {
|
|
|
|
|
|
/**
|
|
|
* 组织创建和访问专辑数量
|
|
|
- *
|
|
|
- * @param type
|
|
|
- * @param tops
|
|
|
- * @param sort
|
|
|
+ * @param queryData
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<AlbumCompanyVo> organizationAlbums(String type, Integer tops, String sort) {
|
|
|
+ public IPage organizationAlbums(QueryData queryData) {
|
|
|
//创建过专辑的公司Id集合
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
int year = calendar.get(Calendar.YEAR);
|
|
|
List<AlbumCompanyVo> result = new ArrayList<>();
|
|
|
- if ("total".equals(type)) {
|
|
|
+ if ("total".equals(queryData.getParams().get("type"))) {
|
|
|
result = analysisAlbumMapper.organizationAlbums(null, null);
|
|
|
- } else if ("year".equals(type)) {
|
|
|
+ } else if ("year".equals(queryData.getParams().get("type"))) {
|
|
|
result = analysisAlbumMapper.organizationAlbums(DateUtils.format(DateUtils.getFirstOfYear(year)),
|
|
|
DateUtils.format(DateUtils.getLastOfYear(year)));
|
|
|
- } else if ("month".equals(type)) {
|
|
|
+ } else if ("month".equals(queryData.getParams().get("type"))) {
|
|
|
int month = calendar.get(Calendar.MONTH);
|
|
|
String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15);
|
|
|
String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15);
|
|
|
result = analysisAlbumMapper.organizationAlbums(firstOfMonth, lastOfMonth);
|
|
|
}
|
|
|
//排序
|
|
|
+ String sort = queryData.getSortField();
|
|
|
if (sort != null) {
|
|
|
+ sort = sort + queryData.getSortOrder();
|
|
|
switch (sort) {
|
|
|
- case "albumDesc":
|
|
|
+ case "albumdesc":
|
|
|
result = result.stream().sorted((t1, t2) -> t2.getAlbum().compareTo(t1.getAlbum())).collect(Collectors.toList());
|
|
|
break;
|
|
|
- case "albumAsc":
|
|
|
+ case "albumasc":
|
|
|
result = result.stream().sorted(Comparator.comparing(AlbumCompanyVo::getAlbum)).collect(Collectors.toList());
|
|
|
break;
|
|
|
- case "pvDesc":
|
|
|
+ case "pvdesc":
|
|
|
result = result.stream().sorted((t1, t2) -> t2.getPv().compareTo(t1.getPv())).collect(Collectors.toList());
|
|
|
break;
|
|
|
- case "pvAsc":
|
|
|
+ case "pvasc":
|
|
|
result = result.stream().sorted(Comparator.comparing(AlbumCompanyVo::getPv)).collect(Collectors.toList());
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
//取tops10
|
|
|
- result = result.stream().limit(tops).collect(Collectors.toList());
|
|
|
+ String tops = queryData.getParams().get("tops");
|
|
|
+ if(StringUtils.isNotEmpty(tops)){
|
|
|
+ result = result.stream().limit(Long.parseLong(tops)).collect(Collectors.toList());
|
|
|
+ } else {
|
|
|
+ result = result.stream().limit(10).collect(Collectors.toList());
|
|
|
+ }
|
|
|
result.forEach(e -> e.setCompany(userService.findDeptByDeptId(e.getCompany()).getName()));
|
|
|
- return result;
|
|
|
+ return PageListUtils.getPages(queryData.getPageNo(),queryData.getPageSize(),result);
|
|
|
}
|
|
|
}
|