Browse Source

fix bug:/api/report/equipment/queryEquipComponentsByProjectId接口查询不到数据

lijie 3 years ago
parent
commit
f4c55687f1

+ 19 - 22
dmp-business/dmp-rwd/src/main/resources/mapper/EquipmentReportMapper.xml

@@ -112,28 +112,25 @@
     </select>
 
     <select id="queryEquipComponentsByProjectId" resultType="java.util.Map">
-        SELECT code,name,IFNULL(count,0) 'count' FROM (
-            SELECT DISTINCT code,name,
-            (select count(class_code) from dt_object where obj_type='component'
-                <if test="null!=equipmentId and equipmentId.length>0">
-                    AND JSON_CONTAINS(infos, JSON_OBJECT('parentId',#{equipmentId}))
-                </if>
-                AND class_code = code
-                <if test="null!=projectId and projectId.length>0">
-                    AND project_id=#{projectId}
-                </if>
-                <if test="null!=groupCode and groupCode.length>0">
-                    AND group_code=#{groupCode}
-                </if>
-                GROUP BY class_code
-            ) count
-            FROM dt_define_type
-            WHERE
-            valid=TRUE AND group_code = '0' -- 查询通用定义
-            <if test="null!=category and category.length>0">
-                AND equipment_code = #{category}
-            </if>
-        ) temp
+        SELECT dt_define_type.`code`,dt_define_type.`name`,IFNULL(temp.count,0) AS count FROM dt_define_type
+        LEFT JOIN (SELECT dt_object.class_code,COUNT(dt_object.id) AS count FROM dt_object
+            INNER JOIN dt_relation ON (dt_relation.obj_to=dt_object.id AND dt_object.obj_type='component'
+        <if test="null!=equipmentId and equipmentId.length>0">
+        AND dt_relation.obj_from=#{equipmentId}
+        </if>
+        AND dt_relation.graph_code='MechSubset' AND dt_relation.rel_code='Eq2Ec'
+        <if test="null!=projectId and projectId.length>0">
+            AND dt_object.project_id=#{projectId}
+        </if>
+        <if test="null!=groupCode and groupCode.length>0">
+            AND dt_object.group_code=#{groupCode}
+        </if>
+        AND dt_object.valid=TRUE AND dt_relation.valid=TRUE) GROUP BY dt_object.class_code) AS temp
+            ON(temp.class_code=dt_define_type.`code`) WHERE dt_define_type.obj_type='component'
+        <if test="null!=category and category.length>0">
+          AND dt_define_type.`code` LIKE CONCAT(#{category},'%')
+        </if>
+          AND dt_define_type.project_id='0' AND dt_define_type.group_code = '0' AND dt_define_type.valid=TRUE;
     </select>
 
     <select id="queryDefineInfoByObjType" resultType="java.util.Map">