feat: 店铺详情页重构 — 四卡片布局(月度目标/推广费/刷单费/店铺订单),筛选栏移至标题行,图标替换为Lucide

This commit is contained in:
小蟑螂
2026-04-30 15:57:32 +08:00
parent 00377bdc63
commit b063f65568
21 changed files with 1211 additions and 961 deletions
@@ -12,12 +12,14 @@ import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.CreateShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopDetailQueryDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopProductPageFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopStatisticsQueryDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.UpdateShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.ShopOverviewQueryDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductVO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopDashboardVO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopOverviewVO;
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.vo.ShopOverviewStatisticsVO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopVO;
@@ -115,4 +117,12 @@ public class ShopController {
ShopOverviewStatisticsVO overviewVO = shopOverviewStatisticsService.getShopOverviewStatistics(queryDTO);
return ApiResponse.success("获取店铺概览统计成功", overviewVO);
}
@Operation(summary = "获取店铺详情页看板数据", description = "获取店铺详情页的月度目标、推广费、刷单费、店铺订单等看板数据")
@PostMapping("/details")
@RequirePermission(value = "ecom:shop:read", description = "查询店铺详情", allowSuper = true)
public ApiResponse<ShopDashboardVO> getShopDetails(@Valid @RequestBody ShopDetailQueryDTO queryDTO) {
ShopDashboardVO dashboard = shopService.getShopDashboard(queryDTO);
return ApiResponse.success("获取店铺详情看板数据成功", dashboard);
}
}
@@ -0,0 +1,133 @@
package top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
* 店铺详情页看板VO
*/
@Data
@Schema(description = "店铺详情页看板VO")
public class ShopDashboardVO {
/**
* 店铺基本信息
*/
@Schema(description = "店铺基本信息")
private ShopInfo shopInfo;
/**
* 月度目标看板数据
*/
@Schema(description = "月度目标看板数据")
private MonthlyTargetKpi monthlyTarget;
/**
* 推广费看板数据
*/
@Schema(description = "推广费看板数据")
private PromotionFeeKpi promotionFee;
/**
* 刷单费看板数据
*/
@Schema(description = "刷单费看板数据")
private BrushOrderKpi brushOrder;
/**
* 店铺订单看板数据
*/
@Schema(description = "店铺订单看板数据")
private ShopOrderKpi shopOrder;
/**
* 店铺基本信息
*/
@Data
@Schema(description = "店铺基本信息")
public static class ShopInfo {
@Schema(description = "店铺ID")
private Long id;
@Schema(description = "店铺名称")
private String name;
@Schema(description = "logo URL")
private String logo;
@Schema(description = "平台名称")
private String platformName;
}
/**
* 月度目标KPI
*/
@Data
@Schema(description = "月度目标KPI")
public static class MonthlyTargetKpi {
/** 年度目标总额 */
@Schema(description = "年度目标总额")
private java.math.BigDecimal totalTargetAmount;
/** 目标单量合计 */
@Schema(description = "目标单量合计")
private Integer totalOrderCount;
/** 本月目标销售额 */
@Schema(description = "本月目标销售额")
private java.math.BigDecimal thisMonthTargetAmount;
/** 本月目标单量 */
@Schema(description = "本月目标单量")
private Integer thisMonthTargetOrderCount;
/** 当前达成率 */
@Schema(description = "当前达成率(百分比)")
private java.math.BigDecimal achievementRate;
}
/**
* 推广费KPI
*/
@Data
@Schema(description = "推广费KPI")
public static class PromotionFeeKpi {
/** 累计推广费 */
@Schema(description = "累计推广费")
private java.math.BigDecimal totalFeeAmount;
/** 本月推广费 */
@Schema(description = "本月推广费")
private java.math.BigDecimal thisMonthFee;
/** 日均推广费 */
@Schema(description = "日均推广费")
private java.math.BigDecimal avgDailyFee;
}
/**
* 刷单费KPI
*/
@Data
@Schema(description = "刷单费KPI")
public static class BrushOrderKpi {
/** 累计刷单费 */
@Schema(description = "累计刷单费")
private java.math.BigDecimal totalBrushAmount;
/** 本月刷单次数 */
@Schema(description = "本月刷单次数")
private Integer thisMonthCount;
/** 平均刷单金额 */
@Schema(description = "平均刷单金额")
private java.math.BigDecimal avgAmount;
}
/**
* 店铺订单KPI
*/
@Data
@Schema(description = "店铺订单KPI")
public static class ShopOrderKpi {
/** 累计实收金额 */
@Schema(description = "累计实收金额")
private java.math.BigDecimal totalReceivedAmount;
/** 累计佣金 */
@Schema(description = "累计佣金")
private java.math.BigDecimal totalCommission;
/** 累计订单数 */
@Schema(description = "累计订单数")
private Integer totalOrderCount;
}
}
@@ -5,12 +5,14 @@ import org.springframework.web.multipart.MultipartFile;
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.CreateShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopDetailQueryDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopProductPageFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopStatisticsQueryDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.UpdateShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.po.ShopPO;
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductVO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopDashboardVO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopOverviewVO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopVO;
import top.xyquan.ecomdmbbackend.modules.sys.file.model.vo.SysFileUploadVO;
@@ -75,4 +77,12 @@ public interface ShopService extends IService<ShopPO> {
* @return 分页结果
*/
PageResultVO<ProductVO> getShopProductPage(PageQueryDTO<ShopProductPageFilterDTO> pageQueryDTO);
/**
* 获取店铺详情页看板数据
*
* @param queryDTO 查询DTO
* @return 看板VO
*/
ShopDashboardVO getShopDashboard(ShopDetailQueryDTO queryDTO);
}
@@ -10,6 +10,8 @@ import org.springframework.transaction.annotation.Transactional;
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
import top.xyquan.ecomdmbbackend.modules.ecom.brushorder.mapper.BrushOrderMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.brushorder.model.po.BrushOrderPO;
import top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.product.mapper.ProductMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.promotion.mapper.PromotionFeeMapper;
@@ -17,7 +19,11 @@ import top.xyquan.ecomdmbbackend.modules.ecom.platform.mapper.PlatformMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.po.PlatformPO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.mapper.ShopMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.mapper.ShopProductRelationMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.monthlytarget.mapper.ShopMonthlyTargetMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.monthlytarget.model.po.ShopMonthlyTargetPO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.monthlytarget.model.vo.ShopMonthlyTargetVO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.CreateShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopDetailQueryDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopProductPageFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopStatisticsQueryDTO;
@@ -32,6 +38,7 @@ import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.po.ShopPO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.po.ShopProductRelationPO;
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductSpecVO;
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductVO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopDashboardVO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopOverviewVO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopVO;
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductSpecService;
@@ -71,12 +78,15 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
private final ProductSpecService productSpecService;
private final OrderStatusService orderStatusService;
private final PlatformMapper platformMapper;
private final BrushOrderMapper brushOrderMapper;
private final ShopMonthlyTargetMapper shopMonthlyTargetMapper;
public ShopServiceImpl(CurrentUserContext currentUserContext, SysFileMapper sysFileMapper, SysFileService sysFileService,
OrderMapper orderMapper, PromotionFeeMapper promotionFeeMapper,
ProductMapper productMapper,
ShopProductRelationMapper shopProductRelationMapper, ProductSpecService productSpecService,
OrderStatusService orderStatusService, PlatformMapper platformMapper) {
OrderStatusService orderStatusService, PlatformMapper platformMapper,
BrushOrderMapper brushOrderMapper, ShopMonthlyTargetMapper shopMonthlyTargetMapper) {
this.currentUserContext = currentUserContext;
this.sysFileMapper = sysFileMapper;
this.sysFileService = sysFileService;
@@ -87,6 +97,8 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
this.productSpecService = productSpecService;
this.orderStatusService = orderStatusService;
this.platformMapper = platformMapper;
this.brushOrderMapper = brushOrderMapper;
this.shopMonthlyTargetMapper = shopMonthlyTargetMapper;
}
/**
@@ -733,4 +745,185 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
BeanUtils.copyProperties(productSpec, productSpecVO);
return productSpecVO;
}
@Override
public ShopDashboardVO getShopDashboard(ShopDetailQueryDTO queryDTO) {
Long companyId = currentUserContext.getCurrentCompanyId();
Long shopId = queryDTO.getShopId();
// 验证店铺
ShopPO shop = this.getById(shopId);
if (shop == null || !shop.getCompanyId().equals(companyId)) {
throw new BusinessException("店铺不存在");
}
// 日期范围(默认当月)
LocalDate startDate = queryDTO.getStartDate() != null ? queryDTO.getStartDate() : LocalDate.now().withDayOfMonth(1);
LocalDate endDate = queryDTO.getEndDate() != null ? queryDTO.getEndDate() : LocalDate.now();
LocalDateTime startDateTime = startDate.atStartOfDay();
LocalDateTime endDateTime = endDate.atTime(23, 59, 59);
ShopDashboardVO dashboard = new ShopDashboardVO();
// 设置店铺基本信息
ShopDashboardVO.ShopInfo shopInfo = new ShopDashboardVO.ShopInfo();
shopInfo.setId(shop.getId());
shopInfo.setName(shop.getName());
shopInfo.setLogo(null); // logoImageId 冗余字段,前端按需使用
// 查询平台名称
if (shop.getPlatformId() != null) {
LambdaQueryWrapper<PlatformPO> platformWrapper = new LambdaQueryWrapper<>();
platformWrapper.eq(PlatformPO::getId, shop.getPlatformId())
.eq(PlatformPO::getCompanyId, companyId);
PlatformPO platform = platformMapper.selectOne(platformWrapper);
if (platform != null) {
shopInfo.setPlatformName(platform.getPlatformName());
}
}
dashboard.setShopInfo(shopInfo);
// 1. 月度目标
dashboard.setMonthlyTarget(buildMonthlyTargetKpi(companyId, shopId, shop, startDate, endDate));
// 2. 推广费
dashboard.setPromotionFee(buildPromotionFeeKpi(companyId, shopId, shop, startDate, endDate));
// 3. 刷单费
dashboard.setBrushOrder(buildBrushOrderKpi(companyId, shopId, shop, startDate, endDate));
// 4. 店铺订单
dashboard.setShopOrder(buildShopOrderKpi(companyId, shopId, shop, startDateTime, endDateTime));
return dashboard;
}
private ShopDashboardVO.MonthlyTargetKpi buildMonthlyTargetKpi(Long companyId, Long shopId, ShopPO shop, LocalDate startDate, LocalDate endDate) {
ShopDashboardVO.MonthlyTargetKpi kpi = new ShopDashboardVO.MonthlyTargetKpi();
// 查询所有目标记录(不限日期,取所有)
LambdaQueryWrapper<ShopMonthlyTargetPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ShopMonthlyTargetPO::getCompanyId, companyId)
.eq(ShopMonthlyTargetPO::getShopId, shopId)
.orderByDesc(ShopMonthlyTargetPO::getTargetMonth);
List<ShopMonthlyTargetPO> allTargets = shopMonthlyTargetMapper.selectList(wrapper);
// 年度总额 & 目标单量合计
BigDecimal totalTargetAmount = allTargets.stream()
.map(ShopMonthlyTargetPO::getTargetAmount)
.reduce(BigDecimal.ZERO, BigDecimal::add);
int totalOrderCount = allTargets.stream()
.mapToInt(t -> t.getTargetOrderCount() != null ? t.getTargetOrderCount() : 0)
.sum();
// 本月目标
String thisMonth = startDate.withDayOfMonth(1).toString().substring(0, 7);
ShopMonthlyTargetPO thisMonthTarget = allTargets.stream()
.filter(t -> t.getTargetMonth() != null && t.getTargetMonth().toString().startsWith(thisMonth))
.findFirst().orElse(null);
kpi.setTotalTargetAmount(totalTargetAmount);
kpi.setTotalOrderCount(totalOrderCount);
kpi.setThisMonthTargetAmount(thisMonthTarget != null ? thisMonthTarget.getTargetAmount() : BigDecimal.ZERO);
kpi.setThisMonthTargetOrderCount(thisMonthTarget != null ? thisMonthTarget.getTargetOrderCount() : 0);
// 达成率 = 实际销售额 / 目标销售额(简化:查时间段内订单实收 / 目标)
LambdaQueryWrapper<OrderPO> orderWrapper = new LambdaQueryWrapper<>();
orderWrapper.eq(OrderPO::getCompanyId, companyId)
.eq(OrderPO::getShopId, shopId)
.ge(OrderPO::getOrderTime, startDate.atStartOfDay())
.le(OrderPO::getOrderTime, endDate.atTime(23, 59, 59));
List<OrderPO> periodOrders = orderMapper.selectList(orderWrapper);
BigDecimal actualSales = periodOrders.stream()
.map(o -> o.getReceivedAmount() != null ? o.getReceivedAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal achievementRate = BigDecimal.ZERO;
if (thisMonthTarget != null && thisMonthTarget.getTargetAmount() != null
&& thisMonthTarget.getTargetAmount().compareTo(BigDecimal.ZERO) > 0) {
achievementRate = actualSales.divide(thisMonthTarget.getTargetAmount(), 4, RoundingMode.HALF_UP)
.multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP);
}
kpi.setAchievementRate(achievementRate);
return kpi;
}
private ShopDashboardVO.PromotionFeeKpi buildPromotionFeeKpi(Long companyId, Long shopId, ShopPO shop, LocalDate startDate, LocalDate endDate) {
ShopDashboardVO.PromotionFeeKpi kpi = new ShopDashboardVO.PromotionFeeKpi();
LambdaQueryWrapper<PromotionFeePO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PromotionFeePO::getCompanyId, companyId)
.eq(PromotionFeePO::getShopId, shopId)
.ge(PromotionFeePO::getFeeDate, startDate)
.le(PromotionFeePO::getFeeDate, endDate)
.orderByDesc(PromotionFeePO::getFeeDate);
List<PromotionFeePO> allFees = promotionFeeMapper.selectList(wrapper);
BigDecimal totalFeeAmount = allFees.stream()
.map(f -> f.getFeeAmount() != null ? f.getFeeAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
// 本月推广费
String thisMonthStr = startDate.withDayOfMonth(1).toString().substring(0, 7);
BigDecimal thisMonthFee = allFees.stream()
.filter(f -> f.getFeeDate() != null && f.getFeeDate().toString().startsWith(thisMonthStr))
.map(f -> f.getFeeAmount() != null ? f.getFeeAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
// 日均
long days = java.time.temporal.ChronoUnit.DAYS.between(startDate, endDate) + 1;
BigDecimal avgDailyFee = days > 0 ? totalFeeAmount.divide(BigDecimal.valueOf(days), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
kpi.setTotalFeeAmount(totalFeeAmount);
kpi.setThisMonthFee(thisMonthFee);
kpi.setAvgDailyFee(avgDailyFee);
return kpi;
}
private ShopDashboardVO.BrushOrderKpi buildBrushOrderKpi(Long companyId, Long shopId, ShopPO shop, LocalDate startDate, LocalDate endDate) {
ShopDashboardVO.BrushOrderKpi kpi = new ShopDashboardVO.BrushOrderKpi();
LambdaQueryWrapper<BrushOrderPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(BrushOrderPO::getCompanyId, companyId)
.eq(BrushOrderPO::getShopId, shopId)
.ge(BrushOrderPO::getBrushTime, startDate.atStartOfDay())
.le(BrushOrderPO::getBrushTime, endDate.atTime(23, 59, 59))
.orderByDesc(BrushOrderPO::getBrushTime);
List<BrushOrderPO> allBrush = brushOrderMapper.selectList(wrapper);
BigDecimal totalBrushAmount = allBrush.stream()
.map(b -> b.getBrushAmount() != null ? b.getBrushAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
long thisMonthCount = allBrush.stream()
.filter(b -> b.getBrushTime() != null && b.getBrushTime().toLocalDate().getMonth().equals(startDate.getMonth()))
.count();
long brushCount = allBrush.size();
BigDecimal avgAmount = brushCount > 0 ? totalBrushAmount.divide(BigDecimal.valueOf(brushCount), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
kpi.setTotalBrushAmount(totalBrushAmount);
kpi.setThisMonthCount((int) thisMonthCount);
kpi.setAvgAmount(avgAmount);
return kpi;
}
private ShopDashboardVO.ShopOrderKpi buildShopOrderKpi(Long companyId, Long shopId, ShopPO shop, LocalDateTime startDateTime, LocalDateTime endDateTime) {
ShopDashboardVO.ShopOrderKpi kpi = new ShopDashboardVO.ShopOrderKpi();
LambdaQueryWrapper<OrderPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(OrderPO::getCompanyId, companyId)
.eq(OrderPO::getShopId, shopId)
.ge(OrderPO::getOrderTime, startDateTime)
.le(OrderPO::getOrderTime, endDateTime)
.orderByDesc(OrderPO::getOrderTime);
List<OrderPO> allOrders = orderMapper.selectList(wrapper);
BigDecimal totalReceived = allOrders.stream()
.map(o -> o.getReceivedAmount() != null ? o.getReceivedAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
kpi.setTotalReceivedAmount(totalReceived);
kpi.setTotalCommission(BigDecimal.ZERO); // 订单表暂无佣金字段
kpi.setTotalOrderCount(allOrders.size());
return kpi;
}
}