1
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
namespace SimpleAdmin.Application;
|
||||
|
||||
public class OnboardingAuditActionInput
|
||||
{
|
||||
[IdNotNull(ErrorMessage = "任务Id不能为空")]
|
||||
public long TaskId { get; set; }
|
||||
|
||||
public string AuditOpinion { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace SimpleAdmin.Application;
|
||||
|
||||
public interface IOnboardingAuditService : ITransient
|
||||
{
|
||||
Task Approve(OnboardingAuditActionInput input);
|
||||
Task Reject(OnboardingAuditActionInput input);
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
namespace SimpleAdmin.Application;
|
||||
|
||||
public class OnboardingAuditService : IOnboardingAuditService
|
||||
{
|
||||
private readonly ISqlSugarClient _db;
|
||||
private readonly IConfigService _config;
|
||||
private readonly IOnboardingContractSnapshotService _snapshotService;
|
||||
|
||||
public OnboardingAuditService(
|
||||
ISqlSugarClient db,
|
||||
IConfigService config,
|
||||
IOnboardingContractSnapshotService snapshotService)
|
||||
{
|
||||
_db = db;
|
||||
_config = config;
|
||||
_snapshotService = snapshotService;
|
||||
}
|
||||
|
||||
public async Task Approve(OnboardingAuditActionInput input)
|
||||
{
|
||||
var task = await GetAuditableTask(input.TaskId);
|
||||
var employeeInfo = await _db.Queryable<ObTaskEmployeeInfo>()
|
||||
.FirstAsync(item => item.TaskId == task.Id)
|
||||
?? throw Oops.Bah("候选人资料不存在");
|
||||
|
||||
var hasMaterialNeedSupplement = await _db.Queryable<ObTaskMaterial>()
|
||||
.AnyAsync(item => item.TaskId == task.Id
|
||||
&& item.ReviewStatus == TaskMaterialReviewStatus.NeedSupplement);
|
||||
if (hasMaterialNeedSupplement)
|
||||
{
|
||||
throw Oops.Bah("仍有资料需要补充,不能审核通过");
|
||||
}
|
||||
|
||||
var hasExistingEmployee = await _db.Queryable<ObEmployee>()
|
||||
.AnyAsync(item => item.IdCardNumber == employeeInfo.IdCardNumber || item.Phone == employeeInfo.Phone);
|
||||
if (hasExistingEmployee)
|
||||
{
|
||||
throw Oops.Bah("该身份证号或手机号已存在正式员工");
|
||||
}
|
||||
|
||||
var extraValues = await _db.Queryable<ObTaskFormValue>()
|
||||
.Where(item => item.TaskId == task.Id)
|
||||
.ToListAsync();
|
||||
var employee = employeeInfo.Adapt<ObEmployee>();
|
||||
employee.Id = global::SimpleAdmin.Core.Utils.CommonUtils.GetSingleId();
|
||||
employee.CompanyId = task.CompanyId;
|
||||
employee.PositionId = task.PositionId;
|
||||
employee.ExtraInfoJson = global::System.Text.Json.JsonSerializer.Serialize(extraValues);
|
||||
|
||||
await _db.Ado.BeginTranAsync();
|
||||
try
|
||||
{
|
||||
await _snapshotService.Build(task.Id, employeeInfo);
|
||||
await _db.Insertable(employee).ExecuteCommandAsync();
|
||||
|
||||
task.EmployeeId = employee.Id;
|
||||
task.TaskStatus = OnboardingTaskStatus.Approved;
|
||||
task.AuditedAt = DateTime.Now;
|
||||
await _db.Updateable(task).ExecuteCommandAsync();
|
||||
await WriteAudit(task, OnboardingAuditAction.Approve, input.AuditOpinion);
|
||||
await _db.Ado.CommitTranAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Reject(OnboardingAuditActionInput input)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(input.AuditOpinion))
|
||||
{
|
||||
throw Oops.Bah("请填写退回原因");
|
||||
}
|
||||
|
||||
var task = await GetAuditableTask(input.TaskId);
|
||||
task.TaskStatus = OnboardingTaskStatus.Rejected;
|
||||
task.RejectReason = input.AuditOpinion;
|
||||
await _db.Updateable(task).ExecuteCommandAsync();
|
||||
await WriteAudit(task, OnboardingAuditAction.Reject, input.AuditOpinion);
|
||||
}
|
||||
|
||||
private async Task<ObOnboardingTask> GetAuditableTask(long taskId)
|
||||
{
|
||||
var task = await _db.Queryable<ObOnboardingTask>().InSingleAsync(taskId)
|
||||
?? throw Oops.Bah("入职任务不存在");
|
||||
if (task.TaskStatus != OnboardingTaskStatus.Reviewing)
|
||||
{
|
||||
throw Oops.Bah("当前任务不在审核中");
|
||||
}
|
||||
|
||||
var config = await _config.GetByConfigKey(CateGoryConst.CONFIG_BIZ_DEFINE, "onboard.reviewer.userIds")
|
||||
?? throw Oops.Bah("请配置入职审核人");
|
||||
using var configJson = global::System.Text.Json.JsonDocument.Parse(config.ConfigValue);
|
||||
var reviewerIds = new List<long>();
|
||||
if (configJson.RootElement.TryGetProperty("all", out var allReviewers))
|
||||
{
|
||||
reviewerIds.AddRange(allReviewers.EnumerateArray().Select(item => item.GetInt64()));
|
||||
}
|
||||
|
||||
if (configJson.RootElement.TryGetProperty("company", out var companyReviewers)
|
||||
&& companyReviewers.TryGetProperty(task.CompanyId.ToString(), out var reviewers))
|
||||
{
|
||||
reviewerIds.AddRange(reviewers.EnumerateArray().Select(item => item.GetInt64()));
|
||||
}
|
||||
|
||||
if (!reviewerIds.Contains(UserManager.UserId))
|
||||
{
|
||||
throw Oops.Bah("您不是该入职任务的审核人");
|
||||
}
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
private Task WriteAudit(ObOnboardingTask task, string action, string opinion)
|
||||
{
|
||||
return _db.Insertable(new ObTaskAudit
|
||||
{
|
||||
Id = global::SimpleAdmin.Core.Utils.CommonUtils.GetSingleId(),
|
||||
TaskId = task.Id,
|
||||
AuditRound = task.SubmitCount,
|
||||
AuditAction = action,
|
||||
AuditorUserId = UserManager.UserId,
|
||||
AuditOpinion = opinion,
|
||||
AuditedAt = DateTime.Now
|
||||
}).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user