UserMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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.jeeplus.modules.sys.mapper.UserMapper">
  4. <sql id="userColumns">
  5. a.id,
  6. a.company_id AS "company.id",
  7. a.office_id AS "office.id",
  8. a.login_name AS "loginName",
  9. a.type AS "type",
  10. a.password,
  11. a.no,
  12. a.name,
  13. a.email,
  14. a.phone,
  15. a.mobile,
  16. a.login_ip,
  17. a.login_date,
  18. a.remarks,
  19. a.login_flag,
  20. a.photo,
  21. a.qrcode,
  22. a.sign,
  23. a.create_by AS "createBy.id",
  24. a.create_date,
  25. a.update_by AS "updateBy.id",
  26. a.update_date,
  27. a.del_flag,
  28. a.leader_id as "leaderId",
  29. a.village_id as "villageId",
  30. a.ifapppermission,
  31. o.dept_name AS "office.deptName",
  32. o.name AS "office.name",
  33. o.parent_id AS "office.parent.id",
  34. o.parent_ids AS "office.parentIds",
  35. o.type AS "office.type"
  36. </sql>
  37. <sql id="userJoins">
  38. <!--LEFT JOIN sys_office c ON c.id = a.company_id
  39. LEFT JOIN sys_area ca ON ca.id = c.area_id
  40. LEFT JOIN sys_office o ON o.id = a.office_id
  41. LEFT JOIN sys_area oa ON oa.id = o.area_id-->
  42. LEFT JOIN leader_org_no o ON o.id = a.office_id
  43. <!--
  44. LEFT JOIN sys_user cu ON cu.id = c.primary_person
  45. LEFT JOIN sys_user cu2 ON cu2.id = c.deputy_person
  46. LEFT JOIN sys_user ou ON ou.id = o.primary_person
  47. LEFT JOIN sys_user ou2 ON ou2.id = o.deputy_person
  48. LEFT JOIN sys_user_role ur ON ur.user_id = a.id
  49. LEFT JOIN sys_role r ON r.id = ur.role_id -->
  50. </sql>
  51. <!-- 根据编号获得用户 -->
  52. <select id="get" resultType="User">
  53. SELECT
  54. <include refid="userColumns"/>
  55. FROM sys_user a
  56. <include refid="userJoins"/>
  57. WHERE a.id = #{id}
  58. </select>
  59. <!-- 根据登录名查询用户 -->
  60. <select id="getByLoginName" resultType="User" parameterType="User">
  61. SELECT
  62. <include refid="userColumns"/>
  63. FROM sys_user a
  64. <include refid="userJoins"/>
  65. WHERE a.login_name = #{loginName} AND a.del_flag = #{DEL_FLAG_NORMAL}
  66. <!--<if test="type != null and type != ''">
  67. AND a.type = #{type}
  68. </if>-->
  69. </select>
  70. <!-- 分页查询用户信息 -->
  71. <select id="findList" resultType="User">
  72. SELECT
  73. <include refid="userColumns"/>
  74. FROM sys_user a
  75. <include refid="userJoins"/>
  76. <if test="role != null and role.id != null and role.id != ''">
  77. JOIN sys_user_role ur ON ur.user_id = a.id AND ur.role_id = #{role.id}
  78. </if>
  79. WHERE a.del_flag = #{DEL_FLAG_NORMAL}
  80. <!--<if test="company != null and company.id != null and company.id != ''">
  81. AND (c.id = #{company.id} OR c.parent_ids LIKE
  82. <if test="dbName == 'oracle'">'%,'||#{company.id}||',%')</if>
  83. <if test="dbName == 'mysql'">CONCAT('%,', #{company.id}, ',%'))</if>
  84. <if test="dbName == 'mssql'">'%'+#{company.id}+'%')</if>
  85. </if>-->
  86. <if test="office != null and office.id != null and office.id != ''">
  87. AND (o.id = #{office.id} OR o.parent_ids LIKE
  88. <if test="dbName == 'oracle'">'%,'||#{office.id}||',%')</if>
  89. <if test="dbName == 'mysql'">CONCAT('%,', #{office.id}, ',%'))</if>
  90. <if test="dbName == 'mssql'">'%'+#{office.id}+'%')</if>
  91. </if>
  92. <!-- 如果不是超级管理员,则不显示超级管理员用户 -->
  93. <if test="!currentUser.admin">
  94. AND a.id != '1'
  95. </if>
  96. <!--<if test="officeId != null and officeId != ''">
  97. AND o.parent_ids LIKE CONCAT('%,', #{officeId}, ',%')
  98. OR a.office_id = #{officeId}
  99. </if>-->
  100. <if test="loginName != null and loginName != ''">
  101. AND a.login_name like
  102. <if test="dbName == 'oracle'">'%'||#{loginName}||'%'</if>
  103. <if test="dbName == 'mysql'">CONCAT('%', #{loginName}, '%')</if>
  104. <if test="dbName == 'mssql'">'%'+#{loginName}+'%'</if>
  105. </if>
  106. <if test="name != null and name != ''">
  107. AND a.name like
  108. <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
  109. <if test="dbName == 'mysql'">CONCAT('%', #{name}, '%')</if>
  110. <if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
  111. </if>
  112. <!-- AND FIND_IN_SET(a.office_id,getChildLst(#{currentUser.office.id})) -->
  113. <!-- 数据范围过滤 -->
  114. ${dataScope}
  115. <choose>
  116. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  117. ORDER BY ${page.orderBy}
  118. </when>
  119. <otherwise>
  120. ORDER BY o.sort, a.name
  121. </otherwise>
  122. </choose>
  123. </select>
  124. <!-- 根据部门查询用户信息 -->
  125. <select id="findListByOffice" resultType="User">
  126. SELECT
  127. <include refid="userColumns"/>
  128. FROM sys_user a
  129. <include refid="userJoins"/>
  130. WHERE a.del_flag = #{DEL_FLAG_NORMAL}
  131. <!--<if test="company != null and company.id != null and company.id != ''">
  132. AND c.id = #{company.id}
  133. </if>-->
  134. <if test="office != null and office.id != null and office.id != ''">
  135. AND o.id = #{office.id}
  136. </if>
  137. <if test="office == null">
  138. AND (o.id = '' or o.id is null)
  139. </if>
  140. <if test="loginName != null and loginName != ''">
  141. AND a.login_name like
  142. <if test="dbName == 'oracle'">'%'||#{loginName}||'%'</if>
  143. <if test="dbName == 'mysql'">CONCAT('%', #{loginName}, '%')</if>
  144. <if test="dbName == 'mssql'">'%'+#{loginName}+'%'</if>
  145. </if>
  146. <if test="name != null and name != ''">
  147. AND a.name like
  148. <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
  149. <if test="dbName == 'mysql'">CONCAT('%', #{name}, '%')</if>
  150. <if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
  151. </if>
  152. <!-- 数据范围过滤 -->
  153. ${dataScope}
  154. <!-- 排序 -->
  155. ORDER BY a.name
  156. </select>
  157. <!-- 根据OfficeId获取用户(树查询用户时用) -->
  158. <select id="findUserByOfficeId" resultType="User" useCache="true">
  159. SELECT
  160. a.id, a.name, a.login_name
  161. FROM sys_user a
  162. WHERE a.del_flag = #{DEL_FLAG_NORMAL}
  163. AND a.office_id = #{office.id}
  164. ORDER BY a.name
  165. </select>
  166. <!-- 查询全部用户 -->
  167. <select id="findAllList" resultType="User">
  168. SELECT
  169. <include refid="userColumns"/>
  170. FROM sys_user a
  171. <include refid="userJoins"/>
  172. WHERE a.del_flag = #{DEL_FLAG_NORMAL}
  173. ORDER BY o.sort, a.name
  174. </select>
  175. <!-- 查询全部用户数目 -->
  176. <select id="findAllCount" resultType="long">
  177. SELECT
  178. COUNT(1)
  179. FROM sys_user a
  180. WHERE a.del_flag = #{DEL_FLAG_NORMAL}
  181. </select>
  182. <!-- 插入用户 -->
  183. <insert id="insert">
  184. INSERT INTO sys_user(
  185. id,
  186. company_id,
  187. office_id,
  188. login_name,
  189. password,
  190. no,
  191. name,
  192. email,
  193. phone,
  194. mobile,
  195. create_by,
  196. create_date,
  197. update_by,
  198. update_date,
  199. remarks,
  200. login_flag,
  201. photo,
  202. qrcode,
  203. del_flag,
  204. village_id,
  205. leader_id,
  206. type,
  207. ifapppermission
  208. ) VALUES (
  209. #{id},
  210. #{company.id},
  211. #{office.id},
  212. #{loginName},
  213. #{password},
  214. #{no},
  215. #{name},
  216. #{email},
  217. #{phone},
  218. #{mobile},
  219. #{createBy.id},
  220. #{createDate},
  221. #{updateBy.id},
  222. #{updateDate},
  223. #{remarks},
  224. #{loginFlag},
  225. #{photo},
  226. #{qrCode},
  227. #{delFlag},
  228. #{villageId},
  229. #{leaderId},
  230. #{type},
  231. #{ifapppermission}
  232. )
  233. </insert>
  234. <insert id="register">
  235. INSERT INTO sys_user(
  236. id,
  237. office_id,
  238. login_name,
  239. password,
  240. name,
  241. mobile,
  242. login_flag,
  243. del_flag,
  244. type,
  245. create_date
  246. ) VALUES (
  247. #{id},
  248. #{officeId},
  249. #{loginName},
  250. #{password},
  251. #{name},
  252. #{mobile},
  253. #{loginFlag},
  254. #{delFlag},
  255. #{type},
  256. #{createDate}
  257. )
  258. </insert>
  259. <!-- 更新用户 -->
  260. <update id="update">
  261. UPDATE sys_user SET
  262. company_id = #{company.id},
  263. office_id = #{office.id},
  264. login_name = #{loginName},
  265. password = #{password},
  266. no = #{no},
  267. name = #{name},
  268. email = #{email},
  269. phone = #{phone},
  270. mobile = #{mobile},
  271. update_by = #{updateBy.id},
  272. update_date = #{updateDate},
  273. remarks = #{remarks},
  274. login_flag = #{loginFlag},
  275. photo = #{photo},
  276. qrcode = #{qrCode},
  277. village_id = #{villageId},
  278. leader_id = #{leaderId},
  279. type = #{type},
  280. ifapppermission=#{ifapppermission}
  281. WHERE id = #{id}
  282. </update>
  283. <!-- 删除用户和角色关联表数据 -->
  284. <delete id="deleteUserRole">
  285. DELETE FROM sys_user_role WHERE user_id = #{id}
  286. </delete>
  287. <!-- 插入用户和角色关联表数据 -->
  288. <insert id="insertUserRole">
  289. INSERT INTO sys_user_role(user_id, role_id)
  290. <foreach collection="roleList" item="role" separator=" union all ">
  291. SELECT #{id}, #{role.id} ${dual}
  292. </foreach>
  293. </insert>
  294. <!-- 更新用户信息 -->
  295. <update id="updateUserInfo">
  296. UPDATE sys_user SET
  297. name = #{name},
  298. email = #{email},
  299. phone = #{phone},
  300. mobile = #{mobile},
  301. update_by = #{updateBy.id},
  302. update_date = #{updateDate},
  303. remarks = #{remarks},
  304. photo = #{photo},
  305. qrcode = #{qrCode},
  306. sign = #{sign}
  307. WHERE id = #{id}
  308. </update>
  309. <!-- 更新用户密码 -->
  310. <update id="updatePasswordById">
  311. UPDATE sys_user SET
  312. password = #{password}
  313. WHERE id = #{id}
  314. </update>
  315. <!-- 更新登录信息,如登录IP、登录时间 -->
  316. <update id="updateLoginInfo">
  317. UPDATE sys_user SET
  318. login_ip = #{loginIp},
  319. login_Date = #{loginDate} ,
  320. login_times = login_times+1
  321. WHERE id = #{id}
  322. </update>
  323. <!-- 物理删除用户 -->
  324. <update id="delete">
  325. DELETE FROM sys_user
  326. WHERE id = #{id}
  327. </update>
  328. <!-- 逻辑删除用户 -->
  329. <update id="deleteByLogic">
  330. UPDATE sys_user SET
  331. del_flag = #{DEL_FLAG_DELETE}
  332. WHERE id = #{id}
  333. </update>
  334. <!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
  335. <select id="findUniqueByProperty" resultType="User" statementType="STATEMENT">
  336. select * from sys_user where ${propertyName} = '${value}'
  337. </select>
  338. <!-- 添加好友 -->
  339. <insert id="insertFriend">
  340. INSERT INTO sys_user_friend(
  341. id,
  342. userId,
  343. friendId
  344. ) VALUES (
  345. #{id},
  346. #{userId},
  347. #{friendId}
  348. )
  349. </insert>
  350. <!-- 根据用户id和好友id获取唯一记录 -->
  351. <select id="findFriend" resultType="User">
  352. SELECT
  353. *
  354. FROM sys_user a
  355. LEFT JOIN sys_user_friend p ON p.userId = a.id
  356. WHERE p.userId = #{userId} and p.friendId = #{friendId}
  357. </select>
  358. <!-- 删除好友 -->
  359. <select id="deleteFriend">
  360. DELETE FROM sys_user_friend WHERE userId = #{userId} and friendId = #{friendId}
  361. </select>
  362. <!-- 查询我的好友列表 -->
  363. <select id="findFriends" resultType="User">
  364. SELECT
  365. <include refid="userColumns"/>
  366. FROM sys_user a
  367. <include refid="userJoins"/>
  368. LEFT JOIN sys_user_friend p ON p.friendId = a.id
  369. WHERE p.userId = #{id}
  370. </select>
  371. <!-- 根据条件检索用户,添加到好友列表 -->
  372. <select id="searchUsers" resultType="User">
  373. SELECT
  374. <include refid="userColumns"/>
  375. FROM sys_user a
  376. <include refid="userJoins"/>
  377. <if test="name != null and name != ''">
  378. WHERE a.name like
  379. <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
  380. <if test="dbName == 'mysql'">CONCAT('%', #{name}, '%')</if>
  381. <if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
  382. </if>
  383. <if test="id!=null and id!=''">
  384. AND a.id = #{id}
  385. </if>
  386. </select>
  387. </mapper>