Explorar o código

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

Lyyyi hai 15 horas
pai
achega
8114b062da

+ 35 - 26
OASystem/OASystem.Api/Controllers/FinancialController.cs

@@ -6220,33 +6220,42 @@ Group by PriceType ", dto.diId);
                                 {
                                     try
                                     {
-                                        var columnValue = rowCode[i].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
-                                        string day = columnValue[2].Substring(2, 2);//日
-                                        string monthAbbreviations = columnValue[2].Substring(4, 3).ToUpper();//月份
-                                        monthAbbreviations = GeneralMethod.GetLonger(monthAbbreviations);
-                                        string EndHHmm = columnValue[5].Substring(0, 2) + ":" + columnValue[5].Substring(2, 2);
-                                        DateTime EndData = DateTime.Parse($"{DateTime.Now.Year}-{monthAbbreviations}-{day} {EndHHmm}");//当前班次
-
-                                        var spDotandEmpty1 = rowCode[i - 1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
-                                        string day1 = spDotandEmpty1[2].Substring(2, 2);//日
-                                        string monthAbbreviations1 = spDotandEmpty1[2].Substring(4, 3).ToUpper();//月份
-                                        monthAbbreviations1 = GeneralMethod.GetLonger(monthAbbreviations1);
-                                        string HHmm = spDotandEmpty1[6].Substring(0, 2) + ":" + spDotandEmpty1[6].Substring(2, 2);
-                                        DateTime data = DateTime.Parse($"{DateTime.Now.Year}-{monthAbbreviations1}-{day1} {HHmm}");//上个班次
-
-                                        TimeSpan t3 = EndData - data;  //两个时间相减 。默认得到的是 两个时间之间的天数   得到:365.00:00:00  
-                                        double getHour = t3.TotalHours;
-
-                                        if (getHour >= 6)
+                                        //var columnValue = rowCode[i].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
+                                        //string day = columnValue[2].Substring(2, 2);//日
+                                        //string monthAbbreviations = columnValue[2].Substring(4, 3).ToUpper();//月份
+                                        //monthAbbreviations = GeneralMethod.GetLonger(monthAbbreviations);
+                                        //string EndHHmm = columnValue[5].Substring(0, 2) + ":" + columnValue[5].Substring(2, 2);
+                                        //DateTime EndData = DateTime.Parse($"{DateTime.Now.Year}-{monthAbbreviations}-{day} {EndHHmm}");//当前班次
+
+                                        //var spDotandEmpty1 = rowCode[i - 1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
+                                        //string day1 = spDotandEmpty1[2].Substring(2, 2);//日
+                                        //string monthAbbreviations1 = spDotandEmpty1[2].Substring(4, 3).ToUpper();//月份
+                                        //monthAbbreviations1 = GeneralMethod.GetLonger(monthAbbreviations1);
+                                        //string HHmm = spDotandEmpty1[6].Substring(0, 2) + ":" + spDotandEmpty1[6].Substring(2, 2);
+                                        //DateTime data = DateTime.Parse($"{DateTime.Now.Year}-{monthAbbreviations1}-{day1} {HHmm}");//上个班次
+
+                                        //TimeSpan t3 = EndData - data;  //两个时间相减 。默认得到的是 两个时间之间的天数   得到:365.00:00:00  
+                                        //double getHour = t3.TotalHours;
+
+                                        //if (getHour >= 6)
+                                        //{
+                                        //    if (air.Price > 0)
+                                        //    {
+                                        //        airCount += 1;
+                                        //    }
+                                        //    else
+                                        //    {
+                                        //        airCount -= 1;
+                                        //    }
+                                        //}
+
+                                        if (air.Price > 0)
                                         {
-                                            if (air.Price > 0)
-                                            {
-                                                airCount += 1;
-                                            }
-                                            else
-                                            {
-                                                airCount -= 1;
-                                            }
+                                            airCount += 1;
+                                        }
+                                        else
+                                        {
+                                            airCount -= 1;
                                         }
                                     }
                                     catch (Exception ex)

+ 264 - 2
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -4073,7 +4073,7 @@ FROM
             }
             catch (Exception ex)
             {
-                return Ok(JsonView(false, "信息提取失败:"+ex.Message));
+                return Ok(JsonView(false, "信息提取失败:" + ex.Message));
             }
 
             #region 数据提交
@@ -6046,7 +6046,7 @@ FROM
 
             if (!string.IsNullOrEmpty(url))
             {
-                return Ok(JsonView(true,"操作成功", url));
+                return Ok(JsonView(true, "操作成功", url));
             }
 
             return Ok(JsonView(false, "操作失败!"));
@@ -32053,6 +32053,268 @@ ORDER BY
             return Ok(JsonView(true, "SUCCESS", backData));
         }
 
