<?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.CmcSettleMapper">
    
    <resultMap type="CmcSettle" id="CmcSettleResult">
        <result property="settleId"    column="settle_id"    />
        <result property="projectId"    column="project_id"    />
        <result property="workloadReport"    column="workload_report"    />
        <result property="reporter"    column="reporter"    />
        <result property="reportTime"    column="report_time"    />
        <result property="settleComment"    column="settle_comment"    />
        <result property="zhUserId"    column="zh_user_id"    />
        <result property="zhTime"    column="zh_time"    />
        <result property="zhComment"    column="zh_comment"    />
        <result property="jsUserId"    column="js_user_id"    />
        <result property="jsTime"    column="js_time"    />
        <result property="jsComment"    column="js_comment"    />
        <result property="jyUserId"    column="jy_user_id"    />
        <result property="jyTime"    column="jy_time"    />
        <result property="jyComment"    column="jy_comment"    />
        <result property="managerUserId"    column="manager_user_id"    />
        <result property="managerTime"    column="manager_time"    />
        <result property="managerComment"    column="manager_comment"    />
        <result property="gmUserId"    column="gm_user_id"    />
        <result property="gmTime"    column="gm_time"    />
        <result property="gmComment"    column="gm_comment"    />
        <result property="dszUserId"    column="dsz_user_id"    />
        <result property="dszTime"    column="dsz_time"    />
        <result property="dszComment"    column="dsz_comment"    />
        <result property="settleDocument"    column="settle_document"    />
        <result property="modifyDocument"    column="modify_document"    />
        <result property="finalDocument"    column="final_document"    />
        <association property="reporterUser"    javaType="SysUser"         resultMap="ReporterUserResult" />
        <association property="zhUser"    javaType="SysUser"         resultMap="ZhUserResult" />
        <association property="jsUser"    javaType="SysUser"         resultMap="JsUserResult" />
        <association property="jyUser"    javaType="SysUser"         resultMap="JyUserResult" />
        <association property="managerUser"    javaType="SysUser"         resultMap="ManagerUserResult" />
        <association property="gmUser"    javaType="SysUser"         resultMap="GmUserResult" />
        <association property="dszUser"    javaType="SysUser"         resultMap="DszUserResult" />
        <association property="project"    javaType="CmcProject"         resultMap="CmcProjectResult" />
    </resultMap>

    <resultMap type="SysUser" id="ReporterUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="reporter_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="ZhUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="zh_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="JsUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="js_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="JyUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="jy_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="GmUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="gm_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="DszUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="dsz_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="selectCmcSettleVo">
        select s.settle_id, s.project_id, p.project_number, p.project_name, s.workload_report, s.reporter, u.nick_name as reporter_nick_name, s.report_time, s.settle_comment, s.zh_user_id, u1.nick_name as zh_nick_name,
               s.zh_time, s.zh_comment, s.js_user_id, u2.nick_name as js_nick_name, s.js_time, s.js_comment, s.jy_user_id, u3.nick_name as jy_nick_name, s.jy_time, s.jy_comment, 
               s.manager_user_id, u4.nick_name as manager_nick_name, s.manager_time, s.manager_comment, s.gm_user_id, u5.nick_name as gm_nick_name, s.gm_time, s.gm_comment,
               s.dsz_user_id, u6.nick_name as dsz_nick_name, s.dsz_time, s.dsz_comment, s.settle_document, s.modify_document, s.final_document from cmc_settle as s
        left join sys_user as u on u.user_id = s.reporter
        left join sys_user as u1 on u1.user_id = s.zh_user_id
        left join sys_user as u2 on u2.user_id = s.js_user_id
        left join sys_user as u3 on u3.user_id = s.jy_user_id
        left join sys_user as u4 on u4.user_id = s.manager_user_id
        left join sys_user as u5 on u5.user_id = s.gm_user_id
        left join sys_user as u6 on u6.user_id = s.dsz_user_id
        left join cmc_project as p on p.project_id = s.project_id
    </sql>

    <select id="selectCmcSettleList" parameterType="CmcSettle" resultMap="CmcSettleResult">
        <include refid="selectCmcSettleVo"/>
        <where>
            <if test="settleId != null  and settleId != ''"> and s.settle_id = #{settleId}</if>
            <if test="projectId != null  and projectId != ''"> and s.project_id = #{projectId}</if>
            <if test="workloadReport != null  and workloadReport != ''"> and s.workload_report = #{workloadReport}</if>
            <if test="reporter != null "> and s.reporter = #{reporter}</if>
            <if test="reportTime != null "> and s.report_time = #{reportTime}</if>
            <if test="settleComment != null  and settleComment != ''"> and s.settle_comment = #{settleComment}</if>
            <if test="zhUserId != null "> and s.zh_user_id = #{zhUserId}</if>
            <if test="zhTime != null "> and s.zh_time = #{zhTime}</if>
            <if test="zhComment != null  and zhComment != ''"> and s.zh_comment = #{zhComment}</if>
            <if test="jsUserId != null "> and s.js_user_id = #{jsUserId}</if>
            <if test="jsTime != null "> and s.js_time = #{jsTime}</if>
            <if test="jsComment != null  and jsComment != ''"> and s.js_comment = #{jsComment}</if>
            <if test="jyUserId != null "> and s.jy_user_id = #{jyUserId}</if>
            <if test="jyTime != null "> and s.jy_time = #{jyTime}</if>
            <if test="jyComment != null  and jyComment != ''"> and s.jy_comment = #{jyComment}</if>
            <if test="managerUserId != null "> and s.manager_user_id = #{managerUserId}</if>
            <if test="managerTime != null "> and s.manager_time = #{managerTime}</if>
            <if test="managerComment != null  and managerComment != ''"> and s.manager_comment = #{managerComment}</if>
            <if test="gmUserId != null "> and s.gm_user_id = #{gmUserId}</if>
            <if test="gmTime != null "> and s.gm_time = #{gmTime}</if>
            <if test="gmComment != null  and gmComment != ''"> and s.gm_comment = #{gmComment}</if>
        </where>
        order by s.report_time desc
    </select>
    
    <select id="selectCmcSettleBySettleId" parameterType="String" resultMap="CmcSettleResult">
        <include refid="selectCmcSettleVo"/>
        where s.settle_id = #{settleId}
    </select>
        
    <insert id="insertCmcSettle" parameterType="CmcSettle">
        insert into cmc_settle
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="settleId != null">settle_id,</if>
            <if test="projectId != null">project_id,</if>
            <if test="workloadReport != null">workload_report,</if>
            <if test="reporter != null">reporter,</if>
            <if test="reportTime != null">report_time,</if>
            <if test="settleComment != null">settle_comment,</if>
            <if test="zhUserId != null">zh_user_id,</if>
            <if test="zhTime != null">zh_time,</if>
            <if test="zhComment != null">zh_comment,</if>
            <if test="jsUserId != null">js_user_id,</if>
            <if test="jsTime != null">js_time,</if>
            <if test="jsComment != null">js_comment,</if>
            <if test="jyUserId != null">jy_user_id,</if>
            <if test="jyTime != null">jy_time,</if>
            <if test="jyComment != null">jy_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="gmUserId != null">gm_user_id,</if>
            <if test="gmTime != null">gm_time,</if>
            <if test="gmComment != null">gm_comment,</if>
            <if test="dszUserId != null">dsz_user_id,</if>
            <if test="dszTime != null">dsz_time,</if>
            <if test="dszComment != null">dsz_comment,</if>
            <if test="settleDocument != null">settle_document,</if>
            <if test="modifyDocument != null">modify_document,</if>
            <if test="finalDocument != null">final_document,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="settleId != null">#{settleId},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="workloadReport != null">#{workloadReport},</if>
            <if test="reporter != null">#{reporter},</if>
            <if test="reportTime != null">#{reportTime},</if>
            <if test="settleComment != null">#{settleComment},</if>
            <if test="zhUserId != null">#{zhUserId},</if>
            <if test="zhTime != null">#{zhTime},</if>
            <if test="zhComment != null">#{zhComment},</if>
            <if test="jsUserId != null">#{jsUserId},</if>
            <if test="jsTime != null">#{jsTime},</if>
            <if test="jsComment != null">#{jsComment},</if>
            <if test="jyUserId != null">#{jyUserId},</if>
            <if test="jyTime != null">#{jyTime},</if>
            <if test="jyComment != null">#{jyComment},</if>
            <if test="managerUserId != null">#{managerUserId},</if>
            <if test="managerTime != null">#{managerTime},</if>
            <if test="managerComment != null">#{managerComment},</if>
            <if test="gmUserId != null">#{gmUserId},</if>
            <if test="gmTime != null">#{gmTime},</if>
            <if test="gmComment != null">#{gmComment},</if>
            <if test="dszUserId != null">#{dszUserId},</if>
            <if test="dszTime != null">#{dszTime},</if>
            <if test="dszComment != null">#{dszComment},</if>
            <if test="settleDocument != null">#{settleDocument},</if>
            <if test="modifyDocument != null">#{modifyDocument},</if>
            <if test="finalDocument != null">#{finalDocument},</if>
         </trim>
    </insert>

    <update id="updateCmcSettle" parameterType="CmcSettle">
        update cmc_settle
        <trim prefix="SET" suffixOverrides=",">
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="workloadReport != null">workload_report = #{workloadReport},</if>
            <if test="reporter != null">reporter = #{reporter},</if>
            <if test="reportTime != null">report_time = #{reportTime},</if>
            <if test="settleComment != null">settle_comment = #{settleComment},</if>
            <if test="zhUserId != null">zh_user_id = #{zhUserId},</if>
            <if test="zhTime != null">zh_time = #{zhTime},</if>
            <if test="zhComment != null">zh_comment = #{zhComment},</if>
            <if test="jsUserId != null">js_user_id = #{jsUserId},</if>
            <if test="jsTime != null">js_time = #{jsTime},</if>
            <if test="jsComment != null">js_comment = #{jsComment},</if>
            <if test="jyUserId != null">jy_user_id = #{jyUserId},</if>
            <if test="jyTime != null">jy_time = #{jyTime},</if>
            <if test="jyComment != null">jy_comment = #{jyComment},</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="gmUserId != null">gm_user_id = #{gmUserId},</if>
            <if test="gmTime != null">gm_time = #{gmTime},</if>
            <if test="gmComment != null">gm_comment = #{gmComment},</if>
            <if test="dszUserId != null">dsz_user_id = #{dszUserId},</if>
            <if test="dszTime != null">dsz_time = #{dszTime},</if>
            <if test="dszComment != null">dsz_comment = #{dszComment},</if>
            <if test="settleDocument != null">settle_document = #{settleDocument},</if>
            <if test="modifyDocument != null">modify_document = #{modifyDocument},</if>
            <if test="finalDocument != null">final_document = #{finalDocument},</if>
        </trim>
        where settle_id = #{settleId}
    </update>

    <delete id="deleteCmcSettleBySettleId" parameterType="String">
        delete from cmc_settle where settle_id = #{settleId}
    </delete>

    <delete id="deleteCmcSettleBySettleIds" parameterType="String">
        delete from cmc_settle where settle_id in 
        <foreach item="settleId" collection="array" open="(" separator="," close=")">
            #{settleId}
        </foreach>
    </delete>
</mapper>