<?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.hdkj.lt.job.mapper.DistOSSSvgFileMapper">

    <select id="getCustomStorageLine" resultType="java.lang.String">
        select f.psr_id from dwd_shb_ds_feeder_base f join SYS_DICT_SINGLE s on f.city = s.VALUE
        join SYS_DICT_TYPE t on s.TYPE_ID = t.TYPE_ID and t.TYPE_NAME = 'custom_storage'
        where s.BAK_1 is null and f.psr_state= '20'
        union all
        select f.psr_id from dwd_shb_ds_feeder_base f join SYS_DICT_SINGLE s on f.city = s.LABEL
        join SYS_DICT_TYPE t on s.TYPE_ID = t.TYPE_ID and t.TYPE_NAME = 'custom_storage'
        where s.BAK_1 is null and f.psr_state= '20'
    </select>

    <insert id="insertDistMasterStationFile">
        insert into fhzg_dist_master_station_file(file_path, upload_time, del_flag, create_time, last_time)
        values
        <foreach collection='fileList' item='item' separator=','>
            (#{item.fileName}, #{item.uploadTime}, '0', #{dateTime}, #{dateTime})
        </foreach>
    </insert>

    <update id="updateConfigFileChangeTime">
        update SYS_BASE_CONFIG set LAST_TIME = #{dateTime}, CONFIG_VALUE = date(#{plusDayTime}) where CONFIG_KEY = 'ds_svg_file_config'
    </update>

    <update id="updateDistMasterStationFile">
        update fhzg_dist_master_station_file set del_flag = '1' where del_flag = '0'
        and file_path in
        <foreach collection='fileNames' item='item' open='(' separator=',' close=')'>
            #{item}
        </foreach>
    </update>

    <select id="getConfigValueFileChange" resultType="java.lang.String">
        select CONFIG_VALUE from SYS_BASE_CONFIG where CONFIG_KEY = 'ds_svg_file_config' limit 1
    </select>

    <select id="getDistMasterStationFile" resultType="java.lang.String">
        select file_path from fhzg_dist_master_station_file where del_flag = '0' limit #{size}
    </select>

    <select id="getAllDistMasterStationFile" resultType="com.hdkj.lt.modle.FileUploadDTO">
        select file_path file_name, max(upload_time) upload_time
        from fhzg_dist_master_station_file s join (select config_key, max(LAST_TIME) conf_time
            from SYS_BASE_CONFIG group by CONFIG_KEY) c on s.upload_time >= c.conf_time
        where c.config_key = 'ds_svg_file_config' group by file_path
    </select>

</mapper>
