KuaishouPromoterMapper.xml 19 KB

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