Browse Source

Merge branch 'master' of http://101.36.160.140:21044/csc/csc-szls-business

gaodd 3 years ago
parent
commit
846a4b454a

+ 7 - 0
src/main/java/com/unissoft/mapper/SysUserActivityMapper.java

@@ -1,7 +1,11 @@
1 1
 package com.unissoft.mapper;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
4 5
 import com.unissoft.model.SysUserActivity;
6
+import org.apache.ibatis.annotations.Param;
7
+
8
+import java.util.List;
5 9
 
6 10
 /**
7 11
  * <p>
@@ -13,4 +17,7 @@ import com.unissoft.model.SysUserActivity;
13 17
  */
14 18
 public interface SysUserActivityMapper extends BaseMapper<SysUserActivity> {
15 19
 
20
+    IPage<SysUserActivity> getPage(IPage<SysUserActivity> page, @Param("depots") List<Integer> depots, @Param("sTime") String sTime);
21
+
22
+    List<SysUserActivity> getGroupByDepotId(@Param("depots") List<Integer> depots, @Param("sTime") String sTime);
16 23
 }

+ 35 - 0
src/main/java/com/unissoft/mapper/SysUserActivityMapper.xml

@@ -24,4 +24,39 @@
24 24
         id, user_id, personnel_name, depot_id, depot_name, province_ranking, depot_ranking, s_position, completion_id, act_time, us_activity, spare_one, spare_two
25 25
     </sql>
26 26
 
