Explorar o código

采集信息点统计相关功能

yucheng %!s(int64=3) %!d(string=hai) anos
pai
achega
b004fe0b99

+ 30 - 0
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/define/dao/ObjectInfoMapper.java

@@ -3,10 +3,12 @@ package com.persagy.dmp.rwd.define.dao;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.toolkit.Constants;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.persagy.dmp.define.entity.ObjectInfoDefine;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 信息点 DAO
@@ -23,4 +25,32 @@ public interface ObjectInfoMapper extends BaseMapper<ObjectInfoDefine> {
      */
     List<ObjectInfoDefine> queryByClassCodes(@Param("projectIds") Iterable<String> projectIds,
                                              @Param(Constants.WRAPPER) Wrapper<ObjectInfoDefine> wrapper);
+
+    /**
+     * 查询采集信息
+     * @param projectIds 不允许为空
+     * @param wrapper 不允许为空
+     * @return
+     */
+    List<Map<String, Object>> queryCollectInfos(@Param("projectIds") Iterable<String> projectIds,
+                                                @Param(Constants.WRAPPER) Wrapper<ObjectInfoDefine> wrapper);
+
+    /**
+     * 查询采集信息
+     * @param pageable
+     * @param projectIds 不允许为空
+     * @param wrapper 不允许为空
+     * @return
+     */
+    Page<Map<String, Object>> queryCollectInfos(Page pageable, @Param("projectIds") Iterable<String> projectIds,
+                                                @Param(Constants.WRAPPER) Wrapper<ObjectInfoDefine> wrapper);
+
+    /**
+     * 查询采集信息统计
+     * @param projectIds
+     * @param wrapper
+     * @return
+     */
+    Map<String, Long> queryCollectReport(@Param("projectIds") Iterable<String> projectIds,
+                                         @Param(Constants.WRAPPER) Wrapper<ObjectInfoDefine> wrapper);
 }

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

@@ -112,4 +112,29 @@ public interface IObjectInfoService {
      * @return Map<classCode, <infoCode, ObjectInfoDefine>>
      */
     Map<String, Map<String, ObjectInfoDefine>> queryInfoMapByClass(String projectId, Iterable<String> classCodes, QueryWrapper<ObjectInfoDefine> wrapper);
+
+    /**
+     * 查询对象采集信息统计
+     * @param projectId
+     * @param wrapper
+     * @return
+     */
+    Map<String, Long> queryCollectReport(String projectId, QueryWrapper<ObjectInfoDefine> wrapper);
+
+    /**
+     * 查询对象采集信息
+     * @param projectId
+     * @param wrapper
+     * @return
+     */
+    List<Map<String, Object>> queryCollectInfos(String projectId, QueryWrapper<ObjectInfoDefine> wrapper);
+
+    /**
+     * 分页查询对象采集信息
+     * @param pageable
+     * @param projectId
+     * @param wrapper
+     * @return
+     */
+    Page<Map<String, Object>> queryCollectInfos(Page pageable, String projectId, QueryWrapper<ObjectInfoDefine> wrapper);
 }

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

@@ -223,4 +223,49 @@ public class ObjectInfoServiceImpl implements IObjectInfoService {
         return vos.stream().collect(Collectors.groupingBy(ObjectInfoDefine::getClassCode,
                 Collectors.toMap(ObjectInfoDefine::getCode, p->p, (v1, v2) -> v1)));
     }
+
+    @Override
+    public Map<String, Long> queryCollectReport(String projectId, QueryWrapper<ObjectInfoDefine> wrapper) {
+        if(StrUtil.isBlank(projectId)) {
+            return null;
+        }
+        List<String> projectIds = CollUtil.newArrayList(CommonConstant.DEFAULT_ID, AppContext.getContext().getGroupCode(), projectId);
+        wrapper = ensureCollectWrapper(wrapper, projectIds);
+        return dao.queryCollectReport(projectIds, wrapper);
+    }
+
+    @Override
+    public List<Map<String, Object>> queryCollectInfos(String projectId, QueryWrapper<ObjectInfoDefine> wrapper) {
+        if(StrUtil.isBlank(projectId)) {
+            return null;
+        }
+        List<String> projectIds = CollUtil.newArrayList(CommonConstant.DEFAULT_ID, AppContext.getContext().getGroupCode(), projectId);
+        wrapper = ensureCollectWrapper(wrapper, projectIds);
+        return dao.queryCollectInfos(projectIds, wrapper);
+    }
+
+    @Override
+    public Page<Map<String, Object>> queryCollectInfos(Page pageable, String projectId, QueryWrapper<ObjectInfoDefine> wrapper) {
+        if(StrUtil.isBlank(projectId)) {
+            return null;
+        }
+        List<String> projectIds = CollUtil.newArrayList(CommonConstant.DEFAULT_ID, AppContext.getContext().getGroupCode(), projectId);
+        wrapper = ensureCollectWrapper(wrapper, projectIds);
+        return dao.queryCollectInfos(pageable, projectIds, wrapper);
+    }
+
+    /**
+     * 补充wrapper信息
+     * @param wrapper
+     * @param projectIds
+     * @return
+     */
+    private QueryWrapper<ObjectInfoDefine> ensureCollectWrapper(QueryWrapper<ObjectInfoDefine> wrapper, List<String> projectIds) {
+        if(wrapper == null) {
+            wrapper = new QueryWrapper<>();
+        }
+        wrapper.in("dt_object.project_id", projectIds.toArray(new String[0]));
+        wrapper.orderByAsc("dt_object.local_id", "dt_define_info.class_code", "dt_define_info.code");
+        return wrapper;
+    }
 }

