Beispiel #1
0
        //public DataTable GetOpenidList(int co_id)
        //{
        //    StringBuilder strSql = new StringBuilder();
        //    strSql.Append("select a.CrmName,c.OpenID");
        //    strSql.Append(" from v3_user as a inner join v3_userinfo as b on a.Ledger=b.Ledger and a.Crm_id=b.Crm_id");
        //    strSql.Append(" inner join v3_openid as c on a.Ledger=c.Ledger and a.Crm_id=c.Crm_id");
        //    strSql.Append(" where a.Ledger=@Ledger and b.Co_id=@Co_id");
        //    return SQLHelper.Query(strSql.ToString(), new { Ledger = this.Ledger, Co_id = co_id });
        //}

        public int AddAlarm(v2_alarm_logVModel am)
        {
            //object params01 = new { Ledger = this.Ledger, Log_id = am.Log_id, Co_id = am.Co_id, Module_id = am.Module_id, ModuleAddr = am.ModuleAddr, AType = am.AType, Content = am.Content, ErrCode = am.ErrCode, ErrTxt= am.ErrTxt };
            //StringBuilder strSql = new StringBuilder();
            //if (am.Log_id == 0)
            //{
            //    strSql.Clear();
            //    strSql.Append("insert into v2_alarm_log(");
            //    strSql.Append("CDate,Ledger,Co_id,Module_id,ModuleAddr,Fun_id,AlarmType,AlarmName,Content,Create_by,Create_dt,CollectTime,CollectValue,Grade,Total,DataCfg,ErrCode,ErrTxt)");
            //    strSql.Append(" values (");
            //    strSql.Append("@CDate,@Ledger,@Co_id,@Module_id,@ModuleAddr,@Fun_id,@FunType,@FunName,@Content,@SysUid,now(),@CollectTime,@CollectValue,@Grade,1,@DataCfg,@ErrCode,@ErrTxt)");


            //    strSql.Append("insert into v2_alarm_log(");
            //    strSql.Append("CDate,Ledger,Co_id,Module_id,ModuleAddr,AType,Content,CTime,CollectTime,ErrCode,ErrTxt)");
            //    strSql.Append(" values (");
            //    strSql.Append("now(),@Ledger,@Co_id,@Module_id,@ModuleAddr,@AType,@Content,now(),now(),@ErrCode,@ErrTxt)");
            //    return SQLHelper.Execute(strSql.ToString(), params01);
            //}
            //else
            //{
            //    strSql.Append("update v2_alarm_log set Content=@Content,ErrCode=@ErrCode,ErrTxt=@ErrTxt where Log_id=@Log_id");
            //    return SQLHelper.Execute(strSql.ToString(), params01);
            //}
            return(0);
        }
Beispiel #2
0
 /// <summary>
 /// 获取IOService的事件数据
 /// </summary>
 /// <param name="lpszDbVarName"></param>
 /// <param name="lpszVal"></param>
 /// <param name="lpszdateTime"></param>
 /// <param name="errTxt"></param>
 internal static void IOServiceEventCollect(DataProcess.Rdc.Package.RdcMethod.IOEvent result)
 {
     foreach (var s1 in NCSys.Pro)
     {
         string        mkey    = s1.Value.ProjectKey + result.lpszDbVarName;
         CollectVModel collect = null;
         if (NCSys.Result.TryGetValue(mkey, out collect) == false)
         {
             continue;
         }
         if (collect.Module_id == 0)
         {
             continue;                        /*没有映射关系不存储告警*/
         }
         v2_alarm_logVModel alarm = new v2_alarm_logVModel();
         alarm.Ledger       = collect.Ledger;
         alarm.Module_id    = collect.Module_id;
         alarm.ModuleAddr   = collect.ModuleAddr;
         alarm.Fun_id       = collect.Fun_id;
         alarm.FunType      = collect.FunType;
         alarm.FunName      = result.lpszType;
         alarm.CollectTime  = result.lpszdateTime;
         alarm.CollectValue = result.lpszVal;
         alarm.Content      = result.content;
         alarm.ErrCode      = 1;
         alarm.ErrTxt       = "";
         alarm.IsMqtt       = true;
         NCSys.AlarmCollect.Enqueue(alarm); /*更新数据库*/
     }
 }
