소스 검색

解决重复信息点查询问题

yucheng 3 년 전
부모
커밋
1204fdcffe

+ 26 - 59
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/define/controller/ObjectInfoController.java

@@ -2,12 +2,10 @@ package com.persagy.dmp.rwd.define.controller;
 
 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.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.dmp.basic.model.QueryCriteria;
 import com.persagy.dmp.basic.utils.QueryCriteriaHelper;
@@ -17,7 +15,6 @@ import com.persagy.dmp.common.context.AppContext;
 import com.persagy.dmp.common.exception.BusinessException;
 import com.persagy.dmp.common.helper.SpringHelper;
 import com.persagy.dmp.common.model.response.CommonResult;
-import com.persagy.dmp.common.utils.JsonHelper;
 import com.persagy.dmp.common.utils.ResultHelper;
 import com.persagy.dmp.define.entity.ObjectInfoDefine;
 import com.persagy.dmp.define.entity.ObjectTypeDefine;
@@ -33,9 +30,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.validation.Valid;
-import java.util.ArrayList;
 import java.util.List;
-import java.util.Set;
 
 /**
  * 对象类型 Controller
@@ -48,7 +43,7 @@ import java.util.Set;
 public class ObjectInfoController {
 
     private final IObjectInfoService service;
-    private final IObjectTypeService objectTypeService;
+    private final IObjectTypeService typeService;
 
     @PostMapping("")
     public CommonResult<List<ObjectInfoDefine>> query(@RequestBody QueryCriteria criteria) {
@@ -60,61 +55,33 @@ public class ObjectInfoController {
         if (null!=objCriteria && objCriteria.size()>0){
             objCriteria.remove(CommonConstant.TYPE);
         }
-        List<ObjectTypeDefine> objectTypeDefines = queryClassCodes(criteria);
-        // 1.如果传的参数不包含classCode走公共逻辑
-        if (CollUtil.isEmpty(objectTypeDefines)){
-            QueryWrapper<ObjectInfoDefine> wrapper = new QueryWrapper<>();
-            // 添加所属项目条件
-            ConditionUtil.ensureProjectCriteria(wrapper);
-            // 转换查询条件
-            QueryCriteriaHelper.toWrapper(wrapper, criteria, ObjectInfoDefine.class);
-            Page<ObjectInfoDefine> page = QueryCriteriaHelper.toPage(criteria);
-            // 没有排序条件时,按默认条件排序
-            if(CollUtil.isEmpty(page.getOrders())) {
-                wrapper.orderByAsc("show_order");
-            }
-            if(criteria.isOnlyCount()) {
-                page = page.setTotal(service.queryCount(wrapper));
-                return ResultHelper.multi(page.getRecords(), page.getTotal());
-            }
-            /// 20210819 临时处理,优化执行计划,解决Mysql:Out of sort memory问题
-            // wrapper.select("/*+ SET_VAR(sort_buffer_size = 2M) */*");
-            page = service.queryByCondition(QueryCriteriaHelper.toPage(criteria), wrapper);
-            return ResultHelper.multi(page.getRecords(), page.getTotal());
+        String projectId = AppContext.getContext().getProjectId();
+        List<ObjectTypeDefine> typeDefineList = queryClassCodes(criteria);
+        // 处理查询条件
+        QueryWrapper<ObjectInfoDefine> wrapper = new QueryWrapper<>();
+        // 没有排序条件时,按默认条件排序
+        if(CollUtil.isEmpty(criteria.getOrders())) {
+            wrapper.orderByAsc("show_order");
         }
