public IList<EGPSCurrentInfo> GetCurrentInfo(string[] arrVehicleCode)
        {
            DateTime now = DateTime.Now;
            IList<EGPSCurrentInfo> ltCurrentInfo = new List<EGPSCurrentInfo>();

            IGPSTrackManager trackManager = new GPSTrackManager();

            IList<EGPSCurrentInfo> resultList = trackManager.GetCurrentInfo(arrVehicleCode.Select(i=>new Guid(i)).ToArray());
            ltCurrentInfo = resultList;

            TimeSpan ts = DateTime.Now - now;

            Logger.Error(string.Format("Get CurrentInfo use{0}", ts.TotalMilliseconds.ToString()));

            return ltCurrentInfo;
        }
        //入口
        public void CheckUp()
        {
            if (!IsHaveSetted())
            {
                return;
            }

            foreach (var setting in _settings)
            {
                OfflineTimeoutAlertReportService reportService = new OfflineTimeoutAlertReportService();
                GPSTrackManager manager = new GPSTrackManager();
                var info = manager.GetCurrentInfo(setting.VehicleCode);
                if (info.ReportTime.AddMinutes(setting.DrivingDuration) < DateTime.Now)
                {
                    _alertReport = reportService.GetRecentReport(setting.VehicleCode);
                    if (_alertReport != null && _alertReport.AlertState == (int)EnumAlertState.Alerting)
                    {
                        continue;
                    }
                    _alertReport = (EOfflineTimeoutAlertReport)CreateAlertReport(EnumAlertState.Alerting, setting);
                    SaveAlertReport();
                    Alert(setting);
                }
                else {
                    _alertReport = reportService.GetRecentReport(setting.VehicleCode);
                    if (_alertReport == null) {
                        continue;
                    }
                    if (_alertReport.AlertState == (int)EnumAlertState.Resume)
                    {
                        continue;
                    }
                    UpdateAlertReport();
                }
            }
        }
        public IList<VRealTimeInfo> GetVehicleRealTimeInfo(string username, string password, string[] arrLicenceNumber)
        {

            Logger.Error(string.Format("{0},{1}", username, password));

            ////password = EncodeStr.EncodePassword(password);
            ////EUser user = null;
            ////try
            ////{
            ////    user = SSOProxy.LogonUser(username, password, PES.Guanaco.Entity.EnumLoginType.UserName, "127.0.0.1");

            ////    if (user == null || user.TenantList.Count == 0)
            ////    {
            ////        throw new Exception("User name or password error!");
            ////    }
            ////}
            ////catch (Exception ex)
            ////{
            ////    Logger.Error(ex);
            ////    throw new Exception("User name or password error!");
            ////}
            try
            {
                UserEntity user = GuanacoServiceFacade.Tenant.GetUser(username, EncodeStr.EncodePassword(password), EnumLoginType.UserName);
                if (user == null || GuanacoServiceFacade.Tenant.GetUserTenants(user.UserCode).Count == 0)
                {
                    throw new Exception("User name or password error!");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new Exception("User name or password error!");
            }

            IVehicleManager vm = new VehicleManager();

            IList<VRealTimeInfo> ltCurrentInfo = new List<VRealTimeInfo>();

            IList<LatLon> ltLatLon = new List<LatLon>();

            foreach (string licenceNumber in arrLicenceNumber)
            {
                Guid vehicleCode = vm.GetVehicleCodeByLicenceNumber(licenceNumber);

                IGPSTrackManager trackManager = new GPSTrackManager();

                EGPSCurrentInfo currentInfo;

                try
                {
                    currentInfo = trackManager.GetCurrentInfo(vehicleCode);

                    ltLatLon.Add(new LatLon(currentInfo.Latitude, currentInfo.Longitude));

                    VRealTimeInfo realtimeInfo = new VRealTimeInfo();

                    realtimeInfo.CurrentGPSInfo = currentInfo;

                    EBaseVehicle vehicle = new EVehicle();

                    vehicle.LicenceNumber = licenceNumber;

                    realtimeInfo.VehicleInfo = vehicle;

                    ltCurrentInfo.Add(realtimeInfo);
                }
                catch (GPSCurrentInfoNullException ex)
                {
                    Logger.Error(ex);
                    throw ex;
                }
            }

            IMapService mapService = new PES.MapService.MapSearchService.MapService();

            IList<LocationInfo> ltLocationInfo = mapService.InverseGeocoding(ltLatLon.ToArray());

            for (int i = 0; i < ltCurrentInfo.Count; i++)
            {
                ltCurrentInfo[i].LocationInfo = ltLocationInfo[i];
            }

            return ltCurrentInfo;
        }
        public string GetVehicleLocationInfo(string vehicleCode)
        {
            IGPSTrackManager trackManager = new GPSTrackManager();

            EGPSCurrentInfo currentInfo;

            try
            {
                currentInfo = trackManager.GetCurrentInfo(new Guid(vehicleCode));
            }
            catch (GPSCurrentInfoNullException ex)
            {
                Logger.Error(ex);
                throw ex;
            }

            IMapService ms = new PES.MapService.MapSearchService.MapService();

            string encode = ms.Encode(currentInfo.Latitude.ToString(), currentInfo.Longitude.ToString());

            LocationInfo locationInfo = ms.InverseGeocoding(currentInfo.Latitude.ToString(), currentInfo.Longitude.ToString());

            return string.Format("{0},{1}", encode, locationInfo.ToString());
        }
        public IList<VVehicleSearchResult> VehicleSearch(string maxEncodeLatLon, string minEncodeLatLon, string tenantCode, string userCode,
            string permissionCode,int rowIndex,int pageSize,ref int rowCount)
        {
            PES.MapService.MapSearchService.MapService mapService = new PES.MapService.MapSearchService.MapService();

            LatLon maxLatLon = mapService.Decode(maxEncodeLatLon);
            LatLon minLatLon = mapService.Decode(minEncodeLatLon);

            IVehicleManager vm = new VehicleManager();

            IList<EBaseVehicle> ltVehicle = vm.Get(tenantCode, userCode, permissionCode);

            Rectangle rec = new Rectangle(maxLatLon.Latitude, maxLatLon.Longitude, minLatLon.Latitude, minLatLon.Longitude);

            IGPSTrackManager trackManager = new GPSTrackManager();

            IList<EGPSCurrentInfo> ltCurrentInfo = trackManager.SearchVehicleInRectange(rec, ltVehicle.Select(s => s.Code).ToArray(), rowIndex, pageSize,ref rowCount);

            Dictionary<Guid, string> dcVehicle = ltVehicle.ToDictionary(new Func<EBaseVehicle, Guid>(c => c.Code),
                    new Func<EBaseVehicle, string>(c => c.LicenceNumber));

            IList<VVehicleSearchResult> ltResult = new List<VVehicleSearchResult>();

            if (ltCurrentInfo == null)
                return ltResult;
            foreach (EGPSCurrentInfo currentInfo in ltCurrentInfo)
            {
                string licenceNumber = dcVehicle[currentInfo.VehicleCode.Value];

                VVehicleSearchResult result = new VVehicleSearchResult(currentInfo.VehicleCode.Value, licenceNumber, currentInfo.GPSCode, currentInfo.ReportTime.ToString(),currentInfo.Latitude,currentInfo.Longitude);

                ltResult.Add(result);
            }
            SetEncodeLatLon(mapService, ltResult);

            return ltResult;
        }
        public IList<Guid> VehicleSearch(string maxEncodeLatLon,string minEncodeLatLon,string tenantCode)
        {
            PES.MapService.MapSearchService.MapService mapService = new PES.MapService.MapSearchService.MapService();

            LatLon maxLatLon = mapService.Decode(maxEncodeLatLon);
            LatLon minLatLon = mapService.Decode(minEncodeLatLon);

            IGPSInstallationManager installManager = new GPSInstallationManager();
            
            IList<string> ltGPSCode = installManager.GetGPSCode(tenantCode);

            IGPSTrackManager trackManager = new GPSTrackManager();

            Rectangle rec = new Rectangle(maxLatLon.Latitude, maxLatLon.Longitude, minLatLon.Latitude, minLatLon.Longitude);

            IList<EGPSCurrentInfo> ltCurrentInfo = trackManager.SearchVehicleInRectange(rec, ltGPSCode.ToArray<string>());


            if (ltCurrentInfo == null || ltCurrentInfo.Count == 0)
                return null;

            return ltCurrentInfo.Select(s => s.VehicleCode.Value).ToList();
        }
        private EBaseAlertReport CreateAlertReport(EnumAlertState state, EOfflineTimeoutAlertSetting alertSetting)
        {
            EGPSCurrentInfo _gpsCurrentInfo = new GPSTrackManager().GetCurrentInfo(alertSetting.VehicleCode);
            EOfflineTimeoutAlertReport newReport = new EOfflineTimeoutAlertReport();
            newReport.EnumAlarmGrade = EnumAlarmGrade.Prompt;
            newReport.ACCState = _gpsCurrentInfo.ACCState;
            newReport.Speed = _gpsCurrentInfo.Speed;
            newReport.VStarkMileage = _gpsCurrentInfo.StarkMileage;
            newReport.EnumSMSInfoType = EnumSMSInfoType.OfflineTimeout;
            newReport.GPSCode = _gpsCurrentInfo.GPSCode;
            newReport.GPSReportTime = _gpsCurrentInfo.ReportTime;
            newReport.Latitude = _gpsCurrentInfo.Latitude;
            newReport.Longitude = _gpsCurrentInfo.Longitude;
            newReport.MobileReceiveBeginTime = alertSetting.MobileReceiveBeginTime;
            newReport.MobileReceiveEndTime = alertSetting.MobileReceiveEndTime;
            newReport.ReceiveMobileList = alertSetting.ReceiveMobileList;
            newReport.ReceiveUserList = alertSetting.ReceiveUserList;
            newReport.TenantCode = alertSetting.TenantCode;
            newReport.UserReceiveBeginTime = alertSetting.UserReceiveBeginTime;
            newReport.UserReceiveEndTime = alertSetting.UserReceiveEndTime;
            newReport.VehicleCode = alertSetting.VehicleCode;
            newReport.VehiclePosition = this.GetPlaceName(_gpsCurrentInfo.Latitude, _gpsCurrentInfo.Longitude);
            if (_MOVOVehicleDict.ContainsKey(alertSetting.VehicleCode))
            {
                newReport.LicensePlate = _MOVOVehicleDict[alertSetting.VehicleCode];
            }

            newReport.EnumAlertState = state;

            newReport.DownSendOrderCode = DownSendCodeHelper.GPS.LogisticVehicle.FatigueDrive;
            newReport.DurationDrivingTime = alertSetting.DrivingDuration;
            newReport.RestTime = alertSetting.RestTime;
            newReport.AlertState = (int)state;
            return newReport;
        }