This commit is contained in:
ah--desktop
2025-12-13 08:11:29 +08:00
parent 5129657f7f
commit ca15b80d86
14 changed files with 503 additions and 339 deletions
@@ -12,10 +12,12 @@ 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.model.dto.shop.CreateShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopDetailQueryDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopProductFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopStatisticsQueryDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.UpdateShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopDetailVO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopProductDetailVO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopStatisticsVO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopVO;
@@ -103,7 +105,7 @@ public class ShopController {
return ApiResponse.success(statistics);
}
@Operation(summary = "分页获取店铺商品详细信息", description = "分页获取店铺商品的详细信息,包含商品基础信息和统计数据(销售额、订单数、客单价),支持按商品名称、商品编码筛选,日期参数不传默认为当日")
@Operation(summary = "分页获取店铺商品详细信息", description = "分页获取店铺商品的详细信息,包含商品基础信息和统计数据(销售额、订单数、客单价),支持按商品名称、商品编码筛选,日期范围参数不传默认为当月1号到今天")
@PostMapping("/products/page")
@RequireRole(description = "查询店铺商品列表", allowUser = true)
public ApiResponse<PageResultVO<ShopProductDetailVO>> getShopProductPage(
@@ -111,4 +113,13 @@ public class ShopController {
PageResultVO<ShopProductDetailVO> result = shopService.getShopProductPage(pageQueryDTO);
return ApiResponse.success(result);
}
@Operation(summary = "获取店铺详情", description = "获取店铺详情,包含统计信息(销售额、订单数、客单价、成本、退款金额、推广费、费比)和所有商品列表,支持按时间范围查询,日期范围参数不传默认为当月1号到今天")
@PostMapping("/detail")
@RequireRole(description = "查询店铺详情", allowUser = true)
public ApiResponse<ShopDetailVO> getShopDetail(
@Valid @RequestBody ShopDetailQueryDTO queryDTO) {
ShopDetailVO shopDetail = shopService.getShopDetail(queryDTO);
return ApiResponse.success(shopDetail);
}
}
@@ -0,0 +1,35 @@
package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.time.LocalDate;
/**
* 店铺详情查询DTO
*/
@Data
@Schema(description = "店铺详情查询DTO")
public class ShopDetailQueryDTO {
/**
* 店铺ID
*/
@Schema(description = "店铺ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "店铺ID不能为空")
private Long shopId;
/**
* 开始日期(不传默认为当月1号)
*/
@Schema(description = "开始日期(不传默认为当月1号)", example = "2024-01-01")
private LocalDate startDate;
/**
* 结束日期(不传默认为今天)
*/
@Schema(description = "结束日期(不传默认为今天)", example = "2024-01-31")
private LocalDate endDate;
}
@@ -31,9 +31,15 @@ public class ShopProductFilterDTO {
private String productCode;
/**
* 统计日期(不传默认为当日)
* 开始日期(不传默认为当月1号)
*/
@Schema(description = "统计日期(不传默认为当日)", example = "2024-01-01")
private LocalDate statDate;
@Schema(description = "开始日期(不传默认为当月1号)", example = "2024-01-01")
private LocalDate startDate;
/**
* 结束日期(不传默认为今天)
*/
@Schema(description = "结束日期(不传默认为今天)", example = "2024-01-31")
private LocalDate endDate;
}
@@ -0,0 +1,27 @@
package top.xyquan.ecomdmbbackend.modules.ecom.model.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
/**
* 店铺详情VO
*/
@Data
@Schema(description = "店铺详情VO")
public class ShopDetailVO {
/**
* 店铺统计信息
*/
@Schema(description = "店铺统计信息")
private ShopStatisticsVO statistics;
/**
* 商品列表
*/
@Schema(description = "商品列表")
private List<ShopProductDetailVO> products;
}
@@ -5,11 +5,13 @@ 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.model.dto.shop.CreateShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopDetailQueryDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopProductFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopStatisticsQueryDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.UpdateShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ShopPO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopDetailVO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopProductDetailVO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopStatisticsVO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopVO;
@@ -83,4 +85,12 @@ public interface ShopService extends IService<ShopPO> {
* @return 分页结果
*/
PageResultVO<ShopProductDetailVO> getShopProductPage(PageQueryDTO<ShopProductFilterDTO> pageQueryDTO);
/**
* 获取店铺详情(包含统计信息和商品分页列表)
*
* @param queryDTO 店铺详情查询DTO
* @return 店铺详情VO
*/
ShopDetailVO getShopDetail(ShopDetailQueryDTO queryDTO);
}
@@ -17,6 +17,7 @@ import top.xyquan.ecomdmbbackend.modules.ecom.mapper.PromotionFeeMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.mapper.ShopMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.mapper.ShopProductRelationMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.CreateShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopDetailQueryDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopProductFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopStatisticsQueryDTO;
@@ -27,6 +28,7 @@ import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ProductPO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.PromotionFeePO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ShopPO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ShopProductRelationPO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopDetailVO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopProductDetailVO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopStatisticsVO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopVO;
@@ -413,10 +415,17 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
throw new BusinessException("店铺不存在");
}
// 确定统计日期(不传默认为当日)
LocalDate statDate = filter.getStatDate() != null ? filter.getStatDate() : LocalDate.now();
LocalDateTime startDateTime = statDate.atStartOfDay();
LocalDateTime endDateTime = statDate.atTime(23, 59, 59);
// 确定统计日期范围(不传默认为当月1号到今天)
LocalDate startDate = filter.getStartDate() != null ? filter.getStartDate() : LocalDate.now().withDayOfMonth(1);
LocalDate endDate = filter.getEndDate() != null ? filter.getEndDate() : LocalDate.now();
// 验证日期范围
if (startDate.isAfter(endDate)) {
throw new BusinessException("开始日期不能晚于结束日期");
}
LocalDateTime startDateTime = startDate.atStartOfDay();
LocalDateTime endDateTime = endDate.atTime(23, 59, 59);
// 创建分页对象
Page<ShopProductRelationPO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
@@ -537,4 +546,91 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
BeanUtils.copyProperties(shop, shopVO);
return shopVO;
}
/**
* 获取店铺详情(包含统计信息和商品列表)
*/
@Override
public ShopDetailVO getShopDetail(ShopDetailQueryDTO queryDTO) {
// 从token中获取公司ID
Long companyId = currentUserContext.getCurrentCompanyId();
// 验证店铺是否存在
ShopPO shop = this.getById(queryDTO.getShopId());
if (shop == null || !shop.getCompanyId().equals(companyId)) {
throw new BusinessException("店铺不存在");
}
// 确定统计日期范围(不传默认为当月1号到今天)
LocalDate startDate = queryDTO.getStartDate() != null ? queryDTO.getStartDate() : LocalDate.now().withDayOfMonth(1);
LocalDate endDate = queryDTO.getEndDate() != null ? queryDTO.getEndDate() : LocalDate.now();
// 验证日期范围
if (startDate.isAfter(endDate)) {
throw new BusinessException("开始日期不能晚于结束日期");
}
LocalDateTime startDateTime = startDate.atStartOfDay();
LocalDateTime endDateTime = endDate.atTime(23, 59, 59);
// 获取店铺统计信息
ShopStatisticsQueryDTO statisticsQueryDTO = new ShopStatisticsQueryDTO();
statisticsQueryDTO.setShopId(queryDTO.getShopId());
statisticsQueryDTO.setStartDate(startDate);
statisticsQueryDTO.setEndDate(endDate);
ShopStatisticsVO statistics = calculateStatistics(statisticsQueryDTO, companyId);
// 获取所有商品列表
List<ShopProductDetailVO> products = getAllShopProducts(queryDTO.getShopId(), companyId, startDateTime, endDateTime);
// 组装返回结果
ShopDetailVO shopDetailVO = new ShopDetailVO();
shopDetailVO.setStatistics(statistics);
shopDetailVO.setProducts(products);
return shopDetailVO;
}
/**
* 获取店铺所有商品详细信息
*/
private List<ShopProductDetailVO> getAllShopProducts(Long shopId, Long companyId,
LocalDateTime startDateTime, LocalDateTime endDateTime) {
// 构建查询条件(店铺商品关联表)
LambdaQueryWrapper<ShopProductRelationPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ShopProductRelationPO::getCompanyId, companyId)
.eq(ShopProductRelationPO::getShopId, shopId);
// 排序
wrapper.orderByAsc(ShopProductRelationPO::getSortOrder)
.orderByDesc(ShopProductRelationPO::getCreateTime);
// 查询所有商品关联记录
List<ShopProductRelationPO> relations = shopProductRelationMapper.selectList(wrapper);
// 转换为VO并填充统计数据
return relations.stream()
.map(relation -> {
ShopProductDetailVO vo = new ShopProductDetailVO();
vo.setRelationId(relation.getId());
vo.setSortOrder(relation.getSortOrder());
vo.setCreateTime(relation.getCreateTime());
vo.setUpdateTime(relation.getUpdateTime());
// 查询商品信息
ProductPO product = productMapper.selectById(relation.getProductId());
if (product != null) {
vo.setProductId(product.getId());
vo.setProductName(product.getName());
vo.setProductCode(product.getProductCode());
vo.setMainImage(product.getMainImage());
}
// 统计订单数据(按日期范围)
calculateProductStatistics(vo, shopId, relation.getProductId(), companyId, startDateTime, endDateTime);
return vo;
})
.collect(Collectors.toList());
}
}