1、功能场景
对接多个外部厂商,比如多个银行的账单获取,需要根据银行信息执行对应的实现类。
2、功能代码
(1)YAML配置来源列表
bank-source: bank_001, bank_002, bank_003
(2)外部来源枚举
public interface BankPlatformEnum {/*** 银行平台类型*/enum BankPlatformType implements BankPlatformEnum {BANK_001("bank_001", "001银行平台", "bank001Service"),BANK_002("bank_002", "002银行平台", "bank002Service"),BANK_003("bank_003", "003银行平台", "bank003Service");/*** 银行平台编码*/String code;/*** 银行平台名称*/String name;/*** 银行平台的实现类名称*/String serviceName;BankPlatformType(String code, String name, String serviceName) {this.code = code;this.name = name;this.serviceName = serviceName;}public String getCode() {return code;}public String getName() {return name;}public String getServiceName() {return serviceName;}public static BankPlatformType getByCode(String code){for (BankPlatformType value : values()) {if (value.getCode().equals(code)) {return value;}}return null;}}}
(3)统一银行业务接口
public interface IBankService {EcsServiceMsg getBillList(BankQO bankQO);}
(4)统一银行业务代理实现类
@Service
@Slf4j
public class BankServiceProxy implements IBankService {@Value("${bank-source: defaultBankSource}")private List<String> bankSourceList;/*** 归集第三方发票(可以配置多个第三方厂商,依次遍历归集动作)*/@Overridepublic Object getBillList(BankQO bankQO) {for(String sourceCode:bankSourceList){// 根据名称获得实例类型try {String serviceName = EcsSyncCollectEnum.BillSourceType.getBySourceCode(sourceCode).getServiceName();AbstractBankService bankService = SpringUtil.getBean(serviceName);bankService.getBillList(bankQO);}catch(Exception e){log.error("发生异常: {}", sourceCode, e);}}return "银行业务执行中,请于5-10分钟后确认执行结果";}
}