예제 #1
0
        private ParkingSingleton(IHubConnectionContext <dynamic> clients)
        {
            Clients = clients;

            log = LogFactory.GetLogger("ParkingSingleton");

            #region 给主页面显示用的
            MainCallback <Location> .Instance().WatchEvent += FileWatch_LctnWatchEvent;

            MainCallback <Device> .Instance().WatchEvent += FileWatch_DeviceWatchEvent;

            MainCallback <ImplementTask> .Instance().WatchEvent += FileWatch_IMPTaskWatchEvent;

            MainCallback <WorkTask> .Instance().WatchEvent += FileWatch_WatchEvent;

            #endregion

            #region 个推
            SingleCallback.Instance().ICCardWatchEvent  += ParkingSingleton_ICCardWatchEvent;
            SingleCallback.Instance().FaultsWatchEvent  += ParkingSingleton_FaultsWatchEvent;
            SingleCallback.Instance().PlateWatchEvent   += ParkingSingleton_PlateWatchEvent;
            SingleCallback.Instance().FixLocsWatchEvent += ParkingSingleton_FixLocsWatchEvent;
            #endregion

            #region 给云服务数据推送的
            CloudCallback.Instance().ParkingRcdWatchEvent += ParkingSingleton_ParkingRcdWatchEvent;
            CloudCallback.Instance().MasterTaskWatchEvent += ParkingSingleton_MasterTaskWatchEvent;
            CloudCallback.Instance().ImpTaskWatchEvent    += ParkingSingleton_ImpTaskWatchEvent;
            CloudCallback.Instance().SendSMSWatchEvent    += ParkingSingleton_SendSMSWatchEvent;
            #endregion
        }
