You've already forked FrameTour-BE
feat(pricing): 添加优惠券管理功能
- 新增 CouponManagementController 控制器,实现优惠券配置和领取记录的管理 - 新增 ICouponManagementService 接口和 CouponManagementServiceImpl 实现类,提供优惠券管理服务 - 在 PricingConfigController 中添加获取所有优惠券配置和领取记录的接口 - 新增 BundleProductListTypeHandler 类,用于处理一口价商品列表的序列化和反序列化 - 更新 PriceCouponClaimRecordMapper 和 PriceCouponConfigMapper,添加管理端所需的查询接口
This commit is contained in:
@@ -0,0 +1,220 @@
|
||||
package com.ycwl.basic.pricing.controller;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ycwl.basic.pricing.entity.PriceCouponClaimRecord;
|
||||
import com.ycwl.basic.pricing.entity.PriceCouponConfig;
|
||||
import com.ycwl.basic.pricing.enums.CouponStatus;
|
||||
import com.ycwl.basic.pricing.service.ICouponManagementService;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 优惠券管理控制器(管理端)
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/pricing/admin/coupons")
|
||||
@RequiredArgsConstructor
|
||||
public class CouponManagementController {
|
||||
|
||||
private final ICouponManagementService couponManagementService;
|
||||
|
||||
// ==================== 优惠券配置管理 ====================
|
||||
|
||||
/**
|
||||
* 创建优惠券配置
|
||||
*/
|
||||
@PostMapping("/configs")
|
||||
public ApiResponse<Long> createCouponConfig(@RequestBody PriceCouponConfig config) {
|
||||
log.info("创建优惠券配置: {}", config.getCouponName());
|
||||
Long id = couponManagementService.createCouponConfig(config);
|
||||
return ApiResponse.success(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新优惠券配置
|
||||
*/
|
||||
@PutMapping("/configs/{id}")
|
||||
public ApiResponse<Boolean> updateCouponConfig(@PathVariable Long id, @RequestBody PriceCouponConfig config) {
|
||||
log.info("更新优惠券配置: id={}, name={}", id, config.getCouponName());
|
||||
config.setId(id);
|
||||
boolean success = couponManagementService.updateCouponConfig(config);
|
||||
return ApiResponse.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除优惠券配置
|
||||
*/
|
||||
@DeleteMapping("/configs/{id}")
|
||||
public ApiResponse<Boolean> deleteCouponConfig(@PathVariable Long id) {
|
||||
log.info("删除优惠券配置: id={}", id);
|
||||
boolean success = couponManagementService.deleteCouponConfig(id);
|
||||
return ApiResponse.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用/禁用优惠券配置
|
||||
*/
|
||||
@PutMapping("/configs/{id}/status")
|
||||
public ApiResponse<Boolean> updateCouponConfigStatus(@PathVariable Long id, @RequestParam Boolean isActive) {
|
||||
log.info("修改优惠券配置状态: id={}, isActive={}", id, isActive);
|
||||
boolean success = couponManagementService.updateCouponConfigStatus(id, isActive);
|
||||
return ApiResponse.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有优惠券配置(包含禁用的)
|
||||
*/
|
||||
@GetMapping("/configs")
|
||||
public ApiResponse<List<PriceCouponConfig>> getAllCouponConfigs() {
|
||||
log.info("管理端获取所有优惠券配置");
|
||||
List<PriceCouponConfig> configs = couponManagementService.getAllCouponConfigs();
|
||||
return ApiResponse.success(configs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询优惠券配置
|
||||
*/
|
||||
@GetMapping("/configs/page")
|
||||
public ApiResponse<PageInfo<PriceCouponConfig>> getCouponConfigsPage(
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize,
|
||||
@RequestParam(required = false) Boolean isActive,
|
||||
@RequestParam(required = false) String couponName) {
|
||||
log.info("分页查询优惠券配置: pageNum={}, pageSize={}, isActive={}, couponName={}",
|
||||
pageNum, pageSize, isActive, couponName);
|
||||
PageInfo<PriceCouponConfig> pageInfo = couponManagementService.getCouponConfigsPage(
|
||||
pageNum, pageSize, isActive, couponName);
|
||||
return ApiResponse.success(pageInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据状态查询优惠券配置
|
||||
*/
|
||||
@GetMapping("/configs/status/{isActive}")
|
||||
public ApiResponse<List<PriceCouponConfig>> getCouponConfigsByStatus(@PathVariable Boolean isActive) {
|
||||
log.info("根据状态查询优惠券配置: {}", isActive);
|
||||
List<PriceCouponConfig> configs = couponManagementService.getCouponConfigsByStatus(isActive);
|
||||
return ApiResponse.success(configs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询优惠券配置
|
||||
*/
|
||||
@GetMapping("/configs/{id}")
|
||||
public ApiResponse<PriceCouponConfig> getCouponConfigById(@PathVariable Long id) {
|
||||
log.info("根据ID查询优惠券配置: {}", id);
|
||||
PriceCouponConfig config = couponManagementService.getCouponConfigById(id);
|
||||
return ApiResponse.success(config);
|
||||
}
|
||||
|
||||
// ==================== 优惠券领取记录查询 ====================
|
||||
|
||||
/**
|
||||
* 查询所有优惠券领取记录
|
||||
*/
|
||||
@GetMapping("/claim-records")
|
||||
public ApiResponse<List<PriceCouponClaimRecord>> getAllClaimRecords() {
|
||||
log.info("查询所有优惠券领取记录");
|
||||
List<PriceCouponClaimRecord> records = couponManagementService.getAllClaimRecords();
|
||||
return ApiResponse.success(records);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询优惠券领取记录
|
||||
*/
|
||||
@GetMapping("/claim-records/page")
|
||||
public ApiResponse<PageInfo<PriceCouponClaimRecord>> getClaimRecordsPage(
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize,
|
||||
@RequestParam(required = false) Long userId,
|
||||
@RequestParam(required = false) Long couponId,
|
||||
@RequestParam(required = false) CouponStatus status,
|
||||
@RequestParam(required = false) String startTime,
|
||||
@RequestParam(required = false) String endTime) {
|
||||
log.info("分页查询优惠券领取记录: pageNum={}, pageSize={}, userId={}, couponId={}, status={}, startTime={}, endTime={}",
|
||||
pageNum, pageSize, userId, couponId, status, startTime, endTime);
|
||||
PageInfo<PriceCouponClaimRecord> pageInfo = couponManagementService.getClaimRecordsPage(
|
||||
pageNum, pageSize, userId, couponId, status, startTime, endTime);
|
||||
return ApiResponse.success(pageInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID查询优惠券领取记录
|
||||
*/
|
||||
@GetMapping("/claim-records/user/{userId}")
|
||||
public ApiResponse<List<PriceCouponClaimRecord>> getClaimRecordsByUserId(@PathVariable Long userId) {
|
||||
log.info("根据用户ID查询优惠券领取记录: {}", userId);
|
||||
List<PriceCouponClaimRecord> records = couponManagementService.getClaimRecordsByUserId(userId);
|
||||
return ApiResponse.success(records);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据优惠券ID查询领取记录
|
||||
*/
|
||||
@GetMapping("/claim-records/coupon/{couponId}")
|
||||
public ApiResponse<List<PriceCouponClaimRecord>> getClaimRecordsByCouponId(@PathVariable Long couponId) {
|
||||
log.info("根据优惠券ID查询领取记录: {}", couponId);
|
||||
List<PriceCouponClaimRecord> records = couponManagementService.getClaimRecordsByCouponId(couponId);
|
||||
return ApiResponse.success(records);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据状态查询领取记录
|
||||
*/
|
||||
@GetMapping("/claim-records/status/{status}")
|
||||
public ApiResponse<List<PriceCouponClaimRecord>> getClaimRecordsByStatus(@PathVariable CouponStatus status) {
|
||||
log.info("根据状态查询领取记录: {}", status);
|
||||
List<PriceCouponClaimRecord> records = couponManagementService.getClaimRecordsByStatus(status);
|
||||
return ApiResponse.success(records);
|
||||
}
|
||||
|
||||
// ==================== 统计功能 ====================
|
||||
|
||||
/**
|
||||
* 查询优惠券使用统计
|
||||
*/
|
||||
@GetMapping("/stats/{couponId}")
|
||||
public ApiResponse<Map<String, Object>> getCouponUsageStats(@PathVariable Long couponId) {
|
||||
log.info("查询优惠券使用统计: {}", couponId);
|
||||
Map<String, Object> stats = couponManagementService.getCouponUsageStats(couponId);
|
||||
return ApiResponse.success(stats);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询优惠券详细统计
|
||||
*/
|
||||
@GetMapping("/stats/{couponId}/detail")
|
||||
public ApiResponse<Map<String, Object>> getCouponDetailStats(@PathVariable Long couponId) {
|
||||
log.info("查询优惠券详细统计: {}", couponId);
|
||||
Map<String, Object> stats = couponManagementService.getCouponDetailStats(couponId);
|
||||
return ApiResponse.success(stats);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询时间范围内的统计数据
|
||||
*/
|
||||
@GetMapping("/stats/period")
|
||||
public ApiResponse<Map<String, Object>> getPeriodStats(
|
||||
@RequestParam String startDate,
|
||||
@RequestParam String endDate) {
|
||||
log.info("查询时间范围统计: startDate={}, endDate={}", startDate, endDate);
|
||||
Map<String, Object> stats = couponManagementService.getPeriodStats(startDate, endDate);
|
||||
return ApiResponse.success(stats);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有优惠券的使用统计概览
|
||||
*/
|
||||
@GetMapping("/stats/overview")
|
||||
public ApiResponse<List<Map<String, Object>>> getAllCouponUsageOverview() {
|
||||
log.info("查询所有优惠券使用统计概览");
|
||||
List<Map<String, Object>> overview = couponManagementService.getAllCouponUsageOverview();
|
||||
return ApiResponse.success(overview);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user