From 0b26067b6cc5d531938fa79cb540a45e125261d2 Mon Sep 17 00:00:00 2001
From: yl <ykxkd@outlook.com>
Date: 星期五, 12 一月 2024 14:55:54 +0800
Subject: [PATCH] 1.App版本升级接口 2.模具清单新增、导入添加仓库、库位字段 3.MES工单查询增加明细id关联

---
 VueWebCoreApi/Controllers/ImportExcelController.cs |  171 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 168 insertions(+), 3 deletions(-)

diff --git a/VueWebCoreApi/Controllers/ImportExcelController.cs b/VueWebCoreApi/Controllers/ImportExcelController.cs
index 2838ec1..1617421 100644
--- a/VueWebCoreApi/Controllers/ImportExcelController.cs
+++ b/VueWebCoreApi/Controllers/ImportExcelController.cs
@@ -1,9 +1,14 @@
-锘縰sing Microsoft.AspNetCore.Mvc;
+锘縰sing Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.Mvc;
 using System;
 using System.Collections.Generic;
+using System.Data;
 using System.IO;
 using System.Linq;
 using System.Threading.Tasks;
+using VueWebCoreApi.DLL.BLL;
+using VueWebCoreApi.Models;
+using VueWebCoreApi.Models.SystemSetting;
 using VueWebCoreApi.Tools;
 
 namespace VueWebCoreApi.Controllers
