|
|
|
@ -9,10 +9,7 @@ import com.hfkj.common.exception.SysCode; |
|
|
|
|
import com.hfkj.common.security.SessionObject; |
|
|
|
|
import com.hfkj.common.security.UserCenter; |
|
|
|
|
import com.hfkj.common.utils.ResponseMsgUtil; |
|
|
|
|
import com.hfkj.entity.CouponDiscount; |
|
|
|
|
import com.hfkj.entity.CouponDiscountGoodsRel; |
|
|
|
|
import com.hfkj.entity.GoodsMsg; |
|
|
|
|
import com.hfkj.entity.GoodsSpecs; |
|
|
|
|
import com.hfkj.entity.*; |
|
|
|
|
import com.hfkj.model.ResponseData; |
|
|
|
|
import com.hfkj.model.SecUserSessionObject; |
|
|
|
|
import com.hfkj.model.UserSessionObject; |
|
|
|
@ -34,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") |
|
|
|
@ -47,6 +48,8 @@ public class DiscountController { |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private CouponDiscountUserRelService discountUserRelService; |
|
|
|
|
@Resource |
|
|
|
|
private CouponDiscountService couponDiscountService; |
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/getListUserDiscount", method = RequestMethod.GET) |
|
|
|
|
@ResponseBody |
|
|
|
@ -70,6 +73,66 @@ public class DiscountController { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/getGoodsDiscount", method = RequestMethod.GET) |
|
|
|
|
@ResponseBody |
|
|
|
|
@ApiOperation(value = "获取商品可用优惠券") |
|
|
|
|
public ResponseData getGoodsDiscount(@RequestParam(value = "specsIds", required = true) String specsIds) { |
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
// 用户session
|
|
|
|
|
UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
map.put("userId", userSession.getUser().getId()); |
|
|
|
|
map.put("status", 1); |
|
|
|
|
|
|
|
|
|
List<CouponDiscountUserRel> list = discountUserRelService.getList(map); |
|
|
|
|
|
|
|
|
|
List<CouponDiscountUserRel> listDiscount = list.stream().filter(distinctByKey(CouponDiscountUserRel::getDiscountId)).collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
List<CouponDiscountUserRel> listFind = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
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<>(); |
|
|
|
|
|
|
|
|
|
couponDiscountGoodsRel.forEach(dg -> { |
|
|
|
|
specsIdList.add(dg.getSpecsId()); |
|
|
|
|
}); |
|
|
|
|
String specsIdsStr = StringUtils.join(specsIdList, ","); |
|
|
|
|
|
|
|
|
|
if (specsIdsStr.contains(specsIds)) { |
|
|
|
|
listFind.add(d); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
return ResponseMsgUtil.exception(e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) { |
|
|
|
|
Set<Object> seen = ConcurrentHashMap.newKeySet(); |
|
|
|
|
return t -> seen.add(keyExtractor.apply(t)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|