fix 补充营业点分配权限接口
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Dlhis.Basic.Dishes.Request;
|
using Dlhis.Basic.BusinessPlace.Services;
|
||||||
|
using Dlhis.Basic.Dishes.Request;
|
||||||
using Dlhis.Basic.Dishes.Response;
|
using Dlhis.Basic.Dishes.Response;
|
||||||
using Dlhis.Entity.Basic.Entity;
|
using Dlhis.Entity.Basic.Entity;
|
||||||
using Dlhis.Entity.Canteen.Entities;
|
using Dlhis.Entity.Canteen.Entities;
|
||||||
@@ -11,16 +12,21 @@ namespace Dlhis.Basic.Dishes.Services.Implements;
|
|||||||
public class DishesCategoryService : IDishesCategoryService
|
public class DishesCategoryService : IDishesCategoryService
|
||||||
{
|
{
|
||||||
private readonly IDbContext _dbContext;
|
private readonly IDbContext _dbContext;
|
||||||
|
private readonly IBusinessPlacePermissionsService _businessPlacePermissionsService;
|
||||||
|
|
||||||
public DishesCategoryService(IDbContext dbContext)
|
public DishesCategoryService(IDbContext dbContext, IBusinessPlacePermissionsService businessPlacePermissionsService)
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
|
_businessPlacePermissionsService = businessPlacePermissionsService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<DishesCategoryTreeResponse>> TreeAsync()
|
public async Task<List<DishesCategoryTreeResponse>> TreeAsync()
|
||||||
{
|
{
|
||||||
|
var mybCodes = await GetMyBusinessPlaceCodesAsync();
|
||||||
|
|
||||||
var categories = await _dbContext.Queryable<DishesCategoryEntity>()
|
var categories = await _dbContext.Queryable<DishesCategoryEntity>()
|
||||||
.LeftJoin<BusinessPlaceEntity>((x, bplace) => x.BusinessPlaceCode == bplace.Code)
|
.LeftJoin<BusinessPlaceEntity>((x, bplace) => x.BusinessPlaceCode == bplace.Code)
|
||||||
|
.Where(x => mybCodes.Contains(x.BusinessPlaceCode))
|
||||||
.Select((x, bplace) => new DishesCategoryTreeResponse
|
.Select((x, bplace) => new DishesCategoryTreeResponse
|
||||||
{
|
{
|
||||||
BusinessPlaceCode = bplace.Code,
|
BusinessPlaceCode = bplace.Code,
|
||||||
@@ -42,6 +48,8 @@ public class DishesCategoryService : IDishesCategoryService
|
|||||||
|
|
||||||
public async Task SaveAsync(DishesCategorySaveRequest request)
|
public async Task SaveAsync(DishesCategorySaveRequest request)
|
||||||
{
|
{
|
||||||
|
await CheckBusinessPlacePermissionAsync(request.BusinessPlaceCode);
|
||||||
|
|
||||||
if (!request.Id.HasValue)
|
if (!request.Id.HasValue)
|
||||||
{
|
{
|
||||||
var entity = request.Adapt<DishesCategoryEntity>();
|
var entity = request.Adapt<DishesCategoryEntity>();
|
||||||
@@ -73,4 +81,27 @@ public class DishesCategoryService : IDishesCategoryService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 检查营业点权限
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="businessPlaceCode"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task CheckBusinessPlacePermissionAsync(Guid businessPlaceCode)
|
||||||
|
{
|
||||||
|
var codes = await GetMyBusinessPlaceCodesAsync();
|
||||||
|
codes.Contains(businessPlaceCode).ThrowIfFalse("无权操作当前营业点");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取我管理的营业点
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task<List<Guid>> GetMyBusinessPlaceCodesAsync()
|
||||||
|
{
|
||||||
|
var mybCodes = (await _businessPlacePermissionsService.GetMyAsync()).Select(x => x.Code).ToList();
|
||||||
|
|
||||||
|
return mybCodes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class BusinessPlacePermissionsController
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[Authorize(Roles = "admin,tenant-admin")]
|
[Authorize(Roles = "admin,tenant-admin,businessplace-manager")]
|
||||||
[HttpGet("page")]
|
[HttpGet("page")]
|
||||||
public async Task<Pagination<BusinessPlacePermissionPageResponse>> GetPageAsync([FromQuery] BusinessPlacePermissionPageRequest request)
|
public async Task<Pagination<BusinessPlacePermissionPageResponse>> GetPageAsync([FromQuery] BusinessPlacePermissionPageRequest request)
|
||||||
{
|
{
|
||||||
@@ -57,4 +57,28 @@ public class BusinessPlacePermissionsController
|
|||||||
{
|
{
|
||||||
await _businessPlacePermissionsService.SaveBusinessPlacePermissionAsync(request);
|
await _businessPlacePermissionsService.SaveBusinessPlacePermissionAsync(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 通过userid获取分配的营业点信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[Authorize(Roles = "admin,tenant-admin")]
|
||||||
|
[HttpGet("assignments/{userId}")]
|
||||||
|
public async Task<List<BusinessPlacePermissionPageResponse>> GetBusinessPlacePermissionByUserIdAsyc(int userId)
|
||||||
|
{
|
||||||
|
return await _businessPlacePermissionsService.GetBusinessPlacePermissionByUserIdAsyc(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除记录
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[Authorize(Roles = "admin,tenant-admin")]
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
public async Task DeleteAssignmentAsync(int id)
|
||||||
|
{
|
||||||
|
await _businessPlacePermissionsService.DeleteAssignmentAsync(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ public class BusinessPlacePermissionPageResponse
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 用户id
|
/// 用户id
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string UserId { get; set; }
|
public int UserId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 用户name
|
/// 用户name
|
||||||
|
|||||||
@@ -12,4 +12,8 @@ public interface IBusinessPlacePermissionsService : IScopeDependency
|
|||||||
Task SaveBusinessPlacePermissionAsync(BusinessPlacePermissionSaveRequest request);
|
Task SaveBusinessPlacePermissionAsync(BusinessPlacePermissionSaveRequest request);
|
||||||
|
|
||||||
Task<List<BusinessPlaceDto>> GetMyAsync();
|
Task<List<BusinessPlaceDto>> GetMyAsync();
|
||||||
|
|
||||||
|
Task<List<BusinessPlacePermissionPageResponse>> GetBusinessPlacePermissionByUserIdAsyc(int id);
|
||||||
|
|
||||||
|
Task DeleteAssignmentAsync(int id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ using Kurisu.Core.User.Abstractions;
|
|||||||
using Kurisu.SqlSugar.Services;
|
using Kurisu.SqlSugar.Services;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
using Dlhis.Basic.Places.Dtos;
|
using Dlhis.Basic.Places.Dtos;
|
||||||
|
using Kurisu.SqlSugar.Extensions;
|
||||||
|
using Dlhis.Sys.Api;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace Dlhis.Basic.BusinessPlace.Services.Implements;
|
namespace Dlhis.Basic.BusinessPlace.Services.Implements;
|
||||||
|
|
||||||
@@ -13,16 +16,36 @@ public class BusinessPlacePermissionsService : IBusinessPlacePermissionsService
|
|||||||
{
|
{
|
||||||
private readonly IDbContext _dbContext;
|
private readonly IDbContext _dbContext;
|
||||||
private readonly ICurrentUser _currentUser;
|
private readonly ICurrentUser _currentUser;
|
||||||
|
private readonly IUserApi _userApi;
|
||||||
|
|
||||||
public BusinessPlacePermissionsService(IDbContext dbContext, ICurrentUser currentUser)
|
public BusinessPlacePermissionsService(IDbContext dbContext, ICurrentUser currentUser, IUserApi userApi)
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
_currentUser = currentUser;
|
_currentUser = currentUser;
|
||||||
|
_userApi = userApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Pagination<BusinessPlacePermissionPageResponse>> GetPageAsync(BusinessPlacePermissionPageRequest request)
|
public async Task<Pagination<BusinessPlacePermissionPageResponse>> GetPageAsync(BusinessPlacePermissionPageRequest request)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
var page = await _dbContext.Queryable<BusinessPlaceManagerRelationshipEntity>()
|
||||||
|
.LeftJoin<BusinessPlaceEntity>((x, bplace) => x.BusinessPlaceCode == bplace.Code)
|
||||||
|
.Select((x, bplace) => new BusinessPlacePermissionPageResponse
|
||||||
|
{
|
||||||
|
UserId = x.ManagerUserId,
|
||||||
|
BusinessPlaceCode = x.BusinessPlaceCode,
|
||||||
|
BusinessPlaceName = bplace.Name,
|
||||||
|
})
|
||||||
|
.ToPageListAsync(request);
|
||||||
|
|
||||||
|
var usersResult = await _userApi.GetUserByIdsAsync(page.Data.Select(x => x.UserId).Distinct().ToList());
|
||||||
|
var users = usersResult.Data;
|
||||||
|
|
||||||
|
page.Data.ForEach(item =>
|
||||||
|
{
|
||||||
|
item.UserName = users.FirstOrDefault(x => x.Id == item.UserId)?.UserName;
|
||||||
|
});
|
||||||
|
|
||||||
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<BusinessPlaceDto>> GetMyAsync()
|
public async Task<List<BusinessPlaceDto>> GetMyAsync()
|
||||||
@@ -59,4 +82,33 @@ public class BusinessPlacePermissionsService : IBusinessPlacePermissionsService
|
|||||||
await _dbContext.InsertAsync(entity);
|
await _dbContext.InsertAsync(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<List<BusinessPlacePermissionPageResponse>> GetBusinessPlacePermissionByUserIdAsyc(int id)
|
||||||
|
{
|
||||||
|
var infos = await _dbContext.Queryable<BusinessPlaceManagerRelationshipEntity>()
|
||||||
|
.LeftJoin<BusinessPlaceEntity>((x, bplace) => x.BusinessPlaceCode == bplace.Code)
|
||||||
|
.Where(x => x.ManagerUserId == id)
|
||||||
|
.Select((x, bplace) => new BusinessPlacePermissionPageResponse
|
||||||
|
{
|
||||||
|
UserId = x.ManagerUserId,
|
||||||
|
BusinessPlaceCode = x.BusinessPlaceCode,
|
||||||
|
BusinessPlaceName = bplace.Name,
|
||||||
|
})
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
var userResult = await _userApi.GetUserByIdAsync(id);
|
||||||
|
var user = userResult.Data;
|
||||||
|
|
||||||
|
infos.ForEach(item =>
|
||||||
|
{
|
||||||
|
item.UserName = user?.UserName;
|
||||||
|
});
|
||||||
|
|
||||||
|
return infos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task DeleteAssignmentAsync(int id)
|
||||||
|
{
|
||||||
|
await _dbContext.Client.Deleteable<BusinessPlaceManagerRelationshipEntity>().Where(x => x.Id == id).ExecuteCommandAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,4 +10,8 @@ public interface IUserApi
|
|||||||
[Auth]
|
[Auth]
|
||||||
[Get("/api/users")]
|
[Get("/api/users")]
|
||||||
Task<DefaultApiResult<UserResponse>> GetUserByIdAsync(int id);
|
Task<DefaultApiResult<UserResponse>> GetUserByIdAsync(int id);
|
||||||
|
|
||||||
|
[Auth]
|
||||||
|
[Post("/api/users/by-ids")]
|
||||||
|
Task<DefaultApiResult<List<UserResponse>>> GetUserByIdsAsync(List<int> ids);
|
||||||
}
|
}
|
||||||
@@ -56,6 +56,13 @@ public class UsersController : ControllerBase
|
|||||||
return await _userService.GetUserByIdAsync(id);
|
return await _userService.GetUserByIdAsync(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[HttpPost("by-ids")]
|
||||||
|
public async Task<List<UserResponse>> GetUserByIdsAsync(List<int> ids)
|
||||||
|
{
|
||||||
|
return await _userService.GetUserByIdsAsync(ids);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 上传头像
|
/// 上传头像
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -15,4 +15,7 @@ public interface IUserService : IScopeDependency
|
|||||||
Task<UserResponse> GetUserByIdAsync(int id);
|
Task<UserResponse> GetUserByIdAsync(int id);
|
||||||
|
|
||||||
Task UploadUserAvatarAsync(UserAvatarUploadRequest request);
|
Task UploadUserAvatarAsync(UserAvatarUploadRequest request);
|
||||||
|
|
||||||
|
|
||||||
|
Task<List<UserResponse>> GetUserByIdsAsync(List<int> ids);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,4 +61,10 @@ public class UserService : IUserService
|
|||||||
{
|
{
|
||||||
var user = await _dbContext.Queryable<UserEntity>().Where(x => x.Id == request.UserNo).Select<UserResponse>().FirstAsync();
|
var user = await _dbContext.Queryable<UserEntity>().Where(x => x.Id == request.UserNo).Select<UserResponse>().FirstAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<List<UserResponse>> GetUserByIdsAsync(List<int> ids)
|
||||||
|
{
|
||||||
|
var users = await _dbContext.Queryable<UserEntity>().Where(x => ids.Contains(x.Id)).Select<UserResponse>().ToListAsync();
|
||||||
|
return users;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user