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.
431 lines
17 KiB
431 lines
17 KiB
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
using Shentun.Peis.CustomerOrgRegisters;
|
|
using Shentun.Peis.Enums;
|
|
using Shentun.Peis.HelperDto;
|
|
using Shentun.Peis.Models;
|
|
using Shentun.Peis.OrganizationUnits;
|
|
using Shentun.Peis.PersonnelTypes;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Volo.Abp;
|
|
using Volo.Abp.Application.Dtos;
|
|
using Volo.Abp.Application.Services;
|
|
using Volo.Abp.Domain.Entities;
|
|
using Volo.Abp.Domain.Repositories;
|
|
using Volo.Abp.Identity;
|
|
using Volo.Abp.ObjectMapping;
|
|
|
|
namespace Shentun.Peis.CustomerOrgs
|
|
{
|
|
|
|
/// <summary>
|
|
/// 团检单位设置
|
|
/// </summary>
|
|
[ApiExplorerSettings(GroupName = "Work")]
|
|
[Authorize]
|
|
public class CustomerOrgAppService : CrudAppService<
|
|
CustomerOrg, //The Book entity
|
|
CustomerOrgDto, //Used to show books
|
|
Guid, //Primary key of the book entity
|
|
PagedAndSortedResultRequestDto, //Used for paging/sorting
|
|
CreateCustomerOrgDto,
|
|
UpdateCustomerOrgDto>
|
|
{
|
|
private readonly IRepository<IdentityUser, Guid> _userRepository;
|
|
private readonly IRepository<CustomerOrgRegister, Guid> _customerOrgRegisterRepository;
|
|
private readonly CustomerOrgManager _manager;
|
|
private readonly CustomerOrgRegisterManager _customerOrgRegisterManager;
|
|
private readonly CacheService _cacheService;
|
|
private readonly IMemoryCache _customerOrgCache;
|
|
public CustomerOrgAppService(
|
|
IRepository<CustomerOrg, Guid> repository,
|
|
IRepository<IdentityUser, Guid> userRepository,
|
|
CustomerOrgManager manager,
|
|
CustomerOrgRegisterManager customerOrgRegisterManager,
|
|
IRepository<CustomerOrgRegister, Guid> customerOrgRegisterRepository,
|
|
CacheService cacheService,
|
|
IMemoryCache customerOrgCache)
|
|
: base(repository)
|
|
{
|
|
_userRepository = userRepository;
|
|
_manager = manager;
|
|
this._customerOrgRegisterManager = customerOrgRegisterManager;
|
|
this._customerOrgRegisterRepository = customerOrgRegisterRepository;
|
|
_cacheService = cacheService;
|
|
_customerOrgCache = customerOrgCache;
|
|
}
|
|
/// <summary>
|
|
/// 获取通过主键
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public override async Task<CustomerOrgDto> GetAsync(Guid id)
|
|
{
|
|
var entityDto = await base.GetAsync(id);
|
|
entityDto.CreatorName = await _cacheService.GetSurnameAsync(entityDto.CreatorId);
|
|
entityDto.LastModifierName = await _cacheService.GetSurnameAsync(entityDto.LastModifierId);
|
|
return entityDto;
|
|
}
|
|
//[AllowAnonymous]
|
|
[HttpPost("api/app/CustomerOrg/GetById")]
|
|
public async Task<CustomerOrgDto> GetByIdAsync(CustomerOrgIdInputDto input)
|
|
{
|
|
var entity = await Repository.GetAsync(input.CustomerOrgId);
|
|
var entityDto = ObjectMapper.Map<CustomerOrg, CustomerOrgDto>(entity);
|
|
entityDto.CreatorName = await _cacheService.GetSurnameAsync(entityDto.CreatorId);
|
|
entityDto.LastModifierName = await _cacheService.GetSurnameAsync(entityDto.LastModifierId);
|
|
return entityDto;
|
|
}
|
|
/// <summary>
|
|
/// 获取所有一级子单位
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("api/app/CustomerOrg/GetChildCustomerOrgsById")]
|
|
public async Task<List<CustomerOrgDto>> GetChildCustomerOrgsByIdAsync(CustomerOrgIdInputDto input)
|
|
{
|
|
var list = await Repository.GetListAsync(o => o.ParentId == input.CustomerOrgId);
|
|
var dtos = new List<CustomerOrgDto>();
|
|
foreach (var customerOrg in list)
|
|
{
|
|
var entityDto = ObjectMapper.Map<CustomerOrg, CustomerOrgDto>(customerOrg);
|
|
entityDto.CreatorName = await _cacheService.GetSurnameAsync(entityDto.CreatorId);
|
|
entityDto.LastModifierName = await _cacheService.GetSurnameAsync(entityDto.LastModifierId);
|
|
dtos.Add(entityDto);
|
|
}
|
|
return dtos;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取列表 团检单位设置
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[RemoteService(false)]
|
|
public override async Task<PagedResultDto<CustomerOrgDto>> GetListAsync(PagedAndSortedResultRequestDto input)
|
|
{
|
|
return await base.GetListAsync(input);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取列表 团检单位设置 可以带名称搜索
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<CustomerOrgDto>> GetListInFilterAsync(GetListDto input)
|
|
{
|
|
var oldlist = await Repository.GetQueryableAsync();
|
|
if (!string.IsNullOrEmpty(input.Filter))
|
|
oldlist = oldlist.Where(m => m.DisplayName.Contains(input.Filter));
|
|
|
|
if (input.IsHidePerson == 1)
|
|
oldlist = oldlist.Where(m => m.Id != GuidFlag.PersonCustomerOrgId);
|
|
|
|
|
|
var entdto = oldlist.Select(s => new CustomerOrgDto
|
|
{
|
|
CreationTime = s.CreationTime,
|
|
CreatorId = s.CreatorId,
|
|
DisplayName = s.DisplayName,
|
|
DisplayOrder = s.DisplayOrder,
|
|
Id = s.Id,
|
|
LastModificationTime = s.LastModificationTime,
|
|
LastModifierId = s.LastModifierId,
|
|
SimpleCode = s.SimpleCode,
|
|
Accounts = s.Accounts,
|
|
Telephone = s.Telephone,
|
|
IsActive = s.IsActive,
|
|
ShortName = s.ShortName,
|
|
Remark = s.Remark,
|
|
PostalCode = s.PostalCode,
|
|
PathCode = s.PathCode,
|
|
ParentId = s.ParentId,
|
|
OrgTypeId = s.OrgTypeId,
|
|
Address = s.Address,
|
|
Bank = s.Bank,
|
|
Fax = s.Fax,
|
|
InvoiceName = s.InvoiceName,
|
|
IsLock = s.IsLock,
|
|
SalesPerson = s.SalesPerson,
|
|
SalesPersonPhone = s.SalesPersonPhone,
|
|
MedicalCenterId = s.MedicalCenterId,
|
|
CountryOrgCode = s.CountryOrgCode,
|
|
CreatorName = _cacheService.GetSurnameAsync(s.CreatorId).Result,
|
|
LastModifierName = _cacheService.GetSurnameAsync(s.LastModifierId).Result
|
|
}).OrderBy(m => m.DisplayOrder).ToList();
|
|
|
|
|
|
|
|
return entdto;
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建单位 单位为树型结构 一级目录默认生成体检次数
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("api/app/customerorg/create")]
|
|
public override async Task<CustomerOrgDto> CreateAsync(CreateCustomerOrgDto input)
|
|
{
|
|
var createEntity = ObjectMapper.Map<CreateCustomerOrgDto, CustomerOrg>(input);
|
|
var entity = await _manager.CreateAsync(createEntity);
|
|
entity = await Repository.InsertAsync(entity);
|
|
if (entity != null && (input.ParentId == null || input.ParentId == Guid.Empty))
|
|
{
|
|
//生成体检次数
|
|
var customerOrgRegisterEntity = await _customerOrgRegisterManager.CreateAsync(entity.Id);
|
|
await _customerOrgRegisterRepository.InsertAsync(customerOrgRegisterEntity);
|
|
}
|
|
_customerOrgCache.Set(entity.Id, entity);
|
|
var dto = ObjectMapper.Map<CustomerOrg, CustomerOrgDto>(entity);
|
|
return dto;
|
|
}
|
|
/// <summary>
|
|
/// 更新
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
public override async Task<CustomerOrgDto> UpdateAsync(Guid id, UpdateCustomerOrgDto input)
|
|
{
|
|
var entity = await Repository.GetAsync(id);
|
|
var sourceEntity = ObjectMapper.Map<UpdateCustomerOrgDto, CustomerOrg>(input);
|
|
await _manager.UpdateAsync(sourceEntity, entity);
|
|
entity = await Repository.UpdateAsync(entity);
|
|
_customerOrgCache.Set(entity.Id, entity);
|
|
return ObjectMapper.Map<CustomerOrg, CustomerOrgDto>(entity);
|
|
}
|
|
/// <summary>
|
|
/// 删除
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public override async Task DeleteAsync(Guid id)
|
|
{
|
|
|
|
var CustomerOrgChildrenIds = await _manager.GetCustomerOrgChildrenId(id); //遍历找出下级ID
|
|
if (CustomerOrgChildrenIds.Any())
|
|
{
|
|
foreach (var CustomerOrgChildrenId in CustomerOrgChildrenIds)
|
|
{
|
|
if (CustomerOrgChildrenId != null)
|
|
{
|
|
await _manager.CheckAndDeleteAsync(CustomerOrgChildrenId.Value);
|
|
_customerOrgCache.Remove(CustomerOrgChildrenId);
|
|
}
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
throw new UserFriendlyException("参数有误");
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 修改排序 置顶,置底
|
|
/// </summary>
|
|
/// <param name="id">需要修改的ID</param>
|
|
/// <param name="SortType">修改方式:1 置顶 2 置底</param>
|
|
/// <returns></returns>
|
|
[HttpPut("api/app/customerorg/updatemanysort")]
|
|
public async Task UpdateManySortAsync(Guid id, int SortType)
|
|
{
|
|
await _manager.UpdateManySortAsync(id, SortType);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改排序 拖拽
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPut("api/app/customerorg/updatesortmany")]
|
|
public async Task UpdateSortManyAsync(UpdateSortManyDto input)
|
|
{
|
|
await _manager.UpdateSortManyAsync(input);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取一级目录 单位列表
|
|
/// </summary>
|
|
/// <param name="Filter">名字搜索,支持模糊查找</param>
|
|
/// <returns></returns>
|
|
public async Task<List<CustomerOrg>> GetParentAllAsync(string Filter)
|
|
{
|
|
var dataList = await Repository.GetListAsync(m => m.ParentId == null || m.ParentId == Guid.Empty);
|
|
if (dataList.Count > 0 && !string.IsNullOrEmpty(Filter))
|
|
dataList = dataList.Where(m => m.DisplayName.Contains(Filter) || m.ShortName.Contains(Filter)).ToList();
|
|
|
|
return dataList.OrderBy(o => o.DisplayOrder).ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取单位树型结构
|
|
/// </summary>
|
|
/// <param name="IsHidePerson">是否隐藏个人信息 1 隐藏 0不隐藏 默认为0</param>
|
|
/// <param name="Filter">名字搜索,支持模糊查找</param>
|
|
/// <returns></returns>
|
|
[HttpGet("api/app/customerorg/getbycodeall")]
|
|
public async Task<List<CustomerOrgTreeChildDto>> GetByCodeAllAsync(string Filter, int IsHidePerson = 0)
|
|
{
|
|
|
|
List<CustomerOrgTreeChildDto> result = new List<CustomerOrgTreeChildDto>();
|
|
|
|
var customerOrgPerson = await Repository.FirstOrDefaultAsync(f => f.Id == GuidFlag.PersonCustomerOrgId);
|
|
|
|
var dataList = (await Repository.GetQueryableAsync());
|
|
if (!string.IsNullOrEmpty(Filter))
|
|
dataList = dataList.Where(m => m.DisplayName.Contains(Filter) || m.ShortName.Contains(Filter));
|
|
if (IsHidePerson == 1)
|
|
{
|
|
dataList = dataList.Where(m => m.Id != GuidFlag.PersonCustomerOrgId);
|
|
}
|
|
else
|
|
{
|
|
if (customerOrgPerson != null)
|
|
{
|
|
result.Add(new CustomerOrgTreeChildDto
|
|
{
|
|
Code = customerOrgPerson.PathCode,
|
|
CustomerOrgCode = customerOrgPerson.CustomerOrgCode,
|
|
DisplayName = customerOrgPerson.DisplayName,
|
|
DisplayOrder = customerOrgPerson.DisplayOrder,
|
|
Id = customerOrgPerson.Id,
|
|
ParentId = customerOrgPerson.ParentId,
|
|
ShortName = customerOrgPerson.ShortName,
|
|
SimpleCode = customerOrgPerson.SimpleCode,
|
|
TreeChildren = null
|
|
});
|
|
}
|
|
}
|
|
|
|
var customerOrgList = dataList.ToList();
|
|
|
|
var items = from p in customerOrgList.Where(m => m.Id != GuidFlag.PersonCustomerOrgId).OrderByDescending(o => o.DisplayOrder).AsParallel()
|
|
select new CustomerOrgTreeChildDto()
|
|
{
|
|
Id = p.Id,
|
|
ParentId = p.ParentId,
|
|
Code = p.PathCode,
|
|
DisplayName = p.DisplayName,
|
|
SimpleCode = p.SimpleCode,
|
|
ShortName = p.ShortName,
|
|
CustomerOrgCode = p.CustomerOrgCode,
|
|
TreeChildren = new List<CustomerOrgTreeChildDto>()
|
|
};
|
|
var customerOrgTreeChildList = GetTree(items.ToList(), null);
|
|
|
|
|
|
//var tree1 = items.Where(m => m.ParentId == null).ToList();
|
|
|
|
//foreach (var item1 in tree1)
|
|
//{
|
|
// item1.TreeChildren = items.Where(m => m.ParentId == item1.Id).ToList();
|
|
|
|
// foreach (var item2 in item1.TreeChildren)
|
|
// {
|
|
// item2.TreeChildren = items.Where(m => m.ParentId == item2.Id).ToList();
|
|
|
|
// foreach (var item3 in item2.TreeChildren)
|
|
// {
|
|
// item3.TreeChildren = items.Where(m => m.ParentId == item3.Id).ToList();
|
|
|
|
// foreach (var item4 in item3.TreeChildren)
|
|
// {
|
|
// item4.TreeChildren = items.Where(m => m.ParentId == item4.Id).ToList();
|
|
// }
|
|
// }
|
|
// }
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
result.AddRange(customerOrgTreeChildList);
|
|
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 使用parentId进行递归
|
|
/// </summary>
|
|
/// <param name="items"></param>
|
|
/// <param name="parentId"></param>
|
|
/// <returns></returns>
|
|
private List<CustomerOrgTreeChildDto> GetTree(List<CustomerOrgTreeChildDto> items, Guid? parentId)
|
|
{
|
|
return (from p in items.AsParallel()
|
|
where p.ParentId == parentId
|
|
let subs = GetTree(items, p.Id)
|
|
select new CustomerOrgTreeChildDto()
|
|
{
|
|
Id = p.Id,
|
|
ParentId = p.ParentId,
|
|
Code = p.Code,
|
|
DisplayName = p.DisplayName,
|
|
SimpleCode = p.SimpleCode,
|
|
ShortName = p.ShortName,
|
|
CustomerOrgCode = p.CustomerOrgCode,
|
|
TreeChildren = subs.ToList()
|
|
}
|
|
).ToList();
|
|
}
|
|
|
|
|
|
///// <summary>
|
|
///// 使用Code进行递归
|
|
///// </summary>
|
|
///// <param name="items"></param>
|
|
///// <param name="deep"></param>
|
|
///// <param name="prefix"></param>
|
|
///// <returns></returns>
|
|
//private List<CustomerOrgTreeChildDto> GetTree(List<CustomerOrgTreeChildDto> items, int deep, string prefix)
|
|
//{
|
|
// return (from p in items
|
|
// where p.Code.StartsWith(prefix) && p.Code.Count(a => a == '.') == deep
|
|
// let subs = GetTree(items, deep + 1, p.Code)
|
|
// select new CustomerOrgTreeChildDto()
|
|
// {
|
|
// Id = p.Id,
|
|
// ParentId = p.ParentId,
|
|
// Code = p.Code,
|
|
// DisplayName = p.DisplayName,
|
|
// SimpleCode = p.SimpleCode,
|
|
// ShortName = p.ShortName,
|
|
// CustomerOrgCode = p.CustomerOrgCode,
|
|
// TreeChildren = subs.ToList()
|
|
// }
|
|
// ).ToList();
|
|
//}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取顶级目录ID
|
|
/// </summary>
|
|
/// <param name="CustomerOrgId"></param>
|
|
/// <returns></returns>
|
|
public async Task<Guid> GetParent(Guid CustomerOrgId)
|
|
{
|
|
var entity = await GetAsync(CustomerOrgId);
|
|
var parentEntity = (await Repository.GetQueryableAsync()).Where(o => o.PathCode == entity.PathCode.Substring(0, 5)).Single();
|
|
return parentEntity.Id;
|
|
//return EntityHelper.GetParentNoSql(await Repository.GetListAsync(), CustomerOrgId);
|
|
}
|
|
|
|
|
|
}
|
|
}
|