QwExternalContactMapper.xml 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  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="leveType" column="level_type" />
  42. <result property="firstTime" column="first_time" />
  43. <result property="lastWatchTime" column="last_watch_time" />
  44. </resultMap>
  45. <sql id="selectQwExternalContactVo">
  46. select id,qw_user_id,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 from qw_external_contact
  47. </sql>
  48. <select id="selectQwExternalContactList" parameterType="QwExternalContact" resultMap="QwExternalContactResult">
  49. <include refid="selectQwExternalContactVo"/>
  50. <where>
  51. <if test="userId != null and userId != ''"> and user_id = #{userId}</if>
  52. <if test="corpId != null and corpId != ''"> and corp_id = #{corpId}</if>
  53. <if test="externalUserId != null and externalUserId != ''"> and external_user_id = #{externalUserId}</if>
  54. <if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
  55. <if test="avatar != null and avatar != ''"> and avatar = #{avatar}</if>
  56. <if test="type != null "> and type = #{type}</if>
  57. <if test="gender != null "> and gender = #{gender}</if>
  58. <if test="description != null and description != ''"> and description = #{description}</if>
  59. <if test="tagIds != null and tagIds != ''"> and tag_ids = #{tagIds}</if>
  60. <if test="remarkMobiles != null and remarkMobiles != ''"> and remark_mobiles = #{remarkMobiles}</if>
  61. <if test="remarkCorpName != null and remarkCorpName != ''"> and remark_corp_name like concat('%', #{remarkCorpName}, '%')</if>
  62. <if test="addWay != null "> and add_way = #{addWay}</if>
  63. <if test="operUserid != null and operUserid != ''"> and oper_userid = #{operUserid}</if>
  64. <if test="companyId != null "> and company_id = #{companyId}</if>
  65. <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
  66. <if test="customerId != null "> and customer_id = #{customerId}</if>
  67. <if test="fsUserId != null "> and fs_user_id = #{fsUserId}</if>
  68. <if test="unionid != null "> and unionid = #{unionid}</if>
  69. </where>
  70. </select>
  71. <select id="selectAllQwJoinAdClickLog" resultType="com.fs.qw.result.QwExternalContactVo">
  72. select a.*,MAX(b.url) url,MAX(b.vid) vid,MAX(b.aid) aid,MAX(b.account_id) accountId from qw_external_contact a
  73. inner join ad_html_click_log b on a.state = b.vid
  74. where a.state is not null and b.type = #{type}
  75. <if test="type == 0">
  76. and b.click_type = 67 and (upload_add_wx_status = 0 or upload_register_status = 0 or upload_finished_status = 0)
  77. </if>
  78. <if test="type == 1">
  79. and b.click_type = 'wechat' and upload_add_wx_status = 0
  80. </if>
  81. group by a.id
  82. </select>
  83. <select id="selectQwExternalContactByIds" resultType="com.fs.qw.domain.QwExternalContact">
  84. select * from qw_external_contact
  85. where id in
  86. <foreach collection="ids" item="id" open="(" separator="," close=")">
  87. #{id}
  88. </foreach>
  89. </select>
  90. <select id="selectQwExternalContactListVOByIds" resultType="com.fs.qw.param.QwExternalContactVOTime">
  91. select id,tag_ids,remark,create_time,fs_user_id,avatar from qw_external_contact
  92. where id in
  93. <foreach collection="ids" item="id" open="(" separator="," close=")">
  94. #{id}
  95. </foreach>
  96. </select>
  97. <select id="selectAllFormAd" resultType="com.fs.qw.result.QwExternalContactLogVo">
  98. select a.*
  99. ,user.nick_name
  100. ,b.aid,b.pid,b.uid,b.userid accountId,b.comb_id,b.create_time as `time`
  101. ,creative.creative_feed_name
  102. ,plan.campaign_feed_name
  103. ,unit.adgroup_feed_name
  104. ,account.account_name
  105. ,info.sex,info.age,info.address
  106. from qw_external_contact a
  107. left join qw_external_contact_info info on a.id = info.external_contact_id
  108. inner join ad_html_click_log b on a.state = b.vid
  109. left join bd_creative creative on b.aid = creative.creative_feed_id
  110. left join bd_plan plan on b.pid = plan.campaign_feed_id
  111. left join bd_unit unit on b.uid = unit.adgroup_feed_id
  112. <if test="accountId == null and userId == null">left join </if>
  113. <if test="accountId != null || userId != null">inner join </if>
  114. bd_account account on b.userid = account.account_id
  115. left join company_user user on account.user_id = user.user_id
  116. where a.state is not null and b.click_type = 67
  117. AND date_format(b.create_time,'%Y-%m-%d %h:%i:%s') &gt;= #{start}
  118. and date_format(b.create_time,'%Y-%m-%d %h:%i:%s') &lt;= #{end}
  119. <if test="accountId != null">
  120. and account.account_id = #{accountId}
  121. </if>
  122. <if test="userId != null">
  123. and account.user_id = #{userId}
  124. </if>
  125. <if test="aid != null">
  126. and b.aid = #{aid}
  127. </if>
  128. <if test="pid != null">
  129. and b.pid = #{pid}
  130. </if>
  131. <if test="uid != null">
  132. and b.uid = #{uid}
  133. </if>
  134. group by a.id
  135. </select>
  136. <select id="selectQwExternalContactById" parameterType="Long" resultMap="QwExternalContactResult">
  137. <include refid="selectQwExternalContactVo"/>
  138. where id = #{id}
  139. </select>
  140. <update id="batchUpdateQwExternalContact" parameterType="map">
  141. UPDATE qw_external_contact
  142. SET
  143. level = CASE id
  144. <foreach collection="list" item="item">
  145. WHEN #{item.id} THEN #{item.level}
  146. </foreach>
  147. ELSE level
  148. END,
  149. level_type = CASE id
  150. <foreach collection="list" item="item">
  151. WHEN #{item.id} THEN #{item.levelType}
  152. </foreach>
  153. ELSE level_type
  154. END,
  155. last_watch_time = CASE id
  156. <foreach collection="list" item="item">
  157. WHEN #{item.id} THEN #{item.lastWatchTime}
  158. </foreach>
  159. ELSE last_watch_time
  160. END
  161. WHERE id IN
  162. <foreach collection="list" item="item" open="(" separator="," close=")">
  163. #{item.id}
  164. </foreach>
  165. </update>
  166. <update id="batchUpdateQwExternalContactByTags" parameterType="map">
  167. UPDATE qw_external_contact
  168. SET
  169. tag_ids = CASE id
  170. <foreach collection="list" item="item">
  171. WHEN #{item.id} THEN #{item.tagIds}
  172. </foreach>
  173. ELSE tag_ids
  174. END
  175. WHERE id IN
  176. <foreach collection="list" item="item" open="(" separator="," close=")">
  177. #{item.id}
  178. </foreach>
  179. </update>
  180. <update id="batchUpdateQwExternalContactStatus" parameterType="map">
  181. UPDATE qw_external_contact
  182. SET status = 4
  183. WHERE user_id = #{qwUserId}
  184. AND corp_id = #{corpId}
  185. AND external_user_id IN
  186. <foreach collection="notInExternalUseridList" item="item" open="(" separator="," close=")">
  187. #{item}
  188. </foreach>
  189. </update>
  190. <insert id="insertQwExternalContact" parameterType="QwExternalContact" useGeneratedKeys="true" keyProperty="id" >
  191. insert into qw_external_contact
  192. <trim prefix="(" suffix=")" suffixOverrides=",">
  193. <if test="id != null">id,</if>
  194. <if test="userId != null">user_id,</if>
  195. <if test="externalUserId != null">external_user_id,</if>
  196. <if test="name != null">name,</if>
  197. <if test="avatar != null">avatar,</if>
  198. <if test="type != null">type,</if>
  199. <if test="gender != null">gender,</if>
  200. <if test="remark != null">remark,</if>
  201. <if test="description != null">description,</if>
  202. <if test="tagIds != null">tag_ids,</if>
  203. <if test="remarkMobiles != null">remark_mobiles,</if>
  204. <if test="remarkCorpName != null">remark_corp_name,</if>
  205. <if test="addWay != null">add_way,</if>
  206. <if test="operUserid != null">oper_userid,</if>
  207. <if test="corpId != null">corp_id,</if>
  208. <if test="companyId != null">company_id,</if>
  209. <if test="companyUserId != null">company_user_id,</if>
  210. <if test="customerId != null">customer_id,</if>
  211. <if test="transferStatus != null">transfer_status,</if>
  212. <if test="status != null">status,</if>
  213. <if test="createTime != null">create_time,</if>
  214. <if test="transferTime != null">transfer_time,</if>
  215. <if test="transferNum != null">transfer_num,</if>
  216. <if test="lossTime != null">loss_time,</if>
  217. <if test="delTime != null">del_time,</if>
  218. <if test="qwUserId != null">qw_user_id,</if>
  219. <if test="state != null">`state`,</if>
  220. <if test="wayId != null">way_id,</if>
  221. <if test="stageStatus != null">stage_status,</if>
  222. <if test="fsUserId != null">fs_user_id,</if>
  223. <if test="openId != null">open_id,</if>
  224. <if test="unionid != null">unionid,</if>
  225. <if test="isInteract != null">is_interact,</if>
  226. <if test="level != null">level,</if>
  227. <if test="levelType != null">level_type,</if>
  228. <if test="firstTime != null">first_time,</if>
  229. </trim>
  230. <trim prefix="values (" suffix=")" suffixOverrides=",">
  231. <if test="id != null">#{id},</if>
  232. <if test="userId != null">#{userId},</if>
  233. <if test="externalUserId != null">#{externalUserId},</if>
  234. <if test="name != null">#{name},</if>
  235. <if test="avatar != null">#{avatar},</if>
  236. <if test="type != null">#{type},</if>
  237. <if test="gender != null">#{gender},</if>
  238. <if test="remark != null">#{remark},</if>
  239. <if test="description != null">#{description},</if>
  240. <if test="tagIds != null">#{tagIds},</if>
  241. <if test="remarkMobiles != null">#{remarkMobiles},</if>
  242. <if test="remarkCorpName != null">#{remarkCorpName},</if>
  243. <if test="addWay != null">#{addWay},</if>
  244. <if test="operUserid != null">#{operUserid},</if>
  245. <if test="corpId != null">#{corpId},</if>
  246. <if test="companyId != null">#{companyId},</if>
  247. <if test="companyUserId != null">#{companyUserId},</if>
  248. <if test="customerId != null">#{customerId},</if>
  249. <if test="transferStatus != null">#{transferStatus},</if>
  250. <if test="status != null">#{status},</if>
  251. <if test="createTime != null">#{createTime},</if>
  252. <if test="transferTime != null">#{transferTime},</if>
  253. <if test="transferNum != null">#{transferNum},</if>
  254. <if test="lossTime != null">#{lossTime},</if>
  255. <if test="delTime != null">#{delTime},</if>
  256. <if test="qwUserId != null">#{qwUserId},</if>
  257. <if test="state != null">#{state},</if>
  258. <if test="wayId != null">#{wayId},</if>
  259. <if test="stageStatus != null">#{stageStatus},</if>
  260. <if test="fsUserId != null">#{fsUserId},</if>
  261. <if test="openId != null">#{openId},</if>
  262. <if test="unionid != null">#{unionid},</if>
  263. <if test="isInteract != null">#{isInteract},</if>
  264. <if test="level != null">#{level},</if>
  265. <if test="levelType != null">#{levelType},</if>
  266. <if test="firstTime != null">#{firstTime},</if>
  267. </trim>
  268. </insert>
  269. <update id="updateQwExternalContact" parameterType="QwExternalContact">
  270. update qw_external_contact
  271. <trim prefix="SET" suffixOverrides=",">
  272. <if test="userId != null">user_id = #{userId},</if>
  273. <if test="corpId != null">corp_id = #{corpId},</if>
  274. <if test="externalUserId != null">external_user_id = #{externalUserId},</if>
  275. <if test="name != null">name = #{name},</if>
  276. <if test="avatar != null">avatar = #{avatar},</if>
  277. <if test="type != null">type = #{type},</if>
  278. <if test="gender != null">gender = #{gender},</if>
  279. <if test="remark != null">remark = #{remark},</if>
  280. <if test="description != null">description = #{description},</if>
  281. <if test="tagIds != null">tag_ids = #{tagIds},</if>
  282. <if test="remarkMobiles != null">remark_mobiles = #{remarkMobiles},</if>
  283. <if test="remarkCorpName != null">remark_corp_name = #{remarkCorpName},</if>
  284. <if test="addWay != null">add_way = #{addWay},</if>
  285. <if test="operUserid != null">oper_userid = #{operUserid},</if>
  286. <if test="companyId != null">company_id = #{companyId},</if>
  287. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  288. <if test="customerId != null">customer_id = #{customerId},</if>
  289. <if test="transferStatus != null">transfer_status = #{transferStatus},</if>
  290. <if test="status != null">status = #{status},</if>
  291. <if test="createTime != null">create_time = #{createTime},</if>
  292. <if test="transferTime != null">transfer_time = #{transferTime},</if>
  293. <if test="transferNum != null">transfer_num = #{transferNum},</if>
  294. <if test="lossTime != null">loss_time = #{lossTime},</if>
  295. <if test="delTime != null">del_time = #{delTime},</if>
  296. <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
  297. <if test="state != null">`state` = #{state},</if>
  298. <if test="wayId != null">way_id = #{wayId},</if>
  299. <if test="stageStatus != null">stage_status = #{stageStatus},</if>
  300. <if test="fsUserId != null">fs_user_id = #{fsUserId},</if>
  301. <if test="openId != null">open_id = #{openId},</if>
  302. <if test="unionid != null">unionid = #{unionid},</if>
  303. <if test="isInteract != null">is_interact = #{isInteract},</if>
  304. <if test="level != null">level = #{level},</if>
  305. <if test="levelType != null">level_type = #{levelType},</if>
  306. <if test="firstTime != null">first_time = #{firstTime},</if>
  307. </trim>
  308. where id = #{id}
  309. </update>
  310. <delete id="deleteQwExternalContactById" parameterType="Long">
  311. delete from qw_external_contact where id = #{id}
  312. </delete>
  313. <delete id="deleteQwExternalContactByIds" parameterType="String">
  314. delete from qw_external_contact where id in
  315. <foreach item="id" collection="array" open="(" separator="," close=")">
  316. #{id}
  317. </foreach>
  318. </delete>
  319. <select id="selectQwExternalContactListVOByUserIds" resultType="com.fs.qw.param.QwExternalContactVOTime">
  320. select id,tag_ids,remark,create_time,external_user_id from qw_external_contact
  321. where external_user_id in
  322. <foreach collection="ids" item="id" open="(" separator="," close=")">
  323. #{id}
  324. </foreach>
  325. group by external_user_id
  326. </select>
  327. <select id="selectByGroupUser" resultType="com.fs.qw.vo.GroupUserExternalVo">
  328. select id,user_id,external_user_id,fs_user_id from qw_external_contact where external_user_id in
  329. <foreach collection="ids" open="(" separator="," close=")" item="item">#{item}</foreach>
  330. GROUP BY user_id,external_user_id
  331. </select>
  332. <select id="getCountAnswer" resultType="com.fs.qw.vo.ExternalContactDetailsVO">
  333. SELECT
  334. count( DISTINCT fs_course_answer_logs.log_id ) AS answerTime,
  335. count( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_course_answer_logs.log_id END ) AS answerRightTime,
  336. is_right,
  337. qw_external_contact.id,
  338. qw_external_contact.external_user_id,
  339. qw_external_contact.qw_user_id
  340. FROM
  341. fs_course_answer_logs
  342. LEFT JOIN qw_user ON qw_user.id = fs_course_answer_logs.qw_user_id
  343. LEFT JOIN qw_external_contact ON qw_external_contact.user_id = qw_user.qw_user_id
  344. <where>
  345. <if test="param.dateTag != null and param.dateTag !='' ">
  346. <choose>
  347. <when test = "param.dateTag == '今天'">
  348. and to_days(fs_course_answer_logs.create_time) = to_days(now())
  349. </when>
  350. <when test = "param.dateTag == ' 昨天'">
  351. and to_days(now()) - to_days(fs_course_answer_logs.create_time) &lt;= 1
  352. </when>
  353. <when test = "param.dateTag == '前天'">
  354. and to_days(now()) - to_days(fs_course_answer_logs.create_time) &lt;= 2
  355. </when>
  356. <when test = "param.dateTag == '近七天'">
  357. and DATE_SUB(CURDATE(), INTERVAL 7 DAY) &lt;= date(fs_course_answer_logs.create_time)
  358. </when>
  359. </choose>
  360. </if>
  361. </where>
  362. GROUP BY
  363. qw_external_contact.id
  364. HAVING
  365. qw_external_contact.id = #{param.contactId}
  366. </select>
  367. <select id="getCountRedPacket" resultType="com.fs.qw.vo.ExternalContactDetailsVO">
  368. SELECT
  369. count( DISTINCT log_id ) AS answerRedPacketTime,
  370. ifnull(sum( amount ), 0) AS answerRedPacketAmount,
  371. amount,
  372. qw_external_contact.id,
  373. qw_external_contact.external_user_id,
  374. qw_external_contact.qw_user_id
  375. FROM
  376. fs_course_red_packet_log
  377. LEFT JOIN qw_user ON qw_user.id = fs_course_red_packet_log.qw_user_id
  378. LEFT JOIN qw_external_contact ON qw_external_contact.user_id = qw_user.qw_user_id
  379. <where>
  380. <if test="param.dateTag != null and param.dateTag !='' ">
  381. <choose>
  382. <when test = "param.dateTag == '今天'">
  383. and to_days(fs_course_red_packet_log.create_time) = to_days(now())
  384. </when>
  385. <when test = "param.dateTag == ' 昨天'">
  386. and to_days(now()) - to_days(fs_course_red_packet_log.create_time) &lt;= 1
  387. </when>
  388. <when test = "param.dateTag == '前天'">
  389. and to_days(now()) - to_days(fs_course_red_packet_log.create_time) &lt;= 2
  390. </when>
  391. <when test = "param.dateTag == '近七天'">
  392. and DATE_SUB(CURDATE(), INTERVAL 7 DAY) &lt;= date(fs_course_red_packet_log.create_time)
  393. </when>
  394. </choose>
  395. </if>
  396. </where>
  397. GROUP BY
  398. qw_external_contact.id
  399. HAVING
  400. qw_external_contact.id = #{param.contactId}
  401. </select>
  402. <select id="getContactNumber" resultType="com.fs.qw.vo.newvo.ExternalContactNumVO">
  403. SELECT
  404. qw_external_contact.STATUS as status,
  405. count( qw_external_contact.id ) as num
  406. FROM
  407. qw_external_contact
  408. LEFT JOIN qw_user ON qw_external_contact.user_id = qw_user.qw_user_id
  409. LEFT JOIN company_user ON qw_user.company_user_id = company_user.user_id
  410. WHERE
  411. company_user.user_id = #{userId}
  412. GROUP BY
  413. qw_external_contact.STATUS
  414. </select>
  415. <select id="selectExternalContactPageList" resultType="com.fs.qw.vo.newvo.ExternalContactListVO">
  416. SELECT
  417. DISTINCT qw_external_contact.id,
  418. qw_external_contact.qw_user_id,
  419. qw_external_contact.user_id,
  420. qw_external_contact.external_user_id,
  421. qw_external_contact.remark_mobiles AS mobile,
  422. qw_external_contact.STATUS,
  423. qw_external_contact.create_time,
  424. qw_external_contact.NAME AS nickName,
  425. qw_external_contact.avatar,
  426. qw_external_contact.gender AS sex,
  427. qw_external_contact.tag_ids,
  428. qw_external_contact.corp_id,
  429. company_user.user_id AS companyUserId,
  430. company_user.user_name AS companyUserName,
  431. company_user.nick_name AS companyUserNickName
  432. FROM
  433. qw_external_contact
  434. LEFT JOIN qw_user ON qw_external_contact.user_id = qw_user.qw_user_id
  435. LEFT JOIN company_user ON qw_user.company_user_id = company_user.user_id
  436. LEFT JOIN qw_tag on qw_tag.corp_id = qw_external_contact.corp_id
  437. WHERE company_user.user_id = #{userId}
  438. <choose>
  439. <when test = "isBlack">
  440. AND qw_external_contact.status = 7
  441. </when>
  442. <otherwise>
  443. AND qw_external_contact.status != 7
  444. </otherwise>
  445. </choose>
  446. <if test="keyword != null and keyword !='' ">
  447. AND (qw_external_contact.NAME LIKE concat('%',#{keyword},'%')
  448. or qw_external_contact.remark_mobiles LIKE concat('%',#{keyword},'%')
  449. or qw_tag.`name` LIKE concat('%',#{keyword},'%')
  450. )
  451. </if>
  452. <if test="registerStartTime != null and registerStartTime !='' ">
  453. AND qw_external_contact.create_time &gt;= #{registerStartTime}
  454. </if>
  455. <if test="registerEndTime != null and registerEndTime !='' ">
  456. AND qw_external_contact.create_time &lt;= #{registerEndTime}
  457. </if>
  458. <if test="tagIds != null and tagIds.length > 0">
  459. AND
  460. <foreach collection="tagIds" item="item" index="index" open="(" separator="or" close=")">
  461. tag_ids LIKE concat('%"',#{item},'"%')
  462. </foreach>
  463. </if>
  464. <if test="tabValue != null and tabValue !='' ">
  465. <choose>
  466. <when test = "tabValue == 1">
  467. AND DAY(qw_external_contact.create_time) = DAY(NOW())
  468. </when>
  469. <when test = "tabValue == 2">
  470. -- 暂时不做
  471. AND 1!=1
  472. </when>
  473. <when test = "tabValue == 3">
  474. -- 暂时不做
  475. AND 1!=1
  476. </when>
  477. </choose>
  478. </if>
  479. <if test="watchCourseType != null and watchCourseType !='' ">
  480. <choose>
  481. <when test = "watchCourseType == 1">
  482. AND 1!=1
  483. </when>
  484. <when test = "watchCourseType == 2">
  485. AND 1!=1
  486. </when>
  487. <when test = "watchCourseType == 3">
  488. AND 1!=1
  489. </when>
  490. </choose>
  491. </if>
  492. </select>
  493. <select id="getCountCourseWatch" resultType="com.fs.qw.vo.ExternalContactDetailsVO">
  494. SELECT
  495. count( CASE WHEN fwl.log_type != 3 THEN fwl.log_id END ) AS courseWatchTime,
  496. count( CASE WHEN fwl.log_type = 2 THEN fwl.log_id END ) AS courseCompleteTime,
  497. GROUP_CONCAT( fwl.video_id ),
  498. fwl.qw_external_contact_id,
  499. fwl.qw_user_id
  500. FROM
  501. fs_course_watch_log fwl
  502. <where>
  503. <if test="param.dateTag != null and param.dateTag !='' ">
  504. <choose>
  505. <when test = "param.dateTag == '今天'">
  506. and to_days(fwl.update_time) = to_days(now())
  507. </when>
  508. <when test = "param.dateTag == ' 昨天'">
  509. and to_days(now()) - to_days(fwl.update_time) &lt;= 1
  510. </when>
  511. <when test = "param.dateTag == '前天'">
  512. and to_days(now()) - to_days(fwl.update_time) &lt;= 2
  513. </when>
  514. <when test = "param.dateTag == '近七天'">
  515. and DATE_SUB(CURDATE(), INTERVAL 7 DAY) &lt;= date(fwl.update_time)
  516. </when>
  517. </choose>
  518. </if>
  519. </where>
  520. GROUP BY
  521. fwl.qw_external_contact_id
  522. having fwl.qw_external_contact_id = #{param.contactId}
  523. </select>
  524. <update id="batchUpdateContactByIds" parameterType="map">
  525. update qw_external_contact
  526. <trim prefix="set" suffixOverrides=",">
  527. <trim prefix="status = case" suffix="end">
  528. <foreach collection="list" item="item" index="index">
  529. <if test="item.status != null">
  530. when id= #{item.id}
  531. then #{item.status}
  532. </if>
  533. </foreach>
  534. </trim>
  535. </trim>
  536. where contact_id in
  537. <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
  538. #{item.id}
  539. </foreach>
  540. </update>
  541. <update id="updateContactByIds" parameterType="map">
  542. update qw_external_contact
  543. set status = #{status}
  544. where id in
  545. <foreach collection="ids" item="id" open="(" separator="," close=")">
  546. #{id}
  547. </foreach>
  548. </update>
  549. </mapper>