1. 后台首页统计看板,用户积分,福利积分,现金券,用户积分总产出/消耗 平台线上/线下总消费,每日线上/线下消费新增
This commit is contained in:
2026-05-30 13:23:49 +08:00
parent c9c36e8b5c
commit ff17b788bf
32 changed files with 276 additions and 27 deletions

View File

@@ -0,0 +1,5 @@
-- 可选:加速正数查询
CREATE INDEX idx_user_point_log_amount_positive ON user_point_log (amount) WHERE amount > 0;
-- 可选:加速负数查询
CREATE INDEX idx_user_point_log_amount_negative ON user_point_log (amount) WHERE amount < 0;

View File

@@ -5,6 +5,7 @@ import org.springblade.modules.common.pojo.entity.CommonUserPointLogEntity;
import org.springblade.modules.common.pojo.vo.CommonUserPointLogVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.market.pojo.vo.MarketUserPointSummaryVO;
import java.util.Date;
import java.util.List;
@@ -28,4 +29,7 @@ public interface CommonUserPointLogMapper extends BaseMapper<CommonUserPointLogE
List<CommonUserPointLogExcel> exportUserPointLog(String account, Date startTime, Date endTime);
MarketUserPointSummaryVO userPointSummary();
}

View File

@@ -49,5 +49,12 @@
order by upl.id desc
</select>
<select id="userPointSummary" resultType="org.springblade.modules.market.pojo.vo.MarketUserPointSummaryVO">
SELECT
SUM(amount) FILTER (WHERE amount &gt; 0) AS added,
ABS(SUM(amount) FILTER (WHERE amount &lt; 0)) AS deducted
FROM user_point_log where is_deleted = 0
</select>
</mapper>

View File

@@ -29,4 +29,7 @@ public interface CommonUserPointMapper extends BaseMapper<CommonUserPointEntity>
int addUserPoint(Long userId, BigDecimal amount, Integer version);
int deductUserPoint(Long userId, BigDecimal amount, Integer version);
BigDecimal selectTotal();
}

View File

@@ -31,6 +31,12 @@
order by up.id desc
</select>
<select id="selectTotal" resultType="java.math.BigDecimal">
SELECT COALESCE(SUM(amount), 0)
FROM user_point
where is_deleted = 0
</select>
<update id="addUserPoint">
update
user_point

View File

@@ -31,6 +31,7 @@ import org.springblade.modules.common.pojo.entity.CommonUserPointLogEntity;
import org.springblade.modules.common.pojo.vo.CommonUserPointLogVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseService;
import org.springblade.modules.market.pojo.vo.MarketUserPointSummaryVO;
import java.math.BigDecimal;
import java.util.List;
@@ -55,4 +56,5 @@ public interface ICommonUserPointLogService extends BaseService<CommonUserPointL
List<CommonUserPointLogExcel> exportUserPointLog(String account, List<String> searchDateRange);
MarketUserPointSummaryVO userPointSummaryByLog();
}

View File

@@ -7,6 +7,7 @@ import org.springblade.modules.common.pojo.entity.CommonUserPointLogEntity;
import org.springblade.modules.common.pojo.vo.CommonUserPointVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseService;
import org.springblade.modules.market.pojo.vo.MarketUserPointSummaryVO;
import java.math.BigDecimal;
import java.util.List;
@@ -36,4 +37,8 @@ public interface ICommonUserPointService extends BaseService<CommonUserPointEnti
void spendPointForOrder(CommonUserOrderEntity order);
List<CommonUserPointLogEntity> queryLogsByUserId(Long userId, Integer size);
BigDecimal selectTotal();
MarketUserPointSummaryVO userPointSummary();
}

View File

