AuthScopeAppService.cs
2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using FoodLabeling.Application.Contracts.Dtos.AuthScope;
using FoodLabeling.Application.Contracts.IServices;
using FoodLabeling.Application.Helpers;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Application.Services;
using Volo.Abp.Caching;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace FoodLabeling.Application.Services;
/// <summary>
/// 登录后 Company → Region → Location 级联选店(Web 管理端)。
/// </summary>
[Authorize]
public class AuthScopeAppService : ApplicationService, IAuthScopeAppService
{
private readonly ISqlSugarDbContext _dbContext;
private readonly IDistributedCache<AdminWorkingScopeCacheItem, AdminWorkingScopeCacheKey> _workingScopeCache;
public AuthScopeAppService(
ISqlSugarDbContext dbContext,
IDistributedCache<AdminWorkingScopeCacheItem, AdminWorkingScopeCacheKey> workingScopeCache)
{
_dbContext = dbContext;
_workingScopeCache = workingScopeCache;
}
/// <inheritdoc />
[HttpGet("auth-scope/companies")]
public virtual Task<List<AuthScopeCompanyOptionDto>> GetCompaniesAsync() =>
AuthScopeQueryHelper.GetCompaniesAsync(CurrentUser, _dbContext);
/// <inheritdoc />
[HttpGet("auth-scope/regions")]
public virtual Task<List<AuthScopeRegionOptionDto>> GetRegionsAsync([FromQuery] string partnerId) =>
AuthScopeQueryHelper.GetRegionsAsync(CurrentUser, _dbContext, partnerId);
/// <inheritdoc />
[HttpGet("auth-scope/locations")]
public virtual Task<List<AuthScopeLocationOptionDto>> GetLocationsAsync(
[FromQuery] string partnerId,
[FromQuery] string groupId) =>
AuthScopeQueryHelper.GetLocationsAsync(CurrentUser, _dbContext, partnerId, groupId);
/// <inheritdoc />
[HttpPost("auth-scope/select-location")]
public virtual Task<AuthScopeSelectLocationOutputDto> SelectLocationAsync(AuthScopeSelectLocationInputVo input) =>
AuthScopeQueryHelper.SelectLocationAsync(CurrentUser, _dbContext, _workingScopeCache, input);
/// <inheritdoc />
[HttpGet("auth-scope/current-scope")]
public virtual Task<AuthScopeSelectLocationOutputDto?> GetCurrentScopeAsync() =>
AuthScopeQueryHelper.GetCurrentScopeAsync(CurrentUser, _dbContext, _workingScopeCache);
}