xudm 2 месяцев назад
Родитель
Сommit
21ada0e9e8

+ 2 - 3
continew-module-system/src/main/java/top/continew/admin/business/mapper/TgUserMapper.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.apache.ibatis.annotations.Param;
 import top.continew.admin.business.model.entity.TgUser;
 import top.continew.admin.business.model.query.TgUserQuery;
+import top.continew.admin.business.model.query.TgUserTeamQuery;
 import top.continew.admin.business.model.req.TgUserReq;
 
 import java.util.List;
@@ -24,10 +25,8 @@ public interface TgUserMapper extends BaseMapper<TgUser> {
     /**
      * 查询团队用户
      *
-     * @param id       用户id
-     * @param teamType 团队类型
      * @return
      */
-    List<TgUser> getMyTeamUserListByType(@Param("userId") Long id, @Param("teamType") String teamType);
+    List<TgUser> getMyTeamUserListByType(@Param("query") TgUserTeamQuery query, Page<TgUser> page);
 
 }

+ 5 - 8
continew-module-system/src/main/java/top/continew/admin/business/model/entity/TgUser.java

@@ -5,26 +5,25 @@ import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.extension.activerecord.Model;
-import lombok.Builder;
-import lombok.Getter;
-import lombok.Setter;
 
 import java.io.Serializable;
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
 
+import lombok.Getter;
+import lombok.Setter;
+
 /**
  * <p>
  * tg用户
  * </p>
  *
  * @author xudm
- * @since 2024-12-14
+ * @since 2024-12-17
  */
 @Getter
 @Setter
 @TableName("b_tg_user")
