SysUserMapper.xml 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  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="wechatId" column="wechat_id"/>
  38. <result property="education" column="education"/>
  39. <result property="nationality" column="nationality"/>
  40. <result property="addr" column="addr"/>
  41. <result property="workStatus" column="work_status"/>
  42. <result property="dateBirth" column="date_birth"/>
  43. <result property="department" column="department"/>
  44. <result property="majorId" column="major_id"/>
  45. <result property="isCheck" column="is_check"/>
  46. <result property="signature" column="signature"/>
  47. <result property="faceImg" column="face_img"/>
  48. <result property="className" column="class_name"/>
  49. <result property="createTimeStr" column="createTimeStr"/>
  50. <association property="dept" column="dept_id" javaType="com.zd.model.entity.SysDept"
  51. resultMap="deptResult"/>
  52. <!--<collection property="roles" javaType="java.util.List" resultMap="RoleResult"/>-->
  53. </resultMap>
  54. <resultMap id="deptResult" type="com.zd.model.entity.SysDept">
  55. <id property="deptId" column="dept_id"/>
  56. <result property="parentId" column="parent_id"/>
  57. <result property="deptName" column="dept_name"/>
  58. <result property="orderNum" column="order_num"/>
  59. <result property="leader" column="leader"/>
  60. <result property="status" column="dept_status"/>
  61. </resultMap>
  62. <resultMap id="RoleResult" type="com.zd.model.entity.SysRole">
  63. <id property="roleId" column="role_id"/>
  64. <result property="roleName" column="role_name"/>
  65. <result property="roleKey" column="role_key"/>
  66. <result property="roleSort" column="role_sort"/>
  67. <result property="dataScope" column="data_scope"/>
  68. <result property="status" column="role_status"/>
  69. </resultMap>
  70. <!--2.6弃用-->
  71. <sql id="selectUserVo">
  72. select u.user_id, 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,u.user_type,
  73. d.dept_id, d.parent_id, d.dept_name, d.order_num, d.leader, d.status as dept_status,
  74. r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status,
  75. u.major,u.major_id, u.grade, u.category, u.tutor_user_id, u.position, u.nature, u.signature,
  76. u.card_num,u.wechat_id,u.education,u.nationality,u.addr,u.work_status,u.date_birth,
  77. ut.nick_name tutorUserName,u.is_check
  78. from sys_user u
  79. left join sys_dept d on u.dept_id = d.dept_id
  80. left join sys_user_role ur on u.user_id = ur.user_id
  81. left join sys_role r on r.role_id = ur.role_id
  82. left join sys_user ut on ut.user_id = u.tutor_user_id
  83. </sql>
  84. <sql id="selectUserNewVo">
  85. select u.user_id, 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,u.user_type,
  86. d.dept_id, d.parent_id, d.dept_name, d.order_num, d.leader, d.status as dept_status,
  87. sm.`major_name` major, u.grade, u.category, u.tutor_user_id, u.position, u.nature, u.signature,
  88. u.card_num,u.wechat_id,u.education,u.nationality,u.addr,u.work_status,u.date_birth,
  89. ut.nick_name tutorUserName,u.is_check,
  90. uf.face_img,sc.class_name,u.major_id,u.signature,pt.`post_name` positionName
  91. from sys_user u
  92. left join sys_dept d on u.dept_id = d.dept_id
  93. left join sys_user ut on ut.user_id = u.tutor_user_id
  94. left join lab_students_info uf on u.user_id = uf.join_students_id
  95. LEFT JOIN sys_class sc ON sc.id = u.grade
  96. LEFT JOIN sys_major sm ON sm.id = u.major_id
  97. left join sys_post pt on pt.`post_id` = u.`position`
  98. </sql>
  99. <select id="selectUserList" parameterType="com.zd.model.entity.SysUser" resultMap="SysUserResult">
  100. select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.password, u.sex,
  101. u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
  102. u.major_id, u.grade, u.tutor_user_id, u.position, p.post_name as positionName,
  103. u.nature,(select sc.class_name from sys_class sc where sc.id = u.grade) gradeName,
  104. u.card_num,u.wechat_id,u.nationality,u.addr,u.work_status,
  105. u.date_birth,d.dept_name, d.leader,u.department,
  106. u.education, u.user_type,sm.`major_name` major,
  107. ut.nick_name tutorUserName,u.is_check,date_format(u.create_time, '%Y-%m-%d') createTimeStr
  108. from
  109. sys_user u
  110. left join sys_dept d on u.dept_id = d.dept_id
  111. left join sys_user ut on ut.user_id = u.tutor_user_id
  112. left join sys_post p on u.position = p.post_id
  113. LEFT JOIN sys_major sm ON sm.id = u.major_id
  114. where u.del_flag = '0'
  115. <if test="userId != null ">
  116. AND u.user_id = #{userId}
  117. </if>
  118. <if test="paramIds != null and paramIds != ''">
  119. AND find_in_set(u.user_id, #{paramIds})
  120. </if>
  121. <if test="userName != null and userName != ''">
  122. AND u.user_name like concat('%', #{userName}, '%')
  123. </if>
  124. <if test="nickName != null and nickName != ''">
  125. AND u.nick_name like concat('%', #{nickName}, '%')
  126. </if>
  127. <if test="cardNum != null and cardNum != ''">
  128. AND u.card_num = #{cardNum}
  129. </if>
  130. <if test="userType != null and userType != ''">
  131. AND u.user_type = #{userType}
  132. </if>
  133. <if test="userType == null or userType == ''">
  134. AND u.user_type != '00' AND u.user_type != '33'
  135. </if>
  136. <if test="status != null and status != ''">
  137. AND u.status = #{status}
  138. </if>
  139. <if test="phonenumber != null and phonenumber != ''">
  140. AND u.phonenumber like concat('%', #{phonenumber}, '%')
  141. </if>
  142. <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
  143. AND date_format(u.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
  144. </if>
  145. <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
  146. AND date_format(u.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
  147. </if>
  148. <if test="deptId != null and deptId != 0">
  149. AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId},
  150. ancestors) ))
  151. </if>
  152. <if test="ids!=null and ids.size > 0">
  153. <choose>
  154. <when test="include">
  155. AND u.user_id not IN
  156. </when>
  157. <otherwise>
  158. AND u.user_id IN
  159. </otherwise>
  160. </choose>
  161. <foreach item="item" collection="ids" separator="," open="(" close=")" index="">'${item}'</foreach>
  162. </if>
  163. <if test="major != null and major != ''">
  164. AND u.major like concat('%', #{major}, '%')
  165. </if>
  166. <if test="majorId != null and majorId != ''">
  167. AND u.major_id = #{majorId}
  168. </if>
  169. <if test="searchValue != null and searchValue != ''">
  170. AND
  171. (
  172. u.nick_name like concat('%', #{searchValue}, '%')
  173. or
  174. u.user_name like concat('%', #{searchValue}, '%')
  175. or
  176. u.phonenumber like concat('%', #{searchValue}, '%')
  177. or
  178. ut.nick_name like concat('%', #{searchValue}, '%')
  179. or
  180. p.post_name like concat('%', #{searchValue}, '%')
  181. )
  182. </if>
  183. <if test="grade != null and grade != ''">
  184. AND u.grade like concat('%', #{grade}, '%')
  185. </if>
  186. <if test="category != null and category != ''">
  187. AND u.category like concat('%', #{category}, '%')
  188. </if>
  189. <if test="tutorUserId != null">
  190. AND u.tutor_user_id = #{tutorUserId}
  191. </if>
  192. <if test="nature != null and nature != ''">
  193. AND u.nature = #{nature}
  194. </if>
  195. <if test="position != null and position != ''">
  196. AND u.position = #{position}
  197. </if>
  198. <if test="isCheck != null">
  199. AND u.is_check = #{isCheck}
  200. </if>
  201. <!-- 数据范围过滤 -->
  202. ${params.dataScope}
  203. order by
  204. <if test="userType == '11'">
  205. u.nature ASC,
  206. </if>
  207. u.create_time DESC
  208. </select>
  209. <select id="selectUserListByDeptIds" resultMap="SysUserResult">
  210. select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.password, u.sex,
  211. u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
  212. u.card_num,u.wechat_id,u.education,u.nationality,u.addr,u.work_status,u.date_birth
  213. from
  214. sys_user u
  215. where u.del_flag = '0'
  216. and u.status = '0'
  217. and u.dept_id in
  218. <foreach collection="array" item="deptId" open="(" separator="," close=")">
  219. #{deptId}
  220. </foreach>
  221. </select>
  222. <select id="selectAllocatedList" parameterType="com.zd.model.entity.SysUser" resultMap="SysUserResult">
  223. select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.user_type, u.email, u.phonenumber, u.status, u.create_time, d.`dept_name`,
  224. u.card_num,u.wechat_id,u.education,u.nationality,u.addr,u.work_status,u.date_birth
  225. from sys_user u
  226. left join sys_dept d on u.dept_id = d.dept_id
  227. left join sys_user_role ur on u.user_id = ur.user_id
  228. left join sys_role r on r.role_id = ur.role_id
  229. where u.del_flag = '0' and r.role_id = #{roleId}
  230. <if test="userName != null and userName != ''">
  231. AND u.user_name like concat('%', #{userName}, '%')
  232. </if>
  233. <if test="nickName != null and nickName != ''">
  234. AND u.nick_name like concat('%', #{nickName}, '%')
  235. </if>
  236. <if test="userType != null and userType != ''">
  237. AND u.user_type = #{userType}
  238. </if>
  239. <if test="phonenumber != null and phonenumber != ''">
  240. AND u.phonenumber like concat('%', #{phonenumber}, '%')
  241. </if>
  242. <if test="deptId != null and deptId != 0">
  243. AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId},
  244. ancestors) ))
  245. </if>
  246. <!-- 数据范围过滤 -->
  247. ${params.dataScope}
  248. </select>
  249. <select id="selectUnallocatedList" parameterType="com.zd.model.entity.SysUser" resultMap="SysUserResult">
  250. select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time,
  251. u.card_num,u.wechat_id,u.education,u.nationality,u.addr,u.work_status
  252. from sys_user u
  253. left join sys_dept d on u.dept_id = d.dept_id
  254. left join sys_user_role ur on u.user_id = ur.user_id
  255. left join sys_role r on r.role_id = ur.role_id
  256. where u.del_flag = '0' and (r.role_id != #{roleId} or r.role_id IS NULL)
  257. 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
  258. ur.role_id = #{roleId})
  259. <if test="userName != null and userName != ''">
  260. AND u.user_name like concat('%', #{userName}, '%')
  261. </if>
  262. <if test="nickName != null and nickName != ''">
  263. AND u.nick_name like concat('%', #{nickName}, '%')
  264. </if>
  265. <if test="userType != null and userType != ''">
  266. AND u.user_type = #{userType}
  267. </if>
  268. <if test="phonenumber != null and phonenumber != ''">
  269. AND u.phonenumber like concat('%', #{phonenumber}, '%')
  270. </if>
  271. <if test="deptId != null and deptId != 0">
  272. AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId},
  273. ancestors) ))
  274. </if>
  275. <!-- 数据范围过滤 -->
  276. ${params.dataScope}
  277. </select>
  278. <select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult">
  279. <include refid="selectUserNewVo"/>
  280. where (u.user_name = #{userName} or u.phonenumber=#{userName}) and u.del_flag = 0
  281. </select>
  282. <select id="selectUserCenterByUserName" parameterType="String" resultMap="SysUserResult">
  283. SELECT u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex,
  284. u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,u.user_type,
  285. d.dept_id, d.parent_id,
  286. CASE WHEN u.user_type='22' THEN d.dept_name ELSE concat(if((SELECT dt.dept_name FROM sys_dept dt WHERE dt.dept_id = d.parent_id) is null ,'',
  287. (SELECT concat(dt.dept_name,'-') FROM sys_dept dt WHERE dt.dept_id = d.parent_id)),d.dept_name) end dept_name,
  288. d.order_num, d.leader, d.status AS dept_status,
  289. CASE WHEN u.user_type='22' THEN sm.`major_name` else pt.`post_name` end major,
  290. u.grade,dd.`dict_label` category, u.tutor_user_id, u.position, u.nature, u.signature,
  291. u.card_num,u.wechat_id,
  292. case when u.user_type='22' then ed.`dict_label` else dd.`dict_label` end education,
  293. u.nationality,u.addr,u.work_status,u.date_birth,
  294. ut.nick_name tutorUserName,u.is_check,
  295. uf.face_img,sc.class_name,u.major_id,u.signature,pt.`post_name` positionName
  296. FROM sys_user u
  297. LEFT JOIN sys_dept d ON u.dept_id = d.dept_id
  298. LEFT JOIN sys_user ut ON ut.user_id = u.tutor_user_id
  299. LEFT JOIN lab_students_info uf ON u.user_id = uf.join_students_id
  300. LEFT JOIN sys_class sc ON sc.id = u.grade
  301. LEFT JOIN sys_major sm ON sm.id = u.major_id
  302. LEFT JOIN sys_post pt ON pt.`post_id` = u.`position`
  303. LEFT JOIN sys_dict_data dd ON dd.`dict_value` = u.category AND dd.`dict_type`='professional'
  304. LEFT JOIN sys_dict_data ed ON ed.`dict_value` = u.education AND ed.`dict_type`='education'
  305. where u.user_name = #{userName} and u.del_flag = 0
  306. </select>
  307. <select id="selectUserByNickName" parameterType="String" resultMap="SysUserResult">
  308. <include refid="selectUserNewVo"/>
  309. where u.nick_name = #{nickName}
  310. </select>
  311. <select id="selectUserByCardNum" parameterType="String" resultMap="SysUserResult">
  312. <include refid="selectUserNewVo"/>
  313. where u.card_num = #{cardNum} and u.del_flag = 0
  314. </select>
  315. <select id="selectUserById" parameterType="Long" resultMap="SysUserResult">
  316. <include refid="selectUserNewVo"/>
  317. where u.user_id = #{userId}
  318. </select>
  319. <select id="checkUserNameUnique" parameterType="String" resultType="int">
  320. select count(1) from sys_user where user_name = #{userName} and del_flag=0 limit 1
  321. </select>
  322. <select id="checkPhoneUnique" parameterType="String" resultMap="SysUserResult">
  323. select user_id, phonenumber from sys_user where phonenumber = #{phonenumber} limit 1
  324. </select>
  325. <select id="checkPhoneUniqueNotOwn" parameterType="com.zd.model.entity.SysUser" resultMap="SysUserResult">
  326. select user_id, phonenumber from sys_user where phonenumber = #{phonenumber} and user_name != #{userName} limit 1
  327. </select>
  328. <select id="checkEmailUnique" parameterType="String" resultMap="SysUserResult">
  329. select user_id, email from sys_user where email = #{email} limit 1
  330. </select>
  331. <select id="selectOption" resultType="java.util.Map">
  332. select user_id userId, nick_name nickName,user_name userName from sys_user
  333. <where>
  334. <if test="userType != null and userType != ''">
  335. AND user_type = #{userType}
  336. </if>
  337. <if test="nickName != null and nickName != ''">
  338. AND nick_name like concat('%', #{nickName}, '%')
  339. </if>
  340. </where>
  341. </select>
  342. <select id="noJoinPositionByList" parameterType="com.zd.model.entity.SysUser" resultMap="SysUserResult">
  343. select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.password, u.sex,
  344. u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
  345. u.major, u.grade, u.category, u.tutor_user_id, u.position, u.nature,
  346. u.card_num,u.wechat_id,u.education,u.nationality,u.addr,u.work_status,u.date_birth,
  347. d.dept_name, d.leader,u.department,
  348. ut.nick_name tutorUserName,u.is_check
  349. from
  350. sys_user u
  351. left join sys_dept d on u.dept_id = d.dept_id
  352. left join sys_user ut on ut.user_id = u.tutor_user_id
  353. where u.del_flag = '0' AND (u.position = '未定' or u.position is null)
  354. <if test="userId != null ">
  355. AND u.user_id = #{userId}
  356. </if>
  357. <if test="userName != null and userName != ''">
  358. AND u.user_name like concat('%', #{userName}, '%')
  359. </if>
  360. <if test="nickName != null and nickName != ''">
  361. AND u.nick_name like concat('%', #{nickName}, '%')
  362. </if>
  363. <if test="cardNum != null and cardNum != ''">
  364. AND u.card_num = #{cardNum}
  365. </if>
  366. <if test="userType != null and userType != ''">
  367. AND u.user_type = #{userType}
  368. </if>
  369. <if test="status != null and status != ''">
  370. AND u.status = #{status}
  371. </if>
  372. <if test="phonenumber != null and phonenumber != ''">
  373. AND u.phonenumber like concat('%', #{phonenumber}, '%')
  374. </if>
  375. <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
  376. AND date_format(u.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
  377. </if>
  378. <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
  379. AND date_format(u.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
  380. </if>
  381. <if test="deptId != null and deptId != 0">
  382. AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId},
  383. ancestors) ))
  384. </if>
  385. <if test="ids!=null and ids.size > 0">
  386. AND u.user_id IN
  387. <foreach item="item" collection="ids" separator="," open="(" close=")" index="">'${item}'</foreach>
  388. </if>
  389. <if test="major != null and major != ''">
  390. AND u.major like concat('%', #{major}, '%')
  391. </if>
  392. <if test="grade != null and grade != ''">
  393. AND u.grade like concat('%', #{grade}, '%')
  394. </if>
  395. <if test="category != null and category != ''">
  396. AND u.category like concat('%', #{category}, '%')
  397. </if>
  398. <if test="tutorUserId != null">
  399. AND u.tutor_user_id = #{tutorUserId}
  400. </if>
  401. <if test="nature != null and nature != ''">
  402. AND u.nature = #{nature}
  403. </if>
  404. <if test="isCheck != null">
  405. AND u.is_check = #{isCheck}
  406. </if>
  407. <!-- 数据范围过滤 -->
  408. ${params.dataScope}
  409. </select>
  410. <insert id="insertUser" parameterType="com.zd.model.entity.SysUser" useGeneratedKeys="true"
  411. keyProperty="userId">
  412. insert into sys_user(
  413. <if test="userId != null and userId != 0">user_id,</if>
  414. <if test="deptId != null and deptId != 0">dept_id,</if>
  415. <if test="userName != null and userName != ''">user_name,</if>
  416. <if test="nickName != null and nickName != ''">nick_name,</if>
  417. <if test="email != null and email != ''">email,</if>
  418. <if test="avatar != null and avatar != ''">avatar,</if>
  419. <if test="phonenumber != null and phonenumber != ''">phonenumber,</if>
  420. <if test="sex != null and sex != ''">sex,</if>
  421. <if test="password != null and password != ''">password,</if>
  422. <if test="status != null and status != ''">status,</if>
  423. <if test="createBy != null and createBy != ''">create_by,</if>
  424. <if test="remark != null and remark != ''">remark,</if>
  425. <if test="userType != null and userType != ''">user_type,</if>
  426. <if test="major != null and major != ''">major,</if>
  427. <if test="grade != null and grade != ''">grade,</if>
  428. <if test="category != null and category != ''">category,</if>
  429. <if test="tutorUserId != null and tutorUserId != '' ">tutor_user_id,</if>
  430. <if test="majorId != null and majorId != ''">major_id,</if>
  431. <if test="position != null and position != ''">position,</if>
  432. <if test="department != null and department != ''">department,</if>
  433. <if test="nature != null and nature != ''">nature,</if>
  434. <if test="cardNum != null and cardNum != ''">card_num,</if>
  435. <if test="education != null and education != ''">education,</if>
  436. <if test="nationality != null and nationality != ''">nationality,</if>
  437. <if test="addr != null and addr != ''">addr,</if>
  438. <if test="workStatus != null and workStatus != ''">work_status,</if>
  439. <if test="dateBirth != null">date_birth,</if>
  440. <if test="isCheck != null and isCheck != ''">is_check,</if>
  441. create_time
  442. )values(
  443. <if test="userId != null and userId != ''">#{userId},</if>
  444. <if test="deptId != null and deptId != ''">#{deptId},</if>
  445. <if test="userName != null and userName != ''">#{userName},</if>
  446. <if test="nickName != null and nickName != ''">#{nickName},</if>
  447. <if test="email != null and email != ''">#{email},</if>
  448. <if test="avatar != null and avatar != ''">#{avatar},</if>
  449. <if test="phonenumber != null and phonenumber != ''">#{phonenumber},</if>
  450. <if test="sex != null and sex != ''">#{sex},</if>
  451. <if test="password != null and password != ''">#{password},</if>
  452. <if test="status != null and status != ''">#{status},</if>
  453. <if test="createBy != null and createBy != ''">#{createBy},</if>
  454. <if test="remark != null and remark != ''">#{remark},</if>
  455. <if test="userType != null and userType != ''">#{userType},</if>
  456. <if test="major != null and major != ''">#{major},</if>
  457. <if test="grade != null and grade != ''">#{grade},</if>
  458. <if test="category != null and category != ''">#{category},</if>
  459. <if test="tutorUserId != null and tutorUserId != ''">#{tutorUserId},</if>
  460. <if test="majorId != null and majorId != ''">#{majorId},</if>
  461. <if test="position != null and position != '' ">#{position},</if>
  462. <if test="department != null and department != ''">#{department},</if>
  463. <if test="nature != null and nature != ''">#{nature},</if>
  464. <if test="cardNum != null and cardNum != ''">#{cardNum},</if>
  465. <if test="education != null and education != ''">#{education},</if>
  466. <if test="nationality != null and nationality != ''">#{nationality},</if>
  467. <if test="addr != null and addr != ''">#{addr},</if>
  468. <if test="workStatus != null and workStatus != ''">#{workStatus},</if>
  469. <if test="dateBirth != null">#{dateBirth},</if>
  470. <if test="isCheck != null and isCheck != ''">#{isCheck},</if>
  471. sysdate()
  472. )
  473. </insert>
  474. <update id="updateUser" parameterType="com.zd.model.entity.SysUser">
  475. update sys_user
  476. <set>
  477. <if test="deptId != null and deptId != 0">dept_id = #{deptId},</if>
  478. <if test="userName != null and userName != ''">user_name = #{userName},</if>
  479. <if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
  480. <if test="email != null ">email = #{email},</if>
  481. <if test="phonenumber != null ">phonenumber = #{phonenumber},</if>
  482. <if test="sex != null and sex != ''">sex = #{sex},</if>
  483. <if test="avatar != null and avatar != ''">avatar = #{avatar},</if>
  484. <if test="password != null and password != ''">password = #{password},</if>
  485. <if test="status != null and status != ''">status = #{status},</if>
  486. <if test="loginIp != null and loginIp != ''">login_ip = #{loginIp},</if>
  487. <if test="loginDate != null">login_date = #{loginDate},</if>
  488. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  489. <if test="remark != null and remark != ''">remark = #{remark},</if>
  490. <if test="userType != null ">user_type = #{userType},</if>
  491. <if test="major != null and major != ''">major = #{major},</if>
  492. <if test="majorId != null">major_id = #{majorId},</if>
  493. <if test="grade != null and grade!=''">grade = #{grade},</if>
  494. <if test="category != null and category !=''">category = #{category},</if>
  495. <if test="tutorUserId != null ">tutor_user_id = #{tutorUserId},</if>
  496. <if test="position != null ">position = #{position},</if>
  497. <if test="department != null ">department = #{department},</if>
  498. <if test="nature != null and nature!=''">nature = #{nature},</if>
  499. <if test="cardNum != null ">card_num = #{cardNum},</if>
  500. <if test="education != null and education!=''">education = #{education},</if>
  501. <if test="nationality != null and nationality!=''">nationality = #{nationality},</if>
  502. <if test="addr != null and addr != ''">addr = #{addr},</if>
  503. <if test="workStatus != null and workStatus != ''">work_status = #{workStatus},</if>
  504. <if test="dateBirth != null">date_birth = #{dateBirth},</if>
  505. <if test="isCheck != null ">is_check = #{isCheck},</if>
  506. <if test="signature != null and signature != ''">signature = #{signature},</if>
  507. update_time = sysdate()
  508. </set>
  509. where user_id = #{userId}
  510. </update>
  511. <update id="updateTeacherUser" parameterType="com.zd.model.entity.SysUser">
  512. update sys_user
  513. <set>
  514. <if test="deptId != null and deptId != 0">dept_id = #{deptId},</if>
  515. <if test="userName != null and userName != ''">user_name = #{userName},</if>
  516. <if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
  517. <if test="email != null ">email = #{email},</if>
  518. <if test="phonenumber != null ">phonenumber = #{phonenumber},</if>
  519. <if test="sex != null and sex != ''">sex = #{sex},</if>
  520. <if test="avatar != null and avatar != ''">avatar = #{avatar},</if>
  521. <if test="password != null and password != ''">password = #{password},</if>
  522. <if test="status != null and status != ''">status = #{status},</if>
  523. <if test="loginIp != null and loginIp != ''">login_ip = #{loginIp},</if>
  524. <if test="loginDate != null">login_date = #{loginDate},</if>
  525. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  526. <if test="remark != null and remark != ''">remark = #{remark},</if>
  527. <if test="userType != null ">user_type = #{userType},</if>
  528. <if test="major != null and major != ''">major = #{major},</if>
  529. <if test="majorId != null">major_id = #{majorId},</if>
  530. <if test="grade != null and grade!=''">grade = #{grade},</if>
  531. <if test="category != null and category !=''">category = #{category},</if>
  532. <if test="tutorUserId != null ">tutor_user_id = #{tutorUserId},</if>
  533. <if test="position != null ">position = #{position},</if>
  534. <if test="department != null ">department = #{department},</if>
  535. <if test="nature != null and nature!=''">nature = #{nature},</if>
  536. card_num = #{cardNum},
  537. <if test="education != null and education!=''">education = #{education},</if>
  538. <if test="nationality != null and nationality!=''">nationality = #{nationality},</if>
  539. <if test="addr != null and addr != ''">addr = #{addr},</if>
  540. <if test="workStatus != null and workStatus != ''">work_status = #{workStatus},</if>
  541. <if test="dateBirth != null">date_birth = #{dateBirth},</if>
  542. <if test="isCheck != null ">is_check = #{isCheck},</if>
  543. <if test="signature != null and signature != ''">signature = #{signature},</if>
  544. update_time = sysdate()
  545. </set>
  546. where user_id = #{userId}
  547. </update>
  548. <update id="updateStudentUser" parameterType="com.zd.model.entity.SysUser">
  549. update sys_user
  550. <set>
  551. <if test="deptId != null and deptId != 0">dept_id = #{deptId},</if>
  552. <if test="userName != null and userName != ''">user_name = #{userName},</if>
  553. <if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
  554. <if test="email != null ">email = #{email},</if>
  555. <if test="phonenumber != null ">phonenumber = #{phonenumber},</if>
  556. <if test="sex != null and sex != ''">sex = #{sex},</if>
  557. <if test="avatar != null and avatar != ''">avatar = #{avatar},</if>
  558. <if test="password != null and password != ''">password = #{password},</if>
  559. <if test="status != null and status != ''">status = #{status},</if>
  560. <if test="loginIp != null and loginIp != ''">login_ip = #{loginIp},</if>
  561. <if test="loginDate != null">login_date = #{loginDate},</if>
  562. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  563. <if test="remark != null and remark != ''">remark = #{remark},</if>
  564. <if test="userType != null ">user_type = #{userType},</if>
  565. <if test="major != null and major != ''">major = #{major},</if>
  566. <if test="majorId != null">major_id = #{majorId},</if>
  567. <if test="grade != null and grade!=''">grade = #{grade},</if>
  568. <if test="category != null and category !=''">category = #{category},</if>
  569. <if test="tutorUserId != null ">tutor_user_id = #{tutorUserId},</if>
  570. <if test="position != null ">position = #{position},</if>
  571. <if test="department != null ">department = #{department},</if>
  572. <if test="nature != null and nature!=''">nature = #{nature},</if>
  573. card_num = #{cardNum},
  574. <if test="education != null and education!=''">education = #{education},</if>
  575. <if test="nationality != null and nationality!=''">nationality = #{nationality},</if>
  576. <if test="addr != null and addr != ''">addr = #{addr},</if>
  577. <if test="workStatus != null and workStatus != ''">work_status = #{workStatus},</if>
  578. <if test="dateBirth != null">date_birth = #{dateBirth},</if>
  579. <if test="isCheck != null ">is_check = #{isCheck},</if>
  580. <if test="signature != null and signature != ''">signature = #{signature},</if>
  581. update_time = sysdate()
  582. </set>
  583. where user_id = #{userId}
  584. </update>
  585. <update id="relieveUserByPosition" parameterType="com.zd.model.entity.SysUser">
  586. update sys_user
  587. set position = '未定'
  588. where user_id = #{userId}
  589. </update>
  590. <update id="updateUserAvatar" parameterType="com.zd.model.entity.SysUser">
  591. update sys_user set avatar = #{avatar} where user_name = #{userName}
  592. </update>
  593. <update id="resetUserPwd" parameterType="com.zd.model.entity.SysUser">
  594. update sys_user set password = #{password} where user_name = #{userName}
  595. </update>
  596. <delete id="deleteUserById" parameterType="Long">
  597. update sys_user set del_flag = '2' where user_id = #{userId}
  598. </delete>
  599. <delete id="deleteUserByIds" parameterType="Long">
  600. update sys_user set del_flag = '2' where user_id in
  601. <foreach collection="array" item="userId" open="(" separator="," close=")">
  602. #{userId}
  603. </foreach>
  604. </delete>
  605. <select id="queryPhoneByIds" resultType="string">
  606. select phonenumber from sys_user
  607. where user_id in
  608. <foreach collection="array" item="id" open="(" separator="," close=")">
  609. #{id}
  610. </foreach>
  611. and length(phonenumber)=11
  612. </select>
  613. <select id="queryCountByDeptIds" resultType="com.zd.model.entity.TotalByID">
  614. select dept_id as id, count(dept_id ) as total from sys_user
  615. where dept_id in
  616. <foreach collection="array" item="deptId" open="(" separator="," close=")">
  617. #{deptId}
  618. </foreach>
  619. group by dept_id
  620. </select>
  621. <select id="selectUserListByName" parameterType="com.zd.model.entity.SysUser" resultMap="SysUserResult">
  622. select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.password, u.sex,
  623. u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
  624. u.major, u.grade, u.category, u.tutor_user_id, u.position, u.nature,
  625. u.card_num,u.wechat_id,u.education,u.nationality,u.addr,u.work_status,u.date_birth,
  626. d.dept_name, d.leader,u.department,u.is_check
  627. from
  628. sys_user u
  629. left join sys_dept d on u.dept_id = d.dept_id
  630. where u.del_flag = '0'
  631. <if test="userId != null ">
  632. AND u.user_id = #{userId}
  633. </if>
  634. <if test="userName != null and userName != ''">
  635. AND u.user_name like concat('%', #{userName}, '%')
  636. </if>
  637. <if test="nickName != null and nickName != ''">
  638. AND u.nick_name like concat('%', #{nickName}, '%')
  639. </if>
  640. <if test="userType != null and userType != ''">
  641. AND u.user_type = #{userType}
  642. </if>
  643. <if test="status != null and status != ''">
  644. AND u.status = #{status}
  645. </if>
  646. <if test="phonenumber != null and phonenumber != ''">
  647. AND u.phonenumber like concat('%', #{phonenumber}, '%')
  648. </if>
  649. <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
  650. AND date_format(u.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
  651. </if>
  652. <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
  653. AND date_format(u.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
  654. </if>
  655. <if test="ids!=null and ids.size > 0">
  656. AND u.user_id IN
  657. <foreach item="item" collection="ids" separator="," open="(" close=")" index="">'${item}'</foreach>
  658. </if>
  659. <if test="major != null and major != ''">
  660. AND u.major like concat('%', #{major}, '%')
  661. </if>
  662. <if test="grade != null and grade != ''">
  663. AND u.grade like concat('%', #{grade}, '%')
  664. </if>
  665. <if test="category != null and category != ''">
  666. AND u.category like concat('%', #{category}, '%')
  667. </if>
  668. <if test="tutorUserId != null">
  669. AND u.tutor_user_id = #{tutorUserId}
  670. </if>
  671. <if test="nature != null and nature != ''">
  672. AND u.nature = #{nature}
  673. </if>
  674. <if test="position != null and position != ''">
  675. AND u.position = #{position}
  676. </if>
  677. <if test="isCheck != null">
  678. AND u.is_check = #{isCheck}
  679. </if>
  680. </select>
  681. <select id="selectUserListByNotWhite" parameterType="com.zd.model.entity.SysUser" resultMap="SysUserResult">
  682. select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.password, u.sex,
  683. u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
  684. u.major, u.grade, u.category, u.tutor_user_id, u.position, u.nature,
  685. u.card_num,u.wechat_id,u.education,u.nationality,u.addr,u.work_status,u.date_birth,
  686. d.dept_name, d.leader,u.department,u.is_check
  687. from
  688. sys_user u
  689. left join sys_dept d on u.dept_id = d.dept_id
  690. where u.del_flag = '0'
  691. and u.`user_id` not in (select w.`user_id` from lab_whitelist w)
  692. <if test="userId != null ">
  693. AND u.user_id = #{userId}
  694. </if>
  695. <if test="userName != null and userName != ''">
  696. AND u.user_name like concat('%', #{userName}, '%')
  697. </if>
  698. <if test="nickName != null and nickName != ''">
  699. AND u.nick_name like concat('%', #{nickName}, '%')
  700. </if>
  701. <if test="userType != null and userType != ''">
  702. AND u.user_type = #{userType}
  703. </if>
  704. <if test="status != null and status != ''">
  705. AND u.status = #{status}
  706. </if>
  707. <if test="phonenumber != null and phonenumber != ''">
  708. AND u.phonenumber like concat('%', #{phonenumber}, '%')
  709. </if>
  710. <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
  711. AND date_format(u.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
  712. </if>
  713. <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
  714. AND date_format(u.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
  715. </if>
  716. <if test="ids!=null and ids.size > 0">
  717. AND u.user_id IN
  718. <foreach item="item" collection="ids" separator="," open="(" close=")" index="">'${item}'</foreach>
  719. </if>
  720. <if test="deptIds !=null and deptIds.size >0" >
  721. AND u.dept_id IN
  722. <foreach item="item" collection="deptIds" separator="," open="(" close=")" index="">'${item}'</foreach>
  723. </if>
  724. <if test="major != null and major != ''">
  725. AND u.major like concat('%', #{major}, '%')
  726. </if>
  727. <if test="grade != null and grade != ''">
  728. AND u.grade like concat('%', #{grade}, '%')
  729. </if>
  730. <if test="category != null and category != ''">
  731. AND u.category like concat('%', #{category}, '%')
  732. </if>
  733. <if test="tutorUserId != null">
  734. AND u.tutor_user_id = #{tutorUserId}
  735. </if>
  736. <if test="nature != null and nature != ''">
  737. AND u.nature = #{nature}
  738. </if>
  739. <if test="position != null and position != ''">
  740. AND u.position = #{position}
  741. </if>
  742. <if test="isCheck != null">
  743. AND u.is_check = #{isCheck}
  744. </if>
  745. </select>
  746. <select id="selectUserInfoByCardNum" resultType="com.zd.model.entity.SysUser">
  747. SELECT user_id,nick_name,card_num FROM sys_user u WHERE u.card_num = #{cardNum}
  748. </select>
  749. <select id="getSafeUserList" parameterType="com.zd.model.entity.SysUser" resultMap="SysUserResult">
  750. select u.user_id, u.nick_name
  751. from
  752. sys_user u
  753. where u.del_flag = '0'
  754. <if test="safeUserId != null">
  755. AND FIND_IN_SET(u.user_id, #{safeUserId})
  756. </if>
  757. </select>
  758. </mapper>