+ 91 - 0
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/simple/controller/CollectInfoController.java

@@ -0,0 +1,91 @@
+package com.persagy.dmp.rwd.simple.controller;
+
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.map.MapUtil;
+import cn.hutool.core.util.StrUtil;
+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.context.AppContext;
+import com.persagy.dmp.common.model.response.CommonResult;
+import com.persagy.dmp.common.utils.ParamCheckUtil;
+import com.persagy.dmp.common.utils.ResultHelper;
+import com.persagy.dmp.define.entity.ObjectInfoDefine;
+import com.persagy.dmp.rwd.define.service.IObjectInfoService;
+import lombok.extern.slf4j.Slf4j;
+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 java.util.List;
+import java.util.Map;
+
+/**
+ * 采集信息查询
+ * @author Charlie Yu
+ * @date 2021-11-17
+ */
+@Slf4j
+@RestController
+@RequestMapping("/api/report/collect")
+public class CollectInfoController {
+
+    private IObjectInfoService infoService;
+
+    /**
+     * 根据类型查询动态信息点、静态信息点交付比例
+     * @param objTypes 对象类型
+     * @return
+     */
+    @PostMapping("/queryCollectReport")
+    public CommonResult<Map<String, Long>> queryCollectReport(@RequestBody(required = false) List<String> objTypes) {
+        //基础参数校验
+        ParamCheckUtil.checkParam(CommonConstant.QUERY_GROUPCODE, CommonConstant.QUERY_PROJECTID);
+        QueryWrapper<ObjectInfoDefine> wrapper = new QueryWrapper<>();
+        wrapper.in(CollUtil.isNotEmpty(objTypes), "dt_object.obj_type", objTypes.toArray(new String[0]));
+        Map<String, Long> rs = infoService.queryCollectReport(AppContext.getContext().getProjectId(), wrapper);
+        return ResultHelper.single(rs);
+    }
+
+    /**
+     * 查询采集信息
+     * @param param {"page": long 页数, "size": long 条数, "objType": "对象基础类型"}
+     * @return
+     */
+    @PostMapping("/queryCollectInfos")
+    public CommonResult<List<Map<String, Object>>> queryCollectInfos(@RequestBody Map<String, Object> param) {
+        //基础参数校验
+        ParamCheckUtil.checkParam(CommonConstant.QUERY_GROUPCODE, CommonConstant.QUERY_PROJECTID);
+        // 获取入参,不传就默认500
+        Long page = MapUtil.getLong(param, "page", 1L);
+        Long size = MapUtil.getLong(param, "size", 500L);
+        String objType = MapUtil.getStr(param, "objType");
+        // 分页查询条件
+        Page<Map<String, Object>> pageable = new Page(page, size);
+        QueryWrapper<ObjectInfoDefine> wrapper = new QueryWrapper<>();
+        wrapper.eq(StrUtil.isNotBlank(objType), "dt_object.obj_type", objType);
+        pageable = infoService.queryCollectInfos(pageable, AppContext.getContext().getProjectId(), wrapper);
+        return ResultHelper.multi(pageable.getRecords(), pageable.getTotal());
+    }
+
+    /**
+     * 查询信息点
+     * @param param {"hasValue":"boolean 是否有值“, "classCode":"String 对象类型"}
+     * @return
+     */
+    @PostMapping("/queryInfosByObject")
+    public CommonResult<List<ObjectInfoDefine>> queryInfosByObject(@RequestBody Map<String, Object> param) {
+        //基础参数校验
+        ParamCheckUtil.checkParam(CommonConstant.QUERY_GROUPCODE, CommonConstant.QUERY_PROJECTID);
+        // 获取入参
+        boolean hasValue = MapUtil.getBool(param, "hasValue", false);
+        String classCode = MapUtil.getStr(param, "classCode");
+        QueryWrapper<ObjectInfoDefine> wrapper = new QueryWrapper<>();
+        wrapper.exists(hasValue, "(select 1 from dt_object where dt_define_info.class_code = dt_object.class_code " +
+                "and json_extract(dt_object.infos, concat('$.', dt_define_info.code)) is not null)");
+        List<ObjectInfoDefine> vos = infoService.queryByClassCodes(AppContext.getContext().getProjectId(), CollUtil.newArrayList(classCode), wrapper);
+        return ResultHelper.multi(vos);
+    }
+}

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

