Browse Source

模型 接口 /model/key

lvxianyun 3 years ago
parent
commit
d7f8128288

+ 51 - 0
src/main/java/com/persagy/proxy/adm/controller/AdmModelController.java

@@ -0,0 +1,51 @@
+package com.persagy.proxy.adm.controller;
+
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.persagy.proxy.adm.constant.AdmCommonConstant;
+import com.persagy.proxy.adm.model.AdmModelKey;
+import com.persagy.proxy.adm.request.AdmQueryCriteria;
+import com.persagy.proxy.adm.request.AdmResponse;
+import com.persagy.proxy.adm.service.IAdmModelKeyService;
+import com.persagy.proxy.common.entity.DmpResult;
+import com.persagy.proxy.common.entity.InstanceUrlParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.ws.rs.QueryParam;
+
+/**
+ * 模型操作
+ * @author lvxy
+ * @date 2021/8/25
+ */
+@RestController
+@RequestMapping("/model")
+public class AdmModelController {
+
+    @Autowired
+    private IAdmModelKeyService service;
+    @Value("${middleware.group.code}")
+    private String groupCode;
+
+    /**
+     * 模型文件下载地址 key
+     */
+    @PostMapping("/key")
+    public AdmResponse count(@QueryParam("projectId") String projectId,
+                             @RequestBody AdmQueryCriteria request) throws Exception {
+
+        if(StrUtil.isBlank(projectId)) {
+            return AdmResponse.failure("项目 id 不能为空");
+        }
+        // 组装上下文条件
+        InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
+
+        DmpResult<JSONArray> result = service.doQuery(context, request);
+        return AdmResponse.fromDmp(request, result, AdmModelKey.class);
+    }
+}

+ 24 - 0
src/main/java/com/persagy/proxy/adm/model/AdmModelKey.java

@@ -0,0 +1,24 @@
+package com.persagy.proxy.adm.model;
+
+import lombok.Data;
+
+/**
+ * 模型下载 key
+ * @author lvxy
+ * @date 2021/8/25
+ */
+@Data
+public class AdmModelKey {
+    /** key */
+    private String key;
+    /** bimid 前缀 */
+    private String bimIdPre;
+    /** 返回状态 */
+    private String result;
+    /** 信息 */
+    private String message;
+    /** 文件对应的楼层 */
+    private String file_name;
+    /** 文件夹名 */
+    private String folder_name;
+}

+ 20 - 0
src/main/java/com/persagy/proxy/adm/service/IAdmModelKeyService.java

@@ -0,0 +1,20 @@
+package com.persagy.proxy.adm.service;
+
+import com.alibaba.fastjson.JSONArray;
+import com.persagy.proxy.adm.request.AdmQueryCriteria;
+import com.persagy.proxy.common.entity.DmpResult;
+import com.persagy.proxy.common.entity.InstanceUrlParam;
+
+/**
+ * ADM 模型下载 key 接口类
+ * @author lvxy
+ * @date 2021/8/25
+ */
+public interface IAdmModelKeyService {
+    /**
+     * 查询
+     * @param request
+     * @return
+     */
+    DmpResult<JSONArray> doQuery(InstanceUrlParam context, AdmQueryCriteria request);
+}

+ 110 - 0
src/main/java/com/persagy/proxy/adm/service/impl/AdmModelKeyServiceImpl.java

@@ -0,0 +1,110 @@
+package com.persagy.proxy.adm.service.impl;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.persagy.proxy.adm.request.AdmQueryCriteria;
+import com.persagy.proxy.adm.request.QueryCriteria;
+import com.persagy.proxy.adm.service.IAdmModelKeyService;
+import com.persagy.proxy.adm.utils.AdmQueryCriteriaHelper;
+import com.persagy.proxy.common.client.DmpRwdClient;
+import com.persagy.proxy.common.entity.DmpResult;
+import com.persagy.proxy.common.entity.InstanceUrlParam;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * ADM 模型下载 key 服务
+ * @author lvxy
+ * @date 2021/8/25
+ *
+ *
+ * {
+ *     "criteria":{
+ *         "objType": "equipment",
+ *   "bimId": {
+ *       "$null": false
+ *   }
+ *   "relationFrom": {
+ *       "graphCode": "MechInArch",
+ *       "relCode": "Eq2Fl",
+ *       "objTo": "#{floorId}"
+ *   }
+ *     }
+ * }
+ */
+@Slf4j
+@Service
+public class AdmModelKeyServiceImpl implements IAdmModelKeyService {
+
+    @Autowired
+    private DmpRwdClient rwdClient;
+    @Autowired
+    private ObjectMapper objectMapper;
+
+    /**
+     * 查询
+     * 参见datacenter 中 ModelService 的 modelKey 方法
+     * @Select("SELECT bim_id as bimIdPre,model_id as key FROM equipment WHERE project_id = #{projectId} AND floor_id = #{floorId} AND not bim_id ISNULL LIMIT 1")
+     * @param request
+     * @return
+     */
+    @Override
+    public DmpResult<JSONArray> doQuery(InstanceUrlParam context, AdmQueryCriteria request) {
+        // 转换为数据中台查询条件
+        QueryCriteria dmpRequest = AdmQueryCriteriaHelper.toDmpCriteria(request);
+        dmpRequest.setSize(1L);
+        ObjectNode criteria = dmpRequest.getCriteria();
+        String objTo = criteria.get("floorId").textValue();
+        DmpResult<JSONArray> result = new DmpResult<>();
+        if(objTo == null){
+            result.setMessage("楼层 id 不能为空");
+            result.setResult(DmpResult.FAILURE);
+            return result;
+        }
+
+        //拼接查询条件
+        criteria.remove("floorId");
+        criteria.put("objType", "equipment");
+        JSONObject relationFrom = new JSONObject();
+        relationFrom.put("objTo", objTo);
+        relationFrom.put("relCode", "Eq2Fl");
+        relationFrom.put("graphCode", "MechInArch");
+        criteria.put("relationFrom", relationFrom.toJSONString());
+
+        JSONObject jsonBimId = new JSONObject();
+        jsonBimId.put("$isnull", false);
+        criteria.put("bimId",jsonBimId.toJSONString());
+
+        dmpRequest.setCriteria(criteria);
+
+        // 转换参数
+        JSONObject paraEquip = null;
+        try {
+            String paraStr = objectMapper.writeValueAsString(dmpRequest);
+            paraEquip = JSONObject.parseObject(paraStr);
+        } catch (JsonProcessingException e) {
+            log.error(e.getMessage(), e);
+            return null;
+        }
+        result = rwdClient.queryObject(context, paraEquip);
+        //处理成目标对象
+        if(result.getCount() == 1){
+            JSONArray jsonArray = result.getData();
+            JSONObject object = result.getData().getJSONObject(0);
+            JSONObject model = new JSONObject();
+            model.put("bimIdPre", object.get("bimId"));
+            model.put("key", object.get("modelId"));
+            jsonArray.remove(0);
+            jsonArray.add(0, model);
+            result.setData(jsonArray);
+        }
+
+        return result;
+    }
+
+}
+