SysUserMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.ruoyi.project.system.mapper.SysUserMapper">
  6. <resultMap type="SysUser" id="SysUserResult">
  7. <id property="userId" column="user_id" />
  8. <result property="staffId" column="staffid" />
  9. <result property="deptId" column="dept_id" />
  10. <result property="userName" column="user_name" />
  11. <result property="nickName" column="nick_name" />
  12. <result property="email" column="email" />
  13. <result property="phonenumber" column="phonenumber" />
  14. <result property="sex" column="sex" />
  15. <result property="avatar" column="avatar" />
  16. <result property="password" column="password" />
  17. <result property="status" column="status" />
  18. <result property="delFlag" column="del_flag" />
  19. <result property="loginIp" column="login_ip" />
  20. <result property="loginDate" column="login_date" />
  21. <result property="createBy" column="create_by" />
  22. <result property="createTime" column="create_time" />
  23. <result property="updateBy" column="update_by" />
  24. <result property="updateTime" column="update_time" />
  25. <result property="remark" column="remark" />
  26. <result property="homeType" column="home_type" />
  27. <result property="dataScope" column="data_scope" />
  28. <result property="deptCheckStrictly" column="dept_check_strictly" />
  29. <result property="signUrl" column="sign_url" />
  30. <association property="dept" column="dept_id" javaType="SysDept" resultMap="deptResult" />
  31. <collection property="roles" javaType="java.util.List" resultMap="RoleResult" />
  32. </resultMap>
  33. <resultMap id="deptResult" type="SysDept">
  34. <id property="deptId" column="dept_id" />
  35. <result property="parentId" column="parent_id" />
  36. <result property="deptName" column="dept_name" />
  37. <result property="orderNum" column="order_num" />
  38. <result property="leader" column="leader" />
  39. <result property="status" column="dept_status" />
  40. </resultMap>
  41. <resultMap id="RoleResult" type="SysRole">
  42. <id property="roleId" column="role_id" />
  43. <result property="roleName" column="role_name" />
  44. <result property="roleKey" column="role_key" />
  45. <result property="roleSort" column="role_sort" />
  46. <result property="dataScope" column="data_scope" />
  47. <result property="status" column="role_status" />
  48. </resultMap>
  49. <select id="selectUserPost" parameterType="tStaffmgr" resultMap="SysUserResult">
  50. select b.USER_ID ,b.NICK_NAME ,b.STAFFID from T_STAFFMGR a
  51. left join SYS_USER b on a.STAFFID=b.STAFFID
  52. left join sys_dept d on a.dept_id = d.dept_id
  53. left join T_WORKLICENSE e on e.EMPLOYEEID=a.STAFFID
  54. <where>
  55. <if test="actualposts != null and actualposts != ''">
  56. and a.actualpost in
  57. <foreach collection="actualposts.split(',')" item="item" index="index"
  58. open="(" close=")" separator=",">
  59. #{item}
  60. </foreach>
  61. </if>
  62. <if test="deptId != null and deptId != ''"> and a.dept_id=#{deptId}</if>
  63. <if test="boiler != null"> and e.boiler=1</if>
  64. <if test="cracking != null"> and e.cracking=1</if>
  65. <if test="hotarea != null"> and e.hotarea=1</if>
  66. <if test="coldarea != null"> and e.coldarea=1</if>
  67. and a.DEL_FLAG=0
  68. and b.USER_ID is not null
  69. </where>
  70. ${params.dataScope}
  71. </select>
  72. <select id="selectUserPostPssr" parameterType="tStaffmgr" resultMap="SysUserResult">
  73. select b.USER_ID ,b.NICK_NAME ,b.STAFFID from T_STAFFMGR a
  74. left join SYS_USER b on a.STAFFID=b.STAFFID
  75. left join sys_dept d on a.dept_id = d.dept_id
  76. left join T_WORKLICENSE e on e.EMPLOYEEID=a.STAFFID
  77. <where>
  78. <if test="actualposts != null and actualposts != ''">
  79. and a.actualpost in
  80. <foreach collection="actualposts.split(',')" item="item" index="index"
  81. open="(" close=")" separator=",">
  82. #{item}
  83. </foreach>
  84. </if>
  85. <if test="deptId != null and deptId != ''"> and a.dept_id=#{deptId}</if>
  86. <if test="boiler != null"> and e.boiler=1</if>
  87. <if test="cracking != null"> and e.cracking=1</if>
  88. <if test="hotarea != null"> and e.hotarea=1</if>
  89. <if test="coldarea != null"> and e.coldarea=1</if>
  90. and a.DEL_FLAG=0
  91. and b.USER_ID is not null
  92. </where>
  93. ${params.dataScope}
  94. </select>
  95. <select id="selectUserByMgrRegion" parameterType="tStaffmgr" resultType="map">
  96. <![CDATA[
  97. WITH split_regions AS (
  98. SELECT
  99. a.STAFFID,
  100. a.DEL_FLAG,
  101. a.dept_id,
  102. TRIM(REGEXP_SUBSTR(a.region, '[^,]+', 1, LEVEL)) as single_region
  103. FROM T_STAFFMGR a
  104. WHERE (a.region LIKE '%芳烃抽提%' OR a.region LIKE '%汽油加氢%' OR a.region LIKE '%压缩%'
  105. OR a.region LIKE '%分离%' OR a.region LIKE '%裂解%')
  106. AND a.DEL_FLAG = 0
  107. CONNECT BY LEVEL <= REGEXP_COUNT(a.region, '[^,]+')
  108. AND PRIOR a.STAFFID = a.STAFFID
  109. AND PRIOR DBMS_RANDOM.VALUE IS NOT NULL
  110. )
  111. SELECT
  112. sr.single_region AS "REGION",
  113. LISTAGG(b.NICK_NAME, ',') WITHIN GROUP (ORDER BY b.NICK_NAME) AS "NICKNAME",
  114. LISTAGG(b.user_id, ',') WITHIN GROUP (ORDER BY b.user_id) AS "USERID"
  115. FROM split_regions sr
  116. LEFT JOIN SYS_USER b ON sr.STAFFID = b.STAFFID
  117. LEFT JOIN sys_dept d ON sr.dept_id = d.dept_id
  118. WHERE b.USER_ID IS NOT NULL
  119. ]]>
  120. ${params.dataScope}
  121. GROUP BY sr.single_region
  122. </select>
  123. <select id="selectAllUser" resultType="SysUser">
  124. select * from sys_user u where u.del_flag = '0'
  125. </select>
  126. <sql id="selectUserVo">
  127. select u.user_id,u.staffid,u.home_type, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
  128. u.data_scope, u.dept_check_strictly,u.sign_url,
  129. d.dept_id, d.parent_id, d.dept_name, d.order_num, d.leader, d.status as dept_status,
  130. r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
  131. from sys_user u
  132. left join sys_dept d on u.dept_id = d.dept_id
  133. left join sys_user_role ur on u.user_id = ur.user_id
  134. left join sys_role r on r.role_id = ur.role_id
  135. </sql>
  136. <select id="selectSafeManagerUserByPlantCode" resultType="SysUser">
  137. SELECT
  138. nick_name,
  139. phonenumber
  140. FROM
  141. SYS_USER
  142. WHERE
  143. USER_ID = (
  144. SELECT
  145. USER_ID
  146. FROM
  147. SYS_USER_ROLE
  148. WHERE
  149. ROLE_ID = 10020
  150. AND USER_ID IN (
  151. SELECT
  152. USER_ID
  153. FROM
  154. SYS_USER
  155. WHERE
  156. DEPT_ID = (
  157. SELECT
  158. DEPT_ID
  159. FROM
  160. SYS_DEPT
  161. WHERE
  162. DEPT_NAME = (
  163. SELECT DEPT_CODE FROM SYS_PLANT WHERE NAME = (
  164. SELECT PLANT_CODE FROM T_REPORT_HI_YLRQ WHERE PLANT_CODE = #{plantCode} AND ROWNUM <![CDATA[ < ]]> 2 )
  165. AND LENGTH(DEPT_CODE) > 0 )
  166. )
  167. )
  168. AND ROWNUM <![CDATA[ < ]]> 2
  169. )
  170. </select>
  171. <select id="selectUserSingle" parameterType="SysUser" resultMap="SysUserResult">
  172. select u.user_id,u.staffid,u.home_type, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from sys_user u
  173. left join sys_dept d on u.dept_id = d.dept_id
  174. where u.del_flag = '0' and 2 > ROWNUM
  175. <if test="nickName != null and nickName != ''">
  176. AND u.nick_name = #{nickName}
  177. </if>
  178. <if test="staffId != null and staffId != ''">
  179. AND u.staffid = #{staffId}
  180. </if>
  181. <if test="deptId != null and deptId != 0">
  182. AND u.dept_id = #{deptId}
  183. </if>
  184. </select>
  185. <select id="selectUserListByDeptId" parameterType="Long" resultMap="SysUserResult">
  186. select u.user_id,u.staffid,u.home_type, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name from sys_user u
  187. left join sys_dept d on u.dept_id = d.dept_id
  188. where u.del_flag = '0' and d.dept_id = #{deptId}
  189. </select>
  190. <select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult">
  191. select u.user_id,u.staffid,u.home_type,u.sign_url, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from sys_user u
  192. left join sys_dept d on u.dept_id = d.dept_id
  193. where u.del_flag = '0'
  194. <if test="userName != null and userName != ''">
  195. AND u.user_name like concat(concat('%',#{userName}),'%')
  196. </if>
  197. <if test="staffId != null and staffId != ''">
  198. AND u.staffid like concat(concat('%',#{staffId}),'%')
  199. </if>
  200. <if test="nickName != null and nickName != ''">
  201. AND u.nick_name like concat(concat('%',#{nickName}),'%')
  202. </if>
  203. <if test="status != null and status != ''">
  204. AND u.status = #{status}
  205. </if>
  206. <if test="phonenumber != null and phonenumber != ''">
  207. AND u.phonenumber like concat(concat('%',#{phonenumber}),'%')
  208. </if>
  209. <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
  210. AND u.create_time &gt;= to_date(#{beginTime},'yyyy-MM-dd HH24:mi:ss')
  211. </if>
  212. <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
  213. AND u.create_time &lt;= to_date(#{endTime},'yyyy-MM-dd HH24:mi:ss')
  214. </if>
  215. <if test="deptId != null and deptId != 0">
  216. AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE FIND_IN_SET(#{deptId}, ancestors) <![CDATA[ <> ]]> 0 ))
  217. </if>
  218. <!-- 数据范围过滤 -->
  219. ${params.dataScope}
  220. </select>
  221. <select id="selectPssrUserList" parameterType="SysUser" resultMap="SysUserResult">
  222. select u.user_id,u.staffid,u.home_type,u.sign_url, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from sys_user u
  223. JOIN sys_dept d ON u.dept_id = d.dept_id
  224. WHERE d.dept_id IN (
  225. -- 递归查询,找到某个父级部门(假设传入的部门ID为 :parent_dept_id)的所有子部门
  226. SELECT dept_id
  227. FROM sys_dept
  228. START WITH dept_id in (10040,10000,108,109)
  229. CONNECT BY PRIOR dept_id = parent_id
  230. )
  231. <if test="nickName != null and nickName != ''">
  232. AND u.nick_name like concat(concat('%',#{nickName}),'%')
  233. </if>
  234. and u.del_flag = '0'
  235. </select>
  236. <select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult">
  237. <include refid="selectUserVo"/>
  238. where upper(u.user_name)= upper(#{userName})
  239. </select>
  240. <select id="selectUserByDept" parameterType="Long" resultMap="SysUserResult">
  241. <include refid="selectUserVo"/>
  242. where u.dept_id = #{deptId}
  243. </select>
  244. <select id="selectUserListByPost" parameterType="String" resultMap="SysUserResult">
  245. select u.user_id,u.staffid,u.email, u.dept_id, u.user_name, u.nick_name||'__'||d.dept_name as nick_name
  246. from sys_user u
  247. left join sys_dept d on u.dept_id = d.dept_id
  248. left join sys_user_role ur on u.user_id = ur.user_id
  249. left join sys_role r on r.role_id = ur.role_id
  250. LEFT JOIN SYS_USER_POST sp on u.USER_ID = sp.USER_ID
  251. LEFT JOIN SYS_POST p on p.POST_ID = sp.POST_ID
  252. where u.del_flag = '0' and u.staffid is not null
  253. <if test="postCode != null and postCode != ''">
  254. and p.POST_CODE = #{postCode}
  255. </if>
  256. </select>
  257. <select id="selectUserListByRoleAndDept" parameterType="SysUser" resultMap="SysUserResult">
  258. select u.user_id,u.staffid,u.email, u.dept_id, u.user_name, u.nick_name ,d.dept_name,r.ROLE_ID
  259. from sys_user u
  260. left join sys_dept d on u.dept_id = d.dept_id
  261. left join sys_user_role ur on u.user_id = ur.user_id
  262. left join sys_role r on r.role_id = ur.role_id
  263. LEFT JOIN SYS_USER_POST sp on u.USER_ID = sp.USER_ID
  264. LEFT JOIN SYS_POST p on p.POST_ID = sp.POST_ID
  265. where u.del_flag = '0' and u.staffid is not null
  266. <if test="roleId != null and roleId != ''">
  267. and r.role_id = #{roleId}
  268. </if>
  269. <if test="deptId != null and deptId != ''">
  270. and d.dept_id = #{deptId}
  271. </if>
  272. </select>
  273. <select id="selectUserById" parameterType="Long" resultMap="SysUserResult">
  274. <include refid="selectUserVo"/>
  275. where u.user_id = #{userId}
  276. </select>
  277. <select id="selectNickNameById" parameterType="Long" resultMap="SysUserResult">
  278. select u.nick_name from SYS_USER u
  279. where u.user_id = #{userId}
  280. </select>
  281. <select id="selectUserByStaffId" parameterType="String" resultMap="SysUserResult">
  282. <include refid="selectUserVo"/>
  283. where 2 > ROWNUM and u.staffid = #{staffid} and u.del_flag = 0
  284. </select>
  285. <select id="checkUserNameUnique" parameterType="String" resultType="int">
  286. select count(1) from sys_user where user_name = #{userName} and rownum <![CDATA[ <= ]]> 1
  287. </select>
  288. <select id="checkPhoneUnique" parameterType="String" resultMap="SysUserResult">
  289. select user_id, phonenumber from sys_user where phonenumber = #{phonenumber} and rownum <![CDATA[ <= ]]> 1
  290. </select>
  291. <select id="checkEmailUnique" parameterType="String" resultMap="SysUserResult">
  292. select user_id, email from sys_user where email = #{email} and rownum <![CDATA[ <= ]]> 1
  293. </select>
  294. <insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId">
  295. <selectKey keyProperty="userId" order="BEFORE" resultType="Long">
  296. select seq_sys_user.nextval as userId from DUAL
  297. </selectKey>
  298. insert into sys_user(
  299. <if test="userId != null and userId != 0">user_id,</if>
  300. <if test="staffId != null and staffId != 0">staffid,</if>
  301. <if test="deptId != null and deptId != 0">dept_id,</if>
  302. <if test="userName != null and userName != ''">user_name,</if>
  303. <if test="nickName != null and nickName != ''">nick_name,</if>
  304. <if test="email != null and email != ''">email,</if>
  305. <if test="avatar != null and avatar != ''">avatar,</if>
  306. <if test="phonenumber != null and phonenumber != ''">phonenumber,</if>
  307. <if test="sex != null and sex != ''">sex,</if>
  308. <if test="homeType != null and homeType != ''">home_type,</if>
  309. <if test="password != null and password != ''">password,</if>
  310. <if test="status != null and status != ''">status,</if>
  311. <if test="createBy != null and createBy != ''">create_by,</if>
  312. <if test="remark != null and remark != ''">remark,</if>
  313. <if test="signUrl != null and signUrl != ''">sign_url,</if>
  314. create_time
  315. )values(
  316. <if test="userId != null and userId != ''">#{userId},</if>
  317. <if test="staffId != null and staffId != ''">#{staffId},</if>
  318. <if test="deptId != null and deptId != ''">#{deptId},</if>
  319. <if test="userName != null and userName != ''">#{userName},</if>
  320. <if test="nickName != null and nickName != ''">#{nickName},</if>
  321. <if test="email != null and email != ''">#{email},</if>
  322. <if test="avatar != null and avatar != ''">#{avatar},</if>
  323. <if test="phonenumber != null and phonenumber != ''">#{phonenumber},</if>
  324. <if test="sex != null and sex != ''">#{sex},</if>
  325. <if test="homeType != null and homeType != ''">#{homeType},</if>
  326. <if test="password != null and password != ''">#{password},</if>
  327. <if test="status != null and status != ''">#{status},</if>
  328. <if test="createBy != null and createBy != ''">#{createBy},</if>
  329. <if test="remark != null and remark != ''">#{remark},</if>
  330. <if test="signUrl != null and signUrl != ''">#{signUrl},</if>
  331. sysdate
  332. )
  333. </insert>
  334. <update id="updateUser" parameterType="SysUser">
  335. update sys_user
  336. <set>
  337. <if test="deptId != null and deptId != 0">dept_id = #{deptId},</if>
  338. <if test="staffId != null and staffId != 0">staffid = #{staffId},</if>
  339. <if test="userName != null and userName != ''">user_name = #{userName},</if>
  340. <if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
  341. <if test="email != null and email != ''">email = #{email},</if>
  342. <if test="phonenumber != null and phonenumber != ''">phonenumber = #{phonenumber},</if>
  343. <if test="sex != null and sex != ''">sex = #{sex},</if>
  344. <if test="homeType != null and homeType != ''">home_type = #{homeType},</if>
  345. <if test="avatar != null and avatar != ''">avatar = #{avatar},</if>
  346. <if test="password != null and password != ''">password = #{password},</if>
  347. <if test="status != null and status != ''">status = #{status},</if>
  348. <if test="loginIp != null and loginIp != ''">login_ip = #{loginIp},</if>
  349. <if test="loginDate != null">login_date = #{loginDate},</if>
  350. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  351. <if test="remark != null">remark = #{remark},</if>
  352. <if test="dataScope != null and dataScope != ''">data_scope = #{dataScope},</if>
  353. <if test="deptCheckStrictly != null">dept_check_strictly = #{deptCheckStrictly},</if>
  354. <if test="signUrl != null">sign_url = #{signUrl},</if>
  355. update_time = sysdate
  356. </set>
  357. where user_id = #{userId}
  358. </update>
  359. <update id="updateUserStatus" parameterType="SysUser">
  360. update sys_user set status = #{status} where user_id = #{userId}
  361. </update>
  362. <update id="updateUserAvatar" parameterType="SysUser">
  363. update sys_user set avatar = #{avatar} where user_name = #{userName}
  364. </update>
  365. <update id="resetUserPwd" parameterType="SysUser">
  366. update sys_user set password = #{password} where user_name = #{userName}
  367. </update>
  368. <delete id="deleteUserById" parameterType="Long">
  369. delete from sys_user where user_id = #{userId}
  370. </delete>
  371. <delete id="deleteUserByIds" parameterType="Long">
  372. delete from sys_user where user_id in
  373. <foreach collection="array" item="userId" open="(" separator="," close=")">
  374. #{userId}
  375. </foreach>
  376. </delete>
  377. <delete id="deleteUserDeptByUserId" parameterType="Long">
  378. delete from sys_user_dept where user_id=#{userId}
  379. </delete>
  380. </mapper>