50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
using Dlhis.Basic.Device.Request;
|
|
using Dlhis.Basic.Device.Response;
|
|
using Dlhis.Entity.Device.Entities;
|
|
using Kurisu.AspNetCore.Utils.Extensions;
|
|
using Kurisu.Core.DataAccess.Dto;
|
|
using Kurisu.SqlSugar.Extensions;
|
|
using Kurisu.SqlSugar.Services;
|
|
using Mapster;
|
|
|
|
namespace Dlhis.Basic.Device.Services.Implements;
|
|
|
|
public class DeviceService : IDeviceService
|
|
{
|
|
private readonly IDbContext _dbContext;
|
|
|
|
public DeviceService(IDbContext dbContext)
|
|
{
|
|
_dbContext = dbContext;
|
|
}
|
|
|
|
public async Task<Pagination<DeviceResponse>> GetPageAsync(DevicePageRequest request)
|
|
{
|
|
var page = await _dbContext.Queryable<DeviceEntity>()
|
|
.Select<DeviceResponse>()
|
|
.ToPageListAsync(request);
|
|
|
|
return page;
|
|
}
|
|
|
|
|
|
public async Task SaveAsync(DeviceSaveRequest request)
|
|
{
|
|
if (!request.Id.HasValue)
|
|
{
|
|
var entity = request.Adapt<DeviceEntity>();
|
|
entity.Code = Guid.NewGuid();
|
|
await _dbContext.InsertAsync(entity);
|
|
}
|
|
else
|
|
{
|
|
var device = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Id == request.Id).FirstAsync();
|
|
device.ThrowIfNull("设备不存在,无法更新");
|
|
|
|
request.Adapt(device);
|
|
|
|
await _dbContext.UpdateAsync(device);
|
|
}
|
|
}
|
|
}
|