feat 外包人员,框架升级

This commit is contained in:
2024-05-30 19:37:27 +08:00
parent 5a437af90b
commit 75bd31d4a5
298 changed files with 2124 additions and 2313 deletions

View File

@@ -1,8 +1,8 @@
using Dlhis.ScheduledTask.TaskAssignment.Request;
using Dlhis.ScheduledTask.TaskAssignment.Response;
using Dlhis.ScheduledTask.TaskAssignment.Services;
using Kurisu.AspNetCore.DataAccess.Dto;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
using Kurisu.Core.DataAccess.Dto;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

View File

@@ -1,4 +1,4 @@
using Kurisu.Core.ConfigurableOptions.Attributes;
using Kurisu.AspNetCore.ConfigurableOptions.Attributes;
namespace Dlhis.ScheduledTask.TaskAssignment;

View File

@@ -1,7 +1,7 @@
using System.ComponentModel.DataAnnotations;
using Dlhis.Entity.Device.Enums;
using Kurisu.Core.CustomClass;
using Kurisu.Core.DataAccess.Dto;
using Kurisu.AspNetCore.CustomClass;
using Kurisu.AspNetCore.DataAccess.Dto;
namespace Dlhis.ScheduledTask.TaskAssignment.Request;

View File

@@ -1,7 +1,7 @@
using System.ComponentModel.DataAnnotations;
using Dlhis.Entity.Device.Enums;
using Kurisu.AspNetCore.DataAccess.Dto;
using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.Core.DataAccess.Dto;
namespace Dlhis.ScheduledTask.TaskAssignment.Request;

View File

@@ -1,4 +1,4 @@
using Kurisu.Core.CustomClass;
using Kurisu.AspNetCore.CustomClass;
namespace Dlhis.ScheduledTask.TaskAssignment.Response;

View File

@@ -1,6 +1,4 @@
using Kurisu.Core.CustomClass;
namespace Dlhis.ScheduledTask.TaskAssignment.Response;
namespace Dlhis.ScheduledTask.TaskAssignment.Response;
public class TimePeriodToDeviceResponse
{

View File

@@ -1,4 +1,4 @@
using Kurisu.Core.CustomClass;
using Kurisu.AspNetCore.CustomClass;
namespace Dlhis.ScheduledTask.TaskAssignment.Response;

View File

@@ -1,4 +1,4 @@
using Kurisu.Core.CustomClass;
using Kurisu.AspNetCore.CustomClass;
namespace Dlhis.ScheduledTask.TaskAssignment.Response;

View File

@@ -1,4 +1,4 @@
using Kurisu.Core.CustomClass;
using Kurisu.AspNetCore.CustomClass;
namespace Dlhis.ScheduledTask.TaskAssignment.Response;
@@ -63,4 +63,4 @@ public class UserToDeviceResponse
/// 假期计划id
/// </summary>
public int Schedule { get; set; }
}
}

View File

@@ -1,6 +1,6 @@
using Dlhis.ScheduledTask.TaskAssignment.Request;
using Dlhis.ScheduledTask.TaskAssignment.Response;
using Kurisu.Core.DataAccess.Dto;
using Kurisu.AspNetCore.DataAccess.Dto;
namespace Dlhis.ScheduledTask.TaskAssignment.Services;

View File

