QwExternalContactMapper.xml 37 KB

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