Browse Source

Merge branch 'develop' of http://132.232.92.186:3000/XinXiBu/OA2023 into develop

amigotrip 7 months ago
parent
commit
c2c6c93c13

+ 117 - 10
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -92,6 +92,7 @@ using System.Drawing.Printing;
 using OASystem.Domain.Dtos.FileDto;
 using Microsoft.VisualBasic;
 using Microsoft.EntityFrameworkCore.Query.Internal;
+using MathNet.Numerics.Distributions;
 
 namespace OASystem.API.Controllers
 {
@@ -3694,7 +3695,7 @@ namespace OASystem.API.Controllers
             {
                 x.FileName,
                 x.Id,
-                Url =  x.FilePath.Replace(AppSettingsHelper.Get("GrpFileBasePath"), AppSettingsHelper.Get("GrpFileBaseUrl") + AppSettingsHelper.Get("GrpFileFtpPath")),
+                Url = AppSettingsHelper.Get("GrpFileBaseUrl") +  System.Web.HttpUtility.UrlEncode(x.FilePath.Replace(AppSettingsHelper.Get("GrpFileBasePath"),AppSettingsHelper.Get("GrpFileFtpPath")), System.Text.Encoding.UTF8),
             })));
         }
 
@@ -3714,28 +3715,66 @@ namespace OASystem.API.Controllers
                 return Ok(jw);
             }
             var dbQuery = _sqlSugar.Queryable<Grp_GroupModelFile>().Where(x => x.IsDel == 0 && x.Diid == dto.Diid).ToList();
+            var isModule = Convert.ToBoolean(dto.isModule);
 
             Dictionary<string, Stream> Zips = new Dictionary<string, Stream>();
+            IOOperatorHelper io = new IOOperatorHelper();
 
-            foreach (var item in dbQuery)
+            if (isModule)
             {
-                using (FileStream fileStream = new FileStream(item.FilePath, FileMode.Open, FileAccess.Read))
+                var moduleGroup =  dbQuery.GroupBy(x => x.Ctable);
+                foreach (var moduleArr in moduleGroup)
                 {
-                    byte[] bytes = new byte[fileStream.Length];
-                    fileStream.Read(bytes, 0, bytes.Length);
-                    fileStream.Close();
-                    Stream stream = new MemoryStream(bytes);
-                    Zips.Add(item.FileName, stream);
+                    var key = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == moduleArr.Key && x.IsDel == 0);
+                    key.Name = Regex.Replace(key.Name, @"[^\w\.@-]", "",
+                                RegexOptions.None, TimeSpan.FromSeconds(1.5));
+                    Dictionary<string, Stream> chiZips = new Dictionary<string, Stream>();
+                    foreach (var item in moduleArr)
+                    {
+                        if (System.IO.File.Exists(item.FilePath))
+                        {
+                            using (FileStream fileStream = new FileStream(item.FilePath, FileMode.Open, FileAccess.Read))
+                            {
+                                byte[] bytes = new byte[fileStream.Length];
+                                fileStream.Read(bytes, 0, bytes.Length);
+                                fileStream.Close();
+                                Stream stream = new MemoryStream(bytes);
+                                chiZips.Add(item.FileName, stream);
+                            }
+                        }
+                    }
+                    if (chiZips.Count > 0)
+                    {
+                        var byts = io.ConvertZipStream(chiZips);
+                        Stream stream = new MemoryStream(byts);
+                        Zips.Add(key.Name+"_.zip", stream);
+                    }
+                }
+            }
+            else
+            {
+                foreach (var item in dbQuery)
+                {
+                    using (FileStream fileStream = new FileStream(item.FilePath, FileMode.Open, FileAccess.Read))
+                    {
+                        byte[] bytes = new byte[fileStream.Length];
+                        fileStream.Read(bytes, 0, bytes.Length);
+                        fileStream.Close();
+                        Stream stream = new MemoryStream(bytes);
+                        while (Zips.Keys.Contains(item.FileName))
+                        {
+                            item.FileName = new Random().Next(100) + "_" + item.FileName;
+                        }
+                        Zips.Add(item.FileName, stream);
+                    }
                 }
             }
 
             groupInfo.TeamName = Regex.Replace(groupInfo.TeamName, @"[^\w\.@-]", "",
                    RegexOptions.None, TimeSpan.FromSeconds(1.5));
 
