|
@@ -1,15 +1,20 @@
|
|
|
package com.fdkankan.manage.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.fdkankan.manage.entity.User;
|
|
|
import com.fdkankan.manage.mapper.IDataMapper;
|
|
|
import com.fdkankan.manage.service.IDataService;
|
|
|
+import com.fdkankan.manage.service.ISceneProService;
|
|
|
+import com.fdkankan.manage.service.IUserService;
|
|
|
+import com.fdkankan.manage.util.Dateutils;
|
|
|
import com.fdkankan.manage.vo.response.*;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.poi.ss.formula.functions.Count;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
public class DataService implements IDataService {
|
|
@@ -20,6 +25,10 @@ public class DataService implements IDataService {
|
|
|
|
|
|
@Resource
|
|
|
IDataMapper dataMapper;
|
|
|
+ @Autowired
|
|
|
+ IUserService userService;
|
|
|
+ @Autowired
|
|
|
+ ISceneProService sceneProService;
|
|
|
|
|
|
@Override
|
|
|
public UserTotalVo getUserTotal() {
|
|
@@ -64,77 +73,190 @@ public class DataService implements IDataService {
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public List<DataGroupByCount> userTrend(Integer type) {
|
|
|
+ public List<DataGroupByCount> userTrend(Integer type,Integer dataType,String startTime,String endTime) {
|
|
|
+ startTime = Dateutils.formatStartTime(startTime,type);
|
|
|
+ endTime = Dateutils.formatEndTime(endTime,type);
|
|
|
+
|
|
|
+ List<DataGroupByCount> dataList = new ArrayList<>();
|
|
|
List<DataGroupByCount> result = new ArrayList<>();
|
|
|
+ int rule = Dateutils.DAY;
|
|
|
+ String tb = "t_user";
|
|
|
+ if(dataType == 2){
|
|
|
+ tb = "t_login_log";
|
|
|
+ }
|
|
|
switch (type){
|
|
|
- case 0 : return dataMapper.userDataGroupBy("t_user",dayFormat);
|
|
|
- case 1 : return dataMapper.userDataGroupByWeek("t_user");
|
|
|
- case 2 : return dataMapper.userDataGroupBy("t_user",mouthFormat);
|
|
|
+ case 0 :
|
|
|
+ dataList = dataMapper.userDataGroupBy(tb, dayFormat, startTime, endTime);
|
|
|
+ break;
|
|
|
+ case 1 :
|
|
|
+ rule = Dateutils.WEEK;
|
|
|
+ dataList = dataMapper.userDataGroupByWeek(tb,startTime,endTime);
|
|
|
+ break;
|
|
|
+ case 2 :
|
|
|
+ rule = Dateutils.MONTH;
|
|
|
+ dataList = dataMapper.userDataGroupBy(tb,mouthFormat,startTime,endTime);
|
|
|
+ break;
|
|
|
}
|
|
|
+ Long totalCount = 0L;
|
|
|
+ if(dataType == 1){ //累加
|
|
|
+ LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.lt(User::getCreateTime,startTime);
|
|
|
+ totalCount = userService.count(wrapper);
|
|
|
+ }
|
|
|
+ //查询从开始时间到结束时间为止所有天数,月份,不存在结果补零
|
|
|
+ HashMap<String,Long> map = new HashMap<>();
|
|
|
+ dataList.forEach(entity -> map.put(entity.getGroupKey(),entity.getCount()));
|
|
|
+ List<String> dates = Dateutils.findDatesStr(Dateutils.getDate(startTime), Dateutils.getDate(endTime),rule );
|
|
|
+
|
|
|
+ setListData(result,map,dates,dataType,totalCount);
|
|
|
+
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public HashMap<String, List<DataGroupByCount>> orderTrend(Integer type) {
|
|
|
+ public HashMap<String, List<DataGroupByCount>> orderTrend(Integer type,String startTime,String endTime) {
|
|
|
+ startTime = Dateutils.formatStartTime(startTime,type);
|
|
|
+ endTime = Dateutils.formatEndTime(endTime,type);
|
|
|
+
|
|
|
HashMap<String,List<DataGroupByCount>> map = new HashMap<>();
|
|
|
List<DataGroupByCount> incrementOrderList = new ArrayList<>();
|
|
|
List<DataGroupByCount> downOrderList = new ArrayList<>();
|
|
|
List<DataGroupByCount> partOrderList = new ArrayList<>();
|
|
|
+ List<DataGroupByCount> incrementOrderResultList = new ArrayList<>();
|
|
|
+ List<DataGroupByCount> downOrderResultList = new ArrayList<>();
|
|
|
+ List<DataGroupByCount> partOrderResultList = new ArrayList<>();
|
|
|
+ int rule = Dateutils.DAY;
|
|
|
switch (type){
|
|
|
case 0 :
|
|
|
- incrementOrderList = dataMapper.userDataGroupBy("t_increment_order",dayFormat);
|
|
|
- downOrderList = dataMapper.userDataGroupBy("t_download_order",dayFormat);
|
|
|
+ incrementOrderList = dataMapper.userDataGroupBy("t_increment_order",dayFormat,startTime,endTime);
|
|
|
+ downOrderList = dataMapper.userDataGroupBy("t_download_order",dayFormat,startTime,endTime);
|
|
|
break;
|
|
|
case 1 :
|
|
|
- incrementOrderList = dataMapper.userDataGroupByWeek("t_increment_order");
|
|
|
- downOrderList = dataMapper.userDataGroupByWeek("t_download_order");
|
|
|
+ rule = Dateutils.WEEK;
|
|
|
+ incrementOrderList = dataMapper.userDataGroupByWeek("t_increment_order",startTime,endTime);
|
|
|
+ downOrderList = dataMapper.userDataGroupByWeek("t_download_order",startTime,endTime);
|
|
|
break;
|
|
|
case 2 :
|
|
|
- incrementOrderList = dataMapper.userDataGroupBy("t_increment_order",mouthFormat);
|
|
|
- downOrderList = dataMapper.userDataGroupBy("t_download_order",mouthFormat);
|
|
|
+ rule = Dateutils.MONTH;
|
|
|
+ incrementOrderList = dataMapper.userDataGroupBy("t_increment_order",mouthFormat,startTime,endTime);
|
|
|
+ downOrderList = dataMapper.userDataGroupBy("t_download_order",mouthFormat,startTime,endTime);
|
|
|
break;
|
|
|
}
|
|
|
- map.put("incrementOrder",incrementOrderList);
|
|
|
- map.put("downOrder",downOrderList);
|
|
|
+ //查询从开始时间到结束时间为止所有天数,月份,不存在结果补零
|
|
|
+ HashMap<String,Long> incrementMap = new HashMap<>();
|
|
|
+ HashMap<String,Long> downOrderMap = new HashMap<>();
|
|
|
+ HashMap<String,Long> partMap = new HashMap<>();
|
|
|
+ incrementOrderList.forEach(entity -> incrementMap.put(entity.getGroupKey(),entity.getCount()));
|
|
|
+ downOrderList.forEach(entity -> downOrderMap.put(entity.getGroupKey(),entity.getCount()));
|
|
|
+
|
|
|
+ List<String> dates = Dateutils.findDatesStr(Dateutils.getDate(startTime), Dateutils.getDate(endTime),rule );
|
|
|
+ for (String date : dates) {
|
|
|
+ DataGroupByCount groupByCount = new DataGroupByCount();
|
|
|
+ groupByCount.setGroupKey(date);
|
|
|
+ groupByCount.setCount(incrementMap.get(date)== null ?0 :incrementMap.get(date));
|
|
|
+ incrementOrderResultList.add(groupByCount);
|
|
|
+
|
|
|
+ DataGroupByCount groupByCount2 = new DataGroupByCount();
|
|
|
+ groupByCount2.setGroupKey(date);
|
|
|
+ groupByCount2.setCount(downOrderMap.get(date)== null ?0 :downOrderMap.get(date));
|
|
|
+ downOrderResultList.add(groupByCount2);
|
|
|
+ }
|
|
|
+ map.put("incrementOrder",incrementOrderResultList);
|
|
|
+ map.put("downOrder",downOrderResultList);
|
|
|
map.put("partOrder",partOrderList);
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public HashMap<String, List<DataGroupByCount>> sceneTrend(Integer type) {
|
|
|
+ public HashMap<String, List<DataGroupByCount>> sceneTrend(Integer type,Integer dataType,String startTime,String endTime) {
|
|
|
+ startTime = Dateutils.formatStartTime(startTime,type);
|
|
|
+ endTime = Dateutils.formatEndTime(endTime,type);
|
|
|
+
|
|
|
HashMap<String,List<DataGroupByCount>> map = new HashMap<>();
|
|
|
List<DataGroupByCount> kkList = new ArrayList<>();
|
|
|
List<DataGroupByCount> kjList = new ArrayList<>();
|
|
|
List<DataGroupByCount> ssList = new ArrayList<>();
|
|
|
- List<DataGroupByCount> ssobjList = new ArrayList<>();
|
|
|
- List<DataGroupByCount> allList = new ArrayList<>();
|
|
|
+ List<DataGroupByCount> ssObjList = new ArrayList<>();
|
|
|
+ List<DataGroupByCount> proList = new ArrayList<>();
|
|
|
+ List<DataGroupByCount> plusList = new ArrayList<>();
|
|
|
+ int rule = Dateutils.DAY;
|
|
|
switch (type){
|
|
|
case 0 :
|
|
|
- allList = dataMapper.sceneGroupBy("t_scene_pro",dayFormat);
|
|
|
+ proList = dataMapper.sceneGroupBy("t_scene_pro",dayFormat,startTime,endTime);
|
|
|
+ plusList = dataMapper.sceneGroupBy("t_scene_plus",dayFormat,startTime,endTime);
|
|
|
break;
|
|
|
case 1 :
|
|
|
- allList = dataMapper.sceneGroupBy("t_scene_pro",dayFormat);
|
|
|
+ rule = Dateutils.WEEK;
|
|
|
+ proList = dataMapper.sceneGroupByWeek("t_scene_pro",startTime,endTime);
|
|
|
+ plusList = dataMapper.sceneGroupByWeek("t_scene_plus",startTime,endTime);
|
|
|
break;
|
|
|
case 2 :
|
|
|
- allList = dataMapper.sceneGroupBy("t_scene_pro",mouthFormat);
|
|
|
+ rule = Dateutils.MONTH;
|
|
|
+ proList = dataMapper.sceneGroupBy("t_scene_pro",mouthFormat,startTime,endTime);
|
|
|
+ plusList = dataMapper.sceneGroupBy("t_scene_plus",mouthFormat,startTime,endTime);
|
|
|
break;
|
|
|
}
|
|
|
- for (DataGroupByCount dataGroupByCount : allList) {
|
|
|
+ HashMap<String, Long> kkMap = new HashMap<>();
|
|
|
+ HashMap<String, Long> kjMap = new HashMap<>();
|
|
|
+ HashMap<String, Long> ssMap = new HashMap<>();
|
|
|
+ HashMap<String, Long> ssObjMap = new HashMap<>();
|
|
|
+ for (DataGroupByCount dataGroupByCount : proList) {
|
|
|
if(dataGroupByCount.getGroupKey2().equals("3")){ //看见
|
|
|
- kjList.add(dataGroupByCount);
|
|
|
+ kjMap.merge(dataGroupByCount.getGroupKey(),dataGroupByCount.getCount(), Long:: sum);
|
|
|
}
|
|
|
if(dataGroupByCount.getGroupKey2().equals("4")){ //深时
|
|
|
- ssList.add(dataGroupByCount);
|
|
|
+ ssMap.merge(dataGroupByCount.getGroupKey(),dataGroupByCount.getCount(), Long:: sum);
|
|
|
}
|
|
|
if(Arrays.asList("1","2","12","13","14").contains(dataGroupByCount.getGroupKey2())){ //看看
|
|
|
- kkList.add(dataGroupByCount);
|
|
|
+ kkMap.merge(dataGroupByCount.getGroupKey(),dataGroupByCount.getCount(), Long:: sum);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (DataGroupByCount dataGroupByCount : plusList) {
|
|
|
+ if(dataGroupByCount.getGroupKey2().equals("3")){ //看见
|
|
|
+ kjMap.merge(dataGroupByCount.getGroupKey(),dataGroupByCount.getCount(), Long:: sum);
|
|
|
+ }
|
|
|
+ if(dataGroupByCount.getGroupKey2().equals("4")){ //深时
|
|
|
+ ssObjMap.merge(dataGroupByCount.getGroupKey(),dataGroupByCount.getCount(), Long:: sum);
|
|
|
+ }
|
|
|
+ if(Arrays.asList("1","2","12","13","14").contains(dataGroupByCount.getGroupKey2())){ //看看
|
|
|
+ kkMap.merge(dataGroupByCount.getGroupKey(),dataGroupByCount.getCount(), Long:: sum);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
+ Long kkCount = 0L;
|
|
|
+ Long KjCount = 0L;
|
|
|
+ Long ssCount = 0L;
|
|
|
+ Long ssObjCount = 0L;
|
|
|
+ if(dataType == 1){
|
|
|
+ kkCount = sceneProService.getKkCount(Arrays.asList("1","2","12","13","14"),startTime);
|
|
|
+ KjCount = sceneProService.getKkCount(Arrays.asList("3"),startTime);
|
|
|
+ ssCount = sceneProService.getSsCount(Arrays.asList("4"),startTime);
|
|
|
+ ssObjCount = sceneProService.getSsObjCount(Arrays.asList("4"),startTime);
|
|
|
+ }
|
|
|
+ List<String> dates = Dateutils.findDatesStr(Dateutils.getDate(startTime), Dateutils.getDate(endTime),rule );
|
|
|
+ setListData(kkList,kkMap,dates,dataType,kkCount);
|
|
|
+ setListData(kjList,kjMap,dates,dataType,KjCount);
|
|
|
+ setListData(ssList,ssMap,dates,dataType,ssObjCount);
|
|
|
+ setListData(ssObjList,ssObjMap,dates,dataType,ssObjCount);
|
|
|
+
|
|
|
map.put("kkList",kkList);
|
|
|
map.put("kjList",kjList);
|
|
|
map.put("ssList",ssList);
|
|
|
- map.put("ssobjList",ssobjList);
|
|
|
+ map.put("ssobjList",ssObjList);
|
|
|
return map;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ private void setListData(List<DataGroupByCount> kkList, HashMap<String, Long> kkMap, List<String> dates,Integer dataType,Long totalCount) {
|
|
|
+ for (String key : dates) {
|
|
|
+ DataGroupByCount newCount = new DataGroupByCount();
|
|
|
+ newCount.setGroupKey(key);
|
|
|
+ Long count = kkMap.get(key) == null ?0 : kkMap.get(key);
|
|
|
+ if(dataType == 1){
|
|
|
+ count += totalCount;
|
|
|
+ totalCount = count;
|
|
|
+ }
|
|
|
+ newCount.setCount(count);
|
|
|
+ kkList.add(newCount);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|