refactor(sales): 重构无源件和销售退货插件的异常处理机制

- 在 PassiveWarehouseReceiptToB、PassiveWarehouseReceiptToC、SoSaleReturnPluginInitializerToB 和 SoSaleReturnPluginInitializerToC 类中添加了 throwChildThreadException 方法
- 该方法用于捕获和抛出子线程中的异常,确保主线程能够感知到子线程的异常情况
- 在多个方法中添加了 AtomicReference<Exception> exceptionHolder = new AtomicReference<>(); 用于存储子线程异常
- 在子线程执行完毕后,调用 throwChildThreadException 方法检查并抛出异常
- 优化了异常日志的记录方式,增加了子线程异常的详细信息
This commit is contained in:
liuy 2025-08-08 17:56:29 +08:00
parent 581f95c4e6
commit 1e4d0c8e8c
4 changed files with 143 additions and 24 deletions

View File

@ -48,6 +48,7 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@ -199,6 +200,7 @@ public class PassiveWarehouseReceiptToB extends PluginBaseEntity {
public JsonResultEntity executeBusiness(JSONObject requestJson) throws Exception {
logger.info("触发调用:{}" + getPluginName());
try {
AtomicReference<Exception> exceptionHolder = new AtomicReference<>();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
@ -231,6 +233,7 @@ public class PassiveWarehouseReceiptToB extends PluginBaseEntity {
}
} catch (Exception e) {
logger.error("executeBusiness方法异常", e);
exceptionHolder.set(e);
}
long endMillis = System.currentTimeMillis();
logger.info("executeBusiness方法调用结束" + getPluginName() + "-插件 执行耗时:{}", (endMillis - startMillis));
@ -246,6 +249,7 @@ public class PassiveWarehouseReceiptToB extends PluginBaseEntity {
logger.error("thread.join();抛出异常", e);
}
}
throwChildThreadException(exceptionHolder);
} catch (Exception e) {
logger.error("executeBusiness方法抛出异常", e);
}
@ -2418,11 +2422,11 @@ public class PassiveWarehouseReceiptToB extends PluginBaseEntity {
* @param newsystemprimary 下游主键
* @author liuyang
*/
private void updateSuccessOrFail1(List<PassiveStorageResponse.Details> sonDetailsDtoList, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary) {
private void updateSuccessOrFail1(List<PassiveStorageResponse.Details> sonDetailsDtoList, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary) throws Exception {
if (newTransmitInfo != null && !"".equals(newTransmitInfo.trim()) && newTransmitInfo.length() >= 400) {
newTransmitInfo = newTransmitInfo.substring(0, 400);
}
AtomicReference<Exception> exceptionHolder = new AtomicReference<>();
String finalNewTransmitInfo = newTransmitInfo;
Thread thread = new Thread(new Runnable() {
@Override
@ -2459,6 +2463,7 @@ public class PassiveWarehouseReceiptToB extends PluginBaseEntity {
}
} catch (Exception e) {
logger.error("无源件日志同步,抛出异常", e);
exceptionHolder.set(e);
}
}
});
@ -2468,6 +2473,7 @@ public class PassiveWarehouseReceiptToB extends PluginBaseEntity {
} catch (Exception e) {
logger.error("updateSuccessOrFail1方法现场抛出异常", e);
}
throwChildThreadException(exceptionHolder);
}
/**
@ -2486,11 +2492,12 @@ public class PassiveWarehouseReceiptToB extends PluginBaseEntity {
*
* @author liuyang
*/
private void updateSuccessOrFail2(List<PassiveStorageResponse.Details> value, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary) {
private void updateSuccessOrFail2(List<PassiveStorageResponse.Details> value, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary) throws Exception {
if (newTransmitInfo != null && !"".equals(newTransmitInfo.trim()) && newTransmitInfo.length() >= 400) {
newTransmitInfo = newTransmitInfo.substring(0, 400);
}
AtomicReference<Exception> exceptionHolder = new AtomicReference<>();
String finalNewTransmitInfo = newTransmitInfo;
Thread thread = new Thread(new Runnable() {
@Override
@ -2528,6 +2535,7 @@ public class PassiveWarehouseReceiptToB extends PluginBaseEntity {
}
} catch (Exception e) {
logger.error("TOB确认收入同步日志抛出异常", e);
exceptionHolder.set(e);
}
}
});
@ -2537,6 +2545,7 @@ public class PassiveWarehouseReceiptToB extends PluginBaseEntity {
} catch (Exception e) {
logger.error("updateSuccessOrFail1方法现场抛出异常", e);
}
throwChildThreadException(exceptionHolder);
}
/**
@ -2550,6 +2559,7 @@ public class PassiveWarehouseReceiptToB extends PluginBaseEntity {
Assert.notNull(errorHeaderDetailsDtoDtoV3List, "errorHeaderDetailsDtoDtoV3List不能为空");
Assert.notNull(sceneType, "sceneType不能为空");
AtomicReference<Exception> exceptionHolder = new AtomicReference<>();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
@ -2615,6 +2625,7 @@ public class PassiveWarehouseReceiptToB extends PluginBaseEntity {
}
} catch (Exception e) {
logger.error("无源件业务填充出库明细日志抛出异常", e);
exceptionHolder.set(e);
}
}
});
@ -2624,6 +2635,7 @@ public class PassiveWarehouseReceiptToB extends PluginBaseEntity {
} catch (Exception e) {
logger.error("updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiry方法调用join 跑出异常", e);
}
throwChildThreadException(exceptionHolder);
}
@ -2632,9 +2644,10 @@ public class PassiveWarehouseReceiptToB extends PluginBaseEntity {
*
* @author liuyang
*/
private void updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiryTran(List<ErrorHeaderDetailsDtoDtoV2> errorHeaderDetailsDtoDtoList) {
private void updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiryTran(List<ErrorHeaderDetailsDtoDtoV2> errorHeaderDetailsDtoDtoList) throws Exception {
Assert.notNull(errorHeaderDetailsDtoDtoList, "errorHeaderDetailsDtoDtoList不能为空");
AtomicReference<Exception> exceptionHolder = new AtomicReference<>();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
@ -2680,6 +2693,7 @@ public class PassiveWarehouseReceiptToB extends PluginBaseEntity {
}
} catch (Exception e) {
logger.error("TOB填充出库明细日志抛出异常", e);
exceptionHolder.set(e);
}
}
});
@ -2689,6 +2703,7 @@ public class PassiveWarehouseReceiptToB extends PluginBaseEntity {
} catch (Exception e) {
logger.error("updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiry方法现场抛出异常", e);
}
throwChildThreadException(exceptionHolder);
}
/**
@ -2890,4 +2905,16 @@ public class PassiveWarehouseReceiptToB extends PluginBaseEntity {
// }
// return filteredList;
// }
/**
* 抛出子线程的异常
*/
private void throwChildThreadException(AtomicReference<Exception> exceptionHolder) throws Exception {
//检查异常是否发生
if (exceptionHolder.get() != null) {
Exception childException = exceptionHolder.get();
logger.error("子线程发生异常,主线程重新抛出", childException);
throw new Exception("子线程执行失败: " + childException.getMessage(), childException);
}
}
}

