Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        public static ResponseCommon DataHandle(ILogger m_ilogger, ISerializer m_serializer)
        {
            ResponseCommon response = new ResponseCommon()
            {
                IsSuccess = false,
                MsgType   = MsgType.PayCard
            };

            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.PayDataManager", "支付数据接收成功.原始数据:" + redisContent);

            IssuedRecord recordModel = m_serializer.Deserialize <IssuedRecord>(redisContent);

            if (recordModel == null)
            {
                response.MessageContent = "redis数据库读取值转换成实体失败:";
                return(response);
            }
            if (string.IsNullOrEmpty(recordModel.ParkingCode) ||
                string.IsNullOrEmpty(recordModel.CarNo) ||
                recordModel.CardType <= 0 ||
                string.IsNullOrEmpty(recordModel.TradeNo)
                //|| string.IsNullOrEmpty(inmodel.Remark)
                )
            {
                response.MessageContent = "redis数据转换成实体后必要参数缺失";
                return(response);
            }
            if (recordModel.CardType == 1)
            {
                if (recordModel.RenewDay <= 0 && recordModel.RenewDayType <= 0)
                {
                    response.MessageContent = "redis数据转换成实体后必要参数缺失";
                    return(response);
                }
            }
            else if (recordModel.CardType == 2 && recordModel.Price <= 0)
            {
                response.MessageContent = "redis数据转换成实体后必要参数缺失";
                return(response);
            }

            db = RedisHelper.GetDatabase(0);
            //判断当前订单号,是否已执行过
            string mqPayDataListKey = "PayDataList:" + recordModel.ParkingCode + ":" + DateTime.Now.ToString("yyyyMMdd");

            if (db.HashExists(mqPayDataListKey, recordModel.TradeNo))
            {
                response.MessageContent = "当前订单记录重复执行";
                m_ilogger.LogInfo(LoggerLogicEnum.Tools, recordModel.TradeNo, recordModel.ParkingCode, recordModel.CardNo, "Fujica.com.cn.MonitorServiceClient.PayDataManager", $"TradeNo:{recordModel.TradeNo} 当前订单记录重复执行");
                return(response);
            }
            else
            {
                db.HashSet(mqPayDataListKey, recordModel.TradeNo, redisContent);
                db.KeyExpire(mqPayDataListKey, DateTime.Now.AddDays(1).Date);
            }

            string           hashkey   = recordModel.ParkingCode + Convert.ToBase64String(Encoding.UTF8.GetBytes(recordModel.CarNo));
            CardServiceModel cardModel = m_serializer.Deserialize <CardServiceModel>(db.HashGet("PermanentCarList", hashkey));

            if (cardModel == null)
            {
                cardModel = GetCard(hashkey, m_ilogger, m_serializer);
                if (cardModel == null)
                {
                    response.MessageContent = "根据车场编号和车牌号,读取卡务模型为空";
                    m_ilogger.LogError(LoggerLogicEnum.Tools, recordModel.TradeNo, recordModel.ParkingCode, recordModel.CardNo, "Fujica.com.cn.MonitorServiceClient.PayDataManager", "根据车场编号和车牌号,读取卡务模型为空");
                    return(response);
                }
            }

            CarTypeModel cartypemodel = m_serializer.Deserialize <CarTypeModel>(db.HashGet("CarTypeList", cardModel.CarTypeGuid));

            if (cartypemodel == null)
            {
                response.MessageContent = "根据车类Guid,读取车类模型为空";
                m_ilogger.LogError(LoggerLogicEnum.Tools, recordModel.TradeNo, recordModel.ParkingCode, recordModel.CardNo, "Fujica.com.cn.MonitorServiceClient.PayDataManager", "根据车类Guid,读取车类模型为空");
                return(response);
            }

            try
            {
                if (recordModel.CardType == 1)
                {
                    //月卡延期(截止时间、延期金额、支付方式)
                    //暂时只控制截至日期,暂无日志记录,所以不需要存储延期金额和支付方式
                    cardModel.EndDate = FormatEndDate(cardModel.EndDate, recordModel.RenewDay, recordModel.RenewDayType);

                    bool flag = false;
                    //修改数据库
                    flag = SaveMonthCarToDB(cardModel, m_ilogger, m_serializer);
                    if (!flag)
                    {
                        response.MessageContent = "月卡保存数据库失败";
                        m_ilogger.LogError(LoggerLogicEnum.Tools, recordModel.TradeNo, recordModel.ParkingCode, recordModel.CardNo, "Fujica.com.cn.MonitorServiceClient.PayDataManager", "月卡保存数据库失败");
                        return(response);
                    }
                    //修改redis
                    flag = SaveMonthCarToRedis(cardModel, m_ilogger, m_serializer);
                    if (!flag)
                    {
                        response.MessageContent = "月卡保存数据库成功,保存redis失败";
                        m_ilogger.LogError(LoggerLogicEnum.Tools, recordModel.TradeNo, recordModel.ParkingCode, recordModel.CardNo, "Fujica.com.cn.MonitorServiceClient.PayDataManager", "月卡保存数据库成功,保存redis失败");
                        return(response);
                    }
                    //发送给相机
                    SendMonthCarToCameras(cardModel, m_ilogger, m_serializer);
                    //发送给Fujica
                    flag = SendMonthCarToFujica(cardModel, cartypemodel.Idx);
                    if (!flag)
                    {
                        response.MessageContent = "月卡保存数据库、redis成功,发送Fujica失败";
                        m_ilogger.LogError(LoggerLogicEnum.Tools, recordModel.TradeNo, recordModel.ParkingCode, recordModel.CardNo, "Fujica.com.cn.MonitorServiceClient.PayDataManager", "月卡保存数据库、redis成功,发送Fujica失败");
                        return(response);
                    }
                    m_ilogger.LogInfo(LoggerLogicEnum.Tools, recordModel.TradeNo, recordModel.ParkingCode, recordModel.CardNo, "Fujica.com.cn.MonitorServiceClient.PayDataManager", "月卡保存数据库、redis、发送Fujica成功");
                }
                else if (recordModel.CardType == 2)
                {
                    //储值卡充值(充值金额、充值方式)
                    //暂时只控制余额,暂无日志记录,所以不需要操作充值金额和充值方式
                    cardModel.Balance += recordModel.Price;

                    bool flag = false;
                    //修改数据库、redis
                    flag = SaveValueCarToDB(cardModel, m_ilogger, m_serializer);
                    if (!flag)
                    {
                        response.MessageContent = "储值卡保存数据库失败";
                        m_ilogger.LogError(LoggerLogicEnum.Tools, recordModel.TradeNo, recordModel.ParkingCode, recordModel.CardNo, "Fujica.com.cn.MonitorServiceClient.PayDataManager", "储值卡保存数据库失败");
                        return(response);
                    }

                    //修改redis
                    flag = SaveValueCarToRedis(cardModel, m_ilogger, m_serializer);
                    if (!flag)
                    {
                        response.MessageContent = "储值卡保存数据库成功,保存redis失败";
                        m_ilogger.LogError(LoggerLogicEnum.Tools, recordModel.TradeNo, recordModel.ParkingCode, recordModel.CardNo, "Fujica.com.cn.MonitorServiceClient.PayDataManager", "储值卡保存数据库成功,保存redis失败");
                        return(response);
                    }
                    //发送给相机
                    SendValueCarToCameras(cardModel, m_ilogger, m_serializer);
                    //发送给Fujica
                    flag = SendValueCarToFujica(cardModel, cartypemodel.Idx);
                    if (!flag)
                    {
                        response.MessageContent = "储值卡保存数据库、redis成功,发送Fujica失败";
                        m_ilogger.LogError(LoggerLogicEnum.Tools, recordModel.TradeNo, recordModel.ParkingCode, recordModel.CardNo, "Fujica.com.cn.MonitorServiceClient.PayDataManager", "储值卡保存数据库、redis成功,发送Fujica失败");
                        return(response);
                    }
                    m_ilogger.LogInfo(LoggerLogicEnum.Tools, recordModel.TradeNo, recordModel.ParkingCode, recordModel.CardNo, "Fujica.com.cn.MonitorServiceClient.PayDataManager", "储值卡保存数据库、redis、发送Fujica成功");
                }

                response.IsSuccess      = true;
                response.MessageContent = "支付数据操作成功";
            }
            catch (Exception ex)
            {
                m_ilogger.LogFatal(LoggerLogicEnum.Tools, recordModel.TradeNo, cardModel.ParkCode, recordModel.CardNo, "Fujica.com.cn.MonitorServiceClient.PayDataManager", cardModel.CarNo + "支付数据发生异常", ex.ToString());

                response.MessageContent = cardModel.CarNo + "支付数据发生异常:" + ex.ToString();
                return(response);
            }

            return(response);
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
        public static ResponseCommon DataHandle(ILogger m_ilogger, ISerializer m_serializer)
        {
            ResponseCommon response = new ResponseCommon()
            {
                IsSuccess = false,
                MsgType   = MsgType.HeartBeat
            };
            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.HeartBeatDataManager", "相机心跳数据接收成功。原始数据:" + redisContent);


            HeartBeatModel heartModel = m_serializer.Deserialize <HeartBeatModel>(redisContent);

            if (heartModel == null)
            {
                response.MessageContent = "redis数据库读取值转换成实体失败:";
                return(response);
            }
            if (string.IsNullOrEmpty(heartModel.TimeStamp) ||
                string.IsNullOrEmpty(heartModel.DeviceIdentify) ||
                string.IsNullOrEmpty(heartModel.ParkingCode)
                )
            {
                response.MessageContent = "redis数据转换成实体后必要参数缺失";
                return(response);
            }

            string hashKey = "HeartBeatList:" + heartModel.ParkingCode;

            db = RedisHelper.GetDatabase(0);
            //因相机和服务器时间同步问题,暂时不使用相机时间进行数据更新
            //db.HashSet(hashKey, heartModel.DeviceIdentify, Regex.Replace(heartModel.TimeStamp, @"(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})", "$1-$2-$3 $4:$5:$6"));
            db.HashSet(hashKey, heartModel.DeviceIdentify, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            db.KeyExpire(hashKey, DateTime.Now.AddDays(1));//一天后自动过期
            bool flag = db.HashExists(hashKey, heartModel.DeviceIdentify);

            if (flag)
            {
                response.IsSuccess      = true;
                response.MessageContent = heartModel.DeviceIdentify + "相机心跳数据添加redis成功";
                m_ilogger.LogInfo(LoggerLogicEnum.Tools, "", "", "", "Fujica.com.cn.MonitorServiceClient.HeartBeatDataManager", heartModel.DeviceIdentify + "相机心跳数据添加redis成功");

                #region 相机心跳数据发送至页面
                HeartBeatModel model = new HeartBeatModel()
                {
                    TimeStamp      = heartModel.TimeStamp,
                    ParkingCode    = heartModel.ParkingCode,
                    DeviceIdentify = heartModel.DeviceIdentify
                };
                SendHeartBeatToClient(model);
                #endregion

                return(response);
            }
            else
            {
                response.MessageContent = heartModel.DeviceIdentify + "相机心跳数据添加redis失败";
                m_ilogger.LogInfo(LoggerLogicEnum.Tools, "", heartModel.ParkingCode, "", "Fujica.com.cn.MonitorServiceClient.HeartBeatDataManager", heartModel.DeviceIdentify + "相机心跳数据添加redis失败");
                return(response);
            }
        }
Esempio n. 6
0
        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();
            }
        }