<?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.CmcCheckMapper">
    
    <resultMap type="CmcCheck" id="CmcCheckResult">
        <result property="checkId"    column="check_id"    />
        <result property="budgetId"    column="budget_id"    />
        <result property="projectId"    column="project_id"    />
        <result property="checker"    column="checker"    />
        <result property="checkTime"    column="check_time"    />
        <result property="checkComment"    column="check_comment"    />
        <result property="totalAdjust"    column="total_adjust"    />
        <result property="cwUserId"    column="cw_user_id"    />
        <result property="cwTime"    column="cw_time"    />
        <result property="cwComment"    column="cw_comment"    />
        <result property="managerUserId"    column="manager_user_id"    />
        <result property="managerTime"    column="manager_time"    />
        <result property="managerComment"    column="manager_comment"    />
        <result property="zjlUserId"    column="zjl_user_id"    />
        <result property="zjlTime"    column="zjl_time"    />
        <result property="zjlComment"    column="zjl_comment"    />
        <association property="checkUser"    javaType="SysUser"         resultMap="CheckUserResult" />
        <association property="cwUser"    javaType="SysUser"         resultMap="CwUserResult" />
        <association property="managerUser"    javaType="SysUser"         resultMap="ManagerUserResult" />
        <association property="zjlUser"    javaType="SysUser"         resultMap="ZjlUserResult" />
        <association property="project"    javaType="CmcProject"         resultMap="CmcProjectResult" />
    </resultMap>

    <resultMap type="SysUser" id="CheckUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="check_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="CwUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="cw_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="CmcProject" id="CmcProjectResult">
        <result property="projectId"    column="project_id"    />
        <result property="projectNumber"    column="project_number"    />
        <result property="projectName"    column="project_name"    />
    </resultMap>

    <sql id="selectCmcCheckVo">
        select c.check_id, c.budget_id, c.project_id, p.project_number, p.project_name, c.checker, u.nick_name as check_nick_name, c.check_time, c.check_comment, c.total_adjust, c.cw_user_id, u1.nick_name as cw_nick_name, c.cw_time,
               c.cw_comment, c.manager_user_id, u2.nick_name as manager_nick_name, c.manager_time, c.manager_comment, c.zjl_user_id, u3.nick_name as zjl_nick_name, c.zjl_time, c.zjl_comment from cmc_check as c
        left join sys_user as u on u.user_id = c.checker
        left join sys_user as u1 on u1.user_id = c.cw_user_id
        left join sys_user as u2 on u2.user_id = c.manager_user_id
        left join sys_user as u3 on u3.user_id = c.zjl_user_id
        left join cmc_project as p on c.project_id = p.project_id
    </sql>

    <select id="selectCmcCheckList" parameterType="CmcCheck" resultMap="CmcCheckResult">
        <include refid="selectCmcCheckVo"/>
        <where>  
            <if test="budgetId != null  and budgetId != ''"> and c.budget_id = #{budgetId}</if>
            <if test="projectId != null  and projectId != ''"> and c.project_id = #{projectId}</if>
            <if test="projectNumber != null  and projectNumber != ''"> and p.project_number like concat('%', #{projectNumber}, '%')</if>
            <if test="checker != null "> and c.checker = #{checker}</if>
            <if test="checkComment != null  and checkComment != ''"> and c.check_comment = #{checkComment}</if>
            <if test="cwUserId != null "> and c.cw_user_id = #{cwUserId}</if>
            <if test="cwTime != null "> and c.cw_time = #{cwTime}</if>
            <if test="cwComment != null  and cwComment != ''"> and c.cw_comment = #{cwComment}</if>
            <if test="managerUserId != null "> and c.manager_user_id = #{managerUserId}</if>
            <if test="managerTime != null "> and c.manager_time = #{managerTime}</if>
            <if test="managerComment != null  and managerComment != ''"> and c.manager_comment = #{managerComment}</if>
            <if test="zjlUserId != null "> and c.zjl_user_id = #{zjlUserId}</if>
            <if test="checkTime != null and @com.ruoyi.common.utils.DateUtils@parseDateToStr('yyyy', checkTime) == '2000' "> and c.check_time is not null</if>
            <if test="checkTime != null and @com.ruoyi.common.utils.DateUtils@parseDateToStr('yyyy', checkTime) != '2000' "> and YEAR(c.check_time) = YEAR(#{checkTime})</if>
            <if test="zjlComment != null  and zjlComment != ''"> and c.zjl_comment = #{zjlComment}</if>
        </where>
    </select>
    
    <select id="selectCmcCheckByCheckId" parameterType="String" resultMap="CmcCheckResult">
        <include refid="selectCmcCheckVo"/>
        where check_id = #{checkId}
    </select>
        
    <insert id="insertCmcCheck" parameterType="CmcCheck">
        insert into cmc_check
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="checkId != null">check_id,</if>
            <if test="budgetId != null">budget_id,</if>
            <if test="projectId != null">project_id,</if>
            <if test="checker != null">checker,</if>
            <if test="checkTime != null">check_time,</if>
            <if test="checkComment != null">check_comment,</if>
            <if test="totalAdjust != null">total_adjust,</if>
            <if test="cwUserId != null">cw_user_id,</if>
            <if test="cwTime != null">cw_time,</if>
            <if test="cwComment != null">cw_comment,</if>
            <if test="managerUserId != null">manager_user_id,</if>
            <if test="managerTime != null">manager_time,</if>
            <if test="managerComment != null">manager_comment,</if>
            <if test="zjlUserId != null">zjl_user_id,</if>
            <if test="zjlTime != null">zjl_time,</if>
            <if test="zjlComment != null">zjl_comment,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="checkId != null">#{checkId},</if>
            <if test="budgetId != null">#{budgetId},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="checker != null">#{checker},</if>
            <if test="checkTime != null">#{checkTime},</if>
            <if test="checkComment != null">#{checkComment},</if>
            <if test="totalAdjust != null">#{totalAdjust},</if>
            <if test="cwUserId != null">#{cwUserId},</if>
            <if test="cwTime != null">#{cwTime},</if>
            <if test="cwComment != null">#{cwComment},</if>
            <if test="managerUserId != null">#{managerUserId},</if>
            <if test="managerTime != null">#{managerTime},</if>
            <if test="managerComment != null">#{managerComment},</if>
            <if test="zjlUserId != null">#{zjlUserId},</if>
            <if test="zjlTime != null">#{zjlTime},</if>
            <if test="zjlComment != null">#{zjlComment},</if>
         </trim>
    </insert>

    <update id="updateCmcCheck" parameterType="CmcCheck">
        update cmc_check
        <trim prefix="SET" suffixOverrides=",">
            <if test="budgetId != null">budget_id = #{budgetId},</if>
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="checker != null">checker = #{checker},</if>
            <if test="checkTime != null">check_time = #{checkTime},</if>
            <if test="checkComment != null">check_comment = #{checkComment},</if>
            <if test="totalAdjust != null">total_adjust = #{totalAdjust},</if>
            <if test="cwUserId != null">cw_user_id = #{cwUserId},</if>
            <if test="cwTime != null">cw_time = #{cwTime},</if>
            <if test="cwComment != null">cw_comment = #{cwComment},</if>
            <if test="managerUserId != null">manager_user_id = #{managerUserId},</if>
            <if test="managerTime != null">manager_time = #{managerTime},</if>
            <if test="managerComment != null">manager_comment = #{managerComment},</if>
            <if test="zjlUserId != null">zjl_user_id = #{zjlUserId},</if>
            <if test="zjlTime != null">zjl_time = #{zjlTime},</if>
            <if test="zjlComment != null">zjl_comment = #{zjlComment},</if>
        </trim>
        where check_id = #{checkId}
    </update>

    <delete id="deleteCmcCheckByCheckId" parameterType="String">
        delete from cmc_check where check_id = #{checkId}
    </delete>

    <delete id="deleteCmcCheckByCheckIds" parameterType="String">
        delete from cmc_check where check_id in 
        <foreach item="checkId" collection="array" open="(" separator="," close=")">
            #{checkId}
        </foreach>
    </delete>
</mapper>