sysUserDao.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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="cn.ourwill.module.sys.dao.SysUserDao">
  4. <resultMap type="cn.ourwill.module.sys.entity.SysUser" id="baseMap">
  5. <result column="user_id" property="userId"/>
  6. <result column="group_id" property="groupId"/>
  7. <result column="login_name" property="loginName"/>
  8. <result column="login_pwd" property="loginPwd"/>
  9. <result column="user_name" property="userName"/>
  10. <result column="user_type" property="userType"/>
  11. <result column="status" property="status"/>
  12. <result column="last_login_time" property="lastLoginTime"/>
  13. <result column="last_login_ip" property="lastLoginIp"/>
  14. <result column="create_time" property="createTime"/>
  15. <result column="email" property="email"/>
  16. <result column="tel" property="tel"/>
  17. <result column="organize_id" property="organizeId"/>
  18. <result column="id" property="id"/>
  19. <result column="uuid" property="uuid"/>
  20. <result column="name" property="name"/>
  21. <result column="realname" property="realname"/>
  22. <result column="password" property="password"/>
  23. <result column="provinceId" property="provinceId"/>
  24. <result column="cityId" property="cityId"/>
  25. <result column="grainId" property="grainId"/>
  26. <result column="houseId" property="houseId"/>
  27. <result column="position" property="position"/>
  28. <result column="c_id" property="cId"/>
  29. <result column="lastTime" property="lastTime"/>
  30. <result column="state" property="state"/>
  31. <result column="c_time" property="cTime"/>
  32. <result column="birthday" property="birthday"/>
  33. <result column="email" property="email"/>
  34. <result column="phone" property="phone"/>
  35. <result column="address" property="address"/>
  36. <result column="avator" property="avator"/>
  37. <result column="u_id" property="uId"/>
  38. <result column="u_time" property="uTime"/>
  39. <result column="version" property="version"/>
  40. <result column="keep_prompt_time" property="keepPromptTime"/>
  41. <result column="device_prompt_time" property="devicePromptTime"/>
  42. <result column="status" property="status"/>
  43. </resultMap>
  44. <sql id="columns">
  45. id ,
  46. uuid ,
  47. `name` ,
  48. realname ,
  49. password ,
  50. email,
  51. phone,
  52. address,
  53. birthday,
  54. avator,
  55. provinceId ,
  56. cityId ,
  57. grainId ,
  58. houseId ,
  59. `position` ,
  60. c_id ,
  61. lastTime ,
  62. state ,
  63. c_time ,
  64. u_id ,
  65. u_time ,
  66. version ,
  67. keep_prompt_time ,
  68. device_prompt_time,
  69. status
  70. </sql>
  71. <sql id="pageEnd">
  72. limit #{page.offset,jdbcType=INTEGER} ,#{page.pageSize,jdbcType=INTEGER}
  73. </sql>
  74. <sql id="joinCols">
  75. </sql>
  76. <select id="get" resultMap="baseMap">
  77. SELECT
  78. <include refid="columns"/>
  79. FROM sys_user a
  80. <include refid="joinCols"/>
  81. WHERE a.id = #{id}
  82. </select>
  83. <select id="getByName" resultMap="baseMap">
  84. SELECT
  85. <include refid="columns"/>
  86. FROM sys_user a
  87. <include refid="joinCols"/>
  88. WHERE a.name = #{name}
  89. limit 1
  90. </select>
  91. <select id="findList" resultMap="baseMap">
  92. SELECT DISTINCT s.*
  93. FROM sys_user s
  94. LEFT JOIN sys_user_role ur on s.id=ur.user_id
  95. LEFT JOIN sys_role r on r.id=ur.role_id
  96. <include refid="joinCols"/>
  97. <where>
  98. <if test="id !=null">
  99. and s.id = #{id}
  100. </if>
  101. <if test="uuid !=null">
  102. and s.uuid = #{uuid}
  103. </if>
  104. <if test="name !=null">
  105. <!--and s.`name` like CONCAT('%',#{name},'%') -->
  106. and s.`name` =#{name}
  107. </if>
  108. <if test="realname !=null">
  109. and s.realname = #{realname}
  110. </if>
  111. <if test="password !=null">
  112. and s.password = #{password}
  113. </if>
  114. <if test="provinceId !=null">
  115. and s.provinceId = #{provinceId}
  116. </if>
  117. <if test="cityId !=null">
  118. and s.cityId = #{cityId}
  119. </if>
  120. <if test="grainId !=null">
  121. and s.grainId = #{grainId}
  122. </if>
  123. <if test="houseId !=null">
  124. and s.houseId = #{houseId}
  125. </if>
  126. <if test="position !=null">
  127. and s.`position` = #{position}
  128. </if>
  129. <if test="cId !=null">
  130. and s.c_id = #{cId}
  131. </if>
  132. <if test="lastTime !=null">
  133. and s.lastTime = #{lastTime}
  134. </if>
  135. <if test="state !=null">
  136. and s.state = #{state}
  137. </if>
  138. <if test="cTime !=null">
  139. and s.c_time = #{cTime}
  140. </if>
  141. <if test="uId !=null">
  142. and s.u_id = #{uId}
  143. </if>
  144. <if test="uTime !=null">
  145. and s.u_time = #{uTime}
  146. </if>
  147. <if test="version !=null">
  148. and s.version = #{version}
  149. </if>
  150. <if test="keepPromptTime !=null">
  151. and s.keep_prompt_time = #{keepPromptTime}
  152. </if>
  153. <if test="devicePromptTime !=null">
  154. and s.device_prompt_time = #{devicePromptTime}
  155. </if>
  156. <if test="status !=null">
  157. and s.status = #{status}
  158. </if>
  159. <if test="roleName !=null">
  160. and r.`name` = #{roleName}
  161. </if>
  162. </where>
  163. <choose>
  164. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  165. ORDER BY ${page.orderBy}
  166. </when>
  167. <otherwise>
  168. </otherwise>
  169. </choose>
  170. </select>
  171. <select id="findAllList" resultMap="baseMap">
  172. SELECT
  173. <include refid="columns"/>
  174. FROM sys_user a
  175. <include refid="joinCols"/>
  176. <where>
  177. <if test="id !=null">
  178. and id = #{id}
  179. </if>
  180. <if test="uuid !=null">
  181. and uuid = #{uuid}
  182. </if>
  183. <if test="name !=null and name !='' ">
  184. and `name` like CONCAT('%',#{name},'%')
  185. </if>
  186. <if test="realname !=null">
  187. and realname = #{realname}
  188. </if>
  189. <if test="password !=null">
  190. and password = #{password}
  191. </if>
  192. <if test="provinceId !=null">
  193. and provinceId = #{provinceId}
  194. </if>
  195. <if test="cityId !=null">
  196. and cityId = #{cityId}
  197. </if>
  198. <if test="grainId !=null">
  199. and grainId = #{grainId}
  200. </if>
  201. <if test="houseId !=null">
  202. and houseId = #{houseId}
  203. </if>
  204. <if test="position !=null">
  205. and `position` = #{position}
  206. </if>
  207. <if test="cId !=null">
  208. and c_id = #{cId}
  209. </if>
  210. <if test="lastTime !=null">
  211. and lastTime = #{lastTime}
  212. </if>
  213. <if test="state !=null">
  214. and state = #{state}
  215. </if>
  216. <if test="cTime !=null">
  217. and c_time = #{cTime}
  218. </if>
  219. <if test="uId !=null">
  220. and u_id = #{uId}
  221. </if>
  222. <if test="uTime !=null">
  223. and u_time = #{uTime}
  224. </if>
  225. <if test="version !=null">
  226. and version = #{version}
  227. </if>
  228. <if test="keepPromptTime !=null">
  229. and keep_prompt_time = #{keepPromptTime}
  230. </if>
  231. <if test="devicePromptTime !=null">
  232. and device_prompt_time = #{devicePromptTime}
  233. </if>
  234. <if test="status !=null">
  235. and status = #{status}
  236. </if>
  237. </where>
  238. <choose>
  239. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  240. ORDER BY ${page.orderBy}
  241. </when>
  242. <otherwise>
  243. </otherwise>
  244. </choose>
  245. </select>
  246. <insert id="insert" keyColumn="id" keyProperty="id" useGeneratedKeys="true"
  247. parameterType="cn.ourwill.module.sys.entity.SysUser">
  248. INSERT INTO sys_user
  249. <trim prefix="(" suffix=")" suffixOverrides=",">
  250. <if test=" id != null">
  251. id,
  252. </if>
  253. <if test=" uuid != null">
  254. uuid,
  255. </if>
  256. <if test=" name != null">
  257. `name`,
  258. </if>
  259. <if test=" realname != null">
  260. realname,
  261. </if>
  262. <if test=" password != null">
  263. password,
  264. </if>
  265. <if test=" birthday != null">
  266. birthday,
  267. </if>
  268. <if test=" email != null">
  269. email,
  270. </if>
  271. <if test=" phone != null">
  272. phone,
  273. </if>
  274. <if test=" address != null">
  275. address,
  276. </if>
  277. <if test=" provinceId != null">
  278. provinceId,
  279. </if>
  280. <if test=" avator != null">
  281. avator,
  282. </if>
  283. <if test=" cityId != null">
  284. cityId,
  285. </if>
  286. <if test=" grainId != null">
  287. grainId,
  288. </if>
  289. <if test=" houseId != null">
  290. houseId,
  291. </if>
  292. <if test=" position != null">
  293. `position` ,
  294. </if>
  295. <if test=" cId != null">
  296. c_id,
  297. </if>
  298. <if test=" lastTime != null">
  299. lastTime,
  300. </if>
  301. <if test=" state != null">
  302. state,
  303. </if>
  304. <if test=" cTime != null">
  305. c_time,
  306. </if>
  307. <if test=" uId != null">
  308. u_id,
  309. </if>
  310. <if test=" uTime != null">
  311. u_time,
  312. </if>
  313. <if test=" version != null">
  314. version,
  315. </if>
  316. <if test="keepPromptTime !=null">
  317. keep_prompt_time,
  318. </if>
  319. <if test="devicePromptTime !=null">
  320. device_prompt_time,
  321. </if>
  322. <if test="status !=null">
  323. status
  324. </if>
  325. </trim>
  326. <trim prefix="values (" suffix=")" suffixOverrides=",">
  327. <if test=" id != null">
  328. #{id}, </if>
  329. <if test=" uuid != null">
  330. #{uuid}, </if>
  331. <if test=" name != null">
  332. #{name}, </if>
  333. <if test=" realname != null">
  334. #{realname}, </if>
  335. <if test=" password != null">
  336. #{password}, </if>
  337. <if test=" birthday != null">
  338. #{birthday}, </if>
  339. <if test=" email != null">
  340. #{email}, </if>
  341. <if test=" phone != null">
  342. #{phone}, </if>
  343. <if test=" address != null">
  344. #{address}, </if>
  345. <if test=" provinceId != null">
  346. #{provinceId}, </if>
  347. <if test=" avator != null">
  348. #{avator}, </if>
  349. <if test=" cityId != null">
  350. #{cityId}, </if>
  351. <if test=" grainId != null">
  352. #{grainId}, </if>
  353. <if test=" houseId != null">
  354. #{houseId}, </if>
  355. <if test=" position != null">
  356. #{position}, </if>
  357. <if test=" cId != null">
  358. #{cId}, </if>
  359. <if test=" lastTime != null">
  360. #{lastTime}, </if>
  361. <if test=" state != null">
  362. #{state}, </if>
  363. <if test=" cTime != null">
  364. #{cTime}, </if>
  365. <if test=" uId != null">
  366. #{uId}, </if>
  367. <if test=" uTime != null">
  368. #{uTime}, </if>
  369. <if test=" version != null">
  370. #{version}, </if>
  371. <if test="keepPromptTime !=null">
  372. #{keepPromptTime},
  373. </if>
  374. <if test="devicePromptTime !=null">
  375. #{devicePromptTime},
  376. </if>
  377. <if test="status !=null">
  378. #{status}
  379. </if>
  380. </trim>
  381. </insert>
  382. <update id="update" parameterType="cn.ourwill.module.sys.entity.SysUser">
  383. UPDATE sys_user <set>
  384. <if test="id != null">
  385. id= #{id} ,
  386. </if>
  387. <if test="uuid != null">
  388. uuid= #{uuid} ,
  389. </if>
  390. <if test="name != null">
  391. `name`= #{name} ,
  392. </if>
  393. <if test="realname != null">
  394. realname= #{realname} ,
  395. </if>
  396. <if test="avator != null">
  397. avator= #{avator} ,
  398. </if>
  399. <if test="password != null">
  400. password= #{password} ,
  401. </if>
  402. <if test="birthday != null">
  403. birthday= #{birthday} ,
  404. </if>
  405. <if test="email != null">
  406. email= #{email} ,
  407. </if>
  408. <if test="phone != null">
  409. phone= #{phone} ,
  410. </if>
  411. <if test="address != null">
  412. address= #{address} ,
  413. </if>
  414. <if test="provinceId != null">
  415. provinceId= #{provinceId} ,
  416. </if>
  417. <if test="cityId != null">
  418. cityId= #{cityId} ,
  419. </if>
  420. <if test="grainId != null">
  421. grainId= #{grainId} ,
  422. </if>
  423. <if test="houseId != null">
  424. houseId= #{houseId} ,
  425. </if>
  426. <if test="position != null">
  427. position= #{position} ,
  428. </if>
  429. <if test="cId != null">
  430. c_id= #{cId} ,
  431. </if>
  432. <if test="lastTime != null">
  433. lastTime= #{lastTime} ,
  434. </if>
  435. <if test="state != null">
  436. state= #{state} ,
  437. </if>
  438. <if test="cTime != null">
  439. c_time= #{cTime} ,
  440. </if>
  441. <if test="uId != null">
  442. u_id= #{uId} ,
  443. </if>
  444. <if test="uTime != null">
  445. u_time= #{uTime} ,
  446. </if>
  447. <if test="version != null">
  448. version= #{version} ,
  449. </if>
  450. <if test="keepPromptTime !=null">
  451. keep_prompt_time = #{keepPromptTime} ,
  452. </if>
  453. <if test="devicePromptTime !=null">
  454. device_prompt_time = #{devicePromptTime},
  455. </if>
  456. <if test="status !=null">
  457. status = #{status}
  458. </if>
  459. </set>
  460. WHERE id = #{id}
  461. </update>
  462. <update id="deleteByIdOpen" parameterType="cn.ourwill.module.sys.entity.SysUser">
  463. UPDATE sys_user <set>
  464. <if test="id != null">
  465. status= #{status} ,
  466. </if>
  467. </set>
  468. WHERE id = #{id}
  469. </update>
  470. <select id="getUser" resultMap="baseMap">
  471. SELECT
  472. <include refid="columns"/>
  473. FROM sys_user a
  474. <include refid="joinCols"/>
  475. <where>
  476. `name`= #{name} and `password`= #{password}
  477. <if test="uuid != null ">
  478. and `uuid`= #{uuid}
  479. </if>
  480. </where>
  481. </select>
  482. <select id="getUserByName" resultMap="baseMap">
  483. SELECT
  484. <include refid="columns"/>
  485. FROM sys_user a
  486. <include refid="joinCols"/>
  487. <where>
  488. `name`= #{name}
  489. </where>
  490. </select>
  491. <delete id="deleteById" parameterType="java.lang.Long">
  492. DELETE FROM sys_user WHERE id = #{id}
  493. </delete>
  494. <delete id="deleteByIds" parameterType="java.util.List">
  495. DELETE FROM sys_user WHERE id IN
  496. <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
  497. #{item}
  498. </foreach>
  499. </delete>
  500. <select id="getByUUID" resultMap="baseMap">
  501. SELECT
  502. <include refid="columns"/>
  503. FROM sys_user a
  504. <include refid="joinCols"/>
  505. where a.`uuid`= #{value}
  506. </select>
  507. <update id="csh_passd" parameterType="cn.ourwill.module.sys.entity.SysUser">
  508. update sys_user a
  509. set a.password='96e79218965eb72c92a549dd5a330112'
  510. WHERE name IN
  511. <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
  512. #{item.name}
  513. </foreach>
  514. </update>
  515. <select id="getAllBaoGuanYuanList" resultMap="baseMap" parameterType="cn.ourwill.module.sys.entity.SysUser">
  516. select
  517. a.id as id,
  518. a.realname as 'name',
  519. sg.name as 'grainName',
  520. sg.id as 'grainId'
  521. from sys_user a
  522. LEFT JOIN sys_grain sg on a.grainId=sg.id
  523. left join sys_user_role b on a.id=b.user_id
  524. left join sys_role c on c.id = b.role_id
  525. <where>
  526. and (c.NAME = '保管员' or c.NAME = '租仓库保管员权限')
  527. <if test="cityId !=null">
  528. and a.cityId = #{cityId}
  529. </if>
  530. <if test="grainId !=null">
  531. and a.grainId = #{grainId}
  532. </if>
  533. and a.uuid not in
  534. (
  535. select user_uuid from house_keeper d
  536. <where>
  537. <if test="grainId !=null">
  538. and d.grainId = #{grainId}
  539. </if>
  540. <if test="cityId !=null">
  541. and d.cityId = #{cityId}
  542. </if>
  543. and d.user_uuid is not NULL
  544. </where>
  545. )
  546. </where>
  547. GROUP by grainName
  548. </select>
  549. <select id="getAllUserByGrainId" resultMap="baseMap" parameterType="cn.ourwill.module.sys.entity.SysUser">
  550. SELECT
  551. <include refid="columns"/>
  552. FROM sys_user a
  553. <include refid="joinCols"/>
  554. WHERE a.grainId=#{grainId}
  555. </select>
  556. <select id="getAllUserByHouseId" resultMap="baseMap" parameterType="cn.ourwill.module.sys.entity.SysUser">
  557. SELECT
  558. <include refid="columns"/>
  559. FROM sys_user a
  560. <include refid="joinCols"/>
  561. WHERE find_in_set(#{grainId}, houseId);
  562. </select>
  563. <select id="getAllBaoGuanYuanNameByGrainId" resultMap="baseMap" parameterType="cn.ourwill.module.sys.entity.SysUser">
  564. SELECT
  565. a.id AS id,
  566. a.realname AS 'name',
  567. sg.id as 'grainId'
  568. FROM
  569. sys_user a
  570. LEFT JOIN sys_grain sg ON a.grainId = sg.id
  571. LEFT JOIN sys_user_role b ON a.id = b.user_id
  572. LEFT JOIN sys_role c ON c.id = b.role_id
  573. WHERE
  574. (c.NAME = '保管员' or c.NAME = '租仓库保管员权限')
  575. and a.grainId=#{grainId}
  576. </select>
  577. </mapper>