@@ -8,6 +8,7 @@ import org.springblade.modules.common.pojo.vo.CommonUserPointLogVO;
import org.springblade.modules.common.mapper.CommonUserPointLogMapper;
import org.springblade.modules.common.service.ICommonUserPointLogService;
import org.springblade.modules.market.eums.MarketLogType;
import org.springblade.modules.market.pojo.vo.MarketUserPointSummaryVO;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseServiceImpl;
@@ -65,5 +66,10 @@ public class CommonUserPointLogServiceImpl extends BaseServiceImpl<CommonUserPoi
return logExcelList;
}
@Override
public MarketUserPointSummaryVO userPointSummaryByLog() {
return baseMapper.userPointSummary();
}
}

View File

@@ -17,6 +17,7 @@ import org.springblade.modules.common.pojo.vo.CommonUserPointVO;
import org.springblade.modules.common.mapper.CommonUserPointMapper;
import org.springblade.modules.common.service.ICommonUserPointLogService;
import org.springblade.modules.common.service.ICommonUserPointService;
import org.springblade.modules.market.pojo.vo.MarketUserPointSummaryVO;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -132,5 +133,13 @@ public class CommonUserPointServiceImpl extends BaseServiceImpl<CommonUserPointM
);
}
@Override
public BigDecimal selectTotal() {
return baseMapper.selectTotal();
}
@Override
public MarketUserPointSummaryVO userPointSummary() {
return userPointLogService.userPointSummaryByLog();
}
}

View File

@@ -78,6 +78,7 @@ public class MarketInfoController extends BladeController {
MarketInfoEntity detail = marketInfoService.getOne(Condition.getQueryWrapper(marketInfo));
return R.data(MarketInfoWrapper.build().entityVO(detail));
}
/**
* 用户拓展信息表 分页
*/
@@ -192,4 +193,25 @@ public class MarketInfoController extends BladeController {
return R.data(marketInfoService.userFlowList(id, type));
}
@GetMapping("/data-summary")
@ApiOperationSupport(order = 15)
@Operation(summary = "面板数据统计")
public R<MarketDataSummaryVO> dataSummary() {
return R.data(marketInfoService.dataSummary());
}
@GetMapping("/user-point-summary")
@ApiOperationSupport(order = 16)
@Operation(summary = "面板用户积分数据统计")
public R<MarketUserPointSummaryVO> userPointSummary() {
return R.data(marketInfoService.userPointSummary());
}
@GetMapping("/user-order-summary")
@ApiOperationSupport(order = 17)
@Operation(summary = "面板用户消费数据统计")
public R<MarketUserOrderSummaryVO> userOrderSummary() {
return R.data(summaryService.userOrderSummary());
}
}

View File

@@ -32,4 +32,5 @@ public interface MarketBenefitPointMapper extends BaseMapper<MarketBenefitPointE
int addBenefitPointBatch(@Param("teamBenefitPointList") List<MarketBenefitPointEntity> teamBenefitPointList);
BigDecimal selectTotal();
}

View File

@@ -32,6 +32,12 @@
</select>
<select id="selectTotal" resultType="java.math.BigDecimal">
SELECT COALESCE(SUM(amount), 0)
FROM benefit_point
where is_deleted = 0
</select>
<update id="addBenefitPoint">
update
benefit_point

View File

@@ -29,4 +29,6 @@ public interface MarketCashCouponMapper extends BaseMapper<MarketCashCouponEntit
int addCashCoupon(Long userId, BigDecimal amount, Integer version);
int deductCashCoupon(Long userId, BigDecimal amount, Integer version);
BigDecimal selectTotal();
}

View File

@@ -31,6 +31,11 @@
order by cc.id desc
</select>
<select id="selectTotal" resultType="java.math.BigDecimal">
SELECT COALESCE(SUM(amount), 0)
FROM cash_coupon
where is_deleted = 0
</select>
<update id="addCashCoupon">
update

View File

@@ -60,4 +60,6 @@ public interface MarketInfoMapper extends BaseMapper<MarketInfoEntity> {
MarketDirectInfoApiVO selectParent(Long pid);
List<Long> selectIdsByPid(Long pid);
List<Long> selectTopUsersIds();
}

View File

