/// <summary> /// 通过车道设备MAC地址获取车道实体 /// </summary> /// <param name="macaddress"></param> /// <returns></returns> public DrivewayModel GetDrivewayByMacAddress(string macaddress) { DrivewayModel model = null; _redisoperate.model = new DrivewayModel() { DeviceMacAddress = macaddress }; model = _extenredisoperate.GetModelByKey(); //从数据库读 if (model == null) { string Guid = _extendatabaseoperate.GetGuidByKey(macaddress); if (!string.IsNullOrWhiteSpace(Guid)) { model = GetDriveway(Guid); } if (model != null) { _redisoperate.model = model; _extenredisoperate.KeyLinkGuid(); } } return(model); }
/// <summary> /// 遥控手动开闸发送数据 /// 添加到异常记录报表 /// </summary> /// <param name="model"></param> /// <returns></returns> private static bool AddOpenGateRecord(GateCatchModel catchModel, DrivewayModel drivewaymodel, ILogger m_ilogger) { bool result = false; try { Dictionary <string, object> dicParam = new Dictionary <string, object>(); RequestFujicaStandard requestFujica = new RequestFujicaStandard(); string servername = "Park/UnderLineAddOpenGateRecord"; dicParam["ParkingCode"] = drivewaymodel.ParkCode; dicParam["EntranceType"] = (Int32)drivewaymodel.Type; dicParam["EquipmentCode"] = drivewaymodel.DeviceMacAddress; dicParam["ThroughName"] = drivewaymodel.DrivewayName; dicParam["DiscernCamera"] = drivewaymodel.DeviceName; dicParam["ThroughType"] = 2; dicParam["OpenGateTime"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); dicParam["OpenGateReason"] = "遥控开闸"; dicParam["OpenGateOperator"] = ""; dicParam["Remarks"] = ""; dicParam["ImageUrl"] = catchModel.ImgUrl; result = requestFujica.RequestInterfaceV2(servername, dicParam); return(result); } catch (Exception ex) { m_ilogger.LogFatal(LoggerLogicEnum.Tools, "", drivewaymodel.ParkCode, catchModel.CarNo, "Fujica.com.cn.MonitorServiceClient.Business.GateCatchDataManager.AddOpenGateRecord", "添加到异常记录报表时发生异常", ex.ToString()); return(false); } }
/// <summary> /// 修改车道 /// </summary> /// <param name="model"></param> /// <param name="oldDeviceMacAddress">修改前的相机mac地址,用于判断相机是否替换</param> /// <returns></returns> public bool ModifyDriveway(DrivewayModel model) { //读取旧的车道信息 DrivewayModel oldModel = GetDriveway(model.Guid); string oldMacAddress = oldModel == null ? "" : oldModel.DeviceMacAddress; _redisoperate.model = model; bool flag = _databaseoperate.SaveToDataBase(model); if (flag) { //此时不需要判断redis是否成功,因为修改时redis一定会返回false _redisoperate.SaveToRedis(); //当前的设备MAC与redis中保存的mac地址不一致,删除掉旧的mac地址 if (oldMacAddress != model.DeviceMacAddress) { //更新mac地址 _extenredisoperate.KeyLinkGuid(); if (!string.IsNullOrEmpty(oldMacAddress)) { //删除旧的mac地址 model.DeviceMacAddress = oldMacAddress; _extenredisoperate.KeyUnLinkGuid(); } } } return(flag); }
public IHttpActionResult SetVoiceCommand(VoiceCommandRequest model) { ResponseBaseCommon response = new ResponseBaseCommon() { IsSuccess = true, MessageCode = (int)ApiBaseErrorCode.API_SUCCESS, MessageContent = ApiBaseErrorCode.API_SUCCESS.ToString() }; if (string.IsNullOrWhiteSpace(model.DrivewayGuid) || string.IsNullOrWhiteSpace(model.ParkingCode) || model.CommandList.Count < 15 || string.IsNullOrWhiteSpace(model.ProjectGuid)) { response.IsSuccess = false; response.MessageCode = (int)ApiBaseErrorCode.API_PARAM_ERROR; response.MessageContent = "必要参数不全,请检查"; return(Ok(response)); } //前端内容带有html字符,传输前进行了url编码 foreach (var item in model.CommandList) { item.ShowText = System.Web.HttpUtility.UrlDecode(item.ShowText); item.ShowVoice = System.Web.HttpUtility.UrlDecode(item.ShowVoice); } DrivewayModel drivewayModel = _parkLotManager.GetDriveway(model.DrivewayGuid); if (drivewayModel == null) { response.IsSuccess = false; response.MessageCode = (int)ApiBaseErrorCode.API_PARAM_ERROR; response.MessageContent = "车道不存在"; return(Ok(response)); } VoiceCommandModel content = new VoiceCommandModel() { ProjectGuid = model.ProjectGuid, ParkCode = model.ParkingCode, DrivewayGuid = model.DrivewayGuid, DeviceMacAddress = drivewayModel.DeviceMacAddress, CommandList = model.CommandList }; if (!_voiceCommandManager.SaveCommand(content)) { response.IsSuccess = false; response.MessageCode = (int)ApiSystemErrorCode.API_DATA_SAVE_ERROR; response.MessageContent = ApiBaseErrorCode.API_INTERFACENAME_ERROR.ToString(); } return(Ok(response)); }
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); }
/// <summary> /// 被扫(用户出示微信/支付宝缴费二维码) /// </summary> public PassiveScanningResponseModel PassiveScanning(PassiveScanningModel model) { PassiveScanningResponseModel responseModel = null; if (model == null || string.IsNullOrEmpty(model.DeviceMACAddress) || string.IsNullOrEmpty(model.Guid) || string.IsNullOrEmpty(model.CarNo) || model.LaneSenseDate == null) { LastErrorDescribe = BussinessErrorCodeEnum.BUSINESS_PARAM_ERROR.GetDesc(); return(responseModel); } responseModel = new PassiveScanningResponseModel() { CarNo = model.CarNo, }; //找到对应车道 DrivewayModel drivewayModel = _parkLotManager.GetDrivewayByMacAddress(model.DeviceMACAddress); if (drivewayModel == null) { LastErrorDescribe = BussinessErrorCodeEnum.BUSINESS_NOTEXISTS_DRIVEWAY.GetDesc(); return(responseModel); } //读取车辆的在场记录并验证停车标识是否一致 VehicleInOutModel entermodel = _parkLotManager.GetEntryRecord(model.CarNo, drivewayModel.ParkCode); if (entermodel == null || entermodel.Guid != model.Guid) { LastErrorDescribe = BussinessErrorCodeEnum.BUSINESS_NOTEXISTS_CAR.GetDesc(); return(responseModel); } //请求Fujica Pay Api 发送支付授权码,申请扣费 bool result = SendAuthCodeToFujica(drivewayModel.ParkCode, entermodel.CarNo, model.ParkingFee, model.PayAuthCode); if (result) { responseModel.PayState = true; } else { responseModel.PayState = false; } responseModel.Remark = ""; responseModel.Extend = ""; return(responseModel); }
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); } } } } } } } }); }
/// <summary> /// 主扫(用户扫描固定车道码缴费) /// </summary> public ActiveScanningResponseModel ActiveScanning(ActiveScanningModel model) { ActiveScanningResponseModel responseModel = null; if (model == null || string.IsNullOrEmpty(model.DeviceMACAddress) || string.IsNullOrEmpty(model.Guid) || string.IsNullOrEmpty(model.CarNo) || model.LaneSenseDate == null) { LastErrorDescribe = BussinessErrorCodeEnum.BUSINESS_PARAM_ERROR.GetDesc(); return(responseModel); } //找到对应车道 DrivewayModel drivewayModel = _parkLotManager.GetDrivewayByMacAddress(model.DeviceMACAddress); if (drivewayModel == null) { LastErrorDescribe = BussinessErrorCodeEnum.BUSINESS_NOTEXISTS_DRIVEWAY.GetDesc(); return(responseModel); } //读取车辆的在场记录并验证停车标识是否一致 VehicleInOutModel entermodel = _parkLotManager.GetEntryRecord(model.CarNo, drivewayModel.ParkCode); if (entermodel == null || entermodel.Guid != model.Guid) { LastErrorDescribe = BussinessErrorCodeEnum.BUSINESS_NOTEXISTS_CAR.GetDesc(); return(responseModel); } //请求Fujica Api 获取车道应缴费用和入场时间信息 decimal actualAmount = 0; DateTime beginTime = DateTime.MinValue; bool fujicaResult = GetLaneCostInfoByFujica(drivewayModel.ParkCode, entermodel.CarNo, drivewayModel.DeviceMacAddress, model.LaneSenseDate, out actualAmount, out beginTime); if (fujicaResult) { responseModel = new ActiveScanningResponseModel(); responseModel.CarNo = model.CarNo; responseModel.ParkingFee = actualAmount; responseModel.BeginTime = beginTime.ToString("yyyy-MM-dd HH:mm:ss"); //93+车编+车道号 responseModel.QRCode = "http://mops-test.fujica.com.cn/v2/Login/Index?key=FUJICA93" + drivewayModel.ParkCode + drivewayModel.DeviceMacAddress; //responseModel.QRCode = "http://mops.fujica.com.cn/v2/Login/Index?key=FUJICA93" + drivewayModel.ParkCode + drivewayModel.DeviceMacAddress;//项目更新发布,这里一定要改回来 responseModel.Remark = ""; responseModel.Extend = ""; } return(responseModel); }
/// <summary> /// 添加车道 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool AddDriveway(DrivewayModel model) { _redisoperate.model = model; bool flag = _databaseoperate.SaveToDataBase(model); if (flag) { flag = _redisoperate.SaveToRedis(); if (flag) { flag = _extenredisoperate.KeyLinkGuid(); //关联设备MAC与车道GUID } } return(flag); }
/// <summary> /// 删除车道 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool DeleteDriveway(DrivewayModel model) { _redisoperate.model = model; bool flag = _databaseoperate.DeleteInDataBase(model); if (flag) { flag = _extenredisoperate.KeyUnLinkGuid(); //解除关联设备MAC与车道GUID if (flag) { flag = _redisoperate.DeleteInRedis(); } } return(flag); }
/// <summary> /// 发送车道类型到设备 /// </summary> /// <param name="model">车道实体</param> /// <param name="count">入口数量</param> /// <param name="commandType">业务类型</param> /// <returns></returns> public bool SendDriveWayType(DrivewayModel model, int entrywayCount, BussineCommand commandType) { try { if (model != null) { CameraTypeModel sendmodel = new CameraTypeModel() { Type = (int)model.Type, DeviceIdentify = model.DeviceMacAddress, ParkingCode = model.ParkCode, EntrywayCount = entrywayCount, DeviceEntranceURI = model.DeviceEntranceURI, DeviceAccount = model.DeviceAccount }; CommandEntity <CameraTypeModel> entity = new CommandEntity <CameraTypeModel>() { command = commandType, idMsg = Convert.ToBase64String(Guid.NewGuid().ToByteArray()), message = sendmodel }; string remark = string.Empty; switch (commandType) { case BussineCommand.CameraInfo: remark = "发送相机初始化类型指令命令"; break; case BussineCommand.CameraDelete: remark = "发送相机删除类型指令命令"; break; default: remark = "发送相机初始化类型指令命令"; break; } return(m_rabbitMQ.SendMessageForRabbitMQ(remark, m_serializer.Serialize(entity), entity.idMsg, model.ParkCode, "CameraParkInit", "FuJiCaYunCameraParkInit.fanout")); } } catch (Exception ex) { m_logger.LogFatal(LoggerLogicEnum.Bussiness, "", model.ParkCode, "", "Fujica.com.cn.Business.ParkLot.DrivewayManager.SendDriveWayType", "下发车道相机类型发生异常", ex.ToString()); } return(false); }
/// <summary> /// 车牌修正 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool CorrectToEntryCamera(CorrectCarnoModel model) { bool flag = SendCorrectToEntryCamera(model); if (flag) { DrivewayModel drivewayModel = _iDrivewayContext.GetDrivewayByMacAddress(model.DeviceIdentify); if (drivewayModel != null) { model.ThroughName = drivewayModel.DrivewayName; model.Discerncamera = drivewayModel.DeviceName; } ////保存至数据库,形成报表记录 flag = _iParkLotContext.AddCarnoRecorddatabaseoperate(model); } return(flag); }
/// <summary> /// 删除车道 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool DeleteDriveway(DrivewayModel model) { bool flag = _iDrivewayContext.DeleteDriveway(model); if (!flag) { //数据库不成功就不要往下执行了 LastErrorDescribe = BussinessErrorCodeEnum.BUSINESS_DELETE_DRIVEWAY.GetDesc(); return(false); } //修改车场信息中车道列表 ParkLotModel content = _iParkLotContext.GetParkLot(model.ParkCode); if (content != null) { if (content.DrivewayList != null) { if (content.DrivewayList.Remove(model.Guid)) { flag = _iParkLotContext.ModifyParkLot(content); if (!flag) { return(false); } } } } //获得入口相机数量 int entrywayCount = GetCameraCount(model.ParkCode, DrivewayType.In); //删除相机 bool mqReturn = SendDriveWayType(model, entrywayCount, BussineCommand.CameraDelete); if (!mqReturn) { LastErrorDescribe = BussinessErrorCodeEnum.BUSINESS_MQ_SEND_ERROR.GetDesc(); return(false); } else { return(true); } }
/// <summary> /// 修改车道 /// </summary> /// <param name="model"></param> /// <param name="oldDeviceMacAddress">修改前的相机mac地址,用于判断相机是否替换</param> /// <returns></returns> public bool ModifyDriveway(DrivewayModel model) { //验证当前输入的设备mac地址是否已存在 DrivewayModel content = _iDrivewayContext.GetDrivewayByMacAddress(model.DeviceMacAddress); if (content != null) { //guid是否一致 if (content.Guid != model.Guid) { LastErrorDescribe = BussinessErrorCodeEnum.BUSINESS_EXISTS_MACADDRESS_DRIVEWAY.GetDesc(); return(false); } } //修改车道 bool flag = _iDrivewayContext.ModifyDriveway(model); if (!flag) { //数据库不成功就不要往下执行了 LastErrorDescribe = BussinessErrorCodeEnum.BUSINESS_SAVE_DRIVEWAY.GetDesc(); return(false); } //获取停车场入口相机数量 int entrywayCount = GetCameraCount(model.ParkCode, DrivewayType.In); //发送车道信息给相机 bool mqReturn = SendDriveWayType(model, entrywayCount, BussineCommand.CameraEdit); if (!mqReturn) { LastErrorDescribe = BussinessErrorCodeEnum.BUSINESS_MQ_SEND_ERROR.GetDesc(); return(false); } else { return(true); } }
/// <summary> /// 车牌修改重推 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool CarNumberRepushToCamera(CorrectCarnoModel model) { CarNumberRepushModel correctModel = new CarNumberRepushModel(); correctModel.DeviceIdentify = model.DeviceIdentify; correctModel.ParkingCode = model.ParkingCode; correctModel.OldCarno = model.OldCarno; correctModel.NewCarno = model.NewCarno; bool flag = SendCarNumberRepushToCameras(correctModel); if (flag) { DrivewayModel drivewayModel = _iDrivewayContext.GetDrivewayByMacAddress(model.DeviceIdentify); if (drivewayModel != null) { model.Discerncamera = drivewayModel.DeviceName; model.ThroughName = drivewayModel.DrivewayName; } ////保存至数据库,形成报表记录 flag = _iParkLotContext.AddCarnoRecorddatabaseoperate(model); } return(flag); }
/// <summary> /// 获取某车道 /// </summary> /// <param name="guid"></param> /// <returns></returns> public DrivewayModel GetDriveway(string guid) { DrivewayModel model = null; _redisoperate.model = new DrivewayModel() { Guid = guid }; model = _redisoperate.GetFromRedis(); //从数据库读 if (model == null) { model = _databaseoperate.GetFromDataBase(guid); //缓存到redis if (model != null) { _redisoperate.model = model; _redisoperate.SaveToRedis(); } } return(model); }
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 bool AddDriveway(DrivewayModel model) { ParkLotModel contentParkLot = GetParkLot(model.ParkCode); //验证当前设备mac地址是否已存在 DrivewayModel content = _iDrivewayContext.GetDrivewayByMacAddress(model.DeviceMacAddress); if (content != null) { LastErrorDescribe = BussinessErrorCodeEnum.BUSINESS_EXISTS_MACADDRESS_DRIVEWAY.GetDesc(); return(false); } //添加车道 bool flag = _iDrivewayContext.AddDriveway(model); if (!flag) { LastErrorDescribe = BussinessErrorCodeEnum.BUSINESS_SAVE_DRIVEWAY.GetDesc(); return(false); } //修改车场信息中车道列表 if (contentParkLot.DrivewayList == null) { contentParkLot.DrivewayList = new List <string>(); } contentParkLot.DrivewayList.Add(model.Guid); flag = _iParkLotContext.ModifyParkLot(contentParkLot); if (!flag) { return(false); } //初始化语音指令 VoiceCommandModel voiceCommandModel = new VoiceCommandModel() { ProjectGuid = model.ProjectGuid, ParkCode = model.ParkCode, DrivewayGuid = model.Guid, DeviceMacAddress = model.DeviceMacAddress, CommandList = null }; //语音指令返回值不影响车道保存结果 _voiceCommandManager.InitVoiceCommand(voiceCommandModel); int entrywayCount = GetCameraCount(model.ParkCode, DrivewayType.In); //初始化相机 bool mqReturn = SendDriveWayType(model, entrywayCount, BussineCommand.CameraInfo); if (!mqReturn) { LastErrorDescribe = BussinessErrorCodeEnum.BUSINESS_MQ_SEND_ERROR.GetDesc(); return(false); } else { return(true); } }
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 ResponseCommon DataHandle(ILogger m_ilogger, ISerializer m_serializer) { ResponseCommon response = new ResponseCommon() { IsSuccess = false, MsgType = MsgType.GateCatch }; IDatabase db; db = RedisHelper.GetDatabase(4); string redisContent = db.ListLeftPop(mq_ListKey); if (string.IsNullOrEmpty(redisContent)) { response.MessageContent = "redis数据库读取值为空"; return(response); } response.RedisContent = redisContent; GateCatchModel catchModel = m_serializer.Deserialize <GateCatchModel>(redisContent); if (catchModel == null) { response.MessageContent = "redis数据库读取值转换成实体失败:"; return(response); } if (string.IsNullOrEmpty(catchModel.DeviceIdentify) || string.IsNullOrEmpty(catchModel.ImgUrl) //|| string.IsNullOrEmpty(catchModel.CarNo) //|| string.IsNullOrEmpty(catchModel.CarTypeGuid) ) { response.MessageContent = "redis数据转换成实体后必要参数缺失"; return(response); } db = RedisHelper.GetDatabase(0); string drivewayguid = db.HashGet("DrivewayLinkMACList", catchModel.DeviceIdentify); DrivewayModel drivewaymodel = m_serializer.Deserialize <DrivewayModel>(db.HashGet("DrivewayList", drivewayguid ?? "")); if (drivewaymodel == null) { response.MessageContent = "根据车道相机设备MAC地址,读取车道模型为空"; m_ilogger.LogError(LoggerLogicEnum.Tools, "", "", catchModel.CarNo, "Fujica.com.cn.MonitorServiceClient.GateCatchDataManager", "根据车道相机设备MAC地址,读取车道模型为空"); return(response); } ParkLotModel parklotmodel = m_serializer.Deserialize <ParkLotModel>(db.HashGet("ParkLotList", drivewaymodel.ParkCode)); if (parklotmodel == null) { response.MessageContent = "根据停车场编码,读取车场模型为空"; m_ilogger.LogError(LoggerLogicEnum.Tools, "", "", catchModel.CarNo, "Fujica.com.cn.MonitorServiceClient.GateCatchDataManager", "根据停车场编码,读取车场模型为空"); return(response); } //500错误为“非法开闸” if (catchModel.ErrorCode == 500) { //将非法开闸数据发送给Fujica Api存入“异常开闸记录”报表 if (!AddOpenGateRecord(catchModel, drivewaymodel, m_ilogger)) { response.MessageContent = "遥控手动非法开闸记录发送Fujica Api失败"; m_ilogger.LogError(LoggerLogicEnum.Tools, "", parklotmodel.ParkCode, catchModel.CarNo, "Fujica.com.cn.MonitorServiceClient.GateCatchDataManager", "遥控手动非法开闸记录发送Fujica Api失败"); return(response); } else { response.IsSuccess = true; response.MessageContent = "遥控手动非法开闸记录成功"; return(response); } } CarTypeModel cartypemodel = null; VehicleEntryDetailModel entrymodel = new VehicleEntryDetailModel(); //入场记录 //无压地感车辆、无牌车数据 if (catchModel.ErrorCode == 407 || catchModel.ErrorCode == 404) { cartypemodel = new CarTypeModel(); } /// 13-无入场记录 /// 14-临时车未缴费 /// 400-黑名单 /// 401-通行限制 /// 402-月卡被锁 /// 403-月卡过期 /// 404-禁止无牌车 /// 405-手动开闸 /// 406-满车位 /// 407-无压地感车辆 /// 408是储值卡余额不足 else { cartypemodel = m_serializer.Deserialize <CarTypeModel>(db.HashGet("CarTypeList", catchModel.CarTypeGuid)); if (cartypemodel == null) { response.MessageContent = "根据车类Guid,读取车类模型为空"; m_ilogger.LogError(LoggerLogicEnum.Tools, "", "", catchModel.CarNo, "Fujica.com.cn.MonitorServiceClient.EntryDataManager", "根据车类Guid,读取车类模型为空"); return(response); } if (catchModel.ErrorCode == 14 || catchModel.ErrorCode == 402 || catchModel.ErrorCode == 403 || catchModel.ErrorCode == 408 || catchModel.ErrorCode == 405) { db = RedisHelper.GetDatabase(Common.GetDatabaseNumber(catchModel.CarNo)); //入场实体内容 entrymodel = m_serializer.Deserialize <VehicleEntryDetailModel>(db.HashGet(catchModel.CarNo, drivewaymodel.ParkCode)); } } GateCatchDetailModel detailModel = new GateCatchDetailModel() { CarNo = catchModel.CarNo, ParkingCode = drivewaymodel.ParkCode, DrivewayName = drivewaymodel.DrivewayName, DriveWayMAC = catchModel.DeviceIdentify, CarType = cartypemodel.CarType, CarTypeGuid = cartypemodel.Guid, CarTypeName = cartypemodel.CarTypeName, ImgUrl = catchModel.ImgUrl }; //存到redis try { db = RedisHelper.GetDatabase(0); db.HashSet("GateCatchList", detailModel.DriveWayMAC, m_serializer.Serialize(detailModel)); //存储车道拦截数据 bool flag = db.HashExists("GateCatchList", detailModel.DriveWayMAC); #region 移动岗亭数据推送 CaptureInOutModel capturModel = new CaptureInOutModel(); capturModel.Guid = drivewaymodel.Guid; capturModel.ParkCode = detailModel.ParkingCode; capturModel.Exit = detailModel.DrivewayName; capturModel.DriveWayMAC = detailModel.DriveWayMAC; capturModel.CarNo = detailModel.CarNo; if (drivewaymodel.Type == DrivewayType.In) //入场 异常数据 { capturModel.InImgUrl = detailModel.ImgUrl; capturModel.InTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); capturModel.EntryType = "0"; } else { capturModel.OutImgUrl = detailModel.ImgUrl; capturModel.OutTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); capturModel.EntryType = "1"; if (catchModel.ErrorCode > 13 && (entrymodel.CarNo != null || entrymodel.CarNo != ""))//有入场记录 { capturModel.InImgUrl = entrymodel.InImgUrl; capturModel.Entrance = entrymodel.Entrance; capturModel.InTime = Convert.ToDateTime(entrymodel.BeginTime); } } capturModel.CarType = Convert.ToInt32(detailModel.CarType); capturModel.CarTypeName = detailModel.CarTypeName; capturModel.CarTypeGuid = detailModel.CarTypeGuid; capturModel.Remark = "异常数据"; capturModel.ErrorCode = catchModel.ErrorCode.ToString(); //推送到客户端(实现移动岗亭功能) SendDataToClient(capturModel); //存储一份在redis中 GateDataToRedis(capturModel, m_serializer); #endregion if (!flag) { response.MessageContent = "车道拦截数据添加redis失败"; return(response); } else { response.IsSuccess = true; response.MessageContent = "车道拦截数据添加redis成功"; return(response); } } catch (Exception ex) { m_ilogger.LogFatal(LoggerLogicEnum.Tools, "", detailModel.ParkingCode, detailModel.CarNo, "Fujica.com.cn.MonitorServiceClient.Business.GateCatchDataManager.DataHandle", "保存车道拦截数据到redis异常", ex.ToString()); response.MessageContent = "车道拦截数据数据发生异常:" + ex.ToString(); return(response); } }
public static ResponseCommon DataHandle(ILogger m_ilogger, ISerializer m_serializer) { ResponseCommon response = new ResponseCommon() { IsSuccess = false, MsgType = MsgType.OutParking }; IDatabase db; db = RedisHelper.GetDatabase(4); string redisContent = db.ListLeftPop(mq_ListKey); if (string.IsNullOrEmpty(redisContent)) { response.MessageContent = "redis数据库读取值为空"; return(response); } response.RedisContent = redisContent; m_ilogger.LogInfo(LoggerLogicEnum.Tools, "", "", "", "Fujica.com.cn.MonitorServiceClient.ExitDataManager", "车辆出场数据接收成功.原始数据:" + redisContent); VehicleOutModel outmodel = m_serializer.Deserialize <VehicleOutModel>(redisContent); if (outmodel == null) { response.MessageContent = "redis数据库读取值转换成实体失败"; return(response); } if (string.IsNullOrEmpty(outmodel.Guid) || string.IsNullOrEmpty(outmodel.DriveWayMAC) || string.IsNullOrEmpty(outmodel.CarNo) //|| string.IsNullOrEmpty(outmodel.ImgUrl) || outmodel.OutTime == DateTime.MinValue || string.IsNullOrEmpty(outmodel.CarTypeGuid)) { response.MessageContent = "redis数据转换成实体后必要参数缺失"; return(response); } //不为空说明是出场数据 db = RedisHelper.GetDatabase(0); string drivewayguid = db.HashGet("DrivewayLinkMACList", outmodel.DriveWayMAC); DrivewayModel drivewaymodel = m_serializer.Deserialize <DrivewayModel>(db.HashGet("DrivewayList", drivewayguid ?? "")); if (drivewaymodel == null) { response.MessageContent = "根据车道相机设备MAC地址,读取车道模型为空"; m_ilogger.LogError(LoggerLogicEnum.Tools, outmodel.Guid, "", outmodel.CarNo, "Fujica.com.cn.MonitorServiceClient.ExitDataManager", "根据车道相机设备MAC地址,读取车道模型为空"); return(response); } CarTypeModel cartypemodel = m_serializer.Deserialize <CarTypeModel>(db.HashGet("CarTypeList", outmodel.CarTypeGuid)); if (cartypemodel == null) { response.MessageContent = "根据车类Guid,读取车类模型为空"; m_ilogger.LogError(LoggerLogicEnum.Tools, outmodel.Guid, drivewaymodel.ParkCode, outmodel.CarNo, "Fujica.com.cn.MonitorServiceClient.ExitDataManager", "根据车类Guid,读取车类模型为空"); return(response); } ParkLotModel parklotmodel = m_serializer.Deserialize <ParkLotModel>(db.HashGet("ParkLotList", drivewaymodel.ParkCode)); if (parklotmodel == null) { response.MessageContent = "根据停车场编码,读取车场模型为空"; m_ilogger.LogError(LoggerLogicEnum.Tools, outmodel.Guid, drivewaymodel.ParkCode, outmodel.CarNo, "Fujica.com.cn.MonitorServiceClient.ExitDataManager", "根据停车场编码,读取车场模型为空"); return(response); } 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, ExitCamera = drivewaymodel.DeviceName, DriveWayMAC = outmodel.DriveWayMAC, OpenType = outmodel.OpenType, Operator = outmodel.Operator }; //redis操作 try { db = RedisHelper.GetDatabase(Common.GetDatabaseNumber(exitmodel.CarNo)); //删除前先拿到实体内容 VehicleEntryDetailModel entrymodel = m_serializer.Deserialize <VehicleEntryDetailModel>(db.HashGet(exitmodel.CarNo, exitmodel.ParkingCode)); if (entrymodel == null) { response.MessageContent = "未找到入场记录"; return(response); } bool flag = db.HashDelete(exitmodel.CarNo, exitmodel.ParkingCode); //1号db移除该在场车牌 if (flag) { db = RedisHelper.GetDatabase(1); string hashKey = entrymodel.ParkingCode + ":" + DateTime.Now.ToString("yyyyMM"); flag = db.SortedSetRemove(hashKey, entrymodel.CarNo); //如果当月集合中不存在,则找最近的二个月的数据 if (!flag) { for (int i = 1; i < 3; i++) { hashKey = entrymodel.ParkingCode + ":" + DateTime.Now.AddMonths(-i).ToString("yyyyMM"); flag = db.SortedSetRemove(hashKey, entrymodel.CarNo); if (flag) { break; } } } } //2号db移除存储入场数据(相机上传原样数据),出场再删掉(用于相机数据同步) if (flag) { db = RedisHelper.GetDatabase(2); string hashKey = entrymodel.ParkingCode + ":" + DateTime.Now.ToString("yyyyMM"); flag = db.HashDelete(hashKey, entrymodel.CarNo); //如果当月集合中不存在,则找最近的二个月的数据 if (!flag) { for (int i = 1; i < 3; i++) { hashKey = entrymodel.ParkingCode + ":" + DateTime.Now.AddMonths(-i).ToString("yyyyMM"); flag = db.HashDelete(hashKey, entrymodel.CarNo); if (flag) { break; } } } } if (flag) { m_ilogger.LogInfo(LoggerLogicEnum.Tools, exitmodel.RecordGuid, exitmodel.ParkingCode, exitmodel.CarNo, "Fujica.com.cn.MonitorServiceClient.ExitDataManager", entrymodel.CarNo + "车辆出场数据删除redis数据成功"); //剩余车位数控制 db = RedisHelper.GetDatabase(0); db.ListRightPush("SpaceNumberList:" + entrymodel.ParkingCode, 1); //调用mq给相机发送当前车位数 int remainingNumber = Convert.ToInt32(db.ListLength("SpaceNumberList:" + entrymodel.ParkingCode)); SpaceNumberToCamera(remainingNumber, entrymodel.ParkingCode, m_ilogger, m_serializer); //修改redis中停车场的剩余车位数 parklotmodel.RemainingSpace = (uint)remainingNumber; db = RedisHelper.GetDatabase(0); db.HashSet("ParkLotList", parklotmodel.ParkCode, m_serializer.Serialize(parklotmodel)); //修改mysql中停车场的剩余车位数 SaveSpaceNumberToDB(parklotmodel, m_ilogger, m_serializer); #region 移动岗亭数据推送 CaptureInOutModel capturModel = new CaptureInOutModel() { Guid = exitmodel.RecordGuid, ParkCode = exitmodel.ParkingCode, Entrance = entrymodel.Entrance, Exit = exitmodel.Exit, DriveWayMAC = exitmodel.DriveWayMAC, RemainingNumber = remainingNumber.ToString(), CarNo = exitmodel.CarNo, EntryType = "1", CarType = Convert.ToInt32(entrymodel.CarType.ToString()), CarTypeName = entrymodel.CarTypeName, CarTypeGuid = entrymodel.CarTypeGuid, InTime = Convert.ToDateTime(entrymodel.BeginTime), OutTime = exitmodel.LeaveTime, OutImgUrl = exitmodel.OutImgUrl, InImgUrl = entrymodel.InImgUrl, Remark = exitmodel.Description, ErrorCode = "-1" //错误类型(异常时使用,正常数据默认是-1) }; //推送到客户端(实现移动岗亭功能) SendOutDataToClient(capturModel); //存储一份在redis中 GateDataToRedis(capturModel, m_serializer); #endregion //往主平台Fujica补发出场数据 bool fujicaResult = ExitDataToFujica(exitmodel, entrymodel, cartypemodel.Idx); if (fujicaResult) { //出场分发服务 DistributeExitData(exitmodel, entrymodel, cartypemodel.Idx, m_ilogger); response.IsSuccess = true; response.MessageContent = entrymodel.CarNo + "车辆出场数据删除redis和补发fujica出场数据成功"; m_ilogger.LogInfo(LoggerLogicEnum.Tools, exitmodel.RecordGuid, exitmodel.ParkingCode, exitmodel.CarNo, "Fujica.com.cn.MonitorServiceClient.ExitDataManager", entrymodel.CarNo + "车辆出场数据删除redis和补发fujica出场数据成功"); return(response); } else { response.IsSuccess = true; response.MessageContent = entrymodel.CarNo + "车辆出场数据删除redis成功;补发fujica出场数据失败"; m_ilogger.LogError(LoggerLogicEnum.Tools, exitmodel.RecordGuid, exitmodel.ParkingCode, exitmodel.CarNo, "Fujica.com.cn.MonitorServiceClient.ExitDataManager", entrymodel.CarNo + "车辆出场数据删除redis成功;补发fujica出场数据失败"); return(response); } } else { response.MessageContent = entrymodel.CarNo + "车辆出场数据删除redis数据失败"; m_ilogger.LogError(LoggerLogicEnum.Tools, exitmodel.RecordGuid, exitmodel.ParkingCode, exitmodel.CarNo, "Fujica.com.cn.MonitorServiceClient.ExitDataManager", entrymodel.CarNo + "车辆出场数据删除redis数据失败"); return(response); } } catch (Exception ex) { m_ilogger.LogFatal(LoggerLogicEnum.Tools, exitmodel.RecordGuid, exitmodel.ParkingCode, exitmodel.CarNo, "Fujica.com.cn.MonitorServiceClient.Business.ExitDataManager.DataHandle", "在redis移除停车数据异常", ex.ToString()); response.MessageContent = "车辆出场数据发生异常:" + ex.ToString(); return(response); } }
public static ResponseCommon DataHandle(ILogger m_ilogger, ISerializer m_serializer) { ResponseCommon response = new ResponseCommon() { IsSuccess = false, MsgType = MsgType.GroundSense }; IDatabase db; db = RedisHelper.GetDatabase(4); string redisContent = db.ListLeftPop(mq_ListKey); if (string.IsNullOrEmpty(redisContent)) { response.MessageContent = "redis数据库读取值为空"; return(response); } response.RedisContent = redisContent; //转换成 出口未缴费临时车辆 实体 ExitTempCarPayModel exitTempCarModel = m_serializer.Deserialize <ExitTempCarPayModel>(redisContent); if (exitTempCarModel == null) { response.MessageContent = "redis数据库读取值转换成实体失败"; return(response); } if (string.IsNullOrEmpty(exitTempCarModel.Guid) || string.IsNullOrEmpty(exitTempCarModel.DriveWayMAC) || string.IsNullOrEmpty(exitTempCarModel.CarNo) || exitTempCarModel.LaneSenseDate == DateTime.MinValue) { response.MessageContent = "redis数据转换成实体后必要参数缺失"; return(response); } db = RedisHelper.GetDatabase(0); //根据相机MAC地址拿到车道的guid string drivewayguid = db.HashGet("DrivewayLinkMACList", exitTempCarModel.DriveWayMAC); //得到相对应的车道实体 DrivewayModel drivewaymodel = m_serializer.Deserialize <DrivewayModel>(db.HashGet("DrivewayList", drivewayguid ?? "")); if (drivewaymodel == null) { response.MessageContent = "根据车道相机设备MAC地址,读取车道模型为空"; return(response); } //验证当前车牌是否在场 string carNumber = exitTempCarModel.CarNo; int dbIndex = Common.GetDatabaseNumber(carNumber); db = RedisHelper.GetDatabase(dbIndex); //去redis中查询车辆是否在场,返回在场实体 VehicleEntryDetailModel entryModel = m_serializer.Deserialize <VehicleEntryDetailModel>(db.HashGet(carNumber, drivewaymodel.ParkCode)); //为空,则代表车辆不在场 if (entryModel == null) { response.MessageContent = "未找到当前车辆在场记录"; return(response); } //相机 临时车实体传过来的“当次停车唯一标识”和redis在场数据中的“当次停车唯一标识”值相等,确认是同一条记录 if (exitTempCarModel.Guid != entryModel.RecordGuid) { response.MessageContent = "当次停车唯一标识与redis数据不一致"; return(response); } //拿到车类信息 CarTypeModel cartypemodel = m_serializer.Deserialize <CarTypeModel>(db.HashGet("CarTypeList", entryModel.CarTypeGuid)); if (cartypemodel == null) { response.MessageContent = "根据车类Guid,读取车类模型为空"; return(response); } try { //去fujica拿到当前停车的费用 string fujicaTempCarModel = GetFujicaTempCarByCarNo(entryModel.CarNo, entryModel.ParkingCode, m_serializer); if (string.IsNullOrEmpty(fujicaTempCarModel)) { response.MessageContent = "fujicaApi/GetTempCarPaymentInfoByCarNo未查询到停车信息"; return(response); } Dictionary <string, object> fujicaTempCarDic = m_serializer.Deserialize <Dictionary <string, object> >(fujicaTempCarModel); if (fujicaTempCarDic == null || fujicaTempCarDic["ParkingFee"] == null || fujicaTempCarDic["ActualAmount"] == null) { response.MessageContent = "fujicaApi/GetTempCarPaymentInfoByCarNo返回结果解析失败" + fujicaTempCarModel; return(response); } //fujica返回停车费用 decimal amount = Convert.ToDecimal(fujicaTempCarDic["ParkingFee"]); //fujica返回应缴费用 decimal actualAmount = Convert.ToDecimal(fujicaTempCarDic["ActualAmount"]); //再将数据组装后,上传到fujica的车道码压地感车辆上传接口 bool uploadResult = UploadExitPayDataToFujica(entryModel.CarNo, entryModel.ParkingCode, amount, actualAmount, exitTempCarModel.LaneSenseDate, entryModel.RecordGuid, cartypemodel.Idx, entryModel.InImgUrl, entryModel.BeginTime, exitTempCarModel.DriveWayMAC, drivewaymodel.DrivewayName); if (uploadResult) { response.IsSuccess = true; response.MessageContent = "车辆压地感数据上传Fujica成功"; return(response); } else { response.MessageContent = "车辆压地感数据上传Fujica失败"; return(response); } } catch (Exception ex) { m_ilogger.LogFatal(LoggerLogicEnum.Tools, entryModel.RecordGuid, entryModel.ParkingCode, entryModel.CarNo, "Fujica.com.cn.MonitorServiceClient.Business.ExitPayDataManager.DataHandle", "未缴费临时车压地感上传fujica出现异常", ex.ToString()); response.MessageContent = "车辆压地感数据发生异常:" + ex.ToString(); return(response); } }
public static ResponseCommon DataHandle(ILogger m_ilogger, ISerializer m_serializer) { ResponseCommon response = new ResponseCommon() { IsSuccess = false, MsgType = MsgType.InParking }; IDatabase db; db = RedisHelper.GetDatabase(4); string redisContent = db.ListLeftPop(mq_ListKey); if (string.IsNullOrEmpty(redisContent)) { response.MessageContent = "redis数据库读取值为空"; return(response); } response.RedisContent = redisContent; m_ilogger.LogInfo(LoggerLogicEnum.Tools, "", "", "", "Fujica.com.cn.MonitorServiceClient.EntryDataManager", "车辆入场数据接收成功.原始数据:" + redisContent); VehicleInModel inmodel = m_serializer.Deserialize <VehicleInModel>(redisContent); if (inmodel == null) { response.MessageContent = "redis数据库读取值转换成实体失败:"; return(response); } if (string.IsNullOrEmpty(inmodel.Guid) || string.IsNullOrEmpty(inmodel.DriveWayMAC) || string.IsNullOrEmpty(inmodel.CarNo) //|| string.IsNullOrEmpty(inmodel.ImgUrl)//补发入场车辆,没有照片 || inmodel.InTime == DateTime.MinValue || string.IsNullOrEmpty(inmodel.CarTypeGuid) //|| string.IsNullOrEmpty(inmodel.Remark) ) { response.MessageContent = "redis数据转换成实体后必要参数缺失"; return(response); } //不为空说明是入场数据 db = RedisHelper.GetDatabase(0); string drivewayguid = db.HashGet("DrivewayLinkMACList", inmodel.DriveWayMAC); DrivewayModel drivewaymodel = m_serializer.Deserialize <DrivewayModel>(db.HashGet("DrivewayList", drivewayguid ?? "")); if (drivewaymodel == null) { response.MessageContent = "根据车道相机设备MAC地址,读取车道模型为空"; m_ilogger.LogError(LoggerLogicEnum.Tools, inmodel.Guid, "", inmodel.CarNo, "Fujica.com.cn.MonitorServiceClient.EntryDataManager", "根据车道相机设备MAC地址,读取车道模型为空"); return(response); } CarTypeModel cartypemodel = m_serializer.Deserialize <CarTypeModel>(db.HashGet("CarTypeList", inmodel.CarTypeGuid)); if (cartypemodel == null) { response.MessageContent = "根据车类Guid,读取车类模型为空"; m_ilogger.LogError(LoggerLogicEnum.Tools, inmodel.Guid, drivewaymodel.ParkCode, inmodel.CarNo, "Fujica.com.cn.MonitorServiceClient.EntryDataManager", "根据车类Guid,读取车类模型为空"); return(response); } ParkLotModel parklotmodel = m_serializer.Deserialize <ParkLotModel>(db.HashGet("ParkLotList", cartypemodel.ParkCode)); if (parklotmodel == null) { response.MessageContent = "根据停车场编码,读取车场模型为空"; m_ilogger.LogError(LoggerLogicEnum.Tools, inmodel.Guid, drivewaymodel.ParkCode, inmodel.CarNo, "Fujica.com.cn.MonitorServiceClient.EntryDataManager", "根据停车场编码,读取车场模型为空"); return(response); } 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 = (Int32)cartypemodel.CarType, CarTypeName = cartypemodel.CarTypeName, Entrance = drivewaymodel.DrivewayName, EntranceCamera = drivewaymodel.DeviceName, DriveWayMAC = inmodel.DriveWayMAC, OpenType = inmodel.OpenType, Operator = inmodel.Operator }; //存到redis try { db = RedisHelper.GetDatabase(Common.GetDatabaseNumber(entrymodel.CarNo)); //查询车辆是否已在场内(是否重复入场) bool repeatEntry = db.HashExists(entrymodel.CarNo, entrymodel.ParkingCode); //散列储存车辆入场数据 db.HashSet(entrymodel.CarNo, entrymodel.ParkingCode, m_serializer.Serialize(entrymodel)); db.KeyExpire(entrymodel.CarNo, DateTime.Now.AddDays(1 - DateTime.Now.Day).Date.AddMonths(3).AddSeconds(-1));//三个月自动过期或出场删除 bool flag = db.HashExists(entrymodel.CarNo, entrymodel.ParkingCode); //在1号db存储在场车牌列表(用于后续业务的分页查询) if (flag) { db = RedisHelper.GetDatabase(1); string hashKey = entrymodel.ParkingCode + ":" + DateTime.Now.ToString("yyyyMM"); db.SortedSetAdd(hashKey, entrymodel.CarNo, Convert.ToDouble(inmodel.InTime.ToString("yyyyMMddHHmmss"))); flag = db.KeyExpire(hashKey, DateTime.Now.AddDays(1 - DateTime.Now.Day).Date.AddMonths(3).AddSeconds(-1));//三个月自动过期或出场删除 } //在2号db存储入场数据实体(相机上传原样数据),出场再删掉(用于相机数据同步) if (flag) { db = RedisHelper.GetDatabase(2); string hashKey = entrymodel.ParkingCode + ":" + DateTime.Now.ToString("yyyyMM"); db.HashSet(hashKey, entrymodel.CarNo, redisContent); db.KeyExpire(hashKey, DateTime.Now.AddDays(1 - DateTime.Now.Day).Date.AddMonths(3).AddSeconds(-1));//三个月自动过期或出场删除 flag = db.HashExists(hashKey, entrymodel.CarNo); } //redis存储成功后 if (flag) { m_ilogger.LogInfo(LoggerLogicEnum.Tools, entrymodel.RecordGuid, entrymodel.ParkingCode, entrymodel.CarNo, "Fujica.com.cn.MonitorServiceClient.EntryDataManager", entrymodel.CarNo + "车辆入场数据添加redis成功"); //当前车位数量 int remainingNumber = Convert.ToInt32(db.ListLength("SpaceNumberList:" + entrymodel.ParkingCode)); //如果不是重复入场,则进行车位数更新 if (!repeatEntry) { //剩余车位数控制 db = RedisHelper.GetDatabase(0); db.ListLeftPop("SpaceNumberList:" + entrymodel.ParkingCode); //调用mq给相机发送当前车位数 //最新车位数量 remainingNumber = Convert.ToInt32(db.ListLength("SpaceNumberList:" + entrymodel.ParkingCode)); SpaceNumberToCamera(remainingNumber, entrymodel.ParkingCode, m_ilogger, m_serializer); //修改redis中停车场的剩余车位数 parklotmodel.RemainingSpace = (uint)remainingNumber; db = RedisHelper.GetDatabase(0); db.HashSet("ParkLotList", parklotmodel.ParkCode, m_serializer.Serialize(parklotmodel)); //修改mysql中停车场的剩余车位数 SaveSpaceNumberToDB(parklotmodel, m_ilogger, m_serializer); } #region 移动岗亭数据推送 CaptureInOutModel capturModel = new CaptureInOutModel() { Guid = entrymodel.RecordGuid, ParkCode = entrymodel.ParkingCode, Entrance = entrymodel.Entrance, DriveWayMAC = entrymodel.DriveWayMAC, RemainingNumber = remainingNumber.ToString(), CarNo = entrymodel.CarNo, EntryType = "0", CarType = entrymodel.CarType, CarTypeName = entrymodel.CarTypeName, CarTypeGuid = entrymodel.CarTypeGuid, InTime = Convert.ToDateTime(entrymodel.BeginTime), InImgUrl = entrymodel.InImgUrl, Remark = entrymodel.Description, ErrorCode = "-1" //错误类型(异常时使用,正常数据默认是-1) }; //推送到客户端(实现移动岗亭功能) SendInDataToClient(capturModel); //存储一份在redis中 GateDataToRedis(capturModel, m_serializer); #endregion //再往主平台Fujica补发入场数据 bool fujicaResult = EntryDataToFujica(entrymodel, cartypemodel.Idx); if (fujicaResult) { //入场分发服务 DistributeEntryData(entrymodel, cartypemodel.Idx, m_ilogger); response.IsSuccess = true; response.MessageContent = entrymodel.CarNo + "车辆入场数据添加redis和补发fujica入场数据成功"; m_ilogger.LogInfo(LoggerLogicEnum.Tools, entrymodel.RecordGuid, entrymodel.ParkingCode, entrymodel.CarNo, "Fujica.com.cn.MonitorServiceClient.EntryDataManager", entrymodel.CarNo + "车辆入场数据添加redis和补发fujica入场数据成功"); return(response); } else { response.IsSuccess = true; response.MessageContent = entrymodel.CarNo + "车辆入场数据添加redis成功;补发fujica入场数据失败"; m_ilogger.LogError(LoggerLogicEnum.Tools, entrymodel.RecordGuid, entrymodel.ParkingCode, entrymodel.CarNo, "Fujica.com.cn.MonitorServiceClient.EntryDataManager", entrymodel.CarNo + "车辆入场数据添加redis成功;补发fujica入场数据失败"); return(response); } } else { response.MessageContent = entrymodel.CarNo + "车辆入场数据添加redis失败"; m_ilogger.LogError(LoggerLogicEnum.Tools, entrymodel.RecordGuid, entrymodel.ParkingCode, entrymodel.CarNo, "Fujica.com.cn.MonitorServiceClient.EntryDataManager", entrymodel.CarNo + "车辆入场数据添加redis失败"); return(response); } } catch (Exception ex) { m_ilogger.LogFatal(LoggerLogicEnum.Tools, entrymodel.RecordGuid, entrymodel.ParkingCode, entrymodel.CarNo, "Fujica.com.cn.MonitorServiceClient.EntryDataManager", entrymodel.CarNo + "保存入场数据到redis异常", ex.ToString()); response.MessageContent = entrymodel.CarNo + "车辆入场数据发生异常:" + ex.ToString(); return(response); } finally { //GC.Collect(); } }