+
+        /// <summary>
+        /// 会务成本从表图片文件上传
+        /// </summary>
+        /// <param name="Dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        public async Task<IActionResult> ConferenceAffairsChildImageUpload([FromForm] ConferenceAffairsChildImageUploadDto Dto)
+        {
+            try
+            {
+                if (Dto == null || Dto.Files == null || Dto.Files.Count == 0)
+                {
+                    return Ok(JsonView(false, "请选择要上传的图片文件!"));
+                }
+
+                var child = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>()
+                    .Where(x => x.IsDel == 0 && x.Id == Dto.childId)
+                    .First();
+
+                if (child == null)
+                {
+                    return Ok(JsonView(false, "会务成本从表不存在!"));
+                }
+
+                // 允许的图片类型
+                var allowedImageTypes = new[] { ".jpg", ".jpeg", ".png", ".gif", ".bmp" };
+                var allowedContentTypes = new[] { "image/jpeg", "image/jpg", "image/png", "image/gif", "image/bmp" };
+
+                // 获取配置路径
+                string baseUrl = AppSettingsHelper.Get("ConferenceCostImageBaseUrl");
+                string basePath = AppSettingsHelper.Get("ConferenceCostImageBasePath");
+                string ftpPath = AppSettingsHelper.Get("ConferenceCostImageFtpPath");
+
+                // 确保路径以/结尾
+                if (!baseUrl.EndsWith("/"))
+                {
+                    baseUrl = baseUrl.TrimEnd('/') + "/";
+                }
+                if (!basePath.EndsWith("\\") && !basePath.EndsWith("/"))
+                {
+                    basePath = basePath.TrimEnd('\\', '/') + "\\";
+                }
+
+                // 创建保存目录(按childId分目录)
+                string saveDir = Path.Combine(basePath, "child", child.Id.ToString());
+                if (!Directory.Exists(saveDir))
+                {
+                    Directory.CreateDirectory(saveDir);
+                }
+
+                var uploadedImageUrls = new List<string>();
+                var existingImgs = string.IsNullOrWhiteSpace(child.Imgs)
+                    ? new List<string>()
+                    : child.Imgs.Split(',').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
+
+                foreach (var file in Dto.Files)
+                {
+                    if (file == null || file.Length == 0)
+                    {
+                        continue;
+                    }
+
+                    // 验证文件扩展名
+                    var fileExtension = Path.GetExtension(file.FileName).ToLowerInvariant();
+                    if (string.IsNullOrEmpty(fileExtension) || !allowedImageTypes.Contains(fileExtension))
+                    {
+                        return Ok(JsonView(false, $"文件 {file.FileName} 不是支持的图片格式,仅支持:{string.Join("、", allowedImageTypes)}"));
+                    }
+
+                    // 验证ContentType
+                    if (!string.IsNullOrEmpty(file.ContentType) && !allowedContentTypes.Contains(file.ContentType.ToLowerInvariant()))
+                    {
+                        return Ok(JsonView(false, $"文件 {file.FileName} 的ContentType不正确,不是图片类型"));
+                    }
+
+                    // 获取原始文件名(不含扩展名)和扩展名
+                    string originalFileName = Path.GetFileNameWithoutExtension(file.FileName);
+                    string fileName = file.FileName;
+                    string filePath = Path.Combine(saveDir, fileName);
+
+                    // 如果文件已存在,添加计数后缀
+                    int count = 0;
+                    while (System.IO.File.Exists(filePath))
+                    {
+                        count++;
+                        fileName = $"{originalFileName}({count}){fileExtension}";
+                        filePath = Path.Combine(saveDir, fileName);
+                    }
+
+                    // 保存文件
+                    using (var stream = new FileStream(filePath, FileMode.Create))
+                    {
+                        await file.CopyToAsync(stream);
+                    }
+
+                    // 生成完整URL路径
+                    string imageUrl = $"{baseUrl}{ftpPath}child/{child.Id}/{fileName}";
+                    uploadedImageUrls.Add(imageUrl);
+                }
+
+                if (uploadedImageUrls.Count == 0)
+                {
+                    return Ok(JsonView(false, "没有成功上传任何图片!"));
+                }
+
+                // 合并现有图片路径和新上传的图片路径
+                existingImgs.AddRange(uploadedImageUrls);
+                string updatedImgs = string.Join(",", existingImgs);
+
+                // 更新数据库
+                _sqlSugar.Updateable<Grp_ConferenceAffairsCostChild>()
+                    .SetColumns(x => new Grp_ConferenceAffairsCostChild { Imgs = updatedImgs })
+                    .Where(x => x.Id == child.Id)
+                    .ExecuteCommand();
+
+                return Ok(JsonView(true, $"成功上传 {uploadedImageUrls.Count} 张图片", uploadedImageUrls));
+            }
+            catch (Exception ex)
+            {
+                return Ok(JsonView(false, $"上传失败:{ex.Message}"));
+            }
+        }
+
+        /// <summary>
+        /// 根据文件名和从表id删除对应的图片
+        /// </summary>
+        /// <param name="Dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        public async Task<IActionResult> ConferenceAffairsChildImageDelete(ConferenceAffairsChildImageDeleteDto Dto)
+        {
+            if (Dto == null || Dto.fileNames == null || Dto.fileNames.Count == 0)
+            {
+                return Ok(JsonView(false, "请提供要删除的文件名列表!"));
+            }
+
+            var child = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>()
+                .Where(x => x.IsDel == 0 && x.Id == Dto.childId)
+                .First();
+
+            if (child == null)
+            {
+                return Ok(JsonView(false, "会务成本id有误!"));
+            }
+
+            var existingImgs = string.IsNullOrWhiteSpace(child.Imgs)
+                ? new List<string>()
+                : child.Imgs.Split(',').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
+
+            // 获取配置路径
+            string baseUrl = AppSettingsHelper.Get("ConferenceCostImageBaseUrl");
+            string basePath = AppSettingsHelper.Get("ConferenceCostImageBasePath");
+            string ftpPath = AppSettingsHelper.Get("ConferenceCostImageFtpPath");
+
+            // 确保路径格式正确
+            if (!baseUrl.EndsWith("/"))
+            {
+                baseUrl = baseUrl.TrimEnd('/') + "/";
+            }
+            if (!basePath.EndsWith("\\") && !basePath.EndsWith("/"))
+            {
+                basePath = basePath.TrimEnd('\\', '/') + "\\";
+            }
+            if (!ftpPath.EndsWith("/"))
+            {
+                ftpPath = ftpPath.TrimEnd('/') + "/";
+            }
+
+            int deletedCount = 0;
+            var expectedUrlPrefix = $"{baseUrl}{ftpPath}child/{child.Id}/";
+            var fileDir = Path.Combine(basePath, "child", child.Id.ToString());
+
+            // 遍历要删除的文件名列表
+            foreach (var fileNameOrUrl in Dto.fileNames)
+            {
+                if (string.IsNullOrWhiteSpace(fileNameOrUrl))
+                {
+                    continue;
+                }
+
+                string fileName = fileNameOrUrl;
+                string fullUrl = fileNameOrUrl;
+
+                // 判断是完整URL还是文件名
+                if (fileNameOrUrl.StartsWith("http://") || fileNameOrUrl.StartsWith("https://"))
+                {
+                    // 是完整URL,提取文件名
+                    try
+                    {
+                        var uri = new Uri(fileNameOrUrl);
+                        fileName = Path.GetFileName(uri.AbsolutePath);
+                        // 如果URL包含child/{childId}/路径,使用完整URL匹配
+                        if (fileNameOrUrl.Contains($"/child/{child.Id}/"))
+                        {
+                            fullUrl = fileNameOrUrl;
+                        }
+                        else
+                        {
+                            // URL格式不匹配,尝试构造完整URL
+                            fullUrl = $"{expectedUrlPrefix}{fileName}";
+                        }
+                    }
+                    catch
+                    {
+                        // URL解析失败,当作文件名处理
+                        fileName = Path.GetFileName(fileNameOrUrl);
+                        fullUrl = $"{expectedUrlPrefix}{fileName}";
+                    }
+                }
+                else
+                {
+                    // 是文件名,构造完整URL用于匹配
+                    fullUrl = $"{expectedUrlPrefix}{fileName}";
+                }
+
+                // 从现有图片列表中移除(支持完整URL匹配或文件名匹配)
+                var removed = existingImgs.RemoveAll(img =>
+                    img.Equals(fullUrl, StringComparison.OrdinalIgnoreCase) ||
+                    img.Equals(fileNameOrUrl, StringComparison.OrdinalIgnoreCase) ||
+                    img.EndsWith($"/{fileName}", StringComparison.OrdinalIgnoreCase));
+
+                if (removed > 0)
+                {
+                    deletedCount++;
+                }
+
+                // 删除磁盘上的文件
+                var filePath = Path.Combine(fileDir, fileName);
+                if (System.IO.File.Exists(filePath))
+                {
+                    try
+                    {
+                        System.IO.File.Delete(filePath);
+                    }
+                    catch (Exception ex)
+                    {
+                        _logger.LogError(ex, "删除图片失败:{fileName}", fileName);
+                    }
+                }
+            }
+
+            if (deletedCount == 0)
+            {
+                return Ok(JsonView(false, "没有找到要删除的图片!"));
+            }
+
+            // 更新数据库
+            var updatedImgs = string.Join(",", existingImgs);
+            _sqlSugar.Updateable<Grp_ConferenceAffairsCostChild>()
+                .SetColumns(x => new Grp_ConferenceAffairsCostChild { Imgs = updatedImgs })
+                .Where(x => x.Id == child.Id)
+                .ExecuteCommand();
+
+            return Ok(JsonView(true, $"成功删除 {deletedCount} 张图片", updatedImgs));
+        }
+
+
+
+
+
+
         /// <summary>
         /// 会务成本保存 
         /// </summary>

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

