|
|
|
@ -18,6 +18,7 @@ using ATS.NonCustodial.Shared.Extensions.AdvancedQuery; |
|
|
|
using AutoMapper.QueryableExtensions; |
|
|
|
using AutoMapper.QueryableExtensions; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
|
|
|
|
using System.Linq; |
|
|
|
using Yitter.IdGenerator; |
|
|
|
using Yitter.IdGenerator; |
|
|
|
|
|
|
|
|
|
|
|
namespace ATS.NonCustodial.Application.Impl.Admins |
|
|
|
namespace ATS.NonCustodial.Application.Impl.Admins |
|
|
|
@ -34,12 +35,15 @@ namespace ATS.NonCustodial.Application.Impl.Admins |
|
|
|
|
|
|
|
|
|
|
|
private readonly IEfRepository<App_Unitcode?, long> _appUnitcodeRepository; |
|
|
|
private readonly IEfRepository<App_Unitcode?, long> _appUnitcodeRepository; |
|
|
|
private readonly IEfRepository<App_Deptcode?, long> _appDeptcodeRepository; |
|
|
|
private readonly IEfRepository<App_Deptcode?, long> _appDeptcodeRepository; |
|
|
|
|
|
|
|
private readonly IEfRepository<AppUser?, long> _userRepository; |
|
|
|
|
|
|
|
|
|
|
|
public UnitcodeService(IEfRepository<App_Unitcode?, long> appUnitcodeRepository, |
|
|
|
public UnitcodeService(IEfRepository<App_Unitcode?, long> appUnitcodeRepository, |
|
|
|
IEfRepository<App_Deptcode?, long> appDeptcodeRepository) |
|
|
|
IEfRepository<App_Deptcode?, long> appDeptcodeRepository, |
|
|
|
|
|
|
|
IEfRepository<AppUser?, long> userRepository) |
|
|
|
{ |
|
|
|
{ |
|
|
|
_appUnitcodeRepository = appUnitcodeRepository; |
|
|
|
_appUnitcodeRepository = appUnitcodeRepository; |
|
|
|
_appDeptcodeRepository = appDeptcodeRepository; |
|
|
|
_appDeptcodeRepository = appDeptcodeRepository; |
|
|
|
|
|
|
|
_userRepository = userRepository; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endregion Identity |
|
|
|
#endregion Identity |
|
|
|
@ -316,6 +320,11 @@ namespace ATS.NonCustodial.Application.Impl.Admins |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!(input?.Id > 0)) return ResultOutput.NotOk(); |
|
|
|
if (!(input?.Id > 0)) return ResultOutput.NotOk(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var unitlist = _appUnitcodeRepository.AsQueryable(false, true).Where(q => q.Id == input.Id).ToList(); |
|
|
|
|
|
|
|
foreach (var item in unitlist) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (item.ParentUnitCode != input.ParentUnitCode) { return ResultOutput.NotOk("单位父级无法修改"); } |
|
|
|
|
|
|
|
} |
|
|
|
var entity = await _appUnitcodeRepository.FindAsync((long)input.Id); |
|
|
|
var entity = await _appUnitcodeRepository.FindAsync((long)input.Id); |
|
|
|
|
|
|
|
|
|
|
|
if (!(entity?.Id > 0)) return ResultOutput.NotOk("编辑失败"); |
|
|
|
if (!(entity?.Id > 0)) return ResultOutput.NotOk("编辑失败"); |
|
|
|
@ -334,14 +343,45 @@ namespace ATS.NonCustodial.Application.Impl.Admins |
|
|
|
{ |
|
|
|
{ |
|
|
|
Uow.BeginTransaction(); |
|
|
|
Uow.BeginTransaction(); |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
for (int i = 0; i < input.Ids.Count; i++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var idlist= GetUnitIdList(input.Ids[i]); |
|
|
|
|
|
|
|
//校验该单位下是否存在用户账户 |
|
|
|
|
|
|
|
if (_userRepository.AsQueryable(false, true).Where(q => idlist.Contains(q.UnitId??-1)).Any()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return ResultOutput.NotOk("该单位下存在用户账户,无法删除"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//删除 |
|
|
|
|
|
|
|
await _appUnitcodeRepository.DeleteAsync(w => idlist.Contains(w.Id)); |
|
|
|
|
|
|
|
} |
|
|
|
//删除 |
|
|
|
//删除 |
|
|
|
await _appUnitcodeRepository.DeleteAsync(w => input.Ids.Contains(w.Id)); |
|
|
|
// await _appUnitcodeRepository.DeleteAsync(w => input.Ids.Contains(w.Id)); |
|
|
|
//删除 |
|
|
|
//删除 |
|
|
|
await _appUnitcodeRepository.DeleteAsync(w => input.Ids.Contains((long)w.ParentUnitCode)); |
|
|
|
// await _appUnitcodeRepository.DeleteAsync(w => input.Ids.Contains((long)w.ParentUnitCode)); |
|
|
|
} |
|
|
|
} |
|
|
|
await Uow.CommitAsync(); |
|
|
|
await Uow.CommitAsync(); |
|
|
|
return ResultOutput.Ok(); |
|
|
|
return ResultOutput.Ok(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 递归查找该单位下的所有单位 |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="unitId">单位id</param> |
|
|
|
|
|
|
|
/// <returns>单位id集合</returns> |
|
|
|
|
|
|
|
private List<long> GetUnitIdList(long unitId) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
List<long> idList=new List<long>(); |
|
|
|
|
|
|
|
idList.Add(unitId); |
|
|
|
|
|
|
|
var unitlist=_appUnitcodeRepository.AsQueryable(false, true).Where(q => q.ParentUnitCode == unitId).ToList() ; |
|
|
|
|
|
|
|
foreach (var item in unitlist) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
idList.Add(item.Id); |
|
|
|
|
|
|
|
var idlist = GetUnitIdList(item.Id); |
|
|
|
|
|
|
|
idList.AddRange(idlist); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return idList; |
|
|
|
|
|
|
|
} |
|
|
|
#region Private |
|
|
|
#region Private |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
|