fix 调整时段码结构
This commit is contained in:
@@ -19,17 +19,14 @@ public class DevicesController : ControllerBase
|
||||
private readonly IDeviceService _deviceService;
|
||||
private readonly IDeviceTemplateService _deviceTemplateService;
|
||||
private readonly IDeviceConnectService _deviceConnectService;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public DevicesController(IDeviceService deviceService,
|
||||
IDeviceTemplateService deviceTemplateService,
|
||||
IDeviceConnectService deviceConnectService,
|
||||
IConfiguration configuration)
|
||||
IDeviceConnectService deviceConnectService)
|
||||
{
|
||||
_deviceService = deviceService;
|
||||
_deviceTemplateService = deviceTemplateService;
|
||||
_deviceConnectService = deviceConnectService;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -106,20 +103,6 @@ public class DevicesController : ControllerBase
|
||||
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>
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
@@ -1,22 +1,23 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.Entity.Device.Models;
|
||||
|
||||
namespace Dlhis.Basic.Device.Request;
|
||||
|
||||
public class DeviceTimePeriodSaveRequest : IValidatableObject
|
||||
public class DeviceTimePeriodSaveRequest
|
||||
{
|
||||
public long? Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 卡类型 timeperiod
|
||||
/// </summary>
|
||||
[Range(2, 3)]
|
||||
[Range(2, 3, ErrorMessage = "卡类型有误")]
|
||||
public int CardType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 分配类型 DeviceTimePeriodAssignEnumType
|
||||
/// </summary>
|
||||
[EnumDataType(typeof(DeviceTimePeriodAssignEnumType))]
|
||||
[EnumDataType(typeof(DeviceTimePeriodAssignEnumType), ErrorMessage = "时段分配类型有误")]
|
||||
public DeviceTimePeriodAssignEnumType AssignType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -26,46 +27,9 @@ public class DeviceTimePeriodSaveRequest : IValidatableObject
|
||||
public Guid Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上班开始
|
||||
/// 星期配置
|
||||
/// </summary>
|
||||
[Required]
|
||||
public TimeOnly OnStart { 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) });
|
||||
}
|
||||
}
|
||||
[MinLength(7, ErrorMessage = "配置有误")]
|
||||
[MaxLength(7, ErrorMessage = "配置有误")]
|
||||
public List<DeviceWeekDayTimePeriod> Sections { get; set; }
|
||||
}
|
||||
@@ -1,16 +1,25 @@
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.Entity.Device.Models;
|
||||
|
||||
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>
|
||||
public int CardType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 卡类型描述
|
||||
/// </summary>
|
||||
public string CardTypeDesc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 分配类型
|
||||
/// </summary>
|
||||
@@ -22,27 +31,7 @@ public class DeviceTimePeriodResponse
|
||||
public Guid Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// 时段信息
|
||||
/// </summary>
|
||||
public string Name { 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; }
|
||||
public List<DeviceWeekDayTimePeriod> Sections { get; set; }
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
using Dlhis.Basic.Device.Dtos;
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
@@ -25,17 +24,24 @@ public class DeviceTimePeriodService : IDeviceTimePeriodService
|
||||
/// <inheritdoc />
|
||||
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)
|
||||
.Select<DeviceTimePeriodResponse>()
|
||||
.ToPageListAsync(request);
|
||||
|
||||
var page = pageOri.Adapt<Pagination<DeviceTimePeriodResponse>>();
|
||||
|
||||
var values = page.Data.Select(x => x.Value);
|
||||
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<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;
|
||||
}
|
||||
@@ -49,8 +55,7 @@ public class DeviceTimePeriodService : IDeviceTimePeriodService
|
||||
var existsData = request.AssignType == DeviceTimePeriodAssignEnumType.Device
|
||||
? await _dbContext.Queryable<DeviceEntity>().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>()
|
||||
.Where(x => x.CardType == request.CardType)
|
||||
@@ -103,10 +108,10 @@ public class DeviceTimePeriodService : IDeviceTimePeriodService
|
||||
var deviceUniqueNo = device.UniqueNo;
|
||||
|
||||
before.TryGetValue(deviceUniqueNo, out var beforeDtos);
|
||||
beforeDtos ??= new List<DeviceTimePeriodDto>(0);
|
||||
beforeDtos ??= new List<DeviceTimePeriodEntity>(0);
|
||||
|
||||
current.TryGetValue(deviceUniqueNo, out var currentDtos);
|
||||
currentDtos ??= new List<DeviceTimePeriodDto>(0);
|
||||
currentDtos ??= new List<DeviceTimePeriodEntity>(0);
|
||||
|
||||
if (beforeDtos.Count != currentDtos.Count)
|
||||
{
|
||||
@@ -138,7 +143,7 @@ public class DeviceTimePeriodService : IDeviceTimePeriodService
|
||||
|
||||
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
|
||||
{
|
||||
@@ -161,7 +166,7 @@ public class DeviceTimePeriodService : IDeviceTimePeriodService
|
||||
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();
|
||||
|
||||
@@ -178,11 +183,11 @@ public class DeviceTimePeriodService : IDeviceTimePeriodService
|
||||
{
|
||||
var tSettings = timePeriods
|
||||
.Where(item => item.AssignType == DeviceTimePeriodAssignEnumType.Template && item.Value == x.TemplateCode)
|
||||
.Adapt<List<DeviceTimePeriodDto>>();
|
||||
.ToList();
|
||||
|
||||
var dSettings = timePeriods
|
||||
.Where(item => item.AssignType == DeviceTimePeriodAssignEnumType.Device && item.Value == x.Code)
|
||||
.Adapt<List<DeviceTimePeriodDto>>();
|
||||
.ToList();
|
||||
|
||||
foreach (var setting in dSettings)
|
||||
{
|
||||
|
||||
@@ -262,6 +262,10 @@ public class GainfoFaceService : IGainfoFaceService
|
||||
Face = request.Face
|
||||
};
|
||||
|
||||
face.CreatedBy = _currentUser.GetIntSubjectId();
|
||||
face.CreateTime = DateTime.Now;
|
||||
face.ModifiedBy = _currentUser.GetIntSubjectId();
|
||||
face.ModifiedTime = DateTime.Now;
|
||||
await _faceDbContext.InsertAsync(face);
|
||||
}
|
||||
else
|
||||
@@ -271,7 +275,9 @@ public class GainfoFaceService : IGainfoFaceService
|
||||
_logger.LogWarning("相同的人脸照片更新忽略");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
face.ModifiedBy = _currentUser.GetIntSubjectId();
|
||||
face.ModifiedTime = DateTime.Now;
|
||||
face.Face = request.Face;
|
||||
await _faceDbContext.UpdateAsync(face);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "http://localhost:5002"
|
||||
"applicationUrl": "http://*:5002"
|
||||
},
|
||||
"Docker": {
|
||||
"commandName": "Docker",
|
||||
|
||||
@@ -195,7 +195,7 @@ public class GainfoEntity : SugarBaseEntity
|
||||
|
||||
|
||||
[SugarColumn(ColumnDescription = "卡类型", IsNullable = true)]
|
||||
public string CardType { get; set; }
|
||||
public int? CardType { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.Entity.Device.Models;
|
||||
using Kurisu.AspNetCore.DataAccess.Entity;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar;
|
||||
using Mapster;
|
||||
@@ -40,28 +41,10 @@ public class DeviceTimePeriodEntity : SugarBaseEntity, ITenantId
|
||||
public Guid Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上班开始
|
||||
/// 时段信息
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "上班开始")]
|
||||
public TimeOnly OnStart { 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(IsJson = true, ColumnDataType = "varchar(1000)")]
|
||||
public List<DeviceWeekDayTimePeriod> Sections { get; set; }
|
||||
|
||||
|
||||
[SugarColumn(IsNullable = false, UniqueGroupNameList = new[] { "unique_DeviceTimePeriod_cardType_assignType_value" })]
|
||||
|
||||
@@ -42,6 +42,12 @@ public class DeviceUploadLogEntity : SugarBaseEntity, ITenantId
|
||||
[SugarColumn(ColumnDataType = "bit")]
|
||||
public bool Sync { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否有效
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDataType = "bit")]
|
||||
public bool Status { get; set; }
|
||||
|
||||
|
||||
[SugarColumn(IndexGroupNameList = new string[] { "idx_DeviceUploadLog_TenantId" })]
|
||||
public string TenantId { get; set; }
|
||||
|
||||
8
Src/Dlhis.Entity/Device/Models/DeviceTimePeriod.cs
Normal file
8
Src/Dlhis.Entity/Device/Models/DeviceTimePeriod.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Kurisu.AspNetCore.CustomClass;
|
||||
|
||||
namespace Dlhis.Entity.Device.Models;
|
||||
|
||||
public class DeviceTimePeriod : TimePeriod
|
||||
{
|
||||
public bool Enable { get; set; }
|
||||
}
|
||||
14
Src/Dlhis.Entity/Device/Models/DeviceWeekDayTimePeriod.cs
Normal file
14
Src/Dlhis.Entity/Device/Models/DeviceWeekDayTimePeriod.cs
Normal 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; }
|
||||
}
|
||||
@@ -266,7 +266,7 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
CostId = item.KOSTL,
|
||||
EntryDate = item.createdate,
|
||||
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,
|
||||
Factory = _tenants.FirstOrDefault(x => x.Name == item.ZZ_GZDCQNM)?.Code ?? item.ZZ_GZDCQNM,
|
||||
};
|
||||
@@ -326,7 +326,7 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
ResignationDate = item.ZLZRQ,
|
||||
Workplace = workplace,
|
||||
Factory = factory,
|
||||
CardType = item.ZZ_KLX
|
||||
CardType = Convert.ToInt32(item.ZZ_KLX)
|
||||
}).Where(x => x.Code == item.ename).ExecuteCommandAsync();
|
||||
await _identityUserSyncService.SyncAccountAsync(gainfo.Code, gainfo.Name, gainfo.IdNo, factory);
|
||||
}
|
||||
|
||||
@@ -24,11 +24,6 @@ public class DeviceUploadLogUploadRequest
|
||||
/// 记录序号
|
||||
/// </summary>
|
||||
public string SerialNo { get; set; }
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// 记录类型
|
||||
// /// </summary>
|
||||
// [EnumDataType(typeof(DeviceUploadLogTypeEnumType))]
|
||||
// public DeviceUploadLogTypeEnumType Type { get; set; } = DeviceUploadLogTypeEnumType.Attendance;
|
||||
|
||||
public bool Status { get; set; }
|
||||
}
|
||||
|
||||
@@ -55,5 +55,13 @@ public class DeviceUploadLogResponse
|
||||
[JsonIgnore]
|
||||
public string OriginUserUniqueNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否同步sap
|
||||
/// </summary>
|
||||
public bool Sync { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否有效
|
||||
/// </summary>
|
||||
public bool Status { get; set; }
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
||||
return await _dbContext.Queryable<DeviceUploadLogEntity>()
|
||||
.LeftJoin<DeviceEntity>((log, d) => log.DeviceUniqueNo == d.UniqueNo)
|
||||
.Where(log => log.UserUniqueNo == jinkoCode)
|
||||
.Where(log => log.Status)
|
||||
.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))
|
||||
.OrderBy(log => log.RaiseDateTime)
|
||||
@@ -46,6 +47,7 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
||||
SerialNo = log.SerialNo,
|
||||
DeployPlace = d.DeployPlace,
|
||||
Sync = log.Sync,
|
||||
Status = log.Status
|
||||
})
|
||||
.ToListAsync();
|
||||
}
|
||||
@@ -88,6 +90,7 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
||||
UserName = ga.Name,
|
||||
DeployPlace = device.DeployPlace,
|
||||
Sync = deviceUp.Sync,
|
||||
Status = deviceUp.Status,
|
||||
})
|
||||
.ToPageListAsync(request);
|
||||
}
|
||||
@@ -122,7 +125,8 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
||||
? DeviceUploadLogTypeEnumType.Attendance
|
||||
: DeviceUploadLogTypeEnumType.Door,
|
||||
|
||||
TenantId = device.TenantId
|
||||
TenantId = device.TenantId,
|
||||
Status = request.Status
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ public class SyncOriginCardInfoJob : BaseJob
|
||||
.Where(x => deviceUniqueNos.Contains(x.DeviceUniqueNo))
|
||||
.Where(x => !string.IsNullOrEmpty(x.UserUniqueNo))
|
||||
.Where(x => x.Sync == false)
|
||||
.Where(x => x.Status)
|
||||
.Where(x => SqlFunc.Subqueryable<OutsourceEntity>().Where(p => p.Code == x.UserUniqueNo).NotAny())
|
||||
.Select((x, device) => new UploadAttendanceRequest
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Dlhis.ScheduledTask.Common.Services;
|
||||
using Kurisu.AspNetCore.Startup;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
|
||||
@@ -24,5 +25,8 @@ public class Startup : DefaultStartup
|
||||
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
base.Configure(app, env);
|
||||
|
||||
|
||||
var token = app.ApplicationServices.GetService<IJinkoJIPService>().IssueToken();
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "http://localhost:5010"
|
||||
"applicationUrl": "http://*:5010"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,16 +55,4 @@ public class AssignmentsController : ControllerBase
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
|
||||
namespace Dlhis.ScheduledTask.TaskAssignment.Dto;
|
||||
|
||||
@@ -23,5 +24,17 @@ public class TaskDto
|
||||
|
||||
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 List<DeviceTimePeriodEntity> TimePeriods { get; set; }
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using Kurisu.AspNetCore.CustomClass;
|
||||
using Dlhis.Entity.Device.Models;
|
||||
|
||||
namespace Dlhis.ScheduledTask.TaskAssignment.Response;
|
||||
|
||||
@@ -12,5 +12,5 @@ public class TimePeriodWeekDaySection
|
||||
/// <summary>
|
||||
/// 时段区间 最多4个
|
||||
/// </summary>
|
||||
public List<TimePeriod> TimePeriods { get; set; }
|
||||
public List<DeviceTimePeriod> TimePeriods { get; set; }
|
||||
}
|
||||
|
||||
@@ -19,11 +19,4 @@ public interface IAssignmentService : IScopeDependency
|
||||
/// <param name="requests"></param>
|
||||
/// <returns></returns>
|
||||
Task UpdateDeviceTaskStatusAsync(List<UpdateDeviceTaskStatusRequest> requests);
|
||||
|
||||
/// <summary>
|
||||
/// 获取新人脸照片
|
||||
/// </summary>
|
||||
/// <param name="taskId"></param>
|
||||
/// <returns></returns>
|
||||
Task<string> RenewFaceUrlAsync(long taskId);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.Entity.Device.Models;
|
||||
using Dlhis.ScheduledTask.TaskAssignment.Request;
|
||||
using Dlhis.ScheduledTask.TaskAssignment.Response;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
@@ -8,12 +9,12 @@ using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using SqlSugar;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Kurisu.AspNetCore;
|
||||
using Kurisu.AspNetCore.Utils;
|
||||
using Dlhis.ScheduledTask.TaskAssignment.Dto;
|
||||
using Kurisu.AspNetCore.CustomClass;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Mapster;
|
||||
|
||||
namespace Dlhis.ScheduledTask.TaskAssignment.Services.Implements;
|
||||
|
||||
@@ -37,6 +38,8 @@ public class AssignmentService : IAssignmentService
|
||||
var data = await GetDataAsync(request);
|
||||
if (data.IsEmpty()) return new List<DeviceTaskToDeviceByDeviceResponse>();
|
||||
|
||||
await HandlerOldDeviceGainfoAsync(data);
|
||||
await HandlerTimePeriodAsync(data);
|
||||
var deviceUploadInfos = await GetDeviceUploadRecordInfosAsync(data);
|
||||
|
||||
var timeLimitedDataProtector = _dataProtectionProvider
|
||||
@@ -90,14 +93,14 @@ public class AssignmentService : IAssignmentService
|
||||
UserName = item.UserName,
|
||||
DepartmentNo = item.DepartmentNo,
|
||||
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, //下发才附带照片信息
|
||||
ValidDatePeriod = new DatePeriod
|
||||
{
|
||||
Start = DateOnly.FromDateTime(DateTime.Now.AddDays(-1)),
|
||||
End = DateOnly.FromDateTime(DateTime.Now.AddYears(20)),
|
||||
},
|
||||
TimePeriods = new List<int> { 1 },
|
||||
TimePeriods = new List<int> { item.CardType },
|
||||
Doors = new List<int> { 1 },
|
||||
Schedule = 1
|
||||
};
|
||||
@@ -106,27 +109,22 @@ public class AssignmentService : IAssignmentService
|
||||
case DeviceTaskEnumType.TimePeriodAdd:
|
||||
case DeviceTaskEnumType.TimePeriodDelete:
|
||||
{
|
||||
dto.Info = new TimePeriodToDeviceResponse
|
||||
dto.Info = item.TimePeriods.Select(t => new TimePeriodToDeviceResponse
|
||||
{
|
||||
Id = 1,
|
||||
Name = "小白领",
|
||||
Id = t.CardType,
|
||||
Name = t.CardType == 2 ? "行政卡" : "车间卡",
|
||||
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,
|
||||
TimePeriods = new List<TimePeriod>
|
||||
{
|
||||
new()
|
||||
{
|
||||
Start = TimeOnly.Parse("08:00:00"),
|
||||
End = TimeOnly.Parse("17:30:00")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Enable = p.Enable,
|
||||
Start = p.Enable ? p.Start : new TimeOnly(00, 00, 00),
|
||||
End = p.Enable ? p.End : new TimeOnly(00, 00, 00),
|
||||
}).ToList()
|
||||
}).ToList()
|
||||
});
|
||||
}
|
||||
break;
|
||||
case DeviceTaskEnumType.ScheduleAdd:
|
||||
@@ -173,33 +171,6 @@ public class AssignmentService : IAssignmentService
|
||||
}).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)
|
||||
{
|
||||
@@ -290,8 +261,12 @@ public class AssignmentService : IAssignmentService
|
||||
.WhereIF(factories.Any(), (deviceTask, device) => factories.Contains(deviceTask.TenantId))
|
||||
.WhereIF(request.Types.IsPresent(), deviceTask => request.Types.Contains(deviceTask.Type))
|
||||
.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)
|
||||
#endif
|
||||
|
||||
.OrderBy(deviceTask => new { Priority = SqlFunc.Desc(deviceTask.Priority), deviceTask.CreateTime })
|
||||
.Select((deviceTask, device, deviceTemplate, ga, gaLeave, department, gainfoEx) => new TaskDto
|
||||
{
|
||||
@@ -313,7 +288,13 @@ public class AssignmentService : IAssignmentService
|
||||
DepartmentName = department.Name,
|
||||
CardNo = ga.CardNo,
|
||||
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);
|
||||
|
||||
@@ -338,28 +319,17 @@ public class AssignmentService : IAssignmentService
|
||||
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;
|
||||
}, 5);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理获取上传记录的任务
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<Dictionary<string, DateTime?>> GetDeviceUploadRecordInfosAsync(List<TaskDto> data)
|
||||
{
|
||||
if (data.All(x => x.Type != DeviceTaskEnumType.UploadRecord))
|
||||
@@ -386,4 +356,65 @@ public class AssignmentService : IAssignmentService
|
||||
|
||||
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;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
"BasicRequestUrl": "http://localhost:5002"
|
||||
},
|
||||
"FaceUrlOptions": {
|
||||
"Url": "http://localhost:5002/api/gainfos/face?token=",
|
||||
"Url": "http://192.168.199.115:5002/api/gainfos/face?token=",
|
||||
"Limit": 7200
|
||||
},
|
||||
"SwaggerOptions": {
|
||||
|
||||
Reference in New Issue
Block a user