| 对比新文件 |
| | |
| | | package com.mzl.flower.web.v2.coupon; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.mzl.flower.base.BaseController; |
| | | import com.mzl.flower.base.R; |
| | | import com.mzl.flower.base.ReturnDataDTO; |
| | | import com.mzl.flower.config.exception.ValidationException; |
| | | import com.mzl.flower.dto.request.coupon.*; |
| | | import com.mzl.flower.dto.response.coupon.CouponPointStatisVO; |
| | | import com.mzl.flower.dto.response.coupon.CouponTemplatePointVO; |
| | | import com.mzl.flower.dto.response.coupon.CouponTemplateVO; |
| | | import com.mzl.flower.entity.coupon.CouponTemplateDO; |
| | | import com.mzl.flower.enums.CouponCategoryEnum; |
| | | import com.mzl.flower.enums.CouponStatusEnum; |
| | | import com.mzl.flower.enums.CouponTypeEnum; |
| | | import com.mzl.flower.enums.CouponUsageTypeEnum; |
| | | import com.mzl.flower.service.coupon.CouponTemplateService2; |
| | | import com.mzl.flower.utils.ConverterUtil; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.math.BigDecimal; |
| | | |
| | | |
| | | /** |
| | | * @author @TaoJie |
| | | * @since 2024-08-22 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/api/v2/coupon/point") |
| | | @Api(value = "优惠券管理-积分", tags = "优惠券管理-积分") |
| | | @Validated |
| | | public class CouponTemplatePointController extends BaseController { |
| | | |
| | | @Autowired |
| | | CouponTemplateService2 couponTemplateService; |
| | | |
| | | @PostMapping("") |
| | | @ApiOperation(value = "新增", notes = "新增") |
| | | public ResponseEntity<ReturnDataDTO> create(@Validated @RequestBody CreateCouponTemplatePointDTO dto) { |
| | | |
| | | // 信息校验 |
| | | valid(dto); |
| | | |
| | | CreateCouponTemplateBO couponTemplateBO = new CreateCouponTemplateBO(); |
| | | BeanUtils.copyProperties(dto, couponTemplateBO); |
| | | |
| | | // 设置成积分优惠券 |
| | | couponTemplateBO.setCategory(CouponCategoryEnum.POINT.getStatus()); |
| | | // 设置默认类型领取后有效 |
| | | couponTemplateBO.setUsageType(CouponUsageTypeEnum.GET_AFTER_TIME.getType()); |
| | | |
| | | couponTemplateService.createCouponTemplate(couponTemplateBO); |
| | | return returnData(R.SUCCESS.getCode(), null); |
| | | |
| | | |
| | | } |
| | | |
| | | @PutMapping("/{id}") |
| | | @ApiOperation(value = "修改", notes = "修改") |
| | | public ResponseEntity<ReturnDataDTO> update(@PathVariable String id,@Validated @RequestBody CreateCouponTemplatePointDTO dto) { |
| | | // 信息校验 |
| | | dto.setId(id); |
| | | valid(dto); |
| | | |
| | | CouponTemplateDO couponTemplateDO = couponTemplateService.getById(dto.getId()); |
| | | if (null == couponTemplateDO) { |
| | | throw new ValidationException("优惠券不存在"); |
| | | } |
| | | |
| | | CreateCouponTemplateBO couponTemplateBO = new CreateCouponTemplateBO(); |
| | | BeanUtils.copyProperties(couponTemplateDO,couponTemplateBO); |
| | | BeanUtils.copyProperties(dto, couponTemplateBO); |
| | | |
| | | // 设置成积分优惠券 |
| | | couponTemplateBO.setCategory(CouponCategoryEnum.POINT.getStatus()); |
| | | // 设置默认类型 |
| | | couponTemplateBO.setUsageType(CouponUsageTypeEnum.GET_AFTER_TIME.getType()); |
| | | |
| | | |
| | | couponTemplateService.updateCouponTemplate(couponTemplateBO); |
| | | |
| | | return returnData(R.SUCCESS.getCode(), null); |
| | | } |
| | | |
| | | @DeleteMapping("/{id}") |
| | | @ApiOperation(value = "删除", notes = "删除") |
| | | public ResponseEntity<ReturnDataDTO> delete(@PathVariable String id) { |
| | | |
| | | CouponTemplateDO couponTemplateDO = couponTemplateService.getById(id); |
| | | if (null == couponTemplateDO) { |
| | | throw new ValidationException("优惠券不存在"); |
| | | } |
| | | couponTemplateService.deleteCouponTemplate(id); |
| | | return returnData(R.SUCCESS.getCode(), null); |
| | | } |
| | | |
| | | @GetMapping("/{id}") |
| | | @ApiOperation(value = "详情", notes = "详情") |
| | | public ResponseEntity<ReturnDataDTO> get(@PathVariable String id) { |
| | | CouponTemplateVO couponTemplateVO = couponTemplateService.getDetailById(id); |
| | | return returnData(R.SUCCESS.getCode(), ConverterUtil.transObject(couponTemplateVO, CouponTemplatePointVO.class)); |
| | | } |
| | | |
| | | @GetMapping("/page") |
| | | @ApiOperation(value = "查询-分页", notes = "查询-分页") |
| | | public ResponseEntity<ReturnDataDTO<Page<CouponTemplatePointVO>>> page(Page page, QueryCouponDTO dto) { |
| | | // 设置只查询积分优惠券的 |
| | | dto.setCategory(CouponCategoryEnum.POINT.getStatus()); |
| | | Page<CouponTemplateVO> resultPage = couponTemplateService.getPage(page, dto); |
| | | return returnData(R.SUCCESS.getCode(), ConverterUtil.transPage(resultPage, CouponTemplatePointVO.class)); |
| | | } |
| | | |
| | | @GetMapping("/list") |
| | | @ApiOperation(value = "查询-全部", notes = "查询-全部") |
| | | public ResponseEntity<ReturnDataDTO<Page<CouponTemplateVO>>> list(QueryCouponDTO dto) { |
| | | // 设置只查询积分优惠券的 |
| | | dto.setCategory(CouponCategoryEnum.POINT.getStatus()); |
| | | return returnData(R.SUCCESS.getCode(), ConverterUtil.transList(couponTemplateService.getList(dto), CouponTemplatePointVO.class)); |
| | | } |
| | | |
| | | |
| | | @PutMapping("/active/{id}") |
| | | @ApiOperation(value = "发布", notes = "发布") |
| | | public ResponseEntity<ReturnDataDTO> active(@PathVariable String id) { |
| | | |
| | | CouponTemplateDO couponTemplateDO = couponTemplateService.getById(id); |
| | | if (null == couponTemplateDO) { |
| | | throw new ValidationException("优惠券不存在"); |
| | | } |
| | | |
| | | couponTemplateService.activeCouponTemplate(id); |
| | | |
| | | return returnData(R.SUCCESS.getCode(), null); |
| | | } |
| | | |
| | | @PutMapping("/expire/{id}") |
| | | @ApiOperation(value = "下架", notes = "下架") |
| | | public ResponseEntity<ReturnDataDTO> expire(@PathVariable String id) { |
| | | |
| | | CouponTemplateDO couponTemplateDO = couponTemplateService.getById(id); |
| | | if (null == couponTemplateDO) { |
| | | throw new ValidationException("优惠券不存在"); |
| | | } |
| | | |
| | | couponTemplateService.expireCouponTemplate(id); |
| | | |
| | | return returnData(R.SUCCESS.getCode(), null); |
| | | } |
| | | |
| | | @PostMapping("/batch/expire") |
| | | @ApiOperation(value = "批量下架", notes = "批量下架") |
| | | public ResponseEntity<ReturnDataDTO> expireBatch(@RequestBody BatchCouponTemplateDTO dto) { |
| | | |
| | | |
| | | couponTemplateService.expireBatchCouponTemplate(dto); |
| | | |
| | | return returnData(R.SUCCESS.getCode(), null); |
| | | } |
| | | |
| | | |
| | | |
| | | @PostMapping("/batch/active") |
| | | @ApiOperation(value = "批量发布", notes = "批量发布") |
| | | public ResponseEntity<ReturnDataDTO> activeBatch(@RequestBody BatchCouponTemplateDTO dto) { |
| | | |
| | | couponTemplateService.activeBatchCouponTemplate(dto); |
| | | |
| | | return returnData(R.SUCCESS.getCode(), null); |
| | | } |
| | | |
| | | |
| | | @PostMapping("/batch/del") |
| | | @ApiOperation(value = "批量删除", notes = "批量删除") |
| | | public ResponseEntity<ReturnDataDTO> deleteBatch(@RequestBody BatchCouponTemplateDTO dto) { |
| | | |
| | | couponTemplateService.deleteBatchCouponTemplate(dto); |
| | | return returnData(R.SUCCESS.getCode(), null); |
| | | } |
| | | |
| | | @GetMapping("/statistics") |
| | | @ApiOperation(value = "积分统计", notes = "积分统计") |
| | | public ResponseEntity<ReturnDataDTO> statistics(QueryCouponStatisticsDTO dto) { |
| | | QueryCouponStatisticsBO queryCouponStatisticsBO=new QueryCouponStatisticsBO(); |
| | | BeanUtils.copyProperties(dto,queryCouponStatisticsBO); |
| | | CouponPointStatisVO vo = couponTemplateService.statisCouponTemplatePoint(queryCouponStatisticsBO); |
| | | return returnData(R.SUCCESS.getCode(), vo); |
| | | } |
| | | |
| | | @GetMapping("/active/list") |
| | | @ApiOperation(value = "查询-全部", notes = "查询-全部") |
| | | public ResponseEntity<ReturnDataDTO<Page<CouponTemplateVO>>> activeList(QueryActivePointCouponDTO dto) { |
| | | // 设置只查询积分优惠券的 |
| | | dto.setCategory(CouponCategoryEnum.POINT.getStatus()); |
| | | dto.setStatus(CouponStatusEnum.ACTIVE.getStatus()); |
| | | return returnData(R.SUCCESS.getCode(), ConverterUtil.transList(couponTemplateService.getPointList(dto), CouponTemplatePointVO.class)); |
| | | } |
| | | |
| | | @GetMapping("/active/page") |
| | | @ApiOperation(value = "查询-分页", notes = "查询-分页") |
| | | public ResponseEntity<ReturnDataDTO<Page<CouponTemplatePointVO>>> activePage(Page page, QueryActivePointCouponDTO dto) { |
| | | // 设置只查询积分优惠券的 |
| | | dto.setCategory(CouponCategoryEnum.POINT.getStatus()); |
| | | dto.setStatus(CouponStatusEnum.ACTIVE.getStatus()); |
| | | Page<CouponTemplateVO> resultPage = couponTemplateService.getPointPage(page, dto); |
| | | return returnData(R.SUCCESS.getCode(), ConverterUtil.transPage(resultPage, CouponTemplatePointVO.class)); |
| | | } |
| | | |
| | | |
| | | private void valid(CreateCouponTemplatePointDTO dto){ |
| | | |
| | | if (StringUtils.isNotBlank(dto.getCouponDiscountType()) |
| | | && dto.getCouponDiscountType().equals(CouponTypeEnum.DISCOUNT.getType()) |
| | | && dto.getMinOrderAmount().compareTo(dto.getCouponDiscountValue()) < 0) { |
| | | throw new ValidationException("订单金额不能小于折扣金额"); |
| | | } |
| | | if (StringUtils.isNotBlank(dto.getCouponDiscountType()) |
| | | && dto.getCouponDiscountType().equals(CouponTypeEnum.DISCOUNT.getType()) |
| | | && dto.getCouponDiscountValue().compareTo(BigDecimal.ZERO) <= 0) { |
| | | throw new ValidationException("折扣金额必须大于0"); |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(dto.getCouponDiscountType()) |
| | | && dto.getCouponDiscountType().equals(CouponTypeEnum.ZERO.getType()) |
| | | && dto.getMinOrderAmount().compareTo(BigDecimal.ZERO) != 0) { |
| | | throw new ValidationException("无门槛的订单金额必须为0"); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | @PostMapping("/exchange") |
| | | @ApiOperation(value = "小程序-积分优惠券兑换", notes = "小程序-积分优惠券兑换") |
| | | public ResponseEntity<ReturnDataDTO> exchangeCoupon(@Validated @RequestBody ExchangeCouponDTO dto) { |
| | | couponTemplateService.exchangeCoupon(dto); |
| | | return returnData(R.SUCCESS.getCode(), null); |
| | | |
| | | |
| | | } |
| | | } |