CompanyUserMapper.xml 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  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. <result property="isAudit" column="is_audit" />
  42. <result property="isNeedRegisterMember" column="is_need_register_member" />
  43. <result property="isAllowedAllRegister" column="is_allowed_all_register" />
  44. <result property="doctorId" column="doctor_id" />
  45. <result property="mpOpenId" column="mp_open_id" />
  46. <association property="dept" column="dept_id" javaType="CompanyDept" resultMap="deptResult" />
  47. <collection property="roles" javaType="java.util.List" resultMap="RoleResult" />
  48. </resultMap>
  49. <resultMap id="CompanyUserQwListVOResult" type="com.fs.company.vo.CompanyUserQwListVO">
  50. <id property="userId" column="user_id"/>
  51. <result property="userName" column="user_name"/>
  52. <result property="nickName" column="nick_name"/>
  53. <result property="companyId" column="company_id"/>
  54. <result property="status" column="status"/>
  55. <result property="qwStatus" column="qw_status"/>
  56. <result property="qwUserId" column="qw_user_id"/>
  57. <result property="phonenumber" column="phonenumber"/>
  58. <result property="createTime" column="create_time"/>
  59. <result property="deptId" column="dept_id"/>
  60. <result property="deptName" column="dept_name"/>
  61. <result property="qrCodeWeixin" column="qr_code_weixin"/>
  62. <result property="postName" column="post_name"/>
  63. <result property="qrCodeWecom" column="qr_code_wecom"/>
  64. <result property="jpushId" column="jpush_id"/>
  65. <result property="callerNo" column="caller_no"/>
  66. <result property="isNeedRegisterMember" column="is_need_register_member" />
  67. <result property="isAllowedAllRegister" column="is_allowed_all_register" />
  68. <collection property="roleNames" ofType="java.lang.String" javaType="java.util.ArrayList"
  69. select="selectUserRoles" column="user_id"/>
  70. </resultMap>
  71. <resultMap id="deptResult" type="CompanyDept">
  72. <id property="deptId" column="dept_id"/>
  73. <result property="parentId" column="parent_id"/>
  74. <result property="deptName" column="dept_name"/>
  75. <result property="orderNum" column="order_num"/>
  76. <result property="leader" column="leader"/>
  77. <result property="status" column="dept_status"/>
  78. </resultMap>
  79. <resultMap id="RoleResult" type="CompanyRole">
  80. <id property="roleId" column="role_id" />
  81. <result property="roleName" column="role_name" />
  82. <result property="roleKey" column="role_key" />
  83. <result property="roleSort" column="role_sort" />
  84. <result property="dataScope" column="data_scope" />
  85. <result property="status" column="role_status" />
  86. </resultMap>
  87. <select id="selectCompanyUserQwListVO" resultMap="CompanyUserQwListVOResult">
  88. select
  89. u.user_id, u.user_name, u.nick_name, u.company_id, u.status,
  90. u.qw_status, u.phonenumber, u.create_time, u.dept_id,
  91. u.qr_code_weixin, u.user_type, u.qr_code_wecom, u.jpush_id,
  92. u.is_need_register_member,u.is_allowed_all_register,
  93. u.avatar,u.address_id,
  94. u.qw_user_id,
  95. d.dept_name,
  96. d.leader,
  97. GROUP_CONCAT(fu.nick_name) bindUser,
  98. cfu.`status` bindStatus
  99. from
  100. company_user u
  101. left join
  102. company_dept d on u.dept_id = d.dept_id
  103. LEFT JOIN
  104. company_fs_user cfu on u.user_id=cfu.company_user_id
  105. LEFT JOIN fs_user fu on cfu.fs_user_id=fu.user_id
  106. where
  107. u.del_flag = '0'
  108. <if test="userId != null ">
  109. AND u.user_id = #{userId}
  110. </if>
  111. <if test="userName != null and userName != ''">
  112. AND u.user_name like concat('%', #{userName}, '%')
  113. </if>
  114. <if test="nickName != null and nickName != ''">
  115. AND u.nick_name like concat( #{nickName}, '%')
  116. </if>
  117. <if test="companyId != null and companyId != ''">
  118. AND u.company_id = #{companyId}
  119. </if>
  120. <if test="status != null and status != ''">
  121. AND u.status = #{status}
  122. </if>
  123. <if test="qwStatus != null">
  124. AND u.qw_status = #{qwStatus}
  125. </if>
  126. <if test="phonenumber != null and phonenumber != ''">
  127. AND u.phonenumber like concat('%', #{phonenumber}, '%')
  128. </if>
  129. <if test="beginTime != null and beginTime != ''">
  130. AND date_format(u.create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
  131. </if>
  132. <if test="endTime != null and endTime != ''">
  133. AND date_format(u.create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
  134. </if>
  135. <if test="deptId != null and deptId != 0">
  136. AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM company_dept t WHERE find_in_set(#{deptId}, ancestors) ))
  137. </if>
  138. <!-- 数据范围过滤 -->
  139. ${params.dataScope}
  140. GROUP BY u.user_id
  141. </select>
  142. <!-- 角色子查询 -->
  143. <select id="selectUserRoles" resultType="java.lang.String">
  144. SELECT cr.role_name
  145. FROM company_user_role cur
  146. LEFT JOIN company_role cr ON cr.role_id = cur.role_id
  147. WHERE cur.user_id = #{userId}
  148. </select>
  149. <select id="selectCompanyUserList" parameterType="CompanyUser" resultMap="CompanyUserResult">
  150. select u.*, d.dept_name, d.leader from company_user u
  151. left join company_dept d on u.dept_id = d.dept_id
  152. where u.del_flag = '0'
  153. <if test="userName != null and userName != ''">
  154. AND u.user_name like concat( #{userName}, '%')
  155. </if>
  156. <if test="nickName != null and nickName != ''">
  157. AND u.nick_name like concat( #{nickName}, '%')
  158. </if>
  159. <if test="companyId != null and companyId != ''">
  160. AND u.company_id = #{companyId}
  161. </if>
  162. <if test="status != null and status != ''">
  163. AND u.status = #{status}
  164. </if>
  165. <if test="phonenumber != null and phonenumber != ''">
  166. AND u.phonenumber like concat('%', #{phonenumber}, '%')
  167. </if>
  168. <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
  169. AND date_format(u.create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
  170. </if>
  171. <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
  172. AND date_format(u.create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
  173. </if>
  174. <if test="deptId != null and deptId != 0">
  175. AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM company_dept t WHERE find_in_set(#{deptId}, ancestors) ))
  176. </if>
  177. <if test="deptList != null and !deptList.isEmpty()">
  178. AND u.dept_id IN
  179. <foreach collection='deptList' item='item' open='(' separator=',' close=')'>
  180. #{item}
  181. </foreach>
  182. </if>
  183. <!-- 数据范围过滤 -->
  184. ${params.dataScope}
  185. </select>
  186. <select id="selectCompanyUserById" parameterType="Long" resultMap="CompanyUserResult">
  187. <include refid="selectUserVo"/>
  188. where u.user_id = #{userId}
  189. </select>
  190. <insert id="insertCompanyUser" parameterType="CompanyUser" useGeneratedKeys="true" keyProperty="userId">
  191. insert into company_user
  192. <trim prefix="(" suffix=")" suffixOverrides=",">
  193. <if test="companyId != null">company_id,</if>
  194. <if test="deptId != null">dept_id,</if>
  195. <if test="userName != null and userName != ''">user_name,</if>
  196. <if test="nickName != null and nickName != ''">nick_name,</if>
  197. <if test="userType != null">user_type,</if>
  198. <if test="email != null">email,</if>
  199. <if test="phonenumber != null">phonenumber,</if>
  200. <if test="sex != null">sex,</if>
  201. <if test="avatar != null">avatar,</if>
  202. <if test="idCard != null">id_card,</if>
  203. <if test="password != null">password,</if>
  204. <if test="status != null">status,</if>
  205. <if test="delFlag != null">del_flag,</if>
  206. <if test="loginIp != null">login_ip,</if>
  207. <if test="loginDate != null">login_date,</if>
  208. <if test="createBy != null">create_by,</if>
  209. <if test="createTime != null">create_time,</if>
  210. <if test="updateBy != null">update_by,</if>
  211. <if test="updateTime != null">update_time,</if>
  212. <if test="token != null">token,</if>
  213. <if test="remark != null">remark,</if>
  214. <if test="openId != null">open_id,</if>
  215. <if test="qrCodeWeixin != null">qr_code_weixin,</if>
  216. <if test="qrCodeWecom != null">qr_code_wecom,</if>
  217. <if test="jpushId != null">jpush_id,</if>
  218. <if test="qwUserId != null">qw_user_id,</if>
  219. <if test="qwStatus != null">qw_status,</if>
  220. <if test="voicePrintUrl != null">voice_print_url,</if>
  221. <if test="addressId != null">address_id,</if>
  222. <if test="domain != null">domain,</if>
  223. <if test="isAudit != null">`is_audit`,</if>
  224. <if test="mpOpenId != null">`mp_open_id`,</if>
  225. </trim>
  226. <trim prefix="values (" suffix=")" suffixOverrides=",">
  227. <if test="companyId != null">#{companyId},</if>
  228. <if test="deptId != null">#{deptId},</if>
  229. <if test="userName != null and userName != ''">#{userName},</if>
  230. <if test="nickName != null and nickName != ''">#{nickName},</if>
  231. <if test="userType != null">#{userType},</if>
  232. <if test="email != null">#{email},</if>
  233. <if test="phonenumber != null">#{phonenumber},</if>
  234. <if test="sex != null">#{sex},</if>
  235. <if test="avatar != null">#{avatar},</if>
  236. <if test="idCard != null">#{idCard},</if>
  237. <if test="password != null">#{password},</if>
  238. <if test="status != null">#{status},</if>
  239. <if test="delFlag != null">#{delFlag},</if>
  240. <if test="loginIp != null">#{loginIp},</if>
  241. <if test="loginDate != null">#{loginDate},</if>
  242. <if test="createBy != null">#{createBy},</if>
  243. <if test="createTime != null">#{createTime},</if>
  244. <if test="updateBy != null">#{updateBy},</if>
  245. <if test="updateTime != null">#{updateTime},</if>
  246. <if test="token != null">#{token},</if>
  247. <if test="remark != null">#{remark},</if>
  248. <if test="openId != null">#{openId},</if>
  249. <if test="qrCodeWeixin != null">#{qrCodeWeixin},</if>
  250. <if test="qrCodeWecom != null">#{qrCodeWecom},</if>
  251. <if test="jpushId != null">#{jpushId},</if>
  252. <if test="qwUserId != null">#{qwUserId},</if>
  253. <if test="qwStatus != null">#{qwStatus},</if>
  254. <if test="voicePrintUrl != null">#{voicePrintUrl},</if>
  255. <if test="addressId != null">#{addressId},</if>
  256. <if test="domain != null">#{domain},</if>
  257. <if test="isAudit != null">#{isAudit},</if>
  258. <if test="mpOpenId != null">#{mpOpenId},</if>
  259. </trim>
  260. </insert>
  261. <insert id="insertQwIpadTotal">
  262. insert into qw_ipad_total (company_id,company_name,bind_count,stat_time) values
  263. <foreach item="item" collection="list" separator=",">
  264. (#{item.companyId},#{item.companyName},#{item.bindCount},#{item.statTime})
  265. </foreach>
  266. </insert>
  267. <update id="uploadQrCode">
  268. update company_user set qr_code_weixin=#{url} where user_id=${userId}
  269. </update>
  270. <update id="updateCompanyUser" parameterType="CompanyUser">
  271. update company_user
  272. <trim prefix="SET" suffixOverrides=",">
  273. <if test="companyId != null">company_id = #{companyId},</if>
  274. <if test="deptId != null">dept_id = #{deptId},</if>
  275. <if test="userName != null and userName != ''">user_name = #{userName},</if>
  276. <if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
  277. <if test="userType != null">user_type = #{userType},</if>
  278. <if test="email != null">email = #{email},</if>
  279. <if test="phonenumber != null">phonenumber = #{phonenumber},</if>
  280. <if test="sex != null">sex = #{sex},</if>
  281. <if test="avatar != null">avatar = #{avatar},</if>
  282. <if test="idCard != null">id_card = #{idCard},</if>
  283. <if test="password != null and password != '' ">password = #{password},</if>
  284. <if test="status != null">status = #{status},</if>
  285. <if test="delFlag != null">del_flag = #{delFlag},</if>
  286. <if test="loginIp != null">login_ip = #{loginIp},</if>
  287. <if test="loginDate != null">login_date = #{loginDate},</if>
  288. <if test="createBy != null">create_by = #{createBy},</if>
  289. <if test="createTime != null">create_time = #{createTime},</if>
  290. <if test="updateBy != null">update_by = #{updateBy},</if>
  291. <if test="updateTime != null">update_time = #{updateTime},</if>
  292. <if test="token != null">token = #{token},</if>
  293. <if test="remark != null">remark = #{remark},</if>
  294. <if test="qrCodeWeixin != null">qr_code_weixin = #{qrCodeWeixin},</if>
  295. <if test="qrCodeWecom != null">qr_code_wecom = #{qrCodeWecom},</if>
  296. <if test="jpushId != null">jpush_id = #{jpushId},</if>
  297. <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
  298. <if test="qwStatus != null">qw_status = #{qwStatus},</if>
  299. <if test="voicePrintUrl != null">voice_print_url = #{voicePrintUrl},</if>
  300. <if test="addressId != null">address_id = #{addressId},</if>
  301. <if test="domain != null">domain = #{domain},</if>
  302. <if test="isAudit != null">`is_audit` = #{isAudit},</if>
  303. <if test="doctorId != null">`doctor_id` = #{doctorId},</if>
  304. <if test="mpOpenId != null">`mp_open_id` = #{mpOpenId},</if>
  305. <if test="invitationCode != null">`invitation_code` = #{invitationCode},</if>
  306. </trim>
  307. where user_id = #{userId}
  308. </update>
  309. <update id="updateAllCompanyUser" parameterType="CompanyUser">
  310. update company_user
  311. <trim prefix="SET" suffixOverrides=",">
  312. <if test="companyId != null">company_id = #{companyId},</if>
  313. <if test="deptId != null">dept_id = #{deptId},</if>
  314. <if test="userName != null and userName != ''">user_name = #{userName},</if>
  315. <if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
  316. <if test="email != null">email = #{email},</if>
  317. <if test="phonenumber != null">phonenumber = #{phonenumber},</if>
  318. <if test="sex != null">sex = #{sex},</if>
  319. <if test="avatar != null">avatar = #{avatar},</if>
  320. <if test="idCard != null">id_card = #{idCard},</if>
  321. <if test="password != null and password != '' ">password = #{password},</if>
  322. <if test="status != null">status = #{status},</if>
  323. <if test="delFlag != null">del_flag = #{delFlag},</if>
  324. <if test="loginIp != null">login_ip = #{loginIp},</if>
  325. <if test="loginDate != null">login_date = #{loginDate},</if>
  326. <if test="createBy != null">create_by = #{createBy},</if>
  327. <if test="createTime != null">create_time = #{createTime},</if>
  328. <if test="updateBy != null">update_by = #{updateBy},</if>
  329. <if test="updateTime != null">update_time = #{updateTime},</if>
  330. <if test="token != null">token = #{token},</if>
  331. <if test="remark != null">remark = #{remark},</if>
  332. <if test="qrCodeWeixin != null">qr_code_weixin = #{qrCodeWeixin},</if>
  333. <if test="qrCodeWecom != null">qr_code_wecom = #{qrCodeWecom},</if>
  334. <if test="jpushId != null">jpush_id = #{jpushId},</if>
  335. <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
  336. <if test="qwStatus != null">qw_status = #{qwStatus},</if>
  337. <if test="domain != null">`domain` = #{domain},</if>
  338. <if test="isAudit != null">`is_audit` = #{isAudit},</if>
  339. <if test="addressId != null">`address_id` = #{addressId},</if>
  340. <if test="maOpenId != null">`ma_open_id` = #{maOpenId},</if>
  341. <if test="mpOpenId != null">`mp_open_id` = #{mpOpenId},</if>
  342. </trim>
  343. where company_id = #{companyId}
  344. </update>
  345. <delete id="deleteCompanyUserById" parameterType="Long">
  346. delete from company_user where user_id = #{userId}
  347. </delete>
  348. <delete id="deleteCompanyUserByIds" parameterType="String">
  349. delete from company_user where user_id in
  350. <foreach item="userId" collection="array" open="(" separator="," close=")">
  351. #{userId}
  352. </foreach>
  353. </delete>
  354. <update id="updateUserAvatar" parameterType="SysUser">
  355. update company_user set avatar = #{avatar} where user_name = #{userName}
  356. </update>
  357. <update id="resetUserPwd" parameterType="SysUser">
  358. update company_user set password = #{password} where user_name = #{userName}
  359. </update>
  360. <select id="selectUserByUserName" parameterType="String" resultMap="CompanyUserResult">
  361. <include refid="selectUserVo"/>
  362. where u.user_name = #{userName}
  363. </select>
  364. <select id="selectCompanyQwUserByIds" resultType="com.fs.company.vo.CompanyQwUserByIdsVo">
  365. SELECT b.user_id,b.company_id,a.qw_user_id,a.qw_user_name,b.nick_name
  366. FROM qw_user a inner join company_user b on a.company_user_id = b.user_id
  367. where a.id in <foreach collection="ids" open="(" close=")" separator="," item="item">#{item}</foreach>
  368. and b.voice_print_url is not null
  369. </select>
  370. <select id="selectCompanyUserByIds" resultType="com.fs.company.domain.CompanyUser">
  371. select cu.*
  372. from company_user cu
  373. where cu.user_id in
  374. <foreach collection="ids" item="id" open="(" separator="," close=")">
  375. #{id}
  376. </foreach>
  377. </select>
  378. <select id="selectAllCompanyUserAndSelf" resultType="CompanyUser">
  379. SELECT
  380. *
  381. FROM
  382. company_user
  383. <where>
  384. del_flag = 0
  385. <if test="companyId == null">
  386. AND (company_user.user_id = #{userId} or company_user.parent_id = #{userId})
  387. </if>
  388. <if test="companyId != null">
  389. AND company_user.company_id = #{companyId}
  390. </if>
  391. </where>
  392. </select>
  393. <select id="getAllUserListLimit" resultType="com.fs.company.domain.CompanyUser">
  394. SELECT * FROM company_user
  395. <where>
  396. <if test="companyId != null">
  397. AND company_id != #{companyId}
  398. </if>
  399. <if test="keywords != null and keywords != ''">
  400. AND (
  401. phonenumber LIKE CONCAT(#{keywords}, '%')
  402. OR user_name LIKE CONCAT(#{keywords}, '%')
  403. OR nick_name LIKE CONCAT(#{keywords}, '%')
  404. )
  405. </if>
  406. </where>
  407. limit 10
  408. </select>
  409. <select id="selectCompanyUserByPhone" resultType="com.fs.company.domain.CompanyUser">
  410. select user_id, dept_id, user_name, nick_name, user_type, email, phonenumber, sex, avatar, password, status, del_flag, login_ip, login_date, create_by, create_time, update_by, update_time, remark, open_id, id_card, company_id, qr_code_weixin, qr_code_wecom, jpush_id, qw_user_id, qw_status, voice_print_url, address_id, `domain`, parent_id, bind_code,mp_open_id from company_user where phonenumber=#{phone} and del_flag=0
  411. </select>
  412. <sql id="selectUserVo">
  413. select u.user_id,u.company_id,u.qw_user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar,
  414. u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by,
  415. 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,
  416. d.dept_id, d.parent_id, d.dept_name, d.order_num, d.leader, d.status as dept_status,
  417. r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status,
  418. u.is_need_register_member, u.is_allowed_all_register,u.doctor_id
  419. from company_user u
  420. left join company_dept d on u.dept_id = d.dept_id
  421. left join company_user_role ur on u.user_id = ur.user_id
  422. left join company_role r on r.role_id = ur.role_id
  423. </sql>
  424. <select id="selectAllCompanyUserByCompanyIdAndDeptId" resultType="com.fs.company.domain.CompanyUser">
  425. select * from company_user where del_flag = '0'
  426. and company_id = #{companyId}
  427. <if test="deptId != null">
  428. and dept_id = #{deptId}
  429. </if>
  430. </select>
  431. <select id="selectCompanyUserListByMap" resultType="com.fs.his.vo.OptionsVO">
  432. select
  433. concat(cu.nick_name,'(',cu.user_id,')') as dictLabel,
  434. cu.user_id as dictValue
  435. from company_user cu
  436. <where>
  437. <if test="params.nickName != null and params.nickName != ''">
  438. and cu.nick_name like concat(#{params.nickName}, '%')
  439. </if>
  440. <if test="params.companyId != null">
  441. and cu.company_id = #{params.companyId}
  442. </if>
  443. <if test="params.combinedDeptList != null and !params.combinedDeptList.isEmpty() ">
  444. AND cu.dept_id IN
  445. <foreach collection='params.combinedDeptList' item='item' open='(' separator=',' close=')'>
  446. #{item}
  447. </foreach>
  448. </if>
  449. </where>
  450. </select>
  451. <update id="setIsRegisterMember" parameterType="Long">
  452. update company_user
  453. set is_need_register_member = #{status} where user_id in
  454. <foreach item="userId" collection="userIds" open="(" separator="," close=")">
  455. #{userId}
  456. </foreach>
  457. </update>
  458. <update id="auditUsers">
  459. update company_user
  460. set is_audit = 1
  461. where user_id in
  462. <foreach collection="userIds" open="(" close=")" separator="," item="id">
  463. #{id}
  464. </foreach>
  465. </update>
  466. <select id="selectMyUserList" parameterType="com.fs.company.vo.CompanyUserVO" resultMap="CompanyUserVOResult">
  467. 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,
  468. cr.role_id, cr.role_name
  469. from company_user u
  470. left join company_user_role cur on cur.user_id = u.user_id
  471. left join company_role cr on cr.role_id = cur.role_id
  472. left join company_dept d on u.dept_id = d.dept_id
  473. where u.del_flag = '0' and u.status=0
  474. <if test="companyId != null ">
  475. AND u.company_id = #{companyId}
  476. </if>
  477. <if test="nickName != null and nickName != ''">
  478. AND u.nick_name like concat('%', #{nickName}, '%')
  479. </if>
  480. <if test="phonenumber != null and phonenumber != ''">
  481. AND u.phonenumber like concat('%', #{phonenumber}, '%')
  482. </if>
  483. <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
  484. AND date_format(u.create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
  485. </if>
  486. <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
  487. AND date_format(u.create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
  488. </if>
  489. <if test="deptId != null and deptId != 0">
  490. AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM company_dept t WHERE find_in_set(#{deptId}, ancestors) ))
  491. </if>
  492. <if test="isAudit != null">
  493. AND u.is_audit = #{isAudit}
  494. </if>
  495. </select>
  496. <resultMap type="com.fs.company.vo.CompanyUserVO" id="CompanyUserVOResult">
  497. <result property="userId" column="user_id" />
  498. <result property="companyId" column="company_id" />
  499. <result property="deptId" column="dept_id" />
  500. <result property="userName" column="user_name" />
  501. <result property="nickName" column="nick_name" />
  502. <result property="userType" column="user_type" />
  503. <result property="email" column="email" />
  504. <result property="phonenumber" column="phonenumber" />
  505. <result property="sex" column="sex" />
  506. <result property="avatar" column="avatar" />
  507. <result property="idCard" column="id_card" />
  508. <result property="password" column="password" />
  509. <result property="status" column="status" />
  510. <result property="delFlag" column="del_flag" />
  511. <result property="loginIp" column="login_ip" />
  512. <result property="loginDate" column="login_date" />
  513. <result property="createBy" column="create_by" />
  514. <result property="createTime" column="create_time" />
  515. <result property="updateBy" column="update_by" />
  516. <result property="updateTime" column="update_time" />
  517. <result property="token" column="token" />
  518. <result property="remark" column="remark" />
  519. <result property="openId" column="open_id" />
  520. <result property="nowDayCustomerCount" column="now_day_customer_count" />
  521. <result property="domain" column="domain" />
  522. <result property="isAudit" column="is_audit" />
  523. <result property="addressId" column="address_id" />
  524. <association property="dept" column="dept_id" javaType="CompanyDept" resultMap="deptResult" />
  525. <collection property="roles" javaType="java.util.List" resultMap="RoleResult" />
  526. <collection property="posts" javaType="java.util.ArrayList" ofType="com.fs.company.domain.CompanyPost"
  527. select="com.fs.company.mapper.CompanyPostMapper.selectPostsByUserId" column="{user_id=user_id}" />
  528. </resultMap>
  529. <select id="getUserInfoByUserIds" resultType="com.fs.company.domain.CompanyUser">
  530. SELECT user_id,user_name FROM company_user WHERE user_id IN <foreach collection="ids" item="item" index="index" open="(" separator="," close=")">
  531. #{item}
  532. </foreach>
  533. </select>
  534. <select id="queryCompanyUserWatchCount" resultType="java.lang.Long">
  535. select count(1) from fs_course_watch_log
  536. <where>
  537. <if test="companyUserId != null">
  538. AND company_user_id = #{companyUserId}
  539. </if>
  540. <if test="previousDay != null">
  541. and camp_period_time = ${previousDay}
  542. </if>
  543. </where>
  544. </select>
  545. <select id="queryCompanyUserWatchCountCompleted" resultType="java.lang.Long">
  546. select count(1) from fs_course_watch_log
  547. <where>
  548. AND log_type = 2
  549. <if test="companyUserId != null">
  550. AND company_user_id = #{companyUserId}
  551. </if>
  552. <if test="previousDay != null">
  553. and camp_period_time = ${previousDay}
  554. </if>
  555. </where>
  556. </select>
  557. <select id="queryCompanyUserInterruptCount" resultType="java.lang.Long">
  558. select count(1) from fs_course_watch_log
  559. <where>
  560. AND log_type = 4
  561. <if test="companyUserId != null">
  562. AND company_user_id = #{companyUserId}
  563. </if>
  564. <if test="previousDay != null">
  565. and camp_period_time = ${previousDay}
  566. </if>
  567. </where>
  568. </select>
  569. <select id="getCompanyUserList" resultType="com.fs.company.domain.CompanyUser">
  570. SELECT
  571. u.user_id,
  572. u.user_name,
  573. u.phonenumber,
  574. cdbu.company_user_id
  575. FROM
  576. company_user u
  577. LEFT JOIN company_domain_bind_user cdbu ON u.user_id=cdbu.company_user_id
  578. WHERE
  579. u.del_flag = '0'
  580. AND cdbu.id IS NULL
  581. <if test="userName != null and userName != ''">
  582. AND u.user_name like concat( #{userName}, '%')
  583. </if>
  584. <if test="nickName != null and nickName != ''">
  585. AND u.nick_name like concat( #{nickName}, '%')
  586. </if>
  587. <if test="companyId != null and companyId != ''">
  588. AND u.company_id = #{companyId}
  589. </if>
  590. <if test="status != null and status != ''">
  591. AND u.status = #{status}
  592. </if>
  593. <if test="phonenumber != null and phonenumber != ''">
  594. AND u.phonenumber like concat('%', #{phonenumber}, '%')
  595. </if>
  596. <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
  597. AND date_format(u.create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
  598. </if>
  599. <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
  600. AND date_format(u.create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
  601. </if>
  602. <!-- 数据范围过滤 -->
  603. ${params.dataScope}
  604. </select>
  605. <select id="selectQwUserListLikeName" resultType="com.fs.qw.vo.QwOptionsVO">
  606. select
  607. concat(qw.qw_user_name,'(',qw.id,')') as dictLabel,
  608. qw.id as dictValue
  609. from qw_user qw
  610. <where>
  611. <if test="params.qwUserName != null and params.qwUserName != ''">
  612. and qw.qw_user_name like concat(#{params.qwUserName}, '%')
  613. </if>
  614. <if test="params.companyId != null">
  615. and qw.company_id = #{params.companyId}
  616. </if>
  617. </where>
  618. </select>
  619. <select id="selectCompanyUserNameByIds" resultType="java.lang.String">
  620. select GROUP_CONCAT(DISTINCT nick_name ORDER BY nick_name SEPARATOR ',') as nick_name from company_user where user_id in
  621. <foreach collection="companyUserIds.split(',')" item="companyUserId" open="(" close=")" separator=",">
  622. #{companyUserId}
  623. </foreach>
  624. </select>
  625. <update id="batchUpdateUserDomain">
  626. update company_user set domain=#{domain} where user_id in <foreach collection="ids" item="item" index="index" open="(" separator="," close=")">#{item}</foreach>
  627. </update>
  628. <update id="batchUpdateUserDept">
  629. UPDATE company_user
  630. SET dept_id = CASE user_id
  631. <foreach collection="companyUserList" item="item" separator=" ">
  632. WHEN #{item.userId} THEN #{item.deptId}
  633. </foreach>
  634. END
  635. WHERE user_id IN
  636. <foreach collection="companyUserList" item="item" open="(" separator="," close=")">
  637. #{item.userId}
  638. </foreach>
  639. </update>
  640. <select id="selectCompanyUserByCompanyUserId" resultMap="CompanyUserResult">
  641. select * from company_user where user_id = #{companyUserId}
  642. </select>
  643. <select id="selectCompanyByIpadStatus" resultType="com.fs.company.vo.QwIpadTotalVo">
  644. select company_id companyId,company_name companyName,
  645. sum(bind_count) bindCount,stat_time statTime from qw_ipad_total
  646. <where>
  647. <if test="dateTime != null">
  648. and stat_time like concat(#{dateTime}, '%')
  649. </if>
  650. </where>
  651. group by company_id,company_name
  652. </select>
  653. <select id="selectCompanyByIpadStatusCount" resultType="com.fs.company.vo.QwIpadTotalVo">
  654. SELECT qw.company_id companyId,c.company_name companyName,count(1) bindCount
  655. FROM `qw_user` qw left join company c on qw.company_id = c.company_id
  656. where qw.ipad_status is not null
  657. GROUP BY qw.company_id
  658. </select>
  659. <update id="updateAllowedAllRegister" parameterType="Long">
  660. update company_user
  661. set is_allowed_all_register = #{status} where user_id in
  662. <foreach item="userId" collection="userIds" open="(" separator="," close=")">
  663. #{userId}
  664. </foreach>
  665. </update>
  666. <select id="selectCompanyUserNameByIdsList" resultType="java.lang.String">
  667. SELECT nick_name from company_user where user_id in
  668. <foreach collection="companyUserIDs" item="id" open="(" separator="," close=")">
  669. #{id}
  670. </foreach>
  671. </select>
  672. <select id="selectMpOpenIdByCompanyUserId" resultType="java.lang.String">
  673. SELECT mp_open_id FROM company_user WHERE user_id = #{companyUserId}
  674. </select>
  675. </mapper>