UserDao.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. package com.nokia.dao;
  2. import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.nokia.pojo.Role;
  5. import com.nokia.pojo.User;
  6. import com.nokia.vo.*;
  7. import com.nokia.vo.flow.FlowRoleVo;
  8. import com.nokia.vo.flow.FlowUserVo;
  9. import org.apache.ibatis.annotations.*;
  10. import java.util.List;
  11. @Mapper
  12. public interface UserDao extends BaseMapper<User> {
  13. /**
  14. * 支持username模糊查询
  15. */
  16. @Select("select distinct r.role_id, r.role_name from sqmdb_rpt.acl_user u, sqmdb_rpt.acl_role r, sqmdb_rpt.acl_user_role_city ur"
  17. + " where u.user_id = ur.user_id and r.role_id = ur.role_id and r.system='flow' and u.user_name like concat('%',#{username},'%')")
  18. List<FlowRoleVo> findRoleList(String username);
  19. /**
  20. * 查询全部
  21. */
  22. @Select("select role_id, role_name from sqmdb_rpt.acl_role where system = 'flow'")
  23. List<FlowRoleVo> findRoleList2();
  24. /**
  25. * 查询全部用户(流程所需),未分页
  26. */
  27. @Results({
  28. @Result(column = "org_id", property = "org.orgId"),
  29. @Result(column = "org_name", property = "org.orgName"),
  30. })
  31. @Select("select a.user_id as user_id, a.login_name as login_id, a.user_name as user_name, a.phone as mobile, a.email as email,"
  32. + " a.city_id as org_id, c1.area_name as org_name, a.area_id as area"
  33. + " from sqmdb_rpt.acl_user a, sqmdb_rpt.acl_area c1"
  34. + " where a.city_id = c1.area_id "
  35. + "and a.deleted = 0")
  36. List<FlowUserVo> findToPage();
  37. /**
  38. * 查询登录用户信息
  39. */
  40. @Results({
  41. @Result(column = "org_id", property = "org.orgId"),
  42. @Result(column = "org_name", property = "org.orgName"),
  43. })
  44. @Select("select a.user_id as user_id, a.login_name as login_id, a.user_name as user_name, a.phone as mobile, a.email as email,"
  45. + " a.city_id as org_id, c.area_name as org_name, a.area_id as area"
  46. + " from sqmdb_rpt.acl_user a, sqmdb_rpt.acl_area c"
  47. + " where a.city_id = c.area_id and a.login_name=#{loginId} and a.deleted = 0")
  48. FlowUserVo getFlowUserVoByLoginId(String loginId);
  49. /**
  50. * 根据用户ID获取用户接口
  51. */
  52. @Results({
  53. @Result(column = "org_id", property = "org.orgId"),
  54. @Result(column = "org_name", property = "org.orgName"),
  55. })
  56. @Select("select a.user_id as user_id, a.login_name as login_id, a.user_name as user_name, a.phone as mobile, a.email as email,"
  57. + " a.city_id as org_id, c.area_name as org_name, a.area_id as area"
  58. + " from sqmdb_rpt.acl_user a, sqmdb_rpt.acl_area c"
  59. + " where a.city_id = c.area_id and user_id=#{userId} and a.deleted = 0")
  60. FlowUserVo getFlowUserVoByUserId(Integer userId);
  61. @Select("select r.role_id from sqmdb_rpt.acl_role r, sqmdb_rpt.acl_user_role_city ur where r.role_id = ur.role_id and r.system='flow' and ur.user_id=#{userId}")
  62. List<Integer> findRoleIdByUserId(Integer userId);
  63. @Select("select u.user_id from sqmdb_rpt.acl_user u, sqmdb_rpt.acl_user_role_city ur where u.user_id = ur.user_id and ur.role_id=#{roleId} and u.deleted = 0")
  64. List<Integer> findUserIdByRoleId(Integer roleId);
  65. @Results({
  66. @Result(column = "org_id", property = "org.orgId"),
  67. @Result(column = "org_name", property = "org.orgName"),
  68. })
  69. @Select("<script>"
  70. + "select a.user_id as user_id, a.login_name as login_id, a.user_name as user_name, a.phone as mobile, a.email as email,"
  71. + " a.city_id as org_id, c.area_name as org_name, a.area_id as area"
  72. + " from sqmdb_rpt.acl_user a, sqmdb_rpt.acl_area c, sqmdb_rpt.acl_user_role_city ur "
  73. + " where a.user_id = ur.user_id and a.city_id = c.area_id and a.deleted = 0"
  74. + "<if test=\"loginId != null and loginId !=''\">"
  75. + " and a.login_name=#{loginId} "
  76. + "</if>"
  77. + "<if test=\"roleId != null\">"
  78. + " and ur.role_id=#{roleId} "
  79. + "</if>"
  80. + "<if test=\"userName != null and userName !=''\">"
  81. + " and a.user_name like concat('%',#{userName},'%') "
  82. + "</if>"
  83. + "</script>")
  84. List<FlowUserVo> findAuthorizedUser(String loginId, Integer roleId, String userName);
  85. List<Role> getRoleCityByUserId(Integer userId);
  86. User getByLoginName(String loginName);
  87. List<User> getByRoleIds(List<Integer> roleIds, List<Integer> cityIds);
  88. List<String> getPhoneListByRole(Integer roleId, Integer cityId);
  89. /**
  90. * 查询用户的app功能列表
  91. *
  92. * @param userId 用户id
  93. * @param client 客户端
  94. * @return {@link List}<{@link AppVerificationVo}>
  95. */
  96. @Select("select af.id, af.\"name\", af.app_url as url, af.app_icon, af.app_priority as priority " +
  97. "from sqmdb_rpt.acl_function af " +
  98. "inner join sqmdb_rpt.acl_user_function auf " +
  99. "on af.id = auf.function_id " +
  100. "where auf.user_id = #{userId} " +
  101. "and (af.client = 0 or af.client = #{client}) " +
  102. "order by af.app_priority desc")
  103. List<AppVerificationVo> listAppFunctions(Integer userId, Integer client);
  104. /**
  105. * 查询用户的web功能列表
  106. *
  107. * @param userId 用户id
  108. * @param client 客户端
  109. * @return {@link List}<{@link WebFunctionVo}>
  110. */
  111. @Select("select af.id, af.\"name\", af.web_url as url, af.web_icon, af.web_priority as priority " +
  112. "from sqmdb_rpt.acl_function af " +
  113. "inner join sqmdb_rpt.acl_user_function auf " +
  114. "on af.id = auf.function_id " +
  115. "where auf.user_id = #{userId} " +
  116. "and (af.client = 0 or af.client = #{client}) " +
  117. "order by af.web_priority desc")
  118. List<WebFunctionVo> listWebFunctions(Integer userId, Integer client);
  119. /**
  120. * 查询用户列表
  121. *
  122. */
  123. @Select("<script> " +
  124. "select au.*, aa1.area_name as province_name, aa2.area_name as city_name, aa3.area_name as area_name " +
  125. "from sqmdb_rpt.acl_user au " +
  126. "left join sqmdb_rpt.acl_area aa1 on au.province_id = aa1.area_id " +
  127. "left join sqmdb_rpt.acl_area aa2 on au.city_id = aa2.area_id " +
  128. "left join sqmdb_rpt.acl_area aa3 on au.area_id = aa3.area_id " +
  129. "where au.deleted = 0 " +
  130. "<if test=\"dto.loginName != null and dto.loginName != ''\"> " +
  131. " and au.login_name like concat(#{dto.loginName}, '%') " +
  132. "</if> " +
  133. "<if test=\"dto.userName != null and dto.userName != ''\"> " +
  134. " and au.user_name like concat(#{dto.userName}, '%') " +
  135. "</if> " +
  136. "<if test=\"dto.org != null and dto.org != ''\"> " +
  137. " and au.org like concat('%', #{dto.org}, '%') " +
  138. "</if> " +
  139. "<if test='dto.areaId'> " +
  140. " and (au.province_id = #{dto.areaId} or au.city_id = #{dto.areaId} or au.area_id = #{dto.areaId}) " +
  141. "</if> " +
  142. "</script>"
  143. )
  144. List<ListUserVo> list(Page<ListUserVo> page, ListUserDto dto);
  145. /**
  146. * 查询top用户信息
  147. *
  148. * @param loginName 登录名
  149. * @return {@link TopUserVo}
  150. */
  151. @Select("select atu.*, aa1.area_name as province_name, aa2.area_name as city_name, aa3.area_name as area_name " +
  152. "from sqmdb_rpt.acl_top_user atu " +
  153. "left join sqmdb_rpt.acl_area aa1 on atu.province_id = aa1.area_id " +
  154. "left join sqmdb_rpt.acl_area aa2 on atu.city_id = aa2.area_id " +
  155. "left join sqmdb_rpt.acl_area aa3 on atu.area_id = aa3.area_id " +
  156. "where login_name = #{loginName}")
  157. TopUserVo getTopUserByLoginName(String loginName);
  158. /**
  159. * 判断账号是否存在且状态正常
  160. *
  161. * @param loginName 登录名
  162. * @return {@link Object}
  163. */
  164. @Select("select 1 from sqmdb_rpt.acl_user where deleted = 0 and login_name = #{loginName}")
  165. Object hasLoginName(String loginName);
  166. /**
  167. * 获取用户详细
  168. *
  169. * @param userId 用户id
  170. * @return {@link GetUserDetailVo}
  171. */
  172. @Select("select au.*, au.org as org_name, aa1.area_name as province_name, aa2.area_name as city_name, aa3.area_name as area_name " +
  173. "from sqmdb_rpt.acl_user au " +
  174. "left join sqmdb_rpt.acl_area aa1 on au.province_id = aa1.area_id " +
  175. "left join sqmdb_rpt.acl_area aa2 on au.city_id = aa2.area_id " +
  176. "left join sqmdb_rpt.acl_area aa3 on au.area_id = aa3.area_id " +
  177. "where au.user_id = #{userId}")
  178. GetUserDetailVo getUserDetail(Integer userId);
  179. /**
  180. * 获取用户详细角色
  181. *
  182. * @param userId 用户id
  183. * @return {@link List}<{@link GetUserDetailRoleVo}>
  184. */
  185. @Select("select aurc.role_id, aurc.city_id, ar.role_name, ar.\"system\", ar.function_id, " +
  186. "af.\"name\" as function_name, as2.system_name, aa.area_name as city_name " +
  187. "from sqmdb_rpt.acl_user_role_city aurc " +
  188. "inner join sqmdb_rpt.acl_role ar on aurc.role_id = ar.role_id " +
  189. "inner join sqmdb_rpt.acl_area aa on aurc.city_id = aa.area_id " +
  190. "inner join sqmdb_rpt.acl_system as2 on ar.\"system\" = as2.\"system\" " +
  191. "inner join sqmdb_rpt.acl_function af on af.id = ar.function_id " +
  192. "where aurc.user_id = #{userId}")
  193. List<GetUserDetailRoleVo> getUserDetailRole(Integer userId);
  194. /**
  195. * 获取账号角色
  196. *
  197. * @param loginName 登录名
  198. * @return {@link List}<{@link GetRoleByLoginNameVo}>
  199. */
  200. @Select("select aurc.role_id, aurc.city_id, ar.role_name, ar.\"system\", ar.function_id, " +
  201. "af.\"name\" as function_name, as2.system_name, aa.area_name as city_name " +
  202. "from sqmdb_rpt.acl_user_role_city aurc " +
  203. "inner join sqmdb_rpt.acl_user au on aurc.user_id = au.user_id " +
  204. "inner join sqmdb_rpt.acl_role ar on aurc.role_id = ar.role_id " +
  205. "inner join sqmdb_rpt.acl_system as2 on ar.\"system\" = as2.\"system\" " +
  206. "inner join sqmdb_rpt.acl_area aa on aurc.city_id = aa.area_id " +
  207. "inner join sqmdb_rpt.acl_function af on af.id = ar.function_id " +
  208. "where au.login_name = #{loginName}")
  209. List<GetRoleByLoginNameVo> getRoleByLoginName(String loginName);
  210. /**
  211. * 根据账号查询用户信息
  212. *
  213. * @param loginName 登录名
  214. * @return {@link User}
  215. */
  216. @Select("select * from sqmdb_rpt.acl_user where login_name = #{loginName}")
  217. User selectByLoginName(String loginName);
  218. /**
  219. * 存在其他地市用户
  220. *
  221. * @param cityId 地市id
  222. * @param list 用户id列表
  223. * @return {@link Object}
  224. */
  225. @Select("<script> " +
  226. "select 1 from sqmdb_rpt.acl_user " +
  227. "where city_id != #{cityId} and user_id in " +
  228. "<foreach open=\"(\" close=\")\" collection=\"list\" item=\"item\" separator=\",\"> " +
  229. " #{item} " +
  230. "</foreach> " +
  231. "limit 1 " +
  232. "</script>")
  233. Object exceptCityUser(Integer cityId, List<Integer> list);
  234. /**
  235. * 通过用户id获取地市id
  236. *
  237. * @param list 列表
  238. * @return {@link List}<{@link Integer}>
  239. */
  240. @Select("<script> " +
  241. "select city_id from sqmdb_rpt.acl_user " +
  242. "where user_id in " +
  243. "<foreach open=\"(\" close=\")\" collection=\"list\" item=\"item\" separator=\",\"> " +
  244. " #{item} " +
  245. "</foreach> " +
  246. "</script>")
  247. List<Integer> getCityIdsByUserIds(List<Integer> list);
  248. /**
  249. * 查询所有用户
  250. *
  251. * @return {@link List}<{@link UserVo}>
  252. */
  253. @Select("select * from sqmdb_rpt.acl_user where deleted = 0 order by user_id")
  254. List<UserVo> baseList();
  255. }