<?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="cn.com.tenlion.systembase.dao.line.ILineDao">

    <resultMap id="lineDTO" type="cn.com.tenlion.systembase.pojo.dtos.line.LineDTO">
        <result column="line_id" property="lineId"/>
        <result column="line_name" property="lineName"/>
        <result column="line_type" property="lineType"/>
        <result column="line_type_name" property="lineTypeName"/>
        <result column="line_type_code" property="lineTypeCode"/>
        <result column="subjection_dept_name" property="subjectionDeptName"/>
        <result column="subjection_dept_address" property="subjectionDeptAddress"/>
        <result column="subjection_dept_phone" property="subjectionDeptPhone"/>
        <result column="subjection_dept_link_man" property="subjectionDeptLinkMan"/>
        <result column="subjection_dept_link_phone" property="subjectionDeptLinkPhone"/>
        <result column="jurisdiction_dept_name" property="jurisdictionDeptName"/>
        <result column="jurisdiction_address" property="jurisdictionAddress"/>
        <result column="jurisdiction_dept_phone" property="jurisdictionDeptPhone"/>
        <result column="charge_link_man" property="chargeLinkMan"/>
        <result column="charge_link_phone" property="chargeLinkPhone"/>
        <result column="security_situation" property="securitySituation"/>
        <result column="situation_level" property="situationLevel"/>
        <result column="situation_level_name" property="situationLevelName"/>
        <result column="situation_level_code" property="situationLevelCode"/>
        <result column="location" property="location"/>
        <result column="location_code" property="locationCode"/>
        <result column="grid" property="grid"/>
    </resultMap>

    <resultMap id="lineBO" type="cn.com.tenlion.systembase.pojo.bos.line.LineBO">
        <result column="line_id" property="lineId"/>
        <result column="line_name" property="lineName"/>
        <result column="line_type" property="lineType"/>
        <result column="line_type_name" property="lineTypeName"/>
        <result column="line_type_code" property="lineTypeCode"/>
        <result column="subjection_dept_name" property="subjectionDeptName"/>
        <result column="subjection_dept_address" property="subjectionDeptAddress"/>
        <result column="subjection_dept_phone" property="subjectionDeptPhone"/>
        <result column="subjection_dept_link_man" property="subjectionDeptLinkMan"/>
        <result column="subjection_dept_link_phone" property="subjectionDeptLinkPhone"/>
        <result column="jurisdiction_dept_name" property="jurisdictionDeptName"/>
        <result column="jurisdiction_address" property="jurisdictionAddress"/>
        <result column="jurisdiction_dept_phone" property="jurisdictionDeptPhone"/>
        <result column="charge_link_man" property="chargeLinkMan"/>
        <result column="charge_link_phone" property="chargeLinkPhone"/>
        <result column="security_situation" property="securitySituation"/>
        <result column="situation_level" property="situationLevel"/>
        <result column="situation_level_name" property="situationLevelName"/>
        <result column="situation_level_code" property="situationLevelCode"/>
    </resultMap>

    <resultMap id="linePO" type="cn.com.tenlion.systembase.pojo.pos.line.LinePO">
        <result column="line_id" property="lineId"/>
        <result column="line_name" property="lineName"/>
        <result column="line_type" property="lineType"/>
        <result column="line_type_name" property="lineTypeName"/>
        <result column="line_type_code" property="lineTypeCode"/>
        <result column="subjection_dept_name" property="subjectionDeptName"/>
        <result column="subjection_dept_address" property="subjectionDeptAddress"/>
        <result column="subjection_dept_phone" property="subjectionDeptPhone"/>
        <result column="subjection_dept_link_man" property="subjectionDeptLinkMan"/>
        <result column="subjection_dept_link_phone" property="subjectionDeptLinkPhone"/>
        <result column="jurisdiction_dept_name" property="jurisdictionDeptName"/>
        <result column="jurisdiction_address" property="jurisdictionAddress"/>
        <result column="jurisdiction_dept_phone" property="jurisdictionDeptPhone"/>
        <result column="charge_link_man" property="chargeLinkMan"/>
        <result column="charge_link_phone" property="chargeLinkPhone"/>
        <result column="security_situation" property="securitySituation"/>
        <result column="situation_level" property="situationLevel"/>
        <result column="situation_level_name" property="situationLevelName"/>
        <result column="situation_level_code" property="situationLevelCode"/>
    </resultMap>

    <!-- 新增护路护线 -->
    <insert id="save" parameterType="map">
        INSERT INTO data_line(
            line_id,
            line_name,
            line_type,
            line_type_name,
            line_type_code,
            subjection_dept_name,
            subjection_dept_address,
            subjection_dept_phone,
            subjection_dept_link_man,
            subjection_dept_link_phone,
            jurisdiction_dept_name,
            jurisdiction_address,
            jurisdiction_dept_phone,
            charge_link_man,
            charge_link_phone,
            security_situation,
            situation_level,
            situation_level_name,
            situation_level_code,
            location,
            location_code,
            grid,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{lineId},
            #{lineName},
            #{lineType},
            #{lineTypeName},
            #{lineTypeCode},
            #{subjectionDeptName},
            #{subjectionDeptAddress},
            #{subjectionDeptPhone},
            #{subjectionDeptLinkMan},
            #{subjectionDeptLinkPhone},
            #{jurisdictionDeptName},
            #{jurisdictionAddress},
            #{jurisdictionDeptPhone},
            #{chargeLinkMan},
            #{chargeLinkPhone},
            #{securitySituation},
            #{situationLevel},
            #{situationLevelName},
            #{situationLevelCode},
            #{location},
            #{locationCode},
            #{grid},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

    <!-- 删除护路护线 -->
    <update id="remove" parameterType="map">
        UPDATE
            data_line
        SET
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            is_delete = 1
        WHERE
            line_id IN
        <foreach collection="lineIds" index="index" open="(" separator="," close=")">
            #{lineIds[${index}]}
        </foreach>
    </update>

    <!-- 删除护路护线（物理） -->
    <update id="delete" parameterType="map">
        DELETE FROM
            data_line
        WHERE
            line_id IN
        <foreach collection="lineIds" index="index" open="(" separator="," close=")">
            #{lineIds[${index}]}
        </foreach>
    </update>

    <!-- 修改护路护线 -->
    <update id="update" parameterType="map">
        UPDATE
            data_line
        SET
        <if test="lineName != null and lineName != ''">
            line_name = #{lineName},
        </if>
        <if test="lineType != null">
            line_type = #{lineType},
        </if>
        <if test="lineTypeName != null and lineTypeName != ''">
            line_type_name = #{lineTypeName},
        </if>
        <if test="lineTypeCode != null and lineTypeCode != ''">
            line_type_code = #{lineTypeCode},
        </if>
        <if test="subjectionDeptName != null and subjectionDeptName != ''">
            subjection_dept_name = #{subjectionDeptName},
        </if>
        <if test="subjectionDeptAddress != null and subjectionDeptAddress != ''">
            subjection_dept_address = #{subjectionDeptAddress},
        </if>
        <if test="subjectionDeptPhone != null and subjectionDeptPhone != ''">
            subjection_dept_phone = #{subjectionDeptPhone},
        </if>
        <if test="subjectionDeptLinkMan != null and subjectionDeptLinkMan != ''">
            subjection_dept_link_man = #{subjectionDeptLinkMan},
        </if>
        <if test="subjectionDeptLinkPhone != null and subjectionDeptLinkPhone != ''">
            subjection_dept_link_phone = #{subjectionDeptLinkPhone},
        </if>
        <if test="jurisdictionDeptName != null and jurisdictionDeptName != ''">
            jurisdiction_dept_name = #{jurisdictionDeptName},
        </if>
        <if test="jurisdictionAddress != null and jurisdictionAddress != ''">
            jurisdiction_address = #{jurisdictionAddress},
        </if>
        <if test="jurisdictionDeptPhone != null and jurisdictionDeptPhone != ''">
            jurisdiction_dept_phone = #{jurisdictionDeptPhone},
        </if>
        <if test="chargeLinkMan != null and chargeLinkMan != ''">
            charge_link_man = #{chargeLinkMan},
        </if>
        <if test="chargeLinkPhone != null and chargeLinkPhone != ''">
            charge_link_phone = #{chargeLinkPhone},
        </if>
        <if test="securitySituation != null and securitySituation != ''">
            security_situation = #{securitySituation},
        </if>
        <if test="situationLevel != null">
            situation_level = #{situationLevel},
        </if>
        <if test="situationLevelName != null and situationLevelName != ''">
            situation_level_name = #{situationLevelName},
        </if>
        <if test="situationLevelCode != null and situationLevelCode != ''">
            situation_level_code = #{situationLevelCode},
        </if>
        <if test="location != null and location != ''">
            location = #{location},
        </if>
        <if test="locationCode != null and locationCode != ''">
            location_code = #{locationCode},
        </if>
        <if test="grid != null and grid != ''">
            grid = #{grid},
        </if>
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            line_id = line_id
        WHERE
            line_id = #{lineId}
    </update>

    <!-- 护路护线详情 -->
    <select id="get" parameterType="map" resultMap="lineDTO">
        SELECT
            t1.line_name,
            t1.line_type,
            t1.line_type_name,
            t1.line_type_code,
            t1.subjection_dept_name,
            t1.subjection_dept_address,
            t1.subjection_dept_phone,
            t1.subjection_dept_link_man,
            t1.subjection_dept_link_phone,
            t1.jurisdiction_dept_name,
            t1.jurisdiction_address,
            t1.jurisdiction_dept_phone,
            t1.charge_link_man,
            t1.charge_link_phone,
            t1.security_situation,
            t1.situation_level,
            t1.situation_level_name,
            t1.situation_level_code,
            t1.location,
            t1.location_code,
            t1.grid,
            t1.line_id
        FROM
            data_line t1
        WHERE
            t1.is_delete = 0
            <if test="lineId != null and lineId != ''">
        AND
            t1.line_id = #{lineId}
            </if>
    </select>

    <!-- 护路护线详情 -->
    <select id="getBO" parameterType="map" resultMap="lineBO">
        SELECT
            t1.line_id,
            t1.line_name,
            t1.line_type,
            t1.line_type_name,
            t1.line_type_code,
            t1.subjection_dept_name,
            t1.subjection_dept_address,
            t1.subjection_dept_phone,
            t1.subjection_dept_link_man,
            t1.subjection_dept_link_phone,
            t1.jurisdiction_dept_name,
            t1.jurisdiction_address,
            t1.jurisdiction_dept_phone,
            t1.charge_link_man,
            t1.charge_link_phone,
            t1.security_situation,
            t1.situation_level,
            t1.situation_level_name,
            t1.situation_level_code
        FROM
            data_line t1
        WHERE
            t1.is_delete = 0
            <if test="lineId != null and lineId != ''">
        AND
            t1.line_id = #{lineId}
            </if>
    </select>

    <!-- 护路护线详情 -->
    <select id="getPO" parameterType="map" resultMap="linePO">
        SELECT
            t1.line_id,
            t1.line_name,
            t1.line_type,
            t1.line_type_name,
            t1.line_type_code,
            t1.subjection_dept_name,
            t1.subjection_dept_address,
            t1.subjection_dept_phone,
            t1.subjection_dept_link_man,
            t1.subjection_dept_link_phone,
            t1.jurisdiction_dept_name,
            t1.jurisdiction_address,
            t1.jurisdiction_dept_phone,
            t1.charge_link_man,
            t1.charge_link_phone,
            t1.security_situation,
            t1.situation_level,
            t1.situation_level_name,
            t1.situation_level_code
        FROM
            data_line t1
        WHERE
            t1.is_delete = 0
            <if test="lineId != null and lineId != ''">
        AND
            t1.line_id = #{lineId}
            </if>
    </select>

    <!-- 护路护线列表 -->
    <select id="list" parameterType="map" resultMap="lineDTO">
        SELECT
            t1.line_id,
            t1.line_name,
            t1.line_type,
            t1.line_type_name,
            t1.line_type_code,
            t1.subjection_dept_name,
            t1.subjection_dept_address,
            t1.subjection_dept_phone,
            t1.subjection_dept_link_man,
            t1.subjection_dept_link_phone,
            t1.jurisdiction_dept_name,
            t1.jurisdiction_address,
            t1.jurisdiction_dept_phone,
            t1.charge_link_man,
            t1.charge_link_phone,
            t1.security_situation,
            t1.situation_level,
            t1.situation_level_name,
            t1.situation_level_code,
            t1.location,
            t1.location_code,
            t1.grid,
            1
        FROM
            data_line t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            t1.line_name LIKE CONCAT('%', #{keywords}, '%')
        )
        </if>
        <if test="startTime != null and startTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
            AND
            LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
        </if>
        <if test="lineIds != null and lineIds.size > 0">
        AND
            t1.line_id IN
            <foreach collection="lineIds" index="index" open="(" separator="," close=")">
                #{lineIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 护路护线列表 -->
    <select id="listBO" parameterType="map" resultMap="lineBO">
        SELECT
            t1.line_id,
            t1.line_name,
            t1.line_type,
            t1.line_type_name,
            t1.line_type_code,
            t1.subjection_dept_name,
            t1.subjection_dept_address,
            t1.subjection_dept_phone,
            t1.subjection_dept_link_man,
            t1.subjection_dept_link_phone,
            t1.jurisdiction_dept_name,
            t1.jurisdiction_address,
            t1.jurisdiction_dept_phone,
            t1.charge_link_man,
            t1.charge_link_phone,
            t1.security_situation,
            t1.situation_level,
            t1.situation_level_name,
            t1.situation_level_code
        FROM
            data_line t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            <!-- 这里添加其他条件 -->
            t1.id LIKE CONCAT('%', #{keywords}, '%')
        )
        </if>
        <if test="startTime != null and startTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
        </if>
        <if test="lineIds != null and lineIds.size > 0">
        AND
            t1.line_id IN
            <foreach collection="lineIds" index="index" open="(" separator="," close=")">
                #{lineIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 护路护线列表 -->
    <select id="listPO" parameterType="map" resultMap="linePO">
        SELECT
            t1.line_id,
            t1.line_name,
            t1.line_type,
            t1.line_type_name,
            t1.line_type_code,
            t1.subjection_dept_name,
            t1.subjection_dept_address,
            t1.subjection_dept_phone,
            t1.subjection_dept_link_man,
            t1.subjection_dept_link_phone,
            t1.jurisdiction_dept_name,
            t1.jurisdiction_address,
            t1.jurisdiction_dept_phone,
            t1.charge_link_man,
            t1.charge_link_phone,
            t1.security_situation,
            t1.situation_level,
            t1.situation_level_name,
            t1.situation_level_code
        FROM
            data_line t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            <!-- 这里添加其他条件 -->
            t1.id LIKE CONCAT('%', #{keywords}, '%')
        )
        </if>
        <if test="startTime != null and startTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
        </if>
        <if test="lineIds != null and lineIds.size > 0">
        AND
            t1.line_id IN
            <foreach collection="lineIds" index="index" open="(" separator="," close=")">
                #{lineIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 护路护线统计  -->
    <select id="count" parameterType="map" resultType="Integer">
        SELECT
            COUNT(*)
        FROM
            data_line t1
        WHERE
            t1.is_delete = 0
    </select>

</mapper>