@@ -160,6 +160,9 @@
   "VisaProgressImageBaseUrl": "http://132.232.92.186:24/",
   "VisaProgressImageBasePath": "D:/FTP/File/OA2023/Image/Visa/",
   "VisaProgressImageFtpPath": "Image/Visa/",
+  "ConferenceCostImageBaseUrl": "http://132.232.92.186:24/",
+  "ConferenceCostImageBasePath": "D:/FTP/File/OA2023/Image/ConferenceCost/",
+  "ConferenceCostImageFtpPath": "Image/ConferenceCost/",
   "WageSheetExcelBaseUrl": "http://132.232.92.186:24/",
   "WageSheetExcelFptPath": "D:/FTP/File/OA2023/Office/WageSheetFile/",
   "WageSheetTaxExcelBaseUrl": "http://132.232.92.186:24/",

+ 14 - 1
OASystem/OASystem.Domain/Dtos/Groups/ConferenceAffairsInIt.cs

@@ -1,4 +1,5 @@
-using OASystem.Domain.ViewModels.Groups;
+using Microsoft.AspNetCore.Http;
+using OASystem.Domain.ViewModels.Groups;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -14,6 +15,18 @@ namespace OASystem.Domain.Dtos.Groups
         public int GroupId { get; set; }
     }
 
