UserMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  3. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  4. <mapper namespace="UserMapper">
  5. <resultMap type="User" id="userAndRoleResultMap">
  6. <id column="USER_ID" property="USER_ID"/>
  7. <result column="USERNAME" property="USERNAME"/>
  8. <result column="PASSWORD" property="PASSWORD"/>
  9. <result column="NAME" property="NAME"/>
  10. <result column="RIGHTS" property="RIGHTS"/>
  11. <result column="LAST_LOGIN" property="LAST_LOGIN"/>
  12. <result column="IP" property="IP"/>
  13. <result column="STATUS" property="STATUS"/>
  14. <result column="SKIN" property="SKIN"/>
  15. <result column="ROLE_IDS" property="ROLE_IDS"/>
  16. <association property="role" column="ROLE_ID" javaType="Role">
  17. <id column="ROLE_ID" property="ROLE_ID"/>
  18. <result column="ROLE_NAME" property="ROLE_NAME"/>
  19. <result column="ROLE_RIGHTS" property="RIGHTS"/>
  20. </association>
  21. </resultMap>
  22. <resultMap type="User" id="userResultMap">
  23. <id column="USER_ID" property="USER_ID"/>
  24. <result column="USERNAME" property="USERNAME"/>
  25. <result column="PASSWORD" property="PASSWORD"/>
  26. <result column="NAME" property="NAME"/>
  27. <result column="RIGHTS" property="RIGHTS"/>
  28. <result column="LAST_LOGIN" property="LAST_LOGIN"/>
  29. <result column="IP" property="IP"/>
  30. <result column="STATUS" property="STATUS"/>
  31. <result column="ROLE_ID" property="ROLE_ID"/>
  32. <result column="SKIN" property="SKIN"/>
  33. <result column="ROLE_IDS" property="ROLE_IDS"/>
  34. <result column="COMPANY" property="COMPANY"/>
  35. <result column="ROAD" property="ROAD"/>
  36. </resultMap>
  37. <!--表名 -->
  38. <sql id="tableName">
  39. SYS_USER
  40. </sql>
  41. <sql id="roleTableName">
  42. SYS_ROLE
  43. </sql>
  44. <sql id="staffTableName">
  45. OA_STAFF
  46. </sql>
  47. <!-- 字段 -->
  48. <sql id="Field">
  49. USER_ID,
  50. USERNAME,
  51. PASSWORD,
  52. NAME,
  53. RIGHTS,
  54. ROLE_ID,
  55. LAST_LOGIN,
  56. IP,
  57. STATUS,
  58. BZ,
  59. SKIN,
  60. EMAIL,
  61. NUMBER,
  62. PHONE,
  63. ROLE_IDS,
  64. COMPANY,
  65. ROAD
  66. </sql>
  67. <!-- 字段值 -->
  68. <sql id="FieldValue">
  69. #{USER_ID},
  70. #{USERNAME},
  71. #{PASSWORD},
  72. #{NAME},
  73. #{RIGHTS},
  74. #{ROLE_ID},
  75. #{LAST_LOGIN},
  76. #{IP},
  77. #{STATUS},
  78. #{BZ},
  79. #{SKIN},
  80. #{EMAIL},
  81. #{NUMBER},
  82. #{PHONE},
  83. #{ROLE_IDS},
  84. #{COMPANY_NAME},
  85. #{ROAD_NAME}
  86. </sql>
  87. <!-- 判断用户名和密码 -->
  88. <select id="getUserInfo" parameterType="pd" resultType="pd">
  89. select <include refid="Field"></include> from
  90. <include refid="tableName"></include>
  91. where 1=1
  92. <if test="USERNAME!=null and PASSWORD!=null">
  93. and USERNAME = #{USERNAME} and PASSWORD=#{PASSWORD}
  94. </if>
  95. <if test="USER_ID!=null and USER_ID>0">
  96. and USER_ID = #{USER_ID}
  97. </if>
  98. </select>
  99. <!-- 更新登录时间 -->
  100. <update id="updateLastLogin" parameterType="pd" >
  101. update
  102. <include refid="tableName"></include>
  103. set
  104. LAST_LOGIN = #{LAST_LOGIN}
  105. where USER_ID = #{USER_ID}
  106. </update>
  107. <!-- 保存用户皮肤 -->
  108. <update id="saveSkin" parameterType="pd" >
  109. update
  110. <include refid="tableName"></include>
  111. set
  112. SKIN = #{SKIN}
  113. where USERNAME = #{USERNAME}
  114. </update>
  115. <!-- 通过用户ID获取用户信息和角色信息 -->
  116. <select id="getUserAndRoleById" parameterType="String" resultMap="userAndRoleResultMap">
  117. select u.USER_ID,
  118. u.USERNAME,
  119. u.NAME,
  120. u.RIGHTS as USER_RIGHTS,
  121. u.PASSWORD,
  122. u.SKIN,
  123. u.ROLE_IDS,
  124. r.ROLE_ID,
  125. r.ROLE_NAME,
  126. r.RIGHTS as ROLE_RIGHTS
  127. from
  128. <include refid="tableName"></include> u
  129. left join
  130. <include refid="roleTableName"></include> r
  131. on u.ROLE_ID=r.ROLE_ID
  132. where u.STATUS=0
  133. and u.USER_ID=#{USER_ID}
  134. </select>
  135. <!-- 通过USERNAME获取数据 -->
  136. <select id="findByUsername" parameterType="pd" resultType="pd" >
  137. select
  138. <include refid="Field"></include>
  139. from
  140. <include refid="tableName"></include>
  141. where
  142. USERNAME = #{USERNAME}
  143. </select>
  144. <!-- 存入IP -->
  145. <update id="saveIP" parameterType="pd" >
  146. update
  147. <include refid="tableName"></include>
  148. set
  149. IP = #{IP}
  150. where
  151. USERNAME = #{USERNAME}
  152. </update>
  153. <!-- 列出某角色下的所有用户 -->
  154. <select id="listAllUserByRoldId" parameterType="pd" resultType="pd" >
  155. select USER_ID
  156. from
  157. <include refid="tableName"></include>
  158. where
  159. ROLE_ID = #{ROLE_ID}
  160. </select>
  161. <!-- 用户列表 -->
  162. <select id="userlistPage" parameterType="page" resultType="pd" >
  163. select u.USER_ID,
  164. u.USERNAME,
  165. u.PASSWORD,
  166. u.LAST_LOGIN,
  167. u.NAME,
  168. u.IP,
  169. u.EMAIL,
  170. u.NUMBER,
  171. u.PHONE,
  172. u.COMPANY,
  173. u.ROAD,
  174. r.ROLE_ID,
  175. r.ROLE_NAME
  176. from <include refid="tableName"></include> u, <include refid="roleTableName"></include> r
  177. where u.ROLE_ID = r.ROLE_ID
  178. and u.USERNAME != 'admin'
  179. and r.PARENT_ID = '1'
  180. <if test="pd.keywords!= null and pd.keywords != ''"><!-- 关键词检索 -->
  181. and
  182. (
  183. u.USERNAME LIKE CONCAT(CONCAT('%', #{pd.keywords}),'%')
  184. or
  185. u.EMAIL LIKE CONCAT(CONCAT('%', #{pd.keywords}),'%')
  186. or
  187. u.NUMBER LIKE CONCAT(CONCAT('%', #{pd.keywords}),'%')
  188. or
  189. u.NAME LIKE CONCAT(CONCAT('%', #{pd.keywords}),'%')
  190. or
  191. u.PHONE LIKE CONCAT(CONCAT('%', #{pd.keywords}),'%')
  192. )
  193. </if>
  194. <if test="pd.ROLE_ID != null and pd.ROLE_ID != ''"><!-- 角色检索 -->
  195. and u.ROLE_ID=#{pd.ROLE_ID}
  196. </if>
  197. <if test="pd.lastLoginStart!=null and pd.lastLoginStart!=''"><!-- 登录时间检索 -->
  198. and u.LAST_LOGIN &gt;= #{pd.lastLoginStart}
  199. </if>
  200. <if test="pd.lastLoginEnd!=null and pd.lastLoginEnd!=''"><!-- 登录时间检索 -->
  201. and u.LAST_LOGIN &lt;= #{pd.lastLoginEnd}
  202. </if>
  203. order by u.LAST_LOGIN desc
  204. </select>
  205. <!-- 用户列表(弹窗选择用) -->
  206. <select id="userBystafflistPage" parameterType="page" resultType="pd" >
  207. select u.USER_ID,
  208. u.USERNAME,
  209. u.PASSWORD,
  210. u.LAST_LOGIN,
  211. u.NAME,
  212. u.IP,
  213. u.EMAIL,
  214. u.NUMBER,
  215. u.PHONE,
  216. r.ROLE_ID,
  217. r.ROLE_NAME
  218. from <include refid="tableName"></include> u, <include refid="roleTableName"></include> r
  219. where u.ROLE_ID = r.ROLE_ID
  220. and u.USERNAME != 'admin'
  221. and r.PARENT_ID = '1'
  222. <if test="pd.keywords!= null and pd.keywords != ''"><!-- 关键词检索 -->
  223. and
  224. (
  225. u.USERNAME LIKE CONCAT(CONCAT('%', #{pd.keywords}),'%')
  226. or
  227. u.EMAIL LIKE CONCAT(CONCAT('%', #{pd.keywords}),'%')
  228. or
  229. u.NUMBER LIKE CONCAT(CONCAT('%', #{pd.keywords}),'%')
  230. or
  231. u.NAME LIKE CONCAT(CONCAT('%', #{pd.keywords}),'%')
  232. or
  233. u.PHONE LIKE CONCAT(CONCAT('%', #{pd.keywords}),'%')
  234. )
  235. </if>
  236. <if test="pd.ROLE_ID != null and pd.ROLE_ID != ''"><!-- 角色检索 -->
  237. and u.ROLE_ID=#{pd.ROLE_ID}
  238. </if>
  239. <if test="pd.lastLoginStart!=null and pd.lastLoginStart!=''"><!-- 登录时间检索 -->
  240. and u.LAST_LOGIN &gt;= #{pd.lastLoginStart}
  241. </if>
  242. <if test="pd.lastLoginEnd!=null and pd.lastLoginEnd!=''"><!-- 登录时间检索 -->
  243. and u.LAST_LOGIN &lt;= #{pd.lastLoginEnd}
  244. </if>
  245. <if test="pd.STAFF_ID != null and pd.STAFF_ID != ''"><!-- 条件满足时是从员工绑定登录用户处调用 -->
  246. and u.USERNAME not in (select s.USER_ID from <include refid="staffTableName"></include> s where s.USER_ID !='')
  247. </if>
  248. order by u.LAST_LOGIN desc
  249. </select>
  250. <!-- 通过邮箱获取数据 -->
  251. <select id="findByUE" parameterType="pd" resultType="pd" >
  252. select
  253. <include refid="Field"></include>
  254. from
  255. <include refid="tableName"></include>
  256. where
  257. EMAIL = #{EMAIL}
  258. <if test="USERNAME != null and USERNAME != ''">
  259. and USERNAME != #{USERNAME}
  260. </if>
  261. </select>
  262. <!-- 通过编号获取数据 -->
  263. <select id="findByUN" parameterType="pd" resultType="pd" >
  264. select
  265. <include refid="Field"></include>
  266. from
  267. <include refid="tableName"></include>
  268. where
  269. NUMBER = #{NUMBER}
  270. <if test="USERNAME != null and USERNAME != ''">
  271. and USERNAME != #{USERNAME}
  272. </if>
  273. </select>
  274. <!-- 通过user_id获取数据 -->
  275. <select id="findById" parameterType="pd" resultType="pd" >
  276. select
  277. <include refid="Field"></include>
  278. from
  279. <include refid="tableName"></include>
  280. where
  281. USER_ID = #{USER_ID}
  282. </select>
  283. <!-- 新增用户 -->
  284. <insert id="saveU" parameterType="pd" >
  285. insert into <include refid="tableName"></include> (
  286. <include refid="Field"></include>
  287. ) values (
  288. <include refid="FieldValue"></include>
  289. )
  290. </insert>
  291. <!-- 修改 -->
  292. <update id="editU" parameterType="pd" >
  293. update <include refid="tableName"></include>
  294. set NAME = #{NAME},
  295. ROLE_ID = #{ROLE_ID},
  296. ROLE_IDS = #{ROLE_IDS},
  297. BZ = #{BZ},
  298. EMAIL = #{EMAIL},
  299. NUMBER = #{NUMBER},
  300. PHONE = #{PHONE}
  301. <if test="PASSWORD != null and PASSWORD != ''">
  302. ,PASSWORD = #{PASSWORD}
  303. </if>
  304. ,COMPANY = #{COMPANY_NAME}
  305. ,ROAD = #{ROAD_NAME}
  306. where
  307. USER_ID = #{USER_ID}
  308. </update>
  309. <!-- 删除用户 -->
  310. <delete id="deleteU" parameterType="pd" flushCache="false">
  311. delete from <include refid="tableName"></include>
  312. where
  313. USER_ID = #{USER_ID}
  314. and
  315. USER_ID != '1'
  316. </delete>
  317. <!-- 批量删除用户 -->
  318. <delete id="deleteAllU" parameterType="String" >
  319. delete from <include refid="tableName"></include>
  320. where
  321. USER_ID in
  322. <foreach item="item" index="index" collection="array" open="(" separator="," close=")">
  323. #{item}
  324. </foreach>
  325. and
  326. USER_ID != '1'
  327. </delete>
  328. <!-- 用户列表(全部) -->
  329. <select id="listAllUser" parameterType="pd" resultType="pd" >
  330. select u.USER_ID,
  331. u.USERNAME,
  332. u.PASSWORD,
  333. u.LAST_LOGIN,
  334. u.NAME,
  335. u.IP,
  336. u.EMAIL,
  337. u.NUMBER,
  338. u.PHONE,
  339. r.ROLE_ID,
  340. r.ROLE_NAME
  341. from <include refid="tableName"></include> u, <include refid="roleTableName"></include> r
  342. where u.ROLE_ID = r.ROLE_ID
  343. and u.USERNAME != 'admin'
  344. and r.PARENT_ID = '1'
  345. <if test="keywords!= null and keywords != ''"><!-- 关键词检索 -->
  346. and
  347. (
  348. u.USERNAME LIKE CONCAT(CONCAT('%', #{keywords}),'%')
  349. or
  350. u.EMAIL LIKE CONCAT(CONCAT('%', #{keywords}),'%')
  351. or
  352. u.NUMBER LIKE CONCAT(CONCAT('%', #{keywords}),'%')
  353. or
  354. u.NAME LIKE CONCAT(CONCAT('%', #{keywords}),'%')
  355. or
  356. u.PHONE LIKE CONCAT(CONCAT('%', #{keywords}),'%')
  357. )
  358. </if>
  359. <if test="ROLE_ID != null and ROLE_ID != ''"><!-- 角色检索 -->
  360. and u.ROLE_ID=#{ROLE_ID}
  361. </if>
  362. <if test="lastLoginStart!=null and lastLoginStart!=''"><!-- 登录时间检索 -->
  363. and u.LAST_LOGIN &gt;= #{lastLoginStart}
  364. </if>
  365. <if test="lastLoginEnd!=null and lastLoginEnd!=''"><!-- 登录时间检索 -->
  366. and u.LAST_LOGIN &lt;= #{lastLoginEnd}
  367. </if>
  368. order by u.LAST_LOGIN desc
  369. </select>
  370. <!-- 获取总数 -->
  371. <select id="getUserCount" parameterType="String" resultType="pd">
  372. select
  373. count(USER_ID) userCount
  374. from
  375. <include refid="tableName"></include>
  376. </select>
  377. <!-- fh313596790qq(青苔) -->
  378. <!-- 获取路公司名 -->
  379. <select id="listAllCompany" resultType="String">
  380. select
  381. NAME
  382. from
  383. oa_department
  384. where PARENT_ID = "0"
  385. ORDER BY (BIANMA+0) ASC
  386. </select>
  387. <!-- 获取路段名 -->
  388. <select id="getAllRoadName" parameterType="String" resultType="String">
  389. select
  390. NAME
  391. from
  392. oa_department
  393. where PARENT_ID = (select DEPARTMENT_ID from oa_department where NAME = #{COMPANY})
  394. ORDER BY (BIANMA+0) ASC
  395. </select>
  396. <insert id="insertAPIUser" parameterType="pd" >
  397. insert into sys_user (
  398. USER_ID,USERNAME,PASSWORD,NAME,ROLE_ID,STATUS,SKIN,COMPANY,ROAD,COMPANY_ID,ROAD_ID
  399. ) values (
  400. #{USER_ID},#{userName},#{password},#{name},#{ROLE_ID},#{STATUS},#{SKIN},#{company_name},#{dep_name},#{COMPANY_ID},#{ROAD_ID}
  401. )
  402. </insert>
  403. <delete id="deleteAPIUser" parameterType="pd" flushCache="false">
  404. delete from sys_user
  405. where USERNAME = #{userName}
  406. and USER_ID != '1'
  407. </delete>
  408. <update id="editAPIUser" parameterType="pd" >
  409. update sys_user
  410. set NAME = #{name},
  411. PASSWORD = #{password},
  412. COMPANY = #{company_name},
  413. ROAD = #{dep_name},
  414. COMPANY_ID = #{COMPANY_ID},
  415. ROAD_ID = #{ROAD_ID},
  416. ROLE_ID = #{ROLE_ID}
  417. where USERNAME = #{userName}
  418. </update>
  419. </mapper>