# game **Repository Path**: wang_ai_xiaolan/game ## Basic Information - **Project Name**: game - **Description**: 下单后端,一个未完成的项目 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-03-03 - **Last Updated**: 2025-03-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 巡航游戏平台项目 ## 项目结构 ``` game ├── src │ ├── main │ │ ├── java │ │ │ └── com │ │ │ └── cruise │ │ │ └── game │ │ │ ├── common │ │ │ ├── controller │ │ │ ├── mapper │ │ │ ├── model │ │ │ ├── security │ │ │ ├── service │ │ │ └── CruiseGameApplication.java │ │ └── resources │ │ ├── mapper │ │ ├── application.yml │ │ ├── application-dev.yml │ │ ├── application-prod.yml │ │ └── logback-spring.xml │ └── test ├── logs ├── target ├── .idea ├── .git ├── application.yml ├── logback-spring.xml ├── pom.xml ├── Dockerfile ├── .gitignore ├── HELP.md └── enhanced-api-design.md ``` ## Controller文件目录 ### 基础Controller 以下是基础Controller文件: 1. `src/main/java/com/cruise/game/controller/BaseController.java` package com.cruise.game.controller; import com.cruise.game.common.api.ApiException; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.RestController; /** * 基础控制器 * * @author cruise * @date 2025-02-28 */ @RestController public class BaseController { /** * 获取当前用户ID * * @return 用户ID */ protected Long getCurrentUserId() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null && authentication.isAuthenticated() && authentication.getPrincipal() != null) { return (Long) authentication.getPrincipal(); } throw new ApiException("用户未登录"); } /** * 获取当前认证信息 * * @return 认证信息 */ protected Authentication getCurrentAuthentication() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null && authentication.isAuthenticated()) { return authentication; } throw new ApiException("用户未登录"); } /** * 获取当前用户角色 * * @return 用户角色 */ protected String getCurrentUserRole() { Authentication authentication = getCurrentAuthentication(); return authentication.getAuthorities().stream() .findFirst() .map(authority -> authority.getAuthority().replace("ROLE_", "")) .orElse(null); } /** * 验证当前用户是否是管理员 * * @return 是否是管理员 */ protected boolean isAdmin() { String role = getCurrentUserRole(); return "admin".equals(role); } /** * 验证当前用户是否是代理 * * @return 是否是代理 */ protected boolean isAgent() { String role = getCurrentUserRole(); return "agent".equals(role) || "admin".equals(role); } } ### 用户相关Controller 以下是 `src/main/java/com/cruise/game/controller/user` 目录下的Controller文件: 1. `UserController.java` package com.cruise.game.controller.user; import com.cruise.game.common.api.ApiResult; import com.cruise.game.controller.BaseController; import com.cruise.game.model.param.user.AgentApplicationParam; import com.cruise.game.model.param.user.RechargeParam; import com.cruise.game.model.param.user.UpdateProfileParam; import com.cruise.game.model.param.user.WithdrawParam; import com.cruise.game.model.vo.user.UserProfileVO; import com.cruise.game.service.user.UserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.HashMap; import java.util.Map; /** * 用户控制器 * * @author cruise * @date 2025-02-28 */ @Slf4j @Api(tags = "用户相关接口") @RestController @RequestMapping("/api/user") public class UserController extends BaseController { @Resource private UserService userService; /** * 获取用户个人信息 */ @ApiOperation("获取用户个人信息") @GetMapping("/profile") public ApiResult getUserProfile() { return ApiResult.success(userService.getUserProfile(getCurrentUserId())); } /** * 更新用户个人信息 */ @ApiOperation("更新用户个人信息") @PutMapping("/profile") public ApiResult updateUserProfile(@RequestBody UpdateProfileParam param) { return ApiResult.success("更新成功", userService.updateUserProfile(getCurrentUserId(), param)); } /** * 申请成为打手 */ @ApiOperation("申请成为打手") @PostMapping("/apply-agent") public ApiResult> applyAgent(@Validated @RequestBody AgentApplicationParam param) { Long applicationId = userService.applyAgent(getCurrentUserId(), param); Map result = new HashMap<>(); result.put("applicationId", applicationId); return ApiResult.success("申请已提交,等待审核", result); } /** * 余额充值 */ @ApiOperation("余额充值") @PostMapping("/recharge") public ApiResult> recharge(@Validated @RequestBody RechargeParam param) { UserService.PaymentInfoVO paymentInfo = userService.recharge(getCurrentUserId(), param); Map result = new HashMap<>(); Map paymentInfoMap = new HashMap<>(); paymentInfoMap.put("appId", paymentInfo.getAppId()); paymentInfoMap.put("timeStamp", paymentInfo.getTimeStamp()); paymentInfoMap.put("nonceStr", paymentInfo.getNonceStr()); paymentInfoMap.put("package", paymentInfo.getPackageValue()); paymentInfoMap.put("signType", paymentInfo.getSignType()); paymentInfoMap.put("paySign", paymentInfo.getPaySign()); result.put("paymentInfo", paymentInfoMap); return ApiResult.success("充值请求已提交", result); } /** * 申请提现 */ @ApiOperation("申请提现") @PostMapping("/withdraw") public ApiResult> withdraw(@Validated @RequestBody WithdrawParam param) { Long applicationId = userService.withdraw(getCurrentUserId(), param); Map result = new HashMap<>(); result.put("applicationId", applicationId); return ApiResult.success("提现申请已提交", result); } } 2. `FavoriteController.java` package com.cruise.game.controller.user; import com.cruise.game.common.api.ApiResult; import com.cruise.game.common.constants.CommonConstants; import com.cruise.game.controller.BaseController; import com.cruise.game.model.vo.common.PageResult; import com.cruise.game.model.vo.user.FavoriteVO; import com.cruise.game.service.user.FavoriteService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.HashMap; import java.util.Map; /** * 收藏控制器 * * @author cruise * @date 2025-02-28 */ @Slf4j @Api(tags = "收藏相关接口") @RestController @RequestMapping("/api/user/favorites") public class FavoriteController extends BaseController { @Resource private FavoriteService favoriteService; /** * 添加收藏 */ @ApiOperation("添加收藏") @PostMapping public ApiResult addFavorite( @ApiParam(value = "服务ID", required = true) @RequestBody Map param) { Long serviceId = param.get("serviceId"); if (serviceId == null) { return ApiResult.paramError("服务ID不能为空"); } return ApiResult.success("收藏成功", favoriteService.addFavorite(getCurrentUserId(), serviceId)); } /** * 取消收藏 */ @ApiOperation("取消收藏") @DeleteMapping("/{serviceId}") public ApiResult cancelFavorite( @ApiParam(value = "服务ID", required = true) @PathVariable("serviceId") Long serviceId) { return ApiResult.success("已取消收藏", favoriteService.cancelFavorite(getCurrentUserId(), serviceId)); } /** * 获取收藏列表 */ @ApiOperation("获取收藏列表") @GetMapping public ApiResult> getFavoriteList( @ApiParam(value = "页码", required = false, defaultValue = "1") @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, @ApiParam(value = "每页条数", required = false, defaultValue = "10") @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) { // 限制最大页面大小 if (pageSize > CommonConstants.MAX_PAGE_SIZE) { pageSize = CommonConstants.MAX_PAGE_SIZE; } return ApiResult.success(favoriteService.getFavoriteList(getCurrentUserId(), page, pageSize)); } /** * 检查是否已收藏 */ @ApiOperation("检查是否已收藏") @GetMapping("/check/{serviceId}") public ApiResult> isFavorite( @ApiParam(value = "服务ID", required = true) @PathVariable("serviceId") Long serviceId) { boolean isFavorite = favoriteService.isFavorite(getCurrentUserId(), serviceId); Map result = new HashMap<>(); result.put("favorite", isFavorite); return ApiResult.success(result); } } 3. `UserTransactionController.java` package com.cruise.game.controller.user; import com.cruise.game.common.api.ApiResult; import com.cruise.game.common.constants.CommonConstants; import com.cruise.game.controller.BaseController; import com.cruise.game.model.vo.common.PageResult; import com.cruise.game.model.vo.user.TransactionVO; import com.cruise.game.model.vo.user.WithdrawalVO; import com.cruise.game.service.user.UserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; /** * 用户交易控制器 * * @author cruise * @date 2025-02-28 */ @Slf4j @Api(tags = "用户交易相关接口") @RestController @RequestMapping("/api/user") public class UserTransactionController extends BaseController { @Resource private UserService userService; /** * 获取交易记录 */ @ApiOperation("获取交易记录") @GetMapping("/transactions") public ApiResult> getTransactions( @ApiParam(value = "交易类型", required = false) @RequestParam(value = "type", required = false) String type, @ApiParam(value = "页码", required = false, defaultValue = "1") @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, @ApiParam(value = "每页条数", required = false, defaultValue = "10") @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) { // 限制最大页面大小 if (pageSize > CommonConstants.MAX_PAGE_SIZE) { pageSize = CommonConstants.MAX_PAGE_SIZE; } return ApiResult.success(userService.getTransactions(getCurrentUserId(), type, page, pageSize)); } /** * 获取提现申请列表 */ @ApiOperation("获取提现申请列表") @GetMapping("/withdrawals") public ApiResult> getWithdrawals( @ApiParam(value = "申请状态", required = false) @RequestParam(value = "status", required = false) String status, @ApiParam(value = "页码", required = false, defaultValue = "1") @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, @ApiParam(value = "每页条数", required = false, defaultValue = "10") @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) { // 限制最大页面大小 if (pageSize > CommonConstants.MAX_PAGE_SIZE) { pageSize = CommonConstants.MAX_PAGE_SIZE; } return ApiResult.success(userService.getWithdrawals(getCurrentUserId(), status, page, pageSize)); } } ### 通用Controller 以下是 `src/main/java/com/cruise/game/controller/common` 目录下的Controller文件: 1. `UploadController.java` package com.cruise.game.controller.common; import com.cruise.game.common.api.ApiResult; import com.cruise.game.controller.BaseController; import com.cruise.game.service.common.UploadService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.util.HashMap; import java.util.Map; /** * 文件上传控制器 * * @author cruise * @date 2025-02-28 */ @Slf4j @Api(tags = "文件上传相关接口") @RestController @RequestMapping("/api/upload") public class UploadController extends BaseController { @Resource private UploadService uploadService; /** * 上传图片 */ @ApiOperation("上传图片") @PostMapping("/image") public ApiResult> uploadImage( @ApiParam(value = "图片文件", required = true) @RequestParam("file") MultipartFile file) { String url = uploadService.uploadImage(file); Map result = new HashMap<>(); result.put("url", url); return ApiResult.success("上传成功", result); } /** * 上传文件 */ @ApiOperation("上传文件") @PostMapping("/file") public ApiResult> uploadFile( @ApiParam(value = "文件", required = true) @RequestParam("file") MultipartFile file, @ApiParam(value = "目录", required = false) @RequestParam(value = "dir", required = false) String dir) { String url = uploadService.uploadFile(file, dir); Map result = new HashMap<>(); result.put("url", url); return ApiResult.success("上传成功", result); } /** * 删除文件 */ @ApiOperation("删除文件") @DeleteMapping("/file") public ApiResult deleteFile( @ApiParam(value = "文件URL", required = true) @RequestParam("url") String fileUrl) { boolean success = uploadService.deleteFile(fileUrl); return success ? ApiResult.success("删除成功", true) : ApiResult.fail("删除失败"); } } 2. `ChatController.java` package com.cruise.game.controller.common; import com.cruise.game.common.api.ApiResult; import com.cruise.game.common.constants.CommonConstants; import com.cruise.game.controller.BaseController; import com.cruise.game.model.vo.chat.ChatMessageVO; import com.cruise.game.model.vo.common.PageResult; import com.cruise.game.service.common.ChatService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.time.LocalDateTime; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 聊天控制器 * * @author cruise * @date 2025-02-28 */ @Slf4j @Api(tags = "聊天相关接口") @RestController @RequestMapping("/api/chat") public class ChatController extends BaseController { @Resource private ChatService chatService; /** * 发送客服消息 */ @ApiOperation("发送客服消息") @PostMapping("/message") public ApiResult> sendMessage( @ApiParam(value = "消息内容", required = true) @RequestParam("message") String message) { Long userId = getCurrentUserId(); // 这里简化处理,实际系统可能会选择一个在线的管理员 Long adminId = 1L; // 假设ID为1的用户是管理员 Long messageId = chatService.sendMessage(userId, adminId, message, true); Map result = new HashMap<>(); result.put("messageId", messageId); return ApiResult.success("消息已发送", result); } /** * 获取客服消息历史 */ @ApiOperation("获取客服消息历史") @GetMapping("/history") public ApiResult> getChatHistory( @ApiParam(value = "页码", required = false, defaultValue = "1") @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, @ApiParam(value = "每页条数", required = false, defaultValue = "20") @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize) { // 限制最大页面大小 if (pageSize > CommonConstants.MAX_PAGE_SIZE) { pageSize = CommonConstants.MAX_PAGE_SIZE; } Long userId = getCurrentUserId(); return ApiResult.success(chatService.getChatHistory(userId, page, pageSize)); } /** * 获取新消息 */ @ApiOperation("获取新消息") @GetMapping("/new-messages") public ApiResult> getNewMessages( @ApiParam(value = "管理员ID", required = true) @RequestParam("adminId") Long adminId, @ApiParam(value = "时间点", required = true) @RequestParam("afterTime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime afterTime) { Long userId = getCurrentUserId(); return ApiResult.success(chatService.getNewMessages(userId, adminId, afterTime)); } /** * 获取未读消息数 */ @ApiOperation("获取未读消息数") @GetMapping("/unread-count") public ApiResult getUnreadMessageCount( @ApiParam(value = "最后读取时间", required = true) @RequestParam("lastReadTime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime lastReadTime) { Long userId = getCurrentUserId(); return ApiResult.success(chatService.getUnreadMessageCount(userId, lastReadTime)); } } 3. `HomeController.java` package com.cruise.game.controller.common; import com.cruise.game.common.api.ApiResult; import com.cruise.game.controller.BaseController; import com.cruise.game.model.vo.common.HomeVO; import com.cruise.game.service.common.HomeService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; /** * 首页控制器 * * @author cruise * @date 2025-02-28 */ @Slf4j @Api(tags = "首页相关接口") @RestController @RequestMapping("/api/home") public class HomeController extends BaseController { @Resource private HomeService homeService; /** * 获取首页数据 */ @ApiOperation("获取首页数据") @GetMapping public ApiResult getHomeData() { return ApiResult.success(homeService.getHomeData()); } } 4. `AuthController.java` package com.cruise.game.controller.common; import com.cruise.game.common.api.ApiResult; import com.cruise.game.common.utils.JwtUtils; import com.cruise.game.controller.BaseController; import com.cruise.game.model.param.common.SetAdminParam; import com.cruise.game.model.param.common.WxLoginParam; import com.cruise.game.model.vo.common.LoginResultVO; import com.cruise.game.model.vo.common.TokenVO; import com.cruise.game.service.common.AuthService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; /** * 认证控制器 * * @author cruise * @date 2025-02-28 */ @Slf4j @Api(tags = "认证相关接口") @RestController @RequestMapping("/api/auth") public class AuthController extends BaseController { @Resource private AuthService authService; @Resource private JwtUtils jwtUtils; /** * 微信登录 */ @ApiOperation("微信登录") @PostMapping("/wx-login") public ApiResult wxLogin(@Validated @RequestBody WxLoginParam param) { log.info("微信登录请求: {}", param.getCode()); return ApiResult.success("登录成功", authService.wxLogin(param)); } /** * 刷新token */ @ApiOperation("刷新token") @PostMapping("/refresh-token") public ApiResult refreshToken(HttpServletRequest request) { String token = jwtUtils.getTokenFromRequest(request); return ApiResult.success("Token已刷新", authService.refreshToken(token)); } /** * 设置为管理员 */ @ApiOperation("设置为管理员") @PostMapping("/set-admin") public ApiResult setAdmin(@Validated @RequestBody SetAdminParam param) { return ApiResult.success("设置管理员成功", authService.setAdmin(param, getCurrentUserId())); } } ### 代理相关Controller 以下是 `src/main/java/com/cruise/game/controller/agent` 目录下的Controller文件: 1. `AgentWithdrawalController.java` package com.cruise.game.controller.agent; import com.cruise.game.common.api.ApiResult; import com.cruise.game.common.constants.CommonConstants; import com.cruise.game.controller.BaseController; import com.cruise.game.model.param.user.WithdrawParam; import com.cruise.game.model.vo.common.PageResult; import com.cruise.game.model.vo.user.WithdrawalVO; import com.cruise.game.service.agent.AgentWithdrawalService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; /** * 代理提现控制器 * * @author cruise * @date 2025-02-28 */ @Slf4j @Api(tags = "代理提现相关接口") @RestController @RequestMapping("/api/agent/withdraw") @PreAuthorize("hasRole('ROLE_AGENT')") public class AgentWithdrawalController extends BaseController { @Resource private AgentWithdrawalService agentWithdrawalService; /** * 提交提现申请 */ @ApiOperation("提交提现申请") @PostMapping public ApiResult submitWithdrawalApplication( @ApiParam(value = "提现信息", required = true) @Validated @RequestBody WithdrawParam param) { Long userId = getCurrentUserId(); Long withdrawalId = agentWithdrawalService.submitWithdrawalApplication(userId, param); return ApiResult.success("提现申请已提交", withdrawalId); } /** * 获取提现申请列表 */ @ApiOperation("获取提现申请列表") @GetMapping public ApiResult> getWithdrawalList( @ApiParam(value = "申请状态", required = false) @RequestParam(value = "status", required = false) String status, @ApiParam(value = "页码", required = false, defaultValue = "1") @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, @ApiParam(value = "每页条数", required = false, defaultValue = "10") @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) { // 限制最大页面大小 if (pageSize > CommonConstants.MAX_PAGE_SIZE) { pageSize = CommonConstants.MAX_PAGE_SIZE; } Long userId = getCurrentUserId(); return ApiResult.success( agentWithdrawalService.getWithdrawalList(userId, status, page, pageSize) ); } /** * 取消提现申请 */ @ApiOperation("取消提现申请") @PostMapping("/{withdrawalId}/cancel") public ApiResult cancelWithdrawalApplication( @ApiParam(value = "提现申请ID", required = true) @PathVariable("withdrawalId") Long withdrawalId) { Long userId = getCurrentUserId(); return ApiResult.success( "提现申请已取消", agentWithdrawalService.cancelWithdrawalApplication(userId, withdrawalId) ); } /** * 获取提现统计 */ @ApiOperation("获取提现统计") @GetMapping("/statistics") public ApiResult getWithdrawalStatistics() { Long userId = getCurrentUserId(); return ApiResult.success(agentWithdrawalService.getWithdrawalStatistics(userId)); } } 2. `AgentController.java` package com.cruise.game.controller.agent; import com.cruise.game.common.api.ApiResult; import com.cruise.game.common.constants.CommonConstants; import com.cruise.game.controller.BaseController; import com.cruise.game.model.entity.Agent; import com.cruise.game.model.param.agent.AgentStatusUpdateParam; import com.cruise.game.model.param.agent.AgentUpdateParam; import com.cruise.game.model.vo.agent.AgentProfileVO; import com.cruise.game.service.agent.AgentService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; /** * 代理(打手)信息控制器 * * @author cruise * @date 2025-02-28 */ @Slf4j @Api(tags = "代理(打手)信息相关接口") @RestController @RequestMapping("/api/agent") @PreAuthorize("hasRole('ROLE_AGENT')") public class AgentController extends BaseController { @Resource private AgentService agentService; /** * 获取代理个人信息 */ @ApiOperation("获取代理个人信息") @GetMapping("/profile") public ApiResult getAgentProfile() { Long userId = getCurrentUserId(); return ApiResult.success(agentService.getAgentProfile(userId)); } /** * 更新代理信息 */ @ApiOperation("更新代理信息") @PutMapping("/profile") public ApiResult updateAgentProfile( @ApiParam(value = "代理信息", required = true) @Validated @RequestBody AgentUpdateParam param) { Long userId = getCurrentUserId(); return ApiResult.success("信息已更新", agentService.updateAgentProfile(userId, param)); } /** * 更新代理状态 */ @ApiOperation("更新代理状态") @PutMapping("/status") public ApiResult updateAgentStatus( @ApiParam(value = "状态更新", required = true) @Validated @RequestBody AgentStatusUpdateParam param) { Long userId = getCurrentUserId(); agentService.updateAgentStatus(userId, param.getStatus()); return ApiResult.success("状态已更新", param.getStatus()); } /** * 获取代理统计信息 */ @ApiOperation("获取代理统计信息") @GetMapping("/statistics") public ApiResult getAgentStatistics() { Long userId = getCurrentUserId(); return ApiResult.success(agentService.getAgentStatistics(userId)); } } 3. `AgentOrderController.java` package com.cruise.game.controller.agent; import com.cruise.game.common.api.ApiResult; import com.cruise.game.common.constants.CommonConstants; import com.cruise.game.controller.BaseController; import com.cruise.game.model.vo.common.PageResult; import com.cruise.game.model.vo.order.OrderDetailVO; import com.cruise.game.model.vo.order.OrderListVO; import com.cruise.game.service.order.OrderService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.Map; /** * 代理订单控制器 * * @author cruise * @date 2025-02-28 */ @Slf4j @Api(tags = "代理订单相关接口") @RestController @RequestMapping("/api/agent/orders") @PreAuthorize("hasAnyRole('ROLE_AGENT', 'ROLE_ADMIN')") public class AgentOrderController extends BaseController { @Resource private OrderService orderService; /** * 获取待接单列表 */ @ApiOperation("获取待接单列表") @GetMapping("/pending") public ApiResult> getPendingOrders( @ApiParam(value = "游戏分类ID", required = false) @RequestParam(value = "gameCategoryId", required = false) Long gameCategoryId, @ApiParam(value = "页码", required = false, defaultValue = "1") @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, @ApiParam(value = "每页条数", required = false, defaultValue = "10") @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) { // 限制最大页面大小 if (pageSize > CommonConstants.MAX_PAGE_SIZE) { pageSize = CommonConstants.MAX_PAGE_SIZE; } return ApiResult.success(orderService.getPendingOrders(gameCategoryId, page, pageSize)); } /** * 接单 */ @ApiOperation("接单") @PostMapping("/{orderId}/accept") public ApiResult acceptOrder( @ApiParam(value = "订单ID", required = true) @PathVariable("orderId") Long orderId) { return ApiResult.success("已接单", orderService.acceptOrder(orderId, getCurrentUserId())); } /** * 开始服务 */ @ApiOperation("开始服务") @PostMapping("/{orderId}/start") public ApiResult startService( @ApiParam(value = "订单ID", required = true) @PathVariable("orderId") Long orderId) { return ApiResult.success("服务已开始", orderService.startService(orderId, getCurrentUserId())); } /** * 完成服务 */ @ApiOperation("完成服务") @PostMapping("/{orderId}/complete") public ApiResult completeService( @ApiParam(value = "订单ID", required = true) @PathVariable("orderId") Long orderId, @ApiParam(value = "完成截图URL", required = true) @RequestBody Map param) { String completionImageUrl = param.get("completionImageUrl"); return ApiResult.success("已完成服务,等待用户确认", orderService.completeService(orderId, completionImageUrl, getCurrentUserId())); } /** * 获取代理订单列表 */ @ApiOperation("获取代理订单列表") @GetMapping public ApiResult> getAgentOrderList( @ApiParam(value = "订单状态", required = false, defaultValue = "all") @RequestParam(value = "status", required = false, defaultValue = "all") String status, @ApiParam(value = "页码", required = false, defaultValue = "1") @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, @ApiParam(value = "每页条数", required = false, defaultValue = "10") @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) { // 限制最大页面大小 if (pageSize > CommonConstants.MAX_PAGE_SIZE) { pageSize = CommonConstants.MAX_PAGE_SIZE; } return ApiResult.success(orderService.getAgentOrderList(getCurrentUserId(), status, page, pageSize)); } /** * 获取代理订单详情 */ @ApiOperation("获取代理订单详情") @GetMapping("/{orderId}") public ApiResult getAgentOrderDetail( @ApiParam(value = "订单ID", required = true) @PathVariable("orderId") Long orderId) { return ApiResult.success(orderService.getAgentOrderDetail(orderId, getCurrentUserId())); } } ### 游戏相关Controller 以下是 `src/main/java/com/cruise/game/controller/game` 目录下的Controller文件: 1. `ServiceController.java` package com.cruise.game.controller.game; import com.cruise.game.common.api.ApiResult; import com.cruise.game.common.constants.CommonConstants; import com.cruise.game.controller.BaseController; import com.cruise.game.model.param.game.GameServiceCreateParam; import com.cruise.game.model.param.game.GameServiceQueryParam; import com.cruise.game.model.param.game.GameServiceUpdateParam; import com.cruise.game.model.vo.common.PageResult; import com.cruise.game.model.vo.game.GameServiceListVO; import com.cruise.game.model.vo.game.GameServiceVO; import com.cruise.game.service.game.ServiceService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.math.BigDecimal; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 游戏服务控制器 * * @author cruise * @date 2025-02-28 */ @Slf4j @Api(tags = "游戏服务相关接口") @RestController @RequestMapping("/api/game/services") public class ServiceController extends BaseController { @Resource private ServiceService serviceService; /** * 获取游戏服务列表 */ @ApiOperation("获取游戏服务列表") @GetMapping public ApiResult> getServiceList( @ApiParam(value = "分类ID", required = false) @RequestParam(value = "categoryId", required = false) Long categoryId, @ApiParam(value = "关键词", required = false) @RequestParam(value = "keyword", required = false) String keyword, @ApiParam(value = "最低价格", required = false) @RequestParam(value = "minPrice", required = false) BigDecimal minPrice, @ApiParam(value = "最高价格", required = false) @RequestParam(value = "maxPrice", required = false) BigDecimal maxPrice, @ApiParam(value = "是否热门", required = false) @RequestParam(value = "isHot", required = false) Boolean isHot, @ApiParam(value = "是否推荐", required = false) @RequestParam(value = "isRecommended", required = false) Boolean isRecommended, @ApiParam(value = "代理ID", required = false) @RequestParam(value = "agentId", required = false) Long agentId, @ApiParam(value = "排序字段", required = false) @RequestParam(value = "sortBy", required = false) String sortBy, @ApiParam(value = "排序方向", required = false, defaultValue = "asc") @RequestParam(value = "sortOrder", required = false, defaultValue = "asc") String sortOrder, @ApiParam(value = "页码", required = false, defaultValue = "1") @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, @ApiParam(value = "每页条数", required = false, defaultValue = "10") @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) { // 限制最大页面大小 if (pageSize > CommonConstants.MAX_PAGE_SIZE) { pageSize = CommonConstants.MAX_PAGE_SIZE; } // 构建查询参数 GameServiceQueryParam param = new GameServiceQueryParam(); param.setCategoryId(categoryId); param.setKeyword(keyword); param.setMinPrice(minPrice); param.setMaxPrice(maxPrice); param.setIsHot(isHot); param.setIsRecommended(isRecommended); param.setAgentId(agentId); param.setSortBy(sortBy); param.setSortOrder(sortOrder); param.setPage(page); param.setPageSize(pageSize); return ApiResult.success(serviceService.getServiceList(param)); } /** * 获取游戏服务详情 */ @ApiOperation("获取游戏服务详情") @GetMapping("/{serviceId}") public ApiResult getServiceDetail( @ApiParam(value = "服务ID", required = true) @PathVariable("serviceId") Long serviceId) { return ApiResult.success(serviceService.getServiceDetail(serviceId)); } /** * 搜索游戏服务 */ @ApiOperation("搜索游戏服务") @GetMapping("/search") public ApiResult> searchServices( @ApiParam(value = "关键词", required = true) @RequestParam("keyword") String keyword, @ApiParam(value = "页码", required = false, defaultValue = "1") @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, @ApiParam(value = "每页条数", required = false, defaultValue = "10") @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) { // 限制最大页面大小 if (pageSize > CommonConstants.MAX_PAGE_SIZE) { pageSize = CommonConstants.MAX_PAGE_SIZE; } return ApiResult.success(serviceService.searchServices(keyword, page, pageSize)); } /** * 获取热门游戏服务列表 */ @ApiOperation("获取热门游戏服务列表") @GetMapping("/hot") public ApiResult> getHotServiceList( @ApiParam(value = "限制数量", required = false, defaultValue = "10") @RequestParam(value = "limit", required = false, defaultValue = "10") Integer limit) { return ApiResult.success(serviceService.getHotServiceList(limit)); } /** * 获取推荐游戏服务列表 */ @ApiOperation("获取推荐游戏服务列表") @GetMapping("/recommended") public ApiResult> getRecommendedServiceList( @ApiParam(value = "限制数量", required = false, defaultValue = "10") @RequestParam(value = "limit", required = false, defaultValue = "10") Integer limit) { return ApiResult.success(serviceService.getRecommendedServiceList(limit)); } /** * 创建游戏服务 */ @ApiOperation("创建游戏服务") @PostMapping @PreAuthorize("hasAnyRole('ROLE_AGENT', 'ROLE_ADMIN')") public ApiResult> createService(@Validated @RequestBody GameServiceCreateParam param) { Long id = serviceService.createService(param, getCurrentUserId()); Map result = new HashMap<>(); result.put("id", id); return ApiResult.success("创建成功", result); } /** * 更新游戏服务 */ @ApiOperation("更新游戏服务") @PutMapping("/{serviceId}") @PreAuthorize("hasAnyRole('ROLE_AGENT', 'ROLE_ADMIN')") public ApiResult updateService( @ApiParam(value = "服务ID", required = true) @PathVariable("serviceId") Long serviceId, @Validated @RequestBody GameServiceUpdateParam param) { return ApiResult.success("更新成功", serviceService.updateService(serviceId, param, getCurrentUserId())); } /** * 删除游戏服务 */ @ApiOperation("删除游戏服务") @DeleteMapping("/{serviceId}") @PreAuthorize("hasAnyRole('ROLE_AGENT', 'ROLE_ADMIN')") public ApiResult deleteService( @ApiParam(value = "服务ID", required = true) @PathVariable("serviceId") Long serviceId) { return ApiResult.success("删除成功", serviceService.deleteService(serviceId, getCurrentUserId())); } /** * 更新游戏服务状态 */ @ApiOperation("更新游戏服务状态") @PutMapping("/{serviceId}/status") @PreAuthorize("hasAnyRole('ROLE_AGENT', 'ROLE_ADMIN')") public ApiResult updateServiceStatus( @ApiParam(value = "服务ID", required = true) @PathVariable("serviceId") Long serviceId, @ApiParam(value = "状态", required = true) @RequestParam("status") String status) { return ApiResult.success("状态已更新", serviceService.updateServiceStatus(serviceId, status, getCurrentUserId())); } /** * 管理员设置热门游戏服务 */ @ApiOperation("管理员设置热门游戏服务") @PutMapping("/{serviceId}/hot") @PreAuthorize("hasRole('ROLE_ADMIN')") public ApiResult adminSetHotService( @ApiParam(value = "服务ID", required = true) @PathVariable("serviceId") Long serviceId, @ApiParam(value = "是否热门", required = true) @RequestParam("isHot") Boolean isHot) { return ApiResult.success("设置成功", serviceService.adminSetHotService(serviceId, isHot)); } /** * 管理员设置推荐游戏服务 */ @ApiOperation("管理员设置推荐游戏服务") @PutMapping("/{serviceId}/recommended") @PreAuthorize("hasRole('ROLE_ADMIN')") public ApiResult adminSetRecommendedService( @ApiParam(value = "服务ID", required = true) @PathVariable("serviceId") Long serviceId, @ApiParam(value = "是否推荐", required = true) @RequestParam("isRecommended") Boolean isRecommended) { return ApiResult.success("设置成功", serviceService.adminSetRecommendedService(serviceId, isRecommended)); } } 2. `CategoryController.java` package com.cruise.game.controller.game; import com.cruise.game.common.api.ApiResult; import com.cruise.game.controller.BaseController; import com.cruise.game.model.vo.admin.GameCategoryVO; import com.cruise.game.service.admin.AdminCategoryService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.List; import java.util.stream.Collectors; /** * 游戏分类控制器 * * @author cruise * @date 2025-02-28 */ @Slf4j @Api(tags = "游戏分类相关接口") @RestController @RequestMapping("/api/game/categories") public class CategoryController extends BaseController { @Resource private AdminCategoryService adminCategoryService; /** * 获取游戏分类列表 */ @ApiOperation("获取游戏分类列表") @GetMapping public ApiResult> getCategoryList() { // 使用管理员的分类服务,但只需第一页数据,且仅返回活跃状态的分类 return ApiResult.success( adminCategoryService.getCategoryList("active", 1, 100) .getList() .stream() .filter(category -> "active".equals(category.getStatus())) .collect(Collectors.toList()) ); } /** * 获取游戏分类详情 */ @ApiOperation("获取游戏分类详情") @GetMapping("/{id}") public ApiResult getCategoryDetail( @ApiParam(value = "游戏分类ID", required = true) @PathVariable("id") Long id) { return ApiResult.success(adminCategoryService.getCategoryDetail(id)); } } ### 订单相关Controller 以下是 `src/main/java/com/cruise/game/controller/order` 目录下的Controller文件: 1. `OrderController.java` package com.cruise.game.controller.game; import com.cruise.game.common.api.ApiResult; import com.cruise.game.controller.BaseController; import com.cruise.game.model.vo.admin.GameCategoryVO; import com.cruise.game.service.admin.AdminCategoryService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.List; import java.util.stream.Collectors; /** * 游戏分类控制器 * * @author cruise * @date 2025-02-28 */ @Slf4j @Api(tags = "游戏分类相关接口") @RestController @RequestMapping("/api/game/categories") public class CategoryController extends BaseController { @Resource private AdminCategoryService adminCategoryService; /** * 获取游戏分类列表 */ @ApiOperation("获取游戏分类列表") @GetMapping public ApiResult> getCategoryList() { // 使用管理员的分类服务,但只需第一页数据,且仅返回活跃状态的分类 return ApiResult.success( adminCategoryService.getCategoryList("active", 1, 100) .getList() .stream() .filter(category -> "active".equals(category.getStatus())) .collect(Collectors.toList()) ); } /** * 获取游戏分类详情 */ @ApiOperation("获取游戏分类详情") @GetMapping("/{id}") public ApiResult getCategoryDetail( @ApiParam(value = "游戏分类ID", required = true) @PathVariable("id") Long id) { return ApiResult.success(adminCategoryService.getCategoryDetail(id)); } } ### 管理员相关Controller 以下是 `src/main/java/com/cruise/game/controller/admin` 目录下的Controller文件: 1. `AdminWithdrawalController.java` package com.cruise.game.controller.admin; import com.cruise.game.common.api.ApiResult; import com.cruise.game.common.constants.CommonConstants; import com.cruise.game.controller.BaseController; import com.cruise.game.model.vo.common.PageResult; import com.cruise.game.model.vo.user.WithdrawalDetailVO; import com.cruise.game.model.vo.user.WithdrawalVO; import com.cruise.game.service.admin.AdminWithdrawalService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.time.LocalDate; import java.util.Map; /** * 管理员提现控制器 * * @author cruise * @date 2025-02-28 */ @Slf4j @Api(tags = "管理员提现相关接口") @RestController @RequestMapping("/api/admin/withdrawals") @PreAuthorize("hasRole('ROLE_ADMIN')") public class AdminWithdrawalController extends BaseController { @Resource private AdminWithdrawalService adminWithdrawalService; /** * 获取提现申请列表 */ @ApiOperation("获取提现申请列表") @GetMapping public ApiResult> getWithdrawalList( @ApiParam(value = "申请状态", required = false) @RequestParam(value = "status", required = false) String status, @ApiParam(value = "开始日期", required = false) @RequestParam(value = "startDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate, @ApiParam(value = "结束日期", required = false) @RequestParam(value = "endDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate, @ApiParam(value = "页码", required = false, defaultValue = "1") @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, @ApiParam(value = "每页条数", required = false, defaultValue = "10") @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) { // 限制最大页面大小 if (pageSize > CommonConstants.MAX_PAGE_SIZE) { pageSize = CommonConstants.MAX_PAGE_SIZE; } return ApiResult.success(adminWithdrawalService.getWithdrawalList(status, startDate, endDate, page, pageSize)); } /** * 获取提现申请详情 */ @ApiOperation("获取提现申请详情") @GetMapping("/{withdrawalId}") public ApiResult getWithdrawalDetail( @ApiParam(value = "提现申请ID", required = true) @PathVariable("withdrawalId") Long withdrawalId) { return ApiResult.success(adminWithdrawalService.getWithdrawalDetail(withdrawalId)); } /** * 处理提现申请 */ @ApiOperation("处理提现申请") @PostMapping("/{withdrawalId}/process") public ApiResult processWithdrawal( @ApiParam(value = "提现申请ID", required = true) @PathVariable("withdrawalId") Long withdrawalId, @ApiParam(value = "是否批准", required = true) @RequestParam("approved") Boolean approved, @ApiParam(value = "处理备注", required = false) @RequestParam(value = "remark", required = false) String remark) { return ApiResult.success("提现申请已处理", adminWithdrawalService.processWithdrawal(withdrawalId, approved, remark)); } /** * 批量处理提现申请 */ @ApiOperation("批量处理提现申请") @PostMapping("/batch-process") public ApiResult> batchProcessWithdrawal( @ApiParam(value = "提现申请ID列表", required = true) @RequestParam("withdrawalIds") String withdrawalIds, @ApiParam(value = "是否批准", required = true) @RequestParam("approved") Boolean approved, @ApiParam(value = "处理备注", required = false) @RequestParam(value = "remark", required = false) String remark) { return ApiResult.success("批量处理成功", adminWithdrawalService.batchProcessWithdrawal(withdrawalIds, approved, remark)); } /** * 查看当日提现统计 */ @ApiOperation("查看当日提现统计") @GetMapping("/today-statistics") public ApiResult> getTodayStatistics() { return ApiResult.success(adminWithdrawalService.getTodayWithdrawalStatistics()); } } 2. `AdminOrderController.java` package com.cruise.game.controller.admin; import com.cruise.game.common.api.ApiResult; import com.cruise.game.common.constants.CommonConstants; import com.cruise.game.controller.BaseController; import com.cruise.game.model.vo.common.PageResult; import com.cruise.game.model.vo.order.OrderDetailVO; import com.cruise.game.model.vo.order.OrderListVO; import com.cruise.game.service.admin.AdminOrderService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.time.LocalDate; import java.util.HashMap; import java.util.Map; /** * 管理员订单控制器 * * @author cruise * @date 2025-02-28 */ @Slf4j @Api(tags = "管理员订单相关接口") @RestController @RequestMapping("/api/admin/orders") @PreAuthorize("hasRole('ROLE_ADMIN')") public class AdminOrderController extends BaseController { @Resource private AdminOrderService adminOrderService; /** * 获取订单列表 */ @ApiOperation("获取订单列表") @GetMapping public ApiResult> getOrderList( @ApiParam(value = "订单状态", required = false) @RequestParam(value = "status", required = false) String status, @ApiParam(value = "搜索关键词", required = false) @RequestParam(value = "keyword", required = false) String keyword, @ApiParam(value = "开始日期", required = false) @RequestParam(value = "startDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate, @ApiParam(value = "结束日期", required = false) @RequestParam(value = "endDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate, @ApiParam(value = "页码", required = false, defaultValue = "1") @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, @ApiParam(value = "每页条数", required = false, defaultValue = "10") @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) { // 限制最大页面大小 if (pageSize > CommonConstants.MAX_PAGE_SIZE) { pageSize = CommonConstants.MAX_PAGE_SIZE; } return ApiResult.success(adminOrderService.getOrderList(status, keyword, startDate, endDate, page, pageSize)); } /** * 获取订单详情 */ @ApiOperation("获取订单详情") @GetMapping("/{orderId}") public ApiResult getOrderDetail( @ApiParam(value = "订单ID", required = true) @PathVariable("orderId") Long orderId) { return ApiResult.success(adminOrderService.getOrderDetail(orderId)); } /** * 手动分配订单 */ @ApiOperation("手动分配订单") @PostMapping("/{orderId}/assign") public ApiResult assignOrder( @ApiParam(value = "订单ID", required = true) @PathVariable("orderId") Long orderId, @ApiParam(value = "代理ID", required = true) @RequestBody Map param) { Long agentId = param.get("agentId"); if (agentId == null) { return ApiResult.paramError("代理ID不能为空"); } return ApiResult.success("订单已分配", adminOrderService.assignOrder(orderId, agentId)); } /** * 取消订单 */ @ApiOperation("取消订单") @PostMapping("/{orderId}/cancel") public ApiResult cancelOrder( @ApiParam(value = "订单ID", required = true) @PathVariable("orderId") Long orderId) { return ApiResult.success("订单已取消", adminOrderService.cancelOrder(orderId)); } /** * 处理售后申请 */ @ApiOperation("处理售后申请") @PostMapping("/{orderId}/after-sales/process") public ApiResult processAfterSales( @ApiParam(value = "订单ID", required = true) @PathVariable("orderId") Long orderId, @ApiParam(value = "是否同意", required = true) @RequestParam("approved") Boolean approved, @ApiParam(value = "处理备注", required = false) @RequestParam(value = "remark", required = false) String remark) { return ApiResult.success("售后申请已处理", adminOrderService.processAfterSales(orderId, approved, remark)); } /** * 查看当日订单统计 */ @ApiOperation("查看当日订单统计") @GetMapping("/today-statistics") public ApiResult> getTodayStatistics() { return ApiResult.success(adminOrderService.getTodayOrderStatistics()); } } 3. `AdminCategoryController.java` package com.cruise.game.controller.admin; import com.cruise.game.common.api.ApiResult; import com.cruise.game.common.constants.CommonConstants; import com.cruise.game.controller.BaseController; import com.cruise.game.model.param.admin.GameCategoryCreateParam; import com.cruise.game.model.param.admin.GameCategoryUpdateParam; import com.cruise.game.model.vo.admin.GameCategoryVO; import com.cruise.game.model.vo.common.PageResult; import com.cruise.game.service.admin.AdminCategoryService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.HashMap; import java.util.Map; /** * 管理员游戏分类控制器 * * @author cruise * @date 2025-02-28 */ @Slf4j @Api(tags = "管理员游戏分类相关接口") @RestController @RequestMapping("/api/admin/game-categories") @PreAuthorize("hasRole('ROLE_ADMIN')") public class AdminCategoryController extends BaseController { @Resource private AdminCategoryService adminCategoryService; /** * 获取游戏分类列表 */ @ApiOperation("获取游戏分类列表") @GetMapping public ApiResult> getCategoryList( @ApiParam(value = "状态", required = false) @RequestParam(value = "status", required = false) String status, @ApiParam(value = "页码", required = false, defaultValue = "1") @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, @ApiParam(value = "每页条数", required = false, defaultValue = "10") @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) { // 限制最大页面大小 if (pageSize > CommonConstants.MAX_PAGE_SIZE) { pageSize = CommonConstants.MAX_PAGE_SIZE; } return ApiResult.success(adminCategoryService.getCategoryList(status, page, pageSize)); } /** * 获取游戏分类详情 */ @ApiOperation("获取游戏分类详情") @GetMapping("/{id}") public ApiResult getCategoryDetail( @ApiParam(value = "游戏分类ID", required = true) @PathVariable("id") Long id) { return ApiResult.success(adminCategoryService.getCategoryDetail(id)); } /** * 创建游戏分类 */ @ApiOperation("创建游戏分类") @PostMapping public ApiResult> createCategory(@Validated @RequestBody GameCategoryCreateParam param) { Long id = adminCategoryService.createCategory(param); Map result = new HashMap<>(); result.put("id", id); return ApiResult.success("添加成功", result); } /** * 更新游戏分类 */ @ApiOperation("更新游戏分类") @PutMapping("/{id}") public ApiResult updateCategory( @ApiParam(value = "游戏分类ID", required = true) @PathVariable("id") Long id, @Validated @RequestBody GameCategoryUpdateParam param) { return ApiResult.success("更新成功", adminCategoryService.updateCategory(id, param)); } /** * 删除游戏分类 */ @ApiOperation("删除游戏分类") @DeleteMapping("/{id}") public ApiResult deleteCategory( @ApiParam(value = "游戏分类ID", required = true) @PathVariable("id") Long id) { return ApiResult.success("删除成功", adminCategoryService.deleteCategory(id)); } /** * 更新游戏分类状态 */ @ApiOperation("更新游戏分类状态") @PutMapping("/{id}/status") public ApiResult updateCategoryStatus( @ApiParam(value = "游戏分类ID", required = true) @PathVariable("id") Long id, @ApiParam(value = "状态", required = true) @RequestParam("status") String status) { return ApiResult.success("状态已更新", adminCategoryService.updateCategoryStatus(id, status)); } } 4. `AdminAnnouncementController.java` package com.cruise.game.controller.admin; import com.cruise.game.common.api.ApiResult; import com.cruise.game.common.constants.CommonConstants; import com.cruise.game.controller.BaseController; import com.cruise.game.model.param.admin.AnnouncementCreateParam; import com.cruise.game.model.vo.admin.AnnouncementVO; import com.cruise.game.model.vo.common.PageResult; import com.cruise.game.service.admin.AdminAnnouncementService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.HashMap; import java.util.Map; /** * 管理员通告控制器 * * @author cruise * @date 2025-02-28 */ @Slf4j @Api(tags = "管理员通告相关接口") @RestController @RequestMapping("/api/admin/announcements") @PreAuthorize("hasRole('ROLE_ADMIN')") public class AdminAnnouncementController extends BaseController { @Resource private AdminAnnouncementService adminAnnouncementService; /** * 获取通告列表 */ @ApiOperation("获取通告列表") @GetMapping public ApiResult> getAnnouncementList( @ApiParam(value = "状态", required = false) @RequestParam(value = "status", required = false) String status, @ApiParam(value = "页码", required = false, defaultValue = "1") @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, @ApiParam(value = "每页条数", required = false, defaultValue = "10") @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) { // 限制最大页面大小 if (pageSize > CommonConstants.MAX_PAGE_SIZE) { pageSize = CommonConstants.MAX_PAGE_SIZE; } return ApiResult.success(adminAnnouncementService.getAnnouncementList(status, page, pageSize)); } /** * 获取通告详情 */ @ApiOperation("获取通告详情") @GetMapping("/{id}") public ApiResult getAnnouncementDetail( @ApiParam(value = "通告ID", required = true) @PathVariable("id") Long id) { return ApiResult.success(adminAnnouncementService.getAnnouncementDetail(id)); } /** * 创建通告 */ @ApiOperation("创建通告") @PostMapping public ApiResult> createAnnouncement(@Validated @RequestBody AnnouncementCreateParam param) { Long id = adminAnnouncementService.createAnnouncement(param); Map result = new HashMap<>(); result.put("id", id); return ApiResult.success("添加成功", result); } /** * 更新通告 */ @ApiOperation("更新通告") @PutMapping("/{id}") public ApiResult updateAnnouncement( @ApiParam(value = "通告ID", required = true) @PathVariable("id") Long id, @Validated @RequestBody AnnouncementCreateParam param) { return ApiResult.success("更新成功", adminAnnouncementService.updateAnnouncement(id, param)); } /** * 删除通告 */ @ApiOperation("删除通告") @DeleteMapping("/{id}") public ApiResult deleteAnnouncement( @ApiParam(value = "通告ID", required = true) @PathVariable("id") Long id) { return ApiResult.success("删除成功", adminAnnouncementService.deleteAnnouncement(id)); } /** * 更新通告状态 */ @ApiOperation("更新通告状态") @PutMapping("/{id}/status") public ApiResult updateAnnouncementStatus( @ApiParam(value = "通告ID", required = true) @PathVariable("id") Long id, @ApiParam(value = "状态", required = true) @RequestParam("status") String status) { return ApiResult.success("状态已更新", adminAnnouncementService.updateAnnouncementStatus(id, status)); } } 5. `AdminCarouselController.java` package com.cruise.game.controller.admin; import com.cruise.game.common.api.ApiResult; import com.cruise.game.common.constants.CommonConstants; import com.cruise.game.controller.BaseController; import com.cruise.game.model.param.admin.CarouselCreateParam; import com.cruise.game.model.param.admin.CarouselUpdateParam; import com.cruise.game.model.vo.admin.CarouselVO; import com.cruise.game.model.vo.common.PageResult; import com.cruise.game.service.admin.AdminCarouselService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.HashMap; import java.util.Map; /** * 管理员轮播图控制器 * * @author cruise * @date 2025-02-28 */ @Slf4j @Api(tags = "管理员轮播图相关接口") @RestController @RequestMapping("/api/admin/carousels") @PreAuthorize("hasRole('ROLE_ADMIN')") public class AdminCarouselController extends BaseController { @Resource private AdminCarouselService adminCarouselService; /** * 获取轮播图列表 */ @ApiOperation("获取轮播图列表") @GetMapping public ApiResult> getCarouselList( @ApiParam(value = "状态", required = false) @RequestParam(value = "status", required = false) String status, @ApiParam(value = "页码", required = false, defaultValue = "1") @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, @ApiParam(value = "每页条数", required = false, defaultValue = "10") @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) { // 限制最大页面大小 if (pageSize > CommonConstants.MAX_PAGE_SIZE) { pageSize = CommonConstants.MAX_PAGE_SIZE; } return ApiResult.success(adminCarouselService.getCarouselList(status, page, pageSize)); } /** * 获取轮播图详情 */ @ApiOperation("获取轮播图详情") @GetMapping("/{id}") public ApiResult getCarouselDetail( @ApiParam(value = "轮播图ID", required = true) @PathVariable("id") Long id) { return ApiResult.success(adminCarouselService.getCarouselDetail(id)); } /** * 创建轮播图 */ @ApiOperation("创建轮播图") @PostMapping public ApiResult> createCarousel(@Validated @RequestBody CarouselCreateParam param) { Long id = adminCarouselService.createCarousel(param); Map result = new HashMap<>(); result.put("id", id); return ApiResult.success("添加成功", result); } /** * 更新轮播图 */ @ApiOperation("更新轮播图") @PutMapping("/{id}") public ApiResult updateCarousel( @ApiParam(value = "轮播图ID", required = true) @PathVariable("id") Long id, @Validated @RequestBody CarouselUpdateParam param) { return ApiResult.success("更新成功", adminCarouselService.updateCarousel(id, param)); } /** * 删除轮播图 */ @ApiOperation("删除轮播图") @DeleteMapping("/{id}") public ApiResult deleteCarousel( @ApiParam(value = "轮播图ID", required = true) @PathVariable("id") Long id) { return ApiResult.success("删除成功", adminCarouselService.deleteCarousel(id)); } } 6. `AdminUserController.java` package com.cruise.game.controller.admin; import com.cruise.game.common.api.ApiResult; import com.cruise.game.common.constants.CommonConstants; import com.cruise.game.controller.BaseController; import com.cruise.game.model.param.admin.UserStatusParam; import com.cruise.game.model.vo.admin.UserDetailVO; import com.cruise.game.model.vo.admin.UserListVO; import com.cruise.game.model.vo.common.PageResult; import com.cruise.game.service.admin.AdminUserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; /** * 管理员用户控制器 * * @author cruise * @date 2025-02-28 */ @Slf4j @Api(tags = "管理员用户相关接口") @RestController @RequestMapping("/api/admin/users") @PreAuthorize("hasRole('ROLE_ADMIN')") public class AdminUserController extends BaseController { @Resource private AdminUserService adminUserService; /** * 获取用户列表 */ @ApiOperation("获取用户列表") @GetMapping public ApiResult> getUserList( @ApiParam(value = "用户角色", required = false) @RequestParam(value = "role", required = false) String role, @ApiParam(value = "账号状态", required = false) @RequestParam(value = "status", required = false) String status, @ApiParam(value = "搜索关键词", required = false) @RequestParam(value = "keyword", required = false) String keyword, @ApiParam(value = "页码", required = false, defaultValue = "1") @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, @ApiParam(value = "每页条数", required = false, defaultValue = "10") @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) { // 限制最大页面大小 if (pageSize > CommonConstants.MAX_PAGE_SIZE) { pageSize = CommonConstants.MAX_PAGE_SIZE; } return ApiResult.success(adminUserService.getUserList(role, status, keyword, page, pageSize)); } /** * 获取用户详情 */ @ApiOperation("获取用户详情") @GetMapping("/{userId}") public ApiResult getUserDetail( @ApiParam(value = "用户ID", required = true) @PathVariable("userId") Long userId) { return ApiResult.success(adminUserService.getUserDetail(userId)); } /** * 更新用户状态 */ @ApiOperation("更新用户状态") @PutMapping("/{userId}/status") public ApiResult updateUserStatus( @ApiParam(value = "用户ID", required = true) @PathVariable("userId") Long userId, @Validated @RequestBody UserStatusParam param) { return ApiResult.success("用户状态已更新", adminUserService.updateUserStatus(userId, param)); } } 7. `AdminStatisticsController.java` package com.cruise.game.controller.admin; import com.cruise.game.common.api.ApiResult; import com.cruise.game.controller.BaseController; import com.cruise.game.model.vo.admin.AdminStatisticsVO; import com.cruise.game.model.vo.admin.FinanceStatisticsVO; import com.cruise.game.service.admin.AdminStatisticsService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.time.LocalDate; /** * 管理员统计控制器 * * @author cruise * @date 2025-02-28 */ @Slf4j @Api(tags = "管理员统计相关接口") @RestController @RequestMapping("/api/admin/statistics") @PreAuthorize("hasRole('ROLE_ADMIN')") public class AdminStatisticsController extends BaseController { @Resource private AdminStatisticsService adminStatisticsService; /** * 获取统计数据 */ @ApiOperation("获取统计数据") @GetMapping public ApiResult getStatistics() { return ApiResult.success(adminStatisticsService.getStatistics()); } /** * 获取财务统计 */ @ApiOperation("获取财务统计") @GetMapping("/finance") public ApiResult getFinanceStatistics( @ApiParam(value = "开始日期", required = false) @RequestParam(value = "startDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate, @ApiParam(value = "结束日期", required = false) @RequestParam(value = "endDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate) { // 默认查询最近30天 if (startDate == null) { startDate = LocalDate.now().minusDays(30); } if (endDate == null) { endDate = LocalDate.now(); } return ApiResult.success(adminStatisticsService.getFinanceStatistics(startDate, endDate)); } } ## 关键接口文件目录