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

    <resultMap type="DmsBaseInspectRoute" id="DmsBaseInspectRouteResult">
        <result property="inspectRouteId"    column="inspect_route_id"    />
        <result property="routeCode"    column="route_code"    />
        <result property="routeName"    column="route_name"    />
        <result property="inspectType"    column="inspect_type"    />
        <result property="cyclePeriod"    column="cycle_period"    />
<!--        <result property="deviceTypeId"    column="device_type_id"    />-->
        <result property="isFlag"    column="is_flag"    />
        <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="selectDmsBaseInspectRouteVo">
        select inspect_route_id, route_code, route_name, inspect_type, cycle_period,
--                device_type_id,
               is_flag, create_by, create_time, update_by, update_time from dms_base_inspect_route
    </sql>

    <select id="selectDmsBaseInspectRouteList" parameterType="DmsBaseInspectRoute" resultMap="DmsBaseInspectRouteResult">
        <include refid="selectDmsBaseInspectRouteVo"/>
        <where>
            <if test="routeCode != null  and routeCode != ''"> and route_code = #{routeCode}</if>
            <if test="inspectRouteId != null  and inspectRouteId != ''"> and inspect_route_id = #{inspectRouteId}</if>
            <if test="routeName != null  and routeName != ''"> and route_name like concat('%', #{routeName}, '%')</if>
            <if test="inspectType != null  and inspectType != ''"> and inspect_type = #{inspectType}</if>
            <if test="cyclePeriod != null  and cyclePeriod != ''"> and cycle_period = #{cyclePeriod}</if>
<!--            <if test="deviceTypeId != null "> and device_type_id = #{deviceTypeId}</if>-->
            <if test="isFlag != null  and isFlag != ''"> and is_flag = #{isFlag}</if>
        </where>
    </select>

    <select id="selectDmsBaseInspectRouteByInspectRouteId" parameterType="Long" resultMap="DmsBaseInspectRouteResult">
        <include refid="selectDmsBaseInspectRouteVo"/>
        where inspect_route_id = #{inspectRouteId}
    </select>

    <insert id="insertDmsBaseInspectRoute" parameterType="DmsBaseInspectRoute">
        <selectKey keyProperty="inspectRouteId" resultType="long" order="BEFORE">
            SELECT SEQ_DMS_INSPECT_ROUTE.NEXTVAL FROM DUAL
        </selectKey>
        insert into dms_base_inspect_route
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="inspectRouteId != null">inspect_route_id,</if>
            <if test="routeCode != null">route_code,</if>
            <if test="routeName != null and routeName != ''">route_name,</if>
            <if test="inspectType != null and inspectType != ''">inspect_type,</if>
            <if test="cyclePeriod != null">cycle_period,</if>
<!--            <if test="deviceTypeId != null">device_type_id,</if>-->
            <if test="isFlag != null and isFlag != ''">is_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="inspectRouteId != null">#{inspectRouteId},</if>
            <if test="routeCode != null">#{routeCode},</if>
            <if test="routeName != null and routeName != ''">#{routeName},</if>
            <if test="inspectType != null and inspectType != ''">#{inspectType},</if>
            <if test="cyclePeriod != null">#{cyclePeriod},</if>
<!--            <if test="deviceTypeId != null">#{deviceTypeId,jdbcType=NUMERIC},</if>-->
            <if test="isFlag != null and isFlag != ''">#{isFlag},</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="updateDmsBaseInspectRoute" parameterType="DmsBaseInspectRoute">
        update dms_base_inspect_route
        <trim prefix="SET" suffixOverrides=",">
            <if test="routeCode != null">route_code = #{routeCode},</if>
            <if test="routeName != null and routeName != ''">route_name = #{routeName},</if>
            <if test="inspectType != null and inspectType != ''">inspect_type = #{inspectType},</if>
            <if test="cyclePeriod != null">cycle_period = #{cyclePeriod},</if>
<!--            <if test="deviceTypeId != null">device_type_id = #{deviceTypeId},</if>-->
            <if test="isFlag != null and isFlag != ''">is_flag = #{isFlag},</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 inspect_route_id = #{inspectRouteId}
    </update>

    <delete id="deleteDmsBaseInspectRouteByInspectRouteId" parameterType="Long">
        delete from dms_base_inspect_route where inspect_route_id = #{inspectRouteId}
    </delete>

    <delete id="deleteDmsBaseInspectRouteByInspectRouteIds" parameterType="String">
        delete from dms_base_inspect_route where inspect_route_id in
        <foreach item="inspectRouteId" collection="array" open="(" separator="," close=")">
            #{inspectRouteId}
        </foreach>
    </delete>
    <select id="selectAmountByInspectRouteId" parameterType="Long" resultType="Long">
        select count(*) from dms_inspect_route_detail where inspect_route_id = #{inspectRouteId}
    </select>
    <select id="selectRouteName" resultType="java.lang.String" parameterType="java.lang.Long">
        SELECT route_name routeName FROM dms_base_inspect_route  where inspect_route_id = #{inspectRouteId}
    </select>
</mapper>
