You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

340 lines
15 KiB

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.demo.mapper.bean.BeanConsumeMapper">
<!--获取消费用户分部-->
<select id="getDept" resultType="java.lang.String">
select distinct fm.dept
from fx_member fm
inner join fx_yaoqing_records fyr on fyr.uid = fm.id
where fm.dept is not null and fm.dept != ''
</select>
<!--筛选查询直播消费-->
<select id="selectLiveBy" resultType="com.example.demo.domain.vo.bean.BeanConsumeLive">
SELECT *
FROM (
SELECT fm.nickname AS name,
fm.jwcode,
fm.dept,
fyr.source_type AS type,
CASE
WHEN LOCATE('直播间', content) > 0 AND LOCATE('送礼物', content) > 0
THEN SUBSTRING(content, LOCATE('送礼物', content) + CHAR_LENGTH('送礼物'))
ELSE NULL
END AS gift,
fyr.money AS beanNum,
CASE
WHEN LOCATE('直播间', content) > 0 AND LOCATE('送礼物', content) > 0
THEN SUBSTRING_INDEX(SUBSTRING(content, LOCATE('直播间', content) + CHAR_LENGTH('直播间')), '送礼物', 1)
ELSE NULL
END AS liveChannel,
fyr.source_name AS liveName,
FROM_UNIXTIME(fyr.time, '%Y-%m-%d %H:%i:%s') AS consumeTime,
fyr.pay_type AS payType
FROM fx_member fm
INNER JOIN fx_yaoqing_records fyr ON fyr.uid = fm.id
<where>
fyr.pay_type IN (1,2,3,4,5)
<if test="beanConsumeLive.jwcode != null and beanConsumeLive.jwcode != ''">
AND fm.jwcode = #{beanConsumeLive.jwcode}
</if>
<if test="beanConsumeLive.dept != null and beanConsumeLive.dept != ''">
AND fm.dept = #{beanConsumeLive.dept}
</if>
<if test="beanConsumeLive.type != null and beanConsumeLive.type != ''">
AND fyr.source_type = #{beanConsumeLive.type}
</if>
<if test="beanConsumeLive.startTime != null and beanConsumeLive.endTime != null">
AND fyr.time BETWEEN UNIX_TIMESTAMP(#{beanConsumeLive.startTime})
AND UNIX_TIMESTAMP(#{beanConsumeLive.endTime})
</if>
</where>
) AS t
<where>
<if test="beanConsumeLive.gift != null and beanConsumeLive.gift != ''">
AND t.gift = #{beanConsumeLive.gift}
</if>
<if test="beanConsumeLive.liveChannel != null and beanConsumeLive.liveChannel != ''">
AND t.liveChannel= #{beanConsumeLive.liveChannel}
</if>
<if test="beanConsumeLive.liveName != null and beanConsumeLive.liveName != ''">
AND t.liveName LIKE CONCAT('%', #{beanConsumeLive.liveName}, '%')
</if>
</where>
<choose>
<when test="beanConsumeLive.sortField != null and beanConsumeLive.sortField != '' and beanConsumeLive.sortOrder != null and beanConsumeLive.sortOrder != ''">
ORDER BY t.${beanConsumeLive.sortField} ${beanConsumeLive.sortOrder}
</when>
<otherwise>
ORDER BY t.consumeTime DESC
</otherwise>
</choose>
</select>
<!--查询消费直播合计数-->
<select id="selectSumLiveBy" resultType="com.example.demo.domain.vo.bean.BeanConsumeGold">
SELECT
IFNULL(SUM(t.money_buy), 0) AS permanentBean,
IFNULL(SUM(t.money_free), 0) AS freeBean,
COUNT(*) AS totalNum
FROM (
SELECT
fyr.money_buy,
fyr.money_free,
fyr.time
FROM fx_member fm
INNER JOIN fx_yaoqing_records fyr ON fyr.uid = fm.id
<where>
fyr.pay_type IN (1,2,3,4,5)
<if test="beanConsumeLive.jwcode != null and beanConsumeLive.jwcode != ''">
AND fm.jwcode = #{beanConsumeLive.jwcode}
</if>
<if test="beanConsumeLive.dept != null and beanConsumeLive.dept != ''">
AND fm.dept = #{beanConsumeLive.dept}
</if>
<if test="beanConsumeLive.type != null and beanConsumeLive.type != ''">
AND fyr.source_type = #{beanConsumeLive.type}
</if>
<if test="beanConsumeLive.gift != null and beanConsumeLive.gift != ''">
AND CASE
WHEN LOCATE('直播间', fyr.content) > 0 AND LOCATE('送礼物', fyr.content) > 0
THEN SUBSTRING(fyr.content, LOCATE('送礼物', fyr.content) + CHAR_LENGTH('送礼物'))
ELSE NULL
END = #{beanConsumeLive.gift}
</if>
<if test="beanConsumeLive.liveChannel != null and beanConsumeLive.liveChannel != ''">
AND CASE
WHEN LOCATE('直播间', fyr.content) > 0 AND LOCATE('送礼物', fyr.content) > 0
THEN SUBSTRING_INDEX(SUBSTRING(fyr.content, LOCATE('直播间', fyr.content) + CHAR_LENGTH('直播间')), '送礼物', 1)
ELSE NULL
END = #{beanConsumeLive.liveChannel}
</if>
<if test="beanConsumeLive.startTime != null and beanConsumeLive.endTime != null">
AND fyr.time BETWEEN UNIX_TIMESTAMP(#{beanConsumeLive.startTime})
AND UNIX_TIMESTAMP(#{beanConsumeLive.endTime})
</if>
<if test="beanConsumeLive.liveName != null and beanConsumeLive.liveName != ''">
AND fyr.source_name LIKE CONCAT('%', #{beanConsumeLive.liveName}, '%')
</if>
</where>
) AS t
</select>
<!--筛选铁粉消费记录-->
<select id="selectFanBy" resultType="com.example.demo.domain.vo.bean.BeanConsumeFan">
SELECT fyr.id AS id,
fm.nickname AS name,
fm.jwcode,
fm.dept,
fyr.money AS beanNum,
fyr.source_name AS channel,
fyr.source_type AS type,
FROM_UNIXTIME(fyr.time, '%Y-%m-%d %H:%i:%s') AS consumeTime,
fyr.pay_type AS payType
FROM fx_member fm
INNER JOIN fx_yaoqing_records fyr ON fyr.uid = fm.id
<where>
fyr.pay_type = 7
<if test="beanConsumeFan.jwcode != null and beanConsumeFan.jwcode != ''">
AND fm.jwcode = #{beanConsumeFan.jwcode}
</if>
<if test="beanConsumeFan.dept != null and beanConsumeFan.dept != ''">
AND fm.dept = #{beanConsumeFan.dept}
</if>
<if test="beanConsumeFan.channel != null and beanConsumeFan.channel != ''">
AND fyr.source_name =#{beanConsumeFan.channel}
</if>
<if test="beanConsumeFan.startTime != null and beanConsumeFan.endTime != null">
AND fyr.time BETWEEN UNIX_TIMESTAMP(#{beanConsumeFan.startTime})
AND UNIX_TIMESTAMP(#{beanConsumeFan.endTime})
</if>
</where>
<choose>
<when test="beanConsumeFan.sortField != null and beanConsumeFan.sortField != '' and beanConsumeFan.sortOrder != null and beanConsumeFan.sortOrder != ''">
ORDER BY ${beanConsumeFan.sortField} ${beanConsumeFan.sortOrder}
</when>
<otherwise>
ORDER BY consumeTime DESC
</otherwise>
</choose>
</select>
<!--铁粉消耗合计数-->
<select id="selectSumFansBy" resultType="com.example.demo.domain.vo.bean.BeanConsumeGold">
SELECT
IFNULL(SUM(t.money_buy), 0) AS permanentBean,
IFNULL(SUM(t.money_free), 0) AS freeBean,
COUNT(*) AS totalNum
FROM (
SELECT
fyr.money_buy,
fyr.money_free,
fyr.time
FROM fx_member fm
INNER JOIN fx_yaoqing_records fyr ON fyr.uid = fm.id
<where>
fyr.pay_type = 7
<if test="beanConsumeFan.jwcode != null and beanConsumeFan.jwcode != ''">
AND fm.jwcode = #{beanConsumeFan.jwcode}
</if>
<if test="beanConsumeFan.dept != null and beanConsumeFan.dept != ''">
AND fm.dept = #{beanConsumeFan.dept}
</if>
<if test="beanConsumeFan.channel != null and beanConsumeFan.channel != ''">
AND fyr.source_name = #{beanConsumeFan.channel}
</if>
<if test="beanConsumeFan.startTime != null and beanConsumeFan.endTime != null">
AND fyr.time BETWEEN UNIX_TIMESTAMP(#{beanConsumeFan.startTime})
AND UNIX_TIMESTAMP(#{beanConsumeFan.endTime})
</if>
</where>
) AS t
</select>
<!--筛选文章消费记录-->
<select id="selectArticleBy" resultType="com.example.demo.domain.vo.bean.BeanConsumeArticle">
SELECT fyr.id AS id,
fm.nickname AS name,
fm.jwcode,
fm.dept,
fyr.source_type AS type,
fyr.money AS beanNum,
fyr.money_free AS freeBean,
fyr.money_buy AS buyBean,
fyr.source_id AS articleId,
fyr.source_name AS articleName,
(SELECT fm2.nickname
FROM fx_member fm2
WHERE fm2.jwcode = fyr.source_jwcode
LIMIT 1) AS author,
FROM_UNIXTIME(fyr.time, '%Y-%m-%d %H:%i:%s') AS consumeTime,
fyr.pay_type AS payType
FROM fx_member fm
INNER JOIN fx_yaoqing_records fyr ON fyr.uid = fm.id
<where>
fyr.pay_type = 8
<if test="beanConsumeArticle.jwcode != null and beanConsumeArticle.jwcode != ''">
AND fm.jwcode = #{beanConsumeArticle.jwcode}
</if>
<if test="beanConsumeArticle.dept != null and beanConsumeArticle.dept != ''">
AND fm.dept = #{beanConsumeArticle.dept}
</if>
<if test="beanConsumeArticle.author != null and beanConsumeArticle.author != ''">
AND (SELECT fm2.nickname
FROM fx_member fm2
WHERE fm2.jwcode = fyr.source_jwcode
LIMIT 1)=#{beanConsumeArticle.author}
</if>
<if test="beanConsumeArticle.ArticleName != null and beanConsumeArticle.ArticleName != ''">
AND fyr.source_name =#{beanConsumeArticle.ArticleName}
</if>
<if test="beanConsumeArticle.articleId != null and beanConsumeArticle.articleId != ''">
AND fyr.source_id =#{beanConsumeArticle.articleId}
</if>
<if test="beanConsumeArticle.startTime != null and beanConsumeArticle.endTime != null">
AND fyr.time BETWEEN UNIX_TIMESTAMP(#{beanConsumeArticle.startTime})
AND UNIX_TIMESTAMP(#{beanConsumeArticle.endTime})
</if>
</where>
<choose>
<when test="beanConsumeArticle.payMode == 0">
AND fyr.source_type IN (9, 10)
</when>
<when test="beanConsumeArticle.payMode == 1">
AND fyr.source_type = 11
</when>
<when test="beanConsumeArticle.payMode == 2">
AND fyr.source_type not in (9, 10,11)
</when>
<when test="beanConsumeArticle.sortField != null and beanConsumeArticle.sortField != '' and beanConsumeArticle.sortOrder != null and beanConsumeArticle.sortOrder != ''">
ORDER BY ${beanConsumeArticle.sortField} ${beanConsumeArticle.sortOrder}
</when>
<otherwise>
ORDER BY consumeTime DESC
</otherwise>
</choose>
</select>
<!--查询金豆文章消费-->
<select id="selectSumArticleBy" resultType="com.example.demo.domain.vo.bean.BeanConsumeGold">
SELECT
IFNULL(SUM(t.money_buy), 0) AS permanentBean,
IFNULL(SUM(t.money_free), 0) AS freeBean,
COUNT(*) AS totalNum
FROM ( SELECT
fyr.money_buy,
fyr.money_free,
fyr.time
FROM fx_member fm
INNER JOIN fx_yaoqing_records fyr ON fyr.uid = fm.id
<where>
fyr.pay_type = 8
<if test="beanConsumeArticle.jwcode != null and beanConsumeArticle.jwcode != ''">
AND fm.jwcode = #{beanConsumeArticle.jwcode}
</if>
<if test="beanConsumeArticle.dept != null and beanConsumeArticle.dept != ''">
AND fm.dept = #{beanConsumeArticle.dept}
</if>
<if test="beanConsumeArticle.ArticleName != null and beanConsumeArticle.ArticleName != ''">
AND fyr.source_name =#{beanConsumeArticle.ArticleName}
</if>
<if test="beanConsumeArticle.author != null and beanConsumeArticle.author != ''">
AND (SELECT fm2.nickname
FROM fx_member fm2
WHERE fm2.jwcode = fyr.source_jwcode
LIMIT 1)=#{beanConsumeArticle.author}
</if>
<if test="beanConsumeArticle.articleId != null and beanConsumeArticle.articleId != ''">
AND fyr.source_id =#{beanConsumeArticle.articleId}
</if>
<if test="beanConsumeArticle.startTime != null and beanConsumeArticle.endTime != null">
AND fyr.time BETWEEN UNIX_TIMESTAMP(#{beanConsumeArticle.startTime})
AND UNIX_TIMESTAMP(#{beanConsumeArticle.endTime})
</if>
</where>
<choose>
<when test="beanConsumeArticle.payMode == 0">
AND fyr.source_type IN (9, 10)
</when>
<when test="beanConsumeArticle.payMode == 1">
AND fyr.source_type = 11
</when>
<when test="beanConsumeArticle.payMode == 2">
AND fyr.source_type not in (9, 10,11)
</when>
</choose>
) as t
</select>
<!--获取直播礼物-->
<select id="getLiveGift" resultType="java.lang.String">
SELECT DISTINCT
CASE
WHEN LOCATE('直播间', content) > 0 AND LOCATE('送礼物', content) > 0
THEN SUBSTRING(content, LOCATE('送礼物', content) + CHAR_LENGTH('送礼物'))
ELSE NULL
END AS gift
FROM fx_yaoqing_records
WHERE LOCATE('直播间', content) > 0 AND LOCATE('送礼物', content) > 0
AND content IS NOT NULL AND source_type=1
</select>
<select id="getLiveChannel" resultType="java.lang.String">
SELECT DISTINCT
CASE
WHEN LOCATE('直播间', content) > 0 AND LOCATE('送礼物', content) > 0
THEN SUBSTRING_INDEX(SUBSTRING(content, LOCATE('直播间', content) + CHAR_LENGTH('直播间')), '送礼物', 1)
ELSE NULL
END AS liveChannel
FROM fx_yaoqing_records
WHERE LOCATE('直播间', content) > 0 AND LOCATE('送礼物', content) > 0
AND content IS NOT NULL AND pay_type in (1,2,3,4,5)
</select>
</mapper>