From 39059b6f4c37f51b490e0097b7ca0ca31d03d44d Mon Sep 17 00:00:00 2001 From: yang <2119157836@qq.com> Date: Sat, 8 Mar 2025 15:18:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(platform):=20=E5=B9=B3=E5=8F=B0=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/platformData/PlatformData.java | 111 +++++++++++++++ mcwl-admin/src/main/resources/application.yml | 2 +- .../web/exception/GlobalExceptionHandler.java | 6 +- .../framework/web/service/TokenService.java | 3 + .../com/mcwl/pay/mapper/OrderTradeMapper.java | 37 +++++ .../mcwl/pay/service/OrderTradeService.java | 35 +++++ .../service/impl/OrderTradeServiceImpl.java | 130 ++++++++++++++++++ .../resources/mapper/pay/OrderTradeMapper.xml | 43 ++++++ .../com/mcwl/system/mapper/SysUserMapper.java | 3 + .../mcwl/system/service/ISysUserService.java | 4 + .../service/impl/SysUserServiceImpl.java | 11 ++ .../resources/mapper/system/SysUserMapper.xml | 11 ++ 12 files changed, 392 insertions(+), 4 deletions(-) create mode 100644 mcwl-admin/src/main/java/com/mcwl/web/controller/platformData/PlatformData.java diff --git a/mcwl-admin/src/main/java/com/mcwl/web/controller/platformData/PlatformData.java b/mcwl-admin/src/main/java/com/mcwl/web/controller/platformData/PlatformData.java new file mode 100644 index 0000000..86b864b --- /dev/null +++ b/mcwl-admin/src/main/java/com/mcwl/web/controller/platformData/PlatformData.java @@ -0,0 +1,111 @@ +package com.mcwl.web.controller.platformData; + + +import com.mcwl.common.core.domain.R; +import com.mcwl.pay.service.OrderTradeService; +import com.mcwl.system.service.ISysUserService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Api(tags = "平台数据") +@RestController +@RequestMapping("platformData") +@RequiredArgsConstructor +public class PlatformData { + + private final OrderTradeService orderTradeService; + + private final ISysUserService sysUserService; + + /** + * 今日收益总额 + */ + @ApiOperation(value = "今日收益总额") + @RequestMapping("getTodayIncome") + public R getTodayIncome() { + Double amount = orderTradeService.getTodayIncome(); + return R.ok(amount); + } + + + /** + * 本月收益总额 + */ + @ApiOperation(value = "本月收益总额") + @RequestMapping("getMonthIncome") + public R getMonthIncome() { + Double amount = orderTradeService.getMonthIncome(); + return R.ok(amount); + } + + /** + * 年度收益总额 + */ + @ApiOperation(value = "年度收益总额") + @RequestMapping("getYearIncome") + public R getYearIncome() { + Double amount = orderTradeService.getYearIncome(); + return R.ok(amount); + } + + /** + * 总收益总额 + */ + @ApiOperation(value = "总收益总额") + @RequestMapping("getTotalIncome") + public R getTotalIncome() { + Double amount = orderTradeService.getTotalIncome(); + return R.ok(amount); + } + + /** + * 收益同比增长 (Year-on-Year, YoY) + * (本期数-同期数)/同期数×100% + */ + @ApiOperation(value = "收益同比增长") + @RequestMapping("getYoYTrend") + public R getYoYTrend() { + Double yoyTrend = orderTradeService.getYoYTrend(); + return R.ok(yoyTrend); + } + + /** + * 收益环比增长 (Month-on-Month, MoM) + * (本期数 - 上期数) / 上期数 × 100% + */ + @ApiOperation(value = "收益环比增长") + @RequestMapping("getMoMTrend") + public R getMoMTrend() { + Double momTrend = orderTradeService.getMoMTrend(); + return R.ok(momTrend); + } + + /** + * 获取用户数量 + */ + @ApiOperation(value = "获取用户数量") + @RequestMapping("getUserCount") + public R getUserCount() { + int count = sysUserService.getUserCount(); + return R.ok(count); + } + + /** + * 本月新增用户数 + */ + @ApiOperation(value = "本月新增用户数") + @RequestMapping("getMonthUserCount") + public R getMonthUserCount() { + int count = sysUserService.getMonthUserCount(); + return R.ok(count); + } + + + + + + +} diff --git a/mcwl-admin/src/main/resources/application.yml b/mcwl-admin/src/main/resources/application.yml index b2d3e28..311a165 100644 --- a/mcwl-admin/src/main/resources/application.yml +++ b/mcwl-admin/src/main/resources/application.yml @@ -34,7 +34,7 @@ server: # 日志配置 logging: level: - com.mcwl: error + com.mcwl: debug org.springframework: warn # 用户配置 diff --git a/mcwl-framework/src/main/java/com/mcwl/framework/web/exception/GlobalExceptionHandler.java b/mcwl-framework/src/main/java/com/mcwl/framework/web/exception/GlobalExceptionHandler.java index a448df0..6baa491 100644 --- a/mcwl-framework/src/main/java/com/mcwl/framework/web/exception/GlobalExceptionHandler.java +++ b/mcwl-framework/src/main/java/com/mcwl/framework/web/exception/GlobalExceptionHandler.java @@ -49,11 +49,11 @@ public class GlobalExceptionHandler { /** * redis连接超时异常 */ - @ExceptionHandler(QueryTimeoutException.class) - public AjaxResult commandTimeoutException(QueryTimeoutException e, HttpServletRequest request) { + @ExceptionHandler(RedisCommandTimeoutException.class) + public AjaxResult commandTimeoutException(RedisCommandTimeoutException e, HttpServletRequest request) { String requestURI = request.getRequestURI(); log.error("redis异常{},{}", requestURI, e.getMessage()); - return AjaxResult.error(HttpStatus.WARN, "超时"); + return AjaxResult.warn("超时"); } diff --git a/mcwl-framework/src/main/java/com/mcwl/framework/web/service/TokenService.java b/mcwl-framework/src/main/java/com/mcwl/framework/web/service/TokenService.java index 413d2fa..9592247 100644 --- a/mcwl-framework/src/main/java/com/mcwl/framework/web/service/TokenService.java +++ b/mcwl-framework/src/main/java/com/mcwl/framework/web/service/TokenService.java @@ -82,6 +82,9 @@ public class TokenService } catch (Exception e) { + if (e.getCause() instanceof io.lettuce.core.RedisCommandTimeoutException) { + throw new RedisCommandTimeoutException("连接超时"); + } log.error("获取用户信息异常'{}'", e.getMessage()); } } diff --git a/mcwl-pay/src/main/java/com/mcwl/pay/mapper/OrderTradeMapper.java b/mcwl-pay/src/main/java/com/mcwl/pay/mapper/OrderTradeMapper.java index 9be6679..a98d5aa 100644 --- a/mcwl-pay/src/main/java/com/mcwl/pay/mapper/OrderTradeMapper.java +++ b/mcwl-pay/src/main/java/com/mcwl/pay/mapper/OrderTradeMapper.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.mcwl.pay.domain.OrderTrade; import com.mcwl.pay.domain.PaymentResult; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; /** * @Author:ChenYan @@ -18,4 +19,40 @@ public interface OrderTradeMapper extends BaseMapper { PaymentResult chargeCard(Integer totalAmount, String paymentMethod); + /** + * 获取今日收益 + * @return Double + */ + Double getTodayIncome(); + + /** + * 获取本月收益 + * @return Double + */ + Double getMonthIncome(); + + /** + * 获取指定年月收益 + * @return Double + */ + Double getIncomeByMonth(@Param("year") Integer year, @Param("month") Integer month); + + /** + * 获取年度收益 + * @return Double + */ + Double getYearIncome(); + + /** + * 获取指定年收益 + * @return Double + */ + Double getIncomeByYear(@Param("year") Integer year); + + /** + * 获取总收益 + * @return Double + */ + Double getTotalIncome(); + } diff --git a/mcwl-pay/src/main/java/com/mcwl/pay/service/OrderTradeService.java b/mcwl-pay/src/main/java/com/mcwl/pay/service/OrderTradeService.java index af53198..b440262 100644 --- a/mcwl-pay/src/main/java/com/mcwl/pay/service/OrderTradeService.java +++ b/mcwl-pay/src/main/java/com/mcwl/pay/service/OrderTradeService.java @@ -40,4 +40,39 @@ public interface OrderTradeService extends IService { */ TableDataInfo getRecord(PageDomain pageDomain, String productName); + /** + * 获取今日收益 + * @return Double + */ + Double getTodayIncome(); + + /** + * 获取本月收益 + * @return Double + */ + Double getMonthIncome(); + + /** + * 获取年度收益 + * @return Double + */ + Double getYearIncome(); + + /** + * 获取总收益 + * @return Double + */ + Double getTotalIncome(); + + /** + * 获取收益同比增长率 + * @return Double + */ + Double getYoYTrend(); + + /** + * 获取收益环比增长 + * @return Double + */ + Double getMoMTrend(); } diff --git a/mcwl-pay/src/main/java/com/mcwl/pay/service/impl/OrderTradeServiceImpl.java b/mcwl-pay/src/main/java/com/mcwl/pay/service/impl/OrderTradeServiceImpl.java index 8c77347..5aa3afb 100644 --- a/mcwl-pay/src/main/java/com/mcwl/pay/service/impl/OrderTradeServiceImpl.java +++ b/mcwl-pay/src/main/java/com/mcwl/pay/service/impl/OrderTradeServiceImpl.java @@ -46,7 +46,9 @@ import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.math.RoundingMode; +import java.time.LocalDate; import java.util.*; +import java.util.concurrent.TimeUnit; /** * @Author:ChenYan @@ -171,6 +173,134 @@ public class OrderTradeServiceImpl extends ServiceImpl selectMallProductList(OrderTrade orderTrade) { diff --git a/mcwl-pay/src/main/resources/mapper/pay/OrderTradeMapper.xml b/mcwl-pay/src/main/resources/mapper/pay/OrderTradeMapper.xml index 44271f2..fab7799 100644 --- a/mcwl-pay/src/main/resources/mapper/pay/OrderTradeMapper.xml +++ b/mcwl-pay/src/main/resources/mapper/pay/OrderTradeMapper.xml @@ -8,4 +8,47 @@ + + + + + + + + + + + + + + diff --git a/mcwl-system/src/main/java/com/mcwl/system/mapper/SysUserMapper.java b/mcwl-system/src/main/java/com/mcwl/system/mapper/SysUserMapper.java index 7f6dbf3..e04517e 100644 --- a/mcwl-system/src/main/java/com/mcwl/system/mapper/SysUserMapper.java +++ b/mcwl-system/src/main/java/com/mcwl/system/mapper/SysUserMapper.java @@ -144,4 +144,7 @@ public interface SysUserMapper void updateBackgroundImg(@Param("id") Long id, @Param("path") String path); + Integer getUserCount(); + + Integer getMonthUserCount(); } diff --git a/mcwl-system/src/main/java/com/mcwl/system/service/ISysUserService.java b/mcwl-system/src/main/java/com/mcwl/system/service/ISysUserService.java index 2ef5258..69b8d49 100644 --- a/mcwl-system/src/main/java/com/mcwl/system/service/ISysUserService.java +++ b/mcwl-system/src/main/java/com/mcwl/system/service/ISysUserService.java @@ -219,4 +219,8 @@ public interface ISysUserService List listByIds(List userIdList); void updateBackgroundImg(Long id, String path); + + Integer getUserCount(); + + Integer getMonthUserCount(); } diff --git a/mcwl-system/src/main/java/com/mcwl/system/service/impl/SysUserServiceImpl.java b/mcwl-system/src/main/java/com/mcwl/system/service/impl/SysUserServiceImpl.java index 9892e3e..cbab0a1 100644 --- a/mcwl-system/src/main/java/com/mcwl/system/service/impl/SysUserServiceImpl.java +++ b/mcwl-system/src/main/java/com/mcwl/system/service/impl/SysUserServiceImpl.java @@ -693,4 +693,15 @@ public class SysUserServiceImpl implements ISysUserService return sb.toString(); } + + + @Override + public Integer getUserCount() { + return userMapper.getUserCount(); + } + + @Override + public Integer getMonthUserCount() { + return userMapper.getMonthUserCount(); + } } diff --git a/mcwl-system/src/main/resources/mapper/system/SysUserMapper.xml b/mcwl-system/src/main/resources/mapper/system/SysUserMapper.xml index b2f368e..765d343 100644 --- a/mcwl-system/src/main/resources/mapper/system/SysUserMapper.xml +++ b/mcwl-system/src/main/resources/mapper/system/SysUserMapper.xml @@ -181,6 +181,17 @@ WHERE a.to_user_id = #{userId} + + + + insert into sys_user( user_id,