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.
305 lines
12 KiB
305 lines
12 KiB
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Shentun.Peis.CustomerOrgRegisters;
|
|
using Shentun.Peis.Enums;
|
|
using Shentun.Peis.HelperDto;
|
|
using Shentun.Peis.Models;
|
|
using Shentun.Peis.OrganizationUnits;
|
|
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.Repositories;
|
|
using Volo.Abp.Identity;
|
|
|
|
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;
|
|
public CustomerOrgAppService(
|
|
IRepository<CustomerOrg, Guid> repository,
|
|
IRepository<IdentityUser, Guid> userRepository,
|
|
CustomerOrgManager manager,
|
|
CustomerOrgRegisterManager customerOrgRegisterManager,
|
|
IRepository<CustomerOrgRegister, Guid> customerOrgRegisterRepository,
|
|
CacheService cacheService)
|
|
: base(repository)
|
|
{
|
|
_userRepository = userRepository;
|
|
_manager = manager;
|
|
this._customerOrgRegisterManager = customerOrgRegisterManager;
|
|
this._customerOrgRegisterRepository = customerOrgRegisterRepository;
|
|
_cacheService = cacheService;
|
|
}
|
|
/// <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.GetUserNameAsync(entityDto.CreatorId);
|
|
entityDto.LastModifierName = await _cacheService.GetUserNameAsync(entityDto.LastModifierId);
|
|
|
|
return entityDto;
|
|
}
|
|
/// <summary>
|
|
/// 获取列表 团检单位设置
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
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<PagedResultDto<CustomerOrgDto>> GetListInFilterAsync(GetListDto input)
|
|
{
|
|
int totalCount = 0;
|
|
|
|
var oldlist = await Repository.GetListAsync();
|
|
if (!string.IsNullOrEmpty(input.Filter))
|
|
oldlist = oldlist.Where(m => m.DisplayName.Contains(input.Filter)).ToList();
|
|
|
|
if (input.IsHidePerson == 1)
|
|
oldlist = oldlist.Where(m => m.Id != GuidFlag.PersonCustomerOrgId).ToList();
|
|
|
|
totalCount = oldlist.Count;
|
|
|
|
oldlist = oldlist.OrderBy(m => m.DisplayOrder).Skip(input.SkipCount * input.MaxResultCount).Take(input.MaxResultCount).ToList();
|
|
|
|
var userList = await _userRepository.GetListAsync();
|
|
|
|
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,
|
|
MedicalCenterId = s.MedicalCenterId,
|
|
CreatorName = EntityHelper.GetUserNameNoSql(userList, s.CreatorId),
|
|
LastModifierName = EntityHelper.GetUserNameNoSql(userList, s.LastModifierId)
|
|
}).ToList();
|
|
|
|
|
|
|
|
return new PagedResultDto<CustomerOrgDto>(totalCount, 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);
|
|
}
|
|
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);
|
|
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);
|
|
}
|
|
|
|
}
|
|
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<TreeChildViewDto>> GetByCodeAllAsync(string Filter, int IsHidePerson = 0)
|
|
{
|
|
var dataList = await Repository.GetListAsync();
|
|
if (!string.IsNullOrEmpty(Filter))
|
|
dataList = dataList.Where(m => m.DisplayName.Contains(Filter) || m.ShortName.Contains(Filter)).ToList();
|
|
if (IsHidePerson == 1)
|
|
{
|
|
dataList = dataList.Where(m => m.Id != GuidFlag.PersonCustomerOrgId).ToList();
|
|
}
|
|
|
|
var items = from p in dataList.OrderBy(o => o.DisplayOrder)
|
|
select new TreeChildViewDto()
|
|
{
|
|
Id = p.Id,
|
|
ParentId = p.ParentId,
|
|
Code = p.PathCode,
|
|
DisplayName = p.DisplayName,
|
|
SimpleCode = p.SimpleCode
|
|
};
|
|
return GetTree(items.ToList(), 0, "");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 使用Code进行递归
|
|
/// </summary>
|
|
/// <param name="items"></param>
|
|
/// <param name="deep"></param>
|
|
/// <param name="prefix"></param>
|
|
/// <returns></returns>
|
|
private List<TreeChildViewDto> GetTree(List<TreeChildViewDto> 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 TreeChildViewDto()
|
|
{
|
|
Id = p.Id,
|
|
ParentId = p.ParentId,
|
|
Code = p.Code,
|
|
DisplayName = p.DisplayName,
|
|
SimpleCode = p.SimpleCode,
|
|
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);
|
|
}
|
|
|
|
|
|
}
|
|
}
|