<?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.CmcPerformanceMapper">
    
    <resultMap type="CmcPerformance" id="CmcPerformanceResult">
        <result property="performanceId"    column="performance_id"    />
        <result property="reporter"    column="reporter"    />
        <result property="document"    column="document"    />
        <result property="remark"    column="remark"    />
        <result property="reportTime"    column="report_time"    />
        <result property="reportDept"    column="report_dept"    />
        <result property="managerUserId"    column="manager_user_id"    />
        <result property="managerComment"    column="manager_comment"    />
        <result property="managerTime"    column="manager_time"    />
        <result property="zjlUserId"    column="zjl_user_id"    />
        <result property="zjlComment"    column="zjl_comment"    />
        <result property="zjlTime"    column="zjl_time"    />
        <result property="zhUserId"    column="zh_user_id"    />
        <result property="zhTime"    column="zh_time"    />
        <association property="reportUser"    javaType="SysUser"         resultMap="ReportUserResult" />
        <association property="managerUser"    javaType="SysUser"         resultMap="ManagerUserResult" />
        <association property="zjlUser"    javaType="SysUser"         resultMap="ZjlUserResult" />
        <association property="dept"    javaType="SysDept"         resultMap="SysDeptResult" />
    </resultMap>

    <resultMap type="SysUser" id="ReportUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="report_nick_name"    />
    </resultMap>

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

    <resultMap type="SysUser" id="ZjlUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="zjl_nick_name"    />
    </resultMap>

    <resultMap type="SysDept" id="SysDeptResult">
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="dept_name"    />
    </resultMap>

    <sql id="selectCmcPerformanceVo">
        select p.performance_id, p.reporter, u.nick_name as report_nick_name, p.document, p.remark, p.report_time, p.report_dept, d.dept_name,
               p.manager_user_id, u1.nick_name as manager_nick_name,p.manager_comment, p.manager_time, p.zjl_user_id, u2.nick_name as zjl_nick_name,
               p.zjl_comment, p.zjl_time, p.zh_user_id, p.zh_time from cmc_performance as p
        left join sys_user as u on u.user_id = p.reporter
        left join sys_user as u1 on u1.user_id = p.manager_user_id
        left join sys_user as u2 on u2.user_id = p.zjl_user_id
        left join sys_dept as d on d.dept_id = p.report_dept
    </sql>

    <select id="selectCmcPerformanceList" parameterType="CmcPerformance" resultMap="CmcPerformanceResult">
        <include refid="selectCmcPerformanceVo"/>
        <where>  
            <if test="reporter != null "> and p.reporter = #{reporter}</if>
            <if test="document != null  and document != ''"> and p.document = #{document}</if>
            <if test="reportTime != null "> and date_format(p.report_time, '%y%m') = date_format(#{reportTime}, '%y%m')</if>
            <if test="reportDept != null "> and p.report_dept = #{reportDept}</if>
            <if test="managerUserId != null "> and p.manager_user_id = #{managerUserId}</if>
            <if test="managerComment != null  and managerComment != ''"> and p.manager_comment = #{managerComment}</if>
            <if test="managerTime != null "> and p.manager_time = #{managerTime}</if>
            <if test="zjlUserId != null "> and p.zjl_user_id = #{zjlUserId}</if>
            <if test="zjlComment != null  and zjlComment != ''"> and p.zjl_comment = #{zjlComment}</if>
            <if test="zjlTime != null "> and p.zjl_time = #{zjlTime}</if>
            <if test="zhUserId != null "> and p.zh_user_id = #{zhUserId}</if>
            <if test="zhTime != null "> and p.zh_time = #{zhTime}</if>
        </where>
        order by p.report_time desc
    </select>
    
    <select id="selectCmcPerformanceByPerformanceId" parameterType="String" resultMap="CmcPerformanceResult">
        <include refid="selectCmcPerformanceVo"/>
        where p.performance_id = #{performanceId}
    </select>
        
    <insert id="insertCmcPerformance" parameterType="CmcPerformance">
        insert into cmc_performance
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="performanceId != null">performance_id,</if>
            <if test="reporter != null">reporter,</if>
            <if test="document != null">document,</if>
            <if test="remark != null">remark,</if>
            <if test="reportTime != null">report_time,</if>
            <if test="reportDept != null">report_dept,</if>
            <if test="managerUserId != null">manager_user_id,</if>
            <if test="managerComment != null">manager_comment,</if>
            <if test="managerTime != null">manager_time,</if>
            <if test="zjlUserId != null">zjl_user_id,</if>
            <if test="zjlComment != null">zjl_comment,</if>
            <if test="zjlTime != null">zjl_time,</if>
            <if test="zhUserId != null">zh_user_id,</if>
            <if test="zhTime != null">zh_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="performanceId != null">#{performanceId},</if>
            <if test="reporter != null">#{reporter},</if>
            <if test="document != null">#{document},</if>
            <if test="remark != null">#{remark},</if>
            <if test="reportTime != null">#{reportTime},</if>
            <if test="reportDept != null">#{reportDept},</if>
            <if test="managerUserId != null">#{managerUserId},</if>
            <if test="managerComment != null">#{managerComment},</if>
            <if test="managerTime != null">#{managerTime},</if>
            <if test="zjlUserId != null">#{zjlUserId},</if>
            <if test="zjlComment != null">#{zjlComment},</if>
            <if test="zjlTime != null">#{zjlTime},</if>
            <if test="zhUserId != null">#{zhUserId},</if>
            <if test="zhTime != null">#{zhTime},</if>
         </trim>
    </insert>

    <update id="updateCmcPerformance" parameterType="CmcPerformance">
        update cmc_performance
        <trim prefix="SET" suffixOverrides=",">
            <if test="reporter != null">reporter = #{reporter},</if>
            <if test="document != null">document = #{document},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="reportTime != null">report_time = #{reportTime},</if>
            <if test="reportDept != null">report_dept = #{reportDept},</if>
            <if test="managerUserId != null">manager_user_id = #{managerUserId},</if>
            <if test="managerComment != null">manager_comment = #{managerComment},</if>
            <if test="managerTime != null">manager_time = #{managerTime},</if>
            <if test="zjlUserId != null">zjl_user_id = #{zjlUserId},</if>
            <if test="zjlComment != null">zjl_comment = #{zjlComment},</if>
            <if test="zjlTime != null">zjl_time = #{zjlTime},</if>
            <if test="zhUserId != null">zh_user_id = #{zhUserId},</if>
            <if test="zhTime != null">zh_time = #{zhTime},</if>
        </trim>
        where performance_id = #{performanceId}
    </update>

    <delete id="deleteCmcPerformanceByPerformanceId" parameterType="String">
        delete from cmc_performance where performance_id = #{performanceId}
    </delete>

    <delete id="deleteCmcPerformanceByPerformanceIds" parameterType="String">
        delete from cmc_performance where performance_id in 
        <foreach item="performanceId" collection="array" open="(" separator="," close=")">
            #{performanceId}
        </foreach>
    </delete>
</mapper>