1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package cn.wisenergy.service.app.impl;
import cn.wisenergy.common.enums.RespCodeEnum;
import cn.wisenergy.common.utils.exception.BaseCustomException;
import cn.wisenergy.mapper.ActivesMapper;
import cn.wisenergy.mapper.UserRechargeMapper;
import cn.wisenergy.mapper.UserWithdrawsMapper;
import cn.wisenergy.mapper.UsersMapper;
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;
/**
* 查询下级用户的基本信息
* @param userId 用户id
* @return
*/
@Override
public List<UserSimpleInfoDto> getDownUserInfoById(Long userId) {
log.info("TestUserServiceImpl[]getDownUserInfoById[]input.param.userId:" + userId);
long startTime=System.currentTimeMillis();
// 1.判断用户是否存在
userIsEmpty(userId);
// 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.查询最深层级数和伞下人员总和
UsersInfoDto userInfoDto = usersMapper.getDownLevelAndTotalPeopleByUserId(userId);
// 4.查询用户充值和提现总额
Double totalRecharge = userRechargeMapper.getTotalRecharge(userId);
Double totalWithdrawal = userWithdrawsMapper.getTotalWithdrawal(userId);
// 5.将查询出来的信息整合到dto类
BeanUtils.copyProperties(user,userInfoDto);
if (null != userInfo) {
BeanUtils.copyProperties(userInfo,userInfoDto);
}
if (null != totalRecharge) {
userInfoDto.setTotalRecharge(totalRecharge.toString());
}
if (null != totalWithdrawal) {
userInfoDto.setTotalWithdrawal(totalWithdrawal.toString());
}
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;
}
}