update remotecall and feat outsource自动离职
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using Dlhis.Basic.Organization.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
@@ -14,11 +15,21 @@ public class GainfoOutsourceService : IGainfoOutsourceService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly RedisCache _redisCache;
|
||||
private readonly IGainfoService _gainfoService;
|
||||
private readonly IFactorySettingService _factorySettingService;
|
||||
private readonly ILogger<GainfoOutsourceService> _logger;
|
||||
|
||||
public GainfoOutsourceService(IDbContext dbContext, RedisCache redisCache)
|
||||
public GainfoOutsourceService(IDbContext dbContext,
|
||||
RedisCache redisCache,
|
||||
IGainfoService gainfoService,
|
||||
IFactorySettingService factorySettingService,
|
||||
ILogger<GainfoOutsourceService> logger)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_redisCache = redisCache;
|
||||
_gainfoService = gainfoService;
|
||||
_factorySettingService = factorySettingService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task SaveAsync(GainfoOutsourceRequest request)
|
||||
@@ -101,6 +112,49 @@ public class GainfoOutsourceService : IGainfoOutsourceService
|
||||
}
|
||||
|
||||
|
||||
public async Task AutoResignAsync()
|
||||
{
|
||||
var outsources = await _dbContext.Queryable<GainfoEntity>()
|
||||
.Where(x => x.Type == GainfoUserTypeEnumType.Outsource)
|
||||
.Select(x => new { x.Id, x.Code, x.Factory, x.CreateTime })
|
||||
.ToListAsync();
|
||||
|
||||
var settings = await _factorySettingService.GetListAsync();
|
||||
//0001/1/1 0:00:00
|
||||
var nullDateTime = new DateTime(1, 1, 1);
|
||||
foreach (var outsource in outsources)
|
||||
{
|
||||
var setting = settings.First(x => x.Factory == outsource.Factory);
|
||||
|
||||
var raiseDateTime = await _dbContext.Queryable<DeviceUploadLogEntity>()
|
||||
.Where(x => x.UserUniqueNo == outsource.Code)
|
||||
.GroupBy(x => x.UserUniqueNo)
|
||||
.Select(x => SqlFunc.IsNull(SqlFunc.AggregateMax(x.RaiseDateTime), outsource.CreateTime))
|
||||
.SingleAsync();
|
||||
|
||||
raiseDateTime = raiseDateTime == nullDateTime ? outsource.CreateTime : raiseDateTime;
|
||||
|
||||
if (raiseDateTime.AddDays(setting.NoRecordAutoResignOutsourceDays) < DateTime.Now)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _gainfoService.ResignAsync(new GainfoResignRequest
|
||||
{
|
||||
Id = outsource.Id,
|
||||
Reason = $"{setting.NoRecordAutoResignOutsourceDays}天无打开记录",
|
||||
Date = DateTime.Now,
|
||||
IsOutsource = true
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "自动离职外包异常:{msg}", e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//********************************************************************** help methods ***********************************************************************************
|
||||
|
||||
private async Task<string> GetOutSourceCodeAsync()
|
||||
@@ -128,17 +182,39 @@ public class GainfoOutsourceService : IGainfoOutsourceService
|
||||
/// <param name="request"></param>
|
||||
private async Task CheckDuplicate(GainfoOutsourceRequest request)
|
||||
{
|
||||
var exists = await _dbContext.Queryable<GainfoEntity>()
|
||||
var gainfo = await _dbContext.Queryable<GainfoEntity>()
|
||||
.WhereIF(request.Id.HasValue, x => x.Id != request.Id)
|
||||
.Where(x => x.IdNo == request.IdNo).AnyAsync();
|
||||
exists.ThrowIfTrue($"证件号{request.IdNo}重复");
|
||||
.Where(x => x.IdNo == request.IdNo).SingleAsync();
|
||||
|
||||
if (gainfo != null)
|
||||
{
|
||||
var msg = string.Empty;
|
||||
var outsource = await _dbContext.Queryable<OutsourceEntity>().Where(x => x.Code == request.Code).SingleAsync();
|
||||
if (outsource != null)
|
||||
{
|
||||
msg = $",对接人工号为{outsource.SapCode}";
|
||||
}
|
||||
|
||||
gainfo.ThrowIfNotNull($"证件号{request.IdNo}重复,厂区为{gainfo.Factory}" + msg);
|
||||
}
|
||||
|
||||
if (request.Code.IsPresent())
|
||||
{
|
||||
exists = await _dbContext.Queryable<GainfoEntity>()
|
||||
gainfo = await _dbContext.Queryable<GainfoEntity>()
|
||||
.WhereIF(request.Id.HasValue, x => x.Id != request.Id)
|
||||
.Where(x => x.Code == request.Code).AnyAsync();
|
||||
exists.ThrowIfTrue($"工号{request.Code}重复");
|
||||
.Where(x => x.Code == request.Code).SingleAsync();
|
||||
|
||||
if (gainfo != null)
|
||||
{
|
||||
var msg = string.Empty;
|
||||
var outsource = await _dbContext.Queryable<OutsourceEntity>().Where(x => x.Code == request.Code).SingleAsync();
|
||||
if (outsource != null)
|
||||
{
|
||||
msg = $",对接人工号为{outsource.SapCode}";
|
||||
}
|
||||
|
||||
gainfo.ThrowIfNotNull($"工号{request.Code}重复,厂区为{gainfo.Factory}" + msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user