🐛 修复货物类型导入未整批回滚,并把导入回滚异常迁到公共模块

问题:CargoTypeServiceImpl.importCargoType 循环内吞掉异常后正常 return,
方法正常返回导致 Spring 照常提交事务,@Transactional 起不到回滚作用。
含 1 行错误的文件会写入前面若干行正确数据,与「任一行失败即整批零写入」口径不符。

改动:
- ImportFailureException 由 org.springblade.system.excel 迁至
  org.springblade.common.excel(与 ImportFailureExcelUtil 同包)。
  blade-transport 只依赖 blade-system-api,原先拿不到该异常,
  迁到 blade-common 后 blade-system 与 blade-transport 均可引用。
- CargoTypeServiceImpl.importCargoType 补 @Transactional(rollbackFor = Exception.class),
  错误收集完毕后抛 ImportFailureException 触发回滚,不再 return failureList。
- CargoTypeController.importCargoType 由「拿返回值导出」改为
  「catch 异常 → 取 failureList 导出 → return null」,并补上传文件校验,
  对齐 PortTerminalController 的写法。
- PortTerminalController / PortTerminalServiceImpl 仅调整 import 指向新包,行为不变。

验证:
- mvn install -DskipTests 全量编译通过。
- 港口码头回归 45/45 通过,确认「异常搬家」未破坏既有基线。
- 货物类型回归 24/24 通过,含 02_一行错误多行正确_应零写入(库中零写入)。
This commit is contained in:
2026-09-23 03:47:58 +08:00
parent 29b846017b
commit 99c4bf4f7d
5 changed files with 43 additions and 10 deletions
@@ -0,0 +1,66 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.common.excel;
import org.springblade.core.log.exception.ServiceException;
import java.io.Serial;
import java.util.List;
/**
* 导入失败异常,携带失败明细用于导出原表并标注错误。
* <p>
* 批量导入采用「任一行失败即整批回滚」语义:循环内先收集完全部错误明细,
* 再抛出本异常触发事务回滚。明细在抛异常前已收集完毕,因此回滚不影响明细内容。
* <p>
* 注意:仅标注 {@code @Transactional} 并不足够。若循环内把异常吞掉(catch 后
* 只往 errorList 塞数据并正常 return),方法会正常返回,Spring 会照常提交事务。
* 必须抛出异常才能让事务真正回滚。
* <p>
* 本类位于 blade-common,供 blade-system 与 blade-transport 等模块共用。
*
* @author Chill
*/
public class ImportFailureException extends ServiceException {
@Serial
private static final long serialVersionUID = 1L;
/**
* 失败明细,包含原表全部数据,错误行已标注错误原因。
*/
private final transient List<?> failureList;
public ImportFailureException(List<?> failureList) {
super("导入失败,已回滚全部数据");
this.failureList = failureList;
}
public List<?> getFailureList() {
return failureList;
}
}