平安校园
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

PositionService.cs 3.9 KiB

pirms 4 mēnešiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. 
  2. //
  3. namespace SafeCampus.Application;
  4. /// <summary>
  5. /// <inheritdoc cref="IPositionService"/>
  6. /// </summary>
  7. public class PositionService : DbRepository<SysPosition>, IPositionService
  8. {
  9. private readonly ISysUserService _sysUserService;
  10. private readonly ISysPositionService _sysPositionService;
  11. public PositionService(ISysUserService sysUserService, ISysPositionService sysPositionService)
  12. {
  13. _sysUserService = sysUserService;
  14. _sysPositionService = sysPositionService;
  15. }
  16. #region 查询
  17. /// <inheritdoc />
  18. public async Task<SqlSugarPagedList<SysPosition>> Page(PositionPageInput input)
  19. {
  20. //获取数据范围
  21. var dataScope = await _sysUserService.GetLoginUserApiDataScope();
  22. input.OrgIds = dataScope;
  23. //分页查询
  24. var pageInfo = await _sysPositionService.Page(input);
  25. return pageInfo;
  26. }
  27. /// <inheritdoc/>
  28. public async Task<List<PositionTreeOutput>> Tree(PositionTreeInput input)
  29. {
  30. var dataScope = await _sysUserService.GetLoginUserApiDataScope();
  31. input.OrgIds = dataScope;
  32. var result = await _sysPositionService.Tree(input);
  33. return result;
  34. }
  35. #endregion
  36. #region 新增
  37. /// <inheritdoc />
  38. public async Task Add(PositionAddInput input)
  39. {
  40. await CheckInput(input, SystemConst.ADD);//检查参数
  41. await _sysPositionService.Add(input, ApplicationConst.BIZ_POS);//添加岗位
  42. }
  43. /// <inheritdoc/>
  44. public async Task<List<PositionSelectorOutput>> Selector(PositionSelectorInput input)
  45. {
  46. //获取数据范围
  47. var dataScope = await _sysUserService.GetLoginUserApiDataScope();
  48. input.OrgIds = dataScope;//赋值机构列表
  49. var result = await _sysPositionService.Selector(input);//查询
  50. return result;
  51. }
  52. /// <inheritdoc />
  53. public async Task<SysPosition> Detail(BaseIdInput input)
  54. {
  55. var position = await _sysPositionService.GetSysPositionById(input.Id);
  56. //判断数据范围
  57. await _sysUserService.CheckApiDataScope(position.OrgId, position.CreateUserId.GetValueOrDefault(), "您没有权限查看该机构");
  58. return position;
  59. }
  60. #endregion
  61. #region 编辑
  62. /// <inheritdoc />
  63. public async Task Edit(PositionEditInput input)
  64. {
  65. await CheckInput(input, SystemConst.EDIT);//检查参数
  66. await _sysPositionService.Edit(input, ApplicationConst.BIZ_POS);//编辑
  67. }
  68. #endregion
  69. #region 删除
  70. /// <inheritdoc />
  71. public async Task Delete(BaseIdListInput input)
  72. {
  73. //获取所有ID
  74. var ids = input.Ids;
  75. //获取要删除的岗位列表
  76. var positions = (await _sysPositionService.GetListAsync()).Where(it => ids.Contains(it.Id)).ToList();
  77. //检查数据范围
  78. var orgIds = positions.Select(it => it.OrgId).ToList();
  79. var createUserIds = positions.Select(it => it.CreateUserId.GetValueOrDefault()).ToList();
  80. await _sysUserService.CheckApiDataScope(orgIds, createUserIds, "您没有权限删除该机构");
  81. await _sysPositionService.Delete(input, ApplicationConst.BIZ_ORG);//删除岗位
  82. }
  83. #endregion
  84. #region 方法
  85. /// <summary>
  86. /// 检查输入参数
  87. /// </summary>
  88. /// <param name="sysPosition">参数</param>
  89. /// <param name="operate">操作名称</param>
  90. private async Task CheckInput(SysPosition sysPosition, string operate)
  91. {
  92. var errorMessage = $"您没有权限在该机构下{operate}岗位";
  93. //如果id大于0表示编辑
  94. if (sysPosition.Id > 0)
  95. {
  96. var position = await _sysPositionService.GetSysPositionById(sysPosition.Id);//获取机构
  97. sysPosition.CreateUserId = position.CreateUserId;
  98. }
  99. await _sysUserService.CheckApiDataScope(sysPosition.OrgId, sysPosition.CreateUserId.GetValueOrDefault(), errorMessage);
  100. }
  101. #endregion 方法
  102. }