master
袁野 6 months ago
parent 8c0b6544e7
commit bf747e76f3
  1. 54
      cweb/src/main/java/com/cweb/controller/discount/DiscountController.java
  2. 3
      service/src/main/java/com/hfkj/service/order/impl/BsOrderChildServiceImpl.java
  3. 8
      service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.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<String, Object> mapSpecs = new HashMap<>();
mapSpecs.put("specsIds", specsIds);
Map<String, Object> map = new HashMap<>();
// 查询规格可用优惠券
List<CouponDiscountGoodsRel> couponDiscountGoodsRel = couponDiscountService.getListGoodsRel(mapSpecs);
map.put("userId", userSession.getUser().getId());
map.put("status", 1);
if (couponDiscountGoodsRel == null) {
return ResponseMsgUtil.success(null);
}
List<CouponDiscountUserRel> list = discountUserRelService.getList(map);
List<CouponDiscountUserRel> listDiscount = list.stream().filter(distinctByKey(CouponDiscountUserRel::getDiscountId)).collect(Collectors.toList());
List<CouponDiscountUserRel> list = new ArrayList<>();
List<CouponDiscountUserRel> listFind = new ArrayList<>();
for(CouponDiscountGoodsRel rel : couponDiscountGoodsRel) {
Map<String, Object> map = new HashMap<>();
listDiscount.forEach(d -> {
Map<String, Object> mapSpecs = new HashMap<>();
mapSpecs.put("discountId", d.getDiscountId());
// 查询规格可用优惠券
List<CouponDiscountGoodsRel> couponDiscountGoodsRel = couponDiscountService.getListGoodsRel(mapSpecs);
List<Long> specsIdList = new ArrayList<>();
map.put("userId", userSession.getUser().getId());
map.put("status", 1);
map.put("discountId", rel.getDiscountId());
CouponDiscountUserRel couponDiscountUserRel = discountUserRelService.getRel(map);
list.add(couponDiscountUserRel);
couponDiscountGoodsRel.forEach(dg -> {
specsIdList.add(dg.getSpecsId());
});
String specsIdsStr = StringUtils.join(specsIdList, ",");
if (specsIdsStr.contains(specsIds)) {
listFind.add(d);
}
});
return ResponseMsgUtil.success(list);
List<CouponDiscountUserRel> filteredList = list.stream()
.filter(obj -> listFind.stream()
.map(CouponDiscountUserRel::getDiscountId)
.collect(Collectors.toList())
.contains(obj.getDiscountId()))
.collect(Collectors.toList());
return ResponseMsgUtil.success(filteredList);
} catch (Exception e) {
log.error("GoodsDetailController --> getListUser() error!", e);
@ -111,6 +128,11 @@ public class DiscountController {
}
}
private static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
Set<Object> seen = ConcurrentHashMap.newKeySet();
return t -> seen.add(keyExtractor.apply(t));
}
}

@ -93,9 +93,6 @@ public class BsOrderChildServiceImpl implements BsOrderChildService {
}
orderChildModelList.add(childModel);
}
return orderChildModelList;

@ -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())));

Loading…
Cancel
Save