浏览代码

解决查询信息点慢的问题

yucheng 3 年之前
父节点
当前提交
092eaee073

+ 8 - 1
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/define/dao/ObjectInfoMapper.java

@@ -1,6 +1,5 @@
 package com.persagy.dmp.rwd.define.dao;
 
-import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.toolkit.Constants;
@@ -21,37 +20,45 @@ public interface ObjectInfoMapper extends BaseMapper<ObjectInfoDefine> {
     /**
      * 按类型查询
      * @param projectIds 不允许为空
+     * @param classCodes 参数传入,能大幅提升查询效率
      * @param wrapper 不允许为空
      * @return
      */
     List<ObjectInfoDefine> queryByClassCodes(@Param("projectIds") Iterable<String> projectIds,
+                                             @Param("classCodes") Iterable<String> classCodes,
                                              @Param(Constants.WRAPPER) Wrapper<ObjectInfoDefine> wrapper);
 
     /**
      * 查询采集信息
      * @param projectIds 不允许为空
+     * @param classCodes
      * @param wrapper 不允许为空
      * @return
      */
     List<Map<String, Object>> queryCollectInfos(@Param("projectIds") Iterable<String> projectIds,
+                                                @Param("classCodes") Iterable<String> classCodes,
                                                 @Param(Constants.WRAPPER) Wrapper<ObjectInfoDefine> wrapper);
 
     /**
      * 查询采集信息
      * @param pageable
      * @param projectIds 不允许为空
+     * @param classCodes
      * @param wrapper 不允许为空
      * @return
      */
     Page<Map<String, Object>> queryCollectInfos(Page pageable, @Param("projectIds") Iterable<String> projectIds,
+                                                @Param("classCodes") Iterable<String> classCodes,
                                                 @Param(Constants.WRAPPER) Wrapper<ObjectInfoDefine> wrapper);
 
     /**
      * 查询采集信息统计
      * @param projectIds
+     * @param classCodes
      * @param wrapper
      * @return
      */
     Map<String, Long> queryCollectReport(@Param("projectIds") Iterable<String> projectIds,
+                                         @Param("classCodes") Iterable<String> classCodes,
                                          @Param(Constants.WRAPPER) Wrapper<ObjectInfoDefine> wrapper);
 }

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

@@ -4,19 +4,18 @@ 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.basic.constant.DigitalMessageConstant;
 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;
-import com.persagy.dmp.basic.constant.DigitalMessageConstant;
 import com.persagy.dmp.rwd.basic.utils.DigitalMessageHelper;
 import com.persagy.dmp.rwd.define.dao.ObjectInfoMapper;
 import com.persagy.dmp.rwd.define.service.IObjectInfoService;
@@ -203,10 +202,7 @@ public class ObjectInfoServiceImpl implements IObjectInfoService {
             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);
+        return dao.queryByClassCodes(projectIds, classCodes, wrapper);
     }
 
     @Override
@@ -231,7 +227,7 @@ public class ObjectInfoServiceImpl implements IObjectInfoService {
         }
         List<String> projectIds = CollUtil.newArrayList(CommonConstant.DEFAULT_ID, AppContext.getContext().getGroupCode(), projectId);
         wrapper = ensureCollectWrapper(wrapper, projectIds);
-        return dao.queryCollectReport(projectIds, wrapper);
+        return dao.queryCollectReport(projectIds, null, wrapper);
     }
 
     @Override
@@ -241,7 +237,7 @@ public class ObjectInfoServiceImpl implements IObjectInfoService {
         }
         List<String> projectIds = CollUtil.newArrayList(CommonConstant.DEFAULT_ID, AppContext.getContext().getGroupCode(), projectId);
         wrapper = ensureCollectWrapper(wrapper, projectIds);
-        return dao.queryCollectInfos(projectIds, wrapper);
+        return dao.queryCollectInfos(projectIds, null, wrapper);
     }
 
     @Override
@@ -251,7 +247,7 @@ public class ObjectInfoServiceImpl implements IObjectInfoService {
         }
         List<String> projectIds = CollUtil.newArrayList(CommonConstant.DEFAULT_ID, AppContext.getContext().getGroupCode(), projectId);
         wrapper = ensureCollectWrapper(wrapper, projectIds);
-        return dao.queryCollectInfos(pageable, projectIds, wrapper);
+        return dao.queryCollectInfos(pageable, projectIds, null, wrapper);
     }
 
     /**

+ 10 - 0
dmp-business/dmp-rwd/src/main/resources/mapper/DefineInfoMapper.xml

@@ -58,6 +58,11 @@
                 #{projectId}
             </foreach>
         </if>
+        <if test="classCodes!=null and classCodes.size>0">
+            <foreach collection="classCodes" item="classCode" separator="," open=" and dt_define_type.code IN (" close=")">
+                #{classCode}
+            </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)
@@ -67,6 +72,11 @@
                 #{projectId}
             </foreach>
         </if>
+        <if test="classCodes!=null and classCodes.size>0">
+            <foreach collection="classCodes" item="classCode" separator="," open=" and dt_define_type.code IN (" close=")">
+                #{classCode}
+            </foreach>
+        </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"/>)