From e9f609413bf903fda1c77b6b5902c4ddb951c5b9 Mon Sep 17 00:00:00 2001 From: lihongjie0209 Date: Sun, 16 Mar 2025 22:23:07 +0800 Subject: [PATCH] =?UTF-8?q?refactor(coal):=20=E6=9B=B4=E6=96=B0=E4=BA=A7?= =?UTF-8?q?=E5=93=81=E5=90=8D=E7=A7=B0=E5=90=8C=E6=AD=A5=E5=88=B0=E6=B4=97?= =?UTF-8?q?=E7=85=A4=E6=97=A5=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 CoalWashingDailyAnalysisRepository 中添加 updateNameByProductId 方法 - 在 CoalWashingDailyAnalysisService 中实现 updateName 方法 - 在 ProductService 中,创建产品后调用 updateName 方法同步产品名称到洗煤日报 --- .../repository/CoalWashingDailyAnalysisRepository.java | 8 +++++++- .../service/CoalWashingDailyAnalysisService.java | 6 ++++++ .../cn/lihongjie/coal/product/service/ProductService.java | 6 ++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/cn/lihongjie/coal/coalWashingDailyAnalysis/repository/CoalWashingDailyAnalysisRepository.java b/src/main/java/cn/lihongjie/coal/coalWashingDailyAnalysis/repository/CoalWashingDailyAnalysisRepository.java index 9d8d06bc..517b05f5 100644 --- a/src/main/java/cn/lihongjie/coal/coalWashingDailyAnalysis/repository/CoalWashingDailyAnalysisRepository.java +++ b/src/main/java/cn/lihongjie/coal/coalWashingDailyAnalysis/repository/CoalWashingDailyAnalysisRepository.java @@ -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 {} + extends BaseRepository { + @Query("update CoalWashingDailyAnalysisEntity c set c.name = :name where c.product.id = :productId") + @Modifying + void updateNameByProductId(String name, String productId); +} diff --git a/src/main/java/cn/lihongjie/coal/coalWashingDailyAnalysis/service/CoalWashingDailyAnalysisService.java b/src/main/java/cn/lihongjie/coal/coalWashingDailyAnalysis/service/CoalWashingDailyAnalysisService.java index 94fe109c..e60d4d1e 100644 --- a/src/main/java/cn/lihongjie/coal/coalWashingDailyAnalysis/service/CoalWashingDailyAnalysisService.java +++ b/src/main/java/cn/lihongjie/coal/coalWashingDailyAnalysis/service/CoalWashingDailyAnalysisService.java @@ -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()); + } } diff --git a/src/main/java/cn/lihongjie/coal/product/service/ProductService.java b/src/main/java/cn/lihongjie/coal/product/service/ProductService.java index 2627b753..7596c38f 100644 --- a/src/main/java/cn/lihongjie/coal/product/service/ProductService.java +++ b/src/main/java/cn/lihongjie/coal/product/service/ProductService.java @@ -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