Beispiel #1
0
        public async void DoMessage(DeviceInfoDto deviceInfoDto)
        {
            ManualResetEvent manualResetEvent = new ManualResetEvent(false);

            using (var unitOfWork = _unitOfWork.Begin())
            {
                DateTime photoTime = DateTime.Now;
                var      result    = deviceInfoDto.Controlable.Camerable.GetPlateNumber();
                string   carNumber = result.Item1;
                //Task.Run(async () =>
                // {
                await parkBoxOptions.SetInfosDic?[deviceInfoDto.EntranceDto.Id]?.SetImage(await result.Item2);
                //});
                if (deviceInfoDto.EntranceDto.EntranceType == Enum.EntranceType.In)
                {
                    //禁止非机动车入场
                    if (!parkBoxOptions.NonmotorVehicleIn && result.Item4 == CarTypeEnum.NonMotorVehicle)
                    {
                        Logger.Info("非机动车辆禁止进入" + result.Item1);
                        return;
                    }
                    var backList = await _repositoryBlackList.FirstOrDefaultAsync(x => x.CarNumber == carNumber);

                    if (backList != null)
                    {
                        Logger.Info(result.Item1 + " 存在于黑名单 禁止进入");
                    }

                    var permission = _carNumberPermission.CheckCarNumberPermission(carNumber, deviceInfoDto.EntranceDto.Id);
                    var carInModel = new Parks.ParkBox.CarInModel()
                    {
                        CarNumber = carNumber,
                        Img       = null,
                        InOutType = Enum.InOutTypeEnum.Photo,
                        InTime    = DateTime.Now,
                        Entrance  = deviceInfoDto.EntranceDto
                    };
                    if (permission.IsCarIn.HasValue && !permission.IsCarIn.Value)
                    {
                        Logger.Debug(carNumber + "no permission" + permission.ToString());

                        return;
                    }
                    else if (permission.IsCarIn == null)
                    {
                        var cancle = MessageBox.Show("当前车辆无权进入是否放行?", "提示", MessageBoxButton.OKCancel);
                        if (cancle == MessageBoxResult.Cancel)
                        {
                            return;
                        }
                    }
                    //入场时检查是否有场内记录
                    var isCarIn = _vehicleFlow.IsCarIn(deviceInfoDto.EntranceDto.ParkLevel.Park.Id, carNumber);
                    if (isCarIn.IsCarIn)
                    {
                        var carOutModel = new CarOutModel()
                        {
                            CarInRecord = isCarIn.CarInRecord,
                            InOutType   = Enum.InOutTypeEnum.Photo,
                            OutTime     = DateTime.Now,
                            Receivable  = 0,
                            ParkId      = deviceInfoDto.EntranceDto.ParkLevel.Park.Id,
                            Remark      = "有场内纪录,再次入场"
                        };
                        _vehicleFlow.CarErrorOut(isCarIn.CarInRecord, carOutModel);
                    }
                    var carIn = _vehicleFlow.CarIn(carInModel, permission);
                    if (carIn != null)
                    {
                        await deviceInfoDto.Controlable?.Camerable?.OpenRod();

                        //await deviceInfoDto.Controlable.Camerable.OpenRod(); //抬杆
                        await _ledManager.SpeakAndShowText(deviceInfoDto, carInModel, permission); //播报语音

                        await parkBoxOptions.SetInfosDic?[deviceInfoDto.EntranceDto.Id]?.SetInfo(carIn);
                    }
                    else
                    {
                        MessageBox.Show("入场失败");
                        return;
                    }
                }
                else
                {
                    /*
                     * 出场逻辑中 无场内车辆的记录也弹出
                     */


                    var isCarIn = _vehicleFlow.IsCarIn(deviceInfoDto.EntranceDto.ParkLevel.Park.Id, carNumber);
                    if (isCarIn.IsCarIn)
                    {
                        var user = _carNumberPermission.GetUser(deviceInfoDto.EntranceDto.ParkLevel.Park.Id, carNumber);
                        if (user != null)
                        {
                            var typeId  = user.CarPorts.FirstOrDefault()?.CarPortTypeId;
                            var carType = _repositoryCarType.GetAll().FirstOrDefault(x => x.Id == (typeId.HasValue ? typeId.Value : parkBoxOptions.TempCarTypeId));
                            //月租车正常出场
                            if (carType.Category == CarType.Month)
                            {
                                if (!isCarIn.CarInRecord.IsMonthTempIn)
                                {
                                    var outRcode = _vehicleFlow.CarOut(isCarIn.CarInRecord, new Parks.ParkBox.CarOutModel()
                                    {
                                        Pay = 0, InOutType = Enum.InOutTypeEnum.Artificial, OutTime = DateTime.Now
                                    });
                                    if (outRcode != null)
                                    {
                                        await parkBoxOptions.SetInfosDic?[deviceInfoDto.EntranceDto.Id]?.SetInfo(outRcode);
                                    }
                                    else
                                    {
                                        MessageBox.Show("出场失败!", "提示");
                                    }
                                }
                                else
                                {  //月租车收费
                                    DateTime outTime = DateTime.Now;

                                    FareRule fareRule  = _repositoryFareRule.GetAll().FirstOrDefault(x => x.CarTypeId == parkBoxOptions.TempCarTypeId);
                                    var      rangTimes = _repositoryRangeTime.GetAllIncluding(x => x.FareRule).Where(x => x.FareRuleId == fareRule.Id).ToList();
                                    fareRule.TimeRangeList = rangTimes;

                                    if (isCarIn.CarInRecord.TempConvertMonthTime.HasValue)
                                    {
                                        outTime = isCarIn.CarInRecord.TempConvertMonthTime.Value;
                                    }
                                    var receivable  = fareRule.CalculateFees(isCarIn.CarInRecord.InTime, outTime, 0);
                                    var carOutModel = new CarOutModel()
                                    {
                                        CarInRecord = isCarIn.CarInRecord,
                                        InOutType   = Enum.InOutTypeEnum.Artificial,
                                        OutTime     = DateTime.Now,
                                        Receivable  = receivable,
                                        ParkId      = deviceInfoDto.EntranceDto.ParkLevel.Park.Id
                                    };
                                    if (parkBoxOptions.IsZeroMoneyOut && receivable == 0) //收费为0 直接放行
                                    {
                                        var outRcode = _vehicleFlow.CarOut(isCarIn.CarInRecord, carOutModel);
                                        if (outRcode != null)
                                        {
                                            await parkBoxOptions.SetInfosDic?[deviceInfoDto.EntranceDto.Id]?.SetInfo(outRcode);

                                            await deviceInfoDto.Controlable?.Camerable?.OpenRod();

                                            await _ledManager.SpeakAndShowText(deviceInfoDto, carOutModel, OutEnum.SuccessfulPayment); //播报语音
                                        }
                                        else
                                        {
                                            MessageBox.Show("出场失败!", "提示");
                                        }
                                        return;
                                    }


                                    await _ledManager.SpeakAndShowText(deviceInfoDto, carOutModel, OutEnum.CalculationFee); //播报语音

                                    var tollWindow = await GetChargerWindow(_ledManager, carOutModel, fareRule, receivable, _repositoryCarType, parkBoxOptions, _repositoryCarPort, _vehicleFlow, deviceInfoDto, _repositoryFareRule, _repositoryRangeTime, manualResetEvent);

                                    tollWindow.Init();
                                    tollWindow.Show();
                                    WaitHandle.WaitAll(new WaitHandle[] { manualResetEvent });
                                    var isFree = tollWindow.IsClose;
                                    if (isFree.HasValue && isFree.Value)
                                    {
                                        await deviceInfoDto.Controlable?.Camerable?.OpenRod();

                                        await parkBoxOptions.SetInfosDic?[deviceInfoDto.EntranceDto.Id]?.SetInfo(tollWindow.CarOutRecord);
                                        await _ledManager.SpeakAndShowText(deviceInfoDto, carOutModel, OutEnum.SuccessfulPayment); //播报语音
                                    }
                                }
                            }
                            else
                            {
                                //其他车类型
                                DateTime outTime = DateTime.Now;

                                FareRule fareRule  = _repositoryFareRule.GetAll().FirstOrDefault(x => x.CarTypeId == carType.Id);
                                var      rangTimes = _repositoryRangeTime.GetAllIncluding(x => x.FareRule).Where(x => x.FareRuleId == fareRule.Id).ToList();
                                fareRule.TimeRangeList = rangTimes;

                                var receivable  = fareRule?.CalculateFees(isCarIn.CarInRecord.InTime, outTime, 0) ?? 0;
                                var carOutModel = new CarOutModel()
                                {
                                    CarInRecord = isCarIn.CarInRecord,
                                    InOutType   = Enum.InOutTypeEnum.Artificial,
                                    OutTime     = outTime,
                                    Receivable  = receivable,
                                    ParkId      = deviceInfoDto.EntranceDto.ParkLevel.Park.Id
                                };

                                if (parkBoxOptions.IsZeroMoneyOut && receivable == 0) //收费为0 直接放行
                                {
                                    var outRcode = _vehicleFlow.CarOut(isCarIn.CarInRecord, carOutModel);
                                    if (outRcode != null)
                                    {
                                        await deviceInfoDto.Controlable?.Camerable?.OpenRod();

                                        await parkBoxOptions.SetInfosDic?[deviceInfoDto.EntranceDto.Id]?.SetInfo(outRcode);
                                        await _ledManager.SpeakAndShowText(deviceInfoDto, carOutModel, OutEnum.SuccessfulPayment); //播报语音
                                    }
                                    else
                                    {
                                        MessageBox.Show("出场失败!", "提示");
                                    }
                                    return;
                                }

                                await _ledManager.SpeakAndShowText(deviceInfoDto, carOutModel, OutEnum.CalculationFee); //播报语音

                                var tollWindow = await GetChargerWindow(_ledManager, carOutModel, fareRule, receivable, _repositoryCarType, parkBoxOptions, _repositoryCarPort, _vehicleFlow, deviceInfoDto, _repositoryFareRule, _repositoryRangeTime, manualResetEvent);

                                tollWindow.Init();
                                tollWindow.Show();
                                WaitHandle.WaitAll(new WaitHandle[] { manualResetEvent });
                                var isFree = tollWindow.IsClose;
                                if (isFree.HasValue && isFree.Value)
                                {
                                    await deviceInfoDto.Controlable?.Camerable?.OpenRod();

                                    await parkBoxOptions.SetInfosDic?[deviceInfoDto.EntranceDto.Id]?.SetInfo(tollWindow.CarOutRecord);


                                    await _ledManager.SpeakAndShowText(deviceInfoDto, carOutModel, OutEnum.SuccessfulPayment); //播报语音
                                }
                            }
                        }
                        else
                        {  //临时车
                            DateTime outTime = DateTime.Now;

                            FareRule fareRule = _repositoryFareRule.GetAll().FirstOrDefault(x => x.CarTypeId == parkBoxOptions.TempCarTypeId);

                            var rangTimes = _repositoryRangeTime.GetAllIncluding(x => x.FareRule).Where(x => x.FareRuleId == fareRule.Id).ToList();
                            fareRule.TimeRangeList = rangTimes;

                            var receivable = fareRule?.CalculateFees(isCarIn.CarInRecord.InTime, outTime, 0) ?? 0;

                            var carOutModel = new CarOutModel()
                            {
                                CarInRecord = isCarIn.CarInRecord,
                                InOutType   = Enum.InOutTypeEnum.Artificial,
                                OutTime     = outTime,
                                Receivable  = receivable,
                                ParkId      = deviceInfoDto.EntranceDto.ParkLevel.Park.Id
                            };

                            if (parkBoxOptions.IsZeroMoneyOut && receivable == 0) //收费为0 直接放行
                            {
                                var outRcode = _vehicleFlow.CarOut(isCarIn.CarInRecord, carOutModel);
                                if (outRcode != null)
                                {
                                    await deviceInfoDto.Controlable?.Camerable?.OpenRod();

                                    await parkBoxOptions.SetInfosDic?[deviceInfoDto.EntranceDto.Id]?.SetInfo(outRcode);
                                    await _ledManager.SpeakAndShowText(deviceInfoDto, carOutModel, OutEnum.SuccessfulPayment); //播报语音
                                }
                                else
                                {
                                    MessageBox.Show("出场失败!", "提示");
                                }
                                return;
                            }

                            await _ledManager.SpeakAndShowText(deviceInfoDto, carOutModel, OutEnum.CalculationFee); //播报语音

                            var tollWindow = await GetChargerWindow(_ledManager, carOutModel, fareRule, receivable, _repositoryCarType, parkBoxOptions, _repositoryCarPort, _vehicleFlow, deviceInfoDto, _repositoryFareRule, _repositoryRangeTime, manualResetEvent);

                            tollWindow.Init();
                            tollWindow.Show();
                            var isFree = tollWindow.IsClose;
                            if (isFree.HasValue && isFree.Value)
                            {
                                await deviceInfoDto.Controlable?.Camerable?.OpenRod();

                                await parkBoxOptions.SetInfosDic?[deviceInfoDto.EntranceDto.Id]?.SetInfo(tollWindow.CarOutRecord);
                                await _ledManager.SpeakAndShowText(deviceInfoDto, carOutModel, OutEnum.SuccessfulPayment); //播报语音
                            }
                        }
                    }
                    else
                    {
                        Logger.Info(carNumber + " 无场内记录");
                        //无在场记录如果为月租车直接放行  否则弹出收费框
                        var user = _carNumberPermission.GetUser(deviceInfoDto.EntranceDto.ParkLevel.Park.Id, carNumber);
                        if (user != null)
                        {
                            var model = new Parks.ParkBox.CarOutModel()
                            {
                                Pay = 0, InOutType = Enum.InOutTypeEnum.Artificial, OutTime = DateTime.Now, ParkId = deviceInfoDto.EntranceDto.ParkLevel.Park.Id
                            };
                            var outRcode = _vehicleFlow.CarOut(carNumber, user, model);
                            if (outRcode != null)
                            {
                                await deviceInfoDto.Controlable?.Camerable?.OpenRod();

                                await parkBoxOptions.SetInfosDic?[deviceInfoDto.EntranceDto.Id]?.SetInfo(outRcode);


                                await _ledManager.SpeakAndShowText(deviceInfoDto, model, OutEnum.SuccessfulPayment); //播报语音
                            }
                            else
                            {
                                MessageBox.Show("出场失败!", "提示");
                            }
                            return;
                        }
                        else
                        {
                            FareRule fareRule  = _repositoryFareRule.GetAll().FirstOrDefault(x => x.CarTypeId == parkBoxOptions.TempCarTypeId);
                            var      rangTimes = _repositoryRangeTime.GetAllIncluding(x => x.FareRule).Where(x => x.FareRuleId == fareRule.Id).ToList();
                            fareRule.TimeRangeList = rangTimes;

                            ///弹出收费框
                            var tollWindow = await GetChargerWindow(_ledManager, carNumber, fareRule, InOutTypeEnum.Photo, _repositoryCarType, parkBoxOptions, _repositoryCarPort, _vehicleFlow, deviceInfoDto, _repositoryFareRule, _repositoryRangeTime, manualResetEvent);

                            tollWindow.Init();
                            tollWindow.Show();
                            WaitHandle.WaitAll(new WaitHandle[] { manualResetEvent });
                            var isFree = tollWindow.IsClose;
                            if (isFree.HasValue && isFree.Value)
                            {
                                await deviceInfoDto.Controlable?.Camerable?.OpenRod();

                                await parkBoxOptions.SetInfosDic?[deviceInfoDto.EntranceDto.Id]?.SetInfo(tollWindow.CarOutRecord);


                                await _ledManager.SpeakAndShowText(deviceInfoDto, tollWindow.CarOutModel, OutEnum.SuccessfulPayment); //播报语音
                            }
                            return;
                        }
                    }
                }


                await unitOfWork.CompleteAsync();
            }
        }
