feat(CoalInfoService): update ymDetails in CoalWashingDailyAnalysisEntity with new name and code

This commit is contained in:
2025-07-12 23:08:46 +08:00
parent 3b07cae6a1
commit 89ffd60cf8
2 changed files with 24 additions and 11 deletions

View File

@@ -16,7 +16,7 @@ public interface CoalInfoRepository extends BaseRepository<CoalInfoEntity> {
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

View File

@@ -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<CoalInfoEntity, CoalInfoReposit
throw new BizException("煤源信息已存在");
}
this.repository.save(entity);
if (!Objects.equals(old, request.getInitPrice())) {
updatePrice(entity);
}
// update cn.lihongjie.coal.coalWashingDailyAnalysis.entity.CoalWashingDailyAnalysisEntity.ymDetails name and code
// update
// cn.lihongjie.coal.coalWashingDailyAnalysis.entity.CoalWashingDailyAnalysisEntity.ymDetails name and code
int i = em.createQuery(
"update CoalWashingDailyAnalysisEntity set ymDetails.name = :name, ymDetails.code = :code where ymDetails.id = :id")
.setParameter("name", entity.getName())
.setParameter("code", entity.getCode())
em.createQuery(
"select e from CoalWashingDailyAnalysisEntity e join e.ymDetails d where d.id = :id")
.setParameter("id", entity.getId())
.executeUpdate();
.getResultList()
.forEach(
e -> {
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());
}