CompanyUserMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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.fs.company.mapper.CompanyUserMapper">
  6. <resultMap type="CompanyUser" id="CompanyUserResult">
  7. <result property="userId" column="user_id" />
  8. <result property="companyId" column="company_id" />
  9. <result property="deptId" column="dept_id" />
  10. <result property="userName" column="user_name" />
  11. <result property="nickName" column="nick_name" />
  12. <result property="userType" column="user_type" />
  13. <result property="email" column="email" />
  14. <result property="phonenumber" column="phonenumber" />
  15. <result property="sex" column="sex" />
  16. <result property="avatar" column="avatar" />
  17. <result property="idCard" column="id_card" />
  18. <result property="password" column="password" />
  19. <result property="status" column="status" />
  20. <result property="delFlag" column="del_flag" />
  21. <result property="loginIp" column="login_ip" />
  22. <result property="loginDate" column="login_date" />
  23. <result property="createBy" column="create_by" />
  24. <result property="createTime" column="create_time" />
  25. <result property="updateBy" column="update_by" />
  26. <result property="updateTime" column="update_time" />
  27. <result property="token" column="token" />
  28. <result property="remark" column="remark" />
  29. <result property="openId" column="open_id" />
  30. <result property="qrCodeWeixin" column="qr_code_weixin" />
  31. <result property="qrCodeWecom" column="qr_code_wecom" />
  32. <result property="jpushId" column="jpush_id" />
  33. <result property="firstchar" column="firstchar" />
  34. <result property="postName" column="post_name" />
  35. <result property="deptName" column="dept_name" />
  36. <result property="qwUserId" column="qw_user_id" />
  37. <result property="qwStatus" column="qw_status" />
  38. <result property="voicePrintUrl" column="voice_print_url" />
  39. <result property="addressId" column="address_id" />
  40. <result property="domain" column="domain" />
  41. <association property="dept" column="dept_id" javaType="CompanyDept" resultMap="deptResult" />
  42. <collection property="roles" javaType="java.util.List" resultMap="RoleResult" />
  43. </resultMap>
  44. <resultMap id="deptResult" type="CompanyDept">
  45. <id property="deptId" column="dept_id" />
  46. <result property="parentId" column="parent_id" />
  47. <result property="deptName" column="dept_name" />
  48. <result property="orderNum" column="order_num" />
  49. <result property="leader" column="leader" />
  50. <result property="status" column="dept_status" />
  51. </resultMap>
  52. <resultMap id="RoleResult" type="CompanyRole">
  53. <id property="roleId" column="role_id" />
  54. <result property="roleName" column="role_name" />
  55. <result property="roleKey" column="role_key" />
  56. <result property="roleSort" column="role_sort" />
  57. <result property="dataScope" column="data_scope" />
  58. <result property="status" column="role_status" />
  59. </resultMap>
  60. <select id="selectCompanyUserList" parameterType="CompanyUser" resultMap="CompanyUserResult">
  61. select u.*, d.dept_name, d.leader from company_user u
  62. left join company_dept d on u.dept_id = d.dept_id
  63. where u.del_flag = '0'
  64. <if test="userName != null and userName != ''">
  65. AND u.user_name like concat( #{userName}, '%')
  66. </if>
  67. <if test="nickName != null and nickName != ''">
  68. AND u.nick_name like concat( #{nickName}, '%')
  69. </if>
  70. <if test="companyId != null and companyId != ''">
  71. AND u.company_id = #{companyId}
  72. </if>
  73. <if test="status != null and status != ''">
  74. AND u.status = #{status}
  75. </if>
  76. <if test="phonenumber != null and phonenumber != ''">
  77. AND u.phonenumber like concat('%', #{phonenumber}, '%')
  78. </if>
  79. <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
  80. AND date_format(u.create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
  81. </if>
  82. <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
  83. AND date_format(u.create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
  84. </if>
  85. <if test="deptId != null and deptId != 0">
  86. AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM company_dept t WHERE find_in_set(#{deptId}, ancestors) ))
  87. </if>
  88. <!-- 数据范围过滤 -->
  89. ${params.dataScope}
  90. </select>
  91. <select id="selectCompanyUserById" parameterType="Long" resultMap="CompanyUserResult">
  92. <include refid="selectUserVo"/>
  93. where u.user_id = #{userId}
  94. </select>
  95. <insert id="insertCompanyUser" parameterType="CompanyUser" useGeneratedKeys="true" keyProperty="userId">
  96. insert into company_user
  97. <trim prefix="(" suffix=")" suffixOverrides=",">
  98. <if test="companyId != null">company_id,</if>
  99. <if test="deptId != null">dept_id,</if>
  100. <if test="userName != null and userName != ''">user_name,</if>
  101. <if test="nickName != null and nickName != ''">nick_name,</if>
  102. <if test="userType != null">user_type,</if>
  103. <if test="email != null">email,</if>
  104. <if test="phonenumber != null">phonenumber,</if>
  105. <if test="sex != null">sex,</if>
  106. <if test="avatar != null">avatar,</if>
  107. <if test="idCard != null">id_card,</if>
  108. <if test="password != null">password,</if>
  109. <if test="status != null">status,</if>
  110. <if test="delFlag != null">del_flag,</if>
  111. <if test="loginIp != null">login_ip,</if>
  112. <if test="loginDate != null">login_date,</if>
  113. <if test="createBy != null">create_by,</if>
  114. <if test="createTime != null">create_time,</if>
  115. <if test="updateBy != null">update_by,</if>
  116. <if test="updateTime != null">update_time,</if>
  117. <if test="token != null">token,</if>
  118. <if test="remark != null">remark,</if>
  119. <if test="openId != null">open_id,</if>
  120. <if test="qrCodeWeixin != null">qr_code_weixin,</if>
  121. <if test="qrCodeWecom != null">qr_code_wecom,</if>
  122. <if test="jpushId != null">jpush_id,</if>
  123. <if test="qwUserId != null">qw_user_id,</if>
  124. <if test="qwStatus != null">qw_status,</if>
  125. <if test="voicePrintUrl != null">voice_print_url,</if>
  126. <if test="addressId != null">address_id,</if>
  127. <if test="domain != null">domain,</if>
  128. </trim>
  129. <trim prefix="values (" suffix=")" suffixOverrides=",">
  130. <if test="companyId != null">#{companyId},</if>
  131. <if test="deptId != null">#{deptId},</if>
  132. <if test="userName != null and userName != ''">#{userName},</if>
  133. <if test="nickName != null and nickName != ''">#{nickName},</if>
  134. <if test="userType != null">#{userType},</if>
  135. <if test="email != null">#{email},</if>
  136. <if test="phonenumber != null">#{phonenumber},</if>
  137. <if test="sex != null">#{sex},</if>
  138. <if test="avatar != null">#{avatar},</if>
  139. <if test="idCard != null">#{idCard},</if>
  140. <if test="password != null">#{password},</if>
  141. <if test="status != null">#{status},</if>
  142. <if test="delFlag != null">#{delFlag},</if>
  143. <if test="loginIp != null">#{loginIp},</if>
  144. <if test="loginDate != null">#{loginDate},</if>
  145. <if test="createBy != null">#{createBy},</if>
  146. <if test="createTime != null">#{createTime},</if>
  147. <if test="updateBy != null">#{updateBy},</if>
  148. <if test="updateTime != null">#{updateTime},</if>
  149. <if test="token != null">#{token},</if>
  150. <if test="remark != null">#{remark},</if>
  151. <if test="openId != null">#{openId},</if>
  152. <if test="qrCodeWeixin != null">#{qrCodeWeixin},</if>
  153. <if test="qrCodeWecom != null">#{qrCodeWecom},</if>
  154. <if test="jpushId != null">#{jpushId},</if>
  155. <if test="qwUserId != null">#{qwUserId},</if>
  156. <if test="qwStatus != null">#{qwStatus},</if>
  157. <if test="voicePrintUrl != null">#{voicePrintUrl},</if>
  158. <if test="addressId != null">#{addressId},</if>
  159. <if test="domain != null">#{domain},</if>
  160. </trim>
  161. </insert>
  162. <update id="updateCompanyUser" parameterType="CompanyUser">
  163. update company_user
  164. <trim prefix="SET" suffixOverrides=",">
  165. <if test="companyId != null">company_id = #{companyId},</if>
  166. <if test="deptId != null">dept_id = #{deptId},</if>
  167. <if test="userName != null and userName != ''">user_name = #{userName},</if>
  168. <if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
  169. <if test="userType != null">user_type = #{userType},</if>
  170. <if test="email != null">email = #{email},</if>
  171. <if test="phonenumber != null">phonenumber = #{phonenumber},</if>
  172. <if test="sex != null">sex = #{sex},</if>
  173. <if test="avatar != null">avatar = #{avatar},</if>
  174. <if test="idCard != null">id_card = #{idCard},</if>
  175. <if test="password != null and password != '' ">password = #{password},</if>
  176. <if test="status != null">status = #{status},</if>
  177. <if test="delFlag != null">del_flag = #{delFlag},</if>
  178. <if test="loginIp != null">login_ip = #{loginIp},</if>
  179. <if test="loginDate != null">login_date = #{loginDate},</if>
  180. <if test="createBy != null">create_by = #{createBy},</if>
  181. <if test="createTime != null">create_time = #{createTime},</if>
  182. <if test="updateBy != null">update_by = #{updateBy},</if>
  183. <if test="updateTime != null">update_time = #{updateTime},</if>
  184. <if test="token != null">token = #{token},</if>
  185. <if test="remark != null">remark = #{remark},</if>
  186. <if test="qrCodeWeixin != null">qr_code_weixin = #{qrCodeWeixin},</if>
  187. <if test="qrCodeWecom != null">qr_code_wecom = #{qrCodeWecom},</if>
  188. <if test="jpushId != null">jpush_id = #{jpushId},</if>
  189. <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
  190. <if test="qwStatus != null">qw_status = #{qwStatus},</if>
  191. <if test="voicePrintUrl != null">voice_print_url = #{voicePrintUrl},</if>
  192. <if test="addressId != null">address_id = #{addressId},</if>
  193. <if test="domain != null">domain = #{domain},</if>
  194. </trim>
  195. where user_id = #{userId}
  196. </update>
  197. <delete id="deleteCompanyUserById" parameterType="Long">
  198. delete from company_user where user_id = #{userId}
  199. </delete>
  200. <delete id="deleteCompanyUserByIds" parameterType="String">
  201. delete from company_user where user_id in
  202. <foreach item="userId" collection="array" open="(" separator="," close=")">
  203. #{userId}
  204. </foreach>
  205. </delete>
  206. <update id="updateUserAvatar" parameterType="SysUser">
  207. update company_user set avatar = #{avatar} where user_name = #{userName}
  208. </update>
  209. <update id="resetUserPwd" parameterType="SysUser">
  210. update company_user set password = #{password} where user_name = #{userName}
  211. </update>
  212. <select id="selectUserByUserName" parameterType="String" resultMap="CompanyUserResult">
  213. <include refid="selectUserVo"/>
  214. where u.user_name = #{userName}
  215. </select>
  216. <select id="selectCompanyQwUserByIds" resultType="com.fs.company.vo.CompanyQwUserByIdsVo">
  217. SELECT b.user_id,b.company_id,a.qw_user_id,a.qw_user_name,b.nick_name
  218. FROM qw_user a inner join company_user b on a.company_user_id = b.user_id
  219. where a.id in <foreach collection="ids" open="(" close=")" separator="," item="item">#{item}</foreach>
  220. and b.voice_print_url is not null
  221. </select>
  222. <select id="selectCompanyUserByIds" resultType="com.fs.company.domain.CompanyUser">
  223. select cu.*
  224. from company_user cu
  225. where cu.user_id in
  226. <foreach collection="ids" item="id" open="(" separator="," close=")">
  227. #{id}
  228. </foreach>
  229. </select>
  230. <select id="selectAllCompanyUserAndSelf" resultType="CompanyUser">
  231. SELECT
  232. *
  233. FROM
  234. company_user
  235. WHERE
  236. del_flag = 0
  237. AND (company_user.user_id = #{userId} or company_user.parent_id = #{userId})
  238. </select>
  239. <select id="getAllUserListLimit" resultType="com.fs.company.domain.CompanyUser">
  240. SELECT * FROM company_user
  241. <where>
  242. <if test="companyId != null">
  243. AND company_id != #{companyId}
  244. </if>
  245. <if test="keywords != null and keywords != ''">
  246. AND (
  247. phonenumber LIKE CONCAT(#{keywords}, '%')
  248. OR user_name LIKE CONCAT(#{keywords}, '%')
  249. OR nick_name LIKE CONCAT(#{keywords}, '%')
  250. )
  251. </if>
  252. </where>
  253. limit 10
  254. </select>
  255. <sql id="selectUserVo">
  256. select u.user_id,u.qw_user_id,u.company_id,u.voice_print_url, u.dept_id, u.user_name, u.nick_name,
  257. u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip,
  258. u.login_date, u.create_by, u.create_time,u.id_card, u.remark,u.user_type,u.open_id,
  259. u.qr_code_weixin,u.qr_code_wecom,u.jpush_id,u.address_id,u.domain,
  260. d.dept_id, d.parent_id, d.dept_name, d.order_num, d.leader, d.status as dept_status,
  261. r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
  262. from company_user u
  263. left join company_dept d on u.dept_id = d.dept_id
  264. left join company_user_role ur on u.user_id = ur.user_id
  265. left join company_role r on r.role_id = ur.role_id
  266. </sql>
  267. <select id="selectAllCompanyUserByDeptId" resultType="com.fs.company.domain.CompanyUser">
  268. select * from company_user where del_flag = '0'
  269. <if test="deptId != null">
  270. and dept_id = #{deptId}
  271. </if>
  272. </select>
  273. <select id="selectCompanyUserListByMap" resultType="com.fs.his.vo.OptionsVO">
  274. select
  275. cu.user_id dictValue,
  276. cu.nick_name dictLabel
  277. from company_user cu
  278. <where>
  279. <if test="params.companyUserName != null and params.companyUserName != ''">
  280. and cu.nick_name like concat('%', #{params.companyUserName}, '%')
  281. </if>
  282. <if test="params.companyId != null">
  283. and cu.company_id = #{params.companyId}
  284. </if>
  285. </where>
  286. </select>
  287. <update id="setIsRegisterMember" parameterType="Long">
  288. update company_user
  289. set is_need_register_member = #{status} where user_id in
  290. <foreach item="userId" collection="userIds" open="(" separator="," close=")">
  291. #{userId}
  292. </foreach>
  293. </update>
  294. </mapper>