Quellcode durchsuchen

* 商品详情接口bug修复

libo vor 4 Jahren
Ursprung
Commit
cfb98559ae

+ 5 - 1
src/main/java/com/tdba/cxb/ares/api/controller/RegionController.java

@@ -15,7 +15,7 @@ import static com.tdba.cxb.ares.api.model.TDBAResponseBuilder.buildSuccess;
15 15
  * @author: libo
16 16
  * @create: 2022-06-02 18:23:33
17 17
  */
18
-@TDBAController("/api/v1/system/city")
18
+//@TDBAController("/api/v1/system/city")
19 19
 public class RegionController {
20 20
 
21 21
     @Resource
@@ -25,4 +25,8 @@ public class RegionController {
25 25
     public TDBAResponse list(){
26 26
         return buildSuccess(districtService.regionList());
27 27
     }
28
+
29
+    public static void main(String[] args) {
30
+        System.out.println("\u50a8\u84c4\u4fdd");
31
+    }
28 32
 }

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

@@ -0,0 +1,67 @@
1
+package com.tdba.cxb.ares.api.controller;
2
+
3
+import com.tdba.cxb.ares.api.model.BaseUser;
4
+import com.tdba.cxb.ares.api.model.BindUserAdd;
5
+import com.tdba.cxb.ares.api.model.OperatorLoginReq;
6
+import com.tdba.cxb.ares.api.model.TDBAResponse;
7
+import com.tdba.cxb.ares.api.service.UserService;
8
+import com.tdba.cxb.ares.api.util.TDBAController;
9
+import org.springframework.validation.annotation.Validated;
10
+import org.springframework.web.bind.annotation.GetMapping;
11
+import org.springframework.web.bind.annotation.PostMapping;
12
+import org.springframework.web.bind.annotation.RequestBody;
13
+
14
+import javax.annotation.Resource;
15
+
16
+import java.time.LocalDate;
17
+
18
+import static com.tdba.cxb.ares.api.model.TDBAResponseBuilder.buildSuccess;
19
+
20
+/**
21
+ * @program: order-web
22
+ * @description: 用户登录
23
+ * @author: libo
24
+ * @create: 2022-06-06 17:48:41
25
+ */
26
+@TDBAController("/api/v1/operate")
27
+public class UserController {
28
+
29
+    @Resource
30
+    private UserService userService;
31
+
32
+    @GetMapping("statistics_list")
33
+    public TDBAResponse statistics_list(){
34
+        userService.createSpreadInfo(LocalDate.of(2021, 4, 9));
35
+        return buildSuccess("");
36
+    }
37
+
38
+    /**
39
+     * 登录
40
+     * @param param 请求参数
41
+     * @return
42
+     */
43
+    @PostMapping("login")
44
+    public TDBAResponse login(@RequestBody @Validated OperatorLoginReq param){
45
+        return buildSuccess("");
46
+    }
47
+
48
+    /**
49
+     * 绑定的成员列表
50
+     * @param param
51
+     * @return
52
+     */
53
+    @GetMapping("bind_list")
54
+    public TDBAResponse bind_list(BaseUser baseUser){
55
+        return buildSuccess("");
56
+    }
57
+
58
+    /**
59
+     * 绑定用户
60
+     * @param baseUser
61
+     * @return
62
+     */
63
+    @PostMapping("bind_add")
64
+    public TDBAResponse bind_add(@RequestBody @Validated BindUserAdd param, BaseUser baseUser){
65
+        return buildSuccess("");
66
+    }
67
+}

+ 48 - 0
src/main/java/com/tdba/cxb/ares/api/model/BindUserAdd.java

@@ -0,0 +1,48 @@
1
+package com.tdba.cxb.ares.api.model;
2
+
3
+import javax.validation.constraints.NotEmpty;
4
+
5
+/**
6
+ * @program: order-web
7
+ * @description: 运营商新增团队成员请求参数
8
+ * @author: libo
9
+ * @create: 2022-06-08 11:21:30
10
+ */
11
+public class BindUserAdd {
12
+
13
+    /** 名称*/
14
+    @NotEmpty(message = "名称不能为空")
15
+    private String name;
16
+
17
+    /** 手机号*/
18
+    @NotEmpty(message = "手机号不能为空")
19
+    private String mobile;
20
+
21
+    /** 验证码*/
22
+    @NotEmpty(message = "验证码不能为空")
23
+    private String code;
24
+
25
+    public String getName() {
26
+        return name;
27
+    }
28
+
29
+    public void setName(String name) {
30
+        this.name = name;
31
+    }
32
+
33
+    public String getMobile() {
34
+        return mobile;
35
+    }
36
+
37
+    public void setMobile(String mobile) {
38
+        this.mobile = mobile;
39
+    }
40
+
41
+    public String getCode() {
42
+        return code;
43
+    }
44
+
45
+    public void setCode(String code) {
46
+        this.code = code;
47
+    }
48
+}

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

@@ -0,0 +1,36 @@
1
+package com.tdba.cxb.ares.api.model;
2
+
3
+import javax.validation.constraints.NotEmpty;
4
+
5
+/**
6
+ * @program: order-web
7
+ * @description: 运营商登录请求参数
8
+ * @author: libo
9
+ * @create: 2022-06-08 11:08:13
10
+ */
11
+public class OperatorLoginReq {
12
+
13
+    /** 手机号*/
14
+    @NotEmpty(message = "手机号不能为空")
15
+    private String mobile;
16
+
17
+    /** 验证码*/
18
+    @NotEmpty(message = "验证码不能为空")
19
+    private String code;
20
+
21
+    public String getMobile() {
22
+        return mobile;
23
+    }
24
+
25
+    public void setMobile(String mobile) {
26
+        this.mobile = mobile;
27
+    }
28
+
29
+    public String getCode() {
30
+        return code;
31
+    }
32
+
33
+    public void setCode(String code) {
34
+        this.code = code;
35
+    }
36
+}

+ 118 - 0
src/main/java/com/tdba/cxb/ares/api/model/UserCount.java

@@ -0,0 +1,118 @@
1
+package com.tdba.cxb.ares.api.model;
2
+
3
+import java.time.LocalDate;
4
+import java.time.LocalDateTime;
5
+
6
+/**
7
+ * @program: order-web
8
+ * @description: 注册用户数量统计
9
+ * @author: libo
10
+ * @create: 2022-06-06 16:52:23
11
+ */
12
+public class UserCount {
13
+
14
+    /** 用户ID*/
15
+    private Integer uid;
16
+
17
+    /** 数量*/
18
+    private Integer num;
19
+
20
+    /** 日期*/
21
+    private LocalDate date;
22
+
23
+    /** 创建时间*/
24
+    private LocalDateTime create_time;
25
+
26
+    /** 用户类型: 0普通用户1大仓会员2商户3渠道商4代理商*/
27
+    private Integer user_type;
28
+
29
+    public Integer getUid() {
30
+        return uid;
31
+    }
32
+
33
+    public void setUid(Integer uid) {
34
+        this.uid = uid;
35
+    }
36
+
37
+    public Integer getNum() {
38
+        return num;
39
+    }
40
+
41
+    public void setNum(Integer num) {
42
+        this.num = num;
43
+    }
44
+
45
+    public LocalDate getDate() {
46
+        return date;
47
+    }
48
+
49
+    public void setDate(LocalDate date) {
50
+        this.date = date;
51
+    }
52
+
53
+    public LocalDateTime getCreate_time() {
54
+        return create_time;
55
+    }
56
+
57
+    public void setCreate_time(LocalDateTime create_time) {
58
+        this.create_time = create_time;
59
+    }
60
+
61
+    public Integer getUser_type() {
62
+        return user_type;
63
+    }
64
+
65
+    public void setUser_type(Integer user_type) {
66
+        this.user_type = user_type;
67
+    }
68
+
69
+    public static final class UserCountBuilder {
70
+        private Integer uid;
71
+        private Integer num;
72
+        private LocalDate date;
73
+        private LocalDateTime create_time;
74
+        private Integer user_type;
75
+
76
+        private UserCountBuilder() {
77
+        }
78
+
79
+        public static UserCountBuilder anUserCount() {
80
+            return new UserCountBuilder();
81
+        }
82
+
83
+        public UserCountBuilder withUid(Integer uid) {
84
+            this.uid = uid;
85
+            return this;
86
+        }
87
+
88
+        public UserCountBuilder withNum(Integer num) {
89
+            this.num = num;
90
+            return this;
91
+        }
92
+
93
+        public UserCountBuilder withDate(LocalDate date) {
94
+            this.date = date;
95
+            return this;
96
+        }
97
+
98
+        public UserCountBuilder withCreate_time(LocalDateTime create_time) {
99
+            this.create_time = create_time;
100
+            return this;
101
+        }
102
+
103
+        public UserCountBuilder withUser_type(Integer user_type) {
104
+            this.user_type = user_type;
105
+            return this;
106
+        }
107
+
108
+        public UserCount build() {
109
+            UserCount userCount = new UserCount();
110
+            userCount.setUid(uid);
111
+            userCount.setNum(num);
112
+            userCount.setDate(date);
113
+            userCount.setCreate_time(create_time);
114
+            userCount.setUser_type(user_type);
115
+            return userCount;
116
+        }
117
+    }
118
+}

+ 86 - 0
src/main/java/com/tdba/cxb/ares/api/model/UserDto.java

@@ -0,0 +1,86 @@
1
+package com.tdba.cxb.ares.api.model;
2
+
3
+/**
4
+ * @program: admin-web
5
+ * @description:
6
+ * @author: libo
7
+ * @create: 2022-06-06 15:26:14
8
+ */
9
+public class UserDto {
10
+
11
+    /**
12
+     * 用户ID
13
+     */
14
+    private Integer uid;
15
+
16
+    /**
17
+     * 推荐人用户ID
18
+     */
19
+    private Integer spread_uid;
20
+
21
+    /**
22
+     * 数量
23
+     */
24
+    private Integer num;
25
+
26
+    public Integer getUid() {
27
+        return uid;
28
+    }
29
+
30
+    public void setUid(Integer uid) {
31
+        this.uid = uid;
32
+    }
33
+
34
+    public Integer getSpread_uid() {
35
+        return spread_uid;
36
+    }
37
+
38
+    public void setSpread_uid(Integer spread_uid) {
39
+        this.spread_uid = spread_uid;
40
+    }
41
+
42
+    public Integer getNum() {
43
+        return num;
44
+    }
45
+
46
+    public void setNum(Integer num) {
47
+        this.num = num;
48
+    }
49
+
50
+
51
+    public static final class UserDtoBuilder {
52
+        private Integer uid;
53
+        private Integer spread_uid;
54
+        private Integer num;
55
+
56
+        private UserDtoBuilder() {
57
+        }
58
+
59
+        public static UserDtoBuilder anUserDto() {
60
+            return new UserDtoBuilder();
61
+        }
62
+
63
+        public UserDtoBuilder withUid(Integer uid) {
64
+            this.uid = uid;
65
+            return this;
66
+        }
67
+
68
+        public UserDtoBuilder withSpread_uid(Integer spread_uid) {
69
+            this.spread_uid = spread_uid;
70
+            return this;
71
+        }
72
+
73
+        public UserDtoBuilder withNum(Integer num) {
74
+            this.num = num;
75
+            return this;
76
+        }
77
+
78
+        public UserDto build() {
79
+            UserDto userDto = new UserDto();
80
+            userDto.setUid(uid);
81
+            userDto.setSpread_uid(spread_uid);
82
+            userDto.setNum(num);
83
+            return userDto;
84
+        }
85
+    }
86
+}

+ 81 - 0
src/main/java/com/tdba/cxb/ares/api/model/UserRelate.java

@@ -0,0 +1,81 @@
1
+package com.tdba.cxb.ares.api.model;
2
+
3
+import java.time.LocalDateTime;
4
+
5
+/**
6
+ * @program: order-web
7
+ * @description: 用户注册关联关系
8
+ * @author: libo
9
+ * @create: 2022-06-06 17:10:08
10
+ */
11
+public class UserRelate {
12
+
13
+    /** 用户ID*/
14
+    private Integer uid;
15
+
16
+    /** 关联用户ID*/
17
+    private Integer pid;
18
+
19
+    /** 创建时间*/
20
+    private LocalDateTime create_time;
21
+
22
+    public Integer getUid() {
23
+        return uid;
24
+    }
25
+
26
+    public void setUid(Integer uid) {
27
+        this.uid = uid;
28
+    }
29
+
30
+    public Integer getPid() {
31
+        return pid;
32
+    }
33
+
34
+    public void setPid(Integer pid) {
35
+        this.pid = pid;
36
+    }
37
+
38
+    public LocalDateTime getCreate_time() {
39
+        return create_time;
40
+    }
41
+
42
+    public void setCreate_time(LocalDateTime create_time) {
43
+        this.create_time = create_time;
44
+    }
45
+
46
+    public static final class UserRelateBuilder {
47
+        private Integer uid;
48
+        private Integer pid;
49
+        private LocalDateTime create_time;
50
+
51
+        private UserRelateBuilder() {
52
+        }
53
+
54
+        public static UserRelateBuilder anUserRelate() {
55
+            return new UserRelateBuilder();
56
+        }
57
+
58
+        public UserRelateBuilder withUid(Integer uid) {
59
+            this.uid = uid;
60
+            return this;
61
+        }
62
+
63
+        public UserRelateBuilder withPid(Integer pid) {
64
+            this.pid = pid;
65
+            return this;
66
+        }
67
+
68
+        public UserRelateBuilder withCreate_time(LocalDateTime create_time) {
69
+            this.create_time = create_time;
70
+            return this;
71
+        }
72
+
73
+        public UserRelate build() {
74
+            UserRelate userRelate = new UserRelate();
75
+            userRelate.setUid(uid);
76
+            userRelate.setPid(pid);
77
+            userRelate.setCreate_time(create_time);
78
+            return userRelate;
79
+        }
80
+    }
81
+}

+ 21 - 0
src/main/java/com/tdba/cxb/ares/api/model/UserTypeEnum.java

@@ -0,0 +1,21 @@
1
+package com.tdba.cxb.ares.api.model;
2
+
3
+/**
4
+ * @program: order-web
5
+ * @description: 用户类型枚举
6
+ * @author: libo
7
+ * @create: 2022-06-08 14:29:11
8
+ */
9
+public enum UserTypeEnum {
10
+
11
+    /** 0普通用户*/
12
+    NORMAL,
13
+    /** 1大仓会员*/
14
+    DACANG,
15
+    /** 2商户*/
16
+    MERCHANT,
17
+    /** 3渠道商*/
18
+    CHANNEL,
19
+    /** 4代理商*/
20
+    AGENT;
21
+}

+ 22 - 0
src/main/java/com/tdba/cxb/ares/api/repository/UserCountMapper.java

@@ -0,0 +1,22 @@
1
+package com.tdba.cxb.ares.api.repository;
2
+
3
+import com.tdba.cxb.ares.api.model.UserCount;
4
+import org.apache.ibatis.annotations.Mapper;
5
+
6
+import java.util.List;
7
+
8
+/**
9
+ * @program: order-web
10
+ * @description: 用户注册统计
11
+ * @author: libo
12
+ * @create: 2022-06-06 17:35:04
13
+ */
14
+@Mapper
15
+public interface UserCountMapper {
16
+
17
+    int insertSelective(UserCount record);
18
+
19
+    int updateByPrimaryKeySelective(UserCount record);
20
+
21
+    int insertSelectiveForeach(List<UserCount> list);
22
+}

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

@@ -0,0 +1,39 @@
1
+package com.tdba.cxb.ares.api.repository;
2
+
3
+import com.tdba.cxb.ares.api.model.UserDto;
4
+import org.apache.ibatis.annotations.Mapper;
5
+import org.apache.ibatis.annotations.Param;
6
+
7
+import java.time.LocalDateTime;
8
+import java.util.List;
9
+
10
+/**
11
+ * @program: order-web
12
+ * @description: 登录用户
13
+ * @author: libo
14
+ * @create: 2022-06-06 15:52:40
15
+ */
16
+@Mapper
17
+public interface UserMapper {
18
+
19
+    /**
20
+     * 根据时间段,获取用户信息
21
+     * @param beginTime 开始时间
22
+     * @param endTime   结束时间
23
+     * @return
24
+     */
25
+    List<UserDto> selectByTimeRegion(@Param("beginTime")LocalDateTime beginTime,
26
+                                     @Param("endTime")LocalDateTime endTime);
27
+
28
+    List<UserDto> selectDacang(@Param("beginTime")LocalDateTime beginTime,
29
+                               @Param("endTime")LocalDateTime endTime);
30
+
31
+    List<UserDto> selectMerchant(@Param("beginTime")LocalDateTime beginTime,
32
+                               @Param("endTime")LocalDateTime endTime);
33
+
34
+    List<UserDto> selectChannel(@Param("beginTime")LocalDateTime beginTime,
35
+                               @Param("endTime")LocalDateTime endTime);
36
+
37
+    List<UserDto> selectAgent(@Param("beginTime")LocalDateTime beginTime,
38
+                               @Param("endTime")LocalDateTime endTime);
39
+}

+ 33 - 0
src/main/java/com/tdba/cxb/ares/api/repository/UserRelateMapper.java

@@ -0,0 +1,33 @@
1
+package com.tdba.cxb.ares.api.repository;
2
+
3
+import com.tdba.cxb.ares.api.model.UserRelate;
4
+import org.apache.ibatis.annotations.Mapper;
5
+import org.apache.ibatis.annotations.Param;
6
+
7
+import java.util.List;
8
+
9
+/**
10
+ * @program: order-web
11
+ * @description: 用户关联关系
12
+ * @author: libo
13
+ * @create: 2022-06-06 17:37:16
14
+ */
15
+@Mapper
16
+public interface UserRelateMapper {
17
+
18
+    /**
19
+     * 根据用户ID,获取关联信息
20
+     * @param uid    用户ID
21
+     * @return
22
+     */
23
+    List<UserRelate> selectByUid(@Param("uid") Integer uid);
24
+
25
+    int insertSelective(UserRelate record);
26
+
27
+    int updateByPrimaryKeySelective(UserRelate record);
28
+
29
+    int insertSelectiveForeach(List<UserRelate> list);
30
+
31
+    Integer updateByUid(@Param("userType") Integer userType,
32
+                        @Param("uid") Integer uid);
33
+}

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

@@ -0,0 +1,299 @@
1
+package com.tdba.cxb.ares.api.service;
2
+
3
+import com.tdba.cxb.ares.api.model.UserCount;
4
+import com.tdba.cxb.ares.api.model.UserDto;
5
+import com.tdba.cxb.ares.api.model.UserRelate;
6
+import com.tdba.cxb.ares.api.model.UserTypeEnum;
7
+import com.tdba.cxb.ares.api.repository.UserCountMapper;
8
+import com.tdba.cxb.ares.api.repository.UserMapper;
9
+import com.tdba.cxb.ares.api.repository.UserRelateMapper;
10
+import com.tdba.cxb.ares.api.util.TDBAException;
11
+import org.slf4j.Logger;
12
+import org.slf4j.LoggerFactory;
13
+import org.springframework.stereotype.Service;
14
+import org.springframework.util.CollectionUtils;
15
+
16
+import javax.annotation.Resource;
17
+import java.time.LocalDate;
18
+import java.time.LocalDateTime;
19
+import java.time.LocalTime;
20
+import java.util.ArrayList;
21
+import java.util.List;
22
+
23
+/**
24
+ * @program: order-web
25
+ * @description: 登录用户
26
+ * @author: libo
27
+ * @create: 2022-06-06 15:58:31
28
+ */
29
+@Service
30
+public class UserService {
31
+
32
+    private static Logger logger = LoggerFactory.getLogger(UserService.class);
33
+
34
+    @Resource
35
+    private UserMapper userMapper;
36
+
37
+    @Resource
38
+    private UserCountMapper userCountMapper;
39
+
40
+    @Resource
41
+    private UserRelateMapper userRelateMapper;
42
+
43
+    public void createSpreadInfo(LocalDate localDate){
44
+
45
+        LocalDateTime currentTime = LocalDateTime.now();
46
+        List<UserCount> resultList = new ArrayList<>();
47
+        List<UserRelate> relateList = new ArrayList<>();
48
+        List<UserDto> list = userMapper.selectByTimeRegion(LocalDateTime.of(localDate, LocalTime.MIN), LocalDateTime.of(localDate, LocalTime.MAX));
49
+        list.stream().forEach(row -> {
50
+            Integer num = countOfChildren(row, list);
51
+            if(0 < num) {
52
+                resultList.add(UserCount.UserCountBuilder.anUserCount()
53
+                        .withUid(row.getUid())
54
+                        .withDate(localDate)
55
+                        .withNum(num)
56
+                        .withCreate_time(currentTime)
57
+                        .build());
58
+
59
+                List<Integer> idlist = listOfChildren(row, list);
60
+                for(int i = 0; i < idlist.size(); i++){
61
+                    Integer currentId = idlist.get(i);
62
+                    relateList.add(UserRelate.UserRelateBuilder.anUserRelate()
63
+                            .withUid(currentId)
64
+                            .withPid(row.getUid())
65
+                            .build());
66
+                    for(int j = i + 1; j < idlist.size(); j++){
67
+                        relateList.add(UserRelate.UserRelateBuilder.anUserRelate()
68
+                                .withUid(idlist.get(j))
69
+                                .withPid(currentId)
70
+                                .build());
71
+                    }
72
+                }
73
+            }
74
+
75
+            final Integer finallyNum = (0 > num)? num: 1;
76
+            //-- 追溯之前的数据
77
+            if((null != row.getSpread_uid()) && (0 < row.getSpread_uid())){
78
+                relateList.add(UserRelate.UserRelateBuilder.anUserRelate()
79
+                        .withUid(row.getUid())
80
+                        .withPid(row.getSpread_uid())
81
+                        .build());
82
+                //推荐人
83
+                resultList.add(UserCount.UserCountBuilder.anUserCount()
84
+                        .withCreate_time(currentTime)
85
+                        .withNum(finallyNum)
86
+                        .withUser_type(UserTypeEnum.NORMAL.ordinal())
87
+                        .withUid(row.getSpread_uid())
88
+                        .withDate(localDate)
89
+                        .build());
90
+
91
+                //往前追溯的推荐人
92
+                userRelateMapper.selectByUid(row.getSpread_uid()).stream().forEach(innerRow -> {
93
+                    resultList.add(UserCount.UserCountBuilder.anUserCount()
94
+                            .withCreate_time(currentTime)
95
+                            .withNum(finallyNum)
96
+                            .withUser_type(UserTypeEnum.NORMAL.ordinal())
97
+                            .withUid(innerRow.getPid())
98
+                            .withDate(localDate)
99
+                            .build());
100
+                });
101
+            }
102
+
103
+        });
104
+        if(!resultList.isEmpty()){
105
+            userCountMapper.insertSelectiveForeach(resultList);
106
+        }
107
+        if(!relateList.isEmpty()){
108
+            userRelateMapper.insertSelectiveForeach(relateList);
109
+        }
110
+        resolverAgent(localDate);
111
+        resolverDacang(localDate);
112
+        resolverMerchant(localDate);
113
+        resolverChannel(localDate);
114
+    }
115
+
116
+    /**
117
+     * 大仓会员
118
+     * @param localDateTime 日期
119
+     */
120
+    public void resolverDacang(LocalDate localDate){
121
+        LocalDateTime currentTime = LocalDateTime.now();
122
+        List<UserDto> userList = userMapper.selectDacang(LocalDateTime.of(localDate, LocalTime.MIN), LocalDateTime.of(localDate, LocalTime.MAX));
123
+        List<UserCount> resultList = new ArrayList<>();
124
+        userList.stream().forEach(row -> {
125
+            if(0 < row.getNum()) {
126
+                resultList.add(UserCount.UserCountBuilder.anUserCount()
127
+                        .withUid(row.getSpread_uid())
128
+                        .withDate(localDate)
129
+                        .withNum(row.getNum())
130
+                        .withUser_type(UserTypeEnum.DACANG.ordinal())
131
+                        .withCreate_time(currentTime)
132
+                        .build());
133
+                userRelateMapper.updateByUid(UserTypeEnum.DACANG.ordinal(), row.getSpread_uid());
134
+
135
+                userRelateMapper.selectByUid(row.getSpread_uid()).stream().forEach(innerRow -> {
136
+                    resultList.add(UserCount.UserCountBuilder.anUserCount()
137
+                            .withCreate_time(currentTime)
138
+                            .withNum(row.getNum())
139
+                            .withUser_type(UserTypeEnum.DACANG.ordinal())
140
+                            .withUid(innerRow.getPid())
141
+                            .withDate(localDate)
142
+                            .build());
143
+                });
144
+            }
145
+        });
146
+        if(!resultList.isEmpty()){
147
+            userCountMapper.insertSelectiveForeach(resultList);
148
+        }
149
+    }
150
+
151
+    /**
152
+     * 商户
153
+     * @param localDateTime 日期
154
+     */
155
+    public void resolverMerchant(LocalDate localDate){
156
+        LocalDateTime currentTime = LocalDateTime.now();
157
+        List<UserDto> userList = userMapper.selectMerchant(LocalDateTime.of(localDate, LocalTime.MIN), LocalDateTime.of(localDate, LocalTime.MAX));
158
+        List<UserCount> resultList = new ArrayList<>();
159
+        userList.stream().forEach(row -> {
160
+            if(0 < row.getNum()) {
161
+                resultList.add(UserCount.UserCountBuilder.anUserCount()
162
+                        .withUid(row.getSpread_uid())
163
+                        .withDate(localDate)
164
+                        .withNum(row.getNum())
165
+                        .withUser_type(UserTypeEnum.MERCHANT.ordinal())
166
+                        .withCreate_time(currentTime)
167
+                        .build());
168
+                userRelateMapper.updateByUid(UserTypeEnum.MERCHANT.ordinal(), row.getSpread_uid());
169
+
170
+                userRelateMapper.selectByUid(row.getSpread_uid()).stream().forEach(innerRow -> {
171
+                    resultList.add(UserCount.UserCountBuilder.anUserCount()
172
+                            .withCreate_time(currentTime)
173
+                            .withNum(row.getNum())
174
+                            .withUser_type(UserTypeEnum.MERCHANT.ordinal())
175
+                            .withUid(innerRow.getPid())
176
+                            .withDate(localDate)
177
+                            .build());
178
+                });
179
+            }
180
+        });
181
+        if(!resultList.isEmpty()){
182
+            userCountMapper.insertSelectiveForeach(resultList);
183
+        }
184
+    }
185
+
186
+    /**
187
+     * 渠道商
188
+     * @param localDateTime 日期
189
+     */
190
+    public void resolverChannel(LocalDate localDate){
191
+        LocalDateTime currentTime = LocalDateTime.now();
192
+        List<UserDto> userList = userMapper.selectChannel(LocalDateTime.of(localDate, LocalTime.MIN), LocalDateTime.of(localDate, LocalTime.MAX));
193
+        List<UserCount> resultList = new ArrayList<>();
194
+        userList.stream().forEach(row -> {
195
+            if(0 < row.getNum()) {
196
+                resultList.add(UserCount.UserCountBuilder.anUserCount()
197
+                        .withUid(row.getSpread_uid())
198
+                        .withDate(localDate)
199
+                        .withNum(row.getNum())
200
+                        .withUser_type(UserTypeEnum.CHANNEL.ordinal())
201
+                        .withCreate_time(currentTime)
202
+                        .build());
203
+                userRelateMapper.updateByUid(UserTypeEnum.CHANNEL.ordinal(), row.getSpread_uid());
204
+
205
+                userRelateMapper.selectByUid(row.getSpread_uid()).stream().forEach(innerRow -> {
206
+                    resultList.add(UserCount.UserCountBuilder.anUserCount()
207
+                            .withCreate_time(currentTime)
208
+                            .withNum(row.getNum())
209
+                            .withUser_type(UserTypeEnum.CHANNEL.ordinal())
210
+                            .withUid(innerRow.getPid())
211
+                            .withDate(localDate)
212
+                            .build());
213
+                });
214
+            }
215
+        });
216
+        if(!resultList.isEmpty()){
217
+            userCountMapper.insertSelectiveForeach(resultList);
218
+        }
219
+    }
220
+
221
+    /**
222
+     * 代理商
223
+     * @param localDateTime 日期
224
+     */
225
+    public void resolverAgent(LocalDate localDate){
226
+        LocalDateTime currentTime = LocalDateTime.now();
227
+        List<UserDto> userList = userMapper.selectAgent(LocalDateTime.of(localDate, LocalTime.MIN), LocalDateTime.of(localDate, LocalTime.MAX));
228
+        List<UserCount> resultList = new ArrayList<>();
229
+        userList.stream().forEach(row -> {
230
+            if(0 < row.getNum()) {
231
+                resultList.add(UserCount.UserCountBuilder.anUserCount()
232
+                        .withUid(row.getSpread_uid())
233
+                        .withDate(localDate)
234
+                        .withNum(row.getNum())
235
+                        .withUser_type(UserTypeEnum.AGENT.ordinal())
236
+                        .withCreate_time(currentTime)
237
+                        .build());
238
+                userRelateMapper.updateByUid(UserTypeEnum.AGENT.ordinal(), row.getSpread_uid());
239
+
240
+                userRelateMapper.selectByUid(row.getSpread_uid()).stream().forEach(innerRow -> {
241
+                    resultList.add(UserCount.UserCountBuilder.anUserCount()
242
+                            .withCreate_time(currentTime)
243
+                            .withNum(row.getNum())
244
+                            .withUser_type(UserTypeEnum.AGENT.ordinal())
245
+                            .withUid(innerRow.getPid())
246
+                            .withDate(localDate)
247
+                            .build());
248
+                });
249
+            }
250
+        });
251
+        if(!resultList.isEmpty()){
252
+            userCountMapper.insertSelectiveForeach(resultList);
253
+        }
254
+    }
255
+
256
+    private List<Integer> listOfChildren(UserDto userDto, List<UserDto> list){
257
+        if(userDto == null || CollectionUtils.isEmpty(list)){
258
+            return List.of();
259
+        }
260
+
261
+        List<Integer> resultList = new ArrayList<>();
262
+        for(UserDto row : list){
263
+            if(userDto.getUid() == row.getUid()){
264
+                continue;
265
+            }
266
+            if(row.getSpread_uid() == userDto.getUid()){
267
+                if(row.getUid() == userDto.getSpread_uid()){
268
+                    logger.error("循环嵌套 row.getSpread_uid() = {}, userDto.getUid() = {}", row.getSpread_uid(), userDto.getSpread_uid());
269
+                    throw new TDBAException("循环嵌套");
270
+                }
271
+                resultList.addAll(listOfChildren(row, list));
272
+            }
273
+        }
274
+        return resultList;
275
+    }
276
+
277
+
278
+    private Integer countOfChildren(UserDto userDto, List<UserDto> list){
279
+
280
+        if(userDto == null || CollectionUtils.isEmpty(list)){
281
+            return 0;
282
+        }
283
+
284
+        Integer result = 0;
285
+        for(UserDto row : list){
286
+            if(userDto.getUid() == row.getUid()){
287
+                continue;
288
+            }
289
+            if(row.getSpread_uid() == userDto.getUid()){
290
+                if(row.getUid() == userDto.getSpread_uid()){
291
+                    logger.error("循环嵌套 row.getSpread_uid() = {}, userDto.getUid() = {}", row.getSpread_uid(), userDto.getSpread_uid());
292
+                    throw new TDBAException("循环嵌套");
293
+                }
294
+                result = 1 + countOfChildren(row, list);
295
+            }
296
+        }
297
+        return result;
298
+    }
299
+}

+ 82 - 0
src/main/resources/mapper/UserCountMapper.xml

@@ -0,0 +1,82 @@
1
+<?xml version="1.0" encoding="UTF-8" ?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
3
+<mapper namespace="com.tdba.cxb.ares.api.repository.UserCountMapper">
4
+
5
+    <insert id="insertSelective">
6
+        insert into user_count
7
+        <trim prefix="(" suffix=")" suffixOverrides=",">
8
+            <if test="null != uid">
9
+                uid,
10
+            </if>
11
+            <if test="null != num">
12
+                num,
13
+            </if>
14
+            <if test="null != date">
15
+                date,
16
+            </if>
17
+            <if test="null != create_time">
18
+                create_time,
19
+            </if>
20
+            <if test="null != del_flag">
21
+                del_flag,
22
+            </if>
23
+        </trim>
24
+
25
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
26
+            <if test="null != uid">
27
+                #{ uid },
28
+            </if>
29
+            <if test="null != num">
30
+                #{ num },
31
+            </if>
32
+            <if test="null != date">
33
+                #{ date },
34
+            </if>
35
+            <if test="null != create_time">
36
+                #{create_time},
37
+            </if>
38
+            <if test="null != del_flag">
39
+                #{del_flag},
40
+            </if>
41
+        </trim>
42
+    </insert>
43
+
44
+    <update id="updateByPrimaryKeySelective">
45
+        update user_count
46
+        <set>
47
+            <if test="null != uid">
48
+                uid = #{ uid },
49
+            </if>
50
+            <if test="null != num">
51
+                num = #{ num },
52
+            </if>
53
+            <if test="null != date">
54
+                date = #{ date },
55
+            </if>
56
+            <if test="null != create_time">
57
+                create_time = #{create_time},
58
+            </if>
59
+            <if test="null != del_flag">
60
+                del_flag = #{del_flag},
61
+            </if>
62
+        </set>
63
+        where id = #{id}
64
+    </update>
65
+
66
+    <insert id="insertSelectiveForeach">
67
+        insert into user_count
68
+        (
69
+        uid,
70
+        num,
71
+        date,
72
+        create_time       )
73
+        values
74
+        <foreach collection="list" separator="," item="row">
75
+            (
76
+            #{row.uid },
77
+            #{row.num },
78
+            #{row.date },
79
+            #{row.create_time }     )
80
+        </foreach>
81
+    </insert>
82
+</mapper>

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

@@ -0,0 +1,85 @@
1
+<?xml version="1.0" encoding="UTF-8" ?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
3
+<mapper namespace="com.tdba.cxb.ares.api.repository.UserMapper">
4
+
5
+    <select id="selectByTimeRegion" resultType="com.tdba.cxb.ares.api.model.UserDto">
6
+        select
7
+            uid,
8
+            spread_uid
9
+        from
10
+            rrx_user
11
+        where
12
+            test_user = 0
13
+            <![CDATA[ and spread_uid > 0 ]]>
14
+            <![CDATA[ and create_time >= #{beginTime} ]]>
15
+            <![CDATA[ and create_time <= #{endTime} ]]>
16
+    </select>
17
+
18
+    <select id="selectDacang" resultType="com.tdba.cxb.ares.api.model.UserDto">
19
+        select
20
+            count(1) 'num',
21
+            u.spread_uid
22
+        from
23
+            rrx_da_cang_user da
24
+        left join
25
+            rrx_user u
26
+            on da.uid = u.uid
27
+        where
28
+            da.status = 1
29
+             <![CDATA[ and da.ctime >= #{beginTime} ]]>
30
+             <![CDATA[ and da.ctime <= #{endTime} ]]>
31
+            and u.test_user = 0
32
+            and u.spread_uid > 0
33
+    </select>
34
+
35
+    <select id="selectMerchant" resultType="com.tdba.cxb.ares.api.model.UserDto">
36
+        select
37
+            count(1) 'num',
38
+            u.spread_uid
39
+        from
40
+            rrx_merchant_admin da
41
+            left join
42
+            rrx_user u
43
+            on da.uid = u.uid
44
+        where
45
+            da.status = 1
46
+            <![CDATA[ and da.create_time >= #{beginTime} ]]>
47
+            <![CDATA[ and da.create_time <=#{endTime} ]]>
48
+            and u.test_user = 0
49
+            and u.spread_uid > 0
50
+    </select>
51
+
52
+    <select id="selectChannel" resultType="com.tdba.cxb.ares.api.model.UserDto">
53
+        select
54
+            count(1) 'num',
55
+            u.spread_uid
56
+        from
57
+            rrx_channel_user da
58
+        left join
59
+            rrx_user u
60
+            on da.uid = u.uid
61
+        where
62
+            da.status = 1
63
+            <![CDATA[ and da.ctime >= #{beginTime} ]]>
64
+            <![CDATA[ and da.ctime <= #{endTime} ]]>
65
+            and u.test_user = 0
66
+            and u.spread_uid > 0
67
+    </select>
68
+
69
+    <select id="selectAgent" resultType="com.tdba.cxb.ares.api.model.UserDto">
70
+        select
71
+            count(1) 'num',
72
+            u.spread_uid
73
+        from
74
+            rrx_user_agent da
75
+            left join
76
+            rrx_user u
77
+            on da.user_id = u.uid
78
+        where
79
+            da.status = 1
80
+            <![CDATA[ and da.add_time >= #{beginTime} ]]>
81
+            <![CDATA[ and da.add_time <= #{endTime} ]]>
82
+            and u.test_user = 0
83
+            and u.spread_uid > 0
84
+    </select>
85
+</mapper>

+ 82 - 0
src/main/resources/mapper/UserRelateMapper.xml

@@ -0,0 +1,82 @@
1
+<?xml version="1.0" encoding="UTF-8" ?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
3
+<mapper namespace="com.tdba.cxb.ares.api.repository.UserRelateMapper">
4
+
5
+    <insert id="insertSelective">
6
+        insert into user_relate
7
+        <trim prefix="(" suffix=")" suffixOverrides=",">
8
+            <if test="null != uid">
9
+                uid,
10
+            </if>
11
+            <if test="null != pid">
12
+                pid,
13
+            </if>
14
+            <if test="null != del_flag">
15
+                del_flag,
16
+            </if>
17
+        </trim>
18
+
19
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
20
+            <if test="null != uid">
21
+                #{ uid },
22
+            </if>
23
+            <if test="null != pid">
24
+                #{ pid },
25
+            </if>
26
+            <if test="null != del_flag">
27
+                #{del_flag},
28
+            </if>
29
+        </trim>
30
+    </insert>
31
+
32
+    <update id="updateByPrimaryKeySelective">
33
+        update user_relate
34
+        <set>
35
+            <if test="null != uid">
36
+                uid = #{ uid },
37
+            </if>
38
+            <if test="null != pid">
39
+                pid = #{ pid },
40
+            </if>
41
+            <if test="null != del_flag">
42
+                del_flag = #{del_flag},
43
+            </if>
44
+        </set>
45
+        where id = #{id}
46
+    </update>
47
+
48
+    <insert id="insertSelectiveForeach">
49
+        insert into user_relate
50
+        (
51
+        uid,
52
+        pid      )
53
+        values
54
+        <foreach collection="list" separator="," item="row">
55
+            (
56
+            #{row.uid },
57
+            #{row.pid }       )
58
+        </foreach>
59
+    </insert>
60
+
61
+    <select id="selectByUid" resultType="com.tdba.cxb.ares.api.model.UserRelate">
62
+        select * from user_relate where del_flag = 0 and uid = #{uid}
63
+    </select>
64
+
65
+    <select id="updateByUid">
66
+        update user_relate set
67
+            <if test="userType == 1">
68
+                is_dacang = 1
69
+            </if>
70
+            <if test="userType == 2">
71
+                is_merchant = 1
72
+            </if>
73
+            <if test="userType == 3">
74
+                is_channel = 1
75
+            </if>
76
+            <if test="userType == 4">
77
+                is_agent = 1
78
+            </if>
79
+
80
+        where uid = #{uid}
81
+    </select>
82
+</mapper>

+ 33 - 0
src/test/java/com/tdba/cxb/ares/api/user/UserDto.java

@@ -0,0 +1,33 @@
1
+package com.tdba.cxb.ares.api.user;
2
+
3
+/**
4
+ * @program: admin-web
5
+ * @description:
6
+ * @author: libo
7
+ * @create: 2022-06-06 15:26:14
8
+ */
9
+public class UserDto {
10
+
11
+    /** 用户ID*/
12
+    private Integer uid;
13
+
14
+    /** 推荐人用户ID*/
15
+    private Integer spread_uid;
16
+
17
+    public Integer getUid() {
18
+        return uid;
19
+    }
20
+
21
+    public void setUid(Integer uid) {
22
+        this.uid = uid;
23
+    }
24
+
25
+    public Integer getSpread_uid() {
26
+        return spread_uid;
27
+    }
28
+
29
+    public void setSpread_uid(Integer spread_uid) {
30
+        this.spread_uid = spread_uid;
31
+    }
32
+
33
+}

+ 27 - 0
src/test/java/com/tdba/cxb/ares/api/user/UserRelateTest.java

@@ -0,0 +1,27 @@
1
+package com.tdba.cxb.ares.api.user;
2
+
3
+import com.tdba.cxb.ares.api.ApplicationStartup;
4
+import com.tdba.cxb.ares.api.service.UserService;
5
+import org.junit.jupiter.api.Test;
6
+import org.springframework.boot.test.context.SpringBootTest;
7
+
8
+import javax.annotation.Resource;
9
+import java.time.LocalDate;
10
+
11
+/**
12
+ * @program: order-web
13
+ * @description:
14
+ * @author: libo
15
+ * @create: 2022-06-06 17:40:27
16
+ */
17
+@SpringBootTest(classes = ApplicationStartup.class)
18
+public class UserRelateTest {
19
+
20
+    @Resource
21
+    private UserService userService;
22
+
23
+    @Test
24
+    public void test(){
25
+        userService.createSpreadInfo(LocalDate.of(2021, 4, 9));
26
+    }
27
+}

+ 68 - 0
src/test/java/com/tdba/cxb/ares/api/user/UserTest.java

@@ -0,0 +1,68 @@
1
+package com.tdba.cxb.ares.api.user;
2
+
3
+import com.tdba.cxb.ares.api.util.TDBAException;
4
+import org.junit.jupiter.api.Test;
5
+import org.slf4j.Logger;
6
+import org.slf4j.LoggerFactory;
7
+import org.springframework.util.CollectionUtils;
8
+
9
+import java.util.List;
10
+
11
+/**
12
+ * @program: admin-web
13
+ * @description:
14
+ * @author: libo
15
+ * @create: 2022-06-06 15:17:42
16
+ */
17
+public class UserTest {
18
+
19
+    private static Logger logger = LoggerFactory.getLogger(UserTest.class);
20
+
21
+    @Test
22
+    public void test(){
23
+
24
+        List<UserDto> list = List.of(UserDto.UserDtoBuilder.anUserDto()
25
+                .withUid(2)
26
+                .withSpread_uid(1)
27
+                .build(),
28
+                UserDto.UserDtoBuilder.anUserDto()
29
+                        .withUid(3)
30
+                        .withSpread_uid(2)
31
+                        .build(),
32
+                UserDto.UserDtoBuilder.anUserDto()
33
+                        .withUid(1)
34
+                        .withSpread_uid(0)
35
+                        .build(),
36
+                UserDto.UserDtoBuilder.anUserDto()
37
+                        .withUid(4)
38
+                        .withSpread_uid(0)
39
+                        .build());
40
+
41
+        list.stream().forEach(row -> {
42
+            logger.info("uid = {}, count = {}", row.getUid(), countOfChildren(row, list));
43
+        });
44
+
45
+    }
46
+
47
+    public static Integer countOfChildren(UserDto userDto, List<UserDto> list){
48
+
49
+        if(userDto == null || CollectionUtils.isEmpty(list)){
50
+            return 0;
51
+        }
52
+
53
+        Integer result = 0;
54
+        for(UserDto row : list){
55
+            if(userDto.getUid() == row.getUid()){
56
+                continue;
57
+            }
58
+           if(row.getSpread_uid() == userDto.getUid()){
59
+               if(row.getUid() == userDto.getSpread_uid()){
60
+                   logger.error("循环嵌套 row.getSpread_uid() = {}, userDto.getUid() = {}", row.getSpread_uid(), userDto.getSpread_uid());
61
+                   throw new TDBAException("循环嵌套");
62
+               }
63
+                result = 1 + countOfChildren(row, list);
64
+           }
65
+        }
66
+        return result;
67
+    }
68
+}