48 lines
1.2 KiB
Java
48 lines
1.2 KiB
Java
package com.solution.rule.handler;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import com.solution.common.constant.ExceptionConstants;
|
|
import com.solution.rule.domain.RuleParam;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import javax.annotation.PostConstruct;
|
|
import javax.annotation.Resource;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 封装规则处理链
|
|
*/
|
|
@Component
|
|
public class RuleChainHandler {
|
|
|
|
@Resource
|
|
private List<AbstractRuleChainHandler> chainHandlers;
|
|
|
|
private AbstractRuleChainHandler firstHandler;
|
|
|
|
/**
|
|
* 组装处理链
|
|
*/
|
|
@PostConstruct
|
|
private void constructChain(){
|
|
if (CollUtil.isEmpty(chainHandlers)) {
|
|
throw new RuntimeException(ExceptionConstants.NOT_FOUND_CARRIAGE_CHAIN_HANDLER);
|
|
}
|
|
this.firstHandler = chainHandlers.get(0);
|
|
for (int i = 0; i < chainHandlers.size(); i++) {
|
|
if(i == (chainHandlers.size() - 1)){
|
|
chainHandlers.get(i).setNextHandler(null);
|
|
}else {
|
|
chainHandlers.get(i).setNextHandler(chainHandlers.get(i + 1));
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public RuleParam findRuleParam(RuleParam ruleParam){
|
|
return firstHandler.doHandler(ruleParam);
|
|
}
|
|
|
|
}
|