package com.qf.backend.controller; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.security.access.prepost.PreAuthorize; import com.qf.backend.dto.Result; import com.qf.backend.entity.Refunds; import com.qf.backend.service.RefundsService; import java.util.List; /** * 退款控制器 * 处理退款相关的HTTP请求 * 遵循RESTful API设计规范 */ @RequestMapping("/api/refunds") @RestController public class RefundsController { private static final Logger logger = LoggerFactory.getLogger(RefundsController.class); @Autowired private RefundsService refundsService; /** * 根据订单ID查询退款记录 * @param orderId 订单ID * @return 退款记录列表 */ @GetMapping("/order/{orderId}") public Result> getRefundsByOrderId(@PathVariable Long orderId) { logger.info("根据订单ID查询退款记录,订单ID:{}", orderId); List refunds = refundsService.getRefundsByOrderId(orderId); return Result.success(refunds); } /** * 根据退款单号查询退款记录 * @param refundNumber 退款单号 * @return 退款记录 */ @GetMapping("/number/{refundNumber}") public Result getRefundByNumber(@PathVariable String refundNumber) { logger.info("根据退款单号查询退款记录,退款单号:{}", refundNumber); Refunds refund = refundsService.getRefundByNumber(refundNumber); return Result.success(refund); } /** * 创建退款记录 * @param refunds 退款信息 * @return 是否成功 */ @PostMapping("/create") @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_USER')") public Result createRefund(@RequestBody Refunds refunds) { logger.info("创建退款记录,退款信息:{}", refunds); boolean result = refundsService.createRefund(refunds); return Result.success(result); } /** * 更新退款信息 * @param refunds 退款信息 * @return 是否成功 */ @PutMapping("/update") @PreAuthorize("hasRole('ROLE_ADMIN')") public Result updateRefund(@RequestBody Refunds refunds) { logger.info("更新退款信息,退款信息:{}", refunds); boolean result = refundsService.updateRefund(refunds); return Result.success(result); } /** * 删除退款记录 * @param id 退款ID * @return 是否成功 */ @DeleteMapping("/delete/{id}") @PreAuthorize("hasRole('ROLE_ADMIN')") public Result deleteRefund(@PathVariable Long id) { logger.info("删除退款记录,退款ID:{}", id); boolean result = refundsService.deleteRefund(id); return Result.success(result); } /** * 根据退款ID查询退款记录 * @param id 退款ID * @return 退款记录 */ @GetMapping("/{id}") public Result getRefundById(@PathVariable Long id) { logger.info("根据退款ID查询退款记录,退款ID:{}", id); Refunds refund = refundsService.getRefundById(id); return Result.success(refund); } /** * 根据用户ID查询退款记录 * @param userId 用户ID * @return 退款记录列表 */ @GetMapping("/user/{userId}") public Result> getRefundsByUserId(@PathVariable Long userId) { logger.info("根据用户ID查询退款记录,用户ID:{}", userId); List refunds = refundsService.getRefundsByUserId(userId); return Result.success(refunds); } /** * 根据退款状态查询退款记录 * @param status 退款状态 * @return 退款记录列表 */ @GetMapping("/status/{status}") public Result> getRefundsByStatus(@PathVariable Integer status) { logger.info("根据退款状态查询退款记录,状态:{}", status); List refunds = refundsService.getRefundsByStatus(status); return Result.success(refunds); } /** * 更新退款状态 * @param refundId 退款ID * @param status 退款状态 * @return 是否成功 */ @PutMapping("/update-status/{refundId}/{status}") @PreAuthorize("hasRole('ROLE_ADMIN')") public Result updateRefundStatus(@PathVariable Long refundId, @PathVariable Integer status) { logger.info("更新退款状态,退款ID:{},状态:{}", refundId, status); boolean result = refundsService.updateRefundStatus(refundId, status); return Result.success(result); } /** * 分页查询退款记录 * @param page 当前页码 * @param size 每页数量 * @return 退款记录列表 */ @GetMapping("/page/{page}/{size}") public Result> listRefundsByPage(@PathVariable int page, @PathVariable int size) { logger.info("分页查询退款记录,页码:{},每页数量:{}", page, size); List refunds = refundsService.listRefundsByPage(page, size); return Result.success(refunds); } }