平安校园
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.
 
 
 
 
 
 

132 lines
3.9 KiB

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