create or replace procedure proc_alarmlog(in_id   in number, --采集器编码
                                          ip_code in number, --采集器ip
                                          in_time varchar2, --采集时间
                                          t_arr   num_array, --温度数据
                                          h_arr   num_array, --湿度数据
                                          c_arr   num_array) --二氧化碳数据
 is
  min_table   num_type := num_type(0); --仓库监控阈值范围最小值
  max_table   num_type := num_type(0); --仓库监控阈值范围最大值
  state_table num_type := num_type(0); --阈值范围对应的仓库状态
  v_value     number; --采集数据的临时变量
  v_wid       number; --仓库编码
  v_count     number; --临时变量,用于判断仓库某个采集区域是否存在警告或异常
  v_state     number; --临时变量,用于判断仓库某个采集区域的状态
  v_reason    varchar2(100):='';--临时变量,用于存储异常信息
  v_err       varchar2(200);--临时变量,用于存储异常信息
begin
  --根据采集器编码获取仓库编码
  begin
    select wid into v_wid from warehouse_new t where t.client_id = in_id;
  exception
    when no_data_found then
      return; --无法找到对应的仓库,返回
  end;
  --根据仓库编码获得仓库温度配置
  --按告警状态倒序查询
  --便于判断温度值状态
  select min_value, max_value, state bulk collect
    into min_table, max_table, state_table
    from temperature t
   where t.wid = v_wid
     and t.state != 1
   order by t.state desc;
  --循环校验温度十个字段值,如果为255跳出循环
  for i in 1 .. 10 loop
    if t_arr(i) = 255 then
      exit;
    else
      v_state := 1;
      for j in 1 .. state_table.count loop
        if t_arr(i) >= min_table(j) and t_arr(i) <= max_table(j) then
          v_state := state_table(j);
          if v_state = 3 then
             v_reason:='异常,范围:'||min_table(j)||'到'||max_table(j);
          elsif v_state = 2 then
             v_reason:='告警,范围:'||min_table(j)||'到'||max_table(j);
          else
             v_reason:='';
          end if;
          exit; --退出内层循环
        end if;
      end loop;
      select count(1)--判断该区域是否已存在未解决的告警信息
        into v_count
        from alarmlog t
       where t.solvestate = 0
         and t.jurisdictionid = i
         and t.warehouseid = v_wid;
      if v_count > 0 then
        update alarmlog t
           set t.state     = decode(v_state,1,t.state,v_state),--如果状态是正常,则不改变告警信息记录的状态
               t.solvetime = decode(v_state,1,to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss'),''),
               t.solvestate = decode(v_state,1,1,0)--如果状态是正常则改变告警信息的解决状态为1:已解决
         where t.solvestate = 0
           and t.jurisdictionid = i
           and t.indicator = 1--温度
           and t.warehouseid = v_wid;
      elsif v_state!= 1 then
        insert into alarmlog
          (id,--主键
           time,--采集时间
           reason,--告警原因
           warehouseid,--所属仓库编码
           jurisdictionid,--异常区域(1-10)
           solvestate,--异常解决状态
           state,--发生异常时仓库状态
           value,--发生异常的值
           ipcode,--采集器编码
           indicator)--异常种类(温度、适度、二氧化碳)
        values
          (alarmlog_id_seq.nextval, in_time, v_reason,v_wid,i,0,v_state,t_arr(i),in_id,1);
      end if;
    end if;
  end loop;
  --根据仓库编码获得仓库湿度配置
  --按告警状态倒序查询
  --便于判断温度值状态
  select min_value, max_value, state bulk collect
    into min_table, max_table, state_table
    from humidity t
   where t.wid = v_wid
     and t.state != 1
   order by t.state desc;
  --循环校验湿度十个字段值,如果为255跳出循环
  for i in 1 .. 10 loop
    if h_arr(i) = 255 then
      exit;
    else
      v_state := 1;
      for j in 1 .. state_table.count loop
        if h_arr(i) >= min_table(j) and h_arr(i) <= max_table(j) then
          v_state := state_table(j);
          if v_state = 3 then
             v_reason:='异常,范围:'||min_table(j)||'到'||max_table(j);
          elsif v_state = 2 then
             v_reason:='告警,范围:'||min_table(j)||'到'||max_table(j);
          else
             v_reason:='';
          end if;
          exit; --退出内层循环
        end if;
      end loop;
      select count(1)--判断该区域是否已存在未解决的告警信息
        into v_count
        from alarmlog t
       where t.solvestate = 0
         and t.jurisdictionid = i
         and t.warehouseid = v_wid;
      if v_count > 0 then
        update alarmlog t
           set t.state     = decode(v_state,1,t.state,v_state),--如果状态是正常,则不改变告警信息记录的状态
               t.solvetime = decode(v_state,1,to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss'),''),
               t.solvestate = decode(v_state,1,1,0)--如果状态是正常则改变告警信息的解决状态为1:已解决
         where t.solvestate = 0
           and t.indicator = 2--湿度
           and t.jurisdictionid = i
           and t.warehouseid = v_wid;
      elsif v_state!= 1 then
        insert into alarmlog
          (id,--主键
           time,--采集时间
           reason,--告警原因
           warehouseid,--所属仓库编码
           jurisdictionid,--异常区域(1-10)
           solvestate,--异常解决状态
           state,--发生异常时仓库状态
           value,--发生异常的值
           ipcode,--采集器编码
           indicator)--异常种类(温度、适度、二氧化碳)
        values
          (alarmlog_id_seq.nextval, in_time, v_reason,v_wid,i,0,v_state,h_arr(i),in_id,2);
      end if;
    end if;
  end loop;
 -- commit;
  exception when others then
    v_err:=sqlerrm;
    insert into operationlog
      (id, time, behavior, state, reason)
    values
      (operationlog_id_seq.nextval,
       to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss'),
       '生成告警信息发生数据库异常',
       1,
       v_err);
   -- commit;
end proc_alarmlog;

PROCEDURE_监测系统_告警信息存储过程—产生告警信息插入告警表的更多相关文章

  1. PROCEDURE_监测系统_数据备份存储过程—备份原始数据,每十分钟一条,取平均值

    create or replace procedure proc_backup_originaldata(retCode out varchar2, -- 返回码                    ...

  2. PROCEDURE_监测系统_原始数据报表数据生成存储过程—求每天平均值插入多表视图

    create or replace procedure proc_generate_report(in_date in varchar2) is  v_retCode varchar2(20);  v ...

  3. TRIGGERS_监测系统_原始数据表触发器—调用告警信息存储过程

    //每次向originaldata表中插入数据就会触发该触发器 create or replace trigger originaldata_to_alarm  after insert on ori ...

  4. TRIGGERS_监测系统_多表视图触发器—向原始数据报表中插入数据

    Create Or Replace Trigger trg_view_report  Instead Of Insert or update or delete on view_for_report  ...

  5. QT--动态人流量监测系统

    QT--动态人流量监测系统 简介: 本项目使用了百度AI的动态人流量监测api,以人体头肩为主要识别目标,适用于低空俯拍,出入口场景,可用于统计当前图像的锁定人数和经过的人数 项目功能 本项目分为相机 ...

  6. 基于RestOn智能睡眠监测器的睡眠监测系统

    一.项目地址为: https://github.com/linqian123... 二.项目功能概述: 该项目实现的是一个基于RestOn智能睡眠监测器的睡眠监测系统.RestOn智能睡眠检测器通过W ...

  7. Security基础(五):部署Cacti监控平台、构建Cacti监测系统

    一.部署Cacti监控平台 目标: 本案例要求部署一台Cacti监控主机,并安装相关监控组件,为进一步执行具体的监控任务做准备: 安装net-snmp.net-snmp-utils 安装LAMP及相关 ...

  8. 胎压监测系统(DWS)

    胎压监测系统(DWS)通过监测和比较行驶时各车轮和轮胎的滚动半径和旋转特性,以确定是否一个或多个轮胎明显充气不足,而非直接测量各轮胎的压力. 系统监测到异常时指示灯将点亮,且仪表上出现信息. 必须校准 ...

  9. Linux系统下输出某进程内存占用信息的c程序实现

    在实际工作中有时需要程序打印出某个进程的内存占用情况以作参考, 下面介绍一种通过Linux下的伪文件系统/proc 计算某进程内存占用的程序实现方法. 首先, 为什么会有所谓的 伪文件 呢. Linu ...

随机推荐

  1. HTML/CSS代码片段

    内容简介:本文收集了我常用的CSS代码片段! *reset @charset "utf-8"; /* reset */ body, dl, dd, h1, h2, h3, h4, ...

  2. WordPress插件制作教程(五): 创建新的数据表

    上一篇讲解了怎样将数据保存到数据库,今天为大家讲解创建新的数据表,也就是说当我们激活插件的时候,会在该数据库下面创建一个新的数据表出来.原理很简单,激活插件的时候运行创建数据库的代码.看下面代码: & ...

  3. Loadrunner根据PV量来确定需要进行压测的并发量

    在实际做压力测试的过程中,我们有时不知道用怎样的并发量比较好,下面是几个用PV量去确定并发量的公式,这个在我们公司是比较适用的,大家可以根据自己的业务进行运算. 方法一:这个方法是我在网上查到的80- ...

  4. MVC之实体框架(数据持久化框架)EntityFrameWork(EF)

    EF - EntityFrameWork 中文名:实体框架(数据持久化框架) 1.使用EF查询(Linq to EF) 1.1使用标准查询运算符来查询 OumindBlogEntities db = ...

  5. rsyslog VS syslog-ng,日志记录哪家强?

    还有慢慢摸索,NG的MYSQL配置,我始终没搞好. RSYSLOG则比较容易. 另外,也可以每个RSYSLOG直接入库,不需要经过LOG SERVER..如果有一个大内网的话... 配合LOGANAL ...

  6. Keil C51处理可重入函数问题的探讨

    在程序设计中,变量具体可以分为四种类型:全局变量.静态全局变量.局部变量.静态局部变量.这几种变量类型对函数的可重入产生的重大的影响,因为不同的编译器采用不同的策略. 针对51的存储区有限,keil ...

  7. 【给你几个使用Xamarin的理由】

    写在开篇前 这种代理操作,绑定影射的机制,有些极端的开发者确实难以接受.追求完美,总感觉原生的各种优点. 如果你非得较这个真,那您还是感觉补习下 Java Eclipse  ,买一台Mac 恶补Obj ...

  8. 多目录下多文件 makefile编写

    前面已经分享了单目录项下多文件的makefile的编写,现在来看看多目录下多文件makefile的编写: 在做项目时,一般文件都会分几个目录来存放:基本的是  include/  bin/ src/ ...

  9. Find the largest multiple of 3 解答

    Question Given an array of non-negative integers. Find the largest multiple of 3 that can be formed ...

  10. SSH2.0编程 ssh协议过程实现

    之前为了自己做一套SSH,先自己实现了一套telnet.但经过这么多天的苦逼,发现以前的工作都是徒劳.ssh的协议很繁杂,核心的内容在于密码算法,而且自己很难在网上找到周全的细节讲解与详细的实现,只有 ...