feat 创建系统默认分组

This commit is contained in:
2024-02-22 14:30:03 +08:00
parent 9345cc6441
commit 170b6a1202
8 changed files with 212 additions and 20 deletions

View File

@@ -2,12 +2,10 @@
using Dlhis.Basic.Organization.Request;
using Dlhis.Basic.Organization.Response;
using Dlhis.Basic.Organization.Services;
using Dlhis.Entity.Basic.Entity;
using Kurisu.AspNetCore.MVC;
using Kurisu.Core.DataAccess.Dto;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Org.BouncyCastle.Asn1.Ocsp;
namespace Dlhis.Basic.MealUser.Controllers;
@@ -142,7 +140,7 @@ public class GainfosController : ControllerBase
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpGet("gainfolist")]
[HttpGet("list")]
public async Task<Pagination<GainfoListResponse>> GetGainfoListTaskAsync([FromQuery]GainfoListRequest request)
{
return await _gainfoService.GetGainfoListTaskAsync(request);
@@ -152,7 +150,7 @@ public class GainfosController : ControllerBase
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpGet("gainfodetail")]
[HttpGet("detail")]
public async Task<GainfoDetailResponse> GetGainfoDetailTaskAsync([FromQuery] GainfoDetailRequest request)
{
return await _gainfoService.GetGainfoDetailTaskAsync(request);

View File

@@ -1,4 +1,7 @@
namespace Dlhis.Basic.Organization.Response;
using Dlhis.Entity.Basic.Enums;
using Kurisu.AspNetCore.Utils.Extensions;
namespace Dlhis.Basic.Organization.Response;
public class GainfoPageResponse
{
@@ -52,7 +55,8 @@ public class GainfoPageResponse
/// <summary>
/// 性别
/// </summary>
public string Gender { get; set; }
public GenderEnumType Gender { get; set; }
public string GenderDesc => Gender.GetDescription();
/// <summary>
/// 生日

View File

@@ -53,9 +53,9 @@ public class GainfoService : IGainfoService
var tenant = _currentUser.GetStringTenantId();
var page = await _gainfoStore.Queryable(request.Status)
.WhereIF(request.DepartmentNos?.Any() == true, gainfo => request.DepartmentNos.Contains(gainfo.DepartmentNo))
.WhereIF(request.DepartmentNos.IsPresent(), gainfo => request.DepartmentNos.Contains(gainfo.DepartmentNo))
.WhereIF(request.Search.IsPresent(), gainfo =>
gainfo.Name.Contains(request.Search)
gainfo.Name.Contains(request.Search)
|| gainfo.Code.Contains(request.Search))
.Where(gainfo => gainfo.Werks == tenant)
.Select<GainfoPageResponse>()
@@ -561,7 +561,7 @@ public class GainfoService : IGainfoService
/// <returns></returns>
private async Task<List<string>> GetRecursionDepartmentNosAsync(List<string> departmentNos)
{
if (departmentNos == null || departmentNos.Count == 0)
if (departmentNos.IsEmpty())
{
return new List<string>();
}

View File

@@ -17,14 +17,14 @@ public class SqlSugarPack : BaseAppPack
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
//using var scope = app.ApplicationServices.CreateScope();
//var db = scope.ServiceProvider.GetService<ISqlSugarClient>();
//var tables = App.ActiveTyps.Where(x => x.IsDefined(typeof(SugarTable), false))
// .Where(x => !x.IsDefined(typeof(SkipScanAttribute), false))
// .ToArray();
using var scope = app.ApplicationServices.CreateScope();
var db = scope.ServiceProvider.GetService<ISqlSugarClient>();
var tables = App.ActiveTyps.Where(x => x.IsDefined(typeof(SugarTable), false))
.Where(x => !x.IsDefined(typeof(SkipScanAttribute), false))
.ToArray();
//db.DbMaintenance.CreateDatabase();
//db.CodeFirst.InitTables(tables);
db.DbMaintenance.CreateDatabase();
db.CodeFirst.InitTables(tables);
//using var scopeFace = app.ApplicationServices.CreateScope();
//var dbFace = scopeFace.ServiceProvider.GetService<ISqlSugarClient>();

View File

@@ -1,4 +1,5 @@
using Kurisu.SqlSugar;
using Kurisu.Core.DataAccess.Entity;
using Kurisu.SqlSugar;
using SqlSugar;
namespace Dlhis.Entity.Basic.Entity;
@@ -7,8 +8,13 @@ namespace Dlhis.Entity.Basic.Entity;
/// 档案组
/// </summary>
[SugarTable(TableName = "GainfoGroup", TableDescription = "档案组")]
public class GainfoGroupEntity : SugarBaseEntity
public class GainfoGroupEntity : SugarBaseEntity, ITenantId
{
/// <summary>
/// 父级Code
/// </summary>
public Guid? PCode { get; set; }
/// <summary>
/// 分组code
/// </summary>
@@ -26,4 +32,19 @@ public class GainfoGroupEntity : SugarBaseEntity
/// </summary>
[SugarColumn(ColumnDescription = "备注")]
public string Remark { get; set; }
/// <summary>
/// 是否默认分组
/// </summary>
[SugarColumn(ColumnDescription = "是否默认分组")]
public bool IsDefault { get; set; }
/// <summary>
/// 是否可编辑
/// </summary>
[SugarColumn(ColumnDescription = "是否可编辑")]
public bool Editable { get; set; }
public string TenantId { get; set; }
}

View File

@@ -12,7 +12,6 @@ namespace Dlhis.Entity.Device.Entities;
[SugarTable(TableName = "DeviceGroup", TableDescription = "设备组")]
public class DeviceGroupEntity : SugarBaseEntity, ITenantId, ISoftDeleted
{
/// <summary>
/// 设备组功能类型
/// </summary>

View File

@@ -0,0 +1,163 @@
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;
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)
{
_logger = logger;
_tenantApi = tenantApi;
_dbContext = dbContext;
}
public async Task RunAsync()
{
_dbContext.Client.QueryFilter.ClearAndBackup<ITenantId>();
try
{
var tenantResult = await _tenantApi.GetTenantsInternalAsync();
var tenants = tenantResult.Data;
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 = "*通用考勤设备组",
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 = "*专用考勤设备组",
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 = "*非公共区域",
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 = "*公共区域",
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();
}
}
}

View File

@@ -1,4 +1,5 @@
using Dlhis.ScheduledTask.SyncSapInfo.Job;
using Dlhis.ScheduledTask.CommonJobs;
using Dlhis.ScheduledTask.SyncSapInfo.Job;
using Dlhis.ScheduledTask.TaskAssignment.Job;
using Hangfire;
using Kurisu.AspNetCore.Startup;
@@ -32,5 +33,11 @@ public class JobPack : BaseAppPack
{
TimeZone = TimeZoneInfo.Local
});
//创建系统默认分组
RecurringJob.AddOrUpdate<CreateDefinitelyGroupJob>("CreateDefinitelyGroup", s => s.RunAsync(), "0 0 5 * * ?", new RecurringJobOptions
{
TimeZone = TimeZoneInfo.Local
});
}
}