| | |
| | | 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 |
| | |
| | | //[ChannelActionFilter] |
| | | public class ImportExcelController : Controller |
| | | { |
| | | //定义全局信息返回变量 |
| | | ToMessage mes = new ToMessage(); |
| | | |
| | | #region[Excel导入模板列表] |
| | | /// <summary> |
| | |
| | | [HttpGet] |
| | | public JsonResult ExcelModelData() |
| | | { |
| | | ToMessage mes = new ToMessage(); |
| | | List<ScoreReport> list = ExcelList.ExcelData(); |
| | | mes.code = "200"; |
| | | mes.data = list; |
| | |
| | | [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"; |
| | |
| | | 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 = ExcelCheckData(myModel); //数据验证 |
| | | //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 |
| | | } |
| | | } |