diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index a9a6c726..f500ad8c 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -59,14 +59,11 @@ public class GainfoService : IGainfoService { request.DepartmentNos = await GetRecursionDepartmentNosAsync(request.DepartmentNos); - var tenant = _currentUser.GetStringTenantId(); - var page = await _gainfoStore.Queryable(request.Status) .WhereIF(request.DepartmentNos.IsPresent(), gainfo => request.DepartmentNos.Contains(gainfo.DepartmentNo)) .WhereIF(request.Search.IsPresent(), gainfo => gainfo.Name.Contains(request.Search) || gainfo.Code.Contains(request.Search)) - .Where(gainfo => gainfo.Werks == tenant) .Select() .ToPageListAsync(request); @@ -148,11 +145,19 @@ public class GainfoService : IGainfoService public async Task CurrentUserInfoAsync() { var identityId = _currentUser.GetIntSubjectId(); + var code = _currentUser.GetUserClaim("jinko-code"); + var gainfo = await _gainfoStore.Queryable().Where(x => x.Code == code).FirstAsync() + ?? await _gainfoStore.Queryable().Where(x => x.IdentityUserId == identityId).FirstAsync(); - var gainfo = await _gainfoStore.Queryable(GainfoStatusEnumType.Working) + if (gainfo == null) + { + return null; + } + + var info = await _gainfoStore.Queryable(GainfoStatusEnumType.Working) .LeftJoin((ga, department) => ga.DepartmentNo == department.No) .LeftJoin((ga, department, mealUser) => ga.No == mealUser.UserNo) - .Where((ga, department) => ga.IdentityUserId == identityId) + .Where((ga, department) => ga.Id == gainfo.Id) .Select((ga, department, mealUser) => new GainfoCurrentResponse { UserNo = ga.No, @@ -169,7 +174,7 @@ public class GainfoService : IGainfoService }) .FirstAsync(); - return gainfo; + return info; } public async Task GetFaceAsync(string token) @@ -368,9 +373,9 @@ public class GainfoService : IGainfoService .LeftJoin((ga, de, type, posi) => ga.Position == posi.Name) .LeftJoin((ga, de, type, posi, type2) => ga.CountryNo == type2.Code && type2.Type == "country") .LeftJoin((ga, de, type, posi, type2, type3) => ga.Nation == type3.Code && type3.Type == "nation") - .LeftJoin((ga, de, type, posi, type2, type3,type4) => ga.IdClass == type4.Code && type4.Type == "cls") + .LeftJoin((ga, de, type, posi, type2, type3, type4) => ga.IdClass == type4.Code && type4.Type == "cls") .Where(ga => ga.No == request.No) - .Select((ga, de, type, posi, type2, type3,type4) => new GainfoDetailResponse + .Select((ga, de, type, posi, type2, type3, type4) => new GainfoDetailResponse { No = ga.No, SapNo = ga.SapNo, @@ -389,7 +394,7 @@ public class GainfoService : IGainfoService Degree = ga.Degree, Werks = ga.Werks, CostId = ga.CostId, - Marital = ga.Marital== "Single" ? "未婚":"已婚", + Marital = ga.Marital == "Single" ? "未婚" : "已婚", CountryName = type2.Display, NationName = type3.Display, ClassName = type4.Display, diff --git a/Src/Dlhis.Basic/appsettings.json b/Src/Dlhis.Basic/appsettings.json index 79da19b2..428e90e9 100644 --- a/Src/Dlhis.Basic/appsettings.json +++ b/Src/Dlhis.Basic/appsettings.json @@ -25,7 +25,7 @@ "LogConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=log;charset=utf8mb4;", "Timeout": 30, "SlowSqlTime": 1, - "EnableSqlLog": false + "EnableSqlLog": true }, "SwaggerOptions": { "Enable": true, diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index b4556880..8de0e473 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -509,7 +509,7 @@ public class BalanceService : IBalanceService No = record.No, BusinessPlaceName = bplace.Name, BusinessShiftName = type.Display, - CostDateTime = record.CreateTime // todo + CostDateTime = record.CostDateTime }) .ToPageListAsync(request); @@ -774,7 +774,7 @@ public class BalanceService : IBalanceService var codeBreakfast = "Breakfast"; if (breakfast != null) { - codeBreakfast = breakfast.Code.ToString(); + codeBreakfast = breakfast.Code.ToString(); } //午餐 var lunch = shifts.Where(x => x.CustomCode == "shift-lunch").FirstOrDefault(); diff --git a/Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs b/Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs index d1462881..63631b17 100644 --- a/Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs @@ -143,15 +143,27 @@ public class GainfoEntity : SugarBaseEntity [SugarColumn(ColumnDescription = "人事范围")] public string Werks { get; set; } + /// + /// 工作地 + /// + [SugarColumn(ColumnDescription = "工作地")] + public string Workplace { get; set; } + + /// + /// 厂区 + /// + [SugarColumn(ColumnDescription = "厂区")] + public string Factory { get; set; } + /// /// 成本中心 /// public string CostId { get; set; } /// - /// 身份认证用户Id + /// 身份认证用户Id(如果为空匹配code) /// - [SugarColumn(ColumnDescription = "身份认证用户Id", IndexGroupNameList = new[] { "idx_Gainfo_IdentityUserId" })] + [SugarColumn(ColumnDescription = "身份认证用户Id", IsNullable = true)] public int IdentityUserId { get; set; } } diff --git a/Src/Dlhis.Entity/Sys/Entities/TenantEntity.cs b/Src/Dlhis.Entity/Sys/Entities/TenantEntity.cs index 5897f319..c67fa035 100644 --- a/Src/Dlhis.Entity/Sys/Entities/TenantEntity.cs +++ b/Src/Dlhis.Entity/Sys/Entities/TenantEntity.cs @@ -12,6 +12,11 @@ public class TenantEntity { public int Id { get; set; } + /// + /// 上级租户 + /// + public string PCode { get; set; } + /// /// 基地code /// diff --git a/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs b/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs index 0bdda3ff..830c8086 100644 --- a/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs +++ b/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs @@ -1,10 +1,14 @@ -using Dlhis.Entity.Basic.Entity; +using System.Collections.Generic; +using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Device.Entities; using Dlhis.Entity.Device.Enums; using Dlhis.Sys.Api; +using Dlhis.User.Api.Response; +using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Entity; using Kurisu.SqlSugar.Services; using Newtonsoft.Json; +using SqlSugar; namespace Dlhis.ScheduledTask.CommonJobs; @@ -14,7 +18,10 @@ public class CreateDefinitelyGroupJob private readonly ITenantApi _tenantApi; private readonly IDbContext _dbContext; - public CreateDefinitelyGroupJob(ILogger logger, ITenantApi tenantApi, IDbContext dbContext, ISqlSugarOptionsService sqlSugarOptionsService) + public CreateDefinitelyGroupJob(ILogger logger, + ITenantApi tenantApi, + IDbContext dbContext, + ISqlSugarOptionsService sqlSugarOptionsService) { _logger = logger; _tenantApi = tenantApi; @@ -28,136 +35,23 @@ public class CreateDefinitelyGroupJob _dbContext.Client.QueryFilter.ClearAndBackup(); 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().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); + await CreateGainfoGroupsAsync(tenants); + //*****************************************************考勤设备组*********************************************************/ - var groups = new[] { "*督查组", "*X3及以上领导组", "*外派人员组" }; - foreach (var group in groups) - { - var grp = new GainfoGroupEntity - { - PCode = null, - Code = Guid.NewGuid(), - Name = group, - IsDefault = false, - Editable = false, + await CreateDeviceGroupAsync(DeviceTypeEnumType.Attendance, new List { "*通用考勤设备组", "*专用考勤设备组" }, tenants); - CreatedBy = 1, - CreateTime = DateTime.Now, - ModifiedBy = 1, - ModifiedTime = DateTime.Now, - TenantId = tenant.Code - }; + //*****************************************************门禁设备组********************************************************/ - await _dbContext.InsertAsync(grp); - } - } - - //**************************************************************************************************************/ - - if (!await _dbContext.Queryable().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().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().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().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, - }); - } - } + await CreateDeviceGroupAsync(DeviceTypeEnumType.Door, new List { "*共用区域", "*非共用区域" }, tenants); } catch (Exception ex) { @@ -168,4 +62,103 @@ public class CreateDefinitelyGroupJob _dbContext.Client.QueryFilter.Restore(); } } + + private async Task CreateGainfoGroupsAsync(List tenants) + { + var grps = new List { "*自定义人员分组", "*督查组", "*X3及以上领导组" }; + var searchGrps = await _dbContext.Queryable().Where(x => grps.Contains(x.Name)).ToListAsync(); + foreach (var grp in grps) + { + if (!searchGrps.Any(x => x.Name == grp)) + { + await _dbContext.InsertAsync(new GainfoGroupEntity + { + PCode = null, + Code = Guid.NewGuid(), + Name = grp, + IsDefault = grp.Equals("*自定义人员分组"), + Editable = false, + + CreatedBy = 1, + CreateTime = DateTime.Now, + ModifiedBy = 1, + ModifiedTime = DateTime.Now, + TenantId = null + }); + } + } + } + + + private async Task CreateDeviceGroupAsync(DeviceTypeEnumType type, List topGroups, List tenants) + { + foreach (var grp in topGroups) + { + var topGrp = await _dbContext.Queryable().FirstAsync(x => x.Name == grp); + if (topGrp == null) + { + topGrp = new DeviceGroupEntity + { + PCode = null, + Code = Guid.NewGuid(), + Type = type, + Name = grp, + Editable = false, + + CreatedBy = 1, + CreateTime = DateTime.Now, + ModifiedBy = 1, + ModifiedTime = DateTime.Now, + TenantId = null, + }; + await _dbContext.InsertAsync(topGrp); + } + + foreach (var workplace in tenants.Where(x => x.PCode.IsEmpty())) + { + var workplaceName = $"*{type.GetDescription()}工作地系统组({workplace.Name})"; + var workplaceGrp = await _dbContext.Queryable().FirstAsync(x => x.Name == workplaceName); + if (workplaceGrp == null) + { + workplaceGrp = new DeviceGroupEntity + { + PCode = topGrp.Code, + Code = Guid.NewGuid(), + Type = type, + Name = workplaceName, + Editable = false, + + CreatedBy = 1, + CreateTime = DateTime.Now, + ModifiedBy = 1, + ModifiedTime = DateTime.Now, + TenantId = null, + }; + await _dbContext.InsertAsync(workplaceGrp); + } + + foreach (var factory in tenants.Where(x => x.PCode == workplace.Code)) + { + var factoryName = $"*{type.GetDescription()}厂区系统组({factory.Name})"; + if (!await _dbContext.Queryable().AnyAsync(x => x.Name == factoryName)) + { + await _dbContext.InsertAsync(new DeviceGroupEntity + { + PCode = workplaceGrp.Code, + Code = Guid.NewGuid(), + Type = type, + Name = factoryName, + Editable = false, + + CreatedBy = 1, + CreateTime = DateTime.Now, + ModifiedBy = 1, + ModifiedTime = DateTime.Now, + TenantId = factory.Code, + }); + } + } + } + } + } } diff --git a/Src/Dlhis.ScheduledTask/appsettings.Development.json b/Src/Dlhis.ScheduledTask/appsettings.Development.json index fbfb5dd0..8674e444 100644 --- a/Src/Dlhis.ScheduledTask/appsettings.Development.json +++ b/Src/Dlhis.ScheduledTask/appsettings.Development.json @@ -5,6 +5,9 @@ "Microsoft.AspNetCore": "Warning" } }, + "InternalRequest": { + "SysRequestUrl": "http://localhost:5003" + }, "FaceUrlOptions": { "Url": "http://localhost:5002/api/gainfos/face?token=", "Limit": 7200 diff --git a/Src/Dlhis.Sys.Api/Response/TenantResponse.cs b/Src/Dlhis.Sys.Api/Response/TenantResponse.cs index 1201754e..e20f2110 100644 --- a/Src/Dlhis.Sys.Api/Response/TenantResponse.cs +++ b/Src/Dlhis.Sys.Api/Response/TenantResponse.cs @@ -4,6 +4,8 @@ public class TenantResponse { public int Id { get; set; } + public string PCode { get; set; } + public string Code { get; set; } public string Name { get; set; } diff --git a/Src/Dlhis.Sys/Identity/Response/TenantResponse.cs b/Src/Dlhis.Sys/Identity/Response/TenantResponse.cs index 1949b745..b265def5 100644 --- a/Src/Dlhis.Sys/Identity/Response/TenantResponse.cs +++ b/Src/Dlhis.Sys/Identity/Response/TenantResponse.cs @@ -4,6 +4,8 @@ public class TenantResponse { public int Id { get; set; } + public string PCode { get; set; } + public string Code { get; set; } public string Name { get; set; }