-
需要调用后端多个 controller,不同接口传不同的参数,如果遇到后端接口修改,会涉及到多个页面的修改,耦合度很高;
-
需要对多个按钮设置权限配置。
-
需要每个业务接口,都去写一个对接第三方接口的 push 推送方法,无形中增加很多重复的代码,耦合度也很高;
-
如果涉及到第三方服务接口改造,后端接口也需要进行更改,会修改大量代码。
-
创建对接第三方服务的微服务,暂定为 tps 服务,该服务只作为一个后端微服务,与第三方服务进行对接,并且合理封装调用参数,将公共参数提出进行封装;
-
后端其余业务系统对接这个独立的微服务,比如订单、结算、供应商系统对接这个服务,由 tps 服务统一提供对接接口,其余服务实现这个 tps 提供的 feign 接口;
-
业务系统只需要关注 service 层业务的实现,无需处理对接的业务逻辑。
//对接第三方服务接口
publicinterfaceIKingdeeManagementService{
Boolean push(KingdeePushCO.Request request);
}
@Slf4j
@Service
publicclassKingdeeManagementServiceImplimplementsIKingdeeManagementService{
@Autowired
private ApplicationContext applicationContext;
@Autowired
private KingdeeThirdSettingService kingdeeThirdSettingService;
@Override
public Boolean push(KingdeePushCO.Request request){
KingdeeBusinessPushServiceEnum kingdeePushServiceEnum = KingdeeBusinessPushServiceEnum.getKingdeePushServiceEnumByType(request.getBusinessType());
IKingdeeBusinessPushService kingdeePushService = null;
try {
kingdeePushService = (IKingdeeBusinessPushService) applicationContext.getBean(kingdeePushServiceEnum.getClazz());
} catch (BeansException e) {
log.error("当前类型暂未实现,请联系开发");
thrownew ServiceException("当前类型暂未实现,请联系开发");
}
R<Boolean> result = null;
result = kingdeePushService.pushKingdee(request);
returntrue;
}
}
public enum KingdeeBusinessPushServiceEnum {
private Class clazz;
private Integer type;
private String interFaceName;
KingdeeBusinessPushServiceEnum(Class clazz, Integer type, String interFaceName) {
this.clazz = clazz;
this.type = type;
this.interFaceName = interFaceName;
}
RECEIPT_VOUCHER(IJaKingdeeBillClient.class, KingdeeBusinessTypeConstant.RECEIPT_VOUCHER, KingdeeSettingEnum.INTERFACE_TYPE_JA_RECEIPT_VOUCHER.getCode()), ;
}
-
clazz 定义为 feign 接口,业务系统提供的服务接口; -
type 代表前端需要传的参数,不同的 Integer 值代表不同的 feign 接口映射; -
interFaceName 第三方接口枚举,表示需要具体调用哪个第三方接口。
来源:juejin.cn/post/7276261829726191676
往期推荐
微服务Token鉴权设计的几种方案
SpringBoot配置优化:Tomcat+数据库+缓存+日志全场景教程
SpringBoot+SSH客户端:在浏览器中执行远程命令
SpringBoot+Minio实现高效文件存储解决方案
项目自从用了接口请求合并,效率直接加倍!
为什么要尽量避免使用 IN 和 NOT IN 呢?

