bimface 模型集成-后端(java)上传、发起转换、获取转换状态

2024-05-17 16:18

本文主要是介绍bimface 模型集成-后端(java)上传、发起转换、获取转换状态,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录

  • 前言
  • 后端架构
  • 流程
    • 存储表结构
    • 全局工具类
    • 先根据appid, appsecret 生成accesstoken, 保存到自己的存储服务器。
    • 利用保存的 accesstoken 上传模型
    • 发起转换
    • 获取转换状态
    • 根据bimface文件ID获取模型viewtoken, 获取到viewtoken就可以利用前端浏览模型或图纸了

前言

之前没有注意官方有个sdk,然后自己就实现了这么个逻辑。建议直接用官方的sdk来嵌入自己的项目。

后端架构

springboot(jeecgboot) + mybatisplus

流程

存储表结构

  • sys_beamface_accesstoken 存储accesstoken. (上传、发起转换、获取转换状态\获取viewtoken 时需要用到accesstoken,)
  • sys_beamface_model_viewtoken 存储viewtoken(流程模型或图纸需要用到)
  • dt_doc中的 bim_file_id 存储模型/图纸上传到bimface后返回的bimface文件ID,
    status 0表示文件未处理,1表示文件已上传,2表示文件已发起转换,3表示文件转换成功
    在这里插入图片描述
    在这里插入图片描述

全局工具类

