已完成小程序端的项目查询

This commit is contained in:
2025-05-11 19:55:57 +08:00
parent 2e33a08a33
commit 3eea5f4dec
8 changed files with 238 additions and 116 deletions

View File

@ -1,5 +1,6 @@
package com.greenorange.promotion.controller.userInfo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.greenorange.promotion.annotation.RequiresPermission;
import com.greenorange.promotion.annotation.SysLog;
import com.greenorange.promotion.common.BaseResponse;
@ -10,9 +11,13 @@ import com.greenorange.promotion.exception.ThrowUtils;
import com.greenorange.promotion.model.dto.CommonBatchRequest;
import com.greenorange.promotion.model.dto.userMainInfo.UserMainInfoAddRequest;
import com.greenorange.promotion.model.dto.userMainInfo.UserMainInfoUpdateRequest;
import com.greenorange.promotion.model.entity.UserInfo;
import com.greenorange.promotion.model.entity.UserMainInfo;
import com.greenorange.promotion.model.vo.userMainInfo.UserMainInfoVO;
import com.greenorange.promotion.model.vo.userMainInfo.UserMemberInfoVO;
import com.greenorange.promotion.model.vo.userMainInfo.UserTeamInfoVO;
import com.greenorange.promotion.service.common.CommonService;
import com.greenorange.promotion.service.userInfo.UserInfoService;
import com.greenorange.promotion.service.userInfo.UserMainInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -26,7 +31,10 @@ import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
@ -38,6 +46,9 @@ import java.util.List;
@Tag(name = "用户主要信息管理")
public class UserMainInfoController {
@Resource
private UserInfoService userInfoService;
@Resource
private UserMainInfoService userMainInfoService;
@ -55,86 +66,115 @@ public class UserMainInfoController {
@SysLog(title = "用户主要信息管理", content = "小程序用户查询团队信息")
public BaseResponse<Boolean> queryUserTeamInfo(HttpServletRequest request) {
Long userId = (Long) request.getAttribute("userId");
LambdaQueryWrapper<UserInfo> userInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
userInfoLambdaQueryWrapper.eq(UserInfo::getParentUserId, userId);
List<UserInfo> userInfoList = userInfoService.list(userInfoLambdaQueryWrapper);
List<UserMainInfo> userMainInfoList = commonService.findByFieldInTargetField(userInfoList, userMainInfoService, UserInfo::getId, "userId");
// 封装Map集合用户id用户信息
Map<Long, UserInfo> userInfoMap = new HashMap<>();
for (UserInfo userInfo : userInfoList) {
userInfoMap.put(userInfo.getId(), userInfo);
}
// 封装Map集合用户id用户主要信息
Map<Long, UserMainInfo> userMainInfoMap = new HashMap<>();
for (UserMainInfo userMainInfo : userMainInfoList) {
userMainInfoMap.put(userMainInfo.getUserId(), userMainInfo);
}
List<UserMemberInfoVO> userMemberInfoVOList = new ArrayList<>();
for (UserInfo userInfo : userInfoList) {
Long id = userInfo.getId();
UserInfo userInformation = userInfoMap.get(id);
UserMainInfo userMainInfo = userMainInfoMap.get(id);
UserMemberInfoVO userMemberInfoVO = UserMemberInfoVO.builder()
.subUserId(id)
.nickName(userInformation.getNickName())
.phoneNumber(userInformation.getPhoneNumber())
.teamSize(userMainInfo.getTeamSize())
.parentEarnings(userMainInfo.getParentEarnings())
.registerTime(userInformation.getCreateTime())
.build();
userMemberInfoVOList.add(userMemberInfoVO);
}
return ResultUtils.success(true);
}
/**
* web端管理员添加用户主要信息
* @param userMainInfoAddRequest 用户主要信息添加请求体
* @return 是否添加成功
*/
@PostMapping("add")
@Operation(summary = "web端管理员添加用户主要信息", description = "参数用户主要信息添加请求体权限管理员方法名addUserMainInfo")
@RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
@SysLog(title = "用户主要信息管理", content = "web端管理员添加用户主要信息")
public BaseResponse<Boolean> addUserMainInfo(@Valid @RequestBody UserMainInfoAddRequest userMainInfoAddRequest) {
UserMainInfo userMainInfo = commonService.copyProperties(userMainInfoAddRequest, UserMainInfo.class);
userMainInfoService.save(userMainInfo);
return ResultUtils.success(true);
}
/**
* web端管理员根据id修改用户主要信息信息
* @param userMainInfoUpdateRequest 用户主要信息更新请求体
* @return 是否更新成功
*/
@PostMapping("update")
@Operation(summary = "web端管理员更新用户主要信息", description = "参数用户主要信息更新请求体权限管理员方法名updateUserMainInfo")
@RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
@SysLog(title = "用户主要信息管理", content = "web端管理员根据id修改用户主要信息信息")
public BaseResponse<Boolean> updateUserMainInfo(@Valid @RequestBody UserMainInfoUpdateRequest userMainInfoUpdateRequest) {
UserMainInfo userMainInfo = commonService.copyProperties(userMainInfoUpdateRequest, UserMainInfo.class);
userMainInfoService.updateById(userMainInfo);
return ResultUtils.success(true);
}
/**
* web端管理员根据id删除用户主要信息
* @param commonRequest 用户主要信息删除请求体
* @return 是否删除成功
*/
@PostMapping("delete")
@Operation(summary = "web端管理员根据id删除用户主要信息", description = "参数用户主要信息删除请求体权限管理员方法名delUserMainInfo")
@RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
@SysLog(title = "用户主要信息管理", content = "web端管理员根据id删除用户主要信息")
public BaseResponse<Boolean> delUserMainInfo(@Valid @RequestBody CommonRequest commonRequest) {
Long id = commonRequest.getId();
userMainInfoService.removeById(id);
return ResultUtils.success(true);
}
/**
* web端管理员批量删除用户主要信息
* @param commonBatchRequest 用户主要信息批量删除请求体
* @return 是否删除成功
*/
@PostMapping("delBatch")
@Operation(summary = "web端管理员批量删除用户主要信息", description = "参数用户主要信息批量删除请求体权限管理员方法名delBatchUserMainInfo")
@RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
@SysLog(title = "用户主要信息管理", content = "web端管理员批量删除用户主要信息")
public BaseResponse<Boolean> delBatchUserMainInfo(@Valid @RequestBody CommonBatchRequest commonBatchRequest) {
List<Long> ids = commonBatchRequest.getIds();
userMainInfoService.removeByIds(ids);
return ResultUtils.success(true);
}
/**
* web端管理员根据id查询用户主要信息
* @param commonRequest 用户主要信息查询请求体
* @return 用户主要信息信息
*/
@PostMapping("queryById")
@Operation(summary = "web端管理员根据id查询用户主要信息", description = "参数用户主要信息查询请求体权限管理员方法名queryUserMainInfoById")
@RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
@SysLog(title = "用户主要信息管理", content = "web端管理员根据id查询用户主要信息")
public BaseResponse<UserMainInfoVO> queryUserMainInfoById(@Valid @RequestBody CommonRequest commonRequest) {
Long id = commonRequest.getId();
UserMainInfo userMainInfo = userMainInfoService.getById(id);
ThrowUtils.throwIf(userMainInfo == null, ErrorCode.OPERATION_ERROR, "当前用户主要信息不存在");
UserMainInfoVO userMainInfoVO = commonService.copyProperties(userMainInfo, UserMainInfoVO.class);
return ResultUtils.success(userMainInfoVO);
}
// /**
// * web端管理员添加用户主要信息
// * @param userMainInfoAddRequest 用户主要信息添加请求体
// * @return 是否添加成功
// */
// @PostMapping("add")
// @Operation(summary = "web端管理员添加用户主要信息", description = "参数用户主要信息添加请求体权限管理员方法名addUserMainInfo")
// @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
// @SysLog(title = "用户主要信息管理", content = "web端管理员添加用户主要信息")
// public BaseResponse<Boolean> addUserMainInfo(@Valid @RequestBody UserMainInfoAddRequest userMainInfoAddRequest) {
// UserMainInfo userMainInfo = commonService.copyProperties(userMainInfoAddRequest, UserMainInfo.class);
// userMainInfoService.save(userMainInfo);
// return ResultUtils.success(true);
// }
//
// /**
// * web端管理员根据id修改用户主要信息信息
// * @param userMainInfoUpdateRequest 用户主要信息更新请求体
// * @return 是否更新成功
// */
// @PostMapping("update")
// @Operation(summary = "web端管理员更新用户主要信息", description = "参数用户主要信息更新请求体权限管理员方法名updateUserMainInfo")
// @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
// @SysLog(title = "用户主要信息管理", content = "web端管理员根据id修改用户主要信息信息")
// public BaseResponse<Boolean> updateUserMainInfo(@Valid @RequestBody UserMainInfoUpdateRequest userMainInfoUpdateRequest) {
// UserMainInfo userMainInfo = commonService.copyProperties(userMainInfoUpdateRequest, UserMainInfo.class);
// userMainInfoService.updateById(userMainInfo);
// return ResultUtils.success(true);
// }
//
// /**
// * web端管理员根据id删除用户主要信息
// * @param commonRequest 用户主要信息删除请求体
// * @return 是否删除成功
// */
// @PostMapping("delete")
// @Operation(summary = "web端管理员根据id删除用户主要信息", description = "参数用户主要信息删除请求体权限管理员方法名delUserMainInfo")
// @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
// @SysLog(title = "用户主要信息管理", content = "web端管理员根据id删除用户主要信息")
// public BaseResponse<Boolean> delUserMainInfo(@Valid @RequestBody CommonRequest commonRequest) {
// Long id = commonRequest.getId();
// userMainInfoService.removeById(id);
// return ResultUtils.success(true);
// }
//
// /**
// * web端管理员批量删除用户主要信息
// * @param commonBatchRequest 用户主要信息批量删除请求体
// * @return 是否删除成功
// */
// @PostMapping("delBatch")
// @Operation(summary = "web端管理员批量删除用户主要信息", description = "参数用户主要信息批量删除请求体权限管理员方法名delBatchUserMainInfo")
// @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
// @SysLog(title = "用户主要信息管理", content = "web端管理员批量删除用户主要信息")
// public BaseResponse<Boolean> delBatchUserMainInfo(@Valid @RequestBody CommonBatchRequest commonBatchRequest) {
// List<Long> ids = commonBatchRequest.getIds();
// userMainInfoService.removeByIds(ids);
// return ResultUtils.success(true);
// }
//
// /**
// * web端管理员根据id查询用户主要信息
// * @param commonRequest 用户主要信息查询请求体
// * @return 用户主要信息信息
// */
// @PostMapping("queryById")
// @Operation(summary = "web端管理员根据id查询用户主要信息", description = "参数用户主要信息查询请求体权限管理员方法名queryUserMainInfoById")
// @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
// @SysLog(title = "用户主要信息管理", content = "web端管理员根据id查询用户主要信息")
// public BaseResponse<UserMainInfoVO> queryUserMainInfoById(@Valid @RequestBody CommonRequest commonRequest) {
// Long id = commonRequest.getId();
// UserMainInfo userMainInfo = userMainInfoService.getById(id);
// ThrowUtils.throwIf(userMainInfo == null, ErrorCode.OPERATION_ERROR, "当前用户主要信息不存在");
// UserMainInfoVO userMainInfoVO = commonService.copyProperties(userMainInfo, UserMainInfoVO.class);
// return ResultUtils.success(userMainInfoVO);
// }
// /**
// * Web端管理员分页查询用户主要信息