-
             if (Zips.Count > 0)
             {
-                IOOperatorHelper io = new IOOperatorHelper();
                 var byts = io.ConvertZipStream(Zips);
                 var path = "\\GroupModelFiles\\" + groupInfo.TeamName;
                 io.ByteToFile(byts, AppSettingsHelper.Get("GrpFileBasePath") + $"{path}\\{groupInfo.TeamName}_.Zip");
@@ -3749,6 +3788,74 @@ namespace OASystem.API.Controllers
             return Ok(jw);
         }
 
+        /// <summary>
+        /// 下载该团组下此模块的所有文件
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        public IActionResult ExportGroupByModule(ExportGroupByModuleDto dto)
+        {
+            var jw = JsonView(false);
+            var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.IsDel == 0 && x.Id == dto.Diid);
+            if (groupInfo == null)
+            {
+                jw.Msg = "团组信息不存在!";
+                return Ok(jw);
+            }
+
+            var dbQuery = _sqlSugar.Queryable<Grp_GroupModelFile>().Where(x => x.IsDel == 0 && x.Diid == dto.Diid && x.Ctable == dto.Ctable).ToList();
+            var key = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == dto.Ctable 
+            && x.IsDel == 0);
+
+            if (key == null)
+            {
+                jw.Msg = "Ctable指向错误!";
+                return Ok(jw);
+            }
+
+            key.Name = Regex.Replace(key.Name, @"[^\w\.@-]", "",
+                              RegexOptions.None, TimeSpan.FromSeconds(1.5));
+            groupInfo.TeamName = Regex.Replace(groupInfo.TeamName, @"[^\w\.@-]", "",
+                  RegexOptions.None, TimeSpan.FromSeconds(1.5));
+
+            IOOperatorHelper io = new IOOperatorHelper();
+            Dictionary<string, Stream> Zips = new Dictionary<string, Stream>();
+
+            foreach (var item in dbQuery)
+            {
+                if (System.IO.File.Exists(item.FilePath))
+                {
+                    using (FileStream fileStream = new FileStream(item.FilePath, FileMode.Open, FileAccess.Read))
+                    {
+                        byte[] bytes = new byte[fileStream.Length];
+                        fileStream.Read(bytes, 0, bytes.Length);
+                        fileStream.Close();
+                        Stream stream = new MemoryStream(bytes);
+                        while (Zips.Keys.Contains(item.FileName))
+                        {
+                            item.FileName = new Random().Next(100) + "_" + item.FileName;
+                        }
+                        Zips.Add(item.FileName, stream);
+                    }
+                }
+            }
+
+            if (Zips.Count > 0)
+            {
+                var byts = io.ConvertZipStream(Zips);
+                var path = "\\GroupModelFiles\\" + groupInfo.TeamName;
+                io.ByteToFile(byts, AppSettingsHelper.Get("GrpFileBasePath") + $"{path}\\{key.Name}_.Zip");
+                jw = JsonView(true, "success", new { url = AppSettingsHelper.Get("GrpFileBaseUrl") + $"{AppSettingsHelper.Get("GrpFileFtpPath")}{path}\\{key.Name}_.zip" });
+            }
+            else
+            {
+                jw.Msg = "暂无生成文件!";
+            }
+
+            return Ok(jw);
+        }
+
         /// <summary>
         /// 删除该团组下的指定文件
         /// </summary>

+ 9 - 0
OASystem/OASystem.Domain/Dtos/FileDto/FileDto.cs

@@ -48,6 +48,15 @@ namespace OASystem.Domain.Dtos.FileDto
     public class ExportGroupZipDto
     {
         public int Diid { get; set; }
+
+        public int isModule { get; set; }
+    }
+
+    public class ExportGroupByModuleDto
+    {
+        public int Ctable { get; set; }
+
+        public int Diid { get;set; }
     }
 
     public class DeleteGroupFileDto