<?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.ruoyi.file.mapper.ProjectMapper">
    
    <resultMap type="Project" id="ProjectResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="token"    column="token"    />
        <result property="remoteHost"    column="remote_host"    />
        <result property="diskPath"    column="disk_path"    />
        <result property="deptId"    column="dept_id"    />
        <result property="disabled"    column="disabled"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectProjectVo">
        select id, name, token, remote_host, disk_path, dept_id, disabled, create_by, create_time, update_by, update_time from project
    </sql>

    <select id="selectProjectList" parameterType="Project" resultMap="ProjectResult">
        <include refid="selectProjectVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="token != null  and token != ''"> and token = #{token}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="disabled != null  and disabled != ''"> and disabled = #{disabled}</if>
        </where>
    </select>
    
    <select id="selectProjectById" parameterType="Long" resultMap="ProjectResult">
        <include refid="selectProjectVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertProject" parameterType="Project" useGeneratedKeys="true" keyProperty="id">
        insert into project
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="token != null and token != ''">token,</if>
            <if test="remoteHost != null and remoteHost != ''">remote_host,</if>
            <if test="diskPath != null and diskPath != ''">disk_path,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="disabled != null and disabled != ''">disabled,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="token != null and token != ''">#{token},</if>
            <if test="remoteHost != null and remoteHost != ''">#{remoteHost},</if>
            <if test="diskPath != null and diskPath != ''">#{diskPath},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="disabled != null and disabled != ''">#{disabled},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <!--批量新增-->
    <insert id="insertProjectBatch" parameterType="list"  useGeneratedKeys="true" keyProperty="id">
        insert into project
        <trim prefix="(" suffix=")" suffixOverrides=",">
            name,
            token,
            remote_host,
            disk_path,
            dept_id,
            disabled,
            create_by,
            create_time,
            update_by,
            update_time,
        </trim>
        values
        <foreach item="item" collection="list" separator="," >
            <trim prefix="(" suffix=")" suffixOverrides=",">
                #{item.name},
                #{item.token},
                #{item.remoteHost},
                #{item.diskPath},
                #{item.deptId},
                #{item.disabled},
                #{item.createBy},
                #{item.createTime},
                #{item.updateBy},
                #{item.updateTime},
            </trim>
        </foreach>
    </insert>

    <update id="updateProject" parameterType="Project">
        update project
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="token != null and token != ''">token = #{token},</if>
            <if test="remoteHost != null and remoteHost != ''">remote_host = #{remoteHost},</if>
            <if test="diskPath != null and diskPath != ''">disk_path = #{diskPath},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="disabled != null and disabled != ''">disabled = #{disabled},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <!--批量更新-->
    <update id="updateProjectBatch" parameterType="list" >
        <foreach collection="list" item="item" index="index" open="" close="" separator=";">
            update project
            <set>
                <if test="item.name != null and item.name != ''">name = #{item.name},</if>
                <if test="item.token != null and item.token != ''">token = #{item.token},</if>
                <if test="item.remoteHost != null and item.remoteHost != ''">remote_host = #{item.remoteHost},</if>
                <if test="item.diskPath != null and item.diskPath != ''">disk_path = #{item.diskPath},</if>
                <if test="item.deptId != null">dept_id = #{item.deptId},</if>
                <if test="item.disabled != null and item.disabled != ''">disabled = #{item.disabled},</if>
                <if test="item.createBy != null">create_by = #{item.createBy},</if>
                <if test="item.createTime != null">create_time = #{item.createTime},</if>
                <if test="item.updateBy != null">update_by = #{item.updateBy},</if>
                <if test="item.updateTime != null">update_time = #{item.updateTime},</if>
            </set>
            where id = #{item.id}
        </foreach>
    </update>

    <delete id="deleteProjectById" parameterType="Long">
        delete from project where id = #{id}
    </delete>

    <delete id="deleteProjectByIds" parameterType="String">
        delete from project where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <!--单条条件查询-->
    <select id="selectProject" parameterType="Project" resultMap="ProjectResult">
        <include refid="selectProjectVo"/>
        <where>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="token != null  and token != ''"> and token = #{token}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="disabled != null  and disabled != ''"> and disabled = #{disabled}</if>
        </where>
        limit 1
    </select>

    <!--条件查询数量-->
    <select id="selectProjectCount" parameterType="Project" resultType="Long">
        select count(*) from project
        <where>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="token != null  and token != ''"> and token = #{token}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="disabled != null  and disabled != ''"> and disabled = #{disabled}</if>
        </where>
    </select>

    <!--条件查询是否存在-->
    <select id="selectProjectExists" parameterType="Project" resultType="int">
        select exists (
            select 1 from project
        <where>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="token != null  and token != ''"> and token = #{token}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="disabled != null  and disabled != ''"> and disabled = #{disabled}</if>
        </where>
        limit 1
        )
    </select>
</mapper>