<?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="uml.tech.bigdata.mapper.FenceInfoMapper">

    <select id="selectAllFenceInfo" resultType="uml.tech.bigdata.domain.FenceInfoEntity">
        select id,
               org_id           as orgId,
               fence_code       as fenceCode,
               fence_version    as fenceVersion,
               fence_name       as fenceName,
               fence_type       as fenceType,
               fence_alarm_type as fenceAlarmType,
               wkt
        from tb_fence
        where del_flag = 0
    </select>

    <select id="selectFenceInfoById" resultType="uml.tech.bigdata.domain.FenceInfoEntity">
        select id,
               org_id           as orgId,
               fence_code       as fenceCode,
               fence_version    as fenceVersion,
               fence_name       as fenceName,
               fence_type       as fenceType,
               fence_alarm_type as fenceAlarmType,
               wkt
        from tb_fence
        where del_flag = 0
          and fence_code = #{fenceCode}
    </select>

    <select id="selectVehicleFences" resultType="uml.tech.bigdata.domain.VehicleFences">
        select did, group_concat(distinct fence_code) as fenceCodes
        from tr_fence_vehicle
        where did is not null
        group by did
    </select>

    <select id="selectVehicleFencesByDid" resultType="uml.tech.bigdata.domain.VehicleFences">
        select did, group_concat(distinct fence_code) as fenceCodes
        from tr_fence_vehicle
        where did = #{did}
        group by did
    </select>
    <select id="selectVehicleIdByDid" resultType="long">
        select vehicle_id
        from tw_nrv_redundant
        where did = #{did} limit 1
    </select>

</mapper>