QwExternalContactMapper.xml 38 KB

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