diff --git a/Src/Dlhis.Basic/Common/Holiday/Controller/HolidaysController.cs b/Src/Dlhis.Basic/Common/Holiday/Controller/HolidaysController.cs new file mode 100644 index 00000000..f6530beb --- /dev/null +++ b/Src/Dlhis.Basic/Common/Holiday/Controller/HolidaysController.cs @@ -0,0 +1,50 @@ +using Dlhis.Basic.Common.Holiday.Requests; +using Dlhis.Basic.Common.Holiday.Responses; +using Dlhis.Basic.Common.Holiday.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace Dlhis.Basic.Common.Holiday.Controller; + +[Authorize(Roles = "admin")] +[ApiController] +[Route("api/[controller]")] +public class HolidaysController : ControllerBase +{ + private readonly IHolidayService _holidayService; + + public HolidaysController(IHolidayService holidayService) + { + _holidayService = holidayService; + } + + /// + /// 保存节假日信息。 + /// + /// 节假日请求参数。 + [HttpPost("save")] + public async Task SaveAsync(HolidayRequest req) + { + await _holidayService.SaveAsync(req); + } + + /// + /// 获取所有节假日信息。 + /// + /// 节假日响应列表。 + [HttpGet("list")] + public async Task> GetAllHolidaysAsync() + { + return await _holidayService.GetAllHolidaysAsync(); + } + + /// + /// 删除指定ID的节假日信息。 + /// + /// 节假日ID。 + [HttpPost("delete/{id}")] + public async Task DeleteAsync(long id) + { + await _holidayService.DeleteAsync(id); + } +} \ No newline at end of file diff --git a/Src/Dlhis.Basic/Common/Holiday/Requests/HolidayRequest.cs b/Src/Dlhis.Basic/Common/Holiday/Requests/HolidayRequest.cs new file mode 100644 index 00000000..b6b872a0 --- /dev/null +++ b/Src/Dlhis.Basic/Common/Holiday/Requests/HolidayRequest.cs @@ -0,0 +1,35 @@ +using System.ComponentModel.DataAnnotations; +using Dlhis.Entity.Basic.Enums; + +namespace Dlhis.Basic.Common.Holiday.Requests; + +public class HolidayRequest +{ + public long? Id { get; set; } + + /// + /// 年份 + /// + public int Year { get; set; } + + /// + /// 名称 + /// + public string Name { get; set; } + + /// + /// 开始日期 + /// + public DateOnly Start { get; set; } + + /// + /// 结束日期 + /// + public DateOnly End { get; set; } + + /// + /// 节假日类型 HolidayEnumType + /// + [EnumDataType(typeof(HolidayEnumType))] + public HolidayEnumType Type { get; set; } +} \ No newline at end of file diff --git a/Src/Dlhis.Basic/Common/Holiday/Responses/HolidayResponse.cs b/Src/Dlhis.Basic/Common/Holiday/Responses/HolidayResponse.cs new file mode 100644 index 00000000..e89a1e21 --- /dev/null +++ b/Src/Dlhis.Basic/Common/Holiday/Responses/HolidayResponse.cs @@ -0,0 +1,39 @@ +using Dlhis.Entity.Basic.Enums; +using Kurisu.AspNetCore.Utils.Extensions; + +namespace Dlhis.Basic.Common.Holiday.Responses; + +public class HolidayResponse +{ + public long Id { get; set; } + + /// + /// 假日类型 + /// + public HolidayEnumType Type { get; set; } + + /// + /// 假日类型描述 + /// + public string TypeDesc => Type.GetDescription(); + + /// + /// 年份 + /// + public int Year { get; set; } + + /// + /// 名称 + /// + public string Name { get; set; } + + /// + /// 开始日期 + /// + public DateOnly Start { get; set; } + + /// + /// 结束日期 + /// + public DateOnly End { get; set; } +} \ No newline at end of file diff --git a/Src/Dlhis.Basic/Common/Holiday/Services/IHolidayService.cs b/Src/Dlhis.Basic/Common/Holiday/Services/IHolidayService.cs new file mode 100644 index 00000000..7f8a0312 --- /dev/null +++ b/Src/Dlhis.Basic/Common/Holiday/Services/IHolidayService.cs @@ -0,0 +1,28 @@ +using Dlhis.Basic.Common.Holiday.Requests; +using Dlhis.Basic.Common.Holiday.Responses; + +namespace Dlhis.Basic.Common.Holiday.Services; + +/// +/// 节假日服务接口,定义节假日相关的操作。 +/// +public interface IHolidayService : IScopeDependency +{ + /// + /// 异步获取所有节假日信息。 + /// + /// 节假日响应列表。 + Task> GetAllHolidaysAsync(); + + /// + /// 异步保存节假日信息。 + /// + /// 节假日请求参数。 + Task SaveAsync(HolidayRequest req); + + /// + /// 异步删除指定ID的节假日信息。 + /// + /// 节假日ID。 + Task DeleteAsync(long id); +} \ No newline at end of file diff --git a/Src/Dlhis.Basic/Common/Holiday/Services/Implements/HolidayService.cs b/Src/Dlhis.Basic/Common/Holiday/Services/Implements/HolidayService.cs new file mode 100644 index 00000000..7c3aa067 --- /dev/null +++ b/Src/Dlhis.Basic/Common/Holiday/Services/Implements/HolidayService.cs @@ -0,0 +1,55 @@ +using Dlhis.Basic.Common.Holiday.Requests; +using Dlhis.Basic.Common.Holiday.Responses; +using Dlhis.Entity.Basic.Entity; +using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; +using Kurisu.AspNetCore.Utils.Extensions; +using Mapster; + +namespace Dlhis.Basic.Common.Holiday.Services.Implements; + +public class HolidayService : IHolidayService +{ + private readonly IDbContext _dbContext; + + public HolidayService(IDbContext dbContext) + { + _dbContext = dbContext; + } + + public async Task> GetAllHolidaysAsync() + { + return await _dbContext.Queryable() + .Select() + .ToListAsync(); + } + + public async Task SaveAsync(HolidayRequest req) + { + var exists = await _dbContext.Queryable() + .WhereIF(req.Id.HasValue, x => x.Id != req.Id) + .Where(x => x.Year == req.Year) + .Where(x => x.Start < req.End && req.Start < x.End) + .Where(x => x.Type != req.Type) + .AnyAsync(); + + exists.ThrowIfTrue("节假日时间冲突,请检查开始和结束时间,或节假日类型是否正确"); + + if (!req.Id.HasValue) + { + await _dbContext.InsertAsync(req.Adapt()); + } + else + { + var entity = await _dbContext.Queryable().SingleAsync(x => x.Id == req.Id); + entity.ThrowIfNull("节假日数据不存在"); + + req.Adapt(entity); + await _dbContext.UpdateAsync(entity); + } + } + + public async Task DeleteAsync(long id) + { + await _dbContext.Deleteable().Where(x => x.Id == id).ExecuteCommandAsync(); + } +} \ No newline at end of file diff --git a/Src/Dlhis.Entity/Basic/Entity/HolidayEntity.cs b/Src/Dlhis.Entity/Basic/Entity/HolidayEntity.cs new file mode 100644 index 00000000..bf0d1c34 --- /dev/null +++ b/Src/Dlhis.Entity/Basic/Entity/HolidayEntity.cs @@ -0,0 +1,43 @@ +using Dlhis.Entity.Basic.Enums; +using Kurisu.AspNetCore.DataAccess.SqlSugar; +using SqlSugar; +using SqlSugar.DbConvert; + +namespace Dlhis.Entity.Basic.Entity; + +/// +/// 节假日 +/// +[SugarTable(TableName = "Holidays")] +public class HolidayEntity : SugarBaseEntity +{ + /// + /// 年份 + /// + [SugarColumn(IsNullable = false, ColumnDescription = "年份")] + public int Year { get; set; } + + /// + /// 节假日类型 + /// + [SugarColumn(IsNullable = false, ColumnDescription = "节假日类型", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))] + public HolidayEnumType Type { get; set; } + + /// + /// 名称 + /// + [SugarColumn(IsNullable = false, ColumnDescription = "名称")] + public string Name { get; set; } + + /// + /// 开始日期 + /// + [SugarColumn(IsNullable = false, ColumnDescription = "开始日期")] + public DateOnly Start { get; set; } + + /// + /// 结束日期 + /// + [SugarColumn(IsNullable = false, ColumnDescription = "结束日期")] + public DateOnly End { get; set; } +} \ No newline at end of file diff --git a/Src/Dlhis.Entity/Basic/Entity/UserAttendanceDataAnalysisEntity.cs b/Src/Dlhis.Entity/Basic/Entity/UserAttendanceDataAnalysisEntity.cs new file mode 100644 index 00000000..0145c280 --- /dev/null +++ b/Src/Dlhis.Entity/Basic/Entity/UserAttendanceDataAnalysisEntity.cs @@ -0,0 +1,17 @@ +using Kurisu.AspNetCore.DataAccess.SqlSugar; +using SqlSugar; + +namespace Dlhis.Entity.Basic.Entity; + +/// +/// 人员考勤数据分析 +/// +[SugarTable(TableName = "UserAttendanceDataAnalysis")] +public class UserAttendanceDataAnalysisEntity : SugarBaseEntity +{ + /// + /// 工号 + /// + [SugarColumn(IsNullable = false, ColumnDescription = "工号")] + public string UserCode { get; set; } +} \ No newline at end of file