feat 最大连续排班控制增加
This commit is contained in:
@@ -21,4 +21,6 @@ public interface IWorkGridScheduleService : IScopeDependency
|
||||
Task<Pagination<WorkGridScheduleAttendancePageResponse>> GetAttendancePageAsync(WorkGridScheduleAttendancePageRequest request);
|
||||
|
||||
Task ManuallyUploadAsync(List<long> logIds);
|
||||
|
||||
Task<List<WorkGridScheduleMaximumConsecutiveDto>> MaximumConsecutiveUserCodesAsync(List<string> userCodes, int days, DateOnly date);
|
||||
}
|
||||
@@ -9,6 +9,13 @@ namespace Dlhis.Basic.WorkGrids.Services;
|
||||
/// </summary>
|
||||
public interface IWorkGridService : IScopeDependency
|
||||
{
|
||||
/// <summary>
|
||||
/// 人员选择接口
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
Task<Pagination<WorkGridGainfoPageResponse>> GetPageAsync(WorkGridGainfoPageRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// 保存
|
||||
/// </summary>
|
||||
|
||||
@@ -62,6 +62,9 @@ public class WorkGridScheduleService : IWorkGridScheduleService
|
||||
|
||||
await _dbContext.InsertAsync(toInserts);
|
||||
|
||||
var maximumConsecutiveDtos = await MaximumConsecutiveUserCodesAsync(request.UserCodes, 11, request.Date);
|
||||
maximumConsecutiveDtos.ThrowIfExists(maximumConsecutiveDtos.Select(x => $"{x.UserCode}已经连续排班10天({x.Start}-{x.End}),不可继续排班").Join("\r\n"));
|
||||
|
||||
await _operateLog.LogAsync(OperateLogType.WorkGrid, $"新增网格({workGrid.Name}){request.Date.ToString("yyyy-M-d")}的{request.PeriodType.GetDescription()}人员:{request.UserCodes.Join(",")}");
|
||||
}
|
||||
|
||||
@@ -206,4 +209,39 @@ public class WorkGridScheduleService : IWorkGridScheduleService
|
||||
|
||||
await _operateLog.LogAsync(OperateLogType.WorkGrid, $"重提上传考勤:{requests.Select(x => x.Id).Join(",")}");
|
||||
}
|
||||
|
||||
public async Task<List<WorkGridScheduleMaximumConsecutiveDto>> MaximumConsecutiveUserCodesAsync(List<string> userCodes, int days, DateOnly date)
|
||||
{
|
||||
var p = userCodes.Select(x => $"@param{x}").Join(",");
|
||||
var values = userCodes.ToDictionary(x => $"param{x}", x => x);
|
||||
|
||||
values.Add("date", date.ToString("yyyy-MM-dd"));
|
||||
values.Add("days", days.ToString());
|
||||
|
||||
var sql = $@"
|
||||
WITH ranked_dates AS (SELECT UserCode,
|
||||
date,
|
||||
ROW_NUMBER() OVER (PARTITION BY UserCode ORDER BY date) AS rn
|
||||
FROM WorkGridSchedules where UserCode in ({p})
|
||||
GROUP BY UserCode, date),
|
||||
grouped AS (SELECT UserCode,
|
||||
date,
|
||||
DATE_SUB(date, INTERVAL rn DAY) AS grp
|
||||
FROM ranked_dates),
|
||||
streaks AS (SELECT UserCode,
|
||||
grp,
|
||||
COUNT(*) AS streak_days,
|
||||
MIN(date) AS start_date,
|
||||
MAX(date) AS end_date
|
||||
FROM grouped
|
||||
GROUP BY UserCode, grp
|
||||
HAVING streak_days >= @days)
|
||||
SELECT UserCode, streak_days as Count, start_date as Start, end_date as End
|
||||
FROM streaks where @date>= start_date and @date<= end_date;
|
||||
|
||||
";
|
||||
|
||||
var data = await _dbContext.Client.Ado.SqlQueryAsync<WorkGridScheduleMaximumConsecutiveDto>(sql, values);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using Dlhis.Basic.WorkGrids.Request;
|
||||
using Dlhis.Basic.WorkGrids.Response;
|
||||
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;
|
||||
@@ -18,17 +19,57 @@ public class WorkGridService : IWorkGridService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly IWorkGridScheduleService _workGridScheduleService;
|
||||
private readonly IOperateLog _operateLog;
|
||||
|
||||
public WorkGridService(IDbContext dbContext,
|
||||
ICurrentUser currentUser,
|
||||
IWorkGridScheduleService workGridScheduleService,
|
||||
IOperateLog operateLog)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_currentUser = currentUser;
|
||||
_workGridScheduleService = workGridScheduleService;
|
||||
_operateLog = operateLog;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<Pagination<WorkGridGainfoPageResponse>> GetPageAsync(WorkGridGainfoPageRequest request)
|
||||
{
|
||||
var factory = _currentUser.GetStringTenantId();
|
||||
|
||||
var r = await _dbContext.Queryable<GainfoEntity>()
|
||||
.LeftJoin<DepartmentEntity>((x, dept) => x.DepartmentNo == dept.No)
|
||||
.LeftJoin<WorkGridUserEntity>((x, dept, wgu) => x.Code == wgu.UserCode)
|
||||
.LeftJoin<WorkGridEntity>((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 userCodes = r.Data.Select(x => x.Code).ToList();
|
||||
var maximumConsecutiveUserCodes = await _workGridScheduleService.MaximumConsecutiveUserCodesAsync(userCodes, 1, DateOnly.FromDateTime(request.Date));
|
||||
|
||||
foreach (var item in r.Data)
|
||||
{
|
||||
item.MaximumConsecutiveSchedules = maximumConsecutiveUserCodes.FirstOrDefault(x => x.UserCode == item.Code);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task SaveAsync(List<WorkGridSaveRequest> requests)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user