<?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.DmsBaseMaintStandardMapper">

    <resultMap type="DmsBaseMaintStandard" id="DmsBaseMaintStandardResult">
        <result property="maintStandardId"    column="maint_standard_id"    />
        <result property="maintStandardCode"    column="maint_standard_code"    />
        <result property="deviceTypeId"    column="device_type_id"    />
        <result property="maintProtocol"    column="maint_protocol"    />
        <result property="operationDescription"    column="operation_description"    />
        <result property="isFlag"    column="is_flag"    />
        <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="selectDmsBaseMaintStandardVo">
        select maint_standard_id, maint_standard_code, device_type_id, maint_protocol, operation_description, is_flag, active_flag, remark, create_by, create_time, update_by, update_time from dms_base_maint_standard
    </sql>

    <select id="selectDmsBaseMaintStandardList" parameterType="DmsBaseMaintStandard" resultMap="DmsBaseMaintStandardResult">
        select a.maint_standard_id, a.maint_standard_code, a.device_type_id, a.maint_protocol, a.operation_description, a.is_flag, a.active_flag, a.remark, a.create_by, a.create_time, a.update_by, a.update_time
        from dms_base_maint_standard a
        <where>
            <if test="maintStandardCode != null  and maintStandardCode != ''"> and a.maint_standard_code like '%' || #{maintStandardCode} || '%' </if>
            <if test="deviceTypeId != null "> and a.device_type_id = #{deviceTypeId}</if>
            <if test="maintProtocol != null  and maintProtocol != ''"> and a.maint_protocol like '%' || #{maintProtocol} || '%' </if>
            <if test="operationDescription != null  and operationDescription != ''"> and a.operation_description = #{operationDescription}</if>
            <if test="isFlag != null "> and a.is_flag = #{isFlag}</if>
        </where>
    </select>

    <select id="selectDmsBaseMaintStandardByMaintStandardId" parameterType="Long" resultMap="DmsBaseMaintStandardResult">
        <include refid="selectDmsBaseMaintStandardVo"/>
        where maint_standard_id = #{maintStandardId}
    </select>

    <insert id="insertDmsBaseMaintStandard" parameterType="DmsBaseMaintStandard">
        <selectKey keyProperty="maintStandardId" resultType="long" order="BEFORE">
            SELECT HAIWEI.SEQ_DMS_MAINT_STD.NEXTVAL FROM DUAL
        </selectKey>
        insert into dms_base_maint_standard
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="maintStandardId != null">maint_standard_id,</if>
            <if test="maintStandardCode != null and maintStandardCode != ''">maint_standard_code,</if>
            <if test="deviceTypeId != null">device_type_id,</if>
            <if test="maintProtocol != null and maintProtocol != ''">maint_protocol,</if>
            <if test="operationDescription != null">operation_description,</if>
            <if test="isFlag != null">is_flag,</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="maintStandardId != null">#{maintStandardId,jdbcType=NUMERIC},</if>
            <if test="maintStandardCode != null and maintStandardCode != ''">#{maintStandardCode},</if>
            <if test="deviceTypeId != null">#{deviceTypeId,jdbcType=NUMERIC},</if>
            <if test="maintProtocol != null and maintProtocol != ''">#{maintProtocol},</if>
            <if test="operationDescription != null">#{operationDescription},</if>
            <if test="isFlag != null">#{isFlag},</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="updateDmsBaseMaintStandard" parameterType="DmsBaseMaintStandard">
        update dms_base_maint_standard
        <trim prefix="SET" suffixOverrides=",">
            <if test="maintStandardCode != null">maint_standard_code = #{maintStandardCode},</if>
            <if test="deviceTypeId != null">device_type_id = #{deviceTypeId},</if>
            <if test="maintProtocol != null and maintProtocol != ''">maint_protocol = #{maintProtocol},</if>
            <if test="operationDescription != null">operation_description = #{operationDescription},</if>
            <if test="isFlag != null">is_flag = #{isFlag},</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_standard_id = #{maintStandardId}
    </update>

    <delete id="deleteDmsBaseMaintStandardByMaintStandardId" parameterType="Long">
        delete from dms_base_maint_standard where maint_standard_id = #{maintStandardId}
    </delete>

    <delete id="deleteDmsBaseMaintStandardByMaintStandardIds" parameterType="String">
        delete from dms_base_maint_standard where maint_standard_id in
        <foreach item="maintStandardId" collection="array" open="(" separator="," close=")">
            #{maintStandardId}
        </foreach>
    </delete>
</mapper>
