diff --git a/24Hour/Controllers/Common/LawyerArchivesController.cs b/24Hour/Controllers/Common/LawyerArchivesController.cs index 8c2bfd7..f4ae34b 100644 --- a/24Hour/Controllers/Common/LawyerArchivesController.cs +++ b/24Hour/Controllers/Common/LawyerArchivesController.cs @@ -11,6 +11,7 @@ using Elight.Utility; using Elight.Utility.Code; using Elight.Utility.Extensions; using Elight.Utility.logs; +using java.io; using java.lang; using java.time; using javax.xml.crypto; @@ -20,6 +21,7 @@ using Microsoft.AspNetCore.Mvc.Filters; using Newtonsoft.Json; using SqlSugar; using SqlSugar.Extensions; +using System.Data; using System.Linq; using System.Net.WebSockets; using System.Text; @@ -115,6 +117,124 @@ namespace _24Hour.Controllers.Common return result; } /// + /// 导入律师库信息,先调用/api/Common/Upload_Files1将文件上传至库,然后用url调用ImportLawyerData + /// + /// excel文件相对路径 + /// + [HttpGet] + [Route("ImportLawyerData")] + public async Task ImportLawyerData(string path) + { + Result res = new Result(); + int updated = 0, added = 0; + var ext = Path.GetExtension(path).ToLower(); + + if (ext == ".xlsx" || ext == ".xls") + { + if (System.IO.File.Exists(path)) + { + var reader = new ExcelReader(path); + var dt = reader.ExcelToDataTable(); + if (dt != null) + { + + + var lawyers = new List(); + foreach (DataRow dr in dt.Rows) + { + var cardid = dr.Field("证件编号"); + if (string.IsNullOrEmpty(cardid)) + { + continue; + } + lawyers.Add(new() + { + Id = Guid.NewGuid().ToString(), + name = dr.Field("姓名"), + sex = dr?.Field("性别")?.Contains('男') == true ? 0 : 1, + phone = dr.Field("手机号码"), + departmentName = dr.Field("执业机构"), + identitycardId = dr.Field("执业证号"), + cardId = dr.Field("证件编号"), + unitCode = _userdata.unitCode, + + createtime = DateTime.Now, + createuserId = _userdata.createuserId, + createusername = _userdata.name, + identity = "律师", + usertype = 1, + audit = 0, + + isdeactivate = 0, + IsDeleted = 0, + }); + } + var cardids = lawyers.Select(e => e.cardId).ToList(); + var lawyersInDb = await _db.Queryable().In(x => x.cardId, cardids).ToListAsync(); + if (lawyersInDb.Any()) + { + var updatelist = new List(); + foreach (var item in lawyersInDb) + { + var lawyerinfo = lawyers.FirstOrDefault(x => x.cardId == item.cardId); + if (lawyerinfo == null) + { + continue; + } + if (item.name != lawyerinfo.name || + item.sex != lawyerinfo.sex || + item.phone != lawyerinfo.phone || + item.departmentName != lawyerinfo.departmentName || + item.cardId != lawyerinfo.cardId) + { + item.name = lawyerinfo.name; + item.sex = lawyerinfo.sex; + item.phone = lawyerinfo.phone; + item.departmentName = lawyerinfo.departmentName; + item.cardId = lawyerinfo.cardId; + updatelist.Add(item); + } + } + if (updatelist.Any()) + updated = await _db.Updateable(updatelist) + .IgnoreColumns(ignoreAllNullColumns: true) + .ExecuteCommandAsync(); + } + var addlawyers = lawyers.Where(x => lawyersInDb.Any(e => e.cardId == x.cardId) == false).ToList(); + + if (addlawyers.Any()) + added = await _db.Insertable(addlawyers).ExecuteCommandAsync(); + + res.IsSucceed = true; + res.result = new + { + updated, + added + }; + } + else + { + res.IsSucceed = false; + res.Message = "数据异常"; + } + } + else + { + res.IsSucceed = false; + res.Message = "文件不存在"; + } + + } + else + { + res.IsSucceed = false; + res.Message = "文件格式不支持"; + } + if (System.IO.File.Exists(path)) + System.IO.File.Delete(path); + return res; + } + /// /// 同步外网律师人员信息(未完成) (根据律师身份证号更新或新增用户信息) /// /// @@ -740,7 +860,7 @@ namespace _24Hour.Controllers.Common } #endregion #region 查询已经阅卷的统计信息 - + var readedlist = await Task.Run(async () => { var registerCount = await _db.Queryable() @@ -851,7 +971,7 @@ namespace _24Hour.Controllers.Common } } return registerCount; - }); + }); #endregion result.IsSucceed = true;