UserMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  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.tofly.base.mapper.UserMapper">
  4. <resultMap id="userMap" type="com.tofly.base.entity.User">
  5. <id property="id" column="ID"/>
  6. <result property="username" column="USERNAME"/>
  7. <result property="password" column="PASSWORD"/>
  8. <result property="salt" column="SALT"/>
  9. <result property="phone" column="PHONE"/>
  10. <result property="avatar" column="AVATAR"/>
  11. <result property="departmentId" column="DEPARTMENT_ID"/>
  12. <result property="createTime" column="CREATE_TIME"/>
  13. <result property="updateTime" column="UPDATE_TIME"/>
  14. <result property="lockFlag" column="LOCK_FLAG"/>
  15. <result property="statusFlag" column="STATUS_FLAG"/>
  16. <result property="wxOpenid" column="WX_OPENID"/>
  17. <result property="qqOpenid" column="QQ_OPENID"/>
  18. <result property="email" column="EMAIL"/>
  19. <result property="realName" column="REAL_NAME"/>
  20. <result property="loginTime" column="LOGIN_TIME"/>
  21. <result property="lastIp" column="LAST_IP"/>
  22. <result property="pwderrtimes" column="PWDERRTIMES"/>
  23. <result property="worknumber" column="WORKNUMBER"/>
  24. <result property="findpwdkey" column="FINDPWDKEY"/>
  25. <result property="aliasname" column="ALIASNAME"/>
  26. <result property="birthday" column="BIRTHDAY"/>
  27. <result property="belong" column="BELONG"/>
  28. <result property="createUser" column="CREATE_USER"/>
  29. <result property="esignature" column="ESIGNATURE"/>
  30. <result property="userLevel" column="USER_LEVEL"/>
  31. <result property="createType" column="CREATE_TYPE"/>
  32. <result property="firstlog" column="FIRSTLOG"/>
  33. <result property="applyer" column="APPLYER"/>
  34. <result property="applytime" column="APPLYTIME"/>
  35. <result property="applystate" column="APPLYSTATE"/>
  36. <result property="auditor" column="AUDITOR"/>
  37. <result property="accountstate" column="ACCOUNTSTATE"/>
  38. <result property="audittime" column="AUDITTIME"/>
  39. <result property="auditstatus" column="AUDITSTATUS"/>
  40. <result property="auditstate" column="AUDITSTATE"/>
  41. <result property="note" column="NOTE"/>
  42. <result property="enableFlag" column="ENABLE_FLAG"/>
  43. <result property="job" column="JOB"/>
  44. <result property="originalPassword" column="ORIGINAL_PASSWORD"/>
  45. <result property="parentCompanyId" column="PARENT_COMPANY_ID"/>
  46. <result property="companyId" column="COMPANY_ID"/>
  47. <result property="nowVersion" column="NOW_VERSION"/>
  48. <result property="lastAppUpdateTime" column="LAST_APP_UPDATE_TIME"/>
  49. <result property="shortNumber" column="SHORT_NUMBER"/>
  50. <result property="sex" column="SEX"/>
  51. <result property="birth" column="BIRTH"/>
  52. <result property="serialNumber" column="SERIAL_NUMBER"/>
  53. <association property="parentCompanyName" column="PARENT_COMPANY_ID" select="getCompanyName"/>
  54. <association property="companyName" column="COMPANY_ID" select="getCompanyName"/>
  55. <association property="departmentName" column="DEPARTMENT_ID" select="getDName"/>
  56. <association property="roleList" column="ID" select="getRoleList"/>
  57. <collection property="deptList" column="ID" select="getDeptList"/>
  58. </resultMap>
  59. <select id="getCompanyName" resultType="string">
  60. select COMPANY_NAME as companyName
  61. from TF_SMPN_COMPANY_X
  62. where id = #{departmentId}
  63. </select>
  64. <select id="getDName" resultType="java.lang.Object" parameterType="java.lang.String">
  65. select name as departmentName
  66. from TF_SMPN_DEPARTMENT_X
  67. where id = #{departmentId}
  68. </select>
  69. <select id="getRoleList" resultType="com.tofly.base.entity.Role">
  70. SELECT
  71. *
  72. FROM
  73. TF_SMPN_ROLE_X
  74. WHERE
  75. ID IN ( SELECT ROLE_ID FROM TF_SMPN_USERROLE_X WHERE USER_ID = #{id} )
  76. </select>
  77. <select id="getDeptList" resultType="com.tofly.base.entity.Department">
  78. SELECT
  79. *
  80. FROM
  81. TF_SMPN_DEPARTMENT_X
  82. WHERE
  83. ID IN ( SELECT DEPT_ID FROM TF_SMPN_USERDEPT_X WHERE USER_ID = #{id} )
  84. </select>
  85. <select id="getUserById" resultMap="userMap">
  86. select id,
  87. username,
  88. phone,
  89. avatar,
  90. department_id,
  91. create_time,
  92. update_time,
  93. lock_flag,
  94. status_flag,
  95. wx_openid,
  96. qq_openid,
  97. email,
  98. real_name,
  99. login_time,
  100. last_ip,
  101. pwderrtimes,
  102. worknumber,
  103. findpwdkey,
  104. aliasname,
  105. birthday,
  106. belong,
  107. create_user,
  108. CREATE_TYPE,
  109. FIRSTLOG,
  110. APPLYER,
  111. APPLYTIME,
  112. APPLYSTATE,
  113. AUDITOR,
  114. ACCOUNTSTATE,
  115. AUDITTIME,
  116. AUDITSTATE,
  117. AUDITSTATUS,
  118. ESIGNATURE,
  119. NOTE,
  120. ENABLE_FLAG,
  121. SHORT_NUMBER,
  122. SEX,
  123. BIRTH,
  124. JOB,
  125. SERIAL_NUMBER
  126. from TF_SMPN_USER_X
  127. where id = #{id}
  128. </select>
  129. <select id="getExistUserListByRole" resultMap="userMap">
  130. select id,
  131. username,
  132. phone,
  133. avatar,
  134. department_id,
  135. create_time,
  136. update_time,
  137. lock_flag,
  138. status_flag,
  139. wx_openid,
  140. qq_openid,
  141. email,
  142. real_name,
  143. login_time,
  144. last_ip,
  145. pwderrtimes,
  146. worknumber,
  147. findpwdkey,
  148. aliasname,
  149. birthday,
  150. belong,
  151. create_user,
  152. CREATE_TYPE,
  153. FIRSTLOG,
  154. APPLYER,
  155. APPLYTIME,
  156. APPLYSTATE,
  157. AUDITOR,
  158. ACCOUNTSTATE,
  159. AUDITTIME,
  160. AUDITSTATE,
  161. AUDITSTATUS,
  162. ESIGNATURE,
  163. NOTE,
  164. SHORT_NUMBER,
  165. SEX,
  166. BIRTH,
  167. JOB,
  168. SERIAL_NUMBER
  169. from TF_SMPN_USER_X u
  170. where status_flag = '1'
  171. and exists(select 1 from TF_SMPN_USERROLE_X where user_id = u.id and role_id = #{roleId})
  172. </select>
  173. <select id="getNoExistUserListByRole" resultMap="userMap">
  174. select id,
  175. username,
  176. phone,
  177. avatar,
  178. department_id,
  179. create_time,
  180. update_time,
  181. lock_flag,
  182. status_flag,
  183. wx_openid,
  184. qq_openid,
  185. email,
  186. real_name,
  187. login_time,
  188. last_ip,
  189. pwderrtimes,
  190. worknumber,
  191. findpwdkey,
  192. aliasname,
  193. birthday,
  194. belong,
  195. create_user
  196. CREATE_TYPE,
  197. FIRSTLOG,
  198. APPLYER,
  199. APPLYTIME,
  200. APPLYSTATE,
  201. AUDITOR,
  202. ACCOUNTSTATE,
  203. AUDITTIME,
  204. AUDITSTATE,
  205. AUDITSTATUS,
  206. ESIGNATURE,
  207. NOTE,
  208. SHORT_NUMBER,
  209. SEX,
  210. BIRTH,
  211. JOB,
  212. SERIAL_NUMBER
  213. from TF_SMPN_USER_X u
  214. where status_flag = '1'
  215. and not exists(select 1 from TF_SMPN_USERROLE_X where user_id = u.id and role_id = #{roleId})
  216. </select>
  217. <select id="getSources" parameterType="java.lang.Long" resultType="map">
  218. select s.*
  219. from TF_SMPN_DEPARTMENTSOURCE_X ds,
  220. TF_SMPN_SOURCE_X s
  221. where ds.source_id = s.id
  222. and ds.department_id = #departmentId#
  223. </select>
  224. <select id="getUserPage" resultType="java.util.LinkedHashMap" databaseId="oracle">
  225. select id,
  226. username,
  227. phone,
  228. avatar,
  229. department_id,
  230. create_time,
  231. lock_flag,
  232. decode(lock_flag,'0','锁定','未锁定') lock_flag_name,
  233. status_flag,
  234. wx_openid,
  235. qq_openid,
  236. email,
  237. real_name,
  238. login_time,
  239. last_ip,
  240. pwderrtimes,
  241. worknumber,
  242. findpwdkey,
  243. aliasname,
  244. birthday,
  245. belong,
  246. create_user,
  247. user_level,
  248. CREATE_TYPE,
  249. FIRSTLOG,
  250. APPLYER,
  251. APPLYTIME,
  252. APPLYSTATE,
  253. AUDITOR,
  254. ACCOUNTSTATE,
  255. AUDITTIME,
  256. AUDITSTATE,
  257. AUDITSTATUS,
  258. ESIGNATURE,
  259. NOTE,
  260. ENABLE_FLAG,
  261. JOB,
  262. PARENT_COMPANY_ID,
  263. COMPANY_ID,
  264. NOW_VERSION,
  265. LAST_APP_UPDATE_TIME,
  266. SHORT_NUMBER,
  267. SEX,
  268. BIRTH,
  269. (select wmsys.wm_concat(u2.real_name)
  270. from TF_SMPN_USER_ASCRIPTION u1 left join TF_SMPN_USER_X u2
  271. on u1.parent_User_Id = u2.id
  272. where u1.user_id = l.id) userGroup,
  273. (select COMPANY_NAME
  274. from TF_SMPN_COMPANY_X
  275. where id = PARENT_COMPANY_ID) as parentCompanyName,
  276. (select COMPANY_NAME
  277. from TF_SMPN_COMPANY_X
  278. where id = COMPANY_ID) as companyName,
  279. (select real_name from TF_SMPN_USER_X
  280. where username=l.AUDITOR) as auditorName,
  281. (select real_name from TF_SMPN_USER_X
  282. where id=l.create_user) as create_user_name,
  283. (select m.name
  284. from TF_SMPN_DEPARTMENT_X m
  285. where m.id = l.department_id) as dept_name,
  286. to_char((select wmsys.wm_concat(n.role_id)
  287. from TF_SMPN_USERROLE_X n
  288. where n.user_id = l.id)) as role_id_list,
  289. to_char((select wmsys.wm_concat(to_char(o.role_name))
  290. from TF_SMPN_ROLE_X o, TF_SMPN_USERROLE_X n
  291. where n.role_id = o.id
  292. and l.id = n.user_id)) as role_name,
  293. (select notes
  294. from tf_smpn_code_x
  295. where key = '0001'
  296. and value = l.status_flag) as status_flag_name
  297. from TF_SMPN_USER_X l
  298. where
  299. 1=1 and status_flag = 1
  300. <if test="user.auditstatus != null and user.auditstatus.trim() != ''">
  301. and AUDITSTATUS = #{user.auditstatus}
  302. </if>
  303. <if test="user.id != null">
  304. and id = #{user.id}
  305. </if>
  306. <if test="user.realName != null and user.realName.trim() != ''">
  307. and real_Name like '%'||#{user.realName}||'%'
  308. </if>
  309. <if test="user.departmentId != null">
  310. AND ID IN (SELECT a.USER_ID FROM TF_SMPN_USERDEPT_X a WHERE a.DEPT_ID = #{user.departmentId})
  311. </if>
  312. <if test="user.enableFlag != null and user.enableFlag.trim() != ''">
  313. and ENABLE_FLAG = #{user.enableFlag}
  314. </if>
  315. <if test="user.lockFlag != null and user.lockFlag.trim() != ''">
  316. and lock_flag = #{user.lockFlag}
  317. </if>
  318. <if test="user.userLevel != null and user.userLevel.trim() != ''">
  319. and user_level = #{user.userLevel}
  320. </if>
  321. <if test="user.username != null">
  322. and USERNAME like '%'||#{user.username}||'%'
  323. </if>
  324. <if test="user.companyId != null">
  325. AND ID IN (SELECT a.USER_ID FROM TF_SMPN_USERDEPT_X a WHERE a.COMPANY_ID = #{user.companyId})
  326. </if>
  327. <if test="user.deptIds != null">
  328. AND ID IN (SELECT a.USER_ID
  329. FROM TF_SMPN_USERDEPT_X a
  330. WHERE to_char(a.DEPT_ID) IN
  331. <foreach item="nodeCodestr" collection="user.deptIds.split(',')" open="(" separator="," close=")">
  332. #{nodeCodestr}
  333. </foreach>
  334. )
  335. </if>
  336. <if test="user.companyIds != null">
  337. AND ID IN (SELECT a.USER_ID
  338. FROM TF_SMPN_USERDEPT_X a
  339. WHERE to_char(a.COMPANY_ID) IN
  340. <foreach item="nodeCodestr" collection="user.companyIds.split(',')" open="(" separator="," close=")">
  341. #{nodeCodestr}
  342. </foreach>
  343. )
  344. </if>
  345. ORDER BY CREATE_TIME DESC
  346. </select>
  347. <select id="getUserPage" resultType="map" databaseId="mysql">
  348. select id,
  349. username,
  350. phone,
  351. avatar,
  352. department_id,
  353. create_time,
  354. lock_flag,
  355. case lock_flag when '0' then '锁定' else '未锁定' end lock_flag_name,
  356. status_flag,
  357. wx_openid,
  358. qq_openid,
  359. email,
  360. real_name,
  361. login_time,
  362. last_ip,
  363. pwderrtimes,
  364. worknumber,
  365. findpwdkey,
  366. aliasname,
  367. birthday,
  368. belong,
  369. create_user,
  370. user_level,
  371. CREATE_TYPE,
  372. FIRSTLOG,
  373. APPLYER,
  374. APPLYTIME,
  375. APPLYSTATE,
  376. AUDITOR,
  377. ACCOUNTSTATE,
  378. AUDITTIME,
  379. AUDITSTATE,
  380. AUDITSTATUS,
  381. ESIGNATURE,
  382. NOTE,
  383. SHORT_NUMBER,
  384. SEX,
  385. BIRTH,
  386. SERIAL_NUMBER,
  387. (select real_name from TF_SMPN_USER_X
  388. where id=l.create_user) as create_user_name,
  389. (select m.name
  390. from TF_SMPN_DEPARTMENT_X m
  391. where m.id = l.department_id) as dept_name,
  392. (select group_concat(n.role_id)
  393. from TF_SMPN_USERROLE_X n
  394. where n.user_id = l.id group by l.id) as role_id_list,
  395. (select group_concat(o.role_name)
  396. from TF_SMPN_ROLE_X o, TF_SMPN_USERROLE_X n
  397. where n.role_id = o.id
  398. and l.id = n.user_id GROUP BY l.id) as role_name,
  399. (select notes
  400. from tf_smpn_code_x
  401. where `key` = '0011'
  402. and `value` = l.status_flag) as status_flag_name
  403. from TF_SMPN_USER_X l where 1=1
  404. <if test="user.auditstatus != null">
  405. and AUDITSTATUS = #{user.auditstatus}
  406. </if>
  407. <if test="user.realName != null and user.realName.trim() != ''">
  408. and (real_name like CONCAT('%',#{user.realName},'%') or real_name like CONCAT('%',#{user.realName},'%'))
  409. </if>
  410. <if test="user.username != null and user.username.trim() != ''">
  411. and (username like CONCAT('%',#{user.username},'%') or username like CONCAT('%',#{user.username},'%'))
  412. </if>
  413. <if test="user.departmentId != null">
  414. and department_id = #{user.departmentId}
  415. </if>
  416. <if test="user.statusFlag != null">
  417. and status_flag = #{user.statusFlag}
  418. </if>
  419. <if test="user.lockFlag != null">
  420. and lock_flag = #{user.lockFlag}
  421. </if>
  422. <if test="user.userLevel != null">
  423. and user_level = #{userLevel}
  424. </if>
  425. </select>
  426. <update id="updateUserInfo">
  427. update TF_SMPN_USER_X
  428. <set>
  429. <if test="lastIp != null and lastIp.trim() != ''">
  430. LAST_IP = #{lastIp} ,
  431. </if>
  432. <if test="pwderrtimes != null">
  433. PWDERRTIMES = #{pwderrtimes} ,
  434. </if>
  435. <if test="loginTime != null">
  436. LOGIN_TIME = #{loginTime} ,
  437. </if>
  438. <if test="lockFlag != null and lockFlag.trim() != ''">
  439. lockFlag = #{lockFlag} ,
  440. </if>
  441. </set>
  442. where id=#{id}
  443. </update>
  444. <select id="getUserByMenu" resultType="map">
  445. select u.id, u.real_name
  446. from TF_SMPN_USER_X u,
  447. TF_SMPN_USERROLE_X ur,
  448. TF_SMPN_ROLE_X r,
  449. TF_SMPN_ROLEMENU_X rm,
  450. TF_SMPN_MENU_X m
  451. where u.id = ur.user_id
  452. and ur.role_id = r.id
  453. and rm.role_id = r.id
  454. and m.id = rm.menu_id
  455. and m.name = #{menuName}
  456. </select>
  457. <select id="getListHistory" resultType="map" databaseId="oracle">
  458. select u.USERNAME,u.REAL_NAME,u.PHONE,u.EMAIL,u.CREATE_TYPE,
  459. u.STATUS_FLAG,u.LOCK_FLAG,u.AUDITSTATE,u.CREATE_TIME,u.CREATE_USER,u.AUDITTIME,
  460. u.AUDITOR,u.AUDITSTATUS,u.AVATAR,u.ESIGNATURE,u.NOTE,u.APPLYER,u.APPLYSTATE,u.SHORT_NUMBER,
  461. u.SEX,u.BIRTH,u.JOB,SERIAL_NUMBER,
  462. (select real_name from TF_SMPN_USER_X where u.APPLYER = username) as applyerName,
  463. (select real_name from TF_SMPN_USER_X
  464. where username=u.AUDITOR) as auditorName,
  465. (select m.name
  466. from TF_SMPN_DEPARTMENT_X m
  467. where m.id = u.department_id) as dept_name,
  468. to_char((select wmsys.wm_concat(to_char(o.role_name))
  469. from TF_SMPN_ROLE_X o, TF_SMPN_USERROLE_X n
  470. where n.role_id = o.id
  471. and u.id = n.user_id)) as role_name
  472. FROM
  473. TF_SMPN_USER_X u
  474. where
  475. u.CREATE_TYPE=1
  476. <if test="map.userName != null and map.userName.trim() != ''">
  477. and u.APPLYER like '%'||#{map.userName}||'%'
  478. </if>
  479. <if test="map.realName != null and map.realName.trim() != ''">
  480. and u.REAL_NAME like '%'||#{map.realName}||'%'
  481. </if>
  482. <if test="map.auditStatus != null and map.auditStatus.trim() != ''">
  483. and u.AUDITSTATUS = #{map.auditStatus}
  484. </if>
  485. <if test="map.StartAuditTime != null and map.StartAuditTime.trim() != ''">
  486. and to_char(u.CREATE_TIME,'yyyy-MM-dd hh:mm:ss') >= #{map.StartAuditTime}
  487. </if>
  488. <if test="map.endAuditTime != null and map.endAuditTime.trim() != ''">
  489. <![CDATA[ and to_char(u.CREATE_TIME,'yyyy-MM-dd hh:mm:ss') <= #{map.endAuditTime} ]]>
  490. </if>
  491. order by u.CREATE_TIME desc
  492. </select>
  493. <update id="updateByIdList" parameterType="java.util.List">
  494. update TF_SMPN_USER_X set LOCK_FLAG=0
  495. where
  496. id in
  497. <foreach item="item" index="index" collection="list" separator="," open="(" close=")">
  498. #{item}
  499. </foreach>
  500. </update>
  501. <update id="updateByIdListToUnlock" parameterType="java.util.List">
  502. update TF_SMPN_USER_X
  503. set LOCK_FLAG=1,
  504. pwderrtimes = 0
  505. where
  506. id in
  507. <foreach item="item" index="index" collection="list" separator="," open="(" close=")">
  508. #{item}
  509. </foreach>
  510. </update>
  511. <update id="updateByIdStatusFlag" parameterType="java.util.List">
  512. update TF_SMPN_USER_X set ENABLE_FLAG=0
  513. where
  514. id in
  515. <foreach item="item" index="index" collection="list" separator="," open="(" close=")">
  516. #{item}
  517. </foreach>
  518. </update>
  519. <update id="updateUnStatusFlag" parameterType="java.util.List">
  520. update TF_SMPN_USER_X set ENABLE_FLAG=1
  521. where
  522. id in
  523. <foreach item="item" index="index" collection="list" separator="," open="(" close=")">
  524. #{item}
  525. </foreach>
  526. </update>
  527. <select id="sysUserReport" resultType="Map">
  528. select t2.NAME as dptName,count(1) as num from TF_SMPN_USER_X t1
  529. inner join
  530. TF_SMPN_DEPARTMENT_X t2
  531. on t1.DEPARTMENT_ID=t2.id
  532. where 1=1
  533. and t1.STATUS_FLAG=1
  534. GROUP BY t2.NAME
  535. </select>
  536. <select id="getDeptUserIdList" resultType="long">
  537. select ID from TF_SMPN_USER_X
  538. <where>
  539. STATUS_FLAG=1
  540. <if test="deptIdList!=null and deptIdList.size()>0">
  541. and department_id IN
  542. <foreach item="deptId" index="idx" collection="deptIdList" separator="," open="(" close=")">
  543. #{deptId}
  544. </foreach>
  545. </if>
  546. </where>
  547. </select>
  548. </mapper>