<?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.DmsBillsMaintDetailProjectMapper">
    
    <resultMap type="DmsBillsMaintDetailProject" id="DmsBillsMaintDetailProjectResult">
        <result property="maintDetailProjectId"    column="maint_detail_project_id"    />
        <result property="billsMaintDetailId"    column="bills_maint_detail_id"    />
        <result property="maintProjectId"    column="maint_project_id"    />
        <result property="maintProjectName"    column="maint_project_name"    />
        <result property="maintProjectDesc"    column="maint_project_desc"    />
        <result property="maintProjectStatus"    column="maint_project_status"    />
        <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="selectDmsBillsMaintDetailProjectVo">
        select maint_detail_project_id, bills_maint_detail_id, maint_project_id, maint_project_name, maint_project_desc, maint_project_status, remark, create_by, create_time, update_by, update_time from dms_bills_maint_detail_project
    </sql>

    <select id="selectDmsBillsMaintDetailProjectList" parameterType="DmsBillsMaintDetailProject" resultMap="DmsBillsMaintDetailProjectResult">
        <include refid="selectDmsBillsMaintDetailProjectVo"/>
        <where>  
            <if test="billsMaintDetailId != null "> and bills_maint_detail_id = #{billsMaintDetailId}</if>
            <if test="maintProjectId != null "> and maint_project_id = #{maintProjectId}</if>
            <if test="maintProjectName != null  and maintProjectName != ''"> and maint_project_name like concat('%', #{maintProjectName}, '%')</if>
            <if test="maintProjectDesc != null  and maintProjectDesc != ''"> and maint_project_desc = #{maintProjectDesc}</if>
            <if test="maintProjectStatus != null  and maintProjectStatus != ''"> and maint_project_status = #{maintProjectStatus}</if>
        </where>
    </select>
    
    <select id="selectDmsBillsMaintDetailProjectByMaintDetailProjectId" parameterType="Long" resultMap="DmsBillsMaintDetailProjectResult">
        <include refid="selectDmsBillsMaintDetailProjectVo"/>
        where maint_detail_project_id = #{maintDetailProjectId}
    </select>
        
    <insert id="insertDmsBillsMaintDetailProject" parameterType="DmsBillsMaintDetailProject">
        <selectKey keyProperty="maintDetailProjectId" resultType="long" order="BEFORE">
            SELECT HAIWEI.SEQ_DMS_MAINT_DTL_PROJ.NEXTVAL FROM DUAL
        </selectKey>
        insert into dms_bills_maint_detail_project
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="maintDetailProjectId != null">maint_detail_project_id,</if>
            <if test="billsMaintDetailId != null">bills_maint_detail_id,</if>
            <if test="maintProjectId != null">maint_project_id,</if>
            <if test="maintProjectName != null and maintProjectName != ''">maint_project_name,</if>
            <if test="maintProjectDesc != null">maint_project_desc,</if>
            <if test="maintProjectStatus != null and maintProjectStatus != ''">maint_project_status,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="maintDetailProjectId != null">#{maintDetailProjectId},</if>
            <if test="billsMaintDetailId != null">#{billsMaintDetailId},</if>
            <if test="maintProjectId != null">#{maintProjectId},</if>
            <if test="maintProjectName != null and maintProjectName != ''">#{maintProjectName},</if>
            <if test="maintProjectDesc != null">#{maintProjectDesc},</if>
            <if test="maintProjectStatus != null and maintProjectStatus != ''">#{maintProjectStatus},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateDmsBillsMaintDetailProject" parameterType="DmsBillsMaintDetailProject">
        update dms_bills_maint_detail_project
        <trim prefix="SET" suffixOverrides=",">
            <if test="billsMaintDetailId != null">bills_maint_detail_id = #{billsMaintDetailId},</if>
            <if test="maintProjectId != null">maint_project_id = #{maintProjectId},</if>
            <if test="maintProjectName != null and maintProjectName != ''">maint_project_name = #{maintProjectName},</if>
            <if test="maintProjectDesc != null">maint_project_desc = #{maintProjectDesc},</if>
            <if test="maintProjectStatus != null and maintProjectStatus != ''">maint_project_status = #{maintProjectStatus},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where maint_detail_project_id = #{maintDetailProjectId}
    </update>

    <delete id="deleteDmsBillsMaintDetailProjectByMaintDetailProjectId" parameterType="Long">
        delete from dms_bills_maint_detail_project where maint_detail_project_id = #{maintDetailProjectId}
    </delete>

    <delete id="deleteDmsBillsMaintDetailProjectByMaintDetailProjectIds" parameterType="String">
        delete from dms_bills_maint_detail_project where maint_detail_project_id in 
        <foreach item="maintDetailProjectId" collection="array" open="(" separator="," close=")">
            #{maintDetailProjectId}
        </foreach>
    </delete>
</mapper>