libo 4 lat temu
rodzic
commit
6b76b2cc09

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

@@ -104,9 +104,9 @@ public class UserController {
104
 
104
 
105
 
105
 
106
     @GetMapping("data_total")
106
     @GetMapping("data_total")
107
-    public TDBAResponse data_total(BaseUser baseUser){
107
+    public TDBAResponse data_total(@RequestParam(name = "id", required = false) Integer id, BaseUser baseUser){
108
         Objects.requireNonNull(baseUser, "请登录后操作");
108
         Objects.requireNonNull(baseUser, "请登录后操作");
109
-        return buildSuccess(userService.dataTotal(baseUser));
109
+        return buildSuccess(userService.dataTotal(id, baseUser));
110
     }
110
     }
111
 
111
 
112
     @GetMapping("data_list")
112
     @GetMapping("data_list")

+ 2 - 1
src/main/java/com/tdba/cxb/ares/api/repository/UserMapper.java

@@ -49,7 +49,8 @@ public interface UserMapper {
49
 
49
 
50
     UserVo selectByAccountForSimple(@Param("mobile") String mobile);
50
     UserVo selectByAccountForSimple(@Param("mobile") String mobile);
51
 
51
 
52
-    List<DataTotalResp> selectTotal(@Param("uid") Integer uid);
52
+    List<DataTotalResp> selectTotal(@Param("uid") Integer uid,
53
+                                    @Param("bindUid") Integer bindUid);
53
     List<DataListResp> selectList(@Param("type") Integer type,
54
     List<DataListResp> selectList(@Param("type") Integer type,
54
                                   @Param("uid") Integer uid);
55
                                   @Param("uid") Integer uid);
55
 }
56
 }

+ 18 - 5
src/main/java/com/tdba/cxb/ares/api/service/UserService.java

@@ -447,9 +447,6 @@ public class UserService {
447
         if(userBindMapper.selectUid(baseUser.getId()).stream().noneMatch(row -> row.equals(param.getId()))){
447
         if(userBindMapper.selectUid(baseUser.getId()).stream().noneMatch(row -> row.equals(param.getId()))){
448
             throw new TDBAException("运营商未关联该用户");
448
             throw new TDBAException("运营商未关联该用户");
449
         }
449
         }
450
-
451
-
452
-
453
     }
450
     }
454
 
451
 
455
     /**
452
     /**
@@ -473,8 +470,9 @@ public class UserService {
473
      * @param baseUser
470
      * @param baseUser
474
      * @return
471
      * @return
475
      */
472
      */
476
-    public List<DataTotalResp> dataTotal(BaseUser baseUser){
477
-        List<DataTotalResp> list = userMapper.selectTotal(baseUser.getId());
473
+    public List<DataTotalResp> dataTotal(Integer id, BaseUser baseUser){
474
+        List<DataTotalResp> list = userMapper.selectTotal(id, baseUser.getId());
475
+
478
         if(list.isEmpty()){
476
         if(list.isEmpty()){
479
             list = List.of(
477
             list = List.of(
480
                     DataTotalResp.DataTotalRespBuilder.aDataTotalResp()
478
                     DataTotalResp.DataTotalRespBuilder.aDataTotalResp()
@@ -498,6 +496,21 @@ public class UserService {
498
                             .withCount(0)
496
                             .withCount(0)
499
                             .build());
497
                             .build());
500
         }
498
         }
499
+
500
+        List<Integer> idList = new ArrayList<>();
501
+        idList.add(0);
502
+        idList.add(1);
503
+        idList.add(2);
504
+        idList.add(3);
505
+        idList.add(4);
506
+        idList.removeAll(list.stream().map(DataTotalResp::getUser_type).toList());
507
+        if(!idList.isEmpty()){
508
+            list.addAll(idList.stream().map(row -> DataTotalResp.DataTotalRespBuilder.aDataTotalResp()
509
+                    .withUser_type(row)
510
+                    .withCount(0)
511
+                    .build()).toList());
512
+        }
513
+
501
         return list.stream().map(row -> {
514
         return list.stream().map(row -> {
502
             row.setName(switch (row.getUser_type()){
515
             row.setName(switch (row.getUser_type()){
503
                 case 0 -> "普通用户";
516
                 case 0 -> "普通用户";

+ 18 - 10
src/main/resources/mapper/UserMapper.xml

@@ -161,16 +161,24 @@
161
             user_count
161
             user_count
162
         where
162
         where
163
             del_flag = 0
163
             del_flag = 0
164
-          and uid in (
165
-            select
166
-                uid
167
-            from
168
-                user_bind ub
169
-            where
170
-                ub.del_flag = 0
171
-              and ub.type = 0
172
-              and ub.bind_uid = #{uid}
173
-        )
164
+
165
+          <choose>
166
+              <when test="uid != null">
167
+                and uid = #{uid}
168
+              </when>
169
+            <otherwise>
170
+                and uid in (
171
+                    select
172
+                        uid
173
+                    from
174
+                        user_bind ub
175
+                    where
176
+                        ub.del_flag = 0
177
+                        and ub.type = 0
178
+                        and ub.bind_uid = #{bindUid}
179
+                )
180
+            </otherwise>
181
+          </choose>
174
         group by
182
         group by
175
             user_type
183
             user_type
176
     </select>
184
     </select>