| | |
| | | import com.dsh.activity.feignclient.other.model.StoreDetailOfCourse; |
| | | import com.dsh.activity.mapper.*; |
| | | import com.dsh.activity.model.ConponJsonRuleModel; |
| | | import com.dsh.activity.model.CouponDeductionQuery; |
| | | import com.dsh.activity.model.CouponDeductionVO; |
| | | import com.dsh.activity.model.CouponListVo; |
| | | import com.dsh.activity.model.request.CouponPackageReq; |
| | | import com.dsh.activity.model.response.CouponPackageResp; |
| | |
| | | import com.dsh.activity.util.GDMapGeocodingUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.math.BigDecimal; |
| | | import java.util.Collections; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Service |
| | | public class UserCouponServiceImpl extends ServiceImpl<UserCouponMapper, UserCoupon> implements UserCouponService { |
| | | |
| | | private static final Logger LOGGER = LoggerFactory.getLogger(UserCouponServiceImpl.class); |
| | | |
| | | @Resource |
| | | private CoursePackageClient coursePackageClient; |
| | |
| | | |
| | | @Resource |
| | | private SiteClient siteClient; |
| | | |
| | | /** |
| | | * 批量解析已核销优惠券的固定抵扣金额,避免统计页面逐条远程查询优惠券。 |
| | | * |
| | | * @param query 用户优惠券领取记录 ID 集合 |
| | | * @return 每条领取记录对应的抵扣金额;无固定抵扣规则时返回 0 |
| | | */ |
| | | @Override |
| | | public List<CouponDeductionVO> queryDeductionAmounts(CouponDeductionQuery query) { |
| | | if (query == null || query.getUserCouponIds() == null || query.getUserCouponIds().isEmpty()) { |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | Set<Long> userCouponIds = new LinkedHashSet<>(query.getUserCouponIds()); |
| | | List<UserCoupon> userCoupons = this.list(new QueryWrapper<UserCoupon>() |
| | | .in("id", userCouponIds)); |
| | | if (userCoupons.isEmpty()) { |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | Set<Integer> couponIds = userCoupons.stream() |
| | | .map(UserCoupon::getCouponId) |
| | | .filter(java.util.Objects::nonNull) |
| | | .collect(Collectors.toSet()); |
| | | List<Coupon> coupons = couponIds.isEmpty() |
| | | ? Collections.emptyList() |
| | | : couponMapper.selectBatchIds(couponIds); |
| | | Map<Integer, Coupon> couponMap = coupons.stream() |
| | | .collect(Collectors.toMap(Coupon::getId, coupon -> coupon)); |
| | | |
| | | List<CouponDeductionVO> result = new ArrayList<>(); |
| | | for (UserCoupon userCoupon : userCoupons) { |
| | | CouponDeductionVO deduction = new CouponDeductionVO(); |
| | | deduction.setUserCouponId(userCoupon.getId()); |
| | | deduction.setDeductionAmount(getCouponDeductionAmount(couponMap.get(userCoupon.getCouponId()))); |
| | | result.add(deduction); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** 解析优惠券规则中的固定抵扣金额。 */ |
| | | private BigDecimal getCouponDeductionAmount(Coupon coupon) { |
| | | if (coupon == null || coupon.getContent() == null) { |
| | | return BigDecimal.ZERO; |
| | | } |
| | | try { |
| | | JSONObject content = JSON.parseObject(coupon.getContent()); |
| | | BigDecimal deductionAmount = content.getBigDecimal("deductionAmount"); |
| | | return deductionAmount == null ? BigDecimal.ZERO : deductionAmount.max(BigDecimal.ZERO); |
| | | } catch (Exception e) { |
| | | LOGGER.warn("解析优惠券抵扣规则失败,couponId={}", coupon.getId(), e); |
| | | return BigDecimal.ZERO; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | |
| | | if (userCoupon.getStatus() == 2) { |
| | | packageResp.setUseStatus(2); |
| | | } |
| | | if (userCoupon.getStatus() == 3) { |
| | | packageResp.setUseStatus(3); |
| | | } |
| | | respList.add(packageResp); |
| | | } |
| | | if (null != req.getCouponType()) { |