<?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.ApplyChildMapper">
    
    <resultMap type="ApplyChild" id="ApplyChildResult">
        <result property="childId"    column="child_id"    />
        <result property="applyId"    column="apply_id"    />
        <result property="danganId"    column="dangan_id"    />
        <result property="danganName"    column="dangan_name"    />
        <result property="loginName"    column="login_name"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectApplyChildVo">
        select ac.child_id, ac.apply_id, ac.dangan_id, d.dangan_name, ac.login_name, ac.status
        from sys_apply_child ac
        left join sys_dangan d on d.dangan_id = ac.dangan_id
    </sql>

    <select id="selectApplyChildList" parameterType="ApplyChild" resultMap="ApplyChildResult">
        <include refid="selectApplyChildVo"/>
        <where>  
            <if test="applyId != null "> and ac.apply_id = #{applyId}</if>
            <if test="danganId != null "> and ac.dangan_id = #{danganId}</if>
            <if test="danganName != null  and danganName != ''"> and d.dangan_name like concat('%', #{danganName}, '%')</if>
            <if test="loginName != null  and loginName != ''"> and ac.login_name like concat('%', #{loginName}, '%')</if>
            <if test="status != null  and status != ''"> and ac.status = #{status}</if>
        </where>
    </select>
    
    <select id="selectApplyChildById" parameterType="Long" resultMap="ApplyChildResult">
        <include refid="selectApplyChildVo"/>
        where ac.child_id = #{childId}
    </select>
        
    <insert id="insertApplyChild" parameterType="ApplyChild" useGeneratedKeys="true" keyProperty="childId">
        insert into sys_apply_child
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="applyId != null">apply_id,</if>
            <if test="danganId != null">dangan_id,</if>
            <if test="danganName != null">dangan_name,</if>
            <if test="loginName != null">login_name,</if>
            <if test="status != null">status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="applyId != null">#{applyId},</if>
            <if test="danganId != null">#{danganId},</if>
            <if test="danganName != null">#{danganName},</if>
            <if test="loginName != null">#{loginName},</if>
            <if test="status != null">#{status},</if>
         </trim>
    </insert>

    <update id="updateApplyChild" parameterType="ApplyChild">
        update sys_apply_child
        <trim prefix="SET" suffixOverrides=",">
            <if test="applyId != null">apply_id = #{applyId},</if>
            <if test="danganId != null">dangan_id = #{danganId},</if>
            <if test="danganName != null">dangan_id = #{danganName},</if>
            <if test="loginName != null">login_name = #{loginName},</if>
            <if test="status != null">status = #{status},</if>
        </trim>
        where child_id = #{childId}
    </update>

    <delete id="deleteApplyChildById" parameterType="Long">
        delete from sys_apply_child where child_id = #{childId}
    </delete>

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

    <insert id="batchChildInfo">
        insert into sys_apply_child (apply_id, dangan_id,login_name,status) values
        <foreach item="item" index="index" collection="list" separator=",">
            (#{item.applyId},#{item.danganId},#{item.loginName},#{item.status})
        </foreach>
    </insert>

</mapper>