KuaishouPromoterMapper.xml 18 KB

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