public static void Execute() { Task.Factory.StartNew(() => { //从mq获取进场数据 ILogger m_ilogger = new Logger.Logger(); ISerializer m_serializer = new JsonSerializer(m_ilogger); RabbitMQPeeker m_rabbitMQ = new RabbitMQPeeker(m_ilogger, m_serializer); IDatabase db; m_rabbitMQ.PeekMessageByRabbitMQ("4GCameraEntryDataQueue", "4GCameraEntryDataQueue", (string content) => { db = FollowRedisHelper.GetDatabase(0); VehicleInRequest inmodel = m_serializer.Deserialize<VehicleInRequest>(content); if (inmodel != null) { //不为空说明是入场数据 string drivewayguid = db.HashGet("DrivewayLinkMACList", inmodel.DriveWayMAC); DrivewayModel drivewaymodel = m_serializer.Deserialize<DrivewayModel>(db.HashGet("DrivewayList", drivewayguid ?? "")); if (drivewaymodel == null) return RabbitMQAction.REJECT; CarTypeModel cartypemodel = m_serializer.Deserialize<CarTypeModel>(db.HashGet("CarTypeList", inmodel.CarTypeGuid)); if (cartypemodel == null) return RabbitMQAction.REJECT; ParkLotModel parklotmodel = m_serializer.Deserialize<ParkLotModel>(db.HashGet("ParkLotList", cartypemodel.ParkCode)); if (parklotmodel == null) return RabbitMQAction.REJECT; VehicleEntryDetailModel entrymodel = new VehicleEntryDetailModel() { RecordGuid = inmodel.Guid, ParkingName = parklotmodel.ParkName, ParkingCode = parklotmodel.ParkCode, CarNo = inmodel.CarNo, InImgUrl = inmodel.ImgUrl, BeginTime = inmodel.InTime, CarTypeGuid = inmodel.CarTypeGuid, Description = inmodel.Remark, CarType = cartypemodel.CarType, CarTypeName = cartypemodel.CarTypeName, Entrance = drivewaymodel.DrivewayName, DriveWayMAC=inmodel.DriveWayMAC }; //存到redis try { db = FollowRedisHelper.GetDatabase(GetDatabaseNumber(entrymodel.CarNo)); db.HashSet(entrymodel.CarNo, entrymodel.ParkingCode, m_serializer.Serialize(entrymodel)); //存储入场数据 bool flag = db.HashExists(entrymodel.CarNo, entrymodel.ParkingCode); //存储成功后在1号db存储在场车牌 在2号db存储待广播的车牌 ////3号db缓存半小时该进场数据 if (flag) { db = FollowRedisHelper.GetDatabase(1); db.HashSet(entrymodel.ParkingCode, entrymodel.CarNo, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //存储车场在场车牌索引 flag = db.HashExists(entrymodel.ParkingCode, entrymodel.CarNo); } //存储成功后在2号db存储待广播的车牌 if (flag) { db = FollowRedisHelper.GetDatabase(2); db.HashSet(entrymodel.ParkingCode, entrymodel.CarNo, content); flag = db.HashExists(entrymodel.ParkingCode, entrymodel.CarNo); } //存储成功后在3号db存储入场车数据半小时 if (flag) { db = FollowRedisHelper.GetDatabase(3); string key = string.Format("{0}_{1}", drivewaymodel.Guid, entrymodel.CarNo); db.StringSet(key, content.Replace("InTime", "EventTime"), TimeSpan.FromSeconds(0.5 * 3600)); flag = db.KeyExists(key); } //如果是临时车辆,并且redis存储成功后 if (entrymodel.CarType == 0 && flag) { //再往主平台Fujica补发入场数据 EntryDataToFujica(entrymodel.CarNo, entrymodel.ParkingCode, entrymodel.ParkingName, entrymodel.RecordGuid, entrymodel.DriveWayMAC, entrymodel.Entrance, entrymodel.InImgUrl, entrymodel.BeginTime, cartypemodel.Idx); } if (!flag) return RabbitMQAction.RETRY; } catch (Exception ex) { m_ilogger.LogFatal(LoggerLogicEnum.Tools, "", entrymodel.ParkingCode, "", "Fujica.com.cn.EntryDataService.MonitorEnterData", "保存入场数据到redis异常", ex.ToString()); return RabbitMQAction.RETRY; } } return RabbitMQAction.ACCEPT; }); }); }
public static void Execute() { Task.Factory.StartNew(() => { //从mq获取出场数据 ILogger m_ilogger = new Logger.Logger(); ISerializer m_serializer = new JsonSerializer(m_ilogger); RabbitMQPeeker m_rabbitMQ = new RabbitMQPeeker(m_ilogger, m_serializer); IDatabase db; m_rabbitMQ.PeekMessageByRabbitMQ("4GCameraExitDataQueue", "4GCameraExitDataQueue", (string content) => { db = FollowRedisHelper.GetDatabase(0); VehicleOutRequest outmodel = m_serializer.Deserialize <VehicleOutRequest>(content); if (outmodel != null) { //不为空说明是出场数据 string drivewayguid = db.HashGet("DrivewayLinkMACList", outmodel.DriveWayMAC); DrivewayModel drivewaymodel = m_serializer.Deserialize <DrivewayModel>(db.HashGet("DrivewayList", drivewayguid ?? "")); if (drivewaymodel == null) { return(RabbitMQAction.REJECT); } CarTypeModel cartypemodel = m_serializer.Deserialize <CarTypeModel>(db.HashGet("CarTypeList", outmodel.CarTypeGuid)); if (cartypemodel == null) { return(RabbitMQAction.REJECT); } ParkLotModel parklotmodel = m_serializer.Deserialize <ParkLotModel>(db.HashGet("ParkLotList", drivewaymodel.ParkCode)); if (parklotmodel == null) { return(RabbitMQAction.REJECT); } VehicleExitDetailModel exitmodel = new VehicleExitDetailModel() { RecordGuid = outmodel.Guid, ParkingName = parklotmodel.ParkName, ParkingCode = parklotmodel.ParkCode, CarNo = outmodel.CarNo, OutImgUrl = outmodel.ImgUrl, LeaveTime = outmodel.OutTime, Description = outmodel.Remark, Exit = drivewaymodel.DrivewayName }; //redis操作 try { db = FollowRedisHelper.GetDatabase(GetDatabaseNumber(exitmodel.CarNo)); //删除前先拿到实体内容 VehicleEntryDetailModel entrymodel = m_serializer.Deserialize <VehicleEntryDetailModel>(db.HashGet(exitmodel.CarNo, exitmodel.ParkingCode)); db.HashDelete(exitmodel.CarNo, exitmodel.ParkingCode); //删除成功后在1号db移除该在场车牌,在2号db移除待广播的车牌(如果未广播的情况下) //3号db缓存半小时该出场数据 //1号 db = FollowRedisHelper.GetDatabase(1); db.HashDelete(exitmodel.ParkingCode, exitmodel.CarNo); //2号 db = FollowRedisHelper.GetDatabase(2); db.HashDelete(exitmodel.ParkingCode, exitmodel.CarNo); //3号 db = FollowRedisHelper.GetDatabase(3); string key = string.Format("{0}_{1}", drivewaymodel.Guid, exitmodel.CarNo); db.StringSet(key, content.Replace("OutTime", "EventTime"), TimeSpan.FromSeconds(0.5 * 3600)); //如果是临时车辆,并且入场实体不为空,则往主平台Fujica补发出场数据 if (cartypemodel.CarType == 0 && entrymodel != null) { ExitDataToFujica(exitmodel.CarNo, exitmodel.ParkingCode, entrymodel.Entrance, exitmodel.Exit, entrymodel.BeginTime, exitmodel.LeaveTime, entrymodel.InImgUrl, exitmodel.OutImgUrl, exitmodel.RecordGuid, cartypemodel.Idx); } return(RabbitMQAction.ACCEPT); } catch (Exception ex) { m_ilogger.LogFatal(LoggerLogicEnum.Tools, "", exitmodel.ParkingCode, "", "Fujica.com.cn.ExitDataService.MonitorEnterData", "在redis移除停车数据异常", ex.ToString()); return(RabbitMQAction.RETRY); } } return(RabbitMQAction.ACCEPT); //无效数据的时候直接返回成功 }); }); }