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.

464 lines
18 KiB

2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
2 years ago
1 year ago
1 year ago
2 years ago
2 years ago
1 year ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
2 years ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.Extensions.Caching.Memory;
  4. using NPOI.POIFS.Properties;
  5. using Shentun.Peis.CustomerOrgRegisters;
  6. using Shentun.Peis.Enums;
  7. using Shentun.Peis.HelperDto;
  8. using Shentun.Peis.Models;
  9. using Shentun.Peis.OrganizationUnits;
  10. using Shentun.Peis.PersonnelTypes;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Threading.Tasks;
  15. using Volo.Abp;
  16. using Volo.Abp.Application.Dtos;
  17. using Volo.Abp.Application.Services;
  18. using Volo.Abp.Domain.Entities;
  19. using Volo.Abp.Domain.Repositories;
  20. using Volo.Abp.Identity;
  21. using Volo.Abp.ObjectMapping;
  22. namespace Shentun.Peis.CustomerOrgs
  23. {
  24. /// <summary>
  25. /// 团检单位设置
  26. /// </summary>
  27. [ApiExplorerSettings(GroupName = "Work")]
  28. [Authorize]
  29. public class CustomerOrgAppService : CrudAppService<
  30. CustomerOrg, //The Book entity
  31. CustomerOrgDto, //Used to show books
  32. Guid, //Primary key of the book entity
  33. PagedAndSortedResultRequestDto, //Used for paging/sorting
  34. CreateCustomerOrgDto,
  35. UpdateCustomerOrgDto>
  36. {
  37. private readonly IRepository<IdentityUser, Guid> _userRepository;
  38. private readonly IRepository<CustomerOrgRegister, Guid> _customerOrgRegisterRepository;
  39. private readonly CustomerOrgManager _manager;
  40. private readonly CustomerOrgRegisterManager _customerOrgRegisterManager;
  41. private readonly CacheService _cacheService;
  42. private readonly IMemoryCache _customerOrgCache;
  43. public CustomerOrgAppService(
  44. IRepository<CustomerOrg, Guid> repository,
  45. IRepository<IdentityUser, Guid> userRepository,
  46. CustomerOrgManager manager,
  47. CustomerOrgRegisterManager customerOrgRegisterManager,
  48. IRepository<CustomerOrgRegister, Guid> customerOrgRegisterRepository,
  49. CacheService cacheService,
  50. IMemoryCache customerOrgCache)
  51. : base(repository)
  52. {
  53. _userRepository = userRepository;
  54. _manager = manager;
  55. this._customerOrgRegisterManager = customerOrgRegisterManager;
  56. this._customerOrgRegisterRepository = customerOrgRegisterRepository;
  57. _cacheService = cacheService;
  58. _customerOrgCache = customerOrgCache;
  59. }
  60. /// <summary>
  61. /// 获取通过主键
  62. /// </summary>
  63. /// <param name="id"></param>
  64. /// <returns></returns>
  65. public override async Task<CustomerOrgDto> GetAsync(Guid id)
  66. {
  67. var entityDto = await base.GetAsync(id);
  68. entityDto.CreatorName = await _cacheService.GetSurnameAsync(entityDto.CreatorId);
  69. entityDto.LastModifierName = await _cacheService.GetSurnameAsync(entityDto.LastModifierId);
  70. return entityDto;
  71. }
  72. //[AllowAnonymous]
  73. [HttpPost("api/app/CustomerOrg/GetById")]
  74. public async Task<CustomerOrgDto> GetByIdAsync(CustomerOrgIdInputDto input)
  75. {
  76. var entity = await Repository.GetAsync(input.CustomerOrgId);
  77. var entityDto = ObjectMapper.Map<CustomerOrg, CustomerOrgDto>(entity);
  78. entityDto.CreatorName = await _cacheService.GetSurnameAsync(entityDto.CreatorId);
  79. entityDto.LastModifierName = await _cacheService.GetSurnameAsync(entityDto.LastModifierId);
  80. return entityDto;
  81. }
  82. /// <summary>
  83. /// 获取所有一级子单位
  84. /// </summary>
  85. /// <param name="input"></param>
  86. /// <returns></returns>
  87. [HttpPost("api/app/CustomerOrg/GetChildCustomerOrgsById")]
  88. public async Task<List<CustomerOrgDto>> GetChildCustomerOrgsByIdAsync(CustomerOrgIdInputDto input)
  89. {
  90. var list = await Repository.GetListAsync(o => o.ParentId == input.CustomerOrgId);
  91. var dtos = new List<CustomerOrgDto>();
  92. foreach (var customerOrg in list)
  93. {
  94. var entityDto = ObjectMapper.Map<CustomerOrg, CustomerOrgDto>(customerOrg);
  95. entityDto.CreatorName = await _cacheService.GetSurnameAsync(entityDto.CreatorId);
  96. entityDto.LastModifierName = await _cacheService.GetSurnameAsync(entityDto.LastModifierId);
  97. dtos.Add(entityDto);
  98. }
  99. return dtos;
  100. }
  101. /// <summary>
  102. /// 获取列表 团检单位设置
  103. /// </summary>
  104. /// <param name="input"></param>
  105. /// <returns></returns>
  106. [RemoteService(false)]
  107. public override async Task<PagedResultDto<CustomerOrgDto>> GetListAsync(PagedAndSortedResultRequestDto input)
  108. {
  109. return await base.GetListAsync(input);
  110. }
  111. /// <summary>
  112. /// 获取列表 团检单位设置 可以带名称搜索
  113. /// </summary>
  114. /// <param name="input"></param>
  115. /// <returns></returns>
  116. public async Task<List<CustomerOrgDto>> GetListInFilterAsync(GetListDto input)
  117. {
  118. var oldlist = await Repository.GetQueryableAsync();
  119. if (!string.IsNullOrEmpty(input.Filter))
  120. oldlist = oldlist.Where(m => m.DisplayName.Contains(input.Filter));
  121. if (input.IsHidePerson == 1)
  122. oldlist = oldlist.Where(m => m.Id != GuidFlag.PersonCustomerOrgId);
  123. var entdto = oldlist.Select(s => new CustomerOrgDto
  124. {
  125. CreationTime = s.CreationTime,
  126. CreatorId = s.CreatorId,
  127. DisplayName = s.DisplayName,
  128. DisplayOrder = s.DisplayOrder,
  129. Id = s.Id,
  130. LastModificationTime = s.LastModificationTime,
  131. LastModifierId = s.LastModifierId,
  132. SimpleCode = s.SimpleCode,
  133. Accounts = s.Accounts,
  134. Telephone = s.Telephone,
  135. IsActive = s.IsActive,
  136. ShortName = s.ShortName,
  137. Remark = s.Remark,
  138. PostalCode = s.PostalCode,
  139. PathCode = s.PathCode,
  140. ParentId = s.ParentId,
  141. OrgTypeId = s.OrgTypeId,
  142. Address = s.Address,
  143. Bank = s.Bank,
  144. Fax = s.Fax,
  145. InvoiceName = s.InvoiceName,
  146. IsLock = s.IsLock,
  147. SalesPerson = s.SalesPerson,
  148. SalesPersonPhone = s.SalesPersonPhone,
  149. MedicalCenterId = s.MedicalCenterId,
  150. CountryOrgCode = s.CountryOrgCode,
  151. CreatorName = _cacheService.GetSurnameAsync(s.CreatorId).Result,
  152. LastModifierName = _cacheService.GetSurnameAsync(s.LastModifierId).Result
  153. }).OrderBy(m => m.DisplayOrder).ToList();
  154. return entdto;
  155. }
  156. /// <summary>
  157. /// 创建单位 单位为树型结构 一级目录默认生成体检次数
  158. /// </summary>
  159. /// <param name="input"></param>
  160. /// <returns></returns>
  161. [HttpPost("api/app/customerorg/create")]
  162. public override async Task<CustomerOrgDto> CreateAsync(CreateCustomerOrgDto input)
  163. {
  164. var createEntity = ObjectMapper.Map<CreateCustomerOrgDto, CustomerOrg>(input);
  165. var entity = await _manager.CreateAsync(createEntity);
  166. entity = await Repository.InsertAsync(entity);
  167. if (entity != null && (input.ParentId == null || input.ParentId == Guid.Empty))
  168. {
  169. //生成体检次数
  170. var customerOrgRegisterEntity = await _customerOrgRegisterManager.CreateAsync(entity.Id);
  171. await _customerOrgRegisterRepository.InsertAsync(customerOrgRegisterEntity);
  172. }
  173. _customerOrgCache.Set(entity.Id, entity);
  174. var dto = ObjectMapper.Map<CustomerOrg, CustomerOrgDto>(entity);
  175. return dto;
  176. }
  177. /// <summary>
  178. /// 更新
  179. /// </summary>
  180. /// <param name="id"></param>
  181. /// <param name="input"></param>
  182. /// <returns></returns>
  183. public override async Task<CustomerOrgDto> UpdateAsync(Guid id, UpdateCustomerOrgDto input)
  184. {
  185. var entity = await Repository.GetAsync(id);
  186. var sourceEntity = ObjectMapper.Map<UpdateCustomerOrgDto, CustomerOrg>(input);
  187. await _manager.UpdateAsync(sourceEntity, entity);
  188. entity = await Repository.UpdateAsync(entity);
  189. _customerOrgCache.Set(entity.Id, entity);
  190. return ObjectMapper.Map<CustomerOrg, CustomerOrgDto>(entity);
  191. }
  192. /// <summary>
  193. /// 删除
  194. /// </summary>
  195. /// <param name="id"></param>
  196. /// <returns></returns>
  197. public override async Task DeleteAsync(Guid id)
  198. {
  199. var CustomerOrgChildrenIds = await _manager.GetCustomerOrgChildrenId(id); //遍历找出下级ID
  200. if (CustomerOrgChildrenIds.Any())
  201. {
  202. foreach (var CustomerOrgChildrenId in CustomerOrgChildrenIds)
  203. {
  204. if (CustomerOrgChildrenId != null)
  205. {
  206. await _manager.CheckAndDeleteAsync(CustomerOrgChildrenId.Value);
  207. _customerOrgCache.Remove(CustomerOrgChildrenId);
  208. }
  209. }
  210. }
  211. else
  212. {
  213. throw new UserFriendlyException("参数有误");
  214. }
  215. }
  216. /// <summary>
  217. /// 修改排序 置顶,置底
  218. /// </summary>
  219. /// <param name="id">需要修改的ID</param>
  220. /// <param name="SortType">修改方式:1 置顶 2 置底</param>
  221. /// <returns></returns>
  222. [HttpPut("api/app/customerorg/updatemanysort")]
  223. public async Task UpdateManySortAsync(Guid id, int SortType)
  224. {
  225. await _manager.UpdateManySortAsync(id, SortType);
  226. }
  227. /// <summary>
  228. /// 修改排序 拖拽
  229. /// </summary>
  230. /// <param name="input"></param>
  231. /// <returns></returns>
  232. [HttpPut("api/app/customerorg/updatesortmany")]
  233. public async Task UpdateSortManyAsync(UpdateSortManyDto input)
  234. {
  235. await _manager.UpdateSortManyAsync(input);
  236. }
  237. /// <summary>
  238. /// 获取一级目录 单位列表
  239. /// </summary>
  240. /// <param name="Filter">名字搜索,支持模糊查找</param>
  241. /// <returns></returns>
  242. public async Task<List<CustomerOrg>> GetParentAllAsync(string Filter)
  243. {
  244. var dataList = await Repository.GetListAsync(m => m.ParentId == null || m.ParentId == Guid.Empty);
  245. if (dataList.Count > 0 && !string.IsNullOrEmpty(Filter))
  246. dataList = dataList.Where(m => m.DisplayName.Contains(Filter) || m.ShortName.Contains(Filter)).ToList();
  247. return dataList.OrderBy(o => o.DisplayOrder).ToList();
  248. }
  249. /// <summary>
  250. /// 根据父ID获取单位列表 分级获取
  251. /// </summary>
  252. /// <param name="input"></param>
  253. /// <returns></returns>
  254. [HttpPost("api/app/CustomerOrg/GetCustomerOrgByParentId")]
  255. public async Task<List<CustomerOrgBaseDto>> GetCustomerOrgByParentIdAsync(ParentIdInputDto input)
  256. {
  257. var parentIds = (await Repository.GetQueryableAsync()).Where(m => m.ParentId != null).Select(s => s.ParentId).ToList();
  258. var query = await Repository.GetQueryableAsync();
  259. query = query.Where(m => m.ParentId == input.ParentId);
  260. var entListDto = query.ToList().Select(s => new CustomerOrgBaseDto
  261. {
  262. CustomerOrgCode = s.CustomerOrgCode,
  263. ParentId = s.ParentId,
  264. DisplayName = s.DisplayName,
  265. DisplayOrder = s.Id == GuidFlag.PersonCustomerOrgId ? 99999 : s.DisplayOrder,
  266. Id = s.Id,
  267. ShortName = s.ShortName,
  268. SimpleCode = s.SimpleCode,
  269. IsChild = parentIds.Any() && parentIds.Contains(s.Id) ? 'Y' : 'N',
  270. }).OrderByDescending(o => o.DisplayOrder).ToList();
  271. return entListDto;
  272. }
  273. /// <summary>
  274. /// 获取单位树型结构
  275. /// </summary>
  276. /// <param name="IsHidePerson">是否隐藏个人信息 1 隐藏 0不隐藏 默认为0</param>
  277. /// <param name="Filter">名字搜索,支持模糊查找</param>
  278. /// <returns></returns>
  279. [HttpGet("api/app/customerorg/getbycodeall")]
  280. public async Task<List<CustomerOrgTreeChildDto>> GetByCodeAllAsync(string Filter, int IsHidePerson = 0)
  281. {
  282. List<CustomerOrgTreeChildDto> result = new List<CustomerOrgTreeChildDto>();
  283. var customerOrgPerson = await Repository.FirstOrDefaultAsync(f => f.Id == GuidFlag.PersonCustomerOrgId);
  284. var dataList = (await Repository.GetQueryableAsync());
  285. if (!string.IsNullOrEmpty(Filter))
  286. dataList = dataList.Where(m => m.DisplayName.Contains(Filter) || m.ShortName.Contains(Filter));
  287. if (IsHidePerson == 1)
  288. {
  289. dataList = dataList.Where(m => m.Id != GuidFlag.PersonCustomerOrgId);
  290. }
  291. else
  292. {
  293. if (customerOrgPerson != null)
  294. {
  295. result.Add(new CustomerOrgTreeChildDto
  296. {
  297. Code = customerOrgPerson.PathCode,
  298. CustomerOrgCode = customerOrgPerson.CustomerOrgCode,
  299. DisplayName = customerOrgPerson.DisplayName,
  300. DisplayOrder = customerOrgPerson.DisplayOrder,
  301. Id = customerOrgPerson.Id,
  302. ParentId = customerOrgPerson.ParentId,
  303. ShortName = customerOrgPerson.ShortName,
  304. SimpleCode = customerOrgPerson.SimpleCode,
  305. TreeChildren = null
  306. });
  307. }
  308. }
  309. var customerOrgList = dataList.ToList();
  310. var items = from p in customerOrgList.Where(m => m.Id != GuidFlag.PersonCustomerOrgId).OrderByDescending(o => o.DisplayOrder).AsParallel()
  311. select new CustomerOrgTreeChildDto()
  312. {
  313. Id = p.Id,
  314. ParentId = p.ParentId,
  315. Code = p.PathCode,
  316. DisplayName = p.DisplayName,
  317. SimpleCode = p.SimpleCode,
  318. ShortName = p.ShortName,
  319. CustomerOrgCode = p.CustomerOrgCode,
  320. TreeChildren = new List<CustomerOrgTreeChildDto>()
  321. };
  322. var customerOrgTreeChildList = GetTree(items.ToList(), null);
  323. //var tree1 = items.Where(m => m.ParentId == null).ToList();
  324. //foreach (var item1 in tree1)
  325. //{
  326. // item1.TreeChildren = items.Where(m => m.ParentId == item1.Id).ToList();
  327. // foreach (var item2 in item1.TreeChildren)
  328. // {
  329. // item2.TreeChildren = items.Where(m => m.ParentId == item2.Id).ToList();
  330. // foreach (var item3 in item2.TreeChildren)
  331. // {
  332. // item3.TreeChildren = items.Where(m => m.ParentId == item3.Id).ToList();
  333. // foreach (var item4 in item3.TreeChildren)
  334. // {
  335. // item4.TreeChildren = items.Where(m => m.ParentId == item4.Id).ToList();
  336. // }
  337. // }
  338. // }
  339. //}
  340. result.AddRange(customerOrgTreeChildList);
  341. return result;
  342. }
  343. /// <summary>
  344. /// 使用parentId进行递归
  345. /// </summary>
  346. /// <param name="items"></param>
  347. /// <param name="parentId"></param>
  348. /// <returns></returns>
  349. private List<CustomerOrgTreeChildDto> GetTree(List<CustomerOrgTreeChildDto> items, Guid? parentId)
  350. {
  351. return (from p in items.AsParallel()
  352. where p.ParentId == parentId
  353. let subs = GetTree(items, p.Id)
  354. select new CustomerOrgTreeChildDto()
  355. {
  356. Id = p.Id,
  357. ParentId = p.ParentId,
  358. Code = p.Code,
  359. DisplayName = p.DisplayName,
  360. SimpleCode = p.SimpleCode,
  361. ShortName = p.ShortName,
  362. CustomerOrgCode = p.CustomerOrgCode,
  363. TreeChildren = subs.ToList()
  364. }
  365. ).ToList();
  366. }
  367. ///// <summary>
  368. ///// 使用Code进行递归
  369. ///// </summary>
  370. ///// <param name="items"></param>
  371. ///// <param name="deep"></param>
  372. ///// <param name="prefix"></param>
  373. ///// <returns></returns>
  374. //private List<CustomerOrgTreeChildDto> GetTree(List<CustomerOrgTreeChildDto> items, int deep, string prefix)
  375. //{
  376. // return (from p in items
  377. // where p.Code.StartsWith(prefix) && p.Code.Count(a => a == '.') == deep
  378. // let subs = GetTree(items, deep + 1, p.Code)
  379. // select new CustomerOrgTreeChildDto()
  380. // {
  381. // Id = p.Id,
  382. // ParentId = p.ParentId,
  383. // Code = p.Code,
  384. // DisplayName = p.DisplayName,
  385. // SimpleCode = p.SimpleCode,
  386. // ShortName = p.ShortName,
  387. // CustomerOrgCode = p.CustomerOrgCode,
  388. // TreeChildren = subs.ToList()
  389. // }
  390. // ).ToList();
  391. //}
  392. /// <summary>
  393. /// 获取顶级目录ID
  394. /// </summary>
  395. /// <param name="CustomerOrgId"></param>
  396. /// <returns></returns>
  397. public async Task<Guid> GetParent(Guid CustomerOrgId)
  398. {
  399. var entity = await GetAsync(CustomerOrgId);
  400. var parentEntity = (await Repository.GetQueryableAsync()).Where(o => o.PathCode == entity.PathCode.Substring(0, 5)).Single();
  401. return parentEntity.Id;
  402. //return EntityHelper.GetParentNoSql(await Repository.GetListAsync(), CustomerOrgId);
  403. }
  404. }
  405. }