Пример #1
0
        /// <summary>
        /// Context工厂
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        private RuleHandler CreateRuleHandler(InputAgs args, ResultAgs rst)
        {
            string errorMsg = "";

            if (args.AreadInfo.IsNestArea && args.AreadInfo.Parent == null)//内部车场时 且上级区域为空时
            {
                args.AreadInfo.Parent = ParkAreaServices.QueryByRecordId(args.AreadInfo.MasterID);
                if (args.AreadInfo.Parent == null)//还是找不到上级区域时
                {
                    LogerHelper.Loger.Error(string.Format("找不到车场[{0}]的上级车场,上级车场ID为[{1}].", args.AreadInfo.AreaName, args.AreadInfo.MasterID));
                    args.AreadInfo.MasterID = "";//找不到就至为空
                }
            }
            //判断系统停车或非系统停车
            var cartype = BaseCarType.TempCar;

            if (!args.Plateinfo.LicenseNum.Contains("无") && args.Plateinfo.LicenseNum.Length > 3)//不是“无车牌”
            {
                EmployeePlate platenumber = null;
                if (args.GateInfo.OpenPlateBlurryMatch == YesOrNo.Yes)
                {
                    string likeplate = args.Plateinfo.LicenseNum;
                    platenumber = EmployeePlateServices.GetEmployeePlateNumberByPlateNumber(args.AreadInfo.Parkinfo.VID, likeplate, out errorMsg);

                    if (platenumber == null && args.Plateinfo.LicenseNum.Length >= 3)//模糊识别 前一位后一位模糊识别
                    {
                        likeplate   = args.Plateinfo.LicenseNum.Substring(2, args.Plateinfo.LicenseNum.Length - 2);
                        platenumber = EmployeePlateServices.GetGrantPlateNumberByLike(args.AreadInfo.Parkinfo.VID, likeplate, out errorMsg);
                        if (platenumber == null)
                        {
                            likeplate   = args.Plateinfo.LicenseNum.Substring(0, args.Plateinfo.LicenseNum.Length - 2);
                            platenumber = EmployeePlateServices.GetGrantPlateNumberByLike(args.AreadInfo.Parkinfo.VID, likeplate, out errorMsg);
                        }
                        if (platenumber != null)
                        {
                            args.Plateinfo.LicenseNum = platenumber.PlateNo;
                        }
                    }
                }
                else
                {
                    platenumber = EmployeePlateServices.GetEmployeePlateNumberByPlateNumber(args.AreadInfo.Parkinfo.VID, args.Plateinfo.LicenseNum, out errorMsg);
                }
                if (platenumber != null)
                {
                    //根据车牌获取车辆用户信息
                    var pkcard = ParkGrantServices.GetParkGrantByPlateNumberID(args.AreadInfo.PKID, platenumber.PlateID, out errorMsg);

                    if (pkcard.Count() > 0)
                    {
                        //判断是否有区域 通道限制
                        var cardinfo = pkcard.First();
                        args.LastCardInfo = cardinfo;
                        if (cardinfo.AreaIDS.IsEmpty())//没有限制
                        {
                            if ((cardinfo.GateID.IsEmpty()) ||
                                cardinfo.GateID.Contains(args.GateInfo.GateID))     //区域包含 且通道未控制授权 或 通道已经授权
                            {
                                args.CardInfo = cardinfo;
                                args.CardInfo.OwnerPlateNumber = platenumber;
                                var usercard = BaseCardServices.GetBaseCard(args.CardInfo.CardID, out errorMsg);
                                if (usercard != null)
                                {
                                    args.CardInfo.Usercard = usercard;
                                }
                                else
                                {
                                    args.CardInfo = null;
                                }
                            }
                        }
                        else
                        {
                            if (cardinfo.AreaIDS.Contains(args.AreadInfo.AreaID) && (cardinfo.GateID.IsEmpty()) ||
                                cardinfo.GateID.Contains(args.GateInfo.GateID))   //区域包含 且通道未控制授权 或 通道已经授权
                            {
                                args.CardInfo = cardinfo;
                                args.CardInfo.OwnerPlateNumber = platenumber;
                                var usercard = BaseCardServices.GetBaseCard(args.CardInfo.CardID, out errorMsg);
                                if (usercard != null)
                                {
                                    args.CardInfo.Usercard = usercard;
                                }
                                else
                                {
                                    args.CardInfo = null;
                                }
                            }
                        }
                        if (args.CardInfo == null)
                        {
                            rst.ValidMsg = "非本区域月卡";
                        }
                    }
                }

                if (args.CardInfo != null)
                {
                    var pkcardtype = ParkCarTypeServices.QueryParkCarTypeByRecordId(args.CardInfo.CarTypeID);
                    if (pkcardtype != null)
                    {
                        args.CarTypeInfo = pkcardtype;
                    }
                    else
                    {
                        //获取对应的卡类型
                        var pkcardtypes = ParkCarTypeServices.QueryCardTypesByBaseCardType(args.AreadInfo.PKID, BaseCarType.TempCar);
                        if (pkcardtypes != null && pkcardtypes.Count() > 0)
                        {
                            args.CarTypeInfo = pkcardtypes.First();
                        }
                    }

                    if (!args.CardInfo.CarModelID.IsEmpty())
                    {
                        var model = ParkCarModelServices.QueryByRecordId(args.CardInfo.CarModelID);
                        args.CarModel = model;
                    }
                    if (args.CarModel == null)
                    {
                        //获取卡对应的车类型
                        var listcarmodel = ParkCarModelServices.GetDefaultCarModel(args.AreadInfo.PKID, out errorMsg);
                        if (listcarmodel != null)
                        {
                            args.CarModel = listcarmodel;
                        }
                    }
                }
                else
                {
                    //默认为临时车
                    var pkcardtypes = ParkCarTypeServices.QueryCardTypesByBaseCardType(args.AreadInfo.PKID, BaseCarType.TempCar);
                    if (pkcardtypes != null && pkcardtypes.Count() > 0)
                    {
                        args.CarTypeInfo = pkcardtypes.First();
                    }

                    ////获取默认车类型
                    //var listcarmodel = ParkCarModelServices.GetDefaultCarModel(args.AreadInfo.PKID, out errorMsg);
                    //if (listcarmodel != null)
                    //{
                    //    args.CarModel = listcarmodel;
                    //}

                    if (args.Plateinfo.PlateColor != null && args.Plateinfo.PlateColor.Contains("黄"))
                    {
                        var list = ParkCarModelServices.QueryByParkingId(args.AreadInfo.PKID);
                        foreach (var item in list)
                        {
                            if (item.PlateColor != null && item.PlateColor.Contains("黄"))
                            {
                                args.CarModel = item;
                                break;
                            }
                        }
                    }
                    if (args.CarModel == null)
                    {
                        //获取卡对应的车类型
                        var carmode = ParkCarModelServices.GetDefaultCarModel(args.AreadInfo.PKID, out errorMsg);
                        if (carmode != null)
                        {
                            args.CarModel = carmode;
                        }
                    }
                }
            }
            else
            {
                //默认为临时车
                var pkcardtypes = ParkCarTypeServices.QueryCardTypesByBaseCardType(args.AreadInfo.PKID, BaseCarType.TempCar);
                if (pkcardtypes != null && pkcardtypes.Count() > 0)
                {
                    args.CarTypeInfo = pkcardtypes.First();
                }
                if (args.Plateinfo.PlateColor != null && args.Plateinfo.PlateColor.Contains("黄"))
                {
                    var list = ParkCarModelServices.QueryByParkingId(args.AreadInfo.PKID);
                    foreach (var item in list)
                    {
                        if (item.PlateColor != null && item.PlateColor.Contains("黄"))
                        {
                            args.CarModel = item;
                            break;
                        }
                    }
                }
                if (args.CarModel == null)
                {
                    //获取卡对应的车类型
                    var carmode = ParkCarModelServices.GetDefaultCarModel(args.AreadInfo.PKID, out errorMsg);
                    if (carmode != null)
                    {
                        args.CarModel = carmode;
                    }
                }
            }
            if (args.AreadInfo.IsNestArea)//小车场 先查询对应的通行记录
            {
                ParkIORecord ioRecord = ParkIORecordServices.GetNoExitIORecordByPlateNumber(args.AreadInfo.PKID, args.Plateinfo.LicenseNum, out errorMsg);

                args.NestAreaIORecord = ioRecord;
            }
            if (args.CarTypeInfo == null)
            {
                rst.ResCode = ResultCode.LocalError;
                throw new Exception("参数错误:默认卡片类型为空");
            }
            if (args.CarTypeInfo == null)
            {
                rst.ResCode = ResultCode.LocalError;
                throw new Exception("参数错误:默认车辆类型为空");
            }

            cartype = args.CarTypeInfo.BaseTypeID;
            #region 生产对应的验证规则
            //此处可根据配置文件利用反射生成配置的验证规则
            RuleHandler ruleHandler = null;
            switch (cartype)
            {
            case BaseCarType.MonthlyRent:
                #region 月卡
                if (args.GateInfo.IoState == IoState.GoIn)    //进
                {
                    ruleHandler = RuleHandlerFactory.Instance.CreateMonthMainInRuleHandler();
                }
                else    //出
                {
                    ruleHandler = RuleHandlerFactory.Instance.CreateMonthMainOutRuleHandler();
                }
                #endregion
                break;

            case BaseCarType.TempCar:
                #region 临时卡
                if (args.GateInfo.IoState == IoState.GoIn)    //进
                {
                    ruleHandler = RuleHandlerFactory.Instance.CreateTempMainInRuleHandler();
                }
                else    //出
                {
                    ruleHandler = RuleHandlerFactory.Instance.CreateTempMainOutRuleHandler();
                }
                #endregion
                break;

            case BaseCarType.StoredValueCar:
                #region 储值卡
                if (args.GateInfo.IoState == IoState.GoIn)    //进
                {
                    ruleHandler = RuleHandlerFactory.Instance.CreateValueMainInRuleHandler();
                }
                else    //出
                {
                    ruleHandler = RuleHandlerFactory.Instance.CreateValueMainOutRuleHandler();
                }
                #endregion
                break;

            case BaseCarType.VIPCar:
                #region VIP卡
                if (args.GateInfo.IoState == IoState.GoIn)    //进
                {
                    ruleHandler = RuleHandlerFactory.Instance.CreateVIPMainInRuleHandler();
                }
                else    //出
                {
                    ruleHandler = RuleHandlerFactory.Instance.CreateVIPMainOutRuleHandler();
                }
                #endregion
                break;
            }
            #endregion
            return(ruleHandler);
        }