-@Builder
 public class TgUser extends Model<TgUser> {
 
     /**
@@ -94,7 +93,7 @@ public class TgUser extends Model<TgUser> {
     private Integer ageLimit;
 
     /**
-     * 是否老用户
+     * 是否老用户[0=新用户, 1=老用户]
      */
     @TableField("old_user")
     private Integer oldUser;
@@ -135,7 +134,6 @@ public class TgUser extends Model<TgUser> {
     @TableField("channel")
     private Integer channel;
 
-
     /**
      * 客流途径 1 新增 2 邀请
      */
@@ -202,7 +200,6 @@ public class TgUser extends Model<TgUser> {
     @TableField("gold_coin_total_his")
     private BigDecimal goldCoinTotalHis;
 
-
     /**
      * 在线时间 单位秒
      */

+ 36 - 0
continew-module-system/src/main/java/top/continew/admin/business/model/query/TgUserTeamQuery.java

@@ -0,0 +1,36 @@
+package top.continew.admin.business.model.query;
+
+import cn.hutool.core.date.DatePattern;
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.NotNull;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
+@Data
+public class TgUserTeamQuery implements Serializable {
+
+    @Schema(description = "用户id")
+    @NotNull(message = "用户id不能为空")
+    private Long id;
+
+    @Schema(description = "团队类型")
+    @NotNull(message = "团队类型不能为空")
+    private String teamType;
+
+    @Schema(description = "用户昵称")
+    private String userName;
+
+    @Schema(description = "注册时间", example = "2023-08-08 00:00:00,2023-08-08 23:59:59")
+    @DateTimeFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
+    private List<Date> time;
+
+    @Schema(description = "当前页码")
+    private int page;
+
+    @Schema(description = "页大小")
+    private int size;
+}

+ 3 - 3
continew-module-system/src/main/java/top/continew/admin/business/service/ITgUserService.java

@@ -3,7 +3,9 @@ package top.continew.admin.business.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import top.continew.admin.business.model.entity.TgUser;
 import top.continew.admin.business.model.query.TgUserQuery;
+import top.continew.admin.business.model.query.TgUserTeamQuery;
 import top.continew.admin.business.model.req.TgUserReq;
+import top.continew.starter.extension.crud.model.resp.BasePageResp;
 import top.continew.starter.extension.crud.model.resp.PageResp;
 
 import java.util.List;
@@ -32,11 +34,9 @@ public interface ITgUserService extends IService<TgUser> {
     /**
      * 查询团队成员列表
      *
-     * @param id       tg用户id
-     * @param teamType 团队类型 A B
      * @return
      */
-    List<TgUser> getMyTeamUserListByType(Long id, String teamType);
+    BasePageResp<TgUser> getMyTeamUserListByType(TgUserTeamQuery queryVo);
 
     /**
      * 更新tg用户的信息

+ 9 - 2
continew-module-system/src/main/java/top/continew/admin/business/service/Impl/TgUserServiceImpl.java

@@ -7,8 +7,10 @@ import org.springframework.stereotype.Service;
 import top.continew.admin.business.mapper.TgUserMapper;
 import top.continew.admin.business.model.entity.TgUser;
 import top.continew.admin.business.model.query.TgUserQuery;
+import top.continew.admin.business.model.query.TgUserTeamQuery;
 import top.continew.admin.business.model.req.TgUserReq;
 import top.continew.admin.business.service.ITgUserService;
+import top.continew.starter.extension.crud.model.resp.BasePageResp;
 import top.continew.starter.extension.crud.model.resp.PageResp;
 
 import java.time.LocalDateTime;
@@ -46,8 +48,13 @@ public class TgUserServiceImpl extends ServiceImpl<TgUserMapper, TgUser> impleme
     }
 
     @Override
-    public List<TgUser> getMyTeamUserListByType(Long id, String teamType) {
-        return getBaseMapper().getMyTeamUserListByType(id, teamType);
+    public BasePageResp<TgUser> getMyTeamUserListByType(TgUserTeamQuery queryVo) {
+        Page<TgUser> page = new Page<>();
+        page.setCurrent(queryVo.getPage() != 0 ? queryVo.getPage() : 1);
+        page.setSize(queryVo.getSize() != 0 ? queryVo.getSize() : 10);
+        List<TgUser> listByType = getBaseMapper().getMyTeamUserListByType(queryVo, page);
+        page.setRecords(listByType);
+        return PageResp.build(page, TgUser.class);
     }
 
     @Override

+ 96 - 53
continew-module-system/src/main/resources/mapper/TgUserMapper.xml

@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="top.continew.admin.business.mapper.TgUserMapper">
+    <!-- 通用查询映射结果 -->
     <!-- 通用查询映射结果 -->
     <resultMap id="BaseResultMap" type="top.continew.admin.business.model.entity.TgUser">
         <id column="id" property="id"/>
@@ -21,7 +22,7 @@
         <result column="ip_address_convert" property="ipAddressConvert"/>
         <result column="disable_flag" property="disableFlag"/>
         <result column="channel" property="channel"/>
-        <result column="ppassenger_flow_way" property="passengerFlowWay"/>
+        <result column="passenger_flow_way" property="passengerFlowWay"/>
         <result column="login_telegram" property="loginTelegram"/>
         <result column="coin_address" property="coinAddress"/>
         <result column="password" property="password"/>
@@ -36,15 +37,46 @@
         <result column="user_amount" property="userAmount"/>
         <result column="created_time" property="createdTime"/>
         <result column="updated_time" property="updatedTime"/>
-        <result column="referrerName" property="referrerName"/>
     </resultMap>
 
-    <!-- 通用查询结果列 -->
-    <sql id="Base_Column_List">
-        id, tg_id, tg_account, first_name, last_name, nickname, real_name, avatar, language_code, wallet_address, age_limit, old_user, check_language, login_ip, login_time, ip_address_convert, disable_flag, channel,passenger_flow_way, login_telegram, coin_address, password, mobile, sex, invite_code, referrer_id, invite_reward, new_user_flag, history_key, key_num, airdrop_coin, gold_coin_amount, gold_coin_total_his, development_gold_coin, online_time, user_amount, created_time, updated_time
-    </sql>
+    <resultMap id="TgUserResultMap" type="top.continew.admin.business.model.entity.TgUser">
+        <id column="id" property="id"/>
+        <result column="tg_id" property="tgId"/>
+        <result column="tg_account" property="tgAccount"/>
+        <result column="first_name" property="firstName"/>
+        <result column="last_name" property="lastName"/>
+        <result column="nickname" property="nickname"/>
+        <result column="real_name" property="realName"/>
+        <result column="avatar" property="avatar"/>
+        <result column="language_code" property="languageCode"/>
+        <result column="wallet_address" property="walletAddress"/>
+        <result column="age_limit" property="ageLimit"/>
+        <result column="old_user" property="oldUser"/>
+        <result column="check_language" property="checkLanguage"/>
+        <result column="login_ip" property="loginIp"/>
+        <result column="login_time" property="loginTime"/>
+        <result column="ip_address_convert" property="ipAddressConvert"/>
+        <result column="disable_flag" property="disableFlag"/>
+        <result column="channel" property="channel"/>
+        <result column="passenger_flow_way" property="passengerFlowWay"/>
+        <result column="login_telegram" property="loginTelegram"/>
+        <result column="coin_address" property="coinAddress"/>
+        <result column="password" property="password"/>
+        <result column="mobile" property="mobile"/>
+        <result column="sex" property="sex"/>
+        <result column="invite_code" property="inviteCode"/>
+        <result column="referrer_id" property="referrerId"/>
+        <result column="airdrop_coin" property="airdropCoin"/>
+        <result column="gold_coin_amount" property="goldCoinAmount"/>
+        <result column="gold_coin_total_his" property="goldCoinTotalHis"/>
+        <result column="online_time" property="onlineTime"/>
+        <result column="user_amount" property="userAmount"/>
+        <result column="created_time" property="createdTime"/>
+        <result column="updated_time" property="updatedTime"/>
+        <result column="referrerName" property="referrerName"/>
+    </resultMap>
 
-    <select id="getTgUserOfPage" resultMap="BaseResultMap">
+    <select id="getTgUserOfPage" resultMap="TgUserResultMap">
         select tu.*,
         case
         when ru.first_name IS NOT NULL or ru.last_name IS NOT NULL
@@ -68,59 +100,70 @@
         order by tu.created_time desc
     </select>
 
-    <select id="getMyTeamUserListByType" resultMap="BaseResultMap">
+    <select id="getMyTeamUserListByType" resultMap="TgUserResultMap">
         WITH RECURSIVE team_hierarchy AS (
-            -- A队:直接被你邀请的用户
-            SELECT id,
-                   tg_id,
-                   tg_account,
-                   first_name,
-                   last_name,
-                   nickname,
-                   real_name,
-                   avatar,
-                   passenger_flow_way,
-                   referrer_id,
-                   created_time,
-                   'A' as team_type,
-                   1   as level
-            FROM b_tg_user
-            WHERE referrer_id = '{#userId}'
+        -- A队:直接被你邀请的用户
+        SELECT id,
+        tg_id,
+        tg_account,
+        first_name,
+        last_name,
+        nickname,
+        real_name,
+        avatar,
+        passenger_flow_way,
+        referrer_id,
+        created_time,
+        'A' as team_type,
+        1 as level
+        FROM b_tg_user
+        WHERE referrer_id = #{query.id}
 
-            UNION ALL
+        UNION ALL
 
-            -- B队:被A队邀请的用户
-            SELECT u.id,
-                   u.tg_id,
-                   u.tg_account,
-                   u.first_name,
-                   u.last_name,
-                   u.nickname,
-                   u.real_name,
-                   u.avatar,
-                   u.passenger_flow_way,
-                   u.referrer_id,
-                   u.created_time,
-                   'B' as team_type,
-                   h.level + 1
-            FROM b_tg_user u
-                     JOIN team_hierarchy h ON u.referrer_id = h.id
-            WHERE h.level = 1 -- 只获取A队成员邀请的用户
+        -- B队:被A队邀请的用户
+        SELECT u.id,
+        u.tg_id,
+        u.tg_account,
+        u.first_name,
+        u.last_name,
+        u.nickname,
+        u.real_name,
+        u.avatar,
+        u.passenger_flow_way,
+        u.referrer_id,
+        u.created_time,
+        'B' as team_type,
+        h.level + 1
+        FROM b_tg_user u
+        JOIN team_hierarchy h ON u.referrer_id = h.id
+        WHERE h.level = 1 -- 只获取A队成员邀请的用户
         )
 
         SELECT id,
-               tg_id,
-               tg_account,
-               first_name,
-               last_name,
-               nickname,
-               real_name,
-               avatar,
-               passenger_flow_way,
-               referrer_id,
-               team_type
+        tg_id,
+        tg_account,
+        first_name,
+        last_name,
+        nickname,
+        real_name,
+        avatar,
+        passenger_flow_way,
+        referrer_id,
+        created_time,
+        team_type
         FROM team_hierarchy
-        where team_type = '#{teamType}'
+        where team_type = #{query.teamType}
+        <if test="query.userName != null and query.userName != ''">
+            AND (
+            tg_account LIKE CONCAT('%', #{query.userName}, '%')
+            OR first_name LIKE CONCAT('%', #{query.userName}, '%')
+            OR last_name LIKE CONCAT('%', #{query.userName}, '%')
+            )
+        </if>
+        <if test="query.time != null and query.time.size() == 2">
+            AND created_time BETWEEN #{query.time[0]} AND #{query.time[1]}
+        </if>
         ORDER BY created_time desc
     </select>
 </mapper>

+ 5 - 7
continew-webapi/src/main/java/top/continew/admin/controller/business/TgUserController.java

@@ -6,9 +6,11 @@ import io.swagger.v3.oas.annotations.Parameters;
 import io.swagger.v3.oas.annotations.enums.ParameterIn;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.AllArgsConstructor;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 import top.continew.admin.business.model.entity.TgUser;
 import top.continew.admin.business.model.query.TgUserQuery;
+import top.continew.admin.business.model.query.TgUserTeamQuery;
 import top.continew.admin.business.model.req.TgUserReq;
 import top.continew.admin.business.service.ITgUserService;
 import top.continew.starter.extension.crud.model.resp.BasePageResp;
@@ -44,12 +46,8 @@ public class TgUserController {
     }
 
     @Operation(summary = "获取团队成员列表", description = "获取团队成员列表")
-    @GetMapping("/getMyTeamUserList/{id}")
-    @Parameters({
-            @Parameter(name = "id", description = "用户id", example = "10004", in = ParameterIn.PATH),
-            @Parameter(name = "teamType", description = "团队类型", example = "A", in = ParameterIn.QUERY)
-    })
-    public List<TgUser> getMyTeamUserList(@PathVariable("id") Long id, @RequestParam("teamType") String teamType) {
-        return userService.getMyTeamUserListByType(id, teamType);
+    @GetMapping("/getMyTeamUserList")
+    public BasePageResp<TgUser> getMyTeamUserList(@Validated TgUserTeamQuery query) {
+        return userService.getMyTeamUserListByType(query);
     }
 }