fix(优惠券管理):优化优惠券管理功能模块保持代码风格统一
This commit is contained in:
+39
-52
@@ -3,10 +3,13 @@ package com.central.order.controller;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.order.entity.Coupon;
|
||||
import com.central.order.service.ICouponService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -15,6 +18,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 优惠券管理控制器
|
||||
@@ -29,37 +33,24 @@ public class CouponController {
|
||||
private ICouponService couponService;
|
||||
|
||||
/**
|
||||
* 分页查询优惠券列表
|
||||
* 列表
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "分页查询优惠券列表")
|
||||
public Result<IPage<Coupon>> getCouponPage(
|
||||
@Parameter(description = "页码") @RequestParam(defaultValue = "1") Integer current,
|
||||
@Parameter(description = "每页大小") @RequestParam(defaultValue = "10") Integer size,
|
||||
@Parameter(description = "优惠券名称") @RequestParam(required = false) String couponName,
|
||||
@Parameter(description = "优惠券类型") @RequestParam(required = false) Integer couponType,
|
||||
@Parameter(description = "状态") @RequestParam(required = false) Integer status,
|
||||
@Parameter(description = "用户手机号") @RequestParam(required = false) String userPhone,
|
||||
@Parameter(description = "来源") @RequestParam(required = false) Integer source) {
|
||||
|
||||
Page<Coupon> page = new Page<>(current, size);
|
||||
Coupon coupon = new Coupon();
|
||||
coupon.setCouponName(couponName);
|
||||
coupon.setCouponType(couponType);
|
||||
coupon.setStatus(status);
|
||||
coupon.setUserPhone(userPhone);
|
||||
coupon.setSource(source);
|
||||
|
||||
IPage<Coupon> result = couponService.getCouponPage(page, coupon);
|
||||
return Result.succeed(result);
|
||||
@Operation(summary = "查询列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "page",description = "分页起始位置",required = true,in=ParameterIn.QUERY),
|
||||
@Parameter(name = "limit",description = "分页结束位置",required = true,in=ParameterIn.QUERY)
|
||||
})
|
||||
@GetMapping
|
||||
public PageResult<Coupon> list(@RequestParam Map<String, Object> params) {
|
||||
return couponService.findList(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询优惠券
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
@Operation(summary = "根据ID查询优惠券")
|
||||
public Result<Coupon> getCouponById(@Parameter(description = "优惠券ID") @PathVariable Long id) {
|
||||
@GetMapping("/{id}")
|
||||
public Result<Coupon> getCouponById(@PathVariable Long id) {
|
||||
Coupon coupon = couponService.getById(id);
|
||||
return Result.succeed(coupon);
|
||||
}
|
||||
@@ -67,8 +58,8 @@ public class CouponController {
|
||||
/**
|
||||
* 创建优惠券
|
||||
*/
|
||||
@PostMapping
|
||||
@Operation(summary = "创建优惠券")
|
||||
@PostMapping
|
||||
public Result<Boolean> createCoupon(@RequestBody Coupon coupon) {
|
||||
boolean result = couponService.createCoupon(coupon);
|
||||
return Result.succeed(result);
|
||||
@@ -77,9 +68,9 @@ public class CouponController {
|
||||
/**
|
||||
* 更新优惠券
|
||||
*/
|
||||
@PutMapping("/{id}")
|
||||
@Operation(summary = "更新优惠券")
|
||||
public Result<Boolean> updateCoupon(@Parameter(description = "优惠券ID") @PathVariable Long id, @RequestBody Coupon coupon) {
|
||||
@PutMapping("/{id}")
|
||||
public Result<Boolean> updateCoupon(@PathVariable Long id, @RequestBody Coupon coupon) {
|
||||
coupon.setId(id);
|
||||
boolean result = couponService.updateCoupon(coupon);
|
||||
return Result.succeed(result);
|
||||
@@ -88,9 +79,9 @@ public class CouponController {
|
||||
/**
|
||||
* 删除优惠券
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
@Operation(summary = "删除优惠券")
|
||||
public Result<Boolean> deleteCoupon(@Parameter(description = "优惠券ID") @PathVariable Long id) {
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<Boolean> deleteCoupon(@PathVariable Long id) {
|
||||
boolean result = couponService.deleteCoupon(id);
|
||||
return Result.succeed(result);
|
||||
}
|
||||
@@ -98,9 +89,9 @@ public class CouponController {
|
||||
/**
|
||||
* 根据手机号查询用户优惠券
|
||||
*/
|
||||
@GetMapping("/user/{userPhone}")
|
||||
@Operation(summary = "根据手机号查询用户优惠券")
|
||||
public Result<List<Coupon>> getCouponsByUserPhone(@Parameter(description = "用户手机号") @PathVariable String userPhone) {
|
||||
@GetMapping("/user/{userPhone}")
|
||||
public Result<List<Coupon>> getCouponsByUserPhone(@PathVariable String userPhone) {
|
||||
List<Coupon> coupons = couponService.getCouponsByUserPhone(userPhone);
|
||||
return Result.succeed(coupons);
|
||||
}
|
||||
@@ -108,9 +99,9 @@ public class CouponController {
|
||||
/**
|
||||
* 根据手机号查询可用优惠券
|
||||
*/
|
||||
@GetMapping("/user/{userPhone}/available")
|
||||
@Operation(summary = "根据手机号查询可用优惠券")
|
||||
public Result<List<Coupon>> getAvailableCouponsByUserPhone(@Parameter(description = "用户手机号") @PathVariable String userPhone) {
|
||||
@GetMapping("/user/{userPhone}/available")
|
||||
public Result<List<Coupon>> getAvailableCouponsByUserPhone(@PathVariable String userPhone) {
|
||||
List<Coupon> coupons = couponService.getAvailableCouponsByUserPhone(userPhone);
|
||||
return Result.succeed(coupons);
|
||||
}
|
||||
@@ -118,11 +109,9 @@ public class CouponController {
|
||||
/**
|
||||
* 使用优惠券
|
||||
*/
|
||||
@PostMapping("/{id}/use")
|
||||
@Operation(summary = "使用优惠券")
|
||||
public Result<Boolean> useCoupon(
|
||||
@Parameter(description = "优惠券ID") @PathVariable Long id,
|
||||
@Parameter(description = "订单号") @RequestParam String orderNo) {
|
||||
@PostMapping("/{id}/use")
|
||||
public Result<Boolean> useCoupon(@PathVariable Long id, @RequestParam String orderNo) {
|
||||
boolean result = couponService.useCoupon(id, orderNo);
|
||||
return Result.succeed(result);
|
||||
}
|
||||
@@ -130,18 +119,18 @@ public class CouponController {
|
||||
/**
|
||||
* 携程创建优惠券接口
|
||||
*/
|
||||
@PostMapping("/ctrip/create")
|
||||
@Operation(summary = "携程创建优惠券接口")
|
||||
@PostMapping("/ctrip/create")
|
||||
public Result<Boolean> createCouponFromCtrip(
|
||||
@Parameter(description = "携程优惠券ID") @RequestParam String ctripCouponId,
|
||||
@Parameter(description = "用户手机号") @RequestParam String userPhone,
|
||||
@Parameter(description = "优惠券名称") @RequestParam String couponName,
|
||||
@Parameter(description = "优惠券类型") @RequestParam Integer couponType,
|
||||
@Parameter(description = "优惠券面额") @RequestParam BigDecimal amount,
|
||||
@Parameter(description = "使用门槛金额") @RequestParam(required = false) BigDecimal minAmount,
|
||||
@Parameter(description = "折扣率") @RequestParam(required = false) Integer discountRate,
|
||||
@Parameter(description = "有效期开始时间") @RequestParam String validStartTime,
|
||||
@Parameter(description = "有效期结束时间") @RequestParam String validEndTime) {
|
||||
@RequestParam String ctripCouponId,
|
||||
@RequestParam String userPhone,
|
||||
@RequestParam String couponName,
|
||||
@RequestParam Integer couponType,
|
||||
@RequestParam BigDecimal amount,
|
||||
@RequestParam(required = false) BigDecimal minAmount,
|
||||
@RequestParam(required = false) Integer discountRate,
|
||||
@RequestParam String validStartTime,
|
||||
@RequestParam String validEndTime) {
|
||||
|
||||
// 这里需要根据实际的时间格式进行解析
|
||||
// 暂时使用当前时间,实际应该解析传入的时间字符串
|
||||
@@ -157,11 +146,9 @@ public class CouponController {
|
||||
/**
|
||||
* 核销携程优惠券
|
||||
*/
|
||||
@PostMapping("/ctrip/verify")
|
||||
@Operation(summary = "核销携程优惠券")
|
||||
public Result<Boolean> verifyCtripCoupon(
|
||||
@Parameter(description = "携程优惠券ID") @RequestParam String ctripCouponId,
|
||||
@Parameter(description = "订单号") @RequestParam String orderNo) {
|
||||
@PostMapping("/ctrip/verify")
|
||||
public Result<Boolean> verifyCtripCoupon(@RequestParam String ctripCouponId, @RequestParam String orderNo) {
|
||||
boolean result = couponService.verifyCtripCoupon(ctripCouponId, orderNo);
|
||||
return Result.succeed(result);
|
||||
}
|
||||
@@ -169,8 +156,8 @@ public class CouponController {
|
||||
/**
|
||||
* 批量更新过期优惠券
|
||||
*/
|
||||
@PostMapping("/update-expired")
|
||||
@Operation(summary = "批量更新过期优惠券")
|
||||
@PostMapping("/update-expired")
|
||||
public Result<Void> updateExpiredCoupons() {
|
||||
couponService.updateExpiredCoupons();
|
||||
return Result.succeed("批量更新过期优惠券成功");
|
||||
|
||||
@@ -4,8 +4,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.central.order.entity.Coupon;
|
||||
import com.central.common.model.PageResult;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 优惠券服务接口
|
||||
@@ -17,6 +19,11 @@ public interface ICouponService extends IService<Coupon> {
|
||||
*/
|
||||
IPage<Coupon> getCouponPage(Page<Coupon> page, Coupon coupon);
|
||||
|
||||
/**
|
||||
* 查询优惠券列表(统一风格)
|
||||
*/
|
||||
PageResult<Coupon> findList(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 创建优惠券
|
||||
*/
|
||||
|
||||
+41
@@ -8,6 +8,7 @@ import com.central.order.entity.Coupon;
|
||||
import com.central.order.mapper.CouponMapper;
|
||||
import com.central.order.service.ICouponService;
|
||||
import com.central.order.service.ICtripApiService;
|
||||
import com.central.common.model.PageResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -16,6 +17,7 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@@ -33,6 +35,45 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> impleme
|
||||
return baseMapper.selectCouponPage(page, coupon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<Coupon> findList(Map<String, Object> params) {
|
||||
// 获取分页参数
|
||||
Integer page = Integer.parseInt(params.getOrDefault("page", "1").toString());
|
||||
Integer limit = Integer.parseInt(params.getOrDefault("limit", "10").toString());
|
||||
|
||||
// 构建查询条件
|
||||
Coupon queryCoupon = new Coupon();
|
||||
if (params.get("couponName") != null) {
|
||||
queryCoupon.setCouponName(params.get("couponName").toString());
|
||||
}
|
||||
if (params.get("couponType") != null) {
|
||||
queryCoupon.setCouponType(Integer.parseInt(params.get("couponType").toString()));
|
||||
}
|
||||
if (params.get("status") != null) {
|
||||
queryCoupon.setStatus(Integer.parseInt(params.get("status").toString()));
|
||||
}
|
||||
if (params.get("userPhone") != null) {
|
||||
queryCoupon.setUserPhone(params.get("userPhone").toString());
|
||||
}
|
||||
if (params.get("source") != null) {
|
||||
queryCoupon.setSource(Integer.parseInt(params.get("source").toString()));
|
||||
}
|
||||
if (params.get("ctripCouponId") != null) {
|
||||
queryCoupon.setCtripCouponId(params.get("ctripCouponId").toString());
|
||||
}
|
||||
|
||||
// 执行分页查询
|
||||
Page<Coupon> pageParam = new Page<>(page, limit);
|
||||
IPage<Coupon> pageResult = baseMapper.selectCouponPage(pageParam, queryCoupon);
|
||||
|
||||
// 构建返回结果
|
||||
return PageResult.<Coupon>builder()
|
||||
.count(pageResult.getTotal())
|
||||
.resp_code(0)
|
||||
.data(pageResult.getRecords())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean createCoupon(Coupon coupon) {
|
||||
|
||||
Reference in New Issue
Block a user