Пример #2
0
        protected override void ProcessRule(InputAgs args, ResultAgs rst)
        {
            rst.InOutBaseCardType = args.CarTypeInfo.BaseTypeID;

            if (args.CardInfo == null)
            {
                return;
            }
            if (args.CardInfo.State == ParkGrantState.Pause || args.CardInfo.State == ParkGrantState.Stop)
            {
                //rst.ResCode = ResultCode.CarLocked;
                //rst.ValidMsg = args.CardInfo.State == 1 ? "月卡 停用" : "月卡 暂停";
                rst.ResCode = args.CardInfo.State == ParkGrantState.Pause ? ResultCode.MonthCarStop : ResultCode.MonthCarPause;
                return;
            }
            string error;

            if (args.GateInfo.IoState == IoState.GoIn)
            {
                if (args.CardInfo.EndDate < args.Plateinfo.TriggerTime || args.CardInfo.EndDate == null)
                {
                    if (args.CarTypeInfo.OverdueToTemp == OverdueToTemp.ProhibitedInAndOut)//不允许入场
                    {
                        rst.ResCode = ResultCode.UserExpired;
                        return;
                    }
                    else//临停转固定
                    {
                        rst.InOutBaseCardType = BaseCarType.TempCar;
                        args.CarTypeInfo      = ParkCarTypeServices.QueryCardTypesByBaseCardType(args.AreadInfo.PKID, BaseCarType.TempCar).First();// ShareData.CarTypes.Find(o => o.BaseTypeID == BaseCarType.TempCar);
                        args.CardInfo         = null;
                        rst.ResCode           = ResultCode.OverdueToTemp;
                        rst.ValidMsg          = "月卡车不在有效期内";
                        rst.EnterType         = 1;
                        return;
                    }
                }
            }
            if (args.CardInfo.PKLot.IsEmpty() || args.GateInfo.IoState != IoState.GoIn)
            {
                return;
            }
            if (args.CardInfo.PKLotNum <= 0)//没有车位忽略  如果有车位的话 根据车位查找在场车辆
            {
                return;
            }
            if (args.AreadInfo.IsNestArea)
            {
                if (args.NestAreaIORecord == null)
                {
                    return;
                }
                var interimes = ParkInterimServices.GetInterimByIOrecord(args.NestAreaIORecord.RecordID, out error);
                if (interimes != null && interimes.Find(i => i.EndInterimTime == DateTime.MinValue) != null)//没有正在转临停 说明是月卡
                {
                    rst.InOutBaseCardType = BaseCarType.TempCar;
                    args.CarTypeInfo      = ParkCarTypeServices.QueryCardTypesByBaseCardType(args.AreadInfo.PKID, BaseCarType.TempCar).First();// ShareData.CarTypes.Find(o => o.BaseTypeID == BaseCarType.TempCar);
                    args.CardInfo         = null;
                    rst.ResCode           = ResultCode.OverdueToTemp;
                    rst.IsOverdueToTemp   = true;
                    rst.ValidMsg          = "车位占用转临时车";
                    rst.EnterType         = 2;
                }
            }
            else
            {
                int occupyCount = 0;//如果有多个车位 且多个车位都被占用时 根据配置是否能进或转临停
                var usercards   = ParkGrantServices.GetCardgrantsByLot(args.AreadInfo.PKID, args.CardInfo.PKLot, out error);

                foreach (var card in usercards)
                {
                    var ownerPlateNumber = EmployeePlateServices.GetPlateNumber(args.AreadInfo.Parkinfo.VID, card.PlateID, out error);
                    if (ownerPlateNumber == null)
                    {
                        continue;
                    }
                    if (ownerPlateNumber.PlateNo == args.Plateinfo.LicenseNum)
                    {
                        continue;
                    }
                    var iorecord = ParkIORecordServices.GetNoExitIORecordByPlateNumber(args.AreadInfo.PKID, ownerPlateNumber.PlateNo, out error);
                    if (iorecord == null)
                    {
                        continue;
                    }

                    var cardtype  = ParkCarTypeServices.QueryParkCarTypeByRecordId(iorecord.CarTypeID);
                    var interimes = ParkInterimServices.GetInterimByIOrecord(iorecord.RecordID, out error);
                    if (interimes == null || interimes.Find(i => i.EndInterimTime == DateTime.MinValue) == null)//没有正在转临停 说明是月卡
                    {
                        occupyCount++;
                        continue;
                    }
                }

                if (occupyCount >= args.CardInfo.PKLotNum)
                {
                    if (args.CarTypeInfo.LotOccupy == LotOccupy.ProhibitedInAndOut)//不允许入场
                    {
                        rst.ResCode = ResultCode.NoPermissionsInOut;
                    }
                    else//固定转临时停车
                    {
                        rst.InOutBaseCardType = BaseCarType.TempCar;
                        args.CarTypeInfo      = ParkCarTypeServices.QueryCardTypesByBaseCardType(args.AreadInfo.PKID, BaseCarType.TempCar).First();// ShareData.CarTypes.Find(o => o.BaseTypeID == BaseCarType.TempCar);
                        args.CardInfo         = null;
                        rst.ResCode           = ResultCode.OverdueToTemp;
                        rst.IsOverdueToTemp   = true;
                        rst.ValidMsg          = "车位占用转临时车";
                        rst.EnterType         = 2;
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// 白天黑夜最大收费参数设置
        /// </summary>
        //public static DayAndNightMaxMoneyPara DayAndNightMaxMoneyPara { get; set; }

        //private static XDocument document;
        //public static XDocument _XDocument
        //{
        //    get
        //    {
        //        return document;
        //    }
        //    private set
        //    {
        //        document = value;
        //    }
        //}

        //static RateProcesser()
        //{
        //    try
        //    {
        //        string xmlName = "TimeShareFeeRule.xml";
        //        var dirName = Path.Combine(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase, xmlName);

        //        XDocument xdoc = XDocument.Load(dirName);
        //        foreach (var item in xdoc.Root.Elements())
        //        {
        //            if (item.Attribute("IsEnable").Value.ToBoolean())
        //            {
        //                _XDocument = xdoc;
        //            }
        //            break;
        //        }
        //    }
        //    catch(Exception ex)
        //    {
        //        LogerHelper.Loger.Error(ex);
        //    }
        //}

        //public static void  LoadCustomFeerule(string ruletext)
        //{

        //    try
        //    {
        //        using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(ruletext)))
        //        {
        //            XDocument xdoc = XDocument.Load(stream);
        //            foreach (var item in xdoc.Root.Elements())
        //            {
        //                if (item.Attribute("IsEnable").Value.ToBoolean())
        //                {
        //                    _XDocument = xdoc;
        //                }
        //                break;
        //            }

        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        LogerHelper.Loger.Error(ex);
        //    }
        //}
        /// <summary>
        /// 根据入场记录算费
        /// </summary>
        /// <param name="ioRecord"></param>
        /// <returns></returns>
        public static ResultAgs GetRateResult(ParkIORecord ioRecord, ParkGate outGate, DateTime exitTime, string carModeid = "")
        {
            if (outGate == null)
            {
                return(null);
            }
            string   errorMsg = "";
            InputAgs args     = new InputAgs();

            args.AreadInfo = ParkAreaServices.QueryByRecordId(ioRecord.AreaID);
            if (args.AreadInfo.IsNestArea && args.AreadInfo.Parent == null)//内部车场时 且上级区域为空时
            {
                args.AreadInfo.Parent = ParkAreaServices.QueryByRecordId(args.AreadInfo.MasterID);
                if (args.AreadInfo.Parent == null)//还是找不到上级区域时
                {
                    LogerHelper.Loger.Error(string.Format("找不到车场[{0}]的上级车场,上级车场ID为[{1}].", args.AreadInfo.AreaName, args.AreadInfo.MasterID));
                    args.AreadInfo.MasterID = "";//找不到就至为空
                }
            }
            args.AreadInfo.Parkinfo = ParkingServices.QueryParkingByParkingID(args.AreadInfo.PKID);
            if (args.AreadInfo.Parkinfo == null)//还是找不到上级区域时
            {
                LogerHelper.Loger.Error(string.Format("找不到区域[{0}]对应的车场.", args.AreadInfo.AreaName));
                return(null);
            }
            args.Plateinfo             = new PlateInfo();
            args.Plateinfo.LicenseNum  = ioRecord.PlateNumber;
            args.Plateinfo.TriggerTime = exitTime;
            args.CarTypeInfo           = ParkCarTypeServices.QueryParkCarTypeByRecordId(ioRecord.CarTypeID);
            string        str         = errorMsg;
            EmployeePlate platenumber = EmployeePlateServices.GetEmployeePlateNumberByPlateNumber(args.AreadInfo.Parkinfo.VID, args.Plateinfo.LicenseNum, out errorMsg);

            if (platenumber != null)
            {
                //根据车牌获取车辆用户信息
                var pkcard = ParkGrantServices.GetParkGrantByPlateNumberID(args.AreadInfo.PKID, platenumber.PlateID, out errorMsg);
                if (pkcard.Count() > 0)
                {
                    //判断是否有区域 通道限制
                    var cardinfo = pkcard.First();
                    args.CardInfo = cardinfo;
                    args.CardInfo.OwnerPlateNumber = platenumber;
                    var usercard = BaseCardServices.GetBaseCard(args.CardInfo.CardID, out errorMsg);
                    if (usercard != null)
                    {
                        args.CardInfo.Usercard = usercard;
                    }
                    else
                    {
                        args.CardInfo = null;
                    }
                    if (!args.CardInfo.CarModelID.IsEmpty())
                    {
                        carModeid = args.CardInfo.CarModelID;
                    }
                }
            }

            if (args.CarTypeInfo == null)
            {
                return(null);
            }
            if (carModeid.IsEmpty())
            {
                args.CarModel = ParkCarModelServices.GetDefaultCarModel(args.AreadInfo.PKID, out errorMsg);
            }
            else
            {
                args.CarModel = ParkCarModelServices.QueryByRecordId(carModeid);
                if (args.CarModel == null)
                {
                    args.CarModel = ParkCarModelServices.GetDefaultCarModel(args.AreadInfo.PKID, out errorMsg);
                }
            }
            if (args.CarModel == null)
            {
                return(null);
            }
            //获取默认车类型
            args.GateInfo = outGate;
            args.IORecord = ioRecord;

            ResultAgs rst = new ResultAgs();

            rst.InOutBaseCardType = BaseCarType.TempCar;
            rst.ResCode           = ResultCode.OutOK;
            var rateContext = new RateTemplate();

            rateContext.Process(args, rst);
            return(rst);
        }