@@ -96,4 +96,9 @@
from user_market_info where is_deleted = 0 and pid = #{pid}
</select>
<select id="selectTopUsersIds" resultType="java.lang.Long">
select id
from user_market_info where is_deleted = 0 and pid is null
</select>
</mapper>

View File

@@ -52,4 +52,6 @@ public interface MarketUserCommissionMapper extends BaseMapper<MarketUserCommiss
int addUserCommission(Long userId, BigDecimal amount, Integer version);
BigDecimal selectTotal();
}

View File

@@ -30,6 +30,12 @@
order by uc.id desc
</select>
<select id="selectTotal" resultType="java.math.BigDecimal">
SELECT COALESCE(SUM(amount), 0)
FROM user_commission
where is_deleted = 0
</select>
<update id="addUserCommission">
update
user_commission

View File

@@ -0,0 +1,23 @@
package org.springblade.modules.market.pojo.vo;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
@Data
public class MarketDataSummaryVO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private BigDecimal userPoints;
private BigDecimal benefitPoints;
private BigDecimal cashCoupons;
private BigDecimal commissions;
}

View File

@@ -0,0 +1,27 @@
package org.springblade.modules.market.pojo.vo;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
@Data
public class MarketUserOrderSummaryVO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private BigDecimal onlineTotal;
private BigDecimal offlineTotal;
private BigDecimal otherTotal;
private BigDecimal increaseOnline;
private BigDecimal increaseOffline;
private BigDecimal increaseOther;
}

View File

@@ -0,0 +1,19 @@
package org.springblade.modules.market.pojo.vo;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
@Data
public class MarketUserPointSummaryVO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private BigDecimal added;
private BigDecimal deducted;
}

View File

@@ -54,5 +54,5 @@ public interface IMarketBenefitPointService extends BaseService<MarketBenefitPoi
List<MarketBenefitPointLogEntity> queryLogsByUserId(Long userId, Integer size);
BigDecimal selectTotal();
}

View File

