fix 调整时段码结构

This commit is contained in:
2024-07-19 16:10:38 +08:00
parent c7c1bf1ec8
commit a48e34f999
25 changed files with 217 additions and 233 deletions

View File

@@ -19,17 +19,14 @@ public class DevicesController : ControllerBase
private readonly IDeviceService _deviceService; private readonly IDeviceService _deviceService;
private readonly IDeviceTemplateService _deviceTemplateService; private readonly IDeviceTemplateService _deviceTemplateService;
private readonly IDeviceConnectService _deviceConnectService; private readonly IDeviceConnectService _deviceConnectService;
private readonly IConfiguration _configuration;
public DevicesController(IDeviceService deviceService, public DevicesController(IDeviceService deviceService,
IDeviceTemplateService deviceTemplateService, IDeviceTemplateService deviceTemplateService,
IDeviceConnectService deviceConnectService, IDeviceConnectService deviceConnectService)
IConfiguration configuration)
{ {
_deviceService = deviceService; _deviceService = deviceService;
_deviceTemplateService = deviceTemplateService; _deviceTemplateService = deviceTemplateService;
_deviceConnectService = deviceConnectService; _deviceConnectService = deviceConnectService;
_configuration = configuration;
} }
/// <summary> /// <summary>
@@ -106,20 +103,6 @@ public class DevicesController : ControllerBase
await _deviceService.SaveAsync(request); await _deviceService.SaveAsync(request);
} }
/// <summary>
/// 获取激活码
/// </summary>
/// <returns></returns>
[HttpPost("resigter-code")]
public object GetRegisterCode()
{
return new
{
AppId = _configuration.GetSection("RegisterAppId").Value,
Key = _configuration.GetSection("RegisterCode").Value
};
}
/// <summary> /// <summary>
/// 获取尚未设置营业点的设备 /// 获取尚未设置营业点的设备
/// </summary> /// </summary>

View File

@@ -1,11 +0,0 @@
namespace Dlhis.Basic.Device.Dtos;
public class DeviceTimePeriodDto
{
public int CardType { get; set; }
public TimeOnly OnStart { get; set; }
public TimeOnly OnEnd { get; set; }
public TimeOnly OffStart { get; set; }
public TimeOnly OffEnd { get; set; }
}

View File

@@ -1,22 +1,23 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Dlhis.Entity.Device.Enums; using Dlhis.Entity.Device.Enums;
using Dlhis.Entity.Device.Models;
namespace Dlhis.Basic.Device.Request; namespace Dlhis.Basic.Device.Request;
public class DeviceTimePeriodSaveRequest : IValidatableObject public class DeviceTimePeriodSaveRequest
{ {
public long? Id { get; set; } public long? Id { get; set; }
/// <summary> /// <summary>
/// 卡类型 timeperiod /// 卡类型 timeperiod
/// </summary> /// </summary>
[Range(2, 3)] [Range(2, 3, ErrorMessage = "卡类型有误")]
public int CardType { get; set; } public int CardType { get; set; }
/// <summary> /// <summary>
/// 分配类型 DeviceTimePeriodAssignEnumType /// 分配类型 DeviceTimePeriodAssignEnumType
/// </summary> /// </summary>
[EnumDataType(typeof(DeviceTimePeriodAssignEnumType))] [EnumDataType(typeof(DeviceTimePeriodAssignEnumType), ErrorMessage = "时段分配类型有误")]
public DeviceTimePeriodAssignEnumType AssignType { get; set; } public DeviceTimePeriodAssignEnumType AssignType { get; set; }
/// <summary> /// <summary>
@@ -26,46 +27,9 @@ public class DeviceTimePeriodSaveRequest : IValidatableObject
public Guid Value { get; set; } public Guid Value { get; set; }
/// <summary> /// <summary>
/// 上班开始 /// 星期配置
/// </summary> /// </summary>
[Required] [MinLength(7, ErrorMessage = "配置有误")]
public TimeOnly OnStart { get; set; } [MaxLength(7, ErrorMessage = "配置有误")]
public List<DeviceWeekDayTimePeriod> Sections { get; set; }
/// <summary>
/// 上班结束
/// </summary>
[Required]
public TimeOnly OnEnd { get; set; }
/// <summary>
/// 下班开始
/// </summary>
[Required]
public TimeOnly OffStart { get; set; }
/// <summary>
/// 下班结束
/// </summary>
[Required]
public TimeOnly OffEnd { get; set; }
/// <inheritdoc />
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (OnStart >= OnEnd)
{
yield return new ValidationResult("上班时段范围有误", new[] { nameof(OnStart) });
}
if (OffStart >= OffEnd)
{
yield return new ValidationResult("下班时段范围有误", new[] { nameof(OffStart) });
}
if (OnEnd >= OffStart)
{
yield return new ValidationResult("上下班时段范围有误", new[] { nameof(OnEnd) });
}
}
} }

View File

