|
|
@@ -48,6 +48,7 @@ import org.springframework.dao.DataAccessException;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
@@ -687,7 +688,8 @@ public class WbsTreeContractController extends BladeController {
|
|
|
@PostMapping("/import-node-excel")
|
|
|
@ApiOperationSupport(order = 13)
|
|
|
@ApiOperation(value = "客户端-导入多sheet excel到对应节点下的表单", notes = "传入节点ID、分类和多sheet excel文件")
|
|
|
- public R<Map<String, Object>> importNodeExcel(
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R importNodeExcel(
|
|
|
@RequestPart MultipartFile file,
|
|
|
@RequestParam Long nodeId,
|
|
|
@RequestParam Integer classify) throws Exception {
|
|
|
@@ -715,7 +717,6 @@ public class WbsTreeContractController extends BladeController {
|
|
|
}
|
|
|
|
|
|
// 3. 遍历所有sheet,逐个处理
|
|
|
- Map<String, Object> allResults = new LinkedHashMap<>(); // 按sheet顺序保存结果
|
|
|
int sheetCount = mainWorkbook.getWorksheets().getCount();
|
|
|
|
|
|
for (int i = 0; i < sheetCount; i++) {
|
|
|
@@ -726,7 +727,6 @@ public class WbsTreeContractController extends BladeController {
|
|
|
// 匹配对应的表单
|
|
|
WbsTreeContract matchedContract = nodeNameToContractMap.get(processedSheetName);
|
|
|
if (matchedContract == null) {
|
|
|
- allResults.put(sheetName, "未找到匹配的表单(节点名:" + sheetName + ")");
|
|
|
logger.warn("sheet名[{}]未匹配到任何表单,已跳过", sheetName);
|
|
|
continue;
|
|
|
}
|
|
|
@@ -758,9 +758,7 @@ public class WbsTreeContractController extends BladeController {
|
|
|
jdbcTemplate.execute(delSql);
|
|
|
jdbcTemplate.execute(sqlInfo);
|
|
|
} catch (Exception e) {
|
|
|
- String errorMsg = "处理sheet[" + sheetName + "]失败:" + e.getMessage();
|
|
|
- allResults.put(sheetName, errorMsg);
|
|
|
- logger.error(errorMsg, e);
|
|
|
+ throw new ServiceException("处理sheet[" + sheetName + "]失败:" + e.getMessage());
|
|
|
} finally {
|
|
|
// 关闭流并删除临时文件
|
|
|
if (tempInputStream != null) {
|
|
|
@@ -772,7 +770,7 @@ public class WbsTreeContractController extends BladeController {
|
|
|
}
|
|
|
}
|
|
|
mainWorkbook.dispose();
|
|
|
- return R.data(allResults);
|
|
|
+ return R.success("导入成功");
|
|
|
}
|
|
|
|
|
|
public StringBuilder buildMTableInsertSql(String tabName, Map<String, String> dataMap2, Object id, Object groupId, Object pKeyId) {
|