|
|
<?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 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 IN (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="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>
|