refactor(coal): 更新产品名称同步到洗煤日报

- 在 CoalWashingDailyAnalysisRepository 中添加 updateNameByProductId 方法
- 在 CoalWashingDailyAnalysisService 中实现 updateName 方法
- 在 ProductService 中,创建产品后调用 updateName 方法同步产品名称到洗煤日报
This commit is contained in:
2025-03-16 22:23:07 +08:00
parent c70d5f53b8
commit e9f609413b
3 changed files with 19 additions and 1 deletions

View File

@@ -3,8 +3,14 @@ package cn.lihongjie.coal.coalWashingDailyAnalysis.repository;
import cn.lihongjie.coal.base.dao.BaseRepository;
import cn.lihongjie.coal.coalWashingDailyAnalysis.entity.CoalWashingDailyAnalysisEntity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
@Repository
public interface CoalWashingDailyAnalysisRepository
extends BaseRepository<CoalWashingDailyAnalysisEntity> {}
extends BaseRepository<CoalWashingDailyAnalysisEntity> {
@Query("update CoalWashingDailyAnalysisEntity c set c.name = :name where c.product.id = :productId")
@Modifying
void updateNameByProductId(String name, String productId);
}

View File

@@ -17,6 +17,7 @@ import cn.lihongjie.coal.common.Ctx;
import cn.lihongjie.coal.common.FreeMakerUtils;
import cn.lihongjie.coal.common.JpaUtils;
import cn.lihongjie.coal.exception.BizException;
import cn.lihongjie.coal.product.entity.ProductEntity;
import cn.lihongjie.coal.product.service.ProductService;
import cn.lihongjie.coal.sse.service.SseService;
@@ -345,4 +346,9 @@ public class CoalWashingDailyAnalysisService
return new PageImpl<>(ans, PageRequest.of(0, request.getPageSize()), count);
}
public void updateName(ProductEntity entity) {
this.repository.updateNameByProductId(entity.getName(), entity.getId());
}
}

View File

@@ -4,6 +4,7 @@ import cn.lihongjie.coal.base.dto.CommonQuery;
import cn.lihongjie.coal.base.dto.IdRequest;
import cn.lihongjie.coal.base.service.BaseService;
import cn.lihongjie.coal.coalWashingDailyAnalysis.entity.CoalWashingDailyAnalysisEntity;
import cn.lihongjie.coal.coalWashingDailyAnalysis.service.CoalWashingDailyAnalysisService;
import cn.lihongjie.coal.exception.BizException;
import cn.lihongjie.coal.product.dto.CreateProductDto;
import cn.lihongjie.coal.product.dto.ProductDto;
@@ -41,6 +42,9 @@ public class ProductService extends BaseService<ProductEntity, ProductRepository
@Autowired private ConversionService conversionService;
@Autowired
CoalWashingDailyAnalysisService coalWashingDailyAnalysisService;
public ProductDto create(CreateProductDto request) {
ProductEntity entity = mapper.toEntity(request);
@@ -54,6 +58,8 @@ public class ProductService extends BaseService<ProductEntity, ProductRepository
this.repository.save(entity);
this.coalWashingDailyAnalysisService.updateName(entity);
return getById(entity.getId());
}