<?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.CmcProjectWorkMapper">
    
    <resultMap type="CmcProjectWork" id="CmcProjectWorkResult">
        <result property="workId"    column="work_id"    />
        <result property="projectId"    column="project_id"    />
        <result property="content"    column="content"    />
        <result property="scale"    column="scale"    />
        <result property="unit"    column="unit"    />
        <result property="workload"    column="workload"    />
        <result property="deadline"    column="deadline"    />
        <result property="finishTime"    column="finish_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectCmcProjectWorkVo">
        select work_id, project_id, content, scale, unit, workload, deadline, finish_time, remark from cmc_project_work
    </sql>

    <select id="selectCmcProjectWorkList" parameterType="CmcProjectWork" resultMap="CmcProjectWorkResult">
        <include refid="selectCmcProjectWorkVo"/>
        <where>  
            <if test="projectId != null  and projectId != ''"> and project_id = #{projectId}</if>
            <if test="content != null  and content != ''"> and content like concat('%', #{content}, '%')</if>
            <if test="scale != null  and scale != ''"> and scale like concat('%', #{scale}, '%')</if>
            <if test="unit != null  and unit != ''"> and unit like concat('%', #{unit}, '%')</if>
            <if test="workload != null  and workload != ''"> and workload = #{workload}</if>
            <if test="deadline != null "> and deadline like concat('%', #{deadline}, '%')</if>
            <if test="finishTime != null "> and finish_time like concat('%', #{finishTime}, '%')</if>
        </where>
        order by deadline desc
    </select>
    
    <select id="selectCmcProjectWorkListByProjectId" parameterType="String" resultMap="CmcProjectWorkResult">
        <include refid="selectCmcProjectWorkVo"/>
        where project_id = #{projectId}
    </select>
        
    <insert id="insertCmcProjectWork" parameterType="CmcProjectWork">
        insert into cmc_project_work
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="workId != null">work_id,</if>
            <if test="projectId != null">project_id,</if>
            <if test="content != null">content,</if>
            <if test="scale != null">scale,</if>
            <if test="unit != null">unit,</if>
            <if test="workload != null">workload,</if>
            <if test="deadline != null">deadline,</if>
            <if test="finishTime != null">finish_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="workId != null">#{workId},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="content != null">#{content},</if>
            <if test="scale != null">#{scale},</if>
            <if test="unit != null">#{unit},</if>
            <if test="workload != null">#{workload},</if>
            <if test="deadline != null">#{deadline},</if>
            <if test="finishTime != null">#{finishTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateCmcProjectWork" parameterType="CmcProjectWork">
        update cmc_project_work
        <trim prefix="SET" suffixOverrides=",">
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="content != null">content = #{content},</if>
            <if test="scale != null">scale = #{scale},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="workload != null">workload = #{workload},</if>
            <if test="deadline != null">deadline = #{deadline},</if>
            <if test="finishTime != null">finish_time = #{finishTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where work_id = #{workId}
    </update>

    <delete id="deleteCmcProjectWorkByProjectId" parameterType="String">
        delete from cmc_project_work where project_id = #{projectId}
    </delete>

    <delete id="deleteCmcProjectWorkByProjectIds" parameterType="String">
        delete from cmc_project_work where project_id in
        <foreach item="projectId" collection="array" open="(" separator="," close=")">
            #{projectId}
        </foreach>
    </delete>
</mapper>