-        // 2.包含classCode则不进行分页并且获取数据集合
-        // 2.1 如果为基础类型、且为平台级,优先级100
-        // 2.2 如果为基础类型、且为集团级,优先级200
-        // 2.3 如果为基础类型、且为项目级,优先级300
-        // 2.4 如果为非基础类型、且为平台级,优先级400
-        // 2.5 如果为非基础类型、且为集团级,优先级500
-        // 2.6 如果为非基础类型、且为项目级,优先级600
-        criteria.getCriteria().remove(ObjectDigital.CLASS_CODE_HUM);
-        List<ObjectInfoDefine> result = new ArrayList<>();
-        for (ObjectTypeDefine objectTypeDefine : objectTypeDefines) {
-            // 获取classCode集合
-            Set<String> classCodes = CollUtil.newHashSet(objectTypeDefine.getCode());
-            if (StrUtil.isNotBlank(objectTypeDefine.getParentCode())){
-                classCodes.add(objectTypeDefine.getParentCode());
-            }
-            if (CollUtil.isEmpty(classCodes)){
-                continue;
-            }
-            QueryWrapper<ObjectInfoDefine> wrapper = new QueryWrapper<>();
-            // 添加所属项目条件
-            ConditionUtil.ensureProjectCriteria(wrapper);
-            // 转换查询条件
+        // 如果入参带classCode:不进行分页并连带查出上级类型信息点
+        if(CollUtil.isNotEmpty(typeDefineList) && StrUtil.isNotBlank(projectId)) {
+            criteria.getCriteria().remove(ObjectDigital.CLASS_CODE_HUM);
             QueryCriteriaHelper.toWrapper(wrapper, criteria, ObjectInfoDefine.class);
-            wrapper.orderByAsc("show_order");
-            wrapper.in(ObjectDigital.CLASS_CODE,classCodes);
-            List<ObjectInfoDefine> objectInfoDefines = service.queryByClassCodes(wrapper,classCodes);
-            if (CollUtil.isEmpty(objectInfoDefines)){
-                continue;
-            }
-            objectInfoDefines.forEach(objectInfoDefine -> objectInfoDefine.setClassCode(objectTypeDefine.getCode()));
-            result.addAll(objectInfoDefines);
+            List<String> classCodes = CollUtil.getFieldValues(typeDefineList, "code", String.class);
+            List<ObjectInfoDefine> vos = service.queryByClassCodes(projectId, classCodes, wrapper);
+            return ResultHelper.multi(vos);
+        }
+        // 普通查询
+        ConditionUtil.ensureProjectCriteria(wrapper);
+        QueryCriteriaHelper.toWrapper(wrapper, criteria, ObjectInfoDefine.class);
+        Page<ObjectInfoDefine> page = QueryCriteriaHelper.toPage(criteria);
+        // 只计数
+        if(criteria.isOnlyCount()) {
+            page = page.setTotal(service.queryCount(wrapper));
+        } else {
+            page = service.queryByCondition(QueryCriteriaHelper.toPage(criteria), wrapper);
         }
-        return ResultHelper.multi(result, result.size());
+        return ResultHelper.multi(page.getRecords(), page.getTotal());
     }
 
     @PostMapping("/create")
