yl
2023-09-08 129879f45b1b59f8e1b26c766a80d50f371be385
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
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
{
    [ApiExplorerSettings(GroupName = "Excel导入")]
    [ApiController]
    [Route("api/[controller]")]
    //[ChannelActionFilter]
    public class ImportExcelController : Controller
    {
 
        #region[Excel导入模板列表]
        /// <summary>
        /// Excel导入模板列表
        /// </summary>
        /// <returns></returns>
        [Route(template: "ExcelModelData")]
        [HttpGet]
        public JsonResult ExcelModelData()
        {
            ToMessage mes = new ToMessage();
            List<ScoreReport> list = ExcelList.ExcelData();
            mes.code = "200";
            mes.data = list;
            return Json(mes);
        }
        #endregion
 
        #region [Excel导入模板下载]
        /// <summary>
        /// Excel导入模板下载
        /// </summary>
        /// <param name="FileCode"></param>
        /// <returns></returns>
        [Route(template: "DownLoadExcel")]
        [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";
            string fileip = AppSetting.GetAppSetting("FileIP");
            var msg = fileip + "/Excel/" + filename;
            mes.code = "200";
            mes.data = msg;
            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
    }
}