UserDao.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="platform.modules.government.dao.UserDao">
  4. <select id="findByNickName" resultType="platform.modules.government.entity.User">
  5. SELECT * FROM z_user u WHERE u.nick_name = #{nick_name}
  6. <if test="user_type != null and user_type !=''">
  7. and u.user_type=${user_type}
  8. </if>
  9. and u.del_flag=0 LIMIT 0 ,1
  10. </select>
  11. <select id="findByNickNameOnly" resultType="platform.modules.government.entity.User">
  12. SELECT * FROM z_user u WHERE u.nick_name = #{nick_name}
  13. and u.del_flag=0 LIMIT 0 ,1
  14. </select>
  15. <select id="findByNickNameReg" resultType="platform.modules.government.entity.User">
  16. SELECT * FROM z_user u WHERE u.nick_name = #{nick_name}
  17. <if test="user_type != null and user_type !=''">
  18. and u.user_type=${user_type}
  19. </if>
  20. and u.del_flag=0 and u.is_register != 2 LIMIT 0 ,1
  21. </select>
  22. <select id="findByLogin" resultType="platform.modules.government.entity.User">
  23. SELECT * FROM z_user u
  24. WHERE (
  25. (u.nick_name = #{loginName} )
  26. or( u.phone = #{loginName} )
  27. or( u.organization_code = #{loginName} and u.user_type = #{companyType})
  28. )
  29. and u.del_flag=0 LIMIT 0 ,1
  30. </select>
  31. <select id="findByMobile" resultType="platform.modules.government.entity.User">
  32. SELECT * FROM z_user u WHERE u.phone = #{mobile}
  33. and u.del_flag=0 LIMIT 0 ,1
  34. </select>
  35. <select id="getUserByMobile" resultType="platform.modules.government.entity.User">
  36. SELECT * FROM z_user u WHERE u.phone = #{mobile}
  37. and u.del_flag=0
  38. </select>
  39. <select id="getUserByNickname" resultType="platform.modules.government.entity.User">
  40. SELECT * FROM z_user u WHERE u.nick_name = #{nickname}
  41. and u.del_flag=0
  42. </select>
  43. <select id="getUserByDepartmentId" resultType="platform.modules.government.entity.User">
  44. SELECT * FROM z_user u WHERE u.department_id = #{department_id}
  45. and u.del_flag=0
  46. </select>
  47. <select id="findUserIdsByUserId" resultType="Integer">
  48. SELECT id,approve_level from z_user where department_id =
  49. (SELECT department_id from z_user where id = #{userId}) and approve_level &gt; (SELECT approve_level from z_user where id = #{userId})
  50. </select>
  51. <select id="findDepartmentIdByUserId" resultType="Integer">
  52. SELECT department_id from z_user where id = #{currentUserId}
  53. </select>
  54. <select id="findUserBydepartmentId" resultType="platform.modules.government.entity.User">
  55. <![CDATA[
  56. SELECT * FROM z_user where department_id=#{id} AND approve_level > -1 and del_flag = 0
  57. ]]>
  58. </select>
  59. <select id="findUserBydepartmentIdWithoutApprovalLevel" resultType="platform.modules.government.entity.User">
  60. SELECT * FROM z_user where department_id=#{id} and del_flag = 0
  61. </select>
  62. <select id="findUserByCondition" resultType="platform.modules.government.entity.User">
  63. SELECT distinct u.*
  64. FROM
  65. z_user u
  66. LEFT JOIN s_street street on street.id = u.street_id
  67. LEFT JOIN sys_user_role ur on u.id = ur.user_id
  68. LEFT JOIN sys_department dept on dept.id = u.department_id
  69. WHERE
  70. u.del_flag =0 and u.is_register=1
  71. AND
  72. (street.del_flag = 0 or street.del_flag is null )
  73. AND
  74. u.user_type != #{siper}
  75. <if test="userData.user_type_build != null and userData.user_type_build != ''
  76. and userData.build_id != null and userData.build_id != ''">
  77. AND
  78. u.user_type = #{userData.user_type_build}
  79. AND
  80. u.build_id = #{userData.build_id}
  81. </if>
  82. <if test="userData.user_type_street != null and userData.user_type_street != ''
  83. and userData.street_id != null and userData.street_id != ''">
  84. AND
  85. u.user_type in (#{userData.user_type_street},#{company})
  86. AND
  87. u.street_id = #{userData.street_id}
  88. <if test="userData.search_user_type != null">
  89. AND
  90. u.user_type = #{userData.search_user_type}
  91. </if>
  92. </if>
  93. <if test="userData.user_type_goverment != null ">
  94. AND
  95. u.user_type in (#{government},#{company})
  96. <if test="userData.search_user_type != null">
  97. AND
  98. u.user_type = #{userData.search_user_type}
  99. </if>
  100. </if>
  101. <if test="userData.user_type_super != null and userData.user_type_super != ''">
  102. AND
  103. u.user_type not in (#{siper})
  104. <if test="userData.search_user_type != null">
  105. AND
  106. u.user_type = #{userData.search_user_type}
  107. </if>
  108. </if>
  109. <if test="userData.user_type_company != null and userData.user_type_company != ''
  110. and userData.company_id != null and userData.company_id != ''">
  111. AND
  112. u.user_type = #{userData.user_type_company}
  113. AND
  114. u.company_id = #{userData.company_id}
  115. </if>
  116. <if test="userData.keyWord != null and userData.keyWord !=''">
  117. AND
  118. ((u.user_name LIKE CONCAT(CONCAT('%',#{userData.keyWord}),'%'))
  119. OR(u.nick_name LIKE CONCAT(CONCAT('%',#{userData.keyWord}),'%'))
  120. OR(u.phone LIKE CONCAT(CONCAT('%',#{userData.keyWord}),'%'))
  121. OR(u.email LIKE CONCAT(CONCAT('%',#{userData.keyWord}),'%'))
  122. )
  123. </if>
  124. <if test="searchCondition.company_name != null and searchCondition.company_name !=''">
  125. AND (
  126. u.company_name LIKE CONCAT(CONCAT('%',#{searchCondition.company_name}),'%')
  127. OR dept.name LIKE CONCAT(CONCAT('%',#{searchCondition.company_name}),'%')
  128. OR street.name LIKE CONCAT(CONCAT('%',#{searchCondition.company_name}),'%')
  129. OR u.build_name LIKE CONCAT( CONCAT( '%', #{searchCondition.company_name} ), '%' )
  130. )
  131. </if>
  132. <if test="searchCondition.street_id != null and searchCondition.street_id !=''">
  133. AND u.street_id = #{searchCondition.street_id}
  134. </if>
  135. <if test="searchCondition.role_id != null and searchCondition.role_id !=''">
  136. AND ur.role_id = #{searchCondition.role_id}
  137. </if>
  138. ORDER BY u.create_time DESC
  139. </select>
  140. <update id="deleteCompanyUser">
  141. update z_user set del_flag=1
  142. where company_id = #{id}
  143. </update>
  144. <update id="updateIsRegist">
  145. update z_user set is_register = #{isRegistration}
  146. where id = #{id}
  147. </update>
  148. <select id="findUsersByPermission" resultType="platform.modules.government.entity.User">
  149. SELECT
  150. distinct zuser.*
  151. FROM
  152. z_user zuser
  153. JOIN sys_user_role sys_user_role ON sys_user_role.user_id = zuser.id
  154. JOIN sys_role_menu sys_role_menu ON sys_role_menu.role_id = sys_user_role.role_id
  155. JOIN sys_menu sys_menu ON sys_menu.id = sys_role_menu.menu_id
  156. WHERE
  157. sys_menu.permission = #{permission}
  158. </select>
  159. <select id="selectAllUsers" resultType="platform.modules.government.entity.User">
  160. SELECT *
  161. FROM
  162. z_user u
  163. WHERE
  164. u.del_flag =0 and u.is_register=1 and u.is_start=1
  165. </select>
  166. <update id="updateByCompanyId">
  167. update z_user
  168. <set>
  169. build_id = #{user.build_id},
  170. <if test="user.build_name != null">
  171. build_name = #{user.build_name},
  172. </if>
  173. <if test="user.street_id != null">
  174. street_id = #{user.street_id},
  175. </if>
  176. <if test="user.street_name != null">
  177. street_name = #{user.street_name},
  178. </if>
  179. <if test="user.company_name != null">
  180. company_name = #{user.company_name},
  181. </if>
  182. </set>
  183. where company_id = #{companyId}
  184. </update>
  185. <update id="updateApproveLevel">
  186. update z_user set approve_level=#{user.approve_level}
  187. where id = #{user.id}
  188. </update>
  189. <select id="getAllDepartmentUsers" resultType="platform.modules.government.entity.User">
  190. SELECT
  191. u.*
  192. FROM
  193. z_user u
  194. LEFT JOIN sys_department sd ON sd.id = u.department_id
  195. WHERE
  196. u.DEL_FLAG = 0
  197. AND ( sd.id = #{department} OR sd.parent_id = #{department} )
  198. </select>
  199. <select id="getUserByName" resultType="platform.modules.government.entity.User">
  200. SELECT * FROM z_user WHERE user_name LIKE CONCAT('%',#{checkName},'%')
  201. </select>
  202. <update id="updateStreetIsStart">
  203. update z_user
  204. set is_start = #{isLock}
  205. where
  206. <if test="streetId != null and streetId != ''">
  207. street_id = #{streetId}
  208. </if>
  209. <if test="buildId != null and buildId != ''">
  210. build_id = #{buildId}
  211. </if>
  212. </update>
  213. <select id="findAllGovUsers" resultType="platform.modules.api.dto.UserInfoDto">
  214. SELECT
  215. u.id,
  216. u.user_name userName,
  217. u.nick_name AS userLoginName,
  218. d.id AS departmentId,
  219. d.`name`AS departmentName
  220. FROM
  221. z_user u
  222. LEFT JOIN sys_department d ON d.id = u.department_id
  223. WHERE
  224. u.del_flag = 0
  225. AND u.user_type = 0
  226. <if test="departmentId != null and departmentId != ''">
  227. AND u.department_id = #{departmentId}
  228. </if>
  229. </select>
  230. <select id="findAllUsers" resultType="platform.modules.api.dto.UserInfoDto">
  231. SELECT
  232. u.id,
  233. u.user_name userName,
  234. u.nick_name AS userLoginName,
  235. u.PASSWORD,
  236. u.user_type AS userType,
  237. (SELECT `name` FROM sys_department WHERE id = u.department_id) AS departmentName,
  238. (SELECT `name` FROM s_street WHERE id = u.street_id) AS streetName,
  239. (SELECT `name` FROM ic_park WHERE id = u.build_id) AS parkName,
  240. IFNULL((SELECT company_name FROM y_company WHERE id = u.company_id), u.company_name) AS companyName
  241. FROM
  242. z_user u
  243. WHERE
  244. u.del_flag = 0 AND u.is_start = 1 AND user_type != 2
  245. <if test="userType != null and userType != ''">
  246. AND u.user_type = #{userType}
  247. </if>
  248. </select>
  249. <update id="updateDepartmentName">
  250. UPDATE z_user set build_name = #{park.name} where build_id = #{park.id}
  251. </update>
  252. <select id="findFirstContact" resultType="platform.modules.government.entity.User">
  253. select c.company_name, u.nick_name, u.user_name, u.phone from z_user u
  254. LEFT JOIN y_company c ON c.id = u.company_id
  255. WHERE u.company_id = #{id} ORDER BY create_time ASC LIMIT 1
  256. </select>
  257. <select id="findUserById" resultType="platform.modules.government.entity.User">
  258. select c.company_name, u.nick_name, u.user_name, u.phone from z_user u
  259. LEFT JOIN y_company c ON c.id = u.company_id
  260. WHERE u.del_flag = 0 AND u.is_use = 1 AND u.id = #{id}
  261. </select>
  262. </mapper>