SysUserPostService.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using Attribute;
  2. using Model;
  3. using Service;
  4. namespace Services
  5. {
  6. /// <summary>
  7. /// 用户岗位
  8. /// </summary>
  9. [AppService(ServiceType = typeof(ISysUserPostService), ServiceLifetime = LifeTime.Transient)]
  10. public class SysUserPostService : BaseService<SysUserPost>, ISysUserPostService
  11. {
  12. /// <summary>
  13. /// 新增用户岗位信息
  14. /// </summary>
  15. /// <param name="user"></param>
  16. public void InsertUserPost(SysUser user)
  17. {
  18. // 新增用户与岗位管理
  19. List<SysUserPost> list = new();
  20. foreach (var item in user.PostIds)
  21. {
  22. list.Add(new SysUserPost() { PostId = item, UserId = user.userId });
  23. }
  24. InsertRange(list);
  25. }
  26. /// <summary>
  27. /// 查询用户岗位集合
  28. /// </summary>
  29. /// <param name="userId"></param>
  30. /// <returns></returns>
  31. public List<long> GetUserPostsByUserId(long userId)
  32. {
  33. var list = GetList(f => f.UserId == userId);
  34. return list.Select(x => x.PostId).ToList();
  35. }
  36. /// <summary>
  37. /// 获取用户岗位
  38. /// </summary>
  39. /// <param name="userId"></param>
  40. /// <returns></returns>
  41. public string GetPostsStrByUserId(long userId)
  42. {
  43. var list = SelectPostsByUserId(userId);
  44. return string.Join(',', list.Select(x => x.postName));
  45. }
  46. public bool Delete(long userId)
  47. {
  48. return Delete(x => x.UserId == userId);
  49. }
  50. /// <summary>
  51. /// 获取用户岗位
  52. /// </summary>
  53. /// <param name="userId"></param>
  54. /// <returns></returns>
  55. public List<SysPost> SelectPostsByUserId(long userId)
  56. {
  57. return Context.Queryable<SysPost, SysUserPost>((p, up) => new JoinQueryInfos(
  58. JoinType.Left, up.PostId == p.postId
  59. )).Where((p, up) => up.UserId == userId)
  60. .Select<SysPost>().ToList();
  61. }
  62. }
  63. }