@@ -4,16 +4,16 @@ using Dlhis.Entity.Device.Enums;
using Dlhis.ScheduledTask.TaskAssignment.Request;
using Dlhis.ScheduledTask.TaskAssignment.Response;
using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.SqlSugar.Services;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.Extensions.Options;
using SqlSugar;
using Kurisu.SqlSugar.Extensions;
using Newtonsoft.Json.Linq;
using Kurisu.Core.CustomClass;
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;
namespace Dlhis.ScheduledTask.TaskAssignment.Services.Implements;
@@ -40,46 +40,46 @@ public class AssignmentService : IAssignmentService
var deviceUploadInfos = await GetDeviceUploadRecordInfosAsync(data);
var timeLimitedDataProtector = _dataProtectionProvider
.CreateProtector("down:face")
.ToTimeLimitedDataProtector();
.CreateProtector("down:face")
.ToTimeLimitedDataProtector();
return data.GroupBy(x => new { x.Brand, x.DeviceUniqueNo, x.DeviceConnectionInfo, x.FuncStr })
.Select(x =>
{
var b = x.Key.Brand;
var d = x.Key.DeviceUniqueNo;
var dc = x.Key.DeviceConnectionInfo ?? "{}";
var func = x.Key.FuncStr ?? "[]";
var jobj = new JObject
.Select(x =>
{
{ "connectionInfo", JToken.Parse(dc) },
{ "function", JArray.Parse(func) }
};
var b = x.Key.Brand;
var d = x.Key.DeviceUniqueNo;
var dc = x.Key.DeviceConnectionInfo ?? "{}";
var func = x.Key.FuncStr ?? "[]";
return new DeviceTaskToDeviceByDeviceResponse
{
Brand = b,
DeviceUniqueNo = d,
DeviceInfo = jobj,
Tasks = x.Select(item =>
var jobj = new JObject
{
var key = $"face:{item.UserCode}";
var token = item.Type == DeviceTaskEnumType.Delete
? string.Empty
: timeLimitedDataProtector.Protect(key, TimeSpan.FromSeconds(_faceUrlOptions.Limit));
{ "connectionInfo", JToken.Parse(dc) },
{ "function", JArray.Parse(func) }
};
var dto = new TaskCombineDto
return new DeviceTaskToDeviceByDeviceResponse
{
Brand = b,
DeviceUniqueNo = d,
DeviceInfo = jobj,
Tasks = x.Select(item =>
{
TaskId = item.TaskId,
Type = item.Type,
};
var key = $"face:{item.UserCode}";
var token = item.Type == DeviceTaskEnumType.Delete
? string.Empty
: timeLimitedDataProtector.Protect(key, TimeSpan.FromSeconds(_faceUrlOptions.Limit));
switch (dto.Type)
{
case DeviceTaskEnumType.Add:
case DeviceTaskEnumType.Delete:
case DeviceTaskEnumType.Update:
var dto = new TaskCombineDto
{
TaskId = item.TaskId,
Type = item.Type,
};
switch (dto.Type)
{
case DeviceTaskEnumType.Add:
case DeviceTaskEnumType.Delete:
case DeviceTaskEnumType.Update:
{
dto.Info = new UserToDeviceResponse
{
@@ -90,7 +90,7 @@ public class AssignmentService : IAssignmentService
DepartmentNo = item.DepartmentNo,
DepartmentName = item.DepartmentName,
CardNo = item.Type == DeviceTaskEnumType.Delete ? string.Empty : 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
{
Start = DateOnly.FromDateTime(DateTime.Now.AddDays(-1)),
@@ -101,9 +101,9 @@ public class AssignmentService : IAssignmentService
Schedule = 1
};
}
break;
case DeviceTaskEnumType.TimePeriodAdd:
case DeviceTaskEnumType.TimePeriodDelete:
break;
case DeviceTaskEnumType.TimePeriodAdd:
case DeviceTaskEnumType.TimePeriodDelete:
{
dto.Info = new TimePeriodToDeviceResponse
{
@@ -112,24 +112,24 @@ public class AssignmentService : IAssignmentService
Enable = true,
Sections = new List<TimePeriodWeekDaySection>()
{
new()
new()
{
DayOfWeek = DayOfWeek.Monday,
TimePeriods = new List<TimePeriod>
{
DayOfWeek= DayOfWeek.Monday,
TimePeriods = new List<TimePeriod>()
new()
{
new()
{
Start = TimeOnly.Parse("08:00:00"),
End = TimeOnly.Parse("17:30:00"),
},
}
Start = TimeOnly.Parse("08:00:00"),
End = TimeOnly.Parse("17:30:00"),
},
}
}
}
};
}
break;
case DeviceTaskEnumType.ScheduleAdd:
case DeviceTaskEnumType.ScheduleDelete:
break;
case DeviceTaskEnumType.ScheduleAdd:
case DeviceTaskEnumType.ScheduleDelete:
{
dto.Info = new ScheduleToDeviceResponse
{
@@ -138,21 +138,21 @@ public class AssignmentService : IAssignmentService
Name = "计划的一部分",
Schedules = new List<ScheduleDto>
{
new()
{
new()
{
Name = "国庆节",
DateTimePeriod = new DateTimePeriod
{
Start = new DateTime(2024,10,1),
End = new DateTime(2024,10,7)
}
Start = new DateTime(2024, 10, 1),
End = new DateTime(2024, 10, 7)
}
}
}
};
}
break;
break;
case DeviceTaskEnumType.UploadRecord:
case DeviceTaskEnumType.UploadRecord:
{
dto.Info = new UploadRecordToDeviceResponse
{
@@ -163,17 +163,15 @@ public class AssignmentService : IAssignmentService
}
};
}
break;
default:
break;
}
break;
default:
break;
}
return dto;
}).ToList()
};
}).ToList();
return dto;
}).ToList()
};
}).ToList();
}
/// <summary>
@@ -234,38 +232,38 @@ public class AssignmentService : IAssignmentService
var data = await CommonHelper.RetryAsync(async () =>
{
var page = await _dbContext.Queryable<DeviceTaskEntity>()
.LeftJoin<DeviceEntity>((deviceTask, deivce) => deviceTask.DeviceUniqueNo == deivce.UniqueNo)
.LeftJoin<DeviceTemplateEntity>((deviceTask, deivce, deivceTamplate) => deivceTamplate.Code == deivce.TemplateCode)
.LeftJoin<GainfoEntity>((deviceTask, deivce, deivceTamplate, ga) => deviceTask.UserNo == ga.No)
.LeftJoin<GainfoLeaveEntity>((deviceTask, deivce, deivceTamplate, ga, galeave) => deviceTask.UserNo == galeave.No)
.LeftJoin<DepartmentEntity>((deviceTask, deivce, deivceTamplate, ga, galeave, department) => department.No == ga.DepartmentNo)
.LeftJoin<GainfoExternalEntity>((deviceTask, deivce, deivceTamplate, ga, galeave, department, gainfoEx) => deviceTask.UserNo == gainfoEx.No)
.WhereIF(!request.IsProcess, deviceTask => deviceTask.Status == DeviceTaskStatusEnumType.Wait)
.WhereIF(request.IsProcess, deviceTask => deviceTask.Status == DeviceTaskStatusEnumType.Process
&& SqlFunc.DateDiff(DateType.Minute, deviceTask.ModifiedTime, DateTime.Now) > 30)
.WhereIF(request.DeviceUniqueNo.IsPresent(), (deviceTask, deivce) => deviceTask.DeviceUniqueNo == request.DeviceUniqueNo)
.WhereIF(request.Types.IsPresent(), deviceTask => request.Types.Contains(deviceTask.Type))
.WhereIF(request.Brand.IsPresent(), (deviceTask, deivce, deivceTamplate) => deivceTamplate.Brand == request.Brand)
.OrderBy(deviceTask => new { Priority = SqlFunc.Desc(deviceTask.Priority), deviceTask.CreateTime })
.Select((deviceTask, deivce, deivceTamplate, ga, galeave, department, gainfoEx) => new TaskDto
{
UserId = SqlFunc.IsNull(SqlFunc.IsNull(deviceTask.UserId, ga.Id), galeave.IdentityUserId),
TaskId = deviceTask.Id,
Type = deviceTask.Type,
DeviceUniqueNo = deviceTask.DeviceUniqueNo,
DeviceConnectionInfo = deivce.ConnectionInfo,
Brand = deivceTamplate.Brand,
FuncStr = deivce.Funcs.ToString(),
UserNo = deviceTask.UserNo,
UserCode = SqlFunc.IsNull(SqlFunc.IsNull(ga.Code, galeave.Code), gainfoEx.Code),
UserName = SqlFunc.IsNull(SqlFunc.IsNull(ga.Name, galeave.Name), gainfoEx.Name),
DepartmentNo = ga.DepartmentNo,
DepartmentName = department.Name,
CardNo = ga.CardNo,
Version = deviceTask.Version,
Status = deviceTask.Status
})
.ToPageListAsync(request);
.LeftJoin<DeviceEntity>((deviceTask, deivce) => deviceTask.DeviceUniqueNo == deivce.UniqueNo)
.LeftJoin<DeviceTemplateEntity>((deviceTask, deivce, deivceTamplate) => deivceTamplate.Code == deivce.TemplateCode)
.LeftJoin<GainfoEntity>((deviceTask, deivce, deivceTamplate, ga) => deviceTask.UserNo == ga.No)
.LeftJoin<GainfoLeaveEntity>((deviceTask, deivce, deivceTamplate, ga, galeave) => deviceTask.UserNo == galeave.No)
.LeftJoin<DepartmentEntity>((deviceTask, deivce, deivceTamplate, ga, galeave, department) => department.No == ga.DepartmentNo)
.LeftJoin<GainfoExternalEntity>((deviceTask, deivce, deivceTamplate, ga, galeave, department, gainfoEx) => deviceTask.UserNo == gainfoEx.No)
.WhereIF(!request.IsProcess, deviceTask => deviceTask.Status == DeviceTaskStatusEnumType.Wait)
.WhereIF(request.IsProcess, deviceTask => deviceTask.Status == DeviceTaskStatusEnumType.Process
&& SqlFunc.DateDiff(DateType.Minute, deviceTask.ModifiedTime, DateTime.Now) > 30)
.WhereIF(request.DeviceUniqueNo.IsPresent(), (deviceTask, deivce) => deviceTask.DeviceUniqueNo == request.DeviceUniqueNo)
.WhereIF(request.Types.IsPresent(), deviceTask => request.Types.Contains(deviceTask.Type))
.WhereIF(request.Brand.IsPresent(), (deviceTask, deivce, deivceTamplate) => deivceTamplate.Brand == request.Brand)
.OrderBy(deviceTask => new { Priority = SqlFunc.Desc(deviceTask.Priority), deviceTask.CreateTime })
.Select((deviceTask, deivce, deivceTamplate, ga, galeave, department, gainfoEx) => new TaskDto
{
UserId = SqlFunc.IsNull(SqlFunc.IsNull(deviceTask.UserId, ga.Id), galeave.IdentityUserId),
TaskId = deviceTask.Id,
Type = deviceTask.Type,
DeviceUniqueNo = deviceTask.DeviceUniqueNo,
DeviceConnectionInfo = deivce.ConnectionInfo,
Brand = deivceTamplate.Brand,
FuncStr = deivce.Funcs.ToString(),
UserNo = deviceTask.UserNo,
UserCode = SqlFunc.IsNull(SqlFunc.IsNull(ga.Code, galeave.Code), gainfoEx.Code),
UserName = SqlFunc.IsNull(SqlFunc.IsNull(ga.Name, galeave.Name), gainfoEx.Name),
DepartmentNo = ga.DepartmentNo,
DepartmentName = department.Name,
CardNo = ga.CardNo,
Version = deviceTask.Version,
Status = deviceTask.Status
})
.ToPageListAsync(request);
if (!page.Data.Any())
{
@@ -274,22 +272,18 @@ public class AssignmentService : IAssignmentService
var taskIdVs = page.Data.Select(x => new { x.TaskId, x.Version, x.Status }).ToList();
var where = LinqExpressionExtensions.False<DeviceTaskEntity>();
taskIdVs.ForEach(p =>
{
where = where.Or(x => x.Id == p.TaskId && x.Version == p.Version && x.Status == p.Status);
});
taskIdVs.ForEach(p => { where = where.Or(x => x.Id == p.TaskId && x.Version == p.Version && x.Status == p.Status); });
var effecet = await _dbContext.Updateable<DeviceTaskEntity>()
.SetColumns(x => x.Version == x.Version + 1)
.SetColumns(x => x.Status == DeviceTaskStatusEnumType.Process)
.SetColumns(x => x.ModifiedTime == DateTime.Now)
.Where(where)
.ExecuteCommandAsync();
.SetColumns(x => x.Version == x.Version + 1)
.SetColumns(x => x.Status == DeviceTaskStatusEnumType.Process)
.SetColumns(x => x.ModifiedTime == DateTime.Now)
.Where(where)
.ExecuteCommandAsync();
(taskIdVs.Count != effecet).ThrowIfTrue("获取任务失败");
return page.Data;
}, 5);
return data;
@@ -304,14 +298,14 @@ public class AssignmentService : IAssignmentService
//日志数据最后一条
var logInfos = await _dbContext.Queryable<DeviceUploadLogEntity>().Select(it => new
{
RowNumber = SqlFunc.RowNumber(SqlFunc.Desc(it.Id), it.DeviceUniqueNo),
it.DeviceUniqueNo,
it.RaiseDateTime
})
.MergeTable()
.Where(it => it.RowNumber == 1)
.ToListAsync();
{
RowNumber = SqlFunc.RowNumber(SqlFunc.Desc(it.Id), it.DeviceUniqueNo),
it.DeviceUniqueNo,
it.RaiseDateTime
})
.MergeTable()
.Where(it => it.RowNumber == 1)
.ToListAsync();
foreach (var item in deviceNos)
{
@@ -324,4 +318,4 @@ public class AssignmentService : IAssignmentService
return new Dictionary<string, DateTime?>();
}
}
}

