<?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.system.mapper.SysSecretProjectMapper">
    
    <resultMap type="SysSecretProject" id="SysSecretProjectResult">
        <result property="id"    column="id"    />
        <result property="projectId"    column="project_id"    />
        <result property="secretKey"    column="secret_key"    />
    </resultMap>

    <resultMap type="SysSecretProjectDTO" id="getSysSecretProjectList">
        <result property="id"    column="id"    />
        <result property="projectId"    column="project_id"    />
        <result property="projectName"    column="project_name"    />
        <result property="secretKey"    column="secret_key"    />
    </resultMap>

    <sql id="selectSysSecretProjectVo">
        select id, project_id, secret_key from sys_secret_project
    </sql>

    <select id="selectSysSecretProjectList" resultMap="getSysSecretProjectList">
        select ssp.id, sp.project_name, secret_key from sys_secret_project ssp
        left join sys_project sp on ssp.project_id = sp.id
        <where>  
            <if test="projectName != null "> and sp.project_name = #{projectName}</if>
            <if test="secretKey != null  and secretKey != ''"> and secret_key = #{secretKey}</if>
        </where>
    </select>
    
    <select id="selectSysSecretProjectById" parameterType="Long" resultMap="getSysSecretProjectList">
        select ssp.id,ssp.project_id, sp.project_name, secret_key from sys_secret_project ssp
        left join sys_project sp on ssp.project_id = sp.id
        where ssp.id = #{id}
    </select>
        
    <insert id="insertSysSecretProject" parameterType="SysSecretProject" useGeneratedKeys="true" keyProperty="id">
        insert into sys_secret_project
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="projectId != null">project_id,</if>
            <if test="secretKey != null">secret_key,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="projectId != null">#{projectId},</if>
            <if test="secretKey != null">#{secretKey},</if>
         </trim>
    </insert>

    <update id="updateSysSecretProject" parameterType="SysSecretProject">
        update sys_secret_project
        <trim prefix="SET" suffixOverrides=",">
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="secretKey != null">secret_key = #{secretKey},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysSecretProjectById" parameterType="Long">
        delete from sys_secret_project where id = #{id}
    </delete>

    <delete id="deleteSysSecretProjectByIds" parameterType="String">
        delete from sys_secret_project where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <select id="selectCountByProjectId" resultType="java.lang.Integer">
        select count(1) from sys_secret_project  where project_id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>
</mapper>