using Jaina;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using HT.Cloud.Code;
using HT.Cloud.Domain.FileManage;
using HT.Cloud.Service.Event;
using HT.Cloud.Service.FileManage;
using HT.Cloud.Service.SystemOrganize;
namespace HT.Cloud.Web.Areas.FileManage.Controllers
{
///
/// 创 建:超级管理员
/// 日 期:2020-07-22 12:04
/// 描 述:文件管理控制器类
///
[Area("FileManage")]
public class UploadfileController : BaseController
{
public UploadfileService _service { get; set; }
public SystemSetService _setService { get; set; }
#region 获取数据
[HandlerAjaxOnly]
[IgnoreAntiforgeryToken]
public async Task GetGridJson(SoulPage pagination, string keyword)
{
if (string.IsNullOrEmpty(pagination.field))
{
pagination.field = "F_Id";
pagination.order = "desc";
}
var data = await _service.GetLookList(pagination, keyword);
return Content(pagination.setData(data).ToJson());
}
[HttpGet]
[HandlerAjaxOnly]
public async Task GetListJson(string keyword)
{
var data = await _service.GetList(keyword);
return Content(data.ToJson());
}
[HttpGet]
[HandlerAjaxOnly]
public async Task GetFormJson(string keyValue)
{
var data = await _service.GetLookForm(keyValue);
return Content(data.ToJson());
}
#endregion 获取数据
#region 提交数据
[HttpPost]
[HandlerLogin]
[IgnoreAntiforgeryToken]
public async Task Upload(string fileby, int filetype = 0)
{
try
{
//1图片,2excel,3template
int[] filetypes = { 1, 2,3 };
if (!filetypes.Contains(filetype))
{
throw new Exception("请指定文件格式");
}
string stemp = "local";
if (_service.currentuser.DbNumber != GlobalContext.SystemConfig.MainDbNumber)
{
var temp = await _setService.GetForm(_service.currentuser.CompanyId);
if (temp != null)
{
stemp = temp.F_CompanyName;
}
else
{
throw new Exception("租户不存在");
}
}
var files = HttpContext.Request.Form.Files;
long size = files.Sum(f => f.Length);
if (size > 104857600)
{
throw new Exception("大小必须小于100M");
}
List