1
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
namespace SimpleAdmin.Application;
|
||||
|
||||
public class OnboardingCompanyService : DbRepository<ObCompany>, IOnboardingCompanyService
|
||||
{
|
||||
public async Task<SqlSugarPagedList<ObCompany>> Page(OnboardingCompanyPageInput input)
|
||||
{
|
||||
return await Context.Queryable<ObCompany>()
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(input.CompanyName), it => it.CompanyName.Contains(input.CompanyName) || it.CompanyCode.Contains(input.CompanyName))
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(input.Status), it => it.Status == input.Status)
|
||||
.OrderByIF(!string.IsNullOrWhiteSpace(input.SortField), $"{input.SortField} {input.SortOrder}")
|
||||
.OrderBy(it => it.CreateTime)
|
||||
.ToPagedListAsync(input.PageNum, input.PageSize);
|
||||
}
|
||||
|
||||
public Task<List<ObCompany>> ListEnabled() => Context.Queryable<ObCompany>().Where(it => it.Status == "enable").OrderBy(it => it.CompanyName).ToListAsync();
|
||||
|
||||
public async Task<ObCompany> Detail(BaseIdInput input) => await GetByIdAsync(input.Id) ?? throw Oops.Bah("公司不存在");
|
||||
|
||||
public async Task Add(OnboardingCompanyAddInput input)
|
||||
{
|
||||
await EnsureCodeUnique(input.CompanyCode, 0);
|
||||
await InsertAsync(input.Adapt<ObCompany>());
|
||||
}
|
||||
|
||||
public async Task Edit(OnboardingCompanyEditInput input)
|
||||
{
|
||||
await Detail(new BaseIdInput { Id = input.Id });
|
||||
await EnsureCodeUnique(input.CompanyCode, input.Id);
|
||||
await UpdateAsync(input.Adapt<ObCompany>());
|
||||
}
|
||||
|
||||
public async Task Delete(BaseIdListInput input)
|
||||
{
|
||||
if (input.Ids.Count == 0) return;
|
||||
if (await Context.Queryable<ObPosition>().AnyAsync(it => input.Ids.Contains(it.CompanyId))) throw Oops.Bah("公司下仍有岗位,不能删除");
|
||||
if (await Context.Queryable<ObOnboardingTask>().AnyAsync(it => input.Ids.Contains(it.CompanyId))) throw Oops.Bah("公司已有入职任务,不能删除");
|
||||
if (await Context.Queryable<ObEmployee>().AnyAsync(it => input.Ids.Contains(it.CompanyId))) throw Oops.Bah("公司已有正式员工,不能删除");
|
||||
await DeleteByIdsAsync(input.Ids.Cast<object>().ToArray());
|
||||
}
|
||||
|
||||
private async Task EnsureCodeUnique(string code, long id)
|
||||
{
|
||||
if (await Context.Queryable<ObCompany>().AnyAsync(it => it.CompanyCode == code && it.Id != id)) throw Oops.Bah("公司编码已存在");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user