You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
364 lines
15 KiB
364 lines
15 KiB
|
3 months ago
|
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.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.Business.MaterialManager;
|
||
|
|
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.Attributes;
|
||
|
|
using ATS.NonCustodial.Shared.Common.Enums;
|
||
|
|
using ATS.NonCustodial.Shared.Common.UnifiedResults;
|
||
|
|
using ATS.NonCustodial.Shared.Extensions;
|
||
|
|
using ATS.NonCustodial.Shared.Extensions.AdvancedQuery;
|
||
|
|
using AutoMapper.QueryableExtensions;
|
||
|
|
using Microsoft.AspNetCore.Mvc;
|
||
|
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
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;
|
||
|
|
|
||
|
|
public UnitcodeService(IEfRepository<App_Unitcode?, long> appUnitcodeRepository,
|
||
|
|
IEfRepository<App_Deptcode?, long> appDeptcodeRepository)
|
||
|
|
{
|
||
|
|
_appUnitcodeRepository = appUnitcodeRepository;
|
||
|
|
_appDeptcodeRepository = appDeptcodeRepository;
|
||
|
|
}
|
||
|
|
|
||
|
|
#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())
|
||
|
|
{
|
||
|
|
if (input.Stat == 0)
|
||
|
|
return ResultOutput.NotOk("机构编码已存在");
|
||
|
|
else
|
||
|
|
return ResultOutput.NotOk("单位编码已存在");
|
||
|
|
}
|
||
|
|
var entity = Mapper.Map<App_Unitcode>(input);
|
||
|
|
entity.Id = YitIdHelper.NextId();
|
||
|
|
var App_Unitcode = await _appUnitcodeRepository.InsertAsync(entity);
|
||
|
|
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 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();
|
||
|
|
{
|
||
|
|
//删除
|
||
|
|
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();
|
||
|
|
}
|
||
|
|
#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
|
||
|
|
}
|
||
|
|
}
|