Commit 1b6007f5 authored by licc's avatar licc

新增获取前三级用户信息接口

parent 7d14b627
package cn.wisenergy.mapper;
import cn.wisenergy.model.app.UserData;
import cn.wisenergy.model.app.Users;
import cn.wisenergy.model.dto.UserDto;
import cn.wisenergy.model.dto.UserSimpleInfoDto;
import cn.wisenergy.model.dto.UsersInfoDto;
import cn.wisenergy.model.vo.UserVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
......@@ -89,21 +87,21 @@ public interface UsersMapper extends BaseMapper<Users> {
*/
List<UserVo> getUserData(@Param("list") List<Long> list);
/*************** chenqi****************/
/**
* 获取伞下有那些用户
* 获取 某一范围内的用户id
*
* @param userId 用户id
* @param startNumber 开始id
* @param endNo 结束id
* @return
*/
List<UserSimpleInfoDto> getDownUsersById(Long userId);
List<Long> getUserIds(@Param("startNo") Integer startNumber, @Param("endNo") Integer endNo);
/**
* 获取用户向下最深层级层级数,伞下人员总和
* 获取前三级用户列表
*
* @param userId 用户
* @return
* @return 用户列表
*/
UsersInfoDto getDownLevelAndTotalPeopleByUserId(Long userId);
List<UserVo> getThreeUser();
}
......@@ -156,7 +156,7 @@
<select id="getLastUser" resultType="cn.wisenergy.model.vo.UserVo">
select u.id as userId,u.parent_id as parentId,a.real_name as realName,a.id_number as idNumber,a.phone as phone,
a.total_recharge as totalRecharge,a.total_withdrawal as totalWithdrawal,a.rank as rank,a.bottom as bottom,
a.total_people as totalPeople,a.buy_total as buyTotal,a.sale_total as saleTotal
a.total_people as totalPeople,a.buy_total as buyTotal,a.sale_total as saleTotal,a.receive_addr as receiveAddr
from users u left join user_data a
on u.id=a.user_id
where u.parent_id =#{parentId}
......@@ -192,52 +192,6 @@
</where>
</select>
<!--*****************************************chenqi***************************************-->
<select id="getDownLevelAndTotalPeopleByUserId" resultType="cn.wisenergy.model.dto.UsersInfoDto">
SELECT
MAX(rank) 'bottom',
count(*)-1 'totalPeople'
FROM
users
WHERE
path like CONCAT((SELECT path FROM users WHERE id=#{userId}), '%')
</select>
<select id="getDownUsersById" resultType="cn.wisenergy.model.dto.UserSimpleInfoDto">
SELECT
u.id 'userId',
a.real_name ,
u.rank,
a.id_number,
u.phone,
if(ur.totalRecharge is NULL,0, round(ur.totalRecharge,2)) 'totalRecharge',
if(uw.totalWithdrawal is NULL,0,round(uw.totalWithdrawal,2)) 'totalWithdrawal',
u.parent_id,
aa.real_name 'parentName'
FROM users u
LEFT JOIN actives a ON u.id = a.user_id
LEFT JOIN actives aa ON u.parent_id = aa.user_id
LEFT JOIN (
SELECT user_id,round(SUM(amount),2) 'totalRecharge'
FROM user_recharge
WHERE user_id in (SELECT id from users WHERE parent_id = #{userId}) and status = 1
GROUP BY user_id
) ur ON ur.user_id=u.id
LEFT JOIN (
SELECT user_id,round(SUM(amount),2) 'totalWithdrawal'
FROM user_withdraws
WHERE user_id in (SELECT id from users WHERE parent_id = #{userId}) and status = 1
GROUP BY user_id
) uw ON uw.user_id=u.id
WHERE
u.parent_id = #{userId} or u.id = #{userId}
ORDER BY u.id
</select>
<select id="getAllUserData" resultType="cn.wisenergy.model.dto.UserDto">
select id as userId,rank,phone
from
......@@ -248,7 +202,7 @@ GROUP BY user_id
<select id="getUserData" resultType="cn.wisenergy.model.vo.UserVo">
select u.id as userId,u.parent_id as parentId,a.real_name as realName,a.id_number as idNumber,a.phone as phone,
a.total_recharge as totalRecharge,a.total_withdrawal as totalWithdrawal,a.rank as rank,a.bottom as bottom,
a.total_people as totalPeople,a.buy_total as buyTotal,a.sale_total as saleTotal
a.total_people as totalPeople,a.buy_total as buyTotal,a.sale_total as saleTotal,a.receive_addr as receiveAddr
from users u left join user_data a
on u.id=a.user_id
where u.id IN
......@@ -258,5 +212,22 @@ GROUP BY user_id
order by u.id
</select>
<select id="getUserIds" resultType="java.lang.Long">
select id
from
<include refid="table"/>
where id> #{startNo} and #{endNo} >=id
</select>
<select id="getThreeUser" resultType="cn.wisenergy.model.vo.UserVo">
select u.id as userId,u.parent_id as parentId,a.real_name as realName,a.id_number as idNumber,a.phone as phone,
a.total_recharge as totalRecharge,a.total_withdrawal as totalWithdrawal,a.rank as rank,a.bottom as bottom,
a.total_people as totalPeople,a.buy_total as buyTotal,a.sale_total as saleTotal,a.receive_addr as receiveAddr
from users u left join user_data a
on u.id=a.user_id
where u.rank in (1,2,3)
order by u.id
</select>
</mapper>
......@@ -11,6 +11,11 @@ import lombok.Data;
@ApiModel(value = "UserQueryVo")
public class UserQueryVo {
@ApiModelProperty(value = "要统计的数量", name = "number")
private Integer number;
@ApiModelProperty(value = "开始查询用户id", name = "startNo")
private Integer startNo;
@ApiModelProperty(value = "结束查询用户id", name = "endNo")
private Integer endNo;
}
......@@ -49,6 +49,9 @@ public class UserVo {
@ApiModelProperty(name = "saleTotal", value = "otc卖出总额")
private String saleTotal;
@ApiModelProperty(name = "receiveAddr", value = "转入地址")
private String receiveAddr;
@ApiModelProperty(value = "子节点数据", name = "childrens")
List<UserVo> children;
......
package cn.wisenergy.service.app;
import cn.wisenergy.model.dto.UserSimpleInfoDto;
import cn.wisenergy.model.dto.UsersInfoDto;
import java.util.List;
/**
* @Authotr:陈奇
* @QQ1799796883
*/
public interface TestUserService {
/**
* 查询下级用户的基本信息
* @param userId 用户id
* @return
*/
List<UserSimpleInfoDto> getDownUserInfoById(Long userId);
/**
* 查询用户详细信息
* @param userId 用户id
* @return
*/
UsersInfoDto getUserInfoById(Long userId);
}
......@@ -3,6 +3,8 @@ package cn.wisenergy.service.app;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.vo.UserQueryVo;
import java.util.List;
/**
* @author 86187
*/
......@@ -15,4 +17,11 @@ public interface UserDataService {
*/
R<Boolean> addBatch(UserQueryVo queryVo);
/**
* 获取没有统计数据的userId
*
* @return
*/
R<List<Long>> getUserIds(Integer startNo, Integer endNo);
}
......@@ -32,10 +32,11 @@ public interface UserService {
* @param userId 用户id
* @return 树结构
*/
R<List<UserVo>> getLastUser(Long userId);
R<UserVo> getLastUser(Long userId);
/**
* 获取用户详细信息
*
* @param userId 用户id
* @return 用户详细信息
*/
......@@ -43,10 +44,19 @@ public interface UserService {
/**
* 获取用户直线树结构
*
* @param userId 用户id
* @return 用户直线树结构
*/
R<List<UserVo>> getLinkTree(Long userId);
/**
* 获取前三级用户信息
*
* @return 用户直线树结构
*/
R<List<UserVo>> getThreeUser();
}
......@@ -29,15 +29,9 @@ public class BottomServiceImpl implements BottomService {
@Override
public R<Boolean> getBottom(UserQueryVo queryVo) {
Long usersId = userDataMapper.getBottomMaxId();
log.info("开始计算用户id:" + usersId);
if (null == usersId) {
usersId = 0L;
}
Integer startNo = Math.toIntExact(usersId) - 1;
Integer endNo = startNo + queryVo.getNumber();
//获取所有用户数据
List<UserData> list = userDataMapper.getBottom(startNo, endNo);
List<UserData> list = userDataMapper.getBottom(queryVo.getStartNo(), queryVo.getEndNo());
if (!CollectionUtils.isEmpty(list)) {
for (UserData userData : list) {
//3、向下最深层级层级数、伞下人员总和
......
package cn.wisenergy.service.app.impl;
import cn.wisenergy.common.enums.RespCodeEnum;
import cn.wisenergy.common.utils.exception.BaseCustomException;
import cn.wisenergy.mapper.*;
import cn.wisenergy.model.app.Actives;
import cn.wisenergy.model.app.Users;
import cn.wisenergy.model.dto.UserSimpleInfoDto;
import cn.wisenergy.model.dto.UsersInfoDto;
import cn.wisenergy.service.app.TestUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @Authotr:陈奇
* @QQ1799796883
*/
@Service
@Slf4j
public class TestUserServiceImpl implements TestUserService {
@Autowired
private UsersMapper usersMapper;
@Autowired
private UserRechargeMapper userRechargeMapper;
@Autowired
private UserWithdrawsMapper userWithdrawsMapper;
@Autowired
private ActivesMapper activesMapper;
@Autowired
private UsdtOrderDetailsMapper usdtOrderDetailsMapper;
private final String MONEYISEMPTY = "0";
/**
* 查询下级用户的基本信息
*
* @param userId 用户id
* @return
*/
@Override
public List<UserSimpleInfoDto> getDownUserInfoById(Long userId) {
log.info("TestUserServiceImpl[]getDownUserInfoById[]input.param.userId:" + userId);
// 1.判断用户是否存在
if (null==userId) {
userId = 1L;
}
Users user = usersMapper.selectById(userId);
if (null == user) {
throw new BaseCustomException(RespCodeEnum.EMPLOYEE_IS_NOT_EXIST_ERROR);
}
// 2.获取用户伞下所有用户的信息
List<UserSimpleInfoDto> downUsersById = usersMapper.getDownUsersById(userId);
return downUsersById;
}
/**
* 查询用户详细信息
*
* @param userId 用户id
* @return
*/
@Override
public UsersInfoDto getUserInfoById(Long userId) {
log.info("TestUserServiceImpl[]getUserInfoById[]input.param.userId:" + userId);
// 1.判断用户是否存在
Users user = userIsEmpty(userId);
// 2.获取用户详细信息
Actives userInfo = activesMapper.getByUserId(userId);
// 3.查询最深层级数和伞下人员总和
long startTime=System.currentTimeMillis();
UsersInfoDto userInfoDto = usersMapper.getDownLevelAndTotalPeopleByUserId(userId);
userInfoDto.setBottom(userInfoDto.getBottom() - user.getRank());
long endTime=System.currentTimeMillis();
// 4.查询用户充值和提现总额
Double totalRecharge = userRechargeMapper.getTotalRecharge(userId);
Double totalWithdrawal = userWithdrawsMapper.getTotalWithdrawal(userId);
// 5.计算OTC买入卖出
Double buyTotal = usdtOrderDetailsMapper.getBuyTotal(userId);
Double saleTotal = usdtOrderDetailsMapper.getSaleTotal(userId);
// 5.将查询出来的信息整合到dto类
userInfoDto.setUserId(userId);
BeanUtils.copyProperties(user, userInfoDto);
if (null != userInfo) {
BeanUtils.copyProperties(userInfo, userInfoDto);
}
userInfoDto.setTotalRecharge(totalRecharge == null ? MONEYISEMPTY : totalRecharge.toString());
userInfoDto.setTotalWithdrawal(totalWithdrawal == null ? MONEYISEMPTY : totalWithdrawal.toString());
userInfoDto.setBuyTotal(buyTotal == null ? MONEYISEMPTY : buyTotal.toString());
userInfoDto.setSaleTotal(saleTotal == null ? MONEYISEMPTY : saleTotal.toString());
System.out.println("程序运行时间: "+(endTime-startTime)+"ms");
return userInfoDto;
}
/**
* 判断用户是否存在,存在并返回user信息
*
* @param userId
* @return
*/
private Users userIsEmpty(Long userId) {
if (null == userId) {
throw new BaseCustomException(RespCodeEnum.INPUT_PARAMETER_ISEMPTY);
}
Users user = usersMapper.selectById(userId);
if (null == user) {
throw new BaseCustomException(RespCodeEnum.EMPLOYEE_IS_NOT_EXIST_ERROR);
}
return user;
}
}
......@@ -4,7 +4,6 @@ import cn.wisenergy.common.utils.R;
import cn.wisenergy.mapper.*;
import cn.wisenergy.model.app.Actives;
import cn.wisenergy.model.app.UserData;
import cn.wisenergy.model.app.Users;
import cn.wisenergy.model.dto.UserDto;
import cn.wisenergy.model.dto.UsersInfoDto;
import cn.wisenergy.model.vo.UserQueryVo;
......@@ -48,19 +47,9 @@ public class UserDataServiceImpl implements UserDataService {
@Override
public R<Boolean> addBatch(UserQueryVo queryVo) {
if (null == queryVo.getNumber() || queryVo.getNumber() == 0) {
return R.error("参数不能为空或0!");
}
Long usersId = userDataMapper.getMaxId();
log.info("开始计算统计数据用户id:" + usersId);
if (null == usersId) {
usersId = 0L;
}
Integer startNo = Math.toIntExact(usersId);
Integer endNo = startNo + queryVo.getNumber();
//获取所有用户数据
List<UserDto> userDtos = usersMapper.getAllUserData(startNo, endNo);
List<UserDto> userDtos = usersMapper.getAllUserData(queryVo.getStartNo(), queryVo.getEndNo());
if (CollectionUtils.isEmpty(userDtos)) {
return R.ok(1, false);
}
......@@ -122,4 +111,19 @@ public class UserDataServiceImpl implements UserDataService {
}
return R.ok(0, true);
}
@Override
public R<List<Long>> getUserIds(Integer startNo, Integer endNo) {
List<Long> userIds = usersMapper.getUserIds(startNo, endNo);
List<Long> list = new ArrayList<>();
for (Long userId : userIds) {
//判断是否存在统计数据
UserData data = userDataMapper.getByUserId(userId);
if (null == data) {
list.add(userId);
}
}
return R.ok(list);
}
}
......@@ -51,46 +51,44 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, Users> implements
}
@Override
public R<List<UserVo>> getLastUser(Long userId) {
public R<UserVo> getLastUser(Long userId) {
UserVo userVo = new UserVo();
//用户id为空时,查询最顶级
if (null == userId) {
userId = 1L;
Users users = usersMapper.getById(userId);
UserVo userVo = new UserVo();
userVo.setUserId(users.getId());
userVo.setParentId(users.getParentId());
//获取用户统计数据
UserData userData = userDataMapper.getByUserId(userId);
userVo.setRealName(userData.getRealName());
if (null != userData.getBuyTotal()) {
userVo.setBuyTotal(userData.getBuyTotal().toString());
}
userVo.setBottom(userData.getBottom());
userVo.setIdNumber(userData.getIdNumber());
userVo.setPhone(userData.getPhone());
userVo.setRank(userData.getRank());
if (null != userData.getSaleTotal()) {
userVo.setSaleTotal(userData.getSaleTotal().toString());
}
userVo.setTotalPeople(userData.getTotalPeople());
}
Users users = usersMapper.getById(userId);
userVo.setUserId(users.getId());
userVo.setParentId(users.getParentId());
//获取用户统计数据
UserData userData = userDataMapper.getByUserId(userId);
userVo.setRealName(userData.getRealName());
if (null != userData.getBuyTotal()) {
userVo.setBuyTotal(userData.getBuyTotal().toString());
}
userVo.setBottom(userData.getBottom());
userVo.setIdNumber(userData.getIdNumber());
userVo.setPhone(userData.getPhone());
userVo.setRank(userData.getRank());
if (null != userData.getSaleTotal()) {
userVo.setSaleTotal(userData.getSaleTotal().toString());
}
userVo.setTotalPeople(userData.getTotalPeople());
if (null != userData.getTotalRecharge()) {
userVo.setTotalRecharge(userData.getTotalRecharge().toString());
}
if (null != userData.getTotalRecharge()) {
userVo.setTotalRecharge(userData.getTotalRecharge().toString());
}
if (null != userData.getTotalWithdrawal()) {
userVo.setTotalWithdrawal(userData.getTotalWithdrawal().toString());
}
List<UserVo> list = new ArrayList<>();
list.add(userVo);
return R.ok(list);
if (null != userData.getTotalWithdrawal()) {
userVo.setTotalWithdrawal(userData.getTotalWithdrawal().toString());
}
//id不为空,查询当前用户的下一级
//查询当前用户的下一级
Users user = usersMapper.getById(userId);
List<UserVo> lastList = usersMapper.getLastUser(Integer.valueOf(user.getId().toString()));
return R.ok(lastList);
userVo.setChildren(lastList);
return R.ok(userVo);
}
@Override
......@@ -142,6 +140,20 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, Users> implements
return R.ok(userVos);
}
@Override
public R<List<UserVo>> getThreeUser() {
List<UserVo> userVos = new ArrayList<>();
//获取前三级用户信息
List<UserVo> list = usersMapper.getThreeUser();
//递归生成树结构
if (CollectionUtils.isNotEmpty(list)) {
userVos = getChildren(list);
}
return R.ok(userVos);
}
private List<UserVo> getChildren(List<UserVo> list) {
List<UserVo> rootList = new ArrayList<>();
List<UserVo> childrenList = new ArrayList<>();
......
......@@ -10,6 +10,7 @@ import cn.wisenergy.web.common.BaseController;
import cn.wisenergy.web.shiro.JwtUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -65,10 +66,16 @@ public class UserController extends BaseController {
@ApiOperation(value = "获取用户顶级/下一级", notes = "获取用户顶级/下一级", httpMethod = "GET")
@ApiImplicitParam(name = "userId", value = "用户id,空值查询顶级,其他查询下一级", dataType = "int")
@GetMapping("/user/getLastUser")
public R<List<UserVo>> getLastUser(Long userId) {
public R<UserVo> getLastUser(Long userId) {
return userService.getLastUser(userId);
}
@ApiOperation(value = "获取前三级用户", notes = "获取前三级用户", httpMethod = "GET")
@GetMapping("/user/getThreeUser")
public R<List<UserVo>> getThreeUser() {
return userService.getThreeUser();
}
@ApiOperation(value = "获取用户详细信息", notes = "获取用户详细信息", httpMethod = "GET")
@ApiImplicitParam(name = "userId", value = "用户id", dataType = "int")
@GetMapping("/user/getUserInfo")
......
......@@ -2,17 +2,19 @@ package cn.wisenergy.web.admin.controller.app;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.vo.UserQueryVo;
import cn.wisenergy.service.app.BottomService;
import cn.wisenergy.service.app.UserDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
......@@ -32,4 +34,14 @@ public class UserDataController {
return userDataService.addBatch(queryVo);
}
@ApiOperation(value = "获取没有统计数据的userId", notes = "获取没有统计数据的userId", httpMethod = "GET")
@ApiImplicitParams({
@ApiImplicitParam(name = "startNo", value = "开始查询用户id", dataType = "int"),
@ApiImplicitParam(name = "endNo", value = "结束查询用户id", dataType = "int")
})
@GetMapping("/user/getUserIds")
public R<List<Long>> getUserIds(Integer startNo, Integer endNo) {
return userDataService.getUserIds(startNo, endNo);
}
}
......@@ -17,7 +17,7 @@ spring:
allow-bean-definition-overriding: true
# 环境 dev|test|prod
profiles:
active: dev
active: prod
# jackson时间格式化
jackson:
time-zone: GMT+8
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment