Переглянути джерело

公务出访 --> 上传文件 功能优化

LEIYI 10 місяців тому
батько
коміт
c594e4d878
1 змінених файлів з 85 додано та 6 видалено
  1. 85 6
      OASystem/OASystem.Api/Controllers/ResourceController.cs

+ 85 - 6
OASystem/OASystem.Api/Controllers/ResourceController.cs

@@ -1804,7 +1804,7 @@ Inner Join Sys_Department as d With(Nolock) On u.DepId=d.Id Where m.Id={0} ", _m
             }
 
             var oaInfo = await _sqlSugar.Queryable<Res_OfficialActivities>().Where(x => x.Id == dto.id).FirstAsync();
-
+            List<string> files = new List<string>();
             var status = false;
             var _oaInfo = new Res_OfficialActivities()
             {
@@ -1826,22 +1826,36 @@ Inner Join Sys_Department as d With(Nolock) On u.DepId=d.Id Where m.Id={0} ", _m
             }
             else
             {
-                var upd = await _sqlSugar.Updateable<Res_OfficialActivities>()
-                                          .SetColumns(x =>  x.ScreenshotOfMailUrl == JsonConvert.SerializeObject(fileUrls))
+
+                var oldFiles = JsonConvert.DeserializeObject<List<string>>(oaInfo.ScreenshotOfMailUrl);
+
+                if (oldFiles.Count > 0)
+                {
+                    fileUrls.AddRange(oldFiles);
+                }
+
+                fileUrls = fileUrls.Distinct().ToList();
+
+                if (oldFiles.Count()>0)
+                {
+                    var upd = await _sqlSugar.Updateable<Res_OfficialActivities>()
+                                          .SetColumns(x => x.ScreenshotOfMailUrl == JsonConvert.SerializeObject(oldFiles))
                                           .Where(x => x.Id == dto.id)
                                           .ExecuteCommandAsync();
 
-                if (upd > 0) status = true;
+                    if (upd > 0) status = true;
+                }
             }
 
+            List<string> returnFileUrls = new List<string>();
             fileUrls.ForEach(x => {
 
-                x = $"{networkPath}{x}";
+                returnFileUrls.Add( $"{networkPath}{x}");
             });
 
             if (status)
             {
-                return Ok(JsonView(true, "操作成功!", new { id = dto.id, fileUrls = fileUrls } ));
+                return Ok(JsonView(true, "操作成功!", new { id = dto.id, fileUrls = returnFileUrls } ));
             }
             return Ok(JsonView(false, "操作失败!"));
         }
@@ -1882,6 +1896,15 @@ Inner Join Sys_Department as d With(Nolock) On u.DepId=d.Id Where m.Id={0} ", _m
                     var updFile = urls.Remove(filePath);
                     if (updFile)
                     {
+                        //删除文件
+                        string fileUrl = AppSettingsHelper.Get("GrpFileBasePath").Replace(@"/Office/GrpFile", "") + filePath;
+
+                        if (System.IO.File.Exists(fileUrl))
+                        {
+                            System.IO.File.Delete(fileUrl);
+                        }
+
+
                         string urlJsonstr = JsonConvert.SerializeObject(urls);
                         var upd = await _sqlSugar.Updateable<Res_OfficialActivities>()
                                                  .SetColumns(x => x.ScreenshotOfMailUrl == urlJsonstr)
@@ -1896,6 +1919,62 @@ Inner Join Sys_Department as d With(Nolock) On u.DepId=d.Id Where m.Id={0} ", _m
         }
 
 
+        /// <summary>
+        /// 公务出访 确认、取消邀请
+        /// </summary>
+        /// <param name="file"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> OfficialActivitiesDelFile1(OfficialActivitiesDelFileDto dto)
+        {
+            string networkPath = AppSettingsHelper.Get("GrpFileBaseUrl");
+            string localPath = AppSettingsHelper.Get("GrpFileBasePath");
+            string ptfPath = AppSettingsHelper.Get("GrpFileFtpPath");
+            if (dto.Id < 1 || string.IsNullOrEmpty(dto.FileName))
+            {
+                return Ok(JsonView(false, "参数有误,上传失败!"));
+            }
+
+            string localFileDir = $"{localPath}{ptfPath}";
+            List<string> fileUrls = new List<string>();
+
+            var oaInfo = await _sqlSugar.Queryable<Res_OfficialActivities>().Where(x => x.Id == dto.Id).FirstAsync();
+
+            if (oaInfo != null)
+            {
+                string urlJson = oaInfo.ScreenshotOfMailUrl ?? "";
+                if (!string.IsNullOrEmpty(urlJson))
+                {
+                    List<string> urls = JsonConvert.DeserializeObject<List<string>>(urlJson);
+
+                    var filePath = urls.Find(x => x.Contains(dto.FileName));
+                    if (string.IsNullOrEmpty(filePath)) return Ok(JsonView(false, "文件不存在!"));
+
+                    var updFile = urls.Remove(filePath);
+                    if (updFile)
+                    {
+                        //删除文件
+                        string fileUrl = AppSettingsHelper.Get("GrpFileBasePath").Replace(@"/Office/GrpFile", "") + filePath;
+
+                        if (System.IO.File.Exists(fileUrl))
+                        {
+                            System.IO.File.Delete(fileUrl);
+                        }
+
+
+                        string urlJsonstr = JsonConvert.SerializeObject(urls);
+                        var upd = await _sqlSugar.Updateable<Res_OfficialActivities>()
+                                                 .SetColumns(x => x.ScreenshotOfMailUrl == urlJsonstr)
+                                                 .Where(x => x.Id == dto.Id)
+                                                 .ExecuteCommandAsync();
+                        if (upd > 0) return Ok(JsonView(true, "操作成功!"));
+                    }
+                }
+            }
+
+            return Ok(JsonView(false, "操作失败!"));
+        }
 
         /// <summary>
         /// 上传文件