public IEnumerable <BaseHouseInfo> SearchHouses(HouseSearchCondition condition) { if (string.IsNullOrEmpty(condition.Source)) { var houseList = new List <BaseHouseInfo>(); // 因为会走几个表,默认每个表取N条 var houseSources = GetCityHouseSources(condition.CityName); var limitCount = condition.HouseCount / houseSources.Count; foreach (var houseSource in houseSources) { //建荣家园数据质量比较差,默认不出 if (houseSource == ConstConfigName.CCBHouse) { continue; } condition.Source = houseSource; condition.HouseCount = limitCount; houseList.AddRange(Search(condition)); } return(houseList.OrderByDescending(h => h.PubTime)); } else { return(Search(condition)); } }
public void Run() { LogHelper.Info("开始RefreshHouseCacheJob..."); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); var cityDashboards = houseDapper.GetHouseDashboard().GroupBy(d => d.CityName); foreach (var item in cityDashboards) { LogHelper.RunActionNotThrowEx(() => { //聚合房源的缓存,前600条数据 var search = new HouseSearchCondition() { CityName = item.Key, HouseCount = 600, IntervalDay = 14, Refresh = true }; houseDapper.SearchHouses(search); foreach (var dashbord in item) { //每类房源的默认缓存,前600条数据 search.HouseCount = 600; search.Source = dashbord.Source; houseDapper.SearchHouses(search); // 为小程序做的缓存,每次拉10条,一共20页 for (var page = 0; page <= 30; page++) { search.HouseCount = 20; search.Source = dashbord.Source; search.Page = page; houseDapper.SearchHouses(search); } } //为移动端做的缓存,每次拉180条,一共5页 for (var page = 0; page <= 5; page++) { search.Source = ""; search.HouseCount = 180; search.Page = page; houseDapper.SearchHouses(search); } //为小程序做的缓存,每次拉20条,一共30页 for (var page = 0; page <= 30; page++) { search.Source = ""; search.HouseCount = 20; search.Page = page; houseDapper.SearchHouses(search); } }, "RefreshHouse"); } sw.Stop(); string copyTime = sw.Elapsed.TotalSeconds.ToString(CultureInfo.InvariantCulture); LogHelper.Info("RefreshHouseCacheJob结束,花费时间:" + copyTime); }
public void Run() { LogHelper.Info("开始RefreshHouseSourceJob..."); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); var cityDashboards = configDapper.GetDashboards().GroupBy(d => d.CityName); foreach (var item in cityDashboards) { LogHelper.RunActionNotThrowEx(() => { //聚合房源的缓存,前600条数据 var search = new HouseSearchCondition() { CityName = item.Key, HouseCount = 600, IntervalDay = 14, Refresh = true }; houseDapper.SearchHouses(search); foreach (var dashbord in item) { //每类房源的默认缓存,前600条数据 search.HouseCount = 600; search.Source = dashbord.Source; houseDapper.SearchHouses(search); } }, "RefreshHouse"); } sw.Stop(); string copyTime = sw.Elapsed.TotalSeconds.ToString(CultureInfo.InvariantCulture); LogHelper.Info("RefreshHouseSourceJob结束,花费时间:" + copyTime); }
public IActionResult Houses([FromBody] HouseSearchCondition search) { try { if (search == null || search.CityName == null) { return(Json(new { IsSuccess = false, error = "查询条件不能为null" })); } var houseList = _houseDapper.SearchHouses(search); return(Json(new { IsSuccess = true, HouseInfos = houseList })); } catch (Exception ex) { return(Json(new { IsSuccess = false, error = ex.ToString() })); } }
public IActionResult GetHouseInfo(string cityName, string source = "", int houseCount = 600, int intervalDay = 14, string keyword = "", bool refresh = false, int page = 0) { try { var searchCondition = new HouseSearchCondition() { CityName = cityName, Source = source, HouseCount = houseCount, IntervalDay = intervalDay, Keyword = keyword, Page = page, Refresh = refresh }; var houseList = _houseDapper.SearchHouses(searchCondition); return(Json(new { IsSuccess = true, HouseInfos = houseList })); } catch (Exception ex) { return(Json(new { IsSuccess = false, error = ex.ToString() })); } }
public IEnumerable <BaseHouseInfo> Search(HouseSearchCondition condition) { string redisKey = condition.RedisKey; var houses = new List <BaseHouseInfo>(); if (!condition.Refresh) { houses = redis.ReadSearchCache(redisKey); if (houses != null && houses.Count > 0) { return(houses); } } using (IDbConnection dbConnection = GetConnection()) { dbConnection.Open(); houses = dbConnection.Query <BaseHouseInfo>(condition.QueryText, condition).ToList(); if (houses != null && houses.Count > 0) { redis.WriteSearchCache(redisKey, houses); } return(houses); } }
public void Run() { LogHelper.Info("开始RefreshHouseCacheJob..."); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); var cityDashboards = houseDapper.GetHouseDashboard().GroupBy(d => d.CityName); foreach (var item in cityDashboards) { var search = new HouseSearchCondition() { CityName = item.Key, HouseCount = 500, IntervalDay = 14, Refresh = true }; houseDapper.SearchHouses(search); foreach (var dashbord in item) { search.HouseCount = 500; search.Source = dashbord.Source; houseDapper.SearchHouses(search); } for (var page = 0; page <= 5; page++) { search.Source = ""; search.HouseCount = 140; search.Page = page; houseDapper.SearchHouses(search); } } sw.Stop(); string copyTime = sw.Elapsed.TotalSeconds.ToString(CultureInfo.InvariantCulture); LogHelper.Info("RefreshHouseCacheJob结束,花费时间:" + copyTime); }