UserDao.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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"
  17. + " from sqmdb_rpt.acl_user u, sqmdb_rpt.acl_role r, sqmdb_rpt.acl_user_role_city ur"
  18. + " where u.user_id = ur.user_id"
  19. + " and r.role_id = ur.role_id"
  20. + " and r.system='flow'"
  21. + " and u.user_name like concat('%',#{username},'%')")
  22. List<FlowRoleVo> findRoleList(String username);
  23. /**
  24. * 查询全部
  25. */
  26. @Select("select role_id, role_name from sqmdb_rpt.acl_role where system = 'flow'")
  27. List<FlowRoleVo> findRoleList2();
  28. /**
  29. * 查询全部用户(流程所需),未分页
  30. */
  31. @Results({
  32. @Result(column = "org_id", property = "org.orgId"),
  33. @Result(column = "org_name", property = "org.orgName"),
  34. })
  35. @Select("select a.user_id as user_id, a.login_name as login_id, a.user_name as user_name, a.phone as mobile,"
  36. + " a.email as email, a.city_id as org_id, c1.area_name as org_name, a.area_id as area"
  37. + " from sqmdb_rpt.acl_user a, sqmdb_rpt.acl_area c1"
  38. + " where a.city_id = c1.area_id"
  39. + " and a.deleted = 0")
  40. List<FlowUserVo> findToPage();
  41. /**
  42. * 查询登录用户信息
  43. */
  44. @Results({
  45. @Result(column = "org_id", property = "org.orgId"),
  46. @Result(column = "org_name", property = "org.orgName"),
  47. })
  48. @Select("select a.user_id as user_id, a.login_name as login_id, a.user_name as user_name, a.phone as mobile,"
  49. + " a.email as email, a.city_id as org_id, c.area_name as org_name, a.area_id as area"
  50. + " from sqmdb_rpt.acl_user a, sqmdb_rpt.acl_area c"
  51. + " where a.city_id = c.area_id and a.login_name=#{loginId} and a.deleted = 0")
  52. FlowUserVo getFlowUserVoByLoginId(String loginId);
  53. /**
  54. * 根据用户ID获取用户接口
  55. */
  56. @Results({
  57. @Result(column = "org_id", property = "org.orgId"),
  58. @Result(column = "org_name", property = "org.orgName"),
  59. })
  60. @Select("select a.user_id as user_id, a.login_name as login_id, a.user_name as user_name, a.phone as mobile,"
  61. + " a.email as email, a.city_id as org_id, c.area_name as org_name, a.area_id as area"
  62. + " from sqmdb_rpt.acl_user a, sqmdb_rpt.acl_area c"
  63. + " where a.city_id = c.area_id and user_id=#{userId} and a.deleted = 0")
  64. FlowUserVo getFlowUserVoByUserId(Integer userId);
  65. @Select("select r.role_id from sqmdb_rpt.acl_role r, sqmdb_rpt.acl_user_role_city ur"
  66. + " where r.role_id = ur.role_id and r.system='flow' and ur.user_id=#{userId}")
  67. List<Integer> findRoleIdByUserId(Integer userId);
  68. @Select("select u.user_id from sqmdb_rpt.acl_user u, sqmdb_rpt.acl_user_role_city ur"
  69. + " where u.user_id = ur.user_id and ur.role_id=#{roleId} and u.deleted = 0")
  70. List<Integer> findUserIdByRoleId(Integer roleId);
  71. @Results({
  72. @Result(column = "org_id", property = "org.orgId"),
  73. @Result(column = "org_name", property = "org.orgName"),
  74. })
  75. @Select("<script>"
  76. + " select a.user_id as user_id, a.login_name as login_id, a.user_name as user_name, a.phone as mobile,"
  77. + " a.email as email, a.city_id as org_id, c.area_name as org_name, a.area_id as area"
  78. + " from sqmdb_rpt.acl_user a, sqmdb_rpt.acl_area c, sqmdb_rpt.acl_user_role_city ur"
  79. + " where a.user_id = ur.user_id and a.city_id = c.area_id and a.deleted = 0"
  80. + " <if test=\"loginId != null and loginId !=''\">"
  81. + " and a.login_name=#{loginId}"
  82. + " </if>"
  83. + " <if test=\"roleId != null\">"
  84. + " and ur.role_id=#{roleId}"
  85. + " </if>"
  86. + " <if test=\"userName != null and userName !=''\">"
  87. + " and a.user_name like concat('%',#{userName},'%')"
  88. + " </if>"
  89. + " </script>")
  90. List<FlowUserVo> findAuthorizedUser(@Param("loginId") String loginId, @Param("roleId") Integer roleId,
  91. @Param("userName") String userName);
  92. List<Role> getRoleCityByUserId(Integer userId);
  93. User getByLoginName(String loginName);
  94. List<User> getByRoleIds(@Param("roleIds") List<Integer> roleIds, @Param("cityIds") List<Integer> cityIds);
  95. List<String> getPhoneListByRole(@Param("roleId") Integer roleId, @Param("cityId") Integer cityId);
  96. /**
  97. * 查询用户的app功能列表
  98. *
  99. * @param userId 用户id
  100. * @param client 客户端
  101. * @return {@link List}<{@link AppVerificationVo}>
  102. */
  103. @Select("select af.id, af.\"name\", af.app_url as url, af.app_icon, af.app_priority as priority"
  104. + " from sqmdb_rpt.acl_function af"
  105. + " inner join sqmdb_rpt.acl_user_function auf"
  106. + " on af.id = auf.function_id"
  107. + " where auf.user_id = #{userId}"
  108. + " and (af.client = 0 or af.client = #{client})"
  109. + " order by af.app_priority desc")
  110. List<AppVerificationVo> listAppFunctions(@Param("userId") Integer userId, @Param("client") Integer client);
  111. /**
  112. * 查询用户的web功能列表
  113. *
  114. * @param userId 用户id
  115. * @param client 客户端
  116. * @return {@link List}<{@link WebFunctionVo}>
  117. */
  118. @Select("select af.id, af.\"name\", af.web_url as url, af.web_icon, af.web_priority as priority, af.\"system\","
  119. + " as2.system_name"
  120. + " from sqmdb_rpt.acl_function af"
  121. + " inner join sqmdb_rpt.acl_user_function auf on af.id = auf.function_id"
  122. + " inner join sqmdb_rpt.acl_system as2 on af.\"system\" = as2.\"system\""
  123. + " where auf.user_id = #{userId}"
  124. + " and (af.client = 0 or af.client = #{client})"
  125. + " order by af.web_priority desc")
  126. List<WebFunctionVo> listWebFunctions(@Param("userId") Integer userId, @Param("client") Integer client);
  127. /**
  128. * 判断用户是否有权限
  129. */
  130. @Select("select exists (select 1 from sqmdb_rpt.acl_user_role_city where role_id = #{roleId} and user_id = #{userId})")
  131. boolean hasRole(@Param("roleId") Integer roleId, @Param("userId") Integer userId);
  132. /**
  133. * 查询用户列表
  134. */
  135. @Select("<script>"
  136. + " select au.*, aa1.area_name as province_name, aa2.area_name as city_name, aa3.area_name as area_name"
  137. + " from sqmdb_rpt.acl_user au"
  138. + " left join sqmdb_rpt.acl_area aa1 on au.province_id = aa1.area_id"
  139. + " left join sqmdb_rpt.acl_area aa2 on au.city_id = aa2.area_id"
  140. + " left join sqmdb_rpt.acl_area aa3 on au.area_id = aa3.area_id"
  141. + " where au.deleted = 0 and au.test_user = 0"
  142. + " <if test=\"loginName != null and loginName != ''\">"
  143. + " and au.login_name like concat(#{loginName}, '%')"
  144. + " </if>"
  145. + " <if test=\"userName != null and userName != ''\">"
  146. + " and au.user_name like concat(#{userName}, '%')"
  147. + " </if>"
  148. + " <if test=\"org != null and org != ''\">"
  149. + " and au.org like concat('%', #{org}, '%')"
  150. + " </if>"
  151. + " <if test='areaId'>"
  152. + " and (au.province_id = #{areaId} or au.city_id = #{areaId} or au.area_id = #{areaId})"
  153. + " </if>"
  154. + " </script>"
  155. )
  156. List<ListUserVo> list(Page<ListUserVo> page, @Param("loginName") String loginName,
  157. @Param("userName") String userName, @Param("org") String org,
  158. @Param("areaId") Integer areaId);
  159. /**
  160. * 查询top用户信息
  161. *
  162. * @param loginName 登录名
  163. * @return {@link TopUserVo}
  164. */
  165. @Select("select atu.*, aa1.area_name as province_name, aa2.area_name as city_name, aa3.area_name as area_name"
  166. + " from sqmdb_rpt.acl_top_user atu"
  167. + " left join sqmdb_rpt.acl_area aa1 on atu.province_id = aa1.area_id"
  168. + " left join sqmdb_rpt.acl_area aa2 on atu.city_id = aa2.area_id"
  169. + " left join sqmdb_rpt.acl_area aa3 on atu.area_id = aa3.area_id"
  170. + " where login_name = #{loginName}")
  171. TopUserVo getTopUserByLoginName(String loginName);
  172. /**
  173. * 判断账号是否存在且状态正常
  174. *
  175. * @param loginName 登录名
  176. * @return {@link Object}
  177. */
  178. @Select("select 1 from sqmdb_rpt.acl_user where deleted = 0 and login_name = #{loginName}")
  179. Object hasLoginName(String loginName);
  180. /**
  181. * 获取用户详细
  182. *
  183. * @param userId 用户id
  184. * @return {@link GetUserDetailVo}
  185. */
  186. @Select("select au.*, au.org as org_name, aa1.area_name as province_name, aa2.area_name as city_name,"
  187. + " aa3.area_name as area_name"
  188. + " from sqmdb_rpt.acl_user au"
  189. + " left join sqmdb_rpt.acl_area aa1 on au.province_id = aa1.area_id"
  190. + " left join sqmdb_rpt.acl_area aa2 on au.city_id = aa2.area_id"
  191. + " left join sqmdb_rpt.acl_area aa3 on au.area_id = aa3.area_id"
  192. + " where au.user_id = #{userId}")
  193. GetUserDetailVo getUserDetail(Integer userId);
  194. /**
  195. * 获取用户详细角色
  196. *
  197. * @param userId 用户id
  198. * @return {@link List}<{@link GetUserDetailRoleVo}>
  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_role ar on aurc.role_id = ar.role_id"
  204. + " inner join sqmdb_rpt.acl_area aa on aurc.city_id = aa.area_id"
  205. + " inner join sqmdb_rpt.acl_system as2 on ar.\"system\" = as2.\"system\""
  206. + " inner join sqmdb_rpt.acl_function af on af.id = ar.function_id"
  207. + " where aurc.user_id = #{userId}"
  208. + " order by af.web_priority desc")
  209. List<GetUserDetailRoleVo> getUserDetailRole(Integer userId);
  210. /**
  211. * 获取账号角色
  212. *
  213. * @param loginName 登录名
  214. * @return {@link List}<{@link GetRoleByLoginNameVo}>
  215. */
  216. @Select("select aurc.role_id, aurc.city_id, ar.role_name, ar.\"system\", ar.function_id,"
  217. + " af.\"name\" as function_name, as2.system_name, aa.area_name as city_name"
  218. + " from sqmdb_rpt.acl_user_role_city aurc"
  219. + " inner join sqmdb_rpt.acl_user au on aurc.user_id = au.user_id"
  220. + " inner join sqmdb_rpt.acl_role ar on aurc.role_id = ar.role_id"
  221. + " inner join sqmdb_rpt.acl_system as2 on ar.\"system\" = as2.\"system\""
  222. + " inner join sqmdb_rpt.acl_area aa on aurc.city_id = aa.area_id"
  223. + " inner join sqmdb_rpt.acl_function af on af.id = ar.function_id"
  224. + " where au.login_name = #{loginName}"
  225. + " order by af.web_priority desc")
  226. List<GetRoleByLoginNameVo> getRoleByLoginName(String loginName);
  227. /**
  228. * 根据账号查询用户信息
  229. *
  230. * @param loginName 登录名
  231. * @return {@link User}
  232. */
  233. @Select("select * from sqmdb_rpt.acl_user where login_name = #{loginName}")
  234. User selectByLoginName(String loginName);
  235. /**
  236. * 存在其他地市用户
  237. *
  238. * @param cityId 地市id
  239. * @param list 用户id列表
  240. * @return {@link Object}
  241. */
  242. @Select("<script>"
  243. + " select 1 from sqmdb_rpt.acl_user"
  244. + " where city_id != #{cityId} and user_id in"
  245. + " <foreach open=\"(\" close=\")\" collection=\"list\" item=\"item\" separator=\",\">"
  246. + " #{item}"
  247. + " </foreach>"
  248. + " limit 1"
  249. + " </script>")
  250. Object exceptCityUser(Integer cityId, List<Integer> list);
  251. /**
  252. * 通过用户id获取地市id
  253. *
  254. * @param list 列表
  255. * @return {@link List}<{@link Integer}>
  256. */
  257. @Select("<script>"
  258. + " select distinct city_id from sqmdb_rpt.acl_user"
  259. + " where user_id in"
  260. + " <foreach open=\"(\" close=\")\" collection=\"list\" item=\"item\" separator=\",\">"
  261. + " #{item}"
  262. + " </foreach>"
  263. + " </script>")
  264. List<Integer> getCityIdsByUserIds(List<Integer> list);
  265. /**
  266. * 查询所有用户,过滤已删除和测试用户
  267. *
  268. * @return {@link List}<{@link UserVo}>
  269. */
  270. @Select("select * from sqmdb_rpt.acl_user where deleted = 0 and test_user = 0 order by user_id")
  271. List<UserVo> baseList();
  272. /**
  273. * 查询地市管理者
  274. * @param cityId 地市id
  275. */
  276. @Select("select\n"
  277. + " *\n"
  278. + "from\n"
  279. + " sqmdb_rpt.acl_user a\n"
  280. + "where\n"
  281. + " test_user = 0\n"
  282. + " and deleted = 0\n"
  283. + " and exists (\n"
  284. + " select\n"
  285. + " 1\n"
  286. + " from\n"
  287. + " sqmdb_rpt.acl_user_role_city b\n"
  288. + " where\n"
  289. + " b.role_id = -1\n"
  290. + " and a.user_id = b.user_id)\n"
  291. + " and city_id = #{cityId}")
  292. List<User> getManagersByCityId(@Param("cityId") Integer cityId);
  293. @Select("select city_id from sqmdb_rpt.acl_top_user where login_name = #{loginName}")
  294. Integer getAclTopUserCityId(@Param("loginName") String loginName);
  295. }