public static bool Execute(string parkingCode, string guid, string carNo, DateTime beginTime, DateTime lastTime) { if (string.IsNullOrEmpty(guid) || string.IsNullOrEmpty(carNo) || beginTime == null || lastTime == null) { return(false); } ILogger m_ilogger = new Logger.Logger(); ISerializer m_serializer = new JsonSerializer(m_ilogger); RabbitMQSender m_rabbitMQ = new RabbitMQSender(m_ilogger, m_serializer); IDatabase db; db = FollowRedisHelper.GetDatabase(0); RedisValue parklotredis = db.HashGet("ParkLotList", parkingCode); if (parklotredis != RedisValue.Null) { ParkLotModel parklotmodel = m_serializer.Deserialize <ParkLotModel>(parklotredis); if (parklotmodel != null) { List <string> drivewaylist = parklotmodel.DrivewayList; //所有车道 if (drivewaylist != null) { //要广播的缴费数据 TempCardModel tempCarModel = new TempCardModel(); tempCarModel.Guid = guid; tempCarModel.CarNo = carNo; tempCarModel.BeginTime = beginTime; tempCarModel.LatestTime = lastTime; tempCarModel.HavePaid = true; foreach (var drivewayguid in drivewaylist) { DrivewayModel drivewaymodel = m_serializer.Deserialize <DrivewayModel>(db.HashGet("DrivewayList", drivewayguid)); //广播到所有出口车道 if (drivewaymodel.Type == DrivewayType.Out) { CommandEntity <TempCardModel> sendCommand = new CommandEntity <TempCardModel>() { command = BussineCommand.TempCar, idMsg = Convert.ToBase64String(Guid.NewGuid().ToByteArray()), message = tempCarModel }; if (m_rabbitMQ.SendMessageForRabbitMQ("发送缴费数据广播命令", m_serializer.Serialize(sendCommand), drivewaymodel.DeviceMacAddress, parkingCode)) { //广播成功 } } } } } } return(true); }
public void Execute(IJobExecutionContext context) { Task.Factory.StartNew(() => { //从redis获取进场待广播数据进行广播 ILogger m_ilogger = new Logger.Logger(); ISerializer m_serializer = new JsonSerializer(m_ilogger); RabbitMQSender m_rabbitMQ = new RabbitMQSender(m_ilogger, m_serializer); IDatabase db = FollowRedisHelper.GetDatabase(2); IServer srv = FollowRedisHelper.GetCurrentServer(); IEnumerable <RedisKey> allParkingCode = srv.Keys(2); foreach (var parkingcode in allParkingCode) { HashEntry[] hashentryarray = db.HashGetAll(parkingcode); //所有实体 string[] allCarNo = db.HashKeys(parkingcode).ToStringArray(); //所有车牌 db = FollowRedisHelper.GetDatabase(0); RedisValue parklotredis = db.HashGet("ParkLotList", parkingcode.ToString()); if (parklotredis != RedisValue.Null) { ParkLotModel parklotmodel = m_serializer.Deserialize <ParkLotModel>(parklotredis); List <string> drivewaylist = parklotmodel.DrivewayList; //所有车道 if (drivewaylist != null) { foreach (var carno in allCarNo) { HashEntry hashenrty = hashentryarray.SingleOrDefault(o => o.Name == carno); string enterdata = hashenrty.Value; //要广播的入场数据 foreach (var drivewayguid in drivewaylist) { DrivewayModel drivewaymodel = m_serializer.Deserialize <DrivewayModel>(db.HashGet("DrivewayList", drivewayguid)); if (drivewaymodel.Type == DrivewayType.Out) { //广播到出口车道 string sendmsg = string.Format("{{\"command\":{0},\"idMsg\":\"{1}\",\"message\":{2}}}", 13, Convert.ToBase64String(Guid.NewGuid().ToByteArray()), enterdata); if (m_rabbitMQ.SendMessageForRabbitMQ("发送入场数据广播命令", sendmsg, drivewaymodel.DeviceMacAddress, parkingcode)) { //广播成功,移除缓存的数据 db = FollowRedisHelper.GetDatabase(2); db.HashDelete(parkingcode, carno); } } } } } } } }); }
public static void Execute() { Task.Factory.StartNew(() => { ILogger m_ilogger = new Logger.Logger(); ISerializer m_serializer = new JsonSerializer(m_ilogger); RabbitMQPeeker m_rabbitMQ = new RabbitMQPeeker(m_ilogger, m_serializer); IDatabase db; //队列 string queue = ""; //路由key string routingKey = ""; m_rabbitMQ.PeekMessageByRabbitMQ(queue, routingKey, (string content) => { //转换成Fujica缴费实体 IssuedRecord payModel = m_serializer.Deserialize <IssuedRecord>(content); if (payModel != null) { //验证当前是否临时车 if (payModel.CardType == 3) { //验证当前车牌是否在场 string carNumber = payModel.CarNo; int dbIndex = GetDatabaseNumber(carNumber); db = FollowRedisHelper.GetDatabase(dbIndex); //去redis中查询车辆是否在场,返回在场实体 VehicleEntryDetailModel entryModel = m_serializer.Deserialize <VehicleEntryDetailModel>(db.HashGet(carNumber, payModel.ParkingCode)); //不为空,则代表车辆在场 if (entryModel != null) { //fujica缴费实体传过来的“停车记录编号”和本系统中的“当次停车唯一标识”的值相等,确认是同一条记录 if (payModel.OffLineOrderId == entryModel.RecordGuid) { //查询当前车辆的计费模板,以获取缴费超时时间,计算最后出场时间 db = FollowRedisHelper.GetDatabase(0); BillingTemplateModel billingModel = m_serializer.Deserialize <BillingTemplateModel>(db.HashGet("BillingTemplateList", entryModel.CarTypeGuid)); int timeOut = TemplateDataTimeOut(billingModel, m_ilogger, m_serializer); //发送缴费数据到相机 SendPayData.Execute(entryModel.ParkingCode, entryModel.RecordGuid, entryModel.CarNo, entryModel.BeginTime, payModel.FeeEndTime.AddMinutes(timeOut)); } } } } return(RabbitMQAction.ACCEPT); }); }); }
static void Main(string[] args) { ILogger m_ilogger = new Logger(); ISerializer m_serializer = new JsonSerializer(m_ilogger); RabbitMQPeeker m_rabbitMQ = new RabbitMQPeeker(m_ilogger, m_serializer); IDatabase db; Console.WriteLine(string.Format("出场数据处理工具运行中:")); //队列名与路由名一致 m_rabbitMQ.PeekMessageByRabbitMQ("4GCameraExitDataQueue", "4GCameraExitDataQueue", (string content) => { Console.WriteLine(string.Format("收到出场数据:{0}", content)); Console.WriteLine(""); 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.BroadcastService.JobsDetails.MonitorEnterData", "在redis移除停车数据异常", ex.ToString()); return(RabbitMQAction.RETRY); } } return(RabbitMQAction.ACCEPT); //无效数据的时候直接返回成功 }); Console.WriteLine("程序逻辑不幸退出"); Console.ReadKey(); }
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; }); }); }