EquipmentDocController.cs 2.33 KB
using HHECS.Application.Service;
using HHECS.Infrastructure.Json;
using HHECS.Model.Entities;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.IdentityModel.Tokens.Jwt;
using System.IO;

namespace HHECS.Web.Areas.EquipmentInfo.Controllers
{
    [Area("EquipmentInfo")]
    public class EquipmentDocController : BaseController
    {
        private readonly EquipmentDocService _docService;

        public EquipmentDocController(EquipmentDocService docService)
        {
            _docService = docService;
        }

        [ServiceFilter(typeof(OperLogFilter))]
        public IActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public string Load(PageReq pageRequest, EquipmentDoc entity)
        {
            return _docService.GetEquipmentDoc(entity, pageRequest.page, pageRequest.limit);
        }

        /// <summary>
        /// 修改数据
        /// </summary>
        /// <param name="entity">修改实例</param>
        /// <returns></returns>
        [HttpPost]
        [XSSFilter]
        [ServiceFilter(typeof(OperLogFilter))]
        public string Upd(EquipmentDoc entity)
        {
            return _docService.Update(entity, User);
        }

        [HttpPost]
        [XSSFilter]
        [ServiceFilter(typeof(OperLogFilter))]
        public string DelByIds(int[] ids)
        {
            return _docService.DeleteByIds(ids);
        }

        /// <summary>
        /// 导入数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public string Import(EquipmentDoc equipmentDoc)
        {
            return _docService.AddOrUpdate(equipmentDoc, User);
        }

        [HttpGet, HttpPost]
        public IActionResult Download(string fileName)
        {
            try
            {
                var fileStream = _docService.GetFileStreamByName(fileName,out string docName );
                return File(fileStream, "application/octet-stream", $"{docName}");
            }
            catch (Exception ex)
            {
                return NotFound(ex.Message);
            }
        }

        [HttpGet]
        [ResponseCache(Duration =20)]
        public string GetTreeList()
        {
            var data = _docService.GetTreeList();
            return JsonHelper.Instance.Serialize(data);
        }
    }
}