package com.common.mapper; import com.common.entity.StatsChangeRecord; import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import java.time.LocalDateTime; @Mapper public interface StatsChangeLogMapper { @Insert("INSERT INTO syslog_stats_change_log (" + "change_seq,change_id,source_type,source_row_id,operation_type," + "old_stat_date,new_stat_date,old_device_id,new_device_id," + "old_collect_id,new_collect_id,old_rule_id,new_rule_id," + "old_event_time,new_event_time,old_collect_time,new_collect_time," + "old_push_success,new_push_success,committed_at" + ") VALUES (seq_syslog_stats_change.NEXTVAL,#{changeId},#{sourceType},#{sourceRowId},#{operationType}," + "#{oldStatDate},#{newStatDate},#{oldDeviceId},#{newDeviceId}," + "#{oldCollectId},#{newCollectId},#{oldRuleId},#{newRuleId}," + "#{oldEventTime},#{newEventTime},#{oldCollectTime},#{newCollectTime}," + "#{oldPushSuccess},#{newPushSuccess},SYSDATE)") int insert(StatsChangeRecord record); @Insert("INSERT INTO stats_projection_pending_change(projection_name,change_seq,change_id,created_at) " + "SELECT 'SYSLOG_STATS',change_seq,change_id,SYSDATE FROM syslog_stats_change_log " + "WHERE change_id=#{changeId}") int insertPending(StatsChangeRecord record); @Insert("INSERT INTO syslog_stats_change_log (change_seq,change_id,source_type,source_row_id," + "operation_type,old_stat_date,old_device_id,old_collect_id,old_event_time,old_collect_time," + "old_push_success,committed_at) SELECT seq_syslog_stats_change.NEXTVAL," + "'DEVICE_RECEIVE:'||TO_CHAR(id)||':DELETE','DEVICE_RECEIVE',TO_CHAR(id),'DELETE'," + "TRUNC(receive_time),device_id,device_collect_id,receive_time,created_at,push_success,SYSDATE " + "FROM device_receive_log WHERE created_at BETWEEN #{startTime} AND #{endTime}") int captureDeviceReceiveDeletes(@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime); @Insert("INSERT INTO stats_projection_pending_change(projection_name,change_seq,change_id,created_at) " + "SELECT 'SYSLOG_STATS',l.change_seq,l.change_id,SYSDATE FROM syslog_stats_change_log l " + "WHERE l.source_type='DEVICE_RECEIVE' AND l.operation_type='DELETE' " + "AND EXISTS (SELECT 1 FROM device_receive_log d WHERE d.created_at BETWEEN #{startTime} AND #{endTime} " + "AND TO_CHAR(d.id)=l.source_row_id) AND NOT EXISTS (SELECT 1 FROM stats_projection_pending_change p " + "WHERE p.projection_name='SYSLOG_STATS' AND p.change_seq=l.change_seq)") int enqueueDeviceReceiveDeletes(@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime); }