333
This commit is contained in:
parent
b0d2592ddb
commit
830732aeeb
|
|
@ -463,76 +463,83 @@ namespace ZR.Admin.WebApi.Controllers
|
||||||
// 查询相关的工作人员
|
// 查询相关的工作人员
|
||||||
var workers = await _CamWorkerService.AsQueryable().Where(it => it.WorkrecordId == id).ToListAsync();
|
var workers = await _CamWorkerService.AsQueryable().Where(it => it.WorkrecordId == id).ToListAsync();
|
||||||
|
|
||||||
// 删除图片文件
|
try
|
||||||
if (!string.IsNullOrEmpty(workRecord.ImageUrl))
|
|
||||||
{
|
{
|
||||||
// 从URL中提取文件路径
|
// 删除图片文件
|
||||||
var imagePath = workRecord.ImageUrl.Substring(workRecord.ImageUrl.IndexOf("workfiles"));
|
if (!string.IsNullOrEmpty(workRecord.ImageUrl))
|
||||||
var fullImagePath = Path.Combine(WebHostEnvironment.WebRootPath, imagePath);
|
|
||||||
|
|
||||||
// 获取文件名
|
|
||||||
var fileName = Path.GetFileName(fullImagePath);
|
|
||||||
var directoryPath = Path.GetDirectoryName(fullImagePath);
|
|
||||||
|
|
||||||
// 删除当日照片
|
|
||||||
if (IOFile.Exists(fullImagePath))
|
|
||||||
{
|
{
|
||||||
IOFile.Delete(fullImagePath);
|
// 从URL中提取文件路径
|
||||||
}
|
var imagePath = workRecord.ImageUrl.Substring(workRecord.ImageUrl.IndexOf("workfiles"));
|
||||||
|
var fullImagePath = Path.Combine(WebHostEnvironment.WebRootPath, imagePath);
|
||||||
|
|
||||||
// 删除参与人员照片
|
// 获取文件名
|
||||||
var participantsPath = Path.Combine(WebHostEnvironment.WebRootPath, "workfiles", workRecord.RecordTime?.ToString("yyyyMM/yyyyMMdd"), "参与人员");
|
var fileName = Path.GetFileName(fullImagePath);
|
||||||
if (Directory.Exists(participantsPath))
|
var directoryPath = Path.GetDirectoryName(fullImagePath);
|
||||||
{
|
|
||||||
foreach (var worker in workers)
|
// 删除当日照片
|
||||||
|
if (IOFile.Exists(fullImagePath))
|
||||||
{
|
{
|
||||||
var workerImagePath = Path.Combine(participantsPath, worker.WorkerName, fileName);
|
IOFile.Delete(fullImagePath);
|
||||||
if (IOFile.Exists(workerImagePath))
|
}
|
||||||
{
|
|
||||||
IOFile.Delete(workerImagePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果该工作人员的文件夹为空,则删除文件夹
|
// 删除参与人员照片
|
||||||
var workerDir = Path.GetDirectoryName(workerImagePath);
|
var participantsPath = Path.Combine(WebHostEnvironment.WebRootPath, "workfiles", workRecord.RecordTime?.ToString("yyyyMM/yyyyMMdd"), "参与人员");
|
||||||
if (Directory.Exists(workerDir) && !Directory.EnumerateFiles(workerDir).Any())
|
if (Directory.Exists(participantsPath))
|
||||||
|
{
|
||||||
|
foreach (var worker in workers)
|
||||||
{
|
{
|
||||||
Directory.Delete(workerDir);
|
var workerImagePath = Path.Combine(participantsPath, worker.WorkerName, fileName);
|
||||||
|
if (IOFile.Exists(workerImagePath))
|
||||||
|
{
|
||||||
|
IOFile.Delete(workerImagePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果该工作人员的文件夹为空,则删除文件夹
|
||||||
|
var workerDir = Path.GetDirectoryName(workerImagePath);
|
||||||
|
if (Directory.Exists(workerDir) && !Directory.EnumerateFiles(workerDir).Any())
|
||||||
|
{
|
||||||
|
Directory.Delete(workerDir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 删除工作内容照片
|
||||||
|
var jobContentPath = Path.Combine(WebHostEnvironment.WebRootPath, "workfiles", workRecord.RecordTime?.ToString("yyyyMM/yyyyMMdd"), "工作内容", workRecord.Content);
|
||||||
|
var jobContentImagePath = Path.Combine(jobContentPath, fileName);
|
||||||
|
if (IOFile.Exists(jobContentImagePath))
|
||||||
|
{
|
||||||
|
IOFile.Delete(jobContentImagePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果工作内容文件夹为空,则删除文件夹
|
||||||
|
if (Directory.Exists(jobContentPath) && !Directory.EnumerateFiles(jobContentPath).Any())
|
||||||
|
{
|
||||||
|
Directory.Delete(jobContentPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除部门照片
|
||||||
|
var departmentPath = Path.Combine(WebHostEnvironment.WebRootPath, "workfiles", workRecord.RecordTime?.ToString("yyyyMM/yyyyMMdd"), "部门", workRecord.DeptName);
|
||||||
|
var departmentImagePath = Path.Combine(departmentPath, fileName);
|
||||||
|
if (IOFile.Exists(departmentImagePath))
|
||||||
|
{
|
||||||
|
IOFile.Delete(departmentImagePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果部门文件夹为空,则删除文件夹
|
||||||
|
if (Directory.Exists(departmentPath) && !Directory.EnumerateFiles(departmentPath).Any())
|
||||||
|
{
|
||||||
|
Directory.Delete(departmentPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清理空文件夹
|
||||||
|
CleanEmptyDirectories(Path.Combine(WebHostEnvironment.WebRootPath, "workfiles", workRecord.RecordTime?.ToString("yyyyMM/yyyyMMdd")));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除工作内容照片
|
|
||||||
var jobContentPath = Path.Combine(WebHostEnvironment.WebRootPath, "workfiles", workRecord.RecordTime?.ToString("yyyyMM/yyyyMMdd"), "工作内容", workRecord.Content);
|
|
||||||
var jobContentImagePath = Path.Combine(jobContentPath, fileName);
|
|
||||||
if (IOFile.Exists(jobContentImagePath))
|
|
||||||
{
|
|
||||||
IOFile.Delete(jobContentImagePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果工作内容文件夹为空,则删除文件夹
|
|
||||||
if (Directory.Exists(jobContentPath) && !Directory.EnumerateFiles(jobContentPath).Any())
|
|
||||||
{
|
|
||||||
Directory.Delete(jobContentPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 删除部门照片
|
|
||||||
var departmentPath = Path.Combine(WebHostEnvironment.WebRootPath, "workfiles", workRecord.RecordTime?.ToString("yyyyMM/yyyyMMdd"), "部门", workRecord.DeptName);
|
|
||||||
var departmentImagePath = Path.Combine(departmentPath, fileName);
|
|
||||||
if (IOFile.Exists(departmentImagePath))
|
|
||||||
{
|
|
||||||
IOFile.Delete(departmentImagePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果部门文件夹为空,则删除文件夹
|
|
||||||
if (Directory.Exists(departmentPath) && !Directory.EnumerateFiles(departmentPath).Any())
|
|
||||||
{
|
|
||||||
Directory.Delete(departmentPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 清理空文件夹
|
|
||||||
CleanEmptyDirectories(Path.Combine(WebHostEnvironment.WebRootPath, "workfiles", workRecord.RecordTime?.ToString("yyyyMM/yyyyMMdd")));
|
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger.Error($"删除文件失败,错误: {ex.Message}");
|
||||||
|
}
|
||||||
// 删除工作人员记录
|
// 删除工作人员记录
|
||||||
await _CamWorkerService.DeleteAsync(it => it.WorkrecordId == id);
|
await _CamWorkerService.DeleteAsync(it => it.WorkrecordId == id);
|
||||||
|
|
||||||
|
|
@ -577,7 +584,7 @@ namespace ZR.Admin.WebApi.Controllers
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public async Task<IActionResult> DownloadZip([FromQuery] string? yearMoney)
|
public async Task<IActionResult> DownloadZip([FromQuery] string? yearMoney)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(yearMoney)|| yearMoney=="null")
|
if (string.IsNullOrEmpty(yearMoney) || yearMoney == "null")
|
||||||
{
|
{
|
||||||
yearMoney = DateTime.Now.ToString("yyyyMM");
|
yearMoney = DateTime.Now.ToString("yyyyMM");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user