using Shentun.Peis.CustomerOrgGroups; using Shentun.Peis.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Services; namespace Shentun.Peis.CustomerOrgGroupDetails { public class CustomerOrgGroupDetailManager : DomainService { private readonly IRepository _repository; private readonly IRepository _customerOrgGroupRepository; private readonly IRepository _customerOrgRegisterRepository; private readonly IRepository _customerOrgRepository; public CustomerOrgGroupDetailManager( IRepository repository, IRepository customerOrgRepository, IRepository customerOrgGroupRepository, IRepository customerOrgRegisterRepository ) { this._repository = repository; this._customerOrgRepository = customerOrgRepository; this._customerOrgGroupRepository = customerOrgGroupRepository; this._customerOrgRegisterRepository = customerOrgRegisterRepository; } /// /// 删除单位分组明细 /// /// 单位分组ID /// /// public async Task CheckAndDeleteAsync(Guid CustomerOrgGroupId) { await CheckCustomerOrgStatus(CustomerOrgGroupId); var customerOrgGroupDetailList = await _repository.GetListAsync(m => m.CustomerOrgGroupId == CustomerOrgGroupId); if (customerOrgGroupDetailList.Any()) { //删除单位分组明细 await _repository.DeleteManyAsync(customerOrgGroupDetailList); } } /// /// 删除组合项目相关的明细 /// /// 组合项目ID /// /// public async Task CheckAndDeleteInAsbitemIdAsync(Guid AsbitemId) { var customerOrgGroupDetailList = await _repository.GetListAsync(m => m.AsbitemId == AsbitemId); if (customerOrgGroupDetailList.Any()) { //删除组合项目相关的明细 await _repository.DeleteManyAsync(customerOrgGroupDetailList); } } /// /// 检查单位状态是否可以使用 未启用和加锁和单位体检次数已完成,不允许操作 /// /// 单位分组ID /// private async Task CheckCustomerOrgStatus(Guid CustomerOrgGroupId) { var customerOrgGroup = (from a in await _customerOrgGroupRepository.GetQueryableAsync() join b in await _customerOrgRegisterRepository.GetQueryableAsync() on a.CustomerOrgRegisterId equals b.Id join c in await _customerOrgRepository.GetQueryableAsync() on b.CustomerOrgId equals c.Id where a.Id == CustomerOrgGroupId && (c.IsLock == 'Y' || c.IsActive == 'N' || b.IsComplete == 'Y') select c.DisplayName).FirstOrDefault(); if (!string.IsNullOrWhiteSpace(customerOrgGroup)) { throw new UserFriendlyException($"单位{customerOrgGroup}未启用或者已锁定,无法操作!"); } } } }