|
@@ -1,22 +1,35 @@
|
|
|
package com.persagy.dmp.rwd.digital.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
import com.persagy.dmp.basic.dto.CoordinateCalInfo;
|
|
|
import com.persagy.dmp.basic.dto.RelationCalDTO;
|
|
|
import com.persagy.dmp.basic.dto.RelationCalRuleDTO;
|
|
|
+import com.persagy.dmp.basic.dto.RequestData;
|
|
|
+import com.persagy.dmp.common.constant.CommonConstant;
|
|
|
import com.persagy.dmp.common.exception.BusinessException;
|
|
|
import com.persagy.dmp.define.entity.RelationDefine;
|
|
|
+import com.persagy.dmp.digital.entity.ObjectDigital;
|
|
|
import com.persagy.dmp.digital.entity.ObjectRelation;
|
|
|
import com.persagy.dmp.rwd.basic.constant.BusinessErrorRwdCode;
|
|
|
+import com.persagy.dmp.rwd.basic.utils.DigitalCommonUtils;
|
|
|
+import com.persagy.dmp.rwd.basic.utils.GeoToolsUtil;
|
|
|
+import com.persagy.dmp.rwd.digital.dao.ObjectDigitalMapper;
|
|
|
import com.persagy.dmp.rwd.digital.domain.CalculatingDTO;
|
|
|
import com.persagy.dmp.rwd.digital.service.CalculateService;
|
|
|
+import com.persagy.dmp.rwd.digital.service.IObjectDigitalService;
|
|
|
+import com.persagy.dmp.rwd.digital.service.IObjectRelationService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
/***
|
|
|
* Description: 根据坐标计算关系的策略类
|
|
@@ -28,6 +41,13 @@ import java.util.Map;
|
|
|
@Slf4j
|
|
|
@RequiredArgsConstructor
|
|
|
public class CoordinateCalculateServiceImpl implements CalculateService {
|
|
|
+
|
|
|
+ private static final Long MAX_HANDLE_NUM = 10000L;
|
|
|
+
|
|
|
+ private final IObjectDigitalService objectDigitalService;
|
|
|
+ private final ObjectDigitalMapper objectDigitalMapper;
|
|
|
+ private final IObjectRelationService objectRelationService;
|
|
|
+
|
|
|
/***
|
|
|
* Description: 根据坐标计算关系
|
|
|
* @param calRule : 计算规则
|
|
@@ -44,11 +64,204 @@ public class CoordinateCalculateServiceImpl implements CalculateService {
|
|
|
if (StrUtil.isBlank(relationDefine.getFromObjType()) || StrUtil.isBlank(relationDefine.getToObjType())){
|
|
|
throw new BusinessException(BusinessErrorRwdCode.A7312.getCode(),BusinessErrorRwdCode.A7312.getDesc());
|
|
|
}
|
|
|
+ // 试验过sql计算后,发现效率低下.先暂时使用java实现
|
|
|
+ String fromObjType = relationDefine.getFromObjType();
|
|
|
+ String toObjType = relationDefine.getToObjType();
|
|
|
+ // 1.先分页查询from对象,在分页处理to对象
|
|
|
+ Boolean calRelFromFileRelFlag = graphCalInfo.getCalRelFromFileRelFlag();
|
|
|
+ if (null!=calRelFromFileRelFlag && calRelFromFileRelFlag){
|
|
|
+ // 这种暂时不计算,还没想好怎么做
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 2.查询from侧的对象
|
|
|
+ if (graphCalInfo.getFromIsPointFlag()){
|
|
|
+ // 左侧为点,则对左侧点做分页操作
|
|
|
+ calculateRelationInternal(graphCalInfo,calculatingDTO,
|
|
|
+ calculatingDTO.getFromIds(),relationDefine.getFromObjType(),graphCalInfo.getFromInfoCode(),
|
|
|
+ calculatingDTO.getToIds(),relationDefine.getToObjType(),graphCalInfo.getToInfoCode());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 右侧为点
|
|
|
+ calculateRelationInternal(graphCalInfo,calculatingDTO,
|
|
|
+ calculatingDTO.getToIds(),relationDefine.getToObjType(),graphCalInfo.getToInfoCode(),
|
|
|
+ calculatingDTO.getFromIds(),relationDefine.getFromObjType(),graphCalInfo.getFromInfoCode());
|
|
|
+ }
|
|
|
+ /***
|
|
|
+ * Description: 内部的计算关系
|
|
|
+ * @param graphCalInfo : 坐标计算信息对象
|
|
|
+ * @param calculatingDTO : 请求参数
|
|
|
+ * @param fromIds : 来源id集合
|
|
|
+ * @param fromObjType : 来源对象分类
|
|
|
+ * @param fromInfoCode : 来与对象信息点
|
|
|
+ * @param toIds : 去向id集合
|
|
|
+ * @param toObjType : 去向对象分类
|
|
|
+ * @param toInfoCode : 去向对象信息点
|
|
|
+ * @return : void
|
|
|
+ * @author : lijie
|
|
|
+ * @date :2021/9/11 14:43
|
|
|
+ * Update By lijie 2021/9/11 14:43
|
|
|
+ */
|
|
|
+ private void calculateRelationInternal(CoordinateCalInfo graphCalInfo, CalculatingDTO calculatingDTO,
|
|
|
+ Set<String> fromIds, String fromObjType, String fromInfoCode,
|
|
|
+ Set<String> toIds, String toObjType, String toInfoCode) {
|
|
|
+ if (StrUtil.isBlank(fromInfoCode) || StrUtil.isBlank(toInfoCode)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 1.查询来源对象
|
|
|
+ List<ObjectDigital> fromObjectDigitals = queryFromData(fromIds,fromObjType,fromInfoCode,calculatingDTO);
|
|
|
+ if (CollUtil.isEmpty(fromObjectDigitals)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 2.查询去向对象
|
|
|
+ List<ObjectDigital> toObjectDigitals = queryToData(toIds,toObjType,toInfoCode,calculatingDTO);
|
|
|
+ if (CollUtil.isEmpty(toObjectDigitals)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 呵呵,O(n^2)
|
|
|
+ List<ObjectRelation> resultList = new ArrayList<>();
|
|
|
+ for (ObjectDigital fromObjectDigital : fromObjectDigitals) {
|
|
|
+ for (ObjectDigital toObjectDigital : toObjectDigitals) {
|
|
|
+ if (CollUtil.isEmpty(toObjectDigital.getOutLines())){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (null==fromObjectDigital.getBimLocation()){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Boolean pointInPoly = GeoToolsUtil
|
|
|
+ .isPointInPoly(fromObjectDigital.getBimLocation(), toObjectDigital.getOutLines());
|
|
|
+ if (!pointInPoly){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ ObjectRelation objectRelation = new ObjectRelation();
|
|
|
+ objectRelation.setGroupCode(fromObjectDigital.getGroupCode());
|
|
|
+ objectRelation.setProjectId(fromObjectDigital.getProjectId());
|
|
|
+ objectRelation.setGraphId(DigitalCommonUtils.getDefaultGraphIdByGraphCode(calculatingDTO.getGraphCode()));
|
|
|
+ objectRelation.setGraphCode(calculatingDTO.getGraphCode());
|
|
|
+ objectRelation.setRelCode(calculatingDTO.getRelCode());
|
|
|
+ objectRelation.setObjFrom(graphCalInfo.getFromIsPointFlag()?fromObjectDigital.getId():toObjectDigital.getId());
|
|
|
+ objectRelation.setObjTo(graphCalInfo.getFromIsPointFlag()?toObjectDigital.getId():fromObjectDigital.getId());
|
|
|
+ objectRelation.setRelValue(calculatingDTO.getRelValue());
|
|
|
+ objectRelation.setCreateApp(calculatingDTO.getAppId());
|
|
|
+ objectRelation.setUpdateApp(calculatingDTO.getAppId());
|
|
|
+ objectRelation.setCreator(calculatingDTO.getAccountId());
|
|
|
+ objectRelation.setModifier(calculatingDTO.getAccountId());
|
|
|
+ objectRelation.setValid(1);
|
|
|
+ resultList.add(objectRelation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (CollUtil.isEmpty(resultList)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 删除关系
|
|
|
+ deleteRelDataByCondition(calculatingDTO,fromIds,toIds);
|
|
|
+ // 新增关系
|
|
|
+ objectRelationService.saveBatch(resultList);
|
|
|
+ }
|
|
|
+ /***
|
|
|
+ * Description: 根据请求参数和id集合删除关系
|
|
|
+ * @param calculatingDTO : 请求参数
|
|
|
+ * @param fromIds : 来源id集合
|
|
|
+ * @param toIds : 去向id集合
|
|
|
+ * @return : void
|
|
|
+ * @author : lijie
|
|
|
+ * @date :2021/9/11 16:13
|
|
|
+ * Update By lijie 2021/9/11 16:13
|
|
|
+ */
|
|
|
+ private void deleteRelDataByCondition(CalculatingDTO calculatingDTO, Set<String> fromIds, Set<String> toIds) {
|
|
|
+ fromIds.addAll(toIds);
|
|
|
+ QueryWrapper<ObjectRelation> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq(ObjectDigital.PROP_VALID,Boolean.TRUE);
|
|
|
+ if (CollUtil.isNotEmpty(fromIds)){
|
|
|
+ queryWrapper.in(ObjectDigital.PROP_ID,fromIds);
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(calculatingDTO.getGroupCode())){
|
|
|
+ queryWrapper.eq(StrUtil.toUnderlineCase(CommonConstant.QUERY_GROUPCODE),calculatingDTO.getGroupCode());
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(calculatingDTO.getProjectId())){
|
|
|
+ queryWrapper.eq(StrUtil.toUnderlineCase(CommonConstant.QUERY_PROJECTID),calculatingDTO.getProjectId());
|
|
|
+ }
|
|
|
+ queryWrapper.eq(StrUtil.toUnderlineCase(ObjectRelation.GRAPH_CODE_HUM),calculatingDTO.getGraphCode());
|
|
|
+ queryWrapper.eq(StrUtil.toUnderlineCase(ObjectRelation.REL_CODE_HUM),calculatingDTO.getRelCode());
|
|
|
+ if (StrUtil.isNotBlank(calculatingDTO.getRelValue())){
|
|
|
+ queryWrapper.eq(StrUtil.toUnderlineCase(ObjectRelation.REL_VALUE_HUM),calculatingDTO.getRelValue());
|
|
|
+ }
|
|
|
+ objectRelationService.remove(queryWrapper);
|
|
|
+ }
|
|
|
|
|
|
+ /***
|
|
|
+ * Description: 查询去向数据
|
|
|
+ * @param toIds : 去向id集合
|
|
|
+ * @param toObjType : 去向对象类型
|
|
|
+ * @param toInfoCode : 去向对象信息点
|
|
|
+ * @param calculatingDTO : 请求参数
|
|
|
+ * @return : java.util.List<com.persagy.dmp.digital.entity.ObjectDigital>
|
|
|
+ * @author : lijie
|
|
|
+ * @date :2021/9/11 15:36
|
|
|
+ * Update By lijie 2021/9/11 15:36
|
|
|
+ */
|
|
|
+ private List<ObjectDigital> queryToData(Set<String> toIds, String toObjType, String toInfoCode, CalculatingDTO calculatingDTO) {
|
|
|
+ QueryWrapper<ObjectDigital> queryWrapper = createCommonQueryWrapper(toIds,toObjType,calculatingDTO);
|
|
|
+ queryWrapper.select(ObjectDigital.PROP_ID,
|
|
|
+ StrUtil.toUnderlineCase(CommonConstant.QUERY_GROUPCODE),
|
|
|
+ StrUtil.toUnderlineCase(CommonConstant.QUERY_PROJECTID),
|
|
|
+ StrUtil.format("JSON_UNQUOTE(JSON_EXTRACT(JSON_UNQUOTE(JSON_EXTRACT(infos,'$.{}'))," +
|
|
|
+ "IF(JSON_DEPTH(JSON_UNQUOTE(JSON_EXTRACT(infos,'$.{}')))=3,'$[*]'," +
|
|
|
+ "IF(JSON_DEPTH(JSON_UNQUOTE(JSON_EXTRACT(infos,'$.{}')))=4,'$[0][*]','$[0][0][*]')))) AS outLines",
|
|
|
+ toInfoCode,toInfoCode,toInfoCode),
|
|
|
+ ObjectDigital.CLASS_CODE,ObjectDigital.OBJ_TYPE);
|
|
|
+ return objectDigitalMapper.queryToData(toIds,toObjType,toInfoCode,calculatingDTO);
|
|
|
+ }
|
|
|
+ /***
|
|
|
+ * Description: 创建通用查询条件对象
|
|
|
+ * @param ids : 对象id数组
|
|
|
+ * @param objType : 对象分类
|
|
|
+ * @param calculatingDTO : 请求参数
|
|
|
+ * @return : com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<com.persagy.dmp.digital.entity.ObjectDigital>
|
|
|
+ * @author : lijie
|
|
|
+ * @date :2021/9/11 15:41
|
|
|
+ * Update By lijie 2021/9/11 15:41
|
|
|
+ */
|
|
|
+ private QueryWrapper<ObjectDigital> createCommonQueryWrapper(Set<String> ids, String objType, CalculatingDTO calculatingDTO) {
|
|
|
+ QueryWrapper<ObjectDigital> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq(ObjectDigital.PROP_VALID,Boolean.TRUE);
|
|
|
+ if (CollUtil.isNotEmpty(ids)){
|
|
|
+ queryWrapper.in(ObjectDigital.PROP_ID,ids);
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(calculatingDTO.getGroupCode())){
|
|
|
+ queryWrapper.eq(StrUtil.toUnderlineCase(CommonConstant.QUERY_GROUPCODE),calculatingDTO.getGroupCode());
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(calculatingDTO.getProjectId())){
|
|
|
+ queryWrapper.eq(StrUtil.toUnderlineCase(CommonConstant.QUERY_PROJECTID),calculatingDTO.getProjectId());
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(objType)){
|
|
|
+ queryWrapper.eq(ObjectDigital.OBJ_TYPE,objType);
|
|
|
+ }
|
|
|
+ return queryWrapper;
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ /***
|
|
|
+ * Description: 查询来源数据
|
|
|
+ * @param fromIds : 来源id集合
|
|
|
+ * @param fromObjType : 对象分类
|
|
|
+ * @param fromInfoCode : 来源信息点
|
|
|
+ * @param calculatingDTO : 请求参数
|
|
|
+ * @return : void
|
|
|
+ * @author : lijie
|
|
|
+ * @date :2021/9/11 15:32
|
|
|
+ * Update By lijie 2021/9/11 15:32
|
|
|
+ */
|
|
|
+ private List<ObjectDigital> queryFromData(Set<String> fromIds, String fromObjType, String fromInfoCode, CalculatingDTO calculatingDTO) {
|
|
|
+ QueryWrapper<ObjectDigital> queryWrapper = createCommonQueryWrapper(fromIds, fromObjType, calculatingDTO);
|
|
|
+ queryWrapper.select(ObjectDigital.PROP_ID,
|
|
|
+ StrUtil.toUnderlineCase(CommonConstant.QUERY_GROUPCODE),
|
|
|
+ StrUtil.toUnderlineCase(CommonConstant.QUERY_PROJECTID),
|
|
|
+ StrUtil.format("JSON_OBJECT('x',JSON_EXTRACT(JSON_UNQUOTE(CONCAT('[',SUBSTRING(" +
|
|
|
+ "JSON_EXTRACT(infos, '$.{}') FROM 2 FOR LENGTH(" +
|
|
|
+ "JSON_EXTRACT(infos, '$.{}'))-2),']')),'$[0]'),'y'," +
|
|
|
+ "JSON_EXTRACT(JSON_UNQUOTE(CONCAT('[',SUBSTRING(JSON_EXTRACT(infos, '$.{}') " +
|
|
|
+ "FROM 2 FOR LENGTH(JSON_EXTRACT(infos, '$.{}'))-2),']')), '$[1]')) AS bimLocation",
|
|
|
+ fromInfoCode,fromInfoCode,fromInfoCode,fromInfoCode),
|
|
|
+ ObjectDigital.CLASS_CODE,ObjectDigital.OBJ_TYPE);
|
|
|
+ return objectDigitalMapper.queryFromData(fromIds,fromObjType,fromInfoCode,calculatingDTO);
|
|
|
}
|
|
|
}
|