public void Execute(IJobExecutionContext context) { List <MiniRegion> miniRegion = new List <MiniRegion>(); try { logger.Info("开始刷新轮胎区域活动缓存"); var allActivityId = GetAllActivityId(); if (allActivityId != null && allActivityId.Any()) { using (var client = new RegionClient()) { var data = client.GetAllMiniRegion(); data.ThrowIfException(true, "获取所有地区服务失败"); miniRegion = data.Result.ToList(); } if (miniRegion != null && miniRegion.Any()) { foreach (var activityId in allActivityId) { foreach (var region in miniRegion) { using (var client = new ConfigClient()) { var result = client.RefreshRegionMarketingCache(activityId, region.RegionId); result.ThrowIfException(true); if (!result.Result) { logger.Error("刷新轮胎区域活动失败"); } } } } } else { logger.Info("未获取到地区"); } } else { logger.Info("没有已配置的活动"); } } catch (Exception ex) { logger.Error("刷新轮胎区域活动缓存Job异常", ex); } logger.Info("刷新轮胎区域活动缓存任务完成"); }
public static List <MiniRegion> GetAllRegion() { using (var client = new RegionClient()) { var vals = client.GetAllMiniRegion(); var data = new List <MiniRegion>(); if (vals.Success) { foreach (var item in vals.Result.ToList()) { var val = new MiniRegion() { RegionId = item.RegionId, RegionName = item.RegionName, PinYin = item.PinYin }; if (item.RegionId == 1 || item.RegionId == 2 || item.RegionId == 19 || item.RegionId == 20) { val.ChildRegions = new List <MiniRegion>() { new MiniRegion() { RegionId = item.RegionId, RegionName = item.RegionName, PinYin = item.PinYin } }; } else { var child = new List <MiniRegion>(); foreach (var it in item.ChildRegions) { child.Add(new MiniRegion() { RegionId = it.RegionId, RegionName = it.RegionName, PinYin = it.PinYin }); } val.ChildRegions = child; } data.Add(val); } return(data); } else { return(null); } } }
public List <MiniRegion> GetAllMiniRegion() { List <MiniRegion> result = new List <MiniRegion>(); try { using (var client = new RegionClient()) { var data = client.GetAllMiniRegion(); data.ThrowIfException(true, "获取所有地区服务失败"); result = data.Result.ToList(); } } catch (Exception ex) { logger.Error(ex); } return(result); }