|  |  | 
 |  |  |     <select id="selectNewestData" resultType="java.util.Map"> | 
 |  |  |         select ai.id alarmInfoId,ai.alarm_time,ai.index,ai.alarm_type,ai.alarm_information,d.id deviceId,d.name deviceName,d.longitude,d.latitude | 
 |  |  |         from alarm_info ai, device d | 
 |  |  |         where ai.device_id in | 
 |  |  |         <foreach collection="deviceIds" item="deviceId" index="index" open="(" close=")" separator=","> | 
 |  |  |             #{deviceId} | 
 |  |  |         </foreach> | 
 |  |  |         and d.id = ai.device_id | 
 |  |  |         ORDER by ai.create_time DESC | 
 |  |  |         limit 0,#{size} | 
 |  |  |         where ai.alarm_time = (SELECT max(alarm_time) from alarm_info limit 1) and   d.id = ai.device_id and ai.device_id in | 
 |  |  |         (select t.id from device t | 
 |  |  |                               inner JOIN monitor_point p on p.id = t.monitor_point_id and p.is_delete = 0 | 
 |  |  |  | 
 |  |  |             and p.organization_id in (   SELECT id FROM ( | 
 |  |  |                                                             SELECT id, parent_id, name FROM organization  WHERE id = #{orgId} | 
 |  |  |                                                             UNION ALL | 
 |  |  |                                                             SELECT i.id, i.parent_id, i.name | 
 |  |  |                                                             FROM organization  i | 
 |  |  |                                                                      INNER JOIN ( | 
 |  |  |                                                                 SELECT * FROM ( | 
 |  |  |                                                                                   SELECT id, parent_id, name FROM organization  WHERE id = #{orgId} | 
 |  |  |                                                                                   UNION ALL | 
 |  |  |                                                                                   SELECT id, parent_id, name FROM organization WHERE parent_id = #{orgId} | 
 |  |  |                                                                               ) t1 | 
 |  |  |                                                             ) t2 ON i.parent_id = t2.id | 
 |  |  |                                                             where i.is_delete = 0 | 
 |  |  |                                                         ) t3) | 
 |  |  |          WHERE | 
 |  |  |              t.is_delete = 0 | 
 |  |  |         ) | 
 |  |  |         ORDER by ai.id DESC | 
 |  |  |         limit #{size} | 
 |  |  |     </select> | 
 |  |  |     <select id="numNews" resultType="java.lang.Integer"> | 
 |  |  |         select count(1) from alarm_info | 
 |  |  |                         where alarm_time >=  date_format(NOW(),'%Y-%m-%d') | 
 |  |  |         and device_id in (SELECT | 
 |  |  |                               t.id | 
 |  |  |                           FROM | 
 |  |  |                               device t | 
 |  |  |                                   INNER JOIN monitor_point p ON p.id = t.monitor_point_id | 
 |  |  |                                   AND p.is_delete = 0 | 
 |  |  |                                   AND p.organization_id IN ( | 
 |  |  |                                       SELECT | 
 |  |  |                                           id | 
 |  |  |                                       FROM | 
 |  |  |                                           ( | 
 |  |  |                                               SELECT | 
 |  |  |                                                   id, | 
 |  |  |                                                   parent_id, | 
 |  |  |                                                   NAME | 
 |  |  |                                               FROM | 
 |  |  |                                                   organization | 
 |  |  |                                               WHERE | 
 |  |  |                                                   id = #{organizationId} UNION ALL | 
 |  |  |                                               SELECT | 
 |  |  |                                                   i.id, | 
 |  |  |                                                   i.parent_id, | 
 |  |  |                                                   i.NAME | 
 |  |  |                                               FROM | 
 |  |  |                                                   organization i | 
 |  |  |                                                       INNER JOIN ( | 
 |  |  |                                                       SELECT | 
 |  |  |                                                           * | 
 |  |  |                                                       FROM | 
 |  |  |                                                           ( | 
 |  |  |                                                               SELECT | 
 |  |  |                                                                   id, | 
 |  |  |                                                                   parent_id, | 
 |  |  |                                                                   NAME | 
 |  |  |                                                               FROM | 
 |  |  |                                                                   organization | 
 |  |  |                                                               WHERE | 
 |  |  |                                                                   id = #{organizationId} UNION ALL | 
 |  |  |                                                               SELECT | 
 |  |  |                                                                   id, | 
 |  |  |                                                                   parent_id, | 
 |  |  |                                                                   NAME | 
 |  |  |                                                               FROM | 
 |  |  |                                                                   organization | 
 |  |  |                                                               WHERE | 
 |  |  |                                                                   parent_id = #{organizationId} | 
 |  |  |                                                           ) t1 | 
 |  |  |                                                   ) t2 ON i.parent_id = t2.id | 
 |  |  |                                               WHERE | 
 |  |  |                                                   i.is_delete = 0 | 
 |  |  |                                           ) t3 | 
 |  |  |                                   ) | 
 |  |  |                           WHERE | 
 |  |  |                               t.is_delete = 0 ) | 
 |  |  |     </select> | 
 |  |  |  | 
 |  |  | </mapper> |