|
@@ -1,5 +1,6 @@
|
|
|
package com.xs.core.service.Impl.coin;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.ObjUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.xs.core.common.constant.GoldCoinConstant;
|
|
@@ -16,6 +17,8 @@ import com.xs.core.model.coin.entity.GoldCoinProdState;
|
|
|
import com.xs.core.model.coin.entity.UserCoinSpeedUpgradesRecord;
|
|
|
import com.xs.core.model.coin.req.CoinSpeedUpgradesRulesReq;
|
|
|
import com.xs.core.model.coin.req.TemporaryRateReq;
|
|
|
+import com.xs.core.model.coin.resp.BoostResidueTimesResp;
|
|
|
+import com.xs.core.model.coin.resp.CoinSpeedUpgradesRulesResp;
|
|
|
import com.xs.core.model.coin.resp.GoldCoinProdStateResp;
|
|
|
import com.xs.core.model.user.entity.TgUser;
|
|
|
import com.xs.core.mq.producer.GoldCoinMessageProducer;
|
|
@@ -29,6 +32,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.time.Instant;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
@@ -54,6 +58,7 @@ public class GoldCoinServiceImpl implements GoldCoinService {
|
|
|
@Autowired
|
|
|
private GoldCoinMessageProducer messageProducer;
|
|
|
|
|
|
+ @Autowired
|
|
|
private ICoinSpeedUpgradesRulesService speedRulesService;
|
|
|
|
|
|
@Override
|
|
@@ -177,10 +182,12 @@ public class GoldCoinServiceImpl implements GoldCoinService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional
|
|
|
public void permanentBoostProductGoldCoinRate(CoinSpeedUpgradesRulesReq req) {
|
|
|
UserContext context = UserContextHolder.getContext();
|
|
|
//获取金币升级速率
|
|
|
CoinSpeedUpgradesRules rules = speedRulesService.getById(req.getRuleId());
|
|
|
+ CheckUtils.throwIfNull(rules, "金币产出速率升级规则不存在");
|
|
|
TgUser user = userService.getById(context.getId());
|
|
|
BigDecimal goldCoinAmount = user.getGoldCoinAmount();
|
|
|
Integer consumeGoldCoin = rules.getConsumeGoldCoin();
|
|
@@ -206,7 +213,7 @@ public class GoldCoinServiceImpl implements GoldCoinService {
|
|
|
GoldRateUpgradesState upgradesState = redisService.get(rateKey, GoldRateUpgradesState.class);
|
|
|
String temporaryRateStr = goldCoinProdState.getTemporaryRate();
|
|
|
|
|
|
- BigDecimal temporaryRate = new BigDecimal(temporaryRateStr);
|
|
|
+ BigDecimal temporaryRate = StrUtil.isNotBlank(temporaryRateStr) ? new BigDecimal(temporaryRateStr) : BigDecimal.ZERO;
|
|
|
BigDecimal numericalValueDec = new BigDecimal(numericalValue);
|
|
|
BigDecimal currentRate = temporaryRate.add(numericalValueDec);
|
|
|
|
|
@@ -235,6 +242,7 @@ public class GoldCoinServiceImpl implements GoldCoinService {
|
|
|
@Override
|
|
|
public void temporaryBoostProductGoldCoinRate(TemporaryRateReq temporaryRateReq) {
|
|
|
String rate = temporaryRateReq.getRate();
|
|
|
+ BigDecimal rateNum = new BigDecimal(rate).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
|
|
|
UserContext context = UserContextHolder.getContext();
|
|
|
CheckUtils.throwIfNull(context, "用户未登录或用户信息为空");
|
|
|
//获取用户的金币产出状态
|
|
@@ -251,9 +259,10 @@ public class GoldCoinServiceImpl implements GoldCoinService {
|
|
|
upgradesState.setHasTemporaryRate(true);
|
|
|
String currentRateStr = upgradesState.getCurrentRate();
|
|
|
BigDecimal currentRate = new BigDecimal(currentRateStr);
|
|
|
- BigDecimal added = currentRate.add(new BigDecimal(rate));
|
|
|
+ //计算当前速率加上临时速率
|
|
|
+ BigDecimal added = currentRate.add(rateNum);
|
|
|
upgradesState.setCurrentRate(added.toPlainString());
|
|
|
- upgradesState.setTemporaryRate(rate);
|
|
|
+ upgradesState.setTemporaryRate(rateNum.toPlainString());
|
|
|
upgradesState.setRateUpdateFlag(1);
|
|
|
upgradesState.setUpdateTimestamp(epochSecond);
|
|
|
//设置用户的临时速率
|
|
@@ -266,10 +275,10 @@ public class GoldCoinServiceImpl implements GoldCoinService {
|
|
|
CheckUtils.throwIfNull(coinProdState, "用户未开启金币产出");
|
|
|
String currentRateStr = coinProdState.getCurrentRate();
|
|
|
BigDecimal currentRate = new BigDecimal(currentRateStr);
|
|
|
- BigDecimal added = currentRate.add(new BigDecimal(rate));
|
|
|
+ BigDecimal added = currentRate.add(rateNum);
|
|
|
upgradesState.setCurrentRate(added.toPlainString());
|
|
|
upgradesState.setUpdateTimestamp(epochSecond);
|
|
|
- upgradesState.setTemporaryRate(rate);
|
|
|
+ upgradesState.setTemporaryRate(rateNum.toPlainString());
|
|
|
upgradesState.setRateUpdateFlag(1);
|
|
|
redisService.set(rateTemporarilyKey, upgradesState);
|
|
|
}
|
|
@@ -318,8 +327,32 @@ public class GoldCoinServiceImpl implements GoldCoinService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<CoinSpeedUpgradesRules> getRateUpgradesRulesByUser() {
|
|
|
+ public CoinSpeedUpgradesRulesResp getRateUpgradesRulesByUser() {
|
|
|
+ UserContext context = UserContextHolder.getContext();
|
|
|
+ List<CoinSpeedUpgradesRules> rules = speedRulesService.getCoinSpeedUpgradesRulesByUserId(context.getId());
|
|
|
+
|
|
|
+ if (CollUtil.isNotEmpty(rules)) {
|
|
|
+ boolean anyMatch = rules.stream().anyMatch(rule -> rule.getUpgradeStatus().equals("MAX"));
|
|
|
+ CoinSpeedUpgradesRulesResp rulesResp = new CoinSpeedUpgradesRulesResp();
|
|
|
+ rulesResp.setList(rules);
|
|
|
+ if (anyMatch) {
|
|
|
+ rulesResp.setStatus(1);
|
|
|
+ } else {
|
|
|
+ rulesResp.setStatus(0);
|
|
|
+ }
|
|
|
+ return rulesResp;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BoostResidueTimesResp getBoostResidueTimes() {
|
|
|
UserContext context = UserContextHolder.getContext();
|
|
|
- return speedRulesService.getCoinSpeedUpgradesRulesByUserId(context.getId());
|
|
|
+ String key = GoldCoinConstant.GOLD_COIN_STATE_KEY + context.getId();
|
|
|
+ GoldCoinProdState goldCoinProdState = redisService.get(key, GoldCoinProdState.class);
|
|
|
+ CheckUtils.throwIfNull(goldCoinProdState, "金币产出结束或未开启金币产出,加成已失效");
|
|
|
+ BoostResidueTimesResp boostResidueTimesResp = new BoostResidueTimesResp();
|
|
|
+ BeanUtils.copyProperties(goldCoinProdState, boostResidueTimesResp);
|
|
|
+ return boostResidueTimesResp;
|
|
|
}
|
|
|
}
|