SysAppController.cs 2.51 KB
using Hh.Mes.Common.Json;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Hosting;
using Hh.Mes.Common.config;
using WebMvc.Aop;
using Hh.Mes.Common.Request;
using Hh.Mes.POJO.Entity;
using Hh.Mes.Service.SystemAuth;
using Hh.Mes.Service.WebService.Base;

namespace WebMvc
{
    /// <summary>
    /// APP管理
    /// </summary>
    [Area("base")]
    public class SysAppController : BaseController
    {
        private readonly SysAppService sysAppService;
        private readonly IWebHostEnvironment environment;

        public SysAppController(IAuth authUtil, SysAppService service, IWebHostEnvironment hostingEnvironment) : base(authUtil)
        {
            environment = hostingEnvironment;
            sysAppService = service;
            sysAppService.sysWebUser = authUtil.GetCurrentUser().User;
        }

        #region 视图功能
        /// <summary>
        /// 默认视图Action
        /// </summary>
        /// <returns></returns>
        [Authenticate]
        [ServiceFilter(typeof(OperLogFilter))]
        public ActionResult Index()
        {
            return View();
        }
        #endregion

        /// <summary>
        /// 加载及分页查询
        /// </summary>
        [HttpPost]
        public string Load(PageReq pageRequest, sys_app entity)
        {
            return Serialize(sysAppService.Load(pageRequest, entity));
        }

        /// <summary>
        /// 修改数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ServiceFilter(typeof(OperLogFilter))]
        [XSSFilter]
        public string Upd(sys_app entity)
        {
            var response = sysAppService.Upd(entity);
            return Serialize(response);
        }


        /// <summary>
        /// 删除
        /// </summary>
        [HttpPost]
        [ServiceFilter(typeof(OperLogFilter))]
        public string DelByIds(int[] ids)
        {
            return Serialize(sysAppService.DelByIds(ids));
        }

        /// <summary>
        /// 导入数据
        /// </summary>
        /// <param name="excelfile">表单提交的文件信息</param>
        /// <returns></returns>
        [HttpPost]
        public string Import(IFormFileCollection excelfile)
        {
            var http = ConfigRead.GetInstance.GetAppsetConnection().HttpOrHttps;
            var port = Request.Host.Port.Value;
            return JsonHelper.Instance.Serialize(sysAppService.Import(http, port, excelfile,  environment.ContentRootPath));
        }

    }
}