67 lines
2.1 KiB
C#
67 lines
2.1 KiB
C#
using Dlhis.Basic.Places.Request;
|
|
using Dlhis.Basic.BusinessPlace.Response;
|
|
using Dlhis.Entity.Basic.Entity;
|
|
using Kurisu.Core.DataAccess.Dto;
|
|
using Kurisu.Core.User.Abstractions;
|
|
using Kurisu.SqlSugar.Services;
|
|
using Mapster;
|
|
|
|
namespace Dlhis.Basic.BusinessPlace.Services.Implements;
|
|
|
|
public class BusinessPlacePermissionsService : IBusinessPlacePermissionsService
|
|
{
|
|
private readonly IDbContext _dbContext;
|
|
private readonly ICurrentUser _currentUser;
|
|
|
|
public BusinessPlacePermissionsService(IDbContext dbContext, ICurrentUser currentUser)
|
|
{
|
|
_dbContext = dbContext;
|
|
_currentUser = currentUser;
|
|
}
|
|
|
|
public async Task<Pagination<BusinessPlacePermissionPageResponse>> GetPageAsync(BusinessPlacePermissionPageRequest request)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<GetMyResponse> GetMyAsync()
|
|
{
|
|
var userId = _currentUser.GetIntSubjectId();
|
|
|
|
var guids = await _dbContext.Queryable<BusinessPlaceManagerRelationshipEntity>()
|
|
.Where(x => x.ManagerUserId == userId)
|
|
.Select(x => x.BusinessPlaceCode)
|
|
.Distinct()
|
|
.ToListAsync();
|
|
|
|
var dtos = await _dbContext.Queryable<BusinessPlaceEntity>()
|
|
.Where(x => guids.Contains(x.Code))
|
|
.Select<BusinessPlaceDto>()
|
|
.ToListAsync();
|
|
var myResponse = new GetMyResponse
|
|
{
|
|
dtos = dtos
|
|
};
|
|
return myResponse;
|
|
}
|
|
|
|
public async Task SaveBusinessPlacePermissionAsync(BusinessPlacePermissionSaveRequest request)
|
|
{
|
|
var userId = _currentUser.GetIntSubjectId();
|
|
if (request.Id.HasValue)
|
|
{
|
|
var entity = await _dbContext.Queryable<BusinessPlaceManagerRelationshipEntity>()
|
|
.Where(x => x.Id == request.Id).FirstAsync();
|
|
|
|
request.Adapt(entity);
|
|
await _dbContext.UpdateAsync(entity);
|
|
}
|
|
else
|
|
{
|
|
var entity = request.Adapt<BusinessPlaceManagerRelationshipEntity>();
|
|
entity.ManagerUserId = userId;
|
|
await _dbContext.InsertAsync(entity);
|
|
}
|
|
}
|
|
}
|