Beispiel #3
0
        public long AddAlarm(v2_alarm_logVModel alarm)
        {
            object parmas01 = new
            {
                Ledger       = this.Ledger,
                Module_id    = alarm.Module_id,
                ModuleAddr   = alarm.ModuleAddr,
                Fun_id       = alarm.Fun_id,
                FunType      = alarm.FunType,
                FunName      = alarm.FunName,
                CollectTime  = alarm.CollectTime,
                CollectValue = alarm.CollectValue,
                ErrCode      = alarm.ErrCode,
                ErrTxt       = alarm.ErrTxt,
                Content      = alarm.Content,
                SysUid       = this.SysUid,
            };
            StringBuilder strSql = new StringBuilder();
            long          log_id = 0;

            strSql.Clear();
            strSql.Append("insert into v2_alarm_log(");
            strSql.Append("CDate,Ledger,Co_id,Module_id,ModuleAddr,Fun_id,FunType,FunName,Content,Create_by,Create_dt,CollectTime,CollectValue,ErrCode,ErrTxt,Total)");
            strSql.Append("select now(),@Ledger,a.Co_id,@Module_id,@ModuleAddr,@Fun_id,@FunType,@FunName,@Content,@SysUid,now(),@CollectTime,@CollectValue,@ErrCode,@ErrTxt,1");
            strSql.Append(" from vp_mdinfo as a where a.Ledger=@Ledger and a.Module_id=@Module_id;");
            strSql.Append("select last_insert_id();");
            log_id = CommFunc.ConvertDBNullToLong(SQLHelper.ExecuteScalar(strSql.ToString(), parmas01));
            return(log_id);
        }
Beispiel #4
0
        private void button9_Click(object sender, EventArgs e)
        {
            bool bIsNext = true;
            var  enumer  = m2mqtt.GetEnumerator();

            while (bIsNext == true)
            {
                bIsNext = enumer.MoveNext();
                if (bIsNext == false)
                {
                    break;
                }
                var    s0  = enumer.Current;
                long   key = s0.Key;
                object obj = s0.Value;

                v2_alarm_logVModel am = CommFunc.GetPropertyValue("cc", obj) as v2_alarm_logVModel;
                DateTime           dd = CommFunc.ConvertDBNullToDateTime(CommFunc.GetPropertyValue("time", obj));
                int  count            = CommFunc.ConvertDBNullToInt32(CommFunc.GetPropertyValue("count", obj));
                bool isUp             = false;
                if (count == 0 || dd.AddMinutes(30) >= DateTime.Now)
                {
                    count = count + 1;
                    isUp  = true;
                }
                if (count == 6)
                {
                    m2mqtt.TryRemove(key, out obj);
                }
                else
                {
                    if (isUp == true)
                    {
                        object newObj = new { cc = am, time = DateTime.Now, count = count };
                        bool   tt     = m2mqtt.TryUpdate(key, newObj, obj);
                    }
                }
            }
            return;

            DateTime mTime = DateTime.Now;

            DateTime.TryParse("2019-10-10 14:25:36", out mTime);
            byte[] data = new byte[16];
            dllHepler.f_des_encryptByTimeEle(mTime.Year, mTime.Month, mTime.Day, mTime.Hour, mTime.Minute, mTime.Second, (float)1.2, data);
        }
Beispiel #5
0
        private void button5_Click(object sender, EventArgs e)
        {
            v2_alarm_logVModel cc = new v2_alarm_logVModel()
            {
                Log_id = ++log_id, Module_id = (int)log_id, ModuleAddr = log_id.ToString()
            };
            object dy = new { cc = cc, time = DateTime.Now, count = 0 };

            m2mqtt.TryAdd(log_id, dy);
            return;

            decimal value = (decimal)9.82;
            //string bbbbb = System.Convert.ToString(aaaaa, 16);
            string str = ((ulong)(value * 100)).ToString("x").Trim();

            byte[] ele = DirectToByte(str, 2);
            byte[] tes = new byte[] { 0x03, 0xd6 };

            byte[] aa = new byte[] { 0x03, 0xD6 };
            return;

            Sms.sendSms();
            return;

            byte a = 0x01;
            byte b = 0x18;
            int  k = a;

            k = k << 8;
            k = k + b;
            MessageBox.Show(k.ToString());
            return;

            List <dynamic> dd = new List <dynamic>();

            dd.Add(new { mp = "123456", name = "dfadf" });
            dd.Add(new { mp = "79564", name = "test" });
            foreach (var s in dd)
            {
                string mp   = s.mp;
                string name = s.name;
            }
            //MessageBox.Show((Math.Round(17.0 / 15.0,2,MidpointRounding.AwayFromZero)).ToString());
        }
