feat 时段码增删改查
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Basic.Device.Services;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Dlhis.Basic.Device.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// 设备时段码
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class DeviceTimePeriodsController : ControllerBase
|
||||
{
|
||||
private readonly IDeviceTimePeriodService _deviceTimePeriodService;
|
||||
|
||||
public DeviceTimePeriodsController(IDeviceTimePeriodService deviceTimePeriodService)
|
||||
{
|
||||
_deviceTimePeriodService = deviceTimePeriodService;
|
||||
}
|
||||
|
||||
[HttpGet("page")]
|
||||
public async Task<Pagination<DeviceTimePeriodPageResponse>> GetPageAsync([FromQuery] DeviceTimePeriodPageRequest request)
|
||||
{
|
||||
return await _deviceTimePeriodService.GetPageAsync(request);
|
||||
}
|
||||
|
||||
[HttpPost("save")]
|
||||
public async Task SaveAsync(DeviceTimePeriodSaveRequest request)
|
||||
{
|
||||
await _deviceTimePeriodService.SaveAsync(request);
|
||||
}
|
||||
}
|
||||
@@ -76,6 +76,10 @@ public class DeviceSaveRequest : IValidatableObject
|
||||
/// </summary>
|
||||
public bool AsAttendance { get; set; }
|
||||
|
||||
|
||||
public bool EnableTimePeriod { get; set; }
|
||||
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if (Type != DeviceTypeEnumType.Door && AsAttendance)
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
|
||||
namespace Dlhis.Basic.Device.Request;
|
||||
|
||||
public class DeviceTimePeriodPageRequest : PageDto
|
||||
{
|
||||
/// <summary>
|
||||
/// DeviceTimePeriodAssignEnumType
|
||||
/// </summary>
|
||||
[EnumDataType(typeof(DeviceTimePeriodAssignEnumType))]
|
||||
public DeviceTimePeriodAssignEnumType AssignType { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
|
||||
namespace Dlhis.Basic.Device.Request;
|
||||
|
||||
public class DeviceTimePeriodSaveRequest : IValidatableObject
|
||||
{
|
||||
public long? Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 卡类型 timeperiod
|
||||
/// </summary>
|
||||
[Range(2, 3)]
|
||||
public int CardType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 分配类型 DeviceTimePeriodAssignEnumType
|
||||
/// </summary>
|
||||
[EnumDataType(typeof(DeviceTimePeriodAssignEnumType))]
|
||||
public DeviceTimePeriodAssignEnumType AssignType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 分配值
|
||||
/// </summary>
|
||||
[Required]
|
||||
public Guid Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上班开始
|
||||
/// </summary>
|
||||
[Required]
|
||||
public TimeOnly OnStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上班结束
|
||||
/// </summary>
|
||||
[Required]
|
||||
public TimeOnly OnEnd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 下班开始
|
||||
/// </summary>
|
||||
[Required]
|
||||
public TimeOnly OffStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 下班结束
|
||||
/// </summary>
|
||||
[Required]
|
||||
public TimeOnly OffEnd { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if (OnStart >= OnEnd)
|
||||
{
|
||||
yield return new ValidationResult("上班时段范围有误", new[] { nameof(OnStart) });
|
||||
}
|
||||
|
||||
if (OffStart >= OffEnd)
|
||||
{
|
||||
yield return new ValidationResult("下班时段范围有误", new[] { nameof(OffStart) });
|
||||
}
|
||||
|
||||
|
||||
if (OnEnd >= OffStart)
|
||||
{
|
||||
yield return new ValidationResult("上下班时段范围有误", new[] { nameof(OnEnd) });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,6 +97,11 @@ public class DevicePageResponse
|
||||
/// </summary>
|
||||
public bool AsAttendance { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用时段码
|
||||
/// </summary>
|
||||
public bool EnableTimePeriod { get; set; }
|
||||
|
||||
|
||||
//*********************************************************附加信息**************************************************************/
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
|
||||
namespace Dlhis.Basic.Device.Response;
|
||||
|
||||
public class DeviceTimePeriodPageResponse
|
||||
{
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 卡类型
|
||||
/// </summary>
|
||||
public int CardType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 分配类型
|
||||
/// </summary>
|
||||
public DeviceTimePeriodAssignEnumType AssignType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 分配值
|
||||
/// </summary>
|
||||
public Guid Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上班开始
|
||||
/// </summary>
|
||||
public TimeOnly OnStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上班结束
|
||||
/// </summary>
|
||||
public TimeOnly OnEnd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 下班开始
|
||||
/// </summary>
|
||||
public TimeOnly OffStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 下班结束
|
||||
/// </summary>
|
||||
public TimeOnly OffEnd { get; set; }
|
||||
}
|
||||
12
Src/Dlhis.Basic/Device/Services/IDeviceTimePeriodService.cs
Normal file
12
Src/Dlhis.Basic/Device/Services/IDeviceTimePeriodService.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Response;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
|
||||
namespace Dlhis.Basic.Device.Services;
|
||||
|
||||
public interface IDeviceTimePeriodService : IScopeDependency
|
||||
{
|
||||
Task<Pagination<DeviceTimePeriodPageResponse>> GetPageAsync(DeviceTimePeriodPageRequest request);
|
||||
|
||||
Task SaveAsync(DeviceTimePeriodSaveRequest request);
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
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.Device.Services.Implements;
|
||||
|
||||
public class DeviceTimePeriodService : IDeviceTimePeriodService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
|
||||
public DeviceTimePeriodService(IDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<Pagination<DeviceTimePeriodPageResponse>> GetPageAsync(DeviceTimePeriodPageRequest request)
|
||||
{
|
||||
var page = await _dbContext.Queryable<DeviceTimePeriodEntity>()
|
||||
.Where(x => x.AssignType == request.AssignType)
|
||||
.Select<DeviceTimePeriodPageResponse>()
|
||||
.ToPageListAsync(request);
|
||||
|
||||
var values = page.Data.Select(x => x.Value);
|
||||
var data = request.AssignType == DeviceTimePeriodAssignEnumType.Device
|
||||
? await _dbContext.Queryable<DeviceEntity>().Where(x => values.Contains(x.Code)).Select(x => new { x.Code, Name = x.DeployPlace }).ToListAsync()
|
||||
: await _dbContext.Queryable<DeviceTemplateEntity>().Where(x => values.Contains(x.Code)).Select(x => new { x.Code, x.Name }).ToListAsync();
|
||||
|
||||
page.Data.ForEach(item => { item.Name = data.FirstOrDefault(x => x.Code == item.Value)?.Name; });
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task SaveAsync(DeviceTimePeriodSaveRequest request)
|
||||
{
|
||||
(await _dbContext.Queryable<BasicTypeEntity>().Where(x => x.Type == "timeperiod").AnyAsync(x => x.Code == request.CardType.ToString()))
|
||||
.ThrowIfFalse($"卡类型{request.CardType}不支持");
|
||||
|
||||
var existsData = request.AssignType == DeviceTimePeriodAssignEnumType.Device
|
||||
? await _dbContext.Queryable<DeviceEntity>().Where(x => x.Code == request.Value).AnyAsync()
|
||||
: await _dbContext.Queryable<DeviceTemplateEntity>().Where(x => x.Code == request.Value).AnyAsync();
|
||||
existsData.ThrowIfFalse("数据不匹配");
|
||||
|
||||
|
||||
(await _dbContext.Queryable<DeviceTimePeriodEntity>()
|
||||
.Where(x => x.CardType == request.CardType)
|
||||
.Where(x => x.AssignType == request.AssignType)
|
||||
.Where(x => x.Value == request.Value)
|
||||
.AnyAsync()).ThrowIfTrue("请勿重复添加");
|
||||
|
||||
|
||||
if (!request.Id.HasValue)
|
||||
{
|
||||
var entity = request.Adapt<DeviceTimePeriodEntity>();
|
||||
entity.CardType = request.CardType;
|
||||
entity.AssignType = request.AssignType;
|
||||
entity.Value = request.Value;
|
||||
await _dbContext.InsertAsync(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
var entity = await _dbContext.Queryable<DeviceTimePeriodEntity>().Where(x => x.Id == request.Id).SingleAsync();
|
||||
request.Adapt(entity);
|
||||
|
||||
await _dbContext.UpdateAsync(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,6 +95,13 @@ namespace Dlhis.Entity.Basic.Entity
|
||||
[SugarColumn(ColumnDataType = "bit", ColumnDescription = "是否作为考勤设备")]
|
||||
public bool AsAttendance { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用时段码
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDataType = "bit", ColumnDescription = "是否启用时段码", DefaultValue = "0")]
|
||||
public bool EnableTimePeriod { get; set; } = false;
|
||||
|
||||
public string TenantId { get; set; }
|
||||
}
|
||||
}
|
||||
69
Src/Dlhis.Entity/Device/Entities/DeviceTimePeriodEntity.cs
Normal file
69
Src/Dlhis.Entity/Device/Entities/DeviceTimePeriodEntity.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Kurisu.AspNetCore.DataAccess.Entity;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar;
|
||||
using Mapster;
|
||||
using SqlSugar;
|
||||
using SqlSugar.DbConvert;
|
||||
|
||||
namespace Dlhis.Entity.Device.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// 设备时段码
|
||||
/// </summary>
|
||||
[SugarTable(TableName = "DeviceTimePeriod", TableDescription = "设备时段码")]
|
||||
public class DeviceTimePeriodEntity : SugarBaseEntity, ITenantId
|
||||
{
|
||||
/// <summary>
|
||||
/// 卡类型
|
||||
/// </summary>
|
||||
[AdaptIgnore(MemberSide.Destination)]
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "卡类型",
|
||||
UniqueGroupNameList = new[] { "unique_DeviceTimePeriod_cardType_assignType_value" })]
|
||||
public int CardType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 分配类型
|
||||
/// </summary>
|
||||
[AdaptIgnore(MemberSide.Destination)]
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "分配类型",
|
||||
ColumnDataType = "varchar(50)",
|
||||
UniqueGroupNameList = new[] { "unique_DeviceTimePeriod_cardType_assignType_value" },
|
||||
SqlParameterDbType = typeof(EnumToStringConvert))]
|
||||
public DeviceTimePeriodAssignEnumType AssignType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 分配值
|
||||
/// </summary>
|
||||
[AdaptIgnore(MemberSide.Destination)]
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "分配值",
|
||||
UniqueGroupNameList = new[] { "unique_DeviceTimePeriod_cardType_assignType_value" })]
|
||||
public Guid Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上班开始
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "上班开始")]
|
||||
public TimeOnly OnStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上班结束
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "上班结束")]
|
||||
public TimeOnly OnEnd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 下班开始
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "下班开始")]
|
||||
public TimeOnly OffStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 下班结束
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "下班结束")]
|
||||
public TimeOnly OffEnd { get; set; }
|
||||
|
||||
|
||||
[SugarColumn(IsNullable = false, UniqueGroupNameList = new[] { "unique_DeviceTimePeriod_cardType_assignType_value" })]
|
||||
public string TenantId { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Dlhis.Entity.Device.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// 设备时段码分配类型
|
||||
/// </summary>
|
||||
[Description("设备时段码分配类型")]
|
||||
public enum DeviceTimePeriodAssignEnumType
|
||||
{
|
||||
/// <summary>
|
||||
/// 模板
|
||||
/// </summary>
|
||||
[Description("模板")]
|
||||
Template = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 设备
|
||||
/// </summary>
|
||||
[Description("设备")]
|
||||
Device = 2
|
||||
}
|
||||
@@ -111,7 +111,7 @@ public class AssignmentService : IAssignmentService
|
||||
Id = 1,
|
||||
Name = "小白领",
|
||||
Enable = true,
|
||||
Sections = new List<TimePeriodWeekDaySection>()
|
||||
Sections = new List<TimePeriodWeekDaySection>
|
||||
{
|
||||
new()
|
||||
{
|
||||
@@ -121,8 +121,8 @@ public class AssignmentService : IAssignmentService
|
||||
new()
|
||||
{
|
||||
Start = TimeOnly.Parse("08:00:00"),
|
||||
End = TimeOnly.Parse("17:30:00"),
|
||||
},
|
||||
End = TimeOnly.Parse("17:30:00")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user