|
@@ -1,20 +1,21 @@
|
|
|
package com.redxun.knowledge.analysis.service;
|
|
|
|
|
|
|
|
|
+import com.redxun.common.tool.StringUtils;
|
|
|
+import com.redxun.knowledge.album.mapper.AlbumCategoryMapper;
|
|
|
import com.redxun.knowledge.analysis.entity.vo.AlbumCategoryVo;
|
|
|
+import com.redxun.knowledge.analysis.entity.vo.AlbumCompanyVo;
|
|
|
import com.redxun.knowledge.analysis.entity.vo.AlbumDetailVisitsVo;
|
|
|
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 lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Calendar;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -36,8 +37,15 @@ public class AnalysisAlbumServiceImpl {
|
|
|
@Autowired
|
|
|
private AnalysisAlbumMapper analysisAlbumMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private AlbumCategoryMapper albumCategoryMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
/**
|
|
|
* 专辑创建总量
|
|
|
+ *
|
|
|
* @param type
|
|
|
* @return
|
|
|
*/
|
|
@@ -47,6 +55,7 @@ public class AnalysisAlbumServiceImpl {
|
|
|
|
|
|
/**
|
|
|
* 专辑详情Top访问量(pv)统计
|
|
|
+ *
|
|
|
* @param type
|
|
|
* @return
|
|
|
*/
|
|
@@ -54,22 +63,22 @@ public class AnalysisAlbumServiceImpl {
|
|
|
List<AlbumDetailVisitsVo> result = new ArrayList<>();
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
int year = calendar.get(Calendar.YEAR);
|
|
|
- if (("total").equals(type)){
|
|
|
- result = pvLogMapper.albumDetailVisits(null,null);
|
|
|
- } else if ("year".equals(type)){
|
|
|
- result = pvLogMapper.albumDetailVisits(DateUtils.format(DateUtils.getFirstOfYear(year)),
|
|
|
- DateUtils.format(DateUtils.getLastOfYear(year)));
|
|
|
- } else if ("month".equals(type)){
|
|
|
+ if (("total").equals(type)) {
|
|
|
+ result = pvLogMapper.albumDetailVisits(null, null);
|
|
|
+ } else if ("year".equals(type)) {
|
|
|
+ result = pvLogMapper.albumDetailVisits(DateUtils.format(DateUtils.getFirstOfYear(year)),
|
|
|
+ DateUtils.format(DateUtils.getLastOfYear(year)));
|
|
|
+ } else if ("month".equals(type)) {
|
|
|
int month = calendar.get(Calendar.MONTH);
|
|
|
String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15);
|
|
|
String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15);
|
|
|
- result = pvLogMapper.albumDetailVisits(firstOfMonth,lastOfMonth);
|
|
|
+ result = pvLogMapper.albumDetailVisits(firstOfMonth, lastOfMonth);
|
|
|
}
|
|
|
//取tops10
|
|
|
result = result.stream().limit(tops).collect(Collectors.toList());
|
|
|
int countSum = result.stream().mapToInt(AlbumDetailVisitsVo::getValue).sum();
|
|
|
//计算百分比
|
|
|
- if (countSum != 0){
|
|
|
+ if (countSum != 0) {
|
|
|
result.forEach(e -> {
|
|
|
BigDecimal countbg = BigDecimal.valueOf(e.getValue() / (double) countSum);
|
|
|
e.setPercentage(countbg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
@@ -81,14 +90,102 @@ public class AnalysisAlbumServiceImpl {
|
|
|
|
|
|
/**
|
|
|
* 各一级分类专辑创建数量
|
|
|
+ *
|
|
|
* @param type
|
|
|
* @param sort
|
|
|
* @return
|
|
|
*/
|
|
|
public List<AlbumCategoryVo> level1AlbumHistogram(String type, String sort) {
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ int year = calendar.get(Calendar.YEAR);
|
|
|
//获取全部一级分类id
|
|
|
List<String> albumCategoryIdList = analysisAlbumMapper.selectCategory();
|
|
|
+ List<AlbumCategoryVo> result = albumCategoryIdList.stream().map(categoryId -> {
|
|
|
+ Integer albumIdList = 0;
|
|
|
+ Integer knowledgeList = 0;
|
|
|
+ AlbumCategoryVo albumCategoryVo = new AlbumCategoryVo();
|
|
|
+ if (("total").equals(type)) {
|
|
|
+ //根据分类Id查询其下所有专辑Id数量
|
|
|
+ albumIdList = analysisAlbumMapper.selectAlbumId(categoryId, null, null);
|
|
|
+ knowledgeList = analysisAlbumMapper.selectKnowledge(categoryId, null, null);
|
|
|
+ } else if (("year").equals(type)) {
|
|
|
+ //根据分类Id查询其下所有专辑Id(按年统计)
|
|
|
+ albumIdList = analysisAlbumMapper.selectAlbumId(categoryId, DateUtils.format(DateUtils.getFirstOfYear(year)),
|
|
|
+ DateUtils.format(DateUtils.getLastOfYear(year)));
|
|
|
+ knowledgeList = analysisAlbumMapper.selectKnowledge(categoryId, DateUtils.format(DateUtils.getFirstOfYear(year)),
|
|
|
+ DateUtils.format(DateUtils.getLastOfYear(year)));
|
|
|
+ } else if (("month").equals(type)) {
|
|
|
+ //根据分类Id查询其下所有专辑Id(按月统计)
|
|
|
+ int month = calendar.get(Calendar.MONTH);
|
|
|
+ String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15);
|
|
|
+ String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15);
|
|
|
+ albumIdList = analysisAlbumMapper.selectAlbumId(categoryId, firstOfMonth, lastOfMonth);
|
|
|
+ knowledgeList = analysisAlbumMapper.selectKnowledge(categoryId, firstOfMonth, lastOfMonth);
|
|
|
+ }
|
|
|
+ albumCategoryVo.setLabel(albumCategoryMapper.selectById(categoryId).getName());
|
|
|
+ albumCategoryVo.setAlbum(albumIdList);
|
|
|
+ albumCategoryVo.setKnowledge(knowledgeList);
|
|
|
+ return albumCategoryVo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ //排序
|
|
|
+ if (StringUtils.isEmpty(sort)) {
|
|
|
+ result = result.stream().
|
|
|
+ sorted(Comparator.comparingInt(AlbumCategoryVo::getKnowledge).thenComparingInt(AlbumCategoryVo::getAlbum).reversed()).
|
|
|
+ collect(Collectors.toList());
|
|
|
+ } else {
|
|
|
+ if ("albumDesc".equals(sort)) {
|
|
|
+ result = result.stream().sorted((t1, t2) -> t2.getAlbum().compareTo(t1.getAlbum())).collect(Collectors.toList());
|
|
|
+ } else {
|
|
|
+ result = result.stream().sorted((t1, t2) -> t2.getKnowledge().compareTo(t1.getKnowledge())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
- return null;
|
|
|
+ /**
|
|
|
+ * 组织创建和访问专辑数量
|
|
|
+ *
|
|
|
+ * @param type
|
|
|
+ * @param tops
|
|
|
+ * @param sort
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<AlbumCompanyVo> organizationAlbums(String type, Integer tops, String sort) {
|
|
|
+ //创建过专辑的公司Id集合
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ int year = calendar.get(Calendar.YEAR);
|
|
|
+ List<AlbumCompanyVo> result = new ArrayList<>();
|
|
|
+ if ("total".equals(type)) {
|
|
|
+ result = analysisAlbumMapper.organizationAlbums(null, null);
|
|
|
+ } else if ("year".equals(type)) {
|
|
|
+ result = analysisAlbumMapper.organizationAlbums(DateUtils.format(DateUtils.getFirstOfYear(year)),
|
|
|
+ DateUtils.format(DateUtils.getLastOfYear(year)));
|
|
|
+ } else if ("month".equals(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);
|
|
|
+ }
|
|
|
+ //排序
|
|
|
+ if (sort != null) {
|
|
|
+ switch (sort) {
|
|
|
+ case "albumDesc":
|
|
|
+ result = result.stream().sorted((t1, t2) -> t2.getAlbum().compareTo(t1.getAlbum())).collect(Collectors.toList());
|
|
|
+ break;
|
|
|
+ case "albumAsc":
|
|
|
+ result = result.stream().sorted(Comparator.comparing(AlbumCompanyVo::getAlbum)).collect(Collectors.toList());
|
|
|
+ break;
|
|
|
+ case "pvDesc":
|
|
|
+ result = result.stream().sorted((t1, t2) -> t2.getPv().compareTo(t1.getPv())).collect(Collectors.toList());
|
|
|
+ break;
|
|
|
+ case "pvAsc":
|
|
|
+ result = result.stream().sorted(Comparator.comparing(AlbumCompanyVo::getPv)).collect(Collectors.toList());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //取tops10
|
|
|
+ result = result.stream().limit(tops).collect(Collectors.toList());
|
|
|
+ result.forEach(e -> e.setCompany(userService.findDeptByDeptId(e.getCompany()).getName()));
|
|
|
+ return result;
|
|
|
}
|
|
|
}
|