| 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.CreateCouponTemplateDTO; | 
| import com.mzl.flower.dto.request.coupon.QueryCouponDTO; | 
| import com.mzl.flower.dto.response.coupon.CouponTemplateActivyVO; | 
| import com.mzl.flower.enums.CouponUsageTypeEnum; | 
| import com.mzl.flower.service.coupon.CouponTemplateService2; | 
| import io.swagger.annotations.ApiOperation; | 
| import org.apache.commons.lang3.StringUtils; | 
| 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 com.mzl.flower.entity.coupon.CouponTemplateDO; | 
|   | 
|   | 
| /** | 
| * @author @TaoJie | 
| * @since 2024-08-22 | 
| */ | 
| @RestController | 
| @RequestMapping("/api/v2/coupon/all") | 
| //@Api(value = "优惠券管理-活动", tags = "优惠券管理-活动") | 
| @Validated | 
| public class CouponTemplateController extends BaseController { | 
|   | 
|     @Autowired | 
|     CouponTemplateService2 couponTemplateService; | 
|   | 
|     @PostMapping("") | 
|     @ApiOperation(value = "新增优惠券", notes = "新增优惠券") | 
|     public ResponseEntity<ReturnDataDTO> create(@Validated @RequestBody CreateCouponTemplateDTO dto) { | 
|   | 
|         // 信息验证 | 
|         valid(dto); | 
|   | 
| //        couponTemplateService.createCouponTemplate(dto); | 
|         return returnData(R.SUCCESS.getCode(), null); | 
|     } | 
|   | 
|     @PutMapping("/{id}") | 
|     @ApiOperation(value = "修改", notes = "修改") | 
|     public ResponseEntity<ReturnDataDTO>  update(@Validated @RequestBody CreateCouponTemplateDTO dto) { | 
|   | 
|         CouponTemplateDO couponTemplateDO= couponTemplateService.getById(dto.getId()); | 
|         if(null==couponTemplateDO){ | 
|             throw new ValidationException("优惠券不存在"); | 
|         } | 
|   | 
|         // 信息验证 | 
|         valid(dto); | 
|   | 
| //        couponTemplateService.updateCouponTemplate(dto); | 
|   | 
|         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) { | 
| //        CouponTemplateActivyVO couponTemplateActivyVO=couponTemplateService.getActivityCouponDetailById(id); | 
|         return returnData(R.SUCCESS.getCode(),null); | 
|     } | 
|   | 
|     @GetMapping("/page") | 
|     @ApiOperation(value = "查询-分页", notes = "查询-分页") | 
|     public ResponseEntity<ReturnDataDTO<Page<CouponTemplateActivyVO>>> page( | 
|             Page page, QueryCouponDTO dto | 
|     ) { | 
| //        couponTemplateService.getActivityPage(page,dto); | 
|         return returnData(R.SUCCESS.getCode(), null); | 
|     } | 
|   | 
|     @GetMapping("/list") | 
|     @ApiOperation(value = "查询-全部", notes = "查询-全部") | 
|     public ResponseEntity<ReturnDataDTO<Page<CouponTemplateActivyVO>>> list(QueryCouponDTO dto | 
|     ) { | 
| //        couponTemplateService.getActivityList(dto) | 
|         return returnData(R.SUCCESS.getCode(), null); | 
|     } | 
|   | 
|   | 
|     @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(CreateCouponTemplateDTO dto){ | 
|         // 领取后 固定时间 | 
|         if(StringUtils.isNotBlank(dto.getUsageType()) && dto.getUsageType().equals(CouponUsageTypeEnum.FIXED.getType()) ){ | 
|             // 如果使用时间是固定时间的话,那么固定时间的开始时间和结束时间就不能为空 | 
|             if(dto.getUsageStartDate()==null){ | 
|                 throw new ValidationException("固定时间开始日期不能为空"); | 
|             } | 
|             if(dto.getUsageEndDate()==null){ | 
|                 throw new ValidationException("固定时间结束日期不能为空"); | 
|             } | 
|         } | 
|   | 
|         // 领取后 有效时间 | 
|         if(StringUtils.isNotBlank(dto.getUsageType()) && dto.getUsageType().equals(CouponUsageTypeEnum.GET_AFTER_TIME.getType())){ | 
|             // 如果使用时间是领取后有效时间的话,那么领取后的时间类型不能为空,且时间不能为空 | 
|             if(StringUtils.isBlank(dto.getUsageTimeType())){ | 
|                 throw new ValidationException("领取后有效时间类型不能为空"); | 
|             } | 
|   | 
|             if(dto.getUsageTimeNum()==null){ | 
|                 throw new ValidationException("领取后有效时间整数不能为空"); | 
|             } | 
|             if(dto.getUsageTimeNum()<=0){ | 
|                 throw new ValidationException("领取后有效时间整数需要大于0"); | 
|             } | 
|         } | 
|     } | 
|   | 
| } |