57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
using Dlhis.Basic.Map.Request;
|
|
using Dlhis.Basic.Map.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;
|
|
|
|
namespace Dlhis.Basic.Map.Services.Implements;
|
|
|
|
public class PointMapService : IPointMapService
|
|
{
|
|
private readonly IDbContext _dbContext;
|
|
|
|
public PointMapService(IDbContext dbContext)
|
|
{
|
|
_dbContext = dbContext;
|
|
}
|
|
|
|
|
|
public async Task<Pagination<PointMapResponse>> GetPageAsync(PageDto request)
|
|
{
|
|
return await _dbContext.Queryable<PointMapEntity>()
|
|
.Select<PointMapResponse>()
|
|
.ToPageListAsync(request);
|
|
}
|
|
|
|
public async Task SaveAsync(SavePointMapRequest request)
|
|
{
|
|
if (!request.Id.HasValue)
|
|
{
|
|
var entity = request.Adapt<PointMapEntity>();
|
|
entity.Code = Guid.NewGuid();
|
|
|
|
await _dbContext.InsertAsync(entity);
|
|
}
|
|
else
|
|
{
|
|
var entity = await _dbContext.Queryable<PointMapEntity>().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<PointMapEntity>().Where(x => x.Id == id).SingleAsync();
|
|
if (entity != null)
|
|
{
|
|
await _dbContext.Deleteable<PointMapEntity>().Where(x => x.Id == id).ExecuteCommandAsync();
|
|
await _dbContext.Deleteable<PointMapDetailEntity>().Where(x => x.PointMapCode == entity.Code).ExecuteCommandAsync();
|
|
}
|
|
}
|
|
}
|