苍穹自定义 微服务调用原创
金蝶云社区-生态
生态
25人赞赏了该文章 5076次浏览 未经作者许可,禁止转载编辑于2020年08月18日 09:41:10

1、简介

微服务调用提供帮助类kd.bos.servicehelper.DispatchServiceHelper,更多详情请查看https://dev.kingdee.com/index/docsNew/3ae654b0-213f-426f-865c-aad26542c416

image.png

调用业务领域提供的接口服务方法

DispatchServiceHelper.invokeBizService(“cloudid”,”appid”,”servicename”,methodName,paras)

参数说明:


Cloudid:云标识,

 appid:应用标识,

servicename:调用服务的类名,

methodName:方法名;

paras:参数列表


反编译查看invokeBizService方法,可以知道cloudid、appid即可唯一确定一套服务,我们需要在对应目录下建

服务工厂类ServiceFactory

image.png

执行二开的提供的服务接口方法

static <T> T invokeService(String factoryQualifiedPrefix, String appId, String serviceName, String methodName, Object... paras)

参数说明:


factoryQualifiedPrefix:Factory类限定前缀,如:服务工厂isv.ti.bo.ServiceFactory,则factoryQualifiedPrefix为: isv.ti.bo

appId: 应用Id                                      
serviceName:注册的服务名称                                            
methodName:调用服务方法                                              
paras: 方法入参     


                                             

2、创建

  1. 创建接口服务类

    image.png

  2. 实现接口服务类

    image.png

  3. 创建微服务工厂类

           业务类名规范:kd.{cloudid}.{appid}.servicehelper.ServiceFactory

image.png



package kd.ecos_test.ecos_testapp.servicehelper;

/*
 * @(#)ServiceFactory.java
 *
 * 金蝶国际软件集团有限公司版权所有
 */
/**
 * 微服务,ServiceFactory一个应用一个,目录需要时kd.云id.应用id.servicehelper
 */
import java.util.HashMap;
import java.util.Map;

import kd.bos.dataentity.TypesContainer;
import kd.bos.dataentity.resource.ResManager;

public class ServiceFactory {

 private static Map<String, String> serviceMap = new HashMap<>();

 static {
  serviceMap.put("WztTestService", "kd.bos.ecos.service.impl.WztTestServiceImpl");
 }

 public static Object getService(String serviceName) {
  String className = serviceMap.get(serviceName);
  if (className == null) {
   throw new RuntimeException(String.format(
     ResManager.loadKDString("%s对应的服务实现未找到", "ServiceFactory_0", "bos-ecos-mservice"), serviceName));
  }
  return TypesContainer.getOrRegisterSingletonInstance(className);
 }
}


二开微服务必须由服务工厂注册定义才能使用,因此必须要有服务工厂类,

服务工厂路由规则为:{isv标识|公司标识}.{云id}.{应用id}.ServiceFactory
如:
二开微服务工程:isv.ti.bo.mservice.xxxService
二开服务工厂:isv.ti.bo.ServiceFactory

二开类名规范:{isv标识|公司标识}.{云id}.{应用id}.ServiceFactory

4.  调用插件类



package kd.bos.ecos.form;

import java.util.EventObject;

import kd.bos.dataentity.utils.StringUtils;
import kd.bos.form.control.events.ItemClickEvent;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.servicehelper.DispatchServiceHelper;

public class TestService extends AbstractFormPlugin{

 @Override
 public void itemClick(ItemClickEvent evt) {
  // TODO Auto-generated method stub
//  evt.getItemKey();
  if (StringUtils.equals(evt.getItemKey(), "ecos_baritemap")) {
   String content = "TestService";
    String result = DispatchServiceHelper.invokeBizService(
    "ecos_test",
    "ecos_testapp",
    "WztTestService",
    "test",
    content);


    String resultisv = DispatchServiceHelper.invokeService(
     "kd.ecos.wzy",
     "ecos_testapp",
     "EcosDemoService",
     "test",
     content);

    System.out.println("调用结果-----"+result);
  }
 }
 @Override
 public void registerListener(EventObject e) {
  // TODO Auto-generated method stub
   this.addItemClickListeners("tbmain");
 }
}


5.  演示结果

image.png

二开调用

image.png


赞 25