UserDao.xml 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.jeeplus.modules.sys.dao.UserDao">
  4. <!-- <resultMap id="userResult" type="User">
  5. <id property="id" column="id" />
  6. <result property="company.id" column="company.id" />
  7. <result property="office.id" column="office.id" />
  8. <result property="loginName" column="login_name" />
  9. <result property="password" column="password" />
  10. <result property="no" column="no" />
  11. <result property="name" column="name" />
  12. <result property="email" column="email" />
  13. <result property="phone" column="phone" />
  14. <result property="mobile" column="mobile" />
  15. <result property="userType" column="user_type" />
  16. <result property="loginIp" column="login_ip" />
  17. <result property="loginDate" column="login_date" />
  18. <result property="remarks" column="remarks" />
  19. <result property="loginFlag" column="loginFlag" />
  20. <result property="photo" column="photo" />
  21. <result property="createBy.id" column="createBy.id" />
  22. <result property="createDate" column="create_date" />
  23. <result property="updateBy.id" column="updateBy.id" />
  24. <result property="updateDate" column="update_date" />
  25. <result property="company.name" column="company.name" />
  26. <result property="company.parentId" column="company.parentId" />
  27. <result property="company.parentIds" column="company.parentIds" />
  28. <result property="company.area.id" column="company.area.id" />
  29. <result property="company.area.name" column="company.area.name" />
  30. <result property="company.area.parentId" column="company.area.parentId" />
  31. <result property="company.area.parentIds" column="company.area.parentIds" />
  32. <result property="company.primaryPerson.id" column="company.primaryPerson.id" />
  33. <result property="company.primaryPerson.name" column="company.primaryPerson.name" />
  34. <result property="company.deputyPerson.id" column="company.deputyPerson.id" />
  35. <result property="company.deputyPerson.name" column="company.deputyPerson.name" />
  36. <result property="office.name" column="office.name" />
  37. <result property="office.parentId" column="office.parentId" />
  38. <result property="office.parentIds" column="office.parentIds" />
  39. <result property="office.area.id" column="office.area.id" />
  40. <result property="office.area.name" column="office.area.name" />
  41. <result property="office.area.parentId" column="office.area.parentId" />
  42. <result property="office.area.parentIds" column="office.area.parentIds" />
  43. <result property="office.primaryPerson.id" column="office.primaryPerson.id" />
  44. <result property="office.primaryPerson.name" column="office.primaryPerson.name" />
  45. <result property="office.deputyPerson.id" column="office.deputyPerson.id" />
  46. <result property="office.deputyPerson.name" column="office.deputyPerson.name" />
  47. <collection property="roleList" ofType="Role">
  48. <id property="id" column="roleList.id" />
  49. <result property="office.id" column="roleList.office.id" />
  50. <result property="name" column="roleList.name" />
  51. <result property="enname" column="roleList.enname" />
  52. <result property="roleType" column="roleList.roleType" />
  53. <result property="dataScope" column="roleList.dataScope" />
  54. <collection property="officeList" ofType="Office">
  55. <id property="id" column="roleList.officeList.id" />
  56. </collection>
  57. </collection>
  58. </resultMap> -->
  59. <sql id="userColumns">
  60. a.id,
  61. a.com_id AS "comId",
  62. a.company_id AS "company.id",
  63. a.office_id AS "office.id",
  64. a.login_name,
  65. a.password,
  66. a.password_remake AS "passwordRemake",
  67. a.no,
  68. a.name,
  69. a.sex,
  70. a.email,
  71. a.phone,
  72. a.mobile,
  73. a.ishide,
  74. a.user_type,
  75. a.login_ip,
  76. a.login_date,
  77. a.remarks,
  78. a.login_flag,
  79. a.photo,
  80. a.default_photo,
  81. a.qrcode,
  82. a.sign,
  83. a.create_by AS "createBy.id",
  84. a.create_date,
  85. a.update_by AS "updateBy.id",
  86. a.update_date,
  87. a.del_flag,
  88. a.first_flag AS "firstFlag",
  89. s.name AS "company.name",
  90. s.parent_id AS "company.parent.id",
  91. s.parent_ids AS "company.parentIds",
  92. s.group_id AS "company.groupId",
  93. s.group_name AS "company.groupName",
  94. s.useable AS "company.useable",
  95. o.name AS "office.name",
  96. o.top_company AS "office.topCompany",
  97. o.parent_id AS "office.parent.id",
  98. o.parent_ids AS "office.parentIds",
  99. bo.id AS "branchOffice.id",
  100. bo.name AS "branchOffice.name",
  101. bo.parent_ids AS "branchOffice.parentIds",
  102. bo.parent_id AS "branchOffice.parent.id"<!-- ,
  103. r.id AS "role.id",
  104. r.office_id AS "role.office.id",
  105. r.name AS "role.name",
  106. r.enname AS "role.enname",
  107. r.role_type AS "role.roleType",
  108. r.data_scope AS "role.dataScope" -->
  109. </sql>
  110. <sql id="userJoins">
  111. LEFT JOIN sys_user_office uo ON uo.user_id = a.id
  112. <if test="company != null and company.id != null and company.id != ''">
  113. AND uo.company_id = #{company.id}
  114. </if>
  115. AND uo.status = '3' AND uo.del_flag = #{DEL_FLAG_NORMAL}
  116. LEFT JOIN sys_office s ON s.id = uo.company_id
  117. LEFT JOIN sys_office o ON o.id = uo.office_id
  118. LEFT JOIN sys_office bo ON bo.id = o.branch_office
  119. <!--
  120. -->
  121. </sql>
  122. <!-- 根据编号获得用户 -->
  123. <select id="get" resultType="User">
  124. SELECT
  125. <include refid="userColumns"/><!-- ,
  126. ro.office_id AS "roleList.officeList.id"
  127. r.id AS "role.id",
  128. r.office_id AS "role.office.id",
  129. r.name AS "role.name",
  130. r.enname AS "role.enname",
  131. r.role_type AS "role.roleType",
  132. r.data_scope AS "role.dataScope" -->
  133. FROM sys_user a
  134. LEFT JOIN sys_office s ON s.id = a.company_id
  135. LEFT JOIN sys_office o ON o.id = a.office_id
  136. LEFT JOIN sys_office bo ON bo.id = o.branch_office
  137. <!--
  138. LEFT JOIN sys_role_office ro ON ro.role_id = r.id
  139. inner JOIN sys_user_role ur ON ur.user_id = a.id
  140. inner JOIN sys_role r ON r.id = ur.role_id and r.company_id = a.company_id -->
  141. WHERE a.id = #{id}
  142. </select>
  143. <!-- 根据编号获得用户 -->
  144. <select id="getByCompanyAndUserId" resultType="User">
  145. SELECT
  146. <include refid="userColumns"/>
  147. FROM sys_user a
  148. LEFT JOIN sys_user_office uo ON uo.user_id = a.id AND uo.company_id = #{companyId} AND uo.status = '3' AND uo.del_flag = '0'
  149. LEFT JOIN sys_office s ON s.id = uo.company_id
  150. LEFT JOIN sys_office o ON o.id = uo.office_id
  151. LEFT JOIN sys_office bo ON bo.id = o.branch_office
  152. WHERE a.id = #{id}
  153. </select>
  154. <!-- 根据编号获得用户 -->
  155. <select id="findUserByRoleId" resultType="User">
  156. SELECT
  157. <include refid="userColumns"/>
  158. FROM sys_user a
  159. LEFT JOIN sys_user_office uo ON uo.user_id = a.id AND uo.company_id = #{companyId} AND uo.status = '3' AND uo.del_flag = '0'
  160. LEFT JOIN sys_office s ON s.id = uo.company_id
  161. LEFT JOIN sys_office o ON o.id = uo.office_id
  162. LEFT JOIN sys_office bo ON bo.id = o.branch_office
  163. LEFT JOIN sys_user_role ur ON ur.user_id = a.id
  164. WHERE ur.role_id = #{roleId} and a.company_id = #{companyId}
  165. </select>
  166. <!-- 根据编号获得用户 -->
  167. <select id="getByUserId" resultType="User">
  168. SELECT
  169. <include refid="userColumns"/><!-- ,
  170. ro.office_id AS "roleList.officeList.id"-->
  171. FROM sys_user a
  172. LEFT JOIN sys_office s ON s.id = a.company_id
  173. LEFT JOIN sys_office o ON o.id = a.office_id
  174. LEFT JOIN sys_office bo ON bo.id = o.branch_office
  175. <!--
  176. LEFT JOIN sys_role_office ro ON ro.role_id = r.id -->
  177. WHERE a.id = #{id}
  178. </select>
  179. <!-- 根据编号获得用户 -->
  180. <select id="findUserByNo" resultType="User">
  181. SELECT
  182. <include refid="userColumns"/><!-- ,
  183. ro.office_id AS "roleList.officeList.id"-->
  184. FROM sys_user a
  185. LEFT JOIN sys_user_office uo ON uo.user_id = a.id
  186. AND uo.company_id = #{companyId} AND uo.status = '3' AND uo.del_flag = '0'
  187. LEFT JOIN sys_office s ON s.id = uo.company_id
  188. LEFT JOIN sys_office o ON o.id = uo.office_id
  189. LEFT JOIN sys_office bo ON bo.id = o.branch_office
  190. <!--
  191. LEFT JOIN sys_role_office ro ON ro.role_id = r.id -->
  192. WHERE a.no =#{no} and a.company_id = #{companyId}
  193. </select>
  194. <!-- 根据登录名查询用户 -->
  195. <select id="getByLoginName" resultType="User" parameterType="User">
  196. SELECT
  197. <include refid="userColumns"/><!-- ,
  198. ro.office_id AS "roleList.officeList.id" -->
  199. FROM sys_user a
  200. LEFT JOIN sys_office s ON s.id = a.company_id
  201. LEFT JOIN sys_office o ON o.id = a.office_id
  202. LEFT JOIN sys_office bo ON bo.id = o.branch_office
  203. <!--
  204. LEFT JOIN sys_role_office ro ON ro.role_id = r.id -->
  205. WHERE a.login_name = #{loginName} AND a.del_flag = #{DEL_FLAG_NORMAL}
  206. </select>
  207. <!-- 根据登录名查询用户 -->
  208. <select id="getByName" resultType="User" parameterType="User">
  209. SELECT
  210. <include refid="userColumns"/><!-- ,
  211. ro.office_id AS "roleList.officeList.id" -->
  212. FROM sys_user a
  213. LEFT JOIN sys_office s ON s.id = a.company_id
  214. LEFT JOIN sys_office o ON o.id = a.office_id
  215. LEFT JOIN sys_office bo ON bo.id = o.branch_office
  216. <!--
  217. LEFT JOIN sys_role_office ro ON ro.role_id = r.id -->
  218. WHERE a.name = #{name} AND a.del_flag = #{DEL_FLAG_NORMAL}
  219. </select>
  220. <!-- 分页查询用户信息 -->
  221. <select id="findList" resultType="User">
  222. SELECT
  223. <include refid="userColumns"/>
  224. FROM sys_user a
  225. <include refid="userJoins"/>
  226. <if test="role != null and role.id != null and role.id != ''">
  227. JOIN sys_user_role ur ON ur.user_id = a.id AND ur.role_id = #{role.id}
  228. </if>
  229. WHERE a.del_flag = #{DEL_FLAG_NORMAL}
  230. <if test="company != null and company.id != null and company.id != ''">
  231. AND (s.id = #{company.id} OR s.parent_ids LIKE
  232. <if test="dbName == 'oracle'">'%,'||#{company.id}||',%')</if>
  233. <if test="dbName == 'mysql'">CONCAT('%,', #{company.id}, ',%'))</if>
  234. </if>
  235. <if test="office != null and office.id != null and office.id != ''">
  236. AND (o.id = #{office.id} OR o.parent_ids LIKE
  237. <if test="dbName == 'oracle'">'%,'||#{office.id}||',%')</if>
  238. <if test="dbName == 'mysql'">CONCAT('%,', #{office.id}, ',%'))</if>
  239. </if>
  240. <if test="branchOffice != null and branchOffice.id != null and branchOffice.id != ''">
  241. AND (o.id = #{branchOffice.id} OR o.parent_ids LIKE
  242. <if test="dbName == 'oracle'">'%,'||#{branchOffice.id}||',%')</if>
  243. <if test="dbName == 'mysql'">CONCAT('%,', #{branchOffice.id}, ',%'))</if>
  244. </if>
  245. <!-- 如果不是超级管理员,则不显示超级管理员用户 -->
  246. <!-- <if test="!currentUser.admin">
  247. AND a.id != '1'
  248. </if>
  249. -->
  250. <if test="loginName != null and loginName != ''">
  251. AND a.login_name like
  252. <if test="dbName == 'oracle'">'%'||#{loginName}||'%'</if>
  253. <if test="dbName == 'mysql'">CONCAT('%', #{loginName}, '%')</if>
  254. </if>
  255. <if test="name != null and name != ''">
  256. AND a.name like
  257. <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
  258. <if test="dbName == 'mysql'">CONCAT('%', #{name}, '%')</if>
  259. </if>
  260. <if test="mobile != null and mobile != ''">
  261. AND a.mobile = #{mobile}
  262. </if>
  263. <!-- 数据范围过滤 -->
  264. ${sqlMap.dsf}
  265. <choose>
  266. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  267. ORDER BY ${page.orderBy}
  268. </when>
  269. <otherwise>
  270. ORDER BY a.update_date DESC
  271. </otherwise>
  272. </choose>
  273. </select>
  274. <!-- 分页查询用户信息 -->
  275. <select id="findListByComany" resultType="User">
  276. SELECT
  277. a.id,
  278. a.com_id AS "comId",
  279. uo.company_id AS "company.id",
  280. uo.office_id AS "office.id",
  281. a.login_name,
  282. a.password,
  283. a.password_remake AS "passwordRemake",
  284. a.name,
  285. a.email,
  286. a.mobile,
  287. a.photo,
  288. a.create_by AS "createBy.id",
  289. a.create_date,
  290. a.update_by AS "updateBy.id",
  291. a.update_date,
  292. a.del_flag
  293. FROM sys_user a
  294. LEFT JOIN sys_user_office uo ON uo.user_id = a.id AND uo.company_id = #{company.id} AND uo.status = '3' AND uo.del_flag = '0'
  295. LEFT JOIN sys_office s ON s.id = uo.company_id
  296. LEFT JOIN sys_office o ON o.id = uo.office_id
  297. WHERE a.del_flag = #{DEL_FLAG_NORMAL}
  298. AND uo.company_id = #{company.id} AND uo.status = '3' AND uo.del_flag = #{DEL_FLAG_NORMAL}
  299. <if test="loginName != null and loginName != ''">
  300. AND a.login_name like
  301. <if test="dbName == 'oracle'">'%'||#{loginName}||'%'</if>
  302. <if test="dbName == 'mysql'">CONCAT('%', #{loginName}, '%')</if>
  303. </if>
  304. <if test="name != null and name != ''">
  305. AND a.name like
  306. <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
  307. <if test="dbName == 'mysql'">CONCAT('%', #{name}, '%')</if>
  308. </if>
  309. <if test="mobile != null and mobile != ''">
  310. AND a.mobile = #{mobile}
  311. </if>
  312. <!-- 数据范围过滤 -->
  313. ${sqlMap.dsf}
  314. <choose>
  315. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  316. ORDER BY ${page.orderBy}
  317. </when>
  318. <otherwise>
  319. ORDER BY a.update_date DESC
  320. </otherwise>
  321. </choose>
  322. </select>
  323. <!-- 分页查询用户信息 -->
  324. <!--<select id="findListByRoleOffice" resultType="User">
  325. SELECT DISTINCT
  326. a.id AS "id",
  327. a.name AS "name"
  328. FROM sys_user a
  329. JOIN sys_office s ON s.id = a.company_id
  330. JOIN sys_user_role ur ON ur.user_id = a.id
  331. JOIN sys_role r ON r.id = ur.role_id
  332. JOIN sys_office o ON ur.office_id = o.id
  333. WHERE a.del_flag = #{DEL_FLAG_NORMAL}
  334. <if test="company != null and company.id != null and company.id != ''">
  335. AND (s.id = #{company.id} OR s.parent_ids LIKE
  336. <if test="dbName == 'oracle'">'%,'||#{company.id}||',%')</if>
  337. <if test="dbName == 'mysql'">CONCAT('%,', #{company.id}, ',%'))</if>
  338. </if>
  339. <if test="office != null and office.id != null and office.id != ''">
  340. AND (o.id = #{office.id} OR o.parent_ids LIKE
  341. <if test="dbName == 'oracle'">'%,'||#{office.id}||',%')</if>
  342. <if test="dbName == 'mysql'">CONCAT('%,', #{office.id}, ',%'))</if>
  343. </if>
  344. &lt;!&ndash; 如果不是超级管理员,则不显示超级管理员用户 &ndash;&gt;
  345. &lt;!&ndash; <if test="!currentUser.admin">
  346. AND a.id != '1'
  347. </if>
  348. &ndash;&gt;
  349. <if test="loginName != null and loginName != ''">
  350. AND a.login_name like
  351. <if test="dbName == 'oracle'">'%'||#{loginName}||'%'</if>
  352. <if test="dbName == 'mysql'">CONCAT('%', #{loginName}, '%')</if>
  353. </if>
  354. <if test="name != null and name != ''">
  355. AND a.name like
  356. <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
  357. <if test="dbName == 'mysql'">CONCAT('%', #{name}, '%')</if>
  358. </if>
  359. &lt;!&ndash; 数据范围过滤 &ndash;&gt;
  360. ${sqlMap.dsf}
  361. <choose>
  362. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  363. ORDER BY ${page.orderBy}
  364. </when>
  365. <otherwise>
  366. ORDER BY s.code, o.code, a.name
  367. </otherwise>
  368. </choose>
  369. </select>-->
  370. <!-- 根据部门查询用户信息 -->
  371. <select id="findListByOffice" resultType="User">
  372. SELECT
  373. <include refid="userColumns"/>
  374. FROM sys_user a
  375. LEFT JOIN sys_user_office uo ON uo.user_id = a.id AND uo.company_id = #{company.id} AND uo.status = '3' AND uo.del_flag = '0'
  376. LEFT JOIN sys_office s ON s.id = uo.company_id
  377. LEFT JOIN sys_office o ON o.id = uo.office_id
  378. LEFT JOIN sys_office bo ON bo.id = o.branch_office
  379. WHERE a.del_flag = #{DEL_FLAG_NORMAL}
  380. <if test="company != null and company.id != null and company.id != ''">
  381. AND s.id = #{company.id}
  382. </if>
  383. <if test="office != null and office.id != null and office.id != ''">
  384. AND o.id = #{office.id}
  385. </if>
  386. <if test="office == null">
  387. AND (o.id = '' or o.id is null)
  388. </if>
  389. <if test="loginName != null and loginName != ''">
  390. AND a.login_name like
  391. <if test="dbName == 'oracle'">'%'||#{loginName}||'%'</if>
  392. <if test="dbName == 'mysql'">CONCAT('%', #{loginName}, '%')</if>
  393. </if>
  394. <if test="name != null and name != ''">
  395. AND a.name like
  396. <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
  397. <if test="dbName == 'mysql'">CONCAT('%', #{name}, '%')</if>
  398. </if>
  399. <!-- 数据范围过滤 -->
  400. ${sqlMap.dsf}
  401. <!-- 排序 -->
  402. ORDER BY a.name
  403. </select>
  404. <!-- 根据OfficeId获取用户(树查询用户时用) -->
  405. <select id="findUserByOfficeId" resultType="User" useCache="true">
  406. SELECT
  407. a.id, a.name, a.login_name,a.photo
  408. FROM sys_user a
  409. LEFT JOIN work_staff_achives uo ON uo.user_id = a.id
  410. LEFT JOIN sys_office o ON o.id = uo.office_id
  411. WHERE a.del_flag = #{DEL_FLAG_NORMAL}
  412. AND o.del_flag = #{DEL_FLAG_NORMAL}
  413. <if test="office != null and office.id != null and office.id !='' ">
  414. AND uo.office_id = #{office.id}
  415. </if>
  416. <if test="company != null and company.id != null and company.id !='' ">
  417. AND uo.company_id = #{company.id}
  418. </if>
  419. AND uo.status IN ('试用','正式','劳务')
  420. ORDER BY a.name
  421. </select>
  422. <!-- 根据OfficeId获取用户(树查询用户时用) -->
  423. <select id="findUserByOffices" resultType="User" useCache="true">
  424. SELECT
  425. a.id, a.name, a.login_name,a.photo
  426. FROM sys_user a
  427. LEFT JOIN work_staff_achives uo ON uo.user_id = a.id
  428. LEFT JOIN sys_office o ON o.id = uo.office_id
  429. WHERE a.del_flag = #{DEL_FLAG_NORMAL}
  430. AND uo.del_flag = #{DEL_FLAG_NORMAL}
  431. AND o.useable = '1'
  432. AND o.del_flag = #{DEL_FLAG_NORMAL}
  433. AND uo.status IN ('试用','正式','劳务')
  434. AND o.id = #{office.id} OR o.parent_ids LIKE
  435. <if test="dbName == 'oracle'">'%,'||#{office.id}||',%'</if>
  436. <if test="dbName == 'mysql'">CONCAT('%,', #{office.id}, ',%')</if>
  437. ORDER BY a.name
  438. </select>
  439. <!-- 查询全部用户 -->
  440. <select id="findAllList" resultType="User">
  441. SELECT
  442. <include refid="userColumns"/>
  443. FROM sys_user a
  444. <include refid="userJoins"/>
  445. WHERE a.del_flag = #{DEL_FLAG_NORMAL}
  446. ORDER BY s.code, o.code, a.name
  447. </select>
  448. <!-- 查询全部用户数目 -->
  449. <select id="findAllCount" resultType="long">
  450. SELECT
  451. COUNT(1)
  452. FROM sys_user a
  453. WHERE a.del_flag = #{DEL_FLAG_NORMAL}
  454. </select>
  455. <!-- 插入用户 -->
  456. <insert id="insert">
  457. INSERT INTO sys_user(
  458. id,
  459. com_id,
  460. company_id,
  461. office_id,
  462. login_name,
  463. password,
  464. no,
  465. name,
  466. sex,
  467. email,
  468. phone,
  469. mobile,
  470. ishide,
  471. user_type,
  472. create_by,
  473. create_date,
  474. update_by,
  475. update_date,
  476. remarks,
  477. login_flag,
  478. photo,
  479. default_photo,
  480. qrcode,
  481. password_remake,
  482. del_flag,
  483. first_flag
  484. ) VALUES (
  485. #{id},
  486. #{comId},
  487. #{company.id},
  488. #{office.id},
  489. #{loginName},
  490. #{password},
  491. #{no},
  492. #{name},
  493. #{sex},
  494. #{email},
  495. #{phone},
  496. #{mobile},
  497. #{ishide},
  498. #{userType},
  499. #{createBy.id},
  500. #{createDate},
  501. #{updateBy.id},
  502. #{updateDate},
  503. #{remarks},
  504. #{loginFlag},
  505. #{photo},
  506. #{defaultPhoto},
  507. #{qrCode},
  508. #{passwordRemake},
  509. #{delFlag},
  510. #{firstFlag}
  511. )
  512. </insert>
  513. <!-- 更新用户 -->
  514. <update id="update">
  515. UPDATE sys_user SET
  516. com_id = #{comId},
  517. company_id = #{company.id},
  518. office_id = #{office.id},
  519. login_name = #{loginName},
  520. password = #{password},
  521. no = #{no},
  522. name = #{name},
  523. sex = #{sex},
  524. email = #{email},
  525. phone = #{phone},
  526. mobile = #{mobile},
  527. ishide = #{ishide},
  528. user_type = #{userType},
  529. update_by = #{updateBy.id},
  530. update_date = #{updateDate},
  531. remarks = #{remarks},
  532. login_flag = #{loginFlag},
  533. photo = #{photo},
  534. default_photo = #{defaultPhoto},
  535. password_remake = #{passwordRemake},
  536. qrcode = #{qrCode}
  537. WHERE id = #{id}
  538. </update>
  539. <update id="updateUserState">
  540. UPDATE sys_user SET
  541. com_id = #{comId},
  542. company_id = #{company.id},
  543. office_id = #{office.id},
  544. update_by = #{updateBy.id},
  545. update_date = #{updateDate}
  546. WHERE id = #{id}
  547. </update>
  548. <!-- 删除用户和岗位关联表数据 -->
  549. <delete id="deleteUserRole">
  550. DELETE FROM sys_user_role WHERE user_id = #{id}
  551. <if test="role != null and role.id != null and role.id != ''">
  552. AND role_id = #{role.id}
  553. </if>
  554. </delete>
  555. <!-- 插入用户和岗位关联表数据 -->
  556. <insert id="insertUserRole">
  557. INSERT INTO sys_user_role(user_id, role_id)
  558. <foreach collection="roleList" item="role" separator=" union all ">
  559. SELECT #{id}, #{role.id} FROM dual
  560. </foreach>
  561. </insert>
  562. <!-- 更新用户信息 -->
  563. <update id="updateUserInfo">
  564. UPDATE sys_user SET
  565. com_id=#{comId},
  566. company_id = #{company.id},
  567. office_id = #{office.id},
  568. login_name = #{loginName},
  569. name = #{name},
  570. sex = #{sex},
  571. email = #{email},
  572. phone = #{phone},
  573. mobile = #{mobile},
  574. ishide = #{ishide},
  575. update_by = #{updateBy.id},
  576. update_date = #{updateDate},
  577. password_remake = #{passwordRemake},
  578. remarks = #{remarks},
  579. photo = #{photo},
  580. default_photo = #{defaultPhoto},
  581. qrcode = #{qrCode},
  582. sign = #{sign}
  583. WHERE id = #{id}
  584. </update>
  585. <update id="updateLoginFlag">
  586. UPDATE sys_user SET
  587. update_by = #{updateBy.id},
  588. update_date = #{updateDate},
  589. login_flag = #{loginFlag}
  590. WHERE id = #{id}
  591. </update>
  592. <!-- 更新手机号 -->
  593. <update id="updateMo">
  594. UPDATE sys_user SET
  595. login_name = #{loginName},
  596. phone = #{phone},
  597. mobile = #{mobile}
  598. WHERE id = #{id}
  599. </update>
  600. <!-- 更新用户密码 -->
  601. <update id="updatePasswordById">
  602. UPDATE sys_user SET
  603. password = #{password},
  604. password_remake = #{passwordRemake},
  605. first_flag = #{firstFlag}
  606. WHERE id = #{id}
  607. </update>
  608. <!-- 更新登录信息,如登录IP、登录时间 -->
  609. <update id="updateLoginInfo">
  610. UPDATE sys_user SET
  611. login_ip = #{loginIp},
  612. login_Date = #{loginDate}
  613. WHERE id = #{id}
  614. </update>
  615. <!-- 物理删除用户 -->
  616. <update id="delete">
  617. DELETE FROM sys_user
  618. WHERE id = #{id}
  619. </update>
  620. <!-- 逻辑删除用户 -->
  621. <update id="deleteByLogic">
  622. UPDATE sys_user SET
  623. del_flag = #{DEL_FLAG_DELETE}
  624. WHERE id = #{id}
  625. </update>
  626. <!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
  627. <select id="findUniqueByProperty" resultType="User" statementType="STATEMENT">
  628. select * from sys_user where ${propertyName} = '${value}'
  629. </select>
  630. <!-- 添加好友 -->
  631. <insert id="insertFriend">
  632. INSERT INTO sys_user_friend(
  633. id,
  634. userId,
  635. friendId,
  636. status,
  637. type,
  638. read_status,
  639. create_date
  640. ) VALUES (
  641. #{id},
  642. #{userId},
  643. #{friendId},
  644. #{status},
  645. #{type},
  646. 0,
  647. now()
  648. )
  649. </insert>
  650. <!-- 根据用户id和好友id获取唯一记录 -->
  651. <select id="findFriend" resultType="User">
  652. SELECT
  653. *
  654. FROM sys_user a
  655. LEFT JOIN sys_user_friend p ON p.userId = a.id
  656. WHERE p.userId = #{userId} and p.friendId = #{friendId} and p.status = '1'
  657. </select>
  658. <!-- 根据用户id和好友id获取唯一记录 -->
  659. <select id="findFriendInfo" resultType="User">
  660. SELECT
  661. <include refid="userColumns"/><!-- ,
  662. ro.office_id AS "roleList.officeList.id" -->
  663. ,p.status AS "auditStatus"
  664. FROM sys_user a
  665. LEFT JOIN sys_office s ON s.id = a.company_id
  666. LEFT JOIN sys_office o ON o.id = a.office_id
  667. LEFT JOIN sys_office bo ON bo.id = o.branch_office
  668. LEFT JOIN sys_user_friend p ON p.friendId = a.id
  669. WHERE p.userId = #{userId} and p.friendId = #{friendId} and p.type = '1'
  670. </select>
  671. <!-- 根据用户id和好友id获取唯一记录 -->
  672. <select id="findFriendByStatus" resultType="User">
  673. SELECT
  674. *
  675. FROM sys_user a
  676. LEFT JOIN sys_user_friend p ON p.userId = a.id
  677. WHERE p.userId = #{userId} and p.friendId = #{friendId} and p.status != '2'
  678. </select>
  679. <!-- 删除好友 -->
  680. <select id="deleteFriend">
  681. DELETE FROM sys_user_friend WHERE userId = #{userId} and friendId = #{friendId}
  682. </select>
  683. <update id="friendAudit">
  684. UPDATE sys_user_friend SET status = '1',create_date = now() WHERE userId = #{userId} and friendId = #{friendId}
  685. </update>
  686. <update id="updateUserRead">
  687. UPDATE sys_user_friend SET read_status = '1' WHERE userId = #{userId} and status != '0' and friendId = #{friendId}
  688. </update>
  689. <update id="updateUserReadAll">
  690. UPDATE sys_user_friend SET read_status = '1' WHERE userId = #{userId} and status != '0'
  691. </update>
  692. <update id="friendAuditNo">
  693. UPDATE sys_user_friend SET status = '2',create_date = now() WHERE userId = #{userId} and friendId = #{friendId}
  694. </update>
  695. <!-- 查询我的好友列表 -->
  696. <select id="findFriends" resultType="User">
  697. SELECT
  698. <include refid="userColumns"/><!-- ,
  699. ro.office_id AS "roleList.officeList.id" -->
  700. FROM sys_user a
  701. LEFT JOIN sys_office s ON s.id = a.company_id
  702. LEFT JOIN sys_office o ON o.id = a.office_id
  703. LEFT JOIN sys_office bo ON bo.id = o.branch_office
  704. LEFT JOIN sys_user_friend p ON p.friendId = a.id
  705. WHERE p.userId = #{id} and p.status = '1'
  706. </select>
  707. <!-- 查询我的待审批列表 -->
  708. <select id="findFriendsAudit" resultType="User">
  709. SELECT
  710. <include refid="userColumns"/><!-- ,
  711. ro.office_id AS "roleList.officeList.id" -->,
  712. p.type AS "friendType"
  713. FROM sys_user a
  714. LEFT JOIN sys_office s ON s.id = a.company_id
  715. LEFT JOIN sys_office o ON o.id = a.office_id
  716. LEFT JOIN sys_office bo ON bo.id = o.branch_office
  717. LEFT JOIN sys_user_friend p ON p.friendId = a.id
  718. WHERE p.userId = #{id} and p.status = '0'
  719. </select>
  720. <!-- 根据条件检索用户,添加到好友列表 -->
  721. <select id="searchUsers" resultType="User">
  722. SELECT
  723. <include refid="userColumns"/><!-- ,
  724. ro.office_id AS "roleList.officeList.id" -->
  725. FROM sys_user a
  726. LEFT JOIN sys_office s ON s.id = a.company_id
  727. LEFT JOIN sys_office o ON o.id = a.office_id
  728. LEFT JOIN sys_office bo ON bo.id = o.branch_office
  729. where 1=1
  730. <if test="name != null and name != ''">
  731. and a.name like
  732. <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
  733. <if test="dbName == 'mysql'">CONCAT('%', #{name}, '%')</if>
  734. </if>
  735. <if test="mobile != null and mobile != ''">
  736. and a.mobile like
  737. <if test="dbName == 'oracle'">'%'||#{mobile}||'%'</if>
  738. <if test="dbName == 'mysql'">CONCAT('%', #{mobile}, '%')</if>
  739. </if>
  740. <if test="company != null and company.id != null and company.id !='' ">
  741. AND a.company_id = #{company.id}
  742. </if>
  743. <!-- 根据手机号查询 -->
  744. </select>
  745. <!-- 根据条件检索用户,添加到好友列表 -->
  746. <select id="findFriendByMobileOrName" resultType="User">
  747. SELECT
  748. <include refid="userColumns"/><!-- ,
  749. ro.office_id AS "roleList.officeList.id" -->
  750. FROM sys_user a
  751. LEFT JOIN sys_user_office uo ON uo.user_id = a.id AND uo.company_id = #{company.id} AND uo.status = '3' AND uo.del_flag = '0'
  752. LEFT JOIN sys_office s ON s.id = uo.company_id
  753. LEFT JOIN sys_office o ON o.id = uo.office_id
  754. LEFT JOIN sys_office bo ON bo.id = o.branch_office
  755. where 1=1
  756. <if test="name != null and name != ''">
  757. and a.name like
  758. <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
  759. <if test="dbName == 'mysql'">CONCAT('%', #{name}, '%')</if>
  760. </if>
  761. <if test="mobile != null and mobile != ''">
  762. and a.mobile = #{mobile}
  763. </if>
  764. <!-- 根据手机号查询 -->
  765. </select>
  766. <!-- 根据条件检索用户,添加到好友列表 -->
  767. <select id="findFriendByMobileOrUserName" resultType="User">
  768. SELECT
  769. <include refid="userColumns"/><!-- ,
  770. ro.office_id AS "roleList.officeList.id" -->
  771. FROM sys_user a
  772. LEFT JOIN sys_user_office uo ON uo.user_id = a.id AND uo.company_id = #{company.id} AND uo.status = '3' AND uo.del_flag = '0'
  773. LEFT JOIN sys_office s ON s.id = uo.company_id
  774. LEFT JOIN sys_office o ON o.id = uo.office_id
  775. LEFT JOIN sys_office bo ON bo.id = o.branch_office
  776. where 1=1
  777. <if test="name != null and name != ''">
  778. and a.name = #{name}
  779. </if>
  780. <if test="mobile != null and mobile != ''">
  781. and a.mobile = #{mobile}
  782. </if>
  783. <!-- 根据手机号查询 -->
  784. </select>
  785. <!-- 根据条件检索用户,添加到好友列表 -->
  786. <select id="findUserByMobileOrName" resultType="User">
  787. SELECT
  788. <include refid="userColumns"/><!-- ,
  789. ro.office_id AS "roleList.officeList.id" -->
  790. FROM sys_user a
  791. JOIN sys_user_friend f ON f.friendId = a.id AND f.status = '1' AND f.userId = #{id}
  792. LEFT JOIN sys_office s ON s.id = a.company_id
  793. LEFT JOIN sys_office o ON o.id = a.office_id
  794. LEFT JOIN sys_office bo ON bo.id = o.branch_office
  795. where 1=1
  796. <if test="name != null and name != ''">
  797. and a.name like
  798. <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
  799. <if test="dbName == 'mysql'">CONCAT('%', #{name}, '%')</if>
  800. </if>
  801. <if test="mobile != null and mobile != ''">
  802. and a.mobile = #{mobile}
  803. </if>
  804. <!-- 根据手机号查询 -->
  805. </select>
  806. <!-- 根据条件检索用户,添加到好友列表 -->
  807. <select id="findFriendAll" resultType="User">
  808. SELECT
  809. <include refid="userColumns"/><!-- ,
  810. ro.office_id AS "roleList.officeList.id" -->
  811. ,f.status AS "auditStatus"
  812. FROM sys_user a
  813. JOIN sys_user_friend f ON f.friendId = a.id AND f.type = '1' AND f.userId = #{id}
  814. LEFT JOIN sys_office s ON s.id = a.company_id
  815. LEFT JOIN sys_office o ON o.id = a.office_id
  816. LEFT JOIN sys_office bo ON bo.id = o.branch_office
  817. where 1=1
  818. <if test="name != null and name != ''">
  819. and a.name like
  820. <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
  821. <if test="dbName == 'mysql'">CONCAT('%', #{name}, '%')</if>
  822. </if>
  823. <if test="mobile != null and mobile != ''">
  824. and a.mobile = #{mobile}
  825. </if>
  826. <!-- 根据手机号查询 -->
  827. </select>
  828. <!-- 根据条件检索用户,查询申请的好友列表 -->
  829. <select id="findUserByStatus" resultType="User">
  830. SELECT
  831. <include refid="userColumns"/><!-- ,
  832. ro.office_id AS "roleList.officeList.id" -->
  833. FROM sys_user a
  834. JOIN sys_user_friend f ON f.friendId = a.id AND f.status = '0' AND f.userId = #{id} AND f.type = '1'
  835. LEFT JOIN sys_office s ON s.id = a.company_id
  836. LEFT JOIN sys_office o ON o.id = a.office_id
  837. LEFT JOIN sys_office bo ON bo.id = o.branch_office
  838. <!-- 根据手机号查询 -->
  839. </select>
  840. <select id="findUserByStatusAudit" resultType="User">
  841. SELECT
  842. <include refid="userColumns"/><!-- ,
  843. ro.office_id AS "roleList.officeList.id" -->
  844. ,f.status AS "auditStatus"
  845. FROM sys_user a
  846. JOIN sys_user_friend f ON f.friendId = a.id AND f.status != '0' AND f.userId = #{id} AND f.type = '0' AND f.read_status = 0
  847. LEFT JOIN sys_office s ON s.id = a.company_id
  848. LEFT JOIN sys_office o ON o.id = a.office_id
  849. LEFT JOIN sys_office bo ON bo.id = o.branch_office
  850. ORDER BY f.create_date DESC
  851. <!-- 根据手机号查询 -->
  852. </select>
  853. <!-- 根据role查询user -->
  854. <select id="findUserByRole" resultType="User" parameterType="Role">
  855. SELECT
  856. a.*
  857. FROM sys_user a
  858. LEFT JOIN sys_user_role ur ON ur.user_id = a.id
  859. WHERE ur.role_id = #{id} AND a.del_flag = #{DEL_FLAG_NORMAL}
  860. </select>
  861. <select id="findUserByMobile" resultType="User">
  862. SELECT
  863. LEFT JOIN sys_office s ON s.id = a.company_id
  864. LEFT JOIN sys_office o ON o.id = a.office_id
  865. LEFT JOIN sys_office bo ON bo.id = o.branch_office
  866. FROM sys_user a
  867. <include refid="userJoins"/>
  868. WHERE a.mobile=#{mobile} AND a.del_flag = #{DEL_FLAG_NORMAL}
  869. </select>
  870. <select id="getUserById" resultType="User">
  871. SELECT
  872. a.id,
  873. a.com_id AS "comId",
  874. a.company_id AS "company.id",
  875. a.office_id AS "office.id",
  876. a.login_name,
  877. a.password,
  878. a.password_remake AS "passwordRemake",
  879. a.no,
  880. a.name,
  881. a.sex,
  882. a.email,
  883. a.phone,
  884. a.mobile,
  885. a.ishide,
  886. a.user_type,
  887. a.login_ip,
  888. a.login_date,
  889. a.remarks,
  890. a.login_flag,
  891. a.photo,
  892. a.default_photo,
  893. a.qrcode,
  894. a.sign,
  895. a.create_by AS "createBy.id",
  896. a.create_date,
  897. a.update_by AS "updateBy.id",
  898. a.update_date,
  899. a.del_flag,
  900. a.first_flag AS "firstFlag"
  901. FROM sys_user a
  902. WHERE a.id = #{id}
  903. </select>
  904. <select id="findListByRoleList" resultType="User">
  905. SELECT
  906. a.id,a.name,a.photo,a.login_name AS "loginName"
  907. FROM sys_user a
  908. JOIN sys_user_role ur ON ur.user_id = a.id
  909. JOIN sys_role r ON ur.role_id = r.id
  910. WHERE a.office_id is not null and find_in_set(r.id,#{roleIds})
  911. </select>
  912. <!-- 依据部门编号查询岗位 -->
  913. <select id="queryRole" parameterType="java.lang.String" resultType="java.util.HashMap">
  914. select * from sys_role where company_id = #{officeId}
  915. </select>
  916. <select id="queryListByIds" resultType="User">
  917. SELECT * FROM sys_user
  918. WHERE id IN
  919. <foreach collection="array" index="index" item="item"
  920. open="(" separator="," close=")">
  921. #{item}
  922. </foreach>
  923. </select>
  924. <select id="findUserRole" resultType="java.util.HashMap" parameterType="java.lang.String">
  925. SELECT * FROM sys_user_role
  926. WHERE user_id=#{userId} and role_id=#{roleId}
  927. </select>
  928. <select id="findUserByRoles" resultType="User" parameterType="java.lang.String">
  929. select
  930. <include refid="userColumns"/>
  931. from sys_user a
  932. LEFT JOIN sys_office s ON s.id = a.company_id
  933. LEFT JOIN sys_office o ON o.id = a.office_id
  934. LEFT JOIN sys_office bo ON bo.id = o.branch_office
  935. where a.id in (
  936. select r.user_id from sys_user_role r where r.role_id in (
  937. SELECT
  938. s.role_id
  939. FROM
  940. sys_role_activity_relation s
  941. WHERE
  942. s.role_activity_id IN (
  943. SELECT
  944. w.role_id
  945. FROM
  946. sys_warning_role w
  947. WHERE
  948. w.warning_id =#{id}
  949. )))
  950. </select>
  951. <select id="findUserByUser" resultType="User" parameterType="java.lang.String">
  952. select
  953. <include refid="userColumns"/>
  954. from sys_user a
  955. LEFT JOIN sys_office s ON s.id = a.company_id
  956. LEFT JOIN sys_office o ON o.id = a.office_id
  957. LEFT JOIN sys_office bo ON bo.id = o.branch_office
  958. where a.id in ( SELECT
  959. w.user_id
  960. FROM
  961. sys_warning_user w
  962. WHERE
  963. w.warning_id =#{id})
  964. </select>
  965. <select id="userCount" resultType="java.lang.Integer" >
  966. SELECT
  967. count(*)
  968. FROM sys_user a
  969. WHERE a.office_id = #{officeId} AND a.del_flag = 0
  970. </select>
  971. <select id="countByOffice" resultType="int">
  972. SELECT
  973. count(*)
  974. FROM sys_user a
  975. LEFT JOIN work_staff_achives uo ON uo.user_id = a.id
  976. LEFT JOIN sys_office o ON o.id = uo.office_id
  977. WHERE a.del_flag = #{DEL_FLAG_NORMAL}
  978. AND uo.del_flag = #{DEL_FLAG_NORMAL}
  979. AND o.useable = '1'
  980. AND o.del_flag = #{DEL_FLAG_NORMAL}
  981. AND uo.status IN ('试用','正式','劳务')
  982. AND (o.id = #{office.id} OR find_in_set(#{office.id},o.parent_ids))
  983. </select>
  984. <select id="findUserByOfficeRole" resultType="User">
  985. SELECT DISTINCT ur.user_id as 'id' FROM sys_role a
  986. LEFT JOIN sys_user_role ur ON ur.role_id = a.id
  987. LEFT JOIN sys_office o ON o.id = a.office_id
  988. WHERE o.id = #{id} or find_in_set(#{id},o.parent_ids)
  989. </select>
  990. <update id="updateUserCompanyId">
  991. UPDATE sys_user SET com_id = '1',company_id = '1',office_id='5' WHERE company_id=#{companyId}
  992. </update>
  993. </mapper>