View File

@ -52,6 +52,7 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@ -183,6 +184,7 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity {
try {
String requestJsonParam = String.valueOf(requestJson.get("param"));
AtomicReference<Exception> exceptionHolder = new AtomicReference<>();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
@ -216,6 +218,7 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity {
}
} catch (Exception e) {
logger.error("executeBusiness方法异常", e);
exceptionHolder.set(e);
}
long endMillis = System.currentTimeMillis();
logger.info("executeBusiness方法调用结束" + getPluginName() + "-插件 执行耗时:{}", (endMillis - startMillis));
@ -231,6 +234,8 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity {
logger.error("thread.join();抛出异常", e);
}
}
throwChildThreadException(exceptionHolder);
} catch (Exception e) {
logger.error("executeBusiness方法抛出异常", e);
}
@ -1587,7 +1592,7 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity {
* @param sceneType 推送场景
* @author liuyang
*/
private List<PassiveStorageSonDetailsDto> queryBasicArchivesStock(List<PassiveStorageResponse.Data> passiveStorageResponseDataList, String sceneType) {
private List<PassiveStorageSonDetailsDto> queryBasicArchivesStock(List<PassiveStorageResponse.Data> passiveStorageResponseDataList, String sceneType) throws Exception {
Assert.notNull(passiveStorageResponseDataList, "passiveStorageResponseDataList不能为空");
Assert.notNull(sceneType, "sceneType不能为空");
@ -1798,7 +1803,7 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity {
* @param passiveStorageResponseDataList OFS无源入库单
* @author liuyang
*/
private List<PassiveStorageSonDetailsDto2> queryBasicArchivesTran(List<PassiveStorageResponse.Data> passiveStorageResponseDataList) {
private List<PassiveStorageSonDetailsDto2> queryBasicArchivesTran(List<PassiveStorageResponse.Data> passiveStorageResponseDataList) throws Exception {
Assert.notNull(passiveStorageResponseDataList, "passiveStorageResponseDataList不能为空");
List<PassiveStorageSonDetailsDto2> sonDetailsDtoList = new ArrayList<>();
@ -3163,10 +3168,11 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity {
* @param sceneType 场景类型
* @author liuyang
*/
private void updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiry(List<ErrorHeaderDetailsDtoDtoV3> errorHeaderDetailsDtoDtoV3List, String sceneType) {
private void updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiry(List<ErrorHeaderDetailsDtoDtoV3> errorHeaderDetailsDtoDtoV3List, String sceneType) throws Exception {
Assert.notNull(errorHeaderDetailsDtoDtoV3List, "errorHeaderDetailsDtoDtoV3List不能为空");
Assert.notNull(sceneType, "sceneType不能为空");
AtomicReference<Exception> exceptionHolder = new AtomicReference<>();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
@ -3233,6 +3239,7 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity {
}
} catch (Exception e) {
logger.error("无源件业务填充出库明细日志抛出异常", e);
exceptionHolder.set(e);
}
}
});
@ -3242,6 +3249,7 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity {
} catch (Exception e) {
logger.error("updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiry方法调用join 跑出异常", e);
}
throwChildThreadException(exceptionHolder);
}
/**
@ -3250,9 +3258,10 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity {
* @param errorHeaderDetailsDtoDtoV3List 错误日志
* @author liuyang
*/
private void updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiry2(List<ErrorHeaderDetailsDtoDtoV4> errorHeaderDetailsDtoDtoV3List) {
private void updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiry2(List<ErrorHeaderDetailsDtoDtoV4> errorHeaderDetailsDtoDtoV3List) throws Exception {
Assert.notNull(errorHeaderDetailsDtoDtoV3List, "errorHeaderDetailsDtoDtoV3List不能为空");
AtomicReference<Exception> exceptionHolder = new AtomicReference<>();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
@ -3320,6 +3329,7 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity {
}
} catch (Exception e) {
logger.error("无源件-售后订单业务填充出库明细日志抛出异常", e);
exceptionHolder.set(e);
}
}
});
@ -3329,6 +3339,7 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity {
} catch (Exception e) {
logger.error("updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiry方法调用join 跑出异常", e);
}
throwChildThreadException(exceptionHolder);
}
/**
@ -3336,11 +3347,11 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity {
*
* @author liuyang
*/
private void updateSuccessOrFail1(List<PassiveStorageSonDetailsDto> sonDetailsDtoList, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary) {
private void updateSuccessOrFail1(List<PassiveStorageSonDetailsDto> sonDetailsDtoList, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary) throws Exception {
if (newTransmitInfo != null && !"".equals(newTransmitInfo.trim()) && newTransmitInfo.length() >= 400) {
newTransmitInfo = newTransmitInfo.substring(0, 400);
}
AtomicReference<Exception> exceptionHolder = new AtomicReference<>();
String finalNewTransmitInfo = newTransmitInfo;
Thread thread = new Thread(new Runnable() {
@Override
@ -3387,6 +3398,7 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity {
}
} catch (Exception e) {
logger.error("无源件日志同步,抛出异常", e);
exceptionHolder.set(e);
}
}
});
@ -3396,6 +3408,7 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity {
} catch (Exception e) {
logger.error("updateSuccessOrFail1方法现场抛出异常", e);
}
throwChildThreadException(exceptionHolder);
}
/**
@ -3469,11 +3482,12 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity {
* @param newsystemprimary 下游系统主键
* @author liuyang
*/
private void updateSuccessOrFail3(List<PassiveStorageSonDetailsDto2> value, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary, String storageTimeStamp) {
private void updateSuccessOrFail3(List<PassiveStorageSonDetailsDto2> value, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary, String storageTimeStamp) throws Exception {
if (newTransmitInfo != null && !"".equals(newTransmitInfo.trim()) && newTransmitInfo.length() >= 400) {
newTransmitInfo = newTransmitInfo.substring(0, 400);
}
AtomicReference<Exception> exceptionHolder = new AtomicReference<>();
String finalNewTransmitInfo = newTransmitInfo;
Thread thread = new Thread(new Runnable() {
@Override
@ -3516,6 +3530,7 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity {
}
} catch (Exception e) {
logger.error("TOC确认收入同步日志抛出异常", e);
exceptionHolder.set(e);
}
}
});
@ -3525,6 +3540,7 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity {
} catch (Exception e) {
logger.error("updateSuccessOrFail1方法现场抛出异常", e);
}
throwChildThreadException(exceptionHolder);
}
/**
@ -3536,11 +3552,12 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity {
* @param newsystemprimary 下游系统主键
* @author liuyang
*/
private void updateSuccessOrFail4(List<PassiveStorageSonDetailsDto2> value, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary, String storageTimeStamp) {
private void updateSuccessOrFail4(List<PassiveStorageSonDetailsDto2> value, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary, String storageTimeStamp) throws Exception {
if (newTransmitInfo != null && !"".equals(newTransmitInfo.trim()) && newTransmitInfo.length() >= 400) {
newTransmitInfo = newTransmitInfo.substring(0, 400);
}
AtomicReference<Exception> exceptionHolder = new AtomicReference<>();
String finalNewTransmitInfo = newTransmitInfo;
Thread thread = new Thread(new Runnable() {
@Override
@ -3583,6 +3600,7 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity {
}
} catch (Exception e) {
logger.error("TOC确认收入同步日志抛出异常", e);
exceptionHolder.set(e);
}
}
});
@ -3592,6 +3610,7 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity {
} catch (Exception e) {
logger.error("updateSuccessOrFail1方法现场抛出异常", e);
}
throwChildThreadException(exceptionHolder);
}
/**
@ -4796,4 +4815,16 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity {
}
return saleorderRequestDto;
}
/**
* 抛出子线程的异常
*/
private void throwChildThreadException(AtomicReference<Exception> exceptionHolder) throws Exception {
//检查异常是否发生
if (exceptionHolder.get() != null) {
Exception childException = exceptionHolder.get();
logger.error("子线程发生异常,主线程重新抛出", childException);
throw new Exception("子线程执行失败: " + childException.getMessage(), childException);
}
}
}

