refactor(mcwl-pay): 调整收入接口返回数据精度

master
yang 2025-03-08 16:06:33 +08:00
parent 39059b6f4c
commit 4369932fa7
2 changed files with 30 additions and 20 deletions

View File

@ -7,6 +7,7 @@ import com.mcwl.system.service.ISysUserService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -24,7 +25,7 @@ public class PlatformData {
* *
*/ */
@ApiOperation(value = "今日收益总额") @ApiOperation(value = "今日收益总额")
@RequestMapping("getTodayIncome") @GetMapping("getTodayIncome")
public R<Double> getTodayIncome() { public R<Double> getTodayIncome() {
Double amount = orderTradeService.getTodayIncome(); Double amount = orderTradeService.getTodayIncome();
return R.ok(amount); return R.ok(amount);
@ -35,7 +36,7 @@ public class PlatformData {
* *
*/ */
@ApiOperation(value = "本月收益总额") @ApiOperation(value = "本月收益总额")
@RequestMapping("getMonthIncome") @GetMapping("getMonthIncome")
public R<Double> getMonthIncome() { public R<Double> getMonthIncome() {
Double amount = orderTradeService.getMonthIncome(); Double amount = orderTradeService.getMonthIncome();
return R.ok(amount); return R.ok(amount);
@ -45,7 +46,7 @@ public class PlatformData {
* *
*/ */
@ApiOperation(value = "年度收益总额") @ApiOperation(value = "年度收益总额")
@RequestMapping("getYearIncome") @GetMapping("getYearIncome")
public R<Double> getYearIncome() { public R<Double> getYearIncome() {
Double amount = orderTradeService.getYearIncome(); Double amount = orderTradeService.getYearIncome();
return R.ok(amount); return R.ok(amount);
@ -55,7 +56,7 @@ public class PlatformData {
* *
*/ */
@ApiOperation(value = "总收益总额") @ApiOperation(value = "总收益总额")
@RequestMapping("getTotalIncome") @GetMapping("getTotalIncome")
public R<Double> getTotalIncome() { public R<Double> getTotalIncome() {
Double amount = orderTradeService.getTotalIncome(); Double amount = orderTradeService.getTotalIncome();
return R.ok(amount); return R.ok(amount);
@ -66,7 +67,7 @@ public class PlatformData {
* ×100% * ×100%
*/ */
@ApiOperation(value = "收益同比增长") @ApiOperation(value = "收益同比增长")
@RequestMapping("getYoYTrend") @GetMapping("getYoYTrend")
public R<Double> getYoYTrend() { public R<Double> getYoYTrend() {
Double yoyTrend = orderTradeService.getYoYTrend(); Double yoyTrend = orderTradeService.getYoYTrend();
return R.ok(yoyTrend); return R.ok(yoyTrend);
@ -77,7 +78,7 @@ public class PlatformData {
* ( - ) / × 100% * ( - ) / × 100%
*/ */
@ApiOperation(value = "收益环比增长") @ApiOperation(value = "收益环比增长")
@RequestMapping("getMoMTrend") @GetMapping("getMoMTrend")
public R<Double> getMoMTrend() { public R<Double> getMoMTrend() {
Double momTrend = orderTradeService.getMoMTrend(); Double momTrend = orderTradeService.getMoMTrend();
return R.ok(momTrend); return R.ok(momTrend);
@ -87,7 +88,7 @@ public class PlatformData {
* *
*/ */
@ApiOperation(value = "获取用户数量") @ApiOperation(value = "获取用户数量")
@RequestMapping("getUserCount") @GetMapping("getUserCount")
public R<Integer> getUserCount() { public R<Integer> getUserCount() {
int count = sysUserService.getUserCount(); int count = sysUserService.getUserCount();
return R.ok(count); return R.ok(count);
@ -97,7 +98,7 @@ public class PlatformData {
* *
*/ */
@ApiOperation(value = "本月新增用户数") @ApiOperation(value = "本月新增用户数")
@RequestMapping("getMonthUserCount") @GetMapping("getMonthUserCount")
public R<Integer> getMonthUserCount() { public R<Integer> getMonthUserCount() {
int count = sysUserService.getMonthUserCount(); int count = sysUserService.getMonthUserCount();
return R.ok(count); return R.ok(count);

View File

@ -185,8 +185,10 @@ public class OrderTradeServiceImpl extends ServiceImpl<OrderTradeMapper, OrderTr
return todayIncome; return todayIncome;
} }
todayIncome = orderTradeMapper.getTodayIncome(); todayIncome = orderTradeMapper.getTodayIncome();
redisCache.setCacheObject("income:todayIncome", todayIncome, 1, TimeUnit.MINUTES); // 保留小数点后两位
return todayIncome; double doubleValue = new BigDecimal(todayIncome).setScale(2, RoundingMode.HALF_UP).doubleValue();
redisCache.setCacheObject("income:todayIncome", doubleValue, 1, TimeUnit.MINUTES);
return doubleValue;
} }
/** /**
@ -201,8 +203,9 @@ public class OrderTradeServiceImpl extends ServiceImpl<OrderTradeMapper, OrderTr
return monthIncome; return monthIncome;
} }
monthIncome = orderTradeMapper.getMonthIncome(); monthIncome = orderTradeMapper.getMonthIncome();
redisCache.setCacheObject("income:monthIncome", monthIncome, 1, TimeUnit.MINUTES); double doubleValue = new BigDecimal(monthIncome).setScale(2, RoundingMode.HALF_UP).doubleValue();
return monthIncome; redisCache.setCacheObject("income:monthIncome", doubleValue, 1, TimeUnit.MINUTES);
return doubleValue;
} }
/** /**
@ -217,8 +220,9 @@ public class OrderTradeServiceImpl extends ServiceImpl<OrderTradeMapper, OrderTr
return yearIncome; return yearIncome;
} }
yearIncome = orderTradeMapper.getYearIncome(); yearIncome = orderTradeMapper.getYearIncome();
redisCache.setCacheObject("income:yearIncome", yearIncome, 1, TimeUnit.MINUTES); double doubleValue = new BigDecimal(yearIncome).setScale(2, RoundingMode.HALF_UP).doubleValue();
return yearIncome; redisCache.setCacheObject("income:yearIncome", doubleValue, 1, TimeUnit.MINUTES);
return doubleValue;
} }
/** /**
@ -233,8 +237,9 @@ public class OrderTradeServiceImpl extends ServiceImpl<OrderTradeMapper, OrderTr
return totalIncome; return totalIncome;
} }
totalIncome = orderTradeMapper.getTotalIncome(); totalIncome = orderTradeMapper.getTotalIncome();
redisCache.setCacheObject("income:totalIncome", totalIncome, 1, TimeUnit.MINUTES); double doubleValue = new BigDecimal(totalIncome).setScale(2, RoundingMode.HALF_UP).doubleValue();
return totalIncome; redisCache.setCacheObject("income:totalIncome", doubleValue, 1, TimeUnit.MINUTES);
return doubleValue;
} }
/** /**
@ -265,9 +270,10 @@ public class OrderTradeServiceImpl extends ServiceImpl<OrderTradeMapper, OrderTr
} }
yoyTrend = (yearIncome - lastYearIncome) / lastYearIncome; yoyTrend = (yearIncome - lastYearIncome) / lastYearIncome;
redisCache.setCacheObject(cacheKey, yoyTrend, 12, TimeUnit.HOURS); double doubleValue = new BigDecimal(yoyTrend).setScale(2, RoundingMode.HALF_UP).doubleValue();
redisCache.setCacheObject(cacheKey, doubleValue, 12, TimeUnit.HOURS);
return yoyTrend; return doubleValue;
} }
/** /**
@ -297,9 +303,12 @@ public class OrderTradeServiceImpl extends ServiceImpl<OrderTradeMapper, OrderTr
} }
momTrend = (month - lastMonth) / lastMonth; momTrend = (month - lastMonth) / lastMonth;
redisCache.setCacheObject(cacheKey, momTrend, 12, TimeUnit.HOURS); // 保留小数点后两位
double doubleValue = new BigDecimal(momTrend).setScale(2, RoundingMode.HALF_UP).doubleValue();
return momTrend; redisCache.setCacheObject(cacheKey, doubleValue, 12, TimeUnit.HOURS);
return doubleValue;
} }
@Override @Override