|
@@ -0,0 +1,185 @@
|
|
|
+package com.chelvc.cloud.maintain.controller;
|
|
|
+
|
|
|
+import com.chelvc.cloud.maintain.copier.CouponCopier;
|
|
|
+import com.chelvc.cloud.maintain.vo.CouponVO;
|
|
|
+import com.chelvc.cloud.vehicle.api.dto.CouponDTO;
|
|
|
+import com.chelvc.cloud.vehicle.api.param.CouponModifyParam;
|
|
|
+import com.chelvc.cloud.vehicle.api.param.CouponPagingParam;
|
|
|
+import com.chelvc.cloud.vehicle.api.service.CouponService;
|
|
|
+import com.chelvc.framework.base.annotation.ResponseWrapping;
|
|
|
+import com.chelvc.framework.common.model.Pagination;
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.PutMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.validation.Valid;
|
|
|
+import javax.validation.constraints.Min;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 优惠券接口
|
|
|
+ *
|
|
|
+ * @author qizai
|
|
|
+ * @date 2023/9/8
|
|
|
+ */
|
|
|
+@Validated
|
|
|
+@RestController
|
|
|
+@ResponseWrapping
|
|
|
+public class CouponController {
|
|
|
+ @DubboReference
|
|
|
+ private CouponService couponService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增优惠券
|
|
|
+ *
|
|
|
+ * @param param 新增参数
|
|
|
+ * @return 优惠券主键
|
|
|
+ */
|
|
|
+ @PostMapping("/coupon")
|
|
|
+ public Long addCoupon(@RequestBody @Valid CouponModifyParam param) {
|
|
|
+ return this.couponService.addCoupon(param);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改优惠券
|
|
|
+ *
|
|
|
+ * @param id 优惠券主键
|
|
|
+ * @param param 修改参数
|
|
|
+ */
|
|
|
+ @PutMapping("/coupon/{id}")
|
|
|
+ public void updateCoupon(@PathVariable("id") @Min(value = 1, message = "优惠券主键不能小于1") Long id,
|
|
|
+ @RequestBody @Valid CouponModifyParam param) {
|
|
|
+ this.couponService.updateCoupon(id, param);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取优惠券信息
|
|
|
+ *
|
|
|
+ * @param id 优惠券主键
|
|
|
+ * @return 优惠券信息
|
|
|
+ */
|
|
|
+ @GetMapping("/coupon/{id}")
|
|
|
+ public CouponVO getCoupon(@PathVariable("id") @Min(value = 1, message = "优惠券主键不能小于1") Long id) {
|
|
|
+ return this.convert(this.couponService.getCoupon(id));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询优惠券分页
|
|
|
+ *
|
|
|
+ * @param param 查询参数
|
|
|
+ * @return 优惠券分页信息
|
|
|
+ */
|
|
|
+ @GetMapping("/coupon/paging")
|
|
|
+ public Pagination<CouponVO> getCouponPaging(@Valid CouponPagingParam param) {
|
|
|
+ Pagination<CouponDTO> pagination = this.couponService.getCouponPaging(param);
|
|
|
+ List<CouponDTO> records = pagination.getRecords();
|
|
|
+ if (CollectionUtils.isEmpty(records)) {
|
|
|
+ return Pagination.empty();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建优惠券信息
|
|
|
+ List<CouponVO> coupons = records.stream().map(this::convert).collect(Collectors.toList());
|
|
|
+ return pagination.convert(coupons);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据商家ID查询优惠券分页
|
|
|
+ *
|
|
|
+ * @param merchantId 商家ID
|
|
|
+ * @param param 查询参数
|
|
|
+ * @return 优惠券分页信息
|
|
|
+ */
|
|
|
+ @GetMapping("/coupon/{merchantId}/paging")
|
|
|
+ public Pagination<CouponVO> listCoupons(@PathVariable("merchantId") @Min(value = 1, message = "优惠券主键不能小于1")
|
|
|
+ Long merchantId, @Valid CouponPagingParam param) {
|
|
|
+ Pagination<CouponDTO> pagination = this.couponService.getMerchantCouponPaging(merchantId, param);
|
|
|
+ List<CouponDTO> records = pagination.getRecords();
|
|
|
+ if (CollectionUtils.isEmpty(records)) {
|
|
|
+ return Pagination.empty();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建优惠券信息
|
|
|
+ List<CouponVO> coupons = records.stream().map(this::convert).collect(Collectors.toList());
|
|
|
+ return pagination.convert(coupons);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 自动领取优惠券
|
|
|
+ *
|
|
|
+ */
|
|
|
+ @PostMapping("/coupon/autoCollect")
|
|
|
+ public void autoCollectCoupons() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 会员领取优惠券
|
|
|
+ *
|
|
|
+ * @param id 优惠券主键
|
|
|
+ */
|
|
|
+ @GetMapping("/coupon/collect/{id}")
|
|
|
+ public void collectCoupon(@PathVariable("id") @Min(value = 1, message = "优惠券主键不能小于1") Long id) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询可领取优惠券列表
|
|
|
+ *
|
|
|
+ * @param param 查询参数
|
|
|
+ * @return 优惠券分页信息
|
|
|
+ */
|
|
|
+ @GetMapping("/coupon/availablePaging")
|
|
|
+ public Pagination<CouponVO> getAvailableCouponPaging(@Valid CouponPagingParam param) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询当前会员的优惠券列表
|
|
|
+ *
|
|
|
+ * @param param 查询参数
|
|
|
+ * @return 优惠券分页信息
|
|
|
+ */
|
|
|
+ @GetMapping("/coupon/ownedPaging")
|
|
|
+ public Pagination<CouponVO> getMemberCouponPaging(@Valid CouponPagingParam param) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询当前会员的对于当前商品可使用的优惠券列表
|
|
|
+ *
|
|
|
+ * @param param 查询参数
|
|
|
+ * @return 优惠券分页信息
|
|
|
+ */
|
|
|
+ @GetMapping("/coupon/usablePaging")
|
|
|
+ public Pagination<CouponVO> getUsableCouponPaging(@Valid CouponPagingParam param) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除优惠券
|
|
|
+ *
|
|
|
+ * @param id 优惠券主键
|
|
|
+ */
|
|
|
+ @DeleteMapping("/coupon/{id}")
|
|
|
+ public void deleteCoupon(@PathVariable("id") @Min(value = 1, message = "优惠券主键不能小于1") Long id) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 转换优惠券
|
|
|
+ *
|
|
|
+ * @param coupon 优惠券DTO
|
|
|
+ * @return 优惠券VO
|
|
|
+ */
|
|
|
+ private CouponVO convert(CouponDTO coupon) {
|
|
|
+ return CouponCopier.INSTANCE.copying(coupon);
|
|
|
+ }
|
|
|
+}
|