@@ -16,9 +16,10 @@ CREATE TABLE IF NOT EXISTS `dt_define_type` (
   `creation_time` char(14) NULL DEFAULT NULL COMMENT '创建时间',
   `modifier` varchar(32) DEFAULT NULL COMMENT '最后修改人',
   `modified_time` char(14) NULL DEFAULT NULL COMMENT '最后修改时间',
-  `valid` tinyint DEFAULT NULL COMMENT '合法标识',
+  `valid` tinyint DEFAULT 1 NOT NULL COMMENT '合法标识',
   `ts` timestamp default current_timestamp on update current_timestamp NOT NULL COMMENT '乐观锁',
   PRIMARY KEY (`id`) USING BTREE,
+  UNIQUE KEY `idx_unikey`(`code`, `valid`) USING BTREE,
   KEY `idx_code` (`code`) USING BTREE,
   KEY `idx_alias_code` (`alias_code`) USING BTREE,
   KEY `idx_parent_code` (`parent_code`) USING BTREE,

+ 49 - 21
dmp-business/dmp-rwd/src/main/resources/mapper/DefineInfoMapper.xml

@@ -5,7 +5,7 @@
 <mapper namespace="com.persagy.dmp.rwd.define.dao.ObjectInfoMapper">
     <!-- 类型如果重复则会出现多条,因此这里先用distinct容错.将基础类型的信息点与非基础信息点一起返回,且class_code改为对应的非基础对象类型 -->
     <sql id="SelectColumns">
-        select distinct
+        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,
@@ -40,30 +40,58 @@
           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)
+    <!-- 按项目查询信息点(包含上级信息点) -->
+    <sql id="InfoTableSQL">
+        select
+        <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">
+        <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>
-            </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
+        </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>
+        </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"/>)
+    </sql>
+    <select id="queryByClassCodes" resultType="com.persagy.dmp.define.entity.ObjectInfoDefine">
+        select ${ew.sqlSelect}
+        from ( <include refid="InfoTableSQL"/> ) dt_define_info
+        WHERE ${ew.expression.sqlSegment}
+    </select>
+    <select id="queryCollectInfos" resultType="java.util.Map">
+        select dt_object.id, dt_object.local_id, dt_object.local_name, dt_define_info.class_code, dt_define_type.name as class_name,
+            dt_define_info.code, dt_define_info.name,dt_define_info.first_tag, dt_define_info.data_type,dt_define_info.category,
+            json_unquote(json_extract(dt_object.infos, concat('$.', dt_define_info.code))) as info_value
+        from ( <include refid="InfoTableSQL"/> ) dt_define_info
+        inner join dt_define_type on dt_define_info.class_code = dt_define_type.code and dt_define_type.valid = 1
+        inner join dt_object on dt_object.class_code = dt_define_info.class_code and dt_object.valid = 1 and dt_define_info.code not in ('localId','localName')
         WHERE ${ew.expression.sqlSegment}
     </select>
+    <select id="queryCollectReport" resultType="java.util.Map">
+        select count(1) as all_num, sum(case when category = 'STATIC' then 1 else 0 end) as static_num,
+            sum(case when category = 'STATIC' and info_value is not null then 1 else 0 end) as static_value_num,
+            sum(case when category != 'STATIC' then 1 else 0 end) as dynamic_num,
+            sum(case when category != 'STATIC' and info_value is not null then 1 else 0 end) as dynamic_value_num
+        from (
+            select dt_object.id, dt_object.local_id, dt_object.local_name, dt_define_info.class_code, dt_define_type.name as class_name,
+            dt_define_info.code, dt_define_info.name,dt_define_info.first_tag, dt_define_info.data_type,dt_define_info.category,
+            json_unquote(json_extract(dt_object.infos, concat('$.', dt_define_info.code))) as info_value
+            from ( <include refid="InfoTableSQL"/> ) dt_define_info
+            inner join dt_define_type on dt_define_info.class_code = dt_define_type.code and dt_define_type.valid = 1
+            inner join dt_object on dt_object.class_code = dt_define_info.class_code and dt_object.valid = 1 and dt_define_info.code not in ('localId','localName')
+            WHERE ${ew.expression.sqlSegment}
+        ) R
+    </select>
+
 </mapper>