@@ -196,7 +163,7 @@ public class ObjectInfoController {
         ConditionUtil.ensureProjectCriteria(wrapper);
         // 转换查询条件
         QueryCriteriaHelper.toWrapper(wrapper, typeCriteria, ObjectTypeDefine.class);
-        List<ObjectTypeDefine> objectTypeDefines = objectTypeService.queryByCondition(wrapper);
+        List<ObjectTypeDefine> objectTypeDefines = typeService.queryByCondition(wrapper);
         if (CollUtil.isEmpty(objectTypeDefines)){
             return null;
         }

+ 9 - 4
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/define/dao/ObjectInfoMapper.java

@@ -1,14 +1,12 @@
 package com.persagy.dmp.rwd.define.dao;
 
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.toolkit.Constants;
 import com.persagy.dmp.define.entity.ObjectInfoDefine;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
-import java.util.Set;
 
 /**
  * 信息点 DAO
@@ -16,6 +14,13 @@ import java.util.Set;
  * @date 2021-06-25
  */
 public interface ObjectInfoMapper extends BaseMapper<ObjectInfoDefine> {
-    List<ObjectInfoDefine> queryByClassCodes(@Param(Constants.WRAPPER) Wrapper<ObjectInfoDefine> wrapper,
-                                             @Param("classCodes") Set<String> classCodes);
+
+    /**
+     * 按类型查询
+     * @param projectIds 不允许为空
+     * @param wrapper 不允许为空
+     * @return
+     */
+    List<ObjectInfoDefine> queryByClassCodes(@Param("projectIds") Iterable<String> projectIds,
+                                             @Param(Constants.WRAPPER) Wrapper<ObjectInfoDefine> wrapper);
 }

+ 40 - 25
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/define/service/IObjectInfoService.java

@@ -3,13 +3,10 @@ package com.persagy.dmp.rwd.define.service;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.persagy.dmp.basic.model.QueryCriteria;
 import com.persagy.dmp.define.entity.ObjectInfoDefine;
-import com.persagy.dmp.define.entity.ObjectTypeDefine;
 
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 /**
  * 信息点 接口
@@ -33,20 +30,6 @@ public interface IObjectInfoService {
     List<ObjectInfoDefine> queryByIds(List<String> idList);
 
     /**
-     * 通过对象类型编码查询
-     * @param typeCode
-     * @return
-     */
-    List<ObjectInfoDefine> queryByType(String typeCode);
-
-    /**
-     * 通过多对象类型编码查询
-     * @param typeCodeList
-     * @return Map<typeCode, Map<InfoCode, ObjectInfo>>
-     */
-    Map<String, Map<String, ObjectInfoDefine>> queryByTypes(List<String> typeCodeList);
-
-    /**
      * 按条件计数
      * @param queryWrapper 查询条件
      * @return 结果数量
@@ -87,14 +70,46 @@ public interface IObjectInfoService {
      * @param idList 主键
      */
     void delete(List<String> idList);
+
+    /***
+     * 根据筛选条件和对象类型编码查询信息点数据
+     * @param projectId 项目ID 必传
+     * @param classCode 对象类型编码
+     * @return
+     */
+    List<ObjectInfoDefine> queryByClassCode(String projectId, String classCode);
+
     /***
-     * Description: 根据筛选条件和对象类型编码查询信息点数据
-     * @param wrapper : 筛选条件
-     * @param classCodes : 对象类型编码集合
-     * @return : java.util.List<com.persagy.dmp.define.entity.ObjectInfoDefine>
-     * @author : lijie
-     * @date :2021/10/28 14:51
-     * Update By lijie 2021/10/28 14:51
+     * 根据筛选条件和对象类型编码查询信息点数据
+     * @param projectId 项目ID 必传
+     * @param classCodes 对象类型编码集合 为空查所有
+     * @return
+     */
+    List<ObjectInfoDefine> queryByClassCodes(String projectId, Iterable<String> classCodes);
+
+    /***
+     * 根据筛选条件和对象类型编码查询信息点数据
+     * @param projectId 项目ID 必传
+     * @param classCodes 对象类型编码集合 为空查所有
+     * @param wrapper 额外筛选条件
+     * @return
+     */
+    List<ObjectInfoDefine> queryByClassCodes(String projectId, Iterable<String> classCodes, QueryWrapper<ObjectInfoDefine> wrapper);
+
+    /**
+     * 根据筛选条件和对象类型编码查询信息点数据
+     * @param projectId 项目ID 必传
+     * @param classCodes : 对象类型编码集合 为空查所有
+     * @return Map<classCode, <infoCode, ObjectInfoDefine>>
+     */
+    Map<String, Map<String, ObjectInfoDefine>> queryInfoMapByClass(String projectId, Iterable<String> classCodes);
+
+    /**
+     * 根据筛选条件和对象类型编码查询信息点数据
+     * @param projectId 项目ID 必传
+     * @param classCodes : 对象类型编码集合 为空查所有
+     * @param wrapper : 额外筛选条件
+     * @return Map<classCode, <infoCode, ObjectInfoDefine>>
      */
-    List<ObjectInfoDefine> queryByClassCodes(QueryWrapper<ObjectInfoDefine> wrapper, Set<String> classCodes);
+    Map<String, Map<String, ObjectInfoDefine>> queryInfoMapByClass(String projectId, Iterable<String> classCodes, QueryWrapper<ObjectInfoDefine> wrapper);
 }

+ 50 - 33
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/define/service/impl/ObjectInfoServiceImpl.java

@@ -4,11 +4,15 @@ import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.map.MapUtil;
 import cn.hutool.core.text.StrFormatter;
+import cn.hutool.core.util.ArrayUtil;
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.persagy.dmp.common.constant.CommonConstant;
 import com.persagy.dmp.common.constant.ValidEnum;
+import com.persagy.dmp.common.context.AppContext;
 import com.persagy.dmp.common.exception.BusinessException;
 import com.persagy.dmp.common.model.entity.BaseEntity;
 import com.persagy.dmp.define.entity.ObjectInfoDefine;
@@ -48,28 +52,6 @@ public class ObjectInfoServiceImpl implements IObjectInfoService {
     }
 
     @Override
