init 项目代码初始化
This commit is contained in:
49
Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs
Normal file
49
Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user