package com.ycwl.basic.pricing.controller; import com.github.pagehelper.PageInfo; import com.ycwl.basic.utils.ApiResponse; import com.ycwl.basic.pricing.dto.req.VoucherUsageHistoryReq; import com.ycwl.basic.pricing.dto.resp.VoucherUsageRecordResp; import com.ycwl.basic.pricing.dto.resp.VoucherUsageStatsResp; import com.ycwl.basic.pricing.service.IVoucherUsageService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import java.util.List; /** * 券码使用记录管理控制器 */ @Slf4j @RestController @RequestMapping("/api/pricing/voucher/usage") @RequiredArgsConstructor public class VoucherUsageController { private final IVoucherUsageService voucherUsageService; @PostMapping("/history") public ApiResponse> getUsageHistory(@RequestBody VoucherUsageHistoryReq req) { try { PageInfo result = voucherUsageService.getUsageHistory(req); return ApiResponse.success(result); } catch (Exception e) { log.error("查询券码使用记录失败", e); return ApiResponse.fail("查询失败: " + e.getMessage()); } } @GetMapping("/{voucherCode}/records") public ApiResponse> getRecordsByCode( @PathVariable String voucherCode) { try { List records = voucherUsageService.getUsageRecordsByCode(voucherCode); return ApiResponse.success(records); } catch (Exception e) { log.error("查询券码使用记录失败: {}", voucherCode, e); return ApiResponse.fail("查询失败: " + e.getMessage()); } } @GetMapping("/{voucherCode}/stats") public ApiResponse getUsageStats( @PathVariable String voucherCode) { try { VoucherUsageStatsResp stats = voucherUsageService.getUsageStats(voucherCode); if (stats == null) { return ApiResponse.fail("券码不存在"); } return ApiResponse.success(stats); } catch (Exception e) { log.error("查询券码统计信息失败: {}", voucherCode, e); return ApiResponse.fail("查询失败: " + e.getMessage()); } } @GetMapping("/user/{faceId}/scenic/{scenicId}") public ApiResponse> getUserUsageRecords( @PathVariable Long faceId, @PathVariable Long scenicId) { try { List records = voucherUsageService.getUserUsageRecords(faceId, scenicId); return ApiResponse.success(records); } catch (Exception e) { log.error("查询用户券码使用记录失败: faceId={}, scenicId={}", faceId, scenicId, e); return ApiResponse.fail("查询失败: " + e.getMessage()); } } @GetMapping("/batch/{batchId}/stats") public ApiResponse> getBatchUsageStats( @PathVariable Long batchId) { try { List statsList = voucherUsageService.getBatchUsageStats(batchId); return ApiResponse.success(statsList); } catch (Exception e) { log.error("查询批次券码统计信息失败: batchId={}", batchId, e); return ApiResponse.fail("查询失败: " + e.getMessage()); } } }