1:用户管理页面优化 2:角色管理页面优化 3:分配角色权限优化
This commit is contained in:
+2
@@ -2,6 +2,7 @@ package com.central.device.service.impl;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.central.common.datascope.annotation.IgnoreTenantScope;
|
||||||
import com.central.common.model.PageResult;
|
import com.central.common.model.PageResult;
|
||||||
import com.central.common.service.impl.SuperServiceImpl;
|
import com.central.common.service.impl.SuperServiceImpl;
|
||||||
import com.central.device.mapper.LineFileMapper;
|
import com.central.device.mapper.LineFileMapper;
|
||||||
@@ -36,6 +37,7 @@ public class LineFileServiceImpl extends SuperServiceImpl<LineFileMapper, LineFi
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@IgnoreTenantScope
|
||||||
public LineFile findLineFileByWaylineId(String waylineId) {
|
public LineFile findLineFileByWaylineId(String waylineId) {
|
||||||
return baseMapper.selectOne(new QueryWrapper<LineFile>()
|
return baseMapper.selectOne(new QueryWrapper<LineFile>()
|
||||||
.eq("wayline_id",waylineId));
|
.eq("wayline_id",waylineId));
|
||||||
|
|||||||
+34
@@ -233,4 +233,38 @@ public class DashboardController {
|
|||||||
return Result.failed("获取订单列表失败:" + e.getMessage());
|
return Result.failed("获取订单列表失败:" + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "获取订单时间序列(创建/完成/退款)")
|
||||||
|
@GetMapping("/statistics/series")
|
||||||
|
public Result<List<com.central.order.model.vo.TrendDataVO>> getOrderSeries(
|
||||||
|
@Parameter(description = "租户ID") @RequestParam(required = false) String tenantId,
|
||||||
|
@Parameter(description = "是否包含子租户") @RequestParam(required = false) Boolean includeChildren,
|
||||||
|
@Parameter(description = "统计类型(date/week/month/year)") @RequestParam(required = false) String statType,
|
||||||
|
@Parameter(description = "景区ID") @RequestParam(required = false) Long tourismId,
|
||||||
|
@Parameter(description = "二维码ID") @RequestParam(required = false) String qrcodeId,
|
||||||
|
@Parameter(description = "设备编号") @RequestParam(required = false) String deviceSn,
|
||||||
|
@Parameter(description = "开始时间") @RequestParam(required = false) String startTime,
|
||||||
|
@Parameter(description = "结束时间") @RequestParam(required = false) String endTime,
|
||||||
|
@Parameter(description = "是否包含测试二维码") @RequestParam(required = false, defaultValue = "false") Boolean includeTestQrcodes)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
Map<String, Object> params = new HashMap<>();
|
||||||
|
params.put("tenantId", tenantId);
|
||||||
|
params.put("includeChildren", includeChildren);
|
||||||
|
params.put("tourismId", tourismId);
|
||||||
|
params.put("qrcodeId", qrcodeId);
|
||||||
|
params.put("deviceSn", deviceSn);
|
||||||
|
params.put("startTime", startTime);
|
||||||
|
params.put("endTime", endTime);
|
||||||
|
params.put("includeTestQrcodes", includeTestQrcodes);
|
||||||
|
// 传递 rangeType 以让后端选择 seriesType
|
||||||
|
params.put("rangeType", statType);
|
||||||
|
params.put("statType", statType);
|
||||||
|
List<com.central.order.model.vo.TrendDataVO> series = dashboardService.getOrderTimeSeries(params);
|
||||||
|
return Result.succeed(series, "获取订单时间序列成功");
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("获取订单时间序列失败", e);
|
||||||
|
return Result.failed("获取订单时间序列失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+130
@@ -1,6 +1,7 @@
|
|||||||
package com.central.order.mapper;
|
package com.central.order.mapper;
|
||||||
|
|
||||||
import com.central.order.model.vo.*;
|
import com.central.order.model.vo.*;
|
||||||
|
import com.central.order.model.vo.TrendDataVO;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
@@ -215,6 +216,135 @@ public interface DashboardMapper {
|
|||||||
})
|
})
|
||||||
Long getTodayPaidOrders(@Param("p") Map<String, Object> params);
|
Long getTodayPaidOrders(@Param("p") Map<String, Object> params);
|
||||||
|
|
||||||
|
// ======================= 新增:折线图三类时间序列(创建/完成/退款) =======================
|
||||||
|
@Select({
|
||||||
|
"<script>",
|
||||||
|
"SELECT",
|
||||||
|
" <choose>",
|
||||||
|
" <when test='p.seriesType == \"hour\"'> DATE_FORMAT(o.create_time, '%H:00') </when>",
|
||||||
|
" <when test='p.seriesType == \"month\"'> DATE_FORMAT(o.create_time, '%Y-%m') </when>",
|
||||||
|
" <otherwise> DATE_FORMAT(o.create_time, '%Y-%m-%d') </otherwise>",
|
||||||
|
" </choose> AS date,",
|
||||||
|
" '订单创建' AS type,",
|
||||||
|
" 'created' AS typeCode,",
|
||||||
|
" COUNT(1) AS value",
|
||||||
|
"FROM orders o",
|
||||||
|
"JOIN qrcodes q ON o.code_id = q.code_id",
|
||||||
|
"WHERE 1=1",
|
||||||
|
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||||
|
" AND q.is_test = 0",
|
||||||
|
"</if>",
|
||||||
|
"<if test='p.tourismId != null'>",
|
||||||
|
" AND o.tourism_id = #{p.tourismId}",
|
||||||
|
"</if>",
|
||||||
|
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
|
||||||
|
" AND o.code_id = #{p.qrcodeId}",
|
||||||
|
"</if>",
|
||||||
|
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
|
||||||
|
" AND o.device_sn = #{p.deviceSn}",
|
||||||
|
"</if>",
|
||||||
|
"<if test='p.startTime != null and p.startTime != \"\"'>",
|
||||||
|
" AND o.create_time >= #{p.startTime}",
|
||||||
|
"</if>",
|
||||||
|
"<if test='p.endTime != null and p.endTime != \"\"'>",
|
||||||
|
" AND o.create_time <= #{p.endTime}",
|
||||||
|
"</if>",
|
||||||
|
"<if test='p.tourismIds != null and p.tourismIds.size > 0'>",
|
||||||
|
" AND o.tourism_id IN",
|
||||||
|
" <foreach collection='p.tourismIds' item='tid' open='(' separator=',' close=')'>#{tid}</foreach>",
|
||||||
|
"</if>",
|
||||||
|
"GROUP BY date",
|
||||||
|
"ORDER BY date ASC",
|
||||||
|
"</script>"
|
||||||
|
})
|
||||||
|
List<TrendDataVO> getOrderSeriesCreated(@Param("p") Map<String, Object> params);
|
||||||
|
|
||||||
|
@Select({
|
||||||
|
"<script>",
|
||||||
|
"SELECT",
|
||||||
|
" <choose>",
|
||||||
|
" <when test='p.seriesType == \"hour\"'> DATE_FORMAT(o.create_time, '%H:00') </when>",
|
||||||
|
" <when test='p.seriesType == \"month\"'> DATE_FORMAT(o.create_time, '%Y-%m') </when>",
|
||||||
|
" <otherwise> DATE_FORMAT(o.create_time, '%Y-%m-%d') </otherwise>",
|
||||||
|
" </choose> AS date,",
|
||||||
|
" '完成' AS type,",
|
||||||
|
" 'completed' AS typeCode,",
|
||||||
|
" COUNT(1) AS value",
|
||||||
|
"FROM orders o",
|
||||||
|
"JOIN qrcodes q ON o.code_id = q.code_id",
|
||||||
|
"WHERE 1=1",
|
||||||
|
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||||
|
" AND q.is_test = 0",
|
||||||
|
"</if>",
|
||||||
|
"AND o.order_status = 3",
|
||||||
|
"<if test='p.tourismId != null'>",
|
||||||
|
" AND o.tourism_id = #{p.tourismId}",
|
||||||
|
"</if>",
|
||||||
|
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
|
||||||
|
" AND o.code_id = #{p.qrcodeId}",
|
||||||
|
"</if>",
|
||||||
|
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
|
||||||
|
" AND o.device_sn = #{p.deviceSn}",
|
||||||
|
"</if>",
|
||||||
|
"<if test='p.startTime != null and p.startTime != \"\"'>",
|
||||||
|
" AND o.create_time >= #{p.startTime}",
|
||||||
|
"</if>",
|
||||||
|
"<if test='p.endTime != null and p.endTime != \"\"'>",
|
||||||
|
" AND o.create_time <= #{p.endTime}",
|
||||||
|
"</if>",
|
||||||
|
"<if test='p.tourismIds != null and p.tourismIds.size > 0'>",
|
||||||
|
" AND o.tourism_id IN",
|
||||||
|
" <foreach collection='p.tourismIds' item='tid' open='(' separator=',' close=')'>#{tid}</foreach>",
|
||||||
|
"</if>",
|
||||||
|
"GROUP BY date",
|
||||||
|
"ORDER BY date ASC",
|
||||||
|
"</script>"
|
||||||
|
})
|
||||||
|
List<TrendDataVO> getOrderSeriesCompleted(@Param("p") Map<String, Object> params);
|
||||||
|
|
||||||
|
@Select({
|
||||||
|
"<script>",
|
||||||
|
"SELECT",
|
||||||
|
" <choose>",
|
||||||
|
" <when test='p.seriesType == \"hour\"'> DATE_FORMAT(o.create_time, '%H:00') </when>",
|
||||||
|
" <when test='p.seriesType == \"month\"'> DATE_FORMAT(o.create_time, '%Y-%m') </when>",
|
||||||
|
" <otherwise> DATE_FORMAT(o.create_time, '%Y-%m-%d') </otherwise>",
|
||||||
|
" </choose> AS date,",
|
||||||
|
" '退款' AS type,",
|
||||||
|
" 'refunded' AS typeCode,",
|
||||||
|
" COUNT(1) AS value",
|
||||||
|
"FROM orders o",
|
||||||
|
"JOIN qrcodes q ON o.code_id = q.code_id",
|
||||||
|
"WHERE 1=1",
|
||||||
|
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||||
|
" AND q.is_test = 0",
|
||||||
|
"</if>",
|
||||||
|
"AND o.order_status = 8",
|
||||||
|
"<if test='p.tourismId != null'>",
|
||||||
|
" AND o.tourism_id = #{p.tourismId}",
|
||||||
|
"</if>",
|
||||||
|
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
|
||||||
|
" AND o.code_id = #{p.qrcodeId}",
|
||||||
|
"</if>",
|
||||||
|
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
|
||||||
|
" AND o.device_sn = #{p.deviceSn}",
|
||||||
|
"</if>",
|
||||||
|
"<if test='p.startTime != null and p.startTime != \"\"'>",
|
||||||
|
" AND o.create_time >= #{p.startTime}",
|
||||||
|
"</if>",
|
||||||
|
"<if test='p.endTime != null and p.endTime != \"\"'>",
|
||||||
|
" AND o.create_time <= #{p.endTime}",
|
||||||
|
"</if>",
|
||||||
|
"<if test='p.tourismIds != null and p.tourismIds.size > 0'>",
|
||||||
|
" AND o.tourism_id IN",
|
||||||
|
" <foreach collection='p.tourismIds' item='tid' open='(' separator=',' close=')'>#{tid}</foreach>",
|
||||||
|
"</if>",
|
||||||
|
"GROUP BY date",
|
||||||
|
"ORDER BY date ASC",
|
||||||
|
"</script>"
|
||||||
|
})
|
||||||
|
List<TrendDataVO> getOrderSeriesRefunded(@Param("p") Map<String, Object> params);
|
||||||
|
|
||||||
// 对账相关统计
|
// 对账相关统计
|
||||||
@Select({
|
@Select({
|
||||||
"<script>",
|
"<script>",
|
||||||
|
|||||||
+8
@@ -17,4 +17,12 @@ public interface IDashboardService {
|
|||||||
* 获取首页订单列表
|
* 获取首页订单列表
|
||||||
*/
|
*/
|
||||||
PageResult<Order> getDashboardOrders(Map<String, Object> params);
|
PageResult<Order> getDashboardOrders(Map<String, Object> params);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单时间序列(创建/完成/退款),按指定粒度聚合:
|
||||||
|
* - date(天):分小时
|
||||||
|
* - week/月:按天
|
||||||
|
* - year:按月
|
||||||
|
*/
|
||||||
|
List<com.central.order.model.vo.TrendDataVO> getOrderTimeSeries(Map<String, Object> params);
|
||||||
}
|
}
|
||||||
|
|||||||
+50
-1
@@ -132,6 +132,56 @@ public class DashboardServiceImpl implements IDashboardService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TrendDataVO> getOrderTimeSeries(Map<String, Object> params) {
|
||||||
|
try {
|
||||||
|
// 解析租户并派生景区集合
|
||||||
|
String tenantId = params != null && params.get("tenantId") != null ? String.valueOf(params.get("tenantId")) : null;
|
||||||
|
List<String> tenantIds = tenantResolverService.resolveTenantIds(tenantId, true);
|
||||||
|
if (tenantIds == null || tenantIds.isEmpty()) {
|
||||||
|
log.warn("无法获取租户列表,tenantId: {}", tenantId);
|
||||||
|
return java.util.Collections.emptyList();
|
||||||
|
}
|
||||||
|
List<Long> tourismIds = resolveTourismIdsByTenants(tenantIds);
|
||||||
|
if (tourismIds == null || tourismIds.isEmpty()) {
|
||||||
|
tourismIds = new java.util.ArrayList<>();
|
||||||
|
tourismIds.add(-1L);
|
||||||
|
}
|
||||||
|
params.put("tourismIds", tourismIds);
|
||||||
|
|
||||||
|
// 维度映射:date->hour,week/month->day,year->month
|
||||||
|
String rt = params != null && params.get("rangeType") != null ? String.valueOf(params.get("rangeType")) : null;
|
||||||
|
String statType = params != null && params.get("statType") != null ? String.valueOf(params.get("statType")) : null;
|
||||||
|
String seriesType;
|
||||||
|
String t = (rt != null && !rt.isEmpty()) ? rt : (statType != null ? statType : "day");
|
||||||
|
if ("date".equalsIgnoreCase(t)) {
|
||||||
|
seriesType = "hour";
|
||||||
|
} else if ("year".equalsIgnoreCase(t)) {
|
||||||
|
seriesType = "month";
|
||||||
|
} else {
|
||||||
|
seriesType = "day";
|
||||||
|
}
|
||||||
|
params.put("seriesType", seriesType);
|
||||||
|
|
||||||
|
// 查询三个序列
|
||||||
|
List<TrendDataVO> created = dashboardMapper.getOrderSeriesCreated(params);
|
||||||
|
List<TrendDataVO> completed = dashboardMapper.getOrderSeriesCompleted(params);
|
||||||
|
List<TrendDataVO> refunded = dashboardMapper.getOrderSeriesRefunded(params);
|
||||||
|
|
||||||
|
// 合并
|
||||||
|
List<TrendDataVO> all = new java.util.ArrayList<>();
|
||||||
|
if (created != null) all.addAll(created);
|
||||||
|
if (completed != null) all.addAll(completed);
|
||||||
|
if (refunded != null) all.addAll(refunded);
|
||||||
|
// 保序(按日期字符串升序)
|
||||||
|
all.sort((a, b) -> String.valueOf(a.getDate()).compareTo(String.valueOf(b.getDate())));
|
||||||
|
return all;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("获取订单时间序列失败", e);
|
||||||
|
return java.util.Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取订单统计
|
* 获取订单统计
|
||||||
*/
|
*/
|
||||||
@@ -311,4 +361,3 @@ public class DashboardServiceImpl implements IDashboardService {
|
|||||||
return tourismMapper.findTourismIdsByTenantId(tenantId) ;
|
return tourismMapper.findTourismIdsByTenantId(tenantId) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,9 +44,6 @@
|
|||||||
<maxFileSize>${LOG_MAXFILESIZE}</maxFileSize>
|
<maxFileSize>${LOG_MAXFILESIZE}</maxFileSize>
|
||||||
</timeBasedFileNamingAndTriggeringPolicy>
|
</timeBasedFileNamingAndTriggeringPolicy>
|
||||||
</rollingPolicy>
|
</rollingPolicy>
|
||||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
|
||||||
<level>INFO</level>
|
|
||||||
</filter>
|
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<appender name="point_log" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
<appender name="point_log" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
@@ -101,9 +98,37 @@
|
|||||||
<logger name="com.central.log.service.impl.LoggerAuditServiceImpl" level="debug" additivity="false">
|
<logger name="com.central.log.service.impl.LoggerAuditServiceImpl" level="debug" additivity="false">
|
||||||
<appender-ref ref="audit_log_async" />
|
<appender-ref ref="audit_log_async" />
|
||||||
</logger>
|
</logger>
|
||||||
|
<!-- <logger name="com.baomidou.mybatisplus" level="DEBUG"/>-->
|
||||||
|
<!-- <logger name="java.sql.Connection" level="DEBUG"/>-->
|
||||||
|
<!-- <logger name="java.sql.Statement" level="DEBUG"/>-->
|
||||||
|
<!-- <logger name="java.sql.PreparedStatement" level="DEBUG"/>-->
|
||||||
|
|
||||||
<root level="INFO">
|
<!--
|
||||||
<appender-ref ref="StdoutAppender"/>
|
通过 Spring Profile 与环境变量控制日志级别:
|
||||||
<appender-ref ref="file_async"/>
|
- 当环境为 prod(SPRING_PROFILES_ACTIVE=prod 或 LOG_ACTIVE=prod / log_active=prod),仅打印 INFO 及以上日志。
|
||||||
</root>
|
- 当环境为 debug(SPRING_PROFILES_ACTIVE=debug 或 LOG_ACTIVE=debug / log_active=debug),打印 DEBUG 及以上日志。
|
||||||
|
- 其他环境默认 INFO。
|
||||||
|
-->
|
||||||
|
<springProfile name="prod">
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="StdoutAppender"/>
|
||||||
|
<appender-ref ref="file_async"/>
|
||||||
|
</root>
|
||||||
|
</springProfile>
|
||||||
|
<springProfile name="debug">
|
||||||
|
<!-- MyBatis / MyBatis-Plus 在 debug 环境打印 SQL、参数等明细日志 -->
|
||||||
|
<logger name="org.apache.ibatis" level="DEBUG"/>
|
||||||
|
<logger name="org.mybatis" level="DEBUG"/>
|
||||||
|
<logger name="com.baomidou.mybatisplus" level="DEBUG"/>
|
||||||
|
<root level="DEBUG">
|
||||||
|
<appender-ref ref="StdoutAppender"/>
|
||||||
|
<appender-ref ref="file_async"/>
|
||||||
|
</root>
|
||||||
|
</springProfile>
|
||||||
|
<springProfile name="dev">
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="StdoutAppender"/>
|
||||||
|
<appender-ref ref="file_async"/>
|
||||||
|
</root>
|
||||||
|
</springProfile>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
########################## bootstrap?????? ##########################
|
########################## bootstrap?????? ##########################
|
||||||
# ??????
|
# ??????
|
||||||
spring.profiles.active=${profiles_active:dev}
|
spring.profiles.active=${log_active:dev}
|
||||||
|
|
||||||
##### nacos(?????????)??
|
##### nacos(?????????)??
|
||||||
#spring.cloud.nacos.server-addr=81.70.164.178:8848
|
#spring.cloud.nacos.server-addr=81.70.164.178:8848
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
"build:test": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=test API_PREFIX=http://119.45.169.13:9900 umi build",
|
"build:test": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=test API_PREFIX=http://119.45.169.13:9900 umi build",
|
||||||
"build:pre": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=pre API_PREFIX=http://119.45.169.13:9900 umi build",
|
"build:pre": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=pre API_PREFIX=http://119.45.169.13:9900 umi build",
|
||||||
"build:prod": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=prod umi build",
|
"build:prod": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=prod umi build",
|
||||||
"build:test:mgnt": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=test APP_BASE=/mgnt API_PREFIX=http://local.goflytec.com:9900 umi build",
|
"build:test:mgnt": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=test APP_BASE=/mgnt API_PREFIX=https://local.goflytec.com:9900 umi build",
|
||||||
"build:pre:mgnt": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=pre APP_BASE=/mgnt API_PREFIX=http://local.goflytec.com:9900 umi build",
|
"build:pre:mgnt": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=pre APP_BASE=/mgnt API_PREFIX=https://local.goflytec.com:9900 umi build",
|
||||||
"build:prod:mgnt": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=prod APP_BASE=/mgnt umi build",
|
"build:prod:mgnt": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=prod APP_BASE=/mgnt umi build",
|
||||||
"lint": "eslint --ext .ts,.tsx src",
|
"lint": "eslint --ext .ts,.tsx src",
|
||||||
"tsc": "tsc --noEmit"
|
"tsc": "tsc --noEmit"
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ const BasicLayout: React.FC = (props: any) => {
|
|||||||
|
|
||||||
const rightContentRender = () => (
|
const rightContentRender = () => (
|
||||||
<Space size="middle">
|
<Space size="middle">
|
||||||
{/*<Link to="/welcome" style={{ color: 'var(--text-primary)' }}>首页</Link>*/}
|
{<Link to="/welcome" style={{ color: 'var(--text-primary)' }}>首页</Link>}
|
||||||
<ThemeSwitch mode={mode} onToggle={toggle} />
|
<ThemeSwitch mode={mode} onToggle={toggle} />
|
||||||
<Dropdown
|
<Dropdown
|
||||||
menu={{
|
menu={{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React, { useEffect, useRef, useState } from 'react';
|
import React, { useEffect, useRef, useState } from 'react';
|
||||||
import { Card, Space, Typography, Row, Col, Button, message, DatePicker, Segmented, List, Tag, Statistic, InputNumber, Slider } from 'antd';
|
import { Card, Space, Typography, Row, Col, Button, message, DatePicker, Segmented, List, Tag, Statistic } from 'antd';
|
||||||
import { ReloadOutlined } from '@ant-design/icons';
|
import { ReloadOutlined } from '@ant-design/icons';
|
||||||
import { Line, Pie, Column } from '@ant-design/plots';
|
import { Line, Pie } from '@ant-design/plots';
|
||||||
import TenantScopeFilter from '@/components/TenantScopeFilter';
|
import TenantScopeFilter from '@/components/TenantScopeFilter';
|
||||||
import { dashboardApi } from '@/services/dashboard';
|
import { dashboardApi } from '@/services/dashboard';
|
||||||
import { ordersApi } from '@/services/orders';
|
import { ordersApi } from '@/services/orders';
|
||||||
@@ -13,61 +13,83 @@ const { RangePicker } = DatePicker;
|
|||||||
type RangeType = 'date' | 'week' | 'month' | 'year';
|
type RangeType = 'date' | 'week' | 'month' | 'year';
|
||||||
|
|
||||||
const makeDefaultToday = (): [Moment, Moment] => [moment().startOf('day'), moment().endOf('day')];
|
const makeDefaultToday = (): [Moment, Moment] => [moment().startOf('day'), moment().endOf('day')];
|
||||||
|
|
||||||
const computeRangeByType = (type: RangeType, anchor?: Moment): [Moment, Moment] => {
|
const computeRangeByType = (type: RangeType, anchor?: Moment): [Moment, Moment] => {
|
||||||
const base = (anchor ? anchor.clone() : moment());
|
const base = (anchor ? anchor.clone() : moment());
|
||||||
const unit = type === 'date' ? 'day' : type;
|
const unit = type === 'date' ? 'day' : type;
|
||||||
return [base.clone().startOf(unit as any), base.clone().endOf(unit as any)];
|
return [base.clone().startOf(unit as any), base.clone().endOf(unit as any)];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const STATUS_OPTIONS: { value: number; label: string; color?: string }[] = [
|
||||||
|
{ value: 0, label: '待支付' },
|
||||||
|
{ value: 1, label: '排队中', color: 'gold' },
|
||||||
|
{ value: 2, label: '已取消', color: 'red' },
|
||||||
|
{ value: 3, label: '设备执行完成', color: 'green' },
|
||||||
|
{ value: 4, label: '正在服务', color: 'blue' },
|
||||||
|
{ value: 5, label: '素材上传', color: 'geekblue' },
|
||||||
|
{ value: 6, label: '任务完成', color: 'purple' },
|
||||||
|
{ value: 7, label: '退款中', color: 'orange' },
|
||||||
|
{ value: 8, label: '退款成功', color: 'lime' },
|
||||||
|
{ value: 9, label: '退款失败', color: 'red' },
|
||||||
|
];
|
||||||
|
|
||||||
const Welcome: React.FC = () => {
|
const Welcome: React.FC = () => {
|
||||||
// 租户维度
|
// 租户与时间
|
||||||
const [tenantId, setTenantId] = useState<string>();
|
const [tenantId, setTenantId] = useState<string>();
|
||||||
const [includeChildren, setIncludeChildren] = useState<boolean>(true);
|
const [includeChildren, setIncludeChildren] = useState<boolean>(true);
|
||||||
|
|
||||||
// 时间范围(默认今日 00:00:00 - 23:59:59)
|
|
||||||
const [rangeType, setRangeType] = useState<RangeType>('date');
|
const [rangeType, setRangeType] = useState<RangeType>('date');
|
||||||
const [range, setRange] = useState<[Moment, Moment]>(makeDefaultToday());
|
const [range, setRange] = useState<[Moment, Moment]>(makeDefaultToday());
|
||||||
|
|
||||||
// 加载状态
|
// 加载与数据
|
||||||
const [loading, setLoading] = useState<boolean>(false);
|
const [loading, setLoading] = useState<boolean>(false);
|
||||||
const [pageLoading, setPageLoading] = useState<boolean>(true);
|
const [pageLoading, setPageLoading] = useState<boolean>(true);
|
||||||
const [ordersLoading, setOrdersLoading] = useState<boolean>(false);
|
const [ordersLoading, setOrdersLoading] = useState<boolean>(false);
|
||||||
const firstLoadRef = useRef(true);
|
const firstLoadRef = useRef(true);
|
||||||
|
|
||||||
// 数据
|
|
||||||
const [stat, setStat] = useState<any>({ orderStats: {}, chartStats: {} });
|
const [stat, setStat] = useState<any>({ orderStats: {}, chartStats: {} });
|
||||||
const [orders, setOrders] = useState<any[]>([]);
|
const [orders, setOrders] = useState<any[]>([]);
|
||||||
const [ordersTotal, setOrdersTotal] = useState<number>(0);
|
const [ordersTotal, setOrdersTotal] = useState<number>(0);
|
||||||
const [page, setPage] = useState<number>(1);
|
const [page, setPage] = useState<number>(1);
|
||||||
const [pageSize, setPageSize] = useState<number>(10);
|
const [pageSize, setPageSize] = useState<number>(10);
|
||||||
// 趋势模式:状态曲线 or 景区柱状
|
|
||||||
const [trendMode, setTrendMode] = useState<'status' | 'tourism'>('status');
|
|
||||||
const [aggLoading, setAggLoading] = useState<boolean>(false);
|
|
||||||
const [statusSeries, setStatusSeries] = useState<{ date: string; type: string; value: number }[]>([]);
|
|
||||||
const [tourismBars, setTourismBars] = useState<{ name: string; value: number }[]>([]);
|
|
||||||
// 分账比例(平台),默认 70%
|
|
||||||
const [splitPercent, setSplitPercent] = useState<number>(70);
|
|
||||||
|
|
||||||
// 统一获取 start/end 时间字符串
|
// 折线(订单创建/完成/退款)
|
||||||
|
const [aggLoading, setAggLoading] = useState<boolean>(false);
|
||||||
|
const [orderLineSeries, setOrderLineSeries] = useState<{ date: string; value: number; type: string }[]>([]);
|
||||||
|
|
||||||
const getTimeParams = () => {
|
const getTimeParams = () => {
|
||||||
const [start, end] = range || makeDefaultToday();
|
const [start, end] = range || makeDefaultToday();
|
||||||
// 使用本地时间字符串,避免 ISO(UTC) 引起后端解析或时区偏差
|
|
||||||
return { startTime: start.format('YYYY-MM-DD HH:mm:ss'), endTime: end.format('YYYY-MM-DD HH:mm:ss') };
|
return { startTime: start.format('YYYY-MM-DD HH:mm:ss'), endTime: end.format('YYYY-MM-DD HH:mm:ss') };
|
||||||
};
|
};
|
||||||
|
|
||||||
// 加载统计与订单列表
|
const handleRangeTypeChange = (val: any) => {
|
||||||
|
const t = (val as RangeType) || 'date';
|
||||||
|
setRangeType(t);
|
||||||
|
const anchor = range?.[0] || moment();
|
||||||
|
setRange(computeRangeByType(t, anchor));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRangeChange = (vals: any) => {
|
||||||
|
if (!Array.isArray(vals) || vals.length !== 2 || !vals[0] || !vals[1]) {
|
||||||
|
setRange(makeDefaultToday());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let s = vals[0] as Moment;
|
||||||
|
let e = vals[1] as Moment;
|
||||||
|
if (rangeType !== 'date') {
|
||||||
|
s = s.clone().startOf('day');
|
||||||
|
e = e.clone().endOf('day');
|
||||||
|
}
|
||||||
|
setRange([s, e]);
|
||||||
|
};
|
||||||
|
|
||||||
const load = async (opts?: { page?: number; pageSize?: number }) => {
|
const load = async (opts?: { page?: number; pageSize?: number }) => {
|
||||||
if (firstLoadRef.current) setPageLoading(true);
|
if (firstLoadRef.current) setPageLoading(true);
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const { startTime, endTime } = getTimeParams();
|
const { startTime, endTime } = getTimeParams();
|
||||||
// 首页统计(默认排除测试二维码)
|
|
||||||
const statType = (rangeType === 'month' ? 'month' : (rangeType === 'year' ? 'year' : 'day')) as 'day'|'month'|'year';
|
const statType = (rangeType === 'month' ? 'month' : (rangeType === 'year' ? 'year' : 'day')) as 'day'|'month'|'year';
|
||||||
const res: any = await dashboardApi.statistics({ tenantId, includeChildren, startTime, endTime, statType, includeTestQrcodes: false });
|
const res: any = await dashboardApi.statistics({ tenantId, includeChildren, startTime, endTime, statType, includeTestQrcodes: false });
|
||||||
setStat(res?.data || res);
|
setStat(res?.data || res);
|
||||||
|
|
||||||
// 右侧订单列表(默认排除测试二维码)
|
|
||||||
setOrdersLoading(true);
|
setOrdersLoading(true);
|
||||||
try {
|
try {
|
||||||
const curPage = opts?.page ?? page;
|
const curPage = opts?.page ?? page;
|
||||||
@@ -85,6 +107,9 @@ const Welcome: React.FC = () => {
|
|||||||
} finally {
|
} finally {
|
||||||
setOrdersLoading(false);
|
setOrdersLoading(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 刷新折线(刷新按钮也会触发到这里)
|
||||||
|
try { await loadAggregations(); } catch {}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
message.error('加载统计失败');
|
message.error('加载统计失败');
|
||||||
} finally {
|
} finally {
|
||||||
@@ -96,79 +121,90 @@ const Welcome: React.FC = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 首次/依赖变更自动加载
|
const loadAggregations = async () => {
|
||||||
useEffect(() => {
|
|
||||||
if (!tenantId) return;
|
if (!tenantId) return;
|
||||||
// 条件变化重置到第 1 页
|
setAggLoading(true);
|
||||||
setPage(1);
|
try {
|
||||||
load({ page: 1, pageSize });
|
const { startTime, endTime } = getTimeParams();
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
const unit: 'hour' | 'day' | 'month' = (rangeType === 'date') ? 'hour' : (rangeType === 'year' ? 'month' : 'day');
|
||||||
}, [tenantId, includeChildren, rangeType, range]);
|
const start = (range?.[0] || moment()).clone().startOf(unit as any);
|
||||||
|
const end = (range?.[1] || moment()).clone().endOf(unit as any);
|
||||||
|
|
||||||
// 趋势聚合:当筛选条件或模式变化时刷新
|
// 生成所有时间点标签
|
||||||
useEffect(() => {
|
const labels: string[] = [];
|
||||||
if (!tenantId) return;
|
const fmtLabel = (m: moment.Moment) => (unit === 'hour' ? m.format('HH:00') : unit === 'day' ? m.format('YYYY-MM-DD') : m.format('YYYY-MM'));
|
||||||
// 趋势分析已关闭,跳过聚合
|
{
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
const cursor = start.clone();
|
||||||
}, [tenantId, includeChildren, rangeType, range]);
|
while (cursor.isSameOrBefore(end)) {
|
||||||
|
labels.push(fmtLabel(cursor));
|
||||||
|
cursor.add(1, unit as any);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Chart 数据
|
const seriesRes: any = await ordersApi.getOrderSeries({ tenantId, includeChildren, startTime, endTime, statType: rangeType, includeTestQrcodes: false });
|
||||||
const chartStats = stat?.chartStats || {};
|
const seriesData: any[] = seriesRes?.data || [];
|
||||||
const orderStats = stat?.orderStats || {};
|
|
||||||
const totalAmountYuan = (orderStats.totalAmount || 0) / 100;
|
|
||||||
const platformAmount = Number(((totalAmountYuan * splitPercent) / 100).toFixed(2));
|
|
||||||
const tenantAmount = Number((totalAmountYuan - platformAmount).toFixed(2));
|
|
||||||
const trendData = (chartStats?.dailySummary || []).map((d: any) => ({ ...d, value: Number(d?.value ?? 0) }));
|
|
||||||
const distributionData = chartStats?.orderDistribution || [];
|
|
||||||
|
|
||||||
const trendColors: Record<string, string> = {
|
// 构建数据映射表
|
||||||
'订单数': '#1668DC',
|
const dataMap: Record<string, Record<string, number>> = {
|
||||||
'订单金额(元)': '#FA8C16',
|
'订单创建': {},
|
||||||
'退款订单数': '#A0D911',
|
'完成': {},
|
||||||
'退款金额(元)': '#F5222D',
|
'退款': {}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 将后端数据填充到映射表
|
||||||
|
seriesData.forEach((item: any) => {
|
||||||
|
const date = item.date || '';
|
||||||
|
const type = item.type || '';
|
||||||
|
const value = Number(item.value || 0);
|
||||||
|
if (dataMap[type]) {
|
||||||
|
dataMap[type][date] = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 填充所有时间点,缺失的补0
|
||||||
|
const lineSeries: { date: string; value: number; type: string }[] = [];
|
||||||
|
labels.forEach((label) => {
|
||||||
|
lineSeries.push({ date: label, type: '订单创建', value: dataMap['订单创建'][label] || 0 });
|
||||||
|
lineSeries.push({ date: label, type: '完成', value: dataMap['完成'][label] || 0 });
|
||||||
|
lineSeries.push({ date: label, type: '退款', value: dataMap['退款'][label] || 0 });
|
||||||
|
});
|
||||||
|
|
||||||
|
setOrderLineSeries(lineSeries);
|
||||||
|
} catch {
|
||||||
|
setOrderLineSeries([]);
|
||||||
|
} finally {
|
||||||
|
setAggLoading(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const trendConfig: any = {
|
// 折线图配置(按 type 分组,不同颜色显示)
|
||||||
data: trendData,
|
const getColorByType = (type: string) => {
|
||||||
|
const colorMapping: Record<string, string> = {
|
||||||
|
'订单创建': '#1890ff',
|
||||||
|
'完成': '#52c41a',
|
||||||
|
'退款': '#ff4d4f'
|
||||||
|
};
|
||||||
|
return colorMapping[type] || '#1890ff';
|
||||||
|
};
|
||||||
|
|
||||||
|
const orderLineConfig: any = {
|
||||||
|
data: orderLineSeries,
|
||||||
xField: 'date',
|
xField: 'date',
|
||||||
yField: 'value',
|
yField: 'value',
|
||||||
seriesField: 'type',
|
seriesField: 'type',
|
||||||
smooth: true,
|
smooth: true,
|
||||||
height: 320,
|
height: 220,
|
||||||
legend: { position: 'top' },
|
legend: { position: 'top' as const },
|
||||||
color: ({ type }: any) => trendColors[type] || '#5B8FF9',
|
color: (datum: any) => {
|
||||||
lineStyle: { lineWidth: 2 },
|
return getColorByType(datum.type);
|
||||||
point: { size: 2, shape: 'circle' },
|
|
||||||
tooltip: {
|
|
||||||
shared: true,
|
|
||||||
customContent: (title: string, items: any[]) => {
|
|
||||||
if (!items || !items.length) return '';
|
|
||||||
const rows = items
|
|
||||||
.map((it) => {
|
|
||||||
const name = it?.name || it?.data?.type;
|
|
||||||
const v = it?.data?.value ?? 0;
|
|
||||||
const isAmount = name && String(name).includes('金额');
|
|
||||||
const text = isAmount ? `¥${Number(v).toFixed(2)}` : `${Math.round(Number(v))}`;
|
|
||||||
const color = it?.color || '#333';
|
|
||||||
return `<div style="display:flex;align-items:center;gap:8px;">
|
|
||||||
<span style="display:inline-block;width:8px;height:8px;border-radius:50%;background:${color}"></span>
|
|
||||||
<span>${name}</span>
|
|
||||||
<span style="margin-left:auto;font-weight:600;">${text}</span>
|
|
||||||
</div>`;
|
|
||||||
})
|
|
||||||
.join('');
|
|
||||||
return `<div style="padding:8px 8px 4px 8px;min-width:200px;">
|
|
||||||
<div style="margin-bottom:6px;font-weight:600;">${title}</div>
|
|
||||||
${rows}
|
|
||||||
</div>`;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
animation: false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const distributionPalette = [
|
// 饼图配置
|
||||||
'#1668DC', '#5AD8A6', '#F6BD16', '#E8684A', '#6DC8EC', '#9270CA', '#FF9D4D', '#269A99', '#FF99C3', '#1D9ED1',
|
const chartStats = stat?.chartStats || {};
|
||||||
];
|
const orderStats = stat?.orderStats || {};
|
||||||
|
const distributionData = chartStats?.orderDistribution || [];
|
||||||
|
const distributionPalette = ['#1668DC', '#5AD8A6', '#F6BD16', '#E8684A', '#6DC8EC', '#9270CA', '#FF9D4D', '#269A99', '#FF99C3', '#1D9ED1'];
|
||||||
const distributionConfig: any = {
|
const distributionConfig: any = {
|
||||||
data: distributionData,
|
data: distributionData,
|
||||||
angleField: 'value',
|
angleField: 'value',
|
||||||
@@ -176,157 +212,25 @@ const Welcome: React.FC = () => {
|
|||||||
radius: 0.9,
|
radius: 0.9,
|
||||||
color: distributionPalette,
|
color: distributionPalette,
|
||||||
legend: { position: 'right' },
|
legend: { position: 'right' },
|
||||||
// 由于当前 @ant-design/plots 版本未注册 spider/outer 等 label 形状,关闭标签以避免 Unknown Component 错误
|
|
||||||
label: false,
|
label: false,
|
||||||
animation: false,
|
animation: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
// 事件:分段切换 -> 根据当前范围起点计算该粒度的起止
|
const totalAmountYuan = Number(((orderStats?.totalAmount ?? 0) as number) / 100);
|
||||||
const handleRangeTypeChange = (val: any) => {
|
const refundAmountYuan = Number(((orderStats?.refundAmount ?? 0) as number) / 100);
|
||||||
const t = (val as RangeType) || 'date';
|
const netIncomeYuan = Number((totalAmountYuan - refundAmountYuan).toFixed(2));
|
||||||
setRangeType(t);
|
|
||||||
const anchor = range?.[0] || moment();
|
|
||||||
setRange(computeRangeByType(t, anchor));
|
|
||||||
};
|
|
||||||
|
|
||||||
// 事件:手动选择时间范围
|
// 首次加载/筛选变化
|
||||||
const handleRangeChange = (vals: any) => {
|
useEffect(() => {
|
||||||
if (!Array.isArray(vals) || vals.length !== 2 || !vals[0] || !vals[1]) {
|
|
||||||
setRange(makeDefaultToday());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let s = vals[0] as Moment;
|
|
||||||
let e = vals[1] as Moment;
|
|
||||||
if (rangeType !== 'date') {
|
|
||||||
s = s.clone().startOf('day');
|
|
||||||
e = e.clone().endOf('day');
|
|
||||||
}
|
|
||||||
setRange([s, e]);
|
|
||||||
};
|
|
||||||
|
|
||||||
// 拉取当前筛选条件下的订单数据,前端聚合生成:
|
|
||||||
// - 状态曲线(按天、按状态统计订单数)
|
|
||||||
// - 景区柱状(按景区统计订单数)
|
|
||||||
const loadAggregations = async () => {
|
|
||||||
if (!tenantId) return;
|
if (!tenantId) return;
|
||||||
setAggLoading(true);
|
setPage(1);
|
||||||
try {
|
load({ page: 1, pageSize });
|
||||||
const { startTime, endTime } = getTimeParams();
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
// 分页抓取,最多抓取一定数量以避免阻塞
|
}, [tenantId, includeChildren, rangeType, range]);
|
||||||
const maxRecords = 5000;
|
|
||||||
const pageSizeAgg = 200;
|
|
||||||
let cp = 1;
|
|
||||||
let pulled = 0;
|
|
||||||
const collected: any[] = [];
|
|
||||||
// 先探测总量
|
|
||||||
let total = 0;
|
|
||||||
try {
|
|
||||||
const probe: any = await ordersApi.getDashboardOrders({ tenantId, includeChildren, startTime, endTime, includeTestQrcodes: false, page: 1, limit: 1 });
|
|
||||||
total = Number(probe?.data?.count ?? probe?.count ?? 0) || 0;
|
|
||||||
} catch {}
|
|
||||||
if (total === 0) {
|
|
||||||
setStatusSeries([]);
|
|
||||||
setTourismBars([]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const target = Math.min(total, maxRecords);
|
|
||||||
while (pulled < target) {
|
|
||||||
const res: any = await ordersApi.getDashboardOrders({ tenantId, includeChildren, startTime, endTime, includeTestQrcodes: false, page: cp, limit: pageSizeAgg });
|
|
||||||
const list = res?.data?.data || res?.data || [];
|
|
||||||
if (!Array.isArray(list) || list.length === 0) break;
|
|
||||||
collected.push(...list);
|
|
||||||
pulled += list.length;
|
|
||||||
cp += 1;
|
|
||||||
if (list.length < pageSizeAgg) break;
|
|
||||||
}
|
|
||||||
// 聚合:按天、按状态计数
|
|
||||||
const byDateStatus = new Map<string, Map<number, number>>();
|
|
||||||
const byTourism = new Map<string, number>();
|
|
||||||
for (const it of collected) {
|
|
||||||
const date = (it?.createTime ? moment(it.createTime) : moment()).format('YYYY-MM-DD');
|
|
||||||
const st = Number(it?.orderStatus);
|
|
||||||
const name = it?.tourismName || '未知景区';
|
|
||||||
// 状态聚合
|
|
||||||
if (!byDateStatus.has(date)) byDateStatus.set(date, new Map<number, number>());
|
|
||||||
const m = byDateStatus.get(date)!;
|
|
||||||
m.set(st, (m.get(st) || 0) + 1);
|
|
||||||
// 景区聚合
|
|
||||||
byTourism.set(name, (byTourism.get(name) || 0) + 1);
|
|
||||||
}
|
|
||||||
// 转换为折线图数据(时间升序)
|
|
||||||
const dates = Array.from(byDateStatus.keys()).sort((a, b) => a.localeCompare(b));
|
|
||||||
const series: { date: string; type: string; value: number }[] = [];
|
|
||||||
for (const d of dates) {
|
|
||||||
const m = byDateStatus.get(d)!;
|
|
||||||
for (const opt of STATUS_OPTIONS) {
|
|
||||||
const v = m.get(opt.value) || 0;
|
|
||||||
if (v > 0) series.push({ date: d, type: opt.label, value: v });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 转换为柱状图数据(按数量降序,取前 20)
|
|
||||||
const bars: { name: string; value: number }[] = Array.from(byTourism.entries())
|
|
||||||
.map(([name, value]) => ({ name, value }))
|
|
||||||
.sort((a, b) => b.value - a.value)
|
|
||||||
.slice(0, 20);
|
|
||||||
setStatusSeries(series);
|
|
||||||
setTourismBars(bars);
|
|
||||||
} catch {
|
|
||||||
setStatusSeries([]);
|
|
||||||
setTourismBars([]);
|
|
||||||
} finally {
|
|
||||||
setAggLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// 订单状态:1. 待支付 2. 已取消 3. 支付成功 4. 设备执行中 5. 素材上传中 6. 素材上传完成 7. 用户已下载完成 8. 退款中 9. 退款成功 10. 退款失败
|
|
||||||
// Tag 颜色使用 antd v4 预设色
|
|
||||||
const STATUS_OPTIONS: { value: number; label: string; color?: string }[] = [
|
|
||||||
{ value: 0, label: '待支付' },
|
|
||||||
{ value: 1, label: '排队中', color: 'gold' },
|
|
||||||
{ value: 2, label: '已取消', color: 'red'},
|
|
||||||
{ value: 3, label: '设备执行完成', color: 'green' },
|
|
||||||
{ value: 4, label: '正在服务中', color: 'blue' },
|
|
||||||
{ value: 5, label: '素材上传中', color: 'geekblue' },
|
|
||||||
{ value: 6, label: '任务完成', color: 'purple' },
|
|
||||||
{ value: 7, label: '退款中', color: 'orange' },
|
|
||||||
{ value: 8, label: '退款成功', color: 'lime' },
|
|
||||||
{ value: 9, label: '退款失败', color: 'red' },
|
|
||||||
];
|
|
||||||
|
|
||||||
const PAY_TYPE_OPTIONS: { value: number; label: string; color?: string }[] = [
|
|
||||||
{ value: 1, label: '微信支付', color: 'green' },
|
|
||||||
{ value: 2, label: '优惠券支付', color: 'blue' },
|
|
||||||
];
|
|
||||||
|
|
||||||
// 将金额(元)格式化为千分位两位小数
|
|
||||||
const fmtCurrency = (yuan?: number) => {
|
|
||||||
const v = Number(yuan || 0);
|
|
||||||
return v.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
||||||
};
|
|
||||||
|
|
||||||
// 从订单行中解析金额(优先 orderAmount,其次 amount)。
|
|
||||||
// orderAmount 多为“分”的整数字符串,如 "5000" => 50.00 元。
|
|
||||||
const getOrderAmountYuan = (it: any): number => {
|
|
||||||
try {
|
|
||||||
const oa = (it || {}).orderAmount;
|
|
||||||
if (oa != null) {
|
|
||||||
const n = Number(oa);
|
|
||||||
if (Number.isFinite(n)) return n / 100;
|
|
||||||
const f = parseFloat(String(oa));
|
|
||||||
if (Number.isFinite(f)) return f;
|
|
||||||
}
|
|
||||||
const a = (it || {}).amount;
|
|
||||||
if (a != null) {
|
|
||||||
const n = Number(a);
|
|
||||||
if (Number.isFinite(n)) return n / 100;
|
|
||||||
}
|
|
||||||
} catch {}
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="page-enter" style={{ padding: 24 }}>
|
<div className="page-enter" style={{ padding: 24 }}>
|
||||||
{/* 顶部工具栏:租户 + 时间选择(分段 + 可自定义起止) */}
|
{/* 顶部工具栏 */}
|
||||||
<Card className="modern-card" style={{ marginBottom: 16 }}>
|
<Card className="modern-card" style={{ marginBottom: 16 }}>
|
||||||
<Row align="middle" justify="space-between" gutter={[12, 12]}>
|
<Row align="middle" justify="space-between" gutter={[12, 12]}>
|
||||||
<Col flex="none"><Title level={4} style={{ margin: 0 }}>首页统计</Title></Col>
|
<Col flex="none"><Title level={4} style={{ margin: 0 }}>首页统计</Title></Col>
|
||||||
@@ -347,14 +251,14 @@ const Welcome: React.FC = () => {
|
|||||||
picker={rangeType as any}
|
picker={rangeType as any}
|
||||||
onChange={handleRangeChange}
|
onChange={handleRangeChange}
|
||||||
/>
|
/>
|
||||||
<Button type="primary" icon={<ReloadOutlined />} loading={loading && !pageLoading} onClick={() => load()}>刷新</Button>
|
<Button type="primary" icon={<ReloadOutlined />} loading={loading && !pageLoading} onClick={() => { load(); }}>刷新</Button>
|
||||||
</Space>
|
</Space>
|
||||||
</Space>
|
</Space>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
{/* 第一行:总订单概览 / 金额统计(两侧对称) */}
|
{/* 概览卡片:左侧订单数统计 + 右侧金额统计 */}
|
||||||
<Row gutter={[16, 16]}>
|
<Row gutter={[16, 16]}>
|
||||||
<Col xs={24} md={12}>
|
<Col xs={24} md={12}>
|
||||||
<Card loading={pageLoading} style={{ height: '100%' }}>
|
<Card loading={pageLoading} style={{ height: '100%' }}>
|
||||||
@@ -363,19 +267,19 @@ const Welcome: React.FC = () => {
|
|||||||
<Row gutter={8} align="middle" style={{ width: '100%' }}>
|
<Row gutter={8} align="middle" style={{ width: '100%' }}>
|
||||||
<Col xs={12} sm={10} md={10}><Text type="secondary">总订单数</Text></Col>
|
<Col xs={12} sm={10} md={10}><Text type="secondary">总订单数</Text></Col>
|
||||||
<Col xs={12} sm={14} md={14} style={{ textAlign: 'right' }}>
|
<Col xs={12} sm={14} md={14} style={{ textAlign: 'right' }}>
|
||||||
<Statistic value={orderStats.totalOrders || 0} valueStyle={{ fontWeight: 600, whiteSpace: 'nowrap' }} />
|
<Statistic value={orderStats?.totalOrders || 0} valueStyle={{ fontWeight: 600, whiteSpace: 'nowrap' }} />
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
<Row gutter={8} align="middle" style={{ width: '100%' }}>
|
<Row gutter={8} align="middle" style={{ width: '100%' }}>
|
||||||
<Col xs={12} sm={10} md={10}><Text type="secondary">退款订单数</Text></Col>
|
<Col xs={12} sm={10} md={10}><Text type="secondary">退款订单数</Text></Col>
|
||||||
<Col xs={12} sm={14} md={14} style={{ textAlign: 'right' }}>
|
<Col xs={12} sm={14} md={14} style={{ textAlign: 'right' }}>
|
||||||
<Statistic value={orderStats.refundedOrders || 0} valueStyle={{ fontWeight: 600, whiteSpace: 'nowrap' }} />
|
<Statistic value={orderStats?.refundedOrders || 0} valueStyle={{ fontWeight: 600, whiteSpace: 'nowrap' }} />
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
<Row gutter={8} align="middle" style={{ width: '100%' }}>
|
<Row gutter={8} align="middle" style={{ width: '100%' }}>
|
||||||
<Col xs={12} sm={10} md={10}><Text type="secondary">净订单数</Text></Col>
|
<Col xs={12} sm={10} md={10}><Text type="secondary">净订单数</Text></Col>
|
||||||
<Col xs={12} sm={14} md={14} style={{ textAlign: 'right' }}>
|
<Col xs={12} sm={14} md={14} style={{ textAlign: 'right' }}>
|
||||||
<Statistic value={(orderStats.totalOrders || 0) - (orderStats.refundedOrders || 0)} valueStyle={{ fontWeight: 600, whiteSpace: 'nowrap' }} />
|
<Statistic value={(orderStats?.totalOrders || 0) - (orderStats?.refundedOrders || 0)} valueStyle={{ fontWeight: 600, whiteSpace: 'nowrap' }} />
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</Space>
|
</Space>
|
||||||
@@ -388,19 +292,19 @@ const Welcome: React.FC = () => {
|
|||||||
<Row gutter={8} align="middle" style={{ width: '100%' }}>
|
<Row gutter={8} align="middle" style={{ width: '100%' }}>
|
||||||
<Col xs={12} sm={10} md={10}><Text type="secondary">订单总金额(元)</Text></Col>
|
<Col xs={12} sm={10} md={10}><Text type="secondary">订单总金额(元)</Text></Col>
|
||||||
<Col xs={12} sm={14} md={14} style={{ textAlign: 'right' }}>
|
<Col xs={12} sm={14} md={14} style={{ textAlign: 'right' }}>
|
||||||
<Statistic value={(orderStats.totalAmount || 0) / 100} precision={2} valueStyle={{ fontWeight: 600, whiteSpace: 'nowrap' }} />
|
<Statistic value={totalAmountYuan} precision={2} valueStyle={{ fontWeight: 600, whiteSpace: 'nowrap' }} />
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
<Row gutter={8} align="middle" style={{ width: '100%' }}>
|
<Row gutter={8} align="middle" style={{ width: '100%' }}>
|
||||||
<Col xs={12} sm={10} md={10}><Text type="secondary">退款总金额(元)</Text></Col>
|
<Col xs={12} sm={10} md={10}><Text type="secondary">退款总金额(元)</Text></Col>
|
||||||
<Col xs={12} sm={14} md={14} style={{ textAlign: 'right' }}>
|
<Col xs={12} sm={14} md={14} style={{ textAlign: 'right' }}>
|
||||||
<Statistic value={(orderStats.refundAmount || 0) / 100} precision={2} valueStyle={{ fontWeight: 600, whiteSpace: 'nowrap' }} />
|
<Statistic value={refundAmountYuan} precision={2} valueStyle={{ fontWeight: 600, whiteSpace: 'nowrap' }} />
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
<Row gutter={8} align="middle" style={{ width: '100%' }}>
|
<Row gutter={8} align="middle" style={{ width: '100%' }}>
|
||||||
<Col xs={12} sm={10} md={10}><Text type="secondary">净收入(元)</Text></Col>
|
<Col xs={12} sm={10} md={10}><Text type="secondary">净收入(元)</Text></Col>
|
||||||
<Col xs={12} sm={14} md={14} style={{ textAlign: 'right' }}>
|
<Col xs={12} sm={14} md={14} style={{ textAlign: 'right' }}>
|
||||||
<Statistic value={(orderStats.netIncome || 0) / 100} precision={2} valueStyle={{ fontWeight: 600, whiteSpace: 'nowrap' }} />
|
<Statistic value={netIncomeYuan} precision={2} valueStyle={{ fontWeight: 600, whiteSpace: 'nowrap' }} />
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</Space>
|
</Space>
|
||||||
@@ -408,59 +312,13 @@ const Welcome: React.FC = () => {
|
|||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
{/* 分账明细框 */}
|
{/* 订单状态分布 + 订单列表 */}
|
||||||
<Row gutter={[16, 16]} style={{ marginTop: 16 }}>
|
|
||||||
<Col span={24}>
|
|
||||||
<Card title="分账明细" loading={pageLoading}>
|
|
||||||
<Space direction="vertical" size={12} style={{ width: '100%' }}>
|
|
||||||
<Row align="middle" gutter={12}>
|
|
||||||
<Col flex="none"><Text>平台分账比例</Text></Col>
|
|
||||||
<Col flex="240px">
|
|
||||||
<InputNumber min={0} max={100} value={splitPercent} onChange={(v) => setSplitPercent(Number(v) || 0)} />
|
|
||||||
<span style={{ marginLeft: 8 }}>%</span>
|
|
||||||
</Col>
|
|
||||||
<Col flex="auto">
|
|
||||||
<Slider min={0} max={100} value={splitPercent} onChange={(v) => setSplitPercent(Number(v))} />
|
|
||||||
</Col>
|
|
||||||
<Col flex="none">
|
|
||||||
<Button onClick={() => setSplitPercent(70)}>重置为 70%</Button>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
<Row gutter={12}>
|
|
||||||
<Col xs={24} md={8}>
|
|
||||||
<Card size="small">
|
|
||||||
<Space direction="vertical" style={{ width: '100%' }}>
|
|
||||||
<Text type="secondary">订单总金额(元)</Text>
|
|
||||||
<Statistic value={totalAmountYuan} precision={2} />
|
|
||||||
</Space>
|
|
||||||
</Card>
|
|
||||||
</Col>
|
|
||||||
<Col xs={24} md={8}>
|
|
||||||
<Card size="small">
|
|
||||||
<Space direction="vertical" style={{ width: '100%' }}>
|
|
||||||
<Text type="secondary">平台分账额度(元)</Text>
|
|
||||||
<Statistic value={platformAmount} precision={2} />
|
|
||||||
</Space>
|
|
||||||
</Card>
|
|
||||||
</Col>
|
|
||||||
<Col xs={24} md={8}>
|
|
||||||
<Card size="small">
|
|
||||||
<Space direction="vertical" style={{ width: '100%' }}>
|
|
||||||
<Text type="secondary">租户分账额度(元)</Text>
|
|
||||||
<Statistic value={tenantAmount} precision={2} />
|
|
||||||
</Space>
|
|
||||||
</Card>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
</Space>
|
|
||||||
</Card>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
|
|
||||||
{/* 第一行:订单状态分布 + 右侧订单列表 */}
|
|
||||||
<Row gutter={[16, 16]}>
|
<Row gutter={[16, 16]}>
|
||||||
<Col xs={24} md={12}>
|
<Col xs={24} md={12}>
|
||||||
<Card title="订单状态分布" loading={pageLoading} style={{ height: '100%' }}>
|
<Card title="订单状态分布" loading={pageLoading || aggLoading} style={{ height: '100%' }}>
|
||||||
|
<div style={{ marginBottom: 12 }}>
|
||||||
|
<Line {...orderLineConfig} />
|
||||||
|
</div>
|
||||||
<Pie {...distributionConfig} />
|
<Pie {...distributionConfig} />
|
||||||
</Card>
|
</Card>
|
||||||
</Col>
|
</Col>
|
||||||
@@ -491,15 +349,7 @@ const Welcome: React.FC = () => {
|
|||||||
}
|
}
|
||||||
description={
|
description={
|
||||||
<Space size={16} wrap>
|
<Space size={16} wrap>
|
||||||
<span>金额:¥{fmtCurrency(getOrderAmountYuan(item))}</span>
|
<span>金额:¥{Number((((item?.orderAmount ?? item?.amount) || 0) as number) / 100).toFixed(2)}</span>
|
||||||
{typeof item?.payType !== 'undefined' ? (
|
|
||||||
<span>
|
|
||||||
支付方式:
|
|
||||||
<Tag color={PAY_TYPE_OPTIONS.find(o => o.value === item.payType)?.color || 'default'}>
|
|
||||||
{PAY_TYPE_OPTIONS.find(o => o.value === item.payType)?.label || '未知'}
|
|
||||||
</Tag>
|
|
||||||
</span>
|
|
||||||
) : null}
|
|
||||||
<span>景区:{item?.tourismName || '-'}</span>
|
<span>景区:{item?.tourismName || '-'}</span>
|
||||||
<span>时间:{item?.createTime || '-'}</span>
|
<span>时间:{item?.createTime || '-'}</span>
|
||||||
</Space>
|
</Space>
|
||||||
@@ -511,58 +361,6 @@ const Welcome: React.FC = () => {
|
|||||||
</Card>
|
</Card>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
{/* 第二行:趋势分析(状态曲线 / 景区柱状) */}
|
|
||||||
<Row gutter={[16, 16]} style={{ marginTop: 16 }}>
|
|
||||||
<Col span={24}>
|
|
||||||
<Card
|
|
||||||
title={
|
|
||||||
<Space>
|
|
||||||
<span>趋势分析</span>
|
|
||||||
<Segmented
|
|
||||||
options={[{ label: '状态曲线', value: 'status' }, { label: '景区柱状', value: 'tourism' }]}
|
|
||||||
value={trendMode}
|
|
||||||
onChange={(v) => setTrendMode(v as any)}
|
|
||||||
/>
|
|
||||||
</Space>
|
|
||||||
}
|
|
||||||
style={{ display: 'none' }}
|
|
||||||
loading={pageLoading || aggLoading}
|
|
||||||
>
|
|
||||||
{trendMode === 'status' ? (
|
|
||||||
<Line
|
|
||||||
data={statusSeries}
|
|
||||||
xField="date"
|
|
||||||
yField="value"
|
|
||||||
seriesField="type"
|
|
||||||
smooth
|
|
||||||
height={340}
|
|
||||||
legend={{ position: 'top' }}
|
|
||||||
color={(d: any) => {
|
|
||||||
const label = d?.type;
|
|
||||||
const opt = STATUS_OPTIONS.find(o => o.label === label);
|
|
||||||
const colorMap: any = {
|
|
||||||
gold: '#FAAD14', green: '#52C41A', blue: '#1677FF', geekblue: '#2F54EB', cyan: '#13C2C2', purple: '#722ED1', orange: '#FA8C16', lime: '#A0D911', red: '#F5222D', default: '#5B8FF9'
|
|
||||||
};
|
|
||||||
return colorMap[opt?.color || 'default'] || '#5B8FF9';
|
|
||||||
}}
|
|
||||||
point={{ size: 2, shape: 'circle' }}
|
|
||||||
tooltip={{ shared: true }}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<Column
|
|
||||||
data={tourismBars}
|
|
||||||
xField="name"
|
|
||||||
yField="value"
|
|
||||||
height={360}
|
|
||||||
xAxis={{ label: { autoHide: true, autoRotate: true } }}
|
|
||||||
meta={{ value: { alias: '订单数' } }}
|
|
||||||
tooltip={{ formatter: (d: any) => ({ name: '订单数', value: String(d?.value ?? 0) }) }}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Card>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -122,6 +122,11 @@ export const ordersApi = {
|
|||||||
const res = await request('/api-order/dashboard/qrcode/options', { method: 'GET', params });
|
const res = await request('/api-order/dashboard/qrcode/options', { method: 'GET', params });
|
||||||
return res as any;
|
return res as any;
|
||||||
},
|
},
|
||||||
|
// 订单时间序列(创建/完成/退款)
|
||||||
|
getOrderSeries: async (params?: { [k: string]: any }) => {
|
||||||
|
const res = await request('/api-order/dashboard/statistics/series', { method: 'GET', params });
|
||||||
|
return res as any;
|
||||||
|
},
|
||||||
|
|
||||||
// 分账
|
// 分账
|
||||||
getProfitSharingDetail: async (orderNo: string) => {
|
getProfitSharingDetail: async (orderNo: string) => {
|
||||||
@@ -237,4 +242,3 @@ export const ordersApi = {
|
|||||||
return (res as any).data || res;
|
return (res as any).data || res;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user