From 8c6fd742db249ad4cc819cf041eb98d880a3ef73 Mon Sep 17 00:00:00 2001 From: hutongqing <hutongqing@hnkhzn.com> Date: 星期四, 02 一月 2025 15:09:07 +0800 Subject: [PATCH] 1 --- WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/DeviceProtocolService.cs | 25 +++++++++++++++++++++++++ 1 files changed, 25 insertions(+), 0 deletions(-) diff --git a/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/DeviceProtocolService.cs b/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/DeviceProtocolService.cs index 82c0830..d14d6bf 100644 --- a/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/DeviceProtocolService.cs +++ b/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/DeviceProtocolService.cs @@ -32,9 +32,16 @@ namespace WIDESEAWCS_QuartzJob.Service { + /// <summary> + /// 璁惧鍗忚淇℃伅涓氬姟灞� + /// </summary> public class DeviceProtocolService : ServiceBase<Dt_DeviceProtocol, IDeviceProtocolRepository>, IDeviceProtocolService { private readonly IUnitOfWorkManage _unitOfWorkManage; + + /// <summary> + /// 璁惧鍗忚淇℃伅涓氬姟灞� + /// </summary> public DeviceProtocolService(IDeviceProtocolRepository BaseDal, IUnitOfWorkManage unitOfWorkManage) : base(BaseDal) { _unitOfWorkManage = unitOfWorkManage; @@ -49,31 +56,49 @@ { 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); } + // 鍒涘缓Excel瀵煎叆鍣� ExcelImporter importer = new ExcelImporter(); + // 瀵煎叆Excel鏂囦欢 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); } } + /// <summary> + /// 娣诲姞鏁版嵁 + /// </summary> + /// <param name="saveModel"></param> + /// <returns></returns> public override WebResponseContent AddData(SaveModel saveModel) { //saveModel.MainData[""] -- Gitblit v1.9.3