AdmModelKeyServiceImpl.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package com.persagy.proxy.adm.service.impl;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.fasterxml.jackson.core.JsonProcessingException;
  5. import com.fasterxml.jackson.databind.ObjectMapper;
  6. import com.fasterxml.jackson.databind.node.JsonNodeFactory;
  7. import com.fasterxml.jackson.databind.node.ObjectNode;
  8. import com.persagy.dmp.basic.model.QueryCriteria;
  9. import com.persagy.proxy.adm.request.AdmQueryCriteria;
  10. import com.persagy.proxy.adm.service.IAdmModelKeyService;
  11. import com.persagy.proxy.adm.utils.AdmQueryCriteriaHelper;
  12. import com.persagy.proxy.common.client.DmpRwdClient;
  13. import com.persagy.proxy.common.entity.DmpResult;
  14. import com.persagy.proxy.common.entity.InstanceUrlParam;
  15. import lombok.extern.slf4j.Slf4j;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.stereotype.Service;
  18. /**
  19. * ADM 模型下载 key 服务
  20. * @author lvxy
  21. * @date 2021/8/25
  22. *
  23. *
  24. * {
  25. * "criteria":{
  26. * "objType": "equipment",
  27. * "bimId": {
  28. * "$null": false
  29. * }
  30. * "relationFrom": {
  31. * "graphCode": "MechInArch",
  32. * "relCode": "Eq2Fl",
  33. * "objTo": "#{floorId}"
  34. * }
  35. * }
  36. * }
  37. */
  38. @Slf4j
  39. @Service
  40. public class AdmModelKeyServiceImpl implements IAdmModelKeyService {
  41. @Autowired
  42. private DmpRwdClient rwdClient;
  43. @Autowired
  44. private ObjectMapper objectMapper;
  45. /**
  46. * 查询
  47. * 参见datacenter 中 ModelService 的 modelKey 方法
  48. * @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")
  49. * @param request
  50. * @return
  51. */
  52. @Override
  53. public DmpResult<JSONArray> doQuery(InstanceUrlParam context, AdmQueryCriteria request) {
  54. // 转换为数据中台查询条件
  55. QueryCriteria dmpRequest = AdmQueryCriteriaHelper.toDmpCriteria(request);
  56. dmpRequest.setSize(1L);
  57. ObjectNode criteria = dmpRequest.getCriteria();
  58. String objTo = criteria.get("floorId").textValue();
  59. DmpResult<JSONArray> result = new DmpResult<>();
  60. if(objTo == null){
  61. result.setMessage("楼层 id 不能为空");
  62. result.setResult(DmpResult.FAILURE);
  63. return result;
  64. }
  65. //拼接中台查询条件
  66. criteria.remove("floorId");
  67. criteria.put("objType", "equipment");
  68. JsonNodeFactory factory = JsonNodeFactory.instance;
  69. ObjectNode relationFrom = factory.objectNode();
  70. relationFrom.put("objTo", objTo);
  71. relationFrom.put("relCode", "Eq2Fl");
  72. relationFrom.put("graphCode", "MechInArch");
  73. criteria.putPOJO("relationFrom", relationFrom);
  74. JSONObject jsonBimId = new JSONObject();
  75. jsonBimId.put("$null", false);
  76. criteria.putPOJO("bimId",jsonBimId);
  77. dmpRequest.setCriteria(criteria);
  78. dmpRequest.setSize(1L);
  79. dmpRequest.setPage(1L);
  80. dmpRequest.setWithoutCount(true);
  81. // 转换参数
  82. JSONObject paraEquip = null;
  83. try {
  84. String paraStr = objectMapper.writeValueAsString(dmpRequest);
  85. paraEquip = JSONObject.parseObject(paraStr);
  86. } catch (JsonProcessingException e) {
  87. log.error(e.getMessage(), e);
  88. return null;
  89. }
  90. result = rwdClient.queryObject(context, paraEquip);
  91. //处理成目标对象
  92. if(result.getResult().equals(DmpResult.SUCCESS)){
  93. JSONArray jsonArray = result.getData();
  94. JSONObject object = result.getData().getJSONObject(0);
  95. JSONObject model = new JSONObject();
  96. model.put("bimIdPre", object.get("bimId"));
  97. model.put("key", object.get("modelId"));
  98. jsonArray.remove(0);
  99. jsonArray.add(0, model);
  100. result.setData(jsonArray);
  101. }
  102. return result;
  103. }
  104. }