QwExternalContactMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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="selectQwExternalContactListVOByIds" resultType="com.fs.qw.param.QwExternalContactVOTime">
  84. select id,tag_ids,remark,create_time,fs_user_id,avatar 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="selectAllFormAd" resultType="com.fs.qw.result.QwExternalContactLogVo">
  91. select a.*
  92. ,user.nick_name
  93. ,b.aid,b.pid,b.uid,b.userid accountId,b.comb_id,b.create_time as `time`
  94. ,creative.creative_feed_name
  95. ,plan.campaign_feed_name
  96. ,unit.adgroup_feed_name
  97. ,account.account_name
  98. ,info.sex,info.age,info.address
  99. from qw_external_contact a
  100. left join qw_external_contact_info info on a.id = info.external_contact_id
  101. inner join ad_html_click_log b on a.state = b.vid
  102. left join bd_creative creative on b.aid = creative.creative_feed_id
  103. left join bd_plan plan on b.pid = plan.campaign_feed_id
  104. left join bd_unit unit on b.uid = unit.adgroup_feed_id
  105. <if test="accountId == null and userId == null">left join </if>
  106. <if test="accountId != null || userId != null">inner join </if>
  107. bd_account account on b.userid = account.account_id
  108. left join company_user user on account.user_id = user.user_id
  109. where a.state is not null and b.click_type = 67
  110. AND date_format(b.create_time,'%Y-%m-%d %h:%i:%s') &gt;= #{start}
  111. and date_format(b.create_time,'%Y-%m-%d %h:%i:%s') &lt;= #{end}
  112. <if test="accountId != null">
  113. and account.account_id = #{accountId}
  114. </if>
  115. <if test="userId != null">
  116. and account.user_id = #{userId}
  117. </if>
  118. <if test="aid != null">
  119. and b.aid = #{aid}
  120. </if>
  121. <if test="pid != null">
  122. and b.pid = #{pid}
  123. </if>
  124. <if test="uid != null">
  125. and b.uid = #{uid}
  126. </if>
  127. group by a.id
  128. </select>
  129. <select id="selectQwExternalContactById" parameterType="Long" resultMap="QwExternalContactResult">
  130. <include refid="selectQwExternalContactVo"/>
  131. where id = #{id}
  132. </select>
  133. <update id="batchUpdateQwExternalContact" parameterType="map">
  134. UPDATE qw_external_contact
  135. SET
  136. level = CASE id
  137. <foreach collection="list" item="item">
  138. WHEN #{item.id} THEN #{item.level}
  139. </foreach>
  140. ELSE level
  141. END,
  142. level_type = CASE id
  143. <foreach collection="list" item="item">
  144. WHEN #{item.id} THEN #{item.levelType}
  145. </foreach>
  146. ELSE level_type
  147. END,
  148. last_watch_time = CASE id
  149. <foreach collection="list" item="item">
  150. WHEN #{item.id} THEN #{item.lastWatchTime}
  151. </foreach>
  152. ELSE last_watch_time
  153. END
  154. WHERE id IN
  155. <foreach collection="list" item="item" open="(" separator="," close=")">
  156. #{item.id}
  157. </foreach>
  158. </update>
  159. <update id="batchUpdateQwExternalContactStatus" parameterType="map">
  160. UPDATE qw_external_contact
  161. SET status = 4
  162. WHERE user_id = #{qwUserId}
  163. AND corp_id = #{corpId}
  164. AND external_user_id IN
  165. <foreach collection="notInExternalUseridList" item="item" open="(" separator="," close=")">
  166. #{item}
  167. </foreach>
  168. </update>
  169. <insert id="insertQwExternalContact" parameterType="QwExternalContact" useGeneratedKeys="true" keyProperty="id" >
  170. insert into qw_external_contact
  171. <trim prefix="(" suffix=")" suffixOverrides=",">
  172. <if test="id != null">id,</if>
  173. <if test="userId != null">user_id,</if>
  174. <if test="externalUserId != null">external_user_id,</if>
  175. <if test="name != null">name,</if>
  176. <if test="avatar != null">avatar,</if>
  177. <if test="type != null">type,</if>
  178. <if test="gender != null">gender,</if>
  179. <if test="remark != null">remark,</if>
  180. <if test="description != null">description,</if>
  181. <if test="tagIds != null">tag_ids,</if>
  182. <if test="remarkMobiles != null">remark_mobiles,</if>
  183. <if test="remarkCorpName != null">remark_corp_name,</if>
  184. <if test="addWay != null">add_way,</if>
  185. <if test="operUserid != null">oper_userid,</if>
  186. <if test="corpId != null">corp_id,</if>
  187. <if test="companyId != null">company_id,</if>
  188. <if test="companyUserId != null">company_user_id,</if>
  189. <if test="customerId != null">customer_id,</if>
  190. <if test="transferStatus != null">transfer_status,</if>
  191. <if test="status != null">status,</if>
  192. <if test="createTime != null">create_time,</if>
  193. <if test="transferTime != null">transfer_time,</if>
  194. <if test="transferNum != null">transfer_num,</if>
  195. <if test="lossTime != null">loss_time,</if>
  196. <if test="delTime != null">del_time,</if>
  197. <if test="qwUserId != null">qw_user_id,</if>
  198. <if test="state != null">`state`,</if>
  199. <if test="wayId != null">way_id,</if>
  200. <if test="stageStatus != null">stage_status,</if>
  201. <if test="fsUserId != null">fs_user_id,</if>
  202. <if test="openId != null">open_id,</if>
  203. <if test="unionid != null">unionid,</if>
  204. <if test="isInteract != null">is_interact,</if>
  205. <if test="level != null">level,</if>
  206. <if test="levelType != null">level_type,</if>
  207. <if test="firstTime != null">first_time,</if>
  208. </trim>
  209. <trim prefix="values (" suffix=")" suffixOverrides=",">
  210. <if test="id != null">#{id},</if>
  211. <if test="userId != null">#{userId},</if>
  212. <if test="externalUserId != null">#{externalUserId},</if>
  213. <if test="name != null">#{name},</if>
  214. <if test="avatar != null">#{avatar},</if>
  215. <if test="type != null">#{type},</if>
  216. <if test="gender != null">#{gender},</if>
  217. <if test="remark != null">#{remark},</if>
  218. <if test="description != null">#{description},</if>
  219. <if test="tagIds != null">#{tagIds},</if>
  220. <if test="remarkMobiles != null">#{remarkMobiles},</if>
  221. <if test="remarkCorpName != null">#{remarkCorpName},</if>
  222. <if test="addWay != null">#{addWay},</if>
  223. <if test="operUserid != null">#{operUserid},</if>
  224. <if test="corpId != null">#{corpId},</if>
  225. <if test="companyId != null">#{companyId},</if>
  226. <if test="companyUserId != null">#{companyUserId},</if>
  227. <if test="customerId != null">#{customerId},</if>
  228. <if test="transferStatus != null">#{transferStatus},</if>
  229. <if test="status != null">#{status},</if>
  230. <if test="createTime != null">#{createTime},</if>
  231. <if test="transferTime != null">#{transferTime},</if>
  232. <if test="transferNum != null">#{transferNum},</if>
  233. <if test="lossTime != null">#{lossTime},</if>
  234. <if test="delTime != null">#{delTime},</if>
  235. <if test="qwUserId != null">#{qwUserId},</if>
  236. <if test="state != null">#{state},</if>
  237. <if test="wayId != null">#{wayId},</if>
  238. <if test="stageStatus != null">#{stageStatus},</if>
  239. <if test="fsUserId != null">#{fsUserId},</if>
  240. <if test="openId != null">#{openId},</if>
  241. <if test="unionid != null">#{unionid},</if>
  242. <if test="isInteract != null">#{isInteract},</if>
  243. <if test="level != null">#{level},</if>
  244. <if test="levelType != null">#{levelType},</if>
  245. <if test="firstTime != null">#{firstTime},</if>
  246. </trim>
  247. </insert>
  248. <update id="updateQwExternalContact" parameterType="QwExternalContact">
  249. update qw_external_contact
  250. <trim prefix="SET" suffixOverrides=",">
  251. <if test="userId != null">user_id = #{userId},</if>
  252. <if test="corpId != null">corp_id = #{corpId},</if>
  253. <if test="externalUserId != null">external_user_id = #{externalUserId},</if>
  254. <if test="name != null">name = #{name},</if>
  255. <if test="avatar != null">avatar = #{avatar},</if>
  256. <if test="type != null">type = #{type},</if>
  257. <if test="gender != null">gender = #{gender},</if>
  258. <if test="remark != null">remark = #{remark},</if>
  259. <if test="description != null">description = #{description},</if>
  260. <if test="tagIds != null">tag_ids = #{tagIds},</if>
  261. <if test="remarkMobiles != null">remark_mobiles = #{remarkMobiles},</if>
  262. <if test="remarkCorpName != null">remark_corp_name = #{remarkCorpName},</if>
  263. <if test="addWay != null">add_way = #{addWay},</if>
  264. <if test="operUserid != null">oper_userid = #{operUserid},</if>
  265. <if test="companyId != null">company_id = #{companyId},</if>
  266. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  267. <if test="customerId != null">customer_id = #{customerId},</if>
  268. <if test="transferStatus != null">transfer_status = #{transferStatus},</if>
  269. <if test="status != null">status = #{status},</if>
  270. <if test="createTime != null">create_time = #{createTime},</if>
  271. <if test="transferTime != null">transfer_time = #{transferTime},</if>
  272. <if test="transferNum != null">transfer_num = #{transferNum},</if>
  273. <if test="lossTime != null">loss_time = #{lossTime},</if>
  274. <if test="delTime != null">del_time = #{delTime},</if>
  275. <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
  276. <if test="state != null">`state` = #{state},</if>
  277. <if test="wayId != null">way_id = #{wayId},</if>
  278. <if test="stageStatus != null">stage_status = #{stageStatus},</if>
  279. <if test="fsUserId != null">fs_user_id = #{fsUserId},</if>
  280. <if test="openId != null">open_id = #{openId},</if>
  281. <if test="unionid != null">unionid = #{unionid},</if>
  282. <if test="isInteract != null">is_interact = #{isInteract},</if>
  283. <if test="level != null">level = #{level},</if>
  284. <if test="levelType != null">level_type = #{levelType},</if>
  285. <if test="firstTime != null">first_time = #{firstTime},</if>
  286. </trim>
  287. where id = #{id}
  288. </update>
  289. <delete id="deleteQwExternalContactById" parameterType="Long">
  290. delete from qw_external_contact where id = #{id}
  291. </delete>
  292. <delete id="deleteQwExternalContactByIds" parameterType="String">
  293. delete from qw_external_contact where id in
  294. <foreach item="id" collection="array" open="(" separator="," close=")">
  295. #{id}
  296. </foreach>
  297. </delete>
  298. <select id="selectQwExternalContactListVOByUserIds" resultType="com.fs.qw.param.QwExternalContactVOTime">
  299. select id,tag_ids,remark,create_time,external_user_id from qw_external_contact
  300. where external_user_id in
  301. <foreach collection="ids" item="id" open="(" separator="," close=")">
  302. #{id}
  303. </foreach>
  304. group by external_user_id
  305. </select>
  306. <select id="selectByGroupUser" resultType="com.fs.qw.vo.GroupUserExternalVo">
  307. select id,user_id,external_user_id from qw_external_contact where external_user_id in
  308. <foreach collection="ids" open="(" separator="," close=")" item="item">#{item}</foreach>
  309. GROUP BY user_id,external_user_id
  310. </select>
  311. </mapper>