package org.jeecg.business.util;import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Date;
import java.util.Map;
import java.util.Map.Entry;import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.ContentBody;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;/*** HTTP工具类 单例模式**/
public class HttpClientUtil {private static Logger log = LoggerFactory.getLogger(HttpClientUtil.class);private static PoolingHttpClientConnectionManager cm;private static String EMPTY_STR = null;private static String UTF_8 = "utf-8";private static void init() {if (cm == null) {cm = new PoolingHttpClientConnectionManager();cm.setMaxTotal(1000);// 整个连接池最大连接数cm.setDefaultMaxPerRoute(500);// 每路由最大连接数}}/*** 通过连接池获取HttpClient* * @return*/private static CloseableHttpClient getHttpClient() {init();return HttpClients.custom().setConnectionManager(cm).build();}/*** Get请求 不带参数* * @param url* @return*/public static String httpGetRequest(String url) {HttpGet httpGet = new HttpGet(url);httpGet.setConfig(setTimedOut());return getResult(httpGet);}/*** Get请求 带参数* * @param url* @param params map* @return* @throws URISyntaxException*/public static String httpGetRequest(String url, Map<String, Object> params) throws URISyntaxException {URIBuilder ub = new URIBuilder();ub.setPath(url);ArrayList<NameValuePair> pairs = covertParams2NVPS(params);ub.setParameters(pairs);HttpGet httpGet = new HttpGet(ub.build());httpGet.setConfig(setTimedOut());return getResult(httpGet);}/*** Get请求 带头域与带参数* * @param url* @param headers 页面头域* @param params  map* @return* @throws URISyntaxException*/public static String httpGetRequest(String url, Map<String, Object> headers, Map<String, Object> params)throws URISyntaxException {URIBuilder ub = new URIBuilder();ub.setPath(url);if (!ObjectUtils.isEmpty(params)) {ArrayList<NameValuePair> pairs = covertParams2NVPS(params);ub.setParameters(pairs);}HttpGet httpGet = new HttpGet(ub.build());httpGet.setConfig(setTimedOut());for (Map.Entry<String, Object> param : headers.entrySet()) {httpGet.addHeader(param.getKey(), String.valueOf(param.getValue()));}return getResult(httpGet);}/*** Post请求 不带参数* * @param url* @return*/public static String httpPostRequest(String url) {HttpPost httpPost = new HttpPost(url);httpPost.setConfig(setTimedOut());return getResult(httpPost);}/*** Post请求 带参数* * @param url* @param params map* @return* @throws UnsupportedEncodingException*/public static String httpPostRequest(String url, Map<String, Object> params) throws UnsupportedEncodingException {HttpPost httpPost = new HttpPost(url);httpPost.setConfig(setTimedOut());ArrayList<NameValuePair> pairs = covertParams2NVPS(params);httpPost.setEntity(new UrlEncodedFormEntity(pairs, UTF_8));return getResult(httpPost);}/*** Post请求 带头域与带参数* * @param url* @param headers 头域* @param params  map* @return* @throws UnsupportedEncodingException*/public static String httpPostRequest(String url, Map<String, Object> headers, Map<String, Object> params)throws UnsupportedEncodingException {HttpPost httpPost = new HttpPost(url);httpPost.setConfig(setTimedOut());for (Map.Entry<String, Object> param : headers.entrySet()) {httpPost.addHeader(param.getKey(), String.valueOf(param.getValue()));}if (!ObjectUtils.isEmpty(params)) {ArrayList<NameValuePair> pairs = covertParams2NVPS(params);httpPost.setEntity(new UrlEncodedFormEntity(pairs, UTF_8));}return getResult(httpPost);}public static String httpPutRequestByRb(String url,  Map<String, Object> headers, String josnString) throws UnsupportedEncodingException {HttpPut httpPut = new HttpPut(url);httpPut.setConfig(setTimedOut());httpPut.setHeader("Content-Type", "application/json;charset=UTF-8");httpPut.setHeader("Date", new Date() + "");httpPut.setHeader("Accept", "application/json");httpPut.setHeader("Cache-Control", "no-store");for (Map.Entry<String, Object> param : headers.entrySet()) {httpPut.addHeader(param.getKey(), String.valueOf(param.getValue()));}StringEntity s = new StringEntity(josnString);s.setContentEncoding(UTF_8);s.setContentType("application/json");// 发送json数据需要设置contentTypehttpPut.setEntity(s);return getResult(httpPut);}public static String postFileMultiPart(String url, Map<String, ContentBody> params, String fileParamName) {HttpPost httpPost = new HttpPost(url);RequestConfig defaultRequestConfig = RequestConfig.custom().setConnectTimeout(5000).setConnectionRequestTimeout(5000).setSocketTimeout(15000).build();httpPost.setConfig(defaultRequestConfig);MultipartEntityBuilder builder = MultipartEntityBuilder.create();for (Entry<String, ContentBody> entry : params.entrySet()) {if (fileParamName.equals(entry.getKey())) continue;builder.addPart(entry.getKey(), entry.getValue());}builder.addPart(fileParamName, params.get(fileParamName));HttpEntity reqEntity = builder.build();httpPost.setEntity(reqEntity);return getResult(httpPost);}/*** map 处理方法* * @param params* @return*/private static ArrayList<NameValuePair> covertParams2NVPS(Map<String, Object> params) {ArrayList<NameValuePair> pairs = new ArrayList<NameValuePair>();for (Map.Entry<String, Object> param : params.entrySet()) {pairs.add(new BasicNameValuePair(param.getKey(), String.valueOf(param.getValue())));}return pairs;}/*** POST请求 带json格式的字符串参数* * @param url* @param json json格式的字符串* @return* @throws UnsupportedEncodingException*/public static String httpPostRequest(String url, String josnString) throws UnsupportedEncodingException {HttpPost httpPost = new HttpPost(url);httpPost.setConfig(setTimedOut());StringEntity s = new StringEntity(josnString);s.setContentEncoding(UTF_8);s.setContentType("application/json");// 发送json数据需要设置contentTypehttpPost.setEntity(s);return getResult(httpPost);}/*** POST请求 带json格式的字符串参数* * @param url* @param json json格式的字符串* @return* @throws UnsupportedEncodingException*/public static String httpPostRequest4Urlencoded(String url, String urlencoded) throws UnsupportedEncodingException {HttpPost httpPost = new HttpPost(url);httpPost.setConfig(setTimedOut());StringEntity s = new StringEntity(urlencoded);s.setContentEncoding(UTF_8);s.setContentType("application/x-www-form-urlencoded");httpPost.setEntity(s);return getResult(httpPost);}/*** 使用POSt方式通过Xml发送HTTP请求* * @param url 请求的URL地址* @param Xml 请求的Xml内容* @return 请求返回的内容体* @throws UnsupportedEncodingException*/public static String httpPostXmlRequest(String url, String xmlBody) throws UnsupportedEncodingException {HttpPost httpPost = new HttpPost(url);httpPost.setConfig(setTimedOut());httpPost.addHeader("content-type", "application/xml");StringEntity s = new StringEntity(xmlBody);s.setContentEncoding(UTF_8);s.setContentType("application/xml");// 设置contentTypehttpPost.setEntity(s);return getResult(httpPost);}/*** 使用PUT方式通过Xml发送HTTP请求* * @param url 请求的URL地址* @param Xml 请求的Xml内容* @return 请求返回的内容体* @throws UnsupportedEncodingException*/public static String httpPutXmlRequest(String url, String xmlBody) throws UnsupportedEncodingException {HttpPut httpPut = new HttpPut(url);httpPut.setConfig(setTimedOut());// httpPut.setHeader("Content-Type", "application/xml");// httpPut.addHeader("content-type", "application/xml");httpPut.setHeader("Content-Type", "application/xml;charset=UTF-8");StringEntity s = new StringEntity(xmlBody, Charset.forName("UTF-8"));s.setContentEncoding(UTF_8);s.setContentType("application/xml");// 设置contentTypehttpPut.setEntity(s);return getResult(httpPut);}/*** 设置Http连接超时间 单位毫秒 setConnectTimeout:设置连接超时时间,单位毫秒* setConnectionRequestTimeout:设置从connect Manager获取Connection 超时时间,单位毫秒* setSocketTimeout:请求获取数据的超时时间,单位毫秒* * @return*/public static RequestConfig setTimedOut() {RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(50000).setConnectionRequestTimeout(20000).setSocketTimeout(50000).build();return requestConfig;}/*** 红包充值新增 POST请求 带json格式的字符串参数* * @param url* @param json json格式的字符串* @return* @throws UnsupportedEncodingException*/public static String httpPostRequestByRb(String url, String josnString) throws UnsupportedEncodingException {HttpPost httpPost = new HttpPost(url);httpPost.setConfig(setTimedOut());httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");httpPost.setHeader("Date", new Date() + "");httpPost.setHeader("Accept", "application/json");httpPost.setHeader("Cache-Control", "no-store");StringEntity s = new StringEntity(josnString);s.setContentEncoding(UTF_8);s.setContentType("application/json");// 发送json数据需要设置contentTypehttpPost.setEntity(s);return getResult(httpPost);}/*** 处理Http请求** @param request* @return* @throws Exception*/private static String getResult(HttpRequestBase request) {CloseableHttpClient httpClient = getHttpClient();CloseableHttpResponse response = null;int code = 0;// 状态码try {response = httpClient.execute(request);code = response.getStatusLine().getStatusCode();log.info("{}", response.getStatusLine());HttpEntity entity = response.getEntity();if (code != 200) {if (entity != null) {// 打印响应内容log.info("*****************response*****************");log.info("响应结果: " + EntityUtils.toString(entity));}return EMPTY_STR;}if (entity != null) {return EntityUtils.toString(entity);}} catch (Exception e) {log.error("调用接口异常: " + request, e);} finally {try {response.close();} catch (IOException e1) {log.error("response关闭异常", e1);}log.info("状态码[" + code + "]调用接口:" + request);}return EMPTY_STR;}}

先根据appid, appsecret 生成accesstoken, 保存到自己的存储服务器。

@Value("${beamface.appKey}")private String beamfaceAppKey;@Value("${beamface.appSecret}")private String beamfaceAppSecret;public static final String GET_ACCESS_TOKEN_URL = "https://api.bimface.com/oauth2/token";
// 获取token逻辑
public String getAccesstoken() {// 检查当前系统的accesstoken是否过期List<SysBeamfaceAccesstoken> accesstokens = list();if (CollectionUtils.isEmpty(accesstokens)) {SysBeamfaceAccesstoken accesstoken = new SysBeamfaceAccesstoken();Map<String, Object> result = getToken();accesstoken.setAcessToken(result.get("token").toString());try {Date date = DateUtils.parseDate(result.get("expireTime").toString(), "yyyy-MM-dd hh:mm:ss");// 保留10分钟误差long l = DateUtils.getMillis(date) - 600 * 1000;accesstoken.setExpiretimets(Long.toString(l));} catch (ParseException e) {throw new JeecgBootException(e.getMessage());}save(accesstoken);return accesstoken.getAcessToken();} else {// 判断时间是否过期SysBeamfaceAccesstoken accesstoken = accesstokens.get(0);long expireDate = DateUtils.getMillis();long old = Long.valueOf(accesstoken.getExpiretimets());// 没过期if (expireDate < old) {return accesstoken.getAcessToken();} else {Map<String, Object> result = getToken();accesstoken.setAcessToken(result.get("token").toString());try {Date date = DateUtils.parseDate(result.get("expireTime").toString(), "yyyy-MM-dd hh:mm:ss");// 保留10分钟误差long l = DateUtils.getMillis(date) - 600 * 1000;accesstoken.setExpiretimets(Long.toString(l));} catch (ParseException e) {throw new JeecgBootException(e.getMessage());}updateById(accesstoken);return accesstoken.getAcessToken();}}}// 请求accesstoken@SuppressWarnings("unchecked")public Map<String, Object> getToken() {if (StringUtils.isEmpty(beamfaceAppKey) || StringUtils.isEmpty(beamfaceAppSecret)) {logger.info("未配置beamface.appKey 或者  beamface.appSecret");return null;}// 将字符串 appKey:appSecret 拼接后(中间用冒号连接),对其进行BASE64编码, 然后在编码后的字符串前添加字符串Basic和一个空格, 即:“Basic” + “ ” + Base64Encode(appKey + “:” + appSecret)String key = this.beamfaceAppKey + ":" + this.beamfaceAppSecret;String authorization = String.format("%s %s", "Basic", Base64Utils.encodeToString(key.getBytes()));Map<String, Object> headers = new HashMap<>();headers.put("Authorization", authorization);try {String result = HttpClientUtil.httpPostRequest(GET_ACCESS_TOKEN_URL, headers, null);Map<String, Object> map = (Map<String, Object>) JSONUtils.parse(result);logger.info("{}", map);String success = (String) map.get("code");if (!"success".equals(success)) {logger.info("请求token失败");throw new JeecgBootException("请求access token失败");} else {return (Map<String, Object>) map.get("data");}} catch (UnsupportedEncodingException e) {throw new JeecgBootException(e.getMessage());}}

利用保存的 accesstoken 上传模型

思路: 利用保存的 accesstoken,构件定时任务:根据文件后缀格式,获取系统文件转台为0的模型文件流,进行上传。上传后 更新文件状态为 1,然后记录bimface文件ID。

String GET_POLICY_URL = "https://file.bimface.com/upload/policy";IDtDocService docService = SpringContextUtils.getBean(IDtDocService.class);Environment evn = SpringContextUtils.getBean(Environment.class);String uploadPath = evn.getProperty("jeecg.path.upload");// 查询状态为0的文件QueryWrapper<DtDoc> queryWrapper = new QueryWrapper<>();queryWrapper.and(i -> i.eq("status", 0).and(j -> j.like("doc_name", "%.rvt").or(s -> s.like("doc_name", "%.dwg")).or(s -> s.like("doc_name", "%.rfa")).or(s -> s.like("doc_name", "%.fbx")).or(s -> s.like("doc_name", "%.dxf")).or(s -> s.like("doc_name", "%.skp")).or(s -> s.like("doc_name", "%.ifc")).or(s -> s.like("doc_name", "%.dgn")).or(s -> s.like("doc_name", "%.obj")).or(s -> s.like("doc_name", "%.stl")).or(s -> s.like("doc_name", "%.3ds")).or(s -> s.like("doc_name", "%.dae")).or(s -> s.like("doc_name", "%.ply")).or(s -> s.like("doc_name", "%.igms"))));List<DtDoc> docList = docService.list(queryWrapper);LOGGER.info("扫描到{}个文件需要上传", docList.size());for (DtDoc dtDoc : docList) {LOGGER.info("开始处理{}", dtDoc.getDocName());String id = UUID.randomUUID().toString().replace("-", "").substring(0, 20);String token = beamfaceAccesstokenService.getAccesstoken();String docName = null;// 根据policy凭证上传文件String docUrl = dtDoc.getDocUrl();try {docName = URLEncoder.encode(dtDoc.getDocName(), "UTF-8");} catch (UnsupportedEncodingException e) {LOGGER.error("编码失败");LOGGER.error(e.getMessage(), e);continue;}if (StringUtils.isEmpty(docUrl)) {LOGGER.error("{} 文件路径不存在", docName);continue;}String filePath = uploadPath + File.separator + docUrl;File wlkxFile = new File(filePath);if (!wlkxFile.exists()) {LOGGER.error("{} 文件不存在", docName);continue;}// 获取policyMap<String, Object> headers = new HashMap<>();headers.put("Authorization", String.format("%s %s", "bearer", token));Map<String, Object> params = new HashMap<>();params.put("name", docName);params.put("sourceId", id);String policyResult = null;try {policyResult = HttpClientUtil.httpGetRequest(GET_POLICY_URL, headers, params);} catch (URISyntaxException e) {LOGGER.error("获取policy失败");LOGGER.error(e.getMessage(), e);continue;}if (policyResult == null) {LOGGER.error("{}, 获取policy失败", dtDoc.getDocName());continue;}LOGGER.info("{} {}, 获取policy成功", dtDoc.getDocName(), policyResult);Map<String, Object> policyResult2 = (Map<String, Object>) JSONUtils.parse(policyResult);if ("success".equals(policyResult2.get("code").toString())) {Map<String, Object> dataMap = (Map<String, Object>) policyResult2.get("data");String policy = dataMap.get("policy").toString();String host = dataMap.get("host").toString();String objectKey = dataMap.get("objectKey").toString();String accessId = dataMap.get("accessId").toString();String callbackBody = dataMap.get("callbackBody").toString();String signature = dataMap.get("signature").toString();Map<String,ContentBody> reqParam = new HashMap<String,ContentBody>();reqParam.put("name", new StringBody(docName, ContentType.MULTIPART_FORM_DATA));reqParam.put("key", new StringBody(objectKey, ContentType.MULTIPART_FORM_DATA));reqParam.put("policy", new StringBody(policy, ContentType.MULTIPART_FORM_DATA));reqParam.put("OSSAccessKeyId", new StringBody(accessId, ContentType.MULTIPART_FORM_DATA));reqParam.put("callback", new StringBody(callbackBody, ContentType.MULTIPART_FORM_DATA));reqParam.put("success_action_status", new StringBody("200", ContentType.MULTIPART_FORM_DATA));reqParam.put("signature", new StringBody(signature, ContentType.MULTIPART_FORM_DATA));ByteArrayOutputStream output = new ByteArrayOutputStream();try {FileUtils.copyFile(new File(filePath), output);} catch (IOException e) {LOGGER.error("读取文件失败");}reqParam.put("file", new ByteArrayBody(output.toByteArray(), docName));String uploadResult = HttpClientUtil.postFileMultiPart(host, reqParam, "file");if (uploadResult == null) {LOGGER.error("{}, upload失败", dtDoc.getDocName());continue;}Map<String, Object> uploadResult2 = (Map<String, Object>) JSONUtils.parse(uploadResult);if ("success".equals(uploadResult2.get("code").toString())) {dataMap = (Map<String, Object>) uploadResult2.get("data");LOGGER.info("{}, upload成功", dtDoc.getDocName());String bimfaceId = dataMap.get("fileId").toString();dtDoc.setBimFileId(bimfaceId);dtDoc.setStatus(1);docService.updateById(dtDoc);}} else {LOGGER.error("上传失败");continue;}}

发起转换

思路:获取文件状态为1的文件,定时获取文件转台,发起转换成功后更新为2.

String CONVERT_URL = "https://api.bimface.com/translate";// 查询状态为1的文件QueryWrapper<DtDoc> queryWrapper = new QueryWrapper<>();queryWrapper.and(i -> i.eq("status", 1).isNotNull("bim_file_id").and(j -> j.like("doc_name", "%.rvt").or(s -> s.like("doc_name", "%.dwg")).or(s -> s.like("doc_name", "%.fbx")).or(s -> s.like("doc_name", "%.rfa")).or(s -> s.like("doc_name", "%.dxf")).or(s -> s.like("doc_name", "%.skp")).or(s -> s.like("doc_name", "%.ifc")).or(s -> s.like("doc_name", "%.dgn")).or(s -> s.like("doc_name", "%.obj")).or(s -> s.like("doc_name", "%.stl")).or(s -> s.like("doc_name", "%.3ds")).or(s -> s.like("doc_name", "%.dae")).or(s -> s.like("doc_name", "%.ply")).or(s -> s.like("doc_name", "%.igms"))));List<DtDoc> docList = docService.list(queryWrapper);LOGGER.info("扫描到{}个文件需要解析", docList.size());Map<String, Object> headersMap = new HashMap<>();headersMap.put("Authorization", String.format("%s %s", "bearer", beamfaceAccesstokenService.getAccesstoken()));for (DtDoc dtDoc : docList) {LOGGER.info("开始处理{}", dtDoc.getDocName());String bimFileId = dtDoc.getBimFileId();Map<String, Object> sourceMap = new HashMap<>();sourceMap.put("fileId", bimFileId);sourceMap.put("compressed", null);sourceMap.put("rootName", null);JSONObject paramMap = new JSONObject();paramMap.put("callback", null);paramMap.put("config", null);paramMap.put("source", sourceMap);try {String converResult = HttpClientUtil.httpPutRequestByRb(CONVERT_URL, headersMap, paramMap.toJSONString());if (converResult == null) {LOGGER.error("调用转换服务失败");continue;}Map<String, Object> converResultJson = (Map<String, Object>) JSONUtils.parse(converResult);String code = converResultJson.get("code").toString();if ("success".equals(code)) {LOGGER.info("调用转换服务成功");dtDoc.setStatus(2);docService.updateById(dtDoc);continue;} else {LOGGER.error("调用转换服务失败");continue;}} catch (UnsupportedEncodingException e) {LOGGER.error("调用转换服务失败");LOGGER.error(e.getMessage(), e);continue;}}

获取转换状态

思路:定时查询文件状态为2的模型,查询bimface的转换状态,成功后转换为3

String GET_CONVERT_URL = "https://api.bimface.com/translate";IDtDocService docService = SpringContextUtils.getBean(IDtDocService.class);// 查询状态为2的文件QueryWrapper<DtDoc> queryWrapper = new QueryWrapper<>();queryWrapper.and(i -> i.eq("status", 2).isNotNull("bim_file_id").and(j -> j.like("doc_name", "%.rvt").or(s -> s.like("doc_name", "%.dwg")).or(s -> s.like("doc_name", "%.rfa")).or(s -> s.like("doc_name", "%.fbx")).or(s -> s.like("doc_name", "%.dxf")).or(s -> s.like("doc_name", "%.skp")).or(s -> s.like("doc_name", "%.ifc")).or(s -> s.like("doc_name", "%.dgn")).or(s -> s.like("doc_name", "%.obj")).or(s -> s.like("doc_name", "%.stl")).or(s -> s.like("doc_name", "%.3ds")).or(s -> s.like("doc_name", "%.dae")).or(s -> s.like("doc_name", "%.ply")).or(s -> s.like("doc_name", "%.igms"))));List<DtDoc> docList = docService.list(queryWrapper);LOGGER.info("扫描到{}个文件需要获取解析状态", docList.size());Map<String, Object> headers = new HashMap<>();headers.put("Authorization", String.format("%s %s", "bearer", beamfaceAccesstokenService.getAccesstoken()));for (DtDoc dtDoc : docList) {String bimFileId = dtDoc.getBimFileId();Map<String, Object> params = new HashMap<>();params.put("fileId", bimFileId);try {String convertResult = HttpClientUtil.httpGetRequest(GET_CONVERT_URL, headers, params);if (convertResult == null) {LOGGER.error("获取转换状态失败");continue;}Map<String, Object> converResultJson = (Map<String, Object>) JSONUtils.parse(convertResult);String code = converResultJson.get("code").toString();if ("success".equals(code)) {LOGGER.info("获取转换状态成功");Map<String, Object> dataMap = (Map<String, Object>) converResultJson.get("data");String status = dataMap.get("status").toString();if ("success".equals(status)) {LOGGER.info("模型{}的状态:成功", dtDoc.getDocName());dtDoc.setStatus(3);docService.updateById(dtDoc);continue;}} else {LOGGER.error("获取转换状态失败");continue;}} catch (URISyntaxException e) {LOGGER.error("获取转换状态失败");LOGGER.error(e.getMessage(), e);continue;}}

根据bimface文件ID获取模型viewtoken, 获取到viewtoken就可以利用前端浏览模型或图纸了

public static final String GET_VIEW_TOKEN_URL = "https://api.bimface.com/view/token";public String getViewToken(SysBeamfaceModelViewtoken beamfaceModelViewtoken) {QueryWrapper<SysBeamfaceModelViewtoken> queryWrapper = new QueryWrapper<>(beamfaceModelViewtoken);SysBeamfaceModelViewtoken sysBeamfaceModelViewtoken = getOne(queryWrapper);if (sysBeamfaceModelViewtoken == null) {sysBeamfaceModelViewtoken = new SysBeamfaceModelViewtoken();String viewToken = getToken(beamfaceModelViewtoken);sysBeamfaceModelViewtoken.setViewToken(viewToken);sysBeamfaceModelViewtoken.setCompareid(beamfaceModelViewtoken.getCompareid());sysBeamfaceModelViewtoken.setFileid(beamfaceModelViewtoken.getFileid());sysBeamfaceModelViewtoken.setIntegrateid(beamfaceModelViewtoken.getIntegrateid());// 过期时间为12个小时 保留10分钟误差long ts = DateUtils.getMillis() + 60 * 1000 * 60 * 12 - 60 * 1000 * 10;sysBeamfaceModelViewtoken.setExpiretimets(Long.toString(ts));save(sysBeamfaceModelViewtoken);} else {long ts = Long.valueOf(sysBeamfaceModelViewtoken.getExpiretimets());long currentTs = DateUtils.getMillis();if (currentTs > ts) {String viewToken = getToken(beamfaceModelViewtoken);sysBeamfaceModelViewtoken.setViewToken(viewToken);long nts = DateUtils.getMillis() + 60 * 1000 * 60 * 12 - 60 * 1000 * 10;sysBeamfaceModelViewtoken.setExpiretimets(Long.toString(nts));updateById(sysBeamfaceModelViewtoken);}}return sysBeamfaceModelViewtoken.getViewToken();}@SuppressWarnings("unchecked")public String getToken(SysBeamfaceModelViewtoken beamfaceModelViewtoken) {// "Authorization: Bearer dc671840-bacc-4dc5-a134-97c1918d664b"String accessToken = beamfaceAccesstokenService.getAccesstoken();String authorization = String.format("%s %s", "Bearer", accessToken);Map<String, Object> headers = new HashMap<>();headers.put("Authorization", authorization);Map<String, Object> params = new HashMap<>();if (!StringUtils.isEmpty(beamfaceModelViewtoken.getCompareid())) {params.put("compareId", beamfaceModelViewtoken.getCompareid());}if (!StringUtils.isEmpty(beamfaceModelViewtoken.getFileid())) {params.put("fileId", beamfaceModelViewtoken.getFileid());}if (!StringUtils.isEmpty(beamfaceModelViewtoken.getIntegrateid())) {params.put("integrateId", beamfaceModelViewtoken.getIntegrateid());}String result = null;try {result = HttpClientUtil.httpGetRequest(GET_VIEW_TOKEN_URL, headers, params);} catch (URISyntaxException e) {logger.error(e.getMessage(), e);logger.error("获取view token失败");}if (result == null) {logger.error("获取view token失败");return null;}Map<String, Object> map = (Map<String, Object>) JSONUtils.parse(result);logger.info("{}", map);String success = (String) map.get("code");if (!"success".equals(success)) {logger.info("请求token失败");throw new JeecgBootException("请求模型 view token失败");} else {return map.get("data").toString();}}

这篇关于bimface 模型集成-后端(java)上传、发起转换、获取转换状态的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/995577

相关文章

JVM 的类初始化机制

前言 当你在 Java 程序中new对象时,有没有考虑过 JVM 是如何把静态的字节码(byte code)转化为运行时对象的呢,这个问题看似简单,但清楚的同学相信也不会太多,这篇文章首先介绍 JVM 类初始化的机制,然后给出几个易出错的实例来分析,帮助大家更好理解这个知识点。 JVM 将字节码转化为运行时对象分为三个阶段,分别是:loading 、Linking、initialization

Spring Security 基于表达式的权限控制

前言 spring security 3.0已经可以使用spring el表达式来控制授权,允许在表达式中使用复杂的布尔逻辑来控制访问的权限。 常见的表达式 Spring Security可用表达式对象的基类是SecurityExpressionRoot。 表达式描述hasRole([role])用户拥有制定的角色时返回true (Spring security默认会带有ROLE_前缀),去

浅析Spring Security认证过程

类图 为了方便理解Spring Security认证流程,特意画了如下的类图,包含相关的核心认证类 概述 核心验证器 AuthenticationManager 该对象提供了认证方法的入口,接收一个Authentiaton对象作为参数; public interface AuthenticationManager {Authentication authenticate(Authenti

Spring Security--Architecture Overview

1 核心组件 这一节主要介绍一些在Spring Security中常见且核心的Java类,它们之间的依赖,构建起了整个框架。想要理解整个架构,最起码得对这些类眼熟。 1.1 SecurityContextHolder SecurityContextHolder用于存储安全上下文(security context)的信息。当前操作的用户是谁,该用户是否已经被认证,他拥有哪些角色权限…这些都被保

Spring Security基于数据库验证流程详解

Spring Security 校验流程图 相关解释说明(认真看哦) AbstractAuthenticationProcessingFilter 抽象类 /*** 调用 #requiresAuthentication(HttpServletRequest, HttpServletResponse) 决定是否需要进行验证操作。* 如果需要验证,则会调用 #attemptAuthentica

Spring Security 从入门到进阶系列教程

Spring Security 入门系列 《保护 Web 应用的安全》 《Spring-Security-入门(一):登录与退出》 《Spring-Security-入门(二):基于数据库验证》 《Spring-Security-入门(三):密码加密》 《Spring-Security-入门(四):自定义-Filter》 《Spring-Security-入门(五):在 Sprin

Java架构师知识体认识

源码分析 常用设计模式 Proxy代理模式Factory工厂模式Singleton单例模式Delegate委派模式Strategy策略模式Prototype原型模式Template模板模式 Spring5 beans 接口实例化代理Bean操作 Context Ioc容器设计原理及高级特性Aop设计原理Factorybean与Beanfactory Transaction 声明式事物

大模型研发全揭秘:客服工单数据标注的完整攻略

在人工智能(AI)领域,数据标注是模型训练过程中至关重要的一步。无论你是新手还是有经验的从业者,掌握数据标注的技术细节和常见问题的解决方案都能为你的AI项目增添不少价值。在电信运营商的客服系统中,工单数据是客户问题和解决方案的重要记录。通过对这些工单数据进行有效标注,不仅能够帮助提升客服自动化系统的智能化水平,还能优化客户服务流程,提高客户满意度。本文将详细介绍如何在电信运营商客服工单的背景下进行

Java进阶13讲__第12讲_1/2

多线程、线程池 1.  线程概念 1.1  什么是线程 1.2  线程的好处 2.   创建线程的三种方式 注意事项 2.1  继承Thread类 2.1.1 认识  2.1.2  编码实现  package cn.hdc.oop10.Thread;import org.slf4j.Logger;import org.slf4j.LoggerFactory

hdu1043(八数码问题,广搜 + hash(实现状态压缩) )

利用康拓展开将一个排列映射成一个自然数,然后就变成了普通的广搜题。 #include<iostream>#include<algorithm>#include<string>#include<stack>#include<queue>#include<map>#include<stdio.h>#include<stdlib.h>#include<ctype.h>#inclu