Beispiel #6
0
        /// <summary>
        /// 获取告警信息
        /// </summary>
        /// <param name="co_id"></param>
        /// <param name="module_id"></param>
        /// <param name="moduleAddr"></param>
        /// <param name="aType"></param>
        /// <param name="rule"></param>
        /// <returns></returns>
        public v2_alarm_logVModel GetAlarmModel(int co_id, int module_id, string moduleAddr, string aType, decimal rule)
        {
            //double hh = (double)(0 - (rule * 24));
            //int hh = (int)rule + 1;
            int      hd       = (int)Math.Ceiling(rule) - 1;
            DateTime cTime    = DateTime.Now.AddDays(0 - hd);
            object   params01 = new
            {
                Ledger     = this.Ledger,
                CDate      = new DateTime(cTime.Year, cTime.Month, cTime.Day),
                Co_id      = co_id,
                Module_id  = module_id,
                ModuleAddr = moduleAddr,
                AType      = aType,
                CTime      = new DateTime(cTime.Year, cTime.Month, cTime.Day, cTime.Hour, 59, 59),
            };
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select Log_id,CDate,Co_id,Module_id,ModuleAddr,AType,Content,str_to_date(CONCAT(CDate,' ',CTime), '%Y-%m-%d %H:%i:%s') as CTime,ErrCode,ErrTxt");
            strSql.Append(" from v2_alarm_log");
            strSql.Append(" where CDate>=@CDate and Co_id=@Co_id and Module_id=@Module_id and ModuleAddr=@ModuleAddr and AType=@AType");
            //strSql.Append(" and str_to_date(CONCAT(CDate,' ',CTime), '%Y-%m-%d %H:%i:%s')>=@CTime");
            strSql.Append(" order by Log_id desc limit 1");
            DataTable          tab = SQLHelper.Query(strSql.ToString(), params01);
            v2_alarm_logVModel mm  = null;

            if (tab.Rows.Count > 0)
            {
                DateTime cdt = CommFunc.ConvertDBNullToDateTime(tab.Rows[0]["CTime"]);
                decimal  dd  = ((int)(DateTime.Now - cdt).TotalDays) * 24;
                decimal  hh  = (decimal)(DateTime.Now - cdt).TotalHours;
                /////////////////////////////////////////////////////////////////////
                decimal last = dd > hh ? dd : hh;
                if ((rule * 24) > last)
                {
                    mm = ModelHandler <v2_alarm_logVModel> .FillModel(tab.Rows[0]);
                }
            }
            return(mm);
        }
Beispiel #7
0
        private v2_alarm_logVModel AlarmInfo(DataRow dr, decimal cfValue, decimal cfRule)
        {
            int      co_id      = CommFunc.ConvertDBNullToInt32(dr["Co_id"]);
            string   coName     = CommFunc.ConvertDBNullToString(dr["CoName"]);
            int      chrgType   = CommFunc.ConvertDBNullToInt32(dr["ChrgType"]);
            DateTime lastTime   = CommFunc.ConvertDBNullToDateTime(dr["LastTime"]);
            decimal  rdVal      = CommFunc.ConvertDBNullToDecimal(dr["RdVal"]);
            decimal  price      = CommFunc.ConvertDBNullToDecimal(dr["Price"]);
            decimal  rdAmt      = Math.Round(rdVal * price, 2, MidpointRounding.AwayFromZero);
            int      module_id  = 0;
            string   moduleAddr = "";
            string   moduleName = CommFunc.ConvertDBNullToString(dr["ModuleName"]);

            if (chrgType >= 2)
            {
                module_id  = CommFunc.ConvertDBNullToInt32(dr["Module_id"]);
                moduleAddr = CommFunc.ConvertDBNullToString(dr["ModuleAddr"]);
            }
            string             ss  = "你好当前设备:" + moduleName + "余额:" + rdAmt.ToString("f2");
            v2_alarm_logVModel ems = bll.GetAlarmModel(co_id, module_id, moduleAddr, AlarmType.Alarm.ToString(), cfRule);

            if (ems == null)
            {
                ems            = new v2_alarm_logVModel();
                ems.Log_id     = 0;
                ems.Co_id      = co_id;
                ems.Module_id  = module_id;
                ems.ModuleAddr = moduleAddr;
                ems.AType      = AlarmType.Alarm.ToString();
            }
            ems.Content = ss;
            ems.ErrTxt  = "";
            if (ems.Log_id == 0)
            {
                bll.AddAlarm(ems);//增加log
            }
            return(ems);
        }
