fix(文件中心):实现平台租户自动分配订单,实现抽成订单金额的功能
This commit is contained in:
+3
-4
@@ -217,9 +217,9 @@ public class OrderController {
|
||||
return Result.failed("该二维码已过期");
|
||||
}
|
||||
|
||||
// 智能租户分配:根据用户ID和二维码ID确定租户
|
||||
// 智能租户分配:根据二维码ID确定租户
|
||||
String determinedTenantId = orderTenantAllocationService.determineTenant(
|
||||
user.getId().toString(), order.getCodeId());
|
||||
qrCode.getCodeId(), qrCode.getTenantId());
|
||||
order.setTenantId(determinedTenantId);
|
||||
|
||||
//设置订单所属tenantId
|
||||
@@ -228,8 +228,7 @@ public class OrderController {
|
||||
order.setOrderAmount(qrCode.getPrice());
|
||||
|
||||
// 更新订单计数(用于下次分配)
|
||||
orderTenantAllocationService.incrementOrderCount(
|
||||
user.getId().toString(), order.getCodeId());
|
||||
orderTenantAllocationService.incrementOrderCount(qrCode.getCodeId());
|
||||
|
||||
}else {
|
||||
Assert.notNull(qrCode,"二维码不存在");
|
||||
|
||||
+52
-3
@@ -9,6 +9,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -33,7 +34,7 @@ public class OrderTenantAllocationController {
|
||||
try {
|
||||
log.info("测试租户分配逻辑 - userId: {}, qrCodeId: {}, expectedCount: {}", userId, qrCodeId, expectedCount);
|
||||
|
||||
Map<String, Object> result = allocationService.validateAllocationLogic(userId, qrCodeId, expectedCount);
|
||||
Map<String, Object> result = allocationService.validateAllocationLogic(qrCodeId, expectedCount);
|
||||
|
||||
// 添加分配示例
|
||||
Map<String, Object> allocationExample = allocationService.getAllocationStatistics(qrCodeId);
|
||||
@@ -66,7 +67,7 @@ public class OrderTenantAllocationController {
|
||||
|
||||
// 模拟订单分配过程
|
||||
for (int i = 0; i < orderCount; i++) {
|
||||
String tenantId = allocationService.determineTenant(userId, qrCodeId);
|
||||
String tenantId = allocationService.determineTenant(qrCodeId, "scenic_tenant_" + qrCodeId);
|
||||
|
||||
if (tenantId.contains("platform")) {
|
||||
platformCount++;
|
||||
@@ -75,7 +76,7 @@ public class OrderTenantAllocationController {
|
||||
}
|
||||
|
||||
// 更新计数(模拟)
|
||||
allocationService.incrementOrderCount(userId, qrCodeId);
|
||||
allocationService.incrementOrderCount(qrCodeId);
|
||||
|
||||
allocationDetails.put("order_" + (i + 1), Map.of(
|
||||
"orderNumber", i + 1,
|
||||
@@ -117,4 +118,52 @@ public class OrderTenantAllocationController {
|
||||
return Result.failed("获取失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "获取详细诊断信息")
|
||||
@GetMapping("/diagnostics")
|
||||
public Result<Map<String, Object>> getDetailedDiagnostics(
|
||||
@Parameter(description = "二维码ID") @RequestParam String qrCodeId) {
|
||||
|
||||
try {
|
||||
log.info("获取详细诊断信息 - qrCodeId: {}", qrCodeId);
|
||||
|
||||
Map<String, Object> result = allocationService.getDetailedDiagnostics(qrCodeId);
|
||||
|
||||
return Result.succeed(result, "获取诊断信息成功");
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("获取详细诊断信息失败", e);
|
||||
return Result.failed("获取失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "测试数据库查询")
|
||||
@GetMapping("/test-db")
|
||||
public Result<Map<String, Object>> testDatabaseQuery(
|
||||
@Parameter(description = "二维码ID") @RequestParam String qrCodeId) {
|
||||
|
||||
try {
|
||||
log.info("测试数据库查询 - qrCodeId: {}", qrCodeId);
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
// 测试各种查询
|
||||
int totalOrders = allocationService.getOrderCountByQrCode(qrCodeId);
|
||||
result.put("totalOrders", totalOrders);
|
||||
|
||||
// 获取统计信息
|
||||
Map<String, Object> statistics = allocationService.getAllocationStatistics(qrCodeId);
|
||||
result.put("statistics", statistics);
|
||||
|
||||
// 获取诊断信息
|
||||
Map<String, Object> diagnostics = allocationService.getDetailedDiagnostics(qrCodeId);
|
||||
result.put("diagnostics", diagnostics);
|
||||
|
||||
return Result.succeed(result, "数据库查询测试完成");
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("测试数据库查询失败", e);
|
||||
return Result.failed("测试失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -134,7 +134,7 @@ public class TenantAllocationConfigController {
|
||||
);
|
||||
|
||||
// 测试分配逻辑
|
||||
Map<String, Object> testResult = allocationService.validateAllocationLogic(userId, qrCodeId, testCount);
|
||||
Map<String, Object> testResult = allocationService.validateAllocationLogic(qrCodeId, testCount);
|
||||
|
||||
// 合并结果
|
||||
Map<String, Object> result = Map.of(
|
||||
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
package com.central.order.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
/**
|
||||
* 租户分配数据库查询Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface OrderTenantAllocationMapper {
|
||||
|
||||
/**
|
||||
* 获取指定二维码下的总订单数量
|
||||
* @param qrCodeId 二维码ID
|
||||
* @return 订单数量
|
||||
*/
|
||||
@Select("SELECT COUNT(*) FROM orders WHERE code_id = #{qrCodeId} AND is_del = 0")
|
||||
int getOrderCountByQrCode(@Param("qrCodeId") String qrCodeId);
|
||||
|
||||
/**
|
||||
* 获取指定二维码下指定租户的订单数量
|
||||
* @param qrCodeId 二维码ID
|
||||
* @param tenantId 租户ID
|
||||
* @return 订单数量
|
||||
*/
|
||||
@Select("SELECT COUNT(*) FROM orders WHERE code_id = #{qrCodeId} AND tenant_id = #{tenantId} AND is_del = 0")
|
||||
int getOrderCountByQrCodeAndTenant(@Param("qrCodeId") String qrCodeId, @Param("tenantId") String tenantId);
|
||||
|
||||
/**
|
||||
* 获取指定二维码下景区租户的订单数量
|
||||
* @param qrCodeId 二维码ID
|
||||
* @param scenicTenantId 景区租户ID
|
||||
* @return 订单数量
|
||||
*/
|
||||
@Select("SELECT COUNT(*) FROM orders WHERE code_id = #{qrCodeId} AND tenant_id = #{scenicTenantId} AND is_del = 0")
|
||||
int getScenicOrderCount(@Param("qrCodeId") String qrCodeId, @Param("scenicTenantId") String scenicTenantId);
|
||||
|
||||
/**
|
||||
* 获取指定二维码下平台租户的订单数量
|
||||
* @param qrCodeId 二维码ID
|
||||
* @param platformTenantId 平台租户ID
|
||||
* @return 订单数量
|
||||
*/
|
||||
@Select("SELECT COUNT(*) FROM orders WHERE code_id = #{qrCodeId} AND tenant_id = #{platformTenantId} AND is_del = 0")
|
||||
int getPlatformOrderCount(@Param("qrCodeId") String qrCodeId, @Param("platformTenantId") String platformTenantId);
|
||||
|
||||
/**
|
||||
* 获取指定二维码下的订单统计信息
|
||||
* @param qrCodeId 二维码ID
|
||||
* @return 统计信息Map
|
||||
*/
|
||||
@Select("SELECT " +
|
||||
"COUNT(*) as totalOrders, " +
|
||||
"SUM(CASE WHEN tenant_id = #{scenicTenantId} THEN 1 ELSE 0 END) as scenicOrders, " +
|
||||
"SUM(CASE WHEN tenant_id = #{platformTenantId} THEN 1 ELSE 0 END) as platformOrders " +
|
||||
"FROM orders " +
|
||||
"WHERE code_id = #{qrCodeId} AND is_del = 0")
|
||||
java.util.Map<String, Object> getOrderStatisticsByQrCode(
|
||||
@Param("qrCodeId") String qrCodeId,
|
||||
@Param("scenicTenantId") String scenicTenantId,
|
||||
@Param("platformTenantId") String platformTenantId);
|
||||
|
||||
/**
|
||||
* 获取指定二维码下最近的订单信息
|
||||
* @param qrCodeId 二维码ID
|
||||
* @param limit 限制数量
|
||||
* @return 订单列表
|
||||
*/
|
||||
@Select("SELECT id, order_no, user_id, tenant_id, order_amount, order_status, create_time " +
|
||||
"FROM orders " +
|
||||
"WHERE code_id = #{qrCodeId} AND is_del = 0 " +
|
||||
"ORDER BY create_time DESC " +
|
||||
"LIMIT #{limit}")
|
||||
java.util.List<java.util.Map<String, Object>> getRecentOrdersByQrCode(
|
||||
@Param("qrCodeId") String qrCodeId, @Param("limit") int limit);
|
||||
|
||||
/**
|
||||
* 获取指定二维码下指定时间范围内的订单数量
|
||||
* @param qrCodeId 二维码ID
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @return 订单数量
|
||||
*/
|
||||
@Select("SELECT COUNT(*) FROM orders " +
|
||||
"WHERE code_id = #{qrCodeId} AND is_del = 0 " +
|
||||
"AND create_time >= #{startTime} AND create_time <= #{endTime}")
|
||||
int getOrderCountByQrCodeAndTimeRange(
|
||||
@Param("qrCodeId") String qrCodeId,
|
||||
@Param("startTime") java.util.Date startTime,
|
||||
@Param("endTime") java.util.Date endTime);
|
||||
}
|
||||
+14
-10
@@ -9,27 +9,25 @@ import java.util.Map;
|
||||
public interface OrderTenantAllocationService {
|
||||
|
||||
/**
|
||||
* 根据用户ID和二维码ID确定订单归属租户
|
||||
* @param userId 用户ID
|
||||
* 根据二维码ID确定订单归属租户
|
||||
* @param qrCodeId 二维码ID
|
||||
* @param scenicTenantId 景区租户ID(来自二维码)
|
||||
* @return 租户ID
|
||||
*/
|
||||
String determineTenant(String userId, String qrCodeId);
|
||||
String determineTenant(String qrCodeId, String scenicTenantId);
|
||||
|
||||
/**
|
||||
* 获取用户在该二维码下的订单计数
|
||||
* @param userId 用户ID
|
||||
* 获取该二维码下的总订单计数
|
||||
* @param qrCodeId 二维码ID
|
||||
* @return 订单计数
|
||||
*/
|
||||
int getOrderCountByUserAndQrCode(String userId, String qrCodeId);
|
||||
int getOrderCountByQrCode(String qrCodeId);
|
||||
|
||||
/**
|
||||
* 更新订单计数
|
||||
* @param userId 用户ID
|
||||
* @param qrCodeId 二维码ID
|
||||
*/
|
||||
void incrementOrderCount(String userId, String qrCodeId);
|
||||
void incrementOrderCount(String qrCodeId);
|
||||
|
||||
/**
|
||||
* 获取分配统计信息
|
||||
@@ -38,12 +36,18 @@ public interface OrderTenantAllocationService {
|
||||
*/
|
||||
Map<String, Object> getAllocationStatistics(String qrCodeId);
|
||||
|
||||
/**
|
||||
* 获取详细的分配诊断信息
|
||||
* @param qrCodeId 二维码ID
|
||||
* @return 诊断信息
|
||||
*/
|
||||
Map<String, Object> getDetailedDiagnostics(String qrCodeId);
|
||||
|
||||
/**
|
||||
* 验证分配逻辑
|
||||
* @param userId 用户ID
|
||||
* @param qrCodeId 二维码ID
|
||||
* @param expectedCount 期望的订单数量
|
||||
* @return 验证结果
|
||||
*/
|
||||
Map<String, Object> validateAllocationLogic(String userId, String qrCodeId, int expectedCount);
|
||||
Map<String, Object> validateAllocationLogic(String qrCodeId, int expectedCount);
|
||||
}
|
||||
+196
-37
@@ -1,6 +1,9 @@
|
||||
package com.central.order.service.impl;
|
||||
|
||||
import com.central.order.config.TenantAllocationConfig;
|
||||
import com.central.order.mapper.OrderTenantAllocationMapper;
|
||||
import com.central.order.model.QrCode;
|
||||
import com.central.order.service.IQrCodeService;
|
||||
import com.central.order.service.OrderTenantAllocationService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -19,21 +22,27 @@ public class OrderTenantAllocationServiceImpl implements OrderTenantAllocationSe
|
||||
@Autowired
|
||||
private TenantAllocationConfig config;
|
||||
|
||||
@Autowired
|
||||
private OrderTenantAllocationMapper orderTenantAllocationMapper;
|
||||
|
||||
@Autowired
|
||||
private IQrCodeService qrCodeService;
|
||||
|
||||
// 分配比例:10单景区 + 1单平台
|
||||
private int allocationRatio = 10;
|
||||
private int cycleSize = 11; // allocationRatio + 1
|
||||
|
||||
@Override
|
||||
public String determineTenant(String userId, String qrCodeId) {
|
||||
public String determineTenant(String qrCodeId, String scenicTenantId) {
|
||||
// 检查是否启用租户分配功能
|
||||
if (!config.isEnabled()) {
|
||||
log.debug("租户分配功能未启用,使用默认租户");
|
||||
return getScenicTenantId(qrCodeId);
|
||||
log.debug("租户分配功能未启用,使用景区租户ID: {}", scenicTenantId);
|
||||
return scenicTenantId;
|
||||
}
|
||||
|
||||
// 检查是否强制使用平台租户(用于测试)
|
||||
if (config.isForcePlatformTenant()) {
|
||||
log.info("强制使用平台租户 - userId: {}, qrCodeId: {}", userId, qrCodeId);
|
||||
log.info("强制使用平台租户 - qrCodeId: {}", qrCodeId);
|
||||
return config.getPlatformTenantId();
|
||||
}
|
||||
|
||||
@@ -41,59 +50,188 @@ public class OrderTenantAllocationServiceImpl implements OrderTenantAllocationSe
|
||||
allocationRatio = config.getAllocationRatio();
|
||||
cycleSize = allocationRatio + 1;
|
||||
|
||||
int orderCount = getOrderCountByUserAndQrCode(userId, qrCodeId);
|
||||
int orderCount = getOrderCountByQrCode(qrCodeId);
|
||||
int remainder = orderCount % cycleSize; // 当前周期内的位置
|
||||
|
||||
if (remainder == allocationRatio) { // 第11单(索引10)
|
||||
String platformTenantId = getPlatformTenantId(qrCodeId);
|
||||
log.info("订单分配给平台租户 - userId: {}, qrCodeId: {}, orderCount: {}, tenantId: {}",
|
||||
userId, qrCodeId, orderCount, platformTenantId);
|
||||
log.info("订单分配给平台租户 - qrCodeId: {}, orderCount: {}, tenantId: {}",
|
||||
qrCodeId, orderCount, platformTenantId);
|
||||
return platformTenantId;
|
||||
} else {
|
||||
String scenicTenantId = getScenicTenantId(qrCodeId);
|
||||
log.info("订单分配给景区租户 - userId: {}, qrCodeId: {}, orderCount: {}, tenantId: {}",
|
||||
userId, qrCodeId, orderCount, scenicTenantId);
|
||||
log.info("订单分配给景区租户 - qrCodeId: {}, orderCount: {}, tenantId: {}",
|
||||
qrCodeId, orderCount, scenicTenantId);
|
||||
return scenicTenantId;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrderCountByUserAndQrCode(String userId, String qrCodeId) {
|
||||
// TODO: 从数据库查询用户在该二维码下的订单计数
|
||||
// 这里先返回模拟数据,实际应该查询数据库
|
||||
log.debug("获取用户订单计数 - userId: {}, qrCodeId: {}", userId, qrCodeId);
|
||||
return 0; // 实际应该从数据库查询
|
||||
public int getOrderCountByQrCode(String qrCodeId) {
|
||||
try {
|
||||
int count = orderTenantAllocationMapper.getOrderCountByQrCode(qrCodeId);
|
||||
log.debug("获取二维码订单计数 - qrCodeId: {}, count: {}", qrCodeId, count);
|
||||
return count;
|
||||
} catch (Exception e) {
|
||||
log.error("查询二维码订单计数失败 - qrCodeId: {}", qrCodeId, e);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementOrderCount(String userId, String qrCodeId) {
|
||||
// TODO: 更新数据库中的订单计数
|
||||
log.info("更新订单计数 - userId: {}, qrCodeId: {}", userId, qrCodeId);
|
||||
// 实际应该更新数据库
|
||||
public void incrementOrderCount(String qrCodeId) {
|
||||
// 订单计数通过实际创建订单时自动增加
|
||||
// 这里主要用于日志记录,实际计数通过查询orders表获取
|
||||
log.info("订单计数已更新 - qrCodeId: {}", qrCodeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getAllocationStatistics(String qrCodeId) {
|
||||
Map<String, Object> statistics = new HashMap<>();
|
||||
|
||||
// 更新分配比例
|
||||
allocationRatio = config.getAllocationRatio();
|
||||
cycleSize = allocationRatio + 1;
|
||||
|
||||
// TODO: 从数据库查询统计信息
|
||||
statistics.put("qrCodeId", qrCodeId);
|
||||
statistics.put("allocationRatio", allocationRatio);
|
||||
statistics.put("cycleSize", cycleSize);
|
||||
statistics.put("enabled", config.isEnabled());
|
||||
statistics.put("platformTenantId", config.getPlatformTenantId());
|
||||
statistics.put("scenicTenantId", getScenicTenantId(qrCodeId));
|
||||
statistics.put("platformTenantId", getPlatformTenantId(qrCodeId));
|
||||
try {
|
||||
// 更新分配比例
|
||||
allocationRatio = config.getAllocationRatio();
|
||||
cycleSize = allocationRatio + 1;
|
||||
|
||||
// 获取景区租户ID - 需要查询二维码表
|
||||
String scenicTenantId = getScenicTenantIdFromQrCode(qrCodeId);
|
||||
String platformTenantId = config.getPlatformTenantId();
|
||||
|
||||
// 从数据库查询统计信息
|
||||
Map<String, Object> dbStatistics = orderTenantAllocationMapper.getOrderStatisticsByQrCode(
|
||||
qrCodeId, scenicTenantId, platformTenantId);
|
||||
|
||||
// 获取最近的订单信息
|
||||
java.util.List<java.util.Map<String, Object>> recentOrders =
|
||||
orderTenantAllocationMapper.getRecentOrdersByQrCode(qrCodeId, 10);
|
||||
|
||||
// 组装统计信息
|
||||
statistics.put("qrCodeId", qrCodeId);
|
||||
statistics.put("allocationRatio", allocationRatio);
|
||||
statistics.put("cycleSize", cycleSize);
|
||||
statistics.put("enabled", config.isEnabled());
|
||||
statistics.put("platformTenantId", platformTenantId);
|
||||
statistics.put("scenicTenantId", scenicTenantId);
|
||||
|
||||
// 数据库统计信息
|
||||
if (dbStatistics != null) {
|
||||
statistics.put("totalOrders", dbStatistics.get("totalOrders"));
|
||||
statistics.put("scenicOrders", dbStatistics.get("scenicOrders"));
|
||||
statistics.put("platformOrders", dbStatistics.get("platformOrders"));
|
||||
|
||||
// 计算百分比
|
||||
Long totalOrders = (Long) dbStatistics.get("totalOrders");
|
||||
Long scenicOrders = (Long) dbStatistics.get("scenicOrders");
|
||||
Long platformOrders = (Long) dbStatistics.get("platformOrders");
|
||||
|
||||
if (totalOrders != null && totalOrders > 0) {
|
||||
statistics.put("scenicPercentage", (double) scenicOrders / totalOrders * 100);
|
||||
statistics.put("platformPercentage", (double) platformOrders / totalOrders * 100);
|
||||
} else {
|
||||
statistics.put("scenicPercentage", 0.0);
|
||||
statistics.put("platformPercentage", 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
// 最近订单信息
|
||||
statistics.put("recentOrders", recentOrders);
|
||||
|
||||
log.info("获取分配统计信息成功 - qrCodeId: {}, 总订单: {}, 景区订单: {}, 平台订单: {}",
|
||||
qrCodeId, statistics.get("totalOrders"), statistics.get("scenicOrders"), statistics.get("platformOrders"));
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("获取分配统计信息失败 - qrCodeId: {}", qrCodeId, e);
|
||||
statistics.put("error", "查询失败:" + e.getMessage());
|
||||
}
|
||||
|
||||
return statistics;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> validateAllocationLogic(String userId, String qrCodeId, int expectedCount) {
|
||||
public Map<String, Object> getDetailedDiagnostics(String qrCodeId) {
|
||||
Map<String, Object> diagnostics = new HashMap<>();
|
||||
|
||||
try {
|
||||
// 获取景区租户ID - 从二维码表查询
|
||||
String scenicTenantId = getScenicTenantIdFromQrCode(qrCodeId);
|
||||
String platformTenantId = config.getPlatformTenantId();
|
||||
|
||||
// 查询各种统计数据
|
||||
int totalOrders = orderTenantAllocationMapper.getOrderCountByQrCode(qrCodeId);
|
||||
int scenicOrders = orderTenantAllocationMapper.getScenicOrderCount(qrCodeId, scenicTenantId);
|
||||
int platformOrders = orderTenantAllocationMapper.getPlatformOrderCount(qrCodeId, platformTenantId);
|
||||
|
||||
// 获取最近的订单详情
|
||||
java.util.List<java.util.Map<String, Object>> recentOrders =
|
||||
orderTenantAllocationMapper.getRecentOrdersByQrCode(qrCodeId, 20);
|
||||
|
||||
// 计算理论分配
|
||||
allocationRatio = config.getAllocationRatio();
|
||||
cycleSize = allocationRatio + 1;
|
||||
int expectedScenicOrders = 0;
|
||||
int expectedPlatformOrders = 0;
|
||||
|
||||
for (int i = 0; i < totalOrders; i++) {
|
||||
int remainder = i % cycleSize;
|
||||
if (remainder == allocationRatio) {
|
||||
expectedPlatformOrders++;
|
||||
} else {
|
||||
expectedScenicOrders++;
|
||||
}
|
||||
}
|
||||
|
||||
// 组装诊断信息
|
||||
diagnostics.put("qrCodeId", qrCodeId);
|
||||
diagnostics.put("scenicTenantId", scenicTenantId);
|
||||
diagnostics.put("platformTenantId", platformTenantId);
|
||||
diagnostics.put("allocationRatio", allocationRatio);
|
||||
diagnostics.put("cycleSize", cycleSize);
|
||||
diagnostics.put("enabled", config.isEnabled());
|
||||
|
||||
// 实际统计
|
||||
diagnostics.put("actualTotalOrders", totalOrders);
|
||||
diagnostics.put("actualScenicOrders", scenicOrders);
|
||||
diagnostics.put("actualPlatformOrders", platformOrders);
|
||||
|
||||
// 理论分配
|
||||
diagnostics.put("expectedScenicOrders", expectedScenicOrders);
|
||||
diagnostics.put("expectedPlatformOrders", expectedPlatformOrders);
|
||||
|
||||
// 差异分析
|
||||
diagnostics.put("scenicOrderDiff", scenicOrders - expectedScenicOrders);
|
||||
diagnostics.put("platformOrderDiff", platformOrders - expectedPlatformOrders);
|
||||
|
||||
// 百分比
|
||||
if (totalOrders > 0) {
|
||||
diagnostics.put("actualScenicPercentage", (double) scenicOrders / totalOrders * 100);
|
||||
diagnostics.put("actualPlatformPercentage", (double) platformOrders / totalOrders * 100);
|
||||
diagnostics.put("expectedScenicPercentage", (double) expectedScenicOrders / totalOrders * 100);
|
||||
diagnostics.put("expectedPlatformPercentage", (double) expectedPlatformOrders / totalOrders * 100);
|
||||
}
|
||||
|
||||
// 最近订单详情
|
||||
diagnostics.put("recentOrders", recentOrders);
|
||||
|
||||
// 分配状态
|
||||
int currentCount = getOrderCountByQrCode(qrCodeId);
|
||||
int remainder = currentCount % cycleSize;
|
||||
diagnostics.put("currentOrderCount", currentCount);
|
||||
diagnostics.put("currentRemainder", remainder);
|
||||
diagnostics.put("nextOrderShouldBePlatform", remainder == allocationRatio);
|
||||
|
||||
log.info("获取详细诊断信息成功 - qrCodeId: {}, 实际: 景区{}单/平台{}单, 理论: 景区{}单/平台{}单",
|
||||
qrCodeId, scenicOrders, platformOrders, expectedScenicOrders, expectedPlatformOrders);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("获取详细诊断信息失败 - qrCodeId: {}", qrCodeId, e);
|
||||
diagnostics.put("error", "查询失败:" + e.getMessage());
|
||||
}
|
||||
|
||||
return diagnostics;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> validateAllocationLogic(String qrCodeId, int expectedCount) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
// 更新分配比例
|
||||
@@ -122,8 +260,8 @@ public class OrderTenantAllocationServiceImpl implements OrderTenantAllocationSe
|
||||
result.put("enabled", config.isEnabled());
|
||||
result.put("platformTenantId", config.getPlatformTenantId());
|
||||
|
||||
log.info("分配逻辑验证完成 - 总订单: {}, 景区订单: {}, 平台订单: {}, 景区占比: {}%, 平台占比: {}%",
|
||||
expectedCount, scenicCount, platformCount,
|
||||
log.info("分配逻辑验证完成 - 二维码: {}, 总订单: {}, 景区订单: {}, 平台订单: {}, 景区占比: {}%, 平台占比: {}%",
|
||||
qrCodeId, expectedCount, scenicCount, platformCount,
|
||||
result.get("scenicPercentage"), result.get("platformPercentage"));
|
||||
|
||||
return result;
|
||||
@@ -133,9 +271,30 @@ public class OrderTenantAllocationServiceImpl implements OrderTenantAllocationSe
|
||||
* 获取景区租户ID
|
||||
*/
|
||||
private String getScenicTenantId(String qrCodeId) {
|
||||
// TODO: 根据二维码ID获取对应的景区租户ID
|
||||
// 这里先返回模拟数据
|
||||
return "scenic_tenant_" + qrCodeId;
|
||||
// 这里应该查询二维码表获取租户ID
|
||||
// 但是由于在订单创建时已经获取了二维码信息,所以直接传入景区租户ID
|
||||
// 这个方法主要用于测试和诊断,实际使用时应该传入正确的景区租户ID
|
||||
log.warn("getScenicTenantId方法被调用,但应该直接使用传入的scenicTenantId参数");
|
||||
return qrCodeId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从二维码表获取景区租户ID
|
||||
*/
|
||||
private String getScenicTenantIdFromQrCode(String qrCodeId) {
|
||||
try {
|
||||
QrCode qrCode = qrCodeService.getByCodeId(qrCodeId);
|
||||
if (qrCode != null && qrCode.getTenantId() != null) {
|
||||
log.debug("从二维码表获取景区租户ID - qrCodeId: {}, tenantId: {}", qrCodeId, qrCode.getTenantId());
|
||||
return qrCode.getTenantId();
|
||||
} else {
|
||||
log.warn("二维码不存在或租户ID为空 - qrCodeId: {}", qrCodeId);
|
||||
return qrCodeId; // 降级处理
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("查询二维码租户ID失败 - qrCodeId: {}", qrCodeId, e);
|
||||
return qrCodeId; // 降级处理
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user