/// <summary> /// 查询 /// </summary> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <param name="type"></param> /// <returns></returns> public async Task <NewsQueryDto> Query(string channelId = ShowApiNewsChannel.Domestic, int type = 0, int pageIndex = 1, int pageSize = 20) { var redisKey = $"{RedisTitle}{type}{channelId}_{pageIndex}_{pageSize}"; var dto = redisCache.GetValue <NewsQueryDto>(redisKey); if (dto != null && dto.List.Any()) { return(dto); } var now = DateTime.Now; var first = newsRepository.FirstOrDefault(x => x.ChannelId == channelId && x.Type == type, x => x.Date); if (first == null || (first != null && (now - first.Date).TotalMinutes >= 30)) { await newsApplicationService.InsertNews(channelId, type, pageIndex, pageSize); } var result = GetNews(channelId, pageIndex, pageSize); redisCache.SetValue(redisKey, result, TimeSpan.FromMinutes(5)); return(result); }
public async Task Execute(IJobExecutionContext context) { await Task.Run(async() => await newsApplicationService.InsertNews()); }