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,
case when upper(c.online_status) = 'ONLINE' or c.online_status = '1' then '1' else '0' end 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
insert into t_collector
(collector_code, 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}, #{ipAddress}, #{macAddress}, #{collectorName}, #{manufacturer}, #{model},
#{channelCount}, case when #{onlineStatus} in ('1', 'ONLINE') then 'ONLINE' else 'OFFLINE' end,
#{lastSeenAtUtc},
#{status}, #{delFlag}, #{createBy}, #{createTime}, #{remark})
update t_collector
set online_status = case when #{onlineStatus} in ('1', 'ONLINE') then 'ONLINE' else 'OFFLINE' end,
last_seen_at_utc = utc_timestamp(3), update_time = sysdate()
where collector_code = #{collectorCode} and del_flag = 0
update t_collector
collector_code = #{collectorCode},
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}
where collector_id = #{collectorId}
and del_flag = '0'
update t_collector
set status = #{status},
update_by = #{updateBy},
update_time = #{updateTime}
where collector_id = #{collectorId}
and del_flag = '0'
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'