SysUserInfoDao.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  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="com.liang.dao.SysUserInfoDao">
  4. <resultMap type="com.liang.entity.SysUserInfo" id="SysUserInfoMap">
  5. <result property="userId" column="user_id" jdbcType="INTEGER"/>
  6. <result property="account" column="account" jdbcType="VARCHAR"/>
  7. <result property="password" column="password" jdbcType="VARCHAR"/>
  8. <result property="name" column="name" jdbcType="VARCHAR"/>
  9. <result property="deptId" column="dept_id" jdbcType="INTEGER"/>
  10. <result property="phone" column="phone" jdbcType="VARCHAR"/>
  11. <result property="email" column="email" jdbcType="VARCHAR"/>
  12. <result property="avatar" column="avatar" jdbcType="VARCHAR"/>
  13. <result property="sex" column="sex" jdbcType="VARCHAR"/>
  14. <result property="status" column="status" jdbcType="VARCHAR"/>
  15. <result property="delFlag" column="del_flag" jdbcType="VARCHAR"/>
  16. <result property="createUser" column="create_user" jdbcType="INTEGER"/>
  17. <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
  18. <result property="updateUser" column="update_user" jdbcType="INTEGER"/>
  19. <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
  20. <result property="bz" column="bz" jdbcType="VARCHAR"/>
  21. </resultMap>
  22. <!--查询单个-->
  23. <select id="queryById" resultMap="SysUserInfoMap">
  24. select u.*, d.dept_name as deptName, d1.dept_name as deptName1, d2.dept_name as deptName2,u.bz
  25. from sys_user_info u
  26. left join sys_dept_info d on d.dept_id = u.dept_id
  27. left join sys_dept_info d1 on d1.dept_id = d.parent_id
  28. left join sys_dept_info d2 on d2.dept_id = d1.parent_id
  29. where user_id = #{userId}
  30. </select>
  31. <!--查询指定行数据-->
  32. <select id="queryAllByLimit" resultMap="SysUserInfoMap">
  33. select
  34. user_id, account, password, name, dept_id, phone, email, avatar, sex, status, del_flag, create_user,
  35. create_time, update_user, update_time
  36. from sys_user_info
  37. <where>
  38. <if test="userId != null">
  39. and user_id = #{userId}
  40. </if>
  41. <if test="account != null and account != ''">
  42. and account = #{account}
  43. </if>
  44. <if test="password != null">
  45. and password = #{password}
  46. </if>
  47. <if test="name != null and name != ''">
  48. and name = #{name}
  49. </if>
  50. <if test="deptId != null and deptId != ''">
  51. and dept_id = #{deptId}
  52. </if>
  53. <if test="phone != null">
  54. and phone = #{phone}
  55. </if>
  56. <if test="email != null">
  57. and email = #{email}
  58. </if>
  59. <if test="avatar != null">
  60. and avatar = #{avatar}
  61. </if>
  62. <if test="sex != null and sex != ''">
  63. and sex = #{sex}
  64. </if>
  65. <if test="status != null and status != ''">
  66. and status = #{status}
  67. </if>
  68. <if test="delFlag != null and delFlag != ''">
  69. and del_flag = #{delFlag}
  70. </if>
  71. <if test="createUser != null">
  72. and create_user = #{createUser}
  73. </if>
  74. <if test="createTime != null">
  75. and create_time = #{createTime}
  76. </if>
  77. <if test="updateUser != null">
  78. and update_user = #{updateUser}
  79. </if>
  80. <if test="updateTime != null">
  81. and update_time = #{updateTime}
  82. </if>
  83. </where>
  84. limit #{pageable.offset}, #{pageable.pageSize}
  85. </select>
  86. <!--统计总行数-->
  87. <select id="count" resultType="java.lang.Long">
  88. select count(1)
  89. from sys_user_info
  90. where del_flag = 0
  91. <if test="userId != null">
  92. and user_id = #{userId}
  93. </if>
  94. <if test="account != null and account != ''">
  95. and account = #{account}
  96. </if>
  97. <if test="password != null">
  98. and password = #{password}
  99. </if>
  100. <if test="name != null and name != ''">
  101. and name = #{name}
  102. </if>
  103. <if test="deptId != null and deptId != ''">
  104. and dept_id = #{deptId}
  105. </if>
  106. <if test="phone != null">
  107. and phone = #{phone}
  108. </if>
  109. <if test="email != null">
  110. and email = #{email}
  111. </if>
  112. <if test="avatar != null">
  113. and avatar = #{avatar}
  114. </if>
  115. <if test="sex != null and sex != ''">
  116. and sex = #{sex}
  117. </if>
  118. <if test="status != null and status != ''">
  119. and status = #{status}
  120. </if>
  121. <if test="delFlag != null and delFlag != ''">
  122. and del_flag = #{delFlag}
  123. </if>
  124. <if test="createUser != null">
  125. and create_user = #{createUser}
  126. </if>
  127. <if test="createTime != null">
  128. and create_time = #{createTime}
  129. </if>
  130. <if test="updateUser != null">
  131. and update_user = #{updateUser}
  132. </if>
  133. <if test="updateTime != null">
  134. and update_time = #{updateTime}
  135. </if>
  136. </select>
  137. <!--新增所有列-->
  138. <insert id="insert" keyProperty="userId" useGeneratedKeys="true">
  139. if
  140. not exists (select * from sys_user_info where account =
  141. #{account}
  142. and
  143. del_flag
  144. =
  145. 0
  146. )
  147. insert
  148. into
  149. sys_user_info
  150. (
  151. account,
  152. password,
  153. name,
  154. dept_id,
  155. phone,
  156. email,
  157. avatar,
  158. sex,
  159. create_user,
  160. create_time
  161. )
  162. values
  163. (
  164. #{account},
  165. #{password},
  166. #{name},
  167. #{deptId},
  168. #{phone},
  169. #{email},
  170. #{avatar},
  171. #{sex},
  172. #{createUser},
  173. GETDATE
  174. (
  175. )
  176. )
  177. </insert>
  178. <insert id="insertBatch" keyProperty="userId" useGeneratedKeys="true">
  179. insert into sys_user_info(account, password, name, dept_id, phone, email, avatar, sex, status, del_flag,
  180. create_user, create_time, update_user, update_time)
  181. values
  182. <foreach collection="entities" item="entity" separator=",">
  183. (#{entity.account}, #{entity.password}, #{entity.name}, #{entity.deptId}, #{entity.phone}, #{entity.email},
  184. #{entity.avatar}, #{entity.sex}, #{entity.status}, #{entity.delFlag}, #{entity.createUser},
  185. #{entity.createTime}, #{entity.updateUser}, #{entity.updateTime})
  186. </foreach>
  187. </insert>
  188. <insert id="insertOrUpdateBatch" keyProperty="userId" useGeneratedKeys="true">
  189. insert into sys_user_info(account, password, name, dept_id, phone, email, avatar, sex, status, del_flag,
  190. create_user, create_time, update_user, update_time)
  191. values
  192. <foreach collection="entities" item="entity" separator=",">
  193. (#{entity.account}, #{entity.password}, #{entity.name}, #{entity.deptId}, #{entity.phone}, #{entity.email},
  194. #{entity.avatar}, #{entity.sex}, #{entity.status}, #{entity.delFlag}, #{entity.createUser},
  195. #{entity.createTime}, #{entity.updateUser}, #{entity.updateTime})
  196. </foreach>
  197. on duplicate key update
  198. account = values(account),
  199. password = values(password),
  200. name = values(name),
  201. dept_id = values(dept_id),
  202. phone = values(phone),
  203. email = values(email),
  204. avatar = values(avatar),
  205. sex = values(sex),
  206. status = values(status),
  207. del_flag = values(del_flag),
  208. create_user = values(create_user),
  209. create_time = values(create_time),
  210. update_user = values(update_user),
  211. update_time = values(update_time)
  212. </insert>
  213. <!--通过主键修改数据-->
  214. <update id="update">
  215. update sys_user_info
  216. <set>
  217. <if test="account != null and account != ''">
  218. account = #{account},
  219. </if>
  220. <if test="password != null">
  221. password = #{password},
  222. </if>
  223. <if test="name != null and name != ''">
  224. name = #{name},
  225. </if>
  226. <if test="deptId != null and deptId != ''">
  227. dept_id = #{deptId},
  228. </if>
  229. <if test="phone != null">
  230. phone = #{phone},
  231. </if>
  232. <if test="email != null">
  233. email = #{email},
  234. </if>
  235. <if test="avatar != null">
  236. avatar = #{avatar},
  237. </if>
  238. <if test="sex != null and sex != ''">
  239. sex = #{sex},
  240. </if>
  241. <if test="status != null and status != ''">
  242. status = #{status},
  243. </if>
  244. update_user = #{updateUser},
  245. update_time = GETDATE(),
  246. bz = #{bz}
  247. </set>
  248. where user_id = #{userId}
  249. </update>
  250. <!--通过主键删除-->
  251. <delete id="deleteById">
  252. update sys_user_info
  253. set del_flag = 1,
  254. update_user = #{updateUser},
  255. update_time = GETDATE()
  256. where user_id = #{userId}
  257. </delete>
  258. <!--查询所有用户-->
  259. <select id="getSysUserInfoList" resultMap="SysUserInfoMap" parameterType="map">
  260. WITH RankedData AS (
  261. SELECT
  262. u.user_id,
  263. u.account,
  264. u.create_time,
  265. u.sex,
  266. u.name,
  267. u.phone,
  268. u.status,
  269. d.dept_name AS deptName,
  270. p.post_name,
  271. ROW_NUMBER() OVER (PARTITION BY u.user_id ORDER BY u.user_id) AS rn
  272. FROM
  273. sys_user_info u
  274. LEFT JOIN
  275. sys_dept_info d ON d.dept_id = u.dept_id
  276. LEFT JOIN
  277. sys_user_post up ON up.user_id = u.user_id
  278. LEFT JOIN
  279. sys_post_info p ON p.post_id = up.post_id
  280. WHERE
  281. u.del_flag = 0
  282. <if test="account != null and account != ''">
  283. and u.account like '%'+#{account}+'%'
  284. </if>
  285. <if test="name != null and name != ''">
  286. and u.name like '%'+#{name}+'%'
  287. </if>
  288. <if test="deptName != null and deptName != ''">
  289. and d.dept_name like '%'+#{deptName}+'%'
  290. </if>
  291. <if test="status != null and status != ''">
  292. and u.status = #{status}
  293. </if>
  294. <if test="id != null and id != ''">
  295. and u.user_id = #{id}
  296. </if>
  297. <if test="postName != null and postName != ''">
  298. and p.post_name like '%'+#{postName}+'%'
  299. </if>
  300. <if test="ssbm != null and ssbm != ''">
  301. and d.dept_id = #{ssbm}
  302. </if>
  303. )
  304. SELECT
  305. user_id,
  306. account,
  307. status,
  308. deptName,
  309. phone,
  310. create_time,
  311. sex,
  312. name,
  313. STUFF((SELECT '、' + post_name
  314. FROM RankedData sub
  315. WHERE sub.user_id = main.user_id
  316. AND sub.rn > 0
  317. FOR XML PATH('')), 1, 1, '') AS userPostName
  318. FROM
  319. RankedData main
  320. WHERE
  321. rn = 1;
  322. </select>
  323. <select id="getGw" resultMap="SysUserInfoMap" parameterType="map">
  324. select u.*, d.dept_name as deptName, p.post_name as userPostName
  325. from sys_user_info u
  326. left join sys_dept_info d on d.dept_id = u.dept_id
  327. left join sys_user_post up on up.user_id = u.user_id
  328. left join sys_post_info p on p.post_id = up.post_id
  329. where u.del_flag = 0
  330. <if test="account != null and account != ''">
  331. and u.account = #{account}
  332. </if>
  333. <if test="name != null and name != ''">
  334. and u.name like '%'+#{name}+'%'
  335. </if>
  336. <if test="deptName != null and deptName != ''">
  337. and d.dept_name like '%'+#{deptName}+'%'
  338. </if>
  339. <if test="status != null and status != ''">
  340. and u.status = #{status}
  341. </if>
  342. <if test="id != null and id != ''">
  343. and u.user_id = #{id}
  344. </if>
  345. <if test="postName != null and postName != ''">
  346. and p.post_name like '%'+#{postName}+'%'
  347. </if>
  348. <if test="ssbm != null and ssbm != ''">
  349. and d.dept_id = #{ssbm}
  350. </if>
  351. <choose>
  352. <when test="sortName != null and sortName != '' and sortOrder != null and sortOrder != ''">
  353. order by ${sortName} ${sortOrder}
  354. </when>
  355. <otherwise>
  356. order by u.user_id asc
  357. </otherwise>
  358. </choose>
  359. </select>
  360. <!--查询用户-->
  361. <select id="getSysUserInfo" resultMap="SysUserInfoMap" parameterType="map">
  362. select * from sys_user_info
  363. where del_flag = 0
  364. <if test="post_name != null and post_name != ''">
  365. and post_name = #{postName}
  366. </if>
  367. </select>
  368. <!--批量删除系统用户-->
  369. <delete id="batchDelete">
  370. update sys_user_info
  371. set del_flag = 1,
  372. update_user = #{updateUser},
  373. update_time = GETDATE()
  374. where user_id in
  375. <foreach item="item" index="index" collection="userIdList" open="(" separator="," close=")">
  376. #{item}
  377. </foreach>
  378. </delete>
  379. <!--删除一个系统用户-->
  380. <delete id="delete" parameterType="java.lang.Integer">
  381. delete
  382. from sys_user_info
  383. where user_id = #{_parameter}
  384. </delete>
  385. <!--校验用户账号是否唯一-->
  386. <select id="checkUserNameUnique" resultType="java.lang.Integer" parameterType="java.lang.String">
  387. select count(*)
  388. from sys_user_info
  389. where account = #{account}
  390. </select>
  391. <!--新增系统用户-->
  392. <insert id="doAdd" parameterType="com.liang.entity.SysUserInfo">
  393. insert into sys_user_info (
  394. <if test="name != null and name != ''">name,</if>
  395. <if test="deptId != null and deptId != ''">dept_id,</if>
  396. <if test="phone != null and phone != ''">phone,</if>
  397. <if test="email != null and email != ''">email,</if>
  398. <if test="avatar != null and avatar != ''">avatar,</if>
  399. <if test="sex != null and sex != ''">sex,</if>
  400. <if test="status != null and status != ''">status,</if>
  401. <if test="delFlag != null and delFlag != ''">del_flag,</if>
  402. <if test="createUser != nul">create_user,</if>
  403. user_id,
  404. account,
  405. password
  406. ) values (
  407. <if test="name != null and name != ''">#{name},</if>
  408. <if test="deptId != null and deptId != ''">#{deptId},</if>
  409. <if test="phone != null and phone != ''">#{phone},</if>
  410. <if test="email != null and email != ''">#{email},</if>
  411. <if test="avatar != null and avatar != ''">#{avatar},</if>
  412. <if test="sex != null and sex != ''">#{sex},</if>
  413. <if test="status != null and status != ''">#{status},</if>
  414. <if test="delFlag != null and delFlag != ''">#{delFlag},</if>
  415. <if test="createUser != null">#{createUser},</if>
  416. #{userId},
  417. #{account},
  418. #{password}
  419. )
  420. </insert>
  421. <!--修改系统用户-->
  422. <update id="doUpdate" parameterType="com.liang.entity.SysUserInfo">
  423. update sys_user_info
  424. set name = #{name},
  425. sex = #{sex},
  426. dept_id = #{deptId},
  427. status = #{status},
  428. phone = #{phone},
  429. email = #{email},
  430. avatar = #{avatar},
  431. update_user = #{updateUser}
  432. where user_id = #{userId}
  433. </update>
  434. <!--用户密码重置-->
  435. <update id="resetPass" parameterType="com.liang.entity.SysUserInfo">
  436. update sys_user_info
  437. set password = #{password}
  438. where user_id = #{userId}
  439. </update>
  440. <!--通过id获取一条记录-->
  441. <select id="getOneById" resultMap="SysUserInfoMap" parameterType="java.lang.Integer">
  442. select *
  443. from sys_user_info
  444. where user_id = #{userId}
  445. </select>
  446. <!--获取创建人-->
  447. <select id="getCJR" resultType="map">
  448. select user_id as code, account as name
  449. from sys_user_info
  450. </select>
  451. <!--获取一条记录通过用户账号一-->
  452. <select id="getUserByAccount" resultType="com.liang.entity.SysUserInfo" parameterType="java.lang.String">
  453. select u.*, p.post_id userPost, p.post_name userPostName
  454. from sys_user_info u
  455. left join sys_user_post up on up.user_id = u.user_id
  456. left join sys_post_info p on p.post_id = up.post_id
  457. where account = #{account}
  458. and del_flag = 0
  459. </select>
  460. <!--根据登录信息查询所属部门名称 -->
  461. <select id="getDeptNameByAccount" resultType="java.lang.String">
  462. SELECT dept_name
  463. FROM sys_dept_info
  464. WHERE dept_id = #{dept_id}
  465. </select>
  466. <!-- 根据登录人员查询所在岗位名称 -->
  467. <select id="getPostNameByUserId" resultType="java.lang.String">
  468. select p.post_name
  469. from sys_user_info u
  470. left join sys_dept_info d on d.dept_id = u.dept_id
  471. left join sys_user_post up on up.user_id = u.user_id
  472. left join sys_post_info p on p.post_id = up.post_id
  473. where u.user_id = #{userId}
  474. </select>
  475. <select id="getDept" resultMap="SysUserInfoMap">
  476. select u.*, d.dept_name as deptName, d1.dept_name as deptName1, d2.dept_name as deptName2, p.post_name as userPostName
  477. from sys_user_info u
  478. left join sys_dept_info d on d.dept_id = u.dept_id
  479. left join sys_dept_info d1 on d1.dept_id = d.parent_id
  480. left join sys_dept_info d2 on d2.dept_id = d1.parent_id
  481. left join sys_user_post up on up.user_id = u.user_id
  482. left join sys_post_info p on p.post_id = up.post_id
  483. where u.user_id = #{id}
  484. </select>
  485. <select id="getDeptName" resultType="com.liang.entity.SysUserInfo">
  486. SELECT * FROM sys_dept_info WHERE del_flag != 1
  487. </select>
  488. <select id="getBzs" resultType="String">
  489. select bz from
  490. sys_user_info
  491. where user_id = #{id}
  492. </select>
  493. </mapper>