@@ -1,16 +1,25 @@
using Dlhis.Entity.Device.Enums; using Dlhis.Entity.Device.Enums;
using Dlhis.Entity.Device.Models;
namespace Dlhis.Basic.Device.Response; namespace Dlhis.Basic.Device.Response;
public class DeviceTimePeriodResponse public class DeviceTimePeriodResponse
{ {
public long Id { get; set; } /// <summary>
/// 名称
/// </summary>
public string Name { get; set; }
/// <summary> /// <summary>
/// 卡类型 /// 卡类型
/// </summary> /// </summary>
public int CardType { get; set; } public int CardType { get; set; }
/// <summary>
/// 卡类型描述
/// </summary>
public string CardTypeDesc { get; set; }
/// <summary> /// <summary>
/// 分配类型 /// 分配类型
/// </summary> /// </summary>
@@ -22,27 +31,7 @@ public class DeviceTimePeriodResponse
public Guid Value { get; set; } public Guid Value { get; set; }
/// <summary> /// <summary>
/// 名称 /// 时段信息
/// </summary> /// </summary>
public string Name { get; set; } public List<DeviceWeekDayTimePeriod> Sections { get; set; }
/// <summary>
/// 上班开始
/// </summary>
public TimeOnly OnStart { get; set; }
/// <summary>
/// 上班结束
/// </summary>
public TimeOnly OnEnd { get; set; }
/// <summary>
/// 下班开始
/// </summary>
public TimeOnly OffStart { get; set; }
/// <summary>
/// 下班结束
/// </summary>
public TimeOnly OffEnd { get; set; }
} }

View File

