ソースを参照

店铺打卡效验

qinxuyang 1 日 前
コミット
04c70cfea9

+ 7 - 13
alien-store/src/main/java/shop/alien/store/service/impl/StoreInfoServiceImpl.java

@@ -6098,19 +6098,13 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
         // 今天在该店铺是否打过卡
 //        int today = (int) clockStoreList.stream().filter(item -> item.getCreatedTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate().equals(LocalDate.now())).count();
         int today = clockStoreList.stream()
-                .anyMatch(item -> {
-                    if (item.getCreatedTime() == null) return false;
-                    Instant created = item.getCreatedTime().toInstant();
-                    Instant now = Instant.now();
-                    Duration diff = Duration.between(created, now);
-                    return diff.compareTo(Duration.ofHours(24)) > 0;
-                })
-                ? 1 : 0;
-        if (today > 0) {
-            result.setClockInStoreToday(1);
-        } else {
-            result.setClockInStoreToday(0);
-        }
+                .filter(item -> item.getCreatedTime() != null)
+                .max(Comparator.comparing(StoreClockIn::getCreatedTime))
+                .map(item -> Duration.between(item.getCreatedTime().toInstant(), Instant.now())
+                        .compareTo(Duration.ofHours(24)) > 0 ? 1 : 0)
+                .orElse(0);
+
+        result.setClockInStoreToday(today);
 
         Integer totalCount = 0;
         Object ratingObj =  commonRatingService.getRatingCount(storeInfo.getId(), 1);