public void CollectData() { //每个月5号,凌晨3点5分,采集数据 if (DateTime.Now.Day == 5 && DateTime.Now.Hour == 3 && DateTime.Now.Minute == 5) { if (!iscollected) { iscollected = true; try { EventLogs.JobLog("开始作业-车型数据采集"); bool hasnewdata = false; string urlBrand = "http://sales.new4s.com/ajax/brand/1/"; string urlSeries = "http://sales.new4s.com/ajax/brand/3/{0}/"; string urlModel = "http://sales.new4s.com/ajax/brand/5/{0}/"; List <CarBrandInfo> listBrand = GetCarBrandList(true); string strBrand = Http.GetPage(urlBrand, 3); List <JsonModel> listJsonBrand = Serializer.DeserializeJson <List <JsonModel> >(strBrand); if (listBrand == null) { listBrand = new List <CarBrandInfo>(); } foreach (JsonModel jsonbrand in listJsonBrand) { int brandid = 0; string brandname = jsonbrand.name.Replace(jsonbrand.fletter + "-", string.Empty); if (!listBrand.Exists(l => l.Name == brandname)) { brandid = AddCarBrand(new CarBrandInfo() { Name = brandname, NameIndex = jsonbrand.fletter }); } else { brandid = listBrand.Find(l => l.Name == brandname).ID; } if (brandid > 0) { List <CarSeriesInfo> listSeries = GetCarSeriesListByBrandID(brandid, true); if (listSeries == null) { listSeries = new List <CarSeriesInfo>(); } string strSeries = Http.GetPage(string.Format(urlSeries, jsonbrand.id), 3); List <JsonModel> listJsonSeries = Serializer.DeserializeJson <List <JsonModel> >(strSeries); foreach (JsonModel jsonseries in listJsonSeries) { int seriesid = 0; string seriesname = jsonseries.name; if (!listSeries.Exists(l => l.Name == seriesname)) { seriesid = AddCarSeries(new CarSeriesInfo() { Name = seriesname, BrandID = brandid }); } else { seriesid = listSeries.Find(l => l.Name == seriesname).ID; } if (seriesid > 0) { List <CarModelInfo> listModel = GetCarModelListBySeriesID(seriesid, true); if (listModel == null) { listModel = new List <CarModelInfo>(); } string strModel = Http.GetPage(string.Format(urlModel, jsonseries.id), 3); List <JsonModel> listJsonModel = Serializer.DeserializeJson <List <JsonModel> >(strModel); foreach (JsonModel jsonmodel in listJsonModel) { int modelid = 0; string modelname = jsonmodel.name; if (!listModel.Exists(l => l.Name == modelname)) { modelid = AddCarModel(new CarModelInfo() { Name = modelname, SeriesID = seriesid }); hasnewdata = true; } else { modelid = listModel.Find(l => l.Name == modelname).ID; } if (modelid == 0) { throw new Exception("新增车型 " + modelname + " 出错"); } } } else { throw new Exception("新增车系 " + seriesname + " 出错"); } } } else { throw new Exception("新增品牌 " + brandname + " 出错"); } } if (hasnewdata) { ReloadCarBrandListCache(); ReloadCarSeriesListCache(); ReloadCarModelListCache(); } EventLogs.JobLog("完成作业-车型数据采集"); } catch (Exception ex) { EventLogs.JobError("作业发生错误-车型数据采集", EventLogs.EVENTID_JOB_ERROR, 0, ex); ExpLog.Write(ex); } } } else { iscollected = false; } }