旗开得胜

This commit is contained in:
chen-xin-zhi 2025-04-27 12:24:24 +08:00
parent 8c557aa0fd
commit be354a98ec
5 changed files with 447 additions and 0 deletions

View File

@ -0,0 +1,161 @@
package com.greenorange.promotion.controller.user;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.greenorange.promotion.common.BaseResponse;
import com.greenorange.promotion.common.ErrorCode;
import com.greenorange.promotion.common.ResultUtils;
import com.greenorange.promotion.exception.BusinessException;
import com.greenorange.promotion.exception.ThrowUtils;
import com.greenorange.promotion.model.dto.CommonBatchRequest;
import com.greenorange.promotion.model.dto.CommonRequest;
import com.greenorange.promotion.model.dto.user.UserInfoAddRequest;
import com.greenorange.promotion.model.dto.user.UserInfoQueryRequest;
import com.greenorange.promotion.model.dto.user.UserInfoUpdateRequest;
import com.greenorange.promotion.model.entity.UserInfo;
import com.greenorange.promotion.model.vo.user.UserInfoVO;
import com.greenorange.promotion.service.common.CommonService;
import com.greenorange.promotion.service.user.UserInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* 用户表 控制器
*/
@RestController
@RequestMapping("userInfo")
@Slf4j
@Tag(name = "用户表管理")
public class UserInfoController {
@Resource
private UserInfoService userInfoService;
@Resource
private CommonService commonService;
// /**
// * web端管理员登录
// * @param userInfoAddRequest 用户表添加请求体
// * @return 是否添加成功
// */
// @PostMapping("add")
// @Operation(summary = "web端管理员添加用户表", description = "参数用户表添加请求体权限管理员boss, admin)方法名addUserInfo")
// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
// public BaseResponse<Boolean> addUserInfo(@RequestBody UserInfoAddRequest userInfoAddRequest) {
// ThrowUtils.throwIf(userInfoAddRequest == null, ErrorCode.PARAMS_ERROR);
// UserInfo userInfo = commonService.copyProperties(userInfoAddRequest, UserInfo.class);
// userInfoService.save(userInfo);
// return ResultUtils.success(true);
// }
/**
* web端管理员添加用户表
* @param userInfoAddRequest 用户表添加请求体
* @return 是否添加成功
*/
@PostMapping("add")
@Operation(summary = "web端管理员添加用户表", description = "参数用户表添加请求体权限管理员boss, admin)方法名addUserInfo")
public BaseResponse<Boolean> addUserInfo(@RequestBody UserInfoAddRequest userInfoAddRequest) {
ThrowUtils.throwIf(userInfoAddRequest == null, ErrorCode.PARAMS_ERROR);
UserInfo userInfo = commonService.copyProperties(userInfoAddRequest, UserInfo.class);
userInfoService.save(userInfo);
return ResultUtils.success(true);
}
/**
* web端管理员更新用户表
* @param userInfoUpdateRequest 用户表更新请求体
* @return 是否更新成功
*/
@PostMapping("update")
@Operation(summary = "web端管理员更新用户表", description = "参数用户表更新请求体权限管理员boss, admin)方法名updateUserInfo")
public BaseResponse<Boolean> updateUserInfo(@RequestBody UserInfoUpdateRequest userInfoUpdateRequest) {
ThrowUtils.throwIf(userInfoUpdateRequest == null || userInfoUpdateRequest.getId() <= 0, ErrorCode.PARAMS_ERROR);
UserInfo userInfo = commonService.copyProperties(userInfoUpdateRequest, UserInfo.class);
userInfoService.updateById(userInfo);
return ResultUtils.success(true);
}
/**
* web端管理员删除用户表
* @param commonRequest 用户表删除请求体
* @return 是否删除成功
*/
@PostMapping("delete")
@Operation(summary = "web端管理员删除用户表", description = "参数用户表删除请求体权限管理员boss, admin)方法名delUserInfo")
public BaseResponse<Boolean> delUserInfo(@RequestBody CommonRequest commonRequest) {
ThrowUtils.throwIf(commonRequest == null || commonRequest.getId() <= 0, ErrorCode.PARAMS_ERROR);
Long id = commonRequest.getId();
userInfoService.removeById(id);
return ResultUtils.success(true);
}
/**
* Web端管理员分页查看用户表
* @param userInfoQueryRequest 用户表查询请求体
* @return 用户表列表
*/
@PostMapping("page")
@Operation(summary = "Web端管理员分页查看用户表", description = "参数用户表查询请求体权限管理员boss, admin),方法名:listUserInfoByPage")
public BaseResponse<Page<UserInfoVO>> listUserInfoByPage(@RequestBody UserInfoQueryRequest userInfoQueryRequest) {
if (userInfoQueryRequest == null) throw new BusinessException(ErrorCode.PARAMS_ERROR);
long current = userInfoQueryRequest.getCurrent();
long pageSize = userInfoQueryRequest.getPageSize();
QueryWrapper<UserInfo> queryWrapper = userInfoService.getQueryWrapper(userInfoQueryRequest);
Page<UserInfo> page = userInfoService.page(new Page<>(current, pageSize), queryWrapper);
List<UserInfo> userInfoList = page.getRecords();
List<UserInfoVO> userInfoVOList = commonService.convertList(userInfoList, UserInfoVO.class);
Page<UserInfoVO> voPage = new Page<>();
voPage.setRecords(userInfoVOList);
voPage.setPages(page.getPages());
voPage.setCurrent(page.getCurrent());
voPage.setTotal(page.getTotal());
voPage.setSize(page.getSize());
return ResultUtils.success(voPage);
}
/**
* web端管理员根据id查询用户表
* @param commonRequest 用户表查询请求体
* @return 用户表信息
*/
@PostMapping("queryById")
@Operation(summary = "web端管理员根据id查询用户表", description = "参数用户表查询请求体权限管理员boss, admin),方法名:queryUserInfoById")
public BaseResponse<UserInfoVO> queryUserInfoById(@RequestBody CommonRequest commonRequest) {
ThrowUtils.throwIf(commonRequest == null || commonRequest.getId() <= 0, ErrorCode.PARAMS_ERROR);
Long id = commonRequest.getId();
UserInfo userInfo = userInfoService.getById(id);
ThrowUtils.throwIf(userInfo == null, ErrorCode.OPERATION_ERROR, "当前用户不存在");
UserInfoVO userInfoVO = commonService.copyProperties(userInfo, UserInfoVO.class);
return ResultUtils.success(userInfoVO);
}
/**
* web端管理员批量删除用户表
* @param commonBatchRequest 用户表批量删除请求体
* @return 是否删除成功
*/
@PostMapping("delBatch")
@Operation(summary = "web端管理员批量删除用户表", description = "参数用户表批量删除请求体权限管理员boss, admin),方法名:delBatchUserInfo")
public BaseResponse<Boolean> delBatchUserInfo(@RequestBody CommonBatchRequest commonBatchRequest) {
ThrowUtils.throwIf(commonBatchRequest == null || commonBatchRequest.getIds() == null || commonBatchRequest.getIds().isEmpty(), ErrorCode.PARAMS_ERROR);
List<Long> ids = commonBatchRequest.getIds();
userInfoService.removeByIds(ids);
return ResultUtils.success(true);
}
}

