LEIYI 8 ヶ月 前
コミット
413e77089b
共有1 個のファイルを変更した73 個の追加10 個の削除を含む
  1. 73 10
      OASystem/OASystem.Api/Controllers/GroupsController.cs

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

@@ -3802,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");
                 // 返回与指定虚拟路径相对应的物理路径即绝对路径
@@ -3836,7 +3838,7 @@ FROM
                             catch (Exception)
                             {
 
-                                files.AddRange(new string[] { info.Attachment });
+                            files = new List<string>() { info.Attachment }.ToArray();
                             }
                         }
                         if (files.Length > 0)
@@ -3856,16 +3858,16 @@ FROM
                                                 .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, "程序错误!"));
@@ -3956,7 +3958,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>