Commit 4e52601c authored by cq990612's avatar cq990612

增加获取用户详细信息和下级用户信息接口

parent 9faf969e
......@@ -2,6 +2,7 @@ package cn.wisenergy.mapper;
import cn.wisenergy.model.app.Users;
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;
......@@ -70,8 +71,17 @@ public interface UsersMapper extends BaseMapper<Users> {
/*************** chenqi****************/
List<UsersInfoDto> getDownUsersById(Long userId);
/**
* 获取伞下有那些用户
* @param userId 用户id
* */
List<UserSimpleInfoDto> getDownUsersById(Long userId);
UsersInfoDto getUsersById(Long userId);
/**
* 获取用户向下最深层级层级数,伞下人员总和
* @param userId 用户
* @return
*/
UsersInfoDto getDownLevelAndTotalPeopleByUserId(Long userId);
}
......@@ -171,19 +171,6 @@
</select>
<!--*****************************************chenqi***************************************-->
<select id="getUsersById" resultType="cn.wisenergy.model.dto.UsersInfoDto">
SELECT u.id,a.real_name,a.id_number,u.phone,u.rank
FROM users u LEFT actives a ON u.id = a.user_id
LEFT user_recharge ur ON u.id = ur.user_id
LEFT user_withdraws uw ON u.id = uw.user_id
<where>
</where>
</select>
<select id="getDownLevel" resultType="java.lang.Double">
select
......@@ -201,4 +188,38 @@
</where>
</select>
<!--*****************************************chenqi***************************************-->
<select id="getDownLevelAndTotalPeopleByUserId" resultType="cn.wisenergy.model.dto.UsersInfoDto">
SELECT id 'userId',
MAX(rank)-rank 'bottom',
count(*)-1 'totalPeople'
FROM
users
WHERE
FIND_IN_SET(#{userId},path)
</select>
<select id="getDownUsersById" resultType="cn.wisenergy.model.dto.UserSimpleInfoDto">
SELECT
u.id 'userId',
a.real_name ,
u.rank,
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
WHERE
u.parent_id = #{userId}
</select>
</mapper>
package cn.wisenergy.model.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* @Authotr:陈奇
* @QQ1799796883
*/
@Data
@Accessors(chain = true)
@ApiModel(value="UserSimpleInfoDto类", description="user简单信息")
public class UserSimpleInfoDto {
@ApiModelProperty(name = "userId", value = "会员ID")
private Long userId;
@ApiModelProperty(name = "realName",value = "姓名")
private String realName;
@ApiModelProperty(name = "rank", value = "层级")
private Integer rank;
@ApiModelProperty(name = "parentId", value = "直接上级id")
private Integer parentId;
@ApiModelProperty(name = "parentName", value = "直接上级姓名")
private String parentName;
}
package cn.wisenergy.service.app;
import cn.wisenergy.model.dto.UserSimpleInfoDto;
import cn.wisenergy.model.dto.UsersInfoDto;
import java.util.List;
......@@ -10,5 +11,18 @@ import java.util.List;
*/
public interface TestUserService {
List<UsersInfoDto> getDownUserInfoById(Long userId);
/**
* 查询下级用户的基本信息
* @param userId 用户id
* @return
*/
List<UserSimpleInfoDto> getDownUserInfoById(Long userId);
/**
* 查询用户详细信息
* @param userId 用户id
* @return
*/
UsersInfoDto getUserInfoById(Long userId);
}
......@@ -2,11 +2,17 @@ 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;
......@@ -23,9 +29,70 @@ 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<UsersInfoDto> getDownUserInfoById(Long userId) {
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);
}
......@@ -33,18 +100,6 @@ public class TestUserServiceImpl implements TestUserService {
if (null == user) {
throw new BaseCustomException(RespCodeEnum.EMPLOYEE_IS_NOT_EXIST_ERROR);
}
// 1.获取用户伞下所有用户的信息
List<UsersInfoDto> downUsersById = usersMapper.getDownUsersById(userId);
// 2.获取当前用户的向下最深层级层级数,伞下人员总和
UsersInfoDto usersInfoDto = usersMapper.getUsersById(userId);
for (UsersInfoDto u : downUsersById) {
if (u.getId().equals(userId)) {
u.setBottom(usersInfoDto.getBottom()).setTotalPeople(usersInfoDto.getTotalPeople());
break;
}
}
return downUsersById;
return user;
}
}
package cn.wisenergy.web.admin.controller.app;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.app.dto.UsersInfoDto;
import cn.wisenergy.model.dto.UserSimpleInfoDto;
import cn.wisenergy.model.dto.UsersInfoDto;
import cn.wisenergy.service.app.TestUserService;
import cn.wisenergy.web.common.BaseController;
import io.swagger.annotations.Api;
......@@ -18,20 +19,29 @@ import java.util.List;
* @author ASUS
*/
@Api(tags = "用户管理(Test)")
@RestController("/users")
@RestController
@Slf4j
public class TestUserController2 extends BaseController {
@Autowired
private TestUserService testUserService;
@ApiOperation(value = "获取用户下用户的信息", notes = "获取用户下用户的信息", httpMethod = "GET")
@ApiOperation(value = "获取下一级用户得信息", notes = "获取下一级用户得信息", httpMethod = "GET")
@ApiImplicitParam(name = "userId", value = "用户id", dataType = "int")
@GetMapping("/getByUserId")
public R<List<UsersInfoDto>> getDownUserInfoById(Long userId) {
log.info("TestUserController2[]getDownUserInfoById[]input.param.userId:" + userId);
List<UsersInfoDto> users = testUserService.getDownUserInfoById(userId);
@GetMapping("/users/getDownUsersInfoById")
public R<List<UserSimpleInfoDto>> getDownUserInfoById(Long userId) {
log.info("TestUserController2[]getDownUsersInfoById[]input.param.userId:" + userId);
List<UserSimpleInfoDto> users = testUserService.getDownUserInfoById(userId);
return R.ok(users);
}
@ApiOperation(value = "获取用户详细信息", notes = "获取用户详细信息", httpMethod = "GET")
@ApiImplicitParam(name = "userId", value = "用户id", dataType = "int")
@GetMapping("/users/getUserInfoById")
public R<UsersInfoDto> getUserInfoById(Long userId) {
log.info("TestUserController2[]getUserInfoById[]input.param.userId:" + userId);
UsersInfoDto user = testUserService.getUserInfoById(userId);
return R.ok(user);
}
}
......@@ -67,6 +67,7 @@ public class ShiroConfig {
filterChainDefinitionMap.put("/webjars/springfox-swagger-ui/**", "anon");
filterChainDefinitionMap.put("/v2/api-docs", "anon");
filterChainDefinitionMap.put("/user/**", "anon");
filterChainDefinitionMap.put("/users/**", "anon");
filterChainDefinitionMap.put("/ZX/**", "anon"); //资讯的访问地址
filterChainDefinitionMap.put("/api/user/**", "anon"); //登录注册路径
filterChainDefinitionMap.put("/api/sms/verifyCode", "anon");
......
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