@@ -7,6 +7,7 @@ import org.springblade.modules.market.pojo.vo.MarketCashCouponVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseService;
import java.math.BigDecimal;
import java.util.List;
/**
@@ -47,4 +48,5 @@ public interface IMarketCashCouponService extends BaseService<MarketCashCouponEn
List<MarketCashCouponLogEntity> queryLogsByUserId(Long userId, Integer size);
BigDecimal selectTotal();
}

View File

@@ -33,6 +33,8 @@ import org.springblade.modules.market.pojo.vo.MarketDailySummaryVO;
import org.springblade.modules.market.excel.MarketDailySummaryExcel;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseService;
import org.springblade.modules.market.pojo.vo.MarketUserOrderSummaryVO;
import java.util.List;
/**
@@ -58,4 +60,7 @@ public interface IMarketDailySummaryService extends BaseService<MarketDailySumma
List<MarketDailySummaryEntity> selectListByUserId(Long userId);
MarketKPIApiVO userSelfKpi(Long userId);
MarketUserOrderSummaryVO userOrderSummary();
}

View File

@@ -28,10 +28,12 @@ package org.springblade.modules.market.service;
import org.springblade.modules.api.vo.MarketDirectInfoApiVO;
import org.springblade.modules.market.pojo.dto.MarketInfoSummaryDTO;
import org.springblade.modules.market.pojo.entity.MarketInfoEntity;
import org.springblade.modules.market.pojo.vo.MarketDataSummaryVO;
import org.springblade.modules.market.pojo.vo.MarketInfoVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseService;
import org.springblade.modules.market.pojo.vo.MarketUserFlowVO;
import org.springblade.modules.market.pojo.vo.MarketUserPointSummaryVO;
import org.springblade.modules.system.pojo.entity.User;
import java.util.Date;
@@ -70,4 +72,10 @@ public interface IMarketInfoService extends BaseService<MarketInfoEntity> {
List<Long> selectIdsByPid(Long pid);
List<MarketUserFlowVO> userFlowList(Long id, Integer type);
MarketDataSummaryVO dataSummary();
MarketUserPointSummaryVO userPointSummary();
List<Long> selectTopUsersIds();
}

View File

@@ -32,6 +32,7 @@ import org.springblade.modules.market.pojo.vo.MarketUserCommissionVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseService;
import java.math.BigDecimal;
import java.util.List;
/**
@@ -54,4 +55,7 @@ public interface IMarketUserCommissionService extends BaseService<MarketUserComm
void earnedCommissionByUserOrder(CommonUserOrderEntity order, Long userId);
List<MarketUserCommissionLogEntity> queryLogsByUserId(Long userId, Integer size);
BigDecimal selectTotal();
}

View File

@@ -199,7 +199,8 @@ public class MarketBenefitPointServiceImpl extends BaseServiceImpl<MarketBenefit
throw new RuntimeException("请稍后重试");
}
@Override
public BigDecimal selectTotal() {
return baseMapper.selectTotal();
}
}

View File

@@ -123,5 +123,10 @@ public class MarketCashCouponServiceImpl extends BaseServiceImpl<MarketCashCoupo
);
}
@Override
public BigDecimal selectTotal() {
return baseMapper.selectTotal();
}
}

View File

@@ -25,6 +25,7 @@
*/
package org.springblade.modules.market.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -40,6 +41,7 @@ import org.springblade.modules.market.pojo.entity.MarketInfoEntity;
import org.springblade.modules.market.pojo.vo.MarketDailySummaryVO;
import org.springblade.modules.market.excel.MarketDailySummaryExcel;
import org.springblade.modules.market.mapper.MarketDailySummaryMapper;
import org.springblade.modules.market.pojo.vo.MarketUserOrderSummaryVO;
import org.springblade.modules.market.service.IMarketDailySummaryService;
import org.springblade.modules.market.service.IMarketInfoService;
import org.springframework.stereotype.Service;
@@ -48,6 +50,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -79,12 +82,12 @@ public class MarketDailySummaryServiceImpl extends BaseServiceImpl<MarketDailySu
@Override
public List<MarketDailySummaryExcel> exportDailySummary(String strDate) {
if (StringUtil.isBlank(strDate)){
if (StringUtil.isBlank(strDate)) {
throw new ServiceException("无效参数");
}
List<MarketDailySummaryExcel> dailySummaryList = baseMapper.exportDailySummaryByDate(DateUtil.parse(strDate, DateUtil.PATTERN_DATE));
if (dailySummaryList.isEmpty()){
if (dailySummaryList.isEmpty()) {
throw new ServiceException("这个日期没有数据");
}
//dailySummaryList.forEach(dailySummary -> {
@@ -137,7 +140,7 @@ public class MarketDailySummaryServiceImpl extends BaseServiceImpl<MarketDailySu
if (Objects.isNull(userId)) {
throw new ServiceException("无效用户");
}
MarketDailySummaryEntity summary = getOne(Wrappers.lambdaQuery(MarketDailySummaryEntity.class).eq(MarketDailySummaryEntity::getUserId, userId).eq(MarketDailySummaryEntity::getIsDeleted, 0).orderByDesc(MarketDailySummaryEntity::getId),false);
MarketDailySummaryEntity summary = getOne(Wrappers.lambdaQuery(MarketDailySummaryEntity.class).eq(MarketDailySummaryEntity::getUserId, userId).eq(MarketDailySummaryEntity::getIsDeleted, 0).orderByDesc(MarketDailySummaryEntity::getId), false);
if (Objects.isNull(summary)) {
return vo;
}
@@ -146,6 +149,36 @@ public class MarketDailySummaryServiceImpl extends BaseServiceImpl<MarketDailySu
return vo;
}
@Override
public MarketUserOrderSummaryVO userOrderSummary() {
List<Long> ids = marketInfoService.selectTopUsersIds();
MarketUserOrderSummaryVO vo = new MarketUserOrderSummaryVO();
MarketDailySummaryEntity summary = getOne(Wrappers.lambdaQuery(MarketDailySummaryEntity.class).eq(MarketDailySummaryEntity::getIsDeleted, 0).orderByDesc(MarketDailySummaryEntity::getId).last("limit 1"));
List<MarketDailySummaryEntity> list = list(Wrappers.lambdaQuery(MarketDailySummaryEntity.class).eq(MarketDailySummaryEntity::getIsDeleted, 0).eq(MarketDailySummaryEntity::getStatDate, summary.getStatDate()).in(MarketDailySummaryEntity::getUserId, ids));
BigDecimal onlineTotal = BigDecimal.ZERO;
BigDecimal offlineTotal = BigDecimal.ZERO;
BigDecimal otherTotal = BigDecimal.ZERO;
BigDecimal increaseOnline = BigDecimal.ZERO;
BigDecimal increaseOffline = BigDecimal.ZERO;
BigDecimal increaseOther = BigDecimal.ZERO;
for (MarketDailySummaryEntity m : list) {
onlineTotal = onlineTotal.add(m.getPersonalOnlineAmount()).add(m.getTeamOnlineAmount());
offlineTotal = offlineTotal.add(m.getPersonalOfflineAmount()).add(m.getTeamOfflineAmount());
otherTotal = otherTotal.add(m.getPersonalOtherAmount()).add(m.getTeamOtherAmount());
increaseOnline = increaseOnline.add(m.getPersonalIncreaseOnlineAmount()).add(m.getTeamIncreaseOnlineAmount());
increaseOffline = increaseOffline.add(m.getPersonalIncreaseOfflineAmount()).add(m.getTeamIncreaseOfflineAmount());
increaseOther = increaseOther.add(m.getPersonalIncreaseOtherAmount()).add(m.getTeamIncreaseOtherAmount());
}
vo.setOnlineTotal(onlineTotal);
vo.setOfflineTotal(offlineTotal);
vo.setOtherTotal(otherTotal);
vo.setIncreaseOnline(increaseOnline);
vo.setIncreaseOffline(increaseOffline);
vo.setIncreaseOther(increaseOther);
return vo;
}
private String desensitizationByName(String name) {
return name.replaceAll("^(.).*$", "$1" + "*".repeat(name.length() - 1));
}

View File

@@ -51,9 +51,11 @@ import org.springblade.modules.common.service.ICommonUserPointService;
import org.springblade.modules.market.eums.UserFlowType;
import org.springblade.modules.market.pojo.dto.MarketInfoSummaryDTO;
import org.springblade.modules.market.pojo.entity.*;
import org.springblade.modules.market.pojo.vo.MarketDataSummaryVO;
import org.springblade.modules.market.pojo.vo.MarketInfoVO;
import org.springblade.modules.market.mapper.MarketInfoMapper;
import org.springblade.modules.market.pojo.vo.MarketUserFlowVO;
import org.springblade.modules.market.pojo.vo.MarketUserPointSummaryVO;
import org.springblade.modules.market.service.*;
import org.springblade.modules.system.pojo.entity.User;
import org.springblade.modules.system.service.IUserService;
@@ -63,6 +65,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.TimeUnit;
@@ -251,5 +254,23 @@ public class MarketInfoServiceImpl extends BaseServiceImpl<MarketInfoMapper, Mar
return voList;
}
@Override
public MarketDataSummaryVO dataSummary() {
MarketDataSummaryVO vo = new MarketDataSummaryVO();
vo.setUserPoints(userPointService.selectTotal());
vo.setBenefitPoints(benefitPointService.selectTotal());
vo.setCashCoupons(cashCouponService.selectTotal());
vo.setCommissions(commissionService.selectTotal());
return vo;
}
@Override
public MarketUserPointSummaryVO userPointSummary() {
return userPointService.userPointSummary();
}
@Override
public List<Long> selectTopUsersIds() {
return baseMapper.selectTopUsersIds();
}
}

View File

@@ -101,6 +101,9 @@ public class MarketUserCommissionServiceImpl extends BaseServiceImpl<MarketUserC
);
}
@Override
public BigDecimal selectTotal() {
return baseMapper.selectTotal();
}
}