init 项目代码初始化
This commit is contained in:
12
Src/Dlhis.Basic/Device/Services/IDeviceService.cs
Normal file
12
Src/Dlhis.Basic/Device/Services/IDeviceService.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Response;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
|
||||
namespace Dlhis.Basic.Device.Services;
|
||||
|
||||
public interface IDeviceService
|
||||
{
|
||||
Task<Pagination<DeviceResponse>> GetPageAsync(DevicePageRequest request);
|
||||
|
||||
Task SaveAsync(DeviceSaveRequest request);
|
||||
}
|
||||
11
Src/Dlhis.Basic/Device/Services/IDeviceTemplateService.cs
Normal file
11
Src/Dlhis.Basic/Device/Services/IDeviceTemplateService.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Response;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
|
||||
namespace Dlhis.Basic.Device.Services;
|
||||
|
||||
public interface IDeviceTemplateService : IScopeDependency
|
||||
{
|
||||
Task SaveTemplateAsync(DeviceTemplateSaveRequest request);
|
||||
Task<Pagination<DeviceTemplateResponse>> GetPageAsync(DeviceTemplatePageRequest request);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
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 DeviceTemplateService : IDeviceTemplateService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
|
||||
public DeviceTemplateService(IDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
|
||||
public async Task<Pagination<DeviceTemplateResponse>> GetPageAsync(DeviceTemplatePageRequest request)
|
||||
{
|
||||
var page = await _dbContext.Queryable<DeviceTemplateEntity>()
|
||||
.Select<DeviceTemplateResponse>()
|
||||
.ToPageListAsync(request);
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
public async Task SaveTemplateAsync(DeviceTemplateSaveRequest request)
|
||||
{
|
||||
if (!request.Id.HasValue)
|
||||
{
|
||||
var entity = request.Adapt<DeviceTemplateEntity>();
|
||||
entity.Code = Guid.NewGuid();
|
||||
await _dbContext.InsertAsync(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
var entity = await _dbContext.Queryable<DeviceTemplateEntity>().Where(x => x.Id == request.Id).FirstAsync();
|
||||
await ExistsDeviceUsingTemplateAsync(entity.Code);
|
||||
await _dbContext.UpdateAsync(entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//**********************************************************************************************************/
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 模板被引用,不能修改
|
||||
/// </summary>
|
||||
/// <param name="templateCode"></param>
|
||||
/// <returns></returns>
|
||||
private async Task ExistsDeviceUsingTemplateAsync(Guid templateCode)
|
||||
{
|
||||
var existsUsing = await _dbContext.Queryable<DeviceEntity>().Where(x => x.TemplateCode == templateCode).AnyAsync();
|
||||
existsUsing.ThrowIfTrue("存在使用中的设备信息,无法修改");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user