@@ -1,4 +1,3 @@
using Dlhis.Basic.Device.Dtos;
using Dlhis.Basic.Device.Request; using Dlhis.Basic.Device.Request;
using Dlhis.Basic.Device.Response; using Dlhis.Basic.Device.Response;
using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Basic.Entity;
@@ -25,17 +24,24 @@ public class DeviceTimePeriodService : IDeviceTimePeriodService
/// <inheritdoc /> /// <inheritdoc />
public async Task<Pagination<DeviceTimePeriodResponse>> GetPageAsync(DeviceTimePeriodPageRequest request) public async Task<Pagination<DeviceTimePeriodResponse>> GetPageAsync(DeviceTimePeriodPageRequest request)
{ {
var page = await _dbContext.Queryable<DeviceTimePeriodEntity>() var pageOri = await _dbContext.Queryable<DeviceTimePeriodEntity>()
.Where(x => x.AssignType == request.AssignType) .Where(x => x.AssignType == request.AssignType)
.Select<DeviceTimePeriodResponse>()
.ToPageListAsync(request); .ToPageListAsync(request);
var page = pageOri.Adapt<Pagination<DeviceTimePeriodResponse>>();
var values = page.Data.Select(x => x.Value); var values = page.Data.Select(x => x.Value);
var data = request.AssignType == DeviceTimePeriodAssignEnumType.Device var data = request.AssignType == DeviceTimePeriodAssignEnumType.Device
? await _dbContext.Queryable<DeviceEntity>().Where(x => values.Contains(x.Code)).Select(x => new { x.Code, Name = x.DeployPlace }).ToListAsync() ? await _dbContext.Queryable<DeviceEntity>().Where(x => values.Contains(x.Code)).Select(x => new { x.Code, Name = x.DeployPlace }).ToListAsync()
: await _dbContext.Queryable<DeviceTemplateEntity>().Where(x => values.Contains(x.Code)).Select(x => new { x.Code, x.Name }).ToListAsync(); : await _dbContext.Queryable<DeviceTemplateEntity>().Where(x => values.Contains(x.Code)).Select(x => new { x.Code, x.Name }).ToListAsync();
page.Data.ForEach(item => { item.Name = data.FirstOrDefault(x => x.Code == item.Value)?.Name; }); var basicTypes = await _dbContext.Queryable<BasicTypeEntity>().Where(x => x.Type == "timeperiod").ToListAsync();
page.Data.ForEach(item =>
{
item.Name = data.FirstOrDefault(x => x.Code == item.Value)?.Name;
item.CardTypeDesc = basicTypes.FirstOrDefault(x => x.Code == item.CardType.ToString())?.Display;
});
return page; return page;
} }
@@ -49,8 +55,7 @@ public class DeviceTimePeriodService : IDeviceTimePeriodService
var existsData = request.AssignType == DeviceTimePeriodAssignEnumType.Device var existsData = request.AssignType == DeviceTimePeriodAssignEnumType.Device
? await _dbContext.Queryable<DeviceEntity>().Where(x => x.Code == request.Value).AnyAsync() ? await _dbContext.Queryable<DeviceEntity>().Where(x => x.Code == request.Value).AnyAsync()
: await _dbContext.Queryable<DeviceTemplateEntity>().Where(x => x.Code == request.Value).AnyAsync(); : await _dbContext.Queryable<DeviceTemplateEntity>().Where(x => x.Code == request.Value).AnyAsync();
existsData.ThrowIfFalse("数据不匹配"); existsData.ThrowIfFalse("数据不匹配分配类型");
(await _dbContext.Queryable<DeviceTimePeriodEntity>() (await _dbContext.Queryable<DeviceTimePeriodEntity>()
.Where(x => x.CardType == request.CardType) .Where(x => x.CardType == request.CardType)
@@ -103,10 +108,10 @@ public class DeviceTimePeriodService : IDeviceTimePeriodService
var deviceUniqueNo = device.UniqueNo; var deviceUniqueNo = device.UniqueNo;
before.TryGetValue(deviceUniqueNo, out var beforeDtos); before.TryGetValue(deviceUniqueNo, out var beforeDtos);
beforeDtos ??= new List<DeviceTimePeriodDto>(0); beforeDtos ??= new List<DeviceTimePeriodEntity>(0);
current.TryGetValue(deviceUniqueNo, out var currentDtos); current.TryGetValue(deviceUniqueNo, out var currentDtos);
currentDtos ??= new List<DeviceTimePeriodDto>(0); currentDtos ??= new List<DeviceTimePeriodEntity>(0);
if (beforeDtos.Count != currentDtos.Count) if (beforeDtos.Count != currentDtos.Count)
{ {
@@ -138,7 +143,7 @@ public class DeviceTimePeriodService : IDeviceTimePeriodService
var c = currentDtos.First(x => x.CardType == cardType); var c = currentDtos.First(x => x.CardType == cardType);
if (b.OnStart != c.OnStart || b.OnEnd != c.OnEnd || b.OffStart != c.OffStart || b.OffEnd != c.OffEnd) if (b.ToJson() != c.ToJson())
{ {
tasks.Add(new DeviceTaskEntity tasks.Add(new DeviceTaskEntity
{ {
@@ -161,7 +166,7 @@ public class DeviceTimePeriodService : IDeviceTimePeriodService
await _dbContext.InsertAsync(tasks); await _dbContext.InsertAsync(tasks);
} }
private async Task<Dictionary<string, List<DeviceTimePeriodDto>>> GetSettingsAsync() private async Task<Dictionary<string, List<DeviceTimePeriodEntity>>> GetSettingsAsync()
{ {
var timePeriods = await _dbContext.Queryable<DeviceTimePeriodEntity>().ToListAsync(); var timePeriods = await _dbContext.Queryable<DeviceTimePeriodEntity>().ToListAsync();
@@ -178,11 +183,11 @@ public class DeviceTimePeriodService : IDeviceTimePeriodService
{ {
var tSettings = timePeriods var tSettings = timePeriods
.Where(item => item.AssignType == DeviceTimePeriodAssignEnumType.Template && item.Value == x.TemplateCode) .Where(item => item.AssignType == DeviceTimePeriodAssignEnumType.Template && item.Value == x.TemplateCode)
.Adapt<List<DeviceTimePeriodDto>>(); .ToList();
var dSettings = timePeriods var dSettings = timePeriods
.Where(item => item.AssignType == DeviceTimePeriodAssignEnumType.Device && item.Value == x.Code) .Where(item => item.AssignType == DeviceTimePeriodAssignEnumType.Device && item.Value == x.Code)
.Adapt<List<DeviceTimePeriodDto>>(); .ToList();
foreach (var setting in dSettings) foreach (var setting in dSettings)
{ {

View File

@@ -262,6 +262,10 @@ public class GainfoFaceService : IGainfoFaceService
Face = request.Face Face = request.Face
}; };
face.CreatedBy = _currentUser.GetIntSubjectId();
face.CreateTime = DateTime.Now;
face.ModifiedBy = _currentUser.GetIntSubjectId();
face.ModifiedTime = DateTime.Now;
await _faceDbContext.InsertAsync(face); await _faceDbContext.InsertAsync(face);
} }
else else
@@ -271,7 +275,9 @@ public class GainfoFaceService : IGainfoFaceService
_logger.LogWarning("相同的人脸照片更新忽略"); _logger.LogWarning("相同的人脸照片更新忽略");
return; return;
} }
face.ModifiedBy = _currentUser.GetIntSubjectId();
face.ModifiedTime = DateTime.Now;
face.Face = request.Face; face.Face = request.Face;
await _faceDbContext.UpdateAsync(face); await _faceDbContext.UpdateAsync(face);
} }

View File

@@ -7,7 +7,7 @@
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
}, },
"dotnetRunMessages": true, "dotnetRunMessages": true,
"applicationUrl": "http://localhost:5002" "applicationUrl": "http://*:5002"
}, },
"Docker": { "Docker": {
"commandName": "Docker", "commandName": "Docker",

View File

@@ -195,7 +195,7 @@ public class GainfoEntity : SugarBaseEntity
[SugarColumn(ColumnDescription = "卡类型", IsNullable = true)] [SugarColumn(ColumnDescription = "卡类型", IsNullable = true)]
public string CardType { get; set; } public int? CardType { get; set; }
} }
/// <summary> /// <summary>

View File

@@ -1,4 +1,5 @@
using Dlhis.Entity.Device.Enums; using Dlhis.Entity.Device.Enums;
using Dlhis.Entity.Device.Models;
using Kurisu.AspNetCore.DataAccess.Entity; using Kurisu.AspNetCore.DataAccess.Entity;
using Kurisu.AspNetCore.DataAccess.SqlSugar; using Kurisu.AspNetCore.DataAccess.SqlSugar;
using Mapster; using Mapster;
@@ -40,28 +41,10 @@ public class DeviceTimePeriodEntity : SugarBaseEntity, ITenantId
public Guid Value { get; set; } public Guid Value { get; set; }
/// <summary> /// <summary>
/// 上班开始 /// 时段信息
/// </summary> /// </summary>
[SugarColumn(IsNullable = false, ColumnDescription = "上班开始")] [SugarColumn(IsJson = true, ColumnDataType = "varchar(1000)")]
public TimeOnly OnStart { get; set; } public List<DeviceWeekDayTimePeriod> Sections { get; set; }
/// <summary>
/// 上班结束
/// </summary>
[SugarColumn(IsNullable = false, ColumnDescription = "上班结束")]
public TimeOnly OnEnd { get; set; }
/// <summary>
/// 下班开始
/// </summary>
[SugarColumn(IsNullable = false, ColumnDescription = "下班开始")]
public TimeOnly OffStart { get; set; }
/// <summary>
/// 下班结束
/// </summary>
[SugarColumn(IsNullable = false, ColumnDescription = "下班结束")]
public TimeOnly OffEnd { get; set; }
[SugarColumn(IsNullable = false, UniqueGroupNameList = new[] { "unique_DeviceTimePeriod_cardType_assignType_value" })] [SugarColumn(IsNullable = false, UniqueGroupNameList = new[] { "unique_DeviceTimePeriod_cardType_assignType_value" })]

View File

@@ -42,6 +42,12 @@ public class DeviceUploadLogEntity : SugarBaseEntity, ITenantId
[SugarColumn(ColumnDataType = "bit")] [SugarColumn(ColumnDataType = "bit")]
public bool Sync { get; set; } public bool Sync { get; set; }
/// <summary>
/// 是否有效
/// </summary>
[SugarColumn(ColumnDataType = "bit")]
public bool Status { get; set; }
[SugarColumn(IndexGroupNameList = new string[] { "idx_DeviceUploadLog_TenantId" })] [SugarColumn(IndexGroupNameList = new string[] { "idx_DeviceUploadLog_TenantId" })]
public string TenantId { get; set; } public string TenantId { get; set; }

View File

@@ -0,0 +1,8 @@
using Kurisu.AspNetCore.CustomClass;
namespace Dlhis.Entity.Device.Models;
public class DeviceTimePeriod : TimePeriod
{
public bool Enable { get; set; }
}

View File

@@ -0,0 +1,14 @@
namespace Dlhis.Entity.Device.Models;
public class DeviceWeekDayTimePeriod
{
/// <summary>
/// 星期
/// </summary>
public DayOfWeek DayOfWeek { get; set; }
/// <summary>
/// 时段
/// </summary>
public List<DeviceTimePeriod> TimePeriods { get; set; }
}

View File

@@ -266,7 +266,7 @@ public class GainfoUpdateService : IGainfoUpdateService
CostId = item.KOSTL, CostId = item.KOSTL,
EntryDate = item.createdate, EntryDate = item.createdate,
ResignationDate = item.ZLZRQ, ResignationDate = item.ZLZRQ,
CardType = item.ZZ_KLX, CardType = Convert.ToInt32(item.ZZ_KLX),
Workplace = _tenants.FirstOrDefault(x => x.Name == item.ZZ_GZDJDNM)?.Code ?? item.ZZ_GZDJDNM, Workplace = _tenants.FirstOrDefault(x => x.Name == item.ZZ_GZDJDNM)?.Code ?? item.ZZ_GZDJDNM,
Factory = _tenants.FirstOrDefault(x => x.Name == item.ZZ_GZDCQNM)?.Code ?? item.ZZ_GZDCQNM, Factory = _tenants.FirstOrDefault(x => x.Name == item.ZZ_GZDCQNM)?.Code ?? item.ZZ_GZDCQNM,
}; };
@@ -326,7 +326,7 @@ public class GainfoUpdateService : IGainfoUpdateService
ResignationDate = item.ZLZRQ, ResignationDate = item.ZLZRQ,
Workplace = workplace, Workplace = workplace,
Factory = factory, Factory = factory,
CardType = item.ZZ_KLX CardType = Convert.ToInt32(item.ZZ_KLX)
}).Where(x => x.Code == item.ename).ExecuteCommandAsync(); }).Where(x => x.Code == item.ename).ExecuteCommandAsync();
await _identityUserSyncService.SyncAccountAsync(gainfo.Code, gainfo.Name, gainfo.IdNo, factory); await _identityUserSyncService.SyncAccountAsync(gainfo.Code, gainfo.Name, gainfo.IdNo, factory);
} }