@@ -14,8 +19,12 @@
     //[ChannelActionFilter]
     public class ImportExcelController : Controller
     {
-        //瀹氫箟鍏ㄥ眬淇℃伅杩斿洖鍙橀噺
-        ToMessage mes = new ToMessage();
+        private readonly IWebHostEnvironment _hostingEnvironment;
+
+        public ImportExcelController(IWebHostEnvironment hostingEnvironment)
+        {
+            _hostingEnvironment = hostingEnvironment;
+        }
 
         #region[Excel瀵煎叆妯℃澘鍒楄〃]
         /// <summary>
@@ -26,6 +35,7 @@
         [HttpGet]
         public JsonResult ExcelModelData()
         {
+            ToMessage mes = new ToMessage();
             List<ScoreReport> list = ExcelList.ExcelData();
             mes.code = "200";
             mes.data = list;
@@ -43,6 +53,7 @@
         [HttpGet]
         public JsonResult DownLoadExcel(string FileCode = null)
         {
+            ToMessage mes = new ToMessage();
             List<ScoreReport> list = ExcelList.ExcelData();
             list = list.Where(s => s.FileCode == FileCode).ToList();
             var filename = list[0].FileName + ".xls";
@@ -51,6 +62,160 @@
             mes.code = "200";
             mes.data = msg;
             return Json(mes);
+
+            //ToMessage mes = new ToMessage();
+            //List<ScoreReport> list = ExcelList.ExcelData();
+            //list = list.Where(s => s.FileCode == FileCode).ToList();
+            //var filename = list[0].FileName + ".xls";
+            //var wwwRootPath = _hostingEnvironment.WebRootPath;
+            //var fileDirectory = Path.Combine(wwwRootPath, "Excel"); // 鏇挎崲涓烘偍鐨凟xcel鏂囦欢鎵�鍦ㄧ洰褰�
+            //var filePath = Path.Combine(fileDirectory, $"{filename}.xlsx"); // 鍋囪鏂囦欢鍚嶇紪鐮佷负鏂囦欢鍚�
+
+            //if (System.IO.File.Exists(filePath))
+            //{
+            //    var fileInfo = new FileInfo(filePath);
+            //    var result = new
+            //    {
+            //        FileName = fileInfo.Name,
+            //        FilePath = filePath,
+            //        FileSize = fileInfo.Length
+            //    };
+            //    return Json(result);
+            //}
+            //else
+            //{
+            //    mes.code = "300";
+            //    mes.data = "";
+            //    mes.message = "鏂囦欢涓嶅瓨鍦�";
+            //}
+            //return Json(mes);
+        }
+        #endregion
+
+        #region [Excel瀵煎叆鏁版嵁鎻愪氦銆佹ā鏉块獙璇併�佹暟鎹鍏
+        /// <summary>
+        /// Excel瀵煎叆鏁版嵁鎻愪氦銆佹ā鏉块獙璇併�佹暟鎹鍏�
+        /// </summary>
+        /// <param name="myModel">鎻愪氦鏁版嵁</param>
+        /// <returns></returns>
+        [Route(template: "ExcelModelCheck")]
+        [HttpPost]
+        public JsonResult ExcelModelCheck([FromBody] ExceImport myModel)
+        {
+            string FileCode = myModel.FileCode;
+            List<DataTable> dataTable = myModel.TableData;
+
+            ExcelModelCheck list = new ExcelModelCheck();
+            list.json1 = ExcelCheck(dataTable, FileCode);  //妯℃澘楠岃瘉
+            if (list.json1.code == "301")
+            {
+                list.json1 = list.json1;
+                return Json(list);
+            }
+            list.json2 = ExcelCheckData(myModel);  //鏁版嵁楠岃瘉
+            if (list.json2.code == "301")
+            {
+                list.json2 = list.json2;
+                return Json(list);
+            }
+            list.json3 = ExcelImportSubmit(dataTable, FileCode);  //鏁版嵁瀵煎叆
+            if (list.json3.code == "300")
+            {
+                list.json3 = list.json3;
+                return Json(list);
+            }
+            return Json(list);
+        }
+        #endregion
+
+        #region [Excel瀵煎叆妯℃澘楠岃瘉]
+        /// <summary>
+        /// Excel瀵煎叆妯℃澘楠岃瘉
+        /// </summary>
+        /// <param name="dataTable">鎻愪氦鏁版嵁</param>
+        /// <param name="FileCode">鏂囦欢缂栫爜</param>
+        /// <returns></returns>
+        [Route(template: "ExcelCheckUpload")]
+        [HttpGet]
+        [ApiExplorerSettings(IgnoreApi = true)]
+        public ToMessage ExcelCheck(List<DataTable> dataTable, string FileCode = null)
+        {
+            ToMessage mes = new ToMessage();
+            try
+            {
+                mes = ExcelCheckBLL.ExcelCheck(FileCode, dataTable);
+                if (mes.code == "301") //涓婁紶妯℃澘涓嶆槸鎸囧畾妯℃澘
+                {
+                    return mes;
+                }
+                return mes;
+            }
+            catch (Exception e)
+            {
+                mes.code = "300";
+                mes.message = e.Message;
+            }
+            return mes;
+        }
+        #endregion
+
+        #region [Excel瀵煎叆鏁版嵁楠岃瘉]
+        /// <summary>
+        /// Excel瀵煎叆鏁版嵁楠岃瘉
+        /// </summary>
+        /// <param name="myModel">鎻愪氦鏁版嵁</param>
+        /// <returns></returns>
+        [Route(template: "ExcelCheckData")]
+        [HttpPost]
+        [ApiExplorerSettings(IgnoreApi = true)]
+        public ToMessage ExcelCheckData([FromBody] ExceImport myModel)
+        {
+            ToMessage mes = new ToMessage();
+            string message = "";
+            string StuCode = "";
+            int count = 0;
+            List<ExcelErro> list = new List<ExcelErro>();
+            string FileCode = myModel.FileCode;
+            List<DataTable> dataTable = myModel.TableData;
+            list = ExcelCheckBLL.ExcelCheckData(FileCode, dataTable, out StuCode, out message, out count);
+            mes.code = StuCode;
+            mes.message = message;
+            mes.count = count;
+            mes.data = list;
+            return mes;
+        }
+        #endregion
+
+        #region[Excel瀵煎叆鏁版嵁]
+        /// <summary>
+        /// Excel瀵煎叆鏁版嵁
+        /// </summary>
+        /// <param name="dataTable">鎻愪氦鏁版嵁</param>
+        /// <param name="FileCode">鏂囦欢缂栫爜</param>
+        /// <returns></returns>
+        [Route(template: "ExcelImportSubmit")]
+        [HttpPost]
+        [ApiExplorerSettings(IgnoreApi = true)]
+        public ToMessage ExcelImportSubmit(List<DataTable> dataTable, string FileCode = null)
+        {
+            ToMessage mes = new ToMessage();
+            try
+            {
+                var token = HttpContext.Request.Headers["Token"].ToString();
+                User us = JwtTools.Denocode(token.ToString());
+                mes = ExcelCheckBLL.ExcelImportSubmit(FileCode, dataTable, us);
+                if (mes.code == "300") 
+                {
+                    return mes;
+                }
+                return mes;
+            }
+            catch (Exception e)
+            {
+                mes.code = "300";
+                mes.message = e.Message;
+            }
+            return mes;
         }
         #endregion
     }

--
Gitblit v1.9.3