fix 优化判断逻辑和获取时间逻辑
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Dlhis.Basic.Appointment.Request;
|
using System.Linq.Expressions;
|
||||||
|
using Dlhis.Basic.Appointment.Request;
|
||||||
using Dlhis.Basic.Appointment.Response;
|
using Dlhis.Basic.Appointment.Response;
|
||||||
using Dlhis.Basic.Common.Message.Requests;
|
using Dlhis.Basic.Common.Message.Requests;
|
||||||
using Dlhis.Basic.Common.Message.Services;
|
using Dlhis.Basic.Common.Message.Services;
|
||||||
@@ -411,21 +412,37 @@ public class AppointmentService : IAppointmentService
|
|||||||
//获取外部人员
|
//获取外部人员
|
||||||
var externals = await _dbContext.Queryable<GainfoEntity>()
|
var externals = await _dbContext.Queryable<GainfoEntity>()
|
||||||
.Where(x => x.Type == GainfoUserTypeEnumType.External)
|
.Where(x => x.Type == GainfoUserTypeEnumType.External)
|
||||||
.Where(x => x.Code == "EXT059373")
|
|
||||||
.Select(x => new { x.Id, x.Code, x.Factory, x.CreateTime })
|
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
var settings = new List<FactorySettingResponse>() { new FactorySettingResponse
|
|
||||||
{
|
|
||||||
Factory= "502",
|
|
||||||
NoRecordAutoResignExternalDays = 3
|
|
||||||
} };//await _factorySettingService.GetListAsync(false);
|
|
||||||
|
|
||||||
//todo 临时处理循环依赖
|
|
||||||
var gainfoService = _serviceProvider.GetService<IGainfoService>();
|
var gainfoService = _serviceProvider.GetService<IGainfoService>();
|
||||||
|
|
||||||
var holidaies = await _dbContext
|
await AutoResignBySettingAsync(externals,
|
||||||
.Queryable<HolidayEntity>()
|
(settings, factory) =>
|
||||||
|
{
|
||||||
|
var setting = settings.First(x => x.Factory == factory);
|
||||||
|
return setting.NoRecordAutoResignExternalDays;
|
||||||
|
},
|
||||||
|
async (g, l) =>
|
||||||
|
{
|
||||||
|
await gainfoService.ResignAsync(new GainfoResignRequest
|
||||||
|
{
|
||||||
|
Id = g.Id,
|
||||||
|
Reason = $"{l}天无通行记录",
|
||||||
|
Date = DateTime.Now
|
||||||
|
});
|
||||||
|
},
|
||||||
|
null, "自动归档外部人员异常");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task AutoResignBySettingAsync(List<GainfoEntity> gainfos
|
||||||
|
, Func<List<FactorySettingResponse>, string, int> getleaveDay
|
||||||
|
, Func<GainfoEntity, int, Task> todo
|
||||||
|
, Expression<Func<DeviceUploadLogEntity, bool>> uploadLogAdditionalExp
|
||||||
|
, string errorMsgPrefix)
|
||||||
|
{
|
||||||
|
var settings = await _factorySettingService.GetListAsync(false);
|
||||||
|
var holidaies = await _dbContext.Queryable<HolidayEntity>()
|
||||||
.Select(x => new
|
.Select(x => new
|
||||||
{
|
{
|
||||||
x.Type,
|
x.Type,
|
||||||
@@ -434,30 +451,26 @@ public class AppointmentService : IAppointmentService
|
|||||||
})
|
})
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
|
|
||||||
var weekends = new List<DayOfWeek>() { DayOfWeek.Saturday, DayOfWeek.Sunday };
|
var weekends = new List<DayOfWeek>() { DayOfWeek.Saturday, DayOfWeek.Sunday };
|
||||||
//人员分组,key为factory
|
//人员分组,key为factory
|
||||||
foreach (var exts in externals.GroupBy(x => x.Factory))
|
foreach (var todoGainfos in gainfos.GroupBy(x => x.Factory))
|
||||||
{
|
{
|
||||||
//factory的设置
|
//设置为0则不处理
|
||||||
var setting = settings.First(x => x.Factory == exts.Key);
|
var leaveDay = getleaveDay(settings, todoGainfos.Key);
|
||||||
if (setting.NoRecordAutoResignExternalDays == 0)
|
if (leaveDay == 0)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var ext in exts)
|
foreach (var gainfo in todoGainfos)
|
||||||
{
|
{
|
||||||
// 查询该外部人员最近一次通行记录的时间
|
//获取最近一次通行记录的时间,如果没有则取创建时间
|
||||||
DateTime? raiseDateTime = await _dbContext.Queryable<DeviceUploadLogEntity>()
|
DateTime? raiseDateTime = await _dbContext.Queryable<DeviceUploadLogEntity>()
|
||||||
.Where(x => x.UserUniqueNo == ext.Code)
|
.Where(x => x.UserUniqueNo == gainfo.Code)
|
||||||
.GroupBy(x => x.UserUniqueNo)
|
.WhereIF(uploadLogAdditionalExp != null, uploadLogAdditionalExp)
|
||||||
.Select(x => SqlFunc.IsNull(SqlFunc.AggregateMax(x.RaiseDateTime), default(DateTime?)))
|
.Select(x => SqlFunc.IsNull(SqlFunc.AggregateMax(x.RaiseDateTime), gainfo.CreateTime))
|
||||||
.SingleAsync();
|
.SingleAsync();
|
||||||
|
|
||||||
// 如果最近通行时间存在且超出未通行天数阈值,则自动归档该外部人员
|
|
||||||
if (raiseDateTime.HasValue)
|
|
||||||
{
|
|
||||||
var checkDates = GetDaysUntilToday(raiseDateTime.Value);
|
var checkDates = GetDaysUntilToday(raiseDateTime.Value);
|
||||||
var days = checkDates.Count;
|
var days = checkDates.Count;
|
||||||
foreach (var date in checkDates)
|
foreach (var date in checkDates)
|
||||||
@@ -480,24 +493,18 @@ public class AppointmentService : IAppointmentService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (days >= setting.NoRecordAutoResignExternalDays)
|
if (days >= leaveDay)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await gainfoService.ResignAsync(new GainfoResignRequest
|
await todo(gainfo, leaveDay);
|
||||||
{
|
|
||||||
Id = ext.Id,
|
|
||||||
Reason = $"{setting.NoRecordAutoResignExternalDays}天无通行记录",
|
|
||||||
Date = DateTime.Now
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
// 记录自动归档异常日志
|
_logger.LogError(e, $"{errorMsgPrefix}:{e.Message}");
|
||||||
_logger.LogError(e, "自动归档外部人员异常:{msg}", e.Message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,16 +163,14 @@ public class GainfoOutsourceService : IGainfoOutsourceService
|
|||||||
|
|
||||||
foreach (var outsource in grp)
|
foreach (var outsource in grp)
|
||||||
{
|
{
|
||||||
DateTime? raiseDateTime = await _dbContext.Queryable<DeviceUploadLogEntity>()
|
DateTime raiseDateTime = await _dbContext.Queryable<DeviceUploadLogEntity>()
|
||||||
.Where(x => x.UserUniqueNo == outsource.Code)
|
.Where(x => x.UserUniqueNo == outsource.Code)
|
||||||
.Where(x => x.TenantId == grp.Key) //本厂区的
|
.Where(x => x.TenantId == grp.Key) //本厂区的
|
||||||
.GroupBy(x => x.UserUniqueNo)
|
.GroupBy(x => x.UserUniqueNo)
|
||||||
.Select(x => SqlFunc.IsNull(SqlFunc.AggregateMax(x.RaiseDateTime), default(DateTime?)))
|
.Select(x => SqlFunc.IsNull(SqlFunc.AggregateMax(x.RaiseDateTime), outsource.CreateTime))
|
||||||
.SingleAsync();
|
.SingleAsync();
|
||||||
|
|
||||||
if (raiseDateTime.HasValue)
|
var checkDates = GetDaysUntilToday(raiseDateTime);
|
||||||
{
|
|
||||||
var checkDates = GetDaysUntilToday(raiseDateTime.Value);
|
|
||||||
var days = checkDates.Count;
|
var days = checkDates.Count;
|
||||||
foreach (var date in checkDates)
|
foreach (var date in checkDates)
|
||||||
{
|
{
|
||||||
@@ -212,7 +210,6 @@ public class GainfoOutsourceService : IGainfoOutsourceService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public List<DateOnly> GetDaysUntilToday(DateTime begin)
|
public List<DateOnly> GetDaysUntilToday(DateTime begin)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user