对比新文件 |
| | |
| | | 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.CouponTemplateVO; |
| | | import com.mzl.flower.dto.response.coupon.CouponTemplateVipVO; |
| | | import com.mzl.flower.entity.coupon.CouponTemplateDO; |
| | | import com.mzl.flower.entity.menber.Member; |
| | | import com.mzl.flower.enums.CouponCategoryEnum; |
| | | import com.mzl.flower.enums.CouponTypeEnum; |
| | | import com.mzl.flower.service.coupon.CouponTemplateService2; |
| | | import com.mzl.flower.service.menber.MemberService; |
| | | 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/vip") |
| | | @Api(value = "优惠券管理-会员", tags = "优惠券管理-会员") |
| | | @Validated |
| | | public class CouponTemplateVipController extends BaseController { |
| | | |
| | | @Autowired |
| | | CouponTemplateService2 couponTemplateService; |
| | | |
| | | @Autowired |
| | | MemberService memberService; |
| | | |
| | | @PostMapping("") |
| | | @ApiOperation(value = "新增", notes = "新增") |
| | | public ResponseEntity<ReturnDataDTO> create(@Validated @RequestBody CreateCouponTemplateVipDTO dto) { |
| | | |
| | | // 信息验证 |
| | | valid(dto); |
| | | |
| | | CreateCouponTemplateBO couponTemplateBO = new CreateCouponTemplateBO(); |
| | | BeanUtils.copyProperties(dto, couponTemplateBO); |
| | | |
| | | // 设置成会员优惠券 |
| | | couponTemplateBO.setCategory(CouponCategoryEnum.MEMBER.getStatus()); |
| | | |
| | | couponTemplateService.createCouponTemplate(couponTemplateBO); |
| | | |
| | | return returnData(R.SUCCESS.getCode(), null); |
| | | } |
| | | |
| | | @PutMapping("/{id}") |
| | | @ApiOperation(value = "修改", notes = "修改") |
| | | public ResponseEntity<ReturnDataDTO> update(@PathVariable String id,@Validated @RequestBody CreateCouponTemplateVipDTO 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.MEMBER.getStatus()); |
| | | |
| | | 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, CouponTemplateVipVO.class)); |
| | | } |
| | | |
| | | @GetMapping("/page") |
| | | @ApiOperation(value = "查询-分页", notes = "查询-分页") |
| | | public ResponseEntity<ReturnDataDTO<Page<CouponTemplateVipVO>>> page( |
| | | Page page, QueryCouponDTO dto |
| | | ) { |
| | | // 设置只查询会员优惠券的 |
| | | dto.setCategory(CouponCategoryEnum.MEMBER.getStatus()); |
| | | Page<CouponTemplateVO> resultPage = couponTemplateService.getPage(page, dto); |
| | | return returnData(R.SUCCESS.getCode(), ConverterUtil.transPage(resultPage, CouponTemplateVipVO.class)); |
| | | |
| | | } |
| | | |
| | | @GetMapping("/list") |
| | | @ApiOperation(value = "查询-全部", notes = "查询-全部") |
| | | public ResponseEntity<ReturnDataDTO<Page<CouponTemplateVipVO>>> list(QueryCouponDTO dto |
| | | ) { |
| | | dto.setCategory(CouponCategoryEnum.MEMBER.getStatus()); |
| | | return returnData(R.SUCCESS.getCode(), ConverterUtil.transList(couponTemplateService.getList(dto), CouponTemplateVipVO.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); |
| | | } |
| | | |
| | | |
| | | private void valid(CreateCouponTemplateVipDTO dto){ |
| | | |
| | | final Member member = memberService.getById(dto.getMemberId()); |
| | | |
| | | if(null==member){ |
| | | throw new ValidationException("会员等级不存在"); |
| | | } |
| | | |
| | | 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"); |
| | | } |
| | | |
| | | } |
| | | } |