|
|
@@ -5,6 +5,7 @@ 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.dto.Location;
|
|
|
import com.izouma.walkchina.dto.MapRegion;
|
|
|
@@ -15,6 +16,8 @@ import com.izouma.walkchina.dto.webservice.RouteStep;
|
|
|
import com.izouma.walkchina.exception.ServiceException;
|
|
|
import com.izouma.walkchina.repo.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.joda.time.Days;
|
|
|
+import org.joda.time.LocalDate;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
@@ -75,22 +78,19 @@ public class MapService {
|
|
|
}
|
|
|
|
|
|
public UserMap userMap(Long userId) {
|
|
|
- UserJourney userJourney = userJourneyRepository.findByUserId(userId);
|
|
|
- if (userJourney == null) {
|
|
|
- throw new ServiceException("无记录");
|
|
|
- }
|
|
|
- City origin = userJourney.getOrigin();
|
|
|
- if (origin == null) {
|
|
|
- throw new ServiceException("无记录");
|
|
|
- }
|
|
|
- City destination = userJourney.getDestination();
|
|
|
- if (destination == null) {
|
|
|
- throw new ServiceException("无记录");
|
|
|
- }
|
|
|
+ UserJourney userJourney = Optional.ofNullable(userJourneyRepository.findByUserId(userId)).orElseThrow(new ServiceException("无记录"));
|
|
|
+ City origin = Optional.ofNullable(userJourney.getOrigin()).orElseThrow(new ServiceException("无记录"));
|
|
|
+ City destination = Optional.ofNullable(userJourney.getDestination()).orElseThrow(new ServiceException("无记录"));
|
|
|
+ UserInfo userInfo = userInfoRepository.findById(userId).orElseThrow(new ServiceException("用户不存在"));
|
|
|
UserMap userMap = UserMap.builder()
|
|
|
.polyline(minifyPolyline(userJourney.getPolyline()))
|
|
|
.origin(origin)
|
|
|
.destination(destination)
|
|
|
+ .nickname(userInfo.getNickname())
|
|
|
+ .avatar(userInfo.getAvatar())
|
|
|
+ .totalSteps(userInfo.getTotalSteps())
|
|
|
+ .walkCities(userInfo.getWalkCities())
|
|
|
+ .level(userInfo.getLevel())
|
|
|
.build();
|
|
|
List<Double> progressPolyline = new ArrayList<>();
|
|
|
List<JourneyStage> stages = journeyStageRepository.findAllByJourneyIdOrderById(userJourney.getId());
|
|
|
@@ -100,11 +100,11 @@ public class MapService {
|
|
|
JourneyStage latestStage = stages.get(stages.size() - 1);
|
|
|
|
|
|
userMap.setProgress(latestStage.getProgress());
|
|
|
- Date now = new Date();
|
|
|
- userMap.setTeamStep(walkDataRepository.sumTeamWalkSteps(userId, now, now).orElse(0L));
|
|
|
- userMap.setTodayStep(walkDataRepository.sumUserWalkSteps(userId, now, now).orElse(0L));
|
|
|
+ userMap.setTeamStep(walkDataRepository.sumTeamWalkSteps(userId, new Date(), new Date()).orElse(0L));
|
|
|
+ userMap.setTodayStep(walkDataRepository.sumUserWalkSteps(userId, new Date(), new Date()).orElse(0L));
|
|
|
userMap.setCurrentStep(latestStage.getCurrentSteps());
|
|
|
userMap.setStageAwards(stageAwardRepository.findAllByUserIdAndStageId(userId, latestStage.getId()));
|
|
|
+ userMap.setDays(Days.daysBetween(LocalDate.fromDateFields(latestStage.getCreatedAt()), LocalDate.fromDateFields(new Date())).getDays());
|
|
|
|
|
|
List<RouteStep> steps = latestStage.getRouteSteps();
|
|
|
// int distance = 0;
|
|
|
@@ -132,7 +132,7 @@ public class MapService {
|
|
|
// break;
|
|
|
// }
|
|
|
// }
|
|
|
- for (int i = 0; i < endPoint(steps, latestStage.getDistance() * latestStage.getProgress()); i++) {
|
|
|
+ for (int i = 0; i <= endPoint(steps, latestStage.getDistance() * latestStage.getProgress()); i++) {
|
|
|
progressPolyline.add(latestStage.getPolyline().get(i));
|
|
|
}
|
|
|
|
|
|
@@ -199,14 +199,8 @@ public class MapService {
|
|
|
}
|
|
|
|
|
|
public Map<String, Object> calcAward(Long originId, Long destinationId) {
|
|
|
- City origin = cityRepository.findById(originId).orElse(null);
|
|
|
- if (origin == null) {
|
|
|
- throw new ServiceException("无记录");
|
|
|
- }
|
|
|
- City destination = cityRepository.findById(destinationId).orElse(null);
|
|
|
- if (destination == null) {
|
|
|
- throw new ServiceException("无记录");
|
|
|
- }
|
|
|
+ City origin = cityRepository.findById(originId).orElseThrow(new ServiceException("无记录"));
|
|
|
+ City destination = cityRepository.findById(destinationId).orElseThrow(new ServiceException("无记录"));
|
|
|
DirectionResponse response = direction(new Location(origin.getLatitude(), origin.getLongitude()), new Location(destination.getLatitude(), destination.getLongitude()));
|
|
|
if (response.getStatus() != 0) {
|
|
|
throw new ServiceException(response.getMessage());
|