主播数据查询接口实现

This commit is contained in:
2025-06-12 19:43:16 +08:00
parent 97e1427303
commit c6382e3283
10 changed files with 235 additions and 35 deletions

View File

@@ -1,6 +1,8 @@
package com.yupi.springbootinit.common;
import com.yupi.springbootinit.constant.CommonConstant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
@@ -10,25 +12,20 @@ import lombok.Data;
* @from <a href="https://yupi.icu">编程导航知识星球</a>
*/
@Data
@ApiModel("分页信息基础类")
public class PageRequest {
/**
* 当前页号
*/
@ApiModelProperty(value = "当前页数", example = " 1")
private int current = 1;
/**
* 页面大小
*/
private int pageSize = 10;
@ApiModelProperty(value = "当前页面大小", example = " 20")
private int pageSize = 20;
/**
* 排序字段
*/
private String sortField;
/**
* 排序顺序(默认升序)
*/
private String sortOrder = CommonConstant.SORT_ORDER_ASC;
}

View File

@@ -1,6 +1,7 @@
package com.yupi.springbootinit.controller;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yupi.springbootinit.common.BaseResponse;
import com.yupi.springbootinit.common.ResultUtils;
import com.yupi.springbootinit.model.dto.host.HostInfoDTO;
@@ -26,10 +27,9 @@ public class HostInfoController {
@Resource
private HostInfoService hostInfoService;
@PostMapping("hosts_info")
public BaseResponse<List<NewHostsVO>> hostsInfo(@RequestBody HostInfoDTO hostInfoDTO){
List<NewHostsVO> hostsVOList=hostInfoService.getConditionHosts(hostInfoDTO);
return ResultUtils.success(hostsVOList);
public BaseResponse<Page<NewHostsVO>> hostsInfo(@RequestBody HostInfoDTO hostInfoDTO){
Page<NewHostsVO> conditionHosts = hostInfoService.getConditionHosts(hostInfoDTO);
return ResultUtils.success(conditionHosts);
}
}

View File

@@ -1,8 +1,13 @@
package com.yupi.springbootinit.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yupi.springbootinit.model.dto.host.HostInfoDTO;
import com.yupi.springbootinit.model.entity.NewHosts;
import java.util.List;
import com.yupi.springbootinit.model.vo.hosts.NewHostsVO;
import org.apache.ibatis.annotations.Param;
/*
@@ -23,4 +28,6 @@ public interface NewHostsMapper extends BaseMapper<NewHosts> {
int updateByPrimaryKey(NewHosts record);
int batchInsert(@Param("list") List<NewHosts> list);
Page<NewHostsVO> selectPageByCondition(@Param("page") Page<NewHostsVO> page, @Param("hostInfoDTO") HostInfoDTO hostInfoDTO);
}

View File

@@ -1,7 +1,12 @@
package com.yupi.springbootinit.model.dto.host;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yupi.springbootinit.common.PageRequest;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/*
@@ -9,80 +14,157 @@ import java.util.Date;
* @date: 2025/6/10 18:58
*/
@Data
public class HostInfoDTO {
@ApiModel("主播信息DTO类")
public class HostInfoDTO extends PageRequest implements Serializable {
/**
* 主键
*/
@ApiModelProperty(value = "主键ID", example = "1")
private Long id;
/**
* 主播id
*/
@ApiModelProperty(value = "主播ID", example = "host123")
private String hostsId;
/**
* 主播等级
*/
@ApiModelProperty(value = "主播等级", example = "A")
private String hostsLevel;
/**
* 主播金币
*/
@ApiModelProperty(value = "主播当前金币数", example = "5000")
private Integer hostsCoins;
/**
* 主播金币最大值
*/
@ApiModelProperty(value = "主播金币查询最大值", example = "10000")
private Integer hostsCoinsMax;
/**
* 主播金币最小值
*/
@ApiModelProperty(value = "主播金币查询最小值", example = "1000")
private Integer hostsCoinsMin;
/**
* 邀请类型
*/
@ApiModelProperty(value = "邀请类型(1:普票 2:金票)", example = "1")
private Integer invitationType;
/**
* 粉丝数量
*/
@ApiModelProperty(value = "粉丝数量", example = "10000")
private Integer fans;
/**
* 粉丝数量最大值
*/
@ApiModelProperty(value = "粉丝数量查询最大值", example = "50000")
private Integer fansMax;
/**
* 粉丝数量最小值
*/
@ApiModelProperty(value = "粉丝数量查询最小值", example = "1000")
private Integer fansMin;
/**
* 关注数量
*/
@ApiModelProperty(value = "关注数量", example = "500")
private Integer fllowernum;
/**
* 关注数量最大值
*/
@ApiModelProperty(value = "关注数量查询最大值", example = "1000")
private Integer fllowernumMax;
/**
* 关注数量最小值
*/
@ApiModelProperty(value = "关注数量查询最小值", example = "100")
private Integer fllowernumMin;
/**
* 昨日金币
*/
@ApiModelProperty(value = "主播昨日金币数", example = "2000")
private Integer yesterdayCoins;
/**
* 昨日金币最大值
*/
@ApiModelProperty(value = "昨日金币查询最大值", example = "5000")
private Integer yesterdayCoinsMax;
/**
* 昨日金币最小值
*/
@ApiModelProperty(value = "昨日金币查询最小值", example = "500")
private Integer yesterdayCoinsMin;
/**
* 主播国家
*/
@ApiModelProperty(value = "主播所在国家", example = "美国")
private String country;
/**
* 直播类型 娱乐,游戏
*/
@ApiModelProperty(value = "直播类型(娱乐/游戏)", example = "娱乐")
private String hostsKind;
/**
* 租户 Id
*/
@ApiModelProperty(value = "租户ID", example = "1001")
private Long tenantId;
/**
* 入库人
*/
@ApiModelProperty(value = "数据创建人ID", example = "101")
private Integer creator;
/**
* 数据插入时间
*/
@ApiModelProperty(value = "创建时间(yyyy-MM-dd)", example = "2023-01-01")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date createTime;
/**
* 更新人
* 数据插入最大
*/
private String updater;
@ApiModelProperty(value = "创建时间查询上限(yyyy-MM-dd)", example = "2023-12-31")
private Date createTimeMax;
/**
* 更新时间
* 数据插入最小
*/
private Date updateTime;
@ApiModelProperty(value = "创建时间查询下限(yyyy-MM-dd)", example = "2023-01-01")
private Date createTimeMin;
/**
* 排序规则
*/
@ApiModelProperty(value = "排序方式(asc/desc)", example = "desc")
private String sort;
/**
* 按照何种业务排序
*/
@ApiModelProperty(value = "排序字段(createTime/hostsCoins/fans等)", example = "hostsCoins")
private String sortName;
}

View File

@@ -2,6 +2,7 @@ package com.yupi.springbootinit.model.vo.hosts;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Date;
@@ -15,42 +16,49 @@ public class NewHostsVO {
/**
* 主键
*/
@TableId(value = "id", type = IdType.AUTO)
@TableId(value = "id")
private Long id;
/**
* 主播id
*/
@TableId(value = "hosts_id")
private String hostsId;
/**
* 主播等级
*/
@TableId(value = "hosts_level")
private String hostsLevel;
/**
* 主播金币
*/
@TableId(value = "hosts_coins")
private Integer hostsCoins;
/**
* 邀请类型
*/
@TableId(value = "invitation_type")
private Integer invitationType;
/**
* 粉丝数量
*/
@TableId(value = "fans")
private Integer fans;
/**
* 关注数量
*/
@TableId(value = "fllowernum")
private Integer fllowernum;
/**
* 昨日金币
*/
@TableId(value = "yesterday_coins")
private Integer yesterdayCoins;
/**
@@ -61,21 +69,14 @@ public class NewHostsVO {
/**
* 直播类型 娱乐,游戏
*/
@TableId(value = "hosts_kind")
private String hostsKind;
/**
* 租户 Id
*/
private Long tenantId;
/**
* 入库人
*/
private Long creator;
/**
* 数据插入时间
*/
@TableId(value = "create_time")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
}

View File

@@ -1,6 +1,7 @@
package com.yupi.springbootinit.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yupi.springbootinit.model.dto.host.HostInfoDTO;
import com.yupi.springbootinit.model.entity.NewHosts;
@@ -16,5 +17,5 @@ import java.util.concurrent.CompletableFuture;
public interface HostInfoService extends IService<NewHosts> {
List<NewHostsVO> getConditionHosts(HostInfoDTO hostInfoDTO);
Page<NewHostsVO> getConditionHosts(HostInfoDTO hostInfoDTO);
}

View File

@@ -1,7 +1,11 @@
package com.yupi.springbootinit.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.yupi.springbootinit.common.BaseResponse;
import com.yupi.springbootinit.common.ResultUtils;
import com.yupi.springbootinit.mapper.NewHostsMapper;
import com.yupi.springbootinit.model.dto.host.HostInfoDTO;
import com.yupi.springbootinit.model.entity.NewHosts;
@@ -12,7 +16,9 @@ import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StopWatch;
import org.springframework.web.bind.annotation.RequestBody;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@@ -27,10 +33,12 @@ import java.util.concurrent.CompletableFuture;
@Transactional(rollbackFor = Exception.class)
public class HostInfoServiceImpl extends ServiceImpl<NewHostsMapper, NewHosts> implements HostInfoService {
@Resource
private NewHostsMapper newHostsMapper;
@Override
public List<NewHostsVO> getConditionHosts(HostInfoDTO hostInfoDTO) {
return List.of();
public Page<NewHostsVO> getConditionHosts(@RequestBody HostInfoDTO hostInfoDTO) {
Page<NewHostsVO> page = new Page<>(hostInfoDTO.getCurrent(),hostInfoDTO.getPageSize());
return newHostsMapper.selectPageByCondition(page, hostInfoDTO);
}
}

View File

@@ -8,7 +8,7 @@ spring:
# todo 需替换配置
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/ruoyi-vue-pro?rewriteBatchedStatements=true
url: jdbc:mysql://localhost:3306/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true
username: root
password: 123asd
# Redis 配置

View File

@@ -8,7 +8,7 @@ spring:
# todo 需替换配置
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/ruoyi-vue-pro?rewriteBatchedStatements=true
url: jdbc:mysql://localhost:3306/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true
username: root
password: 123asd
# Redis 配置

View File

@@ -20,6 +20,23 @@
<result column="updater" jdbcType="VARCHAR" property="updater" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
</resultMap>
<resultMap id="HostInfoVo" type="com.yupi.springbootinit.model.vo.hosts.NewHostsVO">
<!--@mbg.generated-->
<!--@Table new_hosts-->
<id column="id" jdbcType="BIGINT" property="id" />
<result column="hosts_id" jdbcType="VARCHAR" property="hostsId" />
<result column="hosts_level" jdbcType="VARCHAR" property="hostsLevel" />
<result column="hosts_coins" jdbcType="INTEGER" property="hostsCoins" />
<result column="Invitation_type" jdbcType="INTEGER" property="invitationType" />
<result column="fans" jdbcType="INTEGER" property="fans" />
<result column="fllowernum" jdbcType="INTEGER" property="fllowernum" />
<result column="yesterday_coins" jdbcType="INTEGER" property="yesterdayCoins" />
<result column="country" jdbcType="VARCHAR" property="country" />
<result column="hosts_kind" jdbcType="VARCHAR" property="hostsKind" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated-->
id, hosts_id, hosts_level, hosts_coins, Invitation_type, fans, fllowernum, yesterday_coins,
@@ -222,4 +239,91 @@
#{item.tenantId,jdbcType=BIGINT}, #{item.creator,jdbcType=INTEGER})
</foreach>
</insert>
<select id="selectPageByCondition" resultMap="HostInfoVo">
select id,hosts_id, hosts_level, hosts_coins, Invitation_type, fans, fllowernum,
yesterday_coins,create_time, country, hosts_kind from new_hosts where
new_hosts.creator=#{hostInfoDTO.creator}
and new_hosts.tenant_id=#{hostInfoDTO.tenantId}
<if test="hostInfoDTO.country!= '' and hostInfoDTO.country != null">
and new_hosts.country =#{hostInfoDTO.country,jdbcType=VARCHAR}
</if>
<if test="hostInfoDTO.createTime != null">
and DATE(new_hosts.create_time) =#{hostInfoDTO.createTime}
</if>
<if test="hostInfoDTO.hostsId != '' and hostInfoDTO.hostsId != null ">
and new_hosts.hosts_id =#{hostInfoDTO.hostsId,jdbcType=VARCHAR}
</if>
<!-- 今日主播金币筛选 -->
<if test="hostInfoDTO.hostsCoinsMin != null and hostInfoDTO.hostsCoinsMax == null ">
and new_hosts.hosts_coins >=#{hostInfoDTO.hostsCoinsMin,jdbcType=INTEGER}
</if>
<if test="hostInfoDTO.hostsCoinsMax != null and hostInfoDTO.hostsCoinsMin == null ">
and new_hosts.hosts_coins &lt;=#{hostInfoDTO.hostsCoinsMax,jdbcType=INTEGER}
</if>
<if test="hostInfoDTO.hostsCoinsMin != null and hostInfoDTO.hostsCoinsMax != null " >
and new_hosts.hosts_coins between #{hostInfoDTO.hostsCoinsMin,jdbcType=INTEGER} and #{hostInfoDTO.hostsCoinsMax,jdbcType=INTEGER}
</if>
<!-- 昨日主播金币筛选 -->
<if test="hostInfoDTO.yesterdayCoinsMin != null and hostInfoDTO.yesterdayCoinsMax == null ">
and new_hosts.yesterday_coins >=#{hostInfoDTO.yesterdayCoinsMin,jdbcType=INTEGER}
</if>
<if test="hostInfoDTO.yesterdayCoinsMax != null and hostInfoDTO.yesterdayCoinsMin == null ">
and new_hosts.yesterday_coins &lt;=#{hostInfoDTO.yesterdayCoinsMax,jdbcType=INTEGER}
</if>
<if test="hostInfoDTO.yesterdayCoinsMin != null and hostInfoDTO.yesterdayCoinsMax != null " >
and new_hosts.yesterday_coins between #{hostInfoDTO.yesterdayCoinsMin,jdbcType=INTEGER} and #{hostInfoDTO.yesterdayCoinsMax,jdbcType=INTEGER}
</if>
<!-- 主播粉丝数筛选-->
<if test="hostInfoDTO.fansMin != null and hostInfoDTO.fansMax == null ">
and new_hosts.fans >=#{hostInfoDTO.fansMin,jdbcType=INTEGER}
</if>
<if test="hostInfoDTO.fansMax != null and hostInfoDTO.fansMin == null ">
and new_hosts.fans &lt;=#{hostInfoDTO.yesterdayCoinsMax,jdbcType=INTEGER}
</if>
<if test="hostInfoDTO.fansMin != null and hostInfoDTO.fansMax != null " >
and new_hosts.fans between #{hostInfoDTO.fansMin,jdbcType=INTEGER} and #{hostInfoDTO.fansMax,jdbcType=INTEGER}
</if>
<!-- 主播粉关注筛选-->
<if test="hostInfoDTO.fllowernumMin != null and hostInfoDTO.fllowernumMax == null ">
and new_hosts.fllowernum >=#{hostInfoDTO.fllowernumMin,jdbcType=INTEGER}
</if>
<if test="hostInfoDTO.fllowernumMax != null and hostInfoDTO.fllowernumMin == null ">
and new_hosts.fllowernum &lt;=#{hostInfoDTO.fllowernumMax,jdbcType=INTEGER}
</if>
<if test="hostInfoDTO.fllowernumMin != null and hostInfoDTO.fllowernumMax != null " >
and new_hosts.fllowernum between #{hostInfoDTO.fllowernumMin,jdbcType=INTEGER} and #{hostInfoDTO.fllowernumMax,jdbcType=INTEGER}
</if>
<!-- 邀请类筛选 -->
<if test="hostInfoDTO.invitationType != null">
and new_hosts.Invitation_type =#{hostInfoDTO.invitationType,jdbcType=INTEGER}
</if>
<!-- 排序类型 -->
order by
<choose>
<!-- 传空和默认的情况下按照时间降序排序 -->
<when test="hostInfoDTO.sortName == '' or hostInfoDTO.sortName == null ">
new_hosts.create_time desc
</when>
<!-- sortNmae 有值的情况下排序 -->
<when test="hostInfoDTO.sortName != null and hostInfoDTO.sort != null ">
<!-- 昨日主播金币条件排序 -->
<if test="hostInfoDTO.sortName == 'yesterdayCoins' and hostInfoDTO.sort != null">
new_hosts.yesterday_coins ${hostInfoDTO.sort}
</if>
<!-- 主播金币条件排序 -->
<if test="hostInfoDTO.sortName == 'hostsCoins' and hostInfoDTO.sort != null">
new_hosts.hostsCoins ${hostInfoDTO.sort}
</if>
<!-- 主播粉丝条件排序 -->
<if test="hostInfoDTO.sortName == 'fans' and hostInfoDTO.sort != null">
new_hosts.fans ${hostInfoDTO.sort}
</if>
<!-- 主播关注数量排序 -->
<if test="hostInfoDTO.sortName == 'fllowernum' and hostInfoDTO.sort != null">
new_hosts.fllowernum ${hostInfoDTO.sort}
</if>
</when>
</choose>
</select>
</mapper>