PageHomeDataTask.java
6.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package com.linkwechat.quartz.task;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.core.redis.RedisCache;
import com.linkwechat.wecom.domain.WeUser;
import com.linkwechat.wecom.domain.dto.WePageCountDto;
import com.linkwechat.wecom.domain.dto.WePageStaticDataDto;
import com.linkwechat.wecom.domain.query.WePageStateQuery;
import com.linkwechat.wecom.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author danmo
* @description 首页数据统计
* @date 2021/2/23 23:51
**/
@Slf4j
@Component("PageHomeDataTask")
public class PageHomeDataTask {
@Autowired
private IWeCorpAccountService weCorpAccountService;
@Autowired
private IWeUserService weUserService;
@Autowired
private IWeCustomerService weCustomerService;
@Autowired
private IWeGroupService weGroupService;
@Autowired
private IWeGroupMemberService weGroupMemberService;
@Autowired
private IWeUserBehaviorDataService weUserBehaviorDataService;
@Autowired
private IWeGroupStatisticService weGroupStatisticService;
@Autowired
private RedisCache redisCache;
public void getPageHomeDataData(){
getCorpBasicData();
getCorpRealTimeData();
}
public void getCorpBasicData(){
//查询当前使用企业
//WeCorpAccount weCorpAccount = weCorpAccountService.findValidWeCorpAccount();
//String corpId = weCorpAccount.getCorpId();
Map<String,Object> totalMap = new HashMap<>(16);
//企业成员总数
int userCount = weUserService.count(new LambdaQueryWrapper<WeUser>().eq(WeUser::getIsActivate, WeConstans.WE_USER_IS_ACTIVATE));
//客户总人数
int customerCount = weCustomerService.count();
//客户群总数
int groupCount = weGroupService.count();
//群成员总数
int groupMemberCount = weGroupMemberService.count();
totalMap.put("userCount",userCount);
totalMap.put("customerCount",customerCount);
totalMap.put("groupCount",groupCount);
totalMap.put("groupMemberCount",groupMemberCount);
redisCache.setCacheMap("getCorpBasicData",totalMap);
}
public void getCorpRealTimeData(){
WePageStaticDataDto wePageStaticDataDto = new WePageStaticDataDto();
//今天
wePageStaticDataDto.setToday(getTodayData());
wePageStaticDataDto.setWeek(getWeekData());
wePageStaticDataDto.setMonth(getMonthData());
wePageStaticDataDto.setUpdateTime(DateUtil.now());
redisCache.setCacheObject("getCorpRealTimeData",wePageStaticDataDto);
}
private WePageStaticDataDto.PageStaticData getTodayData(){
/**
* 今日
*/
String today = DateUtil.today();
String yesterday = DateUtil.yesterday().toDateStr();
//客户统计
WePageCountDto newTime = weUserBehaviorDataService.getCountDataByDay(today,"day");
/**
* 昨日
*/
//客户统计
WePageCountDto lastTime = weUserBehaviorDataService.getCountDataByDay(yesterday,"day");
WePageStaticDataDto.PageStaticData pageStaticData = setPageStaticData(newTime, lastTime);
WePageStateQuery wePageStateQuery = new WePageStateQuery();
//获取15天前的时间
wePageStateQuery.setStartTime(DateUtil.offsetDay(new Date(), -15).toDateStr());
wePageStateQuery.setEndTime(today);
wePageStateQuery.setFew(14);
List<WePageCountDto> dayCountData = weUserBehaviorDataService.getDayCountData(wePageStateQuery);
pageStaticData.setDataList(dayCountData);
return pageStaticData;
}
private WePageStaticDataDto.PageStaticData getWeekData(){
/**
* 本周
*/
//客户统计
WePageCountDto newTime = weUserBehaviorDataService.getCountDataByDay(DateUtil.today(),"week");
/**
* 上周
*/
//客户统计
WePageCountDto lastTime = weUserBehaviorDataService.getCountDataByDay(DateUtil.lastWeek().toDateStr(),"week");
WePageStaticDataDto.PageStaticData pageStaticData = setPageStaticData(newTime, lastTime);
WePageStateQuery wePageStateQuery = new WePageStateQuery();
wePageStateQuery.setFew(5);
List<WePageCountDto> weekCountData = weUserBehaviorDataService.getWeekCountData(wePageStateQuery);
pageStaticData.setDataList(weekCountData);
return pageStaticData;
}
private WePageStaticDataDto.PageStaticData getMonthData(){
/**
* 本周
*/
//客户统计
WePageCountDto newTime = weUserBehaviorDataService.getCountDataByDay(DateUtil.today(),"month");
/**
* 上周
*/
//客户统计
WePageCountDto lastTime = weUserBehaviorDataService.getCountDataByDay(DateUtil.lastMonth().toDateStr(),"month");
WePageStaticDataDto.PageStaticData pageStaticData = setPageStaticData(newTime, lastTime);
WePageStateQuery wePageStateQuery = new WePageStateQuery();
wePageStateQuery.setFew(5);
List<WePageCountDto> monthCountData = weUserBehaviorDataService.getMonthCountData(wePageStateQuery);
pageStaticData.setDataList(monthCountData);
return pageStaticData;
}
private WePageStaticDataDto.PageStaticData setPageStaticData(WePageCountDto nowTime,WePageCountDto lastTime){
WePageStaticDataDto.PageStaticData pageStaticData = new WePageStaticDataDto.PageStaticData();
pageStaticData.setNewApplyCnt(nowTime.getNewApplyCnt());
pageStaticData.setNewApplyCntDiff(nowTime.getNewApplyCnt() - lastTime.getNewApplyCnt());
pageStaticData.setNegativeFeedbackCnt(nowTime.getNegativeFeedbackCnt());
pageStaticData.setNegativeFeedbackCntDiff(nowTime.getNegativeFeedbackCnt() - lastTime.getNegativeFeedbackCnt());
pageStaticData.setNewContactCnt(nowTime.getNewContactCnt());
pageStaticData.setNewContactCntDiff(nowTime.getNewContactCnt() - lastTime.getNewContactCnt());
return pageStaticData;
}
}