From 89ffd60cf8c04cc0b09ea264db8308ae76e66da4 Mon Sep 17 00:00:00 2001 From: lihongjie0209 Date: Sat, 12 Jul 2025 23:08:46 +0800 Subject: [PATCH] feat(CoalInfoService): update ymDetails in CoalWashingDailyAnalysisEntity with new name and code --- .../repository/CoalInfoRepository.java | 2 +- .../coalInfo/service/CoalInfoService.java | 33 +++++++++++++------ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/main/java/cn/lihongjie/coal/coalInfo/repository/CoalInfoRepository.java b/src/main/java/cn/lihongjie/coal/coalInfo/repository/CoalInfoRepository.java index ba516f8c..e6191361 100644 --- a/src/main/java/cn/lihongjie/coal/coalInfo/repository/CoalInfoRepository.java +++ b/src/main/java/cn/lihongjie/coal/coalInfo/repository/CoalInfoRepository.java @@ -16,7 +16,7 @@ public interface CoalInfoRepository extends BaseRepository { select exists( select 1 from CoalAnalysisEntity e where e.coalInfo.id in :ids union all - select 1 from CoalWashingDailyAnalysisEntity e where e.ymDetails.id in :ids + select 1 from CoalWashingDailyAnalysisEntity e join e.ymDetails d where d.id in :ids union all select 1 from PurchaseOrderEntity p where p.coalInfo.id in :ids union all diff --git a/src/main/java/cn/lihongjie/coal/coalInfo/service/CoalInfoService.java b/src/main/java/cn/lihongjie/coal/coalInfo/service/CoalInfoService.java index 133696e9..6ec32bd5 100644 --- a/src/main/java/cn/lihongjie/coal/coalInfo/service/CoalInfoService.java +++ b/src/main/java/cn/lihongjie/coal/coalInfo/service/CoalInfoService.java @@ -11,6 +11,7 @@ import cn.lihongjie.coal.coalInfo.mapper.CoalInfoMapper; import cn.lihongjie.coal.coalInfo.repository.CoalInfoRepository; import cn.lihongjie.coal.coalPrice.entity.CoalPriceEntity; import cn.lihongjie.coal.coalPrice.service.CoalPriceService; +import cn.lihongjie.coal.coalWashingDailyAnalysis.entity.CoalWashingDailyAnalysisEntity; import cn.lihongjie.coal.exception.BizException; import jakarta.persistence.EntityManager; @@ -18,6 +19,7 @@ import jakarta.persistence.PersistenceContext; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.convert.ConversionService; import org.springframework.data.domain.Page; @@ -92,27 +94,38 @@ public class CoalInfoService extends BaseService { + CoalWashingDailyAnalysisEntity analysis = + (CoalWashingDailyAnalysisEntity) e; - log.info("更新煤洗日报分析的煤源信息,影响行数: {}", i); + if (CollectionUtils.isNotEmpty(analysis.getYmDetails())) { + analysis.getYmDetails() + .forEach( + d -> { + if (Objects.equals(d.getId(), entity.getId())) { + d.setName(entity.getName()); + d.setCode(entity.getCode()); + } + }); + em.merge(analysis); + } + }); return getById(entity.getId()); }