<?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.ProposalUserMapper">
    
    <resultMap type="ProposalUser" id="ProposalUserResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="proposalId"    column="proposal_id"    />
        <result property="name"    column="name"    />
        <result property="unit"    column="unit"    />
        <result property="type"    column="type"    />
        <result property="isAgree"    column="is_agree"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectProposalUserVo">
        select id, user_id, proposal_id, name, unit, type,is_agree, remark from proposal_user
    </sql>

    <select id="selectProposalUserList" parameterType="ProposalUser" resultMap="ProposalUserResult">
        <include refid="selectProposalUserVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="proposalId != null "> and proposal_id = #{proposalId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="unit != null  and unit != ''"> and unit = #{unit}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="isAgree != null  and isAgree != ''"> and is_agree = #{isAgree}</if>
        </where>
    </select>
    
    <select id="selectProposalUserById" parameterType="Long" resultMap="ProposalUserResult">
        <include refid="selectProposalUserVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertProposalUser" parameterType="ProposalUser" useGeneratedKeys="true" keyProperty="id">
        insert into proposal_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null "> user_id,</if>
            <if test="proposalId != null">proposal_id,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="unit != null and unit != ''">unit,</if>
            <if test="type != null">type,</if>
            <if test="isAgree != null ">  is_agree ,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null "> #{userId},</if>
            <if test="proposalId != null">#{proposalId},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="unit != null and unit != ''">#{unit},</if>
            <if test="type != null">#{type},</if>
            <if test="isAgree != null"> #{isAgree},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateProposalUser" parameterType="ProposalUser">
        update proposal_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null "> user_id = #{userId},</if>
            <if test="proposalId != null">proposal_id = #{proposalId},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="unit != null and unit != ''">unit = #{unit},</if>
            <if test="type != null">type = #{type},</if>
            <if test="isAgree != null "> is_agree = #{isAgree},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>
    <update id="updateProposalUserVerify" parameterType="com.ruoyi.system.domain.ProposalUser">
        update proposal_user set is_agree = #{isAgree} where proposal_id = #{proposalId} and type = #{type}
    </update>

    <delete id="deleteProposalUserById" parameterType="Long">
        delete from proposal_user where id = #{id}
    </delete>

    <delete id="deleteProposalUserByIds" parameterType="String">
        delete from proposal_user where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <delete id="deleteProposalUserByProposalId" parameterType="java.lang.Long">
        delete from proposal_user where proposal_id = #{proposalId}
    </delete>
</mapper>