首页优化
This commit is contained in:
1 parent
c58e55a2e1
commit
705609282f
3 files changed
+134
No files matched your search
+21
@@ -0,0 +1,21 @@
|
||||
package com.ruoyi.system.controller;
|
||||
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.system.service.PaymentDashboardService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/** 登录首页支付经营数据。 */
|
||||
@RestController
|
||||
@RequestMapping("/system/dashboard")
|
||||
public class PaymentDashboardController {
|
||||
@Autowired
|
||||
private PaymentDashboardService dashboardService;
|
||||
|
||||
@GetMapping("/overview")
|
||||
public AjaxResult overview() {
|
||||
return AjaxResult.success(dashboardService.overview());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.ruoyi.system.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/** 支付首页聚合查询,所有查询都接受服务端确定的用户数据范围。 */
|
||||
public interface PaymentDashboardMapper {
|
||||
@Select({"<script>",
|
||||
"select count(1) appCount, sum(case when status=1 then 1 else 0 end) enabledAppCount,",
|
||||
"coalesce(sum(usdt_balance),0) usdtBalance, coalesce(sum(trx_balance),0) trxBalance,",
|
||||
"coalesce(sum(usdt_frozen_balance),0) usdtFrozenBalance, coalesce(sum(trx_frozen_balance),0) trxFrozenBalance,",
|
||||
"coalesce(sum(credit_limit),0) creditLimit from apps where deleted_at is null",
|
||||
"<if test='userId != null'> and user_id=#{userId}</if>", "</script>"})
|
||||
Map<String, Object> selectAppsSummary(@Param("userId") Long userId);
|
||||
|
||||
@Select({"<script>",
|
||||
"select count(1) walletCount, coalesce(sum(usdt_balance),0) walletUsdtBalance,",
|
||||
"coalesce(sum(trx_balance),0) walletTrxBalance,",
|
||||
"sum(case when status=1 then 1 else 0 end) enabledWalletCount",
|
||||
"from wallet_address where deleted_at is null and wallet_user_name is not null",
|
||||
"<if test='userId != null'> and user_id=#{userId}</if>", "</script>"})
|
||||
Map<String, Object> selectWalletSummary(@Param("userId") Long userId);
|
||||
|
||||
@Select({"<script>",
|
||||
"select count(1) totalCount, sum(case when status=1 then 1 else 0 end) pendingCount,",
|
||||
"sum(case when status=2 then 1 else 0 end) paidCount, sum(case when status=3 then 1 else 0 end) expiredCount,",
|
||||
"coalesce(sum(case when status=2 then actual_amount else 0 end),0) paidUsdtAmount,",
|
||||
"coalesce(sum(case when status=2 and created_at >= curdate() then actual_amount else 0 end),0) todayPaidUsdtAmount,",
|
||||
"sum(case when status=2 and created_at >= curdate() then 1 else 0 end) todayPaidCount",
|
||||
"from orders where deleted_at is null",
|
||||
"<if test='userId != null'> and user_id=#{userId}</if>", "</script>"})
|
||||
Map<String, Object> selectPaymentSummary(@Param("userId") Long userId);
|
||||
|
||||
@Select({"<script>",
|
||||
"select count(1) totalCount, sum(case when status=0 then 1 else 0 end) pendingAuditCount,",
|
||||
"sum(case when status in (1,6) then 1 else 0 end) pendingExecuteCount,",
|
||||
"sum(case when status=2 then 1 else 0 end) confirmingCount,",
|
||||
"sum(case when status=3 then 1 else 0 end) completedCount,",
|
||||
"sum(case when status=4 then 1 else 0 end) rejectedCount,",
|
||||
"sum(case when status=5 then 1 else 0 end) failedCount,",
|
||||
"coalesce(sum(case when status=3 and currency='USDT' then amount else 0 end),0) completedUsdtAmount,",
|
||||
"coalesce(sum(case when status=3 and currency='TRX' then amount else 0 end),0) completedTrxAmount,",
|
||||
"coalesce(sum(case when status=3 then fee_amount else 0 end),0) payoutFeeTrx",
|
||||
"from usdt_payout_order where deleted_at is null",
|
||||
"<if test='userId != null'> and user_id=#{userId}</if>", "</script>"})
|
||||
Map<String, Object> selectPayoutSummary(@Param("userId") Long userId);
|
||||
|
||||
@Select({"<script>",
|
||||
"select date(created_at) period, count(1) orderCount, coalesce(sum(actual_amount),0) amount",
|
||||
"from orders where deleted_at is null and status=2 and created_at >= date_sub(curdate(), interval 29 day)",
|
||||
"<if test='userId != null'> and user_id=#{userId}</if>",
|
||||
"group by date(created_at) order by period", "</script>"})
|
||||
List<Map<String, Object>> selectPaymentTrend(@Param("userId") Long userId);
|
||||
|
||||
@Select({"<script>",
|
||||
"select date(created_at) period, currency, count(1) orderCount, coalesce(sum(amount),0) amount",
|
||||
"from usdt_payout_order where deleted_at is null and status=3",
|
||||
"and created_at >= date_sub(curdate(), interval 29 day)",
|
||||
"<if test='userId != null'> and user_id=#{userId}</if>",
|
||||
"group by date(created_at), currency order by period, currency", "</script>"})
|
||||
List<Map<String, Object>> selectPayoutTrend(@Param("userId") Long userId);
|
||||
|
||||
@Select({"<script>",
|
||||
"select currency, direction, business_type businessType, count(1) ledgerCount,",
|
||||
"coalesce(sum(amount),0) amount from apps_balance_ledger where created_at >= date_sub(now(), interval 30 day)",
|
||||
"<if test='userId != null'> and user_id=#{userId}</if>",
|
||||
"group by currency, direction, business_type order by amount desc", "</script>"})
|
||||
List<Map<String, Object>> selectLedgerDistribution(@Param("userId") Long userId);
|
||||
|
||||
@Select({"<script>",
|
||||
"select a.id appId, a.name appName,",
|
||||
"sum(case when o.status=2 then 1 else 0 end) paidCount,",
|
||||
"coalesce(sum(case when o.status=2 then o.actual_amount else 0 end),0) paidAmount",
|
||||
"from apps a left join orders o on o.app_id=a.id and o.deleted_at is null",
|
||||
"where a.deleted_at is null <if test='userId != null'> and a.user_id=#{userId}</if>",
|
||||
"group by a.id,a.name order by paidAmount desc limit 8", "</script>"})
|
||||
List<Map<String, Object>> selectTopApps(@Param("userId") Long userId);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.ruoyi.system.service;
|
||||
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.system.mapper.PaymentDashboardMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/** 组装首页所需的支付经营指标,避免前端并发请求多个业务接口。 */
|
||||
@Service
|
||||
public class PaymentDashboardService {
|
||||
@Autowired
|
||||
private PaymentDashboardMapper mapper;
|
||||
|
||||
public Map<String, Object> overview() {
|
||||
Long currentUserId = SecurityUtils.getUserId();
|
||||
Long scopedUserId = SecurityUtils.isAdmin(currentUserId) ? null : currentUserId;
|
||||
Map<String, Object> result = new LinkedHashMap<String, Object>();
|
||||
result.put("admin", scopedUserId == null);
|
||||
result.put("apps", mapper.selectAppsSummary(scopedUserId));
|
||||
result.put("wallets", mapper.selectWalletSummary(scopedUserId));
|
||||
result.put("payments", mapper.selectPaymentSummary(scopedUserId));
|
||||
result.put("payouts", mapper.selectPayoutSummary(scopedUserId));
|
||||
result.put("paymentTrend", mapper.selectPaymentTrend(scopedUserId));
|
||||
result.put("payoutTrend", mapper.selectPayoutTrend(scopedUserId));
|
||||
result.put("ledgerDistribution", mapper.selectLedgerDistribution(scopedUserId));
|
||||
result.put("topApps", mapper.selectTopApps(scopedUserId));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user