feat 例外人员权限增加到期时间,厂区配置增加生日券,外包自动离场报名单
This commit is contained in:
@@ -38,6 +38,7 @@ public class FactorySettingService : IFactorySettingService
|
||||
if (setting == null)
|
||||
{
|
||||
setting = request.Adapt<FactorySettingEntity>();
|
||||
setting.EnableUseBirthdayVoucherFactories = request.EnableUseBirthdayVoucherFactories.ToJson();
|
||||
setting.TenantId = request.Factory;
|
||||
|
||||
await _dbContext.InsertAsync(setting);
|
||||
@@ -45,12 +46,19 @@ public class FactorySettingService : IFactorySettingService
|
||||
else
|
||||
{
|
||||
request.Adapt(setting);
|
||||
setting.EnableUseBirthdayVoucherFactories = request.EnableUseBirthdayVoucherFactories.ToJson();
|
||||
setting.TenantId = request.Factory;
|
||||
|
||||
await _dbContext.UpdateAsync(setting);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> IsEnableBirthdayVoucherAsync(string factory, bool usePermission)
|
||||
{
|
||||
var setting = await GetFactorySettingAsync(factory, usePermission);
|
||||
return setting.EnableBirthdayVoucher;
|
||||
}
|
||||
|
||||
|
||||
public async Task<FactorySettingResponse> GetFactorySettingAsync(string factory, bool usePermission)
|
||||
{
|
||||
@@ -102,6 +110,20 @@ public class FactorySettingService : IFactorySettingService
|
||||
return now >= setting;
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<string>> GetEnableBirthdayVoucherFactoriesAsync()
|
||||
{
|
||||
var settings = await GetListAsync(false);
|
||||
return settings.Where(x => x.EnableBirthdayVoucher).Select(x => x.Factory).ToList();
|
||||
}
|
||||
|
||||
public async Task<List<string>> GetEnableUseBirthdayVoucherFactoriesAsync(string currentFactory)
|
||||
{
|
||||
var settings = await GetFactorySettingsAsync(currentFactory, false);
|
||||
var setting = settings.Where(x => x.EnableBirthdayVoucher).FirstOrDefault();
|
||||
return setting.EnableUseBirthdayVoucherFactories;
|
||||
}
|
||||
|
||||
//************************************************************************************************************************************************************
|
||||
|
||||
private async Task<List<FactorySettingResponse>> GetFactorySettingsAsync(string factory, bool usePermission)
|
||||
@@ -150,8 +172,11 @@ public class FactorySettingService : IFactorySettingService
|
||||
}).ToList()
|
||||
},
|
||||
NoRecordAutoResignOutsourceDays = currentSetting?.NoRecordAutoResignOutsourceDays ?? 30,
|
||||
NoRecordAutoResignExternalDays = currentSetting?.NoRecordAutoResignExternalDays ?? 0
|
||||
NoRecordAutoResignExternalDays = currentSetting?.NoRecordAutoResignExternalDays ?? 0,
|
||||
EnableBirthdayVoucher = currentSetting?.EnableBirthdayVoucher ?? false,
|
||||
EnableUseBirthdayVoucherFactories = (currentSetting?.EnableUseBirthdayVoucherFactories ?? "[]").ToObject<List<string>>()
|
||||
};
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using Dlhis.Basic.Organization.Api;
|
||||
using Dlhis.Basic.Organization.Api.Request;
|
||||
using Dlhis.Basic.Organization.Request;
|
||||
using Dlhis.Basic.Organization.Response;
|
||||
using Dlhis.Basic.ThirdParts;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
|
||||
@@ -3,6 +3,7 @@ using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Basic.Device.Services;
|
||||
using Dlhis.Basic.Organization.Request;
|
||||
using Dlhis.Basic.Organization.Response;
|
||||
using Dlhis.Basic.Utils;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
|
||||
@@ -4,6 +4,7 @@ using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Kurisu.AspNetCore.Cache;
|
||||
using Kurisu.AspNetCore.CustomClass;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Mapster;
|
||||
@@ -94,21 +95,28 @@ public class GainfoOutsourceService : IGainfoOutsourceService
|
||||
|
||||
public async Task<GainfoOutSourceExternalInfoResponse> GetExternalInfoAsync(string userNo)
|
||||
{
|
||||
return await _dbContext.Queryable<OutsourceEntity>()
|
||||
.LeftJoin<GainfoEntity>((a, b) => a.Code == b.Code)
|
||||
.LeftJoin<GainfoEntity>((a, b, c) => a.SapCode == c.Code)
|
||||
.Where((a, b, c) => b.No == userNo)
|
||||
.Select((a, b, c) => new GainfoOutSourceExternalInfoResponse
|
||||
{
|
||||
Supplier = a.Supplier,
|
||||
SapCode = a.SapCode,
|
||||
SapPhone = a.SapPhone,
|
||||
SapName = c.Name,
|
||||
EntryDate = b.EntryDate,
|
||||
ResignationDate = b.ResignationDate,
|
||||
Factory = b.Factory
|
||||
})
|
||||
.SingleAsync();
|
||||
var data = await _dbContext.Queryable<OutsourceEntity>()
|
||||
.LeftJoin<GainfoEntity>((a, b) => a.Code == b.Code)
|
||||
.LeftJoin<GainfoEntity>((a, b, c) => a.SapCode == c.Code)
|
||||
.Where((a, b, c) => b.No == userNo)
|
||||
.Select((a, b, c) => new GainfoOutSourceExternalInfoResponse
|
||||
{
|
||||
UserCode = b.Code,
|
||||
Supplier = a.Supplier,
|
||||
SapCode = a.SapCode,
|
||||
SapPhone = a.SapPhone,
|
||||
SapName = c.Name,
|
||||
EntryDate = b.EntryDate,
|
||||
ResignationDate = b.ResignationDate,
|
||||
Factory = b.Factory
|
||||
})
|
||||
.SingleAsync();
|
||||
|
||||
data.IsWhiteListInAutoResign = await _dbContext.Queryable<OutsourceWhiteListEntity>()
|
||||
.Where(x => x.UserCode == data.UserCode)
|
||||
.AnyAsync();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@@ -116,11 +124,27 @@ public class GainfoOutsourceService : IGainfoOutsourceService
|
||||
{
|
||||
var outsources = await _dbContext.Queryable<GainfoEntity>()
|
||||
.Where(x => x.Type == GainfoUserTypeEnumType.Outsource)
|
||||
.Where(x => SqlFunc.Subqueryable<OutsourceWhiteListEntity>().Where(p => p.UserCode == x.Code).NotAny())//不存在白名单中
|
||||
.Select(x => new { x.Id, x.Code, x.Factory, x.CreateTime })
|
||||
.ToListAsync();
|
||||
|
||||
var settings = await _factorySettingService.GetListAsync(false);
|
||||
|
||||
var holidaies = await _dbContext
|
||||
.Queryable<HolidayEntity>()
|
||||
.Select(x => new
|
||||
{
|
||||
x.Type,
|
||||
Period = new DatePeriod
|
||||
{
|
||||
Start = x.Start,
|
||||
End = x.End
|
||||
}
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
|
||||
var weekends = new List<DayOfWeek>() { DayOfWeek.Saturday, DayOfWeek.Sunday };
|
||||
foreach (var grp in outsources.GroupBy(x => x.Factory))
|
||||
{
|
||||
var setting = settings.First(x => x.Factory == grp.Key);
|
||||
@@ -138,26 +162,67 @@ public class GainfoOutsourceService : IGainfoOutsourceService
|
||||
.Select(x => SqlFunc.IsNull(SqlFunc.AggregateMax(x.RaiseDateTime), default(DateTime?)))
|
||||
.SingleAsync();
|
||||
|
||||
if (raiseDateTime.HasValue && raiseDateTime.Value.AddDays(setting.NoRecordAutoResignOutsourceDays) < DateTime.Now)
|
||||
if (raiseDateTime.HasValue)
|
||||
{
|
||||
try
|
||||
var checkDates = GetDaysUntilToday(raiseDateTime.Value);
|
||||
var days = checkDates.Count;
|
||||
foreach (var date in checkDates)
|
||||
{
|
||||
await _gainfoService.ResignAsync(new GainfoResignRequest
|
||||
//date.DayOfWeek
|
||||
foreach (var holiday in holidaies)
|
||||
{
|
||||
Id = outsource.Id,
|
||||
Reason = $"{setting.NoRecordAutoResignOutsourceDays}天无通行记录",
|
||||
Date = DateTime.Now
|
||||
});
|
||||
var isPresent = date >= holiday.Period.Start && date <= holiday.Period.Start;
|
||||
if (isPresent)
|
||||
{
|
||||
if (holiday.Type == HolidayEnumType.Rest)
|
||||
{
|
||||
days--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (weekends.Contains(date.DayOfWeek))
|
||||
{
|
||||
days--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
if (days >= setting.NoRecordAutoResignOutsourceDays)
|
||||
{
|
||||
_logger.LogError(e, "自动离职外包异常:{msg}", e.Message);
|
||||
try
|
||||
{
|
||||
await _gainfoService.ResignAsync(new GainfoResignRequest
|
||||
{
|
||||
Id = outsource.Id,
|
||||
Reason = $"{setting.NoRecordAutoResignOutsourceDays}天无通行记录",
|
||||
Date = DateTime.Now
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "自动离职外包异常:{msg}", e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<DateOnly> GetDaysUntilToday(DateTime begin)
|
||||
{
|
||||
var start = DateOnly.FromDateTime(begin.Date);
|
||||
var today = DateOnly.FromDateTime(DateTime.Today);
|
||||
if (start > today) return new List<DateOnly>();
|
||||
|
||||
var days = new List<DateOnly>();
|
||||
for (var d = start; d <= today; d = d.AddDays(1))
|
||||
{
|
||||
days.Add(d);
|
||||
}
|
||||
|
||||
return days;
|
||||
}
|
||||
|
||||
//********************************************************************** help methods ***********************************************************************************
|
||||
|
||||
|
||||
@@ -345,7 +345,7 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
|
||||
var content = $"{workGrid.Name}的网格长,你好,检测到你网格中 {gainfo.Name}({gainfo.Code}),因发生离职或者异动,现已经删除该员工{dates}的排班信息,请前往系统处理!";
|
||||
|
||||
await _dingTalkApi.SendWorkMessageAsync(new DingTalkWorkMessageRequest
|
||||
await _dingTalkApi.SendWorkMessageByWorkGridAsync(new DingTalkWorkMessageRequest
|
||||
{
|
||||
Content = content,
|
||||
WorkCodes = new List<string> { workGrid.LeaderUserCode }
|
||||
@@ -409,7 +409,7 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
}).SingleAsync();
|
||||
var content = $"{workGrid.Name}的网格长,你好,检测到你网格中 {gainfo.Name}({gainfo.Code}),因发生离职或者异动,现已经删除该员工{dates}的排班信息,请前往系统处理!";
|
||||
|
||||
await _dingTalkApi.SendWorkMessageAsync(new DingTalkWorkMessageRequest
|
||||
await _dingTalkApi.SendWorkMessageByWorkGridAsync(new DingTalkWorkMessageRequest
|
||||
{
|
||||
Content = content,
|
||||
WorkCodes = new List<string> { workGrid.LeaderUserCode }
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
|
||||
using Dlhis.Basic.Organization.Dto;
|
||||
using Dlhis.Basic.Organization.Request;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
|
||||
namespace Dlhis.Basic.Organization.Services.Implements;
|
||||
|
||||
public class OutsourceWhiteListService : IOutsourceWhiteListService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
|
||||
public OutsourceWhiteListService(IDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task AddAsync(string userCode)
|
||||
{
|
||||
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == userCode).SingleAsync();
|
||||
gainfo.ThrowIfNull("人员信息不存在");
|
||||
(gainfo.Type == GainfoUserTypeEnumType.Outsource).ThrowIfFalse("人员类型不正确");
|
||||
if (!await _dbContext.Queryable<OutsourceWhiteListEntity>().Where(x => x.UserCode == userCode).AnyAsync())
|
||||
{
|
||||
await _dbContext.InsertAsync(new OutsourceWhiteListEntity
|
||||
{
|
||||
UserCode = userCode
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public async Task RemoveAsync(string userCode)
|
||||
{
|
||||
var whitelist = await _dbContext.Queryable<OutsourceWhiteListEntity>().Where(x => x.UserCode == userCode).SingleAsync();
|
||||
if (whitelist != null)
|
||||
{
|
||||
await _dbContext.DeleteAsync(whitelist);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Pagination<GainfoDto>> GetPageAsync(OutsourceWhiteListPageRequest request)
|
||||
{
|
||||
return await _dbContext.Queryable<OutsourceWhiteListEntity>()
|
||||
.LeftJoin<GainfoEntity>((x, ga) => x.UserCode == ga.Code)
|
||||
.Select((x, ga) => new GainfoDto
|
||||
{
|
||||
Code = ga.Code,
|
||||
Name = ga.Name,
|
||||
})
|
||||
.ToPageListAsync(request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user