SysUserMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.aidex.system.mapper.SysUserMapper">
  6. <sql id="userColumns">
  7. t.id as "id",
  8. t.dept_id AS "deptId",
  9. t.name AS "name",
  10. t.name_en AS "nameEn",
  11. t.no AS "no",
  12. t.user_name AS "userName",
  13. t.nick_name AS "nickName",
  14. t.user_type AS "userType",
  15. t.email AS "email",
  16. t.phonenumber AS "phonenumber",
  17. t.sex AS "sex",
  18. t.avatar AS "avatar",
  19. t.password AS "password",
  20. t.birthday AS "birthday",
  21. t.nation AS "nation",
  22. t.birth_address AS "birthAddress",
  23. t.polity AS "polity",
  24. t.title AS "title",
  25. t.office_tel AS "officeTel",
  26. t.fax AS "fax",
  27. t.work_space AS "workSpace",
  28. t.sort AS "sort",
  29. t.user_pinyin AS "userPinyin",
  30. t.login_ip AS "loginIp",
  31. t.login_date AS "loginDate",
  32. t.status AS "status",
  33. t.create_by AS "createBy",
  34. t.create_dept AS "createDept",
  35. t.create_time AS "createTime",
  36. t.update_by AS "updateBy",
  37. t.update_time AS "updateTime",
  38. t.update_ip AS "updateIp",
  39. t.remark AS "remark",
  40. t.version AS "version",
  41. t.del_flag AS "delFlag"
  42. </sql>
  43. <!--用户返回对象集合时使用-->
  44. <resultMap type="SysUser" id="SysUserResult">
  45. <id property="id" column="id" />
  46. <result property="deptId" column="dept_id" />
  47. <result property="userName" column="user_name" />
  48. <result property="name" column="name" />
  49. <result property="nickName" column="nick_name" />
  50. <result property="userType" column="user_type" />
  51. <result property="email" column="email" />
  52. <result property="phonenumber" column="phonenumber" />
  53. <result property="officeTel" column="office_tel" />
  54. <result property="sex" column="sex" />
  55. <result property="avatar" column="avatar" />
  56. <result property="password" column="password" />
  57. <result property="status" column="status" />
  58. <result property="delFlag" column="del_flag" />
  59. <result property="loginIp" column="login_ip" />
  60. <result property="loginDate" column="login_date" />
  61. <result property="createBy" column="create_by" />
  62. <result property="createTime" column="create_time" />
  63. <result property="updateBy" column="update_by" />
  64. <result property="updateTime" column="update_time" />
  65. <result property="remark" column="remark" />
  66. <association property="sysDept" column="dept_id" javaType="SysDept" resultMap="deptResult" />
  67. <collection property="sysRoles" javaType="java.util.List" resultMap="RoleResult" />
  68. </resultMap>
  69. <resultMap id="deptResult" type="SysDept">
  70. <id property="id" column="dept_id" />
  71. <result property="parentId" column="parent_id" />
  72. <result property="deptName" column="dept_name" />
  73. <result property="treeSort" column="tree_sort" />
  74. <result property="leader" column="leader" />
  75. <result property="status" column="dept_status" />
  76. </resultMap>
  77. <resultMap id="RoleResult" type="SysRole">
  78. <id property="id" column="id" />
  79. <result property="roleName" column="role_name" />
  80. <result property="roleKey" column="role_key" />
  81. <result property="sort" column="sort" />
  82. <result property="dataScope" column="data_scope" />
  83. <result property="status" column="role_status" />
  84. </resultMap>
  85. <sql id="columnWhere">
  86. <if test="userName != null and userName != ''">
  87. AND t.user_name like concat('%', #{userName}, '%')
  88. </if>
  89. <if test="name != null and name != ''">
  90. AND t.name like concat('%', #{name}, '%')
  91. </if>
  92. <if test="status != null and status != ''">
  93. AND t.status = #{status}
  94. </if>
  95. <if test="phonenumber != null and phonenumber != ''">
  96. AND t.phonenumber like concat('%', #{phonenumber}, '%')
  97. </if>
  98. <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
  99. AND date_format(t.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
  100. </if>
  101. <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
  102. AND date_format(t.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
  103. </if>
  104. <if test="deptId != null and deptId != ''">
  105. AND t.dept_id IN (select d.id from sys_dept d where concat(d.parent_ids, '/') like concat('%', #{deptId}, '/%') )
  106. </if>
  107. </sql>
  108. <select id="get" resultType="SysUser">
  109. SELECT
  110. <include refid="userColumns"/>,
  111. d.dept_name AS "sysDept.deptName", d.leader AS "sysDept.leader"
  112. FROM sys_user t
  113. left join sys_dept d on t.dept_id = d.id
  114. where t.id = #{id}
  115. </select>
  116. <select id="findList" resultType="SysUser">
  117. select
  118. <include refid="userColumns"/>,
  119. d.dept_name AS "sysDept.deptName", d.leader AS "sysDept.leader"
  120. from sys_user t
  121. left join sys_dept d on t.dept_id = d.id
  122. where t.del_flag = #{DEL_FLAG_NORMAL}
  123. <include refid="columnWhere"/>
  124. <!-- 数据范围过滤 -->
  125. ${params.dataScope}
  126. <choose>
  127. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  128. ORDER BY ${page.orderBy}
  129. </when>
  130. <otherwise>
  131. ORDER BY t.update_time DESC
  132. </otherwise>
  133. </choose>
  134. </select>
  135. <select id="findListWithUnique" resultType="SysUser">
  136. SELECT
  137. 1
  138. FROM sys_user t
  139. where t.del_flag = #{DEL_FLAG_NORMAL}
  140. <if test="userName != null and userName != ''">
  141. AND t.user_name = #{userName}
  142. </if>
  143. <if test="name != null and name != ''">
  144. AND t.name = #{name}
  145. </if>
  146. <if test="no != null and no != ''">
  147. AND t.no = #{no}
  148. </if>
  149. <if test="email != null and email != ''">
  150. AND t.email = #{email}
  151. </if>
  152. <if test="phonenumber != null and phonenumber != ''">
  153. AND t.phonenumber = #{phonenumber}
  154. </if>
  155. <if test="notEqualId != null and notEqualId != ''">
  156. AND t.id != #{notEqualId}
  157. </if>
  158. </select>
  159. <insert id="insert" >
  160. insert into sys_user(
  161. id,
  162. dept_id,
  163. name,
  164. name_en,
  165. no,
  166. user_name,
  167. nick_name,
  168. user_type,
  169. email,
  170. phonenumber,
  171. sex,
  172. avatar,
  173. password,
  174. birthday,
  175. nation,
  176. birth_address,
  177. polity,
  178. title,
  179. office_tel,
  180. fax,
  181. work_space,
  182. sort,
  183. user_pinyin,
  184. login_ip,
  185. login_date,
  186. status,
  187. create_by,
  188. create_dept,
  189. create_time,
  190. update_by,
  191. update_time,
  192. update_ip,
  193. remark,
  194. version,
  195. del_flag
  196. )values(
  197. #{id},
  198. #{deptId},
  199. #{name},
  200. #{nameEn},
  201. #{no},
  202. #{userName},
  203. #{nickName},
  204. #{userType},
  205. #{email},
  206. #{phonenumber},
  207. #{sex},
  208. #{avatar},
  209. #{password},
  210. #{birthday},
  211. #{nation},
  212. #{birthAddress},
  213. #{polity},
  214. #{title},
  215. #{officeTel},
  216. #{fax},
  217. #{workSpace},
  218. #{sort},
  219. #{userPinyin},
  220. #{loginIp},
  221. #{loginDate},
  222. #{status},
  223. #{createBy},
  224. #{createDept},
  225. #{createTime},
  226. #{updateBy},
  227. #{updateTime},
  228. #{updateIp},
  229. #{remark},
  230. 1,
  231. #{DEL_FLAG_NORMAL}
  232. )
  233. </insert>
  234. <update id="update">
  235. update sys_user
  236. <set>
  237. <if test="deptId != null"> dept_id = #{deptId}, </if>
  238. <if test="name != null"> name = #{name}, </if>
  239. <if test="nameEn != null"> name_en = #{nameEn}, </if>
  240. <if test="no != null"> no = #{no}, </if>
  241. <if test="userName != null"> user_name = #{userName}, </if>
  242. <if test="nickName != null"> nick_name = #{nickName}, </if>
  243. <if test="userType != null">user_type = #{userType}, </if>
  244. <if test="email != null">email = #{email}, </if>
  245. <if test="phonenumber != null">phonenumber = #{phonenumber}, </if>
  246. <if test="sex != null">sex = #{sex}, </if>
  247. <if test="avatar != null">avatar = #{avatar}, </if>
  248. <if test="password != null">password = #{password}, </if>
  249. <if test="birthday != null">birthday = #{birthday}, </if>
  250. <if test="nation != null">nation = #{nation}, </if>
  251. <if test="birthAddress != null">birth_address = #{birthAddress}, </if>
  252. <if test="polity != null">polity = #{polity}, </if>
  253. <if test="title != null">title = #{title}, </if>
  254. <if test="officeTel != null">office_tel = #{officeTel}, </if>
  255. <if test="fax != null">fax = #{fax}, </if>
  256. <if test="workSpace != null">work_space = #{workSpace}, </if>
  257. <if test="sort != null">sort = #{sort}, </if>
  258. <if test="userPinyin != null">user_pinyin = #{userPinyin}, </if>
  259. <if test="loginIp != null">login_ip = #{loginIp}, </if>
  260. <if test="loginDate != null">login_date = #{loginDate}, </if>
  261. <if test="status != null">status = #{status}, </if>
  262. <if test="updateBy != null">update_by = #{updateBy}, </if>
  263. <if test="updateTime != null">update_time = #{updateTime}, </if>
  264. <if test="updateIp != null">update_ip = #{updateIp}, </if>
  265. <if test="remark != null">remark = #{remark}, </if>
  266. version = version + 1
  267. </set>
  268. where id = #{id} and version = #{version}
  269. </update>
  270. <sql id="selectUserVo">
  271. select
  272. t.id,
  273. t.dept_id,
  274. t.user_name,
  275. t.name,
  276. t.nick_name,
  277. t.user_type,
  278. t.email,
  279. t.avatar,
  280. t.phonenumber,
  281. t.office_tel,
  282. t.password,
  283. t.sex,
  284. t.status,
  285. t.del_flag,
  286. t.login_ip,
  287. t.login_date,
  288. t.create_by,
  289. t.create_time,
  290. t.remark,
  291. d.id as dept_id,
  292. d.parent_id,
  293. d.dept_name,
  294. d.tree_sort,
  295. d.leader,
  296. d.status as dept_status,
  297. r.id,
  298. r.role_name,
  299. r.role_key,
  300. r.sort,
  301. r.data_scope,
  302. r.status as role_status
  303. from sys_user t
  304. left join sys_dept d on t.dept_id = d.id
  305. left join sys_user_role ur on t.id = ur.user_id
  306. left join sys_role r on r.id = ur.role_id
  307. </sql>
  308. <select id="selectUserByUserName" parameterType="java.util.Map" resultMap="SysUserResult">
  309. <include refid="selectUserVo"/>
  310. where t.user_name = #{userName} and t.del_flag = #{DEL_FLAG_NORMAL}
  311. </select>
  312. <select id="selectUserById" parameterType="String" resultMap="SysUserResult">
  313. <include refid="selectUserVo"/>
  314. where t.id = #{userId}
  315. </select>
  316. <select id="checkUserNameUnique" parameterType="String" resultType="int">
  317. select count(1) from sys_user where user_name = #{userName} and del_flag = '0' limit 1
  318. </select>
  319. <select id="checkPhoneUnique" parameterType="String" resultType="SysUser">
  320. select id, phonenumber from sys_user where phonenumber = #{phonenumber} and del_flag = '0' limit 1
  321. </select>
  322. <select id="checkEmailUnique" parameterType="String" resultType="SysUser">
  323. select id, email from sys_user where email = #{email} and del_flag = '0' limit 1
  324. </select>
  325. <update id="updateUserStatus" parameterType="SysUser">
  326. update sys_user set status = #{status} where id = #{id}
  327. </update>
  328. <update id="updateUserAvatar" parameterType="SysUser">
  329. update sys_user set avatar = #{avatar} where user_name = #{userName}
  330. </update>
  331. <update id="updateUserLoginInfo" parameterType="SysUser">
  332. update sys_user set
  333. login_ip = #{loginIp},
  334. login_date = #{loginDate}
  335. where id = #{id}
  336. </update>
  337. <update id="resetUserPwd" parameterType="SysUser">
  338. update sys_user set password = #{password} where user_name = #{userName}
  339. </update>
  340. <delete id="delete">
  341. UPDATE sys_user SET
  342. del_flag = #{DEL_FLAG_DELETE}
  343. WHERE id = #{id}
  344. </delete>
  345. <delete id="deleteUserByIds" parameterType="java.util.Map">
  346. UPDATE sys_user SET
  347. del_flag = #{DEL_FLAG_DELETE}
  348. WHERE id in
  349. <foreach collection="array" item="ids" open="(" separator="," close=")">
  350. #{ids}
  351. </foreach>
  352. </delete>
  353. <delete id="deleteBatch" parameterType="java.util.List">
  354. <foreach collection="list" item="item" index="index" open="" close="" separator=";">
  355. UPDATE sys_user SET
  356. del_flag = #{DEL_FLAG_DELETE}
  357. WHERE id = #{item.id}
  358. </foreach>
  359. </delete>
  360. <select id="getUserInfoByIds" parameterType="java.util.List" resultType="java.util.HashMap">
  361. SELECT
  362. t.id,
  363. concat(d.parent_ids,'/',t.id) as 'parentIds',
  364. t.name,
  365. d.dept_name as 'subtitle',
  366. 'user' as 'icon'
  367. FROM
  368. sys_user t
  369. left join sys_dept d on t.dept_id = d.id
  370. <where>
  371. t.del_flag = 0
  372. and ( 1 != 1
  373. <foreach collection="ids" item="idsItem">
  374. or t.id in
  375. <foreach collection="idsItem" item="id" open="(" separator="," close=")">
  376. #{id}
  377. </foreach>
  378. </foreach>
  379. )
  380. </where>
  381. </select>
  382. <select id="findRoleUserList" resultType="SysUser">
  383. SELECT
  384. <include refid="userColumns"/>
  385. FROM
  386. sys_user_role r
  387. LEFT JOIN sys_user t ON r.user_id = t.id
  388. WHERE
  389. t.del_flag = #{DEL_FLAG_NORMAL}
  390. AND r.role_id = #{roleId}
  391. AND t.id IS NOT NULL
  392. <if test="userNameOrName != null and userNameOrName != ''">
  393. AND (t.user_name like concat('%', #{userNameOrName}, '%') or t.name like concat('%', #{userNameOrName}, '%'))
  394. </if>
  395. </select>
  396. </mapper>