From b2ad000e07e1c87d3561b5aa94fdc88c779872f0 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期二, 18 二月 2025 22:34:54 +0800
Subject: [PATCH] 1

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseController/ApiBaseController.cs |  117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 117 insertions(+), 0 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseController/ApiBaseController.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseController/ApiBaseController.cs"
new file mode 100644
index 0000000..4ecf1f0
--- /dev/null
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseController/ApiBaseController.cs"
@@ -0,0 +1,117 @@
+锘縰sing Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Options;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using WIDESEA_Core.BaseServices;
+
+namespace WIDESEA_Core.BaseController
+{
+    [Authorize, ApiController]
+    public class ApiBaseController<IService, TEntity> : Controller
+    {
+        protected IService Service;
+
+        public ApiBaseController(IService service)
+        {
+            Service = service;
+        }
+
+        [HttpPost, Route("GetPageData")]
+        public virtual ActionResult GetPageData([FromBody] PageDataOptions options)
+        {
+            return Json(InvokeService("GetPageData", new object[] { options }));
+        }
+
+        [HttpPost, Route("GetDetailPage")]
+        public virtual ActionResult GetDetailPage([FromBody] PageDataOptions pageData)
+        {
+            return Json(InvokeService("GetDetailPage", new object[] { pageData }));
+        }
+
+        [HttpPost, Route("AddData")]
+        public virtual ActionResult AddData([FromBody] TEntity options)
+        {
+            return Json(InvokeService("AddData", new object[] { options }));
+        }
+
+        [HttpPost, Route("Add")]
+        public virtual ActionResult Add([FromBody] SaveModel options)
+        {
+            return Json(InvokeService("AddData", new object[] { options }));
+        }
+
+        [HttpPost, Route("Update")]
+        public virtual ActionResult Update([FromBody] SaveModel options)
+        {
+            return Json(InvokeService("UpdateData", new object[] { options }));
+        }
+
+        [HttpPost, Route("UpdateData")]
+        public virtual ActionResult UpdateData([FromBody] TEntity options)
+        {
+            return Json(InvokeService("UpdateData", new object[] { options }));
+        }
+
+        [HttpPost, Route("Del")]
+        public virtual ActionResult Del([FromBody] object[] key)
+        {
+            return Json(InvokeService("DeleteData", new object[] { key }));
+        }
+
+        [HttpPost, Route("Export")]
+        public virtual ActionResult Export([FromBody] PageDataOptions loadData)
+        {
+            WebResponseContent result = InvokeService("Export", new object[] { loadData }) as WebResponseContent;
+            if (result.Status)
+                return File(
+                       System.IO.File.ReadAllBytes(result.Data.ToString()),
+                       System.Net.Mime.MediaTypeNames.Application.Octet,
+                       Path.GetFileName(result.Data.ToString())
+                   );
+            return Json(result);
+        }
+
+        [HttpPost, HttpGet, Route("DownLoadTemplate")]
+        public virtual ActionResult DownLoadTemplate()
+        {
+            WebResponseContent result = InvokeService("DownLoadTemplate", new object[] { }) as WebResponseContent;
+            if (result.Status)
+                return File(
+                       System.IO.File.ReadAllBytes(result.Data.ToString()),
+                       System.Net.Mime.MediaTypeNames.Application.Octet,
+                       Path.GetFileName(result.Data.ToString())
+                   );
+            return Json(result);
+        }
+
+        [HttpPost, Route("Import")]
+        public virtual ActionResult Import(List<IFormFile> fileInput)
+        {
+            return Json(InvokeService("Import", new object[] { fileInput }));
+        }
+
+        [HttpPost, Route("ExportSeedData"), AllowAnonymous]
+        public ActionResult ExportSeedData()
+        {
+            return Json(InvokeService("ExportSeedData", new object[] { }));
+        }
+
+        private object InvokeService(string methodName, object[] parameters)
+        {
+            Type t = Service.GetType();
+            List<Type> types = new List<Type>();
+            foreach (var param in parameters)
+            {
+                types.Add(param.GetType());
+            }
+            MethodInfo method = t.GetMethod(methodName, types.ToArray());
+            return method.Invoke(Service, parameters);
+        }
+    }
+}

--
Gitblit v1.9.3