CompanyUserMapper.xml 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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="domain" column="domain" />
  39. <result property="isAudit" column="is_audit" />
  40. <result property="addressId" column="address_id" />
  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="domain != null">`domain`,</if>
  126. <if test="isAudit != null">`is_audit`,</if>
  127. <if test="addressId != null">`address_id`,</if>
  128. <if test="maOpenId != null">`ma_open_id`,</if>
  129. </trim>
  130. <trim prefix="values (" suffix=")" suffixOverrides=",">
  131. <if test="companyId != null">#{companyId},</if>
  132. <if test="deptId != null">#{deptId},</if>
  133. <if test="userName != null and userName != ''">#{userName},</if>
  134. <if test="nickName != null and nickName != ''">#{nickName},</if>
  135. <if test="userType != null">#{userType},</if>
  136. <if test="email != null">#{email},</if>
  137. <if test="phonenumber != null">#{phonenumber},</if>
  138. <if test="sex != null">#{sex},</if>
  139. <if test="avatar != null">#{avatar},</if>
  140. <if test="idCard != null">#{idCard},</if>
  141. <if test="password != null">#{password},</if>
  142. <if test="status != null">#{status},</if>
  143. <if test="delFlag != null">#{delFlag},</if>
  144. <if test="loginIp != null">#{loginIp},</if>
  145. <if test="loginDate != null">#{loginDate},</if>
  146. <if test="createBy != null">#{createBy},</if>
  147. <if test="createTime != null">#{createTime},</if>
  148. <if test="updateBy != null">#{updateBy},</if>
  149. <if test="updateTime != null">#{updateTime},</if>
  150. <if test="token != null">#{token},</if>
  151. <if test="remark != null">#{remark},</if>
  152. <if test="openId != null">#{openId},</if>
  153. <if test="qrCodeWeixin != null">#{qrCodeWeixin},</if>
  154. <if test="qrCodeWecom != null">#{qrCodeWecom},</if>
  155. <if test="jpushId != null">#{jpushId},</if>
  156. <if test="qwUserId != null">#{qwUserId},</if>
  157. <if test="qwStatus != null">#{qwStatus},</if>
  158. <if test="domain != null">#{domain},</if>
  159. <if test="isAudit != null">#{isAudit},</if>
  160. <if test="addressId != null">#{addressId},</if>
  161. <if test="maOpenId != null">#{maOpenId},</if>
  162. </trim>
  163. </insert>
  164. <update id="updateCompanyUser" parameterType="CompanyUser">
  165. update company_user
  166. <trim prefix="SET" suffixOverrides=",">
  167. <if test="companyId != null">company_id = #{companyId},</if>
  168. <if test="deptId != null">dept_id = #{deptId},</if>
  169. <if test="userName != null and userName != ''">user_name = #{userName},</if>
  170. <if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
  171. <if test="userType != null">user_type = #{userType},</if>
  172. <if test="email != null">email = #{email},</if>
  173. <if test="phonenumber != null">phonenumber = #{phonenumber},</if>
  174. <if test="sex != null">sex = #{sex},</if>
  175. <if test="avatar != null">avatar = #{avatar},</if>
  176. <if test="idCard != null">id_card = #{idCard},</if>
  177. <if test="password != null and password != '' ">password = #{password},</if>
  178. <if test="status != null">status = #{status},</if>
  179. <if test="delFlag != null">del_flag = #{delFlag},</if>
  180. <if test="loginIp != null">login_ip = #{loginIp},</if>
  181. <if test="loginDate != null">login_date = #{loginDate},</if>
  182. <if test="createBy != null">create_by = #{createBy},</if>
  183. <if test="createTime != null">create_time = #{createTime},</if>
  184. <if test="updateBy != null">update_by = #{updateBy},</if>
  185. <if test="updateTime != null">update_time = #{updateTime},</if>
  186. <if test="token != null">token = #{token},</if>
  187. <if test="remark != null">remark = #{remark},</if>
  188. <if test="qrCodeWeixin != null">qr_code_weixin = #{qrCodeWeixin},</if>
  189. <if test="qrCodeWecom != null">qr_code_wecom = #{qrCodeWecom},</if>
  190. <if test="jpushId != null">jpush_id = #{jpushId},</if>
  191. <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
  192. <if test="qwStatus != null">qw_status = #{qwStatus},</if>
  193. <if test="domain != null">`domain` = #{domain},</if>
  194. <if test="isAudit != null">`is_audit` = #{isAudit},</if>
  195. <if test="addressId != null">`address_id` = #{addressId},</if>
  196. <if test="maOpenId != null">`ma_open_id` = #{maOpenId},</if>
  197. </trim>
  198. where user_id = #{userId}
  199. </update>
  200. <update id="updateAllCompanyUser" parameterType="CompanyUser">
  201. update company_user
  202. <trim prefix="SET" suffixOverrides=",">
  203. <if test="companyId != null">company_id = #{companyId},</if>
  204. <if test="deptId != null">dept_id = #{deptId},</if>
  205. <if test="userName != null and userName != ''">user_name = #{userName},</if>
  206. <if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
  207. <if test="email != null">email = #{email},</if>
  208. <if test="phonenumber != null">phonenumber = #{phonenumber},</if>
  209. <if test="sex != null">sex = #{sex},</if>
  210. <if test="avatar != null">avatar = #{avatar},</if>
  211. <if test="idCard != null">id_card = #{idCard},</if>
  212. <if test="password != null and password != '' ">password = #{password},</if>
  213. <if test="status != null">status = #{status},</if>
  214. <if test="delFlag != null">del_flag = #{delFlag},</if>
  215. <if test="loginIp != null">login_ip = #{loginIp},</if>
  216. <if test="loginDate != null">login_date = #{loginDate},</if>
  217. <if test="createBy != null">create_by = #{createBy},</if>
  218. <if test="createTime != null">create_time = #{createTime},</if>
  219. <if test="updateBy != null">update_by = #{updateBy},</if>
  220. <if test="updateTime != null">update_time = #{updateTime},</if>
  221. <if test="token != null">token = #{token},</if>
  222. <if test="remark != null">remark = #{remark},</if>
  223. <if test="qrCodeWeixin != null">qr_code_weixin = #{qrCodeWeixin},</if>
  224. <if test="qrCodeWecom != null">qr_code_wecom = #{qrCodeWecom},</if>
  225. <if test="jpushId != null">jpush_id = #{jpushId},</if>
  226. <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
  227. <if test="qwStatus != null">qw_status = #{qwStatus},</if>
  228. <if test="domain != null">`domain` = #{domain},</if>
  229. <if test="isAudit != null">`is_audit` = #{isAudit},</if>
  230. <if test="addressId != null">`address_id` = #{addressId},</if>
  231. <if test="maOpenId != null">`ma_open_id` = #{maOpenId},</if>
  232. </trim>
  233. where company_id = #{companyId}
  234. </update>
  235. <delete id="deleteCompanyUserById" parameterType="Long">
  236. delete from company_user where user_id = #{userId}
  237. </delete>
  238. <delete id="deleteCompanyUserByIds" parameterType="String">
  239. delete from company_user where user_id in
  240. <foreach item="userId" collection="array" open="(" separator="," close=")">
  241. #{userId}
  242. </foreach>
  243. </delete>
  244. <update id="updateUserAvatar" parameterType="SysUser">
  245. update company_user set avatar = #{avatar} where user_name = #{userName}
  246. </update>
  247. <update id="resetUserPwd" parameterType="SysUser">
  248. update company_user set password = #{password} where user_name = #{userName}
  249. </update>
  250. <select id="selectUserByUserName" parameterType="String" resultMap="CompanyUserResult">
  251. <include refid="selectUserVo"/>
  252. where u.user_name = #{userName}
  253. </select>
  254. <sql id="selectUserVo">
  255. select u.user_id,u.company_id,u.qw_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.id_card, u.remark,u.user_type,u.open_id,u.qr_code_weixin,u.qr_code_wecom,u.jpush_id,u.domain,u.is_audit,u.address_id,
  256. d.dept_id, d.parent_id, d.dept_name, d.order_num, d.leader, d.status as dept_status,
  257. r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
  258. from company_user u
  259. left join company_dept d on u.dept_id = d.dept_id
  260. left join company_user_role ur on u.user_id = ur.user_id
  261. left join company_role r on r.role_id = ur.role_id
  262. </sql>
  263. <select id="selectMyUserList" parameterType="com.fs.company.vo.CompanyUserVO" resultMap="CompanyUserVOResult">
  264. select u.user_id, u.dept_id, u.nick_name, u.user_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.open_id,u.id_card, d.dept_name, d.leader, u.is_audit
  265. from company_user u
  266. left join company_dept d on u.dept_id = d.dept_id
  267. where u.del_flag = '0' and u.status=0
  268. <if test="companyId != null ">
  269. AND u.company_id = #{companyId}
  270. </if>
  271. <if test="nickName != null and nickName != ''">
  272. AND u.nick_name like concat('%', #{nickName}, '%')
  273. </if>
  274. <if test="phonenumber != null and phonenumber != ''">
  275. AND u.phonenumber like concat('%', #{phonenumber}, '%')
  276. </if>
  277. <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
  278. AND date_format(u.create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
  279. </if>
  280. <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
  281. AND date_format(u.create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
  282. </if>
  283. <if test="deptId != null and deptId != 0">
  284. AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM company_dept t WHERE find_in_set(#{deptId}, ancestors) ))
  285. </if>
  286. <if test="isAudit != null">
  287. AND u.is_audit = #{isAudit}
  288. </if>
  289. </select>
  290. <select id="selecCompanyAllUsersList" parameterType="com.fs.company.vo.CompanyUserVO" resultMap="CompanyUserVOResult">
  291. select u.user_id, u.dept_id, u.nick_name, u.user_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.open_id,u.id_card, d.dept_name, d.leader ,
  292. (select count(1) from crm_customer cc where u.user_id= cc.receive_user_id and date_format(cc.receive_time,'%y%m%d') = date_format(now(),'%y%m%d') ) as now_day_customer_count
  293. from company_user u
  294. left join company_dept d on u.dept_id = d.dept_id
  295. where u.del_flag = '0' and u.status=0
  296. <if test="companyId != null ">
  297. AND u.company_id = #{companyId}
  298. </if>
  299. <if test="nickName != null and nickName != ''">
  300. AND u.nick_name like concat('%', #{nickName}, '%')
  301. </if>
  302. <if test="phonenumber != null and phonenumber != ''">
  303. AND u.phonenumber like concat('%', #{phonenumber}, '%')
  304. </if>
  305. <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
  306. AND date_format(u.create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
  307. </if>
  308. <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
  309. AND date_format(u.create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
  310. </if>
  311. <if test="deptId != null and deptId != 0">
  312. AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM company_dept t WHERE find_in_set(#{deptId}, ancestors) ))
  313. </if>
  314. </select>
  315. <select id="selectCompanyQwUserByIds" resultType="com.fs.company.vo.CompanyQwUserByIdsVo">
  316. SELECT b.user_id,b.company_id,a.qw_user_id,a.qw_user_name,b.nick_name
  317. FROM qw_user a inner join company_user b on a.company_user_id = b.user_id
  318. where a.id in <foreach collection="ids" open="(" close=")" separator="," item="item">#{item}</foreach>
  319. and b.voice_print_url is not null
  320. </select>
  321. <select id="selectCompanyUserByIds" resultType="com.fs.company.domain.CompanyUser">
  322. select cu.*
  323. from company_user cu
  324. where cu.user_id in
  325. <foreach collection="ids" item="id" open="(" separator="," close=")">
  326. #{id}
  327. </foreach>
  328. </select>
  329. <resultMap type="com.fs.company.vo.CompanyUserVO" id="CompanyUserVOResult">
  330. <result property="userId" column="user_id" />
  331. <result property="companyId" column="company_id" />
  332. <result property="deptId" column="dept_id" />
  333. <result property="userName" column="user_name" />
  334. <result property="nickName" column="nick_name" />
  335. <result property="userType" column="user_type" />
  336. <result property="email" column="email" />
  337. <result property="phonenumber" column="phonenumber" />
  338. <result property="sex" column="sex" />
  339. <result property="avatar" column="avatar" />
  340. <result property="idCard" column="id_card" />
  341. <result property="password" column="password" />
  342. <result property="status" column="status" />
  343. <result property="delFlag" column="del_flag" />
  344. <result property="loginIp" column="login_ip" />
  345. <result property="loginDate" column="login_date" />
  346. <result property="createBy" column="create_by" />
  347. <result property="createTime" column="create_time" />
  348. <result property="updateBy" column="update_by" />
  349. <result property="updateTime" column="update_time" />
  350. <result property="token" column="token" />
  351. <result property="remark" column="remark" />
  352. <result property="openId" column="open_id" />
  353. <result property="nowDayCustomerCount" column="now_day_customer_count" />
  354. <result property="domain" column="domain" />
  355. <result property="isAudit" column="is_audit" />
  356. <result property="addressId" column="address_id" />
  357. <association property="dept" column="dept_id" javaType="CompanyDept" resultMap="deptResult" />
  358. <collection property="roles" javaType="java.util.List" resultMap="RoleResult" />
  359. <collection property="posts" javaType="java.util.ArrayList" ofType="com.fs.company.domain.CompanyPost"
  360. select="com.fs.company.mapper.CompanyPostMapper.selectPostsByUserId" column="{user_id=user_id}" />
  361. </resultMap>
  362. <select id="selectAllCompanyUserByParentId" resultType="CompanyUser">
  363. SELECT
  364. *
  365. FROM
  366. company_user
  367. WHERE
  368. del_flag = 0
  369. AND parent_id = #{parentId}
  370. </select>
  371. <select id="getAllUserListLimit" resultType="com.fs.company.domain.CompanyUser">
  372. SELECT * FROM company_user
  373. <where>
  374. <if test="companyId != null">
  375. AND company_id != #{companyId}
  376. </if>
  377. <if test="keywords != null and keywords != ''">
  378. AND (
  379. phonenumber LIKE CONCAT(#{keywords}, '%')
  380. OR user_name LIKE CONCAT(#{keywords}, '%')
  381. OR nick_name LIKE CONCAT(#{keywords}, '%')
  382. )
  383. </if>
  384. </where>
  385. limit 10
  386. </select>
  387. <update id="auditUsers">
  388. update company_user
  389. set is_audit = 1
  390. where user_id in
  391. <foreach collection="userIds" open="(" close=")" separator="," item="id">
  392. #{id}
  393. </foreach>
  394. </update>
  395. <select id="selectAllCompanyUserAndSelf" resultType="CompanyUser">
  396. SELECT
  397. *
  398. FROM
  399. company_user
  400. WHERE
  401. del_flag = 0
  402. AND (company_user.user_id = #{userId} or company_user.parent_id = #{userId})
  403. </select>
  404. <select id="selectQwWatchLogStatisticsListVONewCount" resultType="java.lang.Long">
  405. </select>
  406. <select id="selectCompanyUserListByMap" resultType="com.fs.his.vo.OptionsVO">
  407. select
  408. cu.user_id dictValue,
  409. cu.nick_name dictLabel
  410. from company_user cu
  411. <where>
  412. <if test="params.companyUserName != null and params.companyUserName != ''">
  413. and cu.nick_name like concat('%', #{params.companyUserName}, '%')
  414. </if>
  415. <if test="params.companyId != null">
  416. and cu.company_id = #{params.companyId}
  417. </if>
  418. </where>
  419. </select>
  420. </mapper>