feat 网格二期补充
This commit is contained in:
@@ -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<Pagination<WorkGridGainfoPageResponse>> GetPageAsync([FromQuery] WorkGridGainfoPageRequest request)
|
||||
{
|
||||
return await _workGridService.GetPageAsync(request);
|
||||
return await _workGridService.GetUserSelectionPageAsync(request);
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +56,7 @@ public class WorkGridsController : ControllerBase
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// /网格分页
|
||||
/// 网格分页
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
@@ -174,11 +173,16 @@ public class WorkGridsController : ControllerBase
|
||||
/// <param name="datePeriod"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("user/schedule/summary")]
|
||||
public async Task<IEnumerable<WorkGridScheduleSummaryResponse>> GetListSummaryAsync([FromQuery] Guid workGridCode, [FromQuery] DateTimePeriod datePeriod)
|
||||
public async Task<List<WorkGridScheduleSummaryResponse>> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 人员选择接口
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
Task<Pagination<WorkGridGainfoPageResponse>> GetUserSelectionPageAsync(WorkGridGainfoPageRequest request);
|
||||
|
||||
Task<Pagination<WorkGridPageResponse>> GetPageAsync(WorkGridPageRequest request);
|
||||
}
|
||||
@@ -12,4 +12,17 @@ public interface IWorkGridScheduleRepository : IScopeDependency
|
||||
/// <param name="date">日期</param>
|
||||
/// <returns>最大连续排班信息列表</returns>
|
||||
Task<List<WorkGridScheduleMaximumConsecutiveDto>> MaximumConsecutiveUserCodesAsync(List<string> userCodes, int days, DateOnly date);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定网格和日期范围的排班汇总列表
|
||||
/// </summary>
|
||||
/// <param name="workGridCode">网格编码</param>
|
||||
/// <param name="start">开始日期</param>
|
||||
/// <param name="end">结束日期</param>
|
||||
/// <returns>排班汇总列表</returns>
|
||||
Task<List<WorkGridScheduleSummaryResponse>> GetListSummaryAsync(Guid workGridCode, DateOnly start, DateOnly end);
|
||||
|
||||
|
||||
Task CancelAsync(long id, string reason);
|
||||
}
|
||||
@@ -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<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);
|
||||
|
||||
return pagination;
|
||||
}
|
||||
|
||||
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";
|
||||
|
||||
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
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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<List<WorkGridScheduleMaximumConsecutiveDto>> MaximumConsecutiveUserCodesAsync(List<string> 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<WorkGridScheduleMaximumConsecutiveDto>(sql, parameters);
|
||||
}
|
||||
|
||||
public async Task<List<WorkGridScheduleSummaryResponse>> GetListSummaryAsync(Guid workGridCode, DateOnly start, DateOnly end)
|
||||
{
|
||||
var workGridScheduleList = await _dbContext.Queryable<WorkGridScheduleEntity>()
|
||||
.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<WorkGridScheduleEntity>()
|
||||
.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
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -13,4 +13,9 @@ public class WorkGridPageRequest : PageDto
|
||||
/// 排班日期
|
||||
/// </summary>
|
||||
public DateTime Date { get; set; } = DateTime.Today;
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用显示日期排班详情
|
||||
/// </summary>
|
||||
public bool EnableShowDateScheduleDetails { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Dlhis.Basic.WorkGrids.Request;
|
||||
|
||||
public class WorkGridScheduleCancelRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据id
|
||||
/// </summary>
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 取消原因
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "{0}不能为空")]
|
||||
public string Reason { get; set; }
|
||||
}
|
||||
@@ -39,11 +39,16 @@ public class WorkGridPageResponse
|
||||
/// </summary>
|
||||
public int MaxUserTipCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最大连续排班预警值
|
||||
/// </summary>
|
||||
public int MaxConsecutiveTipCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最大连续排班限制值
|
||||
/// </summary>
|
||||
public int MaxConsecutiveLimitCount { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 别名
|
||||
/// </summary>
|
||||
@@ -53,4 +58,6 @@ public class WorkGridPageResponse
|
||||
/// 编制人数
|
||||
/// </summary>
|
||||
public int Count { get; set; }
|
||||
|
||||
public WorkGridScheduleSummaryResponse DateScheduleSummary { get; set; }
|
||||
}
|
||||
@@ -4,11 +4,28 @@ namespace Dlhis.Basic.WorkGrids.Response;
|
||||
|
||||
public class WorkGridScheduleResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 日期
|
||||
/// </summary>
|
||||
public DateOnly Date { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排版时间段
|
||||
/// </summary>
|
||||
public WorkGridTimePeriodEnumType PeriodType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 工号
|
||||
/// </summary>
|
||||
public string UserCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 姓名
|
||||
/// </summary>
|
||||
public string UserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否取消
|
||||
/// </summary>
|
||||
public bool IsCancel { get; set; }
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace Dlhis.Basic.WorkGrids.Response;
|
||||
|
||||
public class WorkGridScheduleSummaryResponse
|
||||
{
|
||||
public Guid WorkGridCode { get; set; }
|
||||
public DateOnly Date { get; set; }
|
||||
public IEnumerable<WorkGridScheduleSummaryDetailResponse> Details { get; set; }
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
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 workGridCodes = pagination.Data.Select(wg => wg.Code).ToList();
|
||||
if (workGridCodes.Any())
|
||||
{
|
||||
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();
|
||||
|
||||
@@ -38,21 +38,21 @@ public class WorkGridEntity : SugarBaseEntity, ISoftDeleted, ITenantId
|
||||
public string Remark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最大排班用户数提醒
|
||||
/// 排班用户数提醒
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "最大排班用户数提醒")]
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "排班用户数提醒")]
|
||||
public int MaxUserTipCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最大排班连续天数提醒
|
||||
/// 排班连续天数提醒天数
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "最大排班连续天数提醒")]
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "排班连续天数提醒天数")]
|
||||
public int MaxConsecutiveTipCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 请设置连续排班限制
|
||||
/// 连续排班限制人数
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "请设置连续排班限制")]
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "连续排班限制人数")]
|
||||
public int MaxConsecutiveLimitCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -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; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string TenantId { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.Entity.Basic.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// 网格排班取消记录
|
||||
/// </summary>
|
||||
[SugarTable(TableName = "WorkGridScheduleCancelRecord", TableDescription = "工作网格排班取消记录")]
|
||||
public class WorkGridScheduleCancelRecordEntity : SugarBaseEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// 原始记录id
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "原始记录id", UniqueGroupNameList = new[] { "Unique_WorkGridScheduleCancel_WorkGridScheduleId" })]
|
||||
public long WorkGridScheduleId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 取消原因
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "取消原因")]
|
||||
public string Reason { get; set; }
|
||||
}
|
||||
@@ -36,6 +36,11 @@ public class WorkGridScheduleEntity : SugarBaseEntity , ISoftDeleted
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "工号", IndexGroupNameList = new[] { "idx_WorkGridSchedules_userCode" })]
|
||||
public string UserCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否取消
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "是否取消", ColumnDataType = "bit")]
|
||||
public bool IsCancel { get; set; }
|
||||
|
||||
public bool IsDeleted { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user