feat 节假日
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存节假日信息。
|
||||
/// </summary>
|
||||
/// <param name="req">节假日请求参数。</param>
|
||||
[HttpPost("save")]
|
||||
public async Task SaveAsync(HolidayRequest req)
|
||||
{
|
||||
await _holidayService.SaveAsync(req);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有节假日信息。
|
||||
/// </summary>
|
||||
/// <returns>节假日响应列表。</returns>
|
||||
[HttpGet("list")]
|
||||
public async Task<List<HolidayResponse>> GetAllHolidaysAsync()
|
||||
{
|
||||
return await _holidayService.GetAllHolidaysAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除指定ID的节假日信息。
|
||||
/// </summary>
|
||||
/// <param name="id">节假日ID。</param>
|
||||
[HttpPost("delete/{id}")]
|
||||
public async Task DeleteAsync(long id)
|
||||
{
|
||||
await _holidayService.DeleteAsync(id);
|
||||
}
|
||||
}
|
||||
35
Src/Dlhis.Basic/Common/Holiday/Requests/HolidayRequest.cs
Normal file
35
Src/Dlhis.Basic/Common/Holiday/Requests/HolidayRequest.cs
Normal file
@@ -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; }
|
||||
|
||||
/// <summary>
|
||||
/// 年份
|
||||
/// </summary>
|
||||
public int Year { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 开始日期
|
||||
/// </summary>
|
||||
public DateOnly Start { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 结束日期
|
||||
/// </summary>
|
||||
public DateOnly End { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 节假日类型 HolidayEnumType
|
||||
/// </summary>
|
||||
[EnumDataType(typeof(HolidayEnumType))]
|
||||
public HolidayEnumType Type { get; set; }
|
||||
}
|
||||
39
Src/Dlhis.Basic/Common/Holiday/Responses/HolidayResponse.cs
Normal file
39
Src/Dlhis.Basic/Common/Holiday/Responses/HolidayResponse.cs
Normal file
@@ -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; }
|
||||
|
||||
/// <summary>
|
||||
/// 假日类型
|
||||
/// </summary>
|
||||
public HolidayEnumType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 假日类型描述
|
||||
/// </summary>
|
||||
public string TypeDesc => Type.GetDescription();
|
||||
|
||||
/// <summary>
|
||||
/// 年份
|
||||
/// </summary>
|
||||
public int Year { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 开始日期
|
||||
/// </summary>
|
||||
public DateOnly Start { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 结束日期
|
||||
/// </summary>
|
||||
public DateOnly End { get; set; }
|
||||
}
|
||||
28
Src/Dlhis.Basic/Common/Holiday/Services/IHolidayService.cs
Normal file
28
Src/Dlhis.Basic/Common/Holiday/Services/IHolidayService.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Dlhis.Basic.Common.Holiday.Requests;
|
||||
using Dlhis.Basic.Common.Holiday.Responses;
|
||||
|
||||
namespace Dlhis.Basic.Common.Holiday.Services;
|
||||
|
||||
/// <summary>
|
||||
/// 节假日服务接口,定义节假日相关的操作。
|
||||
/// </summary>
|
||||
public interface IHolidayService : IScopeDependency
|
||||
{
|
||||
/// <summary>
|
||||
/// 异步获取所有节假日信息。
|
||||
/// </summary>
|
||||
/// <returns>节假日响应列表。</returns>
|
||||
Task<List<HolidayResponse>> GetAllHolidaysAsync();
|
||||
|
||||
/// <summary>
|
||||
/// 异步保存节假日信息。
|
||||
/// </summary>
|
||||
/// <param name="req">节假日请求参数。</param>
|
||||
Task SaveAsync(HolidayRequest req);
|
||||
|
||||
/// <summary>
|
||||
/// 异步删除指定ID的节假日信息。
|
||||
/// </summary>
|
||||
/// <param name="id">节假日ID。</param>
|
||||
Task DeleteAsync(long id);
|
||||
}
|
||||
@@ -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<List<HolidayResponse>> GetAllHolidaysAsync()
|
||||
{
|
||||
return await _dbContext.Queryable<HolidayEntity>()
|
||||
.Select<HolidayResponse>()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task SaveAsync(HolidayRequest req)
|
||||
{
|
||||
var exists = await _dbContext.Queryable<HolidayEntity>()
|
||||
.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<HolidayEntity>());
|
||||
}
|
||||
else
|
||||
{
|
||||
var entity = await _dbContext.Queryable<HolidayEntity>().SingleAsync(x => x.Id == req.Id);
|
||||
entity.ThrowIfNull("节假日数据不存在");
|
||||
|
||||
req.Adapt(entity);
|
||||
await _dbContext.UpdateAsync(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(long id)
|
||||
{
|
||||
await _dbContext.Deleteable<HolidayEntity>().Where(x => x.Id == id).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
43
Src/Dlhis.Entity/Basic/Entity/HolidayEntity.cs
Normal file
43
Src/Dlhis.Entity/Basic/Entity/HolidayEntity.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar;
|
||||
using SqlSugar;
|
||||
using SqlSugar.DbConvert;
|
||||
|
||||
namespace Dlhis.Entity.Basic.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// 节假日
|
||||
/// </summary>
|
||||
[SugarTable(TableName = "Holidays")]
|
||||
public class HolidayEntity : SugarBaseEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// 年份
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "年份")]
|
||||
public int Year { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 节假日类型
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "节假日类型", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))]
|
||||
public HolidayEnumType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "名称")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 开始日期
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "开始日期")]
|
||||
public DateOnly Start { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 结束日期
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "结束日期")]
|
||||
public DateOnly End { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.Entity.Basic.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// 人员考勤数据分析
|
||||
/// </summary>
|
||||
[SugarTable(TableName = "UserAttendanceDataAnalysis")]
|
||||
public class UserAttendanceDataAnalysisEntity : SugarBaseEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// 工号
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "工号")]
|
||||
public string UserCode { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user