|
|
@@ -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,6 +33,8 @@ 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 {
|
|
|
@@ -162,13 +165,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(authId, getTodayStartTime(), getTodayEndTime());
|
|
|
+ int InviteHelpOthersCounts = riceInviteRepo.countRiceInviteByHelperId(SecurityUtils.getAuthenticatedUser().getId(), getTodayStartTime(), getTodayEndTime());
|
|
|
|
|
|
Long lastSignInTime = rice.getLastSignInTime();
|
|
|
Long currentTime = System.currentTimeMillis();
|
|
|
@@ -200,7 +202,6 @@ 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("isCanExchangeActivityScoreForWater", isCanExchangeActivityScoreForWater)
|
|
|
.add("isInvited", isInvited)
|
|
|
.add("isCanExchangeScore", isCanExchangeScore)
|
|
|
@@ -210,7 +211,6 @@ public class RiceService {
|
|
|
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("isCanExchangeActivityScoreForWater", isCanExchangeActivityScoreForWater)
|
|
|
.add("isInvited", isInvited)
|
|
|
.add("isCanExchangeScore", isCanExchangeScore)
|
|
|
@@ -218,7 +218,6 @@ public class RiceService {
|
|
|
} else {
|
|
|
return R.success("未签到").add("isSignedIn", false)
|
|
|
.add("exchangeCount", rice.getExchangeCount() == null ? 0 : rice.getExchangeCount())
|
|
|
- .add("waterDropCount", rice.getWaterDropCount())
|
|
|
.add("isCanExchangeActivityScoreForWater", isCanExchangeActivityScoreForWater)
|
|
|
.add("isInvited", isInvited)
|
|
|
.add("isCanExchangeScore", isCanExchangeScore)
|
|
|
@@ -347,40 +346,252 @@ public class RiceService {
|
|
|
return R.success(dto);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
//浇水
|
|
|
- public R<? extends Object> watering() {
|
|
|
- // 获取当前用户 ID,
|
|
|
- Long authId = SecurityUtils.getAuthenticatedUser().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() + 10);
|
|
|
- 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);
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ 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("浇水失败");
|
|
|
+
|
|
|
}
|
|
|
- return R.error("浇水失败").add("can", false);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//根据用户ID和今日时间获取今日浇水次数的方法
|
|
|
public Long getTodayWateringCount(Long userId) {
|
|
|
List<RiceUserWaterDropRecord> records = riceUserWaterDropRecordRepo.findByUserId(userId);
|
|
|
@@ -391,7 +602,7 @@ public class RiceService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 每浇水一次可获得2经验值,升级所需经验值为下一等级所配置的经验值标准。按照以下方式来计算用户升级所需水滴数
|
|
|
+ * 每浇水一次可获得10经验值,升级所需经验值为下一等级所配置的经验值标准。按照以下方式来计算用户升级所需水滴数
|
|
|
*
|
|
|
* @param rice
|
|
|
* @return
|
|
|
@@ -424,31 +635,31 @@ public class RiceService {
|
|
|
public R<?> signIn(Long userId) {
|
|
|
Rice rice = riceRepo.findByUserId(userId).orElseThrow(new BusinessException("没找到用户"));
|
|
|
Long lastSignInTime = rice.getLastSignInTime();
|
|
|
- Long beforeWaterDropCount = rice.getWaterDropCount();
|
|
|
+ Long beforeNumberOfSingnIn = rice.getNumberOfSingnIn();
|
|
|
// 判断上次签到时间是否为空,如果为空,则默认为从未签到过
|
|
|
if (lastSignInTime == null) {
|
|
|
- rice.setWaterDropCount(rice.getWaterDropCount() + 1);
|
|
|
+
|
|
|
rice.setSignCount(rice.getSignCount() + 1);
|
|
|
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);
|
|
|
}
|
|
|
// 签到成功,水滴数加1,签到次数加1,更新签到时间
|
|
|
- rice.setWaterDropCount(rice.getWaterDropCount() + 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, 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());
|
|
|
|
|
|
|
|
|
}
|
|
|
@@ -460,35 +671,33 @@ public class RiceService {
|
|
|
//获取当前的积分
|
|
|
Long selfScore = rice.getSelfScore();
|
|
|
Long beforeSelfScore = rice.getSelfScore();
|
|
|
- Integer waterDropCount = Math.toIntExact(rice.getWaterDropCount());
|
|
|
- Long beforeWaterDropCount = rice.getWaterDropCount();
|
|
|
+ Long beforeNumberOfScoreExchanged = rice.getNumberOfScoreExchanged();
|
|
|
// 每次兑换需要消耗的积分和最大兑换次数
|
|
|
int exchangeScore = 10;
|
|
|
int maxExchangeCount = 10;
|
|
|
if (rice.getExchangeCount() == 10) {
|
|
|
- return R.error("您今天已经兑换十次了.").add("waterDropCount", rice.getWaterDropCount()).add("exchangeCount", rice.getExchangeCount());
|
|
|
+ return R.error("您今天已经兑换十次了.");
|
|
|
}
|
|
|
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.setNumberOfScoreExchanged(rice.getNumberOfScoreExchanged()+exchangeCount);
|
|
|
rice.setExchangeCount(rice.getExchangeCount() + exchangeCount);
|
|
|
riceRepo.save(rice);
|
|
|
- createRiceOperationRecord(authenticatedUser.getId(), RiceOperationType.WATER_DROP, (long) exchangeCount, beforeWaterDropCount, rice
|
|
|
- .getWaterDropCount());
|
|
|
+ createRiceOperationRecord(authenticatedUser.getId(), RiceOperationType.WATER_DROP, (long) exchangeCount, beforeNumberOfScoreExchanged, rice
|
|
|
+ .getNumberOfScoreExchanged());
|
|
|
|
|
|
createRiceOperationRecord(authenticatedUser.getId(), RiceOperationType.SELF_SCORE, (long) totalScore, beforeSelfScore, rice
|
|
|
.getSelfScore());
|
|
|
return R.success("兑换成功").add("exchangeCount", exchangeCount)
|
|
|
- .add("waterDropCount", rice.getWaterDropCount());
|
|
|
+ .add("numberOfScoreExchanged", rice.getNumberOfScoreExchanged());
|
|
|
} else if (exchangeCount == 0) {
|
|
|
- return R.error("兑换失败,当前积分不足").add("waterDropCount", rice.getWaterDropCount()).add("exchangeCount", rice.getExchangeCount());
|
|
|
+ return R.error("兑换失败,当前积分不足").add("numberOfScoreExchanged", rice.getNumberOfScoreExchanged()).add("exchangeCount", rice.getExchangeCount());
|
|
|
|
|
|
} else {
|
|
|
- return R.error("兑换失败,当前积分不足").add("exchangeCount", rice.getExchangeCount()).add("waterDropCount", rice.getWaterDropCount());
|
|
|
+ return R.error("兑换失败,当前积分不足").add("exchangeCount", rice.getExchangeCount()).add("numberOfScoreExchanged", rice.getNumberOfScoreExchanged());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -516,7 +725,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);
|
|
|
@@ -526,13 +735,13 @@ 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, exchangedWaterDropCount * 2, currentActivityPoints, rice
|
|
|
.getSelfActivityScore());
|