|
23 | 23 | import org.springframework.ai.tool.annotation.Tool; |
24 | 24 | import org.springframework.beans.factory.annotation.Autowired; |
25 | 25 | import org.springframework.stereotype.Service; |
| 26 | +import org.springframework.transaction.annotation.Transactional; |
26 | 27 |
|
27 | 28 | import java.io.ByteArrayOutputStream; |
28 | 29 | import java.io.IOException; |
@@ -152,7 +153,7 @@ public String readFileFromRepo(String url) { |
152 | 153 | return JsonUtils.mapper().writeValueAsString(fileResult); |
153 | 154 | } catch (Exception e) { |
154 | 155 | e.printStackTrace(); |
155 | | - log.error("从Raw GitHub URL {} 中读取文件 '{}' 失败: {}", url, "bundle.json", e.getMessage()); |
| 156 | + log.error("从 URL {} 中读取文件 '{}' 失败: {}", url, "bundle.json", e.getMessage()); |
156 | 157 | return "Error: " + e.getMessage(); |
157 | 158 | } |
158 | 159 |
|
@@ -344,6 +345,7 @@ private List<Component> buildComponentList(BundleDto bundleDto, List<Map<String, |
344 | 345 | * @param bundleDto The BundleDto containing the materials to be parsed. |
345 | 346 | * @return A Result object containing the BundleResultDto with the parsed components and packages, or an error if parsing fails. |
346 | 347 | */ |
| 348 | + @Transactional(rollbackFor = Exception.class) |
347 | 349 | public Result<BundleResultDto> parseBundle(BundleDto bundleDto) { |
348 | 350 |
|
349 | 351 | List<Map<String, Object>> components = bundleDto.getMaterials().getComponents(); |
@@ -378,6 +380,7 @@ public Result<BundleResultDto> parseBundle(BundleDto bundleDto) { |
378 | 380 | * @param componentList The list of components to be processed for creation or update. |
379 | 381 | * @return A FileResult object containing the count of inserted and updated records. |
380 | 382 | */ |
| 383 | + @Transactional(rollbackFor = Exception.class) |
381 | 384 | public FileResult bulkCreate(List<Component> componentList) { |
382 | 385 | int addNum = 0; |
383 | 386 | int updateNum = 0; |
@@ -416,11 +419,17 @@ public FileResult bulkCreate(List<Component> componentList) { |
416 | 419 | MaterialComponent materialComponent = new MaterialComponent(); |
417 | 420 | materialComponent.setMaterialId(1); |
418 | 421 | materialComponent.setComponentId(component.getId()); |
419 | | - baseMapper.createMaterialComponent(materialComponent); |
| 422 | + Integer materialComponent1 = baseMapper.createMaterialComponent(materialComponent); |
| 423 | + if(materialComponent1 != 1) { |
| 424 | + throw new IllegalStateException("createMaterialComponent failed: " + materialComponent1); |
| 425 | + } |
420 | 426 | MaterialHistoryComponent materialHistoryComponent = new MaterialHistoryComponent(); |
421 | 427 | materialHistoryComponent.setComponentId(component.getId()); |
422 | 428 | materialHistoryComponent.setMaterialHistoryId(1); |
423 | | - baseMapper.createMaterialHistoryComponent(materialHistoryComponent); |
| 429 | + Integer materialHistoryComponent1 = baseMapper.createMaterialHistoryComponent(materialHistoryComponent); |
| 430 | + if(materialHistoryComponent1 != 1) { |
| 431 | + throw new IllegalStateException("createMaterialHistoryComponent failed: " + materialHistoryComponent1); |
| 432 | + } |
424 | 433 | addNum = addNum + 1; |
425 | 434 | } else { |
426 | 435 | // 更新记录 |
|
0 commit comments