예제 #2
0
        /// <summary>
        /// 批量更新
        /// </summary>
        /// <param name="alarmLst"></param>
        /// <returns></returns>
        public async Task <Response> UpdateAlarmListAsync(List <Alarm> alarmLst)
        {
            Response resp = new Response();
            Log      log  = LogFactory.GetLogger("UpdateAlarmList");

            try
            {
                resp = await manager_alarm.UpdateAlarmListAsync(alarmLst);

                #region 报警记录写入数据库
                List <Alarm> faultLst = alarmLst.FindAll(f => f.Color == EnmAlarmColor.Red && f.Description.Contains("备用") == false);
                if (faultLst.Count > 0)
                {
                    new CWFaultLog().AddFaultRecord(faultLst);
                }
                #endregion

                #region 写状态位记录入数据库
                List <Alarm> statusLst = alarmLst.FindAll(f => f.Color == EnmAlarmColor.Green && f.Description.Contains("备用") == false);
                if (faultLst.Count > 0)
                {
                    new CWStatusLog().AddStateRecord(statusLst);
                }
                #endregion

                #region 推送至显示
                int warehouse            = alarmLst.First().Warehouse;
                int devicecode           = alarmLst.First().DeviceCode;
                List <BackAlarm> backlst = new List <BackAlarm>();

                List <Alarm> hasValueLst = await manager_alarm.FindListAsync(al => al.Warehouse == warehouse && al.DeviceCode == devicecode && al.Value == 1);

                foreach (Alarm ar in hasValueLst)
                {
                    if (ar.Description.Contains("备用"))
                    {
                        continue;
                    }
                    int type = 0;
                    if (ar.Color == EnmAlarmColor.Green)
                    {
                        type = 1;
                    }
                    else if (ar.Color == EnmAlarmColor.Red)
                    {
                        type = 2;
                    }

                    BackAlarm back = new BackAlarm
                    {
                        Type        = type,
                        Description = ar.Description
                    };

                    backlst.Add(back);
                }
                SingleCallback.Instance().WatchFaults(warehouse, devicecode, backlst);
                #endregion

                #region 向云服务请求短信发送
                if (faultLst.Count > 0)
                {
                    Alarm  myalarm = faultLst[0];
                    Device smg     = await FindAsync(d => d.Warehouse == myalarm.Warehouse && d.DeviceCode == myalarm.DeviceCode);

                    if (smg == null || smg.TaskID == 0)
                    {
                        return(resp);
                    }
                    //一定是作业时报警才上报
                    ImplementTask itask = await new CWTask().FindAsync(smg.TaskID);
                    if (itask == null)
                    {
                        return(resp);
                    }

                    SMSInfo sms = null;
                    if (dicSmsRequest.ContainsKey(smg.DeviceCode))
                    {
                        SMSInfo info = dicSmsRequest[smg.DeviceCode];
                        //同一个任务,只发送一次
                        if (info.Plate == itask.PlateNum)
                        {
                            return(resp);
                        }
                        //15分钟内只允许发送一条
                        DateTime rcdtime = DateTime.Parse(info.RcdTime);
                        if (DateTime.Compare(rcdtime, DateTime.Now.AddMinutes(15)) < 0)
                        {
                            return(resp);
                        }
                        ////内容重复的,一个小时内只发一次
                        //if (info.Message == myalarm.Description&& DateTime.Compare(rcdtime, DateTime.Now.AddHours(1)) < 0)
                        //{
                        //    return resp;
                        //}

                        sms = new SMSInfo {
                            warehouse  = smg.Warehouse,
                            DeviceCode = smg.DeviceCode,
                            Plate      = itask.PlateNum,
                            AutoStep   = smg.RunStep,
                            Message    = myalarm.Description,
                            RcdTime    = DateTime.Now.ToString()
                        };
                        dicSmsRequest[smg.DeviceCode] = sms;
                    }
                    else
                    {
                        sms = new SMSInfo
                        {
                            warehouse  = smg.Warehouse,
                            DeviceCode = smg.DeviceCode,
                            Plate      = itask.PlateNum,
                            AutoStep   = smg.RunStep,
                            Message    = myalarm.Description,
                            RcdTime    = DateTime.Now.ToString()
                        };

                        dicSmsRequest.Add(smg.DeviceCode, sms);
                    }

                    if (sms != null)
                    {
                        log.Info("发送短信 - " + sms.Message);

                        CloudCallback.Instance().SendSMSToCloud(sms);
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                log.Error(ex.ToString());
            }
            return(resp);
        }
예제 #3
0
        /// <summary>
        /// 数据入库
        /// </summary>
        /// <param name="orig"></param>
        /// <returns></returns>
        public Response LocationIn(Location orig)
        {
            Response resp      = new Response();
            int      warehouse = orig.Warehouse;
            string   Addrs     = orig.Address;
            Location loc       = new CWLocation().FindLocation(lc => lc.Warehouse == warehouse && lc.Address == Addrs);

            if (loc == null)
            {
                resp.Message = "找不到车位-" + Addrs;
                return(resp);
            }
            if (loc.Type != EnmLocationType.Normal)
            {
                resp.Message = "车位不可用,请使用另一个";
                return(resp);
            }
            if (loc.Status != EnmLocationStatus.Space)
            {
                resp.Message = "当前车位不是空闲的,无法使用该车位!";
                return(resp);
            }
            if (string.Compare(loc.LocSize, orig.CarSize) < 0)
            {
                resp.Message = "车位尺寸不匹配,无法完成操作!";
                return(resp);
            }
            SaveCertificate scert = new SaveCertificate();

            scert.IsFingerPrint = 2;
            int proof = Convert.ToInt32(orig.ICCode);

            if (proof >= 10000)
            {
                //是指纹时,找出是否注册了
                FingerPrint fprint = new CWFingerPrint().Find(fp => fp.SN_Number == proof);
                if (fprint == null)
                {
                    resp.Message = "当前凭证是指纹编号,但库里找不到注册的指纹";
                    return(resp);
                }
                scert.Proof  = fprint.FingerInfo;
                scert.SNO    = fprint.SN_Number;
                scert.CustID = fprint.CustID;
            }
            else
            {
                ICCard iccode = new CWICCard().Find(ic => ic.UserCode == orig.ICCode);
                if (iccode == null)
                {
                    resp.Message = "请先注册当前卡号,再使用!";
                    return(resp);
                }
                if (iccode.Status != EnmICCardStatus.Normal)
                {
                    resp.Message = "该卡已注销或挂失!";
                    return(resp);
                }
                scert.Proof  = iccode.PhysicCode;
                scert.SNO    = Convert.ToInt32(iccode.UserCode);
                scert.CustID = iccode.CustID;
            }
            #region 判断存车指纹库中,是否有该记录,如果有,则需更换信息
            CWSaveProof     cwsaveprooft = new CWSaveProof();
            SaveCertificate svcert       = cwsaveprooft.Find(s => s.Proof == scert.Proof);
            if (svcert != null)
            {
                resp.Message = "存车指纹库中存在该记录,当前卡号不可用!";
                return(resp);
            }
            #endregion
            Location lctn = new CWLocation().FindLocation(l => l.ICCode == orig.ICCode);
            if (lctn != null)
            {
                resp.Message = "该卡已被使用,车位 - " + lctn.Address;
                return(resp);
            }
            ImplementTask itask = new CWTask().Find(tsk => tsk.ICCardCode == orig.ICCode);
            if (itask != null)
            {
                resp.Message = "该卡正在作业,无法使用";
                return(resp);
            }
            WorkTask wtask = new CWTask().FindQueue(wk => wk.ICCardCode == orig.ICCode);
            if (wtask != null)
            {
                resp.Message = "该卡已加入队列,无法使用";
                return(resp);
            }

            loc.Status    = EnmLocationStatus.Occupy;
            loc.ICCode    = orig.ICCode;
            loc.WheelBase = orig.WheelBase;
            loc.CarSize   = orig.CarSize;
            loc.PlateNum  = orig.PlateNum;
            loc.InDate    = orig.InDate;
            loc.ImagePath = "";

            resp = new CWLocation().UpdateLocation(loc);

            string     rcdmsg = "数据入库,卡号 - " + loc.ICCode + " 车位 - " + loc.Address + " 轴距 - " + loc.WheelBase + " 外形 - " + loc.CarSize;
            OperateLog olog   = new OperateLog
            {
                Description = rcdmsg,
                CreateDate  = DateTime.Now,
                OptName     = ""
            };
            new CWOperateRecordLog().AddOperateLog(olog);

            //添加到指纹库中
            cwsaveprooft.Add(scert);

            #region 推送停车记录给云平台
            ParkingRecord pkRecord = new ParkingRecord
            {
                TaskType   = 0,
                LocAddrs   = loc.Address,
                Proof      = loc.ICCode,
                PlateNum   = loc.PlateNum,
                carpicture = loc.ImagePath,
                CarSize    = Convert.ToInt32(loc.CarSize),
                LocSize    = Convert.ToInt32(loc.LocSize),
                InDate     = loc.InDate.ToString()
            };
            CloudCallback.Instance().WatchParkingRcd(pkRecord);
            #endregion

            return(resp);
        }
예제 #4
0
        /// <summary>
        /// 数据出库
        /// </summary>
        /// <param name="wh"></param>
        /// <param name="addrs"></param>
        /// <returns></returns>
        public Response LocationOut(int warehouse, string Addrs)
        {
            Response resp = new Response();
            Location loc  = FindLocation(lc => lc.Warehouse == warehouse && lc.Address == Addrs);

            if (loc == null)
            {
                resp.Message = "找不到车位-" + Addrs;
                return(resp);
            }
            #region 推送停车记录给云平台
            ParkingRecord pkRecord = new ParkingRecord
            {
                TaskType   = 1,
                LocAddrs   = loc.Address,
                Proof      = loc.ICCode,
                PlateNum   = loc.PlateNum,
                carpicture = loc.ImagePath,
                CarSize    = string.IsNullOrEmpty(loc.CarSize) ? 0 : Convert.ToInt32(loc.CarSize),
                LocSize    = string.IsNullOrEmpty(loc.LocSize) ? 0 : Convert.ToInt32(loc.LocSize),
                InDate     = loc.InDate.ToString()
            };
            CloudCallback.Instance().WatchParkingRcd(pkRecord);
            #endregion

            string iccd = loc.ICCode;

            loc.Status    = EnmLocationStatus.Space;
            loc.ICCode    = "";
            loc.WheelBase = 0;
            loc.CarSize   = "";
            loc.InDate    = DateTime.Parse("2017-1-1");
            loc.PlateNum  = "";
            loc.ImagePath = "";

            resp = new CWLocation().UpdateLocation(loc);

            string     rcdmsg = "数据出库,卡号 - " + iccd + " 车位 - " + loc.Address;
            OperateLog olog   = new OperateLog
            {
                Description = rcdmsg,
                CreateDate  = DateTime.Now,
                OptName     = ""
            };
            new CWOperateRecordLog().AddOperateLog(olog);

            #region  除存车指纹库记录
            if (!string.IsNullOrEmpty(iccd))
            {
                CWSaveProof     cwsaveproof = new CWSaveProof();
                int             sno         = Convert.ToInt32(iccd);
                SaveCertificate scert       = cwsaveproof.Find(d => d.SNO == sno);
                if (scert != null)
                {
                    cwsaveproof.Delete(scert.ID);
                }
            }
            #endregion

            return(resp);
        }