Newer
Older
huludao / src / main / resources / mapper / StationBaseDao.xml
<?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.newfiber.api.pc.dao.newmonitoring.StationBaseDao">

	<!-- 可根据自己的需求,是否要使用 -->
    <resultMap type="com.newfiber.api.pc.model.monitor.StationBase" id="stationBaseMap">
        <result property="id" column="id"/>
        <result property="stName" column="st_name"/>
        <result property="stCode" column="st_code"/>
        <result property="ut" column="ut"/>
        <result property="tt" column="tt"/>
        <result property="area" column="area"/>
        <result property="constructionStatus" column="construction_status"/>
        <result property="faultStatus" column="fault_status"/>
        <result property="taskStatus" column="task_status"/>
        <result property="platformCode" column="platform_code"/>
        <result property="lat" column="lat"/>
        <result property="lon" column="lon"/>
        <result property="isPush" column="is_push"/>
        <result property="createTime" column="create_time"/>
        <result property="coordinateSystem" column="coordinate_system"/>
        <result property="status" column="status"/>
        <result property="offlineTime" column="offline_time"/>
    </resultMap>

    <resultMap type="com.newfiber.api.pc.model.entity.StationBaseEntity" id="stationBaseExtend">
        <result property="id" column="id"/>
        <result property="stName" column="st_name"/>
        <result property="stCode" column="st_code"/>
        <result property="ut" column="ut"/>
        <result property="tt" column="tt"/>
        <result property="area" column="area"/>
        <result property="platformCode" column="platform_code"/>
        <result property="platformName" column="platformName"/>
        <result property="lat" column="lat"/>
        <result property="lon" column="lon"/>
        <result property="constructionStatus" column="construction_status"/>
        <result property="createTime" column="create_time"/>
        <result property="stationType" column="station_type"/>
        <result property="videoPath" column="video_path"/>
        <result property="installationType" column="installation_type" />
        <result property="address" column="address"/>
        <result property="person" column="person"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateUserId" column="update_user_id"/>
        <result property="createUserId" column="create_user_id"/>
    </resultMap>

    <select id="getTempData" resultType="map">
        SELECT p.`code_property` name,c.`value`
        FROM nf_monitor.station_config c
                 INNER JOIN nf_monitor.site_property_config p ON c.`key` = p.`code_ascll`
        WHERE c.st_code = #{stCode}
    </select>



    <select id="listForStation" resultMap="stationBaseExtend" parameterType="String">
        select s.id,s.st_name,s.st_code,s.ut,s.tt,s.area,s.platform_code,s.platformName,s.lat,s.lon,s.construction_status,s.is_know,
        s.create_time,s.video_path,s.station_type,s.address,s.person,s.create_user_id,s.update_user_id,s.update_time,s.installation_type,
        u1.real_name createUserName,u1.user_account createUserNo, u2.real_name updateUserName,u2.user_account updateUserNo from (
            select distinct
            sb.id as id,st_name,st_code,ut,tt,sb.area,sb.platform_code,sp.name as platformName,sb.lat,sb.lon,
            sb.construction_status,sb.is_know,sb.create_time,sb.video_path,sbe.station_type as station_type,
            sbe.address,sbe.person,sbe.create_user_id ,sbe.update_user_id,sbe.update_time,sbe.installation_type
            from nf_monitor.station_base sb
            left join nf_monitor.station_base_extend sbe on sb.id = sbe.station_base_id
            left join nf_monitor.sys_platform sp on sp.platform_code = sb.platform_code
        <choose>
            <when test="userNo !=null and userNo != '' and isNormal ==true">
                inner join nf_monitor.group_platform_relation gr on sb.platform_code=gr.platfrom_code
                inner join nf_monitor.user_group_relation ugr on gr.group_id=ugr.group_id
                inner join nf_monitor.om_user ou on ugr.user_id = ou.id
                where (ou.user_account =#{userNo} or sb.platform_code is null)
                <if test="searchStr != null and searchStr != ''">
                    and (sb.st_name like concat('%',#{searchStr},'%') or sb.st_code like concat('%',#{searchStr},'%'))
                </if>
            </when>
            <otherwise>
                where 1=1
                <if test="searchStr != null and searchStr != ''">
                    and (sb.st_name like concat('%',#{searchStr},'%') or sb.st_code like concat('%',#{searchStr},'%'))
                </if>
            </otherwise>
        </choose>
        <if test="platformCode != null and platformCode != ''and platformCode != 'null' ">
            and sb.platform_code = #{platformCode}
        </if>
        <if test="sign != null and sign != ''and sign != 'null' ">
            <choose>
                <when test="sign == 'bind'">
                    and sb.platform_code is not null and sb.platform_code !=''
                </when>
                <otherwise>
                    and (sb.platform_code ='' or sb.platform_code is null)
                </otherwise>
            </choose>
        </if>

        <if test="startTime != null and startTime != '' and startTime != 'null'">
            and sb.ut >=  concat('','${startTime}','00:00:00')
        </if>
        <if test="endTime != null and endTime != '' and endTime != 'null'">
            and sb.ut &lt; concat('','${endTime}','23:59:59')
        </if>
        order by sb.ut desc)s
        left join nf_monitor.om_user u1 on s.create_user_id=u1.id
        left join	nf_monitor.om_user u2 on s.update_user_id=u2.id
    </select>

    <select id="selectByStCode" resultType="com.newfiber.api.pc.model.monitor.StationBase">
        select * from nf_monitor.station_base where st_code=#{stCode}
    </select>

    <resultMap id="StationConfigResultMap" type="com.newfiber.api.pc.model.monitor.StationConfig" >
        <result column="st_code" property="stCode" jdbcType="VARCHAR" />
        <result column="st_name" property="stName" jdbcType="VARCHAR" />
        <result column="key" property="key" jdbcType="VARCHAR" />
        <result column="value" property="value" jdbcType="VARCHAR" />
        <result column="tt" property="tt" jdbcType="VARCHAR" />
    </resultMap>

    <select id="selectOnLineStationConfigList" resultMap="StationConfigResultMap">
        select sb.st_code, sb.st_name,sc.key,sc.value,sc.tt from station_base sb INNER JOIN station_config sc on sb.st_code = sc.st_code where sb.status = 0 and
        sb.st_code in
        <foreach collection="stCodeList" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

    <select id="getSiteStateStatistics" resultType="map">
        SELECT
        COUNT( CASE WHEN t.warmType = '离线' THEN 1 ELSE NULL END ) offline,
        COUNT( CASE WHEN t.warmType = '报警' THEN 1 ELSE NULL END ) alarm,
        COUNT( CASE WHEN t.warmType = '预警' THEN 1 ELSE NULL END ) warn,
        COUNT( CASE WHEN t.warmType = '站点设备故障' THEN 1 ELSE NULL END ) malfunction
        FROM
        ( SELECT DISTINCT siteNo, warmType FROM alarmLog WHERE warningTime BETWEEN #{startTime} AND #{endTime} ) t
        INNER JOIN station_base s on t.siteNo = s.st_code
        <where>
            <if test="platform != null">
                s.platform_code = #{platform}
            </if>
        </where>
    </select>

    <resultMap type="com.newfiber.api.pc.model.monitor.StationBase" id="myResultMap">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="st_name" property="stName" jdbcType="VARCHAR"/>
        <result column="st_code" property="stCode" jdbcType="VARCHAR"/>
        <result column="ut" property="ut" jdbcType="TIMESTAMP"/>
        <result column="tt" property="tt" jdbcType="VARCHAR"/>
        <result column="area" property="area" jdbcType="VARCHAR"/>
        <result column="construction_status" property="constructionStatus" jdbcType="INTEGER"/>
        <result column="fault_status" property="faultStatus" jdbcType="INTEGER"/>
        <result column="task_status" property="taskStatus" jdbcType="INTEGER"/>
        <result column="platform_code" property="platformCode" jdbcType="VARCHAR"/>
        <result column="lat" property="lat" jdbcType="VARCHAR"/>
        <result column="lon" property="lon" jdbcType="VARCHAR"/>
        <result column="is_push" property="isPush" jdbcType="INTEGER"/>
        <collection property="data" column="st_code" ofType="map">
            <result column="name" property="name" jdbcType="VARCHAR"/>
            <result column="value" property="value" jdbcType="VARCHAR"/>
        </collection>
    </resultMap>

    <select id="listStationBaseWithTempData" parameterType="map" resultMap="myResultMap">
        /*select b.*,p.CodeProperty name,c.`value` from station_base b
        left join station_config c on b.st_code = c.st_code
        left join site_property_config p ON c.`key` = p.code_ascll
        where 1 = 1*/
        select b.*,p.code_property  name,c.`value` from station_base b
        left join station_config c on b.st_code = c.st_code
        left join site_property_config p ON c.`key` = p.code_ascll
        <if test="platformCode != null and platformCode != ''">
            and b.platform_code = #{platformCode}
        </if>
        <if test="stCode != null and stCode != ''">
            and b.st_code = #{stCode}
        </if>
        <if test="stName != null and stName != ''">
            and b.st_name like concat('%',#{stName},'%')
        </if>
    </select>

    <resultMap type="com.newfiber.api.pc.model.monitor.StationBase" id="baseResultMap">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="st_name" property="stName" jdbcType="VARCHAR"/>
        <result column="st_code" property="stCode" jdbcType="VARCHAR"/>
        <result column="ut" property="ut" jdbcType="TIMESTAMP"/>
        <result column="tt" property="tt" jdbcType="VARCHAR"/>
        <result column="area" property="area" jdbcType="VARCHAR"/>
        <result column="construction_status" property="constructionStatus" jdbcType="INTEGER"/>
        <result column="fault_status" property="faultStatus" jdbcType="INTEGER"/>
        <result column="task_status" property="taskStatus" jdbcType="INTEGER"/>
        <result column="platform_code" property="platformCode" jdbcType="VARCHAR"/>
        <result column="lat" property="lat" jdbcType="VARCHAR"/>
        <result column="lon" property="lon" jdbcType="VARCHAR"/>
        <result column="is_push" property="isPush" jdbcType="INTEGER"/>
        <result column="station_type" property="stationType" jdbcType="VARCHAR"/>
    </resultMap>

    <select id="listStationBase" parameterType="com.newfiber.api.pc.model.monitor.StationBase" resultMap="baseResultMap">
        select sb.*,sp.name,
        (CASE WHEN sbe.station_type like '%水质站(地表水)%' THEN 0 WHEN sbe.station_type like '%水质站(污水)%' THEN 1 ELSE 2 END ) AS station_type
        from station_base sb
        left join sys_platform sp on sb.platform_code=sp.platform_code
        left join station_base_extend sbe on sb.id = sbe.station_base_id
        where 1 = 1
        <if test="platformCode != null and platformCode != ''">
            and sb.platform_code = #{platformCode}
        </if>
        <if test="stCode != null and stCode != ''">
            and sb.st_code = #{stCode}
        </if>
        <if test="stName != null and stName != ''">
            and (sb.st_name like concat('%',#{stName},'%') or sb.st_code like concat('%',#{stName},'%'))
        </if>
        <choose>
            <when test='stationType != null and stationType != "" and stationType != "2" '>
                and sbe.station_type like concat('%',#{stationType},'%')
            </when>
            <when test='stationType != null and stationType != "" and stationType == "2" '>
                and sbe.station_type not like concat('%','水质站','%')
            </when>
        </choose>
    </select>

    <select id="getDataTitle" resultType="map">
        SELECT p.code_property name,p.code_ascll code,p.unit
        FROM station_config c
                 INNER JOIN site_property_config p ON c.`key` = p.code_ascll
        WHERE c.st_code = #{stCode}
    </select>

</mapper>