+    public class ConferenceAffairsChildImageUploadDto
+    {
+        public int childId { get; set; }
+        public List<IFormFile> Files { get; set; }
+    }
+
+    public class ConferenceAffairsChildImageDeleteDto
+    {
+        public int childId { get; set; }
+        public List<string> fileNames { get; set; }
+    }
+
     public class ConferenceAffairsSaveDto
     {
         /// <summary>

+ 5 - 0
OASystem/OASystem.Domain/Entities/Groups/ConferenceAffairsCost.cs

@@ -143,6 +143,11 @@
         /// 主表Id
         /// </summary>
         public int ConferenceAffairsCostId { get; set; }
+
+        /// <summary>
+        /// 图片路径
+        /// </summary>
+        public string Imgs { get; set; }  
     }
 
 

+ 13 - 0
OASystem/OASystem.Domain/ViewModels/Groups/ConferenceAffairsCostView.cs

@@ -148,5 +148,18 @@
 
         public string Remark { get; set; }
 
+        /// <summary>
+        /// 图片路径
+        /// </summary>
+        public string Imgs { get; set; }
+
+        public List<string> ImgsList
+        {
+            get
+            {
+                return string.IsNullOrWhiteSpace(Imgs) ? new List<string>() : Imgs.Split(',').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
+            }
+        }
+
     }
 }