refactor(order): 优化重复购买检查器的延迟初始化
All checks were successful
ZhenTu-BE/pipeline/head This commit looks good

- 在DuplicatePurchaseCheckerFactory类上添加@Lazy注解实现延迟加载
- 在NoCheckDuplicateChecker类上添加@Lazy注解实现延迟加载
- 在ParentResourceDuplicateChecker类上添加@Lazy注解实现延迟加载
- 在UniqueResourceDuplicateChecker类上添加@Lazy注解实现延迟加载
- 添加org.springframework.context.annotation.Lazy导入语句
- 通过延迟初始化提升应用启动性能
This commit is contained in:
2026-01-05 18:12:25 +08:00
parent 981a4ba7bd
commit 1df6a4bc23
4 changed files with 8 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ import com.ycwl.basic.order.strategy.IDuplicatePurchaseChecker;
import com.ycwl.basic.product.capability.DuplicateCheckStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import java.util.HashMap;
@@ -18,6 +19,7 @@ import java.util.Map;
* 2. 类型安全:根据枚举类型查找策略
* 3. 失败快速:找不到策略时抛出异常
*/
@Lazy
@Slf4j
@Service
public class DuplicatePurchaseCheckerFactory {

View File

@@ -4,6 +4,7 @@ import com.ycwl.basic.order.strategy.DuplicateCheckContext;
import com.ycwl.basic.order.strategy.IDuplicatePurchaseChecker;
import com.ycwl.basic.product.capability.DuplicateCheckStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
/**
@@ -13,6 +14,7 @@ import org.springframework.stereotype.Component;
* 检查逻辑:
* 不执行任何检查,直接通过
*/
@Lazy
@Slf4j
@Component
public class NoCheckDuplicateChecker implements IDuplicatePurchaseChecker {

View File

@@ -14,6 +14,7 @@ import com.ycwl.basic.pricing.enums.ProductType;
import com.ycwl.basic.product.capability.DuplicateCheckStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import java.util.List;
@@ -29,6 +30,7 @@ import java.util.List;
*
* SQL查询: WHERE order_id = ? AND product_type = ?
*/
@Lazy
@Slf4j
@Component
public class ParentResourceDuplicateChecker implements IDuplicatePurchaseChecker {

View File

@@ -14,6 +14,7 @@ import com.ycwl.basic.pricing.enums.ProductType;
import com.ycwl.basic.product.capability.DuplicateCheckStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import java.util.List;
@@ -29,6 +30,7 @@ import java.util.List;
*
* SQL查询: WHERE order_id = ? AND product_type = ? AND product_id = ?
*/
@Lazy
@Slf4j
@Component
public class UniqueResourceDuplicateChecker implements IDuplicatePurchaseChecker {