View File

@@ -4,10 +4,10 @@ using Dlhis.Entity.Device.Enums;
using Dlhis.ScheduledTask.TaskAssignment.Request;
using Dlhis.ScheduledTask.TaskAssignment.Response;
using Dlhis.Sys.Api;
using Kurisu.AspNetCore.DataAccess.Dto;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.Core.DataAccess.Dto;
using Kurisu.SqlSugar.Extensions;
using Kurisu.SqlSugar.Services;
using SqlSugar;
namespace Dlhis.ScheduledTask.TaskAssignment.Services.Implements;
@@ -30,15 +30,15 @@ public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService
.LeftJoin<DeviceEntity>((deviceTask, ga, device) => deviceTask.DeviceUniqueNo == device.UniqueNo)
.WhereIF(request.Type.HasValue, (deviceTask, ga, device) => deviceTask.DeviceType == request.Type)
.WhereIF(request.SearchDateTimePeriod?.Start.HasValue == true && request.SearchDateTimePeriod?.End.HasValue == true,
deviceTask => deviceTask.ModifiedTime >= request.SearchDateTimePeriod.Start && deviceTask.ModifiedTime <= request.SearchDateTimePeriod.End
deviceTask => deviceTask.ModifiedTime >= request.SearchDateTimePeriod.Start && deviceTask.ModifiedTime <= request.SearchDateTimePeriod.End
)
.WhereIF(request.TaskTypes.IsPresent(), deviceTask => request.TaskTypes.Contains(deviceTask.Type))
.WhereIF(request.Status.IsPresent(), deviceTask => request.Status.Contains(deviceTask.Status))
.WhereIF(request.UserNo.IsPresent(), deviceTask => deviceTask.UserNo == request.UserNo)
.WhereIF(!request.Search.IsEmpty(), (deviceTask, ga, device) =>
ga.Name == request.Search
|| ga.Code == request.Search
|| deviceTask.DeviceUniqueNo == request.Search
ga.Name == request.Search
|| ga.Code == request.Search
|| deviceTask.DeviceUniqueNo == request.Search
)
.OrderBy(deviceTask => deviceTask.CreateTime, OrderByType.Desc)
.Select((deviceTask, ga, device) => new DeviceTaskAssignmentResponse
@@ -64,11 +64,7 @@ public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService
var tenantResult = await _tenantApi.GetTenantsInternalAsync();
var tenants = tenantResult.Data;
page.Data.ForEach(item =>
{
item.TenantName = tenants.FirstOrDefault(x => x.Code == item.TenantId)?.Name;
});
page.Data.ForEach(item => { item.TenantName = tenants.FirstOrDefault(x => x.Code == item.TenantId)?.Name; });
}
catch (Exception)
{
@@ -92,11 +88,9 @@ public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService
//更新任务状态
await _dbContext.Updateable<DeviceTaskEntity>()
.SetColumns(x => x.Status == DeviceTaskStatusEnumType.Wait)
.SetColumns(x => x.ModifiedTime == DateTime.Now)
.Where(x => request.Ids.Contains(x.Id))
.ExecuteCommandAsync();
.SetColumns(x => x.Status == DeviceTaskStatusEnumType.Wait)
.SetColumns(x => x.ModifiedTime == DateTime.Now)
.Where(x => request.Ids.Contains(x.Id))
.ExecuteCommandAsync();
}
}
}