KuaishouPromoterMapper.xml 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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.ruixuan.isc.mapper.KuaishouPromoterMapper">
  6. <resultMap type="com.ruixuan.isc.entity.KuaishouPromoter" id="KuaishouPromoterResult">
  7. <result property="id" column="id"/>
  8. <result property="userId" column="user_id"/>
  9. <result property="mediaId" column="media_id"/>
  10. <result property="userName" column="user_name"/>
  11. <result property="promoterId" column="promoter_id"/>
  12. <result property="promoterNickName" column="promoter_nick_name"/>
  13. <result property="state" column="state"/>
  14. <result property="province" column="province"/>
  15. <result property="commissionRequirement" column="commission_requirement"/>
  16. <result property="categoryRequirement" column="category_requirement"/>
  17. <result property="createTime" column="create_time"/>
  18. <result property="promoterUrl" column="promoter_url"/>
  19. <result property="totalSale" column="total_sale"/>
  20. <result property="fansNumber" column="fans_number"/>
  21. <result property="phone" column="phone"/>
  22. <result property="consignee" column="consignee"/>
  23. <result property="promoterAddress" column="promoter_address"/>
  24. <result property="avgVideoSales" column="avg_video_sales"/>
  25. <result property="videoSales" column="video_sales"/>
  26. <result property="updateTime" column="update_time"/>
  27. <result property="monthDayGmv" column="30day_gmv"/>
  28. <result property="monthDayOrderNum" column="30day_order_num"/>
  29. <result property="validAmount" column="valid_amount"/>
  30. <result property="followerIncr" column="follower_incr"/>
  31. <result property="liveCount30" column="live_count_30"/>
  32. <result property="awemeAvgDiggCount30" column="aweme_avg_digg_count_30"/>
  33. <result property="awemeDiggFollowerRation" column="aweme_digg_follower_ration"/>
  34. <result property="liveAverageUser30" column="live_average_user_30"/>
  35. <result property="followUpRecord" column="txt"/>
  36. </resultMap>
  37. <sql id="selectKuaishouPromoterVo">
  38. select id,
  39. media_id,
  40. user_id,
  41. user_name,
  42. promoter_id,
  43. promoter_nick_name,
  44. `state`,
  45. province,
  46. commission_requirement,
  47. category_requirement,
  48. promoter_url,
  49. phone,
  50. consignee,
  51. promoter_address,
  52. total_sale,
  53. fans_number,
  54. avg_video_sales,
  55. video_sales,
  56. create_time,
  57. update_time
  58. from kuaishou_promoter
  59. </sql>
  60. <select id="selectKuaishouPromoterList" resultMap="KuaishouPromoterResult">
  61. SELECT
  62. t1.id,
  63. t1.user_id,
  64. t1.media_id,
  65. t1.user_name,
  66. t1.promoter_id,
  67. t1.promoter_nick_name,
  68. t1.`state`,
  69. t1.province,
  70. t1.commission_requirement,
  71. t1.category_requirement,
  72. t1.promoter_url,
  73. t1.phone,
  74. t1.consignee,
  75. t1.promoter_address,
  76. if(t1.media_id = 1, t1.total_sale,t3.total_sale ) as 'total_sale',
  77. if(t1.media_id = 1, t1.fans_number,t3.fans_number ) as 'fans_number',
  78. if(t1.media_id = 1, t1.avg_video_sales,t3.avg_video_sales ) as 'avg_video_sales',
  79. if(t1.media_id = 1,t1.video_sales ,t3.video_sales ) as 'video_sales',
  80. t1.create_time,
  81. t2.30day_gmv,
  82. t2.30day_order_num,
  83. t1.follower_incr,
  84. t1.live_count_30,
  85. t1.aweme_avg_digg_count_30,
  86. t1.aweme_digg_follower_ration,
  87. t1.live_average_user_30,
  88. t4.rule_id,
  89. t4.rule_name
  90. FROM
  91. kuaishou_promoter t1
  92. LEFT JOIN promoter_oerder_amount t2 on t1.promoter_id = t2.promoter_id
  93. LEFT JOIN promoter_sales_info t3 ON t1.promoter_id = t3.promoter_id
  94. left join promoter_bind_rule t4 on t1.promoter_id = t4.promoter_id
  95. <where>
  96. <if test="userList != null and userList.size() > 0 ">
  97. and t1.user_id in
  98. <foreach collection="userList" item="userId" open="(" separator="," close=")">
  99. #{userId}
  100. </foreach>
  101. </if>
  102. <if test="promoterId != null ">
  103. and t1.promoter_id = #{promoterId}
  104. </if>
  105. <if test="promoterNickName != null and promoterNickName != ''">
  106. and t1.promoter_nick_name like concat('%', #{promoterNickName}, '%')
  107. </if>
  108. <if test="mediaId != null and mediaId != ''">
  109. and t1.media_id = #{mediaId}
  110. </if>
  111. </where>
  112. order by ${parameter} ${orderBy}
  113. </select>
  114. <select id="selectAllPromoterList" resultType="com.alibaba.fastjson.JSONObject">
  115. SELECT *
  116. FROM (
  117. SELECT
  118. t1.promoter_id AS 'promoterId',
  119. (CASE WHEN t2.promoter_id IS NULL THEN 2 ELSE 1 END) AS 'status',
  120. IF(t0.promoter_name is null,t2.promoter_nick_name,t0.promoter_name) AS 'promoterNickName',
  121. IFNULL(t2.userName,'') AS 'userName',
  122. IFNULL(t2.commission_requirement,'') AS 'commissionRequirement',
  123. IF(t0.handurl is null,t2.promoter_url,t0.handurl) AS 'promoterUrl',
  124. t1.30day_gmv AS 'monthDayGmv',
  125. t1.30day_order_num AS 'monthDayOrderNum',+
  126. t1.valid_amount AS 'validAmount',
  127. IFNULL(t3.fans_number,'') AS 'fansNumber',
  128. IFNULL(t3.video_sales,'') AS 'videoSales',
  129. IFNULL(t3.avg_video_sales,'') AS 'avgVideoSales',
  130. IFNULL(t3.total_sale,'') AS 'totalSale'
  131. FROM
  132. promoter_oerder_amount t1
  133. LEFT JOIN promoter_info t0 ON t1.promoter_id = t0.promoter_id
  134. LEFT JOIN promoter_sales_info t3 ON t1.promoter_id = t3.promoter_id
  135. <choose>
  136. <when test="userId !=null and userId !='' ">
  137. RIGHT
  138. </when>
  139. <otherwise>
  140. LEFT
  141. </otherwise>
  142. </choose>
  143. JOIN (
  144. SELECT
  145. promoter_id,
  146. group_concat( user_name ) AS 'userName',
  147. fans_number, promoter_url,
  148. commission_requirement,
  149. promoter_nick_name,
  150. avg_video_sales,
  151. video_sales
  152. FROM kuaishou_promoter
  153. <where>
  154. <if test="userId != null ">
  155. and user_id = #{userId}
  156. </if>
  157. </where>
  158. GROUP BY promoter_id
  159. ) t2 ON t1.promoter_id = t2.promoter_id
  160. <where>
  161. <if test="promoterId != null ">
  162. and t1.promoter_id = #{promoterId}
  163. </if>
  164. <if test="promoterNickName != null and promoterNickName != ''">
  165. and t2.promoter_nick_name like concat('%', #{promoterNickName}, '%')
  166. </if>
  167. </where>
  168. ) t
  169. <where>
  170. <if test="status != null ">
  171. and `status` = #{status}
  172. </if>
  173. </where>
  174. order by ${parameter} ${orderBy}
  175. </select>
  176. <select id="selectKuaishouPromoterById" parameterType="Long" resultMap="KuaishouPromoterResult">
  177. <include refid="selectKuaishouPromoterVo"/>
  178. where id = #{id}
  179. </select>
  180. <select id="getFailInfo" resultMap="KuaishouPromoterResult">
  181. <include refid="selectKuaishouPromoterVo"/>
  182. where (promoter_nick_name = '' or promoter_nick_name is null)
  183. AND state =1
  184. </select>
  185. <select id="getBoundPromoterRoleKey" resultType="com.alibaba.fastjson.JSONObject">
  186. SELECT t1.user_id,
  187. t3.role_key,
  188. t1.user_name
  189. FROM kuaishou_promoter t1
  190. LEFT JOIN sys_user_role t2 ON t1.user_id = t2.user_id
  191. LEFT JOIN sys_role t3 ON t2.role_id = t3.role_id
  192. Where t1.promoter_id = #{promoterId}
  193. </select>
  194. <select id="selectPromoterIdList" resultType="String">
  195. select promoter_id
  196. from kuaishou_promoter
  197. <where>
  198. <if test="userList != null ">
  199. AND user_id in
  200. <foreach collection="userList" item="item" separator=","
  201. open="(" close=")">
  202. #{item}
  203. </foreach>
  204. </if>
  205. </where>
  206. </select>
  207. <select id="getOneByIdAndPromoterId" resultMap="KuaishouPromoterResult">
  208. <include refid="selectKuaishouPromoterVo"/>
  209. where promoter_id = #{promoterId}
  210. <if test="userId != null ">
  211. AND user_id = #{userId}
  212. </if>
  213. limit 1
  214. </select>
  215. <select id="getgetMonthPromoterTotal" resultType="com.alibaba.fastjson.JSONObject">
  216. SELECT t1.count,
  217. CONCAT(ROUND(t2.count / t1.count * 100, 2), '%') as 'rate'
  218. FROM
  219. (
  220. SELECT count(promoter_id) as 'count'
  221. FROM kuaishou_promoter
  222. WHERE DATE_FORMAT(create_time, '%Y-%m-%d') >= #{start}
  223. AND DATE_FORMAT(create_time, '%Y-%m-%d') &lt;= #{end}
  224. <if test="userList != null and userList.size() > 0 ">
  225. AND user_id in
  226. <foreach collection="userList" item="item" separator=","
  227. open="(" close=")">
  228. #{item}
  229. </foreach>
  230. </if>
  231. ) t1
  232. LEFT JOIN
  233. (SELECT count(promoter_id) as 'count'
  234. FROM kuaishou_promoter
  235. WHERE DATE_FORMAT(create_time, '%Y-%m-%d') = #{end}
  236. <if test="userList != null and userList.size() > 0 ">
  237. AND user_id in
  238. <foreach collection="userList" item="item" separator=","
  239. open="(" close=")">
  240. #{item}
  241. </foreach>
  242. </if>
  243. ) t2 ON 1 = 1
  244. </select>
  245. <insert id="insertKuaishouPromoter" parameterType="com.ruixuan.isc.entity.KuaishouPromoter" useGeneratedKeys="true"
  246. keyProperty="id">
  247. insert into kuaishou_promoter
  248. <trim prefix="(" suffix=")" suffixOverrides=",">
  249. <if test="userId != null">user_id,</if>
  250. <if test="mediaId != null">media_id,</if>
  251. <if test="userName != null">user_name,</if>
  252. <if test="promoterId != null">promoter_id,</if>
  253. <if test="promoterNickName != null">promoter_nick_name,</if>
  254. <if test="state != null">state,</if>
  255. <if test="province != null">province,</if>
  256. <if test="commissionRequirement != null">commission_requirement,</if>
  257. <if test="categoryRequirement != null">category_requirement,</if>
  258. <if test="createTime != null">create_time,</if>
  259. <if test="updateTime != null">update_time,</if>
  260. <if test="totalSale != null">total_sale,</if>
  261. <if test="fansNumber != null">fans_number,</if>
  262. <if test="promoterUrl != null">promoter_url,</if>
  263. <if test="phone != null">phone,</if>
  264. <if test="consignee != null">consignee,</if>
  265. <if test="promoterAddress != null">promoter_address,</if>
  266. </trim>
  267. <trim prefix="values (" suffix=")" suffixOverrides=",">
  268. <if test="userId != null">#{userId},</if>
  269. <if test="mediaId != null">#{mediaId},</if>
  270. <if test="userName != null">#{userName},</if>
  271. <if test="promoterId != null">#{promoterId},</if>
  272. <if test="promoterNickName != null">#{promoterNickName},</if>
  273. <if test="state != null">#{state},</if>
  274. <if test="province != null">#{province},</if>
  275. <if test="commissionRequirement != null">#{commissionRequirement},</if>
  276. <if test="categoryRequirement != null">#{categoryRequirement},</if>
  277. <if test="createTime != null">#{createTime},</if>
  278. <if test="updateTime != null">#{updateTime},</if>
  279. <if test="totalSale != null">#{totalSale},</if>
  280. <if test="fansNumber != null">#{fansNumber},</if>
  281. <if test="promoterUrl != null">#{promoterUrl},</if>
  282. <if test="phone != null">#{phone},</if>
  283. <if test="consignee != null">#{consignee},</if>
  284. <if test="promoterAddress != null">#{promoterAddress},</if>
  285. </trim>
  286. </insert>
  287. <insert id="addFollowUpRecords">
  288. insert into kuaishou_promoter_follow_up_record
  289. (promoter_id,
  290. user_id,
  291. txt)
  292. values (#{result.promoterId},
  293. #{result.userId},
  294. #{result.txt})
  295. </insert>
  296. <update id="updateFollowUpRecords">
  297. update kuaishou_promoter_follow_up_record
  298. Set txt =#{result.txt}
  299. where id = #{result.id}
  300. </update>
  301. <update id="updateKuaishouPromoter" parameterType="com.ruixuan.isc.entity.KuaishouPromoter">
  302. update kuaishou_promoter
  303. <trim prefix="SET" suffixOverrides=",">
  304. <if test="userId != null">user_id = #{userId},</if>
  305. <if test="mediaId != null">media_id = #{mediaId},</if>
  306. <if test="userName != null">user_name = #{userName},</if>
  307. <if test="promoterId != null">promoter_id = #{promoterId},</if>
  308. <if test="promoterNickName != null">promoter_nick_name = #{promoterNickName},</if>
  309. <if test="totalSale != null">total_sale = #{totalSale},</if>
  310. <if test="fansNumber != null">fans_number = #{fansNumber},</if>
  311. <if test="promoterUrl != null">promoter_url = #{promoterUrl},</if>
  312. <if test="phone != null">phone = #{phone},</if>
  313. <if test="consignee != null">consignee = #{consignee},</if>
  314. <if test="promoterAddress != null">promoter_address = #{promoterAddress},</if>
  315. <if test="state != null">state = #{state},</if>
  316. <if test="province != null">province = #{province},</if>
  317. <if test="commissionRequirement != null">commission_requirement = #{commissionRequirement},</if>
  318. <if test="categoryRequirement != null">category_requirement = #{categoryRequirement},</if>
  319. <if test="avgVideoSales != null">avg_video_sales = #{avgVideoSales},</if>
  320. <if test="videoSales != null">video_sales = #{videoSales},</if>
  321. <if test="createTime != null">create_time = #{createTime},</if>
  322. <if test="updateTime != null">update_time = #{updateTime},</if>
  323. </trim>
  324. where id = #{id}
  325. </update>
  326. <update id="updateKuaishouPromoterByPromoterId" parameterType="com.ruixuan.isc.entity.KuaishouPromoter">
  327. update kuaishou_promoter
  328. <trim prefix="SET" suffixOverrides=",">
  329. <if test="userId != null">user_id = #{userId},</if>
  330. <if test="mediaId != null">media_id = #{mediaId},</if>
  331. <if test="userName != null">user_name = #{userName},</if>
  332. <if test="promoterId != null">promoter_id = #{promoterId},</if>
  333. <if test="promoterNickName != null">promoter_nick_name = #{promoterNickName},</if>
  334. <if test="totalSale != null">total_sale = #{totalSale},</if>
  335. <if test="fansNumber != null">fans_number = #{fansNumber},</if>
  336. <if test="promoterUrl != null">promoter_url = #{promoterUrl},</if>
  337. <if test="phone != null">phone = #{phone},</if>
  338. <if test="consignee != null">consignee = #{consignee},</if>
  339. <if test="promoterAddress != null">promoter_address = #{promoterAddress},</if>
  340. <if test="state != null">state = #{state},</if>
  341. <if test="province != null">province = #{province},</if>
  342. <if test="commissionRequirement != null">commission_requirement = #{commissionRequirement},</if>
  343. <if test="categoryRequirement != null">category_requirement = #{categoryRequirement},</if>
  344. <if test="avgVideoSales != null">avg_video_sales = #{avgVideoSales},</if>
  345. <if test="videoSales != null">video_sales = #{videoSales},</if>
  346. <if test="createTime != null">create_time = #{createTime},</if>
  347. <if test="updateTime != null">update_time = #{updateTime},</if>
  348. <if test="followerIncr != null">follower_incr = #{followerIncr},</if>
  349. <if test="liveCount30 != null">live_count_30 = #{liveCount30},</if>
  350. <if test="awemeAvgDiggCount30 != null">aweme_avg_digg_count_30 = #{awemeAvgDiggCount30},</if>
  351. <if test="awemeDiggFollowerRation != null">aweme_digg_follower_ration = #{awemeDiggFollowerRation},</if>
  352. <if test="liveAverageUser30 != null">live_average_user_30 = #{liveAverageUser30},</if>
  353. </trim>
  354. where promoter_id = #{promoterId}
  355. </update>
  356. <delete id="deleteKuaishouPromoterById" parameterType="Long">
  357. delete
  358. from kuaishou_promoter
  359. where id = #{id}
  360. </delete>
  361. <delete id="deleteKuaishouPromoterByIds" parameterType="String">
  362. delete from kuaishou_promoter where id in
  363. <foreach item="id" collection="array" open="(" separator="," close=")">
  364. #{id}
  365. </foreach>
  366. </delete>
  367. <delete id="deletePromoterLabel" parameterType="String">
  368. delete
  369. from kuaishou_promoter_label_rel
  370. where promoter_id = #{promoterId}
  371. AND user_id = #{userId}
  372. </delete>
  373. <insert id="insertPromoterLabels">
  374. insert into kuaishou_promoter_label_rel
  375. (promoter_id,user_id, label_id)
  376. values
  377. <foreach collection="list" item="ent" separator=",">
  378. (#{ent.promoterId},#{ent.userId}, #{ent.labelId})
  379. </foreach>
  380. </insert>
  381. <select id="getNearlyMonthGmv" resultType="com.alibaba.fastjson.JSONObject">
  382. SELECT SUM(order_amount) as 'orderAmount', CONCAT(IFNULL(ROUND((SELECT COUNT(1)
  383. FROM kuaishou_item_collect_samples
  384. WHERE collect_sample_status = 7
  385. AND promoter_id = #{promoterId})
  386. / (SELECT COUNT(1)
  387. FROM kuaishou_item_collect_samples
  388. WHERE collect_sample_status!=1 AND collect_sample_status!=2 AND promoter_id = #{promoterId})*100,2), 0),
  389. '%') as 'operationCompletionRate'
  390. FROM kuaishou_supply_chain
  391. WHERE promoter_id = #{promoterId}
  392. AND FROM_UNIXTIME(order_create_time / 1000, '%Y-%m-%d') >= #{start}
  393. AND FROM_UNIXTIME(order_create_time / 1000, '%Y-%m-%d') &lt;= #{end}
  394. </select>
  395. <insert id="insertKuaishouPromoterRecord" parameterType="com.alibaba.fastjson.JSONObject" useGeneratedKeys="true"
  396. keyProperty="id">
  397. insert into kuaishou_promoter_record
  398. <trim prefix="(" suffix=")" suffixOverrides=",">
  399. <if test="promoterId != null">promoter_id,</if>
  400. <if test="userId != null">user_id,</if>
  401. <if test="operatorId != null">operator_id,</if>
  402. </trim>
  403. <trim prefix="values (" suffix=")" suffixOverrides=",">
  404. <if test="promoterId != null">#{promoterId},</if>
  405. <if test="userId != null">#{userId},</if>
  406. <if test="operatorId != null">#{operatorId},</if>
  407. </trim>
  408. </insert>
  409. <select id="getFollowUpRecordsByUserId" resultType="com.alibaba.fastjson.JSONObject">
  410. SELECT id,
  411. txt
  412. FROM kuaishou_promoter_follow_up_record
  413. Where promoter_id = #{promoterId}
  414. AND user_id = #{userId}
  415. ORDER BY update_time DESC LIMIT 1
  416. </select>
  417. <select id="getFollowUpRecordListByPromoterId" resultType="com.alibaba.fastjson.JSONObject">
  418. SELECT t1.id,
  419. txt,
  420. t2.nick_name as 'userName',
  421. t1.update_time as 'updateTime'
  422. FROM kuaishou_promoter_follow_up_record t1
  423. LEFT JOIN sys_user t2 ON t1.user_id = t2.user_id
  424. Where t1.promoter_id = #{promoterId}
  425. <if test="id != null">
  426. AND t1.id != #{id}
  427. </if>
  428. ORDER BY t1.update_time DESC
  429. </select>
  430. <select id="getPromoterLabel" resultType="com.alibaba.fastjson.JSONObject">
  431. SELECT t2.id as 'labelId', t2.label_colour as 'labelColour', t2.label_name as 'labelName'
  432. FROM kuaishou_promoter_label_rel t1
  433. LEFT JOIN kuaishou_label t2 ON t1.label_id = t2.id
  434. WHERE t1.promoter_id = #{promoterId}
  435. AND user_id = #{userId}
  436. order by t2.id
  437. </select>
  438. <select id="getOnlyPromoterInfoByUserId" resultType="com.ruixuan.isc.entity.KuaishouPromoter">
  439. <include refid="selectKuaishouPromoterVo"/>
  440. where promoter_id = #{promoterId}
  441. <if test="userId != null ">
  442. AND user_id = #{userId}
  443. </if>
  444. limit 1
  445. </select>
  446. <select id="getUserPromotersCount" resultType="java.lang.Integer">
  447. select promoters_count
  448. from user_promoters_count
  449. where user_id = #{userId}
  450. </select>
  451. <select id="getBoundCount" resultType="java.lang.Integer">
  452. SELECT COUNT(1)
  453. FROM `kuaishou_promoter`
  454. WHERE user_id = #{userId}
  455. </select>
  456. <select id="getRuleName" resultType="java.lang.String" parameterType="java.lang.Long">
  457. select rule_name from kuaishou_settlement_rules where id = #{ruleId}
  458. </select>
  459. <insert id="addPromotersCount">
  460. replace
  461. into user_promoters_count
  462. (user_id, promoters_count,media_id)
  463. values
  464. (
  465. #{userId},
  466. #{promotersCount},
  467. #{mediaId},
  468. )
  469. </insert>
  470. <insert id="addRule">
  471. replace into
  472. promoter_bind_rule(promoter_id,rule_id,rule_name,create_time,update_time)
  473. values
  474. (#{promoterId},#{ruleId},#{ruleName},now(),now())
  475. </insert>
  476. </mapper>