<?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.SysApplyConfigMapper">
    
    <resultMap type="SysApplyConfig" id="SysApplyConfigResult">
        <result property="id"    column="id"    />
        <result property="cfgType"    column="cfg_type"    />
        <result property="cfgId"    column="cfg_id"    />
        <result property="appId"    column="app_id"    />
        <result property="publicKey"    column="public_key"    />
        <result property="privateKey"    column="private_key"    />
        <result property="projectId"    column="project_id"    />
        <result property="projectName"    column="projectName"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="deptName"    />
        <result property="isDel"    column="is_del"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectSysApplyConfigVo">
        select sac.id, sac.cfg_type, sac.cfg_id, sac.app_id, sac.public_key, sac.private_key, sac.project_id, sp.projectName, sac.dept_id, sd.dept_name as deptName, sac.is_del, sac.create_by, sac.create_time, sac.update_by, sac.update_time, sac.remark from sys_apply_config sac
        left join sur_project sp on sac.project_id = sp.id
        left join sys_dept sd on sac.dept_id = sd.dept_id
    </sql>

    <select id="selectSysApplyConfigList" parameterType="SysApplyConfig" resultMap="SysApplyConfigResult">
        <include refid="selectSysApplyConfigVo"/>
        <where>
            <if test="cfgId != null "> and sac.cfg_id = #{cfgId}</if>
            <if test="cfgType != null "> and sac.cfg_type = #{cfgType}</if>
            <if test="appId != null "> and sac.app_id like concat('%', #{appId}, '%')</if>
            <if test="projectName != null "> and sp.projectName like concat('%', #{projectName}, '%')</if>
            <if test="deptName != null "> and sd.dept_name like concat('%', #{deptName}, '%')</if>
            <if test="isDel != null  and isDel != ''"> and sac.is_del = #{isDel}</if>
        </where>
        order by sac.id desc
    </select>
    
    <select id="selectSysApplyConfigById" parameterType="Long" resultMap="SysApplyConfigResult">
        <include refid="selectSysApplyConfigVo"/>
        where sac.id = #{id}
    </select>
        
    <insert id="insertSysApplyConfig" parameterType="SysApplyConfig">
        insert into sys_apply_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="cfgType != null">cfg_type,</if>
            <if test="cfgId != null">cfg_id,</if>
            <if test="appId != null">app_id,</if>
            <if test="publicKey != null">public_key,</if>
            <if test="privateKey != null">private_key,</if>
            <if test="projectId != null">project_id,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="isDel != null">is_del,</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>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="cfgType != null">#{cfgType},</if>
            <if test="cfgId != null">#{cfgId},</if>
            <if test="appId != null">#{appId},</if>
            <if test="publicKey != null">#{publicKey},</if>
            <if test="privateKey != null">#{privateKey},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="isDel != null">#{isDel},</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>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateSysApplyConfig" parameterType="SysApplyConfig">
        update sys_apply_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="cfgType != null">cfg_type = #{cfgType},</if>
            <if test="cfgId != null">cfg_id = #{cfgId},</if>
            <if test="appId != null">app_id = #{appId},</if>
            <if test="publicKey != null">public_key = #{publicKey},</if>
            <if test="privateKey != null">private_key = #{privateKey},</if>
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="isDel != null">is_del = #{isDel},</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>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysApplyConfigById" parameterType="Long">
        delete from sys_apply_config where id = #{id}
    </delete>

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

</mapper>