feat(orders.manager):新增查询用户可用优惠卷的功能
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.jzo2o.orders.manager.controller.consumer;
|
||||
|
||||
import com.jzo2o.api.market.dto.response.AvailableCouponsResDTO;
|
||||
import com.jzo2o.api.orders.dto.request.OrderCancelReqDTO;
|
||||
import com.jzo2o.api.orders.dto.response.OrderResDTO;
|
||||
import com.jzo2o.api.orders.dto.response.OrderSimpleResDTO;
|
||||
@@ -104,4 +105,15 @@ public class ConsumerOrdersController {
|
||||
.currentUserType(currentUser.getUserType())
|
||||
.build());
|
||||
}
|
||||
|
||||
@GetMapping("/getAvailableCoupons")
|
||||
@ApiOperation("获取可用优惠券")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "serveId", value = "服务id", required = true, dataTypeClass = Integer.class),
|
||||
@ApiImplicitParam(name = "purNum", value = "购买数量,默认1", dataTypeClass = Long.class)
|
||||
})
|
||||
public List<AvailableCouponsResDTO> getAvailableCoupons(@RequestParam Long serveId,
|
||||
@RequestParam(required = false, defaultValue = "1") Integer purNum) {
|
||||
return ordersCreateService.getAvailableCoupons(serveId, purNum);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,15 @@
|
||||
package com.jzo2o.orders.manager.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.jzo2o.api.market.dto.response.AvailableCouponsResDTO;
|
||||
import com.jzo2o.orders.base.model.domain.Orders;
|
||||
import com.jzo2o.orders.manager.model.dto.request.OrdersPayReqDTO;
|
||||
import com.jzo2o.orders.manager.model.dto.request.PlaceOrderReqDTO;
|
||||
import com.jzo2o.orders.manager.model.dto.response.OrdersPayResDTO;
|
||||
import com.jzo2o.orders.manager.model.dto.response.PlaceOrderResDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 下单服务类
|
||||
@@ -35,4 +38,9 @@ public interface IOrdersCreateService extends IService<Orders> {
|
||||
* 客户端获取支付状态
|
||||
*/
|
||||
OrdersPayResDTO getPayResult(Long id);
|
||||
|
||||
/**
|
||||
* 客户端获取可用优惠卷
|
||||
*/
|
||||
List<AvailableCouponsResDTO> getAvailableCoupons(Long serveId, Integer purNum);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.jzo2o.orders.manager.service.client;
|
||||
|
||||
import com.alibaba.csp.sentinel.annotation.SentinelResource;
|
||||
import com.alibaba.csp.sentinel.slots.block.BlockException;
|
||||
import com.jzo2o.api.foundations.ServeApi;
|
||||
import com.jzo2o.api.foundations.dto.response.ServeAggregationResDTO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 自定义Feign客户端用于熔断降级
|
||||
* @author JIAN
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@SuppressWarnings("unused")
|
||||
public class FoundationClient {
|
||||
@Resource
|
||||
private ServeApi serveApi;
|
||||
|
||||
@SentinelResource(value = "serveById",
|
||||
fallback = "getServeByIdFallback", blockHandler = "getServeByIdBlockHandler")
|
||||
public ServeAggregationResDTO getServeById(Long id) {
|
||||
return serveApi.findById(id);
|
||||
}
|
||||
|
||||
public ServeAggregationResDTO getServeByIdFallback(Long id, Throwable throwable) {
|
||||
log.warn("服务信息接口异常(未触发熔断), 服务id: {}", id, throwable);
|
||||
return null;
|
||||
}
|
||||
|
||||
public ServeAggregationResDTO getServeByIdBlockHandler(Long id, BlockException blockException) {
|
||||
log.warn("服务信息接口异常(触发熔断降级), 服务id: {}", id, blockException);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.jzo2o.orders.manager.service.client;
|
||||
|
||||
import com.alibaba.csp.sentinel.annotation.SentinelResource;
|
||||
import com.alibaba.csp.sentinel.slots.block.BlockException;
|
||||
import com.jzo2o.api.market.CouponApi;
|
||||
import com.jzo2o.api.market.dto.response.AvailableCouponsResDTO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 自定义Feign客户端用于熔断降级
|
||||
* @author JIAN
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@SuppressWarnings("unused")
|
||||
public class MarketClient {
|
||||
@Resource
|
||||
private CouponApi couponApi;
|
||||
|
||||
@SentinelResource(value = "availableCoupon",
|
||||
fallback = "getAvailableCouponFallback", blockHandler = "getAvailableCouponBlockHandler")
|
||||
public List<AvailableCouponsResDTO> getAvailableCoupon(BigDecimal totalAmount) {
|
||||
return couponApi.getAvailableCoupon(totalAmount);
|
||||
}
|
||||
|
||||
public List<AvailableCouponsResDTO> getAvailableCouponFallback(BigDecimal totalAmount, Throwable throwable) {
|
||||
log.warn("优惠卷接口异常(未触发熔断), 总金额: {}", totalAmount, throwable);
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<AvailableCouponsResDTO> getAvailableCouponBlockHandler(BigDecimal totalAmount, BlockException blockException) {
|
||||
log.warn("优惠卷接口异常(触发熔断降级), 总金额: {}", totalAmount, blockException);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.jzo2o.orders.manager.service.impl;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jzo2o.api.customer.dto.response.AddressBookResDTO;
|
||||
import com.jzo2o.api.foundations.dto.response.ServeAggregationResDTO;
|
||||
import com.jzo2o.api.market.dto.response.AvailableCouponsResDTO;
|
||||
import com.jzo2o.api.trade.NativePayApi;
|
||||
import com.jzo2o.api.trade.TradingApi;
|
||||
import com.jzo2o.api.trade.dto.request.NativePayReqDTO;
|
||||
@@ -10,6 +11,7 @@ import com.jzo2o.api.trade.dto.response.NativePayResDTO;
|
||||
import com.jzo2o.api.trade.dto.response.TradingResDTO;
|
||||
import com.jzo2o.api.trade.enums.PayChannelEnum;
|
||||
import com.jzo2o.api.trade.enums.TradingStateEnum;
|
||||
import com.jzo2o.common.expcetions.BadRequestException;
|
||||
import com.jzo2o.common.expcetions.CommonException;
|
||||
import com.jzo2o.common.expcetions.ForbiddenOperationException;
|
||||
import com.jzo2o.common.utils.BeanUtils;
|
||||
@@ -30,6 +32,8 @@ import com.jzo2o.orders.manager.model.dto.response.PlaceOrderResDTO;
|
||||
import com.jzo2o.orders.manager.porperties.TradeProperties;
|
||||
import com.jzo2o.orders.manager.service.IOrdersCreateService;
|
||||
import com.jzo2o.orders.manager.service.client.CustomerClient;
|
||||
import com.jzo2o.orders.manager.service.client.FoundationClient;
|
||||
import com.jzo2o.orders.manager.service.client.MarketClient;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -38,6 +42,9 @@ import org.springframework.transaction.support.TransactionTemplate;
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -49,6 +56,10 @@ import java.time.LocalDateTime;
|
||||
@Slf4j
|
||||
@Service
|
||||
public class OrdersCreateServiceImpl extends ServiceImpl<OrdersMapper, Orders> implements IOrdersCreateService {
|
||||
@Resource
|
||||
private MarketClient marketClient;
|
||||
@Resource
|
||||
private FoundationClient foundationClient;
|
||||
@Resource
|
||||
private CustomerClient customerClient;
|
||||
@Resource
|
||||
@@ -224,4 +235,17 @@ public class OrdersCreateServiceImpl extends ServiceImpl<OrdersMapper, Orders> i
|
||||
|
||||
return ordersPayResDTO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AvailableCouponsResDTO> getAvailableCoupons(Long serveId, Integer purNum) {
|
||||
ServeAggregationResDTO serve = foundationClient.getServeById(serveId);
|
||||
if (ObjectUtils.isEmpty(serve) || serve.getSaleStatus() != 2) {
|
||||
throw new BadRequestException("服务不可用");
|
||||
}
|
||||
|
||||
BigDecimal totalAmount = serve.getPrice().multiply(BigDecimal.valueOf(purNum));
|
||||
return Optional
|
||||
.ofNullable(marketClient.getAvailableCoupon(totalAmount))
|
||||
.orElseGet(ArrayList::new);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user