using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using CommonHelper;
using CommonHelper.Redis;
using GasolineBlend.Entity;
using GasolineBlend.Filter;
using Pissa.Service;
using Pissa.Service.DbService;
using SqlSugar;
namespace GasolineBlend.Controllers
{
///
///
///
[LoginChecked()]
public class AnalystController : BaseController
{
private SysService _countryService = new SysService();
private readonly AnalystReportService _analyzeReportRepository =new AnalystReportService();
//private readonly CustomerRedis _redis = new CustomerRedis(0);
///
/// 获取新闻列表分页
///
/// 页码
/// 每页条数
///
[HttpPost]
[LoginChecked(false)]
public ActionResult GetPage(string title="",string country="",string topic="",string language="",int pageIndex = 1, int pageSize = 20)
{
var resCountry = _countryService.GetDictItems("countryTerritoryCode");
var resLanguage = _countryService.GetDictItems("languageCode");
var resTopic = _countryService.GetDictItems("topicCode");
var whereExp = Expressionable.Create()
.AndIF(!string.IsNullOrWhiteSpace(title), a => a.Title.Contains(title))
.AndIF(!string.IsNullOrWhiteSpace(language) && !language.Contains("所有"), a => a.Language == resLanguage.Where(b=>b.ItemText==language).FirstOrDefault().ItemValue)
.AndIF(!string.IsNullOrWhiteSpace(country) && !country.Contains("所有"), a => a.Country == resCountry.Where(b => b.ItemText == country).FirstOrDefault().ItemValue)
.AndIF(!string.IsNullOrWhiteSpace(topic) && !topic.Contains("所有"), a => a.Topic == resTopic.Where(b => b.ItemText == topic).FirstOrDefault().ItemValue)
.ToExpression();
if (pageIndex < 0) pageIndex = 1;
if (pageSize < 1) pageSize = 20;
var page = _analyzeReportRepository.GetPagesAsync(pageIndex, pageSize, whereExp, order: a => a.CreateTime,
orderEnum: OrderByType.Desc).Result;
//转换成中文
for (int i = 0; i < page.Items.Count; i++)
{
page.Items[i].Language = resLanguage.Where(b => b.ItemValue == page.Items[i].Language).FirstOrDefault()
.ItemText;
page.Items[i].Topic = resTopic.Where(b => b.ItemValue == page.Items[i].Topic).FirstOrDefault()
.ItemText;
page.Items[i].Country = resCountry.Where(b => b.ItemValue == page.Items[i].Country).FirstOrDefault()
.ItemText;
}
return SuccessNoShowNews(data: page);
}
///
/// 获取详情(新版本取消)
///
///
///
[HttpGet]
public ActionResult GetArticle(string id)
{
//var model = _analyzeReportRepository.GetModelAsync(id).Result;
//var cache = _redis.Get>("ArticleViewCount");
//if (cache == null)
//{
// cache = new Dictionary();
// cache.Add(model.Id, model.PageViews + 1);
//}
//else if(cache.ContainsKey(model.Id))
//{
// cache[model.Id] += 1;
//}
//else
//{
// cache.Add(model.Id, model.PageViews + 1);
//}
//_redis.Set("ArticleViewCount", cache.ToJson());
//model.PageViews = cache[model.Id];
//return Success(data: model);
return SuccessNoShow();
}
///
/// 浏览量+1
///
///
[HttpPost]
[LoginChecked(false)]
public ActionResult ReadArticle(string id)
{
_analyzeReportRepository.Context.Updateable()
.SetColumns(a => a.PageViews == a.PageViews + 1).Where(a => a.Id == id).ExecuteCommand();
return SuccessNoShowNews();
}
}
}