<?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.casic.missiles.modular.system.dao.BusConcentratorMapper">

    <sql id="Base_Column_List">
        ID AS id, CONCENCODE AS concencode, SIMID AS simid, DEPTID AS deptid, POSITION AS position, LAT AS lat, LNG AS lng, LAT_BAIDU AS latBaidu, LNG_BAIDU AS lngBaidu, LAT_GAODE AS latGaode, LNG_GAODE AS lngGaode, PHOTOS AS photos, STATUS AS status, LASTTIME AS lasttime, VALID AS valid, SETUPDATE AS setupdate, TS AS ts
    </sql>
    <sql id="keywords_sql" databaseId="oracle">
        '%' || #{keywords}|| '%'
    </sql>
    <sql id="keywords_sql" databaseId="mysql">
        CONCAT('%',#{keywords},'%')
    </sql>
    <sql id="keywords_sql" databaseId="pgsql">
        CONCAT('%',#{keywords},'%')
    </sql>
    <select id="selectConcentratorPage" resultType="com.casic.missiles.modular.system.model.BusConcentrator" parameterType="com.baomidou.mybatisplus.extension.plugins.pagination.Page">
        SELECT
        <include refid="Base_Column_List"/>,
        (SELECT count(1) FROM bus_device_concentrator WHERE  Active = '1' AND concen_id =  bus_concentrator.id) as devices
        FROM bus_concentrator
        WHERE VALID = '1'
        <if test="keywords != null and keywords !=''">
            and (CONCENCODE like
            <include refid="keywords_sql"/>
            OR POSITION LIKE
            <include refid="keywords_sql"/>
            )
        </if>
        <if test="status != null and status !=''">
            and STATUS = #{status}
        </if>
        ORDER by SETUPDATE DESC
    </select>

</mapper>
