SysUserMapper.java 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. package com.ydtech.modules.admin.dao;
  2. import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.ydtech.core.page.PageResult;
  6. import com.ydtech.modules.admin.model.SysUser;
  7. import com.ydtech.modules.admin.model.vo.SysUserBaseVO;
  8. import com.ydtech.modules.admin.model.vo.SysUserVO;
  9. import com.ydtech.modules.base.model.dto.PageDto;
  10. import org.apache.ibatis.annotations.Param;
  11. import org.apache.ibatis.annotations.Select;
  12. import org.springframework.stereotype.Repository;
  13. import java.util.List;
  14. /**
  15. * @author Administrator
  16. * @description 针对表【sys_user(用户管理)】的数据库操作Mapper
  17. * @createDate 2022-08-17 11:41:01
  18. * @Entity generator.domain.SysUser
  19. */
  20. @Repository
  21. public interface SysUserMapper extends BaseMapper<SysUser> {
  22. String userSql = "select t1.id as userId,t1.name as name,t1.sex as sex,t1.mobile as mobile,t1.`status` as `status`,t2.id as deptId,t2.`name` as deptName,sd2.id as pDeptId,sd2.`name` as pDeptName,t4.id as roleId,t4.`name` as roleName " +
  23. " from sys_user t1 " +
  24. " left join sys_dept t2 on t1.dept_id=t2.id " +
  25. " left join sys_dept sd2 on sd2.id=t2.parent_id " +
  26. " left join sys_user_role t3 on t1.id=t3.user_id" +
  27. " left join sys_role t4 on t3.role_id=t4.id" +
  28. " where t1.id=#{userId}";
  29. ;
  30. String internalUserSql = "select t.id,t.name,t.dept_id deptid,t2.name deptname,t3.id comid,t3.name comname,t.status " +
  31. "from sys_user t left join sys_dept t2 on t.dept_id=t2.id " +
  32. "left join sys_dept t3 on t2.parent_id=t3.id " +
  33. "left join esm_user_internal a on t.id=a.id " +
  34. "where t.id=#{userId}";
  35. String internalUserByDeptIdSql = "select t1.id,t1.name,t1.dept_id deptid,sd.name deptname,sd2.id comid,sd2.name comname,t2.status " +
  36. "from sys_user t1 left join esm_user_internal t2 on t1.id=t2.id " +
  37. "LEFT JOIN sys_dept sd ON t1.dept_id=sd.id " +
  38. "LEFT JOIN sys_dept sd2 ON sd2.id=sd.parent_id " +
  39. "where 1=1 and t2.isteamleader = '1' and t1.dept_id=#{deptId}";
  40. String selectUserParamSql = "select su.id as userId,su.name,info.sex,su.mobile,su.status" +
  41. ",sd.id as deptId,sd.name as deptName" +
  42. ",psd.id as pDeptId,psd.name as pDeptName" +
  43. ",t4.id as roleId" +
  44. ",t4.name as roleName"
  45. ;
  46. String selectUserFromSql = " from sys_user su " +
  47. " left join sys_dept sd on su.dept_id=sd.id " +
  48. " left join sys_dept psd on sd.parent_id=psd.id " +
  49. " left join sys_user_info info on info.id=su.id " +
  50. " left join sys_user_role t3 on su.id=t3.user_id " +
  51. " left join sys_role t4 on t3.role_id=t4.id " +
  52. " where 1=1 " +
  53. " AND sd.id &lt;&gt; '' "
  54. + ""
  55. ;
  56. String selectUserFromWhereSql = " " +
  57. // "<if test='page.columnFilters.usertype !=null and page.columnFilters.usertype.value!=\"\" and page.columnFilters.usertype.value!=null '>" +
  58. // " and su.usertype = #{page.columnFilters.usertype.value}" +
  59. // "</if> " +
  60. // "<if test='page.columnFilters.approvalStatus !=null and page.columnFilters.approvalStatus.value!=\"\" and page.columnFilters.approvalStatus.value!=null '>" +
  61. // " and su.approval_status = #{page.columnFilters.approvalStatus.value}" +
  62. // "</if> " +
  63. "<if test='page.dto !=null '> " +
  64. "<if test='page.dto.status !=null and page.dto.status!=\"\" '> " +
  65. " and su.status = #{page.dto.status}" +
  66. "</if> " +
  67. "<if test='page.dto.name !=null and page.dto.name!=\"\" '> " +
  68. " and su.name like concat('%',#{page.dto.name},'%')" +
  69. "</if> " +
  70. "<if test='page.dto.userId !=null and page.dto.userId!=\"\" '>" +
  71. " and su.id = #{page.dto.userId}" +
  72. "</if> " +
  73. "<if test='page.dto.mobile !=null and page.dto.mobile!=\"\" '>" +
  74. " and su.mobile = #{page.dto.mobile}" +
  75. "</if> " +
  76. "<if test='page.dto.deptId !=null and page.dto.deptId!=\"\" '>" +
  77. " and su.dept_id like concat('%',#{page.dto.deptId},'%')" +
  78. "</if> " +
  79. "<if test='page.dto.roleId !=null and page.dto.roleId!=\"\" '>" +
  80. " and t3.role_id = #{page.dto.roleId}" +
  81. "</if> " +
  82. "</if> " +
  83. "";
  84. // String selectUserFromWhereSql = " " +
  85. // " and su.usertype = #{page.columnFilters.usertype.value}" +
  86. // " and su.status = #{page.columnFilters.status.value}" +
  87. // " and su.name like concat('%',#{page.columnFilters.name.value},'%')" +
  88. // " and su.id = #{page.columnFilters.userId.value}" +
  89. // " and su.mobile = #{page.columnFilters.mobile.value}" +
  90. // "";
  91. @Select(internalUserSql)
  92. SysUserVO gainInternalUser(@Param("userId") String userId);
  93. @Select(internalUserByDeptIdSql)
  94. SysUserVO gainInternalUserByDeptId(@Param("deptId") String deptId);
  95. @Select("SELECT u.id,u.name,r.id roleId,r.name roleName FROM sys_user u " +
  96. "LEFT JOIN sys_user_role sur ON sur.user_id = u.id " +
  97. "LEFT JOIN sys_role r ON r.id = sur.role_id WHERE r.id IN ('20','21') and u.status=1 and u.dept_id=#{deptId}")
  98. List<SysUserVO> findByReferrerId(@Param("deptId") String deptId);
  99. // @Select("select * from (" + selectUserParamSql + selectUserFromSql + selectUserFromWhereSql + " limit #{page.pageNum},#{page.pageSize} ) aaa")
  100. @Select({"<script>",
  101. "select * from (",
  102. selectUserParamSql,
  103. selectUserFromSql,
  104. selectUserFromWhereSql,
  105. " limit #{page.pageNum},#{page.pageSize} ) aaa",
  106. "</script>"})
  107. List<SysUserBaseVO> gainUserBaseInfo(@Param("page") PageDto pageDto);
  108. /**
  109. * 获取用户列表
  110. * @param page 分页信息
  111. * @param sysUser 查询条件
  112. * @param containsSubDept 是否包含下级机构
  113. * @return
  114. */
  115. public IPage<SysUser> selectUserPage(Page page, @Param("sysUser")SysUser sysUser,@Param("containsSubDept")String containsSubDept);
  116. // @Select("select count(1) " + selectUserFromSql + selectUserFromWhereSql)
  117. @Select({"<script>", "select count(1) ", selectUserFromSql, selectUserFromWhereSql, "</script>"})
  118. int gainUserBaseInfoCount(@Param("page") PageDto pageDto);
  119. @Select(userSql)
  120. SysUserBaseVO selectUserById(@Param("userId") String userId);
  121. String selectSql = "SELECT u.* FROM sys_user u " +
  122. "LEFT JOIN sys_user_role sur ON sur.user_id = u.id " +
  123. " WHERE sur.role_id IN ('20') and u.status=1 " +
  124. "<if test='userId!=\"\" '>" +
  125. " and u.id=#{userId} " +
  126. "</if> " ;
  127. @Select({"<script>",selectSql,"</script>"})
  128. List<SysUser> findAllAgentRoleUser(@Param("userId") String userId);
  129. }