|
|
@@ -16,7 +16,9 @@ import org.springframework.data.domain.Page;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
@@ -35,16 +37,35 @@ public class UserCouponService {
|
|
|
}
|
|
|
|
|
|
public Page<UserCouponDTO> backAll(@RequestBody PageQuery pageQuery) {
|
|
|
- Map<Long, String> couponName = couponRepo.findAll()
|
|
|
- .stream()
|
|
|
+ Map<String, Object> query = pageQuery.getQuery();
|
|
|
+
|
|
|
+ Long attractionsId = JpaUtils.getLong(query, "attractionsId");
|
|
|
+
|
|
|
+ List<Coupon> coupons;
|
|
|
+ if (attractionsId > 0) {
|
|
|
+ coupons = couponRepo.findAllByAttractionsId(attractionsId);
|
|
|
+ } else {
|
|
|
+ coupons = couponRepo.findAll();
|
|
|
+ }
|
|
|
+ Map<Long, String> couponName = coupons.stream()
|
|
|
.collect(Collectors.toMap(Coupon::getId, Coupon::getName));
|
|
|
- Page<UserCoupon> all = this.all(pageQuery);
|
|
|
+
|
|
|
+// Page<UserCoupon> all = this.all(pageQuery);
|
|
|
+ Page<UserCoupon> all = userCouponRepo.findAll(((root, criteriaQuery, criteriaBuilder) -> {
|
|
|
+ List<Predicate> and = new ArrayList<>();
|
|
|
+ if (attractionsId > 0L) {
|
|
|
+ and.add(root.get("couponId").in(couponName.keySet()));
|
|
|
+ }
|
|
|
+ return criteriaBuilder.and(and.toArray(new Predicate[0]));
|
|
|
+ }), JpaUtils.toPageRequest(pageQuery));
|
|
|
+
|
|
|
List<UserCoupon> list = all.getContent();
|
|
|
Set<Long> ids = list.stream().map(UserCoupon::getUserId).collect(Collectors.toSet());
|
|
|
ids.addAll(list.stream().map(UserCoupon::getWriteOffUserId).collect(Collectors.toSet()));
|
|
|
Map<Long, String> userMap = userRepo.findAllById(ids)
|
|
|
.stream()
|
|
|
.collect(Collectors.toMap(User::getId, User::getNickname));
|
|
|
+
|
|
|
return all.map(userCoupon -> new UserCouponDTO(userCoupon, userMap.get(userCoupon.getUserId()), userMap.get(userCoupon
|
|
|
.getWriteOffUserId()), couponName.get(userCoupon.getCouponId())));
|
|
|
}
|
|
|
@@ -89,4 +110,5 @@ public class UserCouponService {
|
|
|
userCoupon.setWriteOffUserId(writeOffUserId);
|
|
|
userCouponRepo.save(userCoupon);
|
|
|
}
|
|
|
+
|
|
|
}
|