From 30fd529f75c7a8944ae79b54068fc845544d86d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BD=87=E9=98=B3=20=E9=82=B9?= Date: Wed, 27 Dec 2023 20:47:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=81=E8=A3=85=E5=8A=A0=E8=BD=BD=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E7=9A=84=E6=96=B9=E6=B3=95=EF=BC=8C=E5=9C=A8=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=95=B0=E6=8D=AE=E5=89=8D=E5=85=88=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=8E=9F=E6=9D=A5=E7=9A=84=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Common/LawyerArchivesController.cs | 85 ++++++++++--------- 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/24Hour/Controllers/Common/LawyerArchivesController.cs b/24Hour/Controllers/Common/LawyerArchivesController.cs index f0bd98f..76360b1 100644 --- a/24Hour/Controllers/Common/LawyerArchivesController.cs +++ b/24Hour/Controllers/Common/LawyerArchivesController.cs @@ -1782,6 +1782,25 @@ namespace _24Hour.Controllers.Common lawyerservices = default(List), users = default(List) }); + //替换数据前先删除之前保存的图片 + var deleteOldData = (string? jsonpath) => + { + if (string.IsNullOrEmpty(jsonpath)) + { + return; + } + var photos = jsonpath.ConvertToModel>() ?? new List(); + foreach (var photo in photos.Where(x => x != null)) + { + var urlpath = photo.Split('/'); + var filepath = Path.Combine(Environment.CurrentDirectory, "wwwroot", Path.Combine(urlpath)); + if (System.IO.File.Exists(filepath)) + { + System.IO.File.Delete(filepath); + } + } + }; + foreach (var userim in importdata.users.Where(x => x != null)) { var user = await _db.Queryable() @@ -1818,6 +1837,9 @@ namespace _24Hour.Controllers.Common } else { + deleteOldData(user.cardIdphoto); + deleteOldData(user.identityphoto); + user.cardIdphoto = cardids; user.identityphoto = files; user.unitCode = _userdata.unitCode; @@ -1842,46 +1864,23 @@ namespace _24Hour.Controllers.Common { var svc = await _db.Queryable() .Where(x => x.Id == lawyersvc.Id).FirstAsync(); + var loadphoto = (string dirname) => + { + var dirpath = Path.Combine(ziplawyersvcs, lawyersvc.Id, dirname); + var photos = new DirectoryInfo(dirpath) + .GetFiles() + .Select(x => "/CaseFile/imports/" + Path.GetRelativePath(dir, x.FullName) + .Replace(@"\", @"/")) + .ToList() + .ConvertToJsonStr(); + return photos; + }; - var annexphoto = Path.Combine(ziplawyersvcs, lawyersvc.Id, "annexs"); - var annexs = new DirectoryInfo(annexphoto) - .GetFiles() - .Select(x => "/CaseFile/imports/" + Path.GetRelativePath(dir, x.FullName) - .Replace(@"\", @"/")) - .ToList() - .ConvertToJsonStr(); - - var legalAidPhoto = Path.Combine(ziplawyersvcs, lawyersvc.Id, "legalAidPhoto"); - var legalAidPhotos = new DirectoryInfo(legalAidPhoto) - .GetFiles() - .Select(x => "/CaseFile/imports/" + Path.GetRelativePath(dir, x.FullName) - .Replace(@"\", @"/")) - .ToList() - .ConvertToJsonStr(); - - var relationshipProofPhoto = Path.Combine(ziplawyersvcs, lawyersvc.Id, "relationshipProofPhoto"); - var relationshipProofPhotos = new DirectoryInfo(relationshipProofPhoto) - .GetFiles() - .Select(x => "/CaseFile/imports/" + Path.GetRelativePath(dir, x.FullName) - .Replace(@"\", @"/")) - .ToList() - .ConvertToJsonStr(); - - var otherPhoto = Path.Combine(ziplawyersvcs, lawyersvc.Id, "otherPhoto"); - var otherPhotos = new DirectoryInfo(otherPhoto) - .GetFiles() - .Select(x => "/CaseFile/imports/" + Path.GetRelativePath(dir, x.FullName) - .Replace(@"\", @"/")) - .ToList() - .ConvertToJsonStr(); - - var departmentPhoto = Path.Combine(ziplawyersvcs, lawyersvc.Id, "departmentPhoto"); - var departmentPhotos = new DirectoryInfo(departmentPhoto) - .GetFiles() - .Select(x => "/CaseFile/imports/" + Path.GetRelativePath(dir, x.FullName) - .Replace(@"\", @"/")) - .ToList() - .ConvertToJsonStr(); + var annexs = loadphoto("annexs"); + var legalAidPhotos = loadphoto("legalAidPhoto"); + var relationshipProofPhotos = loadphoto("relationshipProofPhoto"); + var otherPhotos = loadphoto("otherPhoto"); + var departmentPhotos = loadphoto("departmentPhoto"); if (svc == null) { @@ -1912,6 +1911,14 @@ namespace _24Hour.Controllers.Common .Where(x => x.identity == "律师") .FirstAsync(); + + deleteOldData(svc?.annex); + deleteOldData(svc?.legalAidPhoto); + deleteOldData(svc?.relationshipProofPhoto); + deleteOldData(svc?.otherPhoto); + deleteOldData(svc?.departmentPhoto); + + svc.createuserId = lawyer.Id; svc.annex = annexs; svc.legalAidPhoto = legalAidPhotos;