fix 时段变更生成下发任务
This commit is contained in:
@@ -22,12 +22,14 @@ public class DeviceService : IDeviceService
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly ITenantApi _tenantApi;
|
||||
private readonly IDeviceTimePeriodService _deviceTimePeriodService;
|
||||
|
||||
public DeviceService(IDbContext dbContext, ICurrentUser currentUser, ITenantApi tenantApi)
|
||||
public DeviceService(IDbContext dbContext, ICurrentUser currentUser, ITenantApi tenantApi, IDeviceTimePeriodService deviceTimePeriodService)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_currentUser = currentUser;
|
||||
_tenantApi = tenantApi;
|
||||
_deviceTimePeriodService = deviceTimePeriodService;
|
||||
}
|
||||
|
||||
public async Task<Pagination<DevicePageResponse>> GetPageAsync(DevicePageRequest request)
|
||||
@@ -63,50 +65,54 @@ public class DeviceService : IDeviceService
|
||||
await CheckUniqueNoExistsAsync(request);
|
||||
await CheckTemplateExistsAsync(request.TemplateCode);
|
||||
await CheckTemplateFieldAsync(request.TemplateCode, request.ConnectionInfo);
|
||||
|
||||
DeviceEntity entity;
|
||||
if (!request.Id.HasValue)
|
||||
|
||||
await _deviceTimePeriodService.GenerateDeviceTimePeriodTasksAsync(async () =>
|
||||
{
|
||||
entity = request.Adapt<DeviceEntity>();
|
||||
entity.UniqueNo = request.UniqueNo;
|
||||
entity.Code = Guid.NewGuid();
|
||||
await _dbContext.InsertAsync(entity);
|
||||
//同时保存注册信息
|
||||
var registry = await _dbContext.Queryable<DeviceRegistryEntity>().Where(x => x.DeviceUniqueNo == request.UniqueNo).FirstAsync();
|
||||
if (registry == null)
|
||||
DeviceEntity entity;
|
||||
|
||||
if (!request.Id.HasValue)
|
||||
{
|
||||
registry = new DeviceRegistryEntity
|
||||
entity = request.Adapt<DeviceEntity>();
|
||||
entity.UniqueNo = request.UniqueNo;
|
||||
entity.Code = Guid.NewGuid();
|
||||
await _dbContext.InsertAsync(entity);
|
||||
//同时保存注册信息
|
||||
var registry = await _dbContext.Queryable<DeviceRegistryEntity>().Where(x => x.DeviceUniqueNo == request.UniqueNo).FirstAsync();
|
||||
if (registry == null)
|
||||
{
|
||||
DeviceUniqueNo = request.UniqueNo,
|
||||
LastHeartbeatTime = DateTime.Now,
|
||||
RegisterTime = DateTime.Now,
|
||||
BusinessPlaceCode = null,
|
||||
};
|
||||
registry = new DeviceRegistryEntity
|
||||
{
|
||||
DeviceUniqueNo = request.UniqueNo,
|
||||
LastHeartbeatTime = DateTime.Now,
|
||||
RegisterTime = DateTime.Now,
|
||||
BusinessPlaceCode = null,
|
||||
};
|
||||
|
||||
await _dbContext.InsertAsync(registry);
|
||||
await _dbContext.InsertAsync(registry);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
entity = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Id == request.Id).FirstAsync();
|
||||
entity.ThrowIfNull("设备不存在,无法更新");
|
||||
|
||||
//分类发生变化,检查是否存在分组
|
||||
if (request.Type != entity.Type)
|
||||
else
|
||||
{
|
||||
var existsG = await _dbContext.Queryable<DeviceGroupRelationshipEntity>()
|
||||
.LeftJoin<DeviceGroupEntity>((dgr, dg) => dgr.GroupCode == dg.Code)
|
||||
.Where((dgr, dg) => dgr.DeviceCode == entity.Code)
|
||||
.AnyAsync();
|
||||
entity = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Id == request.Id).FirstAsync();
|
||||
entity.ThrowIfNull("设备不存在,无法更新");
|
||||
|
||||
existsG.ThrowIfTrue("存在设备分组,不可修改设备分类");
|
||||
//分类发生变化,检查是否存在分组
|
||||
if (request.Type != entity.Type)
|
||||
{
|
||||
var existsG = await _dbContext.Queryable<DeviceGroupRelationshipEntity>()
|
||||
.LeftJoin<DeviceGroupEntity>((dgr, dg) => dgr.GroupCode == dg.Code)
|
||||
.Where((dgr, dg) => dgr.DeviceCode == entity.Code)
|
||||
.AnyAsync();
|
||||
|
||||
existsG.ThrowIfTrue("存在设备分组,不可修改设备分类");
|
||||
}
|
||||
|
||||
request.Adapt(entity);
|
||||
await _dbContext.UpdateAsync(entity);
|
||||
}
|
||||
|
||||
request.Adapt(entity);
|
||||
await _dbContext.UpdateAsync(entity);
|
||||
}
|
||||
|
||||
await GenerateUploadRecordLogForBeginTimeAsync(entity);
|
||||
await GenerateUploadRecordLogForBeginTimeAsync(entity);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user