Beispiel #2
0
        private async void btn_In_Click(object sender, RoutedEventArgs e)
        {
            if (_inEntranceDto == null)
            {
                await this.ShowMessageAsync("提示", "未找到出入口信息");

                return;
            }
            var carNumber = txt_InCarNumber.Text;

            if (carNumber.IsNullOrEmpty())
            {
                await this.ShowMessageAsync("提示", "车牌号不允许为空!");

                return;
            }
            using (var unitOfWork = UnitOfWorkManager.Begin())
            {
                var backList = await _repositoryBlackList.FirstOrDefaultAsync(x => x.CarNumber == carNumber);

                if (backList != null)
                {
                    if (!parkBoxOptions.IsListView)
                    {
                        var cancle = await this.ShowMessageAsync("提示", "当前车辆在黑名单是否放行?", MessageDialogStyle.AffirmativeAndNegative);

                        if (cancle == MessageDialogResult.Negative)
                        {
                            return;
                        }
                    }
                    else
                    { //打开实时监控画面时   Metro自带的弹窗会被盖住 采用系统弹窗
                        var cancle = MessageBox.Show("当前车辆在黑名单是否放行?", "提示", MessageBoxButton.OKCancel);
                        if (cancle == MessageBoxResult.Cancel)
                        {
                            return;
                        }
                    }
                }

                var result     = _carNumberPermission.CheckCarNumberPermission(carNumber, _inEntranceDto.Id);
                var carInModel = new Parks.ParkBox.CarInModel()
                {
                    CarNumber = carNumber,
                    Img       = null,
                    InOutType = Enum.InOutTypeEnum.Artificial,
                    InTime    = DateTime.Now,
                    Entrance  = _inEntranceDto
                };
                if (result.IsCarIn.HasValue && !result.IsCarIn.Value)
                {
                    Logger.Debug(carNumber + "no permission" + result.ToString());
                    if (!parkBoxOptions.IsListView)
                    {
                        var cancle = await this.ShowMessageAsync("当前车辆无权进入是否放行?", "提示", MessageDialogStyle.AffirmativeAndNegative);

                        if (cancle == MessageDialogResult.Negative)
                        {
                            return;
                        }
                    }
                    else
                    {
                        var cancle = MessageBox.Show("提示", "当前车辆无权进入是否放行?", MessageBoxButton.OKCancel);
                        if (cancle == MessageBoxResult.Cancel)
                        {
                            return;
                        }
                    }
                }
                //入场时检查是否有场内记录
                var isCarIn = _vehicleFlow.IsCarIn(_inEntranceDto.ParkLevel.Park.Id, carNumber);
                if (isCarIn.IsCarIn)
                {
                    var carOutModel = new CarOutModel()
                    {
                        CarInRecord = isCarIn.CarInRecord,
                        InOutType   = Enum.InOutTypeEnum.Artificial,
                        OutTime     = DateTime.Now,
                        Receivable  = 0,
                        ParkId      = _inEntranceDto.ParkLevel.Park.Id,
                        Remark      = "有场内纪录,再次入场"
                    };
                    _vehicleFlow.CarErrorOut(isCarIn.CarInRecord, carOutModel);
                }
                var carIn = _vehicleFlow.CarIn(carInModel, result);
                if (carIn != null)
                {
                    await parkEntrances[_inEntranceDto.Id]?.OpenRod();
                    //await deviceInfoDto.Controlable.Camerable.OpenRod(); //抬杆
                    await _ledManager.SpeakAndShowText((parkEntrances[_inEntranceDto.Id] as ParkEntranceInfo)?.GetDeviceInfo(), carInModel, result); //播报语音

                    parkEntrances[_inEntranceDto.Id]?.SetInfo(carIn);
                }
                else
                {
                    await this.ShowMessageAsync("提示", "入场失败");

                    return;
                }
                await unitOfWork.CompleteAsync();
            }
        }