QwExternalContactMapper.xml 31 KB

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