QwExternalContactMapper.xml 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  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.QwExternalContactMapper">
  6. <resultMap type="QwExternalContact" id="QwExternalContactResult">
  7. <result property="id" column="id" />
  8. <result property="userId" column="user_id" />
  9. <result property="corpId" column="corp_id" />
  10. <result property="externalUserId" column="external_user_id" />
  11. <result property="name" column="name" />
  12. <result property="avatar" column="avatar" />
  13. <result property="type" column="type" />
  14. <result property="gender" column="gender" />
  15. <result property="remark" column="remark" />
  16. <result property="description" column="description" />
  17. <result property="tagIds" column="tag_ids" />
  18. <result property="remarkMobiles" column="remark_mobiles" />
  19. <result property="remarkCorpName" column="remark_corp_name" />
  20. <result property="addWay" column="add_way" />
  21. <result property="operUserid" column="oper_userid" />
  22. <result property="companyId" column="company_id" />
  23. <result property="companyUserId" column="company_user_id" />
  24. <result property="customerId" column="customer_id" />
  25. <result property="transferStatus" column="transfer_status" />
  26. <result property="status" column="status" />
  27. <result property="createTime" column="create_time" />
  28. <result property="transferTime" column="transfer_time" />
  29. <result property="transferNum" column="transfer_num" />
  30. <result property="lossTime" column="loss_time" />
  31. <result property="delTime" column="del_time" />
  32. <result property="qwUserId" column="qw_user_id" />
  33. <result property="state" column="state" />
  34. <result property="wayId" column="way_id" />
  35. <result property="stageStatus" column="stage_status" />
  36. <result property="fsUserId" column="fs_user_id" />
  37. <result property="openId" column="open_id" />
  38. <result property="unionid" column="unionid" />
  39. <result property="isInteract" column="is_interact" />
  40. <result property="level" column="level" />
  41. <result property="levelType" column="level_type" />
  42. <result property="firstTime" column="first_time" />
  43. <result property="lastWatchTime" column="last_watch_time" />
  44. <result property="registerTime" column="register_time" />
  45. <result property="isReply" column="is_reply" />
  46. </resultMap>
  47. <sql id="selectQwExternalContactVo">
  48. select id,qw_user_id,register_time,state,way_id,stage_status,first_time,open_id,is_interact,level, unionid, user_id,transfer_time,loss_time,del_time,transfer_num, external_user_id,transfer_status,status,create_time, name, avatar, type, gender, remark, description, tag_ids, remark_mobiles, remark_corp_name, add_way, oper_userid, corp_id, company_id, company_user_id, customer_id, fs_user_id,is_reply from qw_external_contact
  49. </sql>
  50. <select id="selectQwExternalContactList" parameterType="QwExternalContact" resultMap="QwExternalContactResult">
  51. <include refid="selectQwExternalContactVo"/>
  52. <where>
  53. <if test="userId != null and userId != ''"> and user_id = #{userId}</if>
  54. <if test="corpId != null and corpId != ''"> and corp_id = #{corpId}</if>
  55. <if test="externalUserId != null and externalUserId != ''"> and external_user_id = #{externalUserId}</if>
  56. <if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
  57. <if test="avatar != null and avatar != ''"> and avatar = #{avatar}</if>
  58. <if test="type != null "> and type = #{type}</if>
  59. <if test="gender != null "> and gender = #{gender}</if>
  60. <if test="description != null and description != ''"> and description = #{description}</if>
  61. <if test="tagIds != null and tagIds != ''"> and tag_ids = #{tagIds}</if>
  62. <if test="remarkMobiles != null and remarkMobiles != ''"> and remark_mobiles = #{remarkMobiles}</if>
  63. <if test="remarkCorpName != null and remarkCorpName != ''"> and remark_corp_name like concat('%', #{remarkCorpName}, '%')</if>
  64. <if test="addWay != null "> and add_way = #{addWay}</if>
  65. <if test="operUserid != null and operUserid != ''"> and oper_userid = #{operUserid}</if>
  66. <if test="companyId != null "> and company_id = #{companyId}</if>
  67. <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
  68. <if test="customerId != null "> and customer_id = #{customerId}</if>
  69. <if test="fsUserId != null "> and fs_user_id = #{fsUserId}</if>
  70. <if test="unionid != null "> and unionid = #{unionid}</if>
  71. </where>
  72. </select>
  73. <select id="selectAllQwJoinAdClickLog" resultType="com.fs.qw.result.QwExternalContactVo">
  74. select a.*,MAX(b.url) url,MAX(b.vid) vid,MAX(b.aid) aid,MAX(b.account_id) accountId from qw_external_contact a
  75. inner join ad_html_click_log b on a.state = b.vid
  76. where a.state is not null and b.type = #{type}
  77. <if test="type == 0">
  78. and b.click_type = 67 and (upload_add_wx_status = 0 or upload_register_status = 0 or upload_finished_status = 0)
  79. </if>
  80. <if test="type == 1">
  81. and b.click_type = 'wechat' and upload_add_wx_status = 0
  82. </if>
  83. group by a.id
  84. </select>
  85. <select id="selectQwExternalContactByIds" resultType="com.fs.qw.domain.QwExternalContact">
  86. select * from qw_external_contact
  87. where id in
  88. <foreach collection="ids" item="id" open="(" separator="," close=")">
  89. #{id}
  90. </foreach>
  91. </select>
  92. <select id="selectQwExternalContactByIdsStatus" resultType="com.fs.qw.domain.QwExternalContact">
  93. select * from qw_external_contact
  94. where status !=3 and id in
  95. <foreach collection="ids" item="id" open="(" separator="," close=")">
  96. #{id}
  97. </foreach>
  98. </select>
  99. <select id="selectQwExternalContactListVOByIds" resultType="com.fs.qw.param.QwExternalContactVOTime">
  100. select id,tag_ids,remark,create_time,fs_user_id,avatar from qw_external_contact
  101. where id in
  102. <foreach collection="ids" item="id" open="(" separator="," close=")">
  103. #{id}
  104. </foreach>
  105. </select>
  106. <select id="selectAllFormAd" resultType="com.fs.qw.result.QwExternalContactLogVo">
  107. select a.*
  108. ,user.nick_name
  109. ,b.aid,b.pid,b.uid,b.userid accountId,b.comb_id,b.create_time as `time`
  110. ,creative.creative_feed_name
  111. ,plan.campaign_feed_name
  112. ,unit.adgroup_feed_name
  113. ,account.account_name
  114. ,info.sex,info.age,info.address
  115. from qw_external_contact a
  116. left join qw_external_contact_info info on a.id = info.external_contact_id
  117. inner join ad_html_click_log b on a.state = b.vid
  118. left join bd_creative creative on b.aid = creative.creative_feed_id
  119. left join bd_plan plan on b.pid = plan.campaign_feed_id
  120. left join bd_unit unit on b.uid = unit.adgroup_feed_id
  121. <if test="accountId == null and userId == null">left join </if>
  122. <if test="accountId != null || userId != null">inner join </if>
  123. bd_account account on b.userid = account.account_id
  124. left join company_user user on account.user_id = user.user_id
  125. where a.state is not null and b.click_type = 67
  126. AND date_format(b.create_time,'%Y-%m-%d %h:%i:%s') &gt;= #{start}
  127. and date_format(b.create_time,'%Y-%m-%d %h:%i:%s') &lt;= #{end}
  128. <if test="accountId != null">
  129. and account.account_id = #{accountId}
  130. </if>
  131. <if test="userId != null">
  132. and account.user_id = #{userId}
  133. </if>
  134. <if test="aid != null">
  135. and b.aid = #{aid}
  136. </if>
  137. <if test="pid != null">
  138. and b.pid = #{pid}
  139. </if>
  140. <if test="uid != null">
  141. and b.uid = #{uid}
  142. </if>
  143. group by a.id
  144. </select>
  145. <select id="selectQwExternalContactById" parameterType="Long" resultMap="QwExternalContactResult">
  146. <include refid="selectQwExternalContactVo"/>
  147. where id = #{id}
  148. </select>
  149. <update id="batchUpdateQwExternalContact" parameterType="map">
  150. UPDATE qw_external_contact
  151. SET
  152. level = CASE id
  153. <foreach collection="list" item="item">
  154. WHEN #{item.id} THEN #{item.level}
  155. </foreach>
  156. ELSE level
  157. END,
  158. level_type = CASE id
  159. <foreach collection="list" item="item">
  160. WHEN #{item.id} THEN #{item.levelType}
  161. </foreach>
  162. ELSE level_type
  163. END,
  164. last_watch_time = CASE id
  165. <foreach collection="list" item="item">
  166. WHEN #{item.id} THEN #{item.lastWatchTime}
  167. </foreach>
  168. ELSE last_watch_time
  169. END
  170. WHERE id IN
  171. <foreach collection="list" item="item" open="(" separator="," close=")">
  172. #{item.id}
  173. </foreach>
  174. </update>
  175. <update id="batchUpdateQwExternalContactByTags" parameterType="map">
  176. UPDATE qw_external_contact
  177. SET
  178. tag_ids = CASE id
  179. <foreach collection="list" item="item">
  180. WHEN #{item.id} THEN #{item.tagIds}
  181. </foreach>
  182. ELSE tag_ids
  183. END
  184. WHERE id IN
  185. <foreach collection="list" item="item" open="(" separator="," close=")">
  186. #{item.id}
  187. </foreach>
  188. </update>
  189. <update id="batchUpdateQwExternalContactStatus" parameterType="map">
  190. UPDATE qw_external_contact
  191. SET status = 4
  192. WHERE user_id = #{qwUserId}
  193. AND corp_id = #{corpId}
  194. AND external_user_id IN
  195. <foreach collection="notInExternalUseridList" item="item" open="(" separator="," close=")">
  196. #{item}
  197. </foreach>
  198. </update>
  199. <update id="batchUpdateQwExternalContactByMoreStudy" parameterType="map">
  200. UPDATE qw_external_contact
  201. SET
  202. level = CASE id
  203. <foreach collection="list" item="item">
  204. WHEN #{item.id} THEN #{item.level}
  205. </foreach>
  206. ELSE level
  207. END
  208. WHERE id IN
  209. <foreach collection="list" item="item" open="(" separator="," close=")">
  210. #{item.id}
  211. </foreach>
  212. </update>
  213. <update id="batchUpdateQwExternalByIsDaysNotStudy" parameterType="map">
  214. UPDATE qw_external_contact
  215. SET level = NULL
  216. WHERE id IN
  217. <foreach collection="list" item="item" open="(" separator="," close=")">
  218. #{item.id}
  219. </foreach>
  220. </update>
  221. <insert id="insertQwExternalContact" parameterType="QwExternalContact" useGeneratedKeys="true" keyProperty="id" >
  222. insert into qw_external_contact
  223. <trim prefix="(" suffix=")" suffixOverrides=",">
  224. <if test="id != null">id,</if>
  225. <if test="userId != null">user_id,</if>
  226. <if test="externalUserId != null">external_user_id,</if>
  227. <if test="name != null">name,</if>
  228. <if test="avatar != null">avatar,</if>
  229. <if test="type != null">type,</if>
  230. <if test="gender != null">gender,</if>
  231. <if test="remark != null">remark,</if>
  232. <if test="description != null">description,</if>
  233. <if test="tagIds != null">tag_ids,</if>
  234. <if test="remarkMobiles != null">remark_mobiles,</if>
  235. <if test="remarkCorpName != null">remark_corp_name,</if>
  236. <if test="addWay != null">add_way,</if>
  237. <if test="operUserid != null">oper_userid,</if>
  238. <if test="corpId != null">corp_id,</if>
  239. <if test="companyId != null">company_id,</if>
  240. <if test="companyUserId != null">company_user_id,</if>
  241. <if test="customerId != null">customer_id,</if>
  242. <if test="transferStatus != null">transfer_status,</if>
  243. <if test="status != null">status,</if>
  244. <if test="createTime != null">create_time,</if>
  245. <if test="transferTime != null">transfer_time,</if>
  246. <if test="transferNum != null">transfer_num,</if>
  247. <if test="lossTime != null">loss_time,</if>
  248. <if test="delTime != null">del_time,</if>
  249. <if test="qwUserId != null">qw_user_id,</if>
  250. <if test="state != null">`state`,</if>
  251. <if test="wayId != null">way_id,</if>
  252. <if test="stageStatus != null">stage_status,</if>
  253. <if test="fsUserId != null">fs_user_id,</if>
  254. <if test="openId != null">open_id,</if>
  255. <if test="unionid != null">unionid,</if>
  256. <if test="isInteract != null">is_interact,</if>
  257. <if test="level != null">level,</if>
  258. <if test="levelType != null">level_type,</if>
  259. <if test="firstTime != null">first_time,</if>
  260. <if test="registerTime != null">register_time,</if>
  261. </trim>
  262. <trim prefix="values (" suffix=")" suffixOverrides=",">
  263. <if test="id != null">#{id},</if>
  264. <if test="userId != null">#{userId},</if>
  265. <if test="externalUserId != null">#{externalUserId},</if>
  266. <if test="name != null">#{name},</if>
  267. <if test="avatar != null">#{avatar},</if>
  268. <if test="type != null">#{type},</if>
  269. <if test="gender != null">#{gender},</if>
  270. <if test="remark != null">#{remark},</if>
  271. <if test="description != null">#{description},</if>
  272. <if test="tagIds != null">#{tagIds},</if>
  273. <if test="remarkMobiles != null">#{remarkMobiles},</if>
  274. <if test="remarkCorpName != null">#{remarkCorpName},</if>
  275. <if test="addWay != null">#{addWay},</if>
  276. <if test="operUserid != null">#{operUserid},</if>
  277. <if test="corpId != null">#{corpId},</if>
  278. <if test="companyId != null">#{companyId},</if>
  279. <if test="companyUserId != null">#{companyUserId},</if>
  280. <if test="customerId != null">#{customerId},</if>
  281. <if test="transferStatus != null">#{transferStatus},</if>
  282. <if test="status != null">#{status},</if>
  283. <if test="createTime != null">#{createTime},</if>
  284. <if test="transferTime != null">#{transferTime},</if>
  285. <if test="transferNum != null">#{transferNum},</if>
  286. <if test="lossTime != null">#{lossTime},</if>
  287. <if test="delTime != null">#{delTime},</if>
  288. <if test="qwUserId != null">#{qwUserId},</if>
  289. <if test="state != null">#{state},</if>
  290. <if test="wayId != null">#{wayId},</if>
  291. <if test="stageStatus != null">#{stageStatus},</if>
  292. <if test="fsUserId != null">#{fsUserId},</if>
  293. <if test="openId != null">#{openId},</if>
  294. <if test="unionid != null">#{unionid},</if>
  295. <if test="isInteract != null">#{isInteract},</if>
  296. <if test="level != null">#{level},</if>
  297. <if test="levelType != null">#{levelType},</if>
  298. <if test="firstTime != null">#{firstTime},</if>
  299. <if test="registerTime != null">#{registerTime},</if>
  300. </trim>
  301. </insert>
  302. <update id="updateQwExternalContact" parameterType="QwExternalContact">
  303. update qw_external_contact
  304. <trim prefix="SET" suffixOverrides=",">
  305. <if test="userId != null">user_id = #{userId},</if>
  306. <if test="corpId != null">corp_id = #{corpId},</if>
  307. <if test="externalUserId != null">external_user_id = #{externalUserId},</if>
  308. <if test="name != null">name = #{name},</if>
  309. <if test="avatar != null">avatar = #{avatar},</if>
  310. <if test="type != null">type = #{type},</if>
  311. <if test="gender != null">gender = #{gender},</if>
  312. <if test="remark != null">remark = #{remark},</if>
  313. <if test="description != null">description = #{description},</if>
  314. <if test="tagIds != null">tag_ids = #{tagIds},</if>
  315. <if test="remarkMobiles != null">remark_mobiles = #{remarkMobiles},</if>
  316. <if test="remarkCorpName != null">remark_corp_name = #{remarkCorpName},</if>
  317. <if test="addWay != null">add_way = #{addWay},</if>
  318. <if test="operUserid != null">oper_userid = #{operUserid},</if>
  319. <if test="companyId != null">company_id = #{companyId},</if>
  320. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  321. <if test="customerId != null">customer_id = #{customerId},</if>
  322. <if test="transferStatus != null">transfer_status = #{transferStatus},</if>
  323. <if test="status != null">status = #{status},</if>
  324. <if test="createTime != null">create_time = #{createTime},</if>
  325. <if test="transferTime != null">transfer_time = #{transferTime},</if>
  326. <if test="transferNum != null">transfer_num = #{transferNum},</if>
  327. <if test="lossTime != null">loss_time = #{lossTime},</if>
  328. <if test="delTime != null">del_time = #{delTime},</if>
  329. <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
  330. <if test="state != null">`state` = #{state},</if>
  331. <if test="wayId != null">way_id = #{wayId},</if>
  332. <if test="stageStatus != null">stage_status = #{stageStatus},</if>
  333. <if test="fsUserId != null">fs_user_id = #{fsUserId},</if>
  334. <if test="openId != null">open_id = #{openId},</if>
  335. <if test="unionid != null">unionid = #{unionid},</if>
  336. <if test="isInteract != null">is_interact = #{isInteract},</if>
  337. <if test="level != null">level = #{level},</if>
  338. <if test="levelType != null">level_type = #{levelType},</if>
  339. <if test="firstTime != null">first_time = #{firstTime},</if>
  340. <if test="registerTime != null">register_time = #{registerTime},</if>
  341. </trim>
  342. where id = #{id}
  343. </update>
  344. <delete id="deleteQwExternalContactById" parameterType="Long">
  345. delete from qw_external_contact where id = #{id}
  346. </delete>
  347. <delete id="deleteQwExternalContactByIds" parameterType="String">
  348. delete from qw_external_contact where id in
  349. <foreach item="id" collection="array" open="(" separator="," close=")">
  350. #{id}
  351. </foreach>
  352. </delete>
  353. <select id="selectQwExternalContactListVOByUserIds" resultType="com.fs.qw.param.QwExternalContactVOTime">
  354. select id,tag_ids,remark,create_time,external_user_id from qw_external_contact
  355. where external_user_id in
  356. <foreach collection="ids" item="id" open="(" separator="," close=")">
  357. #{id}
  358. </foreach>
  359. group by external_user_id
  360. </select>
  361. <select id="selectByGroupUser" resultType="com.fs.qw.vo.GroupUserExternalVo">
  362. select id,user_id,external_user_id,fs_user_id from qw_external_contact where external_user_id in
  363. <foreach collection="ids" open="(" separator="," close=")" item="item">#{item}</foreach>
  364. GROUP BY user_id,external_user_id
  365. </select>
  366. <select id="getCountAnswer" resultType="com.fs.qw.vo.ExternalContactDetailsVO">
  367. SELECT
  368. count( DISTINCT fs_course_answer_logs.log_id ) AS answerTime,
  369. count( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_course_answer_logs.log_id END ) AS answerRightTime,
  370. is_right,
  371. qw_external_contact.id,
  372. qw_external_contact.external_user_id,
  373. qw_external_contact.qw_user_id
  374. FROM
  375. fs_course_answer_logs
  376. LEFT JOIN qw_user ON qw_user.id = fs_course_answer_logs.qw_user_id
  377. LEFT JOIN qw_external_contact ON qw_external_contact.user_id = qw_user.qw_user_id
  378. <where>
  379. <if test="param.dateTag != null and param.dateTag !='' ">
  380. <choose>
  381. <when test = "param.dateTag == '今天'">
  382. and to_days(fs_course_answer_logs.create_time) = to_days(now())
  383. </when>
  384. <when test = "param.dateTag == ' 昨天'">
  385. and to_days(now()) - to_days(fs_course_answer_logs.create_time) &lt;= 1
  386. </when>
  387. <when test = "param.dateTag == '前天'">
  388. and to_days(now()) - to_days(fs_course_answer_logs.create_time) &lt;= 2
  389. </when>
  390. <when test = "param.dateTag == '近七天'">
  391. and DATE_SUB(CURDATE(), INTERVAL 7 DAY) &lt;= date(fs_course_answer_logs.create_time)
  392. </when>
  393. </choose>
  394. </if>
  395. </where>
  396. GROUP BY
  397. qw_external_contact.id
  398. HAVING
  399. qw_external_contact.id = #{param.contactId}
  400. </select>
  401. <select id="getCountRedPacket" resultType="com.fs.qw.vo.ExternalContactDetailsVO">
  402. SELECT
  403. count( DISTINCT log_id ) AS answerRedPacketTime,
  404. ifnull(sum( amount ), 0) AS answerRedPacketAmount,
  405. amount,
  406. qw_external_contact.id,
  407. qw_external_contact.external_user_id,
  408. qw_external_contact.qw_user_id
  409. FROM
  410. fs_course_red_packet_log
  411. LEFT JOIN qw_user ON qw_user.id = fs_course_red_packet_log.qw_user_id
  412. LEFT JOIN qw_external_contact ON qw_external_contact.user_id = qw_user.qw_user_id
  413. <where>
  414. <if test="param.dateTag != null and param.dateTag !='' ">
  415. <choose>
  416. <when test = "param.dateTag == '今天'">
  417. and to_days(fs_course_red_packet_log.create_time) = to_days(now())
  418. </when>
  419. <when test = "param.dateTag == ' 昨天'">
  420. and to_days(now()) - to_days(fs_course_red_packet_log.create_time) &lt;= 1
  421. </when>
  422. <when test = "param.dateTag == '前天'">
  423. and to_days(now()) - to_days(fs_course_red_packet_log.create_time) &lt;= 2
  424. </when>
  425. <when test = "param.dateTag == '近七天'">
  426. and DATE_SUB(CURDATE(), INTERVAL 7 DAY) &lt;= date(fs_course_red_packet_log.create_time)
  427. </when>
  428. </choose>
  429. </if>
  430. </where>
  431. GROUP BY
  432. qw_external_contact.id
  433. HAVING
  434. qw_external_contact.id = #{param.contactId}
  435. </select>
  436. <select id="getContactNumber" resultType="com.fs.qw.vo.newvo.ExternalContactNumVO">
  437. SELECT
  438. qw_external_contact.STATUS as status,
  439. count( qw_external_contact.id ) as num
  440. FROM
  441. qw_external_contact
  442. LEFT JOIN qw_user ON qw_external_contact.user_id = qw_user.qw_user_id
  443. LEFT JOIN company_user ON qw_user.company_user_id = company_user.user_id
  444. WHERE
  445. company_user.user_id = #{userId}
  446. GROUP BY
  447. qw_external_contact.STATUS
  448. </select>
  449. <select id="selectExternalContactPageList" resultType="com.fs.qw.vo.newvo.ExternalContactListVO">
  450. SELECT
  451. DISTINCT qw_external_contact.id,
  452. qw_external_contact.qw_user_id,
  453. qw_external_contact.user_id,
  454. qw_external_contact.external_user_id,
  455. qw_external_contact.remark_mobiles AS mobile,
  456. qw_external_contact.STATUS,
  457. qw_external_contact.create_time,
  458. qw_external_contact.NAME AS nickName,
  459. qw_external_contact.avatar,
  460. qw_external_contact.gender AS sex,
  461. qw_external_contact.tag_ids,
  462. qw_external_contact.corp_id,
  463. company_user.user_id AS companyUserId,
  464. company_user.user_name AS companyUserName,
  465. company_user.nick_name AS companyUserNickName
  466. FROM
  467. qw_external_contact
  468. LEFT JOIN qw_user ON qw_external_contact.user_id = qw_user.qw_user_id
  469. LEFT JOIN company_user ON qw_user.company_user_id = company_user.user_id
  470. LEFT JOIN qw_tag on qw_tag.corp_id = qw_external_contact.corp_id
  471. WHERE company_user.user_id = #{userId}
  472. <choose>
  473. <when test = "isBlack">
  474. AND qw_external_contact.status = 7
  475. </when>
  476. <otherwise>
  477. AND qw_external_contact.status != 7
  478. </otherwise>
  479. </choose>
  480. <if test="keyword != null and keyword !='' ">
  481. AND (qw_external_contact.NAME LIKE concat('%',#{keyword},'%')
  482. or qw_external_contact.remark_mobiles LIKE concat('%',#{keyword},'%')
  483. or qw_tag.`name` LIKE concat('%',#{keyword},'%')
  484. )
  485. </if>
  486. <if test="registerStartTime != null and registerStartTime !='' ">
  487. AND qw_external_contact.create_time &gt;= #{registerStartTime}
  488. </if>
  489. <if test="registerEndTime != null and registerEndTime !='' ">
  490. AND qw_external_contact.create_time &lt;= #{registerEndTime}
  491. </if>
  492. <if test="tagIds != null and tagIds.length > 0">
  493. AND
  494. <foreach collection="tagIds" item="item" index="index" open="(" separator="or" close=")">
  495. tag_ids LIKE concat('%"',#{item},'"%')
  496. </foreach>
  497. </if>
  498. <if test="tabValue != null and tabValue !='' ">
  499. <choose>
  500. <when test = "tabValue == 1">
  501. AND DAY(qw_external_contact.create_time) = DAY(NOW())
  502. </when>
  503. <when test = "tabValue == 2">
  504. -- 暂时不做
  505. AND 1!=1
  506. </when>
  507. <when test = "tabValue == 3">
  508. -- 暂时不做
  509. AND 1!=1
  510. </when>
  511. </choose>
  512. </if>
  513. <if test="watchCourseType != null and watchCourseType !='' ">
  514. <choose>
  515. <when test = "watchCourseType == 1">
  516. AND 1!=1
  517. </when>
  518. <when test = "watchCourseType == 2">
  519. AND 1!=1
  520. </when>
  521. <when test = "watchCourseType == 3">
  522. AND 1!=1
  523. </when>
  524. </choose>
  525. </if>
  526. </select>
  527. <select id="getCountCourseWatch" resultType="com.fs.qw.vo.ExternalContactDetailsVO">
  528. SELECT
  529. count( CASE WHEN fwl.log_type != 3 THEN fwl.log_id END ) AS courseWatchTime,
  530. count( CASE WHEN fwl.log_type = 2 THEN fwl.log_id END ) AS courseCompleteTime,
  531. GROUP_CONCAT( fwl.video_id ),
  532. fwl.qw_external_contact_id,
  533. fwl.qw_user_id
  534. FROM
  535. fs_course_watch_log fwl
  536. <where>
  537. <if test="param.dateTag != null and param.dateTag !='' ">
  538. <choose>
  539. <when test = "param.dateTag == '今天'">
  540. and to_days(fwl.update_time) = to_days(now())
  541. </when>
  542. <when test = "param.dateTag == ' 昨天'">
  543. and to_days(now()) - to_days(fwl.update_time) &lt;= 1
  544. </when>
  545. <when test = "param.dateTag == '前天'">
  546. and to_days(now()) - to_days(fwl.update_time) &lt;= 2
  547. </when>
  548. <when test = "param.dateTag == '近七天'">
  549. and DATE_SUB(CURDATE(), INTERVAL 7 DAY) &lt;= date(fwl.update_time)
  550. </when>
  551. </choose>
  552. </if>
  553. </where>
  554. GROUP BY
  555. fwl.qw_external_contact_id
  556. having fwl.qw_external_contact_id = #{param.contactId}
  557. </select>
  558. <update id="batchUpdateContactByIds" parameterType="map">
  559. update qw_external_contact
  560. <trim prefix="set" suffixOverrides=",">
  561. <trim prefix="status = case" suffix="end">
  562. <foreach collection="list" item="item" index="index">
  563. <if test="item.status != null">
  564. when id= #{item.id}
  565. then #{item.status}
  566. </if>
  567. </foreach>
  568. </trim>
  569. </trim>
  570. where contact_id in
  571. <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
  572. #{item.id}
  573. </foreach>
  574. </update>
  575. <update id="updateContactByIds" parameterType="map">
  576. update qw_external_contact
  577. set status = #{status}
  578. where id in
  579. <foreach collection="ids" item="id" open="(" separator="," close=")">
  580. #{id}
  581. </foreach>
  582. </update>
  583. <update id="updateQwExternalContactIsRePlyById">
  584. update qw_external_contact set is_reply = 1 where id = #{id}
  585. </update>
  586. <update id="updateQwExternalContactStatusById">
  587. update qw_external_contact set status = #{status} where id = #{id}
  588. </update>
  589. <select id="selectExternalByFsUserIds" resultType="QwExternalContact">
  590. select * from qw_external_contact
  591. where fs_user_id in
  592. <foreach collection="userIds" item="userId" open="(" separator="," close=")">
  593. #{userId}
  594. </foreach>
  595. </select>
  596. <select id="selectQwExternalContactByFsUserId" resultType="com.fs.qw.domain.QwExternalContact">
  597. <include refid="selectQwExternalContactVo"/>
  598. where fs_user_id = #{userId}
  599. </select>
  600. <select id="selectFsUserCourseComplaintRecordByUserId" resultType="com.fs.qw.vo.QwExternalContactComplaintVO">
  601. select qec.id,qec.qw_user_id,qec.status,qec.user_id,qec.name,qec.avatar,qec.remark,qec.description,qec.fs_user_id,
  602. qu.qw_user_name,cu.user_name ,cu.nick_name
  603. from qw_external_contact qec
  604. left join qw_user qu on qu.id=qec.qw_user_id
  605. left join company_user cu on cu.user_id=qu.company_user_id
  606. where fs_user_id = #{userId}
  607. </select>
  608. <insert id="insertQwUserDelLossLog" parameterType="com.fs.qw.domain.QwUserDelLossLog">
  609. insert into qw_user_del_loss_log (external_contact_id,company_id,company_user_id,type,time,qw_user_id,corp_id) values
  610. (#{param.externalContactId},#{param.companyId},#{param.companyUserId},#{param.type},#{param.time},#{param.qwUserId},#{param.corpId})
  611. </insert>
  612. <select id="selectQwUserDelLossList" resultType="com.fs.qw.vo.QwUserDelLossLogVO">
  613. SELECT
  614. SUM(case WHEN udl.type = 1 THEN 1 ELSE 0 END) delCount,
  615. SUM(case WHEN udl.type = 2 THEN 1 ELSE 0 END) lossCount,
  616. qu.qw_user_id user_id,qu.qw_user_name
  617. FROM `qw_user_del_loss_log` udl
  618. LEFT JOIN qw_user qu ON qu.id = udl.qw_user_id
  619. WHERE 1 = 1
  620. <if test="param.startTime != null and param.endTime != null">
  621. and udl.time BETWEEN #{param.startTime} AND #{param.endTime}
  622. </if>
  623. <if test="param.userName != null and param.userName != ''">
  624. and qu.qw_user_name LIKE CONCAT('%',#{param.userName},'%')
  625. </if>
  626. <if test="param.userId != null and param.userId != ''">
  627. and qu.qw_user_id LIKE CONCAT('%',#{param.userId},'%')
  628. </if>
  629. GROUP BY udl.qw_user_id
  630. </select>
  631. <select id="selectQwExternalContactByFsUserIdAndCompany" resultType="com.fs.qw.domain.QwExternalContact">
  632. <include refid="selectQwExternalContactVo"/>
  633. where fs_user_id = #{userId} and company_user_id = #{companyUserId}
  634. </select>
  635. <select id="selectQwExternalContactListVONewSys" resultType="com.fs.qw.vo.QwExternalContactVO">
  636. select ec.*, qu.qw_user_name, qd.dept_name as departmentName
  637. from qw_external_contact ec
  638. left join qw_user qu on ec.user_id = qu.qw_user_id and qu.corp_id = ec.corp_id
  639. left join qw_dept qd on qd.dept_id = qu.department and qd.corp_id = qu.corp_id
  640. left join company_user cu on ec.company_user_id = cu.user_id
  641. <where>
  642. <if test="userId != null and userId != ''">
  643. and ec.user_id like concat(#{userId}, '%')
  644. </if>
  645. <if test="qwUserName != null and qwUserName != ''">
  646. and qu.qw_user_name like concat(#{qwUserName}, '%')
  647. </if>
  648. <if test="externalUserId != null and externalUserId != ''">
  649. and ec.external_user_id = #{externalUserId}
  650. </if>
  651. <if test="wayId != null and wayId != ''">
  652. and SUBSTRING_INDEX(ec.state, ':', -1) = #{wayId}
  653. </if>
  654. <if test="name != null and name != ''">
  655. and ec.name like concat(#{name}, '%')
  656. </if>
  657. <if test="type != null">
  658. and ec.type = #{type}
  659. </if>
  660. <if test="gender != null">
  661. and ec.gender = #{gender}
  662. </if>
  663. <if test="description != null and description != ''">
  664. and ec.description = #{description}
  665. </if>
  666. <if test="tagIds != null and tagIds.size() != 0">
  667. and (
  668. <foreach collection="tagIds" item="item" index="index" separator=" AND ">
  669. find_in_set(#{item}, REGEXP_REPLACE(ec.tag_ids, '[\"\\[\\]]', ''))
  670. </foreach>
  671. )
  672. </if>
  673. <if test="remarkMobiles != null and remarkMobiles != ''">
  674. and ec.remark_mobiles like concat(#{remarkMobiles}, '%')
  675. </if>
  676. <if test="remark != null and remark != ''">
  677. and ec.remark like concat('%', #{remark}, '%')
  678. </if>
  679. <if test="remarkCorpName != null and remarkCorpName != ''">
  680. and ec.remark_corp_name like concat('%', #{remarkCorpName}, '%')
  681. </if>
  682. <if test="addWay != null">
  683. and ec.add_way = #{addWay}
  684. </if>
  685. <if test="operUserid != null and operUserid != ''">
  686. and ec.oper_userid = #{operUserid}
  687. </if>
  688. <if test="corpId != null and corpId != ''">
  689. and ec.corp_id = #{corpId}
  690. </if>
  691. <!--<if test="companyId != null">
  692. and qu.company_id = #{companyId}
  693. </if>
  694. <if test="companyUserId != null">
  695. and ec.company_user_id = #{companyUserId}
  696. </if>-->
  697. <if test="customerId != null">
  698. and ec.customer_id = #{customerId}
  699. </if>
  700. <if test="status != null">
  701. and ec.status = #{status}
  702. </if>
  703. <if test="stageStatus != null">
  704. and ec.stage_status = #{stageStatus}
  705. </if>
  706. <if test="transferStatus != null">
  707. and ec.transfer_status = #{transferStatus}
  708. </if>
  709. <if test="qwUserId != null">
  710. and ec.qw_user_id = #{qwUserId}
  711. </if>
  712. <if test="level != null">
  713. and ec.level = #{level}
  714. </if>
  715. <if test="levelType != null">
  716. and ec.level_type = #{levelType}
  717. </if>
  718. <if test="isBind == 'isBind'">
  719. and ec.customer_id is not null
  720. </if>
  721. <if test="isBind == 'noBind'">
  722. and ec.customer_id is null
  723. </if>
  724. <if test="isBindMini == 'isBindMini'">
  725. and ec.fs_user_id is not null
  726. </if>
  727. <if test="isBindMini == 'noBindMini'">
  728. and ec.fs_user_id is null
  729. </if>
  730. <if test="lossTime != null">
  731. and DATE(ec.loss_time) = DATE(#{lossTime})
  732. </if>
  733. <if test="createTime != null">
  734. and DATE(ec.create_time) = DATE(#{createTime})
  735. </if>
  736. <if test="delTime != null">
  737. and DATE(ec.del_time) = DATE(#{delTime})
  738. </if>
  739. <if test="sTime != null">
  740. and DATE(ec.create_time) &gt;= DATE(#{sTime})
  741. </if>
  742. <if test="eTime != null">
  743. and DATE(ec.create_time) &lt;= DATE(#{eTime})
  744. </if>
  745. <if test="companyUserName != null and companyUserName != ''">
  746. and cu.user_name = #{companyUserName}
  747. </if>
  748. <if test="cuDeptIdList != null and !cuDeptIdList.isEmpty() and userType != '00'">
  749. AND cu.dept_id IN
  750. <foreach collection="cuDeptIdList" item="item" open="(" separator="," close=")">
  751. #{item}
  752. </foreach>
  753. </if>
  754. <if test="companyUser != null">
  755. and (cu.nick_name like concat('%', #{companyUser}, '%') or cu.phonenumber = #{companyUser})
  756. </if>
  757. </where>
  758. order by ec.create_time desc, ec.id desc
  759. </select>
  760. <select id="selectQwUserListVOByQwUserIdAndCorpIdAndExternalUserId" resultMap="QwExternalContactResult">
  761. <include refid="selectQwExternalContactVo"/>
  762. where user_id = #{userId} and corp_id = #{corpId} and external_user_id = #{externalUserId}
  763. </select>
  764. <update id="updateJoinGroup">
  765. update qw_external_contact set join_group = 1 where id in <foreach collection="ids" open="(" separator="," close=")" item="item">#{item}</foreach>
  766. </update>
  767. <select id="getGroupChatUserByChatIdAndUserName" resultType="com.fs.qw.domain.QwExternalContact">
  768. select t1.* from qw_external_contact t1
  769. inner join qw_group_chat_user t2 on t1.external_user_id = t2.user_id and t2.chat_id = #{chatId}
  770. where t1.name = #{userName}
  771. and t1.user_id = #{userId}
  772. and t1.corp_id = #{corpId}
  773. and t1.status = 0
  774. </select>
  775. </mapper>