x1ongzhu vor 6 Jahren
Ursprung
Commit
8260d4f87d

+ 1 - 0
src/main/java/com/izouma/walkchina/constant/AppConstants.java

@@ -52,6 +52,7 @@ public interface AppConstants {
     }
 
     interface CoinRecordType {
+        int JOIN      = 0; // 加入公开赛
         int STAGE     = 1; // 领取阶段奖励
         int STEAL     = 2; // 偷奖金
         int ARRIVAL   = 3; // 到达城市

+ 2 - 0
src/main/java/com/izouma/walkchina/constant/Strings.java

@@ -30,6 +30,8 @@ public interface Strings {
 
     String MSG_NEW_FRIEND = "你有新的好友 <b>%s</b> 加入“走遍城市公开赛”";
 
+    String REMARK_JOIN = "加入走\"遍城市公开赛\"";
+
     String REMARK_HIRE = "雇佣队员";
 
     String REMARK_BE_HIRED = "队员佣金";

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

@@ -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)

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

@@ -10,6 +10,7 @@ import com.izouma.walkchina.repo.TeamMemberRepository;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.*;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 import java.time.LocalDate;
@@ -37,6 +38,7 @@ public class MessageService {
         messageRepository.readAll(userId);
     }
 
+    @Async
     public void sendStepContributeMsg(UserInfo userInfo, Integer steps) {
         List<UserDTO> leaders = teamMemberRepository.findLeader(userInfo.getId(), LocalDate.now());
         for (UserDTO leader : leaders) {

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

@@ -52,6 +52,10 @@ public class UserInfoService {
     private TeamMemberRepository    teamMemberRepository;
     @Autowired
     private AuthorityRepository     authorityRepository;
+    @Autowired
+    private CoinService             coinService;
+    @Autowired
+    private JourneyService          journeyService;
 
     public UserInfo registerByUserPwd(String username, String password) {
         UserInfo userInfo = userInfoRepository.findByUsername(username);
@@ -92,7 +96,6 @@ public class UserInfoService {
                                .active(true)
                                .sessionKey(sessionKey)
                                .authorities(Collections.singletonList(authorityRepository.findByName(AuthorityName.ROLE_USER)))
-                               .isNew(true)
                                .build();
             userInfo = userInfoRepository.save(userInfo);
             uploadUserMarker(userInfo);
@@ -260,27 +263,25 @@ public class UserInfoService {
             scale += .01;
         }
         price = price.multiply(BigDecimal.valueOf(scale)).setScale(2, RoundingMode.HALF_UP);
-
         userInfo.setPrice(price);
+        userInfoRepository.save(userInfo);
         if (userInfo.getIsNew() != null && userInfo.getIsNew()) {
-            userInfo.setIsNew(false);
-            userInfo.setCoin(Optional.ofNullable(userInfo.getCoin()).orElse(BigDecimal.ZERO).add(price));
+            journeyService.sendJoinAward(userInfo.getId(), price);
         }
-        userInfoRepository.save(userInfo);
     }
 
     public void updateUserLevel(UserInfo userInfo) {
         int walkCities = Optional.ofNullable(userInfo.getWalkCities()).orElse(0);
         int level;
-        if (walkCities <= 5) {
+        if (walkCities < 4) {
             level = 1;
-        } else if (walkCities <= 25) {
+        } else if (walkCities < 37) {
             level = 2;
-        } else if (walkCities <= 125) {
+        } else if (walkCities < 109) {
             level = 3;
-        } else if (walkCities <= 378) {
+        } else if (walkCities < 217) {
             level = 4;
-        } else if (walkCities <= 1314) {
+        } else if (walkCities < 521) {
             level = 5;
         } else {
             level = 6;

BIN
src/main/resources/static/share_img.png