<?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.branch.mapper.TBranchAssessMapper">
    
    <resultMap type="TBranchAssess" id="TBranchAssessResult">
        <result property="assessId"    column="assess_id"    />
        <result property="assessMember"    column="assess_member"    />
        <result property="assessTime"    column="assess_time"    />
        <result property="assessScore"    column="assess_score"    />
        <result property="deptId"    column="dept_id"    />
        <result property="delFlag"    column="del_flag"    />
        <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="nickName"    column="nick_name"    />
    </resultMap>

    <sql id="selectTBranchAssessVo">
        select u.assess_id, u.assess_member, u.assess_time, u.assess_score, u.dept_id, u.del_flag, u.create_by, u.create_time, u.update_by, u.update_time,
        us.NICK_NAME
        from t_branch_assess u
            left join sys_dept d on u.dept_id = d.dept_id
            left join SYS_USER us on us.user_id = u.assess_member
    </sql>

    <select id="selectTBranchAssessList" parameterType="TBranchAssess" resultMap="TBranchAssessResult">
        <include refid="selectTBranchAssessVo"/>
        <where>  
            <if test="assessId != null "> and u.assess_id = #{assessId}</if>
            <if test="assessMember != null  and assessMember != ''"> and u.assess_member = #{assessMember}</if>
            <if test="assessTime != null "> and u.assess_time = #{assessTime}</if>
            <if test="assessScore != null "> and u.assess_score = #{assessScore}</if>
            <if test="deptId != null "> and u.dept_id = #{deptId}</if>
            <if test="nickName != null  and nickName != ''"> and us.nick_name like concat(concat('%', #{nickName}), '%')</if>
            and u.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectTBranchAssessByAssessId" parameterType="Long" resultMap="TBranchAssessResult">
        <include refid="selectTBranchAssessVo"/>
        where u.assess_id = #{assessId}
        and u.del_flag = 0
    </select>
        
    <insert id="insertTBranchAssess" parameterType="TBranchAssess">
        <selectKey keyProperty="assessId" resultType="long" order="BEFORE">
            SELECT seq_t_branch_assess.NEXTVAL as assessId FROM DUAL
        </selectKey>
        insert into t_branch_assess
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="assessId != null">assess_id,</if>
            <if test="assessMember != null">assess_member,</if>
            <if test="assessTime != null">assess_time,</if>
            <if test="assessScore != null">assess_score,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="delFlag != null">del_flag,</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="assessId != null">#{assessId},</if>
            <if test="assessMember != null">#{assessMember},</if>
            <if test="assessTime != null">#{assessTime},</if>
            <if test="assessScore != null">#{assessScore},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="delFlag != null">#{delFlag},</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>

    <update id="updateTBranchAssess" parameterType="TBranchAssess">
        update t_branch_assess
        <trim prefix="SET" suffixOverrides=",">
            <if test="assessMember != null">assess_member = #{assessMember},</if>
            <if test="assessTime != null">assess_time = #{assessTime},</if>
            <if test="assessTime == null">assess_time = null,</if>
            <if test="assessScore != null">assess_score = #{assessScore},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</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 assess_id = #{assessId}
    </update>

    <update id="deleteTBranchAssessByAssessId" parameterType="Long">
        update t_branch_assess set del_flag = 2 where assess_id = #{assessId}
    </update>

    <update id="deleteTBranchAssessByAssessIds" parameterType="String">
        update t_branch_assess set del_flag = 2 where assess_id in
        <foreach item="assessId" collection="array" open="(" separator="," close=")">
            #{assessId}
        </foreach>
    </update>
</mapper>