diff --git a/Src/Dlhis.Basic/WorkGrids/Controllers/WorkGridsController.cs b/Src/Dlhis.Basic/WorkGrids/Controllers/WorkGridsController.cs index 82d207f6..e972efee 100644 --- a/Src/Dlhis.Basic/WorkGrids/Controllers/WorkGridsController.cs +++ b/Src/Dlhis.Basic/WorkGrids/Controllers/WorkGridsController.cs @@ -5,7 +5,6 @@ using Dlhis.Entity.Basic.Enums; using Kurisu.AspNetCore.CustomClass; using Kurisu.AspNetCore.DataAccess.Dto; using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop; -using Kurisu.AspNetCore.UnifyResultAndValidation; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -40,7 +39,7 @@ public class WorkGridsController : ControllerBase [HttpGet("gainfo-selections")] public async Task> GetPageAsync([FromQuery] WorkGridGainfoPageRequest request) { - return await _workGridService.GetPageAsync(request); + return await _workGridService.GetUserSelectionPageAsync(request); } @@ -57,7 +56,7 @@ public class WorkGridsController : ControllerBase } /// - /// /网格分页 + /// 网格分页 /// /// /// @@ -174,11 +173,16 @@ public class WorkGridsController : ControllerBase /// /// [HttpGet("user/schedule/summary")] - public async Task> GetListSummaryAsync([FromQuery] Guid workGridCode, [FromQuery] DateTimePeriod datePeriod) + public async Task> GetListSummaryAsync([FromQuery] Guid workGridCode, [FromQuery] DateTimePeriod datePeriod) { - var start = datePeriod.Start!.Value; - var end = datePeriod.End!.Value; - return await _workGridScheduleService.GetListSummaryAsync(workGridCode, new DateOnly(start.Year, start.Month, start.Day), new DateOnly(end.Year, end.Month, end.Day)); + return await _workGridScheduleService.GetListSummaryAsync(workGridCode, datePeriod); + } + + [HttpPost("user/schedule/cancel")] + [Transactional] + public async Task ManuallyCancelAsync(WorkGridScheduleCancelRequest request) + { + await _workGridScheduleService.ManuallyCancelAsync(request.Id, request.Reason); } /// diff --git a/Src/Dlhis.Basic/WorkGrids/Repositories/IWorkGridRepository.cs b/Src/Dlhis.Basic/WorkGrids/Repositories/IWorkGridRepository.cs new file mode 100644 index 00000000..7a804be9 --- /dev/null +++ b/Src/Dlhis.Basic/WorkGrids/Repositories/IWorkGridRepository.cs @@ -0,0 +1,17 @@ +using Dlhis.Basic.WorkGrids.Request; +using Dlhis.Basic.WorkGrids.Response; +using Kurisu.AspNetCore.DataAccess.Dto; + +namespace Dlhis.Basic.WorkGrids.Repositories; + +public interface IWorkGridRepository : IScopeDependency +{ + /// + /// 人员选择接口 + /// + /// + /// + Task> GetUserSelectionPageAsync(WorkGridGainfoPageRequest request); + + Task> GetPageAsync(WorkGridPageRequest request); +} \ No newline at end of file diff --git a/Src/Dlhis.Basic/WorkGrids/Repositories/IWorkGridScheduleRepository.cs b/Src/Dlhis.Basic/WorkGrids/Repositories/IWorkGridScheduleRepository.cs index 84fcaa64..30d9aa84 100644 --- a/Src/Dlhis.Basic/WorkGrids/Repositories/IWorkGridScheduleRepository.cs +++ b/Src/Dlhis.Basic/WorkGrids/Repositories/IWorkGridScheduleRepository.cs @@ -12,4 +12,17 @@ public interface IWorkGridScheduleRepository : IScopeDependency /// 日期 /// 最大连续排班信息列表 Task> MaximumConsecutiveUserCodesAsync(List userCodes, int days, DateOnly date); + + + /// + /// 获取指定网格和日期范围的排班汇总列表 + /// + /// 网格编码 + /// 开始日期 + /// 结束日期 + /// 排班汇总列表 + Task> GetListSummaryAsync(Guid workGridCode, DateOnly start, DateOnly end); + + + Task CancelAsync(long id, string reason); } \ No newline at end of file diff --git a/Src/Dlhis.Basic/WorkGrids/Repositories/Implements/WorkGridRepository.cs b/Src/Dlhis.Basic/WorkGrids/Repositories/Implements/WorkGridRepository.cs new file mode 100644 index 00000000..fe0510d7 --- /dev/null +++ b/Src/Dlhis.Basic/WorkGrids/Repositories/Implements/WorkGridRepository.cs @@ -0,0 +1,97 @@ +using Dlhis.Basic.WorkGrids.Request; +using Dlhis.Basic.WorkGrids.Response; +using Dlhis.Constants; +using Dlhis.Entity.Basic.Entity; +using Dlhis.Entity.Basic.Enums; +using Kurisu.AspNetCore.Authentication.Abstractions; +using Kurisu.AspNetCore.DataAccess.Dto; +using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions; +using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; +using Kurisu.AspNetCore.Utils.Extensions; +using SqlSugar; + +namespace Dlhis.Basic.WorkGrids.Repositories.Implements; + +public class WorkGridRepository : IWorkGridRepository +{ + private readonly ICurrentUser _currentUser; + private readonly IDbContext _dbContext; + + public WorkGridRepository(ICurrentUser currentUser, IDbContext dbContext) + { + _currentUser = currentUser; + _dbContext = dbContext; + } + + public async Task> GetUserSelectionPageAsync(WorkGridGainfoPageRequest request) + { + var factory = _currentUser.GetStringTenantId(); + + var pagination = await _dbContext.Queryable() + .LeftJoin((x, dept) => x.DepartmentNo == dept.No) + .LeftJoin((x, dept, wgu) => x.Code == wgu.UserCode) + .LeftJoin((x, dept, wgu, wg) => wgu.WorkGridCode == wg.Code) + .Where(x => x.Factory == factory && (x.Type == GainfoUserTypeEnumType.Normal || x.Type == GainfoUserTypeEnumType.SecurityWhite)) + .WhereIF(request.Search.IsPresent(), x => x.Code == request.Search || x.Name.Contains(request.Search)) + .Select((x, dept, wgu, wg) => new WorkGridGainfoPageResponse + { + Id = x.Id, + No = x.No, + Type = x.Type, + Name = x.Name, + Code = x.Code, + Gender = x.Gender, + DepartmentNo = x.DepartmentNo, + DepartmentName = dept.Name, + Remark = x.Remark, + WorkGridName = wg.Name, + }) + .ToPageListAsync(request); + + return pagination; + } + + public async Task> GetPageAsync(WorkGridPageRequest request) + { + var role = _currentUser.GetRole(); + var factory = _currentUser.GetStringTenantId(); + var userCode = _currentUser.GetUserClaim(UserClaimConstants.JinkoCode); + var isAll = role is "admin" or "tenant-admin" or "WGZGLY"; + + return await _dbContext.Queryable() + .LeftJoin((x, ga) => x.LeaderUserCode == ga.Code) + .WhereIF(!isAll, x => x.LeaderUserCode == userCode) + .WhereIF(request.Search.IsPresent(), x => x.Name.Contains(request.Search) || x.LeaderUserCode == request.Search) + .Where(x => SqlFunc.Subqueryable() + .Where(p => p.Code == x.LeaderUserCode && p.Factory == factory) + .Any() + || + SqlFunc.Subqueryable() + .Where(p => p.Code == x.LeaderUserCode && p.Factory == factory) + .Any() + || + SqlFunc.Subqueryable() + .LeftJoin((p, pga) => p.UserCode == pga.Code) + .Where(p => p.WorkGridCode == x.Code) + .Where((p, pga) => pga.Factory == factory) + .Where(p => p.IsDeleted == false) + .Any() + ) + .Select((x, ga) => new WorkGridPageResponse + { + Id = x.Id, + Code = x.Code, + Name = x.Name, + LeaderUserCode = x.LeaderUserCode, + UserName = ga.Name, + Remark = x.Remark, + MaxUserTipCount = x.MaxUserTipCount, + MaxConsecutiveTipCount = x.MaxConsecutiveTipCount, + MaxConsecutiveLimitCount = x.MaxConsecutiveLimitCount, + Alias = x.Alias, + Count = x.Count, + UserCount = SqlFunc.Subqueryable().Where(p => p.WorkGridCode == x.Code && p.IsDeleted == false).Count() + }) + .ToPageListAsync(request); + } +} \ No newline at end of file diff --git a/Src/Dlhis.Basic/WorkGrids/Repositories/Implements/WorkGridScheduleRepository.cs b/Src/Dlhis.Basic/WorkGrids/Repositories/Implements/WorkGridScheduleRepository.cs index 6175ca55..e22a56dc 100644 --- a/Src/Dlhis.Basic/WorkGrids/Repositories/Implements/WorkGridScheduleRepository.cs +++ b/Src/Dlhis.Basic/WorkGrids/Repositories/Implements/WorkGridScheduleRepository.cs @@ -1,4 +1,6 @@ using Dlhis.Basic.WorkGrids.Response; +using Dlhis.Entity.Basic.Entity; +using Kurisu.AspNetCore.Authentication.Abstractions; using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; using Kurisu.AspNetCore.Utils.Extensions; @@ -7,10 +9,12 @@ namespace Dlhis.Basic.WorkGrids.Repositories.Implements; public class WorkGridScheduleRepository : IWorkGridScheduleRepository { private readonly IDbContext _dbContext; + private readonly ICurrentUser _currentUser; - public WorkGridScheduleRepository(IDbContext dbContext) + public WorkGridScheduleRepository(IDbContext dbContext, ICurrentUser currentUser) { _dbContext = dbContext; + _currentUser = currentUser; } public async Task> MaximumConsecutiveUserCodesAsync(List userCodes, int days, DateOnly date) @@ -35,7 +39,7 @@ WITH ranked_dates AS (SELECT UserCode, Date, ROW_NUMBER() OVER (PARTITION BY UserCode ORDER BY Date) AS rn FROM WorkGridSchedules - where IsDeleted = 0 and UserCode in ({userCodesStr}) + where IsDeleted = 0 and IsCancel = 0 and UserCode in ({userCodesStr}) GROUP BY UserCode, Date), grouped AS (SELECT UserCode, Date, @@ -59,4 +63,46 @@ where (@dateBefore >= start_date return await _dbContext.Client.Ado.SqlQueryAsync(sql, parameters); } + + public async Task> GetListSummaryAsync(Guid workGridCode, DateOnly start, DateOnly end) + { + var workGridScheduleList = await _dbContext.Queryable() + .Where(x => x.WorkGridCode == workGridCode && x.Date >= start && x.Date <= end) + .Where(x => x.IsCancel == false) + .ToListAsync(); + + return workGridScheduleList.GroupBy(x => x.Date) + .Select(grp => + { + return new WorkGridScheduleSummaryResponse + { + WorkGridCode = workGridCode, + Date = grp.Key, + Details = grp.GroupBy(p => p.PeriodType) + .Select(p => new WorkGridScheduleSummaryDetailResponse + { + PeriodType = p.Key, + Count = p.Count() + }) + }; + }).ToList(); + } + + public async Task CancelAsync(long id, string reason) + { + var userId = _currentUser.GetIntSubjectId(); + + await _dbContext.Updateable() + .SetColumns(x => x.IsCancel == true) + .SetColumns(x => x.ModifiedBy == userId) + .SetColumns(x => x.ModifiedTime == DateTime.Now) + .Where(x => x.Id == id) + .ExecuteCommandAsync(); + + await _dbContext.InsertAsync(new WorkGridScheduleCancelRecordEntity + { + WorkGridScheduleId = id, + Reason = reason + }); + } } \ No newline at end of file diff --git a/Src/Dlhis.Basic/WorkGrids/Request/WorkGridPageRequest.cs b/Src/Dlhis.Basic/WorkGrids/Request/WorkGridPageRequest.cs index 811a3d55..81fceedd 100644 --- a/Src/Dlhis.Basic/WorkGrids/Request/WorkGridPageRequest.cs +++ b/Src/Dlhis.Basic/WorkGrids/Request/WorkGridPageRequest.cs @@ -13,4 +13,9 @@ public class WorkGridPageRequest : PageDto /// 排班日期 /// public DateTime Date { get; set; } = DateTime.Today; + + /// + /// 是否启用显示日期排班详情 + /// + public bool EnableShowDateScheduleDetails { get; set; } } \ No newline at end of file diff --git a/Src/Dlhis.Basic/WorkGrids/Request/WorkGridScheduleCancelRequest.cs b/Src/Dlhis.Basic/WorkGrids/Request/WorkGridScheduleCancelRequest.cs new file mode 100644 index 00000000..f33ebcc5 --- /dev/null +++ b/Src/Dlhis.Basic/WorkGrids/Request/WorkGridScheduleCancelRequest.cs @@ -0,0 +1,17 @@ +using System.ComponentModel.DataAnnotations; + +namespace Dlhis.Basic.WorkGrids.Request; + +public class WorkGridScheduleCancelRequest +{ + /// + /// 数据id + /// + public long Id { get; set; } + + /// + /// 取消原因 + /// + [Required(ErrorMessage = "{0}不能为空")] + public string Reason { get; set; } +} \ No newline at end of file diff --git a/Src/Dlhis.Basic/WorkGrids/Response/WorkGridPageResponse.cs b/Src/Dlhis.Basic/WorkGrids/Response/WorkGridPageResponse.cs index 7f5e564f..d41c5e0b 100644 --- a/Src/Dlhis.Basic/WorkGrids/Response/WorkGridPageResponse.cs +++ b/Src/Dlhis.Basic/WorkGrids/Response/WorkGridPageResponse.cs @@ -39,11 +39,16 @@ public class WorkGridPageResponse /// public int MaxUserTipCount { get; set; } + /// + /// 最大连续排班预警值 + /// public int MaxConsecutiveTipCount { get; set; } + /// + /// 最大连续排班限制值 + /// public int MaxConsecutiveLimitCount { get; set; } - - + /// /// 别名 /// @@ -53,4 +58,6 @@ public class WorkGridPageResponse /// 编制人数 /// public int Count { get; set; } + + public WorkGridScheduleSummaryResponse DateScheduleSummary { get; set; } } \ No newline at end of file diff --git a/Src/Dlhis.Basic/WorkGrids/Response/WorkGridScheduleResponse.cs b/Src/Dlhis.Basic/WorkGrids/Response/WorkGridScheduleResponse.cs index 34a61f34..f6fb7b62 100644 --- a/Src/Dlhis.Basic/WorkGrids/Response/WorkGridScheduleResponse.cs +++ b/Src/Dlhis.Basic/WorkGrids/Response/WorkGridScheduleResponse.cs @@ -4,11 +4,28 @@ namespace Dlhis.Basic.WorkGrids.Response; public class WorkGridScheduleResponse { + /// + /// 日期 + /// public DateOnly Date { get; set; } + /// + /// 排版时间段 + /// public WorkGridTimePeriodEnumType PeriodType { get; set; } + /// + /// 工号 + /// public string UserCode { get; set; } - + + /// + /// 姓名 + /// public string UserName { get; set; } + + /// + /// 是否取消 + /// + public bool IsCancel { get; set; } } \ No newline at end of file diff --git a/Src/Dlhis.Basic/WorkGrids/Response/WorkGridScheduleSummaryResponse.cs b/Src/Dlhis.Basic/WorkGrids/Response/WorkGridScheduleSummaryResponse.cs index b55d9606..8f30ebe1 100644 --- a/Src/Dlhis.Basic/WorkGrids/Response/WorkGridScheduleSummaryResponse.cs +++ b/Src/Dlhis.Basic/WorkGrids/Response/WorkGridScheduleSummaryResponse.cs @@ -4,6 +4,7 @@ namespace Dlhis.Basic.WorkGrids.Response; public class WorkGridScheduleSummaryResponse { + public Guid WorkGridCode { get; set; } public DateOnly Date { get; set; } public IEnumerable Details { get; set; } } diff --git a/Src/Dlhis.Basic/WorkGrids/Services/IWorkGridScheduleService.cs b/Src/Dlhis.Basic/WorkGrids/Services/IWorkGridScheduleService.cs index 1c31dcb3..5a3c9423 100644 --- a/Src/Dlhis.Basic/WorkGrids/Services/IWorkGridScheduleService.cs +++ b/Src/Dlhis.Basic/WorkGrids/Services/IWorkGridScheduleService.cs @@ -1,6 +1,7 @@ using Dlhis.Basic.WorkGrids.Request; using Dlhis.Basic.WorkGrids.Response; using Dlhis.Entity.Basic.Enums; +using Kurisu.AspNetCore.CustomClass; using Kurisu.AspNetCore.DataAccess.Dto; namespace Dlhis.Basic.WorkGrids.Services; @@ -35,10 +36,9 @@ public interface IWorkGridScheduleService : IScopeDependency /// 获取指定网格和日期范围的排班汇总列表 /// /// 网格编码 - /// 开始日期 - /// 结束日期 + /// /// 排班汇总列表 - Task> GetListSummaryAsync(Guid workGridCode, DateOnly start, DateOnly end); + Task> GetListSummaryAsync(Guid workGridCode, DateTimePeriod dateTimePeriod); /// /// 获取排班考勤分页数据 @@ -60,6 +60,15 @@ public interface IWorkGridScheduleService : IScopeDependency /// 考勤日志ID列表 Task ManuallyUploadAsync(List logIds); + /// + /// 手动取消排班 + /// + /// 只能操作历史数据 + /// + /// + /// + Task ManuallyCancelAsync(long id, string reason); + /// /// 测试接口 /// diff --git a/Src/Dlhis.Basic/WorkGrids/Services/IWorkGridService.cs b/Src/Dlhis.Basic/WorkGrids/Services/IWorkGridService.cs index eb1f2517..a71fa0c2 100644 --- a/Src/Dlhis.Basic/WorkGrids/Services/IWorkGridService.cs +++ b/Src/Dlhis.Basic/WorkGrids/Services/IWorkGridService.cs @@ -14,7 +14,7 @@ public interface IWorkGridService : IScopeDependency /// /// /// - Task> GetPageAsync(WorkGridGainfoPageRequest request); + Task> GetUserSelectionPageAsync(WorkGridGainfoPageRequest request); /// /// 保存 diff --git a/Src/Dlhis.Basic/WorkGrids/Services/Implements/WorkGridScheduleService.cs b/Src/Dlhis.Basic/WorkGrids/Services/Implements/WorkGridScheduleService.cs index 6a568669..c610b8d9 100644 --- a/Src/Dlhis.Basic/WorkGrids/Services/Implements/WorkGridScheduleService.cs +++ b/Src/Dlhis.Basic/WorkGrids/Services/Implements/WorkGridScheduleService.cs @@ -156,6 +156,19 @@ public class WorkGridScheduleService : IWorkGridScheduleService } + public async Task ManuallyCancelAsync(long id, string reason) + { + var currentDate = DateOnly.FromDateTime(DateTime.Today); + + var workGridSchedule = await _dbContext.Queryable() + .Where(x => x.Date < currentDate) + .SingleAsync(x => x.Id == id); + workGridSchedule.ThrowIfNull("排班信息不存在或不可操作"); + workGridSchedule.IsCancel.ThrowIfTrue("排班信息已被取消,请勿重复操作"); + + await _workGridScheduleRepository.CancelAsync(id, reason); + } + public async Task TestAsync(WorkGridScheduleSaveRequest request) { request.UserCodes = request.UserCodes.Distinct().ToList(); @@ -241,7 +254,6 @@ public class WorkGridScheduleService : IWorkGridScheduleService } } - /// public async Task> GetListAsync(Guid workGridCode, DateOnly date, WorkGridTimePeriodEnumType? periodType) { var data = await _dbContext.Queryable() @@ -253,32 +265,23 @@ public class WorkGridScheduleService : IWorkGridScheduleService Date = x.Date, PeriodType = x.PeriodType, UserCode = x.UserCode, - UserName = ga.Name + UserName = ga.Name, + IsCancel = x.IsCancel }) .ToListAsync(); return data; } - /// - public async Task> GetListSummaryAsync(Guid workGridCode, DateOnly start, DateOnly end) + public async Task> GetListSummaryAsync(Guid workGridCode, DateTimePeriod dateTimePeriod) { - var workGridSchedules = await _dbContext.Queryable() - .Where(x => x.WorkGridCode == workGridCode && x.Date >= start && x.Date <= end) - .ToListAsync(); + var start = dateTimePeriod.Start!.Value; + var end = dateTimePeriod.End!.Value; - return workGridSchedules.GroupBy(x => x.Date).Select(x => - { - return new WorkGridScheduleSummaryResponse - { - Date = x.Key, - Details = x.GroupBy(p => p.PeriodType).Select(p => new WorkGridScheduleSummaryDetailResponse - { - PeriodType = p.Key, - Count = p.Count() - }) - }; - }); + return await _workGridScheduleRepository.GetListSummaryAsync(workGridCode, + new DateOnly(start.Year, start.Month, start.Day), + new DateOnly(end.Year, end.Month, end.Day) + ); } /// diff --git a/Src/Dlhis.Basic/WorkGrids/Services/Implements/WorkGridService.cs b/Src/Dlhis.Basic/WorkGrids/Services/Implements/WorkGridService.cs index 02a60ee1..640f3592 100644 --- a/Src/Dlhis.Basic/WorkGrids/Services/Implements/WorkGridService.cs +++ b/Src/Dlhis.Basic/WorkGrids/Services/Implements/WorkGridService.cs @@ -5,15 +5,12 @@ using Dlhis.Basic.WorkGrids.Response; using Dlhis.Basic.WorkGrids.Validations; using Dlhis.Constants; using Dlhis.Entity.Basic.Entity; -using Dlhis.Entity.Basic.Enums; using Dlhis.Entity.Common.Enums; using Kurisu.AspNetCore.Authentication.Abstractions; using Kurisu.AspNetCore.DataAccess.Dto; -using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions; using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; using Kurisu.AspNetCore.Utils.Extensions; using Mapster; -using SqlSugar; namespace Dlhis.Basic.WorkGrids.Services.Implements; @@ -22,47 +19,28 @@ public class WorkGridService : IWorkGridService private readonly IDbContext _dbContext; private readonly ICurrentUser _currentUser; private readonly IWorkGridValidateService _workGridValidateService; + private readonly IWorkGridRepository _workGridRepository; private readonly IWorkGridScheduleRepository _workGridScheduleRepository; private readonly IOperateLog _operateLog; public WorkGridService(IDbContext dbContext, ICurrentUser currentUser, IWorkGridValidateService workGridValidateService, + IWorkGridRepository workGridRepository, IWorkGridScheduleRepository workGridScheduleRepository, IOperateLog operateLog) { _dbContext = dbContext; _currentUser = currentUser; _workGridValidateService = workGridValidateService; + _workGridRepository = workGridRepository; _workGridScheduleRepository = workGridScheduleRepository; _operateLog = operateLog; } - /// - public async Task> GetPageAsync(WorkGridGainfoPageRequest request) + public async Task> GetUserSelectionPageAsync(WorkGridGainfoPageRequest request) { - var factory = _currentUser.GetStringTenantId(); - - var pagination = await _dbContext.Queryable() - .LeftJoin((x, dept) => x.DepartmentNo == dept.No) - .LeftJoin((x, dept, wgu) => x.Code == wgu.UserCode) - .LeftJoin((x, dept, wgu, wg) => wgu.WorkGridCode == wg.Code) - .Where(x => x.Factory == factory && (x.Type == GainfoUserTypeEnumType.Normal || x.Type == GainfoUserTypeEnumType.SecurityWhite)) - .WhereIF(request.Search.IsPresent(), x => x.Code == request.Search || x.Name.Contains(request.Search)) - .Select((x, dept, wgu, wg) => new WorkGridGainfoPageResponse - { - Id = x.Id, - No = x.No, - Type = x.Type, - Name = x.Name, - Code = x.Code, - Gender = x.Gender, - DepartmentNo = x.DepartmentNo, - DepartmentName = dept.Name, - Remark = x.Remark, - WorkGridName = wg.Name, - }) - .ToPageListAsync(request); + var pagination = await _workGridRepository.GetUserSelectionPageAsync(request); var userCodeList = pagination.Data.Select(x => x.Code).ToList(); if (userCodeList.Any()) @@ -131,46 +109,27 @@ public class WorkGridService : IWorkGridService public async Task> GetPageAsync(WorkGridPageRequest request) { - var role = _currentUser.GetRole(); - var factory = _currentUser.GetStringTenantId(); - var userCode = _currentUser.GetUserClaim(UserClaimConstants.JinkoCode); - var isAll = role is "admin" or "tenant-admin" or "WGZGLY"; + var pagination = await _workGridRepository.GetPageAsync(request); - return await _dbContext.Queryable() - .LeftJoin((x, ga) => x.LeaderUserCode == ga.Code) - .WhereIF(!isAll, x => x.LeaderUserCode == userCode) - .WhereIF(request.Search.IsPresent(), x => x.Name.Contains(request.Search) || x.LeaderUserCode == request.Search) - .Where(x => SqlFunc.Subqueryable() - .Where(p => p.Code == x.LeaderUserCode && p.Factory == factory) - .Any() - || - SqlFunc.Subqueryable() - .Where(p => p.Code == x.LeaderUserCode && p.Factory == factory) - .Any() - || - SqlFunc.Subqueryable() - .LeftJoin((p, pga) => p.UserCode == pga.Code) - .Where(p => p.WorkGridCode == x.Code) - .Where((p, pga) => pga.Factory == factory) - .Where(p => p.IsDeleted == false) - .Any() - ) - .Select((x, ga) => new WorkGridPageResponse + if (request.EnableShowDateScheduleDetails) + { + var workGridCodes = pagination.Data.Select(wg => wg.Code).ToList(); + if (workGridCodes.Any()) { - Id = x.Id, - Code = x.Code, - Name = x.Name, - LeaderUserCode = x.LeaderUserCode, - UserName = ga.Name, - Remark = x.Remark, - MaxUserTipCount = x.MaxUserTipCount, - MaxConsecutiveTipCount = x.MaxConsecutiveTipCount, - MaxConsecutiveLimitCount = x.MaxConsecutiveLimitCount, - Alias = x.Alias, - Count = x.Count, - UserCount = SqlFunc.Subqueryable().Where(p => p.WorkGridCode == x.Code && p.IsDeleted == false).Count() - }) - .ToPageListAsync(request); + var date = DateOnly.FromDateTime(request.Date); + + var tasks = workGridCodes.Select(code => _workGridScheduleRepository.GetListSummaryAsync(code, date, date)); + var scheduleSummaryResponsesPack = await Task.WhenAll(tasks); + var scheduleSummaryResponses = scheduleSummaryResponsesPack.SelectMany(x => x).ToList(); + + foreach (var item in pagination.Data) + { + item.DateScheduleSummary = scheduleSummaryResponses.FirstOrDefault(x => x.WorkGridCode == item.Code); + } + } + } + + return pagination; } public async Task ChangeAsync(string from, string to) @@ -283,7 +242,6 @@ public class WorkGridService : IWorkGridService await _operateLog.LogAsync(OperateLogType.WorkGrid, $"分配人员到网格({myWorkGrid.Name}),人员:{dataToInserts.Select(x => x.UserCode).Join(",")}"); } - /// public async Task RemoveAsync(WorkGridUserRemoveRequest request) { var role = _currentUser.GetRole(); diff --git a/Src/Dlhis.Entity/Basic/Entity/WorkGridEntity.cs b/Src/Dlhis.Entity/Basic/Entity/WorkGridEntity.cs index 79ba352e..2e31d1bd 100644 --- a/Src/Dlhis.Entity/Basic/Entity/WorkGridEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/WorkGridEntity.cs @@ -38,21 +38,21 @@ public class WorkGridEntity : SugarBaseEntity, ISoftDeleted, ITenantId public string Remark { get; set; } /// - /// 最大排班用户数提醒 + /// 排班用户数提醒 /// - [SugarColumn(IsNullable = false, ColumnDescription = "最大排班用户数提醒")] + [SugarColumn(IsNullable = false, ColumnDescription = "排班用户数提醒")] public int MaxUserTipCount { get; set; } /// - /// 最大排班连续天数提醒 + /// 排班连续天数提醒天数 /// - [SugarColumn(IsNullable = false, ColumnDescription = "最大排班连续天数提醒")] + [SugarColumn(IsNullable = false, ColumnDescription = "排班连续天数提醒天数")] public int MaxConsecutiveTipCount { get; set; } /// - /// 请设置连续排班限制 + /// 连续排班限制人数 /// - [SugarColumn(IsNullable = false, ColumnDescription = "请设置连续排班限制")] + [SugarColumn(IsNullable = false, ColumnDescription = "连续排班限制人数")] public int MaxConsecutiveLimitCount { get; set; } /// @@ -68,8 +68,8 @@ public class WorkGridEntity : SugarBaseEntity, ISoftDeleted, ITenantId public int Count { get; set; } = 50; + [SugarColumn(IsNullable = false, ColumnDataType = "bit")] public bool IsDeleted { get; set; } - /// public string TenantId { get; set; } } \ No newline at end of file diff --git a/Src/Dlhis.Entity/Basic/Entity/WorkGridScheduleCancelEntity.cs b/Src/Dlhis.Entity/Basic/Entity/WorkGridScheduleCancelEntity.cs new file mode 100644 index 00000000..7fbd022b --- /dev/null +++ b/Src/Dlhis.Entity/Basic/Entity/WorkGridScheduleCancelEntity.cs @@ -0,0 +1,23 @@ +using Kurisu.AspNetCore.DataAccess.SqlSugar; +using SqlSugar; + +namespace Dlhis.Entity.Basic.Entity; + +/// +/// 网格排班取消记录 +/// +[SugarTable(TableName = "WorkGridScheduleCancelRecord", TableDescription = "工作网格排班取消记录")] +public class WorkGridScheduleCancelRecordEntity : SugarBaseEntity +{ + /// + /// 原始记录id + /// + [SugarColumn(IsNullable = false, ColumnDescription = "原始记录id", UniqueGroupNameList = new[] { "Unique_WorkGridScheduleCancel_WorkGridScheduleId" })] + public long WorkGridScheduleId { get; set; } + + /// + /// 取消原因 + /// + [SugarColumn(IsNullable = false, ColumnDescription = "取消原因")] + public string Reason { get; set; } +} \ No newline at end of file diff --git a/Src/Dlhis.Entity/Basic/Entity/WorkGridScheduleEntity.cs b/Src/Dlhis.Entity/Basic/Entity/WorkGridScheduleEntity.cs index 517bf5e6..2b402712 100644 --- a/Src/Dlhis.Entity/Basic/Entity/WorkGridScheduleEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/WorkGridScheduleEntity.cs @@ -36,6 +36,11 @@ public class WorkGridScheduleEntity : SugarBaseEntity , ISoftDeleted [SugarColumn(IsNullable = false, ColumnDescription = "工号", IndexGroupNameList = new[] { "idx_WorkGridSchedules_userCode" })] public string UserCode { get; set; } + /// + /// 是否取消 + /// + [SugarColumn(IsNullable = false, ColumnDescription = "是否取消", ColumnDataType = "bit")] + public bool IsCancel { get; set; } public bool IsDeleted { get; set; } } \ No newline at end of file