diff --git a/ds-wms-service/DS.WMS.Core/Op/Interface/IOpFileService.cs b/ds-wms-service/DS.WMS.Core/Op/Interface/IOpFileService.cs
index a9b337b6..092fb053 100644
--- a/ds-wms-service/DS.WMS.Core/Op/Interface/IOpFileService.cs
+++ b/ds-wms-service/DS.WMS.Core/Op/Interface/IOpFileService.cs
@@ -55,5 +55,13 @@ namespace DS.WMS.Core.Op.Interface
///
///
public DataResult GetOpFileDownLoad(string id);
+
+ ///
+ /// 添加附件-测试
+ ///
+ ///
+ ///
+ ///
+ public Task> AddMultiFilesTest(IFormCollection formCollection, [FromForm] OpFileReq req);
}
}
diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/OpFileService.cs b/ds-wms-service/DS.WMS.Core/Op/Method/OpFileService.cs
index dd9fe0d3..3cd93259 100644
--- a/ds-wms-service/DS.WMS.Core/Op/Method/OpFileService.cs
+++ b/ds-wms-service/DS.WMS.Core/Op/Method/OpFileService.cs
@@ -18,6 +18,7 @@ using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Web;
@@ -186,6 +187,91 @@ namespace DS.WMS.Core.Op.Method
return await Task.FromResult(DataResult.Success(string.Join(",",filesPath.ToArray())));
//return await Task.FromResult(DataResult.Success(fileRelaPath));
}
+
+ ///
+ /// 添加附件-测试
+ ///
+ ///
+ ///
+ ///
+ public async Task> AddMultiFilesTest(IFormCollection formCollection, [FromForm] OpFileReq req)
+ {
+ var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
+ //文件集合
+ FormFileCollection fileCollection = (FormFileCollection)formCollection.Files;
+ //未上传文件
+ if (fileCollection == null || fileCollection.Count == 0)
+ {
+ return await Task.FromResult(DataResult.Failed("附件不存在!"));
+ }
+
+ var limitFiles = AppSetting.app(new string[] { "FileSettings", "FileType" });
+ //var basePath = AppSetting.app(new string[] { "FileSettings", "BasePath" });
+ var basePath = @"\\\\66a1249094-ckl94.cn-qingdao.nas.aliyuncs.com\\myshare\\ds8WebFiles";
+ var relativePath = AppSetting.app(new string[] { "FileSettings", "RelativePath" });
+ var filesPath = new List();
+
+ // 用户名和密码
+ string username = "administrator";
+ string password = "Dctz989898";
+
+ // 使用Windows凭据进行身份验证
+ NetworkCredential credentials = new NetworkCredential(username, password);
+ CredentialCache credentialCache = new CredentialCache();
+ credentialCache.Add(new Uri(basePath), "Basic", credentials);
+
+ foreach (IFormFile file in fileCollection)
+ {
+ var originalFilename = file.FileName; // 文件原始名称
+ var fileSuffix = Path.GetExtension(file.FileName).ToLower(); // 文件后缀
+ if (!limitFiles.Contains(fileSuffix))
+ {
+ return await Task.FromResult(DataResult.Failed("不允许的文件类型!"));
+ }
+ var dirAbs = string.Empty;
+ var fileRelaPath = string.Empty;
+ var fileAbsPath = string.Empty;
+ if (string.IsNullOrEmpty(basePath))
+ {
+ dirAbs = Path.Combine(_environment.WebRootPath, relativePath);
+ }
+ else
+ {
+ dirAbs = Path.Combine(basePath, relativePath);
+ }
+
+ if (!Directory.Exists(dirAbs))
+ Directory.CreateDirectory(dirAbs);
+ // 先存库获取Id
+ var id = SnowFlakeSingle.Instance.NextId();
+ var fileSaveName = $"{id}{fileSuffix}".ToLower();
+ fileRelaPath = Path.Combine(relativePath, fileSaveName).ToLower();
+ fileAbsPath = Path.Combine(dirAbs, fileSaveName).ToLower();
+ var newFile = new OpFile
+ {
+ Id = id,
+ FileName = originalFilename,
+ FilePath = fileSaveName,
+ TypeCode = req.TypeCode,
+ TypeName = req.TypeName,
+ LinkId = req.LinkId,
+ FileSize = file.Length.ToInt(),
+ FileType = Path.GetExtension(originalFilename),
+ Extension = Path.GetExtension(originalFilename),
+ Note = req.Note,
+
+ };
+ await tenantDb.Insertable(newFile).ExecuteCommandAsync();
+
+ using (var stream = File.Create(fileAbsPath))
+ {
+ await file.CopyToAsync(stream);
+ }
+ filesPath.Add(fileSaveName);
+ }
+ return await Task.FromResult(DataResult.Success(string.Join(",", filesPath.ToArray())));
+ //return await Task.FromResult(DataResult.Success(fileRelaPath));
+ }
///
/// 获取业务附件
///
diff --git a/ds-wms-service/DS.WMS.MainApi/Controllers/OpFileController.cs b/ds-wms-service/DS.WMS.MainApi/Controllers/OpFileController.cs
index 626e8a68..73297baa 100644
--- a/ds-wms-service/DS.WMS.MainApi/Controllers/OpFileController.cs
+++ b/ds-wms-service/DS.WMS.MainApi/Controllers/OpFileController.cs
@@ -122,5 +122,17 @@ public class OpFileController : ApiController
};
}
-
+ ///
+ /// 多附件上传-测试
+ ///
+ /// 文件信息
+ /// 业务附件请求实体
+ ///
+ [HttpPost]
+ [Route("AddMultiFilesTest")]
+ public async Task> AddMultiFilesTest(IFormCollection formCollection, [FromForm] OpFileReq req)
+ {
+ var res = _invokeService.AddMultiFilesTest(formCollection, req);
+ return await res;
+ }
}
\ No newline at end of file