Browse Source

2019/08/26

x1ongzhu 6 years ago
parent
commit
eee2aa0ab8

+ 1 - 1
src/main/java/com/izouma/walkchina/repo/StageAwardRepository.java

@@ -8,7 +8,7 @@ import java.util.List;
 public interface StageAwardRepository extends JpaRepository<StageAward, Long> {
     int countAllByUserIdAndReceivedEquals(Long userId, boolean received);
 
-    int countAllByUserIdAndNeedProgressLessThanAndReceivedEquals(Long userId, double progress, boolean received);
+    List<StageAward> findAllByUserIdAndNeedProgressLessThanAndReceivedEquals(Long userId, double progress, boolean received);
 
     List<StageAward> findAllByUserIdAndStageId(Long userId, Long stageId);
 

+ 1 - 1
src/main/java/com/izouma/walkchina/service/JourneyService.java

@@ -170,7 +170,6 @@ public class JourneyService {
         }
         progress = needSteps * AppConstants.STEP_TO_DISTANCE_RATE / journeyStage.getDistance();
 
-        List<Double> extracted = mapService.extractPolyline(journeyStage.getPolyline());
         Location location = mapService.endPoint(journeyStage.getRouteSteps(), journeyStage.getDistance() * progress, journeyStage.getPolyline());
         BigDecimal coin = Optional.ofNullable(userInfo.getPrice()).orElse(AppConstants.MIN_PRICE).divide(BigDecimal.valueOf(10), RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_EVEN);
         StageAward stageAward = StageAward.builder()
@@ -184,6 +183,7 @@ public class JourneyService {
                                           .needProgress(progress)
                                           .needSteps(needSteps)
                                           .received(false)
+                                          .arrival(false)
                                           .build();
         stageAwardRepository.save(stageAward);
     }

+ 16 - 7
src/main/java/com/izouma/walkchina/service/MapService.java

@@ -3,10 +3,7 @@ package com.izouma.walkchina.service;
 import com.github.kevinsawicki.http.HttpRequest;
 import com.google.gson.Gson;
 import com.izouma.walkchina.constant.AppConstants;
-import com.izouma.walkchina.domain.City;
-import com.izouma.walkchina.domain.JourneyStage;
-import com.izouma.walkchina.domain.UserInfo;
-import com.izouma.walkchina.domain.UserJourney;
+import com.izouma.walkchina.domain.*;
 import com.izouma.walkchina.dto.Location;
 import com.izouma.walkchina.dto.MapRegion;
 import com.izouma.walkchina.dto.UserMap;
@@ -27,6 +24,7 @@ import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.time.LocalDate;
 import java.util.*;
+import java.util.function.Predicate;
 
 import static java.time.temporal.ChronoUnit.DAYS;
 
@@ -73,8 +71,8 @@ public class MapService {
 
         northeast.setLatitude(northeast.getLatitude() - dLat);
         northeast.setLongitude(northeast.getLongitude() - dLng);
-        southwest.setLatitude(northeast.getLatitude() - dLat);
-        southwest.setLongitude(northeast.getLongitude() - dLng);
+        southwest.setLatitude(southwest.getLatitude() - dLat);
+        southwest.setLongitude(southwest.getLongitude() - dLng);
 
         List<UserMarker> list = userInfoRepository.findInRegion(userId, mapRegion.getSouthwest().getLatitude(), mapRegion.getSouthwest().getLongitude(),
                                                                 mapRegion.getNortheast().getLongitude(), mapRegion.getNortheast().getLongitude());
@@ -82,7 +80,18 @@ public class MapService {
             userMarker.setIcon(ossDomain + "/marker/user/" + userMarker.getUserId() + ".png");
             JourneyStage journeyStage = journeyStageRepository.findFirstByUserIdOrderByCreatedAtDesc(userMarker.getUserId()).orElse(null);
             if (journeyStage != null) {
-                userMarker.setCanSteal(stageAwardRepository.countAllByUserIdAndNeedProgressLessThanAndReceivedEquals(userMarker.getUserId(), journeyStage.getProgress(), false) > 0);
+                List<StageAward> stageAwards = stageAwardRepository.findAllByUserIdAndNeedProgressLessThanAndReceivedEquals(userMarker.getUserId(), journeyStage.getProgress(), false);
+                userMarker.setCanSteal(stageAwards.stream().anyMatch(new Predicate<StageAward>() {
+                    @Override
+                    public boolean test(StageAward stageAward) {
+                        return (stageAward.getArrival() ? stageAward.getReceiveRecords().size() < 10 : stageAward.getReceiveRecords().size() < 3) && stageAward.getReceiveRecords().stream().noneMatch(new Predicate<StageAwardRecord>() {
+                            @Override
+                            public boolean test(StageAwardRecord stageAwardRecord) {
+                                return stageAwardRecord.getUserId().equals(userId);
+                            }
+                        });
+                    }
+                }));
             } else {
                 userMarker.setCanSteal(false);
             }

+ 2 - 2
src/main/java/com/izouma/walkchina/service/UserInfoService.java

@@ -175,8 +175,8 @@ public class UserInfoService {
 
     public void updateLocation(Long userId, Double latitude, Double longitude) {
         UserInfo userInfo = userInfoRepository.findById(userId).orElseThrow(new ServiceException("用户不存在"));
-        userInfo.setLatitude(latitude + Math.random() * 0.0003 + 0.0003 * (Math.random() > 0.5 ? 1 : -1));
-        userInfo.setLongitude(longitude + Math.random() * 0.0003 + 0.0003 * (Math.random() > 0.5 ? 1 : -1));
+        userInfo.setLatitude(latitude + Math.random() * 0.0006 + 0.0006 * (Math.random() > 0.5 ? 1 : -1));
+        userInfo.setLongitude(longitude + Math.random() * 0.0006 + 0.0006 * (Math.random() > 0.5 ? 1 : -1));
         userInfoRepository.save(userInfo);
     }
 

+ 6 - 0
src/test/java/com/izouma/walkchina/CommonTest.java

@@ -209,4 +209,10 @@ public class CommonTest {
         System.out.println(amount);
     }
 
+    @Test
+    public void bbb() {
+        Boolean b = null;
+        System.out.println(b ? 1 : 2);
+    }
+
 }

+ 0 - 2
src/test/java/com/izouma/walkchina/repo/StageAwardRepositoryTest.java

@@ -18,8 +18,6 @@ public class StageAwardRepositoryTest {
 
     @Test
     public void countAllByUserIdAndNeedProgressLessThanAndReceivedEquals() {
-        int num = stageAwardRepository.countAllByUserIdAndNeedProgressLessThanAndReceivedEquals(189L, 0.6, false);
-        System.out.println(num);
     }
 
     @Test