<?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.ym.mec.biz.dal.dao.ManagerDownloadDao">
    <resultMap id="ManagerDownload" type="com.ym.mec.biz.dal.entity.ManagerDownload">
        <!--@mbg.generated-->
        <!--@Table manager_download-->
        <id column="id_" property="id"/>
        <result column="user_id_" property="userId"/>
        <result column="name_" property="name"/>
        <result column="file_url_" property="fileUrl"/>
        <result column="type_" property="type" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="status_" property="status"/>
        <result column="create_time_" property="createTime"/>
        <result column="update_time_" property="updateTime"/>
		<result column="tenant_id_" property="tenantId" />
    </resultMap>

    <select id="get" parameterType="java.lang.Integer" resultMap="ManagerDownload">
        <!--@mbg.generated-->
        select * from manager_download
        where id_ = #{id}
    </select>
    <delete id="delete" parameterType="java.lang.Integer">
        <!--@mbg.generated-->
        delete from manager_download
        where id_ = #{id,jdbcType=INTEGER}
    </delete>
    <delete id="batchDel">
        delete from manager_download where FIND_IN_SET(id_, #{ids})
    </delete>
    <insert id="insert" keyColumn="id_" keyProperty="id" parameterType="com.ym.mec.biz.dal.entity.ManagerDownload"
            useGeneratedKeys="true">
        <!--@mbg.generated-->
        insert into manager_download (user_id_, name_, file_url_,type_,
        status_, create_time_, update_time_,tenant_id_
        )
        values (#{userId}, #{name}, #{fileUrl},#{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
        #{status}, #{createTime}, #{updateTime},#{tenantId}
        )
    </insert>

    <update id="update" parameterType="com.ym.mec.biz.dal.entity.ManagerDownload">
        <!--@mbg.generated-->
        update manager_download
        <set>
            <if test="userId != null">
                user_id_ = #{userId},
            </if>
            <if test="name != null">
                name_ = #{name},
            </if>
            <if test="fileUrl != null">
                file_url_ = #{fileUrl},
            </if>
            <if test="status != null">
                status_ = #{status},
            </if>
            create_time_ = NOW(),
            update_time_ = NOW(),
        </set>
        where id_ = #{id} and tenant_id_ = #{tenantId}
    </update>

    <!-- 分页查询 -->
    <select id="queryPage" resultMap="ManagerDownload" parameterType="map">
        SELECT * FROM manager_download
        <include refid="queryPageSql"/>
        ORDER BY id_ DESC
        <include refid="global.limit"/>
    </select>

    <!-- 查询当前表的总记录数 -->
    <select id="queryCount" resultType="int">
        SELECT COUNT(*) FROM manager_download
        <include refid="queryPageSql"/>
    </select>

    <sql id="queryPageSql">
        <where>
        	tenant_id_ = #{tenantId}
            <if test="userId != null">
                AND user_id_ = #{userId}
            </if>
            <if test="type != null">
                AND type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
            </if>
        </where>
    </sql>
</mapper>