SysUserMapper.xml 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253
  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.zd.system.mapper.SysUserMapper">
  6. <resultMap type="com.zd.model.entity.SysUser" id="SysUserResult">
  7. <id property="userId" column="user_id"/>
  8. <result property="deptId" column="dept_id"/>
  9. <result property="userName" column="user_name"/>
  10. <result property="nickName" column="nick_name"/>
  11. <result property="email" column="email"/>
  12. <result property="phonenumber" column="phonenumber"/>
  13. <result property="sex" column="sex"/>
  14. <result property="avatar" column="avatar"/>
  15. <result property="password" column="password"/>
  16. <result property="status" column="status"/>
  17. <result property="delFlag" column="del_flag"/>
  18. <result property="loginIp" column="login_ip"/>
  19. <result property="loginDate" column="login_date"/>
  20. <result property="createBy" column="create_by"/>
  21. <result property="createTime" column="create_time"/>
  22. <result property="updateBy" column="update_by"/>
  23. <result property="updateTime" column="update_time"/>
  24. <result property="remark" column="remark"/>
  25. <result property="userType" column="user_type"/>
  26. <result property="major" column="major"/>
  27. <result property="grade" column="grade"/>
  28. <result property="gradeName" column="gradeName"/>
  29. <result property="category" column="category"/>
  30. <result property="tutorUserId" column="tutor_user_id"/>
  31. <result property="position" column="position"/>
  32. <result property="positionName" column="positionName"/>
  33. <result property="nature" column="nature"/>
  34. <result property="deptName" column="dept_name"/>
  35. <result property="tutorUserName" column="tutorUserName"/>
  36. <result property="cardNum" column="card_num"/>
  37. <result property="cardNumSimple" column="card_num_simple"/>
  38. <result property="wechatId" column="wechat_id"/>
  39. <result property="education" column="education"/>
  40. <result property="nationality" column="nationality"/>
  41. <result property="addr" column="addr"/>
  42. <result property="workStatus" column="work_status"/>
  43. <result property="dateBirth" column="date_birth"/>
  44. <result property="department" column="department"/>
  45. <result property="majorId" column="major_id"/>
  46. <result property="isCheck" column="is_check"/>
  47. <result property="signature" column="signature"/>
  48. <result property="faceImg" column="face_img"/>
  49. <result property="className" column="class_name"/>
  50. <result property="createTimeStr" column="createTimeStr"/>
  51. <association property="dept" column="dept_id" javaType="com.zd.model.entity.SysDept"
  52. resultMap="deptResult"/>
  53. <!--<collection property="roles" javaType="java.util.List" resultMap="RoleResult"/>-->
  54. </resultMap>
  55. <resultMap id="deptResult" type="com.zd.model.entity.SysDept">
  56. <id property="deptId" column="dept_id"/>
  57. <result property="parentId" column="parent_id"/>
  58. <result property="deptName" column="dept_name"/>
  59. <result property="orderNum" column="order_num"/>
  60. <result property="leader" column="leader"/>
  61. <result property="status" column="dept_status"/>
  62. </resultMap>
  63. <resultMap id="RoleResult" type="com.zd.model.entity.SysRole">
  64. <id property="roleId" column="role_id"/>
  65. <result property="roleName" column="role_name"/>
  66. <result property="roleKey" column="role_key"/>
  67. <result property="roleSort" column="role_sort"/>
  68. <result property="dataScope" column="data_scope"/>
  69. <result property="status" column="role_status"/>
  70. </resultMap>
  71. <!--2.6弃用-->
  72. <sql id="selectUserVo">
  73. select u.user_id,
  74. u.dept_id,
  75. u.user_name,
  76. u.nick_name,
  77. u.email,
  78. u.avatar,
  79. u.phonenumber,
  80. u.password,
  81. u.sex,
  82. u.status,
  83. u.del_flag,
  84. u.login_ip,
  85. u.login_date,
  86. u.create_by,
  87. u.create_time,
  88. u.remark,
  89. u.user_type,
  90. d.dept_id,
  91. d.parent_id,
  92. d.dept_name,
  93. d.order_num,
  94. d.leader,
  95. d.status as dept_status,
  96. r.role_id,
  97. r.role_name,
  98. r.role_key,
  99. r.role_sort,
  100. r.data_scope,
  101. r.status as role_status,
  102. u.major,
  103. u.major_id,
  104. u.grade,
  105. u.category,
  106. u.tutor_user_id,
  107. u.position,
  108. u.nature,
  109. u.signature,
  110. u.card_num,
  111. u.wechat_id,
  112. u.education,
  113. u.nationality,
  114. u.addr,
  115. u.work_status,
  116. u.date_birth,
  117. ut.nick_name tutorUserName,
  118. u.is_check
  119. from sys_user u
  120. left join sys_dept d on u.dept_id = d.dept_id
  121. left join sys_user_role ur on u.user_id = ur.user_id
  122. left join sys_role r on r.role_id = ur.role_id
  123. left join sys_user ut on ut.user_id = u.tutor_user_id
  124. </sql>
  125. <sql id="selectUserNewVo">
  126. select u.user_id,
  127. u.dept_id,
  128. u.user_name,
  129. u.nick_name,
  130. u.email,
  131. u.avatar,
  132. u.phonenumber,
  133. u.password,
  134. u.sex,
  135. u.status,
  136. u.del_flag,
  137. u.login_ip,
  138. u.login_date,
  139. u.create_by,
  140. u.create_time,
  141. u.remark,
  142. u.user_type,
  143. d.dept_id,
  144. d.parent_id,
  145. d.dept_name,
  146. d.order_num,
  147. d.leader,
  148. d.status as dept_status,
  149. sm.`major_name` major,
  150. u.grade,
  151. u.category,
  152. u.tutor_user_id,
  153. u.position,
  154. u.nature,
  155. u.signature,
  156. u.card_num,
  157. u.card_num_simple,
  158. u.wechat_id,
  159. u.education,
  160. u.nationality,
  161. u.addr,
  162. u.work_status,
  163. u.date_birth,
  164. ut.nick_name tutorUserName,
  165. u.is_check,
  166. uf.face_img,
  167. sc.class_name,
  168. u.major_id,
  169. u.signature,
  170. pt.`post_name` positionName
  171. from sys_user u
  172. left join sys_dept d on u.dept_id = d.dept_id
  173. left join sys_user ut on ut.user_id = u.tutor_user_id
  174. left join lab_students_info uf on u.user_id = uf.join_students_id
  175. LEFT JOIN sys_class sc ON sc.id = u.grade
  176. LEFT JOIN sys_major sm ON sm.id = u.major_id
  177. left join sys_post pt on pt.`post_id` = u.`position`
  178. </sql>
  179. <select id="selectUserList" parameterType="com.zd.model.entity.SysUser" resultMap="SysUserResult">
  180. select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.password, u.sex,
  181. u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
  182. u.major_id, u.grade, u.tutor_user_id, u.position, p.post_name as positionName,
  183. u.nature,(select sc.class_name from sys_class sc where sc.id = u.grade) gradeName,
  184. u.card_num,u.card_num_simple,u.wechat_id,u.nationality,u.addr,u.work_status,
  185. u.date_birth,d.dept_name, d.leader,u.department,
  186. u.education, u.user_type,sm.`major_name` major,
  187. ut.nick_name tutorUserName,u.is_check,date_format(u.create_time, '%Y-%m-%d') createTimeStr
  188. from
  189. sys_user u
  190. left join sys_dept d on u.dept_id = d.dept_id
  191. left join sys_user ut on ut.user_id = u.tutor_user_id
  192. left join sys_post p on u.position = p.post_id
  193. LEFT JOIN sys_major sm ON sm.id = u.major_id
  194. where u.del_flag = '0'
  195. <if test="userId != null ">
  196. AND u.user_id = #{userId}
  197. </if>
  198. <if test="paramIds != null and paramIds != ''">
  199. AND find_in_set(u.user_id, #{paramIds})
  200. </if>
  201. <if test="userName != null and userName != ''">
  202. AND u.user_name like concat('%', #{userName}, '%')
  203. </if>
  204. <if test="nickName != null and nickName != ''">
  205. AND u.nick_name like concat('%', #{nickName}, '%')
  206. </if>
  207. <if test="cardNum != null and cardNum != ''">
  208. AND u.card_num = #{cardNum}
  209. </if>
  210. <if test="cardNumSimple != null and cardNumSimple != ''">
  211. <if test="cardNumSimple == 1">
  212. AND u.card_num_simple is not null
  213. </if>
  214. <if test="cardNumSimple == 0">
  215. AND u.card_num_simple is null
  216. </if>
  217. </if>
  218. <if test="userType != null and userType != ''">
  219. AND u.user_type = #{userType}
  220. </if>
  221. <if test="userType == null or userType == ''">
  222. AND u.user_type != '00' AND u.user_type != '33'
  223. </if>
  224. <if test="status != null and status != ''">
  225. AND u.status = #{status}
  226. </if>
  227. <if test="phonenumber != null and phonenumber != ''">
  228. AND u.phonenumber like concat('%', #{phonenumber}, '%')
  229. </if>
  230. <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
  231. AND date_format(u.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
  232. </if>
  233. <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
  234. AND date_format(u.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
  235. </if>
  236. <if test="deptId != null and deptId != 0">
  237. AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId},
  238. ancestors) ))
  239. </if>
  240. <if test="ids!=null and ids.size > 0">
  241. <choose>
  242. <when test="include">
  243. AND u.user_id not IN
  244. </when>
  245. <otherwise>
  246. AND u.user_id IN
  247. </otherwise>
  248. </choose>
  249. <foreach item="item" collection="ids" separator="," open="(" close=")" index="">'${item}'</foreach>
  250. </if>
  251. <if test="major != null and major != ''">
  252. AND u.major like concat('%', #{major}, '%')
  253. </if>
  254. <if test="majorId != null and majorId != ''">
  255. AND u.major_id = #{majorId}
  256. </if>
  257. <if test="searchValue != null and searchValue != ''">
  258. AND
  259. (
  260. u.nick_name like concat('%', #{searchValue}, '%')
  261. or
  262. u.user_name like concat('%', #{searchValue}, '%')
  263. or
  264. u.phonenumber like concat('%', #{searchValue}, '%')
  265. or
  266. ut.nick_name like concat('%', #{searchValue}, '%')
  267. or
  268. p.post_name like concat('%', #{searchValue}, '%')
  269. )
  270. </if>
  271. <if test="grade != null and grade != ''">
  272. AND u.grade like concat('%', #{grade}, '%')
  273. </if>
  274. <if test="category != null and category != ''">
  275. AND u.category like concat('%', #{category}, '%')
  276. </if>
  277. <if test="tutorUserId != null">
  278. AND u.tutor_user_id = #{tutorUserId}
  279. </if>
  280. <if test="nature != null and nature != ''">
  281. AND u.nature = #{nature}
  282. </if>
  283. <if test="position != null and position != ''">
  284. AND u.position = #{position}
  285. </if>
  286. <if test="isCheck != null">
  287. AND u.is_check = #{isCheck}
  288. </if>
  289. <!-- 数据范围过滤 -->
  290. ${params.dataScope}
  291. order by
  292. <if test="userType == '11'">
  293. u.nature ASC,
  294. </if>
  295. u.create_time DESC
  296. </select>
  297. <select id="selectUserListByDeptIds" resultMap="SysUserResult">
  298. select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.password, u.sex,
  299. u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
  300. u.card_num,u.wechat_id,u.education,u.nationality,u.addr,u.work_status,u.date_birth
  301. from
  302. sys_user u
  303. where u.del_flag = '0'
  304. and u.status = '0'
  305. and u.dept_id in
  306. <foreach collection="array" item="deptId" open="(" separator="," close=")">
  307. #{deptId}
  308. </foreach>
  309. </select>
  310. <select id="selectAllocatedList" parameterType="com.zd.model.entity.SysUser" resultMap="SysUserResult">
  311. select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.user_type, u.email, u.phonenumber, u.status,
  312. u.create_time, d.`dept_name`,
  313. u.card_num,u.wechat_id,u.education,u.nationality,u.addr,u.work_status,u.date_birth
  314. from sys_user u
  315. left join sys_dept d on u.dept_id = d.dept_id
  316. left join sys_user_role ur on u.user_id = ur.user_id
  317. left join sys_role r on r.role_id = ur.role_id
  318. where u.del_flag = '0' and r.role_id = #{roleId}
  319. <if test="userName != null and userName != ''">
  320. AND u.user_name like concat('%', #{userName}, '%')
  321. </if>
  322. <if test="nickName != null and nickName != ''">
  323. AND u.nick_name like concat('%', #{nickName}, '%')
  324. </if>
  325. <if test="userType != null and userType != ''">
  326. AND u.user_type = #{userType}
  327. </if>
  328. <if test="phonenumber != null and phonenumber != ''">
  329. AND u.phonenumber like concat('%', #{phonenumber}, '%')
  330. </if>
  331. <if test="deptId != null and deptId != 0">
  332. AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId},
  333. ancestors) ))
  334. </if>
  335. <!-- 数据范围过滤 -->
  336. ${params.dataScope}
  337. </select>
  338. <select id="selectUnallocatedList" parameterType="com.zd.model.entity.SysUser" resultMap="SysUserResult">
  339. select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time,
  340. u.card_num,u.wechat_id,u.education,u.nationality,u.addr,u.work_status
  341. from sys_user u
  342. left join sys_dept d on u.dept_id = d.dept_id
  343. left join sys_user_role ur on u.user_id = ur.user_id
  344. left join sys_role r on r.role_id = ur.role_id
  345. where u.del_flag = '0' and (r.role_id != #{roleId} or r.role_id IS NULL)
  346. and u.user_id not in (select u.user_id from sys_user u inner join sys_user_role ur on u.user_id = ur.user_id and
  347. ur.role_id = #{roleId})
  348. <if test="userName != null and userName != ''">
  349. AND u.user_name like concat('%', #{userName}, '%')
  350. </if>
  351. <if test="nickName != null and nickName != ''">
  352. AND u.nick_name like concat('%', #{nickName}, '%')
  353. </if>
  354. <if test="userType != null and userType != ''">
  355. AND u.user_type = #{userType}
  356. </if>
  357. <if test="phonenumber != null and phonenumber != ''">
  358. AND u.phonenumber like concat('%', #{phonenumber}, '%')
  359. </if>
  360. <if test="deptId != null and deptId != 0">
  361. AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId},
  362. ancestors) ))
  363. </if>
  364. <!-- 数据范围过滤 -->
  365. ${params.dataScope}
  366. </select>
  367. <select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult">
  368. <include refid="selectUserNewVo"/>
  369. where (u.user_name = #{userName} or u.phonenumber=#{userName}) and u.del_flag = 0
  370. </select>
  371. <select id="selectUserCenterByUserName" parameterType="String" resultMap="SysUserResult">
  372. SELECT u.user_id,
  373. u.dept_id,
  374. u.user_name,
  375. u.nick_name,
  376. u.email,
  377. u.avatar,
  378. u.phonenumber,
  379. u.password,
  380. u.sex,
  381. u.status,
  382. u.del_flag,
  383. u.login_ip,
  384. u.login_date,
  385. u.create_by,
  386. u.create_time,
  387. u.remark,
  388. u.user_type,
  389. d.dept_id,
  390. d.parent_id,
  391. CASE
  392. WHEN u.user_type = '22' THEN d.dept_name
  393. ELSE concat(if((SELECT dt.dept_name FROM sys_dept dt WHERE dt.dept_id = d.parent_id) is null, '',
  394. (SELECT concat(dt.dept_name, '-') FROM sys_dept dt WHERE dt.dept_id = d.parent_id)),
  395. d.dept_name) end dept_name,
  396. d.order_num,
  397. d.leader,
  398. d.status AS dept_status,
  399. CASE WHEN u.user_type = '22' THEN sm.`major_name` else pt.`post_name` end major,
  400. u.grade,
  401. dd.`dict_label` category,
  402. u.tutor_user_id,
  403. u.position,
  404. u.nature,
  405. u.signature,
  406. u.card_num,
  407. u.wechat_id,
  408. case when u.user_type = '22' then ed.`dict_label` else dd.`dict_label` end education,
  409. u.nationality,
  410. u.addr,
  411. u.work_status,
  412. u.date_birth,
  413. ut.nick_name tutorUserName,
  414. u.is_check,
  415. uf.face_img,
  416. sc.class_name,
  417. u.major_id,
  418. u.signature,
  419. pt.`post_name` positionName
  420. FROM sys_user u
  421. LEFT JOIN sys_dept d ON u.dept_id = d.dept_id
  422. LEFT JOIN sys_user ut ON ut.user_id = u.tutor_user_id
  423. LEFT JOIN lab_students_info uf ON u.user_id = uf.join_students_id
  424. LEFT JOIN sys_class sc ON sc.id = u.grade
  425. LEFT JOIN sys_major sm ON sm.id = u.major_id
  426. LEFT JOIN sys_post pt ON pt.`post_id` = u.`position`
  427. LEFT JOIN sys_dict_data dd ON dd.`dict_value` = u.category AND dd.`dict_type` = 'professional'
  428. LEFT JOIN sys_dict_data ed ON ed.`dict_value` = u.education AND ed.`dict_type` = 'education'
  429. where u.user_name = #{userName}
  430. and u.del_flag = 0
  431. </select>
  432. <select id="selectUserByNickName" parameterType="String" resultMap="SysUserResult">
  433. <include refid="selectUserNewVo"/>
  434. where u.nick_name = #{nickName}
  435. </select>
  436. <select id="selectUserByCardNum" parameterType="String" resultMap="SysUserResult">
  437. <include refid="selectUserNewVo"/>
  438. where u.card_num_simple = #{cardNumSimple} and u.del_flag = 0
  439. </select>
  440. <select id="selectUserById" parameterType="Long" resultMap="SysUserResult">
  441. <include refid="selectUserNewVo"/>
  442. where u.user_id = #{userId}
  443. </select>
  444. <select id="checkUserNameUnique" parameterType="String" resultType="int">
  445. select count(1)
  446. from sys_user
  447. where user_name = #{userName}
  448. and del_flag = 0 limit 1
  449. </select>
  450. <select id="checkUserNameUniqueNotOwn" parameterType="com.zd.model.entity.SysUser" resultType="int">
  451. select count(1)
  452. from sys_user
  453. where user_name = #{userName}
  454. and del_flag = 0
  455. and user_id != #{userId} limit 1
  456. </select>
  457. <select id="checkCardUnique" parameterType="com.zd.model.entity.SysUser" resultType="int">
  458. select count(1)
  459. from sys_user
  460. where card_num = #{cardNum}
  461. and del_flag = 0 limit 1
  462. </select>
  463. <select id="checkCardSimpleUnique" parameterType="com.zd.model.entity.SysUser" resultType="int">
  464. select count(1)
  465. from sys_user
  466. where card_num_simple = #{cardNumSimple}
  467. and del_flag = 0
  468. and user_id != #{userId} limit 1
  469. </select>
  470. <select id="checkPhoneUnique" parameterType="String" resultMap="SysUserResult">
  471. select user_id, phonenumber
  472. from sys_user
  473. where phonenumber = #{phonenumber}
  474. and del_flag = 0 limit 1
  475. </select>
  476. <select id="checkPhoneUniqueNotOwn" parameterType="com.zd.model.entity.SysUser" resultMap="SysUserResult">
  477. select user_id, phonenumber
  478. from sys_user
  479. where phonenumber = #{phonenumber}
  480. and user_name != #{userName} limit 1
  481. </select>
  482. <select id="checkEmailUnique" parameterType="String" resultMap="SysUserResult">
  483. select user_id, email
  484. from sys_user
  485. where email = #{email} limit 1
  486. </select>
  487. <select id="selectOption" resultType="java.util.Map">
  488. select user_id userId, nick_name nickName,user_name userName from sys_user
  489. <where>
  490. <if test="userType != null and userType != ''">
  491. AND user_type = #{userType}
  492. </if>
  493. <if test="nickName != null and nickName != ''">
  494. AND nick_name like concat('%', #{nickName}, '%')
  495. </if>
  496. </where>
  497. </select>
  498. <select id="noJoinPositionByList" parameterType="com.zd.model.entity.SysUser" resultMap="SysUserResult">
  499. select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.password, u.sex,
  500. u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
  501. u.major, u.grade, u.category, u.tutor_user_id, u.position, u.nature,
  502. u.card_num,u.wechat_id,u.education,u.nationality,u.addr,u.work_status,u.date_birth,
  503. d.dept_name, d.leader,u.department,
  504. ut.nick_name tutorUserName,u.is_check
  505. from
  506. sys_user u
  507. left join sys_dept d on u.dept_id = d.dept_id
  508. left join sys_user ut on ut.user_id = u.tutor_user_id
  509. where u.del_flag = '0' AND (u.position = '未定' or u.position is null)
  510. <if test="userId != null ">
  511. AND u.user_id = #{userId}
  512. </if>
  513. <if test="userName != null and userName != ''">
  514. AND u.user_name like concat('%', #{userName}, '%')
  515. </if>
  516. <if test="nickName != null and nickName != ''">
  517. AND u.nick_name like concat('%', #{nickName}, '%')
  518. </if>
  519. <if test="cardNum != null and cardNum != ''">
  520. AND u.card_num = #{cardNum}
  521. </if>
  522. <if test="userType != null and userType != ''">
  523. AND u.user_type = #{userType}
  524. </if>
  525. <if test="status != null and status != ''">
  526. AND u.status = #{status}
  527. </if>
  528. <if test="phonenumber != null and phonenumber != ''">
  529. AND u.phonenumber like concat('%', #{phonenumber}, '%')
  530. </if>
  531. <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
  532. AND date_format(u.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
  533. </if>
  534. <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
  535. AND date_format(u.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
  536. </if>
  537. <if test="deptId != null and deptId != 0">
  538. AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId},
  539. ancestors) ))
  540. </if>
  541. <if test="ids!=null and ids.size > 0">
  542. AND u.user_id IN
  543. <foreach item="item" collection="ids" separator="," open="(" close=")" index="">'${item}'</foreach>
  544. </if>
  545. <if test="major != null and major != ''">
  546. AND u.major like concat('%', #{major}, '%')
  547. </if>
  548. <if test="grade != null and grade != ''">
  549. AND u.grade like concat('%', #{grade}, '%')
  550. </if>
  551. <if test="category != null and category != ''">
  552. AND u.category like concat('%', #{category}, '%')
  553. </if>
  554. <if test="tutorUserId != null">
  555. AND u.tutor_user_id = #{tutorUserId}
  556. </if>
  557. <if test="nature != null and nature != ''">
  558. AND u.nature = #{nature}
  559. </if>
  560. <if test="isCheck != null">
  561. AND u.is_check = #{isCheck}
  562. </if>
  563. <!-- 数据范围过滤 -->
  564. ${params.dataScope}
  565. </select>
  566. <insert id="insertUser" parameterType="com.zd.model.entity.SysUser" useGeneratedKeys="true"
  567. keyProperty="userId">
  568. insert into sys_user(
  569. <if test="userId != null and userId != 0">user_id,</if>
  570. <if test="deptId != null and deptId != 0">dept_id,</if>
  571. <if test="userName != null and userName != ''">user_name,</if>
  572. <if test="nickName != null and nickName != ''">nick_name,</if>
  573. <if test="email != null and email != ''">email,</if>
  574. <if test="avatar != null and avatar != ''">avatar,</if>
  575. <if test="phonenumber != null and phonenumber != ''">phonenumber,</if>
  576. <if test="sex != null and sex != ''">sex,</if>
  577. <if test="password != null and password != ''">password,</if>
  578. <if test="status != null and status != ''">status,</if>
  579. <if test="createBy != null and createBy != ''">create_by,</if>
  580. <if test="remark != null and remark != ''">remark,</if>
  581. <if test="userType != null and userType != ''">user_type,</if>
  582. <if test="major != null and major != ''">major,</if>
  583. <if test="grade != null and grade != ''">grade,</if>
  584. <if test="category != null and category != ''">category,</if>
  585. <if test="tutorUserId != null and tutorUserId != '' ">tutor_user_id,</if>
  586. <if test="majorId != null and majorId != ''">major_id,</if>
  587. <if test="position != null and position != ''">position,</if>
  588. <if test="department != null and department != ''">department,</if>
  589. <if test="nature != null and nature != ''">nature,</if>
  590. <if test="cardNum != null and cardNum != ''">card_num,</if>
  591. <if test="cardNumSimple != null and cardNumSimple != ''">card_num_simple,</if>
  592. <if test="education != null and education != ''">education,</if>
  593. <if test="nationality != null and nationality != ''">nationality,</if>
  594. <if test="addr != null and addr != ''">addr,</if>
  595. <if test="workStatus != null and workStatus != ''">work_status,</if>
  596. <if test="dateBirth != null">date_birth,</if>
  597. <if test="isCheck != null and isCheck != ''">is_check,</if>
  598. create_time
  599. )values(
  600. <if test="userId != null and userId != ''">#{userId},</if>
  601. <if test="deptId != null and deptId != ''">#{deptId},</if>
  602. <if test="userName != null and userName != ''">#{userName},</if>
  603. <if test="nickName != null and nickName != ''">#{nickName},</if>
  604. <if test="email != null and email != ''">#{email},</if>
  605. <if test="avatar != null and avatar != ''">#{avatar},</if>
  606. <if test="phonenumber != null and phonenumber != ''">#{phonenumber},</if>
  607. <if test="sex != null and sex != ''">#{sex},</if>
  608. <if test="password != null and password != ''">#{password},</if>
  609. <if test="status != null and status != ''">#{status},</if>
  610. <if test="createBy != null and createBy != ''">#{createBy},</if>
  611. <if test="remark != null and remark != ''">#{remark},</if>
  612. <if test="userType != null and userType != ''">#{userType},</if>
  613. <if test="major != null and major != ''">#{major},</if>
  614. <if test="grade != null and grade != ''">#{grade},</if>
  615. <if test="category != null and category != ''">#{category},</if>
  616. <if test="tutorUserId != null and tutorUserId != ''">#{tutorUserId},</if>
  617. <if test="majorId != null and majorId != ''">#{majorId},</if>
  618. <if test="position != null and position != '' ">#{position},</if>
  619. <if test="department != null and department != ''">#{department},</if>
  620. <if test="nature != null and nature != ''">#{nature},</if>
  621. <if test="cardNum != null and cardNum != ''">#{cardNum},</if>
  622. <if test="cardNumSimple != null and cardNumSimple != ''">#{cardNumSimple},</if>
  623. <if test="education != null and education != ''">#{education},</if>
  624. <if test="nationality != null and nationality != ''">#{nationality},</if>
  625. <if test="addr != null and addr != ''">#{addr},</if>
  626. <if test="workStatus != null and workStatus != ''">#{workStatus},</if>
  627. <if test="dateBirth != null">#{dateBirth},</if>
  628. <if test="isCheck != null and isCheck != ''">#{isCheck},</if>
  629. sysdate()
  630. )
  631. </insert>
  632. <update id="updateUser" parameterType="com.zd.model.entity.SysUser">
  633. update sys_user
  634. <set>
  635. <if test="deptId != null and deptId != 0">dept_id = #{deptId},</if>
  636. <if test="userName != null and userName != ''">user_name = #{userName},</if>
  637. <if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
  638. <if test="email != null ">email = #{email},</if>
  639. <if test="phonenumber != null ">phonenumber = #{phonenumber},</if>
  640. <if test="sex != null and sex != ''">sex = #{sex},</if>
  641. <if test="avatar != null and avatar != ''">avatar = #{avatar},</if>
  642. <if test="password != null and password != ''">password = #{password},</if>
  643. <if test="status != null and status != ''">status = #{status},</if>
  644. <if test="loginIp != null and loginIp != ''">login_ip = #{loginIp},</if>
  645. <if test="loginDate != null">login_date = #{loginDate},</if>
  646. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  647. <if test="remark != null and remark != ''">remark = #{remark},</if>
  648. <if test="userType != null and userType !=''">user_type = #{userType},</if>
  649. <if test="major != null and major != ''">major = #{major},</if>
  650. <if test="majorId != null">major_id = #{majorId},</if>
  651. <if test="grade != null and grade!=''">grade = #{grade},</if>
  652. <if test="category != null and category !=''">category = #{category},</if>
  653. <if test="tutorUserId != null ">tutor_user_id = #{tutorUserId},</if>
  654. <if test="position != null ">position = #{position},</if>
  655. <if test="department != null ">department = #{department},</if>
  656. <if test="nature != null and nature!=''">nature = #{nature},</if>
  657. <if test="cardNum != null and cardNum!=''">card_num = #{cardNum},</if>
  658. <if test="cardNumSimple != null and cardNumSimple!=''">card_num_simple = #{cardNumSimple},</if>
  659. <if test="education != null and education!=''">education = #{education},</if>
  660. <if test="nationality != null and nationality!=''">nationality = #{nationality},</if>
  661. <if test="addr != null and addr != ''">addr = #{addr},</if>
  662. <if test="workStatus != null and workStatus != ''">work_status = #{workStatus},</if>
  663. <if test="dateBirth != null">date_birth = #{dateBirth},</if>
  664. <if test="isCheck != null ">is_check = #{isCheck},</if>
  665. <if test="signature != null and signature != ''">signature = #{signature},</if>
  666. update_time = sysdate()
  667. </set>
  668. where user_id = #{userId}
  669. </update>
  670. <update id="updateTeacherUser" parameterType="com.zd.model.entity.SysUser">
  671. update sys_user
  672. <set>
  673. <if test="deptId != null and deptId != 0">dept_id = #{deptId},</if>
  674. <if test="userName != null and userName != ''">user_name = #{userName},</if>
  675. <if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
  676. <if test="email != null and email != ''">email = #{email},</if>
  677. <if test="phonenumber != null ">phonenumber = #{phonenumber},</if>
  678. <if test="sex != null and sex != ''">sex = #{sex},</if>
  679. <if test="avatar != null and avatar != ''">avatar = #{avatar},</if>
  680. <if test="password != null and password != ''">password = #{password},</if>
  681. <if test="status != null and status != ''">status = #{status},</if>
  682. <if test="loginIp != null and loginIp != ''">login_ip = #{loginIp},</if>
  683. <if test="loginDate != null">login_date = #{loginDate},</if>
  684. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  685. <if test="remark != null and remark != ''">remark = #{remark},</if>
  686. <if test="userType != null and userType !=''">user_type = #{userType},</if>
  687. <if test="major != null and major != ''">major = #{major},</if>
  688. <if test="majorId != null">major_id = #{majorId},</if>
  689. <if test="grade != null and grade!=''">grade = #{grade},</if>
  690. <if test="category != null and category !=''">category = #{category},</if>
  691. <if test="tutorUserId != null ">tutor_user_id = #{tutorUserId},</if>
  692. <if test="position != null ">position = #{position},</if>
  693. <if test="department != null ">department = #{department},</if>
  694. <if test="nature != null and nature!=''">nature = #{nature},</if>
  695. card_num = #{cardNum},
  696. card_num_simple = #{cardNumSimple},
  697. <if test="education != null and education!=''">education = #{education},</if>
  698. <if test="nationality != null and nationality!=''">nationality = #{nationality},</if>
  699. <if test="addr != null and addr != ''">addr = #{addr},</if>
  700. <if test="workStatus != null and workStatus != ''">work_status = #{workStatus},</if>
  701. <if test="dateBirth != null">date_birth = #{dateBirth},</if>
  702. <if test="isCheck != null ">is_check = #{isCheck},</if>
  703. <if test="signature != null and signature != ''">signature = #{signature},</if>
  704. update_time = sysdate()
  705. </set>
  706. where user_id = #{userId}
  707. </update>
  708. <update id="updateStudentUser" parameterType="com.zd.model.entity.SysUser">
  709. update sys_user
  710. <set>
  711. <if test="deptId != null and deptId != 0">dept_id = #{deptId},</if>
  712. <if test="userName != null and userName != ''">user_name = #{userName},</if>
  713. <if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
  714. <if test="email != null and email != ''">email = #{email},</if>
  715. <if test="phonenumber != null ">phonenumber = #{phonenumber},</if>
  716. <if test="sex != null and sex != ''">sex = #{sex},</if>
  717. <if test="avatar != null and avatar != ''">avatar = #{avatar},</if>
  718. <if test="password != null and password != ''">password = #{password},</if>
  719. <if test="status != null and status != ''">status = #{status},</if>
  720. <if test="loginIp != null and loginIp != ''">login_ip = #{loginIp},</if>
  721. <if test="loginDate != null">login_date = #{loginDate},</if>
  722. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  723. <if test="remark != null and remark != ''">remark = #{remark},</if>
  724. <if test="userType != null and userType !=''">user_type = #{userType},</if>
  725. <if test="major != null and major != ''">major = #{major},</if>
  726. <if test="majorId != null">major_id = #{majorId},</if>
  727. <if test="grade != null and grade!=''">grade = #{grade},</if>
  728. <if test="category != null and category !=''">category = #{category},</if>
  729. <if test="tutorUserId != null ">tutor_user_id = #{tutorUserId},</if>
  730. <if test="position != null ">position = #{position},</if>
  731. <if test="department != null ">department = #{department},</if>
  732. <if test="nature != null and nature!=''">nature = #{nature},</if>
  733. card_num = #{cardNum},
  734. card_num_simple = #{cardNumSimple},
  735. <if test="education != null and education!=''">education = #{education},</if>
  736. <if test="nationality != null and nationality!=''">nationality = #{nationality},</if>
  737. <if test="addr != null and addr != ''">addr = #{addr},</if>
  738. <if test="workStatus != null and workStatus != ''">work_status = #{workStatus},</if>
  739. <if test="dateBirth != null">date_birth = #{dateBirth},</if>
  740. <if test="isCheck != null ">is_check = #{isCheck},</if>
  741. <if test="signature != null and signature != ''">signature = #{signature},</if>
  742. update_time = sysdate()
  743. </set>
  744. where user_id = #{userId}
  745. </update>
  746. <update id="relieveUserByPosition" parameterType="com.zd.model.entity.SysUser">
  747. update sys_user
  748. set position = '未定'
  749. where user_id = #{userId}
  750. </update>
  751. <update id="updateUserAvatar" parameterType="com.zd.model.entity.SysUser">
  752. update sys_user
  753. set avatar = #{avatar}
  754. where user_name = #{userName}
  755. </update>
  756. <update id="resetUserPwd" parameterType="com.zd.model.entity.SysUser">
  757. update sys_user
  758. set password = #{password}
  759. where user_name = #{userName}
  760. </update>
  761. <delete id="deleteUserById" parameterType="Long">
  762. update sys_user
  763. set del_flag = '2'
  764. where user_id = #{userId}
  765. </delete>
  766. <delete id="deleteUserByIds" parameterType="Long">
  767. update sys_user set del_flag = '2' where user_id in
  768. <foreach collection="array" item="userId" open="(" separator="," close=")">
  769. #{userId}
  770. </foreach>
  771. </delete>
  772. <select id="queryPhoneByIds" resultType="string">
  773. select phonenumber from sys_user
  774. where user_id in
  775. <foreach collection="array" item="id" open="(" separator="," close=")">
  776. #{id}
  777. </foreach>
  778. and length(phonenumber)=11
  779. </select>
  780. <select id="queryCardNumByIds" resultType="com.zd.model.entity.SysUser">
  781. select * from sys_user
  782. where card_num_simple in
  783. <foreach collection="array" item="cardNums" open="(" separator="," close=")">
  784. #{cardNums}
  785. </foreach>
  786. </select>
  787. <select id="queryCountByDeptIds" resultType="com.zd.model.entity.TotalByID">
  788. select dept_id as id, count(dept_id ) as total from sys_user
  789. where dept_id in
  790. <foreach collection="array" item="deptId" open="(" separator="," close=")">
  791. #{deptId}
  792. </foreach>
  793. group by dept_id
  794. </select>
  795. <select id="selectUserListByName" parameterType="com.zd.model.entity.SysUser" resultMap="SysUserResult">
  796. select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.password, u.sex,
  797. u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
  798. u.major, u.grade, u.category, u.tutor_user_id, u.position, u.nature,
  799. u.card_num,u.wechat_id,u.education,u.nationality,u.addr,u.work_status,u.date_birth,
  800. d.dept_name, d.leader,u.department,u.is_check
  801. from
  802. sys_user u
  803. left join sys_dept d on u.dept_id = d.dept_id
  804. where u.del_flag = '0'
  805. <if test="userId != null ">
  806. AND u.user_id = #{userId}
  807. </if>
  808. <if test="userName != null and userName != ''">
  809. AND u.user_name like concat('%', #{userName}, '%')
  810. </if>
  811. <if test="nickName != null and nickName != ''">
  812. AND u.nick_name like concat('%', #{nickName}, '%')
  813. </if>
  814. <if test="userType != null and userType != ''">
  815. AND u.user_type = #{userType}
  816. </if>
  817. <if test="status != null and status != ''">
  818. AND u.status = #{status}
  819. </if>
  820. <if test="phonenumber != null and phonenumber != ''">
  821. AND u.phonenumber like concat('%', #{phonenumber}, '%')
  822. </if>
  823. <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
  824. AND date_format(u.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
  825. </if>
  826. <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
  827. AND date_format(u.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
  828. </if>
  829. <if test="ids!=null and ids.size > 0">
  830. AND u.user_id IN
  831. <foreach item="item" collection="ids" separator="," open="(" close=")" index="">'${item}'</foreach>
  832. </if>
  833. <if test="major != null and major != ''">
  834. AND u.major like concat('%', #{major}, '%')
  835. </if>
  836. <if test="grade != null and grade != ''">
  837. AND u.grade like concat('%', #{grade}, '%')
  838. </if>
  839. <if test="category != null and category != ''">
  840. AND u.category like concat('%', #{category}, '%')
  841. </if>
  842. <if test="tutorUserId != null">
  843. AND u.tutor_user_id = #{tutorUserId}
  844. </if>
  845. <if test="nature != null and nature != ''">
  846. AND u.nature = #{nature}
  847. </if>
  848. <if test="position != null and position != ''">
  849. AND u.position = #{position}
  850. </if>
  851. <if test="isCheck != null">
  852. AND u.is_check = #{isCheck}
  853. </if>
  854. </select>
  855. <select id="selectUserListByNotWhite" parameterType="com.zd.model.entity.SysUser" resultMap="SysUserResult">
  856. select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.password, u.sex,
  857. u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
  858. u.major, u.grade, u.category, u.tutor_user_id, u.position, u.nature,
  859. u.card_num,u.wechat_id,u.education,u.nationality,u.addr,u.work_status,u.date_birth,
  860. d.dept_name, d.leader,u.department,u.is_check
  861. from
  862. sys_user u
  863. left join sys_dept d on u.dept_id = d.dept_id
  864. where u.del_flag = '0'
  865. and u.`user_id` not in (select w.`user_id` from lab_whitelist w)
  866. <if test="userId != null ">
  867. AND u.user_id = #{userId}
  868. </if>
  869. <if test="userName != null and userName != ''">
  870. AND u.user_name like concat('%', #{userName}, '%')
  871. </if>
  872. <if test="nickName != null and nickName != ''">
  873. AND u.nick_name like concat('%', #{nickName}, '%')
  874. </if>
  875. <if test="userType != null and userType != ''">
  876. AND u.user_type = #{userType}
  877. </if>
  878. <if test="status != null and status != ''">
  879. AND u.status = #{status}
  880. </if>
  881. <if test="phonenumber != null and phonenumber != ''">
  882. AND u.phonenumber like concat('%', #{phonenumber}, '%')
  883. </if>
  884. <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
  885. AND date_format(u.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
  886. </if>
  887. <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
  888. AND date_format(u.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
  889. </if>
  890. <if test="ids!=null and ids.size > 0">
  891. AND u.user_id IN
  892. <foreach item="item" collection="ids" separator="," open="(" close=")" index="">'${item}'</foreach>
  893. </if>
  894. <if test="deptIds !=null and deptIds.size >0">
  895. AND u.dept_id IN
  896. <foreach item="item" collection="deptIds" separator="," open="(" close=")" index="">'${item}'</foreach>
  897. </if>
  898. <if test="major != null and major != ''">
  899. AND u.major like concat('%', #{major}, '%')
  900. </if>
  901. <if test="grade != null and grade != ''">
  902. AND u.grade like concat('%', #{grade}, '%')
  903. </if>
  904. <if test="category != null and category != ''">
  905. AND u.category like concat('%', #{category}, '%')
  906. </if>
  907. <if test="tutorUserId != null">
  908. AND u.tutor_user_id = #{tutorUserId}
  909. </if>
  910. <if test="nature != null and nature != ''">
  911. AND u.nature = #{nature}
  912. </if>
  913. <if test="position != null and position != ''">
  914. AND u.position = #{position}
  915. </if>
  916. <if test="isCheck != null">
  917. AND u.is_check = #{isCheck}
  918. </if>
  919. </select>
  920. <select id="selectUserInfoByCardNum" resultType="com.zd.model.entity.SysUser">
  921. SELECT user_id, nick_name, card_num, card_num_simple
  922. FROM sys_user u
  923. WHERE u.card_num_simple = #{cardNumSimple}
  924. and u.user_id != #{userId}
  925. </select>
  926. <select id="getSafeUserList" parameterType="com.zd.model.entity.SysUser" resultMap="SysUserResult">
  927. select u.user_id, u.nick_name
  928. from
  929. sys_user u
  930. where u.del_flag = '0'
  931. <if test="safeUserId != null">
  932. AND FIND_IN_SET(u.user_id, #{safeUserId})
  933. </if>
  934. </select>
  935. <select id="oldCheckNewCard" resultMap="SysUserResult">
  936. select u.user_id,
  937. u.dept_id,
  938. u.nick_name,
  939. u.user_name,
  940. u.email,
  941. u.avatar,
  942. u.phonenumber,
  943. u.password,
  944. u.sex,
  945. u.status,
  946. u.del_flag,
  947. u.login_ip,
  948. u.login_date,
  949. u.create_by,
  950. u.create_time,
  951. u.remark,
  952. u.major_id,
  953. u.grade,
  954. u.tutor_user_id,
  955. u.position,
  956. p.post_name as positionName,
  957. u.nature,
  958. (select sc.class_name from sys_class sc where sc.id = u.grade) gradeName,
  959. u.card_num,
  960. u.wechat_id,
  961. u.nationality,
  962. u.addr,
  963. u.work_status,
  964. u.date_birth,
  965. d.dept_name,
  966. d.leader,
  967. u.department,
  968. u.education,
  969. u.user_type,
  970. sm.`major_name` major,
  971. ut.nick_name tutorUserName,
  972. u.is_check,
  973. date_format(u.create_time, '%Y-%m-%d') createTimeStr
  974. from sys_user u
  975. left join sys_dept d on u.dept_id = d.dept_id
  976. left join sys_user ut on ut.user_id = u.tutor_user_id
  977. left join sys_post p on u.position = p.post_id
  978. LEFT JOIN sys_major sm ON sm.id = u.major_id
  979. where u.del_flag = '0'
  980. AND u.card_num IS NOT NULL
  981. AND u.`card_num_simple` IS NULL
  982. </select>
  983. <!--值班人员列表-->
  984. <select id="selectUserDutyList" parameterType="com.zd.model.entity.SysUser" resultMap="SysUserResult">
  985. select u.user_id, u.dept_id,d.dept_name, u.user_name, u.nick_name, u.avatar, u.phonenumber, u.sex,
  986. u.status, u.del_flag,u.user_type
  987. from
  988. (
  989. select w.user_id from lab_whitelist w LEFT JOIN lab_white_join_sublist j on w.user_id = j.white_user_id
  990. <if test="deptId != null and deptId != 0">
  991. AND (w.dept_id = #{deptId} OR w.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId},
  992. ancestors) ))
  993. </if>
  994. <if test="subjectIds!=null and subjectIds.size > 0">
  995. where j.subject_id in
  996. <foreach item="item" collection="subjectIds" open="(" separator="," close=")">
  997. #{item}
  998. </foreach>
  999. </if>
  1000. GROUP BY w.user_id
  1001. union all
  1002. select a.user_id from lab_security_apply a
  1003. where audit_status=2
  1004. and date_format(a.valid_end_time,'%Y-%m-%d') &gt;= date_format(NOW(),'%Y-%m-%d')
  1005. <if test="subjectIds!=null and subjectIds.size > 0">
  1006. and a.subject_id in
  1007. <foreach item="item" collection="subjectIds" open="(" separator="," close=")">
  1008. #{item}
  1009. </foreach>
  1010. <if test="dateList!=null and dateList.size > 0">
  1011. <foreach item="item" collection="dateList">
  1012. and date_format(a.valid_end_time,'%Y-%m-%d') &gt;=date_format(#{item},'%Y-%m-%d')
  1013. </foreach>
  1014. </if>
  1015. </if>
  1016. ) t
  1017. LEFT JOIN sys_user u on t.user_id=u.user_id
  1018. LEFT JOIN sys_dept d on d.dept_id = u.dept_id
  1019. <where>
  1020. <if test="deptId != null and deptId != 0">
  1021. AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId},
  1022. ancestors) ))
  1023. </if>
  1024. <if test="nickName != null and nickName != ''">
  1025. AND u.nick_name like concat('%', #{nickName}, '%')
  1026. </if>
  1027. <if test="userType != null and userType != ''">
  1028. AND u.user_type = #{userType}
  1029. </if>
  1030. </where>
  1031. <!-- 数据范围过滤 -->
  1032. ${params.dataScope}
  1033. </select>
  1034. <!--值班人员列表,多个实验室时使用-->
  1035. <select id="selectUserDutyListMultiple" parameterType="com.zd.model.entity.SysUser" resultMap="SysUserResult">
  1036. select u.user_id, u.dept_id,d.dept_name, u.user_name, u.nick_name, u.avatar, u.phonenumber, u.sex,
  1037. u.status, u.del_flag,u.user_type, count
  1038. from
  1039. (
  1040. select w.user_id,j.subject_id,count(1) count from lab_whitelist w LEFT JOIN lab_white_join_sublist j on w.user_id = j.white_user_id
  1041. <if test="deptId != null and deptId != 0">
  1042. AND (w.dept_id = #{deptId} OR w.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId},
  1043. ancestors) ))
  1044. </if>
  1045. <if test="subjectIds!=null and subjectIds.size > 0">
  1046. where j.subject_id in
  1047. <foreach item="item" collection="subjectIds" open="(" separator="," close=")">
  1048. #{item}
  1049. </foreach>
  1050. </if>
  1051. GROUP BY w.user_id
  1052. union all
  1053. select a.user_id,a.subject_id,count(1) count from lab_security_apply a
  1054. where audit_status=2
  1055. and date_format(a.valid_end_time,'%Y-%m-%d') &gt;= date_format(NOW(),'%Y-%m-%d')
  1056. <if test="dateList!=null and dateList.size > 0">
  1057. <foreach item="item" collection="dateList">
  1058. and date_format(a.valid_end_time,'%Y-%m-%d') &gt;=date_format(#{item},'%Y-%m-%d')
  1059. </foreach>
  1060. </if>
  1061. <if test="subjectIds!=null and subjectIds.size > 0">
  1062. and a.subject_id in
  1063. <foreach item="item" collection="subjectIds" open="(" separator="," close=")">
  1064. #{item}
  1065. </foreach>
  1066. </if>
  1067. GROUP BY a.user_id
  1068. ) t
  1069. LEFT JOIN sys_user u on t.user_id=u.user_id
  1070. LEFT JOIN sys_dept d on d.dept_id = u.dept_id
  1071. <where>
  1072. <if test="deptId != null and deptId != 0">
  1073. AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId},
  1074. ancestors) ))
  1075. </if>
  1076. <if test="nickName != null and nickName != ''">
  1077. AND u.nick_name like concat('%', #{nickName}, '%')
  1078. </if>
  1079. <if test="userType != null and userType != ''">
  1080. AND u.user_type = #{userType}
  1081. </if>
  1082. and count >= #{majorId}
  1083. </where>
  1084. <!-- 数据范围过滤 -->
  1085. ${params.dataScope}
  1086. </select>
  1087. <select id="selectUserByUserId" resultType="java.util.Map">
  1088. SELECT user_type userType,nick_name userName,user_id userId,avatar,dept_id deptId,(SELECT dept_name FROM sys_dept sd WHERE sd.dept_id=su.dept_id) deptName FROM `sys_user` su WHERE del_flag=0 AND user_id=#{userId}
  1089. </select>
  1090. <select id="getUserByIdentityType" resultType="com.zd.system.domain.vo.SysUserVo">
  1091. <if test="subAdmin != null and subAdmin != ''">
  1092. SELECT s.id subId,s.`name` subName,s.`room` subRomm,d.`dept_id` deptId,d.`dept_name` deptName,u.`user_id` userId,u.`nick_name` nickName,1 attriType FROM lab_subject s
  1093. INNER JOIN sys_user u ON s.`admin_id` = u.`user_id` INNER JOIN sys_dept d ON s.`dept_id` = d.`dept_id`
  1094. WHERE u.del_flag=0 AND s.is_del=0
  1095. <if test="(subSafe != null and subSafe != '') or (subWhite != null and subWhite != '')">
  1096. UNION
  1097. </if>
  1098. </if>
  1099. <if test="subSafe != null and subSafe != ''">
  1100. SELECT s.id subId,s.`name` subName,s.`room` subRomm,d.`dept_id` deptId,d.`dept_name` deptName,u.`user_id` userId,u.`nick_name` nickName,2 attriType FROM lab_subject s INNER JOIN sys_user u ON u.`user_id`
  1101. IN (
  1102. SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(s.safe_user_id, ',', b.help_topic_id + 1), ',',
  1103. -1) result
  1104. FROM mysql.help_topic b
  1105. WHERE b.help_topic_id &lt;
  1106. (LENGTH(s.safe_user_id) - LENGTH(REPLACE(s.safe_user_id, ',', '')) + 1)
  1107. )
  1108. INNER JOIN sys_dept d ON s.`dept_id` = d.`dept_id`
  1109. WHERE u.del_flag=0 AND s.is_del=0
  1110. <if test="(subWhite != null and subWhite != '')">
  1111. UNION
  1112. </if>
  1113. </if>
  1114. <if test="subWhite != null and subWhite != ''">
  1115. SELECT s.id subId,s.`name` subName,s.`room` subRomm,d.`dept_id` deptId,d.`dept_name` deptName,u.`user_id` userId,u.`nick_name` nickName,3 attriType FROM lab_subject s INNER JOIN lab_white_join_sublist js ON s.`id` = js.subject_id
  1116. INNER JOIN sys_user u ON js.white_user_id = u.`user_id` INNER JOIN sys_dept d ON s.`dept_id` = d.`dept_id`
  1117. WHERE u.del_flag=0 AND s.is_del=0
  1118. </if>
  1119. </select>
  1120. <select id="findUserList" resultType="com.zd.system.api.vo.CheckUserVo">
  1121. SELECT
  1122. su.user_name,
  1123. su.nick_name,
  1124. su.user_type,
  1125. su.user_id,
  1126. su.dept_id,
  1127. sd.dept_name
  1128. FROM
  1129. `sys_user` su
  1130. LEFT JOIN sys_dept sd ON su.dept_id = sd.dept_id
  1131. <where>
  1132. su.user_type = "11" and su.del_flag = 0
  1133. <if test="sysUserPageDto.deptId != null and sysUserPageDto.deptId != 0">
  1134. and ( su.dept_id in (SELECT dt.dept_id FROM sys_dept dt WHERE find_in_set(#{sysUserPageDto.deptId}
  1135. ,ancestors )) or su.dept_id = #{sysUserPageDto.deptId} )
  1136. </if>
  1137. <if test="sysUserPageDto.userIds != null and sysUserPageDto.userIds.length != 0">
  1138. <foreach collection="sysUserPageDto.userIds" item="id" open=" and su.user_id in(" separator="," close=")">
  1139. #{id}
  1140. </foreach>
  1141. </if>
  1142. <if test="(sysUserPageDto.userIds == null or sysUserPageDto.userIds.length == 0) and sysUserPageDto.filtType == 2">
  1143. and su.user_id = -999999
  1144. </if>
  1145. <if test="sysUserPageDto.selectedUserIds != null and sysUserPageDto.selectedUserIds.length != 0">
  1146. <foreach collection="sysUserPageDto.selectedUserIds" item="id" open=" and su.user_id not in(" separator="," close=")">
  1147. #{id}
  1148. </foreach>
  1149. </if>
  1150. <if test="sysUserPageDto.searchValue != null and sysUserPageDto.searchValue != ''">
  1151. and (su.nick_name like concat('%',#{sysUserPageDto.searchValue},'%') or su.user_name like concat('%',#{sysUserPageDto.searchValue},'%'))
  1152. </if>
  1153. </where>
  1154. </select>
  1155. <select id="selectUserListByBatch" parameterType="com.zd.model.entity.SysUser" resultMap="SysUserResult">
  1156. select user_id, dept_id, nick_name, user_name, email, avatar, phonenumber, sex,
  1157. status, del_flag, create_by, create_time, remark
  1158. from sys_user
  1159. <where>
  1160. <if test="userId != null ">
  1161. AND user_id = #{userId}
  1162. </if>
  1163. <if test="deptId != null ">
  1164. AND dept_id = #{deptId}
  1165. </if>
  1166. <if test="userName != null and userName != ''">
  1167. AND u.user_name like concat('%', #{userName}, '%')
  1168. </if>
  1169. <if test="nickName != null and nickName != ''">
  1170. AND u.nick_name like concat('%', #{nickName}, '%')
  1171. </if>
  1172. <if test="cardNum != null and cardNum != ''">
  1173. AND u.card_num = #{cardNum}
  1174. </if>
  1175. <if test="delFlag != null ">
  1176. AND del_flag = #{delFlag}
  1177. </if>
  1178. <if test="status != null ">
  1179. AND status = #{status}
  1180. </if>
  1181. <if test="deptIds != null and deptIds.size > 0">
  1182. <foreach collection="deptIds" item="item" open="AND dept_id IN(" separator="," close=")">
  1183. #{item}
  1184. </foreach>
  1185. </if>
  1186. </where>
  1187. </select>
  1188. </mapper>