# DEMO示例

# 服务场景描述

应用IQCAD图纸解析引擎,通过调用API,可提取图纸中图框坐标,楼层,构件,图纸样式等图纸属性信息,并可对板文本内容进行知识抽取,识别实体以及实体关系。

可以通过接口调用实现以下场景

  • 对图纸中的图框进行识别并获取图框中的图名,图号等信息
  • 获取图框对应图纸的楼层,和构件分类
  • 获取图纸中的楼层表
  • 对板筋文本进行实体及实体关系抽取

接口调用流程

# 服务调用流程

# 1.服务调用前置条件

  • 创建应用,获取appkey、appsecert;

  • 获取服务调用token;

  • 开通服务,scope授权通过;

    以上步骤可参考前置准备

# 2.具体调用步骤

  • 数据准备

上传dwg数据完成文件转换

step1: 上传dwg

可参考上传dwgAPI

step2: 获取文件状态

可参考获取文件状态API

step3: 发起转换

可参考图纸转换API

step4: 获取转换状态

可参考获取转换状态API

  • 图纸特征结构化服务

调用服务进行图纸分割图签提取(SheetFrame)

调用服务提取楼层表信息(FloorTable)

step1: 图纸特征结构化服务

可参考图纸特征结构化服务API

step2: 获取图纸特征结构化状态

可参考获取图纸特征结构化状态API

step3: 获取图纸特征结构化

可参考获取图纸特征结构化数据包地址API

# 演示代码

step1:maven依赖

<dependency>
    <groupId>com.squareup.okhttp3</groupId>
    <artifactId>okhttp</artifactId>
    <version>3.10.0</version>
</dependency>
1
2
3
4
5

step2:OkHttpUtil工具类

package com.utils;

import okhttp3.*;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.Set;

public class OkHttpUtil {

    private static Logger logger = LoggerFactory
            .getLogger(OkHttpUtil.class);

    private OkHttpClient client = new OkHttpClient();

    private Request.Builder createBuilder(String url,Map<String, String> requestProperty) {
        Request.Builder builder = new Request.Builder()
                .url(url);
        if (requestProperty != null) {
            Set<String> keys = requestProperty.keySet();
            for (String key : keys) {
                builder.addHeader(key, requestProperty.get(key));
            }
        }
        return builder;
    }

    private String loadResponseStr(Request.Builder builder) {
        Request request = builder.build();
        try {
            Response response = client.newCall(request).execute();
            if (response.isSuccessful()) {
                return response.body().string();
            }
        } catch (Exception e) {
            logger.error("LoadResponseStr:", e);
        }
        return null;
    }

    private RequestBody createRequestBody(Map<String, String> params){
        FormBody.Builder formBody = new FormBody.Builder();
        if (params != null) {
            Set<String> keys = params.keySet();
            for (String key : keys) {
                formBody.add(key, params.get(key));
            }
        }
        return formBody.build();
    }

    /**
     * 采用Get方式
     *
     * @param urlStr
     * @param param
     * @param requestProperty 请求头
     * @return
     */
    public String doGet(String urlStr, String param,
                        Map<String, String> requestProperty) {
        String url = StringUtils.isBlank(param) ? urlStr : urlStr + "?"
                + param;
        return loadResponseStr(createBuilder(url,requestProperty));
    }

    /**
     * 采用Post方式,模拟form提交
     *
     * @param urlStr
     * @param params
     * @param requestProperty 请求头
     * @return
     */
    public String doPost(String urlStr, Map<String, String> params,
                         Map<String, String> requestProperty) {
        return loadResponseStr(createBuilder(urlStr,requestProperty).post(createRequestBody(params)));
    }


    /**
     * 采用Post方式,提交json
     *
     * @param urlStr
     * @param jsonBody
     * @param requestProperty 请求头
     * @return
     */
    public String doPostJson(String urlStr, String jsonBody,
                             Map<String, String> requestProperty) {
        //数据类型为json格式
        MediaType JSON = MediaType.parse("application/json; charset=utf-8");
        RequestBody body = RequestBody.create(JSON, jsonBody);
        return loadResponseStr(createBuilder(urlStr,requestProperty).post(body));
    }


    /**
     * 采用Put方式,提交json
     *
     * @param urlStr
     * @param jsonBody
     * @param requestProperty 请求头
     * @return
     */
    public String doPutJson(String urlStr, String jsonBody,
                            Map<String, String> requestProperty) {
       //数据类型为json格式
        if(StringUtils.isNotBlank(jsonBody)) {
            MediaType JSON = MediaType.parse("application/json; charset=utf-8");
            RequestBody body = RequestBody.create(JSON, jsonBody);
            return loadResponseStr(createBuilder(urlStr,requestProperty).put(body));
        } else {
            RequestBody body =RequestBody.create(null, new byte[0]);
            return loadResponseStr(createBuilder(urlStr,requestProperty).put(body));
        }
    }
} 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

step3:获取token

