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.

177 lines
5.8 KiB

3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
  1. using AutoMapper.Internal.Mappers;
  2. using Microsoft.AspNetCore.Authorization;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Shentun.Peis.GuideTypes;
  5. using Shentun.Peis.HelperDto;
  6. using Shentun.Peis.Models;
  7. using Shentun.Peis.Sexs;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using Volo.Abp;
  14. using Volo.Abp.Application.Dtos;
  15. using Volo.Abp.Application.Services;
  16. using Volo.Abp.Domain.Repositories;
  17. namespace Shentun.Peis.MaritalStatuses
  18. {
  19. /// <summary>
  20. /// 婚姻状况
  21. /// </summary>
  22. [ApiExplorerSettings(GroupName = "Work")]
  23. [Authorize]
  24. public class MaritalStatusesAppService : ApplicationService
  25. {
  26. private readonly IRepository<MaritalStatus> _repository;
  27. public MaritalStatusesAppService(IRepository<MaritalStatus> repository)
  28. {
  29. this._repository = repository;
  30. }
  31. /// <summary>
  32. /// 获取婚姻状况表数据列表
  33. /// </summary>
  34. /// <returns></returns>
  35. public async Task<PagedResultDto<MaritalStatusDto>> GetListAsync(PagedAndSortedResultRequestDto input)
  36. {
  37. var totalCount = await _repository.CountAsync();
  38. var entlist = await _repository.GetPagedListAsync(input.SkipCount, input.MaxResultCount, input.Sorting);
  39. entlist = entlist.OrderBy(o => o.DisplayOrder).ToList();
  40. var entdto = ObjectMapper.Map<List<MaritalStatus>, List<MaritalStatusDto>>(entlist);
  41. return new PagedResultDto<MaritalStatusDto>(totalCount, entdto);
  42. }
  43. /// <summary>
  44. /// 修改
  45. /// </summary>
  46. /// <param name="Id">主键ID</param>
  47. /// <param name="input">修改参数</param>
  48. /// <returns></returns>
  49. public async Task<MaritalStatusDto> UpdateAsync(char Id, UpdateMaritalStatusDto input)
  50. {
  51. var ent = await _repository.GetAsync(m => m.Id == Id);
  52. ent.SimpleCode = input.SimpleCode;
  53. ent.DisplayName = input.DisplayName;
  54. var newent = await _repository.UpdateAsync(ent);
  55. return ObjectMapper.Map<MaritalStatus, MaritalStatusDto>(newent);
  56. }
  57. /// <summary>
  58. /// 修改排序 相邻之间
  59. /// </summary>
  60. /// <param name="id">需要修改的ID</param>
  61. /// <param name="targetid">目标ID</param>
  62. [HttpPut("api/app/maritalstatus/updatesort")]
  63. [RemoteService(false)]
  64. public async Task UpdateSortAsync(char id, char targetid)
  65. {
  66. var entity = await _repository.GetAsync(m => m.Id == id);
  67. var targetentity = await _repository.GetAsync(m => m.Id == targetid);
  68. int olddisplaynum = entity.DisplayOrder;
  69. entity.DisplayOrder = targetentity.DisplayOrder;
  70. targetentity.DisplayOrder = olddisplaynum;
  71. List<MaritalStatus> entlist = new List<MaritalStatus>();
  72. entlist.Add(entity);
  73. entlist.Add(targetentity);
  74. await _repository.UpdateManyAsync(entlist);
  75. }
  76. /// <summary>
  77. /// 修改排序 置顶,置底
  78. /// </summary>
  79. /// <param name="id">需要修改的ID</param>
  80. /// <param name="SortType">修改方式:1 置顶 2 置底</param>
  81. /// <returns></returns>
  82. [HttpPut("api/app/maritalstatus/updatemanysort")]
  83. public async Task UpdateManySortAsync(char id, int SortType)
  84. {
  85. var entity = await _repository.GetAsync(m => m.Id == id);
  86. List<MaritalStatus> UptList = new List<MaritalStatus>();
  87. if (SortType == 2)
  88. {
  89. UptList = (await _repository.GetListAsync(o => o.DisplayOrder > entity.DisplayOrder)).OrderBy(o => o.DisplayOrder).ToList();
  90. if (UptList.Count > 0)
  91. {
  92. int indexnum = entity.DisplayOrder; //原有值
  93. entity.DisplayOrder = UptList[UptList.Count - 1].DisplayOrder; //修改当前排序值为最大
  94. //置顶操作,往上一行开始,逐渐替换
  95. foreach (var item in UptList)
  96. {
  97. int dqnum = item.DisplayOrder;
  98. item.DisplayOrder = indexnum;
  99. indexnum = dqnum;
  100. }
  101. }
  102. }
  103. else
  104. {
  105. UptList = (await _repository.GetListAsync(o => o.DisplayOrder < entity.DisplayOrder)).OrderByDescending(o => o.DisplayOrder).ToList(); ;
  106. int indexnum = entity.DisplayOrder; //原有值
  107. entity.DisplayOrder = UptList[UptList.Count - 1].DisplayOrder; //修改当前排序值为最小
  108. //置底操作,往下一行开始,逐渐替换
  109. foreach (var item in UptList)
  110. {
  111. int dqnum = item.DisplayOrder;
  112. item.DisplayOrder = indexnum;
  113. indexnum = dqnum;
  114. }
  115. }
  116. UptList.Add(entity);
  117. await _repository.UpdateManyAsync(UptList);
  118. }
  119. /// <summary>
  120. /// 修改排序 拖拽
  121. /// </summary>
  122. /// <param name="input"></param>
  123. /// <returns></returns>
  124. [HttpPut("api/app/maritalstatus/updatesortmany")]
  125. public async Task UpdateSortManyAsync(UpdateSortManyNokeyDto input)
  126. {
  127. var entitylist = await _repository.GetListAsync(o => input.ItemList.Select(s => s.Id).Contains(o.Id.ToString()));
  128. foreach (var entity in entitylist)
  129. {
  130. foreach (var item in input.ItemList)
  131. {
  132. if (item.Id == entity.Id.ToString())
  133. entity.DisplayOrder = item.DisplayOrder;
  134. }
  135. }
  136. await _repository.UpdateManyAsync(entitylist);
  137. }
  138. }
  139. }