27
+    <select id="getPage" resultMap="BaseResultMap">
28
+        SELECT
29
+        <include refid="Base_Column_List"/>
30
+        FROM
31
+        sys_user_activity
32
+        <where>
33
+            <if test="sTime != null and sTime != ''">
34
+                and DATE_FORMAT(`act_time`, '%Y%m') = DATE_FORMAT(#{sTime}, '%Y%m')
35
+            </if>
36
+            <if test="depots != null">
37
+                AND depot_id IN
38
+                <foreach item="item" collection="depots" index="index" open="(" separator="," close=")">#{item}</foreach>
39
+            </if>
40
+        </where>
41
+        ORDER BY
42
+        us_activity DESC
43
+    </select>
44
+
45
+    <select id="getGroupByDepotId" resultMap="BaseResultMap">
46
+        SELECT
47
+        <include refid="Base_Column_List"/>
48
+        FROM
49
+        sys_user_activity
50
+        <where>
51
+            <if test="sTime != null and sTime != ''">
52
+                and DATE_FORMAT(`act_time`, '%Y%m') = DATE_FORMAT(#{sTime}, '%Y%m')
53
+            </if>
54
+            <if test="depots != null">
55
+                AND depot_id IN
56
+                <foreach item="item" collection="depots" index="index" open="(" separator="," close=")">#{item}</foreach>
57
+            </if>
58
+        </where>
59
+        ORDER BY
60
+        us_activity DESC
61
+    </select>
27 62
 </mapper>

+ 3 - 1
src/main/java/com/unissoft/model/SysUserActivity.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
4 4
 import com.baomidou.mybatisplus.annotation.TableField;
5 5
 import com.baomidou.mybatisplus.annotation.TableId;
6 6
 import com.baomidou.mybatisplus.annotation.TableName;
7
+import com.fasterxml.jackson.annotation.JsonFormat;
7 8
 import io.swagger.annotations.ApiModel;
8 9
 import io.swagger.annotations.ApiModelProperty;
9 10
 import lombok.Data;
@@ -23,7 +24,7 @@ import java.util.Date;
23 24
 @Data
24 25
 @EqualsAndHashCode(callSuper = false)
25 26
 @TableName("sys_user_activity")
26
-@ApiModel(value="SysUserActivity对象", description="用户活跃度统计表")
27
+@ApiModel(value = "SysUserActivity对象", description = "用户活跃度统计表")
27 28
 public class SysUserActivity implements Serializable {
28 29
 
29 30
     private static final long serialVersionUID = 1L;
@@ -63,6 +64,7 @@ public class SysUserActivity implements Serializable {
63 64
     @TableField("completion_id")
64 65
     private Integer completionId;
65 66
 
67
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
66 68
     @TableField("act_time")
67 69
     private Date actTime;
68 70
 

+ 33 - 3
src/main/java/com/unissoft/ventilation/controller/SysUserActivityController.java

@@ -1,8 +1,17 @@
1 1
 package com.unissoft.ventilation.controller;
2 2
 
3 3
 
4
-import org.springframework.web.bind.annotation.RequestMapping;
5
-import org.springframework.web.bind.annotation.RestController;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.unissoft.model.SysUserActivity;
6
+import com.unissoft.result.PageParam;
7
+import com.unissoft.result.ResultView;
8
+import com.unissoft.ventilation.service.SysUserActivityService;
9
+import io.swagger.annotations.Api;
10
+import io.swagger.annotations.ApiOperation;
11
+import org.springframework.beans.factory.annotation.Autowired;
12
+import org.springframework.web.bind.annotation.*;
13
+
14
+import java.util.Map;
6 15
 
7 16
 /**
8 17
  * <p>
@@ -12,8 +21,29 @@ import org.springframework.web.bind.annotation.RestController;
12 21
  * @author root
13 22
  * @since 2021-03-10
14 23
  */
24
+@Api(description = "用户活跃度统计")
15 25
 @RestController
16
-@RequestMapping("/sys-user-activity")
26
+@RequestMapping("/sysUserActivity")
17 27
 public class SysUserActivityController {
18 28
 
29
+    @Autowired
30
+    private SysUserActivityService activityService;
31
+
32
+    @ApiOperation(value = "统计列表分页查询,其中type属性代表是否查询单个库下面的数据(1代表单个库,空代表所有)", notes = "{\n" +
33
+            "  \"condition\": \"{'depotId':'2','sTime':'2021-03','type':'1'}\",\n" +
34
+            "  \"pageIndex\": 1,\n" +
35
+            "  \"pageSize\": 10\n" +
36
+            "}")
37
+    @PostMapping("/getByPage")
38
+    public ResultView getByPage(@RequestBody PageParam pageParam) {
39
+        IPage<SysUserActivity> byPage = activityService.getByPage(pageParam);
40
+        return ResultView.success(byPage);
41
+    }
42
+
43
+    @ApiOperation(value = "首页右侧工作统计查询", notes = "depotId库编码,homeType<1.分公司领导首页 2.库主任及以上领导首页 3.员工首页>")
44
+    @GetMapping("/getGroupByDepotId")
45
+    public ResultView getGroupByDepotId(@RequestParam("depotId") Integer depotId, @RequestParam("homeType") Integer homeType) {
46
+        Map<String, Object> groupByDepotId = activityService.getGroupByDepotId(depotId, homeType);
47
+        return ResultView.success(groupByDepotId);
48
+    }
19 49
 }

+ 7 - 0
src/main/java/com/unissoft/ventilation/service/SysUserActivityService.java

@@ -1,7 +1,11 @@
1 1
 package com.unissoft.ventilation.service;
2 2
 
3
+import com.baomidou.mybatisplus.core.metadata.IPage;
3 4
 import com.baomidou.mybatisplus.extension.service.IService;
4 5
 import com.unissoft.model.SysUserActivity;
6
+import com.unissoft.result.PageParam;
7
+
8
+import java.util.Map;
5 9
 
6 10
 /**
7 11
  * <p>
@@ -13,4 +17,7 @@ import com.unissoft.model.SysUserActivity;
13 17
  */
14 18
 public interface SysUserActivityService extends IService<SysUserActivity> {
15 19
 
20
+    IPage<SysUserActivity> getByPage(PageParam pageParam);
21
+
22
+    Map<String, Object> getGroupByDepotId(Integer depotId, Integer homeType);
16 23
 }

+ 10 - 6
src/main/java/com/unissoft/ventilation/service/impl/StatisticsWorkCompletionServiceImpl.java

@@ -10,7 +10,6 @@ import com.unissoft.feign.SystemFeign;
10 10
 import com.unissoft.mapper.StatisticsWorkCompletionMapper;
11 11
 import com.unissoft.model.StatisticsWorkCompletion;
12 12
 import com.unissoft.result.PageParam;
13
-import com.unissoft.result.ResultView;
14 13
 import com.unissoft.utils.DateUtil;
15 14
 import com.unissoft.ventilation.service.StatisticsWorkCompletionService;
16 15
 import org.apache.commons.lang.StringUtils;
@@ -18,7 +17,10 @@ import org.json.JSONObject;
18 17
 import org.springframework.beans.factory.annotation.Autowired;
19 18
 import org.springframework.stereotype.Service;
20 19
 
21
-import java.util.*;
20
+import java.util.ArrayList;
21
+import java.util.HashMap;
22
+import java.util.List;
23
+import java.util.Map;
22 24
 import java.util.stream.Collectors;
23 25
 
24 26
 /**
@@ -81,7 +83,7 @@ public class StatisticsWorkCompletionServiceImpl extends ServiceImpl<StatisticsW
81 83
         //获取上个月份
82 84
         String lastMonth = DateUtil.getLastMonth();
83 85
         ArrayList<String> depotNames = Lists.newArrayList();
84
-        ArrayList<Double> sScores = Lists.newArrayList();
86
+        ArrayList<Integer> sScores = Lists.newArrayList();
85 87
         if (homeType == 1) {
86 88
             //查詢
87 89
             List<StatisticsWorkCompletion> groupByDepotId = workCompletionMapper.getGroupByDepotId(null, lastMonth);
@@ -90,7 +92,8 @@ public class StatisticsWorkCompletionServiceImpl extends ServiceImpl<StatisticsW
90 92
                 Map<String, List<StatisticsWorkCompletion>> collect = groupByDepotId.stream().collect(Collectors.groupingBy(t -> t.getDepotName()));
91 93
                 for (String key : collect.keySet()) {
92 94
                     depotNames.add(key);
93
-                    sScores.add(collect.get(key).stream().mapToInt(t -> t.getSScore()).average().getAsDouble());
95
+                    Double asDouble = collect.get(key).stream().mapToInt(t -> t.getSScore()).average().getAsDouble();
96
+                    sScores.add(asDouble.intValue());
94 97
                 }
95 98
             }
96 99
         }
@@ -103,7 +106,8 @@ public class StatisticsWorkCompletionServiceImpl extends ServiceImpl<StatisticsW
103 106
                 Map<String, List<StatisticsWorkCompletion>> collect = groupByDepotId.stream().collect(Collectors.groupingBy(t -> t.getDepotName()));
104 107
                 for (String key : collect.keySet()) {
105 108
                     depotNames.add(key);
106
-                    sScores.add(collect.get(key).stream().mapToInt(t -> t.getSScore()).average().getAsDouble());
109
+                    Double asDouble = collect.get(key).stream().mapToInt(t -> t.getSScore()).average().getAsDouble();
110
+                    sScores.add(asDouble.intValue());
107 111
                 }
108 112
             }
109 113
         }
@@ -112,7 +116,7 @@ public class StatisticsWorkCompletionServiceImpl extends ServiceImpl<StatisticsW
112 116
             List<StatisticsWorkCompletion> groupByDepotId = workCompletionMapper.getGroupByDepotId(Lists.newArrayList(depotId), lastMonth);
113 117
             for (StatisticsWorkCompletion comp : groupByDepotId) {
114 118
                 depotNames.add(comp.getPersonnelName());
115
-                sScores.add(Double.valueOf(comp.getSScore()));
119
+                sScores.add(comp.getSScore());
116 120
             }
117 121
         }
118 122
 

+ 107 - 0
src/main/java/com/unissoft/ventilation/service/impl/SysUserActivityServiceImpl.java

@@ -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
 }