<?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">

<!-- 影像数据表(分表空间)(rscp_image_data_total) -->
<mapper namespace="com.upyuns.platform.rs.datacenter.mapper.RscpImageDataTotalMapper">
    <!-- This code was generated by TableGo tools, mark 1 begin. -->
    <!-- 字段映射 -->
    <resultMap id="BaseResultMap" type="com.upyuns.platform.rs.datacenter.entity.RscpImageDataTotal">
        <result column="id" property="id" jdbcType="BIGINT" />
        <result column="data_no" property="dataNo" jdbcType="VARCHAR" />
        <result column="category_id" property="categoryId" jdbcType="VARCHAR" />
        <result column="name" property="name" jdbcType="VARCHAR" />
        <result column="range" property="range" jdbcType="VARCHAR" />
        <result column="thumbnail_path" property="thumbnailPath" jdbcType="VARCHAR" />
        <result column="display_name" property="displayName" jdbcType="VARCHAR" />
        <result column="image_resolution" property="imageResolution" jdbcType="VARCHAR" typeHandler="com.upyuns.platform.rs.datacenter.mybatis.ArrayTypeHandler"/>
        <result column="image_spectrum_type" property="imageSpectrumType" jdbcType="VARCHAR" typeHandler="com.upyuns.platform.rs.datacenter.mybatis.ArrayTypeHandler"/>
        <result column="image_spectrum_type_display" property="imageSpectrumTypeDisplay" jdbcType="VARCHAR" typeHandler="com.upyuns.platform.rs.datacenter.mybatis.ArrayTypeHandler"/>
        <result column="image_row_col" property="imageRowCol" jdbcType="VARCHAR" />
        <result column="image_row" property="imageRow" jdbcType="VARCHAR" />
        <result column="image_col" property="imageCol" jdbcType="VARCHAR" />
        <result column="image_product_type" property="imageProductType" jdbcType="VARCHAR" />
        <result column="image_product_type_display" property="imageProductTypeDisplay" jdbcType="VARCHAR" />
        <result column="image_file_path" property="imageFilePath" jdbcType="VARCHAR" />
        <result column="image_center_point" property="imageCenterPoint" jdbcType="VARCHAR" />
        <result column="image_province" property="imageProvince" jdbcType="VARCHAR" />
        <result column="image_city" property="imageCity" jdbcType="VARCHAR" />
        <result column="image_area" property="imageArea" jdbcType="VARCHAR" />
        <result column="image_projection" property="imageProjection" jdbcType="VARCHAR" />
        <result column="image_satellite_type" property="imageSatelliteType" jdbcType="VARCHAR" />
        <result column="image_satellite_type_display" property="imageSatelliteTypeDisplay" jdbcType="VARCHAR" />
        <result column="image_take_time" property="imageTakeTime" jdbcType="VARCHAR" />
        <result column="image_cloudage" property="imageCloudage" jdbcType="INTEGER" />
        <result column="image_product_level" property="imageProductLevel" jdbcType="VARCHAR" />
        <result column="image_observation" property="imageObservation" jdbcType="VARCHAR" />
        <result column="image_sensor_type" property="imageSensorType" jdbcType="VARCHAR" />
        <result column="sell_price" property="sellPrice" jdbcType="INTEGER" />
        <result column="is_sell" property="isSell" jdbcType="INTEGER" />
        <result column="is_del" property="isDel" jdbcType="INTEGER" />
        <result column="remark" property="remark" jdbcType="VARCHAR" />
        <result column="files" property="files" jdbcType="VARCHAR" typeHandler="com.upyuns.platform.rs.datacenter.mybatis.ArrayTypeHandler"/>
        <result column="image_wms_path" property="imageWmsPath" jdbcType="VARCHAR" />
        <result column="image_out_path" property="imageOutPath" jdbcType="VARCHAR" />
        <result column="image_is_save" property="imageIsSave" jdbcType="INTEGER" />
        <result column="create_dt" property="createDt" jdbcType="TIMESTAMP" />
        <result column="image_sensor_id" property="imageSensorId" jdbcType="VARCHAR" />
        <result column="image_product_type1" property="imageProductType1" jdbcType="VARCHAR" />
        <result column="image_scene_id" property="imageSceneId" jdbcType="VARCHAR" />
        <result column="image_product_id" property="imageProductId" jdbcType="VARCHAR" />
        <result column="image_product_format" property="imageProductFormat" jdbcType="VARCHAR" />
        <result column="image_product_time" property="imageProductTime" jdbcType="VARCHAR" />
        <result column="image_sat_path" property="imageSatPath" jdbcType="VARCHAR" />
        <result column="image_sat_row" property="imageSatRow" jdbcType="VARCHAR" />
        <result column="image_start_time" property="imageStartTime" jdbcType="VARCHAR" />
        <result column="image_end_time" property="imageEndTime" jdbcType="VARCHAR" />
        <result column="image_center_time" property="imageCenterTime" jdbcType="VARCHAR" />
        <result column="image_width_in_pixels" property="imageWidthInPixels" jdbcType="VARCHAR" />
        <result column="image_pitch_satellitess_angle" property="imagePitchSatellitessAngle" jdbcType="VARCHAR" />
        <result column="image_solar_azimuth" property="imageSolarAzimuth" jdbcType="VARCHAR" />
        <result column="image_solar_zenith" property="imageSolarZenith" jdbcType="VARCHAR" />
        <result column="image_satellite_azimuth" property="imageSatelliteAzimuth" jdbcType="VARCHAR" />
        <result column="image_satellite_zenith" property="imageSatelliteZenith" jdbcType="VARCHAR" />
        <result column="image_height_in_pixels" property="imageHeightInPixels" jdbcType="VARCHAR" />
        <result column="image_yaw_satellite_angle" property="imageYawSatelliteAngle" jdbcType="VARCHAR" />
        <result column="job_id" property="jobId" jdbcType="VARCHAR" />
        <result column="correct_status" property="correctStatus" jdbcType="INTEGER" />
        <result column="relation_no" property="relationNo" jdbcType="VARCHAR" />
        <result column="shop_id" property="shopId" jdbcType="VARCHAR" />
        <result column="tif_job_id" property="tifJobId" jdbcType="VARCHAR" />
        <result column="tif_task_status" property="tifTaskStatus" jdbcType="INTEGER" />
        <result column="json_task_date" property="jsonTaskDate" jdbcType="TIMESTAMP" />
        <result column="json_task_status" property="jsonTaskStatus" jdbcType="INTEGER" />
        <result column="image_year" property="imageYear" jdbcType="INTEGER" />
        <result column="status" property="status" javaType="INTEGER"/>
    </resultMap>
    <!-- This code was generated by TableGo tools, mark 1 end. -->
    
    <!-- This code was generated by TableGo tools, mark 2 begin. -->
    <!-- 表查询字段 -->
    <sql id="allColumns">
        ridt.id, ridt.data_no, ridt.category_id, ridt.name, ridt.range, ridt.thumbnail_path, ridt.display_name, ridt.image_resolution, 
        ridt.image_spectrum_type, ridt.image_spectrum_type_display, ridt.image_row_col, ridt.image_row, ridt.image_col, ridt.image_product_type, ridt.image_product_type_display, ridt.image_file_path, 
        ridt.image_center_point, ridt.image_province, ridt.image_city, ridt.image_area, ridt.image_projection, ridt.image_satellite_type, ridt.image_satellite_type_display, ridt.image_take_time, 
        ridt.image_cloudage, ridt.image_product_level, ridt.image_observation, ridt.image_sensor_type, ridt.sell_price, ridt.is_sell, ridt.is_del, ridt.remark, 
        ridt.files, ridt.image_wms_path, ridt.image_out_path, ridt.image_is_save, ridt.create_dt, ridt.image_sensor_id, ridt.image_product_type1, ridt.image_scene_id, 
        ridt.image_product_id, ridt.image_product_format, ridt.image_product_time, ridt.image_sat_path, ridt.image_sat_row, ridt.image_start_time, ridt.image_end_time, ridt.image_center_time, 
        ridt.image_width_in_pixels, ridt.image_pitch_satellitess_angle, ridt.image_solar_azimuth, ridt.image_solar_zenith, ridt.image_satellite_azimuth, ridt.image_satellite_zenith, ridt.image_height_in_pixels, ridt.image_yaw_satellite_angle, 
        ridt.job_id, ridt.correct_status, ridt.relation_no, ridt.shop_id, ridt.tif_job_id, ridt.tif_task_status, ridt.json_task_date, ridt.json_task_status, 
        ridt.image_year
    </sql>
    <!-- This code was generated by TableGo tools, mark 2 end. -->

    <select id="queryDataList" resultMap="BaseResultMap">
            select st_asgeojson(range,16,0) as range, *
                <include refid="geomSelectSql" />
            limit 5000
            offset 0;
    </select>

    <select id="bgQueryDataList" resultMap="BaseResultMap">
        select *
        from rscp_image_data_total
        <where>
        <if test="name != null">
            and name like '%' || #{name} || '%'
        </if>
        <if test="imageSatelliteType != null">
            and image_satellite_type like '%' || #{imageSatelliteType} || '%'
        </if>
        <if test="resolution != null">
            and #{resolution} = any(image_resolution)
        </if>
        <if test="startDateTime != null">
            and image_take_time &gt;= #{startDateTime}
        </if>
        <if test="endDateTime != null">
            and image_take_time &lt;= #{endDateTime}
        </if>
        <if test="imageSatelliteType != null">
            image_satellite_type = #{imageSatelliteType}
        </if>
        <if test="status != null">
            status = #{status}
        </if>


        </where>
    </select>

    <select id="queryDataById" resultMap="BaseResultMap">
        select st_asgeojson(range,16,0) as range, *
        from rscp_image_data_total
        where id = #{id}
    </select>

    <select id="queryGeomsJson" resultType="String">
        select st_asgeojson(geoms_input,16,0) as range
        from
        (
            select st_union(item_geom) geoms_input
            from
            <foreach collection="geoms" index="geomsIndex" item="geomsItem" open="(" close=")" separator=" UNION ALL ">
                select geojsontowkt(#{geomsItem}, 'true') item_geom
            </foreach>
            as item_temp
        ) temp
    </select>

    <sql id="geomSelectSql" >
        from rscp_image_data_total
        <if test="geom != null">
            , (select geojsontowkt(#{geom}, 'true') geom_input) temp
        </if>
        <if test="geoms != null">
            , ( select st_union(item_geom) geoms_input
                from
                    <foreach collection="geoms" index="geomsIndex" item="geomsItem" open="(" close=")" separator=" UNION ALL ">
                       select geojsontowkt(#{geomsItem}, 'true') item_geom
                    </foreach>
                as item_temp
              ) temp
        </if>
        <where>
            <if test="saSensor != null">
                and
                <foreach collection="saSensor" item="sa" open="(" separator=" or " close=")">
                    image_satellite_type = #{sa.satellite}
                    <if test="sa.sensors != null and sa.sensors.size > 0">
                        and image_sensor_type in
                        <foreach collection="sa.sensors" item="sensor" open="(" separator="," close=")">
                            #{sensor}
                        </foreach>
                    </if>
                </foreach>
            </if>
            <if test="resolution != null">
                and #{resolution} = any(image_resolution)
            </if>
            <if test="startDateTime != null">
                and image_take_time &gt;= #{startDateTime}
            </if>
            <if test="endDateTime != null">
                and image_take_time &lt;= #{endDateTime}
            </if>
            <if test="cloud != null">
                and image_cloudage &lt;= #{cloud}
            </if>
            <if test="geom != null">
                and ST_Intersects(temp.geom_input,range)
            </if>
            <if test="geoms != null">
                and ST_Intersects(temp.geoms_input,range)
            </if>
        </where>
    </sql>
</mapper>