using System;
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Linq;
|
using System.Threading.Tasks;
|
using System.Web.Mvc;
|
using CommonHelper;
|
using GasolineBlend.Entity;
|
using Pissa.Service.DbService;
|
using Quartz.Util;
|
using SqlSugar;
|
|
namespace GasolineBlend.Controllers
|
{
|
public class SysController : BaseController
|
{
|
private SysService _countryService = new SysService();
|
private SysHotWordService _hotWordService = new SysHotWordService();
|
|
/// <summary>
|
/// 获取国家信息
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
public ActionResult GetCountry()
|
{
|
var res = _countryService.GetListAsync(null, a => a.Sort, OrderByType.Asc, false).Result;
|
return SuccessNoShow(data:res);
|
}
|
|
/// <summary>
|
/// 获取主要国家信息
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
public ActionResult GetCountryMain()
|
{
|
List<string> listNameCH = new List<string>();
|
string[] strNameCh = {"中国", "美国", "日本", "韩国", "德国","法国","意大利", "瑞典", "芬兰", "挪威", "英国", "瑞士", "俄罗斯", "印度", "巴西" };
|
listNameCH = strNameCh.ToList();
|
var res = _countryService.GetListAsync(a=>listNameCH.Contains(a.NameCh), a => a.Sort, OrderByType.Asc, false).Result;
|
return SuccessNoShow(data: res);
|
}
|
|
/// <summary>
|
/// 获取字典信息
|
/// </summary>
|
/// <param name="dictCode"></param>
|
/// <returns></returns>
|
[HttpPost]
|
public ActionResult GetDictItems(string dictCode)
|
{
|
var res = _countryService.GetDictItems(dictCode);
|
return SuccessNoShow(data: res);
|
}
|
|
|
/// <summary>
|
/// 获取ipc
|
/// </summary>
|
/// <param name="year">年份</param>
|
/// <param name="parentCode">父编码</param>
|
/// <returns></returns>
|
[HttpPost]
|
public ActionResult GetIpcClass(int year=2021, string parentCode = "")
|
{
|
var res = _countryService.GetIpcClass(year,parentCode);
|
return SuccessNoShow(data: res);
|
}
|
|
/// <summary>
|
/// 获取cpc
|
/// </summary>
|
/// <param name="parentCode">父编码</param>
|
/// <returns></returns>
|
[HttpPost]
|
public ActionResult GetCpcClass(string parentCode = "")
|
{
|
var res = _countryService.GetCpcClass(parentCode);
|
return SuccessNoShow(data: res);
|
}
|
/// <summary>
|
/// 获取产业分类
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
public ActionResult GetStraindustryTree()
|
{
|
var res = _countryService.GetStraindustryTree();
|
return SuccessNoShow(data: res);
|
}
|
|
/// <summary>
|
/// 获取国民经济行业分类
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
public ActionResult GetEcoindustryTree()
|
{
|
var res = _countryService.GetEcoindustryTree();
|
return SuccessNoShow(data: res);
|
}
|
|
/// <summary>
|
/// 获取轮播图
|
/// </summary>
|
/// <param name="isDisplay">是否展示</param>
|
/// <returns></returns>
|
[HttpPost]
|
public ActionResult GetCarouselImg(bool? isDisplay = null)
|
{
|
var res = _countryService.Context.Queryable<SysCarouselImg>()
|
.WhereIF(isDisplay != null, a => a.IsDisplay == isDisplay)
|
.OrderBy(a => a.Sort)
|
.ToList();
|
return SuccessNoShow(data: res);
|
}
|
|
/// <summary>
|
/// 上传轮播图
|
/// </summary>
|
/// <param name="imgName"></param>
|
/// <param name="sort"></param>
|
/// <param name="isDisplay"></param>
|
/// <returns></returns>
|
[HttpPost]
|
public ActionResult AddCarouselImg(string imgName, int sort = 0, bool isDisplay = true)
|
{
|
//LogHelper.Error("文件名Test:"+imgName);
|
if (HttpContext.Request.Files.Count == 0)
|
return Error("上传文件的数量是0");
|
var file = Request.Files[0];
|
if (file == null)
|
return Error("请上传图像文件");
|
if (imgName.IsNullOrWhiteSpace())
|
imgName = file.FileName;
|
if (!Directory.Exists(Server.MapPath("/CarouselImg")))
|
Directory.CreateDirectory(Server.MapPath("/CarouselImg"));
|
string filePath = $"/CarouselImg/{Guid.NewGuid()}{Path.GetExtension(file.FileName)}";
|
string absolutePath = Server.MapPath(filePath);
|
file.SaveAs(absolutePath);
|
|
var model = new SysCarouselImg()
|
{
|
Name = imgName,
|
Sort = sort,
|
IsDisplay = isDisplay,
|
CreateUserId = OperatorProvider.Instance?.Current?.UserId??"0",
|
Url = filePath
|
};
|
var res = _countryService.Context.Insertable(model).ExecuteReturnIdentity();
|
return Success(data: res);
|
}
|
/// <summary>
|
/// 修改
|
/// </summary>
|
/// <param name="id"></param>
|
/// <param name="imgName"></param>
|
/// <param name="sort"></param>
|
/// <param name="isDisplay"></param>
|
/// <returns></returns>
|
[HttpPost]
|
public ActionResult UpdateCarouselImg(int id,string imgName, int? sort = null, bool? isDisplay = null)
|
{
|
var res = _countryService.Context.Updateable<SysCarouselImg>()
|
.SetColumns(a => new SysCarouselImg() { UpdateTime = DateTime.Now})
|
.SetColumnsIF(!string.IsNullOrWhiteSpace(imgName),a=>a.Name==imgName)
|
.SetColumnsIF(sort!=null,a=>a.Sort==(int)sort)
|
.SetColumnsIF(isDisplay != null,a=>a.IsDisplay == (bool)isDisplay)
|
.Where(a => a.Id == id)
|
.ExecuteCommand();
|
return Success();
|
}
|
/// <summary>
|
/// 删除
|
/// </summary>
|
/// <param name="id"></param>
|
/// <returns></returns>
|
[HttpPost]
|
public ActionResult DeleteCarouselImg(int id)
|
{
|
var img = _countryService.Context.Queryable<SysCarouselImg>()
|
.Where(a => a.Id == id)
|
.First();
|
if (img == null)
|
return Error("找不到该图片");
|
|
var res = _countryService.Context.Deleteable<SysCarouselImg>()
|
.Where(a => a.Id == id)
|
.ExecuteCommand();
|
System.IO.File.Delete(Server.MapPath(img.Url));
|
return res > 0 ? Success() : Error();
|
}
|
|
|
/// <summary>
|
/// 洛迦诺分类
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
public ActionResult GetLoccn()
|
{
|
var res = _countryService.GetLoccn();
|
return SuccessNoShow(data: res);
|
}
|
|
#region SysHotwords
|
|
|
[HttpPost]
|
public async Task<ActionResult> AddHotWord(SysHotWord model)
|
{
|
model.CreateUserId = OperatorProvider.Instance?.Current?.UserId;
|
var res = await _hotWordService.AddAsync(model);
|
return Success();
|
}
|
[HttpPost]
|
public async Task<ActionResult> DelHotWord(int id)
|
{
|
var res = await _hotWordService.DeleteAsync(a=>a.Id == id);
|
return Success();
|
}
|
[HttpPost]
|
public async Task<ActionResult> UpdateHotWord(SysHotWord model)
|
{
|
model.CreateUserId = OperatorProvider.Instance?.Current?.UserId;
|
var res = await _hotWordService.UpdateAsync(model);
|
return Success();
|
}
|
[HttpPost]
|
public async Task<ActionResult> GetHotWordList()
|
{
|
var res = await _hotWordService.GetListAsync(null, a => a.Sort, OrderByType.Asc);
|
return SuccessNoShow(data:res);
|
}
|
|
#endregion
|
}
|
}
|