View File

@@ -24,11 +24,6 @@ public class DeviceUploadLogUploadRequest
/// 记录序号 /// 记录序号
/// </summary> /// </summary>
public string SerialNo { get; set; } public string SerialNo { get; set; }
public bool Status { get; set; }
// /// <summary>
// /// 记录类型
// /// </summary>
// [EnumDataType(typeof(DeviceUploadLogTypeEnumType))]
// public DeviceUploadLogTypeEnumType Type { get; set; } = DeviceUploadLogTypeEnumType.Attendance;
} }

View File

@@ -55,5 +55,13 @@ public class DeviceUploadLogResponse
[JsonIgnore] [JsonIgnore]
public string OriginUserUniqueNo { get; set; } public string OriginUserUniqueNo { get; set; }
/// <summary>
/// 是否同步sap
/// </summary>
public bool Sync { get; set; } public bool Sync { get; set; }
/// <summary>
/// 是否有效
/// </summary>
public bool Status { get; set; }
} }

View File

@@ -32,6 +32,7 @@ public class DeviceUploadLogService : IDeviceUploadLogService
return await _dbContext.Queryable<DeviceUploadLogEntity>() return await _dbContext.Queryable<DeviceUploadLogEntity>()
.LeftJoin<DeviceEntity>((log, d) => log.DeviceUniqueNo == d.UniqueNo) .LeftJoin<DeviceEntity>((log, d) => log.DeviceUniqueNo == d.UniqueNo)
.Where(log => log.UserUniqueNo == jinkoCode) .Where(log => log.UserUniqueNo == jinkoCode)
.Where(log => log.Status)
.WhereIF(request.DateTimePeriod.HasValue(), log => log.RaiseDateTime >= request.DateTimePeriod.Start && log.RaiseDateTime <= request.DateTimePeriod.End) .WhereIF(request.DateTimePeriod.HasValue(), log => log.RaiseDateTime >= request.DateTimePeriod.Start && log.RaiseDateTime <= request.DateTimePeriod.End)
.Where((log, d) => d.Type == DeviceTypeEnumType.Attendance || (d.Type == DeviceTypeEnumType.Door && d.AsAttendance)) .Where((log, d) => d.Type == DeviceTypeEnumType.Attendance || (d.Type == DeviceTypeEnumType.Door && d.AsAttendance))
.OrderBy(log => log.RaiseDateTime) .OrderBy(log => log.RaiseDateTime)
@@ -46,6 +47,7 @@ public class DeviceUploadLogService : IDeviceUploadLogService
SerialNo = log.SerialNo, SerialNo = log.SerialNo,
DeployPlace = d.DeployPlace, DeployPlace = d.DeployPlace,
Sync = log.Sync, Sync = log.Sync,
Status = log.Status
}) })
.ToListAsync(); .ToListAsync();
} }
@@ -88,6 +90,7 @@ public class DeviceUploadLogService : IDeviceUploadLogService
UserName = ga.Name, UserName = ga.Name,
DeployPlace = device.DeployPlace, DeployPlace = device.DeployPlace,
Sync = deviceUp.Sync, Sync = deviceUp.Sync,
Status = deviceUp.Status,
}) })
.ToPageListAsync(request); .ToPageListAsync(request);
} }
@@ -122,7 +125,8 @@ public class DeviceUploadLogService : IDeviceUploadLogService
? DeviceUploadLogTypeEnumType.Attendance ? DeviceUploadLogTypeEnumType.Attendance
: DeviceUploadLogTypeEnumType.Door, : DeviceUploadLogTypeEnumType.Door,
TenantId = device.TenantId TenantId = device.TenantId,
Status = request.Status
}); });
} }

