diff --git a/ZR.Admin.WebApi/Controllers/CommonController.cs b/ZR.Admin.WebApi/Controllers/CommonController.cs index 1f69d5c..c3b11e7 100644 --- a/ZR.Admin.WebApi/Controllers/CommonController.cs +++ b/ZR.Admin.WebApi/Controllers/CommonController.cs @@ -266,7 +266,7 @@ namespace ZR.Admin.WebApi.Controllers { return ToResponse(ResultCode.PARAM_ERROR, "请选择工作人员"); } - if (string.IsNullOrEmpty(parm.Image)) + if (string.IsNullOrEmpty(parm.Image) && !string.IsNullOrEmpty(parm.ImageUrl)) { return ToResponse(ResultCode.PARAM_ERROR, "请上传图片"); } @@ -277,7 +277,7 @@ namespace ZR.Admin.WebApi.Controllers //- 当日根据【部门】分类的照片 var imageprx = ImageConverter.GetFileExtensionFromBase64(parm.Image); - var filePath = "/workfiles/" + DateTime.Now.ToString("yyyyMM/yyyyMMdd"); + var filePath = "/workfiles/" + parm.RecordTime?.ToString("yyyyMM/yyyyMMdd"); string savePath = Path.Combine(WebHostEnvironment.WebRootPath); var path = savePath + filePath; var images = ImageConverter.Base64ToImageBytes(parm.Image); @@ -288,71 +288,77 @@ namespace ZR.Admin.WebApi.Controllers if (parm.Id != null && parm.Id > 0) { - //删除之前的人员照片 - var m = await _CamWorkrecordService.AsQueryable().Where(it => it.Id == parm.Id).FirstAsync(); - var m_workers = await _CamWorkerService.AsQueryable().Where(it => it.WorkrecordId == parm.Id).ToListAsync(); - if (m == null) + if (parm.ImageUrl.IndexOf("http") == -1) { - return ToResponse(ResultCode.PARAM_ERROR, "未找到该记录"); - } - if (!string.IsNullOrEmpty(m.ImageUrl)) - { - //m.ImageUrl http://localhost:8888/workfiles/202508/20250819/当日照片/1755617080_7078.jpg - var imagePath = m.ImageUrl.Substring(m.ImageUrl.IndexOf("workfiles")); - var fullImagePath = Path.Combine(WebHostEnvironment.WebRootPath, imagePath); - - // 获取文件名 - var fileName = Path.GetFileName(fullImagePath); - var directoryPath = Path.GetDirectoryName(fullImagePath); - - // 删除当日照片 - if (File.Exists(fullImagePath)) + + //删除之前的人员照片 + var m = await _CamWorkrecordService.AsQueryable().Where(it => it.Id == parm.Id).FirstAsync(); + var m_workers = await _CamWorkerService.AsQueryable().Where(it => it.WorkrecordId == parm.Id).ToListAsync(); + if (m == null) { - File.Delete(fullImagePath); + return ToResponse(ResultCode.PARAM_ERROR, "未找到该记录"); } - - // 删除参与人员照片 - var participantsPath = Path.Combine(WebHostEnvironment.WebRootPath, "workfiles", DateTime.Now.ToString("yyyyMM/yyyyMMdd"), "参与人员"); - if (Directory.Exists(participantsPath)) + if (!string.IsNullOrEmpty(m.ImageUrl)) { - foreach (var workerDir in Directory.GetDirectories(participantsPath)) + //m.ImageUrl http://localhost:8888/workfiles/202508/20250819/当日照片/1755617080_7078.jpg + var imagePath = m.ImageUrl.Substring(m.ImageUrl.IndexOf("workfiles")); + var fullImagePath = Path.Combine(WebHostEnvironment.WebRootPath, imagePath); + + // 获取文件名 + var fileName = Path.GetFileName(fullImagePath); + var directoryPath = Path.GetDirectoryName(fullImagePath); + + // 删除当日照片 + if (IOFile.Exists(fullImagePath)) { - var workerImagePath = Path.Combine(workerDir, fileName); - if (File.Exists(workerImagePath)) + IOFile.Delete(fullImagePath); + } + + // 删除参与人员照片 + var participantsPath = Path.Combine(WebHostEnvironment.WebRootPath, "workfiles", m.RecordTime?.ToString("yyyyMM/yyyyMMdd"), "参与人员"); + if (Directory.Exists(participantsPath)) + { + foreach (var workerDir in m_workers) { - File.Delete(workerImagePath); + var workerImagePath = Path.Combine(participantsPath, workerDir.WorkerName, fileName); + if (IOFile.Exists(workerImagePath)) + { + IOFile.Delete(workerImagePath); + } } } + + // 删除工作内容照片 + var jobContentPath = Path.Combine(WebHostEnvironment.WebRootPath, "workfiles", m.RecordTime?.ToString("yyyyMM/yyyyMMdd"), "工作内容", m.Content); + var jobContentImagePath = Path.Combine(jobContentPath, fileName); + if (IOFile.Exists(jobContentImagePath)) + { + IOFile.Delete(jobContentImagePath); + } + + // 删除部门照片 + var departmentPath = Path.Combine(WebHostEnvironment.WebRootPath, "workfiles", m.RecordTime?.ToString("yyyyMM/yyyyMMdd"), "部门", m.DeptName); + var departmentImagePath = Path.Combine(departmentPath, fileName); + if (IOFile.Exists(departmentImagePath)) + { + IOFile.Delete(departmentImagePath); + } } - - // 删除工作内容照片 - var jobContentPath = Path.Combine(WebHostEnvironment.WebRootPath, "workfiles", DateTime.Now.ToString("yyyyMM/yyyyMMdd"), "工作内容", m.Content); - var jobContentImagePath = Path.Combine(jobContentPath, fileName); - if (File.Exists(jobContentImagePath)) - { - File.Delete(jobContentImagePath); - } - - // 删除部门照片 - var departmentPath = Path.Combine(WebHostEnvironment.WebRootPath, "workfiles", DateTime.Now.ToString("yyyyMM/yyyyMMdd"), "部门", m.DeptName); - var departmentImagePath = Path.Combine(departmentPath, fileName); - if (File.Exists(departmentImagePath)) - { - File.Delete(departmentImagePath); - } - //删除施工人员数据 await _CamWorkerService.DeleteAsync(it => it.WorkrecordId == parm.Id); } } + int MaxSize = 300 * 1024; // 300KB = 307200 字节 // 如果图片大于300KB才压缩 + if (images.Length > MaxSize) { images = CompressImage(images, 70); // 压缩质量 70 imageprx = ".jpg"; } + var imageName = ImageConverter.GenerateImageFileName(imageprx); var participantsUrl = $"{path}/参与人员/"; var photosDay = $"{path}/当日照片/"; @@ -442,7 +448,7 @@ namespace ZR.Admin.WebApi.Controllers [AllowAnonymous] public async Task DownloadZip([FromQuery] string? yearMoney) { - if (string.IsNullOrEmpty(yearMoney)) + if (string.IsNullOrEmpty(yearMoney)|| yearMoney=="null") { yearMoney = DateTime.Now.ToString("yyyyMM"); } diff --git a/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/参与人员/张三/1755617080_7078.jpg b/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/参与人员/张三/1755617080_7078.jpg deleted file mode 100644 index 593533f..0000000 Binary files a/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/参与人员/张三/1755617080_7078.jpg and /dev/null differ diff --git a/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/参与人员/张三/1755617093_1631.jpg b/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/参与人员/张三/1755617093_1631.jpg deleted file mode 100644 index e4a74ed..0000000 Binary files a/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/参与人员/张三/1755617093_1631.jpg and /dev/null differ diff --git a/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/参与人员/李四/1755617080_7078.jpg b/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/参与人员/李四/1755617080_7078.jpg deleted file mode 100644 index 593533f..0000000 Binary files a/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/参与人员/李四/1755617080_7078.jpg and /dev/null differ diff --git a/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/参与人员/李四/1755617093_1631.jpg b/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/参与人员/李四/1755617093_1631.jpg deleted file mode 100644 index e4a74ed..0000000 Binary files a/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/参与人员/李四/1755617093_1631.jpg and /dev/null differ diff --git a/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/参与人员/王五/1755617080_7078.jpg b/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/参与人员/王五/1755617080_7078.jpg deleted file mode 100644 index 593533f..0000000 Binary files a/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/参与人员/王五/1755617080_7078.jpg and /dev/null differ diff --git a/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/参与人员/王五/1755617093_1631.jpg b/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/参与人员/王五/1755617093_1631.jpg deleted file mode 100644 index e4a74ed..0000000 Binary files a/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/参与人员/王五/1755617093_1631.jpg and /dev/null differ diff --git a/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/工作内容/测试/1755617080_7078.jpg b/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/工作内容/测试/1755617080_7078.jpg deleted file mode 100644 index 593533f..0000000 Binary files a/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/工作内容/测试/1755617080_7078.jpg and /dev/null differ diff --git a/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/工作内容/测试/1755617093_1631.jpg b/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/工作内容/测试/1755617093_1631.jpg deleted file mode 100644 index e4a74ed..0000000 Binary files a/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/工作内容/测试/1755617093_1631.jpg and /dev/null differ diff --git a/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/当日照片/1755617080_7078.jpg b/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/当日照片/1755617080_7078.jpg deleted file mode 100644 index 593533f..0000000 Binary files a/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/当日照片/1755617080_7078.jpg and /dev/null differ diff --git a/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/当日照片/1755617093_1631.jpg b/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/当日照片/1755617093_1631.jpg deleted file mode 100644 index e4a74ed..0000000 Binary files a/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/当日照片/1755617093_1631.jpg and /dev/null differ diff --git a/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/部门/研发部门/1755617080_7078.jpg b/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/部门/研发部门/1755617080_7078.jpg deleted file mode 100644 index 593533f..0000000 Binary files a/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/部门/研发部门/1755617080_7078.jpg and /dev/null differ diff --git a/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/部门/研发部门/1755617093_1631.jpg b/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/部门/研发部门/1755617093_1631.jpg deleted file mode 100644 index e4a74ed..0000000 Binary files a/ZR.Admin.WebApi/wwwroot/workfiles/202508/20250819/部门/研发部门/1755617093_1631.jpg and /dev/null differ diff --git a/ZR.Admin.WebApi/wwwroot/workfiles/temp/202508.zip b/ZR.Admin.WebApi/wwwroot/workfiles/temp/202508.zip deleted file mode 100644 index ec6e891..0000000 Binary files a/ZR.Admin.WebApi/wwwroot/workfiles/temp/202508.zip and /dev/null differ diff --git a/ZR.Model/Business/Dto/CamWorkrecordDto.cs b/ZR.Model/Business/Dto/CamWorkrecordDto.cs index 6247c5b..ca3cc11 100644 --- a/ZR.Model/Business/Dto/CamWorkrecordDto.cs +++ b/ZR.Model/Business/Dto/CamWorkrecordDto.cs @@ -71,6 +71,8 @@ namespace ZR.Model.Business.Dto /// public string DeptName { get; set; } + public string ImageUrl { get; set; } + /// /// 图片地址 /// diff --git a/ZR.Service/Business/CamWorkersService.cs b/ZR.Service/Business/CamWorkersService.cs index ade35e0..03dc54e 100644 --- a/ZR.Service/Business/CamWorkersService.cs +++ b/ZR.Service/Business/CamWorkersService.cs @@ -46,7 +46,7 @@ SELECT CONVERT(varchar(7), CAST(r.RecordTime AS date), 120) AS YearMonth, COUNT(DISTINCT CAST(r.RecordTime AS date)) AS WorkDays FROM cam_worker w -LEFT JOIN cam_workrecord r ON w.workrecordId = r.Id where 1=1 {where} +LEFT JOIN cam_workrecord r ON w.workrecordId = r.Id where r.RecordTime is not null {where} GROUP BY r.DeptName, w.WorkerName,