feat: 门店员工与排班管理上线

This commit is contained in:
2025-12-04 09:32:03 +08:00
parent 1a5209a8b1
commit 19422df0f1
31 changed files with 1265 additions and 7 deletions

View File

@@ -0,0 +1,99 @@
using System.Collections.Generic;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using TakeoutSaaS.Application.App.Stores.Commands;
using TakeoutSaaS.Application.App.Stores.Dto;
using TakeoutSaaS.Application.App.Stores.Queries;
using TakeoutSaaS.Module.Authorization.Attributes;
using TakeoutSaaS.Shared.Abstractions.Constants;
using TakeoutSaaS.Shared.Abstractions.Results;
using TakeoutSaaS.Shared.Web.Api;
namespace TakeoutSaaS.AdminApi.Controllers;
/// <summary>
/// 门店排班管理。
/// </summary>
[ApiVersion("1.0")]
[Authorize]
[Route("api/admin/v{version:apiVersion}/stores/{storeId:long}/shifts")]
public sealed class StoreShiftsController(IMediator mediator) : BaseApiController
{
/// <summary>
/// 查询排班(默认未来 7 天)。
/// </summary>
[HttpGet]
[PermissionAuthorize("store-shift:read")]
[ProducesResponseType(typeof(ApiResponse<IReadOnlyList<StoreEmployeeShiftDto>>), StatusCodes.Status200OK)]
public async Task<ApiResponse<IReadOnlyList<StoreEmployeeShiftDto>>> List(
long storeId,
[FromQuery] DateTime? from,
[FromQuery] DateTime? to,
[FromQuery] long? staffId,
CancellationToken cancellationToken)
{
var result = await mediator.Send(new ListStoreEmployeeShiftsQuery
{
StoreId = storeId,
From = from,
To = to,
StaffId = staffId
}, cancellationToken);
return ApiResponse<IReadOnlyList<StoreEmployeeShiftDto>>.Ok(result);
}
/// <summary>
/// 创建排班。
/// </summary>
[HttpPost]
[PermissionAuthorize("store-shift:create")]
[ProducesResponseType(typeof(ApiResponse<StoreEmployeeShiftDto>), StatusCodes.Status200OK)]
public async Task<ApiResponse<StoreEmployeeShiftDto>> Create(long storeId, [FromBody] CreateStoreEmployeeShiftCommand command, CancellationToken cancellationToken)
{
if (command.StoreId == 0)
{
command = command with { StoreId = storeId };
}
var result = await mediator.Send(command, cancellationToken);
return ApiResponse<StoreEmployeeShiftDto>.Ok(result);
}
/// <summary>
/// 更新排班。
/// </summary>
[HttpPut("{shiftId:long}")]
[PermissionAuthorize("store-shift:update")]
[ProducesResponseType(typeof(ApiResponse<StoreEmployeeShiftDto>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
public async Task<ApiResponse<StoreEmployeeShiftDto>> Update(long storeId, long shiftId, [FromBody] UpdateStoreEmployeeShiftCommand command, CancellationToken cancellationToken)
{
if (command.StoreId == 0 || command.ShiftId == 0)
{
command = command with { StoreId = storeId, ShiftId = shiftId };
}
var result = await mediator.Send(command, cancellationToken);
return result == null
? ApiResponse<StoreEmployeeShiftDto>.Error(ErrorCodes.NotFound, "排班不存在")
: ApiResponse<StoreEmployeeShiftDto>.Ok(result);
}
/// <summary>
/// 删除排班。
/// </summary>
[HttpDelete("{shiftId:long}")]
[PermissionAuthorize("store-shift:delete")]
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
public async Task<ApiResponse<object>> Delete(long storeId, long shiftId, CancellationToken cancellationToken)
{
var success = await mediator.Send(new DeleteStoreEmployeeShiftCommand { StoreId = storeId, ShiftId = shiftId }, cancellationToken);
return success
? ApiResponse<object>.Ok(null)
: ApiResponse<object>.Error(ErrorCodes.NotFound, "排班不存在");
}
}

View File

@@ -0,0 +1,98 @@
using System.Collections.Generic;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using TakeoutSaaS.Application.App.Stores.Commands;
using TakeoutSaaS.Application.App.Stores.Dto;
using TakeoutSaaS.Application.App.Stores.Queries;
using TakeoutSaaS.Domain.Merchants.Enums;
using TakeoutSaaS.Module.Authorization.Attributes;
using TakeoutSaaS.Shared.Abstractions.Constants;
using TakeoutSaaS.Shared.Abstractions.Results;
using TakeoutSaaS.Shared.Web.Api;
namespace TakeoutSaaS.AdminApi.Controllers;
/// <summary>
/// 门店员工管理。
/// </summary>
[ApiVersion("1.0")]
[Authorize]
[Route("api/admin/v{version:apiVersion}/stores/{storeId:long}/staffs")]
public sealed class StoreStaffsController(IMediator mediator) : BaseApiController
{
/// <summary>
/// 查询门店员工列表。
/// </summary>
[HttpGet]
[PermissionAuthorize("store-staff:read")]
[ProducesResponseType(typeof(ApiResponse<IReadOnlyList<StoreStaffDto>>), StatusCodes.Status200OK)]
public async Task<ApiResponse<IReadOnlyList<StoreStaffDto>>> List(
long storeId,
[FromQuery] StaffRoleType? role,
[FromQuery] StaffStatus? status,
CancellationToken cancellationToken)
{
var result = await mediator.Send(new ListStoreStaffQuery
{
StoreId = storeId,
RoleType = role,
Status = status
}, cancellationToken);
return ApiResponse<IReadOnlyList<StoreStaffDto>>.Ok(result);
}
/// <summary>
/// 创建门店员工。
/// </summary>
[HttpPost]
[PermissionAuthorize("store-staff:create")]
[ProducesResponseType(typeof(ApiResponse<StoreStaffDto>), StatusCodes.Status200OK)]
public async Task<ApiResponse<StoreStaffDto>> Create(long storeId, [FromBody] CreateStoreStaffCommand command, CancellationToken cancellationToken)
{
if (command.StoreId == 0)
{
command = command with { StoreId = storeId };
}
var result = await mediator.Send(command, cancellationToken);
return ApiResponse<StoreStaffDto>.Ok(result);
}
/// <summary>
/// 更新门店员工。
/// </summary>
[HttpPut("{staffId:long}")]
[PermissionAuthorize("store-staff:update")]
[ProducesResponseType(typeof(ApiResponse<StoreStaffDto>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
public async Task<ApiResponse<StoreStaffDto>> Update(long storeId, long staffId, [FromBody] UpdateStoreStaffCommand command, CancellationToken cancellationToken)
{
if (command.StoreId == 0 || command.StaffId == 0)
{
command = command with { StoreId = storeId, StaffId = staffId };
}
var result = await mediator.Send(command, cancellationToken);
return result == null
? ApiResponse<StoreStaffDto>.Error(ErrorCodes.NotFound, "员工不存在")
: ApiResponse<StoreStaffDto>.Ok(result);
}
/// <summary>
/// 删除门店员工。
/// </summary>
[HttpDelete("{staffId:long}")]
[PermissionAuthorize("store-staff:delete")]
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
public async Task<ApiResponse<object>> Delete(long storeId, long staffId, CancellationToken cancellationToken)
{
var success = await mediator.Send(new DeleteStoreStaffCommand { StoreId = storeId, StaffId = staffId }, cancellationToken);
return success
? ApiResponse<object>.Ok(null)
: ApiResponse<object>.Error(ErrorCodes.NotFound, "员工不存在");
}
}

View File

@@ -100,6 +100,14 @@
"store-table:update",
"store-table:delete",
"store-table:export",
"store-staff:read",
"store-staff:create",
"store-staff:update",
"store-staff:delete",
"store-shift:read",
"store-shift:create",
"store-shift:update",
"store-shift:delete",
"product:create",
"product:read",
"product:update",
@@ -176,6 +184,14 @@
"store-table:update",
"store-table:delete",
"store-table:export",
"store-staff:read",
"store-staff:create",
"store-staff:update",
"store-staff:delete",
"store-shift:read",
"store-shift:create",
"store-shift:update",
"store-shift:delete",
"product:create",
"product:read",
"product:update",
@@ -216,6 +232,12 @@
"store-table:create",
"store-table:update",
"store-table:export",
"store-staff:read",
"store-staff:create",
"store-staff:update",
"store-shift:read",
"store-shift:create",
"store-shift:update",
"product:create",
"product:read",
"product:update",
@@ -242,6 +264,7 @@
"store:read",
"store-table-area:read",
"store-table:read",
"store-shift:read",
"product:read",
"order:read",
"order:update",