feat 工作网格
This commit is contained in:
@@ -21,8 +21,6 @@ public class GainfoDto
|
||||
|
||||
public class AnalyzePackDto
|
||||
{
|
||||
|
||||
|
||||
public string UserNo { get; set; }
|
||||
|
||||
public string UserDepartment { get; set; }
|
||||
|
||||
154
Src/Dlhis.Basic/WorkGrids/Controllers/WorkGridsController.cs
Normal file
154
Src/Dlhis.Basic/WorkGrids/Controllers/WorkGridsController.cs
Normal file
@@ -0,0 +1,154 @@
|
||||
using Dlhis.Basic.WorkGrids.Request;
|
||||
using Dlhis.Basic.WorkGrids.Response;
|
||||
using Dlhis.Basic.WorkGrids.Services;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Dlhis.Basic.WorkGrids.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// 工作网格
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class WorkGridsController : ControllerBase
|
||||
{
|
||||
private readonly IWorkGridService _workGridService;
|
||||
private readonly IWorkGridTimePeriodService _workGridTimePeriodService;
|
||||
private readonly IWorkGridScheduleService _workGridScheduleService;
|
||||
|
||||
public WorkGridsController(IWorkGridService workGridService,
|
||||
IWorkGridTimePeriodService workGridTimePeriodService,
|
||||
IWorkGridScheduleService workGridScheduleService)
|
||||
{
|
||||
_workGridService = workGridService;
|
||||
_workGridTimePeriodService = workGridTimePeriodService;
|
||||
_workGridScheduleService = workGridScheduleService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存
|
||||
/// </summary>
|
||||
/// <param name="requests"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("save")]
|
||||
[Transactional]
|
||||
public async Task SaveWorkGridsAsync(List<WorkGridSaveRequest> requests)
|
||||
{
|
||||
await _workGridService.SaveAsync(requests);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// /网格分页
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("page")]
|
||||
public async Task<Pagination<WorkGridPageResponse>> GetWorkGridPageAsync([FromQuery] WorkGridPageRequest request)
|
||||
{
|
||||
return await _workGridService.GetPageAsync(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改网格管理者
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("leader/change")]
|
||||
public async Task ChangeWorkGridLeaderAsync(WorkGridChangeRequest request)
|
||||
{
|
||||
await _workGridService.ChangeAsync(request.From, request.To);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取我的网格信息
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("info")]
|
||||
public async Task<WorkGridUserPageResponse> GetMyWorkGridAsync([FromQuery] WorkGridPageRequest request)
|
||||
{
|
||||
return await _workGridService.GetMyWorkGridAsync(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存网格工作时间
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("timePeriod/save")]
|
||||
public async Task SaveWorkGridTimePeriodAsync(WorkGridTimePeriodSaveRequest request)
|
||||
{
|
||||
await _workGridTimePeriodService.SaveAsync(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// /获取网格工作时间分页
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("timePeriod/page")]
|
||||
public async Task<Pagination<WorkGridTimePeriodPageResponse>> GetWorkGridTimePeriodPageAsync([FromQuery] WorkGridTimePeriodPageRequest request)
|
||||
{
|
||||
return await _workGridTimePeriodService.GetPageAsync(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分配人员到网格中
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("user/assign")]
|
||||
public async Task AssignUsersToWorkGridAsync(WorkGridUserAssignRequest request)
|
||||
{
|
||||
await _workGridService.AssignAsync(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除网格的人员
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("user/remove")]
|
||||
public async Task RemoveUsersFromWorkGridAsync(WorkGridUserRemoveRequest request)
|
||||
{
|
||||
await _workGridService.RemoveAsync(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存网格人员排班
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
[HttpPost("user/schedule/save")]
|
||||
public async Task SaveScheduleAsync(WorkGridScheduleSaveRequest request)
|
||||
{
|
||||
await _workGridScheduleService.SaveAsync(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取人网格员排班列表
|
||||
/// </summary>
|
||||
/// <param name="workGridCode">网格code</param>
|
||||
/// <param name="date"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("user/schedule/list")]
|
||||
public async Task<List<WorkGridScheduleResponse>> GetListAsync(Guid workGridCode, DateOnly date)
|
||||
{
|
||||
return await _workGridScheduleService.GetListAsync(workGridCode, date);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取网格人员排班详情
|
||||
/// </summary>
|
||||
/// <param name="workGridCode">网格</param>
|
||||
/// <param name="start">开始日期</param>
|
||||
/// <param name="end">结束日期</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("user/schedule/summary")]
|
||||
public async Task<IEnumerable<WorkGridScheduleSummaryResponse>> GetListSummaryAsync([FromQuery] Guid workGridCode, [FromQuery] DateOnly start, [FromQuery] DateOnly end)
|
||||
{
|
||||
return await _workGridScheduleService.GetListSummaryAsync(workGridCode, start, end);
|
||||
}
|
||||
}
|
||||
12
Src/Dlhis.Basic/WorkGrids/Request/WorkGridChangeRequest.cs
Normal file
12
Src/Dlhis.Basic/WorkGrids/Request/WorkGridChangeRequest.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Dlhis.Basic.WorkGrids.Request;
|
||||
|
||||
public class WorkGridChangeRequest
|
||||
{
|
||||
[Required]
|
||||
public string From { get; set; }
|
||||
|
||||
[Required]
|
||||
public string To { get; set; }
|
||||
}
|
||||
8
Src/Dlhis.Basic/WorkGrids/Request/WorkGridPageRequest.cs
Normal file
8
Src/Dlhis.Basic/WorkGrids/Request/WorkGridPageRequest.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
|
||||
namespace Dlhis.Basic.WorkGrids.Request;
|
||||
|
||||
public class WorkGridPageRequest : PageDto
|
||||
{
|
||||
|
||||
}
|
||||
22
Src/Dlhis.Basic/WorkGrids/Request/WorkGridSaveRequest.cs
Normal file
22
Src/Dlhis.Basic/WorkGrids/Request/WorkGridSaveRequest.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Dlhis.Basic.WorkGrids.Request;
|
||||
|
||||
public class WorkGridSaveRequest
|
||||
{
|
||||
public long? Id { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "名称不可为空")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 负责人
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "负责人不可为空")]
|
||||
public string LeaderUserCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string Remark { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
|
||||
namespace Dlhis.Basic.WorkGrids.Request;
|
||||
|
||||
public class WorkGridScheduleSaveRequest
|
||||
{
|
||||
public Guid WorkGridCode { get; set; }
|
||||
|
||||
public DateOnly Date { get; set; }
|
||||
|
||||
public WorkGridTimePeriodEnumType PeriodType { get; set; }
|
||||
|
||||
public List<string> UserCodes { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
|
||||
namespace Dlhis.Basic.WorkGrids.Request;
|
||||
|
||||
public class WorkGridTimePeriodPageRequest : PageDto
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
|
||||
namespace Dlhis.Basic.WorkGrids.Request;
|
||||
|
||||
public class WorkGridTimePeriodSaveRequest
|
||||
{
|
||||
public long? Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 班次, eg: 禁止编辑
|
||||
/// </summary>
|
||||
public WorkGridTimePeriodEnumType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 前(min)
|
||||
/// </summary>
|
||||
[Range(1, int.MaxValue)]
|
||||
public int Before { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 后(min)
|
||||
/// </summary>
|
||||
[Range(1, int.MaxValue)]
|
||||
public int After { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 开始时间
|
||||
/// </summary>
|
||||
public TimeOnly Start { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 结束时间
|
||||
/// </summary>
|
||||
public TimeOnly End { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Dlhis.Basic.WorkGrids.Request;
|
||||
|
||||
public class WorkGridUserAssignRequest
|
||||
{
|
||||
public Guid? WorkGridCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 人员
|
||||
/// </summary>
|
||||
[MinLength(1, ErrorMessage = "请选择人员")]
|
||||
public List<string> UserCodes { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Dlhis.Basic.WorkGrids.Request;
|
||||
|
||||
public class WorkGridUserRemoveRequest
|
||||
{
|
||||
public Guid? WorkGridCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 人员
|
||||
/// </summary>
|
||||
[MinLength(1, ErrorMessage = "请选择人员")]
|
||||
public List<string> UserCodes { get; set; }
|
||||
}
|
||||
31
Src/Dlhis.Basic/WorkGrids/Response/WorkGridPageResponse.cs
Normal file
31
Src/Dlhis.Basic/WorkGrids/Response/WorkGridPageResponse.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
namespace Dlhis.Basic.WorkGrids.Response;
|
||||
|
||||
public class WorkGridPageResponse
|
||||
{
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 网格code
|
||||
/// </summary>
|
||||
public Guid Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 网格名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 负责人工号
|
||||
/// </summary>
|
||||
public string LeaderUserCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 负责人姓名
|
||||
/// </summary>
|
||||
public string UserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string Remark { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
|
||||
namespace Dlhis.Basic.WorkGrids.Response;
|
||||
|
||||
public class WorkGridScheduleResponse
|
||||
{
|
||||
public DateOnly Date { get; set; }
|
||||
|
||||
public WorkGridTimePeriodEnumType PeriodType { get; set; }
|
||||
|
||||
public string UserCode { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
|
||||
namespace Dlhis.Basic.WorkGrids.Response;
|
||||
|
||||
public class WorkGridScheduleSummaryResponse
|
||||
{
|
||||
public DateOnly Date { get; set; }
|
||||
public IEnumerable<WorkGridScheduleSummaryDetailResponse> Details { get; set; }
|
||||
}
|
||||
|
||||
public class WorkGridScheduleSummaryDetailResponse
|
||||
{
|
||||
public WorkGridTimePeriodEnumType PeriodType { get; set; }
|
||||
|
||||
public int Count { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
|
||||
namespace Dlhis.Basic.WorkGrids.Response;
|
||||
|
||||
public class WorkGridTimePeriodPageResponse
|
||||
{
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 班次
|
||||
/// </summary>
|
||||
public WorkGridTimePeriodEnumType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 班次描述
|
||||
/// </summary>
|
||||
public string TypeDesc => Type.GetDescription();
|
||||
|
||||
/// <summary>
|
||||
/// 前
|
||||
/// </summary>
|
||||
public int Before { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 后
|
||||
/// </summary>
|
||||
public int After { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 开始时间
|
||||
/// </summary>
|
||||
public TimeOnly Start { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 结束时间
|
||||
/// </summary>
|
||||
public TimeOnly End { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 配置描述
|
||||
/// </summary>
|
||||
public string Description
|
||||
{
|
||||
get { return Type.GetDescription() + "打卡时间从" + Start + "到" + End + "\r\n" + "上班允许提前" + GetTimeDescription(Before) + "\r\n" + "下班允许延迟" + GetTimeDescription(After); }
|
||||
}
|
||||
|
||||
|
||||
private string GetTimeDescription(int minutes)
|
||||
{
|
||||
string d;
|
||||
|
||||
if (minutes >= 60)
|
||||
{
|
||||
var remaining = minutes % 60;
|
||||
|
||||
d = $"{minutes / 60}小时";
|
||||
|
||||
if (remaining > 0)
|
||||
{
|
||||
d += $"{remaining}分钟";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
d = $"{minutes}分钟";
|
||||
}
|
||||
|
||||
|
||||
return d;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
namespace Dlhis.Basic.WorkGrids.Response;
|
||||
|
||||
public class WorkGridUserPageResponse
|
||||
{
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 网格code
|
||||
/// </summary>
|
||||
public Guid Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 网格名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string Remark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 员工明细
|
||||
/// </summary>
|
||||
public List<WorkGridUserPageDetailResponse> UserInfos { get; set; }
|
||||
}
|
||||
|
||||
public class WorkGridUserPageDetailResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 人员工号
|
||||
/// </summary>
|
||||
public string Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 人员姓名
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
// /// <summary>
|
||||
// /// 排班值
|
||||
// /// </summary>
|
||||
// public WorkGridTimePeriodEnumType? ScheduleType { get; set; }
|
||||
//
|
||||
// /// <summary>
|
||||
// /// 排班描述
|
||||
// /// </summary>
|
||||
// public string ScheduleTypeDesc
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return !ScheduleType.HasValue
|
||||
// ? "未排班"
|
||||
// : ScheduleType.Value.GetDescription();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Dlhis.Basic.WorkGrids.Request;
|
||||
using Dlhis.Basic.WorkGrids.Response;
|
||||
|
||||
namespace Dlhis.Basic.WorkGrids.Services;
|
||||
|
||||
/// <summary>
|
||||
/// 网格排班
|
||||
/// </summary>
|
||||
public interface IWorkGridScheduleService : IScopeDependency
|
||||
{
|
||||
Task SaveAsync(WorkGridScheduleSaveRequest request);
|
||||
|
||||
Task<List<WorkGridScheduleResponse>> GetListAsync(Guid workGridCode, DateOnly date);
|
||||
|
||||
Task<IEnumerable<WorkGridScheduleSummaryResponse>> GetListSummaryAsync(Guid workGridCode, DateOnly start, DateOnly end);
|
||||
}
|
||||
52
Src/Dlhis.Basic/WorkGrids/Services/IWorkGridService.cs
Normal file
52
Src/Dlhis.Basic/WorkGrids/Services/IWorkGridService.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using Dlhis.Basic.WorkGrids.Request;
|
||||
using Dlhis.Basic.WorkGrids.Response;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
|
||||
namespace Dlhis.Basic.WorkGrids.Services;
|
||||
|
||||
/// <summary>
|
||||
/// 工作网格
|
||||
/// </summary>
|
||||
public interface IWorkGridService : IScopeDependency
|
||||
{
|
||||
/// <summary>
|
||||
/// 保存
|
||||
/// </summary>
|
||||
/// <param name="requests"></param>
|
||||
/// <returns></returns>
|
||||
Task SaveAsync(List<WorkGridSaveRequest> requests);
|
||||
|
||||
/// <summary>
|
||||
/// /网格分页
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
Task<Pagination<WorkGridPageResponse>> GetPageAsync(WorkGridPageRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// 修改管理者
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task ChangeAsync(string from, string to);
|
||||
|
||||
/// <summary>
|
||||
/// 获取
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
Task<WorkGridUserPageResponse> GetMyWorkGridAsync(WorkGridPageRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// 分配人员
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
Task AssignAsync(WorkGridUserAssignRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// 移除人员
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
Task RemoveAsync(WorkGridUserRemoveRequest request);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using Dlhis.Basic.WorkGrids.Request;
|
||||
using Dlhis.Basic.WorkGrids.Response;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
|
||||
namespace Dlhis.Basic.WorkGrids.Services;
|
||||
|
||||
/// <summary>
|
||||
/// 工作网格班次时段配置
|
||||
/// </summary>
|
||||
public interface IWorkGridTimePeriodService : IScopeDependency
|
||||
{
|
||||
/// <summary>
|
||||
/// 保存
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
Task SaveAsync(WorkGridTimePeriodSaveRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// 获取分页
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
Task<Pagination<WorkGridTimePeriodPageResponse>> GetPageAsync(WorkGridTimePeriodPageRequest request);
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
using Dlhis.Basic.WorkGrids.Request;
|
||||
using Dlhis.Basic.WorkGrids.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
|
||||
namespace Dlhis.Basic.WorkGrids.Services.Implements;
|
||||
|
||||
public class WorkGridScheduleService : IWorkGridScheduleService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
|
||||
public WorkGridScheduleService(IDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task SaveAsync(WorkGridScheduleSaveRequest request)
|
||||
{
|
||||
var exists = await _dbContext.Queryable<WorkGridScheduleEntity>()
|
||||
.Where(x => x.Date == request.Date)
|
||||
.Where(x => x.PeriodType != request.PeriodType)
|
||||
.Where(x => request.UserCodes.Contains(x.UserCode))
|
||||
.AnyAsync();
|
||||
|
||||
exists.ThrowIfTrue($"存在已经分配的人员");
|
||||
|
||||
var data = await _dbContext.Queryable<WorkGridScheduleEntity>()
|
||||
.Where(x => x.WorkGridCode == request.WorkGridCode)
|
||||
.Where(x => x.Date == request.Date)
|
||||
.Where(x => x.PeriodType == request.PeriodType)
|
||||
.ToListAsync();
|
||||
|
||||
await _dbContext.DeleteReallyAsync(data);
|
||||
|
||||
var toInserts = request.UserCodes.Select(x => new WorkGridScheduleEntity
|
||||
{
|
||||
WorkGridCode = request.WorkGridCode,
|
||||
Date = request.Date,
|
||||
PeriodType = request.PeriodType,
|
||||
UserCode = x
|
||||
}).ToList();
|
||||
|
||||
await _dbContext.InsertAsync(toInserts);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<WorkGridScheduleResponse>> GetListAsync(Guid workGridCode, DateOnly date)
|
||||
{
|
||||
return await _dbContext.Queryable<WorkGridScheduleEntity>()
|
||||
.Where(x => x.WorkGridCode == workGridCode && x.Date == date)
|
||||
.Select(x => new WorkGridScheduleResponse
|
||||
{
|
||||
Date = x.Date,
|
||||
PeriodType = x.PeriodType,
|
||||
UserCode = x.UserCode
|
||||
})
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IEnumerable<WorkGridScheduleSummaryResponse>> GetListSummaryAsync(Guid workGridCode, DateOnly start, DateOnly end)
|
||||
{
|
||||
var workGridSchedules = await _dbContext.Queryable<WorkGridScheduleEntity>()
|
||||
.Where(x => x.WorkGridCode == workGridCode && x.Date >= start && x.Date <= end)
|
||||
.ToListAsync();
|
||||
|
||||
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()
|
||||
})
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
154
Src/Dlhis.Basic/WorkGrids/Services/Implements/WorkGridService.cs
Normal file
154
Src/Dlhis.Basic/WorkGrids/Services/Implements/WorkGridService.cs
Normal file
@@ -0,0 +1,154 @@
|
||||
using Dlhis.Basic.WorkGrids.Request;
|
||||
using Dlhis.Basic.WorkGrids.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
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;
|
||||
|
||||
public class WorkGridService : IWorkGridService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
|
||||
public WorkGridService(IDbContext dbContext, ICurrentUser currentUser)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_currentUser = currentUser;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task SaveAsync(List<WorkGridSaveRequest> requests)
|
||||
{
|
||||
foreach (var request in requests)
|
||||
{
|
||||
var exists = await _dbContext.Queryable<WorkGridEntity>()
|
||||
.Where(x => x.LeaderUserCode == request.LeaderUserCode)
|
||||
.WhereIF(request.Id.HasValue, x => x.Id != request.Id)
|
||||
.AnyAsync();
|
||||
|
||||
exists.ThrowIfTrue($"{request.LeaderUserCode}已存在管理的网格");
|
||||
|
||||
if (!request.Id.HasValue)
|
||||
{
|
||||
var entity = request.Adapt<WorkGridEntity>();
|
||||
entity.Code = Guid.NewGuid();
|
||||
|
||||
await _dbContext.InsertAsync(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
var entity = await _dbContext.Queryable<WorkGridEntity>().Where(x => x.Id == request.Id).SingleAsync();
|
||||
request.Adapt(entity);
|
||||
|
||||
await _dbContext.UpdateAsync(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<Pagination<WorkGridPageResponse>> GetPageAsync(WorkGridPageRequest request)
|
||||
{
|
||||
return await _dbContext.Queryable<WorkGridEntity>()
|
||||
.LeftJoin<GainfoEntity>((x, ga) => x.LeaderUserCode == ga.Code)
|
||||
.Select((x, ga) => new WorkGridPageResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
Code = x.Code,
|
||||
Name = x.Name,
|
||||
LeaderUserCode = x.LeaderUserCode,
|
||||
UserName = ga.Name,
|
||||
Remark = x.Remark
|
||||
})
|
||||
.ToPageListAsync(request);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task ChangeAsync(string from, string to)
|
||||
{
|
||||
var workGrid = await _dbContext.Queryable<WorkGridEntity>().Where(x => x.LeaderUserCode == from).SingleAsync();
|
||||
workGrid.ThrowIfNull("网格不存在");
|
||||
|
||||
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == to).SingleAsync();
|
||||
gainfo.ThrowIfNull($"{to}人员不存在");
|
||||
|
||||
workGrid.LeaderUserCode = to;
|
||||
await _dbContext.UpdateAsync(workGrid);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<WorkGridUserPageResponse> GetMyWorkGridAsync(WorkGridPageRequest request)
|
||||
{
|
||||
var currentUserCode = _currentUser.GetUserClaim("jinko-code");
|
||||
var myWorkGrid = await _dbContext.Queryable<WorkGridEntity>()
|
||||
.Where(x => x.LeaderUserCode == currentUserCode)
|
||||
.Select(x => new WorkGridUserPageResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
Code = x.Code,
|
||||
Name = x.Name,
|
||||
Remark = x.Remark,
|
||||
UserInfos = SqlFunc.Subqueryable<WorkGridUserEntity>()
|
||||
.LeftJoin<GainfoEntity>((p, ga) => p.UserCode == ga.Code)
|
||||
.Where((p, ga) => p.WorkGridCode == x.Code)
|
||||
.ToList((p, ga) => new WorkGridUserPageDetailResponse
|
||||
{
|
||||
Code = p.UserCode,
|
||||
Name = ga.Name
|
||||
})
|
||||
})
|
||||
.SingleAsync();
|
||||
|
||||
return myWorkGrid;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task AssignAsync(WorkGridUserAssignRequest request)
|
||||
{
|
||||
var currentFactory = _currentUser.GetStringTenantId();
|
||||
var currentUserCode = _currentUser.GetUserClaim("jinko-code");
|
||||
|
||||
var myWorkGrid = await _dbContext.Queryable<WorkGridEntity>().Where(x => x.LeaderUserCode == currentUserCode).SingleAsync();
|
||||
myWorkGrid.ThrowIfNull("工作网格尚未配置,请联系管理员");
|
||||
|
||||
//检查配置的人员
|
||||
var count = await _dbContext.Queryable<GainfoEntity>()
|
||||
.Where(x => x.Factory == currentFactory)
|
||||
.Where(x => request.UserCodes.Contains(x.Code))
|
||||
.CountAsync();
|
||||
|
||||
(count != request.UserCodes.Count).ThrowIfTrue("存在非当前厂区人员,请检查");
|
||||
|
||||
var existsAssigned = await _dbContext.Queryable<WorkGridUserEntity>().Where(x => x.WorkGridCode == myWorkGrid.Code)
|
||||
.Where(x => request.UserCodes.Contains(x.UserCode))
|
||||
.AnyAsync();
|
||||
existsAssigned.ThrowIfTrue("存在已经分配人员,请勿重复分配");
|
||||
|
||||
var dataToInserts = request.UserCodes.Select(x => new WorkGridUserEntity
|
||||
{
|
||||
WorkGridCode = myWorkGrid.Code,
|
||||
UserCode = x
|
||||
}).ToList();
|
||||
|
||||
await _dbContext.InsertAsync(dataToInserts);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task RemoveAsync(WorkGridUserRemoveRequest request)
|
||||
{
|
||||
var currentUserCode = _currentUser.GetUserClaim("jinko-code");
|
||||
var myWorkGrid = await _dbContext.Queryable<WorkGridEntity>().Where(x => x.LeaderUserCode == currentUserCode).SingleAsync();
|
||||
myWorkGrid.ThrowIfNull("工作网格尚未配置,请联系管理员");
|
||||
|
||||
var workGridUsers = await _dbContext.Queryable<WorkGridUserEntity>().Where(x => x.WorkGridCode == myWorkGrid.Code)
|
||||
.Where(x => request.UserCodes.Contains(x.UserCode))
|
||||
.ToListAsync();
|
||||
|
||||
await _dbContext.DeleteReallyAsync(workGridUsers);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
using Dlhis.Basic.WorkGrids.Request;
|
||||
using Dlhis.Basic.WorkGrids.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
using Kurisu.AspNetCore.CustomClass;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Mapster;
|
||||
|
||||
namespace Dlhis.Basic.WorkGrids.Services.Implements;
|
||||
|
||||
public class WorkGridTimePeriodService : IWorkGridTimePeriodService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
|
||||
public WorkGridTimePeriodService(IDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task SaveAsync(WorkGridTimePeriodSaveRequest request)
|
||||
{
|
||||
//await CheckDuplicateTimePeriodAsync(request);
|
||||
|
||||
if (!request.Id.HasValue)
|
||||
{
|
||||
//判断重复配置
|
||||
var existsSameType = await _dbContext.Queryable<WorkGridTimePeriodEntity>()
|
||||
.Where(x => x.Type == request.Type)
|
||||
.AnyAsync();
|
||||
|
||||
existsSameType.ThrowIfTrue($"已存在{request.Type}配置");
|
||||
|
||||
var data = request.Adapt<WorkGridTimePeriodEntity>();
|
||||
data.Type = request.Type;
|
||||
await _dbContext.InsertAsync(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
var entity = await _dbContext.Queryable<WorkGridTimePeriodEntity>().Where(x => x.Id == request.Id).SingleAsync();
|
||||
request.Adapt(entity);
|
||||
|
||||
await _dbContext.UpdateAsync(entity);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<Pagination<WorkGridTimePeriodPageResponse>> GetPageAsync(WorkGridTimePeriodPageRequest request)
|
||||
{
|
||||
return await _dbContext.Queryable<WorkGridTimePeriodEntity>()
|
||||
.Select<WorkGridTimePeriodPageResponse>()
|
||||
.ToPageListAsync(request);
|
||||
}
|
||||
|
||||
//*************************************************************************************************************************************************
|
||||
|
||||
/// <summary>
|
||||
/// 根据类型获取配置
|
||||
/// </summary>
|
||||
/// <param name="timePeriodType"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<WorkGridTimePeriodEntity> GetSettingAsync(WorkGridTimePeriodEnumType timePeriodType)
|
||||
{
|
||||
return await _dbContext.Queryable<WorkGridTimePeriodEntity>()
|
||||
.Where(x => x.Type == timePeriodType)
|
||||
.SingleAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查时间段重合检查
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
private async Task CheckDuplicateTimePeriodAsync(WorkGridTimePeriodSaveRequest request)
|
||||
{
|
||||
var periods = await _dbContext.Queryable<WorkGridTimePeriodEntity>()
|
||||
.Where(x => x.Type != request.Type)
|
||||
.Select(x => new TimePeriod
|
||||
{
|
||||
Start = x.Start,
|
||||
End = x.End
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var period in periods)
|
||||
{
|
||||
period.IsDuplicate(request.Adapt<TimePeriod>()).ThrowIfTrue($"存在时间段重合[{period.Start}-{period.End}]");
|
||||
}
|
||||
}
|
||||
}
|
||||
37
Src/Dlhis.Entity/Basic/Entity/WorkGridEntity.cs
Normal file
37
Src/Dlhis.Entity/Basic/Entity/WorkGridEntity.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar;
|
||||
using Mapster;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.Entity.Basic.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// 工作网格
|
||||
/// </summary>
|
||||
[SugarTable(TableName = "WorkGrid")]
|
||||
public class WorkGridEntity : SugarBaseEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// 网格code
|
||||
/// </summary>
|
||||
[AdaptIgnore(MemberSide.Destination)]
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "网格code")]
|
||||
public Guid Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 网格名称
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "网格名称")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 负责人工号
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "负责人工号", UniqueGroupNameList = new[] { "idx_WorkGrid_LeaderUserCode" })]
|
||||
public string LeaderUserCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true, ColumnDescription = "备注")]
|
||||
public string Remark { get; set; }
|
||||
}
|
||||
42
Src/Dlhis.Entity/Basic/Entity/WorkGridScheduleEntity.cs
Normal file
42
Src/Dlhis.Entity/Basic/Entity/WorkGridScheduleEntity.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
using Kurisu.AspNetCore.DataAccess.Entity;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar;
|
||||
using SqlSugar;
|
||||
using SqlSugar.DbConvert;
|
||||
|
||||
namespace Dlhis.Entity.Basic.Entity;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarTable(TableName = "WorkGridSchedule")]
|
||||
public class WorkGridScheduleEntity : SugarBaseEntity, ITenantId
|
||||
{
|
||||
/// <summary>
|
||||
/// 网格code
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "网格code")]
|
||||
public Guid WorkGridCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排班日期
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "排班日期")]
|
||||
public DateOnly Date { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排班类型
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "排班类型", SqlParameterDbType = typeof(EnumToStringConvert))]
|
||||
public WorkGridTimePeriodEnumType PeriodType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 工号
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "工号")]
|
||||
public string UserCode { get; set; }
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public string TenantId { get; set; }
|
||||
}
|
||||
44
Src/Dlhis.Entity/Basic/Entity/WorkGridTimePeriodEntity.cs
Normal file
44
Src/Dlhis.Entity/Basic/Entity/WorkGridTimePeriodEntity.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
using Kurisu.AspNetCore.DataAccess.Entity;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar;
|
||||
using Mapster;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.Entity.Basic.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// 工作网格
|
||||
/// </summary>
|
||||
[SugarTable(TableName = "WorkGridTimePeriod")]
|
||||
public class WorkGridTimePeriodEntity : SugarBaseEntity, ITenantId
|
||||
{
|
||||
/// <summary>
|
||||
/// 班次
|
||||
/// </summary>
|
||||
[AdaptIgnore(MemberSide.Destination)]
|
||||
public WorkGridTimePeriodEnumType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 前
|
||||
/// </summary>
|
||||
public int Before { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 后
|
||||
/// </summary>
|
||||
public int After { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 开始时间
|
||||
/// </summary>
|
||||
public TimeOnly Start { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 结束时间
|
||||
/// </summary>
|
||||
public TimeOnly End { get; set; }
|
||||
|
||||
|
||||
[SugarColumn(UniqueGroupNameList = new[] { "idx_workGridTimePeriod_type_tenantId" })]
|
||||
public string TenantId { get; set; }
|
||||
}
|
||||
35
Src/Dlhis.Entity/Basic/Entity/WorkGridUserEntity.cs
Normal file
35
Src/Dlhis.Entity/Basic/Entity/WorkGridUserEntity.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
using Kurisu.AspNetCore.DataAccess.Entity;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar;
|
||||
using SqlSugar;
|
||||
using SqlSugar.DbConvert;
|
||||
|
||||
namespace Dlhis.Entity.Basic.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// 网格人员
|
||||
/// </summary>
|
||||
[SugarTable(TableName = "WorkGridUsers")]
|
||||
public class WorkGridUserEntity : SugarBaseEntity, ITenantId
|
||||
{
|
||||
/// <summary>
|
||||
/// 网格code
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "网格code")]
|
||||
public Guid WorkGridCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 网格人员
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "网格人员")]
|
||||
public string UserCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排班类型
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true, ColumnDescription = "排班类型", SqlParameterDbType = typeof(EnumToStringConvert))]
|
||||
public WorkGridTimePeriodEnumType? ScheduleType { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string TenantId { get; set; }
|
||||
}
|
||||
22
Src/Dlhis.Entity/Basic/Enums/WorkGridTimePeriodEnumType.cs
Normal file
22
Src/Dlhis.Entity/Basic/Enums/WorkGridTimePeriodEnumType.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Dlhis.Entity.Basic.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// 网格班次
|
||||
/// </summary>
|
||||
[Description("网格班次")]
|
||||
public enum WorkGridTimePeriodEnumType
|
||||
{
|
||||
/// <summary>
|
||||
/// 白班
|
||||
/// </summary>
|
||||
[Description("白班")]
|
||||
Day = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 晚班
|
||||
/// </summary>
|
||||
[Description("晚班")]
|
||||
Night = 2,
|
||||
}
|
||||
Reference in New Issue
Block a user