-    public List<ObjectInfoDefine> queryByType(String typeCode) {
-        LambdaQueryWrapper<ObjectInfoDefine> wrapper = new LambdaQueryWrapper();
-        wrapper.eq(ObjectInfoDefine::getClassCode, typeCode);
-        wrapper.eq(ObjectInfoDefine::getValid, ValidEnum.TRUE.getType());
-        wrapper.orderByAsc(ObjectInfoDefine::getShowOrder);
-        return queryByCondition(wrapper);
-    }
-
-    @Override
-    public Map<String, Map<String, ObjectInfoDefine>> queryByTypes(List<String> typeCodeList) {
-        LambdaQueryWrapper<ObjectInfoDefine> wrapper = new LambdaQueryWrapper<>();
-        wrapper.in(ObjectInfoDefine::getClassCode, typeCodeList);
-        wrapper.eq(ObjectInfoDefine::getValid, ValidEnum.TRUE.getType());
-        wrapper.orderByAsc(ObjectInfoDefine::getShowOrder);
-        List<ObjectInfoDefine> infoList = queryByCondition(wrapper);
-        if(CollUtil.isEmpty(infoList)) {
-            return null;
-        }
-        return infoList.stream().collect(Collectors.groupingBy(ObjectInfoDefine::getClassCode, Collectors.toMap(ObjectInfoDefine::getCode, p->p, (v1, v2) -> v1)));
-    }
-
-    @Override
     public List<ObjectInfoDefine> queryByCondition(Wrapper<ObjectInfoDefine> queryWrapper) {
         return dao.selectList(queryWrapper);
     }
@@ -193,17 +175,52 @@ public class ObjectInfoServiceImpl implements IObjectInfoService {
             messageSender.sendMessage(DigitalMessageConstant.OPERATE_AFTER_DELETE, null, dbVO, false);
         });
     }
-    /***
-     * Description: 根据筛选条件和对象类型编码查询信息点数据
-     * @param wrapper : 筛选条件
-     * @param classCodes : 对象类型编码集合
-     * @return : java.util.List<com.persagy.dmp.define.entity.ObjectInfoDefine>
-     * @author : lijie
-     * @date :2021/10/28 14:51
-     * Update By lijie 2021/10/28 14:51
-     */
+
+    @Override
+    public List<ObjectInfoDefine> queryByClassCode(String projectId, String classCode) {
+        if(StrUtil.isBlank(classCode)) {
+            return null;
+        }
+        return queryByClassCodes(projectId, CollUtil.newArrayList(classCode));
+    }
+
     @Override
-    public List<ObjectInfoDefine> queryByClassCodes(QueryWrapper<ObjectInfoDefine> wrapper, Set<String> classCodes) {
-        return dao.queryByClassCodes(wrapper,classCodes);
+    public List<ObjectInfoDefine> queryByClassCodes(String projectId, Iterable<String> classCodes) {
+        return queryByClassCodes(projectId, classCodes, null);
+    }
+
+    @Override
+    public List<ObjectInfoDefine> queryByClassCodes(String projectId, Iterable<String> classCodes, QueryWrapper<ObjectInfoDefine> wrapper) {
+        if(StrUtil.isBlank(projectId)) {
+            // 如果项目ID为空,不返回
+            return null;
+        }
+        if(wrapper == null) {
+            wrapper = new QueryWrapper<>();
+        }
+        // 默认查所有字段
+        if(StrUtil.isBlank(wrapper.getSqlSelect())) {
+            wrapper.select("*");
+        }
+        List<String> projectIds = CollUtil.newArrayList(CommonConstant.DEFAULT_ID, AppContext.getContext().getGroupCode(), projectId);
+        if(CollUtil.isNotEmpty(classCodes)) {
+            wrapper.lambda().in(ObjectInfoDefine::getClassCode, ArrayUtil.toArray(classCodes, String.class));
+        }
+        return dao.queryByClassCodes(projectIds, wrapper);
+    }
+
+    @Override
+    public Map<String, Map<String, ObjectInfoDefine>> queryInfoMapByClass(String projectId, Iterable<String> classCodes) {
+        return queryInfoMapByClass(projectId, classCodes, null);
+    }
+
+    @Override
+    public Map<String, Map<String, ObjectInfoDefine>> queryInfoMapByClass(String projectId, Iterable<String> classCodes, QueryWrapper<ObjectInfoDefine> wrapper) {
+        List<ObjectInfoDefine> vos = queryByClassCodes(projectId, classCodes, wrapper);
+        if(CollUtil.isEmpty(vos)) {
+            return null;
+        }
+        return vos.stream().collect(Collectors.groupingBy(ObjectInfoDefine::getClassCode,
+                Collectors.toMap(ObjectInfoDefine::getCode, p->p, (v1, v2) -> v1)));
     }
 }

+ 9 - 54
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/digital/service/impl/ObjectDigitalServiceImpl.java