View File

@ -46,6 +46,7 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@ -112,6 +113,7 @@ public class SoSaleReturnPluginInitializerToB extends PluginBaseEntity {
public JsonResultEntity executeBusiness(JSONObject requestJson) throws Exception {
logger.info("触发调用:{}" + getPluginName());
try {
AtomicReference<Exception> exceptionHolder = new AtomicReference<>();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
@ -144,6 +146,7 @@ public class SoSaleReturnPluginInitializerToB extends PluginBaseEntity {
}
} catch (Exception e) {
logger.error("executeBusiness方法异常", e);
exceptionHolder.set(e);
}
long endMillis = System.currentTimeMillis();
logger.info("executeBusiness方法调用结束" + getPluginName() + "-插件 执行耗时:{}", (endMillis - startMillis));
@ -159,6 +162,7 @@ public class SoSaleReturnPluginInitializerToB extends PluginBaseEntity {
logger.error("thread.join();抛出异常", e);
}
}
throwChildThreadException(exceptionHolder);
} catch (Exception e) {
logger.error("executeBusiness方法抛出异常", e);
}
@ -1266,7 +1270,7 @@ public class SoSaleReturnPluginInitializerToB extends PluginBaseEntity {
* @param returnGoodHeaderDetailsDataDtoList 查询出来的售后入库单数据
* @author liuyang
*/
private List<OrderToBHeaderDto> queryBasicArchivesTran(List<StockinOrderSearchResponse.StockinOrder> returnGoodHeaderDetailsDataDtoList) {
private List<OrderToBHeaderDto> queryBasicArchivesTran(List<StockinOrderSearchResponse.StockinOrder> returnGoodHeaderDetailsDataDtoList) throws Exception {
if (returnGoodHeaderDetailsDataDtoList != null) {
logger.info("确认收入需要把OFS档案转换为U8C档案的O数据条数{}", returnGoodHeaderDetailsDataDtoList.size());
}
@ -2387,11 +2391,11 @@ public class SoSaleReturnPluginInitializerToB extends PluginBaseEntity {
*
* @author liuyang
*/
private void updateSuccessOrFail1(List<StockinOrderSearchResponse.StockinOrder.StockinB> sonDetailsDtoList, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary) {
private void updateSuccessOrFail1(List<StockinOrderSearchResponse.StockinOrder.StockinB> sonDetailsDtoList, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary) throws Exception {
if (newTransmitInfo != null && !"".equals(newTransmitInfo.trim()) && newTransmitInfo.length() >= 400) {
newTransmitInfo = newTransmitInfo.substring(0, 400);
}
AtomicReference<Exception> exceptionHolder = new AtomicReference<>();
String finalNewTransmitInfo = newTransmitInfo;
Thread thread = new Thread(new Runnable() {
@Override
@ -2428,6 +2432,7 @@ public class SoSaleReturnPluginInitializerToB extends PluginBaseEntity {
}
} catch (Exception e) {
logger.error("TOC库存同步日志抛出异常", e);
exceptionHolder.set(e);
}
}
});
@ -2437,6 +2442,7 @@ public class SoSaleReturnPluginInitializerToB extends PluginBaseEntity {
} catch (Exception e) {
logger.error("updateSuccessOrFail1方法现场抛出异常", e);
}
throwChildThreadException(exceptionHolder);
}
/**
@ -2455,11 +2461,12 @@ public class SoSaleReturnPluginInitializerToB extends PluginBaseEntity {
*
* @author liuyang
*/
private void updateSuccessOrFail2(List<StockinOrderSearchResponse.StockinOrder.StockinB> sonDetailsDtoList, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary) {
private void updateSuccessOrFail2(List<StockinOrderSearchResponse.StockinOrder.StockinB> sonDetailsDtoList, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary) throws Exception {
if (newTransmitInfo != null && !"".equals(newTransmitInfo.trim()) && newTransmitInfo.length() >= 400) {
newTransmitInfo = newTransmitInfo.substring(0, 400);
}
AtomicReference<Exception> exceptionHolder = new AtomicReference<>();
String finalNewTransmitInfo = newTransmitInfo;
Thread thread = new Thread(new Runnable() {
@Override
@ -2496,6 +2503,7 @@ public class SoSaleReturnPluginInitializerToB extends PluginBaseEntity {
}
} catch (Exception e) {
logger.error("TOC库存同步日志抛出异常", e);
exceptionHolder.set(e);
}
}
});
@ -2505,6 +2513,7 @@ public class SoSaleReturnPluginInitializerToB extends PluginBaseEntity {
} catch (Exception e) {
logger.error("updateSuccessOrFail2方法现场抛出异常", e);
}
throwChildThreadException(exceptionHolder);
}
/**
@ -2515,6 +2524,7 @@ public class SoSaleReturnPluginInitializerToB extends PluginBaseEntity {
private void updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiryStock(List<ErrorHeaderDetailsDtoDtoV2> errorHeaderDetailsDtoDtoList) throws Exception {
Assert.notNull(errorHeaderDetailsDtoDtoList, "errorHeaderDetailsDtoDtoList不能为空");
AtomicReference<Exception> exceptionHolder = new AtomicReference<>();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
@ -2560,6 +2570,7 @@ public class SoSaleReturnPluginInitializerToB extends PluginBaseEntity {
}
} catch (Exception e) {
logger.error("TOB填充出库明细日志抛出异常", e);
exceptionHolder.set(e);
}
}
});
@ -2569,6 +2580,7 @@ public class SoSaleReturnPluginInitializerToB extends PluginBaseEntity {
} catch (Exception e) {
logger.error("updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiry方法现场抛出异常", e);
}
throwChildThreadException(exceptionHolder);
}
@ -2577,9 +2589,10 @@ public class SoSaleReturnPluginInitializerToB extends PluginBaseEntity {
*
* @author liuyang
*/
private void updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiryTran(List<ErrorHeaderDetailsDtoDtoV2> errorHeaderDetailsDtoDtoList) {
private void updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiryTran(List<ErrorHeaderDetailsDtoDtoV2> errorHeaderDetailsDtoDtoList) throws Exception {
Assert.notNull(errorHeaderDetailsDtoDtoList, "errorHeaderDetailsDtoDtoList不能为空");
AtomicReference<Exception> exceptionHolder = new AtomicReference<>();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
@ -2625,6 +2638,7 @@ public class SoSaleReturnPluginInitializerToB extends PluginBaseEntity {
}
} catch (Exception e) {
logger.error("TOB填充出库明细日志抛出异常", e);
exceptionHolder.set(e);
}
}
});
@ -2634,6 +2648,7 @@ public class SoSaleReturnPluginInitializerToB extends PluginBaseEntity {
} catch (Exception e) {
logger.error("updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiry方法现场抛出异常", e);
}
throwChildThreadException(exceptionHolder);
}
/**
@ -2800,4 +2815,16 @@ public class SoSaleReturnPluginInitializerToB extends PluginBaseEntity {
logger.error("{} 插件:{},打印拉取到的单据号出错", type, getPluginName(), e);
}
}
/**
* 抛出子线程的异常
*/
private void throwChildThreadException(AtomicReference<Exception> exceptionHolder) throws Exception {
//检查异常是否发生
if (exceptionHolder.get() != null) {
Exception childException = exceptionHolder.get();
logger.error("子线程发生异常,主线程重新抛出", childException);
throw new Exception("子线程执行失败: " + childException.getMessage(), childException);
}
}
}

