libo 4 lat temu
rodzic
commit
6ae7356c75

+ 18 - 8
src/main/java/com/tdba/cxb/ares/api/controller/UserController.java

@@ -12,11 +12,15 @@ import org.springframework.web.bind.annotation.*;
12 12
 import javax.annotation.Resource;
13 13
 import javax.validation.constraints.NotNull;
14 14
 
15
+import java.security.Identity;
15 16
 import java.time.LocalDate;
16 17
 import java.time.LocalDateTime;
17 18
 import java.time.ZoneOffset;
18 19
 import java.time.ZonedDateTime;
20
+import java.util.Map;
19 21
 import java.util.Objects;
22
+import java.util.function.Function;
23
+import java.util.stream.Collectors;
20 24
 
21 25
 import static com.tdba.cxb.ares.api.config.PageEntityBuilder.buildByPageInfo;
22 26
 import static com.tdba.cxb.ares.api.model.TDBAResponseBuilder.buildSuccess;
@@ -85,21 +89,27 @@ public class UserController {
85 89
     @GetMapping("data_total")
86 90
     public TDBAResponse data_total(BaseUser baseUser){
87 91
         Objects.requireNonNull(baseUser, "请登录后操作");
88
-        return buildSuccess("");
92
+        return buildSuccess(userService.dataTotal(baseUser).stream().collect(Collectors.toMap(DataTotalResp::getUser_type, DataTotalResp::getCount)));
89 93
     }
90 94
 
91 95
     @GetMapping("data_list")
92
-    public TDBAResponse data_list(@RequestParam(name = "type", required = false) @NotNull(message = "类型不能为空") Integer type, BaseUser baseUser){
96
+    public TDBAResponse data_list(@ModelAttribute @Validated DataLIstReq param, BaseUser baseUser){
93 97
         Objects.requireNonNull(baseUser, "请登录后操作");
94
-
95
-        return buildSuccess("");
98
+        PageHelper.startPage(param.getPage(), param.getLimit());
99
+        return buildSuccess(buildByPageInfo(new PageInfo(userService.dataList(param, baseUser))));
96 100
     }
97 101
 
98 102
     @GetMapping("detail_list")
99
-    public TDBAResponse detail_list(@RequestParam(name = "userId", required = false) @NotNull(message = "用户ID不能为空") Integer userId,
100
-                                    @RequestParam(name = "userType", required = false) Integer userType, BaseUser baseUser){
101
-//        Objects.requireNonNull(baseUser, "请登录后操作");
102
-        return buildSuccess(userService.detailList(userId, userType));
103
+    public TDBAResponse detail_list(@ModelAttribute @Validated DetailListReq param, BaseUser baseUser){
104
+        Objects.requireNonNull(baseUser, "请登录后操作");
105
+        PageHelper.startPage(param.getPage(), param.getLimit());
106
+        return buildSuccess(buildByPageInfo(new PageInfo(userService.detailList(param.getUser_id(), param.getUser_type()))));
107
+    }
108
+
109
+    @GetMapping("info")
110
+    public TDBAResponse info(BaseUser baseUser){
111
+        Objects.requireNonNull(baseUser, "请登录后操作");
112
+        return buildSuccess(userService.info(baseUser.getId()));
103 113
     }
104 114
 
105 115
     public static void main(String[] args) {

+ 23 - 0
src/main/java/com/tdba/cxb/ares/api/model/DataLIstReq.java

@@ -0,0 +1,23 @@
1
+package com.tdba.cxb.ares.api.model;
2
+
3
+import javax.validation.constraints.NotNull;
4
+
5
+/**
6
+ * @program: order-web
7
+ * @description:
8
+ * @author: libo
9
+ * @create: 2022-06-10 16:53:21
10
+ */
11
+public class DataLIstReq extends PageParam {
12
+
13
+    @NotNull(message = "类型不能为空")
14
+    private Integer type;
15
+
16
+    public Integer getType() {
17
+        return type;
18
+    }
19
+
20
+    public void setType(Integer type) {
21
+        this.type = type;
22
+    }
23
+}

+ 9 - 10
src/main/java/com/tdba/cxb/ares/api/model/DataListResp.java

@@ -11,6 +11,8 @@ import java.time.LocalDateTime;
11 11
  */
12 12
 public class DataListResp {
13 13
 
14
+    private String date;
15
+
14 16
     /** 普通用户数量*/
15 17
     private Integer user_count = 0;
16 18
 
@@ -26,8 +28,13 @@ public class DataListResp {
26 28
     /** 代理商数量*/
27 29
     private Integer agent_count = 0;
28 30
 
29
-    /** 创建时间*/
30
-    private LocalDate date;
31
+    public String getDate() {
32
+        return date;
33
+    }
34
+
35
+    public void setDate(String date) {
36
+        this.date = date;
37
+    }
31 38
 
32 39
     public Integer getUser_count() {
33 40
         return user_count;
@@ -68,12 +75,4 @@ public class DataListResp {
68 75
     public void setAgent_count(Integer agent_count) {
69 76
         this.agent_count = agent_count;
70 77
     }
71
-
72
-    public LocalDate getDate() {
73
-        return date;
74
-    }
75
-
76
-    public void setDate(LocalDate date) {
77
-        this.date = date;
78
-    }
79 78
 }

+ 12 - 45
src/main/java/com/tdba/cxb/ares/api/model/DataTotalResp.java

@@ -10,58 +10,25 @@ import java.time.LocalDateTime;
10 10
  */
11 11
 public class DataTotalResp {
12 12
 
13
-    /** 普通用户数量*/
14
-    private Integer user_count = 0;
13
+    /** 用户类型*/
14
+    private Integer user_type = 0;
15 15
 
16
-    /** 大仓会员数量*/
17
-    private Integer warehouse_count = 0;
16
+    /** 数量*/
17
+    private Integer count = 0;
18 18
 
19
-    /** 商户数量*/
20
-    private Integer merchant_count = 0;
21
-
22
-    /** 渠道商数量*/
23
-    private Integer channel_count = 0;
24
-
25
-    /** 代理商数量*/
26
-    private Integer agent_count = 0;
27
-
28
-    public Integer getUser_count() {
29
-        return user_count;
30
-    }
31
-
32
-    public void setUser_count(Integer user_count) {
33
-        this.user_count = user_count;
34
-    }
35
-
36
-    public Integer getWarehouse_count() {
37
-        return warehouse_count;
38
-    }
39
-
40
-    public void setWarehouse_count(Integer warehouse_count) {
41
-        this.warehouse_count = warehouse_count;
42
-    }
43
-
44
-    public Integer getMerchant_count() {
45
-        return merchant_count;
46
-    }
47
-
48
-    public void setMerchant_count(Integer merchant_count) {
49
-        this.merchant_count = merchant_count;
50
-    }
51
-
52
-    public Integer getChannel_count() {
53
-        return channel_count;
19
+    public Integer getUser_type() {
20
+        return user_type;
54 21
     }
55 22
 
56
-    public void setChannel_count(Integer channel_count) {
57
-        this.channel_count = channel_count;
23
+    public void setUser_type(Integer user_type) {
24
+        this.user_type = user_type;
58 25
     }
59 26
 
60
-    public Integer getAgent_count() {
61
-        return agent_count;
27
+    public Integer getCount() {
28
+        return count;
62 29
     }
63 30
 
64
-    public void setAgent_count(Integer agent_count) {
65
-        this.agent_count = agent_count;
31
+    public void setCount(Integer count) {
32
+        this.count = count;
66 33
     }
67 34
 }

+ 36 - 0
src/main/java/com/tdba/cxb/ares/api/model/DetailListReq.java

@@ -0,0 +1,36 @@
1
+package com.tdba.cxb.ares.api.model;
2
+
3
+import org.springframework.web.bind.annotation.RequestParam;
4
+
5
+import javax.validation.constraints.NotNull;
6
+
7
+/**
8
+ * @program: order-web
9
+ * @description:
10
+ * @author: libo
11
+ * @create: 2022-06-10 16:57:36
12
+ */
13
+public class DetailListReq extends PageParam{
14
+
15
+    @NotNull(message = "用户ID不能为空")
16
+    private Integer user_id;
17
+
18
+    @NotNull(message = "用户类型不能为空")
19
+    private Integer user_type;
20
+
21
+    public Integer getUser_id() {
22
+        return user_id;
23
+    }
24
+
25
+    public void setUser_id(Integer user_id) {
26
+        this.user_id = user_id;
27
+    }
28
+
29
+    public Integer getUser_type() {
30
+        return user_type;
31
+    }
32
+
33
+    public void setUser_type(Integer user_type) {
34
+        this.user_type = user_type;
35
+    }
36
+}

+ 6 - 0
src/main/java/com/tdba/cxb/ares/api/repository/UserMapper.java

@@ -1,5 +1,7 @@
1 1
 package com.tdba.cxb.ares.api.repository;
2 2
 
3
+import com.tdba.cxb.ares.api.model.DataListResp;
4
+import com.tdba.cxb.ares.api.model.DataTotalResp;
3 5
 import com.tdba.cxb.ares.api.model.UserDto;
4 6
 import com.tdba.cxb.ares.api.model.UserVo;
5 7
 import org.apache.ibatis.annotations.Mapper;
@@ -46,4 +48,8 @@ public interface UserMapper {
46 48
     List<UserVo> selectByBindUid(@Param("bindUid") Integer bindUid);
47 49
 
48 50
     UserVo selectByAccountForSimple(@Param("mobile") String mobile);
51
+
52
+    List<DataTotalResp> selectTotal(@Param("uid") Integer uid);
53
+    List<DataListResp> selectList(@Param("type") Integer type,
54
+                                  @Param("uid") Integer uid);
49 55
 }

+ 13 - 0
src/main/java/com/tdba/cxb/ares/api/service/UserService.java

@@ -427,4 +427,17 @@ public class UserService {
427 427
     public List<DetailListResp> detailList(Integer uid, Integer userType){
428 428
         return userRelateMapper.selectByPid(uid, (null == userType)?0:userType);
429 429
     }
430
+
431
+    /**
432
+     * 用户数量统计
433
+     * @param baseUser
434
+     * @return
435
+     */
436
+    public List<DataTotalResp> dataTotal(BaseUser baseUser){
437
+        return userMapper.selectTotal(baseUser.getId());
438
+    }
439
+
440
+    public List<DataListResp> dataList(DataLIstReq param, BaseUser baseUser){
441
+        return userMapper.selectList(param.getType(), baseUser.getId());
442
+    }
430 443
 }

+ 68 - 0
src/main/resources/mapper/UserMapper.xml

@@ -149,4 +149,72 @@
149 149
            u.account = #{mobile}
150 150
         limit 1
151 151
     </select>
152
+
153
+    <select id="selectTotal" resultType="com.tdba.cxb.ares.api.model.DataTotalResp">
154
+        select
155
+            user_type,
156
+            sum(num) 'count'
157
+        from
158
+            user_count
159
+        where
160
+            del_flag = 0
161
+          and uid in (
162
+            select
163
+                uid
164
+            from
165
+                user_bind ub
166
+            where
167
+                ub.del_flag = 0
168
+              and ub.bind_uid = #{uid}
169
+        )
170
+        group by
171
+            user_type
172
+    </select>
173
+
174
+    <select id="selectList" resultType="com.tdba.cxb.ares.api.model.DataListResp">
175
+        select
176
+            <choose>
177
+                <when test="type == null || type == 0">
178
+                    DATE_FORMAT(date,'%Y-%m-%d') as 'date',
179
+                </when>
180
+                <when test="type == 1">
181
+                    DATE_FORMAT(date,'%Y-%m') as 'date',
182
+                </when>
183
+            </choose>
184
+            sum(IF(user_type = 0, num, 0)) as 'user_count',
185
+            sum(IF(user_type = 1, num, 0)) as 'warehouse_count',
186
+            sum(IF(user_type = 2, num, 0)) as 'merchant_count',
187
+            sum(IF(user_type = 3, num, 0)) as 'channel_count',
188
+            sum(IF(user_type = 4, num, 0)) as 'agent_count'
189
+        from
190
+            user_count
191
+        where
192
+            del_flag = 0
193
+            and uid in (
194
+                select
195
+                    uid
196
+                    from
197
+                        user_bind ub
198
+                    where
199
+                        ub.del_flag = 0
200
+                        and ub.bind_uid = #{uid}
201
+            )
202
+        <choose>
203
+            <when test="type == null || type == 0">
204
+                group by `date`
205
+            </when>
206
+            <when test="type == 1">
207
+                group by DATE_FORMAT(date,'%Y-%m')
208
+            </when>
209
+        </choose>
210
+
211
+        <choose>
212
+            <when test="type == null || type == 0">
213
+                order by `date` desc
214
+            </when>
215
+            <when test="type == 1">
216
+                order by DATE_FORMAT(date,'%Y-%m') desc
217
+            </when>
218
+        </choose>
219
+    </select>
152 220
 </mapper>

+ 2 - 1
src/main/resources/mapper/UserRelateMapper.xml

@@ -162,7 +162,7 @@
162 162
         select
163 163
             u.account 'mobile',
164 164
                 u.uid 'id',
165
-                u.nickname 'name'
165
+                u.nickname 'name',
166 166
                 ur.date
167 167
         from
168 168
             user_relate ur
@@ -208,5 +208,6 @@
208 208
                 and ur.is_agent = 0
209 209
             </otherwise>
210 210
         </choose>
211
+        order by date desc
211 212
     </select>
212 213
 </mapper>