feat 网格二期补充
This commit is contained in:
@@ -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
|
||||
/// 获取指定网格和日期范围的排班汇总列表
|
||||
/// </summary>
|
||||
/// <param name="workGridCode">网格编码</param>
|
||||
/// <param name="start">开始日期</param>
|
||||
/// <param name="end">结束日期</param>
|
||||
/// <param name="dateTimePeriod"></param>
|
||||
/// <returns>排班汇总列表</returns>
|
||||
Task<IEnumerable<WorkGridScheduleSummaryResponse>> GetListSummaryAsync(Guid workGridCode, DateOnly start, DateOnly end);
|
||||
Task<List<WorkGridScheduleSummaryResponse>> GetListSummaryAsync(Guid workGridCode, DateTimePeriod dateTimePeriod);
|
||||
|
||||
/// <summary>
|
||||
/// 获取排班考勤分页数据
|
||||
@@ -60,6 +60,15 @@ public interface IWorkGridScheduleService : IScopeDependency
|
||||
/// <param name="logIds">考勤日志ID列表</param>
|
||||
Task ManuallyUploadAsync(List<long> logIds);
|
||||
|
||||
/// <summary>
|
||||
/// 手动取消排班
|
||||
/// </summary>
|
||||
/// <remarks>只能操作历史数据</remarks>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="reason"></param>
|
||||
/// <returns></returns>
|
||||
Task ManuallyCancelAsync(long id, string reason);
|
||||
|
||||
/// <summary>
|
||||
/// 测试接口
|
||||
/// </summary>
|
||||
|
||||
@@ -14,7 +14,7 @@ public interface IWorkGridService : IScopeDependency
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
Task<Pagination<WorkGridGainfoPageResponse>> GetPageAsync(WorkGridGainfoPageRequest request);
|
||||
Task<Pagination<WorkGridGainfoPageResponse>> GetUserSelectionPageAsync(WorkGridGainfoPageRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// 保存
|
||||
|
||||
@@ -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<WorkGridScheduleEntity>()
|
||||
.Where(x => x.Date < currentDate)
|
||||
.SingleAsync(x => x.Id == id);
|
||||
workGridSchedule.ThrowIfNull("排班信息不存在或不可操作");
|
||||
workGridSchedule.IsCancel.ThrowIfTrue("排班信息已被取消,请勿重复操作");
|
||||
|
||||
await _workGridScheduleRepository.CancelAsync(id, reason);
|
||||
}
|
||||
|
||||
public async Task<object> TestAsync(WorkGridScheduleSaveRequest request)
|
||||
{
|
||||
request.UserCodes = request.UserCodes.Distinct().ToList();
|
||||
@@ -241,7 +254,6 @@ public class WorkGridScheduleService : IWorkGridScheduleService
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<WorkGridScheduleResponse>> GetListAsync(Guid workGridCode, DateOnly date, WorkGridTimePeriodEnumType? periodType)
|
||||
{
|
||||
var data = await _dbContext.Queryable<WorkGridScheduleEntity>()
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IEnumerable<WorkGridScheduleSummaryResponse>> GetListSummaryAsync(Guid workGridCode, DateOnly start, DateOnly end)
|
||||
public async Task<List<WorkGridScheduleSummaryResponse>> GetListSummaryAsync(Guid workGridCode, DateTimePeriod dateTimePeriod)
|
||||
{
|
||||
var workGridSchedules = await _dbContext.Queryable<WorkGridScheduleEntity>()
|
||||
.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)
|
||||
);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<Pagination<WorkGridGainfoPageResponse>> GetPageAsync(WorkGridGainfoPageRequest request)
|
||||
public async Task<Pagination<WorkGridGainfoPageResponse>> GetUserSelectionPageAsync(WorkGridGainfoPageRequest request)
|
||||
{
|
||||
var factory = _currentUser.GetStringTenantId();
|
||||
|
||||
var pagination = 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 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<Pagination<WorkGridPageResponse>> 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<WorkGridEntity>()
|
||||
.LeftJoin<GainfoEntity>((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<GainfoEntity>()
|
||||
.Where(p => p.Code == x.LeaderUserCode && p.Factory == factory)
|
||||
.Any()
|
||||
||
|
||||
SqlFunc.Subqueryable<GainfoLeaveEntity>()
|
||||
.Where(p => p.Code == x.LeaderUserCode && p.Factory == factory)
|
||||
.Any()
|
||||
||
|
||||
SqlFunc.Subqueryable<WorkGridUserEntity>()
|
||||
.LeftJoin<GainfoEntity>((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<WorkGridUserEntity>().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(",")}");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task RemoveAsync(WorkGridUserRemoveRequest request)
|
||||
{
|
||||
var role = _currentUser.GetRole();
|
||||
|
||||
Reference in New Issue
Block a user