|
@@ -1,11 +1,28 @@
|
1
|
1
|
package com.unissoft.ventilation.service.impl;
|
2
|
2
|
|
|
3
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
4
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
3
|
5
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
6
|
+import com.google.common.collect.Lists;
|
|
7
|
+import com.google.common.collect.Maps;
|
|
8
|
+import com.unissoft.MyConstant;
|
|
9
|
+import com.unissoft.feign.SystemFeign;
|
4
|
10
|
import com.unissoft.mapper.SysUserActivityMapper;
|
5
|
11
|
import com.unissoft.model.SysUserActivity;
|
|
12
|
+import com.unissoft.result.PageParam;
|
|
13
|
+import com.unissoft.utils.DateUtil;
|
6
|
14
|
import com.unissoft.ventilation.service.SysUserActivityService;
|
|
15
|
+import org.apache.commons.lang.StringUtils;
|
|
16
|
+import org.json.JSONObject;
|
|
17
|
+import org.springframework.beans.factory.annotation.Autowired;
|
7
|
18
|
import org.springframework.stereotype.Service;
|
8
|
19
|
|
|
20
|
+import java.util.ArrayList;
|
|
21
|
+import java.util.HashMap;
|
|
22
|
+import java.util.List;
|
|
23
|
+import java.util.Map;
|
|
24
|
+import java.util.stream.Collectors;
|
|
25
|
+
|
9
|
26
|
/**
|
10
|
27
|
* <p>
|
11
|
28
|
* 用户活跃度统计表 服务实现类
|
|
@@ -17,4 +34,94 @@ import org.springframework.stereotype.Service;
|
17
|
34
|
@Service
|
18
|
35
|
public class SysUserActivityServiceImpl extends ServiceImpl<SysUserActivityMapper, SysUserActivity> implements SysUserActivityService {
|
19
|
36
|
|
|
37
|
+ @Autowired
|
|
38
|
+ private SysUserActivityMapper activityMapper;
|
|
39
|
+
|
|
40
|
+ @Autowired
|
|
41
|
+ private SystemFeign systemFeign;
|
|
42
|
+
|
|
43
|
+ @Override
|
|
44
|
+ public IPage<SysUserActivity> getByPage(PageParam pageParam) {
|
|
45
|
+ Integer pageIndex = pageParam.getPageIndex();
|
|
46
|
+ Integer pageSize = pageParam.getPageSize();
|
|
47
|
+ String depotId = null, sTime = null, type = null;
|
|
48
|
+ if (!StringUtils.isEmpty(pageParam.getCondition())) {
|
|
49
|
+ JSONObject object = new JSONObject(pageParam.getCondition());
|
|
50
|
+ depotId = object.optString("depotId").trim();
|
|
51
|
+ sTime = object.optString("sTime").trim();
|
|
52
|
+ type = object.optString("type").trim();
|
|
53
|
+ }
|
|
54
|
+
|
|
55
|
+ Page page = null;
|
|
56
|
+ if (pageIndex != MyConstant.ZERO && pageSize != MyConstant.ZERO) {
|
|
57
|
+ page = new Page(pageIndex, pageSize);
|
|
58
|
+ }
|
|
59
|
+ List<Integer> allDepotChild = null;
|
|
60
|
+ if (StringUtils.isNotBlank(depotId) && StringUtils.isBlank(type)) {
|
|
61
|
+ //获取本库下所有库id
|
|
62
|
+ allDepotChild = systemFeign.getAllDepotChild(Integer.valueOf(depotId));
|
|
63
|
+ }
|
|
64
|
+ //type不等于空代表查询一个库下面的统计
|
|
65
|
+ if (StringUtils.isNotBlank(type)) {
|
|
66
|
+ allDepotChild = Lists.newArrayList();
|
|
67
|
+ allDepotChild.add(Integer.valueOf(depotId));
|
|
68
|
+ }
|
|
69
|
+ //默认获取上个月份
|
|
70
|
+ if (StringUtils.isEmpty(sTime)) {
|
|
71
|
+ sTime = DateUtil.getLastMonth();
|
|
72
|
+ } else {
|
|
73
|
+ sTime += MyConstant.BURDEN_ZERO;
|
|
74
|
+ }
|
|
75
|
+ IPage<SysUserActivity> pageResult = activityMapper.getPage(page, allDepotChild, sTime);
|
|
76
|
+ return pageResult;
|
|
77
|
+ }
|
|
78
|
+
|
|
79
|
+ @Override
|
|
80
|
+ public Map<String, Object> getGroupByDepotId(Integer depotId, Integer homeType) {
|
|
81
|
+ // 1.分公司领导首页 2.库主任及以上领导首页 3.员工首页
|
|
82
|
+ //获取上个月份
|
|
83
|
+ String lastMonth = DateUtil.getLastMonth();
|
|
84
|
+ ArrayList<String> depotNames = Lists.newArrayList();
|
|
85
|
+ ArrayList<Integer> sScores = Lists.newArrayList();
|
|
86
|
+ if (homeType == 1) {
|
|
87
|
+ //查詢
|
|
88
|
+ List<SysUserActivity> groupByDepotId = activityMapper.getGroupByDepotId(null, lastMonth);
|
|
89
|
+ if (groupByDepotId != null && groupByDepotId.size() > MyConstant.ZERO) {
|
|
90
|
+ //获取所有库map
|
|
91
|
+ Map<String, List<SysUserActivity>> collect = groupByDepotId.stream().collect(Collectors.groupingBy(t -> t.getDepotName()));
|
|
92
|
+ for (String key : collect.keySet()) {
|
|
93
|
+ depotNames.add(key);
|
|
94
|
+ Double asDouble = collect.get(key).stream().mapToInt(t -> t.getUsActivity()).average().getAsDouble();
|
|
95
|
+ sScores.add(asDouble.intValue());
|
|
96
|
+ }
|
|
97
|
+ }
|
|
98
|
+ }
|
|
99
|
+ if (homeType == 2) {
|
|
100
|
+ //获取本库下所有库id
|
|
101
|
+ List<Integer> allDepotChild = systemFeign.getAllDepotChild(depotId);
|
|
102
|
+ List<SysUserActivity> groupByDepotId = activityMapper.getGroupByDepotId(allDepotChild, lastMonth);
|
|
103
|
+ if (groupByDepotId != null && groupByDepotId.size() > MyConstant.ZERO) {
|
|
104
|
+ //获取所有库map
|
|
105
|
+ Map<String, List<SysUserActivity>> collect = groupByDepotId.stream().collect(Collectors.groupingBy(t -> t.getDepotName()));
|
|
106
|
+ for (String key : collect.keySet()) {
|
|
107
|
+ depotNames.add(key);
|
|
108
|
+ Double asDouble = collect.get(key).stream().mapToInt(t -> t.getUsActivity()).average().getAsDouble();
|
|
109
|
+ sScores.add(asDouble.intValue());
|
|
110
|
+ }
|
|
111
|
+ }
|
|
112
|
+ }
|
|
113
|
+ if (homeType == 3) {
|
|
114
|
+ //获取本库下所有库id
|
|
115
|
+ List<SysUserActivity> groupByDepotId = activityMapper.getGroupByDepotId(Lists.newArrayList(depotId), lastMonth);
|
|
116
|
+ for (SysUserActivity comp : groupByDepotId) {
|
|
117
|
+ depotNames.add(comp.getPersonnelName());
|
|
118
|
+ sScores.add(comp.getUsActivity());
|
|
119
|
+ }
|
|
120
|
+ }
|
|
121
|
+
|
|
122
|
+ HashMap<String, Object> map = Maps.newHashMap();
|
|
123
|
+ map.put("depotName", depotNames);
|
|
124
|
+ map.put("series", sScores);
|
|
125
|
+ return map;
|
|
126
|
+ }
|
20
|
127
|
}
|