public DBProcessResult  DeleteCar(string sVechileCode)
 {
     DBProcessResult result = new DBProcessResult() { IsSuccess = false, Message = "删除失败!" };
     VehicleDAL vDal = new VehicleDAL();
     bool isSucess = vDal.DeleteCar(sVechileCode);
     if (isSucess)
     {
         result.IsSuccess = true;
         result.Message = "删除成功!";
        
     }
     return result;
 }
Exemple #2
0
        ///// <summary>
        ///// 查询一段时间内的里程明细(里程报表,里程日报表,里程月报表)
        ///// </summary>
        ///// <param name="para"></param>
        ///// <returns></returns>
        //public List<ReportMileageDetailViewModel> GetMileageDetail(ReportMileageDetailWCFPara para)
        //{
        //    Guid guid = Guid.NewGuid();
        //    Logger.Info("In GetMileageDetail:" + guid.ToString());

        //    List<ReportMileageDetailViewModel> ReportMileageDetailViewModelList = new List<ReportMileageDetailViewModel>();
        //    try
        //    {
        //        //取出车辆列表所用到的历史数据配置信息列表
        //        List<EHistoryDataStoreConfig> configList = tableConfigSev.GetVehicleStoreTableConfig(para.VehicleCode.ToList());

        //        //对历史数据配置信息中的StoreTable字段进行GroupBy操作,去除重复
        //        var q = from f in configList group f by f.StoreTable into g select new EHistoryDataStoreConfig { StoreTable = g.Key };

        //        List<EHistoryDataStoreConfig> tableList = q.ToList();

        //        //获得VehicleCode和LicenceNuber之间的关系
        //        Dictionary<Guid, string> dicCodeAndLicence = new Dictionary<Guid, string>();
        //        for (int i = 0, i_Count = para.VehicleCode.Count(); i < i_Count; i++)
        //        {
        //            dicCodeAndLicence.Add(para.VehicleCode[i], para.LicenceNumber[i]);
        //        }

        //        foreach (EHistoryDataStoreConfig config in tableList)
        //        {
        //            if (config.StoreTable == null)
        //                continue;
        //            //将同一个历史表的车辆里程数据一次性查询出来
        //            var query = from f in configList
        //                        where f.StoreTable == config.StoreTable
        //                        select f.VehicleCode;
        //            List<Guid> vehicleList = query.ToList<Guid>();

        //            List<EMileage> EMileageList = GetReportTimeSpanListMileage(config, vehicleList, para.TimeSpan, para.tenantCode, para.getPostition);

        //            foreach (Guid vehicleCode in vehicleList)
        //            {
        //                List<EMileage> tmpList = EMileageList.Where(o => o.VehicleCode == vehicleCode).ToList();
        //                ReportMileageDetailViewModel objViewModel = new ReportMileageDetailViewModel();
        //                objViewModel.VehicleCode = vehicleCode;
        //                objViewModel.LicenceNumber = dicCodeAndLicence[vehicleCode];
        //                if (tmpList == null || tmpList.Count == 0)
        //                {
        //                    //objViewModel.MileageDetails = new List<TimeSpanMileage>();
        //                }
        //                else
        //                {
        //                    List<TimeSpanMileage> DetailList = new List<TimeSpanMileage>();
        //                    foreach (EMileage objEMileage in tmpList)
        //                    {
        //                        TimeSpanMileage objTimeSpanMileage = new TimeSpanMileage()
        //                        {
        //                            QueryBeginTime = DateTime.MaxValue,
        //                            QueryEndTime = DateTime.MaxValue,
        //                            BeginTime = DateTime.MaxValue,
        //                            EndTime = DateTime.MaxValue,
        //                            Mileage = 0,
        //                            BeginLocation = string.Empty,
        //                            EndLocation = string.Empty,
        //                            BeginMileage = 0,
        //                            EndMileage = 0
        //                        };
        //                        objTimeSpanMileage.BeginTime = getDataTime(objEMileage.BeginTime);
        //                        objTimeSpanMileage.QueryBeginTime = getDataTime(objEMileage.QueryBeginTime);
        //                        objTimeSpanMileage.EndTime = getDataTime(objEMileage.EndTime);
        //                        objTimeSpanMileage.QueryEndTime = getDataTime(objEMileage.QueryEndTime);
        //                        objTimeSpanMileage.BeginMileage = objEMileage.BeginMileage;
        //                        objTimeSpanMileage.EndMileage = objEMileage.EndMileage;
        //                        if (para.getPostition)
        //                        {
        //                            objTimeSpanMileage.BeginLocation = objEMileage.BeginLocation;
        //                            objTimeSpanMileage.EndLocation = objEMileage.EndLocation;
        //                        }
        //                        objTimeSpanMileage.Mileage = objEMileage.TotalMileage;
        //                        DetailList.Add(objTimeSpanMileage);
        //                    }
        //                    //objViewModel.MileageDetails = DetailList;
        //                }
        //                ReportMileageDetailViewModelList.Add(objViewModel);
        //            }
        //        }
        //    }
        //    catch (Exception ex) 
        //    {
        //        Logger.Error("Error GetMileageDetail(" + guid.ToString() + "):" + ex.Message, ex);
        //    }

        //    Logger.Info("Out GetMileageDetail:" + guid.ToString());

        //    return ReportMileageDetailViewModelList;
        //}

        /// <summary>
        /// 查询一段时间内的里程明细(里程报表,里程日报表,里程月报表)
        /// </summary>
        /// <param name="para"></param>
        /// <returns></returns>
        public List<ReportMileageDetailViewModel> GetMileageDetail(ReportMileageDetailWCFPara para)
        {
            Guid guid = Guid.NewGuid();
            Logger.Info("In GetMileageDetail:" + guid.ToString());

            List<ReportMileageDetailViewModel> ReportMileageDetailViewModelList = new List<ReportMileageDetailViewModel>();
            try
            {
                /*
                //取出车辆列表所用到的历史数据配置信息列表(select * from gps_historydatastoreconfig where VehicleCode in {0})
                List<EHistoryDataStoreConfig> configList = tableConfigSev.GetVehicleStoreTableConfig(para.VehicleCode.ToList());

                //对历史数据配置信息中的StoreTable字段进行GroupBy操作,去除重复
                var q = from f in configList group f by f.StoreTable into g select new EHistoryDataStoreConfig { StoreTable = g.Key };
                List<EHistoryDataStoreConfig> tableList = q.ToList();
                  */
                //代码优化
                VehicleDAL veDal = new VehicleDAL();
                List<EHistoryDataStoreConfig> tableList = veDal.GetVechileInfo(para.VehicleCode.ToList());
                //获得VehicleCode和LicenceNuber之间的关系
                Dictionary<Guid, string> dicCodeAndLicence = new Dictionary<Guid, string>();
                for (int i = 0, i_Count = para.VehicleCode.Count(); i < i_Count; i++)
                {
                    dicCodeAndLicence.Add(para.VehicleCode[i], para.LicenceNumber[i]);
                }

                foreach (EHistoryDataStoreConfig config in tableList)
                {
                    if (config.StoreTable == null)
                        continue;
                    //将同一个历史表的车辆里程数据一次性查询出来
                    /*var query = from f in configList
                                where f.StoreTable == config.StoreTable
                                select f.VehicleCode;
                    List<Guid> vehicleList = query.ToList<Guid>();
                    */
                    List<Guid> vehicleList = tableList.Where(b => b.StoreTable == config.StoreTable).Select(c => c.VehicleCode).ToList();
                    List<EMileage> EMileageList = GetReportTimeSpanListMileage(config, vehicleList, para.TimeSpan, para.tenantCode, para.getPostition);

                    foreach (EMileage eMileage in EMileageList)
                    {
                        ReportMileageDetailViewModel model = new ReportMileageDetailViewModel();
                        model.VehicleCode = eMileage.VehicleCode;
                        model.LicenceNumber = dicCodeAndLicence[eMileage.VehicleCode];
                        model.BeginLocation = eMileage.BeginLocation;
                        model.EndLocation = eMileage.EndLocation;
                        model.BeginTime = eMileage.BeginTime;
                        model.EndTime = eMileage.EndTime;
                        model.DayMileage = eMileage.TotalMileage;
                        ReportMileageDetailViewModelList.Add(model);
                    }
                    ReportMileageDetailViewModelList = ReportMileageDetailViewModelList.OrderBy(p => p.LicenceNumber).ToList();
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Error GetMileageDetail(" + guid.ToString() + "):" + ex.Message, ex);
            }

            Logger.Info("Out GetMileageDetail:" + guid.ToString());

            return ReportMileageDetailViewModelList;
        }
Exemple #3
0
        /// <summary>
        /// 采用ado 查询一段时间内的里程
        /// </summary>
        /// <param name="para"></param>
        /// <returns></returns>
        public List<ReportMileageViewModel> GetNewMileage(ReportMileageWCFPara para)
        {
            List<ReportMileageViewModel> ReportMileageViewModelList = new List<ReportMileageViewModel>();
            try
            {
                if (para.VehicleCode == null || para.VehicleCode.Count() == 0)
                    return ReportMileageViewModelList;

                VehicleDAL vdal = new VehicleDAL();
                List<EHistoryDataStoreConfig> tableList = vdal.GetVechileInfo(para.VehicleCode.ToList());

                //获得VehicleCode和LicenceNuber之间的关系
                Dictionary<Guid, string> dicCodeAndLicence = new Dictionary<Guid, string>();
                for (int i = 0, i_Count = para.VehicleCode.Count(); i < i_Count; i++)
                {
                    dicCodeAndLicence.Add(para.VehicleCode[i], para.LicenceNumber[i]);
                }
                
                foreach (EHistoryDataStoreConfig config in tableList)
                {
                    if (config.StoreTable == null)
                        continue;

                    List<Guid> vehicleList = tableList.Where(b=>b.StoreTable==config.StoreTable).Select(c => c.VehicleCode).ToList();
                    List<EMileage> EMileageList = GetReportTimeSpanMileage(config, vehicleList, para.BeginTime, para.EndTime, false);

                    foreach (EMileage objEMileage in EMileageList)
                    {
                        ReportMileageViewModel objModel = new ReportMileageViewModel();
                        objModel.VehicleCode = objEMileage.VehicleCode;
                        objModel.LicenceNumber = dicCodeAndLicence[objModel.VehicleCode];
                        objModel.Mileage = objEMileage.TotalMileage;
                        ReportMileageViewModelList.Add(objModel);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("GetMileage" + ex.Message, ex);
            }
            return ReportMileageViewModelList;
        }
Exemple #4
0
        /// <summary>
        /// 里程汇总报表
        /// </summary>
        /// <param name="para"></param>
        /// <returns></returns>
        //public List<ReportMainViewModel> GetReportMainViewModel(ReportMainWCFPara para)
        //{
        //    System.Diagnostics.Stopwatch sh = new System.Diagnostics.Stopwatch();
        //    sh.Start();

        //    Guid guid = Guid.NewGuid();
        //    Logger.Info("In GetReportMainViewModel:" + guid.ToString());

        //    List<ReportMainViewModel> ltModel = new List<ReportMainViewModel>();
        //    try
        //    {
        //        //今日里程
        //        DateTime BeginTime1 = new DateTime(para.QueryTime.Year, para.QueryTime.Month, para.QueryTime.Day);
        //        DateTime EndTime1 = para.QueryTime;
        //        //昨日里程
        //        DateTime BeginTime2 = BeginTime1.AddDays(-1);
        //        DateTime EndTime2 = BeginTime1.AddMilliseconds(-1);
        //        //近7天里程
        //        DateTime BeginTime3 = para.QueryTime.AddDays(-7);
        //        DateTime EndTime3 = para.QueryTime;
        //        //近30天里程
        //        DateTime BeginTime4 = para.QueryTime.AddDays(-30);
        //        DateTime EndTime4 = para.QueryTime;

        //        //这里改为查询当前绑定了GPS的车辆,如果某车辆当前未绑定GPS,之前有绑定,也有里程数据,仍然不查询
        //        //IList<EBaseVehicle> ltVehicle = objVehicleService.GetUsingVehilceList(para.tenantCode);
        //        IList<Guid> ltVehicle = para.VehicleCode;
        //        IList<string> ltLicenceNumber = para.LicenceNumber;
        //        if (ltVehicle != null)
        //        {
        //            for (int i = 0, i_Count = ltVehicle.Count; i < i_Count; i++)
        //            {
        //                EMileage Model1 = GetReportTimeSpanMileage(ltVehicle[i], BeginTime1, EndTime1, false);
        //                EMileage Model2 = GetReportTimeSpanMileage(ltVehicle[i], BeginTime2, EndTime2, false);
        //                EMileage Model3 = GetReportTimeSpanMileage(ltVehicle[i], BeginTime3, EndTime3, false);
        //                EMileage Model4 = GetReportTimeSpanMileage(ltVehicle[i], BeginTime4, EndTime4, false);
        //                ReportMainViewModel viewModel = new ReportMainViewModel();
        //                viewModel.VehicleCode = ltVehicle[i];
        //                Guid objvehicle = ltVehicle.FirstOrDefault(o => o == viewModel.VehicleCode);
        //                viewModel.LicenceNumber = objvehicle == null ? null : ltLicenceNumber[i];
        //                viewModel.MileageOfTody = Model1.TotalMileage;
        //                viewModel.MileageOfYestoday = Model2.TotalMileage;
        //                viewModel.MileageOfLast7Day = Model3.TotalMileage;
        //                viewModel.MileageOfLast30Day = Model4.TotalMileage;
        //                ltModel.Add(viewModel);
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        Logger.Error("Error GetReportMainViewModel(" + guid.ToString() + "):" + ex.Message, ex);
        //    }

        //    Logger.Info("Out GetReportMainViewModel:" + guid.ToString());
        //    sh.Stop();
        //    Logger.Info("时间:" + sh.ElapsedMilliseconds);

        //    return ltModel;
        //}

        public List<ReportMainViewModel> GetReportMainViewModel(ReportMainWCFPara para)
        {
            //System.Diagnostics.Stopwatch sh = new System.Diagnostics.Stopwatch();
            //sh.Start();

            //Guid guid = Guid.NewGuid();
            //Logger.Info("In GetReportMainViewModel:" + guid.ToString());

            //需要返回的实体
            List<ReportMainViewModel> ltModel = new List<ReportMainViewModel>();

            try
            {
                ////今日里程
                //DateTime BeginTime1 = new DateTime(para.QueryTime.Year, para.QueryTime.Month, para.QueryTime.Day);
                //DateTime EndTime1 = para.QueryTime;
                ////昨日里程
                //DateTime BeginTime2 = BeginTime1.AddDays(-1);
                //DateTime EndTime2 = BeginTime1.AddMilliseconds(-1);
                ////近7天里程
                //DateTime BeginTime3 = para.QueryTime.AddDays(-7);
                //DateTime EndTime3 = para.QueryTime;
                ////近30天里程
                //DateTime BeginTime4 = para.QueryTime.AddDays(-29);
                //DateTime EndTime4 = para.QueryTime;

                //这里改为查询当前绑定了GPS的车辆,如果某车辆当前未绑定GPS,之前有绑定,也有里程数据,仍然不查询
                //IList<EBaseVehicle> ltVehicle = objVehicleService.GetUsingVehilceList(para.tenantCode);
                List<Guid> ltVehicle = para.VehicleCode.ToList();
                List<string> ltLicenceNumber = para.LicenceNumber.ToList();

                if (ltVehicle != null)
                {
                    for (int i = 0, i_Count = ltVehicle.Count; i < i_Count; i++)
                    {
                        ReportMainViewModel viewModel = new ReportMainViewModel();
                        viewModel.VehicleCode = ltVehicle[i];
                        viewModel.LicenceNumber = ltLicenceNumber[i];
                        ltModel.Add(viewModel);
                    }
                    /*
                     *
                    //取出车辆列表所用到的历史数据配置信息列表
                     List<EHistoryDataStoreConfig> configList = tableConfigSev.GetVehicleStoreTableConfig(ltVehicle);

                    //对历史数据配置信息中的StoreTable字段进行GroupBy操作,去除重复
                     var q = from f in configList group f by f.StoreTable into g select new EHistoryDataStoreConfig { StoreTable = g.Key };
                     List<EHistoryDataStoreConfig> tableList = q.ToList();
                    */

                    //代码优化后
                    VehicleDAL veDal = new VehicleDAL();
                    List<EHistoryDataStoreConfig> tableList = veDal.GetVechileInfo(ltVehicle);
                    //实例化存放车辆当天、昨天、上周、上月里程数据实体列表
                    //List<EMileage> Model1 = new List<EMileage>();
                    //List<EMileage> Model2 = new List<EMileage>();
                    //List<EMileage> Model3 = new List<EMileage>();
                    //List<EMileage> Model4 = new List<EMileage>();
                    List<EMileage> Model = new List<EMileage>();
                    
                    foreach (EHistoryDataStoreConfig config in tableList)
                    {
                        if (config.StoreTable == null)
                            continue;
                        /*
                        //将同一个历史表的车辆里程数据一次性查询出来
                        //var query = from f in configList
                        //            where f.StoreTable == config.StoreTable
                        //            select f.VehicleCode;
                        //List<Guid> vehicleList = query.ToList<Guid>();
                        */
                        List<Guid> vehicleList = tableList.Where(b=>b.StoreTable==config.StoreTable).Select(c => c.VehicleCode).ToList();
                        //List<Guid> vehicleList = ltVehicle.Where(f => f == config.VehicleCode).ToList();

                        //分别获取指定车辆列表所有里程类型的里程数据
                        //Model1.AddRange(GetReportTimeSpanMileage(config, vehicleList, BeginTime1, EndTime1, false));
                        //Model2.AddRange(GetReportTimeSpanMileage(config, vehicleList, BeginTime2, EndTime2, false));
                        //Model3.AddRange(GetReportTimeSpanMileage(config, vehicleList, BeginTime3, EndTime3, false));
                        //Model4.AddRange(GetReportTimeSpanMileage(config, vehicleList, BeginTime4, EndTime4, false));

                        Model.AddRange(GetReportTimeSpanMileage(config, vehicleList, para.beginTime, para.endTime, false));
                    }
                    EMileage tmp = null;
                    foreach (ReportMainViewModel model in ltModel)
                    {
                        //tmp = Model1.FirstOrDefault(f => f.VehicleCode == model.VehicleCode);
                        //model.MileageOfTody = tmp == null ? 0 : tmp.TotalMileage;
                        //tmp = Model2.FirstOrDefault(f => f.VehicleCode == model.VehicleCode);
                        //model.MileageOfYestoday = tmp == null ? 0 : tmp.TotalMileage;
                        //tmp = Model3.FirstOrDefault(f => f.VehicleCode == model.VehicleCode);
                        //model.MileageOfLast7Day = tmp == null ? 0 : tmp.TotalMileage;
                        //tmp = Model4.FirstOrDefault(f => f.VehicleCode == model.VehicleCode);
                        //model.MileageOfLast30Day = tmp == null ? 0 : tmp.TotalMileage;

                        tmp = Model.FirstOrDefault(f => f.VehicleCode == model.VehicleCode);
                        model.MileageCount = tmp == null ? 0 : tmp.TotalMileage;
                    }
                }
            }
            catch (Exception ex)
            {
                //Logger.Error("Error GetReportMainViewModel(" + guid.ToString() + "):" + ex.Message, ex);
                Logger.Error("Error GetReportMainViewModel:" + ex.Message, ex);
            }

            //Logger.Info("Out GetReportMainViewModel:" + guid.ToString());
            //sh.Stop();
            //Logger.Info("时间:" + sh.ElapsedMilliseconds);

            return ltModel;
        }
        /// <summary>
        /// 查询车辆当前信息和最近指令信息
        /// </summary>
        public VehicleOilControlInfoVMList SearchVehicleOilControlInfo(SearchVehicleOilControlInfoParam param)
        {
            EMGpsTypeService gpsTypeSve = new EMGpsTypeService();
            List<EMGpsType> gpsTypeList = gpsTypeSve.GetByPeripheralList(new List<PeripheralEnum>() { PeripheralEnum.Relay });
            List<ulong> gpsTypeIDList = gpsTypeList.Select(o => o.GPSTypeID).ToList();
           
            int rowCount;
            VehicleDAL veDal = new VehicleDAL();
            List<EMVehicleOilInfo> veOilList = veDal.GetVehicleOil(param.VehicleCodes, gpsTypeIDList, param.RowIndex, param.PageSize, out  rowCount, Param_OffLineTime);
            if (rowCount == 0)
                return null;
            IList<VehicleOilControlInfoVM> ltVM = NewBuildVM(veOilList);
           
            //PositioningWCFService positioningWCFServ = new PositioningWCFService();
            //positioningWCFServ.GetLoaction(ltVM);   //获取地址

            return new VehicleOilControlInfoVMList()
            {
                List = ltVM.ToList(),
                RowCount = rowCount
            };
        }
        public PagedDataList<PersonalSettingViewModel> PersonalSettingSearch(PersonalSettingSearchViewModel model)
        {
            EMVehicleService service = new EMVehicleService();
            PositionService positionServ = new PositionService();
            try
            {
                //int rowCount = 0;
                //IList<EMVehicle> list = service.Select(model.userCode,model.vehilceLikeStr,true,model.ltGpsTypeID, model.rowIndex,model.pageSize, out rowCount);
                //IList<Guid> ltVehicleCode_Paging = list.Select(p => p.VehicleCode).ToList();
                //IList<EGPSCurrentInfo> ltCurrentInfo = positionServ.GetCurrentInfoList(ltVehicleCode_Paging);

                //IDictionary<Guid, DateTime> CurrentInfoDic = ltCurrentInfo.ToDictionary(p => p.VehicleCode, p => p.ReportTime);
                //IList<EMOpenGPSInfo> listEntity = null;
                /////获取开启GPSCode的返回数据
                //if (model.OpenGPSCodeList != null && model.OpenGPSCodeList.Count > 0)
                //{
                   //  EMOpenGPSInfoService openGPSservice = new EMOpenGPSInfoService();
                   //  listEntity = openGPSservice.GetList(list.Select(p => p.GPSCode).ToList(), 1);
                //}
                //if (list != null && list.Count > 0 && rowCount > 0)
                //{
                //    List<PersonalSettingViewModel> newList = new List<PersonalSettingViewModel>();
                //    PagedDataList<PersonalSettingViewModel> pdl = new PagedDataList<PersonalSettingViewModel>();
                //    foreach (EMVehicle emVehicle in list)
                //    {
                //        PersonalSettingViewModel psvModel = new PersonalSettingViewModel();
                //        psvModel.GpsCode = emVehicle.GPSCode;
                //        psvModel.GpsTypeID = emVehicle.GPSTypeID;
                //        psvModel.VehicleInfo = emVehicle.LicenceNumber;
                //        psvModel.VehicleCode = emVehicle.VehicleCode;
                //        if (CurrentInfoDic.ContainsKey(emVehicle.VehicleCode))
                //        {
                //            TimeSpan timeSpan = DateTime.Now.Subtract(CurrentInfoDic[emVehicle.VehicleCode]);
                //            psvModel.IsEnable = !(timeSpan.TotalMinutes > Param_OffLineTime);
                //        }
                //        else
                //            psvModel.IsEnable = false;
                //        if (listEntity != null && listEntity.Count > 0)
                //        {
                //            foreach (EMOpenGPSInfo gpsInfo in listEntity)
                //            {
                //                if (psvModel.GpsCode == gpsInfo.GPSCode)
                //                {
                //                    psvModel.OpenResultContent = gpsInfo.Results;
                //                    psvModel.LastSetTime = gpsInfo.LastSetTime;
                //                }
                //            }
                //        }
                //        newList.Add(psvModel);
                //    }
                //    pdl.Datas = newList;
                //    pdl.RowCount = rowCount;
                //    return pdl;

                //代码优化
                int rowCount = 0;
                VehicleDAL vDal = new VehicleDAL();
                 List<EmPersonalSetting> pelist = service.NewSelect(model.userCode, model.vehilceLikeStr, true, model.ltGpsTypeID, model.rowIndex, model.pageSize, out rowCount, 1);
                
                if (pelist != null && pelist.Count > 0 && rowCount > 0)
                {
                     
                    PagedDataList<PersonalSettingViewModel> pdl = new PagedDataList<PersonalSettingViewModel>();
                    pdl.Datas = GetPerSettingViewModel(pelist); 
                    pdl.RowCount = rowCount;
                    return pdl;
                }
                return null;
                
                 
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                return null;
            }
        }
        public DBProcessResult<int> AddVehicleOperateTran(EMVehicle entity, string sUserName)
        {
            DBProcessResult<int> result = new DBProcessResult<int>();
            try
            {
                VehicleDAL ve = new VehicleDAL();
                IdentityNoService noService = new IdentityNoService();
                bool isLiceNum = ve.IsLicenceNumber(entity.TenantCode, entity.LicenceNumber);
                if (isLiceNum)
                {
                    result.IsSuccess = false;
                    result.Message = "已经有相同车牌号的车辆";
                    result.ReturnValue = -1;
                    return result;
                }
                EMGpsType gpsTypeEntity = ve.GetGpsTypeByGpsTypeId(entity.GPSTypeID);
                entity.GPSTypeName = gpsTypeEntity.TypeName;
                bool isDev = ve.IsDeviceNo(entity.DeviceNo);
                if (isDev != true)
                {
                    //新增车辆历史数据配置
                    string tableName = GetTableNameByCondition(gpsTypeEntity.PrefixCode);
                    EHisotryDataStoreTables table = ve.GetHistoryTable(tableName);

                    if (table == null)
                    {
                        result.IsSuccess = false;
                        result.Message = string.Format("找不到对应的历史数据表[{0}],请联系DBA!", tableName);
                        result.ReturnValue = -1;
                        return result;
                    }
                    //新增车辆
                    EnumGPSCodeRule codeType = (EnumGPSCodeRule)gpsTypeEntity.GPSCodeRule;
                    entity.GPSCode = GetGPSCodeHelper.GetGPSCode(gpsTypeEntity.PrefixCode, codeType, entity.SIMNo, entity.DeviceNo);

                    if (entity.DeviceNo.Length == gpsTypeEntity.MachineCodeLength)
                    {
                        GetVehicleGroupID(entity);    //客户管理中新增车辆时,没有车辆组,默认增加到顶级车辆组
                        
                        EHistoryDataStoreConfig configEntity = new EHistoryDataStoreConfig();
                        configEntity.RecordID = Guid.NewGuid();
                        configEntity.CreateDate = DateTime.Now;
                        configEntity.Enable = true;
                        configEntity.StoreTable = table;
                        configEntity.VehicleCode = entity.VehicleCode;
                       
                        //新增车辆Log
                        EMVehicleLog vehicleLog = new EMVehicleLog()
                        {
                            BeginDate = DateTime.Now,
                            LogID = noService.GetVehicleLogID(),
                            DeviceNo = entity.DeviceNo,
                            EndDate = null,
                            GPSCode = entity.GPSCode,
                            GPSTypeID = entity.GPSTypeID,
                            InitMileage = entity.InitMileage,
                            LicenceNumber = entity.LicenceNumber,
                            Operator = sUserName,
                            SIMNo = entity.SIMNo,
                            TenantCode = entity.TenantCode,
                            VehicleCode = entity.VehicleCode,
                            GroupID = entity.GroupID
                        };
                        var res = ve.AddVehicleOperTrans(entity, configEntity, vehicleLog);

                        result.IsSuccess = res.State;
                        result.Message = res.Msg;
                        result.ReturnValue = new VehicleDAL().SelectCount(entity.TenantCode.ToString());
                    }
                    else
                    {
                        result.IsSuccess = false;
                        result.Message = string.Format(@"GPS设备号长度为{0},请重新填写!", gpsTypeEntity.MachineCodeLength);
                        result.ReturnValue = -1;
                    }
                }
                else
                {
                    result.IsSuccess = false;
                    result.Message = "设备号已存在,请重新填写!";
                    result.ReturnValue = -1;
                }
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Message = ex.Message;
                result.ReturnValue = -1;
                Logger.Error("VehicleManagerWCFService.AddVehicleOperateTran(EMVehicle entity, string sUserName);" + ex.Message, ex);
            }
            return result;
            
        }
 public List<VehicleManager> GetCarList(string tenantCode, string LicenceNumber, string SIMNo, string DeviceNo, int rows, int pageSize, out int rowCount)
 {
     VehicleDAL vdal = new VehicleDAL();
     return vdal.GetCarList(tenantCode, LicenceNumber, SIMNo, DeviceNo, rows, pageSize, out rowCount);
 }
        public DBProcessResult AddVehicleOperate(EMVehicle entity, string sUserName)
        {
            DBProcessResult result = new DBProcessResult();
            try
            {
                VehicleDAL ve = new VehicleDAL();
                IdentityNoService noService = new IdentityNoService();
                bool isLiceNum = ve.IsLicenceNumber(entity.TenantCode, entity.LicenceNumber);
                if (isLiceNum)
                {
                    result.IsSuccess = false;
                    result.Message = "已经有相同车牌号的车辆";
                    return result;
                }

                //EMVehicle entity = ConvertHelper.ConvertObj<EMVehicleViewModel, EMVehicle>(view);
                EMGpsType gpsTypeEntity = ve.GetGpsTypeByGpsTypeId(entity.GPSTypeID);
                entity.GPSTypeName = gpsTypeEntity.TypeName;
                bool isDev = ve.IsDeviceNo(entity.DeviceNo);
                if (isDev != true)
                {
                    //新增车辆历史数据配置
                    string tableName = GetTableNameByCondition(gpsTypeEntity.PrefixCode);
                    EHisotryDataStoreTables table = ve.GetHistoryTable(tableName);
                    
                    if (table == null)
                    {
                        result.IsSuccess = false;
                        result.Message = string.Format("找不到对应的历史数据表[{0}],请联系DBA!", tableName);
                        return result;
                    }
                    //新增车辆
                    EnumGPSCodeRule codeType = (EnumGPSCodeRule)gpsTypeEntity.GPSCodeRule;
                    entity.GPSCode = GetGPSCodeHelper.GetGPSCode(gpsTypeEntity.PrefixCode, codeType, entity.SIMNo, entity.DeviceNo);

                    if (entity.DeviceNo.Length == gpsTypeEntity.MachineCodeLength)
                    {
                        GetVehicleGroupID(entity);    //客户管理中新增车辆时,没有车辆组,默认增加到顶级车辆组
                        Logger.Info("新增车辆: " + entity.LicenceNumber + "开始");
                        ve.AddVehicle(entity);
                        Logger.Info("新增车辆: " + entity.LicenceNumber + "结束");

                        EHistoryDataStoreConfig configEntity = new EHistoryDataStoreConfig();
                        configEntity.RecordID = Guid.NewGuid();
                        configEntity.CreateDate = DateTime.Now;
                        configEntity.Enable = true;
                        configEntity.StoreTable = table;
                        configEntity.VehicleCode = entity.VehicleCode;
                        Logger.Info("新增车辆 gps_historydatastoreconfig: " + configEntity.StoreTable.TableName + "开始");
                        ve.AddHistoryDataStoreConfig(configEntity);
                        Logger.Info("新增车辆 gps_historydatastoreconfig: " + configEntity.StoreTable.TableName + "结束");

                        //新增车辆Log
                        EMVehicleLog vehicleLog = new EMVehicleLog()
                        {
                            BeginDate = DateTime.Now,
                            LogID = noService.GetVehicleLogID(),
                            DeviceNo = entity.DeviceNo,
                            EndDate = null,
                            GPSCode = entity.GPSCode,
                            GPSTypeID = entity.GPSTypeID,
                            InitMileage = entity.InitMileage,
                            LicenceNumber = entity.LicenceNumber,
                            Operator = sUserName,
                            SIMNo = entity.SIMNo,
                            TenantCode = entity.TenantCode,
                            VehicleCode = entity.VehicleCode,
                            GroupID = entity.GroupID,
                        };
                        Logger.Info("新增车辆 movo_vehiclelog: " + configEntity.StoreTable.TableName + "开始");
                        ve.AddVehicleLog(vehicleLog);
                        Logger.Info("新增车辆 movo_vehiclelog: " + configEntity.StoreTable.TableName + "结束");

                        result.IsSuccess = true;
                    }
                    else
                    {
                        result.IsSuccess = false;
                        result.Message = string.Format(@"GPS设备号长度为{0},请重新填写!", gpsTypeEntity.MachineCodeLength);
                    }
                }
                else
                {
                    result.IsSuccess = false;
                    result.Message = "设备号已存在,请重新填写!";
                }
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Message = ex.Message;
                Logger.Info("新增车辆:" + ex.StackTrace + "【" + ex.Message + "】");
            }
            return result;
            
          
        }
        public List<ChangeCusCarWithOMViewModel> GetChangeCusCarOfPlat(string tenantCode, string iconSkin)
        {
            List<ChangeCusCarWithOMViewModel> list = new List<ChangeCusCarWithOMViewModel>();
            try
            {
                IList<EMTenant> ltTenantAll = new EMTenantService().GetGrandChildren(tenantCode);
                if (ltTenantAll.IsNullOrEmpty())
                    return list;

                var ltAllCus = ltTenantAll.Where(s => s.TenantType == EnumTenantType.EndCustomer && !string.IsNullOrEmpty(s.TenantName));
                if (ltAllCus.Count() == 0) return list;

                List<string> ltCusTenantCode = ltAllCus.Select(o => o.TenantCode).ToList();
                EMVehicleService vehicleServ = new EMVehicleService();
                //客户和客户的车辆总数
                Dictionary<string, int> dicVehicleCount = vehicleServ.SelectVehicleCount(ltCusTenantCode);
               
                EMTenant lastCreateTenant = ltAllCus.OrderByDescending(s => s.CreateTime).ElementAt(0);

                IList<ChangeCusCarWithOMViewModel> ltChildren = GetCarChildren(tenantCode, lastCreateTenant.TenantCode, ltTenantAll, dicVehicleCount);
                if (!ltChildren.IsNullOrEmpty())
                    list.AddRange(ltChildren);

                List<ChangeCusCarWithOMViewModel> vechileList = null;
                for (int j = 0; j < list.Count; j++)
                {
                    if (list[j].Children.Count == 0)
                    {
                        string stenantCode = list[j].TenantCode;

                        List<EMVehicle> veList = new VehicleDAL().GetVehicleListByTenantCode(stenantCode);
                        if (veList != null&&veList.Count>0)
                        {
                            vechileList = new List<ChangeCusCarWithOMViewModel>();
                            for (int a = 0; a < veList.Count; a++)
                            {
                                ChangeCusCarWithOMViewModel ve = new ChangeCusCarWithOMViewModel();
                                ve.TenantCode = veList[a].VehicleCode.ToString();
                                ve.TenantName = veList[a].LicenceNumber;
                                ve.iconSkin = "CarDeviceNo";
                                 
                                vechileList.Add(ve);
                            }
                            list[j].iconSkin = iconSkin;// 值为CarDeviceNo表示是车辆的上一级可以选中,为空表示车辆的上一级不可以选中
                            list[j].Children.AddRange(vechileList);
                        }
                    }
                    else
                    {
                        for (int k = 0; k < list[j].Children.Count; k++)
                        {
                            string stenantCode = list[j].Children[k].TenantCode;
                            vechileList = new List<ChangeCusCarWithOMViewModel>();
                            List<EMVehicle> veList = new VehicleDAL().GetVehicleListByTenantCode(stenantCode);
                            if (veList != null&&veList.Count>0)
                            {
                                for (int a = 0; a < veList.Count; a++)
                                {
                                    ChangeCusCarWithOMViewModel ve = new ChangeCusCarWithOMViewModel();
                                    ve.TenantCode = veList[a].VehicleCode.ToString();
                                    ve.TenantName = veList[a].LicenceNumber;
                                   
                                    ve.iconSkin = "CarDeviceNo";
                                    vechileList.Add(ve);

                                }
                                list[j].Children[k].iconSkin = iconSkin;
                                list[j].Children[k].Children.AddRange(vechileList);
                            }
                        }
                    }
                }

                return list;
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
                return list;
            }
             
        }
        /// <summary>
        /// 获取终端用户的车辆列表
        /// </summary>
        /// <param name="tenantCode"></param>
        /// <returns></returns>
        public List<ChangeCusCarWithOMViewModel> GetEndCustomerCarList(string tenantCode, string iconSkin)
        {
            List<ChangeCusCarWithOMViewModel> list = new List<ChangeCusCarWithOMViewModel>();
            ChangeCusCarWithOMViewModel car=new ChangeCusCarWithOMViewModel ();
            TenantDAL dal=new TenantDAL ();
            EMTenant emt=new EMTenant ();
            emt=dal.GetTenantBySuperTenantID(tenantCode);
            car.IsLastCreated = false;
            car.IsOM = emt.TenantType == EnumTenantType.EndCustomer;
            car.TenantCode = emt.TenantCode;
            car.TenantName = emt.TenantName;
            car.OperatorLevel = emt.OperatorLevel;
            car.Children = new List<ChangeCusCarWithOMViewModel>();
            car.RegisterUserCode = emt.RegisterUserCode;
            car.VehicleCount = 0;
            car.VehicleOnlineNum = 0;
            car.iconSkin = "pIcon";
            list.Add(car);

            List<EMVehicle> veList = new VehicleDAL().GetVehicleListByTenantCode(tenantCode);
            if (veList != null && veList.Count > 0)
            {
                List<ChangeCusCarWithOMViewModel>   vechileList = new List<ChangeCusCarWithOMViewModel>();
                for (int a = 0; a < veList.Count; a++)
                {
                    ChangeCusCarWithOMViewModel ve = new ChangeCusCarWithOMViewModel();
                    ve.TenantCode = veList[a].VehicleCode.ToString();
                    ve.TenantName = veList[a].LicenceNumber;
                    ve.iconSkin = "CarDeviceNo";

                    vechileList.Add(ve);
                }
                list[0].iconSkin = iconSkin; //值为CarDeviceNo表示是车辆的上一级可以选中,为空表示车辆的上一级不可以选中
                list[0].Children.AddRange(vechileList);
            }
            return list;
        }
        public List<MonitorVehicleEntity> GetMonitorVehicleList(string userCode, string tenantCode, EnumMapType mapType, string vehGroupID)
        {
            if (string.IsNullOrEmpty(userCode) || string.IsNullOrEmpty(tenantCode))
            {
                Logger.Info("PositioningWCFService/GetMonitorVehicleList(string userCode, string tenantCode, EnumMapType mapType),参数(userCode 或 tenantCode)为空。");
                return null;
            }

            try
            {
                var res = new VehicleDAL().GetMonitorVehicleList(userCode, tenantCode, mapType, vehGroupID);
                return res;
            }
            catch (Exception ex)
            {
                Logger.Error("PositioningWCFService/GetMonitorVehicleList(string userCode, string tenantCode, EnumMapType mapType)," + ex.Message, ex);
                return null;
            }
        }