View File

@@ -36,6 +36,7 @@ public class SyncOriginCardInfoJob : BaseJob
.Where(x => deviceUniqueNos.Contains(x.DeviceUniqueNo)) .Where(x => deviceUniqueNos.Contains(x.DeviceUniqueNo))
.Where(x => !string.IsNullOrEmpty(x.UserUniqueNo)) .Where(x => !string.IsNullOrEmpty(x.UserUniqueNo))
.Where(x => x.Sync == false) .Where(x => x.Sync == false)
.Where(x => x.Status)
.Where(x => SqlFunc.Subqueryable<OutsourceEntity>().Where(p => p.Code == x.UserUniqueNo).NotAny()) .Where(x => SqlFunc.Subqueryable<OutsourceEntity>().Where(p => p.Code == x.UserUniqueNo).NotAny())
.Select((x, device) => new UploadAttendanceRequest .Select((x, device) => new UploadAttendanceRequest
{ {

View File

@@ -1,3 +1,4 @@
using Dlhis.ScheduledTask.Common.Services;
using Kurisu.AspNetCore.Startup; using Kurisu.AspNetCore.Startup;
using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.AspNetCore.Utils.Extensions;
@@ -24,5 +25,8 @@ public class Startup : DefaultStartup
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env) public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{ {
base.Configure(app, env); base.Configure(app, env);
var token = app.ApplicationServices.GetService<IJinkoJIPService>().IssueToken();
} }
} }

View File

@@ -5,7 +5,7 @@
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
}, },
"applicationUrl": "http://localhost:5010" "applicationUrl": "http://*:5010"
} }
} }
} }

View File

@@ -55,16 +55,4 @@ public class AssignmentsController : ControllerBase
{ {
await _assignmentService.UpdateDeviceTaskStatusAsync(requests); await _assignmentService.UpdateDeviceTaskStatusAsync(requests);
} }
/// <summary>
/// 获取新人脸照片
/// </summary>
/// <param name="taskId"></param>
/// <returns></returns>
[HttpGet("renewfaceurl")]
[IgnoreTenant]
public async Task<string> RenewFaceUrlAsync(long taskId)
{
return await _assignmentService.RenewFaceUrlAsync(taskId);
}
} }

View File

@@ -1,4 +1,5 @@
using Dlhis.Entity.Device.Enums; using Dlhis.Entity.Device.Entities;
using Dlhis.Entity.Device.Enums;
namespace Dlhis.ScheduledTask.TaskAssignment.Dto; namespace Dlhis.ScheduledTask.TaskAssignment.Dto;
@@ -23,5 +24,17 @@ public class TaskDto
public int Version { get; set; } public int Version { get; set; }
/// <summary>
/// 是否启用时段码
/// </summary>
public bool EnableTimePeriod { get; set; }
/// <summary>
/// 卡类型
/// </summary>
public int CardType { get; set; }
public DeviceTaskStatusEnumType Status { get; set; } public DeviceTaskStatusEnumType Status { get; set; }
}
public List<DeviceTimePeriodEntity> TimePeriods { get; set; }
}

