CouponRulerApi.java 1.86 KB
package com.diligrp.etrade.coupon.api;

import com.diligrp.etrade.core.domain.Message;
import com.diligrp.etrade.coupon.domain.CouponForOrderDto;
import com.diligrp.etrade.coupon.model.CouponRulerResponseDo;
import com.diligrp.etrade.coupon.service.CouponRulerService;
import com.diligrp.etrade.coupon.util.TUtils;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.ObjectUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author jy
 * @Date 2023/9/11 10:22
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/coupon/ruler")
public class CouponRulerApi {
    Logger log = LoggerFactory.getLogger(CouponRulerApi.class);
    @Resource
    private CouponRulerService couponRulerService;
    /**
     * 下单验证优惠劵并计算出最优优惠劵及优惠金额和应付金额
     * @param couponForOrderDto
     * @return
     */
    @PostMapping("/validate")
    public Message<CouponRulerResponseDo> validate(@RequestBody CouponForOrderDto couponForOrderDto){
        log.info("下单验证优惠劵并计算出最优优惠劵及优惠金额和应付金额入参,{}",couponForOrderDto);
        TUtils.isTure(ObjectUtils.isEmpty(couponForOrderDto.getCustomerId())).throwMessage("客户信息不能为空");
        TUtils.isTure(ObjectUtils.isEmpty(couponForOrderDto.getMarketId())).throwMessage("市场信息不能为空");
        TUtils.isTure(ObjectUtils.isEmpty(couponForOrderDto.getAmount())).throwMessage("订单金额不能为空");
        CouponRulerResponseDo couponRulerResponseDo = couponRulerService.validate(couponForOrderDto);
        return Message.success(couponRulerResponseDo);
    }
}