fix 优化出差组生成

This commit is contained in:
2024-07-04 18:27:53 +08:00
parent ac70d6c724
commit 930c9fba1a

View File

@@ -115,13 +115,13 @@ public class CreateDefinitelyGroupJob : BaseJob
foreach (var factory in tenants.Where(x => x.PCode == workplace.Code)) foreach (var factory in tenants.Where(x => x.PCode == workplace.Code))
{ {
var factoryName = $"*{type.GetDescription()}厂区系统组({factory.Name})"; var factoryName = $"*{type.GetDescription()}厂区系统组({factory.Name})";
if (!await DbContext.Queryable<DeviceGroupEntity>().Where(x => x.PCode == workplaceGrp.Code).AnyAsync(x => x.Name == factoryName)) var factoryGrp = await DbContext.Queryable<DeviceGroupEntity>().Where(x => x.PCode == workplaceGrp.Code).FirstAsync(x => x.Name == factoryName);
if (factoryGrp == null)
{ {
var currentCode = Guid.NewGuid(); factoryGrp = new DeviceGroupEntity
await DbContext.InsertAsync(new DeviceGroupEntity
{ {
PCode = workplaceGrp.Code, PCode = workplaceGrp.Code,
Code = currentCode, Code = Guid.NewGuid(),
Type = type, Type = type,
Name = factoryName, Name = factoryName,
Editable = false, Editable = false,
@@ -129,21 +129,26 @@ public class CreateDefinitelyGroupJob : BaseJob
Remark = _remark, Remark = _remark,
TenantId = factory.Code, TenantId = factory.Code,
}); };
await DbContext.InsertAsync(factoryGrp);
}
if (type == DeviceTypeEnumType.Door) if (type == DeviceTypeEnumType.Door)
{
if (!await DbContext.Queryable<DeviceGroupEntity>().Where(x => x.PCode == factoryGrp.Code).AnyAsync(x => x.IsBusinessTrip))
{ {
await DbContext.InsertAsync(new DeviceGroupEntity await DbContext.InsertAsync(new DeviceGroupEntity
{ {
PCode = currentCode, PCode = factoryGrp.Code,
Code = currentCode, Code = Guid.NewGuid(),
Type = type, Type = type,
Name = "出差组", Name = "*出差组",
Editable = false, Editable = false,
AbleSetNext = false, AbleSetNext = false,
Remark = _remark,
IsBusinessTrip = true, IsBusinessTrip = true,
TenantId = factory.Code Remark = _remark,
TenantId = factory.Code,
}); });
} }
} }