|
@@ -0,0 +1,77 @@
|
|
|
+package com.redxun.knowledge.analysis.service;
|
|
|
+
|
|
|
+
|
|
|
+import com.redxun.knowledge.analysis.entity.vo.AlbumDetailVisitsVo;
|
|
|
+import com.redxun.knowledge.analysis.mapper.PvLogMapper;
|
|
|
+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.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 文件名: AnalysisAlbumServiceImpl
|
|
|
+ * 作者: zizg
|
|
|
+ * 时间: 2023/3/21
|
|
|
+ * 描述:
|
|
|
+ * 修改人:
|
|
|
+ * 修改时间:
|
|
|
+ * 修改内容:
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class AnalysisAlbumServiceImpl {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PvLogMapper pvLogMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 专辑创建总量
|
|
|
+ * @param type
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String, Object> albumAmount(String type) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 专辑详情Top访问量(pv)统计
|
|
|
+ * @param type
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<AlbumDetailVisitsVo> albumDetailVisits(String type, Integer tops) {
|
|
|
+ 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)){
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ //取tops10
|
|
|
+ result = result.stream().limit(tops).collect(Collectors.toList());
|
|
|
+ int countSum = result.stream().mapToInt(AlbumDetailVisitsVo::getValue).sum();
|
|
|
+ //计算百分比
|
|
|
+ if (countSum != 0){
|
|
|
+ result.forEach(e -> {
|
|
|
+ BigDecimal countbg = BigDecimal.valueOf(e.getValue() / (double) countSum);
|
|
|
+ e.setPercentage(countbg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|