Beispiel #8
0
        //private static SendMessageApi send = new SendMessageApi();//uniPush初始化参数
        public void Run()
        {
            while (true)
            {
                Thread.Sleep(100);/*每100毫秒*/
                v2_alarm_logVModel cc = null;
                if (NCSys.AlarmCollect.TryDequeue(out cc) == true)
                {
                    try
                    {
                        DataProcessBLL bll    = new DataProcessBLL(cc.Ledger, Config.Uid);
                        long           log_id = bll.AddAlarm(cc);
                        if (cc.IsMqtt == true)
                        {
                            object dy = new { cc = cc, time = DateTime.Now, count = 0 };
                            m2mqtt.TryAdd(log_id, dy);
                        }
                    }
                    catch (Exception ex)
                    {
                        FileLog.Error("内容:" + JsonHelper.Serialize(cc) + "记录告警错误:" + ex.Message + ex.StackTrace);
                    }
                }

                try
                {/*告警信息半个钟推一次,一共需要6次,现场确认下来了*/   /*2020.01.06 最新修改设置 告警信息一分钟推一次,一共需要10次*/
                    bool bIsNext = true;
                    var  enumer  = m2mqtt.GetEnumerator();
                    while (bIsNext == true)
                    {
                        Thread.Sleep(1000);/*每100毫秒*/
                        bIsNext = enumer.MoveNext();
                        if (bIsNext == false)
                        {
                            break;
                        }
                        var    s0  = enumer.Current;
                        long   key = s0.Key;
                        object obj = s0.Value;

                        v2_alarm_logVModel am = CommFunc.GetPropertyValue("cc", obj) as v2_alarm_logVModel;
                        DateTime           dd = CommFunc.ConvertDBNullToDateTime(CommFunc.GetPropertyValue("time", obj));
                        int  count            = CommFunc.ConvertDBNullToInt32(CommFunc.GetPropertyValue("count", obj));
                        bool isUp             = false;
                        int  Log_id           = 0;
                        int  Co_id            = 0;
                        if (count == 0 || DateTime.Now >= dd.AddMinutes(1)) //一分钟推一次
                        {
                            //权限过滤
                            DataProcessBLL bll = new DataProcessBLL(am.Ledger, Config.Uid);
                            //string AreaPowerStr = "";
                            //bool IsCheckAreaPower = bll.GetAlarmFisrt(am.Ledger, Config.Uid, out AreaPowerStr);
                            //bool qx = false;
                            //string[] sArray = AreaPowerStr.Split(',');
                            var datas = bll.Getv2_alarm_log(CommFunc.ConvertDBNullToInt32(key)); //历史表
                            if (datas.Rows.Count > 0)
                            {
                                Log_id = CommFunc.ConvertDBNullToInt32(datas.Rows[0]["Log_id"].ToString());
                                Co_id  = CommFunc.ConvertDBNullToInt32(datas.Rows[0]["Co_id"].ToString());
                                //var Content = datas.Rows[0]["Content"].ToString();
                                //foreach (string i in sArray)
                                //{
                                //    if (Co_id == CommFunc.ConvertDBNullToInt32(i))
                                //    {
                                //        qx = true;
                                //        continue;
                                //    }
                                //}
                            }
                            //if (qx)
                            //{
                            var content = am.Content + "," + Co_id;
                            DataProcess.Business.m2mqtt.Publish(content);
                            //send.send(content,"CID");//uniPush推送
                            count = count + 1;
                            isUp  = true;
                            FileLog.WriteLog("Log_id:" + key + " 推送次数:" + count);
                            //}

                            //FileLog.WriteLog("+++++++ Ledger;" + am.Ledger + " Uid;" + Config.Uid + " Log_id:" + key + " 库Log_id:" + am.Log_id + " 库Co_id:" + Co_id + " 权限ID:" + AreaPowerStr + " +++++++");
                        }
                        if (count == 10)
                        {//一共需要10次
                            m2mqtt.TryRemove(key, out obj);
                            FileLog.WriteLog("Log_id:" + key + " 推送:" + count + "移除");
                        }
                        else
                        {
                            if (isUp == true)
                            {
                                object newObj = new { cc = am, time = DateTime.Now, count = count };
                                if (m2mqtt.TryUpdate(key, newObj, obj))
                                {
                                    FileLog.WriteLog("Log_id:" + key + " 推送:" + count + " 更新成功!");
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    //m2mqtt.Clear(); //移除所有的键和值.
                    FileLog.Error("推送mqtt记录内容错误:" + ex.Message + ex.StackTrace);
                }
            }
        }
Beispiel #9
0
        internal bool GetAlarm()
        {
            DataTable dtSource      = null;
            DataTable dtAlarmConfig = null;

            try
            {
                dtAlarmConfig = bll.GetAlarmConfig();
                int     cnt       = dtAlarmConfig.Rows.Count;
                decimal alarmVal1 = cnt == 0 ? 0 : CommFunc.ConvertDBNullToDecimal(dtAlarmConfig.Rows[0]["CfValue"]);
                string  unit      = cnt == 0 ? "" : CommFunc.ConvertDBNullToString(dtAlarmConfig.Rows[0]["Unit"]);
                dtSource = bll.GetAlarmData(alarmVal1, unit);
            }
            catch (Exception ex)
            {
                FileLog.WriteLog("获取告警数据错误:" + ex.Message + ex.StackTrace);
            }
            //
            if (dtSource == null)
            {
                return(false);
            }
            Thread.Sleep(100);
            int co_idPrev = -9999;

            foreach (DataRow dr in dtSource.Rows)
            {
                int      co_id = CommFunc.ConvertDBNullToInt32(dr["Co_id"]);
                string   coName = CommFunc.ConvertDBNullToString(dr["CoName"]);
                int      chrgType = CommFunc.ConvertDBNullToInt32(dr["ChrgType"]); /*<=1 房间 >1电表*/
                int      isAlarm = CommFunc.ConvertDBNullToInt32(dr["IsAlarm"]);   /*<=1 房间 >1电表*/
                DateTime lastTime = CommFunc.ConvertDBNullToDateTime(dr["LastTime"]);
                int      transferType = CommFunc.ConvertDBNullToInt32(dr["TransferType"]);
                decimal  rdVal = CommFunc.ConvertDBNullToDecimal(dr["RdVal"]);
                decimal  price = CommFunc.ConvertDBNullToDecimal(dr["Price"]);
                decimal  rdAmt = CommFunc.ConvertDBNullToDecimal(dr["RdAmt"]);
                int      module_id = CommFunc.ConvertDBNullToInt32(dr["Module_id"]);
                string   moduleAddr = CommFunc.ConvertDBNullToString(dr["ModuleAddr"]);
                string   moduleName = CommFunc.ConvertDBNullToString(dr["ModuleName"]);
                string   cfKey = "", cfUnit = "";
                decimal  cfValue = 0;
                decimal  cfRule  = 1;
                bool     isRun   = true;
                if (chrgType <= 1 && co_idPrev == co_id)
                {
                    isRun = false;
                }
                co_idPrev = co_id;
                if (isRun == false)
                {
                    continue;
                }
                int ccc = dtAlarmConfig.Rows.Count;
                int crn = 0;
                foreach (DataRow drC in dtAlarmConfig.Rows)
                {/*从大到小排列*/
                    cfKey   = CommFunc.ConvertDBNullToString(drC["CfKey"]);
                    cfValue = CommFunc.ConvertDBNullToDecimal(drC["CfValue"]);
                    cfRule  = CommFunc.ConvertDBNullToDecimal(drC["Rule"]);
                    cfUnit  = CommFunc.ConvertDBNullToString(drC["Unit"]).ToLower();
                    if (pro.Project.Equals("YdXip") && cfKey.Equals("AlarmValOd"))
                    {/*西安培华的拉闸电量*/
                        cfValue = CommFunc.ConvertDBNullToDecimal(dr["OdValue"]);
                    }
                    //if (!cfKey.ToLower().Equals("AlarmValOd".ToLower()))
                    //    cfRule = cfRule == 0 ? 1 : cfRule;
                    decimal comVal  = string.IsNullOrEmpty(cfUnit) || cfUnit.Equals("kWh".ToLower()) ? rdVal : rdAmt;
                    decimal toValue = cfValue;
                    if (crn < ccc - 1)
                    {
                        toValue = CommFunc.ConvertDBNullToDecimal(dtAlarmConfig.Rows[crn + 1]["CfValue"]);
                    }
                    if (cfValue >= comVal && comVal > toValue)
                    {
                        break;
                    }
                    crn = crn + 1;
                }
                //FileLog.WriteLog("电表ID:" + module_id + "地址:" + moduleAddr + "房间:" + coName + "剩余电量:" + rdVal + "告警类型:" + cfKey + "规则:" + cfRule + "告警值:" + cfValue);
                bool sendAlarm = true;
                if (cfKey.ToLower().Equals("AlarmValOd".ToLower()) && isAlarm == 1)
                {     /*拉合闸*/
                    if (CommFunc.ConvertDBNullToInt32(cfRule) == 1)
                    { /*发送拉合闸命令*/
                        sendAlarm = false;
                        try
                        {
                            string key    = pro.ProjectKey + CommFunc.ConvertDBNullToString(dr["LpszSsr"]);
                            RstVar rstVar = MemcachedMgr.GetVal <RstVar>(key);
                            bool   isPass = false;
                            if (rstVar != null && CommFunc.ConvertDBNullToDecimal(rstVar.lpszVal) == 0)
                            {
                                isPass = true;
                            }

                            if (isPass == true)
                            {
                                this.CtorlSsr1(module_id);
                            }
                        }
                        catch (Exception ex)
                        {
                            FileLog.Error("透支电量发送拉合闸命令错误:" + ex.Message + ex.StackTrace);
                        }
                    }
                }
                if (sendAlarm == true)
                {/*发送告警*/
                    cfRule = cfRule == 0 ? 1 : cfRule;
                    v2_alarm_logVModel alarmInfo = this.AlarmInfo(dr, cfValue, cfRule);
                    if (isAlarm == 1)
                    {
                        if (!string.IsNullOrEmpty(EmailUtilities.EmConfig.MailFrom) && !string.IsNullOrEmpty(EmailUtilities.EmConfig.MailSmtpHost) &&
                            !string.IsNullOrEmpty(EmailUtilities.EmConfig.MailSmtpUser) && !string.IsNullOrEmpty(EmailUtilities.EmConfig.MailSmtpPassword)
                            )
                        {/*邮件告警*/
                            this.AlarmEmail(alarmInfo.Log_id, co_id, coName, lastTime, rdVal);
                        }
                        if (!string.IsNullOrEmpty(pro.Sms.ComSmsConfig.ComSms) ||
                            (!string.IsNullOrEmpty(SmsFun.AliSmsConfig.AliAppKey) && !string.IsNullOrEmpty(SmsFun.AliSmsConfig.AliAppSecret) && !string.IsNullOrEmpty(SmsFun.AliSmsConfig.AliSignName))
                            )
                        {/*短信告警*/
                            this.AlarmSms(alarmInfo.Log_id, co_id, moduleName, coName, lastTime, rdVal, rdAmt);
                        }
                        if (!string.IsNullOrEmpty(pro.Wx.WxConfig.WxAPPID))
                        {/*微信告警*/
                         //this.AlarmWx(alarmInfo.Log_id, co_id, coName, lastTime, rdVal);
                        }
                    }
                }
            }
            return(true);
        }
Beispiel #10
0
        //public DataTable GetOpenidList(int co_id)
        //{
        //    return dal.GetOpenidList(co_id);
        //}

        public int AddAlarm(v2_alarm_logVModel am)
        {
            return(dal.AddAlarm(am));
        }
Beispiel #11
0
 public long AddAlarm(v2_alarm_logVModel alarm)
 {
     return(dal.AddAlarm(alarm));
 }