UserMapper.xml 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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.diagbot.mapper.UserMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.diagbot.entity.User">
  6. <id column="id" property="id" />
  7. <result column="is_deleted" property="isDeleted" />
  8. <result column="gmt_create" property="gmtCreate" />
  9. <result column="gmt_modified" property="gmtModified" />
  10. <result column="creator" property="creator" />
  11. <result column="modifier" property="modifier" />
  12. <result column="password" property="password" />
  13. <result column="username" property="username" />
  14. <result column="linkman" property="linkman" />
  15. <result column="email" property="email" />
  16. <result column="type" property="type" />
  17. </resultMap>
  18. <resultMap id="UserOrgDTO" type="com.diagbot.dto.UserOrgDTO">
  19. <id column="user_id" property="userId" />
  20. <result column="username" property="username" />
  21. <result column="linkman" property="linkman" />
  22. <result column="email" property="email" />
  23. <result column="org_id" property="orgId" />
  24. <result column="org_name" property="orgName" />
  25. <result column="is_reject" property="isReject" />
  26. <result column="au_status" property="auStatus" />
  27. <result column="sub_num" property="subNum" />
  28. </resultMap>
  29. <select id="findByName" resultMap="BaseResultMap" parameterType="java.lang.String">
  30. select * from sys_user
  31. where username = #{username} and is_deleted = 'N'
  32. </select>
  33. <select id="selectUserListPage" resultMap="BaseResultMap">
  34. select u.*
  35. from sys_user u
  36. LEFT JOIN sys_user_role ur on u.id= ur.user_id
  37. LEFT JOIN sys_role r on ur.role_id=r.id
  38. where u.is_deleted = 'N'
  39. <if test="user.id != null">
  40. and u.id = #{user.id}
  41. </if>
  42. </select>
  43. <select id="indexPage" resultMap="BaseResultMap">
  44. select u.* from sys_user u where u.is_deleted = 'N'
  45. <if test="user.id != null">
  46. and u.id = #{user.id}
  47. </if>
  48. <if test="user.username != null and user.username != '' ">
  49. and u.username like concat('%',#{user.username},'%')
  50. </if>
  51. </select>
  52. <select id="getByIds" resultMap="BaseResultMap">
  53. select u.* from sys_user u where u.is_deleted = 'N'
  54. and u.id in
  55. <foreach collection="list" item="ids" open="(" close=")" separator=",">
  56. #{ids}
  57. </foreach>
  58. </select>
  59. <select id="getUserOrgDTOByIds" resultMap="UserOrgDTO">
  60. select u.id user_id ,u.username username, u.email email, u.linkman linkman , org.id org_id, org.name org_name, ua.is_reject is_reject, ua.status au_status,org.sub_num
  61. from sys_user u, sys_user_organization uo, sys_organization org , sys_user_authentication ua
  62. where u.is_deleted = 'N' and uo.is_deleted = 'N' and org.is_deleted = 'N'
  63. and u.id = uo.user_id and uo.organization_id = org.id and u.id = ua.user_id
  64. and u.id in
  65. <foreach collection="list" item="ids" open="(" close=")" separator=",">
  66. #{ids}
  67. </foreach>
  68. </select>
  69. <!-- <select id="selectUserInfoListPage" resultMap="BaseResultMap">
  70. select u.*
  71. LEFT JOIN sys_user_role ur on u.id= ur.user_id
  72. LEFT JOIN
  73. sys_role r on ur.role_id=r.id
  74. where u.is_deleted = 'N' and type = "0"
  75. ORDER BY gmt_create DESC
  76. </select> -->
  77. <!-- <select id="selectUserInfoPage" parameterType="com.diagbot.dto.UserInfoDTO" resultType="com.diagbot.dto.UserInfoDTO">
  78. SELECT
  79. u.id AS userId,
  80. u.gmt_create as userGmtCreate,
  81. u.username as userName,
  82. u.linkman as linKman,
  83. u.email as email,
  84. org.id AS orgId,
  85. org.gmt_create as orgGmtCreate,
  86. org.name as orgName
  87. FROM sys_user u
  88. LEFT JOIN sys_user_organization uorg ON u.id = uorg.user_id
  89. LEFT JOIN sys_organization org ON uorg.organization_id = org.id
  90. WHERE u.is_deleted = 'N' AND u.TYPE = 0 ORDER BY u.gmt_create DESC
  91. </select> -->
  92. <select id="selectUserInfoListPage" resultType="com.diagbot.dto.UserInfoDTO">
  93. SELECT
  94. u.id AS userId,
  95. u.gmt_create AS userGmtCreate,
  96. u.username AS userName,
  97. u.linkman AS linKman,
  98. u.email AS email,
  99. org.id AS orgId,
  100. org.gmt_create AS orgGmtCreate,
  101. org.name AS orgName,
  102. org.type as orgType,
  103. org.principal AS orgPrincipal,
  104. org.address as orgAddress,
  105. org.parent_id as orgParent_id,
  106. org.sub_num as orgSub_num,
  107. aut.position as autPosition,
  108. aut.is_reject as autIsReject,
  109. aut.status as autStatus
  110. FROM sys_user u
  111. LEFT JOIN sys_user_organization uorg ON u.id = uorg.user_id
  112. LEFT JOIN sys_organization org ON uorg.organization_id = org.id
  113. LEFT JOIN sys_user_authentication aut ON u.id = aut.user_id
  114. WHERE u.is_deleted = 'N' AND u.TYPE = 0
  115. <if test="userInfo.orgName != null">
  116. AND org.name LIKE CONCAT('%', #{userInfo.orgName}, '%')
  117. </if>
  118. <if test="userInfo.autStatus != null">
  119. AND aut.status = #{userInfo.autStatus}
  120. </if>
  121. ORDER BY u.gmt_create DESC
  122. </select>
  123. <update id="updateUserInfoAll" parameterType="java.util.Map" >
  124. UPDATE sys_user u ,sys_user_organization a ,
  125. sys_organization b ,sys_user_authentication c
  126. SET u.remark = "0"
  127. <if test="userMap.email != null">
  128. <if test="userMap.gmtModified !=null">
  129. ,u.gmt_modified=#{userMap.gmtModified}
  130. </if>
  131. <if test="userMap.modifier != null">
  132. ,u.modifier=#{userMap.modifier}
  133. </if>
  134. ,u.email=#{userMap.email}
  135. </if>
  136. <if test="userMap.principal != null || userMap.address != null || userMap.type != null">
  137. <if test="userMap.gmtModified !=null">
  138. ,b.gmt_modified=#{userMap.gmtModified}
  139. </if>
  140. <if test="userMap.modifier != null">
  141. ,b.modifier=#{userMap.modifier}
  142. </if>
  143. <if test="userMap.principal != null">
  144. ,b.principal=#{userMap.principal}
  145. </if>
  146. <if test="userMap.address != null">
  147. ,b.address=#{userMap.address}
  148. </if>
  149. <if test="userMap.type != null">
  150. ,b.type=#{userMap.type}
  151. </if>
  152. </if>
  153. <!-- <if test="position != null || isReject != null || rejectType !=null || rejectComment !=null || status != null"> -->
  154. <if test="userMap.position != null">
  155. <if test="userMap.gmtModified !=null">
  156. ,c.gmt_modified=#{userMap.gmtModified}
  157. </if>
  158. <if test="userMap.modifier != null">
  159. ,c.modifier=#{userMap.modifier}
  160. </if>
  161. ,c.position=#{userMap.position}
  162. </if>
  163. <!-- <if test="isReject != null">
  164. ,c.is_reject=#{isReject}
  165. </if>
  166. <if test="rejectType !=null">
  167. ,c.reject_type=#{rejectType}
  168. </if>
  169. <if test="rejectComment !=null">
  170. ,c.reject_comment=#{rejectComment}
  171. </if>
  172. <if test="status != null">
  173. ,c.status = #{status}
  174. </if> -->
  175. <!-- </if> -->
  176. WHERE
  177. u.is_deleted = "N"
  178. AND u.id = #{userMap.userId}
  179. AND c.user_id= #{userMap.userId}
  180. AND a.user_id = #{userMap.userId}
  181. AND a.organization_id =b.id
  182. </update>
  183. <update id="updateDeleted" parameterType="java.util.Map">
  184. UPDATE sys_user u ,sys_user_organization a ,
  185. sys_organization b,sys_user_authentication c
  186. SET u.is_deleted = "Y",a.is_deleted= "Y",b.is_deleted= "Y",c.is_deleted="Y"
  187. <if test="map.gmtModified !=null">
  188. ,u.gmt_modified=#{map.gmtModified}
  189. ,b.gmt_modified=#{map.gmtModified}
  190. ,c.gmt_modified=#{map.gmtModified}
  191. </if>
  192. <if test="map.modifier != null">
  193. ,u.modifier=#{map.modifier}
  194. ,b.modifier=#{map.modifier}
  195. ,c.modifier=#{map.modifier}
  196. </if>
  197. WHERE u.id = #{map.userId}
  198. AND c.user_id= #{map.userId}
  199. AND a.user_id = #{map.userId}
  200. AND a.organization_id =b.id
  201. </update>
  202. <update id="auditUserInfoAll" parameterType="java.util.Map">
  203. UPDATE sys_user_authentication
  204. <trim prefix="set" suffixOverrides=",">
  205. <if test="auditMap.gmtModified !=null">gmt_modified=#{auditMap.gmtModified},</if>
  206. <if test="auditMap.modifier != null">modifier=#{auditMap.modifier},</if>
  207. <if test="auditMap.isReject != null">is_reject = #{auditMap.isReject} ,</if>
  208. <if test="auditMap.rejectType != null">reject_type =#{auditMap.rejectType},</if>
  209. <if test="auditMap.rejectComment != null">reject_comment= #{auditMap.rejectComment},</if>
  210. <if test="auditMap.status != null">STATUS= #{auditMap.status}</if>
  211. </trim>
  212. WHERE
  213. user_id = #{auditMap.userId}
  214. AND is_deleted = "N"
  215. </update>
  216. <select id="dependentuserInfoByTime" parameterType="java.util.Map" resultType="com.diagbot.dto.UserInfoExportDTO" >
  217. SELECT
  218. u.id AS userId,
  219. u.gmt_create AS userGmtCreate,
  220. u.username AS userName,
  221. u.linkman AS linKman,
  222. u.email AS email,
  223. org.id AS orgId,
  224. org.gmt_create AS orgGmtCreate,
  225. org.name AS orgName,
  226. org.type,
  227. org.principal AS orgPrincipal,
  228. org.address,
  229. org.parent_id,
  230. org.sub_num,
  231. aut.position,
  232. aut.is_reject,
  233. aut.status
  234. FROM sys_user u
  235. LEFT JOIN sys_user_organization uorg ON u.id = uorg.user_id
  236. LEFT JOIN sys_organization org ON uorg.organization_id = org.id
  237. LEFT JOIN sys_user_authentication aut ON u.id = aut.user_id
  238. WHERE
  239. u.is_deleted = 'N'
  240. AND u.TYPE = "0"
  241. <if test="userExport.orgName != null">
  242. AND org.name LIKE CONCAT('%', #{userInfo.orgName}, '%')
  243. </if>
  244. <if test="userExport.autStatus != null">
  245. AND aut.status = #{userInfo.autStatus}
  246. </if>
  247. <if test="userExport.startTime != null and userExport.endDate != null">
  248. AND u.gmt_create BETWEEN #{userExport.startTime} and #{userExport.endTime}
  249. </if>
  250. ORDER BY u.gmt_create DESC
  251. </select>
  252. </mapper>