first commit
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
using F9WebAiTest.Application.Common;
|
||||
using F9WebAiTest.Application.Dtos;
|
||||
using F9WebAiTest.Application.Dtos.Attendance;
|
||||
using F9WebAiTest.Application.Services;
|
||||
using F9WebAiTest.Application.Services.Attendance;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace F9WebAiTest.Api.Controllers.Attendance;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/attendance")]
|
||||
[Authorize]
|
||||
public class AttendanceController : ControllerBase
|
||||
{
|
||||
private readonly IAttendanceService _service;
|
||||
|
||||
public AttendanceController(IAttendanceService service)
|
||||
{
|
||||
_service = service;
|
||||
}
|
||||
|
||||
// POST /api/attendance/punch 打卡
|
||||
[HttpPost("punch")]
|
||||
public async Task<IActionResult> Punch()
|
||||
{
|
||||
var result = await _service.PunchAsync(GetUserId());
|
||||
return Ok(ApiResult<PunchResultDto>.Ok(result));
|
||||
}
|
||||
|
||||
// GET /api/attendance/my 我的考勤记录
|
||||
[HttpGet("my")]
|
||||
public async Task<IActionResult> GetMy([FromQuery] int pageIndex = 1, [FromQuery] int pageSize = 10)
|
||||
{
|
||||
var result = await _service.GetMyRecordsAsync(GetUserId(), pageIndex, pageSize);
|
||||
return Ok(ApiResult<PageResult<AttendanceDto>>.Ok(result));
|
||||
}
|
||||
|
||||
// GET /api/attendance/my/summary 我的考勤统计
|
||||
[HttpGet("my/summary")]
|
||||
public async Task<IActionResult> GetMySummary([FromQuery] string month)
|
||||
{
|
||||
var result = await _service.GetMySummaryAsync(GetUserId(), month);
|
||||
return Ok(ApiResult<AttendanceSummaryDto>.Ok(result));
|
||||
}
|
||||
|
||||
// GET /api/attendance 全部考勤(管理员)
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetAll([FromQuery] AttendanceQueryDto query)
|
||||
{
|
||||
var result = await _service.GetAllRecordsAsync(query);
|
||||
return Ok(ApiResult<PageResult<AttendanceDto>>.Ok(result));
|
||||
}
|
||||
|
||||
// POST /api/attendance/leave 申请请假
|
||||
[HttpPost("leave")]
|
||||
public async Task<IActionResult> ApplyLeave([FromBody] CreateLeaveDto dto)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _service.ApplyLeaveAsync(GetUserId(), dto);
|
||||
return Ok(ApiResult<LeaveRequestDto>.Ok(result, "申请已提交"));
|
||||
}
|
||||
catch (ServiceException ex)
|
||||
{
|
||||
return StatusCode(ex.Code, ApiResult<object>.Fail(ex.Message, ex.Code));
|
||||
}
|
||||
}
|
||||
|
||||
// GET /api/attendance/leave/my 我的请假
|
||||
[HttpGet("leave/my")]
|
||||
public async Task<IActionResult> GetMyLeaves()
|
||||
{
|
||||
var result = await _service.GetMyLeavesAsync(GetUserId());
|
||||
return Ok(ApiResult<List<LeaveRequestDto>>.Ok(result));
|
||||
}
|
||||
|
||||
// GET /api/attendance/leave 全部请假(管理员)
|
||||
[HttpGet("leave")]
|
||||
public async Task<IActionResult> GetAllLeaves([FromQuery] string status)
|
||||
{
|
||||
var result = await _service.GetAllLeavesAsync(status);
|
||||
return Ok(ApiResult<List<LeaveRequestDto>>.Ok(result));
|
||||
}
|
||||
|
||||
// PUT /api/attendance/leave/{id}/approve 审批请假
|
||||
[HttpPut("leave/{id}/approve")]
|
||||
public async Task<IActionResult> ApproveLeave(long id, [FromBody] ApproveLeaveDto dto)
|
||||
{
|
||||
try
|
||||
{
|
||||
var approverName = User.FindFirst("realName")?.Value ?? "管理员";
|
||||
var result = await _service.ApproveLeaveAsync(id, GetUserId(), approverName, dto);
|
||||
return Ok(ApiResult<LeaveRequestDto>.Ok(result, "审批完成"));
|
||||
}
|
||||
catch (ServiceException ex)
|
||||
{
|
||||
return StatusCode(ex.Code, ApiResult<object>.Fail(ex.Message, ex.Code));
|
||||
}
|
||||
}
|
||||
|
||||
private long GetUserId() => long.Parse(User.FindFirst("id")!.Value);
|
||||
}
|
||||
Reference in New Issue
Block a user