更新项目代码:新增彩种模块、组件优化、管理后台功能完善

This commit is contained in:
lihanqi
2026-02-13 17:43:41 +08:00
parent d395295aa0
commit 3d7358079a
146 changed files with 48171 additions and 8804 deletions

View File

@@ -1,119 +1,482 @@
package com.xy.xyaicpzs.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xy.xyaicpzs.common.DeleteRequest;
import com.xy.xyaicpzs.common.ErrorCode;
import com.xy.xyaicpzs.common.ResultUtils;
import com.xy.xyaicpzs.common.response.ApiResponse;
import com.xy.xyaicpzs.domain.dto.user.*;
import com.xy.xyaicpzs.domain.entity.User;
import com.xy.xyaicpzs.domain.vo.UserVO;
import com.xy.xyaicpzs.exception.BusinessException;
import com.xy.xyaicpzs.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.stream.Collectors;
/**
* 用户接口
*/
@Slf4j
@RestController
@RequestMapping("/user")
@Tag(name = "用户管理", description = "用户管理相关接口")
public class UserController {
@Resource
private UserService userService;
// region 登录相关
/**
* 用户注册
*
* @param userRegisterRequest
* @return
/**
* 管理员获取所有双色球推测记录支持分页和用户ID筛选
* @param userId 用户ID可选
* @param current 当前页码默认为1
* @param pageSize 每页大小默认为10
* @param request HTTP请求
* @return 分页的双色球预测记录
*/
@PostMapping("/register")
@Operation(summary = "用户注册", description = "用户注册接口")
public ApiResponse<Long> userRegister(@RequestBody UserRegisterRequest userRegisterRequest) {
if (userRegisterRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
@GetMapping("/admin/all-records")
@Operation(summary = "管理员获取所有推测记录", description = "管理员获取所有双色球推测记录支持分页和根据用户ID、中奖等级筛选")
public ApiResponse<PageResponse<PredictRecord>> getAllRecordsForAdmin(
@Parameter(description = "用户ID可选用于筛选指定用户的记录")
@RequestParam(value = "userId", required = false) Long userId,
@Parameter(description = "中奖等级(可选),例如:一等奖、二等奖、未中奖")
@RequestParam(value = "predictResult", required = false) String predictResult,
@Parameter(description = "当前页码从1开始默认为1")
@RequestParam(value = "current", defaultValue = "1") Integer current,
@Parameter(description = "每页大小默认为10")
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
HttpServletRequest request) {
// 验证管理员权限
User loginUser = userService.getLoginUser(request);
if (loginUser == null) {
return ResultUtils.error(ErrorCode.NOT_LOGIN_ERROR, "用户未登录");
}
String userAccount = userRegisterRequest.getUserAccount();
String userPassword = userRegisterRequest.getUserPassword();
String checkPassword = userRegisterRequest.getCheckPassword();
if (StringUtils.isAnyBlank(userAccount, userPassword, checkPassword)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
if (!userService.isAdmin(loginUser)) {
return ResultUtils.error(ErrorCode.NO_AUTH_ERROR, "无权限访问,仅管理员可用");
}
try {
log.info("管理员获取所有双色球推测记录userId={}predictResult={}current={}pageSize={}",
userId, predictResult, current, pageSize);
// 调用Service层方法
PageResponse<PredictRecord> result = predictRecordService.getAllRecordsForAdmin(userId, predictResult, current, pageSize);
log.info("管理员获取双色球推测记录完成,总记录数:{}", result.getTotal());
return ResultUtils.success(result);
} catch (Exception e) {
log.error("管理员获取双色球推测记录失败:{}", e.getMessage(), e);
return ResultUtils.error(ErrorCode.SYSTEM_ERROR, "获取推测记录失败:" + e.getMessage());
}
long result = userService.userRegister(userAccount, userPassword, checkPassword);
return ResultUtils.success(result);
}
/**
* 用户登录
*
* @param userLoginRequest
* @param request
* @return
*/
@PostMapping("/login")
@Operation(summary = "用户登录", description = "用户登录接口")
public ApiResponse<UserVO> userLogin(@RequestBody UserLoginRequest userLoginRequest, HttpServletRequest request) {
if (userLoginRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
GET http://localhost:8123/api/ball-analysis/admin/all-records?
userId={{$random.integer(100)}}&
predictResult={{$random.alphanumeric(8)}}&
current={{$random.integer(100)}}&
pageSize={{$random.integer(100)}}
响应示例
{
"code": 0,
"success": true,
"message": "操作成功",
"data": {
"records": [
{
"id": 57,
"userId": 1,
"drawId": 2025096,
"drawDate": 1759766400000,
"redBall1": 25,
"redBall2": 17,
"redBall3": 18,
"redBall4": 15,
"redBall5": 21,
"redBall6": 29,
"blueBall": 11,
"predictStatus": "未中奖",
"predictResult": "未中奖",
"predictTime": 1759824079000,
"bonus": 0,
"type": "ssq"
},
{
"id": 56,
"userId": 1,
"drawId": 2025096,
"drawDate": 1759766400000,
"redBall1": 13,
"redBall2": 18,
"redBall3": 2,
"redBall4": 4,
"redBall5": 5,
"redBall6": 1,
"blueBall": 10,
"predictStatus": "未中奖",
"predictResult": "未中奖",
"predictTime": 1759818889000,
"bonus": 0,
"type": "ssq"
},
{
"id": 55,
"userId": 1,
"drawId": 2025096,
"drawDate": 1758384000000,
"redBall1": 22,
"redBall2": 33,
"redBall3": 24,
"redBall4": 25,
"redBall5": 20,
"redBall6": 15,
"blueBall": 14,
"predictStatus": "未中奖",
"predictResult": "未中奖",
"predictTime": 1758427874000,
"bonus": 0,
"type": "ssq"
},
{
"id": 54,
"userId": 1,
"drawId": 2025096,
"drawDate": 1758384000000,
"redBall1": 23,
"redBall2": 25,
"redBall3": 33,
"redBall4": 29,
"redBall5": 24,
"redBall6": 20,
"blueBall": 15,
"predictStatus": "已中奖",
"predictResult": "六等奖",
"predictTime": 1758427335000,
"bonus": 5,
"type": "ssq"
},
{
"id": 53,
"userId": 1,
"drawId": 2025096,
"drawDate": 1758384000000,
"redBall1": 22,
"redBall2": 27,
"redBall3": 29,
"redBall4": 24,
"redBall5": 30,
"redBall6": 25,
"blueBall": 14,
"predictStatus": "未中奖",
"predictResult": "未中奖",
"predictTime": 1758427265000,
"bonus": 0,
"type": "ssq"
},
{
"id": 52,
"userId": 1,
"drawId": 2025096,
"drawDate": 1758384000000,
"redBall1": 18,
"redBall2": 27,
"redBall3": 32,
"redBall4": 30,
"redBall5": 29,
"redBall6": 28,
"blueBall": 15,
"predictStatus": "已中奖",
"predictResult": "六等奖",
"predictTime": 1758426942000,
"bonus": 5,
"type": "ssq"
},
{
"id": 51,
"userId": 1,
"drawId": 2025096,
"drawDate": 1758384000000,
"redBall1": 26,
"redBall2": 18,
"redBall3": 23,
"redBall4": 19,
"redBall5": 20,
"redBall6": 25,
"blueBall": 14,
"predictStatus": "未中奖",
"predictResult": "未中奖",
"predictTime": 1758426099000,
"bonus": 0,
"type": "ssq"
},
{
"id": 50,
"userId": 1,
"drawId": 2025096,
"drawDate": 1757520000000,
"redBall1": 22,
"redBall2": 18,
"redBall3": 19,
"redBall4": 23,
"redBall5": 20,
"redBall6": 15,
"blueBall": 13,
"predictStatus": "未中奖",
"predictResult": "未中奖",
"predictTime": 1757597385000,
"bonus": 0,
"type": "ssq"
},
{
"id": 49,
"userId": 1,
"drawId": 2025096,
"drawDate": 1757260800000,
"redBall1": 14,
"redBall2": 20,
"redBall3": 18,
"redBall4": 27,
"redBall5": 33,
"redBall6": 13,
"blueBall": 15,
"predictStatus": "已中奖",
"predictResult": "六等奖",
"predictTime": 1757312366000,
"bonus": 5,
"type": "ssq"
},
{
"id": 48,
"userId": 1,
"drawId": 2025095,
"drawDate": 1756828800000,
"redBall1": 17,
"redBall2": 22,
"redBall3": 27,
"redBall4": 16,
"redBall5": 6,
"redBall6": 7,
"blueBall": 4,
"predictStatus": "未中奖",
"predictResult": "未中奖",
"predictTime": 1756882722000,
"bonus": 0,
"type": "ssq"
}
],
"total": 35,
"page": 1,
"size": 10,
"totalPages": 4,
"hasNext": true,
"hasPrevious": false
}
}
@GetMapping("/admin/all-records")
@Operation(summary = "管理员获取所有推测记录", description = "管理员获取所有大乐透推测记录支持分页和根据用户ID、中奖等级筛选")
public ApiResponse<PageResponse<DltPredictRecord>> getAllRecordsForAdmin(
@Parameter(description = "用户ID可选用于筛选指定用户的记录")
@RequestParam(value = "userId", required = false) Long userId,
@Parameter(description = "中奖等级(可选),例如:一等奖、二等奖、未中奖")
@RequestParam(value = "predictResult", required = false) String predictResult,
@Parameter(description = "当前页码从1开始默认为1")
@RequestParam(value = "current", defaultValue = "1") Integer current,
@Parameter(description = "每页大小默认为10")
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
HttpServletRequest request) {
// 验证管理员权限
User loginUser = userService.getLoginUser(request);
if (loginUser == null) {
return ResultUtils.error(ErrorCode.NOT_LOGIN_ERROR, "用户未登录");
}
String userAccount = userLoginRequest.getUserAccount();
String userPassword = userLoginRequest.getUserPassword();
if (StringUtils.isAnyBlank(userAccount, userPassword)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
if (!userService.isAdmin(loginUser)) {
return ResultUtils.error(ErrorCode.NO_AUTH_ERROR, "无权限访问,仅管理员可用");
}
try {
log.info("管理员获取所有大乐透推测记录userId={}predictResult={}current={}pageSize={}",
userId, predictResult, current, pageSize);
// 调用Service层方法
PageResponse<DltPredictRecord> result = dltPredictRecordService.getAllRecordsForAdmin(userId, predictResult, current, pageSize);
log.info("管理员获取大乐透推测记录完成,总记录数:{}", result.getTotal());
return ResultUtils.success(result);
} catch (Exception e) {
log.error("管理员获取大乐透推测记录失败:{}", e.getMessage(), e);
return ResultUtils.error(ErrorCode.SYSTEM_ERROR, "获取推测记录失败:" + e.getMessage());
}
User user = userService.userLogin(userAccount, userPassword, request);
UserVO userVO = new UserVO();
BeanUtils.copyProperties(user, userVO);
return ResultUtils.success(userVO);
}
/**
* 用户注销
*
* @param request
* @return
*/
@PostMapping("/logout")
@Operation(summary = "用户注销", description = "用户注销接口")
public ApiResponse<Boolean> userLogout(HttpServletRequest request) {
if (request == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
boolean result = userService.userLogout(request);
return ResultUtils.success(result);
}
GET http://localhost:8123/api/dlt-predict/admin/all-records?
userId={{$random.integer(100)}}&
predictResult={{$random.alphanumeric(8)}}&
current={{$random.integer(100)}}&
pageSize={{$random.integer(100)}}
/**
* 获取当前登录用户
*
* @param request
* @return
*/
@GetMapping("/get/login")
@Operation(summary = "获取当前登录用户", description = "获取当前登录用户信息")
public ApiResponse<UserVO> getLoginUser(HttpServletRequest request) {
User user = userService.getLoginUser(request);
UserVO userVO = new UserVO();
BeanUtils.copyProperties(user, userVO);
return ResultUtils.success(userVO);
}
// endregion
}
{
"code": 0,
"success": true,
"message": "操作成功",
"data": {
"records": [
{
"id": 23,
"userId": 1,
"drawId": 25117,
"drawDate": null,
"frontendBall1": 16,
"frontendBall2": 13,
"frontendBall3": 14,
"frontendBall4": 9,
"frontendBall5": 4,
"backendBall1": 2,
"backendBall2": 5,
"predictStatus": "待开奖",
"predictResult": "待开奖",
"predictTime": 1763967816000,
"bonus": 0
},
{
"id": 22,
"userId": 1,
"drawId": 25106,
"drawDate": null,
"frontendBall1": 10,
"frontendBall2": 32,
"frontendBall3": 33,
"frontendBall4": 35,
"frontendBall5": 1,
"backendBall1": 6,
"backendBall2": 8,
"predictStatus": "未中奖",
"predictResult": "未中奖",
"predictTime": 1759909486000,
"bonus": 0
},
{
"id": 21,
"userId": 1,
"drawId": 25106,
"drawDate": null,
"frontendBall1": 11,
"frontendBall2": 22,
"frontendBall3": 25,
"frontendBall4": 28,
"frontendBall5": 29,
"backendBall1": 11,
"backendBall2": 12,
"predictStatus": "未中奖",
"predictResult": "未中奖",
"predictTime": 1759909424000,
"bonus": 0
},
{
"id": 20,
"userId": 1,
"drawId": 25106,
"drawDate": null,
"frontendBall1": 5,
"frontendBall2": 22,
"frontendBall3": 28,
"frontendBall4": 30,
"frontendBall5": 35,
"backendBall1": 7,
"backendBall2": 3,
"predictStatus": "未中奖",
"predictResult": "未中奖",
"predictTime": 1759909344000,
"bonus": 0
},
{
"id": 19,
"userId": 1,
"drawId": 25109,
"drawDate": null,
"frontendBall1": 5,
"frontendBall2": 28,
"frontendBall3": 18,
"frontendBall4": 32,
"frontendBall5": 22,
"backendBall1": 9,
"backendBall2": 12,
"predictStatus": "未中奖",
"predictResult": "未中奖",
"predictTime": 1758511498000,
"bonus": 0
},
{
"id": 18,
"userId": 1,
"drawId": 25109,
"drawDate": null,
"frontendBall1": 3,
"frontendBall2": 11,
"frontendBall3": 23,
"frontendBall4": 29,
"frontendBall5": 34,
"backendBall1": 2,
"backendBall2": 7,
"predictStatus": "未中奖",
"predictResult": "未中奖",
"predictTime": 1758510538000,
"bonus": 0
},
{
"id": 17,
"userId": 1,
"drawId": 25109,
"drawDate": null,
"frontendBall1": 32,
"frontendBall2": 1,
"frontendBall3": 2,
"frontendBall4": 5,
"frontendBall5": 23,
"backendBall1": 3,
"backendBall2": 7,
"predictStatus": "未中奖",
"predictResult": "未中奖",
"predictTime": 1758510155000,
"bonus": 0
},
{
"id": 16,
"userId": 1,
"drawId": 25109,
"drawDate": null,
"frontendBall1": 19,
"frontendBall2": 12,
"frontendBall3": 2,
"frontendBall4": 33,
"frontendBall5": 22,
"backendBall1": 1,
"backendBall2": 7,
"predictStatus": "未中奖",
"predictResult": "未中奖",
"predictTime": 1758509942000,
"bonus": 0
},
{
"id": 15,
"userId": 1,
"drawId": 25109,
"drawDate": null,
"frontendBall1": 29,
"frontendBall2": 20,
"frontendBall3": 22,
"frontendBall4": 32,
"frontendBall5": 35,
"backendBall1": 10,
"backendBall2": 2,
"predictStatus": "未中奖",
"predictResult": "未中奖",
"predictTime": 1758509591000,
"bonus": 0
},
{
"id": 14,
"userId": 1,
"drawId": 25109,
"drawDate": null,
"frontendBall1": 14,
"frontendBall2": 28,
"frontendBall3": 30,
"frontendBall4": 2,
"frontendBall5": 20,
"backendBall1": 2,
"backendBall2": 3,
"predictStatus": "未中奖",
"predictResult": "未中奖",
"predictTime": 1758509292000,
"bonus": 0
}
],
"total": 14,
"page": 1,
"size": 10,
"totalPages": 2,
"hasNext": true,
"hasPrevious": false
}
}