public void getToken() throws UnsupportedEncodingException {
    OkHttpUtil client = new OkHttpUtil();
    String appKey = "aaa"; //isv申请的appKey
    String appSecret = "aaaa"; //isv申请的appSecret
    String creds = String.format("%s:%s", appKey, appSecret);
    String credential = Base64.encode(creds.getBytes("UTF-8"));
    String urlStr = "https://account.glodon.com/oauth2/token";
    Map<String, String> params = new HashMap();
    params.put("grant_type","client_credentials");
    Map<String, String> requestProperty = new HashMap();
    requestProperty.put("Authorization","Basic "+credential);
    String res = client.doPost(urlStr,params,requestProperty);
    System.out.println(res);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

step4:上传图纸

public void upload(){
    OkHttpUtil client = new OkHttpUtil();
    String access_token = "cn-e1br0908-09dd-4039-9040-9fd583";
    String fileName = "xx.dwg";
    String fileUrl = "https://glodon-cad-drawing.oss-cn-beijing.aliyuncs.com/xx.dwg";
    String urlStr = "https://apigate.glodon.com/bimface/file/upload?name="+URLEncoder.encode(fileName,"UTF-8")+"&url="+ URLEncoder.encode(fileUrl, "UTF-8" );
    Map<String, String> requestProperty = new HashMap();
    requestProperty.put("Authorization","Bearer "+access_token);
    String res = client.doPutJson(urlStr, null, requestProperty);
    // 得到fileId
    System.out.println(res);
}
1
2
3
4
5
6
7
8
9
10
11
12

step5:查询上传图纸状态

public void uploadStatus(){
    String access_token = "cn-e1br0908-09dd-4039-9040-9fd583";
    OkHttpUtil client = new OkHttpUtil();
    // fileId是从step4结果获取的
    String urlStr = "https://apigate.glodon.com/bimface/file/files/"+fileId+"/uploadStatus";
    Map<String, String> requestProperty = new HashMap();
    requestProperty.put("Authorization","Bearer "+access_token);
    String res = client.doGet(urlStr, null,requestProperty);
    System.out.println(res);
}
1
2
3
4
5
6
7
8
9
10

step6:图纸转换

public void translate(){
    String access_token = "cn-e1br0908-09dd-4039-9040-9fd583";
    OkHttpUtil client = new OkHttpUtil();
    // fileId是从step4结果获取的
    String urlStr = "https://apigate.glodon.com/bimface/api/translate";
    Map<String, String> requestProperty = new HashMap();
    requestProperty.put("Authorization","Bearer "+access_token);
    String requestBody = "{\"source\":{\"fileId\":xxx,\"compressed\":false, \"rootName\":\"xxx.dwg\"},\"config\":{\"split\":true}}";
    String res = client.doPutJson(urlStr, requestBody, requestProperty);
    System.out.println(res);
}
1
2
3
4
5
6
7
8
9
10
11

step7:查询图纸转换状态

public void translateStatus(){
    String access_token = "cn-e1br0908-09dd-4039-9040-9fd583";
    OkHttpUtil client = new OkHttpUtil();
    // fileId是从step4结果获取的
    String urlStr = "https://apigate.glodon.com/bimface/api/translate?fileId=xxx";
    Map<String, String> requestProperty = new HashMap();
    requestProperty.put("Authorization","Bearer "+access_token);
    String res = client.doGet(urlStr, null,requestProperty);
    System.out.println(res);
}
1
2
3
4
5
6
7
8
9
10

step8:图纸结构化解析

public void extractFeatures(){
    String access_token = "cn-e1br0908-09dd-4039-9040-9fd583";
    OkHttpUtil client = new OkHttpUtil();
    // fileId是从step4结果获取的
    String urlStr = "https://apigate.glodon.com/bimface/api/files/"+fileId+"/extractFeatures";
    Map<String, String> requestProperty = new HashMap();
    requestProperty.put("Authorization","Bearer "+access_token);
    String requestBody = "{\"config\":{\"features\":[\"sheetFrame\",\"floorTable\"]}}";
    String res = client.doPutJson(urlStr, requestBody, requestProperty);
    System.out.println(res);
}
1
2
3
4
5
6
7
8
9
10
11

step9:查询图纸结构化解析状态

public void extractFeaturesStatus(){
    String access_token = "cn-e1br0908-09dd-4039-9040-9fd583";
    OkHttpUtil client = new OkHttpUtil();
    // fileId是从step4结果获取的
    String urlStr = "https://apigate.glodon.com/bimface/api/files/"+fileId+"/extractFeatures";
    Map<String, String> requestProperty = new HashMap();
    requestProperty.put("Authorization","Bearer "+access_token);
    String res = client.doGet(urlStr, null,requestProperty);
    System.out.println(res);
}
1
2
3
4
5
6
7
8
9
10

step10:获取图纸结构化解析结果

public void drawingFeatures() {
    String access_token = "cn-e1br0908-09dd-4039-9040-9fd583";
    OkHttpUtil client = new OkHttpUtil();
    // fileId是从step4结果获取的
    String urlStr = "https://apigate.glodon.com/bimface/api/data/v2/files/"+fileId+"/drawingFeatures";
    Map<String, String> requestProperty = new HashMap();
    requestProperty.put("Authorization","Bearer "+access_token);
    String res = client.doGet(urlStr, null,requestProperty);
    System.out.println(res);
}
1
2
3
4
5
6
7
8
9
10
  • 在线客服

  • 意见反馈