From 63f4ffa7a4e4986fc4d70072931430eae8f5c802 Mon Sep 17 00:00:00 2001 From: wet <1034391973@qq.com> Date: Sat, 6 May 2023 09:27:06 +0800 Subject: [PATCH] 1 --- .../Service/DataSync/DataSyncService.cs | 72 +++++++++++++++++-- 1 file changed, 67 insertions(+), 5 deletions(-) diff --git a/Myshipping.Application/Service/DataSync/DataSyncService.cs b/Myshipping.Application/Service/DataSync/DataSyncService.cs index 81dd49e7..7a5a390d 100644 --- a/Myshipping.Application/Service/DataSync/DataSyncService.cs +++ b/Myshipping.Application/Service/DataSync/DataSyncService.cs @@ -32,6 +32,8 @@ using Myshipping.Core.Service; using System.Reflection.Emit; using Myshipping.Application.Service.DataSync.Dto; using Newtonsoft.Json.Linq; +using Myshipping.Application.Service.BookingOrder.Dto; +using Myshipping.Application.Enum; namespace Myshipping.Application { @@ -64,6 +66,7 @@ namespace Myshipping.Application private readonly SqlSugarRepository _relaPortLane; private readonly ICommonDBService _commonDBService; private readonly SqlSugarRepository _codeForwarder; + private readonly SqlSugarRepository _bookingfile; private readonly SqlSugarRepository _accountconfig; @@ -75,7 +78,7 @@ namespace Myshipping.Application SqlSugarRepository goodsStatus, SqlSugarRepository goodsStatusConfig, SqlSugarRepository repline, SqlSugarRepository bookingremark, SqlSugarRepository mapcarrier, SqlSugarRepository codeForwarder, SqlSugarRepository codePortRep, SqlSugarRepository codeLaneRep, ICommonDBService commonDBService, SqlSugarRepository relaPortLane, - SqlSugarRepository accountconfig) + SqlSugarRepository accountconfig, SqlSugarRepository bookingfile) { this._logger = logger; this._rep = rep; @@ -100,7 +103,8 @@ namespace Myshipping.Application this._commonDBService = commonDBService; this._relaPortLane = relaPortLane; this._codeForwarder = codeForwarder; - this._accountconfig= accountconfig; + this._accountconfig = accountconfig; + this._bookingfile = bookingfile; } @@ -2080,7 +2084,8 @@ namespace Myshipping.Application accountConfig = await _accountconfig.AsQueryable().InnerJoin((d, t) => d.TenantId == t.TenantId).Where((d, t) => d.TypeCode == TypeCode && t.TenantId == UserManager.TENANT_ID && d.IsTenant == true).FirstAsync(); } - else { + else + { accountConfig = await _accountconfig.FirstOrDefaultAsync(x => x.TypeCode == TypeCode && x.CreatedUserId == UserId); } return accountConfig; @@ -2091,15 +2096,72 @@ namespace Myshipping.Application /// /// [HttpGet("/DataSync/GetParamValue"), ApiUser(ApiCode = "GetParamValue")] - public dynamic GetParamValue() + public dynamic GetParamValue() { - var list = _cache.GetAllTenantParam().Result.Where( x=>x.TenantId == UserManager.TENANT_ID).OrderBy(x => x.Sort).ToList(); + var list = _cache.GetAllTenantParam().Result.Where(x => x.TenantId == UserManager.TENANT_ID).OrderBy(x => x.Sort).ToList(); return list; } + /// + /// 挂载订舱文件 + /// + /// + /// + /// + [HttpPost("/DataSync/AddFile"), ApiUser(ApiCode = "AddFile")] + public async Task AddFile(IFormFile file, [FromForm] BookingFileDto dto) + { + //未上传文件 + if (file == null || file.Length == 0) + { + throw Oops.Bah(BookingErrorCode.BOOK200); + } + var opt = App.GetOptions(); + var originalFilename = file.FileName; // 文件原始名称 + var fileSuffix = Path.GetExtension(file.FileName).ToLower(); // 文件后缀 + if (!opt.fileType.Contains(fileSuffix)) + { + throw Oops.Bah(BookingErrorCode.BOOK114); + } + var dirAbs = string.Empty; + if (string.IsNullOrEmpty(opt.basePath)) + { + dirAbs = Path.Combine(App.WebHostEnvironment.WebRootPath, opt.relativePath); + } + else + { + dirAbs = Path.Combine(opt.basePath, opt.relativePath); + } + + if (!Directory.Exists(dirAbs)) + Directory.CreateDirectory(dirAbs); + + + // 先存库获取Id + var id = YitIdHelper.NextId(); + var fileSaveName = $"{id}{fileSuffix}".ToLower(); + var fileRelaPath = Path.Combine(opt.relativePath, fileSaveName).ToLower(); + var fileAbsPath = Path.Combine(dirAbs, fileSaveName).ToLower(); + var newFile = new BookingFile + { + Id = id, + FileName = originalFilename, + FilePath = fileRelaPath, + TypeCode = dto.TypeCode, + TypeName = dto.TypeName, + BookingId = dto.BookingId, + + }; + await _bookingfile.InsertAsync(newFile); + using (var stream = File.Create(fileAbsPath)) + { + await file.CopyToAsync(stream); + } + + }