@@ -12,6 +12,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.persagy.dmp.basic.constant.DigitalMessageConstant;
 import com.persagy.dmp.basic.dto.RequestData;
 import com.persagy.dmp.basic.model.CodeTableTypeEnum;
 import com.persagy.dmp.codetable.client.CodeTableDataFacade;
@@ -27,7 +28,6 @@ import com.persagy.dmp.common.utils.ResultHelper;
 import com.persagy.dmp.define.entity.ObjectInfoDefine;
 import com.persagy.dmp.digital.entity.ObjectDigital;
 import com.persagy.dmp.digital.entity.ObjectRelation;
-import com.persagy.dmp.basic.constant.DigitalMessageConstant;
 import com.persagy.dmp.rwd.basic.constant.DigitalObjectType;
 import com.persagy.dmp.rwd.basic.constant.DigitalRelCode;
 import com.persagy.dmp.rwd.basic.utils.DigitalCommonUtils;
@@ -40,7 +40,6 @@ import com.persagy.dmp.rwd.digital.service.IObjectDigitalService;
 import com.persagy.dmp.rwd.parser.service.InfoDataFactory;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang.StringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -113,7 +112,6 @@ public class ObjectDigitalServiceImpl extends ServiceImpl<ObjectDigitalMapper, O
         return voList;
     }
 
