Browse Source

文件上传添加

yuanrf 8 months ago
parent
commit
1071a97cd6

+ 4 - 1
OASystem/EntitySync/EntitySync.csproj

@@ -10,7 +10,10 @@
   <ItemGroup>
     <PackageReference Include="Autofac" Version="6.4.0" />
     <PackageReference Include="Autofac.Extensions.DependencyInjection" Version="8.0.0" />
-    <PackageReference Include="SqlSugarCore" Version="5.1.3.32" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="..\OASystem.Api\OASystem.API.csproj" />
   </ItemGroup>
 
 </Project>

+ 1 - 0
OASystem/EntitySync/Program.cs

@@ -138,6 +138,7 @@ db.CodeFirst.SetStringDefaultLength(50).BackupTable().InitTables(new Type[]
      //typeof(Sys_Countries),  //洲
      //typeof(Sys_Continent),  //国家
      typeof(Sys_Cities),  //城市
+     typeof(Grp_GroupModelFile),//团组文件
 
 });
 Console.WriteLine("数据库结构同步完成!");

+ 92 - 0
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -89,6 +89,7 @@ using K4os.Compression.LZ4.Internal;
 using static Pipelines.Sockets.Unofficial.SocketConnection;
 using System.Diagnostics.PerformanceData;
 using System.Drawing.Printing;
+using OASystem.Domain.Dtos.FileDto;
 
 namespace OASystem.API.Controllers
 {
@@ -3528,6 +3529,97 @@ namespace OASystem.API.Controllers
             }
         }
 
+        /// <summary>
+        /// 团组模块文件上传
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        public IActionResult CommonSaveFile([FromForm] CommonSaveFileDto dto)
+        {
+            var jw = JsonView(false);
+
+            if (dto.File == null)
+            {
+                jw.Msg = "无文件信息!";
+                return Ok(jw);
+            }
+
+            var nameSp = dto.File.Name.Split(".");
+            if (nameSp.Length < 2)
+            {
+                jw.Msg = "拓展名称有误!";
+                return Ok(jw);
+            }
+
+            var existsName = new string[]{ "RAR", "ZIP", "ARJ","GZ","Z","7Z","TAR" };
+            if (!existsName.Contains(nameSp[1].ToUpper()))
+            {
+                jw.Msg = $"请使用指定拓展名!({string.Join("-",existsName)})";
+                return Ok(jw);
+            }
+
+            var Ctable = _sqlSugar.Queryable<Sys_SetData>().First(x => x.STid == 16 && x.IsDel == 0 && x.Id == dto.Ctable);
+            if (Ctable == null)
+            {
+                jw.Msg = "Ctable指向有误!";
+                return Ok(jw);
+            }
+
+            var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid && x.IsDel == 0);
+            if (groupInfo == null)
+            {
+                jw.Msg = "团组信息不存在!";
+                return Ok(jw);
+            }
+
+            var path = "\\GroupModelFiles\\" + groupInfo.TeamName + "\\" + Ctable.Name;
+            var fileBase = AppSettingsHelper.Get("GrpFileBasePath") + path;
+
+            try
+            {
+                if (!Directory.Exists(fileBase))
+                {
+                    Directory.CreateDirectory(fileBase);
+                }
+
+                var saveFilePath = fileBase + dto.File.Name;
+
+                Grp_GroupModelFile file = new Grp_GroupModelFile()
+                {
+                    Cid = dto.Cid,
+                    CreateTime = DateTime.Now,
+                    CreateUserId = dto.Userid,
+                    Ctable = dto.Ctable,
+                    Diid = dto.Diid,
+                    IsDel = 0,
+                    FilePath = saveFilePath,
+                };
+
+                using (FileStream fs = System.IO.File.Create(saveFilePath))
+                {
+                    dto.File.CopyTo(fs);
+                    fs.Flush();
+                }
+
+                var addResult = _sqlSugar.Insertable<Grp_GroupModelFile>(file).ExecuteCommand();
+
+                jw = JsonView(true, "保存成功!", new
+                {
+                    url = AppSettingsHelper.Get("WordBaseUrl") + AppSettingsHelper.Get("GrpFileFtpPath") + path
+                }) ;
+            }
+            catch (Exception ex)
+            {
+                jw = JsonView(false, $"保存失败! ({ex.Message}) ", new
+                {
+                    url = ""
+                }) ;
+            }
+
+            return Ok(jw);
+        }
+
         #endregion
 
         #region 团组英文资料

+ 1 - 0
OASystem/OASystem.Api/appsettings.json

@@ -120,6 +120,7 @@
 
   "GrpFileBaseUrl": "http://132.232.92.186:24/",
   "GrpFileBasePath": "C:/Server/File/OA2023/Office/GrpFile/",
+  "GrpFileFtpPath": "Office/GrpFile/",
 
   "VisaProgressImageBaseUrl": "http://132.232.92.186:24/",
   "VisaProgressImageBasePath": "C:/Server/File/OA2023/Image/Visa/",

+ 10 - 1
OASystem/OASystem.Domain/Dtos/DtoBase.cs

@@ -90,5 +90,14 @@ namespace OASystem.Domain.Dtos
         public int PageId { get; set; }
     }
 
-   
+    public class CommonSaveFileDto
+    {
+        public IFormFile File { get; set; }
+        public int Ctable { get; set; }
+        public int Diid { get; set; }
+
+        public int Cid { get; set; }
+
+        public int Userid { get; set; }
+    }
 }

+ 23 - 0
OASystem/OASystem.Domain/Entities/Groups/GroupModelFile.cs

@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.Entities.Groups
+{
+    /// <summary>
+    /// 团组模块文件
+    /// </summary>
+    public class Grp_GroupModelFile: EntityBase
+    {
+        public int Diid { get; set; }
+
+        [SugarColumn(IsNullable = true, ColumnDataType = "nvarchar(150)")]
+        public string FilePath { get; set; }
+
+        public int Ctable { get; set; }
+
+        public int Cid { get; set; }
+    }
+}