<?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.oa.mapper.CmcAssessMapper">

    <resultMap type="CmcAssess" id="CmcAssessResult">
        <result property="assessId"    column="assess_id"    />
        <result property="userId"    column="user_id"    />
        <result property="projectId"    column="project_id"    />
        <result property="assessTime"    column="assess_time"    />
        <result property="deptAssessment"    column="dept_assessment"    />
        <result property="deptAdvice"    column="dept_advice"    />
        <result property="deptTime"    column="dept_time"    />
        <result property="deptAssesser"    column="dept_assesser"    />
        <result property="managerAssessment"    column="manager_assessment"    />
        <result property="managerAdvice"    column="manager_advice"    />
        <result property="managerTime"    column="manager_time"    />
        <result property="managerAssesser"    column="manager_assesser"    />
        <result property="selfAssess"    column="self_assess"    />
        <result property="fillTime"    column="fill_time"    />
        <result property="otherWork"    column="other_work"    />
        <result property="assessType"    column="assess_type"    />
        <association property="user"    javaType="SysUser"         resultMap="UserResult" />
        <association property="deptUser"    javaType="SysUser"         resultMap="DeptUserResult" />
        <association property="managerUser"    javaType="SysUser"         resultMap="ManagerUserResult" />
        <association property="project"    javaType="CmcProject"         resultMap="CmcProjectResult" />
    </resultMap>

    <resultMap type="SysUser" id="UserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="DeptUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="dept_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="ManagerUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="manager_nick_name"    />
    </resultMap>

    <resultMap type="CmcProject" id="CmcProjectResult">
        <result property="projectId"    column="project_id"    />
        <result property="projectNumber"    column="project_number"    />
        <result property="projectName"    column="project_name"    />
    </resultMap>

    <sql id="selectCmcAssessVo">
        select a.assess_id, a.user_id, u.nick_name as nick_name, a.project_id, p.project_number, p.project_name, a.assess_time, a.dept_assessment, a.dept_advice, a.dept_time, a.dept_assesser, u1.nick_name as dept_nick_name, a.manager_assessment,
               a.manager_advice, a.manager_time, a.manager_assesser, u2.nick_name as manager_nick_name, a.self_assess, a.fill_time, a.other_work, a.assess_type from cmc_assess as a
        left join sys_user as u on u.user_id = a.user_id
        left join sys_user as u1 on u1.user_id = a.dept_assesser
        left join sys_user as u2 on u2.user_id = a.manager_assesser
        left join cmc_project as p on p.project_id = a.project_id
    </sql>

    <select id="selectCmcAssessList" parameterType="CmcAssess" resultMap="CmcAssessResult">
        <include refid="selectCmcAssessVo"/>
        <where>
            <if test="assessId != null "> and a.assess_id = #{assessId}</if>
            <if test="userId != null "> and a.user_id = #{userId}</if>
            <if test="projectId != null "> and a.project_id = #{projectId}</if>
            <if test="assessTime != null "> and a.assess_time = #{assessTime}</if>
            <if test="deptAssessment != null  and deptAssessment != ''"> and a.dept_assessment = #{deptAssessment}</if>
            <if test="deptAdvice != null  and deptAdvice != ''"> and a.dept_advice = #{deptAdvice}</if>
            <if test="deptTime != null "> and a.dept_time = #{deptTime}</if>
            <if test="deptAssesser != null  and deptAssesser != ''"> and a.dept_assesser = #{deptAssesser}</if>
            <if test="managerAssessment != null  and managerAssessment != ''"> and a.manager_assessment = #{managerAssessment}</if>
            <if test="managerAdvice != null  and managerAdvice != ''"> and a.manager_advice = #{managerAdvice}</if>
            <if test="managerTime != null "> and a.manager_time = #{managerTime}</if>
            <if test="managerAssesser != null  and managerAssesser != ''"> and a.manager_assesser = #{managerAssesser}</if>
            <if test="selfAssess != null  and selfAssess != ''"> and a.self_assess = #{selfAssess}</if>
            <if test="fillTime != null "> and a.fill_time = #{fillTime}</if>
            <if test="otherWork != null  and otherWork != ''"> and a.other_work = #{otherWork}</if>
            <if test="assessType != null  and assessType != ''"> and a.assess_type = #{assessType}</if>
        </where>
    </select>

    <select id="selectCmcAssessByAssessId" parameterType="String" resultMap="CmcAssessResult">
        <include refid="selectCmcAssessVo"/>
        where a.assess_id = #{assessId}
    </select>

    <insert id="insertCmcAssess" parameterType="CmcAssess">
        insert into cmc_assess
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="assessId != null">assess_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="projectId != null">project_id,</if>
            <if test="assessTime != null">assess_time,</if>
            <if test="deptAssessment != null">dept_assessment,</if>
            <if test="deptAdvice != null">dept_advice,</if>
            <if test="deptTime != null">dept_time,</if>
            <if test="deptAssesser != null">dept_assesser,</if>
            <if test="managerAssessment != null">manager_assessment,</if>
            <if test="managerAdvice != null">manager_advice,</if>
            <if test="managerTime != null">manager_time,</if>
            <if test="managerAssesser != null">manager_assesser,</if>
            <if test="selfAssess != null">self_assess,</if>
            <if test="fillTime != null">fill_time,</if>
            <if test="otherWork != null">other_work,</if>
            <if test="assessType != null">assess_type,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="assessId != null">#{assessId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="assessTime != null">#{assessTime},</if>
            <if test="deptAssessment != null">#{deptAssessment},</if>
            <if test="deptAdvice != null">#{deptAdvice},</if>
            <if test="deptTime != null">#{deptTime},</if>
            <if test="deptAssesser != null">#{deptAssesser},</if>
            <if test="managerAssessment != null">#{managerAssessment},</if>
            <if test="managerAdvice != null">#{managerAdvice},</if>
            <if test="managerTime != null">#{managerTime},</if>
            <if test="managerAssesser != null">#{managerAssesser},</if>
            <if test="selfAssess != null">#{selfAssess},</if>
            <if test="fillTime != null">#{fillTime},</if>
            <if test="otherWork != null">#{otherWork},</if>
            <if test="assessType != null">#{assessType},</if>
        </trim>
    </insert>

    <update id="updateCmcAssess" parameterType="CmcAssess">
        update cmc_assess
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="assessTime != null">assess_time = #{assessTime},</if>
            <if test="deptAssessment != null">dept_assessment = #{deptAssessment},</if>
            <if test="deptAdvice != null">dept_advice = #{deptAdvice},</if>
            <if test="deptTime != null">dept_time = #{deptTime},</if>
            <if test="deptAssesser != null">dept_assesser = #{deptAssesser},</if>
            <if test="managerAssessment != null">manager_assessment = #{managerAssessment},</if>
            <if test="managerAdvice != null">manager_advice = #{managerAdvice},</if>
            <if test="managerTime != null">manager_time = #{managerTime},</if>
            <if test="managerAssesser != null">manager_assesser = #{managerAssesser},</if>
            <if test="selfAssess != null">self_assess = #{selfAssess},</if>
            <if test="fillTime != null">fill_time = #{fillTime},</if>
            <if test="otherWork != null">other_work = #{otherWork},</if>
            <if test="assessType != null">assess_type = #{assessType},</if>
        </trim>
        where assess_id = #{assessId}
    </update>

    <delete id="deleteCmcAssessByAssessId" parameterType="String">
        delete from cmc_assess where assess_id = #{assessId}
    </delete>

    <delete id="deleteCmcAssessByAssessIds" parameterType="String">
        delete from cmc_assess where assess_id in
        <foreach item="assessId" collection="array" open="(" separator="," close=")">
            #{assessId}
        </foreach>
    </delete>
</mapper>