View File

@ -0,0 +1,67 @@
package com.greenorange.promotion.model.dto.user;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
* 用户表添加请求体
*/
@Data
@Schema(description = "用户表添加请求体", requiredProperties = {"name", "categoryId", "price", "image", "period", "isShelves"})
public class UserInfoAddRequest implements Serializable {
/**
* 用户昵称
*/
@Schema(description = "用户昵称", example = "${field.example}")
private String nickName;
/**
* 用户头像URL
*/
@Schema(description = "用户头像URL", example = "${field.example}")
private String userAvatar;
/**
* 手机号
*/
@Schema(description = "手机号", example = "${field.example}")
private String phoneNumber;
/**
* 密码建议加密存储
*/
@Schema(description = "密码(建议加密存储)", example = "${field.example}")
private String userPassword;
/**
* 邀请码
*/
@Schema(description = "邀请码", example = "${field.example}")
private String invitationCode;
/**
* 用户角色
*/
@Schema(description = "用户角色", example = "${field.example}")
private String userRole;
/**
* 上级用户id
*/
@Schema(description = "上级用户id", example = "${field.example}")
private Long parentUserId;
/**
* 上级用户列表1,2,3
*/
@Schema(description = "上级用户列表1,2,3", example = "${field.example}")
private String superUserList;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,73 @@
package com.greenorange.promotion.model.dto.user;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import com.greenorange.promotion.common.PageRequest;
/**
* 用户表查询请求体继承自分页请求 PageRequest
*/
@Data
@Schema(description = "用户表查询请求体", requiredProperties = {"current", "pageSize"})
public class UserInfoQueryRequest extends PageRequest implements Serializable {
/**
* 用户表 ID
*/
@Schema(description = "用户表 ID", example = "1")
private Long id;
/**
* 用户昵称
*/
@Schema(description = "用户昵称", example = "${field.example}")
private String nickName;
/**
* 用户头像URL
*/
@Schema(description = "用户头像URL", example = "${field.example}")
private String userAvatar;
/**
* 手机号
*/
@Schema(description = "手机号", example = "${field.example}")
private String phoneNumber;
/**
* 密码建议加密存储
*/
@Schema(description = "密码(建议加密存储)", example = "${field.example}")
private String userPassword;
/**
* 邀请码
*/
@Schema(description = "邀请码", example = "${field.example}")
private String invitationCode;
/**
* 用户角色
*/
@Schema(description = "用户角色", example = "${field.example}")
private String userRole;
/**
* 上级用户id
*/
@Schema(description = "上级用户id", example = "${field.example}")
private Long parentUserId;
/**
* 上级用户列表1,2,3
*/
@Schema(description = "上级用户列表1,2,3", example = "${field.example}")
private String superUserList;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,73 @@
package com.greenorange.promotion.model.dto.user;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
* 用户表更新请求体
*/
@Data
@Schema(description = "用户表更新请求体", requiredProperties = {"id", "name", "categoryId", "price", "image", "period", "isShelves"})
public class UserInfoUpdateRequest implements Serializable {
/**
* 用户表 ID
*/
@Schema(description = "用户表 ID", example = "1")
private Long id;
/**
* 用户昵称
*/
@Schema(description = "用户昵称", example = "${field.example}")
private String nickName;
/**
* 用户头像URL
*/
@Schema(description = "用户头像URL", example = "${field.example}")
private String userAvatar;
/**
* 手机号
*/
@Schema(description = "手机号", example = "${field.example}")
private String phoneNumber;
/**
* 密码建议加密存储
*/
@Schema(description = "密码(建议加密存储)", example = "${field.example}")
private String userPassword;
/**
* 邀请码
*/
@Schema(description = "邀请码", example = "${field.example}")
private String invitationCode;
/**
* 用户角色
*/
@Schema(description = "用户角色", example = "${field.example}")
private String userRole;
/**
* 上级用户id
*/
@Schema(description = "上级用户id", example = "${field.example}")
private Long parentUserId;
/**
* 上级用户列表1,2,3
*/
@Schema(description = "上级用户列表1,2,3", example = "${field.example}")
private String superUserList;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,73 @@
package com.greenorange.promotion.model.vo.user;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
* 用户表 视图对象
*/
@Data
@Schema(description = "用户表 视图对象")
public class UserInfoVO implements Serializable {
/**
* 用户表 ID
*/
@Schema(description = "用户表 ID", example = "1")
private Long id;
/**
* 用户昵称
*/
@Schema(description = "用户昵称", example = "${field.example}")
private String nickName;
/**
* 用户头像URL
*/
@Schema(description = "用户头像URL", example = "${field.example}")
private String userAvatar;
/**
* 手机号
*/
@Schema(description = "手机号", example = "${field.example}")
private String phoneNumber;
/**
* 密码建议加密存储
*/
@Schema(description = "密码(建议加密存储)", example = "${field.example}")
private String userPassword;
/**
* 邀请码
*/
@Schema(description = "邀请码", example = "${field.example}")
private String invitationCode;
/**
* 用户角色
*/
@Schema(description = "用户角色", example = "${field.example}")
private String userRole;
/**
* 上级用户id
*/
@Schema(description = "上级用户id", example = "${field.example}")
private Long parentUserId;
/**
* 上级用户列表1,2,3
*/
@Schema(description = "上级用户列表1,2,3", example = "${field.example}")
private String superUserList;
@Serial
private static final long serialVersionUID = 1L;
}