<?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.DmsBaseMaintProjectMapper">
    
    <resultMap type="DmsBaseMaintProject" id="DmsBaseMaintProjectResult">
        <result property="maintProjectId"    column="maint_project_id"    />
        <result property="maintProjectName"    column="maint_project_name"    />
        <result property="maintProjectDesc"    column="maint_project_desc"    />
        <result property="activeFlag"    column="active_flag"    />
        <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="selectDmsBaseMaintProjectVo">
        select dbmp.maint_project_id,
               dbmp.maint_project_name,
               dbmp.maint_project_desc,
               dbmp.active_flag,
               dbmp.remark, dbmp.create_by, dbmp.create_time, dbmp.update_by, dbmp.update_time
        from dms_base_maint_project dbmp
    </sql>

    <sql id="selectDmsBaseMaintProjectMenuVo">
        select dbmp.maint_project_id,
               dbmp.maint_project_name,
               dbmp.maint_project_desc,
               dbmp.active_flag,
               dbmp.remark, dbmp.create_by, dbmp.create_time, dbmp.update_by, dbmp.update_time,
                dbsp.maint_station_id
        from dms_base_maint_project dbmp
        left join dms_base_station_project dbsp on dbmp.maint_project_id = dbsp.maint_project_id
    </sql>

<!--    public List<DmsBaseMaintProject> selectProjectMenuByStationId(Long maintStationId);
        先根据maintStationId去dms_base_station_project中查maintStationId相关的maint_project_id，再从dms_base_maint_project根据maint_project_id-->
    <select id="selectProjectMenuByStationId" parameterType="Long" resultMap="DmsBaseMaintProjectResult">
        <include refid="selectDmsBaseMaintProjectMenuVo"/>
        where dbsp.maint_station_id = #{maintStationId}
    </select>



    <select id="selectDmsBaseMaintProjectList" parameterType="DmsBaseMaintProject" resultMap="DmsBaseMaintProjectResult">
        <include refid="selectDmsBaseMaintProjectVo"/>
        <where>  
            <if test="maintProjectName != null  and maintProjectName != ''"> and dbmp.maint_project_name like '%' || #{maintProjectName} || '%'</if>
            <if test="maintProjectDesc != null  and maintProjectDesc != ''"> and dbmp.maint_project_desc = #{maintProjectDesc}</if>
<!--             <if test="maint_station_id != null"> and dbsp.maint_station_id = #{maintStationId}</if>-->
              <if test="maintProjectId != null"> and dbmp.maint_project_id = #{maintProjectId}</if>
        </where>
    </select>
    
    <select id="selectDmsBaseMaintProjectByMaintProjectId" parameterType="Long" resultMap="DmsBaseMaintProjectResult">
        <include refid="selectDmsBaseMaintProjectVo"/>
        where dbmp.maint_project_id = #{maintProjectId}
    </select>
        
    <insert id="insertDmsBaseMaintProject" parameterType="DmsBaseMaintProject">
        <selectKey keyProperty="maintProjectId" resultType="long" order="BEFORE">
            SELECT HAIWEI.SEQ_DMS_MAINT_PROJ.NEXTVAL FROM DUAL
        </selectKey>
        insert into dms_base_maint_project
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <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="activeFlag != null">active_flag,</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="maintProjectId != null">#{maintProjectId},</if>
            <if test="maintProjectName != null and maintProjectName != ''">#{maintProjectName},</if>
            <if test="maintProjectDesc != null">#{maintProjectDesc},</if>
            <if test="activeFlag != null">#{activeFlag},</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="updateDmsBaseMaintProject" parameterType="DmsBaseMaintProject">
        update dms_base_maint_project
        <trim prefix="SET" suffixOverrides=",">
            <if test="maintProjectName != null and maintProjectName != ''">maint_project_name = #{maintProjectName},</if>
            <if test="maintProjectDesc != null">maint_project_desc = #{maintProjectDesc},</if>
            <if test="activeFlag != null">active_flag = #{activeFlag},</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_project_id = #{maintProjectId}
    </update>

    <delete id="deleteDmsBaseMaintProjectByMaintProjectId" parameterType="Long">
        delete from dms_base_maint_project where maint_project_id = #{maintProjectId}
    </delete>

    <delete id="deleteDmsBaseMaintProjectByMaintProjectIds" parameterType="String">
        delete from dms_base_maint_project where maint_project_id in 
        <foreach item="maintProjectId" collection="array" open="(" separator="," close=")">
            #{maintProjectId}
        </foreach>
    </delete>


</mapper>