对比新文件 |
| | |
| | | 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.CreateCouponRecordDTO; |
| | | import com.mzl.flower.dto.request.coupon.QueryCouponRecordDTO; |
| | | import com.mzl.flower.dto.response.coupon.CouponRecordResultVO; |
| | | import com.mzl.flower.dto.response.coupon.CouponRecordVO; |
| | | import com.mzl.flower.entity.coupon.CouponRecordDO; |
| | | import com.mzl.flower.entity.coupon.CouponTemplateDO; |
| | | import com.mzl.flower.enums.CouponStatusEnum; |
| | | import com.mzl.flower.service.coupon.CouponRecordService; |
| | | 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.factory.annotation.Autowired; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | |
| | | /** |
| | | * @author @TaoJie |
| | | * @since 2024-08-27 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/v2/coupon-record") |
| | | @Api(value = "优惠券记录管理-活动", tags = "优惠券记录管理") |
| | | @Validated |
| | | public class CouponRecordController extends BaseController { |
| | | |
| | | @Autowired |
| | | CouponRecordService couponRecordService; |
| | | |
| | | @Autowired |
| | | private CouponTemplateService2 couponTemplateService; |
| | | |
| | | |
| | | @PostMapping("") |
| | | @ApiOperation(value = "新增", notes = "新增") |
| | | public ResponseEntity<ReturnDataDTO> create(@Validated @RequestBody CreateCouponRecordDTO dto) { |
| | | |
| | | final CouponTemplateDO couponTemplateDO = couponTemplateService.getById(dto.getCouponId()); |
| | | if(null==couponTemplateDO){ |
| | | throw new ValidationException("优惠券不存在"); |
| | | } |
| | | |
| | | if(StringUtils.isNotBlank(couponTemplateDO.getStatus()) && couponTemplateDO.getStatus().equals(CouponStatusEnum.INACTIVE.getStatus())){ |
| | | throw new ValidationException("优惠券还未发布"); |
| | | } |
| | | if(StringUtils.isNotBlank(couponTemplateDO.getStatus()) && couponTemplateDO.getStatus().equals(CouponStatusEnum.EXPIRED.getStatus())){ |
| | | throw new ValidationException("优惠券已下架"); |
| | | } |
| | | |
| | | couponRecordService.createCouponRecord(dto); |
| | | return returnData(R.SUCCESS.getCode(), null); |
| | | } |
| | | |
| | | @PutMapping("/{id}") |
| | | @ApiOperation(value = "修改", notes = "修改") |
| | | public ResponseEntity<ReturnDataDTO> update(@PathVariable String id,@Validated @RequestBody CreateCouponRecordDTO dto) { |
| | | |
| | | dto.setId(id); |
| | | |
| | | CouponRecordDO couponRecordDO= couponRecordService.getById(dto.getId()); |
| | | if(null==couponRecordDO){ |
| | | throw new ValidationException("优惠券记录不存在"); |
| | | } |
| | | |
| | | return returnData(R.SUCCESS.getCode(), couponRecordService.updateCouponRecord(dto)); |
| | | } |
| | | |
| | | @DeleteMapping("/{id}") |
| | | @ApiOperation(value = "删除", notes = "删除") |
| | | public ResponseEntity<ReturnDataDTO> delete(@PathVariable String id ) { |
| | | |
| | | CouponRecordDO couponRecordDO= couponRecordService.getById(id); |
| | | if(null==couponRecordDO){ |
| | | throw new ValidationException("优惠券记录不存在"); |
| | | } |
| | | couponRecordService.deleteCouponRecord(id); |
| | | return returnData(R.SUCCESS.getCode(), null); |
| | | } |
| | | |
| | | @GetMapping("/{id}") |
| | | @ApiOperation(value = "详情", notes = "详情") |
| | | public ResponseEntity<ReturnDataDTO> get(@PathVariable String id) { |
| | | CouponRecordVO couponRecordVO=couponRecordService.getCouponRecordById(id); |
| | | return returnData(R.SUCCESS.getCode(),ConverterUtil.transObject(couponRecordVO, CouponRecordResultVO.class)); |
| | | } |
| | | |
| | | @GetMapping("/page") |
| | | @ApiOperation(value = "查询-分页", notes = "查询-分页") |
| | | public ResponseEntity<ReturnDataDTO<Page<CouponRecordVO>>> page( |
| | | Page page, QueryCouponRecordDTO dto |
| | | ) { |
| | | return returnData(R.SUCCESS.getCode(), ConverterUtil.transPage(couponRecordService.getPage(page,dto), CouponRecordResultVO.class)); |
| | | } |
| | | |
| | | @GetMapping("/list") |
| | | @ApiOperation(value = "查询-全部", notes = "查询-全部") |
| | | public ResponseEntity<ReturnDataDTO<Page<CouponRecordVO>>> list(QueryCouponRecordDTO dto |
| | | ) { |
| | | return returnData(R.SUCCESS.getCode(),ConverterUtil.transList(couponRecordService.getList(dto), CouponRecordResultVO.class)); |
| | | |
| | | } |
| | | |
| | | } |