<?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.reghao.tnb.file.app.zoss.db.mapper.UploadChannelMapper">
    <insert id="save" useGeneratedKeys="true" keyProperty="id">
        insert into file_upload_channel
        (`channel_code`,`name`,`prefix`,`max_size`,`file_type`,`set_url`,`set_callback`,`scope`,`enabled`,`user_node_id`,`create_by`)
        values
        (#{channelCode},#{name},#{prefix},#{maxSize},#{fileType},#{setUrl},#{setCallback},#{scope},#{enabled},#{userNodeId},#{createBy})
    </insert>
    <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
        insert into file_upload_channel
        (`channel_code`,`name`,`prefix`,`max_size`,`file_type`,`set_url`,`set_callback`,`scope`,`enabled`,`user_node_id`,`create_by`)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.channelCode},#{item.name},#{item.prefix},#{item.maxSize},#{item.fileType},#{item.setUrl},#{item.setCallback},#{item.scope},#{item.enabled},#{item.userNodeId},#{item.createBy})
        </foreach>
    </insert>

    <delete id="deleteById">
        delete from file_upload_channel
        where id=#{id}
    </delete>

    <select id="countByCreateBy" resultType="java.lang.Integer">
        select count(*)
        from file_upload_channel
        where create_by=#{createBy}
    </select>
    <select id="findByCreateBy" resultType="cn.reghao.tnb.file.app.zoss.model.po.UploadChannel">
        select *
        from file_upload_channel
        where create_by=#{createBy}
    </select>
    <select id="findById" resultType="cn.reghao.tnb.file.app.zoss.model.po.UploadChannel">
        select *
        from file_upload_channel
        where id=#{id}
    </select>
    <select id="findByCreateByAndUserNodeId" resultType="cn.reghao.tnb.file.app.zoss.model.po.UploadChannel">
        select *
        from file_upload_channel
        where create_by=#{createBy} and user_node_id=#{userNodeId}
    </select>
    <select id="findByCreateByAndChannelCode" resultType="cn.reghao.tnb.file.app.zoss.model.po.UploadChannel">
        select *
        from file_upload_channel
        where create_by=#{createBy} and channel_code=#{channelCode}
    </select>
    <select id="findByCreateByAndPrefix" resultType="cn.reghao.tnb.file.app.zoss.model.po.UploadChannel">
        select *
        from file_upload_channel
        where create_by=#{createBy} and prefix like concat(#{prefix},'%')
    </select>
    <select id="findByCreateByAndName" resultType="cn.reghao.tnb.file.app.zoss.model.po.UploadChannel">
        select *
        from file_upload_channel
        where create_by=#{createBy} and name=#{name}
    </select>
</mapper>
