SysComanyController.cs 3.61 KB
using Hh.Mes.Common;
using Hh.Mes.Common.Request;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.Response;
using Hh.Mes.Service;
using Hh.Mes.Service.Configure;
using Hh.Mes.Service.SystemAuth;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using WebMvc.Aop;

namespace WebMvc.Areas.configure.Controllers
{
    /// <summary>
    /// 公司设置
    /// </summary>
    [Area("configure")]
    public class SysCompanyController : BaseController
    {
        private readonly SysCompanyService SyscompanyService;
        private readonly IWebHostEnvironment environment;
        public SysCompanyController(IAuth authUtil, SysCompanyService service, IWebHostEnvironment hostingEnvironment) : base(authUtil)
        {
            SyscompanyService = service;
            SyscompanyService.sysWebUser = authUtil.GetCurrentUser().User;
            environment = hostingEnvironment;
        }

        [ResponseCache(Duration = 60)]
        public ActionResult Index()
        {
            return View();
        }

        #region 公司设置模块 获取数据
        /// <summary>
        /// 加载及分页查询
        /// </summary>
        /// <param name="pageRequest">表单请求信息</param>
        /// <param name="entity">请求条件实例</param>
        /// <returns></returns>
        [HttpPost]
        public string Load(PageReq pageRequest, base_company entity)
        {
            var sysCompanies = new List<base_company> { SyscompanyService.GetSysCompanyOne() };
            var retrunResult = new Response
            {
                Count = 1,
                Result = sysCompanies
            };
            return Serialize(retrunResult);
        }

        #endregion

        #region 提交数据
        /// <summary>
        /// 新增数据
        /// </summary>
        /// <param name="entity">新增实例</param>
        /// <returns></returns>
        [HttpPost]
        [XSSFilter]
        [ServiceFilter(typeof(OperLogFilter))]
        public string Ins(base_company entity)
        {
            return Serialize(SyscompanyService.Ins(entity));
        }

        /// <summary>
        /// 修改数据
        /// </summary>
        /// <param name="entity">修改实例</param>
        /// <returns></returns>
        [HttpPost]
        [XSSFilter]
        [ServiceFilter(typeof(OperLogFilter))]
        public string Upd(base_company entity)
        {
            return Serialize(SyscompanyService.UpdataById(entity));
        }

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        [ServiceFilter(typeof(OperLogFilter))]
        public string DelByIds(int[] ids)
        {
            return Serialize(SyscompanyService.DeleteByIds(ids));
        }
        #endregion

        [HttpPost]
        public string Import(IFormFileCollection excelfile, int targetId, string position)
        {
            try
            {
                var port = Request.HttpContext.Connection.LocalPort;
                var model = new sys_File
                {
                    targetId = targetId,
                    host = ComputerHelp.GetAddressIP() + ":" + port,
                    position = position
                };
                Result = SyscompanyService.Upload(excelfile, environment.ContentRootPath, model);
            }
            catch (Exception ex)
            {
                Result.Status = false;
                Result.Message = ex.Message;
            }
            return Serialize(Result);
        }
    }
}