| | |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << 版 本 注 释 >> |
| | | |
| | | using Magicodes.ExporterAndImporter.Core.Models; |
| | | using Magicodes.ExporterAndImporter.Excel; |
| | | using Microsoft.AspNetCore.Http; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | using WIDESEAWCS_QuartzJob.Repository; |
| | | |
| | |
| | | { |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | } |
| | | |
| | | public WebResponseContent GetImportData(List<IFormFile> fileInput) |
| | | { |
| | | try |
| | | { |
| | | if (fileInput == null || fileInput.Count == 0) |
| | | return new WebResponseContent { Status = true, Message = "请选择上传的文件" }; |
| | | Microsoft.AspNetCore.Http.IFormFile formFile = fileInput[0]; |
| | | string dicPath = AppDomain.CurrentDomain.BaseDirectory + $"ExcelImprot/{DateTime.Now.ToString("yyyMMdd")}/{typeof(Dt_DeviceProtocol).Name}/"; |
| | | if (!Directory.Exists(dicPath)) Directory.CreateDirectory(dicPath); |
| | | string fileName = $"{Guid.NewGuid()}_{formFile.FileName}"; |
| | | dicPath = $"{dicPath}{fileName}"; |
| | | using (FileStream stream = new FileStream(dicPath, FileMode.Create)) |
| | | { |
| | | formFile.CopyTo(stream); |
| | | } |
| | | ExcelImporter importer = new ExcelImporter(); |
| | | ImportResult<Dt_DeviceProtocol> importResult = importer.Import<Dt_DeviceProtocol>(dicPath, "").Result; |
| | | if (importResult.HasError) |
| | | { |
| | | return WebResponseContent.Instance.Error(importResult.TemplateErrors.Serialize()); |
| | | } |
| | | return WebResponseContent.Instance.OK(data: importResult.Data); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public override WebResponseContent AddData(SaveModel saveModel) |
| | | { |
| | | //saveModel.MainData[""] |
| | | return base.AddData(saveModel); |
| | | } |
| | | } |
| | | } |