<?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.battery.business.mapper.TCollectorMapper">
|
|
<resultMap type="TCollector" id="TCollectorResult">
|
<id property="collectorId" column="collector_id" />
|
<result property="adapterId" column="adapter_id" />
|
<result property="collectorCode" column="collector_code" />
|
<result property="ipAddress" column="ip_address" />
|
<result property="macAddress" column="mac_address" />
|
<result property="collectorName" column="collector_name" />
|
<result property="manufacturer" column="manufacturer" />
|
<result property="model" column="model" />
|
<result property="channelCount" column="channel_count" />
|
<result property="onlineStatus" column="online_status" />
|
<result property="testStatus" column="test_status" />
|
<result property="lastSeenAtUtc" column="last_seen_at_utc" />
|
<result property="status" column="status" />
|
<result property="delFlag" column="del_flag" />
|
<result property="createBy" column="create_by" />
|
<result property="createTime" column="create_time" />
|
<result property="updateBy" column="update_by" />
|
<result property="updateTime" column="update_time" />
|
<result property="remark" column="remark" />
|
<collection property="relatedTests" column="collector_id"
|
select="com.battery.business.mapper.DeviceRelatedTestMapper.selectCollectorRelatedTests" />
|
</resultMap>
|
|
<!-- 在线状态取所链接来源实例的连接结果(ADR-0063:在线只表示来源可达);
|
采集器测量由该来源提供,所以它不是独立可达的硬件。SELECT 与 WHERE 各用一次,故抽成片段。 -->
|
<sql id="derivedOnlineStatus">
|
case when exists (
|
select 1 from t_device_adapter adapter_fact
|
where adapter_fact.adapter_id = c.adapter_id
|
and upper(adapter_fact.connection_status) = 'ONLINE'
|
) then '1' else '0' end
|
</sql>
|
|
<sql id="selectCollectorVo">
|
select c.collector_id, c.collector_code, c.adapter_id, c.ip_address, c.mac_address, c.collector_name,
|
c.manufacturer, c.model, c.channel_count,
|
<include refid="derivedOnlineStatus" /> as online_status,
|
c.last_seen_at_utc,
|
case when exists (
|
select 1 from t_test_collector_channel mapping
|
join t_test test_fact on test_fact.test_id = mapping.test_id
|
where mapping.collector_id = c.collector_id
|
and test_fact.del_flag = 0
|
and test_fact.test_status in ('RUNNING', 'PAUSED')
|
) then '1' else '0' end as test_status,
|
c.status, c.del_flag, c.create_by,
|
c.create_time, c.update_by, c.update_time, c.remark
|
from t_collector c
|
</sql>
|
|
<select id="selectCollectorById" parameterType="Long" resultMap="TCollectorResult">
|
<include refid="selectCollectorVo" />
|
where collector_id = #{collectorId}
|
and del_flag = '0'
|
</select>
|
|
<select id="selectCollectorList" parameterType="TCollector" resultMap="TCollectorResult">
|
<include refid="selectCollectorVo" />
|
<where>
|
del_flag = '0'
|
<if test="device != null and device != ''">
|
and (ip_address like concat('%', #{device}, '%')
|
or collector_code like concat('%', #{device}, '%')
|
or mac_address like concat('%', #{device}, '%')
|
or collector_name like concat('%', #{device}, '%'))
|
</if>
|
<if test="beginCreateTime != null and beginCreateTime != ''">
|
and create_time >= #{beginCreateTime}
|
</if>
|
<if test="endCreateTime != null and endCreateTime != ''">
|
and create_time <= #{endCreateTime}
|
</if>
|
<if test="onlineStatus != null and onlineStatus != ''">
|
<!-- WHERE 里不能用 SELECT 别名(MySQL 只在 HAVING 认得),所以按同一表达式再过一遍。 -->
|
and (<include refid="derivedOnlineStatus" />) = #{onlineStatus}
|
</if>
|
<if test="testStatus != null and testStatus != ''">
|
and (case when exists (
|
select 1 from t_test_collector_channel mapping
|
join t_test test_fact on test_fact.test_id = mapping.test_id
|
where mapping.collector_id = c.collector_id
|
and test_fact.del_flag = 0
|
and test_fact.test_status in ('RUNNING', 'PAUSED')
|
) then '1' else '0' end) = #{testStatus}
|
</if>
|
<if test="status != null and status != ''">
|
and status = #{status}
|
</if>
|
</where>
|
order by create_time desc, collector_id desc
|
</select>
|
|
<select id="selectCollectorByCode" parameterType="String" resultMap="TCollectorResult">
|
<include refid="selectCollectorVo" />
|
where collector_code = #{collectorCode}
|
and del_flag = '0'
|
limit 1
|
</select>
|
|
<select id="selectCollectorByMacAddress" parameterType="String" resultMap="TCollectorResult">
|
<include refid="selectCollectorVo" />
|
where mac_address = #{macAddress}
|
and del_flag = '0'
|
limit 1
|
</select>
|
|
<insert id="insertCollector" parameterType="TCollector" useGeneratedKeys="true" keyProperty="collectorId">
|
insert into t_collector
|
(collector_code, adapter_id, ip_address, mac_address, collector_name, manufacturer, model,
|
channel_count, online_status, last_seen_at_utc,
|
status, del_flag, create_by, create_time, remark)
|
values
|
(#{collectorCode}, #{adapterId}, #{ipAddress}, #{macAddress}, #{collectorName}, #{manufacturer}, #{model},
|
#{channelCount}, case when #{onlineStatus} in ('1', 'ONLINE') then 'ONLINE' else 'OFFLINE' end,
|
#{lastSeenAtUtc},
|
#{status}, #{delFlag}, #{createBy}, #{createTime}, #{remark})
|
</insert>
|
|
<update id="updateCollector" parameterType="TCollector">
|
update t_collector
|
<set>
|
collector_code = #{collectorCode},
|
adapter_id = #{adapterId},
|
ip_address = #{ipAddress},
|
mac_address = #{macAddress},
|
collector_name = #{collectorName},
|
manufacturer = #{manufacturer},
|
model = #{model},
|
channel_count = #{channelCount},
|
status = #{status},
|
remark = #{remark},
|
update_by = #{updateBy},
|
update_time = #{updateTime}
|
</set>
|
where collector_id = #{collectorId}
|
and del_flag = '0'
|
</update>
|
|
<update id="updateCollectorStatus" parameterType="TCollector">
|
update t_collector
|
set status = #{status},
|
update_by = #{updateBy},
|
update_time = #{updateTime}
|
where collector_id = #{collectorId}
|
and del_flag = '0'
|
</update>
|
|
<update id="deleteCollectorById">
|
update t_collector
|
set del_flag = cast(collector_id as char),
|
update_by = #{updateBy},
|
update_time = sysdate()
|
where collector_id = #{collectorId}
|
and del_flag = '0'
|
</update>
|
</mapper>
|