参考网址:https://www.yuque.com/qinbinbin-nw5ci/kb/aqn1o8?#
@Service
public class BankCardForStrategyFactory implements ApplicationContextAware {
//创建一个map集合 ConcurrentHashMap保证线程是安全的
Map<String, StrategyBankCardRuteService> map = new ConcurrentHashMap<String, StrategyBankCardRuteService>();
/**
* 通过spring方式通过构造方法得到所有的接口实现类
* @param applicationContext
* @throws BeansException
*/
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
Map<String, StrategyBankCardRuteService> tempMap = applicationContext.getBeansOfType(StrategyBankCardRuteService.class);
tempMap.forEach((key, value) -> map.put(value.getBingBankCardKey(), value));
}
/**
* 通过规则名ruteName获取对应的实现策略
* @param key
* @return
*/
public StrategyBankCardRuteService getBankCardServiceFactory(String key) {
return map.containsKey(key) ? map.get(key): null;
}
}
package com.ruoyi.enums;
/**
* @PackageName:com.example.demo.enu
* @ClassName: FieldStrategyEnum
* @Author yms
* @Description: 枚举类
* @Date 2023/6/2 12:26
* @Version 1.0
*/
public enum FieldStrategyEnum {
ALIYUN("aliyun", "aliyun"),
CHECKBOX("checkbox", "checkbox"),
SELECT("select", "select"),
ZDYSELECT("zdyselect","zdyselect"),
TREE_SELECT("treeSelect", "treeselect"),
TTEXTAREA("textarea","textarea"),
OTHER("other", "other");
private String FieldType;
private String className;
private FieldStrategyEnum(String fieldType, String className) {
this.FieldType = fieldType;
this.className = className;
}
public String getFieldType() {
return FieldType;
}
public String getClassName() {
return className;
}
public static FieldStrategyEnum getByFieldType(String fieldType) {
for (FieldStrategyEnum fieldStrategyEnum : FieldStrategyEnum.values()) {
if (fieldStrategyEnum.getFieldType().equals(fieldType)) {
return fieldStrategyEnum;
}
}
return FieldStrategyEnum.OTHER;
}
public static boolean contains(String fieldType) {
for (FieldStrategyEnum d : FieldStrategyEnum.values()) {
if (d.getFieldType().equals(fieldType)) {
return true;
}
}
return false;
}
}
package com.ruoyi.strategy;
import com.ruoyi.vo.BankCardVo;
/**
* @PackageName:com.example.demo.factory
* @ClassName: StrategyBankCardRuteService
* @Author yms
* @Description: TODO
* @Date 2023/6/2 11:53
* @Version 1.0
*/
public interface StrategyBankCardRuteService {
/**
* @Author yms
* @Description 写一个绑卡策略服务
* @return
*/
String getBingBankCardKey();
/**
* 银行卡实名认证-银行卡实名验证-银行卡实名核验-银行卡四要素-银行卡四元素实名查询
* @return
*/
boolean bankCardAuthentication(BankCardVo bankCardVo);
}
标签:return,策略,fieldType,模式,FieldStrategyEnum,com,public,String From: https://www.cnblogs.com/ymsblog/p/17451782.html