fix 预定就餐送货地点
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
using Dlhis.Basic.MealUser.Request;
|
||||
using Dlhis.Basic.MealUser.Response;
|
||||
using Dlhis.Basic.MealUser.Services;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Dlhis.Basic.MealUser.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 订餐地址
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class BookingAddresController : ControllerBase
|
||||
{
|
||||
private readonly IBookingAddresService _bookingAddresService;
|
||||
|
||||
public BookingAddresController(IBookingAddresService bookingAddresService)
|
||||
{
|
||||
_bookingAddresService = bookingAddresService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 地址分页
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("pageAddres")]
|
||||
public async Task<Pagination<GetAddresPageResponse>> GetAddresPageAsync([FromQuery] GetAddresPageRequest request)
|
||||
{
|
||||
return await _bookingAddresService.GetAddresPageRequest(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 地址保存
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("saveAddres")]
|
||||
public async Task SaveAddresAsync(SaveAddresRequest request)
|
||||
{
|
||||
await _bookingAddresService.SaveAddresAsync(request);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
|
||||
namespace Dlhis.Basic.MealUser.Request
|
||||
{
|
||||
public class GetAddresPageRequest : PageDto
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.Basic.MealUser.Request
|
||||
{
|
||||
public class SaveAddresRequest
|
||||
{
|
||||
|
||||
public long? Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 订餐地址
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "订餐地址")]
|
||||
public string Addres { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.Basic.MealUser.Response
|
||||
{
|
||||
public class GetAddresPageResponse
|
||||
{
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 订餐地址
|
||||
/// </summary>
|
||||
public string Addres { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
using Dlhis.Basic.MealUser.Request;
|
||||
using Dlhis.Basic.MealUser.Response;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
|
||||
namespace Dlhis.Basic.MealUser.Services
|
||||
{
|
||||
public interface IBookingAddresService : IScopeDependency
|
||||
{
|
||||
Task<Pagination<GetAddresPageResponse>> GetAddresPageRequest(GetAddresPageRequest request);
|
||||
Task SaveAddresAsync(SaveAddresRequest request);
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
using Dlhis.Basic.MealUser.Request;
|
||||
using Dlhis.Basic.MealUser.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Kurisu.SqlSugar.Extensions;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Dlhis.Basic.MealUser.Services.Implements
|
||||
{
|
||||
public class BookingAddresService : IBookingAddresService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
|
||||
public BookingAddresService(IDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task<Pagination<GetAddresPageResponse>> GetAddresPageRequest(GetAddresPageRequest request)
|
||||
{
|
||||
return await _dbContext.Queryable<BookingAddresEntity>()
|
||||
.WhereIF(request.Search.IsPresent(),x=>x.Addres.Contains(request.Search))
|
||||
.Select<GetAddresPageResponse>()
|
||||
.ToPageListAsync(request);
|
||||
}
|
||||
|
||||
public async Task SaveAddresAsync(SaveAddresRequest request)
|
||||
{
|
||||
if (!request.Id.HasValue)
|
||||
{
|
||||
var entity = request.Adapt<BookingAddresEntity>();
|
||||
await _dbContext.InsertAsync(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
var entity = await _dbContext.Queryable<BookingAddresEntity>()
|
||||
.Where(x => x.Id == request.Id)
|
||||
.FirstAsync();
|
||||
request.Adapt(entity);
|
||||
await _dbContext.UpdateAsync(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
|
||||
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
|
||||
namespace Dlhis.Basic.Places.Request;
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
public class BusinessPlacePermissionSaveRequest
|
||||
{
|
||||
public long? Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 管理人员userId
|
||||
/// </summary>
|
||||
@@ -10,5 +12,5 @@ public class BusinessPlacePermissionSaveRequest
|
||||
/// <summary>
|
||||
/// 营业点
|
||||
/// </summary>
|
||||
public List<Guid> BusinessPlaceCodes { get; set; } = new();
|
||||
public Guid BusinessPlaceCode { get; set; }
|
||||
}
|
||||
|
||||
8
Src/Dlhis.Basic/Places/Response/BusinessPlaceDto.cs
Normal file
8
Src/Dlhis.Basic/Places/Response/BusinessPlaceDto.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Dlhis.Basic.BusinessPlace.Response
|
||||
{
|
||||
public class BusinessPlaceDto
|
||||
{
|
||||
public Guid Code { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
7
Src/Dlhis.Basic/Places/Response/GetMyResponse.cs
Normal file
7
Src/Dlhis.Basic/Places/Response/GetMyResponse.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Dlhis.Basic.BusinessPlace.Response
|
||||
{
|
||||
public class GetMyResponse
|
||||
{
|
||||
public List<BusinessPlaceDto> dtos { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
using Dlhis.Basic.Places.Request;
|
||||
using Dlhis.Basic.BusinessPlace.Response;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Dlhis.Basic.Places.Dtos;
|
||||
|
||||
namespace Dlhis.Basic.BusinessPlace.Services;
|
||||
|
||||
@@ -11,9 +10,5 @@ public interface IBusinessPlacePermissionsService : IScopeDependency
|
||||
|
||||
Task SaveBusinessPlacePermissionAsync(BusinessPlacePermissionSaveRequest request);
|
||||
|
||||
Task<List<BusinessPlaceDto>> GetMyAsync();
|
||||
|
||||
Task<List<BusinessPlacePermissionPageResponse>> GetBusinessPlacePermissionByUserIdAsyc(int id);
|
||||
|
||||
Task DeleteAssignmentAsync(int id);
|
||||
Task<GetMyResponse> GetMyAsync();
|
||||
}
|
||||
|
||||
@@ -5,11 +5,6 @@ using Kurisu.Core.DataAccess.Dto;
|
||||
using Kurisu.Core.User.Abstractions;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using Mapster;
|
||||
using Dlhis.Basic.Places.Dtos;
|
||||
using Kurisu.SqlSugar.Extensions;
|
||||
using Dlhis.Sys.Api;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace Dlhis.Basic.BusinessPlace.Services.Implements;
|
||||
|
||||
@@ -17,108 +12,55 @@ public class BusinessPlacePermissionsService : IBusinessPlacePermissionsService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly IUserApi _userApi;
|
||||
|
||||
public BusinessPlacePermissionsService(IDbContext dbContext, ICurrentUser currentUser, IUserApi userApi)
|
||||
public BusinessPlacePermissionsService(IDbContext dbContext, ICurrentUser currentUser)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_currentUser = currentUser;
|
||||
_userApi = userApi;
|
||||
}
|
||||
|
||||
public async Task<Pagination<BusinessPlacePermissionPageResponse>> GetPageAsync(BusinessPlacePermissionPageRequest request)
|
||||
{
|
||||
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;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<List<BusinessPlaceDto>> GetMyAsync()
|
||||
public async Task<GetMyResponse> GetMyAsync()
|
||||
{
|
||||
var userId = _currentUser.GetIntSubjectId();
|
||||
var role = _currentUser.GetUserClaim(ClaimTypes.Role);
|
||||
var isAdmin = role == "admin" || role == "tenant-admin";
|
||||
|
||||
var codes = new List<Guid>();
|
||||
if (isAdmin)
|
||||
{
|
||||
codes = await _dbContext.Queryable<BusinessPlaceEntity>()
|
||||
.Select(x => x.Code)
|
||||
.ToListAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
codes = await _dbContext.Queryable<BusinessPlaceManagerRelationshipEntity>()
|
||||
var guids = await _dbContext.Queryable<BusinessPlaceManagerRelationshipEntity>()
|
||||
.Where(x => x.ManagerUserId == userId)
|
||||
.Select(x => x.BusinessPlaceCode)
|
||||
.Distinct()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
return await _dbContext.Queryable<BusinessPlaceEntity>()
|
||||
.Where(x => codes.Contains(x.Code))
|
||||
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();
|
||||
|
||||
await _dbContext.Client.Deleteable<BusinessPlaceManagerRelationshipEntity>()
|
||||
.Where(x => x.ManagerUserId == request.UserId)
|
||||
.ExecuteCommandAsync();
|
||||
|
||||
await _dbContext.InsertAsync(request.BusinessPlaceCodes.Select(x => new BusinessPlaceManagerRelationshipEntity
|
||||
if (request.Id.HasValue)
|
||||
{
|
||||
BusinessPlaceCode = x,
|
||||
ManagerUserId = request.UserId
|
||||
}).ToList());
|
||||
}
|
||||
var entity = await _dbContext.Queryable<BusinessPlaceManagerRelationshipEntity>()
|
||||
.Where(x => x.Id == request.Id).FirstAsync();
|
||||
|
||||
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 =>
|
||||
request.Adapt(entity);
|
||||
await _dbContext.UpdateAsync(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
item.UserName = user?.UserName;
|
||||
});
|
||||
|
||||
return infos;
|
||||
}
|
||||
|
||||
public async Task DeleteAssignmentAsync(int id)
|
||||
{
|
||||
await _dbContext.Client.Deleteable<BusinessPlaceManagerRelationshipEntity>().Where(x => x.Id == id).ExecuteCommandAsync();
|
||||
var entity = request.Adapt<BusinessPlaceManagerRelationshipEntity>();
|
||||
entity.ManagerUserId = userId;
|
||||
await _dbContext.InsertAsync(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
using Kurisu.Core.DataAccess.Entity;
|
||||
using Kurisu.SqlSugar;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Dlhis.Entity.Basic.Entity
|
||||
{
|
||||
/// <summary>
|
||||
/// 就餐地址
|
||||
/// </summary>
|
||||
[SugarTable(TableName = "BookingAddres", TableDescription = "就餐地址")]
|
||||
public class BookingAddresEntity : SugarBaseEntity, ITenantId
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 订餐地址
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "订餐地址")]
|
||||
public string Addres { get; set; }
|
||||
|
||||
public string TenantId { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user