Ver Fonte

feat: 今日收益/历史收益小数位读取配置

hidewnd há 4 semanas atrás
pai
commit
8adb6bc085

+ 11 - 3
yt-question/yt-question-service/src/main/java/com/ytpm/question/controller/UserController.java

@@ -37,6 +37,8 @@ import com.ytpm.risk.view.RiskConfigView;
 import com.ytpm.risk.view.RiskTemplateView;
 import com.ytpm.util.NumberUtils;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -59,6 +61,7 @@ import java.util.Objects;
 import java.util.stream.Collectors;
 
 @Slf4j
+@RefreshScope
 @RestController
 @RequestMapping("/user")
 public class UserController {
@@ -78,6 +81,9 @@ public class UserController {
     @Resource
     private RiskFeign riskFeign;
 
+    @Value("${yt.revenue.scale:3}")
+    private Integer revenueScale;
+
     /**
      * 根据应用ID查询当月注册用户
      */
@@ -171,14 +177,16 @@ public class UserController {
             BigDecimal totalRevenue = user.getTotalIncome() == null ? adRecordMapper.getToTalRevenue(userId, 2) : user.getTotalIncome();
             if (StrUtil.isNotEmpty(revenueDisplayRate)) {
                 BigDecimal rate = NumberUtils.rateToBigDecimal(revenueDisplayRate);
-                int revenueScale = 2;
-                todayRevenue = todayRevenue.multiply(rate).setScale(revenueScale, RoundingMode.HALF_UP).stripTrailingZeros();
-                totalRevenue = totalRevenue.multiply(rate).setScale(revenueScale, RoundingMode.HALF_UP).stripTrailingZeros();
+                todayRevenue = todayRevenue.multiply(rate).setScale(revenueScale, RoundingMode.HALF_UP);
+                totalRevenue = totalRevenue.multiply(rate).setScale(revenueScale, RoundingMode.HALF_UP);
             }
             // 今日收益
             user.setTodayIncome(todayRevenue);
             // 历史收益
             user.setTotalIncome(totalRevenue);
+            if (user.getNearlyIncome() != null) {
+                user.setNearlyIncome(user.getNearlyIncome().setScale(revenueScale, RoundingMode.HALF_UP));
+            }
             // 是否体力已达上限
             boolean ifPowerLimit = false;
             Result<?> result = riskFeign.checkAdRisk(user);