<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fdkankan.ucenter.mapper.ISceneCleanMapper">

  <select id="selectNeadCleanScene" resultType="com.fdkankan.ucenter.bean.SceneBean">
    select t.num, t.data_source from (
      SELECT p.num, p.data_source
      FROM t_scene_pro p
      WHERE p.status != 0 and p.is_upgrade != 1 and p.create_time <![CDATA[ <= ]]> #{time}
      and p.num NOT IN (
          SELECT c.num FROM t_scene_clean c WHERE c.state = 1
      )

      union

      SELECT p.num, e.data_source
      FROM t_scene_plus p
      left join t_scene_plus_ext e on p.id = e.plus_id
      WHERE p.scene_status != 0 and e.algorithm_time <![CDATA[ <= ]]> #{time}
      and p.num NOT IN (
          SELECT c.num FROM t_scene_clean c WHERE c.state = 1
      )
    ) t
    LIMIT #{index},#{size}
  </select>

  <select id="findAllByDateSource" resultType="com.fdkankan.ucenter.bean.SceneClean">
    select t.create_time from (
    SELECT p.create_time
    FROM t_scene_pro p
    WHERE p.data_source = #{dataSource}

    union

    SELECT p.algorithm_time
    FROM t_scene_plus_ext p
    WHERE p.data_source = #{dataSource}
    ) t order by create_time desc
  </select>

</mapper>