View File

@@ -1,4 +1,4 @@
using Kurisu.AspNetCore.CustomClass; using Dlhis.Entity.Device.Models;
namespace Dlhis.ScheduledTask.TaskAssignment.Response; namespace Dlhis.ScheduledTask.TaskAssignment.Response;
@@ -12,5 +12,5 @@ public class TimePeriodWeekDaySection
/// <summary> /// <summary>
/// 时段区间 最多4个 /// 时段区间 最多4个
/// </summary> /// </summary>
public List<TimePeriod> TimePeriods { get; set; } public List<DeviceTimePeriod> TimePeriods { get; set; }
} }

View File

@@ -19,11 +19,4 @@ public interface IAssignmentService : IScopeDependency
/// <param name="requests"></param> /// <param name="requests"></param>
/// <returns></returns> /// <returns></returns>
Task UpdateDeviceTaskStatusAsync(List<UpdateDeviceTaskStatusRequest> requests); Task UpdateDeviceTaskStatusAsync(List<UpdateDeviceTaskStatusRequest> requests);
/// <summary>
/// 获取新人脸照片
/// </summary>
/// <param name="taskId"></param>
/// <returns></returns>
Task<string> RenewFaceUrlAsync(long taskId);
} }

View File

@@ -1,6 +1,7 @@
using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Device.Entities; using Dlhis.Entity.Device.Entities;
using Dlhis.Entity.Device.Enums; using Dlhis.Entity.Device.Enums;
using Dlhis.Entity.Device.Models;
using Dlhis.ScheduledTask.TaskAssignment.Request; using Dlhis.ScheduledTask.TaskAssignment.Request;
using Dlhis.ScheduledTask.TaskAssignment.Response; using Dlhis.ScheduledTask.TaskAssignment.Response;
using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.AspNetCore.Utils.Extensions;
@@ -8,12 +9,12 @@ using Microsoft.AspNetCore.DataProtection;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using SqlSugar; using SqlSugar;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Kurisu.AspNetCore;
using Kurisu.AspNetCore.Utils; using Kurisu.AspNetCore.Utils;
using Dlhis.ScheduledTask.TaskAssignment.Dto; using Dlhis.ScheduledTask.TaskAssignment.Dto;
using Kurisu.AspNetCore.CustomClass; using Kurisu.AspNetCore.CustomClass;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions; using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
using Mapster;
namespace Dlhis.ScheduledTask.TaskAssignment.Services.Implements; namespace Dlhis.ScheduledTask.TaskAssignment.Services.Implements;
@@ -37,6 +38,8 @@ public class AssignmentService : IAssignmentService
var data = await GetDataAsync(request); var data = await GetDataAsync(request);
if (data.IsEmpty()) return new List<DeviceTaskToDeviceByDeviceResponse>(); if (data.IsEmpty()) return new List<DeviceTaskToDeviceByDeviceResponse>();
await HandlerOldDeviceGainfoAsync(data);
await HandlerTimePeriodAsync(data);
var deviceUploadInfos = await GetDeviceUploadRecordInfosAsync(data); var deviceUploadInfos = await GetDeviceUploadRecordInfosAsync(data);
var timeLimitedDataProtector = _dataProtectionProvider var timeLimitedDataProtector = _dataProtectionProvider
@@ -90,14 +93,14 @@ public class AssignmentService : IAssignmentService
UserName = item.UserName, UserName = item.UserName,
DepartmentNo = item.DepartmentNo, DepartmentNo = item.DepartmentNo,
DepartmentName = item.DepartmentName, DepartmentName = item.DepartmentName,
CardNo = item.Type == DeviceTaskEnumType.Delete ? string.Empty : item.CardNo, CardNo = item.CardNo,
Face = item.Type == DeviceTaskEnumType.Delete ? string.Empty : _faceUrlOptions.Url + token, //下发才附带照片信息 Face = item.Type == DeviceTaskEnumType.Delete ? string.Empty : _faceUrlOptions.Url + token, //下发才附带照片信息
ValidDatePeriod = new DatePeriod ValidDatePeriod = new DatePeriod
{ {
Start = DateOnly.FromDateTime(DateTime.Now.AddDays(-1)), Start = DateOnly.FromDateTime(DateTime.Now.AddDays(-1)),
End = DateOnly.FromDateTime(DateTime.Now.AddYears(20)), End = DateOnly.FromDateTime(DateTime.Now.AddYears(20)),
}, },
TimePeriods = new List<int> { 1 }, TimePeriods = new List<int> { item.CardType },
Doors = new List<int> { 1 }, Doors = new List<int> { 1 },
Schedule = 1 Schedule = 1
}; };
@@ -106,27 +109,22 @@ public class AssignmentService : IAssignmentService
case DeviceTaskEnumType.TimePeriodAdd: case DeviceTaskEnumType.TimePeriodAdd:
case DeviceTaskEnumType.TimePeriodDelete: case DeviceTaskEnumType.TimePeriodDelete:
{ {
dto.Info = new TimePeriodToDeviceResponse dto.Info = item.TimePeriods.Select(t => new TimePeriodToDeviceResponse
{ {
Id = 1, Id = t.CardType,
Name = "小白领", Name = t.CardType == 2 ? "行政卡" : "车间卡",
Enable = true, Enable = true,
Sections = new List<TimePeriodWeekDaySection> Sections = t.Sections.Select(s => new TimePeriodWeekDaySection
{ {
new() DayOfWeek = s.DayOfWeek,
TimePeriods = s.TimePeriods.Select(p => new DeviceTimePeriod
{ {
DayOfWeek = DayOfWeek.Monday, Enable = p.Enable,
TimePeriods = new List<TimePeriod> Start = p.Enable ? p.Start : new TimeOnly(00, 00, 00),
{ End = p.Enable ? p.End : new TimeOnly(00, 00, 00),
new() }).ToList()
{ }).ToList()
Start = TimeOnly.Parse("08:00:00"), });
End = TimeOnly.Parse("17:30:00")
}
}
}
}
};
} }
break; break;
case DeviceTaskEnumType.ScheduleAdd: case DeviceTaskEnumType.ScheduleAdd:
@@ -173,33 +171,6 @@ public class AssignmentService : IAssignmentService
}).ToList(); }).ToList();
} }
/// <summary>
/// 获取新token
/// </summary>
/// <param name="taskId"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public async Task<string> RenewFaceUrlAsync(long taskId)
{
var task = await _dbContext.Queryable<DeviceTaskEntity>().Where(x => x.Id == taskId).FirstAsync();
task.ThrowIfNull("该任务不存在");
(task.Status != DeviceTaskStatusEnumType.Process).ThrowIfTrue($"设备任务下发状态需为{DeviceTaskStatusEnumType.Process.GetDescription()}");
var faceUrlOptions = App.GetServiceProvider(true).GetService<IOptions<FaceUrlOptions>>().Value;
var dataProtectionProvider = App.GetServiceProvider(true).GetService<IDataProtectionProvider>();
var timeLimitedDataProtector = dataProtectionProvider
.CreateProtector("down:face")
.ToTimeLimitedDataProtector();
var userCode = await _dbContext.Queryable<GainfoEntity>().Where(x => x.No == task.UserNo).Select(x => x.Code).SingleAsync();
var key = $"face:{userCode}";
var token = timeLimitedDataProtector.Protect(key, TimeSpan.FromSeconds(faceUrlOptions.Limit));
return faceUrlOptions.Url + token;
}
public async Task UpdateDeviceTaskStatusAsync(List<UpdateDeviceTaskStatusRequest> requests) public async Task UpdateDeviceTaskStatusAsync(List<UpdateDeviceTaskStatusRequest> requests)
{ {
@@ -290,8 +261,12 @@ public class AssignmentService : IAssignmentService
.WhereIF(factories.Any(), (deviceTask, device) => factories.Contains(deviceTask.TenantId)) .WhereIF(factories.Any(), (deviceTask, device) => factories.Contains(deviceTask.TenantId))
.WhereIF(request.Types.IsPresent(), deviceTask => request.Types.Contains(deviceTask.Type)) .WhereIF(request.Types.IsPresent(), deviceTask => request.Types.Contains(deviceTask.Type))
.WhereIF(request.Brand.IsPresent(), (deviceTask, device, deviceTemplate) => deviceTemplate.Brand == request.Brand) .WhereIF(request.Brand.IsPresent(), (deviceTask, device, deviceTemplate) => deviceTemplate.Brand == request.Brand)
.Where((deviceTask, device, deviceTemplate, ga, gaLeave, department, gainfoEx, deviceRegistry) =>
#if !DEBUG
.Where((deviceTask, device, deviceTemplate, ga, gaLeave, department, gainfoEx, deviceRegistry) =>
device.HeartbeatInterval == 0 || SqlFunc.DateAdd(deviceRegistry.LastHeartbeatTime, device.HeartbeatInterval, DateType.Second) > DateTime.Now) device.HeartbeatInterval == 0 || SqlFunc.DateAdd(deviceRegistry.LastHeartbeatTime, device.HeartbeatInterval, DateType.Second) > DateTime.Now)
#endif
.OrderBy(deviceTask => new { Priority = SqlFunc.Desc(deviceTask.Priority), deviceTask.CreateTime }) .OrderBy(deviceTask => new { Priority = SqlFunc.Desc(deviceTask.Priority), deviceTask.CreateTime })
.Select((deviceTask, device, deviceTemplate, ga, gaLeave, department, gainfoEx) => new TaskDto .Select((deviceTask, device, deviceTemplate, ga, gaLeave, department, gainfoEx) => new TaskDto
{ {
@@ -313,7 +288,13 @@ public class AssignmentService : IAssignmentService
DepartmentName = department.Name, DepartmentName = department.Name,
CardNo = ga.CardNo, CardNo = ga.CardNo,
Version = deviceTask.Version, Version = deviceTask.Version,
Status = deviceTask.Status Status = deviceTask.Status,
EnableTimePeriod = device.EnableTimePeriod,
CardType = device.EnableTimePeriod
? SqlFunc.IsNullOrEmpty(ga.CardType)
? 1
: SqlFunc.ToInt32(ga.CardType)
: 1
}) })
.ToPageListAsync(request); .ToPageListAsync(request);
@@ -338,28 +319,17 @@ public class AssignmentService : IAssignmentService
throw new VersionExceptions("version exceptions"); throw new VersionExceptions("version exceptions");
} }
if (await _dbContext.Queryable<OldDeviceGainfoEntity>().Where(x => x.Status != OldDeviceGainfoEnumType.Deleted).AnyAsync())
{
var oldDeviceGainfoWhere = LinqExpressionExtensions.False<OldDeviceGainfoEntity>();
page.Data.ForEach(item => { oldDeviceGainfoWhere = oldDeviceGainfoWhere.Or(x => x.Code == item.UserCode && x.DeviceUniqueNo == item.DeviceUniqueNo); });
var oldData = await _dbContext.Queryable<OldDeviceGainfoEntity>().Where(x => x.Status == OldDeviceGainfoEnumType.Wait || x.Status == OldDeviceGainfoEnumType.Error)
.Where(oldDeviceGainfoWhere)
.ToListAsync();
page.Data.ForEach(item =>
{
var o = oldData.FirstOrDefault(x => x.Code == item.UserCode && x.DeviceUniqueNo == item.DeviceUniqueNo);
if (o != null)
item.OldUserNo = o.No;
});
}
return page.Data; return page.Data;
}, 5); }, 5);
return data; return data;
} }
/// <summary>
/// 处理获取上传记录的任务
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
private async Task<Dictionary<string, DateTime?>> GetDeviceUploadRecordInfosAsync(List<TaskDto> data) private async Task<Dictionary<string, DateTime?>> GetDeviceUploadRecordInfosAsync(List<TaskDto> data)
{ {
if (data.All(x => x.Type != DeviceTaskEnumType.UploadRecord)) if (data.All(x => x.Type != DeviceTaskEnumType.UploadRecord))
@@ -383,4 +353,65 @@ public class AssignmentService : IAssignmentService
return result; return result;
} }
/// <summary>
/// 处理老档案数据
/// </summary>
/// <param name="data"></param>
private async Task HandlerOldDeviceGainfoAsync(List<TaskDto> data)
{
if (await _dbContext.Queryable<OldDeviceGainfoEntity>().Where(x => x.Status != OldDeviceGainfoEnumType.Deleted).AnyAsync())
{
var oldDeviceGainfoWhere = LinqExpressionExtensions.False<OldDeviceGainfoEntity>();
data.ForEach(item => { oldDeviceGainfoWhere = oldDeviceGainfoWhere.Or(x => x.Code == item.UserCode && x.DeviceUniqueNo == item.DeviceUniqueNo); });
var oldData = await _dbContext.Queryable<OldDeviceGainfoEntity>().Where(x => x.Status == OldDeviceGainfoEnumType.Wait || x.Status == OldDeviceGainfoEnumType.Error)
.Where(oldDeviceGainfoWhere)
.ToListAsync();
data.ForEach(item =>
{
var o = oldData.FirstOrDefault(x => x.Code == item.UserCode && x.DeviceUniqueNo == item.DeviceUniqueNo);
if (o != null)
item.OldUserNo = o.No;
});
}
}
private async Task HandlerTimePeriodAsync(List<TaskDto> data)
{
var tasks = data.Where(x => x.EnableTimePeriod).Where(x => x.Type is DeviceTaskEnumType.TimePeriodAdd or DeviceTaskEnumType.TimePeriodDelete).ToList();
var deviceUniqueNos = tasks.Select(x => x.DeviceUniqueNo).ToList();
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => deviceUniqueNos.Contains(x.UniqueNo)).ToListAsync();
var templateCodes = devices.Select(x => x.TemplateCode).Distinct().ToList();
var deviceCodes = devices.Select(x => x.Code).Distinct().ToList();
var settings = await _dbContext.Queryable<DeviceTimePeriodEntity>()
.Where(x => (x.AssignType == DeviceTimePeriodAssignEnumType.Template && templateCodes.Contains(x.Value))
|| (x.AssignType == DeviceTimePeriodAssignEnumType.Device && deviceCodes.Contains(x.Value)))
.ToListAsync();
data.ForEach(item =>
{
var templateCode = devices.FirstOrDefault(x => x.UniqueNo == item.DeviceUniqueNo)?.TemplateCode;
var code = devices.FirstOrDefault(x => x.UniqueNo == item.DeviceUniqueNo)?.Code;
var tSettings = settings.Where(x => x.AssignType == DeviceTimePeriodAssignEnumType.Template).Where(x => x.Value == templateCode).ToList();
var dSettings = settings.Where(x => x.AssignType == DeviceTimePeriodAssignEnumType.Device).Where(x => x.Value == code).ToList();
foreach (var setting in dSettings)
{
var s = tSettings.FirstOrDefault(x => x.CardType == setting.CardType);
if (s != null)
{
tSettings.Remove(s);
}
tSettings.Add(setting);
}
item.TimePeriods = tSettings;
});
}
} }

View File

@@ -10,7 +10,7 @@
"BasicRequestUrl": "http://localhost:5002" "BasicRequestUrl": "http://localhost:5002"
}, },
"FaceUrlOptions": { "FaceUrlOptions": {
"Url": "http://localhost:5002/api/gainfos/face?token=", "Url": "http://192.168.199.115:5002/api/gainfos/face?token=",
"Limit": 7200 "Limit": 7200
}, },
"SwaggerOptions": { "SwaggerOptions": {