逻辑调整
This commit is contained in:
+10
-144
@@ -1,7 +1,7 @@
|
||||
namespace SimpleAdmin.Application;
|
||||
|
||||
/// <summary>
|
||||
/// 维护员工端动态字段、材料类型及公司岗位要求。
|
||||
/// 维护员工端动态补充字段和材料类型;与公司、岗位的组合关系由入职模板统一管理。
|
||||
/// </summary>
|
||||
public class OnboardingEntryConfigService : IOnboardingEntryConfigService
|
||||
{
|
||||
@@ -92,8 +92,10 @@ public class OnboardingEntryConfigService : IOnboardingEntryConfigService
|
||||
|
||||
var isReferenced = await _db.Queryable<ObFormRequirement>()
|
||||
.AnyAsync(x => input.Ids.Contains(x.FieldId));
|
||||
if (isReferenced)
|
||||
throw Oops.Bah("字段已被填写要求引用,不能删除");
|
||||
var isReferencedByTemplate = await _db.Queryable<ObOnboardingTemplateFormField>()
|
||||
.AnyAsync(x => input.Ids.Contains(x.FieldId));
|
||||
if (isReferenced || isReferencedByTemplate)
|
||||
throw Oops.Bah("字段已被入职模板引用,不能删除");
|
||||
|
||||
await _db.Deleteable<ObFormField>().In(input.Ids).ExecuteCommandAsync();
|
||||
}
|
||||
@@ -155,8 +157,10 @@ public class OnboardingEntryConfigService : IOnboardingEntryConfigService
|
||||
|
||||
var isReferenced = await _db.Queryable<ObMaterialRequirement>()
|
||||
.AnyAsync(x => input.Ids.Contains(x.MaterialTypeId));
|
||||
if (isReferenced)
|
||||
throw Oops.Bah("资料类型已被资料要求引用,不能删除");
|
||||
var isReferencedByTemplate = await _db.Queryable<ObOnboardingTemplateMaterial>()
|
||||
.AnyAsync(x => input.Ids.Contains(x.MaterialTypeId));
|
||||
if (isReferenced || isReferencedByTemplate)
|
||||
throw Oops.Bah("资料类型已被入职模板引用,不能删除");
|
||||
|
||||
var hasUploads = await _db.Queryable<ObTaskMaterial>()
|
||||
.AnyAsync(x => input.Ids.Contains(x.MaterialTypeId));
|
||||
@@ -165,142 +169,4 @@ public class OnboardingEntryConfigService : IOnboardingEntryConfigService
|
||||
|
||||
await _db.Deleteable<ObMaterialType>().In(input.Ids).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询指定公司的动态字段填写要求。
|
||||
/// </summary>
|
||||
public Task<List<ObFormRequirement>> ListFormRequirements(long companyId)
|
||||
{
|
||||
return _db.Queryable<ObFormRequirement>()
|
||||
.Where(x => x.CompanyId == companyId)
|
||||
.OrderBy(x => x.SortCode)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增或编辑公司岗位动态字段要求。
|
||||
/// </summary>
|
||||
public async Task SaveFormRequirement(OnboardingFormRequirementSaveInput input)
|
||||
{
|
||||
await EnsureCompanyAndPosition(input.CompanyId, input.PositionId);
|
||||
|
||||
var fieldExists = await _db.Queryable<ObFormField>()
|
||||
.AnyAsync(x => x.Id == input.FieldId && x.Status == "enable");
|
||||
if (!fieldExists)
|
||||
throw Oops.Bah("动态字段不存在或未启用");
|
||||
|
||||
var requirementExists = await _db.Queryable<ObFormRequirement>()
|
||||
.AnyAsync(x => x.CompanyId == input.CompanyId
|
||||
&& x.PositionId == input.PositionId
|
||||
&& x.FieldId == input.FieldId
|
||||
&& x.Id != input.Id);
|
||||
if (requirementExists)
|
||||
throw Oops.Bah("该公司、岗位和字段的要求已存在");
|
||||
|
||||
var entity = new ObFormRequirement
|
||||
{
|
||||
Id = input.Id ?? global::SimpleAdmin.Core.Utils.CommonUtils.GetSingleId(),
|
||||
CompanyId = input.CompanyId,
|
||||
PositionId = input.PositionId,
|
||||
FieldId = input.FieldId,
|
||||
Required = input.Required,
|
||||
SortCode = input.SortCode
|
||||
};
|
||||
|
||||
if (input.Id.HasValue)
|
||||
{
|
||||
await _db.Updateable(entity).ExecuteCommandAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
await _db.Insertable(entity).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除动态字段填写要求。
|
||||
/// </summary>
|
||||
public Task DeleteFormRequirements(BaseIdListInput input)
|
||||
{
|
||||
if (input.Ids.Count == 0)
|
||||
return Task.CompletedTask;
|
||||
|
||||
return _db.Deleteable<ObFormRequirement>().In(input.Ids).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询指定公司的材料上传要求。
|
||||
/// </summary>
|
||||
public Task<List<ObMaterialRequirement>> ListMaterialRequirements(long companyId)
|
||||
{
|
||||
return _db.Queryable<ObMaterialRequirement>()
|
||||
.Where(x => x.CompanyId == companyId)
|
||||
.OrderBy(x => x.SortCode)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增或编辑公司岗位材料要求。
|
||||
/// </summary>
|
||||
public async Task SaveMaterialRequirement(OnboardingMaterialRequirementSaveInput input)
|
||||
{
|
||||
await EnsureCompanyAndPosition(input.CompanyId, input.PositionId);
|
||||
|
||||
var materialTypeExists = await _db.Queryable<ObMaterialType>()
|
||||
.AnyAsync(x => x.Id == input.MaterialTypeId && x.Status == "enable");
|
||||
if (!materialTypeExists)
|
||||
throw Oops.Bah("资料类型不存在或未启用");
|
||||
|
||||
var requirementExists = await _db.Queryable<ObMaterialRequirement>()
|
||||
.AnyAsync(x => x.CompanyId == input.CompanyId
|
||||
&& x.PositionId == input.PositionId
|
||||
&& x.MaterialTypeId == input.MaterialTypeId
|
||||
&& x.Id != input.Id);
|
||||
if (requirementExists)
|
||||
throw Oops.Bah("该公司、岗位和资料类型的要求已存在");
|
||||
|
||||
var entity = new ObMaterialRequirement
|
||||
{
|
||||
Id = input.Id ?? global::SimpleAdmin.Core.Utils.CommonUtils.GetSingleId(),
|
||||
CompanyId = input.CompanyId,
|
||||
PositionId = input.PositionId,
|
||||
MaterialTypeId = input.MaterialTypeId,
|
||||
Required = input.Required,
|
||||
SortCode = input.SortCode
|
||||
};
|
||||
|
||||
if (input.Id.HasValue)
|
||||
{
|
||||
await _db.Updateable(entity).ExecuteCommandAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
await _db.Insertable(entity).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除材料上传要求。
|
||||
/// </summary>
|
||||
public Task DeleteMaterialRequirements(BaseIdListInput input)
|
||||
{
|
||||
if (input.Ids.Count == 0)
|
||||
return Task.CompletedTask;
|
||||
|
||||
return _db.Deleteable<ObMaterialRequirement>().In(input.Ids).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
private async Task EnsureCompanyAndPosition(long companyId, long? positionId)
|
||||
{
|
||||
var companyExists = await _db.Queryable<ObCompany>()
|
||||
.AnyAsync(x => x.Id == companyId && x.Status == "enable");
|
||||
if (!companyExists)
|
||||
throw Oops.Bah("公司不存在或未启用");
|
||||
|
||||
if (!positionId.HasValue)
|
||||
return;
|
||||
|
||||
var positionExists = await _db.Queryable<ObPosition>()
|
||||
.AnyAsync(x => x.Id == positionId.Value && x.CompanyId == companyId && x.Status == "enable");
|
||||
if (!positionExists)
|
||||
throw Oops.Bah("岗位不存在、未启用或不属于该公司");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user