This commit is contained in:
Leo
2025-11-15 17:42:56 +08:00
parent 7f4b0dd986
commit b495431b7e
2 changed files with 133 additions and 1 deletions

View File

@@ -17,6 +17,7 @@ import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jarvis.domain.JDOrder;
import com.ruoyi.jarvis.domain.dto.JDOrderSimpleDTO;
import com.ruoyi.jarvis.service.IJDOrderService;
import com.ruoyi.jarvis.service.IInstructionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
@@ -32,10 +33,12 @@ public class JDOrderListController extends BaseController
private final IJDOrderService jdOrderService;
private final IOrderRowsService orderRowsService;
private final IInstructionService instructionService;
public JDOrderListController(IJDOrderService jdOrderService, IOrderRowsService orderRowsService) {
public JDOrderListController(IJDOrderService jdOrderService, IOrderRowsService orderRowsService, IInstructionService instructionService) {
this.jdOrderService = jdOrderService;
this.orderRowsService = orderRowsService;
this.instructionService = instructionService;
}
/**
@@ -260,4 +263,24 @@ public class JDOrderListController extends BaseController
return getDataTable(simpleList);
}
/**
* 一次性批量更新历史订单将赔付金额大于0的订单标记为后返到账
* 此方法只应执行一次,用于处理历史数据
*/
@PostMapping("/tools/batch-mark-rebate-received")
public AjaxResult batchMarkRebateReceivedForCompensation() {
try {
// 调用批量更新方法
if (instructionService instanceof com.ruoyi.jarvis.service.impl.InstructionServiceImpl) {
((com.ruoyi.jarvis.service.impl.InstructionServiceImpl) instructionService)
.batchMarkRebateReceivedForCompensation();
return AjaxResult.success("批量标记后返到账完成,请查看控制台日志");
} else {
return AjaxResult.error("无法执行批量更新操作");
}
} catch (Exception e) {
return AjaxResult.error("批量标记失败: " + e.getMessage());
}
}
}

View File

@@ -66,6 +66,11 @@ public class InstructionServiceImpl implements IInstructionService {
// 存储接收的消息到Redis队列
storeMessageToRedis("instruction:request", command);
// 检测价保/赔付消息,自动标记后返到账
if (command != null && !command.trim().isEmpty()) {
handleCompensationMessage(command);
}
List<String> result;
if (command == null || command.trim().isEmpty()) {
@@ -1859,6 +1864,110 @@ public class InstructionServiceImpl implements IInstructionService {
}
}, "TencentDoc-Writer-" + order.getRemark()).start();
}
/**
* 处理价保/赔付消息,自动标记后返到账
* 消息格式示例:
* [爱心] 价保/赔付 100 [爱心]
* [裂开] 违规订单-违反京东平台规则
* 京粉:凡
* 订单343216308806 (非plus)
* ...
*/
private void handleCompensationMessage(String message) {
try {
// 检测是否包含价保/赔付和违规订单-违反京东平台规则
if (message.contains("价保/赔付") || message.contains("价保") || message.contains("赔付")) {
if (message.contains("违规订单-违反京东平台规则")) {
// 提取订单号订单343216308806
Pattern orderPattern = Pattern.compile("订单[:]\\s*(\\d+)");
Matcher matcher = orderPattern.matcher(message);
if (matcher.find()) {
String orderId = matcher.group(1);
// 查找订单
JDOrder order = jdOrderService.selectJDOrderByOrderId(orderId);
if (order != null) {
// 设置后返到账状态为1并设置到账日期为当前时间
order.setIsRebateReceived(1);
order.setRebateReceivedDate(new Date());
// 更新订单
int updateResult = jdOrderService.updateJDOrder(order);
if (updateResult > 0) {
System.out.println("✓ 自动标记后返到账成功 - 订单号: " + orderId);
} else {
System.err.println("✗ 自动标记后返到账失败 - 订单号: " + orderId + " (更新失败)");
}
} else {
System.err.println("✗ 未找到订单 - 订单号: " + orderId);
}
} else {
System.err.println("✗ 无法从消息中提取订单号");
}
}
}
} catch (Exception e) {
System.err.println("✗ 处理价保/赔付消息时发生异常: " + e.getMessage());
e.printStackTrace();
}
}
/**
* 一次性批量更新历史订单将赔付金额大于0的订单标记为后返到账
* 此方法只应执行一次,用于处理历史数据
*/
public void batchMarkRebateReceivedForCompensation() {
try {
System.out.println("开始批量标记后返到账(赔付金额>0的订单...");
// 查询所有订单
List<JDOrder> allOrders = jdOrderService.selectJDOrderList(new JDOrder());
// 查询所有订单的赔付金额从OrderRows表
int updatedCount = 0;
int skippedCount = 0;
for (JDOrder order : allOrders) {
// 查询订单的赔付金额
OrderRows orderRows = orderRowsService.selectOrderRowsByOrderId(order.getOrderId());
if (orderRows != null && orderRows.getProPriceAmount() != null && orderRows.getProPriceAmount() > 0) {
// 如果赔付金额大于0且后返到账状态不是1则更新
if (order.getIsRebateReceived() == null || order.getIsRebateReceived() != 1) {
order.setIsRebateReceived(1);
// 如果到账日期为空,设置为当前时间
if (order.getRebateReceivedDate() == null) {
order.setRebateReceivedDate(new Date());
}
int updateResult = jdOrderService.updateJDOrder(order);
if (updateResult > 0) {
updatedCount++;
System.out.println("✓ 标记后返到账 - 订单号: " + order.getOrderId() +
", 赔付金额: " + orderRows.getProPriceAmount());
} else {
System.err.println("✗ 更新失败 - 订单号: " + order.getOrderId());
}
} else {
skippedCount++;
}
} else {
skippedCount++;
}
}
System.out.println("批量标记完成!");
System.out.println("更新数量: " + updatedCount);
System.out.println("跳过数量: " + skippedCount);
System.out.println("总计: " + allOrders.size());
} catch (Exception e) {
System.err.println("✗ 批量标记后返到账时发生异常: " + e.getMessage());
e.printStackTrace();
}
}
}