-
     @Override
     public List<ObjectDigital> update(List<ObjectDigital> voList){
         if(CollUtil.isEmpty(voList)) {
@@ -676,33 +674,17 @@ public class ObjectDigitalServiceImpl extends ServiceImpl<ObjectDigitalMapper, O
         if(CollUtil.isEmpty(voList)) {
             return;
         }
+        // 保存时,项目ID一定有,而且都是操作这个项目的数据。这是前提,若后续放开全集团保存,则应按项目分组后查询信息点
+        String projectId = AppContext.getContext().getProjectId();
         //获取该信息点当前classCode
-        List<String> typeCodeList = CollUtil.getFieldValues(voList, "classCode", String.class);
-        //查询通用类型:equipment,building,floor,space等
-        Map<String, String> objTypeMap = typeService.queryObjTypeMap();
-        addParentClassCode(typeCodeList,objTypeMap);
+        List<String> classCodes = CollUtil.getFieldValues(voList, "classCode", String.class);
         // 查询信息点定义
-        Map<String, Map<String, ObjectInfoDefine>> allInfoMap = infoService.queryByTypes(typeCodeList);
+        Map<String, Map<String, ObjectInfoDefine>> typeInfoMap = infoService.queryInfoMapByClass(projectId, classCodes);
         // 信息点校验器
         List<ObjectDigital> restList = new ArrayList<>();
         for(ObjectDigital vo:voList) {
-            // 获取信息点列表 TODO 先这样处理,后续优化信息点接口后直接删掉此段即可
-            Map<String, ObjectInfoDefine> infoMap = new HashMap<>(16);
-            //设置通用信息点
-            String objType = objTypeMap.getOrDefault(vo.getClassCode(),"");
-            if(!objType.equals(vo.getClassCode()) && MapUtil.isNotEmpty(allInfoMap)){
-                Map<String, ObjectInfoDefine> commonInfoDefineMap = allInfoMap.getOrDefault(objType,new HashMap<>(16));
-                if(MapUtil.isNotEmpty(commonInfoDefineMap)){
-                    infoMap.putAll(commonInfoDefineMap);
-                }
-            }
-            //设置自定义信息点
-            if(MapUtil.isNotEmpty(allInfoMap)){
-                Map<String, ObjectInfoDefine> infoDefineMap = allInfoMap.get(vo.getClassCode());
-                if(MapUtil.isNotEmpty(infoDefineMap)){
-                    infoMap.putAll(infoDefineMap);
-                }
-            }
+            // 获取信息点列表
+            Map<String, ObjectInfoDefine> infoMap = typeInfoMap == null ? null : typeInfoMap.get(vo.getClassCode());
             if(MapUtil.isEmpty(infoMap)) {
                 log.error(StrUtil.format("没有对象类型【{}】的信息点定义信息!", vo.getClassCode()));
                 continue;
@@ -763,29 +745,6 @@ public class ObjectDigitalServiceImpl extends ServiceImpl<ObjectDigitalMapper, O
     }
 
     /**
-     * 添加对应的通用类型
-     * @param typeCodeList
-     */
-    private void addParentClassCode(List<String> typeCodeList,Map<String, String> objTypeMap){
-        if(typeCodeList == null || typeCodeList.size()<=0){
-            return;
-        }
-        //查询classCode对应点objType
-        Set<String> parentCodes = new HashSet<>();
-        for (String classCode : typeCodeList) {
-            String objType = objTypeMap.get(classCode);
-            if(StringUtils.isEmpty(objType) || "0".equals(objType) || parentCodes.contains(objType)){
-                continue;
-            }
-            parentCodes.add(objType);
-        }
-        parentCodes.addAll(typeCodeList);
-        // 将新Set值返给List
-        typeCodeList.clear();
-        typeCodeList.addAll(parentCodes);
-    }
-
-    /**
      * 修改时填充classCode
      * @param voList
      * @param dbMap
@@ -805,7 +764,6 @@ public class ObjectDigitalServiceImpl extends ServiceImpl<ObjectDigitalMapper, O
         }
     }
 
-
     /**
      * 查询虚拟信息点
      * @param projectId
@@ -821,10 +779,7 @@ public class ObjectDigitalServiceImpl extends ServiceImpl<ObjectDigitalMapper, O
         wrapper.eq(ObjectDigital::getGroupCode,groupCode);
         wrapper.in(ObjectDigital::getId,ids);
         wrapper.eq(ObjectDigital::getValid, ValidEnum.TRUE.getType());
-        List<ObjectDigital> objectDigitals = queryByCondition(wrapper);
-        return CollUtil.fieldValueAsMap(objectDigitals, "id", "virtual_codes");
+        List<ObjectDigital> vos = queryByCondition(wrapper);
+        return CollUtil.fieldValueAsMap(vos, "id", "virtual_codes");
     }
-
-
-
 }

+ 1 - 0
dmp-business/dmp-rwd/src/main/resources/db/init/schema.sql

@@ -58,6 +58,7 @@ CREATE TABLE IF NOT EXISTS `dt_define_info` (
   `valid` tinyint DEFAULT NULL COMMENT '合法标识',
   `ts` timestamp default current_timestamp on update current_timestamp NOT NULL COMMENT '乐观锁',
   PRIMARY KEY (`id`) USING BTREE,
+  UNIQUE KEY `idx_unikey`(`project_id`, `class_code`, `code`, `valid`) USING BTREE,
   KEY `idx_class_1` (`class_code`,`code`) USING BTREE
 ) ENGINE=InnoDB ROW_FORMAT=DYNAMIC COMMENT='信息点定义表';
 

+ 60 - 125
dmp-business/dmp-rwd/src/main/resources/mapper/DefineInfoMapper.xml

@@ -3,132 +3,67 @@
         PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.persagy.dmp.rwd.define.dao.ObjectInfoMapper">
-
-    <resultMap id="BaseResultMap" type="com.persagy.dmp.define.entity.ObjectInfoDefine">
-            <id property="id" column="id" jdbcType="VARCHAR"/>
-            <result property="code" column="code" jdbcType="VARCHAR"/>
-            <result property="name" column="name" jdbcType="VARCHAR"/>
-            <result property="aliasCode" column="alias_code" jdbcType="VARCHAR"/>
-            <result property="aliasName" column="alias_name" jdbcType="VARCHAR"/>
-            <result property="classCode" column="class_code" jdbcType="VARCHAR"/>
-            <result property="groupCode" column="group_code" jdbcType="VARCHAR"/>
-            <result property="projectId" column="project_id" jdbcType="VARCHAR"/>
-            <result property="category" column="category" jdbcType="VARCHAR"/>
-            <result property="firstTag" column="first_tag" jdbcType="VARCHAR"/>
-            <result property="secondTag" column="second_tag" jdbcType="VARCHAR"/>
-            <result property="priority" column="priority" jdbcType="VARCHAR"/>
-            <result property="inputMode" column="input_mode" jdbcType="VARCHAR"/>
-            <result property="unit" column="unit" jdbcType="VARCHAR"/>
-            <result property="dataType" column="data_type" jdbcType="VARCHAR"/>
-            <result property="isMultiple" column="is_multiple" jdbcType="INTEGER"/>
-            <result property="isRegion" column="is_region" jdbcType="INTEGER"/>
-            <result property="formater" column="formater" jdbcType="VARCHAR"/>
-            <result property="dataSource" column="data_source" jdbcType="OTHER" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
-            <result property="remark" column="remark" jdbcType="VARCHAR"/>
-            <result property="subFlag" column="sub_flag" jdbcType="INTEGER"/>
-            <result property="weakPoint" column="weak_point" jdbcType="INTEGER"/>
-            <result property="showOrder" column="show_order" jdbcType="INTEGER"/>
-            <result property="version" column="version" jdbcType="VARCHAR"/>
-            <result property="creator" column="creator" jdbcType="VARCHAR"/>
-            <result property="creationTime" column="creation_time" jdbcType="CHAR"/>
-            <result property="modifier" column="modifier" jdbcType="VARCHAR"/>
-            <result property="modifiedTime" column="modified_time" jdbcType="CHAR"/>
-            <result property="valid" column="valid" jdbcType="TINYINT"/>
-            <result property="ts" column="ts" jdbcType="TIMESTAMP"/>
-    </resultMap>
-
-    <sql id="Base_Column_List">
-        id,`code`,`name`,
-        alias_code,alias_name,class_code,
-        group_code,project_id,category,
-        first_tag,second_tag,priority,
-        input_mode,unit,data_type,
-        is_multiple,is_region,formater,
-        data_source,remark,sub_flag,
-        weak_point,show_order,version,
-        creator,creation_time,modifier,
-        modified_time,valid,ts
+    <!-- 类型如果重复则会出现多条,因此这里先用distinct容错.将基础类型的信息点与非基础信息点一起返回,且class_code改为对应的非基础对象类型 -->
+    <sql id="SelectColumns">
+        select distinct
+          dt_define_info.id, dt_define_info.code, dt_define_info.name, dt_define_info.alias_code,
+          dt_define_info.alias_name, dt_define_type.code as class_code, dt_define_info.group_code,
+          dt_define_info.project_id,dt_define_info.category,dt_define_info.first_tag,
+          dt_define_info.second_tag, dt_define_info.priority,dt_define_info.input_mode,
+          dt_define_info.unit,dt_define_info.data_type,dt_define_info.is_multiple,dt_define_info.is_region,
+          dt_define_info.formater,dt_define_info.data_source,dt_define_info.remark,dt_define_info.sub_flag,
+          dt_define_info.weak_point,dt_define_info.show_order,dt_define_info.version,dt_define_info.creator,
+          dt_define_info.creation_time,dt_define_info.modifier,dt_define_info.modified_time,
+          dt_define_info.valid,dt_define_info.ts
     </sql>
-    <select id="queryByClassCodes" resultMap="BaseResultMap">
-        SELECT
-            *
-        FROM
-            (
-                SELECT DISTINCT
-                    dt_define_info.*
-                FROM
-                    dt_define_info
-                        INNER JOIN dt_define_type ON dt_define_info.class_code = dt_define_type.CODE
-                WHERE
-                <foreach collection="classCodes" item="classCode" separator="," open="class_code IN (" close=")">
-                    #{classCode}
+    <!--
+        1. 如果为基础类型、且为平台级,优先级100
+        2. 如果为基础类型、且为集团级,优先级200
+        3. 如果为基础类型、且为项目级,优先级300
+        4. 如果为非基础类型、且为平台级,优先级400
+        5. 如果为非基础类型、且为集团级,优先级500
+        6. 如果为非基础类型、且为项目级,优先级600
+    -->
+    <sql id="ShowLevelSQL">
+        (case
+        when dt_define_info.class_code in ('project','building','floor','space','system','equipment','shaft','component','virtual','tool','material')
+          and dt_define_info.project_id = '0' then 100
+        when dt_define_info.class_code in ('project','building','floor','space','system','equipment','shaft','component','virtual','tool','material')
+          and dt_define_info.project_id = dt_define_info.group_code then 200
+        when dt_define_info.class_code in ('project','building','floor','space','system','equipment','shaft','component','virtual','tool','material')
+          and dt_define_info.project_id != dt_define_info.group_code then 300
+        when dt_define_info.class_code not in ('project','building','floor','space','system','equipment','shaft','component','virtual','tool','material')
+          and dt_define_info.project_id = '0' then 400
+        when dt_define_info.class_code not in ('project','building','floor','space','system','equipment','shaft','component','virtual','tool','material')
+          and dt_define_info.project_id = dt_define_info.group_code then 500
+        when dt_define_info.class_code not in ('project','building','floor','space','system','equipment','shaft','component','virtual','tool','material')
+          and dt_define_info.project_id != dt_define_info.group_code then 600
+        else 0 end)
+    </sql>
+    <select id="queryByClassCodes" resultType="com.persagy.dmp.define.entity.ObjectInfoDefine">
+        select ${ew.sqlSelect}
+        from (
+          <include refid="SelectColumns"/>
+          from dt_define_type inner join dt_define_info on dt_define_info.class_code in (dt_define_type.code, dt_define_type.obj_type)
+            and dt_define_type.valid = 1 and dt_define_info.valid = 1
+          <if test="projectIds!=null and projectIds.size>0">
+            <foreach collection="projectIds" item="projectId" separator="," open=" and dt_define_info.project_id IN (" close=")">
+                #{projectId}
+            </foreach>
+          </if>
+          where exists(select 1 from (
+            select dt_define_type.code class_code, dt_define_info.code code, max(<include refid="ShowLevelSQL"/>) max_show_level
+            from dt_define_type inner join dt_define_info on dt_define_info.class_code in (dt_define_type.code, dt_define_type.obj_type)
+              and dt_define_type.valid = 1 and dt_define_info.valid = 1
+            <if test="projectIds!=null and projectIds.size>0">
+                <foreach collection="projectIds" item="projectId" separator="," open="where dt_define_info.project_id IN (" close=")">
+                    #{projectId}
                 </foreach>
-                  AND EXISTS (
-                        SELECT
-                            1
-                        FROM
-                            (
-                                SELECT
-                                    dt_define_info.CODE,
-                                    max(
-                                            CASE
-                                                WHEN dt_define_info.class_code = dt_define_type.obj_type
-                                                    AND dt_define_info.project_id = '0' THEN
-                                                    100
-                                                WHEN dt_define_info.class_code = dt_define_type.obj_type
-                                                    AND dt_define_info.project_id = dt_define_info.group_code THEN
-                                                    200
-                                                WHEN dt_define_info.class_code = dt_define_type.obj_type
-                                                    AND dt_define_info.project_id != dt_define_info.group_code THEN
-                                                    300
-                                                WHEN dt_define_info.class_code != dt_define_type.obj_type
-                                                    AND dt_define_info.project_id = '0' THEN
-                                                    400
-                                                WHEN dt_define_info.class_code != dt_define_type.obj_type
-                                                    AND dt_define_info.project_id = dt_define_info.group_code THEN
-                                                    500
-                                                WHEN dt_define_info.class_code != dt_define_type.obj_type
-                                                    AND dt_define_info.project_id != dt_define_info.group_code THEN
-                                                    600 ELSE 0
-                                                END
-                                        ) show_level
-                                FROM
-                                    dt_define_info
-                                        INNER JOIN dt_define_type ON dt_define_info.class_code = dt_define_type.CODE
-                                WHERE
-                                    <foreach collection="classCodes" item="classCode" separator="," open="class_code IN (" close=")">
-                                        #{classCode}
-                                    </foreach>
-                                GROUP BY
-                                    dt_define_info.CODE
-                            ) T
-                        WHERE
-                            T.CODE = dt_define_info.CODE
-                          AND (
-                                  CASE
-                                      WHEN dt_define_info.class_code = dt_define_type.obj_type
-                                          AND dt_define_info.project_id = '0' THEN
-                                          100
-                                      WHEN dt_define_info.class_code = dt_define_type.obj_type
-                                          AND dt_define_info.project_id = dt_define_info.group_code THEN
-                                          200
-                                      WHEN dt_define_info.class_code = dt_define_type.obj_type
-                                          AND dt_define_info.project_id != dt_define_info.group_code THEN
-                                          300
-                                      WHEN dt_define_info.class_code != dt_define_type.obj_type
-                                          AND dt_define_info.project_id = '0' THEN
-                                          400
-                                      WHEN dt_define_info.class_code != dt_define_type.obj_type
-                                          AND dt_define_info.project_id = dt_define_info.group_code THEN
-                                          500
-                                      WHEN dt_define_info.class_code != dt_define_type.obj_type
-                                          AND dt_define_info.project_id != dt_define_info.group_code THEN
-                                          600 ELSE 0
-                                      END
-                                  ) = T.show_level
-                    )
-            ) dt_define_info WHERE ${ew.expression.sqlSegment};
+            </if>
+            group by dt_define_type.code, dt_define_info.code
+            ) T
+            where T.class_code = dt_define_type.code and T.code = dt_define_info.code and T.max_show_level = <include refid="ShowLevelSQL"/>)
+        ) dt_define_info
+        WHERE ${ew.expression.sqlSegment}
     </select>
-
-
 </mapper>