|
|
@@ -12,6 +12,7 @@ import com.izouma.walkchina.repo.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Example;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
@@ -156,6 +157,28 @@ public class JourneyService {
|
|
|
.build());
|
|
|
}
|
|
|
|
|
|
+ @Async
|
|
|
+ public void sendJoinAward(Long userId, BigDecimal coin) {
|
|
|
+ UserInfo userInfo = userInfoRepository.findById(userId).orElseThrow(new ServiceException("用户不存在"));
|
|
|
+ UserJourney userJourney = userJourneyRepository.findByUserId(userId);
|
|
|
+ JourneyStage journeyStage = journeyStageRepository.findFirstByUserIdAndJourneyIdOrderByCreatedAtDesc(userId, userJourney
|
|
|
+ .getId()).orElseThrow(new ServiceException("无记录"));
|
|
|
+ coinService.balanceChange(userInfo, coin, AppConstants.CoinRecordType.JOIN, Strings.REMARK_JOIN, null);
|
|
|
+ userInfo.setIsNew(false);
|
|
|
+ userInfoRepository.save(userInfo);
|
|
|
+ stageAwardRepository.save(StageAward.builder()
|
|
|
+ .userId(userId)
|
|
|
+ .journeyId(userJourney.getId())
|
|
|
+ .stageId(journeyStage.getId())
|
|
|
+ .coin(coin)
|
|
|
+ .received(true)
|
|
|
+ .needProgress(0D)
|
|
|
+ .needSteps(0L)
|
|
|
+ .longitude(journeyStage.getOrigin().getLongitude())
|
|
|
+ .latitude(journeyStage.getOrigin().getLatitude())
|
|
|
+ .build());
|
|
|
+ }
|
|
|
+
|
|
|
private void createStageAward(UserJourney userJourney, JourneyStage journeyStage, Long needSteps) {
|
|
|
StageAward latest = stageAwardRepository.findFirstByUserIdAndStageIdAndArrivalIsFalseOrderByCreatedAtDesc(userJourney.getUserId(), journeyStage.getId());
|
|
|
UserInfo userInfo = userInfoRepository.findById(userJourney.getUserId()).orElseThrow(new ServiceException("用户不存在"));
|
|
|
@@ -228,7 +251,7 @@ public class JourneyService {
|
|
|
steps,
|
|
|
Math.round(progress * 100));
|
|
|
Message lastMsg = messageRepository.findFirstByUserIdAndTypeOrderByCreatedAtDesc(userId, AppConstants.MessageType.PROGRESS_UPDATE);
|
|
|
- if (lastMsg == null || (lastMsg.getCreatedAt().plusMinutes(5).isBefore(LocalDateTime.now()) && !content.equals(lastMsg.getContent()))) {
|
|
|
+ if (lastMsg == null || !content.equals(lastMsg.getContent())) {
|
|
|
Message msg = Message.builder()
|
|
|
.userId(userId)
|
|
|
.content(content)
|