QwUserMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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.qw.mapper.QwUserMapper">
  6. <resultMap type="QwUser" id="QwUserResult">
  7. <result property="id" column="id" />
  8. <result property="qwUserId" column="qw_user_id" />
  9. <result property="qwUserName" column="qw_user_name" />
  10. <result property="department" column="department" />
  11. <result property="openid" column="openid" />
  12. <result property="companyId" column="company_id" />
  13. <result property="companyUserId" column="company_user_id" />
  14. <result property="corpId" column="corp_id" />
  15. <result property="status" column="status" />
  16. <result property="isDel" column="is_del" />
  17. <result property="welcomeText" column="welcome_text" />
  18. <result property="welcomeImage" column="welcome_image" />
  19. <result property="isSendMsg" column="is_send_msg" />
  20. <result property="appKey" column="app_key" />
  21. <result property="contactWay" column="contact_way" />
  22. <result property="configId" column="config_id" />
  23. <result property="qwHookId" column="qw_hook_id" />
  24. <result property="fastGptRoleId" column="fastGpt_role_id" />
  25. <result property="loginStatus" column="login_status" />
  26. <result property="toolStatus" column="tool_status" />
  27. <result property="loginCodeUrl" column="login_code_url" />
  28. <result property="version" column="version" />
  29. <result property="vid" column="vid" />
  30. <result property="uid" column="uid" />
  31. <result property="ipadStatus" column="ipad_status" />
  32. <result property="serverId" column="server_id" />
  33. <result property="serverStatus" column="server_status" />
  34. <result property="isAuto" column="is_auto" />
  35. <result property="videoGetStatus" column="video_get_status" />
  36. </resultMap>
  37. <sql id="selectQwUserVo">
  38. select id,is_auto, video_get_status, qw_user_id,server_id,server_status,ipad_status,config_id,vid,uid,contact_way,app_key, qw_user_name, department, openid, company_id, company_user_id, corp_id, status, is_del, welcome_text, welcome_image, is_send_msg,app_key,qw_hook_id,fastGpt_role_id,login_status,tool_status,login_code_url,version from qw_user
  39. </sql>
  40. <select id="selectQwUserList" parameterType="QwUser" resultMap="QwUserResult">
  41. <include refid="selectQwUserVo"/>
  42. <where>
  43. 1=1 and is_del = 0 and company_user_id is not null
  44. <if test="qwUserId != null and qwUserId != ''"> and qw_user_id = #{qwUserId}</if>
  45. <if test="qwUserName != null and qwUserName != ''"> and qw_user_name like concat('%', #{qwUserName}, '%')</if>
  46. <if test="department != null and department != ''"> and department = #{department}</if>
  47. <if test="openid != null and openid != ''"> and openid = #{openid}</if>
  48. <if test="companyId != null "> and company_id = #{companyId}</if>
  49. <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
  50. <if test="corpId != null and corpId != ''"> and corp_id = #{corpId}</if>
  51. <if test="status != null "> and status = #{status}</if>
  52. <if test="isDel != null "> and is_del = #{isDel}</if>
  53. <if test="welcomeText != null and welcomeText != ''"> and welcome_text = #{welcomeText}</if>
  54. <if test="welcomeImage != null and welcomeImage != ''"> and welcome_image = #{welcomeImage}</if>
  55. <if test="isSendMsg != null "> and is_send_msg = #{isSendMsg}</if>
  56. <if test="fastGptRoleId != null "> and fastGpt_role_id = #{fastGptRoleId}</if>
  57. <if test="loginStatus != null "> and login_status = #{loginStatus}</if>
  58. <if test="toolStatus != null "> and tool_status = #{toolStatus}</if>
  59. <if test="loginCodeUrl != null "> and login_code_url = #{loginCodeUrl}</if>
  60. <if test="version != null "> and version = #{version}</if>
  61. <if test="isAuto != null "> and is_auto = #{isAuto}</if>
  62. </where>
  63. </select>
  64. <select id="selectQwUserById" parameterType="Long" resultMap="QwUserResult">
  65. <include refid="selectQwUserVo"/>
  66. where id = #{id}
  67. </select>
  68. <select id="batchGetQwUser" resultType="QwUser">
  69. SELECT
  70. qw_user_id,
  71. corp_id,
  72. qw_user_name
  73. FROM
  74. qw_user
  75. WHERE
  76. (qw_user_id, corp_id) IN
  77. <foreach item="item" collection="list" separator="," open="(" close=")">
  78. (#{item.qwUserid}, #{item.corpId})
  79. </foreach>
  80. </select>
  81. <insert id="insertQwUser" parameterType="QwUser" useGeneratedKeys="true" keyProperty="id">
  82. insert into qw_user
  83. <trim prefix="(" suffix=")" suffixOverrides=",">
  84. <if test="qwUserId != null">qw_user_id,</if>
  85. <if test="qwUserName != null">qw_user_name,</if>
  86. <if test="department != null">department,</if>
  87. <if test="openid != null">openid,</if>
  88. <if test="companyId != null">company_id,</if>
  89. <if test="companyUserId != null">company_user_id,</if>
  90. <if test="corpId != null">corp_id,</if>
  91. <if test="status != null">status,</if>
  92. <if test="isDel != null">is_del,</if>
  93. <if test="welcomeText != null">welcome_text,</if>
  94. <if test="welcomeImage != null">welcome_image,</if>
  95. <if test="isSendMsg != null">is_send_msg,</if>
  96. <if test="contactWay != null">contact_way,</if>
  97. <if test="configId != null">config_id,</if>
  98. <if test="appKey != null">app_key,</if>
  99. <if test="qwHookId != null">qw_hook_id,</if>
  100. <if test="fastGptRoleId != null">fastGpt_role_id,</if>
  101. <if test="loginStatus != null">login_status,</if>
  102. <if test="toolStatus != null">tool_status,</if>
  103. <if test="loginCodeUrl != null">login_code_url,</if>
  104. <if test="version != null">version,</if>
  105. <if test="vid != null">vid,</if>
  106. <if test="uid != null">uid,</if>
  107. <if test="ipadStatus != null">ipad_status,</if>
  108. <if test="serverId != null">server_id,</if>
  109. <if test="serverStatus != null">server_status,</if>
  110. <if test="isAuto != null">is_auto,</if>
  111. <if test="videoGetStatus != null">video_get_status,</if>
  112. </trim>
  113. <trim prefix="values (" suffix=")" suffixOverrides=",">
  114. <if test="qwUserId != null">#{qwUserId},</if>
  115. <if test="qwUserName != null">#{qwUserName},</if>
  116. <if test="department != null">#{department},</if>
  117. <if test="openid != null">#{openid},</if>
  118. <if test="companyId != null">#{companyId},</if>
  119. <if test="companyUserId != null">#{companyUserId},</if>
  120. <if test="corpId != null">#{corpId},</if>
  121. <if test="status != null">#{status},</if>
  122. <if test="isDel != null">#{isDel},</if>
  123. <if test="welcomeText != null">#{welcomeText},</if>
  124. <if test="welcomeImage != null">#{welcomeImage},</if>
  125. <if test="isSendMsg != null">#{isSendMsg},</if>
  126. <if test="contactWay != null">#{contactWay},</if>
  127. <if test="configId != null">#{configId},</if>
  128. <if test="appKey != null">#{appKey},</if>
  129. <if test="qwHookId != null">#{qwHookId},</if>
  130. <if test="fastGptRoleId != null">#{fastGptRoleId},</if>
  131. <if test="loginStatus != null">#{loginStatus},</if>
  132. <if test="toolStatus != null">#{tool_status},</if>
  133. <if test="version != null">#{version},</if>
  134. <if test="vid != null">#{vid},</if>
  135. <if test="uid != null">#{uid},</if>
  136. <if test="ipadStatus != null">#{ipadStatus},</if>
  137. <if test="serverId != null">#{serverId},</if>
  138. <if test="isAuto != null">#{isAuto},</if>
  139. <if test="videoGetStatus != null">#{videoGetStatus},</if>
  140. </trim>
  141. </insert>
  142. <update id="updateQwUser" parameterType="QwUser">
  143. update qw_user
  144. <trim prefix="SET" suffixOverrides=",">
  145. <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
  146. <if test="qwUserName != null">qw_user_name = #{qwUserName},</if>
  147. <if test="department != null">department = #{department},</if>
  148. <if test="openid != null">openid = #{openid},</if>
  149. <if test="companyId != null">company_id = #{companyId},</if>
  150. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  151. <if test="corpId != null">corp_id = #{corpId},</if>
  152. <if test="status != null">status = #{status},</if>
  153. <if test="isDel != null">is_del = #{isDel},</if>
  154. <if test="welcomeText != null">welcome_text = #{welcomeText},</if>
  155. <if test="welcomeImage != null">welcome_image = #{welcomeImage},</if>
  156. <if test="isSendMsg != null">is_send_msg = #{isSendMsg},</if>
  157. <if test="contactWay != null">contact_way = #{contactWay},</if>
  158. <if test="configId != null">config_id = #{configId},</if>
  159. <if test="appKey != null">app_key = #{appKey},</if>
  160. <if test="qwHookId != null">qw_hook_id = #{qwHookId},</if>
  161. <if test="fastGptRoleId != null">fastGpt_role_id = #{fastGptRoleId},</if>
  162. <if test="loginStatus != null">login_status = #{loginStatus},</if>
  163. <if test="toolStatus != null">tool_status = #{toolStatus},</if>
  164. <if test="loginCodeUrl != null">login_code_url = #{loginCodeUrl},</if>
  165. <if test="version != null">version = #{version},</if>
  166. <if test="vid != null">`vid` = #{vid},</if>
  167. <if test="uid != null">uid = #{uid},</if>
  168. <if test="ipadStatus != null">ipad_status = #{ipadStatus},</if>
  169. <if test="serverId != null">server_id = #{serverId},</if>
  170. <if test="serverStatus != null">server_status = #{serverStatus},</if>
  171. <if test="isAuto != null">is_auto = #{isAuto},</if>
  172. <if test="videoGetStatus != null">video_get_status = #{videoGetStatus},</if>
  173. </trim>
  174. where id = #{id}
  175. </update>
  176. <update id="updateQwUserByAppKey" parameterType="QwUser">
  177. update qw_user set login_status = #{loginStatus},remark = NULL
  178. <if test="version != null">,version = #{version} </if>
  179. where app_key = #{appKey}
  180. </update>
  181. <update id="updateQwUserByAppKeyTool" parameterType="QwUser">
  182. update qw_user set tool_status = #{toolStatus}
  183. where app_key = #{appKey}
  184. </update>
  185. <update id="updateQwUserByAppKeyToUrl" parameterType="QwUser">
  186. update qw_user set login_code_url = #{loginCodeUrl}
  187. where app_key = #{appKey}
  188. </update>
  189. <update id="updateQwUserByCompanyUserId" parameterType="String">
  190. update qw_user set status = 0 , is_del= 2 , company_user_id=null where company_user_id in
  191. <foreach item="userId" collection="array" open="(" separator="," close=")">
  192. #{userId}
  193. </foreach>
  194. </update>
  195. <delete id="deleteQwUserById" parameterType="Long">
  196. delete from qw_user where id = #{id}
  197. </delete>
  198. <delete id="deleteQwUserByIds" parameterType="String">
  199. delete from qw_user where id in
  200. <foreach item="id" collection="array" open="(" separator="," close=")">
  201. #{id}
  202. </foreach>
  203. </delete>
  204. <select id="selectQwUserByUserIds" parameterType="java.util.List" resultMap="QwUserResult">
  205. <include refid="selectQwUserVo"/>
  206. WHERE id IN
  207. <foreach item="userId" collection="list" open="(" separator="," close=")">
  208. #{userId}
  209. </foreach>
  210. </select>
  211. <select id="selectQwWorkTaskList" resultType="com.fs.qw.domain.QwWorkTask">
  212. select
  213. qwt.id,qwt.ext_id, qwt.qw_user_id, qwt.status, qwt.track_type, qwt.type, qwt.title, qwt.remark, qwt.score, qwt.sop_id,
  214. qwt.company_id, qwt.company_user_id, qwt.duration, qwt.create_time, qwt.update_time
  215. from qw_work_task qwt
  216. where qwt.qw_user_id = #{userId}
  217. and date(qwt.create_time) = #{date}
  218. and qwt.status = 0
  219. </select>
  220. <select id="selectQwUserByFsUserId" resultType="com.fs.qw.vo.sidebar.ExternalContactQwUserVO">
  221. SELECT
  222. qw_user.id,
  223. qw_user.qw_user_id,
  224. qw_user.qw_user_name,
  225. qw_user.department,
  226. qw_user.company_user_id,
  227. qw_user.company_id,
  228. company.company_name,
  229. company_user.nick_name as companyUserName
  230. FROM
  231. qw_user
  232. LEFT JOIN company_user ON company_user.user_id = qw_user.company_user_id
  233. LEFT JOIN company ON company.company_id = qw_user.company_id
  234. WHERE
  235. qw_user.qw_user_id IN ( SELECT user_id FROM qw_external_contact WHERE fs_user_id = #{fsUserId} )
  236. </select>
  237. <update id="updateSendType">
  238. update qw_user set send_msg_type = #{type} where id in <foreach collection="ids" open="(" close=")" separator="," item="item">#{item}</foreach>
  239. </update>
  240. <select id="selectOfflineUser" resultType="com.fs.qw.domain.QwUser">
  241. select * from qw_user where send_msg_type = 2 and server_id is not null and server_status = 1 and ipad_status = 1 limit 1
  242. </select>
  243. <select id="batchSelectQwUserByQwUserIdAndCorpId" resultType="QwUser">
  244. SELECT qw_user_id, corp_id, qw_user_name
  245. FROM qw_user
  246. WHERE
  247. <foreach collection="data" item="query" open="(" separator=" OR " close=")">
  248. (qw_user_id = #{query.qwUserId} AND corp_id = #{query.corpId})
  249. </foreach>
  250. </select>
  251. <select id="selectQwCompanyListOptionsVOBySys" resultType="com.fs.qw.vo.QwOptionsVO">
  252. select corp_id as dictValue,corp_name as dictLabel from qw_company
  253. </select>
  254. <select id="selectQwUserListVOByCompanyIdAndCorpIdAndNickName" resultType="com.fs.qw.vo.QwUserVO">
  255. select
  256. qu.*,
  257. cu.nick_name,
  258. cu.user_name,
  259. qd.dept_name as departmentName,
  260. c.company_name
  261. from qw_user qu
  262. left join company_user cu on cu.user_id = qu.company_user_id
  263. right join qw_dept qd on qu.department = qd.dept_id and qd.corp_id = qu.corp_id
  264. left join company c on qu.company_id = c.company_id
  265. where qu.company_id = #{companyId} and qu.corp_id = #{corpId}
  266. <if test="nickName != null and nickName != ''">
  267. and qu.qw_user_name like concat('%', #{nickName}, '%')
  268. </if>
  269. </select>
  270. <!-- 递归查询子部门,不包括自己,深度5 -->
  271. <select id="selectDeptByParentId" resultType="java.lang.Long">
  272. WITH RECURSIVE sub_dept AS (
  273. SELECT dept_id, parentid, 1 as depth
  274. FROM qw_dept
  275. WHERE parentid = #{deptId} and corp_id=#{corpId}
  276. UNION ALL
  277. SELECT qd.dept_id, qd.parentid, sd.depth + 1
  278. FROM qw_dept qd
  279. INNER JOIN sub_dept sd ON qd.parentid = sd.dept_id
  280. WHERE sd.depth &lt; 5 and qd.corp_id=#{corpId}
  281. )
  282. SELECT dept_id FROM sub_dept
  283. </select>
  284. </mapper>