java-base-app/bd-business/bd-business-member/src/main/resources/mapper/member/statis/CuBonusLenjoyStatisMapper.xml

400 lines
19 KiB
XML
Raw Normal View History

2025-04-24 19:02:08 +08:00
<?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.hzs.member.statis.mapper.CuBonusLenjoyStatisMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.hzs.common.domain.member.statis.CuBonusVertexStatis">
<id column="PK_ID" property="pkId" />
<result column="CREATION_TIME" property="creationTime" />
<result column="PK_COUNTRY" property="pkCountry" />
<result column="DEL_FLAG" property="delFlag" />
<result column="STATIS_TYPE" property="statisType" />
<result column="PERIOD" property="period" />
<result column="START_DATE" property="startDate" />
<result column="END_DATE" property="endDate" />
<result column="MAIN_REG_AMOUNT" property="mainRegAmount" />
<result column="MAIN_UP_AMOUNT" property="mainUpAmount" />
<result column="MAIN_REPUR_AMOUNT" property="mainRepurAmount" />
<result column="HIFANS_REG_AMOUNT" property="hifansRegAmount" />
<result column="INTRODUCE_BONUS" property="introduceBonus" />
<result column="ORG_BONUS" property="orgBonus" />
<result column="LEADER_BONUS" property="leaderBonus" />
<result column="SHARE_BONUS" property="shareBonus" />
<result column="SERVICE_BONUS" property="serviceBonus" />
<result column="HI_FUN_INCOME" property="hiFunIncome" />
<result column="REPUR_RANGE_BONUS" property="repurRangeBonus" />
<result column="REPUR_ORG_BONUS" property="repurOrgBonus" />
<result column="MAIN_BONUS" property="mainBonus" />
<result column="REPUR_BONUS" property="repurBonus" />
<result column="PK_BD_VERTEX" property="pkBdVertex" />
<result column="PK_TEAM_CODE" property="pkTeamCode" />
<result column="HAI_FUN_INCOME" property="haiFunIncome" />
<result column="GIFT_ORDER" property="giftOrder" />
<result column="SPECIAL_REGISTER_AMOUNT" property="specialRegisterAmount" />
<result column="SPECIAL_UPGRADE_AMOUNT" property="specialUpgradeAmount" />
<result column="CLOUD_COLLEGE_AMOUNT" property="cloudCollegeAmount" />
<result column="MALL_AMOUNT" property="mallAmount" />
<result column="MAKER_GIFT_AMOUNT" property="makerGiftAmount" />
<result column="EMPOWERMENT_GIFT_AMOUNT" property="empowermentGiftAmount" />
<result column="COOPERATE_AMOUNT" property="cooperateAmount" />
<result column="SPECIAL_REPURCHASE_AMOUNT" property="specialRepurchaseAmount" />
<result column="HAI_FUN_UPGRADE_AMOUNT" property="haiFunUpgradeAmount" />
<result column="REPUR_PUSH_INCOME" property="repurPushIncome" />
<result column="MAKER_DIRECT" property="makerDirect" />
<result column="MAKER_SHARE" property="makerShare" />
<result column="THIRD_ORDER" property="thirdOrder" />
<result column="FICTITIOUS_AMOUNT" property="fictitiousAmount" />
<result column="MAKER_ORDER" property="makerOrder" />
<result column="WELFARE_ORDER" property="welfareOrder" />
<result column="MAIN_REG_PV" property="mainRegPv" />
<result column="MAIN_UP_PV" property="mainUpPv" />
<result column="MAIN_REPUR_PV" property="mainRepurPv" />
<result column="SPECIAL_REGISTER_PV" property="specialRegisterPv" />
<result column="SPECIAL_UPGRADE_PV" property="specialUpgradePv" />
<result column="SPECIAL_REPURCHASE_PV" property="specialRepurchasePv" />
<result column="FICTITIOUS_PV" property="fictitiousPv" />
<result column="HIFANS_REG_PV" property="hifansRegPv" />
<result column="HAI_FUN_UPGRADE_PV" property="haiFunUpgradePv" />
<result column="CLOUD_COLLEGE_PV" property="cloudCollegePv" />
<result column="MALL_PV" property="mallPv" />
<result column="EMPOWERMENT_GIFT_PV" property="empowermentGiftPv" />
<result column="COOPERATE_PV" property="cooperatePv" />
<result column="MAKER_ORDER_PV" property="makerOrderPv" />
<result column="MAKER_GIFT_PV" property="makerGiftPv" />
<result column="WELFARE_ORDER_PV" property="welfareOrderPv" />
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
CREATION_TIME,
PK_COUNTRY,
DEL_FLAG,
PK_ID, STATIS_TYPE, PERIOD, START_DATE, END_DATE, MAIN_REG_AMOUNT, MAIN_UP_AMOUNT, MAIN_REPUR_AMOUNT, HIFANS_REG_AMOUNT, INTRODUCE_BONUS, ORG_BONUS, LEADER_BONUS, SHARE_BONUS, SERVICE_BONUS, HI_FUN_INCOME, REPUR_RANGE_BONUS, REPUR_ORG_BONUS, MAIN_BONUS, REPUR_BONUS, PK_BD_VERTEX, PK_TEAM_CODE, HAI_FUN_INCOME, GIFT_ORDER, SPECIAL_REGISTER_AMOUNT, SPECIAL_UPGRADE_AMOUNT, CLOUD_COLLEGE_AMOUNT, MALL_AMOUNT, MAKER_GIFT_AMOUNT, EMPOWERMENT_GIFT_AMOUNT, COOPERATE_AMOUNT, SPECIAL_REPURCHASE_AMOUNT, HAI_FUN_UPGRADE_AMOUNT, REPUR_PUSH_INCOME, MAKER_DIRECT, MAKER_SHARE, THIRD_ORDER, FICTITIOUS_AMOUNT, MAKER_ORDER, WELFARE_ORDER, MAIN_REG_PV, MAIN_UP_PV, MAIN_REPUR_PV, SPECIAL_REGISTER_PV, SPECIAL_UPGRADE_PV, SPECIAL_REPURCHASE_PV, FICTITIOUS_PV, HIFANS_REG_PV, HAI_FUN_UPGRADE_PV, CLOUD_COLLEGE_PV, MALL_PV, EMPOWERMENT_GIFT_PV, COOPERATE_PV, MAKER_ORDER_PV, MAKER_GIFT_PV, WELFARE_ORDER_PV
</sql>
<!-- 奖金拨比列表-->
<select id="queryCuBonusStatis" parameterType="com.hzs.member.statis.vo.CuBonusLenjoyStatisVO"
resultType="com.hzs.member.statis.vo.CuBonusLenjoyStatisVO">
SELECT
cbs.LENJOY_AMOUNT lenjoyAmount,
cbs.LENJOY_PV lenjoyPv,
cbs.CLOUD_REAL_SUBTOTAL cloudRealSubtotal,
cbs.PK_BD_VERTEX pkVertex,
cbs.PK_TEAM_CODE pkTeamCode,
cm.MEMBER_CODE as memberCode,
cm.MEMBER_NAME as memberName,
cbs.PK_ID pkId,
cbs.PERIOD period,
cbs.CREATION_TIME creationTime,
cbs.PK_COUNTRY pkCountry,
CASE WHEN (cbs.LENJOY_AMOUNT)=0 THEN 0 ELSE
ROUND(#{perCent}*cbs.CLOUD_REAL_SUBTOTAL/(cbs.LENJOY_AMOUNT),4) end as lenjoyRate
FROM
CU_BONUS_VERTEX_STATIS cbs
LEFT JOIN CU_MEMBER cm ON cm.PK_ID = cbs.PK_BD_VERTEX AND cm.DEL_FLAG = 0 and cm.SYSTEM_TYPE=1
WHERE 1=1
<if test="pkCountry != null">
and cbs.PK_COUNTRY=#{pkCountry}
</if>
<if test="pkVertex != null ">
and cbs.PK_BD_VERTEX =#{pkVertex}
</if>
<if test="startDate!=null and startDate!='' ">
and cbs.CREATION_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
</if>
<if test="endDate!=null and endDate!='' ">
and cbs.CREATION_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
</if>
ORDER BY cbs.CREATION_TIME asc
</select>
<!-- 乐享奖金拨比汇总(最后一行)-->
<select id="queryCuBonusSumStatis" parameterType="com.hzs.member.statis.vo.CuBonusLenjoyStatisVO"
resultType="com.hzs.member.statis.vo.CuBonusLenjoyStatisVO">
SELECT
SUM(cbs.LENJOY_AMOUNT) lenjoyAmount,
SUM(cbs.LENJOY_PV*#{rate}) lenjoyPv,
SUM(cbs.CLOUD_REAL_SUBTOTAL*#{rate}) cloudRealSubtotal,
CASE WHEN (SUM(cbs.LENJOY_AMOUNT))=0 THEN 0 ELSE
ROUND(#{perCent}*SUM(cbs.CLOUD_REAL_SUBTOTAL)/(SUM(cbs.LENJOY_AMOUNT)),4) end as lenjoyRate
FROM
CU_BONUS_VERTEX_STATIS cbs
LEFT JOIN CU_MEMBER cm ON cm.PK_ID = cbs.PK_BD_VERTEX AND cm.DEL_FLAG = 0 and cm.SYSTEM_TYPE=1
WHERE 1=1
<if test="pkCountry != null">
and cbs.PK_COUNTRY=#{pkCountry}
</if>
<if test="pkVertex != null ">
and cbs.PK_BD_VERTEX =#{pkVertex}
</if>
<if test="startDate!=null and startDate!='' ">
and cbs.CREATION_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
</if>
<if test="endDate!=null and endDate!='' ">
and cbs.CREATION_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
</if>
</select>
<!-- 7天重算查询订单-->
<select id="queryAnewSaOrderByLessDay" parameterType="com.hzs.member.statis.vo.CuBonusLenjoyStatisVO"
resultType="com.hzs.member.statis.vo.CuBonusLenjoyStatisVO">
select * from (
select
cm.pk_Member pkMember,
#{pkVertex} pkVertex,
so.PK_COUNTRY pkCountry,
so.ORDER_TYPE orderType,
so.ORDER_AMOUNT orderAmount,
so.ORDER_ACHIEVE orderAchieve,
to_date(to_char(so.PAY_TIME, 'yyyy-mm-dd'),'yyyy-mm-dd') AS creationTime
from (
SELECT
pk_member
FROM
${settleTableName}
WHERE category=0
start with PK_PARENT = #{pkVertex}
connect by PK_PARENT = prior pk_member
) cm
INNER JOIN SA_ORDER so on so.pk_member=cm.pk_member
where so.ORDER_TYPE in (40)
<if test="pkCountry != null">
and so.pk_country=#{pkCountry}
</if>
<if test="delFlag != null">
AND so.DEL_FLAG=#{delFlag}
</if>
<if test="orderStatus != null">
AND so.order_status=#{orderStatus}
</if>
<if test="startDate != null and startDate!='' ">
and so.PAY_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
</if>
<if test="endDate != null and endDate!='' ">
and so.PAY_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
</if>
)
</select>
<!-- 删除奖金拨比统计表数据-->
<delete id="delStatis">
delete from CU_BONUS_VERTEX_STATIS
where 1=1
<if test="pkVertexList!=null and pkVertexList.size> 0 ">
and PK_BD_VERTEX in
<foreach collection="pkVertexList" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<if test="startDate != null and startDate!='' ">
and CREATION_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
</if>
<if test="endDate != null and endDate!='' ">
and CREATION_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
</if>
</delete>
<!-- 查询有效顶点-->
<select id="vertexList" parameterType="com.hzs.member.statis.vo.CuBonusLenjoyStatisVO"
resultType="com.hzs.member.statis.vo.CuBonusLenjoyStatisVO">
SELECT
pk_id as pkVertex,
MEMBER_CODE as memberCode,
MEMBER_NAME as memberName
FROM
cu_member m
WHERE
m.pk_place_parent = 2
AND m.del_flag = 0
AND m.pk_country = 1
AND m.category = 0
AND m.pay_status =1
AND m.SYSTEM_TYPE =1
<if test="pkVertex!=null">
AND m.pk_id=#{pkVertex}
</if>
</select>
<!-- 查询中国奖金-->
<select id="queryChinaCountryBonus" parameterType="com.hzs.member.statis.vo.CuBonusLenjoyStatisVO"
resultType="com.hzs.member.statis.vo.CuBonusLenjoyStatisVO">
select
#{pkCountry} pkCountry,sum(mbp.REAL_INCOME) realIncome,
mbp.PK_COUNTRY con,
bbi.BONUS_VALUE bonusType,
#{pkVertex} pkVertex,
to_date(to_char(so.PAY_TIME, 'yyyy-mm-dd'),'yyyy-mm-dd') AS creationTime
from cu_member_bonus_push mbp
INNER JOIN CU_MEMBER_BONUS cmb on mbp.PK_BONUS=cmb.pk_id
INNER join ( SELECT cm.pk_id FROM cu_member cm WHERE del_flag = 0 AND category = 0 START WITH PK_PARENT =#{pkVertex} CONNECT BY pk_place_parent = PRIOR pk_id ) cm
on cm.pk_id = cmb.pk_member
inner join BD_BONUS_ITEMS bbi on bbi.pk_id=mbp.PK_BONUS_ITEMS
INNER JOIN sa_order so on so.pk_id=mbp.pk_order and so.PK_COUNTRY=#{pkCountry} and so.del_flag=0
where mbp.DEL_FLAG=0
and mbp.INCOME_STATUS=0
and bbi.BONUS_VALUE in (3,4,5,7,8,9,12,24,20,21,14,15,16,1)
<if test="startDate!=null and startDate!='' ">
and so.PAY_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
</if>
<if test="endDate!=null and endDate!='' ">
and so.PAY_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
</if>
GROUP BY mbp.PK_COUNTRY,
bbi.BONUS_VALUE,
to_char(so.PAY_TIME, 'yyyy-mm-dd')
UNION ALL
select
#{pkCountry} pkCountry,sum(mbe.REAL_INCOME) realIncome,
mbe.PK_COUNTRY con,
bbi.BONUS_VALUE bonusType,
#{pkVertex} pkVertex,
to_date(to_char(so.PAY_TIME, 'yyyy-mm-dd'),'yyyy-mm-dd') AS creationTime
from CU_MEMBER_BONUS_EXPAND mbe
INNER JOIN CU_MEMBER_BONUS cmb on mbe.PK_BONUS=cmb.pk_id
INNER join ( SELECT cm.pk_id FROM cu_member cm WHERE del_flag = 0 AND category = 0 START WITH PK_PARENT =#{pkVertex} CONNECT BY pk_place_parent = PRIOR pk_id ) cm
on cm.pk_id = cmb.pk_member
inner join BD_BONUS_ITEMS bbi on bbi.pk_id=mbe.PK_BONUS_ITEMS
INNER JOIN sa_order so on so.pk_id=mbe.pk_order and so.PK_COUNTRY=#{pkCountry} and so.del_flag=0
where mbe.DEL_FLAG=0
and mbe.INCOME_STATUS=0
and bbi.BONUS_VALUE in (3,4,5,7,8,9,12,24,20,21,14,15,16,1)
<if test="startDate!=null and startDate!='' ">
and so.PAY_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
</if>
<if test="endDate!=null and endDate!='' ">
and so.PAY_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
</if>
GROUP BY mbe.PK_COUNTRY,
bbi.BONUS_VALUE,
to_char(so.PAY_TIME, 'yyyy-mm-dd')
UNION ALL
select
#{pkCountry} pkCountry,sum(mbc.REAL_INCOME) realIncome,
mbc.PK_COUNTRY con,
bbi.BONUS_VALUE bonusType,
#{pkVertex} pkVertex,
to_date(to_char(so.PAY_TIME, 'yyyy-mm-dd'),'yyyy-mm-dd') AS creationTime
from CU_MEMBER_BONUS_COACH mbc
INNER JOIN CU_MEMBER_BONUS cmb on mbc.PK_BONUS=cmb.pk_id
INNER join ( SELECT cm.pk_id FROM cu_member cm WHERE del_flag = 0 AND category = 0 START WITH PK_PARENT =#{pkVertex} CONNECT BY pk_place_parent = PRIOR pk_id ) cm
on cm.pk_id = cmb.pk_member
inner join BD_BONUS_ITEMS bbi on bbi.pk_id=mbc.PK_BONUS_ITEMS
INNER JOIN sa_order so on so.pk_id=mbc.pk_order and so.PK_COUNTRY=#{pkCountry} and so.del_flag=0
where mbc.DEL_FLAG=0
and mbc.INCOME_STATUS=0
and bbi.BONUS_VALUE in (3,4,5,7,8,9,12,24,20,21,14,15,16,1)
<if test="startDate!=null and startDate!='' ">
and so.PAY_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
</if>
<if test="endDate!=null and endDate!='' ">
and so.PAY_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
</if>
GROUP BY mbc.PK_COUNTRY,
bbi.BONUS_VALUE,
to_char(so.PAY_TIME, 'yyyy-mm-dd')
UNION ALL
select
#{pkCountry} pkCountry,sum(mbr.REAL_INCOME) realIncome,
mbr.PK_COUNTRY con,
bbi.BONUS_VALUE bonusType,
#{pkVertex} pkVertex,
to_date(to_char(so.PAY_TIME, 'yyyy-mm-dd'),'yyyy-mm-dd') AS creationTime
from cu_member_bonus_range mbr
INNER JOIN CU_MEMBER_BONUS cmb on mbr.PK_BONUS=cmb.pk_id
INNER join ( SELECT cm.pk_id FROM cu_member cm WHERE del_flag = 0 AND category = 0 START WITH PK_PARENT =#{pkVertex} CONNECT BY pk_place_parent = PRIOR pk_id ) cm
on cm.pk_id = cmb.pk_member
inner join BD_BONUS_ITEMS bbi on bbi.pk_id=mbr.PK_BONUS_ITEMS
INNER JOIN sa_order so on so.pk_id=mbr.pk_order and so.PK_COUNTRY=#{pkCountry} and so.del_flag=0
where mbr.DEL_FLAG=0
and mbr.INCOME_STATUS=0
and bbi.BONUS_VALUE in (3,4,5,7,8,9,12,24,20,21,14,15,16,1)
<if test="startDate!=null and startDate!='' ">
and so.PAY_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
</if>
<if test="endDate!=null and endDate!='' ">
and so.PAY_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
</if>
GROUP BY bbi.BONUS_VALUE,
mbr.PK_COUNTRY,
to_char(so.PAY_TIME, 'yyyy-mm-dd')
UNION ALL
select
#{pkCountry} pkCountry,sum(mbd.REAL_INCOME) realIncome,
mbd.PK_COUNTRY con,
bbi.BONUS_VALUE bonusType,
#{pkVertex} pkVertex,
to_date(to_char(so.PAY_TIME, 'yyyy-mm-dd'),'yyyy-mm-dd') AS creationTime
from cu_member_bonus_detail mbd
INNER JOIN CU_MEMBER_BONUS cmb on mbd.PK_BONUS=cmb.pk_id
INNER join ( SELECT cm.pk_id FROM cu_member cm WHERE del_flag = 0 AND category = 0 START WITH PK_PARENT =#{pkVertex} CONNECT BY pk_place_parent = PRIOR pk_id ) cm
on cm.pk_id = cmb.pk_member
inner join BD_BONUS_ITEMS bbi on bbi.pk_id=mbd.PK_BONUS_ITEMS
INNER JOIN sa_order so on so.pk_id=mbd.pk_order and so.PK_COUNTRY=#{pkCountry} and so.del_flag=0
where mbd.DEL_FLAG=0
and mbd.INCOME_STATUS=0
and bbi.BONUS_VALUE in (3,4,5,7,8,9,12,24,20,21,14,15,16,1)
<if test="startDate!=null and startDate!='' ">
and so.PAY_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
</if>
<if test="endDate!=null and endDate!='' ">
and so.PAY_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
</if>
GROUP BY bbi.BONUS_VALUE,
mbd.PK_COUNTRY,
to_char(so.PAY_TIME, 'yyyy-mm-dd')
</select>
<!-- 查询7天重算奖金查询-->
<select id="queryVertexChinaCountryBonus" parameterType="com.hzs.member.statis.vo.CuBonusLenjoyStatisVO"
resultType="com.hzs.member.statis.vo.CuBonusLenjoyStatisVO">
select
1 pkCountry,
sum(cmb.CLOUD_REAL_SUBTOTAL) realIncome,
#{pkVertex} pkVertex,
to_date(to_char(cmsp.SETTLE_DATE, 'yyyy-mm-dd'),'yyyy-mm-dd') AS creationTime
from CU_MEMBER_BONUS cmb
INNER join ( SELECT
pk_member
FROM
${settleTableName}
WHERE category=0
start with pk_member = #{pkVertex}
connect by PK_PARENT = prior pk_member ) cm
on cm.pk_member = cmb.pk_member
INNER JOIN CU_MEMBER_SETTLE_PERIOD cmsp on cmsp.pk_id=cmb.PERIOD
where cmb.DEL_FLAG=0
and cmb.PERIOD=#{period}
GROUP BY
to_char(cmsp.SETTLE_DATE, 'yyyy-mm-dd')
</select>
<!-- 查询当天团队统计数据-->
<select id="getCuBonusStatis" parameterType="com.hzs.common.domain.member.statis.CuBonusVertexStatis"
resultType="com.hzs.common.domain.member.statis.CuBonusVertexStatis">
SELECT *
FROM
CU_BONUS_VERTEX_STATIS a
WHERE
1=1
<if test="pkBdVertex != null ">
AND a.PK_BD_VERTEX = #{pkBdVertex}
</if>
<if test="pkCountry != null ">
AND a.PK_COUNTRY = #{pkCountry}
</if>
<if test="creationTime != null ">
and to_char(a.CREATION_TIME, 'yyyy-mm-dd') = to_char(#{creationTime}, 'yyyy-mm-dd')
</if>
</select>
</mapper>