<?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.aucma.dms.mapper.DmsRepairProjectMapper">
    
    <resultMap type="DmsRepairProject" id="DmsRepairProjectResult">
        <result property="projectId"    column="project_id"    />
        <result property="workOrderId"    column="work_order_id"    />
        <result property="projectSeq"    column="project_seq"    />
        <result property="projectName"    column="project_name"    />
        <result property="projectType"    column="project_type"    />
        <result property="projectContent"    column="project_content"    />
        <result property="technicalRequirement"    column="technical_requirement"    />
        <result property="planHours"    column="plan_hours"    />
        <result property="actualHours"    column="actual_hours"    />
        <result property="executionStatus"    column="execution_status"    />
        <result property="executor"    column="executor"    />
        <result property="qualityLevel"    column="quality_level"    />
        <result property="remark"    column="remark"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectDmsRepairProjectVo">
        select project_id, work_order_id, project_seq, project_name, project_type, 
               project_content, technical_requirement, plan_hours, actual_hours, 
               execution_status, executor, quality_level, remark, 
               create_by, create_time, update_by, update_time
        from dms_repair_project
    </sql>

    <select id="selectDmsRepairProjectList" parameterType="DmsRepairProject" resultMap="DmsRepairProjectResult">
        <include refid="selectDmsRepairProjectVo"/>
        <where>
            <if test="workOrderId != null">
                and work_order_id = #{workOrderId}
            </if>
            <if test="projectName != null and projectName != ''">
                and project_name like '%' || #{projectName} || '%'
            </if>
            <if test="projectType != null and projectType != ''">
                and project_type = #{projectType}
            </if>
            <if test="executionStatus != null and executionStatus != ''">
                and execution_status = #{executionStatus}
            </if>
        </where>
        order by project_seq
    </select>
    
    <select id="selectDmsRepairProjectByProjectId" parameterType="Long" resultMap="DmsRepairProjectResult">
        <include refid="selectDmsRepairProjectVo"/>
        where project_id = #{projectId}
    </select>
        
    <insert id="insertDmsRepairProject" parameterType="DmsRepairProject">
        <selectKey keyProperty="projectId" resultType="long" order="BEFORE">
            select HAIWEI.SEQ_DMS_REPAIR_PROJECT.nextval as projectId from DUAL
        </selectKey>
        insert into dms_repair_project
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="projectId != null">project_id,</if>
            <if test="workOrderId != null">work_order_id,</if>
            <if test="projectSeq != null">project_seq,</if>
            <if test="projectName != null">project_name,</if>
            <if test="projectType != null">project_type,</if>
            <if test="projectContent != null">project_content,</if>
            <if test="technicalRequirement != null">technical_requirement,</if>
            <if test="planHours != null">plan_hours,</if>
            <if test="actualHours != null">actual_hours,</if>
            <if test="executionStatus != null">execution_status,</if>
            <if test="executor != null">executor,</if>
            <if test="qualityLevel != null">quality_level,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null">create_by,</if>
            create_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="projectId != null">#{projectId},</if>
            <if test="workOrderId != null">#{workOrderId},</if>
            <if test="projectSeq != null">#{projectSeq},</if>
            <if test="projectName != null">#{projectName},</if>
            <if test="projectType != null">#{projectType},</if>
            <if test="projectContent != null">#{projectContent},</if>
            <if test="technicalRequirement != null">#{technicalRequirement},</if>
            <if test="planHours != null">#{planHours},</if>
            <if test="actualHours != null">#{actualHours},</if>
            <if test="executionStatus != null">#{executionStatus},</if>
            <if test="executor != null">#{executor},</if>
            <if test="qualityLevel != null">#{qualityLevel},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null">#{createBy},</if>
            sysdate
        </trim>
    </insert>

    <update id="updateDmsRepairProject" parameterType="DmsRepairProject">
        update dms_repair_project
        <trim prefix="SET" suffixOverrides=",">
            <if test="workOrderId != null">work_order_id = #{workOrderId},</if>
            <if test="projectSeq != null">project_seq = #{projectSeq},</if>
            <if test="projectName != null">project_name = #{projectName},</if>
            <if test="projectType != null">project_type = #{projectType},</if>
            <if test="projectContent != null">project_content = #{projectContent},</if>
            <if test="technicalRequirement != null">technical_requirement = #{technicalRequirement},</if>
            <if test="planHours != null">plan_hours = #{planHours},</if>
            <if test="actualHours != null">actual_hours = #{actualHours},</if>
            <if test="executionStatus != null">execution_status = #{executionStatus},</if>
            <if test="executor != null">executor = #{executor},</if>
            <if test="qualityLevel != null">quality_level = #{qualityLevel},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            update_time = sysdate
        </trim>
        where project_id = #{projectId}
    </update>

    <delete id="deleteDmsRepairProjectByProjectId" parameterType="Long">
        delete from dms_repair_project where project_id = #{projectId}
    </delete>

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

    <delete id="deleteDmsRepairProjectByWorkOrderId" parameterType="Long">
        delete from dms_repair_project where work_order_id = #{workOrderId}
    </delete>
</mapper>
