This commit is contained in:
zpc 2025-08-20 00:59:04 +08:00
parent 82a7d3e6aa
commit 87897f5126
16 changed files with 56 additions and 48 deletions

View File

@ -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<IActionResult> DownloadZip([FromQuery] string? yearMoney)
{
if (string.IsNullOrEmpty(yearMoney))
if (string.IsNullOrEmpty(yearMoney)|| yearMoney=="null")
{
yearMoney = DateTime.Now.ToString("yyyyMM");
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 549 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 749 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 549 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 749 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 549 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 749 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 549 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 749 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 549 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 749 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 549 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 749 KiB

View File

@ -71,6 +71,8 @@ namespace ZR.Model.Business.Dto
/// </summary>
public string DeptName { get; set; }
public string ImageUrl { get; set; }
/// <summary>
/// 图片地址
/// </summary>

View File

@ -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,