|
@@ -1,7 +1,18 @@
|
|
|
package com.ruoyi.system.service.impl;
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
+import com.ruoyi.common.core.domain.entity.SysDictData;
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
+import com.ruoyi.system.service.ISysDictTypeService;
|
|
|
+import org.apache.commons.lang3.math.NumberUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.ruoyi.system.mapper.BomanNewsMapper;
|
|
@@ -20,6 +31,9 @@ public class BomanNewsServiceImpl implements IBomanNewsService
|
|
|
@Autowired
|
|
|
private BomanNewsMapper bomanNewsMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ISysDictTypeService dictTypeService;
|
|
|
+
|
|
|
/**
|
|
|
* 查询boman_news
|
|
|
*
|
|
@@ -93,4 +107,65 @@ public class BomanNewsServiceImpl implements IBomanNewsService
|
|
|
{
|
|
|
return bomanNewsMapper.deleteBomanNewsByNewsId(newsId);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发布首页统计
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public AjaxResult indexStatisticsInFor() {
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ map.put("year",0);
|
|
|
+ map.put("yearMonth",0);
|
|
|
+ //查询字典值
|
|
|
+ List<SysDictData> dictDataList = dictTypeService.selectDictDataByType("wenzl");
|
|
|
+ if (dictDataList != null && dictDataList.size() > 0){
|
|
|
+ for (SysDictData sysDictData : dictDataList) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("this",0);
|
|
|
+ jsonObject.put("last",0);
|
|
|
+ jsonObject.put("status",0);
|
|
|
+ map.put(sysDictData.getDictValue(),jsonObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //查询本月发布的文章数据
|
|
|
+ BomanNews bomanNews = new BomanNews();
|
|
|
+ bomanNews.setReleaseTime(DateUtils.getNowDate());
|
|
|
+ //本月数据
|
|
|
+ List<BomanNews> bomanNewsList = bomanNewsMapper.selectBomanNewsList(bomanNews);
|
|
|
+ //查询上月数据
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ Calendar c = Calendar.getInstance();
|
|
|
+ c.add(Calendar.MONTH, -1); //得到前一个月
|
|
|
+ bomanNews.setReleaseTime(DateUtils.parseDate(format.format(c.getTime())));
|
|
|
+ List<BomanNews> bomanNewsListLast = bomanNewsMapper.selectBomanNewsList(bomanNews);
|
|
|
+ if (bomanNewsList != null && bomanNewsList.size() > 0){
|
|
|
+ map.put("yearMonth",bomanNewsList.size());
|
|
|
+ //进行数据比对
|
|
|
+ Map<String, List<BomanNews>> collect = bomanNewsList.stream().collect(Collectors.groupingBy(BomanNews::getType));
|
|
|
+ if (collect != null && collect.size() > 0){
|
|
|
+ for (String key : collect.keySet()) {
|
|
|
+ JSONObject jsonObject = (JSONObject)map.get(key);
|
|
|
+ jsonObject.put("this",collect.get(key).size());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (bomanNewsListLast != null && bomanNewsListLast.size() > 0){
|
|
|
+ //计算上月数据
|
|
|
+ Map<String, List<BomanNews>> collectLast = bomanNewsListLast.stream().collect(Collectors.groupingBy(BomanNews::getType));
|
|
|
+ if (collect != null && collect.size() > 0){
|
|
|
+ for (String key : collect.keySet()) {
|
|
|
+ //本月数据
|
|
|
+ JSONObject jsonObject = (JSONObject)map.get(key);
|
|
|
+ int num = (int)jsonObject.get("this");
|
|
|
+ //上月数据
|
|
|
+ int numLast = collectLast.get(key).size();
|
|
|
+ //计算 x=y=0 x<y=-1 x>y=1
|
|
|
+ int compare = NumberUtils.compare(num, numLast);
|
|
|
+ jsonObject.put("last",num-numLast);
|
|
|
+ jsonObject.put("status",compare);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return AjaxResult.success(map);
|
|
|
+ }
|
|
|
}
|