This commit is contained in:
ah--desktop
2025-12-11 08:04:56 +08:00
parent a3b8797955
commit 5129657f7f
69 changed files with 1695 additions and 545 deletions
@@ -7,14 +7,17 @@ import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import top.xyquan.ecomdmbbackend.common.annotation.RequireRole;
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.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.ShopProductDetailVO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopStatisticsVO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopVO;
import top.xyquan.ecomdmbbackend.modules.ecom.service.ShopService;
import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaImageVO;
@@ -82,19 +85,30 @@ public class ShopController {
return ApiResponse.success(mediaImageVO);
}
@Operation(summary = "根据名称精准查询店铺", description = "根据店铺名称精准查询店铺信息,用于数据导入")
@GetMapping("/find-by-name/{name}")
@RequireRole(description = "根据名称查询店铺", allowUser = true)
public ApiResponse<ShopVO> getShopByName(@Parameter(description = "店铺名称") @PathVariable String name) {
ShopVO shopVO = shopService.getShopByName(name);
return ApiResponse.success(shopVO);
@Operation(summary = "获取店铺当月统计信息", description = "获取当前店铺当月的销售额、订单数、客单价、成本、退款金额、推广费、费比等统计信息")
@GetMapping("/statistics/current-month/{id}")
@RequireRole(description = "查询店铺当月统计", allowUser = true)
public ApiResponse<ShopStatisticsVO> getShopCurrentMonthStatistics(
@Parameter(description = "店铺ID") @PathVariable Long id) {
ShopStatisticsVO statistics = shopService.getShopCurrentMonthStatistics(id);
return ApiResponse.success(statistics);
}
@Operation(summary = "批量根据名称查询店铺", description = "批量根据店铺名称精准查询店铺信息,用于数据导入")
@PostMapping("/find-by-names")
@RequireRole(description = "批量根据名称查询店铺", allowUser = true)
public ApiResponse<List<ShopVO>> getShopsByNames(@RequestBody List<String> names) {
List<ShopVO> shopVOs = shopService.getShopsByNames(names);
return ApiResponse.success(shopVOs);
@Operation(summary = "获取店铺统计信息", description = "通过维度参数和时间范围返回不同维度指定时间的统计信息(销售额、订单数、客单价、成本、退款金额、推广费、费比)")
@PostMapping("/statistics")
@RequireRole(description = "查询店铺统计", allowUser = true)
public ApiResponse<ShopStatisticsVO> getShopStatistics(
@Valid @RequestBody ShopStatisticsQueryDTO queryDTO) {
ShopStatisticsVO statistics = shopService.getShopStatistics(queryDTO);
return ApiResponse.success(statistics);
}
@Operation(summary = "分页获取店铺商品详细信息", description = "分页获取店铺商品的详细信息,包含商品基础信息和统计数据(销售额、订单数、客单价),支持按商品名称、商品编码筛选,日期参数不传默认为当日")
@PostMapping("/products/page")
@RequireRole(description = "查询店铺商品列表", allowUser = true)
public ApiResponse<PageResultVO<ShopProductDetailVO>> getShopProductPage(
@Valid @RequestBody PageQueryDTO<ShopProductFilterDTO> pageQueryDTO) {
PageResultVO<ShopProductDetailVO> result = shopService.getShopProductPage(pageQueryDTO);
return ApiResponse.success(result);
}
}
@@ -0,0 +1,13 @@
package top.xyquan.ecomdmbbackend.modules.ecom.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ShopProductRelationPO;
/**
* 店铺商品关联Mapper接口
*/
@Mapper
public interface ShopProductRelationMapper extends BaseMapper<ShopProductRelationPO> {
}
@@ -22,7 +22,7 @@ public class BatchSortImportFieldDefDTO {
/**
* 排序项列表
*/
@Schema(description = "排序项列表", required = true)
@Schema(description = "排序项列表", requiredMode = Schema.RequiredMode.REQUIRED)
@Valid
@NotNull(message = "排序项列表不能为空")
private List<FieldDefSortItem> sortItems;
@@ -39,14 +39,14 @@ public class BatchSortImportFieldDefDTO {
/**
* 字段定义ID
*/
@Schema(description = "字段定义ID", example = "1", required = true)
@Schema(description = "字段定义ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "字段定义ID不能为空")
private Long fieldDefId;
/**
* 排序值
*/
@Schema(description = "排序值", example = "0", required = true)
@Schema(description = "排序值", example = "0", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "排序值不能为空")
@Min(value = 0, message = "排序值不能小于0")
private Integer sort;
@@ -16,7 +16,7 @@ public class CreateImportFieldDefDTO {
/**
* 导入类型(product-商品 order-订单)
*/
@Schema(description = "导入类型", example = "product", required = true, allowableValues = {"product", "order"})
@Schema(description = "导入类型", example = "product", requiredMode = Schema.RequiredMode.REQUIRED, allowableValues = {"product", "order"})
@NotBlank(message = "导入类型不能为空")
@Pattern(regexp = "^(product|order)$", message = "导入类型只能是product或order")
private String type;
@@ -24,14 +24,14 @@ public class CreateImportFieldDefDTO {
/**
* 数据库字段名,如 name
*/
@Schema(description = "数据库字段名", example = "name", required = true)
@Schema(description = "数据库字段名", example = "name", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "字段名不能为空")
private String fieldName;
/**
* 中文字段名,如 商品名称
*/
@Schema(description = "中文字段名", example = "商品名称", required = true)
@Schema(description = "中文字段名", example = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "字段标签不能为空")
private String fieldLabel;
@@ -15,7 +15,7 @@ public class UpdateImportFieldDefDTO {
/**
* 中文字段名,如 商品名称
*/
@Schema(description = "中文字段名", example = "商品名称", required = true)
@Schema(description = "中文字段名", example = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "字段标签不能为空")
private String fieldLabel;
@@ -15,7 +15,7 @@ public class CreateImportMappingDTO {
/**
* 导入类型(product-商品 order-订单)
*/
@Schema(description = "导入类型", example = "product", required = true, allowableValues = {"product", "order"})
@Schema(description = "导入类型", example = "product", requiredMode = Schema.RequiredMode.REQUIRED, allowableValues = {"product", "order"})
@NotBlank(message = "导入类型不能为空")
@Pattern(regexp = "^(product|order)$", message = "导入类型只能是product或order")
private String type;
@@ -23,14 +23,14 @@ public class CreateImportMappingDTO {
/**
* 映射名称
*/
@Schema(description = "映射名称", example = "商品导入映射模板", required = true)
@Schema(description = "映射名称", example = "商品导入映射模板", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "映射名称不能为空")
private String name;
/**
* 字段映射(JSON格式)
*/
@Schema(description = "字段映射(JSON格式)", example = "{\"商品名称\":\"name\",\"价格(元)\":\"price\"}", required = true)
@Schema(description = "字段映射(JSON格式)", example = "{\"商品名称\":\"name\",\"价格(元)\":\"price\"}", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "字段映射不能为空")
private String mapping;
}
@@ -20,7 +20,7 @@ public class UpdateImportMappingDTO {
/**
* 字段映射(JSON格式)
*/
@Schema(description = "字段映射(JSON格式)", example = "{\"商品名称\":\"name\",\"价格(元)\":\"price\"}", required = true)
@Schema(description = "字段映射(JSON格式)", example = "{\"商品名称\":\"name\",\"价格(元)\":\"price\"}", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "字段映射不能为空")
private String mapping;
}
@@ -16,14 +16,14 @@ public class CreateImportTaskDTO {
/**
* 所属店铺ID
*/
@Schema(description = "所属店铺ID", example = "1", required = true)
@Schema(description = "所属店铺ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "店铺ID不能为空")
private Long shopId;
/**
* 导入类型(product-商品 order-订单)
*/
@Schema(description = "导入类型", example = "product", required = true, allowableValues = {"product", "order"})
@Schema(description = "导入类型", example = "product", requiredMode = Schema.RequiredMode.REQUIRED, allowableValues = {"product", "order"})
@NotBlank(message = "导入类型不能为空")
@Pattern(regexp = "^(product|order)$", message = "导入类型只能是product或order")
private String type;
@@ -31,14 +31,14 @@ public class CreateImportTaskDTO {
/**
* 原始文件名
*/
@Schema(description = "原始文件名", example = "商品导入.xlsx", required = true)
@Schema(description = "原始文件名", example = "商品导入.xlsx", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "文件名不能为空")
private String fileName;
/**
* 存储路径
*/
@Schema(description = "存储路径", example = "/uploads/import/2025/01/xxx.xlsx", required = true)
@Schema(description = "存储路径", example = "/uploads/import/2025/01/xxx.xlsx", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "存储路径不能为空")
private String filePath;
@@ -17,7 +17,7 @@ public class BatchImportOrderDTO {
/**
* 订单列表
*/
@Schema(description = "订单列表", required = true)
@Schema(description = "订单列表", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "订单列表不能为空")
@Valid
private List<CreateOrderDTO> orders;
@@ -18,7 +18,7 @@ public class CreateOrderDTO {
/**
* 店铺ID
*/
@Schema(description = "店铺ID", example = "1", required = true)
@Schema(description = "店铺ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "店铺ID不能为空")
private Long shopId;
@@ -31,28 +31,28 @@ public class CreateOrderDTO {
/**
* 订单状态ID
*/
@Schema(description = "订单状态ID", example = "1", required = true)
@Schema(description = "订单状态ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "订单状态ID不能为空")
private Long statusId;
/**
* 商家实收金额
*/
@Schema(description = "商家实收金额", example = "9999.00", required = true)
@Schema(description = "商家实收金额", example = "9999.00", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "商家实收金额不能为空")
private BigDecimal receivedAmount;
/**
* 下单时间
*/
@Schema(description = "下单时间", example = "2024-01-01T10:00:00", required = true)
@Schema(description = "下单时间", example = "2024-01-01T10:00:00", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "下单时间不能为空")
private LocalDateTime orderDate;
/**
* 商品ID
*/
@Schema(description = "商品ID", example = "1", required = true)
@Schema(description = "商品ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "商品ID不能为空")
private Long productId;
@@ -65,7 +65,7 @@ public class CreateOrderDTO {
/**
* 商品名称(冗余存储)
*/
@Schema(description = "商品名称", example = "iPhone 15 Pro", required = true)
@Schema(description = "商品名称", example = "iPhone 15 Pro", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "商品名称不能为空")
private String productName;
@@ -78,7 +78,7 @@ public class CreateOrderDTO {
/**
* 数量
*/
@Schema(description = "数量", example = "1", required = true)
@Schema(description = "数量", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "数量不能为空")
@Positive(message = "数量必须大于0")
private Integer quantity;
@@ -86,14 +86,14 @@ public class CreateOrderDTO {
/**
* 销售单价
*/
@Schema(description = "销售单价", example = "9999.00", required = true)
@Schema(description = "销售单价", example = "9999.00", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "销售单价不能为空")
private BigDecimal unitPrice;
/**
* 成本价(下单时快照)
*/
@Schema(description = "成本价", example = "8000.00", required = true)
@Schema(description = "成本价", example = "8000.00", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "成本价不能为空")
private BigDecimal costPrice;
}
@@ -14,7 +14,7 @@ public class CreateOrderStatusDTO {
/**
* 状态名称
*/
@Schema(description = "状态名称", example = "待发货", required = true)
@Schema(description = "状态名称", example = "待发货", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "状态名称不能为空")
private String statusName;
@@ -17,7 +17,7 @@ public class UpdateOrderDTO {
/**
* 店铺ID
*/
@Schema(description = "店铺ID", example = "1", required = true)
@Schema(description = "店铺ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "店铺ID不能为空")
private Long shopId;
@@ -36,14 +36,14 @@ public class UpdateOrderDTO {
/**
* 商家实收金额
*/
@Schema(description = "商家实收金额", example = "9999.00", required = true)
@Schema(description = "商家实收金额", example = "9999.00", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "商家实收金额不能为空")
private BigDecimal receivedAmount;
/**
* 下单时间
*/
@Schema(description = "下单时间", example = "2024-01-01T10:00:00", required = true)
@Schema(description = "下单时间", example = "2024-01-01T10:00:00", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "下单时间不能为空")
private LocalDateTime orderDate;
@@ -15,21 +15,21 @@ public class UpdateOrderStatusDTO {
/**
* 状态ID
*/
@Schema(description = "状态ID", example = "1", required = true)
@Schema(description = "状态ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "状态ID不能为空")
private Long id;
/**
* 状态码
*/
@Schema(description = "状态码", example = "0", required = true)
@Schema(description = "状态码", example = "0", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "状态码不能为空")
private Integer statusCode;
/**
* 状态名称
*/
@Schema(description = "状态名称", example = "待发货", required = true)
@Schema(description = "状态名称", example = "待发货", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "状态名称不能为空")
private String statusName;
@@ -19,7 +19,7 @@ public class CreateProductDTO {
/**
* 商品名称
*/
@Schema(description = "商品名称", example = "iPhone 15 Pro", required = true)
@Schema(description = "商品名称", example = "iPhone 15 Pro", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "商品名称不能为空")
private String name;
@@ -52,7 +52,7 @@ public class CreateProductDTO {
/**
* 规格名称
*/
@Schema(description = "规格名称", example = "128GB 深空黑色", required = true)
@Schema(description = "规格名称", example = "128GB 深空黑色", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "规格名称不能为空")
private String name;
@@ -65,7 +65,7 @@ public class CreateProductDTO {
/**
* 成本价
*/
@Schema(description = "成本价", example = "8000.00", required = true)
@Schema(description = "成本价", example = "8000.00", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "成本价不能为空")
private BigDecimal costPrice;
}
@@ -17,14 +17,14 @@ public class CreateProductSpecDTO {
/**
* 商品ID
*/
@Schema(description = "商品ID", example = "1", required = true)
@Schema(description = "商品ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "商品ID不能为空")
private Long productId;
/**
* 规格名称
*/
@Schema(description = "规格名称", example = "128GB 深空黑色", required = true)
@Schema(description = "规格名称", example = "128GB 深空黑色", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "规格名称不能为空")
private String name;
@@ -37,7 +37,7 @@ public class CreateProductSpecDTO {
/**
* 成本价
*/
@Schema(description = "成本价", example = "8000.00", required = true)
@Schema(description = "成本价", example = "8000.00", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "成本价不能为空")
private BigDecimal costPrice;
}
@@ -9,6 +9,11 @@ import lombok.Data;
@Data
@Schema(description = "商品分页查询过滤DTO")
public class ProductFilterDTO {
/**
* 商品ID
*/
@Schema(description = "商品ID", example = "1")
private Long id;
/**
* 商品名称(模糊查询)
@@ -16,6 +16,12 @@ public class ProductSpecFilterDTO {
@Schema(description = "商品ID", example = "1")
private Long productId;
/**
* 规格ID
*/
@Schema(description = "规格ID", example = "1")
private Long id;
/**
* 规格名称
*/
@@ -2,11 +2,8 @@ package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.product;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.math.BigDecimal;
/**
* 更新商品DTO
*/
@@ -17,7 +14,7 @@ public class UpdateProductDTO {
/**
* 商品名称
*/
@Schema(description = "商品名称", example = "iPhone 15 Pro", required = true)
@Schema(description = "商品名称", example = "iPhone 15 Pro", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "商品名称不能为空")
private String name;
@@ -17,14 +17,14 @@ public class UpdateProductSpecDTO {
/**
* 规格ID
*/
@Schema(description = "规格ID", example = "1", required = true)
@Schema(description = "规格ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "规格ID不能为空")
private Long id;
/**
* 规格名称
*/
@Schema(description = "规格名称", example = "128GB 深空黑色", required = true)
@Schema(description = "规格名称", example = "128GB 深空黑色", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "规格名称不能为空")
private String name;
@@ -37,7 +37,7 @@ public class UpdateProductSpecDTO {
/**
* 成本价
*/
@Schema(description = "成本价", example = "8000.00", required = true)
@Schema(description = "成本价", example = "8000.00", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "成本价不能为空")
private BigDecimal costPrice;
}
@@ -18,21 +18,21 @@ public class CreatePromotionFeeDTO {
/**
* 店铺ID
*/
@Schema(description = "店铺ID", example = "1", required = true)
@Schema(description = "店铺ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "店铺ID不能为空")
private Long shopId;
/**
* 推广费类型ID
*/
@Schema(description = "推广费类型ID", example = "1", required = true)
@Schema(description = "推广费类型ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "推广费类型ID不能为空")
private Long feeTypeId;
/**
* 推广费名称
*/
@Schema(description = "推广费名称", example = "直通车推广", required = true)
@Schema(description = "推广费名称", example = "直通车推广", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "推广费名称不能为空")
private String feeName;
@@ -51,7 +51,7 @@ public class CreatePromotionFeeDTO {
/**
* 推广费金额
*/
@Schema(description = "推广费金额", example = "1000.00", required = true)
@Schema(description = "推广费金额", example = "1000.00", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "推广费金额不能为空")
private BigDecimal feeAmount;
@@ -88,7 +88,7 @@ public class CreatePromotionFeeDTO {
/**
* 推广费发生日期
*/
@Schema(description = "推广费发生日期", example = "2024-01-01", required = true)
@Schema(description = "推广费发生日期", example = "2024-01-01", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "推广费发生日期不能为空")
private LocalDate feeDate;
@@ -14,7 +14,7 @@ public class CreatePromotionFeeTypeDTO {
/**
* 类型名称
*/
@Schema(description = "类型名称", example = "直通车", required = true)
@Schema(description = "类型名称", example = "直通车", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "类型名称不能为空")
private String typeName;
@@ -18,28 +18,28 @@ public class UpdatePromotionFeeDTO {
/**
* 推广费记录ID
*/
@Schema(description = "推广费记录ID", example = "1", required = true)
@Schema(description = "推广费记录ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "推广费记录ID不能为空")
private Long id;
/**
* 店铺ID
*/
@Schema(description = "店铺ID", example = "1", required = true)
@Schema(description = "店铺ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "店铺ID不能为空")
private Long shopId;
/**
* 推广费类型ID
*/
@Schema(description = "推广费类型ID", example = "1", required = true)
@Schema(description = "推广费类型ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "推广费类型ID不能为空")
private Long feeTypeId;
/**
* 推广费名称
*/
@Schema(description = "推广费名称", example = "直通车推广", required = true)
@Schema(description = "推广费名称", example = "直通车推广", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "推广费名称不能为空")
private String feeName;
@@ -58,7 +58,7 @@ public class UpdatePromotionFeeDTO {
/**
* 推广费金额
*/
@Schema(description = "推广费金额", example = "1000.00", required = true)
@Schema(description = "推广费金额", example = "1000.00", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "推广费金额不能为空")
private BigDecimal feeAmount;
@@ -95,7 +95,7 @@ public class UpdatePromotionFeeDTO {
/**
* 推广费发生日期
*/
@Schema(description = "推广费发生日期", example = "2024-01-01", required = true)
@Schema(description = "推广费发生日期", example = "2024-01-01", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "推广费发生日期不能为空")
private LocalDate feeDate;
@@ -15,21 +15,21 @@ public class UpdatePromotionFeeTypeDTO {
/**
* 推广费类型ID
*/
@Schema(description = "推广费类型ID", example = "1", required = true)
@Schema(description = "推广费类型ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "推广费类型ID不能为空")
private Long id;
/**
* 类型编码
*/
@Schema(description = "类型编码", example = "DIRECT_TRAFFIC", required = true)
@Schema(description = "类型编码", example = "DIRECT_TRAFFIC", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "类型编码不能为空")
private String typeCode;
/**
* 类型名称
*/
@Schema(description = "类型名称", example = "直通车", required = true)
@Schema(description = "类型名称", example = "直通车", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "类型名称不能为空")
private String typeName;
@@ -14,7 +14,7 @@ public class CreateShopDTO {
/**
* 店铺名称
*/
@Schema(description = "店铺名称", example = "旗舰店", required = true)
@Schema(description = "店铺名称", example = "旗舰店", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "店铺名称不能为空")
private String name;
@@ -0,0 +1,39 @@
package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDate;
/**
* 店铺商品分页查询过滤DTO
*/
@Data
@Schema(description = "店铺商品分页查询过滤DTO")
public class ShopProductFilterDTO {
/**
* 店铺ID
*/
@Schema(description = "店铺ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
private Long shopId;
/**
* 商品名称(模糊查询)
*/
@Schema(description = "商品名称(模糊查询)", example = "iPhone")
private String productName;
/**
* 商品编码(模糊查询)
*/
@Schema(description = "商品编码(模糊查询)", example = "IPHONE")
private String productCode;
/**
* 统计日期(不传默认为当日)
*/
@Schema(description = "统计日期(不传默认为当日)", example = "2024-01-01")
private LocalDate statDate;
}
@@ -0,0 +1,37 @@
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 ShopStatisticsQueryDTO {
/**
* 店铺ID
*/
@Schema(description = "店铺ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "店铺ID不能为空")
private Long shopId;
/**
* 开始日期
*/
@Schema(description = "开始日期", example = "2024-01-01", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "开始日期不能为空")
private LocalDate startDate;
/**
* 结束日期
*/
@Schema(description = "结束日期", example = "2024-01-31", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "结束日期不能为空")
private LocalDate endDate;
}
@@ -14,7 +14,7 @@ public class UpdateShopDTO {
/**
* 店铺名称
*/
@Schema(description = "店铺名称", example = "旗舰店", required = true)
@Schema(description = "店铺名称", example = "旗舰店", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "店铺名称不能为空")
private String name;
@@ -0,0 +1,71 @@
package top.xyquan.ecomdmbbackend.modules.ecom.model.po;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDateTime;
/**
* 电商-店铺商品关联实体
*/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("ec_shop_product_relation")
public class ShopProductRelationPO {
/**
* 关联ID
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 公司ID
*/
@TableField("company_id")
private Long companyId;
/**
* 店铺ID
*/
@TableField("shop_id")
private Long shopId;
/**
* 商品ID
*/
@TableField("product_id")
private Long productId;
/**
* 排序
*/
@TableField("sort_order")
private Integer sortOrder;
/**
* 创建时间
*/
@TableField(value = "create_time", fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 创建人ID
*/
@TableField("create_by")
private Long createBy;
/**
* 更新人ID
*/
@TableField("update_by")
private Long updateBy;
}
@@ -0,0 +1,82 @@
package top.xyquan.ecomdmbbackend.modules.ecom.model.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 店铺商品详细信息VO
*/
@Data
@Schema(description = "店铺商品详细信息VO")
public class ShopProductDetailVO {
/**
* 商品ID
*/
@Schema(description = "商品ID", example = "1")
private Long productId;
/**
* 商品名称
*/
@Schema(description = "商品名称", example = "iPhone 15 Pro")
private String productName;
/**
* 商品编码
*/
@Schema(description = "商品编码", example = "IPHONE15PRO001")
private String productCode;
/**
* 主图URL
*/
@Schema(description = "主图URL", example = "https://example.com/product.jpg")
private String mainImage;
/**
* 关联ID
*/
@Schema(description = "关联ID", example = "1")
private Long relationId;
/**
* 排序
*/
@Schema(description = "排序", example = "0")
private Integer sortOrder;
/**
* 创建时间
*/
@Schema(description = "创建时间", example = "2024-01-01T10:00:00")
private LocalDateTime createTime;
/**
* 更新时间
*/
@Schema(description = "更新时间", example = "2024-01-01T10:00:00")
private LocalDateTime updateTime;
/**
* 销售额(商家实收金额总和)
*/
@Schema(description = "销售额", example = "10000.00")
private BigDecimal salesAmount;
/**
* 订单数
*/
@Schema(description = "订单数", example = "10")
private Long orderCount;
/**
* 客单价(销售额/订单数)
*/
@Schema(description = "客单价", example = "1000.00")
private BigDecimal averageOrderValue;
}
@@ -0,0 +1,57 @@
package top.xyquan.ecomdmbbackend.modules.ecom.model.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;
/**
* 店铺统计VO
*/
@Data
@Schema(description = "店铺统计VO")
public class ShopStatisticsVO {
/**
* 销售额(商家实收金额总和)
*/
@Schema(description = "销售额", example = "100000.00")
private BigDecimal salesAmount;
/**
* 订单数
*/
@Schema(description = "订单数", example = "100")
private Long orderCount;
/**
* 客单价(销售额/订单数)
*/
@Schema(description = "客单价", example = "1000.00")
private BigDecimal averageOrderValue;
/**
* 成本(成本价*数量总和)
*/
@Schema(description = "成本", example = "60000.00")
private BigDecimal costAmount;
/**
* 退款金额(已退款订单的实收金额总和)
*/
@Schema(description = "退款金额", example = "5000.00")
private BigDecimal refundAmount;
/**
* 推广费
*/
@Schema(description = "推广费", example = "10000.00")
private BigDecimal promotionFee;
/**
* 费比(推广费/销售额)
*/
@Schema(description = "费比", example = "0.10")
private BigDecimal feeRatio;
}
@@ -6,13 +6,15 @@ 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.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.ShopProductDetailVO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopStatisticsVO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopVO;
import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaImageVO;
import java.util.List;
/**
* 店铺服务接口
*/
@@ -59,18 +61,26 @@ public interface ShopService extends IService<ShopPO> {
MediaImageVO uploadLogo(MultipartFile file);
/**
* 根据名称精准查询店铺
* 获取店铺当月统计信息
*
* @param name 店铺名称
* @return 店铺VO
* @param shopId 店铺ID
* @return 店铺统计信息
*/
ShopVO getShopByName(String name);
ShopStatisticsVO getShopCurrentMonthStatistics(Long shopId);
/**
* 批量根据名称查询店铺
* 获取店铺指定时间范围的统计信息
*
* @param names 店铺名称列表
* @return 店铺VO列表
* @param queryDTO 统计查询DTO
* @return 店铺统计信息
*/
List<ShopVO> getShopsByNames(List<String> names);
ShopStatisticsVO getShopStatistics(ShopStatisticsQueryDTO queryDTO);
/**
* 分页获取店铺商品详细信息
*
* @param pageQueryDTO 分页查询DTO
* @return 分页结果
*/
PageResultVO<ShopProductDetailVO> getShopProductPage(PageQueryDTO<ShopProductFilterDTO> pageQueryDTO);
}
@@ -12,11 +12,13 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
import top.xyquan.ecomdmbbackend.modules.ecom.mapper.OrderStatusMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.mapper.ShopProductRelationMapper;
import org.springframework.beans.BeanUtils;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.order.CreateOrderDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ImportTaskPO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.OrderStatusPO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ProductSpecPO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ShopProductRelationPO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ImportTaskVO;
import top.xyquan.ecomdmbbackend.modules.ecom.service.ImportTaskProcessorService;
import top.xyquan.ecomdmbbackend.modules.ecom.mapper.OrderMapper;
@@ -97,6 +99,7 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
private final OrderMapper orderMapper;
private final ProductMapper productMapper;
private final ShopService shopService;
private final ShopProductRelationMapper shopProductRelationMapper;
private final SseNotificationService sseNotificationService;
private final ObjectMapper objectMapper;
@@ -109,6 +112,7 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
OrderMapper orderMapper,
ProductMapper productMapper,
ShopService shopService,
ShopProductRelationMapper shopProductRelationMapper,
SseNotificationService sseNotificationService,
ObjectMapper objectMapper) {
this.importTaskService = importTaskService;
@@ -117,6 +121,7 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
this.orderMapper = orderMapper;
this.productMapper = productMapper;
this.shopService = shopService;
this.shopProductRelationMapper = shopProductRelationMapper;
this.sseNotificationService = sseNotificationService;
this.objectMapper = objectMapper;
}
@@ -753,6 +758,9 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
}
}
// 检查并创建店铺商品关联(如果不存在)
ensureShopProductRelation(createOrderDTO.getShopId(), createOrderDTO.getProductId(), companyId, createBy);
// 创建订单(包含商品明细)
OrderPO order = new OrderPO();
order.setCompanyId(companyId);
@@ -789,6 +797,39 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
return orderVO;
}
/**
* 确保店铺商品关联存在,如果不存在则创建
*
* @param shopId 店铺ID
* @param productId 商品ID
* @param companyId 公司ID
* @param createBy 创建人ID
*/
private void ensureShopProductRelation(Long shopId, Long productId, Long companyId, Long createBy) {
// 检查关联是否已存在
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<ShopProductRelationPO> wrapper =
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>();
wrapper.eq(ShopProductRelationPO::getShopId, shopId)
.eq(ShopProductRelationPO::getProductId, productId)
.eq(ShopProductRelationPO::getCompanyId, companyId);
ShopProductRelationPO existingRelation = shopProductRelationMapper.selectOne(wrapper);
if (existingRelation == null) {
// 关联不存在,创建新关联
ShopProductRelationPO relation = new ShopProductRelationPO();
relation.setCompanyId(companyId);
relation.setShopId(shopId);
relation.setProductId(productId);
relation.setSortOrder(0); // 默认排序为0
relation.setCreateBy(createBy);
shopProductRelationMapper.insert(relation);
logger.info("创建店铺商品关联: 店铺ID={}, 商品ID={}", shopId, productId);
} else {
logger.debug("店铺商品关联已存在: 店铺ID={}, 商品ID={}", shopId, productId);
}
}
/**
* 通过订单状态名称查找订单状态ID
*
@@ -10,11 +10,25 @@ 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.mapper.OrderMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.mapper.OrderStatusMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.mapper.ProductMapper;
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.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.OrderPO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.OrderStatusPO;
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.ShopProductDetailVO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopStatisticsVO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopVO;
import top.xyquan.ecomdmbbackend.modules.ecom.service.ShopService;
import top.xyquan.ecomdmbbackend.modules.media.service.MediaImageService;
@@ -22,6 +36,10 @@ import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaImageVO;
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
import org.springframework.web.multipart.MultipartFile;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
@@ -33,10 +51,23 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
private final CurrentUserContext currentUserContext;
private final MediaImageService mediaImageService;
private final OrderMapper orderMapper;
private final PromotionFeeMapper promotionFeeMapper;
private final OrderStatusMapper orderStatusMapper;
private final ProductMapper productMapper;
private final ShopProductRelationMapper shopProductRelationMapper;
public ShopServiceImpl(CurrentUserContext currentUserContext, MediaImageService mediaImageService) {
public ShopServiceImpl(CurrentUserContext currentUserContext, MediaImageService mediaImageService,
OrderMapper orderMapper, PromotionFeeMapper promotionFeeMapper,
OrderStatusMapper orderStatusMapper, ProductMapper productMapper,
ShopProductRelationMapper shopProductRelationMapper) {
this.currentUserContext = currentUserContext;
this.mediaImageService = mediaImageService;
this.orderMapper = orderMapper;
this.promotionFeeMapper = promotionFeeMapper;
this.orderStatusMapper = orderStatusMapper;
this.productMapper = productMapper;
this.shopProductRelationMapper = shopProductRelationMapper;
}
/**
@@ -211,52 +242,291 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
}
/**
* 根据名称获取店铺
* @param name 店铺名称
* @return 店铺VO
* 获取店铺当月统计信息
*/
@Override
public ShopVO getShopByName(String name) {
public ShopStatisticsVO getShopCurrentMonthStatistics(Long shopId) {
// 从token中获取公司ID
Long companyId = currentUserContext.getCurrentCompanyId();
// 根据名称精准查询店铺
LambdaQueryWrapper<ShopPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ShopPO::getName, name)
.eq(ShopPO::getCompanyId, companyId);
ShopPO shop = this.getOne(wrapper);
if (shop == null) {
return null;
// 验证店铺是否存在
ShopPO shop = this.getById(shopId);
if (shop == null || !shop.getCompanyId().equals(companyId)) {
throw new BusinessException("店铺不存在");
}
return convertToVO(shop);
// 获取当月开始和结束时间
LocalDate now = LocalDate.now();
LocalDate startDate = now.withDayOfMonth(1);
LocalDate endDate = now.withDayOfMonth(now.lengthOfMonth());
// 构建查询DTO
ShopStatisticsQueryDTO queryDTO = new ShopStatisticsQueryDTO();
queryDTO.setShopId(shopId);
queryDTO.setStartDate(startDate);
queryDTO.setEndDate(endDate);
return calculateStatistics(queryDTO, companyId);
}
/**
* 根据名称列表获取店铺列表
* @param names 店铺名称列表
* @return 店铺VO列表
* 获取店铺指定时间范围的统计信息
*/
@Override
public List<ShopVO> getShopsByNames(List<String> names) {
if (names == null || names.isEmpty()) {
return List.of();
}
public ShopStatisticsVO getShopStatistics(ShopStatisticsQueryDTO queryDTO) {
// 从token中获取公司ID
Long companyId = currentUserContext.getCurrentCompanyId();
// 批量根据名称查询店铺
LambdaQueryWrapper<ShopPO> wrapper = new LambdaQueryWrapper<>();
wrapper.in(ShopPO::getName, names)
.eq(ShopPO::getCompanyId, companyId)
.orderByAsc(ShopPO::getName);
// 验证店铺是否存在
ShopPO shop = this.getById(queryDTO.getShopId());
if (shop == null || !shop.getCompanyId().equals(companyId)) {
throw new BusinessException("店铺不存在");
}
List<ShopPO> shops = this.list(wrapper);
return shops.stream()
.map(this::convertToVO)
// 验证日期范围
if (queryDTO.getStartDate().isAfter(queryDTO.getEndDate())) {
throw new BusinessException("开始日期不能晚于结束日期");
}
return calculateStatistics(queryDTO, companyId);
}
/**
* 计算统计信息
*/
private ShopStatisticsVO calculateStatistics(ShopStatisticsQueryDTO queryDTO, Long companyId) {
ShopStatisticsVO statistics = new ShopStatisticsVO();
// 查询时间范围(订单使用orderDate,推广费使用feeDate)
LocalDateTime startDateTime = queryDTO.getStartDate().atStartOfDay();
LocalDateTime endDateTime = queryDTO.getEndDate().atTime(23, 59, 59);
// 查询订单数据
LambdaQueryWrapper<OrderPO> orderWrapper = new LambdaQueryWrapper<>();
orderWrapper.eq(OrderPO::getCompanyId, companyId)
.eq(OrderPO::getShopId, queryDTO.getShopId())
.ge(OrderPO::getOrderDate, startDateTime)
.le(OrderPO::getOrderDate, endDateTime);
List<OrderPO> orders = orderMapper.selectList(orderWrapper);
// 查询推广费数据
LambdaQueryWrapper<PromotionFeePO> promotionWrapper = new LambdaQueryWrapper<>();
promotionWrapper.eq(PromotionFeePO::getCompanyId, companyId)
.eq(PromotionFeePO::getShopId, queryDTO.getShopId())
.ge(PromotionFeePO::getFeeDate, queryDTO.getStartDate())
.le(PromotionFeePO::getFeeDate, queryDTO.getEndDate());
List<PromotionFeePO> promotionFees = promotionFeeMapper.selectList(promotionWrapper);
// 获取退款状态ID(状态名称为"已退款")
Long refundStatusId = getRefundStatusId(companyId);
// 计算销售额(商家实收金额总和)
BigDecimal salesAmount = orders.stream()
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
statistics.setSalesAmount(salesAmount);
// 计算订单数(按平台订单号去重)
long orderCount = orders.stream()
.map(OrderPO::getPlatformOrderNo)
.filter(no -> no != null && !no.isEmpty())
.distinct()
.count();
// 如果没有平台订单号,则使用订单记录数
if (orderCount == 0) {
orderCount = orders.size();
}
statistics.setOrderCount(orderCount);
// 计算客单价(销售额/订单数)
BigDecimal averageOrderValue = orderCount > 0
? salesAmount.divide(BigDecimal.valueOf(orderCount), 2, RoundingMode.HALF_UP)
: BigDecimal.ZERO;
statistics.setAverageOrderValue(averageOrderValue);
// 计算成本(成本价*数量总和)
BigDecimal costAmount = orders.stream()
.map(order -> {
BigDecimal cost = order.getCostPrice() != null ? order.getCostPrice() : BigDecimal.ZERO;
Integer quantity = order.getQuantity() != null ? order.getQuantity() : 0;
return cost.multiply(BigDecimal.valueOf(quantity));
})
.reduce(BigDecimal.ZERO, BigDecimal::add);
statistics.setCostAmount(costAmount);
// 计算退款金额(已退款订单的实收金额总和)
BigDecimal refundAmount = BigDecimal.ZERO;
if (refundStatusId != null) {
refundAmount = orders.stream()
.filter(order -> refundStatusId.equals(order.getStatusId()))
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
}
statistics.setRefundAmount(refundAmount);
// 计算推广费
BigDecimal promotionFee = promotionFees.stream()
.map(fee -> fee.getFeeAmount() != null ? fee.getFeeAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
statistics.setPromotionFee(promotionFee);
// 计算费比(推广费/销售额)
BigDecimal feeRatio = salesAmount.compareTo(BigDecimal.ZERO) > 0
? promotionFee.divide(salesAmount, 4, RoundingMode.HALF_UP)
: BigDecimal.ZERO;
statistics.setFeeRatio(feeRatio);
return statistics;
}
/**
* 获取退款状态ID
*/
private Long getRefundStatusId(Long companyId) {
LambdaQueryWrapper<OrderStatusPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(OrderStatusPO::getCompanyId, companyId)
.eq(OrderStatusPO::getStatusName, "已退款")
.eq(OrderStatusPO::getIsActive, 1);
OrderStatusPO status = orderStatusMapper.selectOne(wrapper);
return status != null ? status.getId() : null;
}
/**
* 分页获取店铺商品详细信息
*/
@Override
public PageResultVO<ShopProductDetailVO> getShopProductPage(PageQueryDTO<ShopProductFilterDTO> pageQueryDTO) {
// 从token中获取公司ID
Long companyId = currentUserContext.getCurrentCompanyId();
// 获取过滤条件
ShopProductFilterDTO filter = pageQueryDTO.getFilters();
if (filter == null || filter.getShopId() == null) {
throw new BusinessException("店铺ID不能为空");
}
Long shopId = filter.getShopId();
// 验证店铺是否存在
ShopPO shop = this.getById(shopId);
if (shop == null || !shop.getCompanyId().equals(companyId)) {
throw new BusinessException("店铺不存在");
}
// 确定统计日期(不传默认为当日)
LocalDate statDate = filter.getStatDate() != null ? filter.getStatDate() : LocalDate.now();
LocalDateTime startDateTime = statDate.atStartOfDay();
LocalDateTime endDateTime = statDate.atTime(23, 59, 59);
// 创建分页对象
Page<ShopProductRelationPO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
// 构建查询条件(店铺商品关联表)
LambdaQueryWrapper<ShopProductRelationPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ShopProductRelationPO::getCompanyId, companyId)
.eq(ShopProductRelationPO::getShopId, shopId);
// 添加商品名称和编码过滤(需要关联商品表)
// 如果同时有商品名称和编码过滤,需要取交集
boolean hasProductFilter = (filter.getProductName() != null && !filter.getProductName().trim().isEmpty()) ||
(filter.getProductCode() != null && !filter.getProductCode().trim().isEmpty());
if (hasProductFilter) {
LambdaQueryWrapper<ProductPO> productWrapper = new LambdaQueryWrapper<>();
productWrapper.eq(ProductPO::getCompanyId, companyId);
if (filter.getProductName() != null && !filter.getProductName().trim().isEmpty()) {
productWrapper.like(ProductPO::getName, filter.getProductName().trim());
}
if (filter.getProductCode() != null && !filter.getProductCode().trim().isEmpty()) {
productWrapper.like(ProductPO::getProductCode, filter.getProductCode().trim());
}
List<ProductPO> products = productMapper.selectList(productWrapper);
if (products.isEmpty()) {
// 如果没有匹配的商品,返回空结果
return PageResultVO.create(List.of(), 0L, pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
}
List<Long> productIds = products.stream().map(ProductPO::getId).collect(Collectors.toList());
wrapper.in(ShopProductRelationPO::getProductId, productIds);
}
// 排序
wrapper.orderByAsc(ShopProductRelationPO::getSortOrder)
.orderByDesc(ShopProductRelationPO::getCreateTime);
// 执行分页查询
IPage<ShopProductRelationPO> pageResult = shopProductRelationMapper.selectPage(page, wrapper);
// 转换为VO并填充统计数据
List<ShopProductDetailVO> voList = pageResult.getRecords().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());
// 构建分页结果
return PageResultVO.create(voList, pageResult.getTotal(), pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
}
/**
* 计算商品统计数据
*/
private void calculateProductStatistics(ShopProductDetailVO vo, Long shopId, Long productId,
Long companyId, LocalDateTime startDateTime, LocalDateTime endDateTime) {
// 查询该店铺该商品在指定日期的订单
LambdaQueryWrapper<OrderPO> orderWrapper = new LambdaQueryWrapper<>();
orderWrapper.eq(OrderPO::getCompanyId, companyId)
.eq(OrderPO::getShopId, shopId)
.eq(OrderPO::getProductId, productId)
.ge(OrderPO::getOrderDate, startDateTime)
.le(OrderPO::getOrderDate, endDateTime);
List<OrderPO> orders = orderMapper.selectList(orderWrapper);
// 计算销售额(商家实收金额总和)
BigDecimal salesAmount = orders.stream()
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
vo.setSalesAmount(salesAmount);
// 计算订单数(按平台订单号去重)
long orderCount = orders.stream()
.map(OrderPO::getPlatformOrderNo)
.filter(no -> no != null && !no.isEmpty())
.distinct()
.count();
// 如果没有平台订单号,则使用订单记录数
if (orderCount == 0) {
orderCount = orders.size();
}
vo.setOrderCount(orderCount);
// 计算客单价(销售额/订单数)
BigDecimal averageOrderValue = orderCount > 0
? salesAmount.divide(BigDecimal.valueOf(orderCount), 2, RoundingMode.HALF_UP)
: BigDecimal.ZERO;
vo.setAverageOrderValue(averageOrderValue);
}
/**
@@ -22,7 +22,7 @@ public class CompanyDTO {
/**
* 公司名称
*/
@Schema(description = "公司名称", example = "某某科技有限公司", required = true)
@Schema(description = "公司名称", example = "某某科技有限公司", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "公司名称不能为空")
private String name;
@@ -16,7 +16,7 @@ public class CreateCompanyDTO {
/**
* 公司名称
*/
@Schema(description = "公司名称", example = "某某科技有限公司", required = true)
@Schema(description = "公司名称", example = "某某科技有限公司", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "公司名称不能为空")
private String name;
@@ -16,7 +16,7 @@ public class UpdateCompanyDTO {
/**
* 公司名称
*/
@Schema(description = "公司名称", example = "某某科技有限公司", required = true)
@Schema(description = "公司名称", example = "某某科技有限公司", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "公司名称不能为空")
private String name;
@@ -17,14 +17,14 @@ public class BatchCompanyMenuDTO {
/**
* 公司ID
*/
@Schema(description = "公司ID", example = "1", required = true)
@Schema(description = "公司ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "公司ID不能为空")
private Long companyId;
/**
* 菜单ID列表
*/
@Schema(description = "菜单ID列表", example = "[1, 2, 3]", required = true)
@Schema(description = "菜单ID列表", example = "[1, 2, 3]", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "菜单ID列表不能为空")
private List<Long> menuIds;
}
@@ -20,7 +20,7 @@ public class CompanyMenuDTO {
/**
* 公司ID
*/
@Schema(description = "公司ID", example = "1", required = true)
@Schema(description = "公司ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "公司ID不能为空")
private Long companyId;
@@ -33,7 +33,7 @@ public class CompanyMenuDTO {
/**
* 菜单ID
*/
@Schema(description = "菜单ID", example = "1", required = true)
@Schema(description = "菜单ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "菜单ID不能为空")
private Long menuId;
@@ -14,7 +14,7 @@ public class CreateCompanyMenuDTO {
/**
* 公司ID
*/
@Schema(description = "公司ID", example = "1", required = true)
@Schema(description = "公司ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "公司ID不能为空")
private Long companyId;
@@ -27,7 +27,7 @@ public class CreateCompanyMenuDTO {
/**
* 菜单ID
*/
@Schema(description = "菜单ID", example = "1", required = true)
@Schema(description = "菜单ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "菜单ID不能为空")
private Long menuId;
@@ -14,7 +14,7 @@ public class UpdateCompanyMenuDTO {
/**
* 公司ID
*/
@Schema(description = "公司ID", example = "1", required = true)
@Schema(description = "公司ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "公司ID不能为空")
private Long companyId;
@@ -27,7 +27,7 @@ public class UpdateCompanyMenuDTO {
/**
* 菜单ID
*/
@Schema(description = "菜单ID", example = "1", required = true)
@Schema(description = "菜单ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "菜单ID不能为空")
private Long menuId;
@@ -14,7 +14,7 @@ public class CreateDepartmentDTO {
/**
* 部门名称
*/
@Schema(description = "部门名称", example = "技术部", required = true)
@Schema(description = "部门名称", example = "技术部", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "部门名称不能为空")
private String name;
@@ -21,7 +21,7 @@ public class DepartmentDTO {
/**
* 部门名称
*/
@Schema(description = "部门名称", example = "技术部", required = true)
@Schema(description = "部门名称", example = "技术部", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "部门名称不能为空")
private String name;
@@ -34,7 +34,7 @@ public class DepartmentDTO {
/**
* 公司ID
*/
@Schema(description = "公司ID", example = "1", required = true)
@Schema(description = "公司ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "公司ID不能为空")
private Long companyId;
@@ -14,7 +14,7 @@ public class UpdateDepartmentDTO {
/**
* 部门名称
*/
@Schema(description = "部门名称", example = "技术部", required = true)
@Schema(description = "部门名称", example = "技术部", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "部门名称不能为空")
private String name;
@@ -14,7 +14,7 @@ public class CreatePositionDTO {
/**
* 岗位名称
*/
@Schema(description = "岗位名称", example = "软件工程师", required = true)
@Schema(description = "岗位名称", example = "软件工程师", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "岗位名称不能为空")
private String name;
@@ -21,7 +21,7 @@ public class PositionDTO {
/**
* 岗位名称
*/
@Schema(description = "岗位名称", example = "软件工程师", required = true)
@Schema(description = "岗位名称", example = "软件工程师", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "岗位名称不能为空")
private String name;
@@ -34,7 +34,7 @@ public class PositionDTO {
/**
* 公司ID
*/
@Schema(description = "公司ID", example = "1", required = true)
@Schema(description = "公司ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "公司ID不能为空")
private Long companyId;
@@ -14,7 +14,7 @@ public class UpdatePositionDTO {
/**
* 岗位名称
*/
@Schema(description = "岗位名称", example = "软件工程师", required = true)
@Schema(description = "岗位名称", example = "软件工程师", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "岗位名称不能为空")
private String name;
@@ -1,18 +0,0 @@
-- 为导入映射表添加名称字段并修改唯一约束
-- 执行时间:2025-12-03
-- 1. 添加名称字段
ALTER TABLE `ec_import_mappings`
ADD COLUMN `name` varchar(20) NOT NULL COMMENT '映射名称' AFTER `type`;
-- 2. 为现有数据设置默认名称(根据类型设置,确保唯一性)
UPDATE `ec_import_mappings` SET `name` = CONCAT('商品导入映射-', DATE_FORMAT(create_time, '%Y%m%d')) WHERE `type` = 'product';
UPDATE `ec_import_mappings` SET `name` = CONCAT('订单导入映射-', DATE_FORMAT(create_time, '%Y%m%d')) WHERE `type` = 'order';
-- 3. 删除旧的唯一约束(如果存在)
ALTER TABLE `ec_import_mappings` DROP INDEX IF EXISTS `uniq_company_type`;
-- 4. 添加新的唯一约束(公司ID、导入类型、名称)
ALTER TABLE `ec_import_mappings`
ADD UNIQUE KEY `uniq_company_type_name` (`company_id`, `type`, `name`);
@@ -257,3 +257,29 @@ CREATE TABLE `ec_import_field_defs` (
PRIMARY KEY (`id`),
UNIQUE KEY `uniq_type_field` (`type`,`field_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-导入字段定义表';
-- 店铺商品关联表(中间表)
CREATE TABLE `ec_shop_product_relation` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '关联ID',
`company_id` BIGINT UNSIGNED NOT NULL COMMENT '公司ID',
`shop_id` BIGINT UNSIGNED NOT NULL COMMENT '店铺ID',
`product_id` BIGINT UNSIGNED NOT NULL COMMENT '商品ID',
`sort_order` INT NOT NULL DEFAULT 0 COMMENT '排序',
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`create_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '创建人ID',
`update_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '更新人ID',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_shop_product` (`shop_id`, `product_id`),
KEY `idx_company_id` (`company_id`),
KEY `idx_shop_id` (`shop_id`),
KEY `idx_product_id` (`product_id`),
KEY `idx_sort_order` (`sort_order`),
KEY `fk_ec_shop_product_creator` (`create_by`),
KEY `fk_ec_shop_product_updater` (`update_by`),
CONSTRAINT `fk_ec_shop_product_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_shop_product_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_shop_product_product` FOREIGN KEY (`product_id`) REFERENCES `ec_product` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_shop_product_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_shop_product_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-店铺商品关联表';