diff --git a/cweb/src/main/java/com/cweb/controller/discount/DiscountController.java b/cweb/src/main/java/com/cweb/controller/discount/DiscountController.java index 50ea6f0..d64e310 100644 --- a/cweb/src/main/java/com/cweb/controller/discount/DiscountController.java +++ b/cweb/src/main/java/com/cweb/controller/discount/DiscountController.java @@ -31,6 +31,10 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Collectors; @Controller @RequestMapping(value="/discount") @@ -78,32 +82,45 @@ public class DiscountController { // 用户session UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class); - Map mapSpecs = new HashMap<>(); - mapSpecs.put("specsIds", specsIds); + Map map = new HashMap<>(); + + map.put("userId", userSession.getUser().getId()); + map.put("status", 1); + + List list = discountUserRelService.getList(map); - // 查询规格可用优惠券 - List couponDiscountGoodsRel = couponDiscountService.getListGoodsRel(mapSpecs); + List listDiscount = list.stream().filter(distinctByKey(CouponDiscountUserRel::getDiscountId)).collect(Collectors.toList()); - if (couponDiscountGoodsRel == null) { - return ResponseMsgUtil.success(null); - } + List listFind = new ArrayList<>(); + listDiscount.forEach(d -> { + Map mapSpecs = new HashMap<>(); + mapSpecs.put("discountId", d.getDiscountId()); + // 查询规格可用优惠券 + List couponDiscountGoodsRel = couponDiscountService.getListGoodsRel(mapSpecs); + List specsIdList = new ArrayList<>(); - List list = new ArrayList<>(); + couponDiscountGoodsRel.forEach(dg -> { + specsIdList.add(dg.getSpecsId()); + }); + String specsIdsStr = StringUtils.join(specsIdList, ","); - for(CouponDiscountGoodsRel rel : couponDiscountGoodsRel) { - Map map = new HashMap<>(); + if (specsIdsStr.contains(specsIds)) { + listFind.add(d); + } + }); - map.put("userId", userSession.getUser().getId()); - map.put("status", 1); - map.put("discountId", rel.getDiscountId()); - CouponDiscountUserRel couponDiscountUserRel = discountUserRelService.getRel(map); - list.add(couponDiscountUserRel); - } + List filteredList = list.stream() + .filter(obj -> listFind.stream() + .map(CouponDiscountUserRel::getDiscountId) + .collect(Collectors.toList()) + .contains(obj.getDiscountId())) + .collect(Collectors.toList()); - return ResponseMsgUtil.success(list); + + return ResponseMsgUtil.success(filteredList); } catch (Exception e) { log.error("GoodsDetailController --> getListUser() error!", e); @@ -111,6 +128,11 @@ public class DiscountController { } } + private static Predicate distinctByKey(Function keyExtractor) { + Set seen = ConcurrentHashMap.newKeySet(); + return t -> seen.add(keyExtractor.apply(t)); + } + } diff --git a/service/src/main/java/com/hfkj/service/order/impl/BsOrderChildServiceImpl.java b/service/src/main/java/com/hfkj/service/order/impl/BsOrderChildServiceImpl.java index 126dc2d..266b76b 100644 --- a/service/src/main/java/com/hfkj/service/order/impl/BsOrderChildServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/order/impl/BsOrderChildServiceImpl.java @@ -94,9 +94,6 @@ public class BsOrderChildServiceImpl implements BsOrderChildService { } - - - orderChildModelList.add(childModel); } return orderChildModelList; diff --git a/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java b/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java index c3c616b..50d86ef 100644 --- a/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java @@ -1,6 +1,5 @@ package com.hfkj.service.order.impl; -import com.alibaba.fastjson.JSONObject; import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; @@ -8,7 +7,6 @@ import com.hfkj.common.utils.DateUtil; import com.hfkj.common.utils.RandomUtils; import com.hfkj.common.utils.RedisUtil; import com.hfkj.dao.BsOrderMapper; -import com.hfkj.dao.CouponDiscountGoodsRelMapper; import com.hfkj.entity.*; import com.hfkj.model.order.OrderChildModel; import com.hfkj.model.order.OrderModel; @@ -34,7 +32,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; -import org.thymeleaf.util.DateUtils; import javax.annotation.Resource; import java.math.BigDecimal; @@ -131,6 +128,11 @@ public class BsOrderServiceImpl implements BsOrderService { } else if (child.getProductType().equals(OrderChildProductTypeEnum.type2.getCode())) { // 提交订单虚拟商品处理 + // todo 1.0阶段暂时需要返回收货地址使用 + order.setBusiness(child.getBusiness()); + } + // 提交订单前产品处理 + if (child.getProductType().equals(OrderChildProductTypeEnum.type2.getCode())) { child = orderCreateService.product(order, child); } child.setProductTotalPrice(child.getProductPrice().multiply(new BigDecimal(child.getProductCount().toString())));