172 lines
6.5 KiB
C#
172 lines
6.5 KiB
C#
using Dlhis.Entity.Basic.Entity;
|
|
using Dlhis.Entity.Device.Entities;
|
|
using Dlhis.Entity.Device.Enums;
|
|
using Dlhis.Sys.Api;
|
|
using Kurisu.Core.DataAccess.Entity;
|
|
using Kurisu.SqlSugar.Services;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace Dlhis.ScheduledTask.CommonJobs;
|
|
|
|
public class CreateDefinitelyGroupJob
|
|
{
|
|
private readonly ILogger<CreateDefinitelyGroupJob> _logger;
|
|
private readonly ITenantApi _tenantApi;
|
|
private readonly IDbContext _dbContext;
|
|
|
|
public CreateDefinitelyGroupJob(ILogger<CreateDefinitelyGroupJob> logger, ITenantApi tenantApi, IDbContext dbContext, ISqlSugarOptionsService sqlSugarOptionsService)
|
|
{
|
|
_logger = logger;
|
|
_tenantApi = tenantApi;
|
|
_dbContext = dbContext;
|
|
|
|
sqlSugarOptionsService.IgnoreTenant = true;
|
|
}
|
|
|
|
public async Task RunAsync()
|
|
{
|
|
_dbContext.Client.QueryFilter.ClearAndBackup<ITenantId>();
|
|
try
|
|
{
|
|
var tenantResult = await _tenantApi.GetTenantsInternalAsync();
|
|
var tenants = tenantResult.Data;
|
|
|
|
_logger.LogInformation("获取基地信息:{json}", JsonConvert.SerializeObject(tenants));
|
|
|
|
foreach (var tenant in tenants)
|
|
{
|
|
if (!await _dbContext.Queryable<GainfoGroupEntity>().Where(x => x.TenantId == tenant.Code).AnyAsync(x => x.IsDefault))
|
|
{
|
|
var customGroup = new GainfoGroupEntity
|
|
{
|
|
PCode = null,
|
|
Code = Guid.NewGuid(),
|
|
Name = "*自定义人员分组",
|
|
IsDefault = true,
|
|
Editable = false,
|
|
|
|
CreatedBy = 1,
|
|
CreateTime = DateTime.Now,
|
|
ModifiedBy = 1,
|
|
ModifiedTime = DateTime.Now,
|
|
TenantId = tenant.Code
|
|
};
|
|
await _dbContext.InsertAsync(customGroup);
|
|
|
|
|
|
var groups = new[] { "*督查组", "*X3及以上领导组", "*外派人员组" };
|
|
foreach (var group in groups)
|
|
{
|
|
var grp = new GainfoGroupEntity
|
|
{
|
|
PCode = null,
|
|
Code = Guid.NewGuid(),
|
|
Name = group,
|
|
IsDefault = false,
|
|
Editable = false,
|
|
|
|
CreatedBy = 1,
|
|
CreateTime = DateTime.Now,
|
|
ModifiedBy = 1,
|
|
ModifiedTime = DateTime.Now,
|
|
TenantId = tenant.Code
|
|
};
|
|
|
|
await _dbContext.InsertAsync(grp);
|
|
}
|
|
}
|
|
|
|
//**************************************************************************************************************/
|
|
|
|
if (!await _dbContext.Queryable<DeviceGroupEntity>().Where(x => x.TenantId == tenant.Code).AnyAsync(x => x.Name == "*通用考勤设备组"))
|
|
{
|
|
await _dbContext.InsertAsync(new DeviceGroupEntity
|
|
{
|
|
PCode = null,
|
|
Code = Guid.NewGuid(),
|
|
Type = DeviceTypeEnumType.Attendance,
|
|
Name = "*通用考勤设备组",
|
|
Editable = false,
|
|
|
|
CreatedBy = 1,
|
|
CreateTime = DateTime.Now,
|
|
ModifiedBy = 1,
|
|
ModifiedTime = DateTime.Now,
|
|
TenantId = tenant.Code,
|
|
});
|
|
}
|
|
|
|
if (!await _dbContext.Queryable<DeviceGroupEntity>().Where(x => x.TenantId == tenant.Code).AnyAsync(x => x.Name == "*专用考勤设备组"))
|
|
{
|
|
await _dbContext.InsertAsync(new DeviceGroupEntity
|
|
{
|
|
PCode = null,
|
|
Code = Guid.NewGuid(),
|
|
Type = DeviceTypeEnumType.Attendance,
|
|
Name = "*专用考勤设备组",
|
|
Editable = false,
|
|
|
|
CreatedBy = 1,
|
|
CreateTime = DateTime.Now,
|
|
ModifiedBy = 1,
|
|
ModifiedTime = DateTime.Now,
|
|
TenantId = tenant.Code,
|
|
});
|
|
}
|
|
|
|
//**************************************************************************************************************/
|
|
|
|
if (!await _dbContext.Queryable<DeviceGroupEntity>().Where(x => x.TenantId == tenant.Code)
|
|
.Where(x => x.Type == DeviceTypeEnumType.Door)
|
|
.AnyAsync(x => x.Name == "*通用考勤设备组")
|
|
)
|
|
{
|
|
await _dbContext.InsertAsync(new DeviceGroupEntity
|
|
{
|
|
PCode = null,
|
|
Code = Guid.NewGuid(),
|
|
Type = DeviceTypeEnumType.Door,
|
|
Name = "*非公共区域",
|
|
Editable = false,
|
|
|
|
CreatedBy = 1,
|
|
CreateTime = DateTime.Now,
|
|
ModifiedBy = 1,
|
|
ModifiedTime = DateTime.Now,
|
|
TenantId = tenant.Code,
|
|
});
|
|
}
|
|
|
|
if (!await _dbContext.Queryable<DeviceGroupEntity>().Where(x => x.TenantId == tenant.Code)
|
|
.Where(x => x.Type == DeviceTypeEnumType.Door)
|
|
.AnyAsync(x => x.Name == "*专用考勤设备组")
|
|
)
|
|
{
|
|
await _dbContext.InsertAsync(new DeviceGroupEntity
|
|
{
|
|
PCode = null,
|
|
Code = Guid.NewGuid(),
|
|
Type = DeviceTypeEnumType.Door,
|
|
Name = "*公共区域",
|
|
Editable = false,
|
|
|
|
CreatedBy = 1,
|
|
CreateTime = DateTime.Now,
|
|
ModifiedBy = 1,
|
|
ModifiedTime = DateTime.Now,
|
|
TenantId = tenant.Code,
|
|
});
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "自动创建系统分组失败:{message}", ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
_dbContext.Client.QueryFilter.Restore();
|
|
}
|
|
}
|
|
}
|