Explorar el Código

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

yuanrf hace 4 meses
padre
commit
e6029859be

+ 106 - 13
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -2,6 +2,7 @@
 using Aspose.Words;
 using Aspose.Words.Drawing;
 using Aspose.Words.Tables;
+using EyeSoft.Collections.Generic;
 using EyeSoft.IO;
 using Microsoft.AspNetCore.SignalR;
 using MySqlX.XDevAPI.Relational;
@@ -3801,6 +3802,8 @@ FROM
             try
             {
                 var TypeName = Request.Headers["TypeName"].ToString();
+                if (string.IsNullOrEmpty(TypeName)) return Ok(JsonView(false, "请选择选组对应模块!"));
+
                 string filePath = "";
                 var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
                 // 返回与指定虚拟路径相对应的物理路径即绝对路径
@@ -3821,20 +3824,49 @@ FROM
                     filePath = fileDir + "/商邀相关文件/" + dto.fileName;
                     // 删除该文件
                     System.IO.File.Delete(filePath);
-                    id = await _sqlSugar.Updateable<Grp_InvitationOfficialActivities>()
-                        .Where(a => a.Id == dto.Id)
-                        .SetColumns(a => new Grp_InvitationOfficialActivities { Attachment = "" })
-                        .ExecuteCommandAsync();
-                }
+
+                    var info = await _sqlSugar.Queryable<Grp_InvitationOfficialActivities>().Where(x => x.Id == dto.Id && x.IsDel == 0).FirstAsync();
+                    if (info != null)
+                    {
+                        string[] files = new string[] { };
+                        if (!string.IsNullOrEmpty(info.Attachment))
+                        {
+                            try
+                            {
+                                files = JsonConvert.DeserializeObject<string[]>(info.Attachment);
+                            }
+                            catch (Exception)
+                            {
+
+                            files = new List<string>() { info.Attachment }.ToArray();
+                            }
+                        }
+                        if (files.Length > 0)
+                        {
+                            var files1 = files.Where(x => !x.Equals(dto.fileName)).ToArray();
+
+                            string filePath2 = string.Empty;
+                            if (files1.Length > 0)
+                            {
+                                filePath2 = JsonConvert.SerializeObject( files1);
+                            }
+
+                            id = await _sqlSugar.Updateable<Grp_InvitationOfficialActivities>()
+                                                .Where(a => a.Id == dto.Id)
+                                                .SetColumns(a => new Grp_InvitationOfficialActivities { Attachment = filePath2 })
+                                                .ExecuteCommandAsync();
+                        }
+                    }
+            }
                 if (id != 0)
-                {
-                    return Ok(JsonView(true, "成功!"));
-                }
-                else
-                {
-                    return Ok(JsonView(false, "失败!"));
-                }
+            {
+                return Ok(JsonView(true, "成功!"));
+            }
+            else
+            {
+                return Ok(JsonView(false, "失败!"));
             }
+        }
             catch (Exception ex)
             {
                 return Ok(JsonView(false, "程序错误!"));
@@ -3925,7 +3957,68 @@ FROM
             return Ok(JsonView(true, groupData.Msg, groupData.Data));
         }
 
-        
+
+        /// <summary>
+        /// 商邀费用列表
+        /// 下载文件
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpGet("{id}")]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> InvitationOfficialActivitiesListDownFile(int id)
+        {
+            if (id < 1) return Ok(JsonView(false, "请传入有效的Id!"));
+
+            var info = await _InvitationOfficialActivitiesRep.Query(x => x.Id == id).FirstAsync();
+
+            if (info == null) return Ok(JsonView(false, "数据不存在!"));
+
+            if (string.IsNullOrEmpty(info.Attachment)) return Ok(JsonView(false, "文件不存在!"));
+
+            var filePaths = new List<string>();
+            var filePathBase = @$"{AppSettingsHelper.Get("GrpFileBasePath")}/商邀相关文件/";
+            try
+            {
+                filePaths = JsonConvert.DeserializeObject<List<string>>(info.Attachment);
+            }
+            catch (Exception ex)
+            {
+
+                filePaths.Add(info.Attachment);
+            }
+
+            if (filePaths != null && filePaths.Count < 1) return Ok(JsonView(false, "文件不存在!"));
+
+            for (int i = 0; i < filePaths.Count; i++)
+            {
+                filePaths[i] = $"{filePathBase}{filePaths[i]}";
+            }
+
+            var zipFilePathGuid = $"{Guid.NewGuid()}.zip";
+            var zipFilePath = $"{AppSettingsHelper.Get("GrpFileBasePath")}/商邀相关文件/{zipFilePathGuid}";
+            using (FileStream zipFileStream = new FileStream(zipFilePath, FileMode.Create))
+            {
+                using (ZipArchive zipArchive = new ZipArchive(zipFileStream, ZipArchiveMode.Create))
+                {
+                    foreach (string filePath in filePaths)
+                    {
+                        if (System.IO.File.Exists(filePath))
+                        {
+                            // 获取文件名
+                            string fileName = Path.GetFileName(filePath);
+                            // 将文件添加到ZIP归档中
+                            zipArchive.CreateEntryFromFile(filePath, fileName);
+                        }
+                    }
+                }
+            }
+
+            return Ok(JsonView(new {url = @$"{AppSettingsHelper.Get("OfficeBaseUrl")}{AppSettingsHelper.Get("GrpFileFtpPath")}/商邀相关文件/{zipFilePathGuid}" }));
+        }
+
+
+
         /// <summary>
         /// 商邀费用 Info Page 基础数据源
         /// </summary>

+ 2 - 2
OASystem/OASystem.Domain/ViewModels/Groups/InvitationOfficialActivitiesByIdView.cs

@@ -104,7 +104,7 @@ namespace OASystem.Domain.ViewModels.Groups
                     catch (Exception)
                     {
 
-                        array.AddRange(new string[] { Attachment });
+                        array = new List<string>() { Attachment }.ToArray();
                     }
                 }
                 return array;
@@ -227,7 +227,7 @@ namespace OASystem.Domain.ViewModels.Groups
                     catch (Exception)
                     {
 
-                        array.AddRange(new string[] { Attachment });
+                        array = new List<string>() { Attachment }.ToArray();
                     }
                 }
                 return array;

+ 1 - 2
OASystem/OASystem.Domain/ViewModels/Groups/InvitationOfficialActivitiesView.cs

@@ -109,8 +109,7 @@ namespace OASystem.Domain.ViewModels.Groups
                     }
                     catch (Exception)
                     {
-
-                        array.AddRange(new string[] { Attachment });
+                        array = new List<string>() { Attachment }.ToArray();
                     }
                 }
                 return array;