|
|
|
|
using ATS.NonCustodial.Application.Base;
|
|
|
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.Unitcode;
|
|
|
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.Unitcode.Input;
|
|
|
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.Unitcode.Output;
|
|
|
|
|
using ATS.NonCustodial.Domain.Entities.Admins;
|
|
|
|
|
using ATS.NonCustodial.Domain.Shared.AggRootEntities;
|
|
|
|
|
using ATS.NonCustodial.Domain.Shared.AggRootEntities.Dtos;
|
|
|
|
|
using ATS.NonCustodial.Domain.Shared.OrmRepositories.Basic.EfCore;
|
|
|
|
|
using ATS.NonCustodial.DynamicApi;
|
|
|
|
|
using ATS.NonCustodial.DynamicApi.Attributes;
|
|
|
|
|
using ATS.NonCustodial.Shared.Common.UnifiedResults;
|
|
|
|
|
using ATS.NonCustodial.Shared.Extensions;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using SixLabors.ImageSharp.Drawing;
|
|
|
|
|
using Yitter.IdGenerator;
|
|
|
|
|
|
|
|
|
|
namespace ATS.NonCustodial.Application.Impl.Admins
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 单位服务
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// Author:mxg
|
|
|
|
|
/// CreatedTimed:2022-05-15 10:08 PM
|
|
|
|
|
[DynamicApi(Area = "admin")]
|
|
|
|
|
public class UnitcodeService : AdminAppServiceBase, IUnitcodeService, IDynamicApi
|
|
|
|
|
{
|
|
|
|
|
#region Identity
|
|
|
|
|
|
|
|
|
|
private readonly IEfRepository<App_Unitcode?, long> _appUnitcodeRepository;
|
|
|
|
|
private readonly IEfRepository<App_Deptcode?, long> _appDeptcodeRepository;
|
|
|
|
|
private readonly IEfRepository<AppUser?, long> _userRepository;
|
|
|
|
|
|
|
|
|
|
public UnitcodeService(IEfRepository<App_Unitcode?, long> appUnitcodeRepository,
|
|
|
|
|
IEfRepository<App_Deptcode?, long> appDeptcodeRepository,
|
|
|
|
|
IEfRepository<AppUser?, long> userRepository)
|
|
|
|
|
{
|
|
|
|
|
_appUnitcodeRepository = appUnitcodeRepository;
|
|
|
|
|
_appDeptcodeRepository = appDeptcodeRepository;
|
|
|
|
|
_userRepository = userRepository;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion Identity
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询接口
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<IResultOutput> GetAsync(long id)
|
|
|
|
|
{
|
|
|
|
|
var rtn = await base.GetAsync<App_Unitcode, UnitcodeListOutput, long>(_appUnitcodeRepository, id);
|
|
|
|
|
return ResultOutput.Ok(rtn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询单位----列表---stat: 0-监管机构 1-单位管理
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<IResultOutput> GetlistAsync(long stat, long mechanismId)
|
|
|
|
|
{
|
|
|
|
|
var express = await _appUnitcodeRepository.AsQueryable(false, true).WhereIf(mechanismId > 0, a => a.mechanismId == mechanismId).Where(q => q.Stat == stat).ToListAsync();
|
|
|
|
|
var rtnlist = new List<dynamic>();//返回结果
|
|
|
|
|
//foreach (var item in express.Where(q => q.ParentUnitCode == 0||q.ParentUnitCode == null))
|
|
|
|
|
//{
|
|
|
|
|
// rtnlist.Add(new
|
|
|
|
|
// {
|
|
|
|
|
// Id = item.Id,
|
|
|
|
|
// ParentUnitCode = item.ParentUnitCode,
|
|
|
|
|
// UnitCode = item.UnitCode,
|
|
|
|
|
// NameEntity = item.NameEntity,
|
|
|
|
|
// children = pidlist(express.Where(q => q.ParentUnitCode != 0 || q.ParentUnitCode != null).ToList(), item.Id)
|
|
|
|
|
// });
|
|
|
|
|
//}
|
|
|
|
|
return ResultOutput.Ok(express);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询单位列表---树
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<IResultOutput> GetPageAsync(UnitcodeGetPageDto input)
|
|
|
|
|
{
|
|
|
|
|
var rtnlist = new List<dynamic>();//五条件返回结果
|
|
|
|
|
var express = GetExpression(input, _appUnitcodeRepository.AsQueryable(false, true).WhereIf(input.mechanismId.IsNotEmptyOrNull(), a => a.mechanismId == input.mechanismId).Where(q => q.Stat == 1));
|
|
|
|
|
if (express.Count() == 0) return ResultOutput.Ok(rtnlist);
|
|
|
|
|
if (!string.IsNullOrEmpty(input.name)) return ResultOutput.Ok(express);//有条件返回结果
|
|
|
|
|
foreach (var item in await express.Where(q => q.ParentUnitCode == null || q.ParentUnitCode == 0).ToArrayAsync())
|
|
|
|
|
{
|
|
|
|
|
rtnlist.Add(new
|
|
|
|
|
{
|
|
|
|
|
Id = item.Id,
|
|
|
|
|
ParentUnitCode = item.ParentUnitCode,
|
|
|
|
|
UnitCode = item.UnitCode,
|
|
|
|
|
NameEntity = item.NameEntity,
|
|
|
|
|
dw = false,
|
|
|
|
|
children = pidlist(express.Where(q => q.ParentUnitCode != 0 || q.ParentUnitCode != null).ToList(), item.Id)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return ResultOutput.Ok(rtnlist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 角色管理查询监管机构-单位列表---树
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<IResultOutput> GettreedwAsync(UnitcodeGetPageDto input)
|
|
|
|
|
{
|
|
|
|
|
var rtnlist = new List<dynamic>();//五条件返回结果
|
|
|
|
|
//监管机构
|
|
|
|
|
var express = GetExpression(input, _appUnitcodeRepository.AsQueryable(false, true).WhereIf(input.mechanismId.IsNotEmptyOrNull(), a => a.mechanismId == input.mechanismId).Where(q => q.Stat == 0));
|
|
|
|
|
if (express.Count() == 0) return ResultOutput.Ok(rtnlist);
|
|
|
|
|
if (!string.IsNullOrEmpty(input.name)) return ResultOutput.Ok(express);//有条件返回结果
|
|
|
|
|
//单位集合
|
|
|
|
|
var dwgllist = _appUnitcodeRepository.AsQueryable(false, true).Where(q => q.Stat == 1).ToList();
|
|
|
|
|
foreach (var item in await express.Where(q => q.ParentUnitCode == null || q.ParentUnitCode == 0).ToArrayAsync())
|
|
|
|
|
{
|
|
|
|
|
rtnlist.Add(new
|
|
|
|
|
{
|
|
|
|
|
Id = item.Id,
|
|
|
|
|
ParentUnitCode = item.ParentUnitCode,
|
|
|
|
|
UnitCode = item.UnitCode,
|
|
|
|
|
NameEntity = item.NameEntity,
|
|
|
|
|
dw = true,
|
|
|
|
|
children = pidlist(express.Where(q => q.ParentUnitCode != null || q.ParentUnitCode != 0).ToList(), item.Id, dwgllist)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return ResultOutput.Ok(rtnlist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 角色管理查询监管机构-单位-部门列表---树
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<IResultOutput> GettreeAsync(UnitcodeGetPageDto input)
|
|
|
|
|
{
|
|
|
|
|
var rtnlist = new List<dynamic>();//五条件返回结果
|
|
|
|
|
//监管机构
|
|
|
|
|
var express = GetExpression(input, _appUnitcodeRepository.AsQueryable(false, true).WhereIf(input.mechanismId.IsNotEmptyOrNull(), a => a.mechanismId == input.mechanismId).Where(q => q.Stat == 0));
|
|
|
|
|
if (express.Count() == 0) return ResultOutput.Ok(rtnlist);
|
|
|
|
|
if (!string.IsNullOrEmpty(input.name)) return ResultOutput.Ok(express);//有条件返回结果
|
|
|
|
|
//单位集合
|
|
|
|
|
var dwgllist = _appUnitcodeRepository.AsQueryable(false, true).Where(q => q.Stat == 1).ToList();
|
|
|
|
|
//部门集合
|
|
|
|
|
var Deptlist = _appDeptcodeRepository.AsQueryable(false, true).ToList();
|
|
|
|
|
foreach (var item in await express.Where(q => q.ParentUnitCode == null || q.ParentUnitCode == 0).ToArrayAsync())
|
|
|
|
|
{
|
|
|
|
|
rtnlist.Add(new
|
|
|
|
|
{
|
|
|
|
|
Id = item.Id,
|
|
|
|
|
ParentUnitCode = item.ParentUnitCode,
|
|
|
|
|
UnitCode = item.UnitCode,
|
|
|
|
|
NameEntity = item.NameEntity,
|
|
|
|
|
dw = true,
|
|
|
|
|
children = pidlist(express.Where(q => q.ParentUnitCode != null || q.ParentUnitCode != 0).ToList(), item.Id, dwgllist, Deptlist)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return ResultOutput.Ok(rtnlist);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询监管机构列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<IResultOutput> GetjgPageAsync(UnitcodeGetPageDto input)
|
|
|
|
|
{
|
|
|
|
|
var rtnlist = new List<dynamic>();//五条件返回结果
|
|
|
|
|
var express = GetExpression(input, _appUnitcodeRepository.AsQueryable(false, true).Where(q => q.Stat == 0));
|
|
|
|
|
if (express.Count() == 0) return ResultOutput.Ok(rtnlist);
|
|
|
|
|
if (!string.IsNullOrEmpty(input.name)) return ResultOutput.Ok(express);//有条件返回结果
|
|
|
|
|
foreach (var item in await express.Where(q => q.ParentUnitCode == null || q.ParentUnitCode == 0).ToArrayAsync())
|
|
|
|
|
{
|
|
|
|
|
rtnlist.Add(new
|
|
|
|
|
{
|
|
|
|
|
Id = item.Id,
|
|
|
|
|
ParentUnitCode = item.ParentUnitCode,
|
|
|
|
|
UnitCode = item.UnitCode,
|
|
|
|
|
NameEntity = item.NameEntity,
|
|
|
|
|
dw = true,
|
|
|
|
|
children = pidlist(express.Where(q => q.ParentUnitCode != 0 || q.ParentUnitCode != null).ToList(), item.Id)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return ResultOutput.Ok(rtnlist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 循环获取子级
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="list"></param>
|
|
|
|
|
/// <param name="pid"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static List<dynamic> pidlist(List<App_Unitcode> list, long pid, List<App_Unitcode> dwgllist = null, List<App_Deptcode> Deptlist = null)
|
|
|
|
|
{
|
|
|
|
|
var plist = new List<dynamic>();
|
|
|
|
|
var dwgllist1 = new List<App_Unitcode>();
|
|
|
|
|
//通过监管机构查询查询单位
|
|
|
|
|
if (dwgllist != null)
|
|
|
|
|
dwgllist1 = dwgllist.Where(q => q.mechanismId == pid).ToList();
|
|
|
|
|
//通过单位查询部门
|
|
|
|
|
var Deptcode = new List<App_Deptcode>();
|
|
|
|
|
if (Deptlist != null)
|
|
|
|
|
Deptcode = Deptlist.Where(q => q.UnitId == pid).ToList();
|
|
|
|
|
//监管机构查询下级
|
|
|
|
|
foreach (var item in list.Where(q => q.ParentUnitCode == pid).ToList())
|
|
|
|
|
{
|
|
|
|
|
plist.Add(new
|
|
|
|
|
{
|
|
|
|
|
Id = item.Id,
|
|
|
|
|
ParentUnitCode = item.ParentUnitCode,
|
|
|
|
|
NameEntity = item.NameEntity,
|
|
|
|
|
UnitCode = item.UnitCode,
|
|
|
|
|
dw = item.Stat == 0 ? true : false,
|
|
|
|
|
children = pidlist(list, item.Id, dwgllist, Deptlist)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
//单位查找下级
|
|
|
|
|
if (dwgllist1 != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in dwgllist1.Where(q => q.ParentUnitCode == 0 || q.ParentUnitCode == null).ToList())
|
|
|
|
|
{
|
|
|
|
|
plist.Add(new
|
|
|
|
|
{
|
|
|
|
|
Id = item.Id,
|
|
|
|
|
ParentUnitCode = item.ParentUnitCode,
|
|
|
|
|
NameEntity = item.NameEntity,
|
|
|
|
|
UnitCode = item.UnitCode,
|
|
|
|
|
dw = false,
|
|
|
|
|
children = pidlist(dwgllist.Where(q => q.ParentUnitCode != 0 || q.ParentUnitCode != null).ToList(), item.Id, null, Deptlist)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//部门查找下级
|
|
|
|
|
if (Deptlist != null)
|
|
|
|
|
{
|
|
|
|
|
var datalist = Deptcode.Where(q => q.pid == 0 || q.pid == null).ToList();
|
|
|
|
|
foreach (var item in datalist)
|
|
|
|
|
{
|
|
|
|
|
plist.Add(new
|
|
|
|
|
{
|
|
|
|
|
Id = item.Id,
|
|
|
|
|
ParentUnitCode = item.pid,
|
|
|
|
|
NameEntity = item.DeptName,
|
|
|
|
|
UnitCode = item.DeptCode,
|
|
|
|
|
dep = true,
|
|
|
|
|
children = deptpidlist(Deptlist.Where(q => q.pid != 0 || q.pid != null).ToList(), item.Id)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return plist;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 部门循环获取子级
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="list"></param>
|
|
|
|
|
/// <param name="pid"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static List<dynamic> deptpidlist(List<App_Deptcode> list, long pid)
|
|
|
|
|
{
|
|
|
|
|
var plist = new List<dynamic>();
|
|
|
|
|
//部门查询下级
|
|
|
|
|
foreach (var item in list.Where(q => q.pid == pid).ToList())
|
|
|
|
|
{
|
|
|
|
|
plist.Add(new
|
|
|
|
|
{
|
|
|
|
|
Id = item.Id,
|
|
|
|
|
ParentUnitCode = item.pid,
|
|
|
|
|
NameEntity = item.DeptName,
|
|
|
|
|
UnitCode = item.DeptCode,
|
|
|
|
|
dep = true,
|
|
|
|
|
children = deptpidlist(list, item.Id)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return plist;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 添加
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<IResultOutput> AddAsync(UnitcodeAddInput input)
|
|
|
|
|
{
|
|
|
|
|
if (_appUnitcodeRepository.AsQueryable(false, true).Where(q => q.UnitCode == input.UnitCode).Any())
|
|
|
|
|
{
|
|
|
|
|
return input.Stat == 0 ? ResultOutput.NotOk("机构编码已存在") : ResultOutput.NotOk("单位编码已存在");
|
|
|
|
|
}
|
|
|
|
|
var entity = Mapper.Map<App_Unitcode>(input);
|
|
|
|
|
entity.Id = YitIdHelper.NextId();
|
|
|
|
|
entity.Limits = entity.Id.ToString();
|
|
|
|
|
var App_Unitcode = await _appUnitcodeRepository.InsertAsync(entity);
|
|
|
|
|
//添加父级单位权限
|
|
|
|
|
if (entity.ParentUnitCode.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var idList = GetParentUnitIdList((long)entity.ParentUnitCode);
|
|
|
|
|
idList.Add((long)entity.ParentUnitCode);
|
|
|
|
|
for (int i = 0; i < idList.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var parentunit = await _appUnitcodeRepository.FindAsync(idList[i]);
|
|
|
|
|
if (parentunit != null)
|
|
|
|
|
{
|
|
|
|
|
parentunit.Limits += "," + entity.Id;
|
|
|
|
|
await _appUnitcodeRepository.UpdateAsync(parentunit);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ResultOutput.Result(App_Unitcode.Id > 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 修改
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<IResultOutput> UpdateAsync(UnitcodeUpdateInput input)
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
if (!(entity?.Id > 0)) return ResultOutput.NotOk("编辑失败");
|
|
|
|
|
|
|
|
|
|
Mapper.Map(input, entity);
|
|
|
|
|
await _appUnitcodeRepository.UpdateAsync(entity);
|
|
|
|
|
return ResultOutput.Ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 批量彻底删除
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<IResultOutput> DeleteAsync(BatchIdsInput input)
|
|
|
|
|
{
|
|
|
|
|
Uow.BeginTransaction();
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < input.Ids.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
//获取该单位下的所有子单位id
|
|
|
|
|
var idlist = GetUnitIdList(input.Ids[i]);
|
|
|
|
|
//校验该单位下是否存在用户账户
|
|
|
|
|
if (_userRepository.AsQueryable(false, true).Where(q => idlist.Contains(q.UnitId ?? -1)).Any())
|
|
|
|
|
{
|
|
|
|
|
return ResultOutput.NotOk("该单位下存在用户账户,无法删除");
|
|
|
|
|
}
|
|
|
|
|
var idParentList = GetParentUnitIdList(input.Ids[i]);
|
|
|
|
|
//删除
|
|
|
|
|
await _appUnitcodeRepository.DeleteAsync(w => idlist.Contains(w.Id));
|
|
|
|
|
//获取该单位的所有父级单位id
|
|
|
|
|
for (int j = 0; j < idParentList.Count; j++)
|
|
|
|
|
{
|
|
|
|
|
var parentunit = await _appUnitcodeRepository.FindAsync(idParentList[j]);
|
|
|
|
|
if (parentunit != null)
|
|
|
|
|
{
|
|
|
|
|
// 步骤1:统一分隔符并分割字符串
|
|
|
|
|
var numbers = parentunit.Limits
|
|
|
|
|
.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) // 按英文逗号分割
|
|
|
|
|
.Select(s => long.Parse(s.Trim())); // 转换为整数并去除空格
|
|
|
|
|
|
|
|
|
|
// 步骤2:过滤掉存在于 filterList 中的数字
|
|
|
|
|
var filteredNumbers = numbers.Where(n => !idlist.Contains(n)).ToList();
|
|
|
|
|
|
|
|
|
|
// 步骤3:重新拼接为字符串
|
|
|
|
|
string result = string.Join(",", filteredNumbers);
|
|
|
|
|
|
|
|
|
|
parentunit.Limits = result;
|
|
|
|
|
await _appUnitcodeRepository.UpdateAsync(parentunit);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//删除
|
|
|
|
|
// await _appUnitcodeRepository.DeleteAsync(w => input.Ids.Contains(w.Id));
|
|
|
|
|
//删除
|
|
|
|
|
// await _appUnitcodeRepository.DeleteAsync(w => input.Ids.Contains((long)w.ParentUnitCode));
|
|
|
|
|
}
|
|
|
|
|
await Uow.CommitAsync();
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 递归查找该单位的所有父级单位
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="unitId">单位id</param>
|
|
|
|
|
/// <returns>单位id集合</returns>
|
|
|
|
|
private List<long> GetParentUnitIdList(long unitId)
|
|
|
|
|
{
|
|
|
|
|
List<long> idList = new List<long>();
|
|
|
|
|
var unitlist = _appUnitcodeRepository.AsQueryable(false, true).Where(q => q.Id == unitId).ToList();
|
|
|
|
|
foreach (var item in unitlist)
|
|
|
|
|
{
|
|
|
|
|
if (item != null && item.ParentUnitCode.HasValue)
|
|
|
|
|
{
|
|
|
|
|
idList.Add((long)item.ParentUnitCode);
|
|
|
|
|
var idlist = GetParentUnitIdList((long)item.ParentUnitCode);
|
|
|
|
|
idList.AddRange(idlist);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return idList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Private
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询条件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pageInput"></param>
|
|
|
|
|
/// <param name="query"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private IQueryable<App_Unitcode> GetExpression(UnitcodeGetPageDto pageInput, IQueryable<App_Unitcode?> query)
|
|
|
|
|
{
|
|
|
|
|
var key = pageInput?.name;
|
|
|
|
|
|
|
|
|
|
query = query
|
|
|
|
|
.WhereIf(key.NotNull(), a => a.NameEntity.Contains(key) || a.UnitIsReferToAs.Contains(key));
|
|
|
|
|
return query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion Private
|
|
|
|
|
}
|
|
|
|
|
}
|