在《C#开发BIMFACE系列31 服务端API之模型对比2:获取模型对比状态》中介绍了根据对比ID,获取一笔记录的对比状态。由于模型对比是在BIMFACE云端进行的,通常需要5~10分钟,在等待对比的过程中还可以发起更多的模型对比,最后通过接口一次性批量获取模型对比状态 。
该功能与BIMFACE控制台中“图模对比”功能相同
请求地址:POST https://api.bimface.com/compares
说明:应用发起对比以后,可以根据筛选条件,通过该接口批量查询对比状态
参数:
其中 ModelCompareQueryRequest 类如下
1 ///2 /// 批量获取模型对比状态的请求参数类 3 /// 4 public class ModelCompareQueryRequest 5 { 6 /// 7 /// 【必填项】应用的 appKey 8 /// 9 [JsonProperty("appKey")] 10 public string AppKey { get; set; } 11 12 /// 13 /// 【非必填项】对比后返回的ID,用于获取对比状态或者结果等信息 14 /// 15 [JsonProperty("compareId", NullValueHandling = NullValueHandling.Ignore)] 16 public long? CompareId { get; set; } 17 18 /// 19 /// 【非必填项】模型对比的类型 rvt(或者igms…) 20 /// 21 [JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)] 22 public string Type { get; set; } 23 24 /// 25 /// 【非必填项】文件名称 26 /// 27 [JsonProperty("fileName", NullValueHandling = NullValueHandling.Ignore)] 28 public string FileName { get; set; } 29 30 /// 31 /// 【非必填项】模型对应的sourceId。例如:389c28de59ee62e66a7d87ec12692a76 32 /// 33 [JsonProperty("sourceId", NullValueHandling = NullValueHandling.Ignore)] 34 public string SourceId { get; set; } 35 36 /// 37 /// 【非必填项】(分页)当前页码 38 /// 39 [JsonProperty("pageNo", NullValueHandling = NullValueHandling.Ignore)] 40 public int? PageNo { get; set; } 41 42 /// 43 /// 【非必填项】(分页)每页记录数 44 /// 45 [JsonProperty("pageSize", NullValueHandling = NullValueHandling.Ignore)] 46 public int? PageSize { get; set; } 47 48 /// 49 /// 【非必填项】模型状态码。0(所有) 1(处理中) 99(成功) -1(失败) 50 /// 51 [JsonProperty("status", NullValueHandling = NullValueHandling.Ignore)] 52 public short? Status { get; set; } 53 54 /// 55 /// 【非必填项】筛选类型。例如:create_time desc 56 /// 57 [JsonProperty("sortType", NullValueHandling = NullValueHandling.Ignore)] 58 public string SortType { get; set; } 59 60 /// 61 /// 【非必填项】对比开始时间,格式:yyyy-MM-dd hh:mm:ss 62 /// 63 [JsonProperty("startDate", NullValueHandling = NullValueHandling.Ignore)] 64 public string StartDate { get; set; } 65 66 /// 67 /// 【非必填项】对比结束时间,格式:yyyy-MM-dd hh:mm:ss 68 /// 69 [JsonProperty("endDate", NullValueHandling = NullValueHandling.Ignore)] 70 public string EndDate { get; set; } 71 }
请求 path(示例):https://api.bimface.com/compares
请求 header(示例):"Authorization: Bearer dc671840-bacc-4dc5-a134-97c1918d664b"
请求 body(示例):
1 { 2 "appKey" : "appKey", 3 "compareId" : 0, 4 "endDate" : "string", 5 "fileName" : "fileName", 6 "pageNo" : 0, 7 "pageSize" : 0, 8 "sortType" : "sortType", 9 "sourceId" : "23be51b7e1eb4228bd896ac1a4640c62", 10 "startDate" : "string", 11 "status" : 0, 12 "type" : "type" 13 }
HTTP响应示例(200):
1 { 2 "code" : "success", 3 "data" : { 4 "list" : [ { 5 "compareId" : 1248756572307264, 6 "cost" : 0, 7 "createTime" : "2017-12-25 16:17:27", 8 "name" : "compare0001", 9 "offlineDatabagStatus" : "offlineDatabagStatus", 10 "priority" : 2, 11 "reason" : "reason", 12 "sourceId" : "123223223212", 13 "status" : "succcess", 14 "thumbnail" : [ "https://m.bimface.com/9b711803a43b92d871cde346b63e5019/thumbnail/96.png" ], 15 "type" : "type", 16 "workerType" : "workerType" 17 } ], 18 "page" : { 19 "htmlDisplay" : "string", 20 "nextPage" : 0, 21 "pageNo" : 0, 22 "pageSize" : 0, 23 "prePage" : 0, 24 "startIndex" : 0, 25 "totalCount" : 0, 26 "totalPages" : 0 27 } 28 }, 29 "message" : "" 30 }
返回体参数说明请参考 ModelCompareBean 类
1 public class ModelCompareBean 2 { 3 ///4 /// 对比后返回的ID,用于获取对比状态或者结果等信息 5 /// 6 [JsonProperty("compareId", NullValueHandling = NullValueHandling.Ignore)] 7 public long? CompareId { get; set; } 8 9 /// 10 /// 对比完成的消耗时间,单位是秒 11 /// 12 [JsonProperty("cost", NullValueHandling = NullValueHandling.Ignore)] 13 public int? Cost { get; set; } 14 15 /// 16 /// 对比开始时间,格式:yyyy-MM-dd hh:mm:ss 17 /// 18 [JsonProperty("createTime", NullValueHandling = NullValueHandling.Ignore)] 19 public string CreateTime { get; set; } 20 21 /// 22 /// 用户指定对比后的模型的名字 23 /// 24 [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] 25 public string Name { get; set; } 26 27 /// 28 /// 离线数据包生成状态。prepare(未生成); processing(生成中); success(生成成功); failed(生成失败) 29 /// 30 [JsonProperty("offlineDatabagStatus", NullValueHandling = NullValueHandling.Ignore)] 31 public string OfflineDatabagStatus { get; set; } 32 33 /// 34 /// 对比优先级。取值 1、2、3。数字越大,优先级越低。默认为2 35 /// 36 [JsonProperty("priority", NullValueHandling = NullValueHandling.Ignore)] 37 public int? Priority { get; set; } 38 39 /// 40 /// 若对比失败,返回失败原因 41 /// 42 [JsonProperty("reason", NullValueHandling = NullValueHandling.Ignore)] 43 public string Reason { get; set; } 44 45 /// 46 /// 第三方应用自己的ID 47 /// 48 [JsonProperty("sourceId", NullValueHandling = NullValueHandling.Ignore)] 49 public string SourceId { get; set; } 50 51 /// 52 /// 对比状态:prepare(待对比)、processing(对比中)、success(对比成功)、failed(对比失败) 53 /// 54 [JsonProperty("status", NullValueHandling = NullValueHandling.Ignore)] 55 public string Status { get; set; } 56 57 /// 58 /// 对比几个缩略图 59 /// 60 [JsonProperty("thumbnail", NullValueHandling = NullValueHandling.Ignore)] 61 public string[] Thumbnails { get; set; } 62 63 /// 64 /// 模型对比的类型 rvt(或者igms…) 65 /// 66 [JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)] 67 public string Type { get; set; } 68 69 /// 70 /// 处理对比任务的worker类型。model-compare(或者drawing-compare…) 71 /// 72 [JsonProperty("workerType", NullValueHandling = NullValueHandling.Ignore)] 73 public string WorkerType { get; set; } 74 75 /// 返回表示当前对象的字符串。 76 /// 表示当前对象的字符串。 77 public override string ToString() 78 { 79 return this.SerializeToJson(); 80 }
C#实现方法:
1 ///2 /// 批量获取模型对比状态 3 /// 4 /// 【必填】令牌 5 /// 【必填】批量获取模型对比状态的请求参数 6 /// 7 public virtual ModelCompareQueryResponse GetCompareStatusList(string accessToken, ModelCompareQueryRequest request) 8 { 9 //POST https://api.bimface.com/compares 10 string url = BimfaceConstants.API_HOST + "/compares"; 11 string data = request.SerializeToJson(); 12 BimFaceHttpHeaders headers = new BimFaceHttpHeaders(); 13 headers.AddOAuth2Header(accessToken); 14 15 try 16 { 17 ModelCompareQueryResponse response; 18 19 HttpManager httpManager = new HttpManager(headers); 20 HttpResult httpResult = httpManager.Post(url, data); 21 if (httpResult.Status == HttpResult.STATUS_SUCCESS) 22 { 23 response = httpResult.Text.DeserializeJsonToObject (); 24 } 25 else 26 { 27 response = new ModelCompareQueryResponse 28 { 29 Message = httpResult.RefText 30 }; 31 } 32 33 return response; 34 } 35 catch (Exception ex) 36 { 37 throw new Exception("[批量获取模型对比状态]发生异常!", ex); 38 } 39 }