<?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="cn.roadm.mapper.UploadFileMapper">

    <resultMap type="cn.roadm.bo.UploadFile" id="uploadFileResultMap">
        <id column="id" property="id"/>
        <result column="file_name" property="fileName"/>
        <result column="channel_id" property="channelId"/>
        <result column="otype" property="otype"/>
        <result column="create_user" property="createUser"/>
        <result column="create_time" property="createTime"/>
        <result column="status" property="status"/>
        <result column="error_file" property="errorFile"/>
        <result column="success_file" property="successFile"/>
        <result column="head_review_file" property="headReviewFile"/>
        <result column="check_port_status" property="checkPortStatus"/>
        <result column="check_port_file" property="checkPortFile"/>
        <result column="file_path" property="filePath"/>
        <result column="data_file_name" property="dataFileName"/>
        <result column="data_file_path" property="dataFilePath"/>
        <result column="fileId_file_path" property="fileIdFilePath"/>
    </resultMap>

    <select id="listPageUpLoadFile" resultMap="uploadFileResultMap">
        select id,file_name,channel_id,otype,create_user,DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%s') create_time,
        status,error_file,success_file,head_review_file,file_path,data_file_name,data_file_path,fileId_file_path from upload_file_info
        where 1=1
        <if test="channelId != null">
            and channel_id = #{channelId}
        </if>
        <if test="fileName != null and fileName != ''">
            and file_name like concat('%',#{fileName},'%')
        </if>
        <if test="otype != null">
            and otype = #{otype}
        </if>
        order by create_time desc
    </select>

    <select id="selectById" resultMap="uploadFileResultMap">
        select id,file_name,channel_id,otype,create_user,create_time,status,error_file,success_file,head_review_file,
               check_port_status,file_path,fileId_file_path
        from upload_file_info where id = #{id}
    </select>

    <insert id="insert" parameterType="cn.roadm.bo.UploadFile">
        insert into upload_file_info (file_name,channel_id,otype,create_user,create_time,status,error_file,file_path,
        data_file_name,data_file_path) value
        (#{fileName},#{channelId},#{otype},#{createUser},now(),#{status},#{errorFile},#{filePath},#{dataFileName},#{dataFilePath})
    </insert>

    <select id="getAccountInfo" resultType="cn.roadm.bo.UploadAccount">
        select id,channel_id channelId ,username,password,sms_port smsPort,province_code provinceCode
        from upload_account_info where channel_id = #{channelId}
    </select>

    <select id="getAccountInfoById" resultType="cn.roadm.bo.UploadAccount">
        select id,channel_id channelId ,username,password,sms_port smsPort,province_code provinceCode
        from upload_account_info where id = #{id}
    </select>

    <select id="selectChannelInfo" resultType="map">
        select id,channel_name channelName,IS_SUPPORT_UNICOM isSupportUnicom,IS_SUPPORT_MOBILE isSupportMobile
        ,IS_SUPPORT_TELECOM isSupportTelecom from sms_send_channel_info
    </select>

    <select id="getAccountInfos" resultType="cn.roadm.bo.UploadAccount">
        select id,channel_id channelId,username,password,sms_port,province_code provinceCode from upload_account_info
    </select>

    <update id="updateStatusById">
        update upload_file_info set `status` = '5' where id = #{id}
    </update>

    <update id="updateCheckStatus1ById">
        update upload_file_info set `check_port_status` = '1' where id = #{id}
    </update>

    <update id="updateCheckStatus0ById">
        update upload_file_info set `check_port_status` = '0' where id = #{id}
    </update>

    <update id="updateCheckPortFile">
        update upload_file_info set `check_port_file` =  #{checkPortFile} where id = #{id}
    </update>

    <update id="updateErrorFile">
        update upload_file_info set `error_file` =  #{errorFile} where id = #{id}
    </update>

</mapper>