|
|
@@ -6,6 +6,7 @@ import com.izouma.nineth.dto.PageQuery;
|
|
|
import com.izouma.nineth.dto.R;
|
|
|
import com.izouma.nineth.dto.RiceDTO;
|
|
|
import com.izouma.nineth.enums.RiceOperationType;
|
|
|
+import com.izouma.nineth.enums.RiceWaterType;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
import com.izouma.nineth.repo.*;
|
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
|
@@ -32,18 +33,20 @@ import java.time.LocalTime;
|
|
|
import java.time.ZoneOffset;
|
|
|
import java.util.*;
|
|
|
|
|
|
+import static com.izouma.nineth.enums.RiceWaterType.ACTIVITY_AWARD;
|
|
|
+
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
public class RiceService {
|
|
|
|
|
|
private static final int MAX_NICKNAME_LENGTH = 6;
|
|
|
private static final String UPDATE_SUCCESS_MSG = "修改成功";
|
|
|
- private RiceRepo riceRepo;
|
|
|
- private RiceUserWaterDropRecordRepo riceUserWaterDropRecordRepo;
|
|
|
- private RiceOperationRecordRepo riceOperationRecordRepo;
|
|
|
- private UserRepo userRepo;
|
|
|
- private SysConfigService sysConfigService;
|
|
|
- private RiceInviteRepo riceInviteRepo;
|
|
|
+ private final RiceRepo riceRepo;
|
|
|
+ private final RiceUserWaterDropRecordRepo riceUserWaterDropRecordRepo;
|
|
|
+ private final RiceOperationRecordRepo riceOperationRecordRepo;
|
|
|
+ private final UserRepo userRepo;
|
|
|
+ private final SysConfigService sysConfigService;
|
|
|
+ private final RiceInviteRepo riceInviteRepo;
|
|
|
|
|
|
public Page<Rice> all(PageQuery pageQuery) {
|
|
|
return riceRepo.findAll(JpaUtils.toSpecification(pageQuery, Rice.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
@@ -60,7 +63,7 @@ public class RiceService {
|
|
|
User user = byId.get();
|
|
|
nickname = user.getNickname();
|
|
|
avatar = user.getAvatar();
|
|
|
- phone= user.getPhone();
|
|
|
+ phone = user.getPhone();
|
|
|
} else {
|
|
|
throw new BusinessException("用户不存在");
|
|
|
}
|
|
|
@@ -78,7 +81,6 @@ public class RiceService {
|
|
|
rice.setNickname(nickname);
|
|
|
rice.setPhone(phone);
|
|
|
rice.setLevel(0L);
|
|
|
- rice.setWaterDropCount(0L);
|
|
|
rice.setSignCount(0L);
|
|
|
rice.setSelfScore(0L);
|
|
|
rice.setSelfActivityScore(0L);
|
|
|
@@ -100,12 +102,7 @@ public class RiceService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 获取当前等级
|
|
|
- *
|
|
|
- * @param empiricalValue
|
|
|
- * @return
|
|
|
- */
|
|
|
+ //获取当前等级
|
|
|
public Map<String, Object> getCurrentLevel(Long empiricalValue) {
|
|
|
String jsonString = sysConfigService.getString("rice_level");
|
|
|
User authenticatedUser = SecurityUtils.getAuthenticatedUser();
|
|
|
@@ -113,24 +110,20 @@ public class RiceService {
|
|
|
Optional<Rice> byUserId = riceRepo.findByUserId(authId);
|
|
|
if (byUserId.isPresent()) {
|
|
|
Rice rice = byUserId.get();
|
|
|
- empiricalValue = rice.getEmpiricalValue();
|
|
|
-
|
|
|
JsonReader jsonReader = Json.createReader(new StringReader(jsonString));
|
|
|
JsonArray jsonArray = jsonReader.readArray();
|
|
|
-
|
|
|
Long currentLevel = null;
|
|
|
Long currentStart = null;
|
|
|
Long nextStart = null;
|
|
|
for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
JsonObject jsonObject = jsonArray.getJsonObject(i);
|
|
|
Long start = Long.valueOf(jsonObject.getInt("start"));
|
|
|
-
|
|
|
- if (empiricalValue >= start && empiricalValue < (i < jsonArray.size() - 1 ? Long
|
|
|
- .valueOf(jsonArray.getJsonObject(i + 1).getInt("start")) : Long.MAX_VALUE)) {
|
|
|
+ if (empiricalValue >= start && empiricalValue < (i < jsonArray.size() - 1 ? Long.valueOf(jsonArray.getJsonObject(i + 1).getInt("start")) : Long.MAX_VALUE)) {
|
|
|
String currentLevelStr = jsonObject.getString("name").replace("Lv", "");
|
|
|
currentLevel = Long.parseLong(currentLevelStr);
|
|
|
+ rice.setLevel(currentLevel);
|
|
|
+ riceRepo.save(rice);
|
|
|
currentStart = Long.valueOf(jsonObject.getInt("start"));
|
|
|
-
|
|
|
if (i < jsonArray.size() - 1) {
|
|
|
JsonObject nextObject = jsonArray.getJsonObject(i + 1);
|
|
|
nextStart = nextObject.getJsonNumber("start").longValue();
|
|
|
@@ -165,12 +158,12 @@ public class RiceService {
|
|
|
* @return R<?>
|
|
|
*/
|
|
|
public R<?> taskInitialization() {
|
|
|
- User authenticatedUser = SecurityUtils.getAuthenticatedUser();
|
|
|
- Long authId = authenticatedUser.getId();
|
|
|
- Optional<Rice> byUserId = riceRepo.findByUserId(authId);
|
|
|
+
|
|
|
+ Optional<Rice> byUserId = riceRepo.findByUserId(SecurityUtils.getAuthenticatedUser().getId());
|
|
|
if (byUserId.isPresent()) {
|
|
|
Rice rice = byUserId.get();
|
|
|
int i = riceInviteRepo.countRiceInviteBy(rice.getUserId(), getTodayStartTime(), getTodayEndTime());
|
|
|
+ int InviteHelpOthersCounts = riceInviteRepo.countRiceInviteByHelperId(SecurityUtils.getAuthenticatedUser().getId(), getTodayStartTime(), getTodayEndTime());
|
|
|
|
|
|
Long lastSignInTime = rice.getLastSignInTime();
|
|
|
Long currentTime = System.currentTimeMillis();
|
|
|
@@ -179,16 +172,16 @@ public class RiceService {
|
|
|
Boolean isInvited;
|
|
|
Boolean isCanExchangeScore;
|
|
|
|
|
|
- if(rice.getSelfActivityScore()<10&&rice.getSelfScore()>=2){
|
|
|
- isCanExchangeScore=true;
|
|
|
- }else {
|
|
|
- isCanExchangeScore=false;
|
|
|
+ if (rice.getExchangeCount() < 10 && rice.getSelfScore() >= 10) {
|
|
|
+ isCanExchangeScore = true;
|
|
|
+ } else {
|
|
|
+ isCanExchangeScore = false;
|
|
|
}
|
|
|
|
|
|
- if(i==0){
|
|
|
+ if (i == 0) {
|
|
|
isInvited = false;
|
|
|
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
isInvited = true;
|
|
|
}
|
|
|
|
|
|
@@ -201,27 +194,27 @@ public class RiceService {
|
|
|
// 判断上次签到时间是否为空,如果为空,则默认为从未签到过
|
|
|
if (lastSignInTime == null) {
|
|
|
return R.success("未签到").add("isSignedIn", false)
|
|
|
- .add("exchangeCount", rice.getExchangeCount() == null ? 0 : rice.getExchangeCount())
|
|
|
- .add("waterDropCount", rice.getWaterDropCount())
|
|
|
+ .add("exchangeCount", rice.getExchangeCount())
|
|
|
.add("isCanExchangeActivityScoreForWater", isCanExchangeActivityScoreForWater)
|
|
|
- .add("isInvited",isInvited)
|
|
|
- .add("isCanExchangeScore",isCanExchangeScore);
|
|
|
+ .add("isInvited", isInvited)
|
|
|
+ .add("isCanExchangeScore", isCanExchangeScore)
|
|
|
+ .add("InviteHelpOthersCounts", InviteHelpOthersCounts);
|
|
|
}
|
|
|
// 判断今天是否已经签到过
|
|
|
if (DateUtils.isSameDay(new Date(lastSignInTime), new Date(currentTime))) {
|
|
|
return R.success("已签到").add("isSignedIn", true)
|
|
|
- .add("exchangeCount", rice.getExchangeCount() == null ? 0 : rice.getExchangeCount())
|
|
|
- .add("waterDropCount", rice.getWaterDropCount())
|
|
|
+ .add("exchangeCount", rice.getExchangeCount())
|
|
|
.add("isCanExchangeActivityScoreForWater", isCanExchangeActivityScoreForWater)
|
|
|
- .add("isInvited",isInvited)
|
|
|
- .add("isCanExchangeScore",isCanExchangeScore);
|
|
|
+ .add("isInvited", isInvited)
|
|
|
+ .add("isCanExchangeScore", isCanExchangeScore)
|
|
|
+ .add("InviteHelpOthersCounts", InviteHelpOthersCounts);
|
|
|
} else {
|
|
|
return R.success("未签到").add("isSignedIn", false)
|
|
|
- .add("exchangeCount", rice.getExchangeCount() == null ? 0 : rice.getExchangeCount())
|
|
|
- .add("waterDropCount", rice.getWaterDropCount())
|
|
|
+ .add("exchangeCount", rice.getExchangeCount())
|
|
|
.add("isCanExchangeActivityScoreForWater", isCanExchangeActivityScoreForWater)
|
|
|
- .add("isInvited",isInvited)
|
|
|
- .add("isCanExchangeScore",isCanExchangeScore);
|
|
|
+ .add("isInvited", isInvited)
|
|
|
+ .add("isCanExchangeScore", isCanExchangeScore)
|
|
|
+ .add("InviteHelpOthersCounts", InviteHelpOthersCounts);
|
|
|
}
|
|
|
}
|
|
|
return R.error("查询失败");
|
|
|
@@ -232,42 +225,53 @@ public class RiceService {
|
|
|
* 获取当前用户积分
|
|
|
*/
|
|
|
public R<String> getCurrentScore() {
|
|
|
- User authenticatedUser = SecurityUtils.getAuthenticatedUser();
|
|
|
- Long authId = authenticatedUser.getId();
|
|
|
- Optional<Rice> byUserId = riceRepo.findByUserId(authId);
|
|
|
- if (byUserId.isPresent()) {
|
|
|
- Rice rice = byUserId.get();
|
|
|
- Long selfScore = rice.getSelfScore();
|
|
|
- return R.success("获取到当前用户积分").add("selfScore", selfScore);
|
|
|
- }
|
|
|
- return R.error("获取失败");
|
|
|
+ Rice rice = riceRepo.findByUserId(SecurityUtils.getAuthenticatedUser().getId()).orElseThrow(new BusinessException("用户不存在"));
|
|
|
+ Long selfScore = rice.getSelfScore();
|
|
|
+ return R.success("获取到当前用户积分").add("selfScore", selfScore);
|
|
|
}
|
|
|
|
|
|
|
|
|
//在RiceService中添加一个方法用于更新所有用户的排名。
|
|
|
- public void updateScoreRank() {
|
|
|
+ public void updateLvRank() {
|
|
|
List<Rice> allRices = riceRepo.findAll();
|
|
|
- allRices.sort(Comparator.comparing(Rice::getSelfScore).reversed());
|
|
|
for (int i = 0; i < allRices.size(); i++) {
|
|
|
Rice rice = allRices.get(i);
|
|
|
-// rice.setScoreRank(i + 1);
|
|
|
- riceRepo.save(rice);
|
|
|
+
|
|
|
+ String jsonString = sysConfigService.getString("rice_level");
|
|
|
+ JsonReader jsonReader = Json.createReader(new StringReader(jsonString));
|
|
|
+ JsonArray jsonArray = jsonReader.readArray();
|
|
|
+ Long currentLevel = null;
|
|
|
+
|
|
|
+ for (int j = 0; j < jsonArray.size(); j++) {
|
|
|
+ JsonObject jsonObject = jsonArray.getJsonObject(j);
|
|
|
+ Long start = Long.valueOf(jsonObject.getInt("start"));
|
|
|
+ if (rice.getEmpiricalValue() >= start && rice.getEmpiricalValue() < (j < jsonArray.size() - 1 ? Long.valueOf(jsonArray.getJsonObject(j + 1).getInt("start")) : Long.MAX_VALUE)) {
|
|
|
+ String currentLevelStr = jsonObject.getString("name").replace("Lv", "");
|
|
|
+ currentLevel = Long.parseLong(currentLevelStr);
|
|
|
+ rice.setLevel(currentLevel);
|
|
|
+ riceRepo.save(rice);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+ //一个获取积分排行榜的接口
|
|
|
public List<RiceDTO> getTop100(Long userId) {
|
|
|
+ this.updateLvRank();
|
|
|
List<Rice> top100Rices = riceRepo.findTop100OrderByEmpiricalValueDesc();
|
|
|
List<RiceDTO> result = new ArrayList<>();
|
|
|
|
|
|
// 计算自己的排名
|
|
|
- int selfRank = 0;
|
|
|
- for (int i = 0; i < top100Rices.size(); i++) {
|
|
|
- if (top100Rices.get(i).getId().equals(userId)) {
|
|
|
- selfRank = i + 1;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
+// int selfRank = 0;
|
|
|
+// for (int i = 0; i < top100Rices.size(); i++) {
|
|
|
+// if (top100Rices.get(i).getId().equals(userId)) {
|
|
|
+// selfRank = i + 1;
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
for (int i = 0; i < top100Rices.size(); i++) {
|
|
|
Rice rice = top100Rices.get(i);
|
|
|
@@ -297,6 +301,21 @@ public class RiceService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ //获取当前等级
|
|
|
+ public R<Map<String, Object>> showLevel() {
|
|
|
+ Rice rice = riceRepo.findByUserId(SecurityUtils.getAuthenticatedUser().getId()).orElseThrow(new BusinessException("用户不存在"));
|
|
|
+ Map<String, Object> currentLevel = this.getCurrentLevel(rice.getEmpiricalValue());
|
|
|
+ Long riceLevel = (Long) currentLevel.get("currentLevel");
|
|
|
+ Double levelUpPercentage = (Double) currentLevel.get("levelUpPercentage");
|
|
|
+ rice.setLevel(riceLevel);
|
|
|
+ riceRepo.save(rice);
|
|
|
+ Map<String, Object> responseData = new HashMap<>();
|
|
|
+ responseData.put("riceLevel", currentLevel);
|
|
|
+ responseData.put("levelUpPercentage", levelUpPercentage);
|
|
|
+ return R.success(responseData).add("msg", "查询成功");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
//计算自己排名
|
|
|
public R<RiceDTO> getRiceUserRank(Long userId) {
|
|
|
Optional<Rice> rice1 = riceRepo.findByUserId(userId);
|
|
|
@@ -314,7 +333,6 @@ public class RiceService {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
for (int i = 0; i < top100Rices.size(); i++) {
|
|
|
Rice rice = top100Rices.get(i);
|
|
|
RiceDTO riceDTO = new RiceDTO();
|
|
|
@@ -336,177 +354,326 @@ public class RiceService {
|
|
|
} else {
|
|
|
riceDTO.setRankGap(i + 1 - 100);
|
|
|
}
|
|
|
-
|
|
|
BeanUtils.copyProperties(riceDTO, dto);
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
if (dto == null) {
|
|
|
return R.error("用户不存在");
|
|
|
}
|
|
|
-
|
|
|
return R.success(dto);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//浇水
|
|
|
- public R<? extends Object> watering() {
|
|
|
- // 获取当前用户 ID,
|
|
|
- User authenticatedUser = SecurityUtils.getAuthenticatedUser();
|
|
|
- Long authId = authenticatedUser.getId();
|
|
|
- Optional<Rice> byUserId = riceRepo.findByUserId(authId);
|
|
|
- if (byUserId.isPresent()) {
|
|
|
- Rice rice = byUserId.get();
|
|
|
- Long waterDropCount = rice.getWaterDropCount();
|
|
|
- Long beforeWaterDropCount = rice.getWaterDropCount();
|
|
|
- Long beforeEmpiricalValue = rice.getEmpiricalValue();
|
|
|
- // 如果水滴次数为 0,返回不能浇水的提示
|
|
|
- if (waterDropCount == 0) {
|
|
|
- return R.error("水滴次数已用完,无法浇水").add("can", false);
|
|
|
- }
|
|
|
- // 浇水成功,更新水滴次数,经验值加2
|
|
|
- rice.setWaterDropCount(waterDropCount - 1);
|
|
|
- rice.setEmpiricalValue(rice.getEmpiricalValue() + 2);
|
|
|
- riceRepo.save(rice);
|
|
|
- createRiceOperationRecord(authId, RiceOperationType.WATER_DROP, 1L, beforeWaterDropCount, rice
|
|
|
- .getWaterDropCount());
|
|
|
- createRiceOperationRecord(authId, RiceOperationType.EMPIRICAL_VALUE, 2L, beforeEmpiricalValue, rice
|
|
|
- .getEmpiricalValue());
|
|
|
-
|
|
|
- // Save watering record
|
|
|
- RiceUserWaterDropRecord record = new RiceUserWaterDropRecord();
|
|
|
- record.setUserId(authId);
|
|
|
- record.setWateringTime(LocalDateTime.now());
|
|
|
- riceUserWaterDropRecordRepo.save(record);
|
|
|
-
|
|
|
- return R.success("浇水成功").add("can", true).add("time", waterDropCount - 1);
|
|
|
- }
|
|
|
- return R.error("浇水失败").add("can", false);
|
|
|
- }
|
|
|
+ public R<? extends Object> waterDrop(RiceWaterType riceWaterType, Long riceId) {
|
|
|
+
|
|
|
+ Rice rice = riceRepo.findByUserId(riceId).orElseThrow(new BusinessException("未找到用户"));
|
|
|
+ switch (riceWaterType) {
|
|
|
+ case DAILY_CHECK_IN:
|
|
|
+ // 处理水滴之签到
|
|
|
+ Long numberOfSingnIn = rice.getNumberOfSingnIn();
|
|
|
+ Long beforeEmpiricalValue = rice.getEmpiricalValue();
|
|
|
+ if (numberOfSingnIn == 0) {
|
|
|
+ return R.error("浇水次数已用完,无法浇水").add("can", false).add("num", rice.getNumberOfSingnIn());
|
|
|
+ }
|
|
|
+ if (numberOfSingnIn <= 10) {
|
|
|
+ // 浇水成功,更新水滴次数,经验值加
|
|
|
+ rice.setNumberOfSingnIn((long) 0);
|
|
|
+ rice.setEmpiricalValue(rice.getEmpiricalValue() + 10 * numberOfSingnIn);
|
|
|
+ riceRepo.save(rice);
|
|
|
+ createRiceOperationRecord(riceId, RiceOperationType.WATER_DROP, numberOfSingnIn, numberOfSingnIn, rice
|
|
|
+ .getNumberOfSingnIn());
|
|
|
+ createRiceOperationRecord(riceId, RiceOperationType.EMPIRICAL_VALUE, 10 * numberOfSingnIn, beforeEmpiricalValue, rice
|
|
|
+ .getEmpiricalValue());
|
|
|
+
|
|
|
+ // Save watering record
|
|
|
+ RiceUserWaterDropRecord record = new RiceUserWaterDropRecord();
|
|
|
+ record.setUserId(riceId);
|
|
|
+ record.setWateringTime(LocalDateTime.now());
|
|
|
+ riceUserWaterDropRecordRepo.save(record);
|
|
|
+
|
|
|
+ return R.success("浇水成功").add("can", true).add("num", rice.getNumberOfSingnIn());
|
|
|
+ }
|
|
|
+ if (numberOfSingnIn > 10) {
|
|
|
+ rice.setNumberOfSingnIn(rice.getNumberOfSingnIn() - 10);
|
|
|
+ rice.setEmpiricalValue(rice.getEmpiricalValue() + 100);
|
|
|
+ riceRepo.save(rice);
|
|
|
+ createRiceOperationRecord(riceId, RiceOperationType.WATER_DROP, (long) 10, numberOfSingnIn, rice
|
|
|
+ .getNumberOfSingnIn());
|
|
|
+ createRiceOperationRecord(riceId, RiceOperationType.EMPIRICAL_VALUE, (long) 100, beforeEmpiricalValue, rice
|
|
|
+ .getEmpiricalValue());
|
|
|
+
|
|
|
+ // Save watering record
|
|
|
+ RiceUserWaterDropRecord record = new RiceUserWaterDropRecord();
|
|
|
+ record.setUserId(riceId);
|
|
|
+ record.setWateringTime(LocalDateTime.now());
|
|
|
+ riceUserWaterDropRecordRepo.save(record);
|
|
|
+
|
|
|
+ return R.success("浇水成功").add("can", true).add("num", rice.getNumberOfSingnIn());
|
|
|
+ }
|
|
|
|
|
|
- //根据用户ID和今日时间获取今日浇水次数的方法
|
|
|
- public Long getTodayWateringCount(Long userId) {
|
|
|
- List<RiceUserWaterDropRecord> records = riceUserWaterDropRecordRepo.findByUserId(userId);
|
|
|
- Long count = records.stream()
|
|
|
- .filter(RiceUserWaterDropRecord::isToday)
|
|
|
- .count();
|
|
|
- return count;
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 每浇水一次可获得2经验值,升级所需经验值为下一等级所配置的经验值标准。按照以下方式来计算用户升级所需水滴数
|
|
|
- *
|
|
|
- * @param rice
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Long getWaterDropNeededForLevelUp(Rice rice) {
|
|
|
- Long currentEmpiricalValue = rice.getEmpiricalValue();
|
|
|
- String jsonString = sysConfigService.getString("rice_level");
|
|
|
- JsonReader jsonReader = Json.createReader(new StringReader(jsonString));
|
|
|
- JsonArray jsonArray = jsonReader.readArray();
|
|
|
-
|
|
|
- for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
- JsonObject jsonObject = jsonArray.getJsonObject(i);
|
|
|
- Long start = Long.valueOf(jsonObject.getInt("start"));
|
|
|
- Long nextStart = 0L;
|
|
|
- if (i + 1 < jsonArray.size()) {
|
|
|
- JsonObject nextJsonObject = jsonArray.getJsonObject(i + 1);
|
|
|
- nextStart = Long.valueOf(nextJsonObject.getInt("start"));
|
|
|
- }
|
|
|
- if (currentEmpiricalValue >= start && currentEmpiricalValue < nextStart) {
|
|
|
- Long levelUpEmpiricalValue = nextStart - currentEmpiricalValue;
|
|
|
- Long waterDropNeededForLevelUp = levelUpEmpiricalValue / 2;
|
|
|
- return waterDropNeededForLevelUp;
|
|
|
- }
|
|
|
+ case INVITE_FRIENDS:
|
|
|
+ // 处理水滴之邀请
|
|
|
+ Long numberOfInviteFriends = rice.getNumberOfInviteFriends();
|
|
|
+ Long beforeEmpiricalValue1 = rice.getEmpiricalValue();
|
|
|
+ if (numberOfInviteFriends == 0) {
|
|
|
+ return R.error("电量次数已用完,无法充能").add("can", false);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (numberOfInviteFriends <= 10) {
|
|
|
+
|
|
|
+ // 浇水成功,更新水滴次数,经验值加2
|
|
|
+ rice.setNumberOfInviteFriends((long) 0);
|
|
|
+ rice.setEmpiricalValue(rice.getEmpiricalValue() + 10 * numberOfInviteFriends);
|
|
|
+ riceRepo.save(rice);
|
|
|
+ createRiceOperationRecord(riceId, RiceOperationType.WATER_DROP, numberOfInviteFriends, numberOfInviteFriends, rice
|
|
|
+ .getNumberOfInviteFriends());
|
|
|
+ createRiceOperationRecord(riceId, RiceOperationType.EMPIRICAL_VALUE, 10 * numberOfInviteFriends, beforeEmpiricalValue1, rice
|
|
|
+ .getEmpiricalValue());
|
|
|
+
|
|
|
+ // Save watering record
|
|
|
+ RiceUserWaterDropRecord record1 = new RiceUserWaterDropRecord();
|
|
|
+ record1.setUserId(riceId);
|
|
|
+ record1.setWateringTime(LocalDateTime.now());
|
|
|
+ riceUserWaterDropRecordRepo.save(record1);
|
|
|
+
|
|
|
+ return R.success("浇水成功").add("can", true).add("num", rice.getNumberOfInviteFriends());
|
|
|
+ }
|
|
|
+ if (numberOfInviteFriends > 10) {
|
|
|
+ // 浇水成功,更新水滴次数,经验值加2
|
|
|
+ rice.setNumberOfInviteFriends(rice.getNumberOfInviteFriends() - 10);
|
|
|
+ rice.setEmpiricalValue(rice.getEmpiricalValue() + 100L);
|
|
|
+ riceRepo.save(rice);
|
|
|
+ createRiceOperationRecord(riceId, RiceOperationType.WATER_DROP, 10L, numberOfInviteFriends, rice
|
|
|
+ .getNumberOfInviteFriends());
|
|
|
+ createRiceOperationRecord(riceId, RiceOperationType.EMPIRICAL_VALUE, 100L, beforeEmpiricalValue1, rice
|
|
|
+ .getEmpiricalValue());
|
|
|
+
|
|
|
+ // Save watering record
|
|
|
+ RiceUserWaterDropRecord record1 = new RiceUserWaterDropRecord();
|
|
|
+ record1.setUserId(riceId);
|
|
|
+ record1.setWateringTime(LocalDateTime.now());
|
|
|
+ riceUserWaterDropRecordRepo.save(record1);
|
|
|
+
|
|
|
+ return R.success("浇水成功").add("can", true).add("num", rice.getNumberOfInviteFriends());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ case FRIENDS_HELP:
|
|
|
+ // 处理水滴之助力
|
|
|
+ Long numberOfHelpOthers = rice.getNumberOfHelpOthers();
|
|
|
+ Long beforeEmpiricalValue2 = rice.getEmpiricalValue();
|
|
|
+ if (numberOfHelpOthers == 0) {
|
|
|
+ return R.error("电量次数已用完,无法充能").add("can", false);
|
|
|
+ }
|
|
|
+ if (numberOfHelpOthers <= 10) {
|
|
|
+ // 浇水成功,更新水滴次数,经验值加2
|
|
|
+ rice.setNumberOfHelpOthers((long) 0);
|
|
|
+ rice.setEmpiricalValue(rice.getEmpiricalValue() + 10 * numberOfHelpOthers);
|
|
|
+ riceRepo.save(rice);
|
|
|
+ createRiceOperationRecord(riceId, RiceOperationType.WATER_DROP, numberOfHelpOthers, numberOfHelpOthers, rice
|
|
|
+ .getNumberOfHelpOthers());
|
|
|
+ createRiceOperationRecord(riceId, RiceOperationType.EMPIRICAL_VALUE, 10 * numberOfHelpOthers, beforeEmpiricalValue2, rice
|
|
|
+ .getEmpiricalValue());
|
|
|
+
|
|
|
+ // Save watering record
|
|
|
+ RiceUserWaterDropRecord record2 = new RiceUserWaterDropRecord();
|
|
|
+ record2.setUserId(riceId);
|
|
|
+ record2.setWateringTime(LocalDateTime.now());
|
|
|
+ riceUserWaterDropRecordRepo.save(record2);
|
|
|
+
|
|
|
+ return R.success("浇水成功").add("can", true).add("num", rice.getNumberOfHelpOthers());
|
|
|
+ }
|
|
|
+ if (numberOfHelpOthers > 10) {
|
|
|
+ // 浇水成功,更新水滴次数,经验值加2
|
|
|
+ rice.setNumberOfHelpOthers(rice.getNumberOfHelpOthers() - 10L);
|
|
|
+ rice.setEmpiricalValue(rice.getEmpiricalValue() + 100L);
|
|
|
+ riceRepo.save(rice);
|
|
|
+ createRiceOperationRecord(riceId, RiceOperationType.WATER_DROP, 10L, numberOfHelpOthers, rice
|
|
|
+ .getNumberOfHelpOthers());
|
|
|
+ createRiceOperationRecord(riceId, RiceOperationType.EMPIRICAL_VALUE, 100L, beforeEmpiricalValue2, rice
|
|
|
+ .getEmpiricalValue());
|
|
|
+
|
|
|
+ // Save watering record
|
|
|
+ RiceUserWaterDropRecord record2 = new RiceUserWaterDropRecord();
|
|
|
+ record2.setUserId(riceId);
|
|
|
+ record2.setWateringTime(LocalDateTime.now());
|
|
|
+ riceUserWaterDropRecordRepo.save(record2);
|
|
|
+
|
|
|
+ return R.success("浇水成功").add("can", true).add("num", rice.getNumberOfHelpOthers());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ case REDEEM:
|
|
|
+ // 处理水滴之积分兑换
|
|
|
+ Long numberOfScoreExchanged = rice.getNumberOfScoreExchanged();
|
|
|
+ Long beforeEmpiricalValue3 = rice.getEmpiricalValue();
|
|
|
+ if (numberOfScoreExchanged == 0) {
|
|
|
+ return R.error("电量次数已用完,无法充能").add("can", false);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (numberOfScoreExchanged <= 10) {
|
|
|
+ // 浇水成功,更新水滴次数,经验值加2
|
|
|
+ rice.setNumberOfScoreExchanged((long) 0);
|
|
|
+ rice.setEmpiricalValue(rice.getEmpiricalValue() + 10 * numberOfScoreExchanged);
|
|
|
+ riceRepo.save(rice);
|
|
|
+ createRiceOperationRecord(riceId, RiceOperationType.WATER_DROP, numberOfScoreExchanged, numberOfScoreExchanged, rice
|
|
|
+ .getNumberOfScoreExchanged());
|
|
|
+ createRiceOperationRecord(riceId, RiceOperationType.EMPIRICAL_VALUE, 10 * numberOfScoreExchanged, beforeEmpiricalValue3, rice
|
|
|
+ .getEmpiricalValue());
|
|
|
+
|
|
|
+ // Save watering record
|
|
|
+ RiceUserWaterDropRecord record3 = new RiceUserWaterDropRecord();
|
|
|
+ record3.setUserId(riceId);
|
|
|
+ record3.setWateringTime(LocalDateTime.now());
|
|
|
+ riceUserWaterDropRecordRepo.save(record3);
|
|
|
+
|
|
|
+ return R.success("浇水成功").add("can", true).add("num", rice.getNumberOfScoreExchanged());
|
|
|
+ }
|
|
|
+ if (numberOfScoreExchanged > 10) {
|
|
|
+ // 浇水成功,更新水滴次数,经验值加2
|
|
|
+ rice.setNumberOfScoreExchanged(rice.getNumberOfScoreExchanged() - 10L);
|
|
|
+ rice.setEmpiricalValue(rice.getEmpiricalValue() + 100L);
|
|
|
+ riceRepo.save(rice);
|
|
|
+ createRiceOperationRecord(riceId, RiceOperationType.WATER_DROP, 10L, numberOfScoreExchanged, rice
|
|
|
+ .getNumberOfScoreExchanged());
|
|
|
+ createRiceOperationRecord(riceId, RiceOperationType.EMPIRICAL_VALUE, 100L, beforeEmpiricalValue3, rice
|
|
|
+ .getEmpiricalValue());
|
|
|
+
|
|
|
+ // Save watering record
|
|
|
+ RiceUserWaterDropRecord record3 = new RiceUserWaterDropRecord();
|
|
|
+ record3.setUserId(riceId);
|
|
|
+ record3.setWateringTime(LocalDateTime.now());
|
|
|
+ riceUserWaterDropRecordRepo.save(record3);
|
|
|
+
|
|
|
+ return R.success("浇水成功").add("can", true).add("num", rice.getNumberOfScoreExchanged());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ case ACTIVITY_AWARD:
|
|
|
+ // 处理水滴之活动
|
|
|
+ Long numberOfActivity = rice.getNumberOfActivity();
|
|
|
+ Long beforeEmpiricalValue4 = rice.getEmpiricalValue();
|
|
|
+ if (numberOfActivity == 0) {
|
|
|
+ return R.error("电量次数已用完,无法充能").add("can", false);
|
|
|
+ }
|
|
|
+ if (numberOfActivity <= 10) {
|
|
|
+ // 浇水成功,更新水滴次数,经验值加2
|
|
|
+ rice.setNumberOfActivity((long) 0);
|
|
|
+ rice.setEmpiricalValue(rice.getEmpiricalValue() + 10 * numberOfActivity);
|
|
|
+ riceRepo.save(rice);
|
|
|
+ createRiceOperationRecord(riceId, RiceOperationType.WATER_DROP, numberOfActivity, numberOfActivity, rice
|
|
|
+ .getNumberOfActivity());
|
|
|
+ createRiceOperationRecord(riceId, RiceOperationType.EMPIRICAL_VALUE, 10 * numberOfActivity, beforeEmpiricalValue4, rice
|
|
|
+ .getEmpiricalValue());
|
|
|
+
|
|
|
+ // Save watering record
|
|
|
+ RiceUserWaterDropRecord record4 = new RiceUserWaterDropRecord();
|
|
|
+ record4.setUserId(riceId);
|
|
|
+ record4.setWateringTime(LocalDateTime.now());
|
|
|
+ riceUserWaterDropRecordRepo.save(record4);
|
|
|
+
|
|
|
+ return R.success("浇水成功").add("can", true).add("num", rice.getNumberOfActivity());
|
|
|
+ }
|
|
|
+ if (numberOfActivity > 10) {
|
|
|
+ // 浇水成功,更新水滴次数,经验值加2
|
|
|
+ rice.setNumberOfActivity(rice.getNumberOfActivity() - 10L);
|
|
|
+ rice.setEmpiricalValue(rice.getEmpiricalValue() + 100L);
|
|
|
+ riceRepo.save(rice);
|
|
|
+ createRiceOperationRecord(riceId, RiceOperationType.WATER_DROP, 10L, numberOfActivity, rice
|
|
|
+ .getNumberOfActivity());
|
|
|
+ createRiceOperationRecord(riceId, RiceOperationType.EMPIRICAL_VALUE, 100L, beforeEmpiricalValue4, rice
|
|
|
+ .getEmpiricalValue());
|
|
|
+
|
|
|
+ // Save watering record
|
|
|
+ RiceUserWaterDropRecord record4 = new RiceUserWaterDropRecord();
|
|
|
+ record4.setUserId(riceId);
|
|
|
+ record4.setWateringTime(LocalDateTime.now());
|
|
|
+ riceUserWaterDropRecordRepo.save(record4);
|
|
|
+
|
|
|
+ return R.success("浇水成功").add("can", true).add("num", rice.getNumberOfActivity());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ default:
|
|
|
+ // 处理未知类型
|
|
|
+ return R.error("浇水失败");
|
|
|
+
|
|
|
}
|
|
|
- throw new BusinessException("没有配置对应的等级对应经验值");
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
//签到
|
|
|
public R<?> signIn(Long userId) {
|
|
|
- Optional<Rice> byUserId = riceRepo.findByUserId(userId);
|
|
|
- if (byUserId.isPresent()) {
|
|
|
- Rice rice = byUserId.get();
|
|
|
- Long lastSignInTime = rice.getLastSignInTime();
|
|
|
- Long currentTime = System.currentTimeMillis();
|
|
|
- Long beforeWaterDropCount = rice.getWaterDropCount();
|
|
|
- Long beforeEmpiricalValue = rice.getEmpiricalValue();
|
|
|
- // 判断上次签到时间是否为空,如果为空,则默认为从未签到过
|
|
|
- if (lastSignInTime == null) {
|
|
|
- rice.setWaterDropCount(rice.getWaterDropCount() + 1);
|
|
|
- rice.setSignCount(rice.getSignCount() + 1);
|
|
|
- rice.setLastSignInTime(currentTime);
|
|
|
- riceRepo.save(rice);
|
|
|
- createRiceOperationRecord(userId, RiceOperationType.WATER_DROP, (long) 1, beforeWaterDropCount, rice
|
|
|
- .getWaterDropCount());
|
|
|
- return R.success("签到成功").add("can", true).add("waterDropCount", rice.getWaterDropCount());
|
|
|
- }
|
|
|
- // 判断今天是否已经签到过
|
|
|
- if (DateUtils.isSameDay(new Date(lastSignInTime), new Date(currentTime))) {
|
|
|
- return R.error("今天已经签到过了").add("can", false);
|
|
|
- }
|
|
|
- // 签到成功,水滴数加1,签到次数加1,更新签到时间
|
|
|
- rice.setWaterDropCount(rice.getWaterDropCount() + 1);
|
|
|
+ Rice rice = riceRepo.findByUserId(userId).orElseThrow(new BusinessException("没找到用户"));
|
|
|
+ Long lastSignInTime = rice.getLastSignInTime();
|
|
|
+ Long beforeNumberOfSingnIn = rice.getNumberOfSingnIn();
|
|
|
+ // 判断上次签到时间是否为空,如果为空,则默认为从未签到过
|
|
|
+ if (lastSignInTime == null) {
|
|
|
+
|
|
|
rice.setSignCount(rice.getSignCount() + 1);
|
|
|
- rice.setLastSignInTime(currentTime);
|
|
|
+ rice.setLastSignInTime(System.currentTimeMillis());
|
|
|
+ rice.setNumberOfSingnIn(rice.getNumberOfSingnIn() + 1);
|
|
|
riceRepo.save(rice);
|
|
|
- createRiceOperationRecord(userId, RiceOperationType.WATER_DROP, (long) 1, beforeWaterDropCount, rice
|
|
|
- .getWaterDropCount());
|
|
|
- return R.success("签到成功").add("can", true).add("waterDropCount", rice.getWaterDropCount());
|
|
|
+ createRiceOperationRecord(userId, RiceOperationType.WATER_DROP, (long) 1, beforeNumberOfSingnIn, rice
|
|
|
+ .getNumberOfSingnIn());
|
|
|
+ return R.success("签到成功").add("can", true).add("waterDropCount", rice.getNumberOfSingnIn());
|
|
|
+ }
|
|
|
+ // 判断今天是否已经签到过
|
|
|
+ if (DateUtils.isSameDay(new Date(lastSignInTime), new Date(System.currentTimeMillis()))) {
|
|
|
+ return R.error("今天已经签到过了").add("can", false);
|
|
|
}
|
|
|
- return R.error("签到失败").add("can", false);
|
|
|
+ // 签到成功,水滴数加1,签到次数加1,更新签到时间
|
|
|
+ rice.setNumberOfSingnIn(rice.getNumberOfSingnIn() + 1);
|
|
|
+ rice.setSignCount(rice.getSignCount() + 1);
|
|
|
+ rice.setLastSignInTime(System.currentTimeMillis());
|
|
|
+ riceRepo.save(rice);
|
|
|
+
|
|
|
+ createRiceOperationRecord(userId, RiceOperationType.WATER_DROP, (long) 1, beforeNumberOfSingnIn, rice
|
|
|
+ .getNumberOfSingnIn());
|
|
|
+ return R.success("签到成功").add("can", true).add("waterDropCount", rice.getNumberOfSingnIn());
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
//积分兑换水滴
|
|
|
public R<?> exchangeScoreForWaterDrop(User authenticatedUser) {
|
|
|
- Long authId = authenticatedUser.getId();
|
|
|
- Optional<Rice> byUserId = riceRepo.findByUserId(authId);
|
|
|
- if (byUserId.isPresent()) {
|
|
|
- Rice rice = byUserId.get();
|
|
|
- Long selfScore = rice.getSelfScore();
|
|
|
- Long beforeSelfScore = rice.getSelfScore();
|
|
|
- Integer waterDropCount = Math.toIntExact(rice.getWaterDropCount());
|
|
|
- Long beforeWaterDropCount = rice.getWaterDropCount();
|
|
|
+ Rice rice = riceRepo.findByUserId(authenticatedUser.getId()).orElseThrow(new BusinessException("没找到用户"));
|
|
|
+ //获取当前的积分
|
|
|
+ Long selfScore = rice.getSelfScore();
|
|
|
+ Long beforeSelfScore = rice.getSelfScore();
|
|
|
+ Long beforeNumberOfScoreExchanged = rice.getNumberOfScoreExchanged();
|
|
|
+ // 每次兑换需要消耗的积分和最大兑换次数
|
|
|
+ int exchangeScore = 10;
|
|
|
+ int maxExchangeCount = 10;
|
|
|
+ if (rice.getExchangeCount() == 10) {
|
|
|
+ return R.error("您今天已经兑换十次了.");
|
|
|
+ }
|
|
|
+ int exchangeCount = Math.min((int) (selfScore / exchangeScore), maxExchangeCount - rice.getExchangeCount());
|
|
|
+ int totalScore = exchangeCount * exchangeScore;
|
|
|
|
|
|
- // 每次兑换需要消耗的积分和最大兑换次数
|
|
|
- int exchangeScore = 2;
|
|
|
- int maxExchangeCount = 10;
|
|
|
+ if (exchangeCount > 0) {
|
|
|
+ rice.setSelfScore(selfScore - totalScore);
|
|
|
+ rice.setNumberOfScoreExchanged(rice.getNumberOfScoreExchanged() + exchangeCount);
|
|
|
+ rice.setExchangeCount(rice.getExchangeCount() + exchangeCount);
|
|
|
+ riceRepo.save(rice);
|
|
|
+ createRiceOperationRecord(authenticatedUser.getId(), RiceOperationType.WATER_DROP, (long) exchangeCount, beforeNumberOfScoreExchanged, rice
|
|
|
+ .getNumberOfScoreExchanged());
|
|
|
|
|
|
- // 计算当前可兑换的次数和消耗的积分
|
|
|
-// if (rice.getExchangeCount() == null) {
|
|
|
-// rice.setExchangeCount(0);
|
|
|
-// }
|
|
|
+// createRiceOperationRecord(authenticatedUser.getId(), RiceOperationType.SELF_SCORE, (long) totalScore, beforeSelfScore, rice
|
|
|
+// .getSelfScore());
|
|
|
+ return R.success("兑换成功").add("exchangeCount", exchangeCount)
|
|
|
+ .add("numberOfScoreExchanged", rice.getNumberOfScoreExchanged());
|
|
|
+ } else if (exchangeCount == 0) {
|
|
|
+ return R.error("兑换失败,当前积分不足").add("numberOfScoreExchanged", rice.getNumberOfScoreExchanged()).add("exchangeCount", rice.getExchangeCount());
|
|
|
|
|
|
- if (rice.getExchangeCount() == 10) {
|
|
|
- return R.error("您今天已经兑换十次了.").add("waterDropCount", rice.getWaterDropCount());
|
|
|
- }
|
|
|
- int exchangeCount = Math.min((int) (selfScore / exchangeScore), maxExchangeCount - rice.getExchangeCount());
|
|
|
- int totalScore = exchangeCount * exchangeScore;
|
|
|
-
|
|
|
- if (exchangeCount > 0) {
|
|
|
- rice.setSelfScore(selfScore - totalScore);
|
|
|
- rice.setWaterDropCount((long) (waterDropCount + exchangeCount));
|
|
|
- rice.setExchangeCount(rice.getExchangeCount()+exchangeCount);
|
|
|
- riceRepo.save(rice);
|
|
|
- createRiceOperationRecord(authId, RiceOperationType.WATER_DROP, (long) exchangeCount, beforeWaterDropCount, rice
|
|
|
- .getWaterDropCount());
|
|
|
-
|
|
|
- createRiceOperationRecord(authId, RiceOperationType.SELF_SCORE, (long) totalScore, beforeSelfScore, rice
|
|
|
- .getSelfScore());
|
|
|
- return R.success("兑换成功").add("exchangeCount", exchangeCount)
|
|
|
- .add("waterDropCount", rice.getWaterDropCount());
|
|
|
- } else if (exchangeCount == 0) {
|
|
|
- return R.error("兑换失败,当前积分不足").add("waterDropCount", rice.getWaterDropCount());
|
|
|
-
|
|
|
- } else {
|
|
|
- return R.error("兑换失败,当前积分不足").add("exchangeCount", rice.getExchangeCount()).add("waterDropCount", rice.getWaterDropCount());
|
|
|
- }
|
|
|
+ } else {
|
|
|
+ return R.error("兑换失败,当前积分不足").add("exchangeCount", rice.getExchangeCount()).add("numberOfScoreExchanged", rice.getNumberOfScoreExchanged());
|
|
|
}
|
|
|
- return R.error("兑换失败,用户不存在");
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -532,7 +699,7 @@ public class RiceService {
|
|
|
}
|
|
|
Rice rice = optionalRice.get();
|
|
|
Long currentActivityPoints = rice.getSelfActivityScore();
|
|
|
- Long beforeWaterDropCount = rice.getWaterDropCount();
|
|
|
+ Long beforeWaterDropCount = rice.getNumberOfActivity();
|
|
|
|
|
|
// 计算兑换的水滴数量
|
|
|
Long exchangedWaterDropCount = (long) Math.floor(currentActivityPoints / 2.0);
|
|
|
@@ -542,15 +709,15 @@ public class RiceService {
|
|
|
|
|
|
// 更新用户活动积分和水滴数
|
|
|
rice.setSelfActivityScore(currentActivityPoints - (Long) exchangedWaterDropCount * 2);
|
|
|
- rice.setWaterDropCount(rice.getWaterDropCount() + exchangedWaterDropCount);
|
|
|
+ rice.setNumberOfActivity(rice.getNumberOfActivity() + exchangedWaterDropCount);
|
|
|
riceRepo.save(rice);
|
|
|
|
|
|
// 记录水滴操作记录
|
|
|
createRiceOperationRecord(authenticatedUser
|
|
|
.getId(), RiceOperationType.WATER_DROP, exchangedWaterDropCount, beforeWaterDropCount, rice
|
|
|
- .getWaterDropCount());
|
|
|
+ .getNumberOfActivity());
|
|
|
createRiceOperationRecord(authenticatedUser
|
|
|
- .getId(), RiceOperationType.SELF_ACTIVITY_SCORE, (Long) exchangedWaterDropCount * 2, currentActivityPoints, rice
|
|
|
+ .getId(), RiceOperationType.SELF_ACTIVITY_SCORE, exchangedWaterDropCount * 2, currentActivityPoints, rice
|
|
|
.getSelfActivityScore());
|
|
|
|
|
|
return R.success("兑换成功").add("counts", exchangedWaterDropCount);
|
|
|
@@ -558,6 +725,7 @@ public class RiceService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ //购买商品获得积分
|
|
|
public void addScoreInOrder(Long userId) {
|
|
|
|
|
|
Optional<Rice> byUserId = riceRepo.findByUserId(userId);
|
|
|
@@ -572,28 +740,35 @@ public class RiceService {
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
LocalDateTime todayStartTime = LocalDateTime.of(now.toLocalDate(), LocalTime.MIN).withNano(0);
|
|
|
LocalDateTime todayEndTime = LocalDateTime.of(now.toLocalDate(), LocalTime.MAX).withNano(0);
|
|
|
- int counts = riceOperationRecordRepo.countTodayRiceOperationType(rice.getUserId(), RiceOperationType.SELF_SCORE, todayStartTime, todayEndTime);
|
|
|
- counts = counts + 1;
|
|
|
- int defaultScore = 0;
|
|
|
- for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
- JsonObject jsonObject = jsonArray.getJsonObject(i);
|
|
|
- JsonArray countsArray = jsonObject.getJsonArray("counts");
|
|
|
- int score = jsonObject.getInt("score");
|
|
|
|
|
|
- int lowerBound = countsArray.getInt(0);
|
|
|
- int upperBound = countsArray.getInt(countsArray.size() - 1);
|
|
|
-
|
|
|
- if (counts >= lowerBound && counts <= upperBound) {
|
|
|
- defaultScore = score;
|
|
|
- break;
|
|
|
+ if (rice.getEarnPointsEveryDay() <= 80) {
|
|
|
+ int counts = riceOperationRecordRepo.countTodayRiceOperationType(rice.getUserId(), RiceOperationType.SELF_SCORE, todayStartTime, todayEndTime);
|
|
|
+ counts = counts + 1;
|
|
|
+ int defaultScore = 0;
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
+ JsonObject jsonObject = jsonArray.getJsonObject(i);
|
|
|
+ JsonArray countsArray = jsonObject.getJsonArray("counts");
|
|
|
+ int score = jsonObject.getInt("score");
|
|
|
+
|
|
|
+ int lowerBound = countsArray.getInt(0);
|
|
|
+ int upperBound = countsArray.getInt(countsArray.size() - 1);
|
|
|
+
|
|
|
+ if (counts >= lowerBound && counts <= upperBound) {
|
|
|
+ defaultScore = score;
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ rice.setSelfScore(rice.getSelfScore() + defaultScore);
|
|
|
+ rice.setEarnPointsEveryDay(rice.getEarnPointsEveryDay()+defaultScore);
|
|
|
+ riceRepo.save(rice);
|
|
|
+ createRiceOperationRecord(userId, RiceOperationType.SELF_SCORE, (long) defaultScore, beforeSelfScore, rice.getSelfScore());
|
|
|
+
|
|
|
}
|
|
|
- // 如果 counts 不在任何范围内,则默认的 score 值是最后一个对象中的 score 值
|
|
|
- if (!(defaultScore == 0 && jsonArray.size() > 0)) {
|
|
|
- rice.setSelfScore(rice.getSelfScore() + defaultScore);
|
|
|
- riceRepo.save(rice);
|
|
|
- createRiceOperationRecord(userId, RiceOperationType.SELF_SCORE, (long) defaultScore, beforeSelfScore, rice.getSelfScore());
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|
|
|
}
|