|
|
|
@ -2,23 +2,17 @@ |
|
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.Unitcode; |
|
|
|
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.Input; |
|
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.Unitcode.Output; |
|
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.Unitcode.Output; |
|
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Business.MaterialManager.Template.Input; |
|
|
|
|
|
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Business.MaterialManager.Template.Output; |
|
|
|
|
|
|
|
using ATS.NonCustodial.Domain.Entities.Admins; |
|
|
|
using ATS.NonCustodial.Domain.Entities.Admins; |
|
|
|
using ATS.NonCustodial.Domain.Entities.Business.MaterialManager; |
|
|
|
using ATS.NonCustodial.Domain.Shared.AggRootEntities; |
|
|
|
using ATS.NonCustodial.Domain.Shared.AggRootEntities.Dtos; |
|
|
|
using ATS.NonCustodial.Domain.Shared.AggRootEntities.Dtos; |
|
|
|
using ATS.NonCustodial.Domain.Shared.OrmRepositories.Basic.EfCore; |
|
|
|
using ATS.NonCustodial.Domain.Shared.OrmRepositories.Basic.EfCore; |
|
|
|
using ATS.NonCustodial.DynamicApi; |
|
|
|
using ATS.NonCustodial.DynamicApi; |
|
|
|
using ATS.NonCustodial.DynamicApi.Attributes; |
|
|
|
using ATS.NonCustodial.DynamicApi.Attributes; |
|
|
|
using ATS.NonCustodial.Shared.Common.Attributes; |
|
|
|
|
|
|
|
using ATS.NonCustodial.Shared.Common.Enums; |
|
|
|
|
|
|
|
using ATS.NonCustodial.Shared.Common.UnifiedResults; |
|
|
|
using ATS.NonCustodial.Shared.Common.UnifiedResults; |
|
|
|
using ATS.NonCustodial.Shared.Extensions; |
|
|
|
using ATS.NonCustodial.Shared.Extensions; |
|
|
|
using ATS.NonCustodial.Shared.Extensions.AdvancedQuery; |
|
|
|
|
|
|
|
using AutoMapper.QueryableExtensions; |
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using System.Linq; |
|
|
|
using SixLabors.ImageSharp.Drawing; |
|
|
|
using Yitter.IdGenerator; |
|
|
|
using Yitter.IdGenerator; |
|
|
|
|
|
|
|
|
|
|
|
namespace ATS.NonCustodial.Application.Impl.Admins |
|
|
|
namespace ATS.NonCustodial.Application.Impl.Admins |
|
|
|
@ -65,9 +59,9 @@ namespace ATS.NonCustodial.Application.Impl.Admins |
|
|
|
/// <param name="input"></param> |
|
|
|
/// <param name="input"></param> |
|
|
|
/// <returns></returns> |
|
|
|
/// <returns></returns> |
|
|
|
[HttpGet] |
|
|
|
[HttpGet] |
|
|
|
public async Task<IResultOutput> GetlistAsync(long stat,long mechanismId) |
|
|
|
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 express = await _appUnitcodeRepository.AsQueryable(false, true).WhereIf(mechanismId > 0, a => a.mechanismId == mechanismId).Where(q => q.Stat == stat).ToListAsync(); |
|
|
|
var rtnlist = new List<dynamic>();//返回结果 |
|
|
|
var rtnlist = new List<dynamic>();//返回结果 |
|
|
|
//foreach (var item in express.Where(q => q.ParentUnitCode == 0||q.ParentUnitCode == null)) |
|
|
|
//foreach (var item in express.Where(q => q.ParentUnitCode == 0||q.ParentUnitCode == null)) |
|
|
|
//{ |
|
|
|
//{ |
|
|
|
@ -92,10 +86,10 @@ namespace ATS.NonCustodial.Application.Impl.Admins |
|
|
|
public async Task<IResultOutput> GetPageAsync(UnitcodeGetPageDto input) |
|
|
|
public async Task<IResultOutput> GetPageAsync(UnitcodeGetPageDto input) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var rtnlist = new List<dynamic>();//五条件返回结果 |
|
|
|
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)); |
|
|
|
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 (express.Count() == 0) return ResultOutput.Ok(rtnlist); |
|
|
|
if (!string.IsNullOrEmpty(input.name)) return ResultOutput.Ok(express);//有条件返回结果 |
|
|
|
if (!string.IsNullOrEmpty(input.name)) return ResultOutput.Ok(express);//有条件返回结果 |
|
|
|
foreach (var item in await express.Where(q => q.ParentUnitCode == null|| q.ParentUnitCode == 0).ToArrayAsync()) |
|
|
|
foreach (var item in await express.Where(q => q.ParentUnitCode == null || q.ParentUnitCode == 0).ToArrayAsync()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
rtnlist.Add(new |
|
|
|
rtnlist.Add(new |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -104,7 +98,7 @@ namespace ATS.NonCustodial.Application.Impl.Admins |
|
|
|
UnitCode = item.UnitCode, |
|
|
|
UnitCode = item.UnitCode, |
|
|
|
NameEntity = item.NameEntity, |
|
|
|
NameEntity = item.NameEntity, |
|
|
|
dw = false, |
|
|
|
dw = false, |
|
|
|
children = pidlist(express.Where(q => q.ParentUnitCode != 0||q.ParentUnitCode != null).ToList(),item.Id) |
|
|
|
children = pidlist(express.Where(q => q.ParentUnitCode != 0 || q.ParentUnitCode != null).ToList(), item.Id) |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
return ResultOutput.Ok(rtnlist); |
|
|
|
return ResultOutput.Ok(rtnlist); |
|
|
|
@ -182,7 +176,7 @@ namespace ATS.NonCustodial.Application.Impl.Admins |
|
|
|
public async Task<IResultOutput> GetjgPageAsync(UnitcodeGetPageDto input) |
|
|
|
public async Task<IResultOutput> GetjgPageAsync(UnitcodeGetPageDto input) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var rtnlist = new List<dynamic>();//五条件返回结果 |
|
|
|
var rtnlist = new List<dynamic>();//五条件返回结果 |
|
|
|
var express = GetExpression(input, _appUnitcodeRepository.AsQueryable(false, true).Where(q=>q.Stat==0)); |
|
|
|
var express = GetExpression(input, _appUnitcodeRepository.AsQueryable(false, true).Where(q => q.Stat == 0)); |
|
|
|
if (express.Count() == 0) return ResultOutput.Ok(rtnlist); |
|
|
|
if (express.Count() == 0) return ResultOutput.Ok(rtnlist); |
|
|
|
if (!string.IsNullOrEmpty(input.name)) return ResultOutput.Ok(express);//有条件返回结果 |
|
|
|
if (!string.IsNullOrEmpty(input.name)) return ResultOutput.Ok(express);//有条件返回结果 |
|
|
|
foreach (var item in await express.Where(q => q.ParentUnitCode == null || q.ParentUnitCode == 0).ToArrayAsync()) |
|
|
|
foreach (var item in await express.Where(q => q.ParentUnitCode == null || q.ParentUnitCode == 0).ToArrayAsync()) |
|
|
|
@ -206,19 +200,19 @@ namespace ATS.NonCustodial.Application.Impl.Admins |
|
|
|
/// <param name="list"></param> |
|
|
|
/// <param name="list"></param> |
|
|
|
/// <param name="pid"></param> |
|
|
|
/// <param name="pid"></param> |
|
|
|
/// <returns></returns> |
|
|
|
/// <returns></returns> |
|
|
|
public static List<dynamic> pidlist(List<App_Unitcode> list,long pid, List<App_Unitcode> dwgllist=null,List<App_Deptcode> Deptlist = null) |
|
|
|
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 plist = new List<dynamic>(); |
|
|
|
var dwgllist1 = new List<App_Unitcode>(); |
|
|
|
var dwgllist1 = new List<App_Unitcode>(); |
|
|
|
//通过监管机构查询查询单位 |
|
|
|
//通过监管机构查询查询单位 |
|
|
|
if (dwgllist!=null) |
|
|
|
if (dwgllist != null) |
|
|
|
dwgllist1 = dwgllist.Where(q => q.mechanismId == pid).ToList(); |
|
|
|
dwgllist1 = dwgllist.Where(q => q.mechanismId == pid).ToList(); |
|
|
|
//通过单位查询部门 |
|
|
|
//通过单位查询部门 |
|
|
|
var Deptcode = new List<App_Deptcode>(); |
|
|
|
var Deptcode = new List<App_Deptcode>(); |
|
|
|
if (Deptlist != null) |
|
|
|
if (Deptlist != null) |
|
|
|
Deptcode = Deptlist.Where(q => q.UnitId == pid).ToList(); |
|
|
|
Deptcode = Deptlist.Where(q => q.UnitId == pid).ToList(); |
|
|
|
//监管机构查询下级 |
|
|
|
//监管机构查询下级 |
|
|
|
foreach (var item in list.Where(q=>q.ParentUnitCode==pid).ToList()) |
|
|
|
foreach (var item in list.Where(q => q.ParentUnitCode == pid).ToList()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
plist.Add(new |
|
|
|
plist.Add(new |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -231,7 +225,7 @@ namespace ATS.NonCustodial.Application.Impl.Admins |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
//单位查找下级 |
|
|
|
//单位查找下级 |
|
|
|
if (dwgllist1 != null) |
|
|
|
if (dwgllist1 != null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
foreach (var item in dwgllist1.Where(q => q.ParentUnitCode == 0 || q.ParentUnitCode == null).ToList()) |
|
|
|
foreach (var item in dwgllist1.Where(q => q.ParentUnitCode == 0 || q.ParentUnitCode == null).ToList()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -241,15 +235,15 @@ namespace ATS.NonCustodial.Application.Impl.Admins |
|
|
|
ParentUnitCode = item.ParentUnitCode, |
|
|
|
ParentUnitCode = item.ParentUnitCode, |
|
|
|
NameEntity = item.NameEntity, |
|
|
|
NameEntity = item.NameEntity, |
|
|
|
UnitCode = item.UnitCode, |
|
|
|
UnitCode = item.UnitCode, |
|
|
|
dw =false, |
|
|
|
dw = false, |
|
|
|
children = pidlist(dwgllist.Where(q => q.ParentUnitCode != 0 || q.ParentUnitCode != null).ToList(), item.Id,null, Deptlist) |
|
|
|
children = pidlist(dwgllist.Where(q => q.ParentUnitCode != 0 || q.ParentUnitCode != null).ToList(), item.Id, null, Deptlist) |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//部门查找下级 |
|
|
|
//部门查找下级 |
|
|
|
if (Deptlist != null) |
|
|
|
if (Deptlist != null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var datalist= Deptcode.Where(q => q.pid == 0 || q.pid == null).ToList(); |
|
|
|
var datalist = Deptcode.Where(q => q.pid == 0 || q.pid == null).ToList(); |
|
|
|
foreach (var item in datalist) |
|
|
|
foreach (var item in datalist) |
|
|
|
{ |
|
|
|
{ |
|
|
|
plist.Add(new |
|
|
|
plist.Add(new |
|
|
|
@ -298,16 +292,29 @@ namespace ATS.NonCustodial.Application.Impl.Admins |
|
|
|
/// <returns></returns> |
|
|
|
/// <returns></returns> |
|
|
|
public async Task<IResultOutput> AddAsync(UnitcodeAddInput input) |
|
|
|
public async Task<IResultOutput> AddAsync(UnitcodeAddInput input) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (_appUnitcodeRepository.AsQueryable(false, true).Where(q => q.UnitCode == input.UnitCode).Any()) |
|
|
|
if (_appUnitcodeRepository.AsQueryable(false, true).Where(q => q.UnitCode == input.UnitCode).Any()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (input.Stat == 0) |
|
|
|
return input.Stat == 0 ? ResultOutput.NotOk("机构编码已存在") : ResultOutput.NotOk("单位编码已存在"); |
|
|
|
return ResultOutput.NotOk("机构编码已存在"); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return ResultOutput.NotOk("单位编码已存在"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
var entity = Mapper.Map<App_Unitcode>(input); |
|
|
|
var entity = Mapper.Map<App_Unitcode>(input); |
|
|
|
entity.Id = YitIdHelper.NextId(); |
|
|
|
entity.Id = YitIdHelper.NextId(); |
|
|
|
|
|
|
|
entity.Limits = entity.Id.ToString(); |
|
|
|
var App_Unitcode = await _appUnitcodeRepository.InsertAsync(entity); |
|
|
|
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); |
|
|
|
return ResultOutput.Result(App_Unitcode.Id > 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -345,20 +352,44 @@ namespace ATS.NonCustodial.Application.Impl.Admins |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (int i = 0; i < input.Ids.Count; i++) |
|
|
|
for (int i = 0; i < input.Ids.Count; i++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var idlist= GetUnitIdList(input.Ids[i]); |
|
|
|
//获取该单位下的所有子单位id |
|
|
|
|
|
|
|
var idlist = GetUnitIdList(input.Ids[i]); |
|
|
|
//校验该单位下是否存在用户账户 |
|
|
|
//校验该单位下是否存在用户账户 |
|
|
|
if (_userRepository.AsQueryable(false, true).Where(q => idlist.Contains(q.UnitId??-1)).Any()) |
|
|
|
if (_userRepository.AsQueryable(false, true).Where(q => idlist.Contains(q.UnitId ?? -1)).Any()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return ResultOutput.NotOk("该单位下存在用户账户,无法删除"); |
|
|
|
return ResultOutput.NotOk("该单位下存在用户账户,无法删除"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var idParentList = GetParentUnitIdList(input.Ids[i]); |
|
|
|
//删除 |
|
|
|
//删除 |
|
|
|
await _appUnitcodeRepository.DeleteAsync(w => idlist.Contains(w.Id)); |
|
|
|
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(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(); |
|
|
|
@ -369,11 +400,11 @@ namespace ATS.NonCustodial.Application.Impl.Admins |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
/// <param name="unitId">单位id</param> |
|
|
|
/// <param name="unitId">单位id</param> |
|
|
|
/// <returns>单位id集合</returns> |
|
|
|
/// <returns>单位id集合</returns> |
|
|
|
private List<long> GetUnitIdList(long unitId) |
|
|
|
private List<long> GetUnitIdList(long unitId) |
|
|
|
{ |
|
|
|
{ |
|
|
|
List<long> idList=new List<long>(); |
|
|
|
List<long> idList = new List<long>(); |
|
|
|
idList.Add(unitId); |
|
|
|
idList.Add(unitId); |
|
|
|
var unitlist=_appUnitcodeRepository.AsQueryable(false, true).Where(q => q.ParentUnitCode == unitId).ToList() ; |
|
|
|
var unitlist = _appUnitcodeRepository.AsQueryable(false, true).Where(q => q.ParentUnitCode == unitId).ToList(); |
|
|
|
foreach (var item in unitlist) |
|
|
|
foreach (var item in unitlist) |
|
|
|
{ |
|
|
|
{ |
|
|
|
idList.Add(item.Id); |
|
|
|
idList.Add(item.Id); |
|
|
|
@ -382,6 +413,27 @@ namespace ATS.NonCustodial.Application.Impl.Admins |
|
|
|
} |
|
|
|
} |
|
|
|
return 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 |
|
|
|
#region Private |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
|