View File

@ -45,6 +45,7 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@ -120,6 +121,7 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
try {
String requestJsonParam = String.valueOf(requestJson.get("param"));
AtomicReference<Exception> exceptionHolder = new AtomicReference<>();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
@ -153,6 +155,7 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
}
} catch (Exception e) {
logger.error("executeBusiness方法异常", e);
exceptionHolder.set(e);
}
long endMillis = System.currentTimeMillis();
logger.info("executeBusiness方法调用结束" + getPluginName() + "-插件 执行耗时:{}", (endMillis - startMillis));
@ -168,6 +171,7 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
logger.error("thread.join();抛出异常", e);
}
}
throwChildThreadException(exceptionHolder);
} catch (Exception e) {
logger.error("executeBusiness方法抛出异常", e);
}
@ -588,6 +592,8 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
*/
private void batchInsert(List<StockinOrderSearchResponse.StockinOrder> returnGoodHeaderDetailsDataDtoArrayList) throws Exception {
if (returnGoodHeaderDetailsDataDtoArrayList != null && returnGoodHeaderDetailsDataDtoArrayList.size() > 0) {
AtomicReference<Exception> exceptionHolder = new AtomicReference<>();
List<StockinOrderSearchResponse.StockinOrder.StockinH> headerDetailsDtoList1 = new ArrayList<>();
List<StockinOrderSearchResponse.StockinOrder.StockinB> headerDetailsDtoList2 = new ArrayList<>();
@ -620,6 +626,7 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
}
} catch (Exception e) {
logger.error("线程保存TOC退货主表抛出异常", e);
exceptionHolder.set(e);
}
}
});
@ -631,6 +638,8 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
}
long endTime = System.currentTimeMillis();
logger.info("插入或更新TOC退货入库表头-耗时:{}", (endTime - startTime));
throwChildThreadException(exceptionHolder);
}
//插入明细表
@ -651,6 +660,7 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
}
} catch (Exception e) {
logger.error("线程保存TOC退货明细抛出异常", e);
exceptionHolder.set(e);
}
}
});
@ -662,6 +672,8 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
}
long endTime = System.currentTimeMillis();
logger.info("插入或更新TOC退货入库表体-耗时:{}", (endTime - startTime));
throwChildThreadException(exceptionHolder);
}
}
}
@ -1535,7 +1547,7 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
* @param sceneType 业务场景类型
* @author liuyang
*/
private List<GoodsRertunSonDetailsDto> queryBasicArchivesStock(List<StockinOrderSearchResponse.StockinOrder> returnGoodHeaderDetailsDataDtoList1, String sceneType) {
private List<GoodsRertunSonDetailsDto> queryBasicArchivesStock(List<StockinOrderSearchResponse.StockinOrder> returnGoodHeaderDetailsDataDtoList1, String sceneType) throws Exception {
Assert.notNull(returnGoodHeaderDetailsDataDtoList1, "returnGoodHeaderDetailsDataDtoList1不能为空");
Assert.notNull(sceneType, "sceneType不能为空");
@ -2555,9 +2567,10 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
* @param sceneType 场景类型
* @author liuyang
*/
private void updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiry(List<ErrorHeaderDetailsDtoDtoV2> errorHeaderDetailsDtoDtoList, String sceneType) {
private void updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiry(List<ErrorHeaderDetailsDtoDtoV2> errorHeaderDetailsDtoDtoList, String sceneType) throws Exception {
Assert.notNull(errorHeaderDetailsDtoDtoList, "errorHeaderDetailsDtoDtoList不能为空");
AtomicReference<Exception> exceptionHolder = new AtomicReference<>();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
@ -2637,6 +2650,7 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
}
} catch (Exception e) {
logger.error("TOB业务填充出库明细日志抛出异常", e);
exceptionHolder.set(e);
}
}
});
@ -2646,6 +2660,7 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
} catch (Exception e) {
logger.error("updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiry方法现场抛出异常", e);
}
throwChildThreadException(exceptionHolder);
}
/**
@ -2653,11 +2668,11 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
*
* @author liuyang
*/
private void updateSuccessOrFail1(List<GoodsRertunSonDetailsDto> sonDetailsDtoList, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary) {
private void updateSuccessOrFail1(List<GoodsRertunSonDetailsDto> sonDetailsDtoList, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary) throws Exception {
if (newTransmitInfo != null && !"".equals(newTransmitInfo.trim()) && newTransmitInfo.length() >= 400) {
newTransmitInfo = newTransmitInfo.substring(0, 400);
}
AtomicReference<Exception> exceptionHolder = new AtomicReference<>();
String finalNewTransmitInfo = newTransmitInfo;
Thread thread = new Thread(new Runnable() {
@Override
@ -2698,6 +2713,7 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
}
} catch (Exception e) {
logger.error("TOC库存同步日志抛出异常", e);
exceptionHolder.set(e);
}
}
});
@ -2707,6 +2723,7 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
} catch (Exception e) {
logger.error("updateSuccessOrFail1方法现场抛出异常", e);
}
throwChildThreadException(exceptionHolder);
}
/**
@ -2714,11 +2731,12 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
*
* @author liuyang
*/
private void updateSuccessOrFail2(List<GoodsRertunSonDetailsDto> sonDetailsDtoList, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary, String storageTimeStamp) {
private void updateSuccessOrFail2(List<GoodsRertunSonDetailsDto> sonDetailsDtoList, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary, String storageTimeStamp) throws Exception {
if (newTransmitInfo != null && !"".equals(newTransmitInfo.trim()) && newTransmitInfo.length() >= 400) {
newTransmitInfo = newTransmitInfo.substring(0, 400);
}
AtomicReference<Exception> exceptionHolder = new AtomicReference<>();
String finalNewTransmitInfo = newTransmitInfo;
Thread thread = new Thread(new Runnable() {
@Override
@ -2760,6 +2778,7 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
}
} catch (Exception e) {
logger.error("TOC确认收入同步日志抛出异常", e);
exceptionHolder.set(e);
}
}
});
@ -2769,6 +2788,7 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
} catch (Exception e) {
logger.error("updateSuccessOrFail1方法现场抛出异常", e);
}
throwChildThreadException(exceptionHolder);
}
/**
@ -2776,11 +2796,11 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
*
* @author liuyang
*/
private void updateSuccessOrFail3(List<GoodsRertunSonDetailsDto> sonDetailsDtoList, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary, String storageTimeStamp) {
private void updateSuccessOrFail3(List<GoodsRertunSonDetailsDto> sonDetailsDtoList, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary, String storageTimeStamp) throws Exception {
if (newTransmitInfo != null && !"".equals(newTransmitInfo.trim()) && newTransmitInfo.length() >= 400) {
newTransmitInfo = newTransmitInfo.substring(0, 400);
}
AtomicReference<Exception> exceptionHolder = new AtomicReference<>();
String finalNewTransmitInfo = newTransmitInfo;
Thread thread = new Thread(new Runnable() {
@Override
@ -2823,6 +2843,7 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
}
} catch (Exception e) {
logger.error("TOC确认收入同步日志抛出异常", e);
exceptionHolder.set(e);
}
}
});
@ -2832,6 +2853,7 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
} catch (Exception e) {
logger.error("updateSuccessOrFail1方法现场抛出异常", e);
}
throwChildThreadException(exceptionHolder);
}
/**
@ -3929,4 +3951,16 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
}
return saleorderRequestDto;
}
/**
* 抛出子线程的异常
*/
private void throwChildThreadException(AtomicReference<Exception> exceptionHolder) throws Exception {
//检查异常是否发生
if (exceptionHolder.get() != null) {
Exception childException = exceptionHolder.get();
logger.error("子线程发生异常,主线程重新抛出", childException);
throw new Exception("子线程执行失败: " + childException.getMessage(), childException);
}
}
}