<?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.tuoheng.admin.mapper.StructureMapper">

    <resultMap type="com.tuoheng.admin.entity.Structure" id="StructureResult">
        <result property="id"    column="id"    />
        <result property="tenantId"    column="tenant_id"    />
        <result property="structureType"    column="structure_type"    />
        <result property="structureName"    column="structure_name"    />
        <result property="roadId"    column="road_id"    />
        <result property="sectionId"    column="section_id"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="imageUrl"    column="image_url"    />
        <result property="createUser"    column="create_user"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateUser"    column="update_user"    />
        <result property="updateTime"    column="update_time"    />
        <result property="mark"    column="mark"    />
    </resultMap>

    <sql id="selectStructureVo">
        select id, tenant_id, structure_type, structure_name, road_id, section_id, longitude, latitude, image_url, create_user, create_time, update_user, update_time, mark from th_structure
    </sql>

    <select id="queryPage" resultType="com.tuoheng.admin.vo.StructureInfoVo">
        SELECT
        sr.id,
        sr.tenant_id as tenantId,
        sr.road_id as roadId,
        sr.section_id as sectionId,
        sr.structure_type as structureType,
        sr.structure_name as structureName,
        sr.longitude as longitude,
        sr.latitude as latitude,
        sr.image_url as imageUrl,
        se.section_range as sectionRange,
        rd.code as code
        from
        th_structure sr
        left JOIN th_section se ON sr.section_id=se.id
        left JOIN th_road rd ON sr.road_id=rd.id
        where sr.mark=1 and se.mark=1 and rd.mark=1
        <if test="request.structureName !=null and request.structureName !=''">
            AND sr.`structure_name` like concat('%',#{request.structureName},'%')
        </if>
        <if test="request.structureType !=null">
            AND sr.structure_type = #{request.structureType}
        </if>
        <if test="request.roadId !=null">
            AND sr.road_id = #{request.roadId}
        </if>
        ORDER BY
        sr.create_time DESC
    </select>

    <select id="queryPageBySectionId" resultType="com.tuoheng.admin.vo.StructureInfoVo">
        SELECT
        sr.id,
        sr.tenant_id as tenantId,
        sr.road_id as roadId,
        sr.section_id as sectionId,
        sr.structure_type as structureType,
        sr.structure_name as structureName,
        sr.longitude as longitude,
        sr.latitude as latitude,
        sr.image_url as imageUrl,
        se.section_range as sectionRange,
        rd.code as code
        from
        th_structure sr
        left JOIN th_section se ON sr.section_id=se.id
        left JOIN th_road rd ON sr.road_id=rd.id
        where sr.mark=1 and se.mark=1 and rd.mark=1
        <if test="request.structureName !=null and request.structureName !=''">
            AND sr.`structure_name` like concat('%',#{request.structureName},'%')
        </if>
        <if test="request.sectionId !=null">
            AND sr.section_id = #{request.sectionId}
        </if>
        <if test="request.structureType !=null">
            AND sr.structure_type = #{request.structureType}
        </if>
        <if test="request.roadId !=null">
            AND sr.road_id = #{request.roadId}
        </if>
        ORDER BY
        sr.create_time DESC
    </select>


</mapper>