fix 调整时段码结构
This commit is contained in:
@@ -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))
|
||||
@@ -383,4 +353,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