diff --git a/IRaCIS.Core.API/_ServiceExtensions/NewtonsoftJson/JSONTimeZoneConverter.cs b/IRaCIS.Core.API/_ServiceExtensions/NewtonsoftJson/JSONTimeZoneConverter.cs index 1ae4adfd2..9b289e8a4 100644 --- a/IRaCIS.Core.API/_ServiceExtensions/NewtonsoftJson/JSONTimeZoneConverter.cs +++ b/IRaCIS.Core.API/_ServiceExtensions/NewtonsoftJson/JSONTimeZoneConverter.cs @@ -126,6 +126,51 @@ namespace IRaCIS.Core.API } + public class DateOnlyUniversalJsonConverter : JsonConverter + { + private readonly string _format; + + public DateOnlyUniversalJsonConverter(string format = "yyyy-MM-dd") + { + _format = format; + } + + public override bool CanConvert(Type objectType) + { + return objectType == typeof(DateOnly) || objectType == typeof(DateOnly?); + } + + public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) + { + if (value == null) + { + writer.WriteValue(""); // null -> 空字符串 + return; + } + + var date = (DateOnly)value; + if (date == default) + { + writer.WriteValue(""); // default(DateOnly) -> 空字符串 + } + else + { + writer.WriteValue(date.ToString(_format)); + } + } + + public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) + { + var str = reader.TokenType == JsonToken.Null ? null : reader.Value?.ToString(); + + if (string.IsNullOrWhiteSpace(str) || !DateOnly.TryParse(str, out var date)) + { + return objectType == typeof(DateOnly?) ? null : default(DateOnly); + } + + return date; + } + } #region 废弃 diff --git a/IRaCIS.Core.API/_ServiceExtensions/NewtonsoftJson/NewtonsoftJsonSetup.cs b/IRaCIS.Core.API/_ServiceExtensions/NewtonsoftJson/NewtonsoftJsonSetup.cs index 147472270..79d96c953 100644 --- a/IRaCIS.Core.API/_ServiceExtensions/NewtonsoftJson/NewtonsoftJsonSetup.cs +++ b/IRaCIS.Core.API/_ServiceExtensions/NewtonsoftJson/NewtonsoftJsonSetup.cs @@ -49,6 +49,8 @@ namespace IRaCIS.Core.API //必须放在后面 options.SerializerSettings.Converters.Add(services.BuildServiceProvider().GetService()); + //options.SerializerSettings.Converters.Add(new DateOnlyUniversalJsonConverter("yyyy-MM-dd")); + }) .AddControllersAsServices()//动态webApi属性注入需要 diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index 9c0eb0902..d941bdda3 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -1489,6 +1489,13 @@ + + + 查看授权时间内的稽查 (admin qa 看所有 EA只看到自己参与的) + + + + 稽查记录 列表 @@ -1505,7 +1512,7 @@ - 设置授权 + 设置稽查记录某个文件 或者某个文件夹授权 @@ -1555,6 +1562,13 @@ + + + 获取面包屑导航 (查询自己的祖先,不包括自己) + + + + 获取稽查文档 @@ -1570,13 +1584,6 @@ - - - 获取面包屑导航 - - - - 修改稽查文档 diff --git a/IRaCIS.Core.Application/Service/Document/AuditDocumentService.cs b/IRaCIS.Core.Application/Service/Document/AuditDocumentService.cs index a1a3a6a03..761618443 100644 --- a/IRaCIS.Core.Application/Service/Document/AuditDocumentService.cs +++ b/IRaCIS.Core.Application/Service/Document/AuditDocumentService.cs @@ -38,6 +38,42 @@ public class AuditDocumentService(IRepository _auditDocumentRepos #region 稽查新增需求 + + /// + /// 查看授权时间内的稽查 (admin qa 看所有 EA只看到自己参与的) + /// + /// + /// + [HttpPost] + public async Task> GetAuditRecordSelectList(AuditRecordQuery inQuery) + { + + var dateTimeNow = DateTime.Now; + + var isAdminOrQA = _userInfo.UserTypeEnumInt == (int)UserTypeEnum.Admin || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SuperAdmin || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.QA; + + var auditRecordQueryable = _auditRecordRepository + //过滤查看用户 + .WhereIf(isAdminOrQA == false, t => t.AuditRecordIdentityUserList.Any(t => t.IdentityUserId == _userInfo.IdentityUserId) && t.BeginTime < dateTimeNow && t.EndTime > dateTimeNow) + .WhereIf(inQuery.BeginAuditTime != null, t => t.AuditTime >= inQuery.BeginAuditTime) + .WhereIf(inQuery.EndAuditTime != null, t => t.AuditTime <= inQuery.EndAuditTime) + .WhereIf(inQuery.AuditState != null, t => t.AuditState == inQuery.AuditState) + .WhereIf(inQuery.AuditType != null, t => t.AuditType == inQuery.AuditType) + .WhereIf(inQuery.BeginTime != null, t => t.BeginTime >= inQuery.BeginTime) + .WhereIf(inQuery.EndTime != null, t => t.EndTime <= inQuery.EndTime) + .WhereIf(inQuery.BeginCreateTime != null, t => t.CreateTime >= inQuery.BeginCreateTime) + .WhereIf(inQuery.EndCreateTime != null, t => t.CreateTime <= inQuery.EndCreateTime) + .WhereIf(inQuery.IdentityUserName.IsNotNullOrEmpty(), t => t.AuditRecordIdentityUserList.Any(c => c.IdentityUser.UserName.Contains(inQuery.IdentityUserName) || c.IdentityUser.FullName.Contains(inQuery.IdentityUserName))) + .WhereIf(inQuery.CompanyName.IsNotNullOrEmpty(), t => t.CompanyName.Contains(inQuery.CompanyName)) + .WhereIf(inQuery.AuditContent.IsNotNullOrEmpty(), t => t.AuditContent.Contains(inQuery.AuditContent)) + .ProjectTo(_mapper.ConfigurationProvider); + + var list = await auditRecordQueryable.OrderBy(t => t.AuditTime).ToListAsync(); + + return list; + } + + /// /// 稽查记录 列表 /// @@ -51,8 +87,12 @@ public class AuditDocumentService(IRepository _auditDocumentRepos .WhereIf(inQuery.BeginAuditTime != null, t => t.AuditTime >= inQuery.BeginAuditTime) .WhereIf(inQuery.EndAuditTime != null, t => t.AuditTime <= inQuery.EndAuditTime) .WhereIf(inQuery.AuditState != null, t => t.AuditState == inQuery.AuditState) + .WhereIf(inQuery.AuditType != null, t => t.AuditType == inQuery.AuditType) .WhereIf(inQuery.BeginTime != null, t => t.BeginTime >= inQuery.BeginTime) .WhereIf(inQuery.EndTime != null, t => t.EndTime <= inQuery.EndTime) + .WhereIf(inQuery.BeginCreateTime != null, t => t.CreateTime >= inQuery.BeginCreateTime) + .WhereIf(inQuery.EndCreateTime != null, t => t.CreateTime <= inQuery.EndCreateTime) + .WhereIf(inQuery.IdentityUserName.IsNotNullOrEmpty(), t => t.AuditRecordIdentityUserList.Any(c => c.IdentityUser.UserName.Contains(inQuery.IdentityUserName) || c.IdentityUser.FullName.Contains(inQuery.IdentityUserName))) .WhereIf(inQuery.CompanyName.IsNotNullOrEmpty(), t => t.CompanyName.Contains(inQuery.CompanyName)) .WhereIf(inQuery.AuditContent.IsNotNullOrEmpty(), t => t.AuditContent.Contains(inQuery.AuditContent)) .ProjectTo(_mapper.ConfigurationProvider); @@ -127,7 +167,7 @@ public class AuditDocumentService(IRepository _auditDocumentRepos } /// - /// 设置授权 + /// 设置稽查记录某个文件 或者某个文件夹授权 /// /// /// @@ -148,6 +188,9 @@ public class AuditDocumentService(IRepository _auditDocumentRepos } + + + #endregion #region 闭包修改 @@ -290,7 +333,13 @@ public class AuditDocumentService(IRepository _auditDocumentRepos //闭包表中找到 设置Id为祖先的所有 后代 包括自己 var matchIdQuery = _auditDocumentClosureRepository.Where(t => inDto.Ids.Contains(t.AncestorId)).Select(t => t.DescendantId); - await _auditDocumentRepository.BatchUpdateNoTrackingAsync(t => matchIdQuery.Contains(t.Id), u => new AuditDocument() { IsAuthorization = inDto.IsAuthorization }); + //闭包表中找到 设置Id为后代的所有 祖先 包括自己 + var matchIdQuery2 = _auditDocumentClosureRepository.Where(t => inDto.Ids.Contains(t.DescendantId)).Select(t => t.AncestorId); + + + var unionQuery = matchIdQuery.Union(matchIdQuery2); + + await _auditDocumentRepository.BatchUpdateNoTrackingAsync(t => unionQuery.Contains(t.Id), u => new AuditDocument() { IsAuthorization = inDto.IsAuthorization }); return ResponseOutput.Ok(); @@ -464,6 +513,48 @@ public class AuditDocumentService(IRepository _auditDocumentRepos + /// + /// 获取面包屑导航 (查询自己的祖先,不包括自己) + /// + /// + /// + [HttpPost] + public async Task> GetBreadcrumbData(GetBreadcrumbDataInDto inDto) + { + + //闭包表中找到 设置Id为后代的所有 祖先 Depth > 0 不包括自己 + var list = await _auditDocumentClosureRepository.Where(t => inDto.Id == t.DescendantId /*&& t.Depth > 0*/) + .OrderByDescending(t => t.Depth).Select(t => t.Ancestor).ProjectTo(_mapper.ConfigurationProvider).ToListAsync(); + + return list; + + + + #region 无闭包表废弃 + //List result = new List(); + + //await findParent(result, inDto.Id); + //async Task findParent(List datas, Guid id) + //{ + // var data = await _auditDocumentRepository.Where(x => x.Id == id).ProjectTo(_mapper.ConfigurationProvider).FirstNotNullAsync(); + // datas.Add(data); + // if (data.ParentId != null) + // { + // await findParent(datas, data.ParentId.Value); + // } + + //} + + //result.Reverse(); + + //return result; + + #endregion + + } + + + #endregion @@ -506,38 +597,6 @@ public class AuditDocumentService(IRepository _auditDocumentRepos } - /// - /// 获取面包屑导航 - /// - /// - /// - [HttpPost] - public async Task> GetBreadcrumbData(GetBreadcrumbDataInDto inDto) - { - List result = new List(); - - await findParent(result, inDto.Id); - async Task findParent(List datas, Guid id) - { - var data = await _auditDocumentRepository.Where(x => x.Id == id).ProjectTo(_mapper.ConfigurationProvider).FirstNotNullAsync(); - datas.Add(data); - if (data.ParentId != null) - { - await findParent(datas, data.ParentId.Value); - } - - } - - result.Reverse(); - - return result; - - } - - - - - #endregion diff --git a/IRaCIS.Core.Application/Service/Document/DTO/AuditDocumentViewModel.cs b/IRaCIS.Core.Application/Service/Document/DTO/AuditDocumentViewModel.cs index 9dee2cadf..6321bca29 100644 --- a/IRaCIS.Core.Application/Service/Document/DTO/AuditDocumentViewModel.cs +++ b/IRaCIS.Core.Application/Service/Document/DTO/AuditDocumentViewModel.cs @@ -67,6 +67,15 @@ public class AuditRecordQuery : PageInput public DateTime? EndTime { get; set; } public AuditState? AuditState { get; set; } + + public AuditType? AuditType { get; set; } + + + public DateTime? BeginCreateTime { get; set; } + + public DateTime? EndCreateTime { get; set; } + + public string? IdentityUserName { get; set; } } public class SetAuditRecordPermissionCommand diff --git a/IRaCIS.Core.Application/TestService.cs b/IRaCIS.Core.Application/TestService.cs index ba4f6d478..3e25bb06e 100644 --- a/IRaCIS.Core.Application/TestService.cs +++ b/IRaCIS.Core.Application/TestService.cs @@ -81,9 +81,12 @@ namespace IRaCIS.Core.Application.Service /// /// [AllowAnonymous] - public async Task RebuildAuditDocumentClosureAsync([FromServices]IRepository _auditDocumentClosureRepository, [FromServices] IRepository _auditDocumentRepository) + public async Task RebuildAuditDocumentClosureAsync([FromServices] IRepository _auditDocumentClosureRepository, [FromServices] IRepository _auditDocumentRepository) { - var documents = await _auditDocumentRepository.Where().Select(t=>new {t.Id,t.ParentId}).ToListAsync(); + + await _auditDocumentClosureRepository.BatchDeleteNoTrackingAsync(t => t.Id != Guid.Empty); + + var documents = await _auditDocumentRepository.Where().Select(t => new { t.Id, t.ParentId }).ToListAsync(); var closures = new List();