diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/PassiveWarehouseReceiptToB.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/PassiveWarehouseReceiptToB.java index b2c822be..5e2214b0 100644 --- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/PassiveWarehouseReceiptToB.java +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/PassiveWarehouseReceiptToB.java @@ -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 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 sonDetailsDtoList, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary) { + private void updateSuccessOrFail1(List 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 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 value, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary) { + private void updateSuccessOrFail2(List 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 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 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 errorHeaderDetailsDtoDtoList) { + private void updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiryTran(List errorHeaderDetailsDtoDtoList) throws Exception { Assert.notNull(errorHeaderDetailsDtoDtoList, "errorHeaderDetailsDtoDtoList不能为空!"); + AtomicReference 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 exceptionHolder) throws Exception { + //检查异常是否发生 + if (exceptionHolder.get() != null) { + Exception childException = exceptionHolder.get(); + logger.error("子线程发生异常,主线程重新抛出", childException); + throw new Exception("子线程执行失败: " + childException.getMessage(), childException); + } + } } \ No newline at end of file diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/PassiveWarehouseReceiptToC.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/PassiveWarehouseReceiptToC.java index dab2b002..4a5c987e 100644 --- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/PassiveWarehouseReceiptToC.java +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/PassiveWarehouseReceiptToC.java @@ -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 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 queryBasicArchivesStock(List passiveStorageResponseDataList, String sceneType) { + private List queryBasicArchivesStock(List 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 queryBasicArchivesTran(List passiveStorageResponseDataList) { + private List queryBasicArchivesTran(List passiveStorageResponseDataList) throws Exception { Assert.notNull(passiveStorageResponseDataList, "passiveStorageResponseDataList不能为空"); List sonDetailsDtoList = new ArrayList<>(); @@ -3163,10 +3168,11 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity { * @param sceneType 场景类型 * @author liuyang */ - private void updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiry(List errorHeaderDetailsDtoDtoV3List, String sceneType) { + private void updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiry(List errorHeaderDetailsDtoDtoV3List, String sceneType) throws Exception { Assert.notNull(errorHeaderDetailsDtoDtoV3List, "errorHeaderDetailsDtoDtoV3List不能为空!"); Assert.notNull(sceneType, "sceneType不能为空!"); + AtomicReference 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 errorHeaderDetailsDtoDtoV3List) { + private void updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiry2(List errorHeaderDetailsDtoDtoV3List) throws Exception { Assert.notNull(errorHeaderDetailsDtoDtoV3List, "errorHeaderDetailsDtoDtoV3List不能为空!"); + AtomicReference 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 sonDetailsDtoList, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary) { + private void updateSuccessOrFail1(List 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 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 value, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary, String storageTimeStamp) { + private void updateSuccessOrFail3(List 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 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 value, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary, String storageTimeStamp) { + private void updateSuccessOrFail4(List 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 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 exceptionHolder) throws Exception { + //检查异常是否发生 + if (exceptionHolder.get() != null) { + Exception childException = exceptionHolder.get(); + logger.error("子线程发生异常,主线程重新抛出", childException); + throw new Exception("子线程执行失败: " + childException.getMessage(), childException); + } + } } \ No newline at end of file diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleReturnPluginInitializerToB.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleReturnPluginInitializerToB.java index e04c5a26..9c633b45 100644 --- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleReturnPluginInitializerToB.java +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleReturnPluginInitializerToB.java @@ -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 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 queryBasicArchivesTran(List returnGoodHeaderDetailsDataDtoList) { + private List queryBasicArchivesTran(List 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 sonDetailsDtoList, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary) { + private void updateSuccessOrFail1(List 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 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 sonDetailsDtoList, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary) { + private void updateSuccessOrFail2(List 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 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 errorHeaderDetailsDtoDtoList) throws Exception { Assert.notNull(errorHeaderDetailsDtoDtoList, "errorHeaderDetailsDtoDtoList不能为空!"); + AtomicReference 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 errorHeaderDetailsDtoDtoList) { + private void updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiryTran(List errorHeaderDetailsDtoDtoList) throws Exception { Assert.notNull(errorHeaderDetailsDtoDtoList, "errorHeaderDetailsDtoDtoList不能为空!"); + AtomicReference 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 exceptionHolder) throws Exception { + //检查异常是否发生 + if (exceptionHolder.get() != null) { + Exception childException = exceptionHolder.get(); + logger.error("子线程发生异常,主线程重新抛出", childException); + throw new Exception("子线程执行失败: " + childException.getMessage(), childException); + } + } } \ No newline at end of file diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleReturnPluginInitializerToC.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleReturnPluginInitializerToC.java index 71c7839a..53dd3d1e 100644 --- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleReturnPluginInitializerToC.java +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleReturnPluginInitializerToC.java @@ -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 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 returnGoodHeaderDetailsDataDtoArrayList) throws Exception { if (returnGoodHeaderDetailsDataDtoArrayList != null && returnGoodHeaderDetailsDataDtoArrayList.size() > 0) { + AtomicReference exceptionHolder = new AtomicReference<>(); + List headerDetailsDtoList1 = new ArrayList<>(); List 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 queryBasicArchivesStock(List returnGoodHeaderDetailsDataDtoList1, String sceneType) { + private List queryBasicArchivesStock(List 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 errorHeaderDetailsDtoDtoList, String sceneType) { + private void updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiry(List errorHeaderDetailsDtoDtoList, String sceneType) throws Exception { Assert.notNull(errorHeaderDetailsDtoDtoList, "errorHeaderDetailsDtoDtoList不能为空!"); + AtomicReference 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 sonDetailsDtoList, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary) { + private void updateSuccessOrFail1(List 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 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 sonDetailsDtoList, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary, String storageTimeStamp) { + private void updateSuccessOrFail2(List 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 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 sonDetailsDtoList, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary, String storageTimeStamp) { + private void updateSuccessOrFail3(List 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 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 exceptionHolder) throws Exception { + //检查异常是否发生 + if (exceptionHolder.get() != null) { + Exception childException = exceptionHolder.get(); + logger.error("子线程发生异常,主线程重新抛出", childException); + throw new Exception("子线程执行失败: " + childException.getMessage(), childException); + } + } } \ No newline at end of file