|
|
|
@ -403,22 +403,21 @@ public class QuoteDetailBomTreeServiceImpl extends ServiceImpl<QuoteDetailBomTre |
|
|
|
doSaveBomDataRecursive(finalNodeData, finalDetail, 0L); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 2. 重新计算成本 (如果开启) |
|
|
|
// 将其放在同一个事务中,如果计算失败,BOM 切换也会一并回滚,保证数据一致性 |
|
|
|
if (Boolean.TRUE.equals(tree.getRecalculateCost()) && finalDetail != null) { |
|
|
|
log.info("[BOM_SWITCH] Recalculate cost is enabled, executing cost calculation for QuoteDetailId: {}", finalDetail.getId()); |
|
|
|
try { |
|
|
|
quoteDetailService.queryQuoteDetailCost(finalDetail); |
|
|
|
log.info("[BOM_SWITCH] Cost calculation completed successfully for QuoteDetailId: {}", finalDetail.getId()); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("[BOM_SWITCH] Cost calculation failed for QuoteDetailId: {}, Error: {}", finalDetail.getId(), e.getMessage(), e); |
|
|
|
// 抛出 RuntimeException 以触发 transactionTemplate 回滚 |
|
|
|
throw new RuntimeException("成本计算失败: " + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
return null; |
|
|
|
}); |
|
|
|
|
|
|
|
// 2. 重新计算成本 (如果开启) |
|
|
|
// 移出事务外执行,避免长事务锁表导致其他用户无法查看/编辑条目明细 |
|
|
|
if (Boolean.TRUE.equals(tree.getRecalculateCost()) && finalDetail != null) { |
|
|
|
log.info("[BOM_SWITCH] Recalculate cost is enabled, executing cost calculation for QuoteDetailId: {}", finalDetail.getId()); |
|
|
|
try { |
|
|
|
quoteDetailService.queryQuoteDetailCost(finalDetail); |
|
|
|
log.info("[BOM_SWITCH] Cost calculation completed successfully for QuoteDetailId: {}", finalDetail.getId()); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("[BOM_SWITCH] Cost calculation failed for QuoteDetailId: {}, Error: {}", finalDetail.getId(), e.getMessage(), e); |
|
|
|
throw new RuntimeException("BOM切换成功,但成本重新计算失败: " + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// ========================================================================= |
|
|
|
|