94 lines
2.8 KiB
C#
94 lines
2.8 KiB
C#
using Dlhis.Entity.Visitor.Entity;
|
|
using Dlhis.Visitor.Appointment.Request;
|
|
using Dlhis.Visitor.Appointment.Response;
|
|
using Kurisu.AspNetCore.Utils.Extensions;
|
|
using Kurisu.Core.DataAccess.Dto;
|
|
using Kurisu.SqlSugar.Extensions;
|
|
using Kurisu.SqlSugar.Services;
|
|
using Mapster;
|
|
|
|
namespace Dlhis.Visitor.Appointment.Services.Implements;
|
|
|
|
public class ApponintmentAreaService : IApponintmentAreaService
|
|
{
|
|
private readonly IDbContext _dbContext;
|
|
|
|
public ApponintmentAreaService(IDbContext dbContext)
|
|
{
|
|
_dbContext = dbContext;
|
|
}
|
|
|
|
public async Task<Pagination<ApponintmentAreaPageResponse>> GetPageAsync(PageDto request)
|
|
{
|
|
return await _dbContext.Queryable<AppointmentAreaEntity>()
|
|
.Select<ApponintmentAreaPageResponse>()
|
|
.ToPageListAsync(request);
|
|
}
|
|
|
|
|
|
public async Task SaveAsync(AppointmentAreaSaveRequest request)
|
|
{
|
|
await CheckCustomCodeDuplicateAsync(request);
|
|
|
|
if (!request.Id.HasValue)
|
|
{
|
|
var entity = request.Adapt<AppointmentAreaEntity>();
|
|
entity.Type = request.Type;
|
|
entity.CustomCode = request.CustomCode;
|
|
|
|
await _dbContext.InsertAsync(entity);
|
|
}
|
|
else
|
|
{
|
|
var entity = await _dbContext.Queryable<AppointmentAreaEntity>().Where(x => x.Id == request.Id).SingleAsync();
|
|
entity.ThrowIfNull("预约区域不存在");
|
|
|
|
request.Adapt(entity);
|
|
|
|
await _dbContext.UpdateAsync(entity);
|
|
}
|
|
}
|
|
|
|
|
|
public async Task DeleteAsync(long id)
|
|
{
|
|
var entity = await _dbContext.Queryable<AppointmentAreaEntity>().Where(x => x.Id == id).SingleAsync();
|
|
await _dbContext.DeleteAsync(entity);
|
|
}
|
|
|
|
|
|
public async Task AssignAsync(AppointmentAreaAssignRequest request)
|
|
{
|
|
await _dbContext.Client.Deleteable<AppointmentAreaAssignmentEntity>()
|
|
.Where(x => x.CustomCode == request.CustomCode)
|
|
.ExecuteCommandAsync();
|
|
|
|
var data = request.DeviceCodes.Select(x => new AppointmentAreaAssignmentEntity
|
|
{
|
|
CustomCode = request.CustomCode,
|
|
DeviceCode = x,
|
|
})
|
|
.ToList();
|
|
|
|
await _dbContext.InsertAsync(data);
|
|
}
|
|
|
|
|
|
//********************************************************* help methods ***************************************************************
|
|
|
|
/// <summary>
|
|
/// 检查编码重复
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
private async Task CheckCustomCodeDuplicateAsync(AppointmentAreaSaveRequest request)
|
|
{
|
|
var exists = await _dbContext.Queryable<AppointmentAreaEntity>()
|
|
.Where(x => x.CustomCode == request.CustomCode)
|
|
.WhereIF(request.Id.HasValue, x => x.Id == request.Id)
|
|
.AnyAsync();
|
|
|
|
exists.ThrowIfTrue("重复区域编码,请检查");
|
|
}
|
|
}
|