mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 02:39:19 +08:00
1
This commit is contained in:
+76
@@ -0,0 +1,76 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
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.brushorder.BrushOrderFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.brushorder.CreateBrushOrderDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.brushorder.UpdateBrushOrderDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.BrushOrderVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.service.BrushOrderService;
|
||||
|
||||
/**
|
||||
* 刷单记录管理控制器
|
||||
*/
|
||||
@Tag(name = "电商-刷单记录管理", description = "刷单记录的增删改查接口")
|
||||
@RestController
|
||||
@RequestMapping("/ec/brush-order")
|
||||
public class BrushOrderController {
|
||||
|
||||
private final BrushOrderService brushOrderService;
|
||||
|
||||
public BrushOrderController(BrushOrderService brushOrderService) {
|
||||
this.brushOrderService = brushOrderService;
|
||||
}
|
||||
|
||||
@Operation(summary = "创建刷单记录", description = "创建新的刷单记录")
|
||||
@PostMapping("/create")
|
||||
@RequireRole(description = "创建刷单记录", allowUser = false)
|
||||
public ApiResponse<BrushOrderVO> createBrushOrder(@Valid @RequestBody CreateBrushOrderDTO createBrushOrderDTO) {
|
||||
BrushOrderVO brushOrderVO = brushOrderService.createBrushOrder(createBrushOrderDTO);
|
||||
return ApiResponse.success(brushOrderVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新刷单记录", description = "更新现有刷单记录信息")
|
||||
@PutMapping("/update/{id}")
|
||||
@RequireRole(description = "更新刷单记录", allowUser = false)
|
||||
public ApiResponse<BrushOrderVO> updateBrushOrder(@Valid @RequestBody UpdateBrushOrderDTO updateBrushOrderDTO,
|
||||
@Parameter(description = "刷单记录ID") @PathVariable Long id) {
|
||||
BrushOrderVO brushOrderVO = brushOrderService.updateBrushOrder(updateBrushOrderDTO, id);
|
||||
return ApiResponse.success(brushOrderVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除刷单记录", description = "删除指定刷单记录")
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@RequireRole(description = "删除刷单记录", allowUser = false)
|
||||
public ApiResponse<Void> deleteBrushOrder(
|
||||
@Parameter(description = "刷单记录ID") @PathVariable Long id) {
|
||||
brushOrderService.deleteBrushOrder(id);
|
||||
return ApiResponse.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "分页获取刷单记录列表", description = "分页获取刷单记录列表,支持条件过滤")
|
||||
@PostMapping("/page")
|
||||
@RequireRole(description = "查询刷单记录列表", allowUser = true)
|
||||
public ApiResponse<PageResultVO<BrushOrderVO>> getBrushOrderPage(
|
||||
@Valid @RequestBody PageQueryDTO<BrushOrderFilterDTO> pageQueryDTO) {
|
||||
PageResultVO<BrushOrderVO> result = brushOrderService.getBrushOrderPage(pageQueryDTO);
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取刷单记录详情", description = "根据ID获取刷单记录详情")
|
||||
@GetMapping("/detail/{id}")
|
||||
@RequireRole(description = "查询刷单记录详情", allowUser = true)
|
||||
public ApiResponse<BrushOrderVO> getBrushOrderById(
|
||||
@Parameter(description = "刷单记录ID") @PathVariable Long id) {
|
||||
BrushOrderVO brushOrderVO = brushOrderService.getBrushOrderById(id);
|
||||
return ApiResponse.success(brushOrderVO);
|
||||
}
|
||||
}
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequireRole;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.overview.CompanyOverviewQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.CompanyOverviewVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.service.CompanyOverviewService;
|
||||
|
||||
/**
|
||||
* 全店铺概览控制器
|
||||
*/
|
||||
@Tag(name = "电商-全店铺概览", description = "全店铺概览统计接口")
|
||||
@RestController
|
||||
@RequestMapping("/ec/company-overview")
|
||||
public class CompanyOverviewController {
|
||||
|
||||
private final CompanyOverviewService companyOverviewService;
|
||||
|
||||
public CompanyOverviewController(CompanyOverviewService companyOverviewService) {
|
||||
this.companyOverviewService = companyOverviewService;
|
||||
}
|
||||
|
||||
@Operation(summary = "获取全店铺概览统计数据", description = "获取当前公司所有店铺的概览统计数据,包括销售额、单量、推广费、利润、ROI等")
|
||||
@PostMapping("/statistics")
|
||||
@RequireRole(description = "查询全店铺概览", allowUser = true)
|
||||
public ApiResponse<CompanyOverviewVO> getCompanyOverview(@Valid @RequestBody CompanyOverviewQueryDTO queryDTO) {
|
||||
CompanyOverviewVO overviewVO = companyOverviewService.getCompanyOverview(queryDTO);
|
||||
return ApiResponse.success(overviewVO);
|
||||
}
|
||||
}
|
||||
|
||||
+13
@@ -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.BrushOrderPO;
|
||||
|
||||
/**
|
||||
* 刷单记录Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface BrushOrderMapper extends BaseMapper<BrushOrderPO> {
|
||||
}
|
||||
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.brushorder;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 刷单记录分页查询过滤DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "刷单记录分页查询过滤DTO")
|
||||
public class BrushOrderFilterDTO {
|
||||
|
||||
/**
|
||||
* 店铺ID
|
||||
*/
|
||||
@Schema(description = "店铺ID", example = "1")
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 商品ID
|
||||
*/
|
||||
@Schema(description = "商品ID", example = "1")
|
||||
private Long productId;
|
||||
|
||||
/**
|
||||
* 平台订单号(模糊查询)
|
||||
*/
|
||||
@Schema(description = "平台订单号(模糊查询)", example = "TB2024")
|
||||
private String platformOrderNo;
|
||||
|
||||
/**
|
||||
* 刷单金额范围-最小值
|
||||
*/
|
||||
@Schema(description = "刷单金额范围-最小值", example = "100.00")
|
||||
private BigDecimal minBrushAmount;
|
||||
|
||||
/**
|
||||
* 刷单金额范围-最大值
|
||||
*/
|
||||
@Schema(description = "刷单金额范围-最大值", example = "10000.00")
|
||||
private BigDecimal maxBrushAmount;
|
||||
|
||||
/**
|
||||
* 刷单时间范围-开始时间
|
||||
*/
|
||||
@Schema(description = "刷单时间范围-开始时间", example = "2024-01-01T00:00:00")
|
||||
private LocalDateTime startBrushTime;
|
||||
|
||||
/**
|
||||
* 刷单时间范围-结束时间
|
||||
*/
|
||||
@Schema(description = "刷单时间范围-结束时间", example = "2024-12-31T23:59:59")
|
||||
private LocalDateTime endBrushTime;
|
||||
}
|
||||
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.brushorder;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Positive;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 创建刷单记录DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "创建刷单记录DTO")
|
||||
public class CreateBrushOrderDTO {
|
||||
|
||||
/**
|
||||
* 店铺ID
|
||||
*/
|
||||
@Schema(description = "店铺ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "店铺ID不能为空")
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 商品ID(可选)
|
||||
*/
|
||||
@Schema(description = "商品ID", example = "1")
|
||||
private Long productId;
|
||||
|
||||
/**
|
||||
* 商品规格ID(可选)
|
||||
*/
|
||||
@Schema(description = "商品规格ID", example = "1")
|
||||
private Long productSpecId;
|
||||
|
||||
/**
|
||||
* 刷单金额
|
||||
*/
|
||||
@Schema(description = "刷单金额", example = "9999.00", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "刷单金额不能为空")
|
||||
private BigDecimal brushAmount;
|
||||
|
||||
/**
|
||||
* 刷单时间
|
||||
*/
|
||||
@Schema(description = "刷单时间", example = "2024-01-01T10:00:00", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "刷单时间不能为空")
|
||||
private LocalDateTime brushTime;
|
||||
|
||||
/**
|
||||
* 平台订单号(可选)
|
||||
*/
|
||||
@Schema(description = "平台订单号", example = "TB202401010001")
|
||||
private String platformOrderNo;
|
||||
|
||||
/**
|
||||
* 刷单数量
|
||||
*/
|
||||
@Schema(description = "刷单数量", example = "1")
|
||||
@Positive(message = "刷单数量必须大于0")
|
||||
private Integer quantity;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Schema(description = "备注", example = "备注信息")
|
||||
private String remark;
|
||||
}
|
||||
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.brushorder;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Positive;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 更新刷单记录DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "更新刷单记录DTO")
|
||||
public class UpdateBrushOrderDTO {
|
||||
|
||||
/**
|
||||
* 店铺ID
|
||||
*/
|
||||
@Schema(description = "店铺ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "店铺ID不能为空")
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 商品ID(可选)
|
||||
*/
|
||||
@Schema(description = "商品ID", example = "1")
|
||||
private Long productId;
|
||||
|
||||
/**
|
||||
* 商品规格ID(可选)
|
||||
*/
|
||||
@Schema(description = "商品规格ID", example = "1")
|
||||
private Long productSpecId;
|
||||
|
||||
/**
|
||||
* 刷单金额
|
||||
*/
|
||||
@Schema(description = "刷单金额", example = "9999.00", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "刷单金额不能为空")
|
||||
private BigDecimal brushAmount;
|
||||
|
||||
/**
|
||||
* 刷单时间
|
||||
*/
|
||||
@Schema(description = "刷单时间", example = "2024-01-01T10:00:00", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "刷单时间不能为空")
|
||||
private LocalDateTime brushTime;
|
||||
|
||||
/**
|
||||
* 平台订单号(可选)
|
||||
*/
|
||||
@Schema(description = "平台订单号", example = "TB202401010001")
|
||||
private String platformOrderNo;
|
||||
|
||||
/**
|
||||
* 刷单数量
|
||||
*/
|
||||
@Schema(description = "刷单数量", example = "1")
|
||||
@Positive(message = "刷单数量必须大于0")
|
||||
private Integer quantity;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Schema(description = "备注", example = "备注信息")
|
||||
private String remark;
|
||||
}
|
||||
|
||||
+34
-4
@@ -91,9 +91,39 @@ public class CreateOrderDTO {
|
||||
private BigDecimal unitPrice;
|
||||
|
||||
/**
|
||||
* 成本价(下单时快照)
|
||||
* 单件商品成本(下单时快照)
|
||||
*/
|
||||
@Schema(description = "成本价", example = "8000.00", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "成本价不能为空")
|
||||
private BigDecimal costPrice;
|
||||
@Schema(description = "单件商品成本", example = "8000.00", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "单件商品成本不能为空")
|
||||
private BigDecimal productCost;
|
||||
|
||||
/**
|
||||
* 单件运费成本(下单时快照)
|
||||
*/
|
||||
@Schema(description = "单件运费成本", example = "10.00")
|
||||
private BigDecimal shippingCost;
|
||||
|
||||
/**
|
||||
* 单件其他成本(下单时快照)
|
||||
*/
|
||||
@Schema(description = "单件其他成本", example = "5.00")
|
||||
private BigDecimal otherCost;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Schema(description = "备注", example = "备注信息")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 导入任务ID
|
||||
*/
|
||||
@Schema(description = "导入任务ID", example = "1")
|
||||
private Long importTaskId;
|
||||
|
||||
/**
|
||||
* 确认(0-否 1-是)
|
||||
*/
|
||||
@Schema(description = "确认", example = "1")
|
||||
private Integer confirm;
|
||||
}
|
||||
|
||||
+12
@@ -54,4 +54,16 @@ public class OrderFilterDTO {
|
||||
*/
|
||||
@Schema(description = "下单时间范围-结束时间", example = "2024-12-31T23:59:59")
|
||||
private LocalDateTime endOrderTime;
|
||||
|
||||
/**
|
||||
* 导入任务ID
|
||||
*/
|
||||
@Schema(description = "导入任务ID", example = "1")
|
||||
private Long importTaskId;
|
||||
|
||||
/**
|
||||
* 确认(0-否 1-是)
|
||||
*/
|
||||
@Schema(description = "确认", example = "1")
|
||||
private Integer confirm;
|
||||
}
|
||||
|
||||
+27
-3
@@ -84,8 +84,32 @@ public class UpdateOrderDTO {
|
||||
private BigDecimal unitPrice;
|
||||
|
||||
/**
|
||||
* 成本价(下单时快照)
|
||||
* 单件商品成本(下单时快照)
|
||||
*/
|
||||
@Schema(description = "成本价", example = "8000.00")
|
||||
private BigDecimal costPrice;
|
||||
@Schema(description = "单件商品成本", example = "8000.00")
|
||||
private BigDecimal productCost;
|
||||
|
||||
/**
|
||||
* 单件运费成本(下单时快照)
|
||||
*/
|
||||
@Schema(description = "单件运费成本", example = "10.00")
|
||||
private BigDecimal shippingCost;
|
||||
|
||||
/**
|
||||
* 单件其他成本(下单时快照)
|
||||
*/
|
||||
@Schema(description = "单件其他成本", example = "5.00")
|
||||
private BigDecimal otherCost;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Schema(description = "备注", example = "备注信息")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 确认(0-否 1-是)
|
||||
*/
|
||||
@Schema(description = "确认", example = "1")
|
||||
private Integer confirm;
|
||||
}
|
||||
|
||||
+4
-4
@@ -32,10 +32,10 @@ public class CreateOrderStatusDTO {
|
||||
private Integer sortOrder;
|
||||
|
||||
/**
|
||||
* 是否默认参与统计 0不参与 1参与
|
||||
* 是否自动参与统计 0不参与 1参与
|
||||
*/
|
||||
@Schema(description = "是否默认参与统计", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "是否默认参与统计不能为空")
|
||||
private Integer isDefaultStat;
|
||||
@Schema(description = "是否自动参与统计", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "是否自动参与统计不能为空")
|
||||
private Integer autoStatistics;
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -32,10 +32,10 @@ public class UpdateOrderStatusDTO {
|
||||
private Integer sortOrder;
|
||||
|
||||
/**
|
||||
* 是否默认参与统计 0不参与 1参与
|
||||
* 是否自动参与统计 0不参与 1参与
|
||||
*/
|
||||
@Schema(description = "是否默认参与统计", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "是否默认参与统计不能为空")
|
||||
private Integer isDefaultStat;
|
||||
@Schema(description = "是否自动参与统计", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "是否自动参与统计不能为空")
|
||||
private Integer autoStatistics;
|
||||
}
|
||||
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.overview;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 全店铺概览查询DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "全店铺概览查询DTO")
|
||||
public class CompanyOverviewQueryDTO {
|
||||
|
||||
/**
|
||||
* 日期范围数组(第一个是开始日期,第二个是结束日期,只有一个日期则返回当天数据)
|
||||
*/
|
||||
@Schema(description = "日期范围数组", example = "[\"2024-01-01\", \"2024-01-31\"]", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "日期范围不能为空")
|
||||
@Size(min = 1, max = 2, message = "日期范围数组必须包含1-2个日期")
|
||||
private List<LocalDate> dateRange;
|
||||
}
|
||||
|
||||
+22
-4
@@ -63,10 +63,28 @@ public class CreateProductDTO {
|
||||
private String specCode;
|
||||
|
||||
/**
|
||||
* 成本价
|
||||
* 商品成本
|
||||
*/
|
||||
@Schema(description = "成本价", example = "8000.00", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "成本价不能为空")
|
||||
private BigDecimal costPrice;
|
||||
@Schema(description = "商品成本", example = "8000.00", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "商品成本不能为空")
|
||||
private BigDecimal productCost;
|
||||
|
||||
/**
|
||||
* 运费成本
|
||||
*/
|
||||
@Schema(description = "运费成本", example = "10.00")
|
||||
private BigDecimal shippingCost;
|
||||
|
||||
/**
|
||||
* 其他成本
|
||||
*/
|
||||
@Schema(description = "其他成本", example = "5.00")
|
||||
private BigDecimal otherCost;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Schema(description = "备注", example = "备注信息")
|
||||
private String remark;
|
||||
}
|
||||
}
|
||||
|
||||
+22
-4
@@ -35,9 +35,27 @@ public class CreateProductSpecDTO {
|
||||
private String specCode;
|
||||
|
||||
/**
|
||||
* 成本价
|
||||
* 商品成本
|
||||
*/
|
||||
@Schema(description = "成本价", example = "8000.00", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "成本价不能为空")
|
||||
private BigDecimal costPrice;
|
||||
@Schema(description = "商品成本", example = "8000.00", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "商品成本不能为空")
|
||||
private BigDecimal productCost;
|
||||
|
||||
/**
|
||||
* 运费成本
|
||||
*/
|
||||
@Schema(description = "运费成本", example = "10.00")
|
||||
private BigDecimal shippingCost;
|
||||
|
||||
/**
|
||||
* 其他成本
|
||||
*/
|
||||
@Schema(description = "其他成本", example = "5.00")
|
||||
private BigDecimal otherCost;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Schema(description = "备注", example = "备注信息")
|
||||
private String remark;
|
||||
}
|
||||
|
||||
+22
-4
@@ -70,10 +70,28 @@ public class UpdateProductDTO {
|
||||
private String specCode;
|
||||
|
||||
/**
|
||||
* 成本价
|
||||
* 商品成本
|
||||
*/
|
||||
@Schema(description = "成本价", example = "8000.00", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "成本价不能为空")
|
||||
private BigDecimal costPrice;
|
||||
@Schema(description = "商品成本", example = "8000.00", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "商品成本不能为空")
|
||||
private BigDecimal productCost;
|
||||
|
||||
/**
|
||||
* 运费成本
|
||||
*/
|
||||
@Schema(description = "运费成本", example = "10.00")
|
||||
private BigDecimal shippingCost;
|
||||
|
||||
/**
|
||||
* 其他成本
|
||||
*/
|
||||
@Schema(description = "其他成本", example = "5.00")
|
||||
private BigDecimal otherCost;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Schema(description = "备注", example = "备注信息")
|
||||
private String remark;
|
||||
}
|
||||
}
|
||||
|
||||
+22
-4
@@ -35,9 +35,27 @@ public class UpdateProductSpecDTO {
|
||||
private String specCode;
|
||||
|
||||
/**
|
||||
* 成本价
|
||||
* 商品成本
|
||||
*/
|
||||
@Schema(description = "成本价", example = "8000.00", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "成本价不能为空")
|
||||
private BigDecimal costPrice;
|
||||
@Schema(description = "商品成本", example = "8000.00", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "商品成本不能为空")
|
||||
private BigDecimal productCost;
|
||||
|
||||
/**
|
||||
* 运费成本
|
||||
*/
|
||||
@Schema(description = "运费成本", example = "10.00")
|
||||
private BigDecimal shippingCost;
|
||||
|
||||
/**
|
||||
* 其他成本
|
||||
*/
|
||||
@Schema(description = "其他成本", example = "5.00")
|
||||
private BigDecimal otherCost;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Schema(description = "备注", example = "备注信息")
|
||||
private String remark;
|
||||
}
|
||||
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 电商-刷单记录实体
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("ec_brush_order")
|
||||
public class BrushOrderPO {
|
||||
|
||||
/**
|
||||
* 刷单记录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;
|
||||
|
||||
/**
|
||||
* 商品规格ID(可选)
|
||||
*/
|
||||
@TableField("product_spec_id")
|
||||
private Long productSpecId;
|
||||
|
||||
/**
|
||||
* 刷单金额
|
||||
*/
|
||||
@TableField("brush_amount")
|
||||
private BigDecimal brushAmount;
|
||||
|
||||
/**
|
||||
* 刷单时间
|
||||
*/
|
||||
@TableField("brush_time")
|
||||
private LocalDateTime brushTime;
|
||||
|
||||
/**
|
||||
* 平台订单号(可选)
|
||||
*/
|
||||
@TableField("platform_order_no")
|
||||
private String platformOrderNo;
|
||||
|
||||
/**
|
||||
* 刷单数量
|
||||
*/
|
||||
@TableField("quantity")
|
||||
private Integer quantity;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@TableField("remark")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@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;
|
||||
}
|
||||
|
||||
+33
-3
@@ -82,10 +82,40 @@ public class OrderPO {
|
||||
private BigDecimal unitPrice;
|
||||
|
||||
/**
|
||||
* 成本价(下单时快照)
|
||||
* 单件商品成本(下单时快照)
|
||||
*/
|
||||
@TableField("cost_price")
|
||||
private BigDecimal costPrice;
|
||||
@TableField("product_cost")
|
||||
private BigDecimal productCost;
|
||||
|
||||
/**
|
||||
* 单件运费成本(下单时快照)
|
||||
*/
|
||||
@TableField("shipping_cost")
|
||||
private BigDecimal shippingCost;
|
||||
|
||||
/**
|
||||
* 单件其他成本(下单时快照)
|
||||
*/
|
||||
@TableField("other_cost")
|
||||
private BigDecimal otherCost;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@TableField("remark")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 导入任务ID
|
||||
*/
|
||||
@TableField("import_task_id")
|
||||
private Long importTaskId;
|
||||
|
||||
/**
|
||||
* 确认(0-否 1-是)
|
||||
*/
|
||||
@TableField("confirm")
|
||||
private Integer confirm;
|
||||
|
||||
/**
|
||||
* 商家实收金额
|
||||
|
||||
+3
-3
@@ -45,10 +45,10 @@ public class OrderStatusPO {
|
||||
private Integer sortOrder;
|
||||
|
||||
/**
|
||||
* 是否默认参与统计 0不参与 1参与
|
||||
* 是否自动参与统计 0不参与 1参与
|
||||
*/
|
||||
@TableField("is_default_stat")
|
||||
private Integer isDefaultStat;
|
||||
@TableField("auto_statistics")
|
||||
private Integer autoStatistics;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
|
||||
+21
-3
@@ -46,10 +46,28 @@ public class ProductSpecPO {
|
||||
private String specCode;
|
||||
|
||||
/**
|
||||
* 成本价
|
||||
* 商品成本
|
||||
*/
|
||||
@TableField("cost_price")
|
||||
private BigDecimal costPrice;
|
||||
@TableField("product_cost")
|
||||
private BigDecimal productCost;
|
||||
|
||||
/**
|
||||
* 运费成本
|
||||
*/
|
||||
@TableField("shipping_cost")
|
||||
private BigDecimal shippingCost;
|
||||
|
||||
/**
|
||||
* 其他成本
|
||||
*/
|
||||
@TableField("other_cost")
|
||||
private BigDecimal otherCost;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@TableField("remark")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
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 BrushOrderVO {
|
||||
|
||||
/**
|
||||
* 刷单记录ID
|
||||
*/
|
||||
@Schema(description = "刷单记录ID", example = "1")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 公司ID
|
||||
*/
|
||||
@Schema(description = "公司ID", example = "1")
|
||||
private Long companyId;
|
||||
|
||||
/**
|
||||
* 店铺ID
|
||||
*/
|
||||
@Schema(description = "店铺ID", example = "1")
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 店铺名称
|
||||
*/
|
||||
@Schema(description = "店铺名称", example = "旗舰店")
|
||||
private String shopName;
|
||||
|
||||
/**
|
||||
* 商品ID
|
||||
*/
|
||||
@Schema(description = "商品ID", example = "1")
|
||||
private Long productId;
|
||||
|
||||
/**
|
||||
* 商品名称
|
||||
*/
|
||||
@Schema(description = "商品名称", example = "iPhone 15 Pro")
|
||||
private String productName;
|
||||
|
||||
/**
|
||||
* 商品规格ID
|
||||
*/
|
||||
@Schema(description = "商品规格ID", example = "1")
|
||||
private Long productSpecId;
|
||||
|
||||
/**
|
||||
* 商品规格名称
|
||||
*/
|
||||
@Schema(description = "商品规格名称", example = "256GB 深空黑色")
|
||||
private String productSpecName;
|
||||
|
||||
/**
|
||||
* 刷单金额
|
||||
*/
|
||||
@Schema(description = "刷单金额", example = "9999.00")
|
||||
private BigDecimal brushAmount;
|
||||
|
||||
/**
|
||||
* 刷单时间
|
||||
*/
|
||||
@Schema(description = "刷单时间", example = "2024-01-01T10:00:00")
|
||||
private LocalDateTime brushTime;
|
||||
|
||||
/**
|
||||
* 平台订单号
|
||||
*/
|
||||
@Schema(description = "平台订单号", example = "TB202401010001")
|
||||
private String platformOrderNo;
|
||||
|
||||
/**
|
||||
* 刷单数量
|
||||
*/
|
||||
@Schema(description = "刷单数量", example = "1")
|
||||
private Integer quantity;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Schema(description = "备注", example = "备注信息")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Schema(description = "创建时间", example = "2024-01-01T10:00:00")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@Schema(description = "更新时间", example = "2024-01-01T10:00:00")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
@Schema(description = "创建人ID", example = "1")
|
||||
private Long createBy;
|
||||
|
||||
/**
|
||||
* 更新人ID
|
||||
*/
|
||||
@Schema(description = "更新人ID", example = "1")
|
||||
private Long updateBy;
|
||||
}
|
||||
|
||||
+190
@@ -0,0 +1,190 @@
|
||||
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.util.List;
|
||||
|
||||
/**
|
||||
* 全店铺概览VO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "全店铺概览VO")
|
||||
public class CompanyOverviewVO {
|
||||
|
||||
/**
|
||||
* 全店总销售额
|
||||
*/
|
||||
@Schema(description = "全店总销售额", example = "100000.00")
|
||||
private BigDecimal totalSalesAmount;
|
||||
|
||||
/**
|
||||
* 较上月同期增长百分比
|
||||
*/
|
||||
@Schema(description = "较上月同期增长百分比", example = "15.50")
|
||||
private BigDecimal monthOverMonthGrowth;
|
||||
|
||||
/**
|
||||
* 全店总单量
|
||||
*/
|
||||
@Schema(description = "全店总单量", example = "1000")
|
||||
private Integer totalOrderCount;
|
||||
|
||||
/**
|
||||
* 总推广费支出
|
||||
*/
|
||||
@Schema(description = "总推广费支出", example = "5000.00")
|
||||
private BigDecimal totalPromotionFee;
|
||||
|
||||
/**
|
||||
* 平均费比(推广费/销售额)
|
||||
*/
|
||||
@Schema(description = "平均费比", example = "0.05")
|
||||
private BigDecimal averageFeeRatio;
|
||||
|
||||
/**
|
||||
* 全店总净利(税后)
|
||||
*/
|
||||
@Schema(description = "全店总净利(税后)", example = "80000.00")
|
||||
private BigDecimal totalNetProfitAfterTax;
|
||||
|
||||
/**
|
||||
* 扣除总税额
|
||||
*/
|
||||
@Schema(description = "扣除总税额", example = "6000.00")
|
||||
private BigDecimal totalTaxAmount;
|
||||
|
||||
/**
|
||||
* 各店铺销售占比排行
|
||||
*/
|
||||
@Schema(description = "各店铺销售占比排行")
|
||||
private List<ShopSalesRatio> shopSalesRatios;
|
||||
|
||||
/**
|
||||
* 店铺效率象限(ROI vs 净利)
|
||||
*/
|
||||
@Schema(description = "店铺效率象限")
|
||||
private List<ShopEfficiencyQuadrant> shopEfficiencyQuadrants;
|
||||
|
||||
/**
|
||||
* 多店铺数据横向对比(16维度)
|
||||
*/
|
||||
@Schema(description = "多店铺数据横向对比")
|
||||
private List<ShopComparison> shopComparisons;
|
||||
|
||||
/**
|
||||
* 汇总ROI
|
||||
*/
|
||||
@Schema(description = "汇总ROI", example = "1.5")
|
||||
private BigDecimal totalROI;
|
||||
|
||||
/**
|
||||
* 总税后盈亏
|
||||
*/
|
||||
@Schema(description = "总税后盈亏", example = "80000.00")
|
||||
private BigDecimal totalProfitAfterTax;
|
||||
|
||||
/**
|
||||
* 店铺销售占比
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "店铺销售占比")
|
||||
public static class ShopSalesRatio {
|
||||
@Schema(description = "店铺ID", example = "1")
|
||||
private Long shopId;
|
||||
|
||||
@Schema(description = "店铺名称", example = "旗舰店")
|
||||
private String shopName;
|
||||
|
||||
@Schema(description = "销售额", example = "50000.00")
|
||||
private BigDecimal salesAmount;
|
||||
|
||||
@Schema(description = "占比百分比", example = "50.00")
|
||||
private BigDecimal ratio;
|
||||
}
|
||||
|
||||
/**
|
||||
* 店铺效率象限
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "店铺效率象限")
|
||||
public static class ShopEfficiencyQuadrant {
|
||||
@Schema(description = "店铺ID", example = "1")
|
||||
private Long shopId;
|
||||
|
||||
@Schema(description = "店铺名称", example = "旗舰店")
|
||||
private String shopName;
|
||||
|
||||
@Schema(description = "ROI", example = "1.5")
|
||||
private BigDecimal roi;
|
||||
|
||||
@Schema(description = "净利", example = "30000.00")
|
||||
private BigDecimal netProfit;
|
||||
|
||||
@Schema(description = "象限(1-高ROI高净利,2-高ROI低净利,3-低ROI高净利,4-低ROI低净利)", example = "1")
|
||||
private Integer quadrant;
|
||||
}
|
||||
|
||||
/**
|
||||
* 店铺对比数据(16维度)
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "店铺对比数据")
|
||||
public static class ShopComparison {
|
||||
@Schema(description = "店铺ID", example = "1")
|
||||
private Long shopId;
|
||||
|
||||
@Schema(description = "店铺名称", example = "旗舰店")
|
||||
private String shopName;
|
||||
|
||||
@Schema(description = "平台", example = "拼多多")
|
||||
private String platform;
|
||||
|
||||
@Schema(description = "销售额", example = "50000.00")
|
||||
private BigDecimal salesAmount;
|
||||
|
||||
@Schema(description = "ROI", example = "1.5")
|
||||
private BigDecimal roi;
|
||||
|
||||
@Schema(description = "退款金额", example = "1000.00")
|
||||
private BigDecimal refundAmount;
|
||||
|
||||
@Schema(description = "刷单费", example = "2000.00")
|
||||
private BigDecimal brushFee;
|
||||
|
||||
@Schema(description = "推广费总和", example = "5000.00")
|
||||
private BigDecimal totalPromotionFee;
|
||||
|
||||
@Schema(description = "税后盈亏", example = "30000.00")
|
||||
private BigDecimal profitAfterTax;
|
||||
|
||||
@Schema(description = "订单数量", example = "500")
|
||||
private Integer orderCount;
|
||||
|
||||
@Schema(description = "总成本", example = "15000.00")
|
||||
private BigDecimal totalCost;
|
||||
|
||||
@Schema(description = "总利润(税前)", example = "35000.00")
|
||||
private BigDecimal totalProfitBeforeTax;
|
||||
|
||||
@Schema(description = "税额", example = "3000.00")
|
||||
private BigDecimal taxAmount;
|
||||
|
||||
@Schema(description = "费比", example = "0.10")
|
||||
private BigDecimal feeRatio;
|
||||
|
||||
@Schema(description = "客单价", example = "100.00")
|
||||
private BigDecimal averageOrderValue;
|
||||
|
||||
@Schema(description = "利润率", example = "0.60")
|
||||
private BigDecimal profitMargin;
|
||||
|
||||
@Schema(description = "推广费占比", example = "0.10")
|
||||
private BigDecimal promotionFeeRatio;
|
||||
|
||||
@Schema(description = "退款率", example = "0.02")
|
||||
private BigDecimal refundRate;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -43,10 +43,10 @@ public class OrderStatusVO {
|
||||
private Integer sortOrder;
|
||||
|
||||
/**
|
||||
* 是否默认参与统计 0不参与 1参与
|
||||
* 是否自动参与统计 0不参与 1参与
|
||||
*/
|
||||
@Schema(description = "是否默认参与统计", example = "1")
|
||||
private Integer isDefaultStat;
|
||||
@Schema(description = "是否自动参与统计", example = "1")
|
||||
private Integer autoStatistics;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
|
||||
+33
-3
@@ -128,8 +128,38 @@ public class OrderVO {
|
||||
private BigDecimal unitPrice;
|
||||
|
||||
/**
|
||||
* 成本价(下单时快照)
|
||||
* 单件商品成本(下单时快照)
|
||||
*/
|
||||
@Schema(description = "成本价", example = "8000.00")
|
||||
private BigDecimal costPrice;
|
||||
@Schema(description = "单件商品成本", example = "8000.00")
|
||||
private BigDecimal productCost;
|
||||
|
||||
/**
|
||||
* 单件运费成本(下单时快照)
|
||||
*/
|
||||
@Schema(description = "单件运费成本", example = "10.00")
|
||||
private BigDecimal shippingCost;
|
||||
|
||||
/**
|
||||
* 单件其他成本(下单时快照)
|
||||
*/
|
||||
@Schema(description = "单件其他成本", example = "5.00")
|
||||
private BigDecimal otherCost;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Schema(description = "备注", example = "备注信息")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 导入任务ID
|
||||
*/
|
||||
@Schema(description = "导入任务ID", example = "1")
|
||||
private Long importTaskId;
|
||||
|
||||
/**
|
||||
* 确认(0-否 1-是)
|
||||
*/
|
||||
@Schema(description = "确认", example = "1")
|
||||
private Integer confirm;
|
||||
}
|
||||
|
||||
+21
-3
@@ -50,10 +50,28 @@ public class ProductSpecVO {
|
||||
private String specCode;
|
||||
|
||||
/**
|
||||
* 成本价
|
||||
* 商品成本
|
||||
*/
|
||||
@Schema(description = "成本价", example = "8000.00")
|
||||
private BigDecimal costPrice;
|
||||
@Schema(description = "商品成本", example = "8000.00")
|
||||
private BigDecimal productCost;
|
||||
|
||||
/**
|
||||
* 运费成本
|
||||
*/
|
||||
@Schema(description = "运费成本", example = "10.00")
|
||||
private BigDecimal shippingCost;
|
||||
|
||||
/**
|
||||
* 其他成本
|
||||
*/
|
||||
@Schema(description = "其他成本", example = "5.00")
|
||||
private BigDecimal otherCost;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Schema(description = "备注", example = "备注信息")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.brushorder.BrushOrderFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.brushorder.CreateBrushOrderDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.brushorder.UpdateBrushOrderDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.BrushOrderPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.BrushOrderVO;
|
||||
|
||||
/**
|
||||
* 刷单记录服务接口
|
||||
*/
|
||||
public interface BrushOrderService extends IService<BrushOrderPO> {
|
||||
|
||||
/**
|
||||
* 创建刷单记录
|
||||
*
|
||||
* @param createBrushOrderDTO 创建刷单记录DTO
|
||||
* @return 刷单记录VO
|
||||
*/
|
||||
BrushOrderVO createBrushOrder(CreateBrushOrderDTO createBrushOrderDTO);
|
||||
|
||||
/**
|
||||
* 更新刷单记录
|
||||
*
|
||||
* @param updateBrushOrderDTO 更新刷单记录DTO
|
||||
* @param id 刷单记录ID
|
||||
* @return 刷单记录VO
|
||||
*/
|
||||
BrushOrderVO updateBrushOrder(UpdateBrushOrderDTO updateBrushOrderDTO, Long id);
|
||||
|
||||
/**
|
||||
* 删除刷单记录
|
||||
*
|
||||
* @param id 刷单记录ID
|
||||
*/
|
||||
void deleteBrushOrder(Long id);
|
||||
|
||||
/**
|
||||
* 分页获取刷单记录列表
|
||||
*
|
||||
* @param pageQueryDTO 分页查询DTO
|
||||
* @return 分页结果
|
||||
*/
|
||||
PageResultVO<BrushOrderVO> getBrushOrderPage(PageQueryDTO<BrushOrderFilterDTO> pageQueryDTO);
|
||||
|
||||
/**
|
||||
* 根据ID获取刷单记录详情
|
||||
*
|
||||
* @param id 刷单记录ID
|
||||
* @return 刷单记录VO
|
||||
*/
|
||||
BrushOrderVO getBrushOrderById(Long id);
|
||||
}
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.service;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.overview.CompanyOverviewQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.CompanyOverviewVO;
|
||||
|
||||
/**
|
||||
* 全店铺概览服务接口
|
||||
*/
|
||||
public interface CompanyOverviewService {
|
||||
|
||||
/**
|
||||
* 获取全店铺概览统计数据
|
||||
*
|
||||
* @param queryDTO 查询DTO
|
||||
* @return 全店铺概览VO
|
||||
*/
|
||||
CompanyOverviewVO getCompanyOverview(CompanyOverviewQueryDTO queryDTO);
|
||||
}
|
||||
|
||||
+300
@@ -0,0 +1,300 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
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.BrushOrderMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.brushorder.BrushOrderFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.brushorder.CreateBrushOrderDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.brushorder.UpdateBrushOrderDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.BrushOrderPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ProductPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ProductSpecPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ShopPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.BrushOrderVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.service.BrushOrderService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.service.ProductService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.service.ProductSpecService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.service.ShopService;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 刷单记录服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class BrushOrderServiceImpl extends ServiceImpl<BrushOrderMapper, BrushOrderPO> implements BrushOrderService {
|
||||
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final ShopService shopService;
|
||||
private final ProductService productService;
|
||||
private final ProductSpecService productSpecService;
|
||||
|
||||
public BrushOrderServiceImpl(CurrentUserContext currentUserContext, ShopService shopService,
|
||||
ProductService productService, ProductSpecService productSpecService) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.shopService = shopService;
|
||||
this.productService = productService;
|
||||
this.productSpecService = productSpecService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建刷单记录
|
||||
*
|
||||
* @param createBrushOrderDTO 创建刷单记录DTO
|
||||
* @return 刷单记录VO
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public BrushOrderVO createBrushOrder(CreateBrushOrderDTO createBrushOrderDTO) {
|
||||
// 从token中获取公司ID
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
// 验证店铺是否存在且属于当前公司
|
||||
ShopPO shop = shopService.getById(createBrushOrderDTO.getShopId());
|
||||
if (shop == null || !shop.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("店铺不存在");
|
||||
}
|
||||
|
||||
// 验证商品是否存在且属于当前公司(如果提供了商品ID)
|
||||
if (createBrushOrderDTO.getProductId() != null) {
|
||||
ProductPO product = productService.getById(createBrushOrderDTO.getProductId());
|
||||
if (product == null || !product.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("商品不存在");
|
||||
}
|
||||
|
||||
// 验证商品规格是否存在且属于当前公司(如果提供了规格ID)
|
||||
if (createBrushOrderDTO.getProductSpecId() != null) {
|
||||
ProductSpecPO productSpec = productSpecService.getById(createBrushOrderDTO.getProductSpecId());
|
||||
if (productSpec == null || !productSpec.getCompanyId().equals(companyId) ||
|
||||
!productSpec.getProductId().equals(createBrushOrderDTO.getProductId())) {
|
||||
throw new BusinessException("商品规格不存在或不属于该商品");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 创建刷单记录
|
||||
BrushOrderPO brushOrder = new BrushOrderPO();
|
||||
brushOrder.setCompanyId(companyId);
|
||||
brushOrder.setShopId(createBrushOrderDTO.getShopId());
|
||||
brushOrder.setProductId(createBrushOrderDTO.getProductId());
|
||||
brushOrder.setProductSpecId(createBrushOrderDTO.getProductSpecId());
|
||||
brushOrder.setBrushAmount(createBrushOrderDTO.getBrushAmount());
|
||||
brushOrder.setBrushTime(createBrushOrderDTO.getBrushTime());
|
||||
brushOrder.setPlatformOrderNo(createBrushOrderDTO.getPlatformOrderNo());
|
||||
brushOrder.setQuantity(createBrushOrderDTO.getQuantity() != null ? createBrushOrderDTO.getQuantity() : 1);
|
||||
brushOrder.setRemark(createBrushOrderDTO.getRemark());
|
||||
brushOrder.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
// 保存刷单记录
|
||||
this.save(brushOrder);
|
||||
|
||||
// 转换为VO并返回
|
||||
return convertToVO(brushOrder);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新刷单记录
|
||||
*
|
||||
* @param updateBrushOrderDTO 更新刷单记录DTO
|
||||
* @param id 刷单记录ID
|
||||
* @return 刷单记录VO
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public BrushOrderVO updateBrushOrder(UpdateBrushOrderDTO updateBrushOrderDTO, Long id) {
|
||||
// 从token中获取公司ID
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
// 验证刷单记录是否存在
|
||||
BrushOrderPO existingBrushOrder = this.getById(id);
|
||||
if (existingBrushOrder == null || !existingBrushOrder.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("刷单记录不存在");
|
||||
}
|
||||
|
||||
// 验证店铺是否存在且属于当前公司
|
||||
ShopPO shop = shopService.getById(updateBrushOrderDTO.getShopId());
|
||||
if (shop == null || !shop.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("店铺不存在");
|
||||
}
|
||||
|
||||
// 验证商品是否存在且属于当前公司(如果提供了商品ID)
|
||||
if (updateBrushOrderDTO.getProductId() != null) {
|
||||
ProductPO product = productService.getById(updateBrushOrderDTO.getProductId());
|
||||
if (product == null || !product.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("商品不存在");
|
||||
}
|
||||
|
||||
// 验证商品规格是否存在且属于当前公司(如果提供了规格ID)
|
||||
if (updateBrushOrderDTO.getProductSpecId() != null) {
|
||||
ProductSpecPO productSpec = productSpecService.getById(updateBrushOrderDTO.getProductSpecId());
|
||||
if (productSpec == null || !productSpec.getCompanyId().equals(companyId) ||
|
||||
!productSpec.getProductId().equals(updateBrushOrderDTO.getProductId())) {
|
||||
throw new BusinessException("商品规格不存在或不属于该商品");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 更新刷单记录
|
||||
existingBrushOrder.setShopId(updateBrushOrderDTO.getShopId());
|
||||
existingBrushOrder.setProductId(updateBrushOrderDTO.getProductId());
|
||||
existingBrushOrder.setProductSpecId(updateBrushOrderDTO.getProductSpecId());
|
||||
existingBrushOrder.setBrushAmount(updateBrushOrderDTO.getBrushAmount());
|
||||
existingBrushOrder.setBrushTime(updateBrushOrderDTO.getBrushTime());
|
||||
existingBrushOrder.setPlatformOrderNo(updateBrushOrderDTO.getPlatformOrderNo());
|
||||
if (updateBrushOrderDTO.getQuantity() != null) {
|
||||
existingBrushOrder.setQuantity(updateBrushOrderDTO.getQuantity());
|
||||
}
|
||||
existingBrushOrder.setRemark(updateBrushOrderDTO.getRemark());
|
||||
existingBrushOrder.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
// 保存更新
|
||||
this.updateById(existingBrushOrder);
|
||||
|
||||
// 转换为VO并返回
|
||||
return convertToVO(existingBrushOrder);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除刷单记录
|
||||
*
|
||||
* @param id 刷单记录ID
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteBrushOrder(Long id) {
|
||||
// 从token中获取公司ID
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
// 验证刷单记录是否存在
|
||||
BrushOrderPO existingBrushOrder = this.getById(id);
|
||||
if (existingBrushOrder == null || !existingBrushOrder.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("刷单记录不存在");
|
||||
}
|
||||
|
||||
// 硬删除刷单记录
|
||||
this.removeById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取刷单记录分页列表
|
||||
*
|
||||
* @param pageQueryDTO 分页查询DTO
|
||||
* @return 分页结果VO
|
||||
*/
|
||||
@Override
|
||||
public PageResultVO<BrushOrderVO> getBrushOrderPage(PageQueryDTO<BrushOrderFilterDTO> pageQueryDTO) {
|
||||
// 从token中获取公司ID
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
// 创建分页对象
|
||||
Page<BrushOrderPO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||
|
||||
// 构建查询条件
|
||||
LambdaQueryWrapper<BrushOrderPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(BrushOrderPO::getCompanyId, companyId);
|
||||
|
||||
// 添加过滤条件
|
||||
BrushOrderFilterDTO filter = pageQueryDTO.getFilters();
|
||||
if (filter != null) {
|
||||
if (filter.getShopId() != null) {
|
||||
wrapper.eq(BrushOrderPO::getShopId, filter.getShopId());
|
||||
}
|
||||
if (filter.getProductId() != null) {
|
||||
wrapper.eq(BrushOrderPO::getProductId, filter.getProductId());
|
||||
}
|
||||
if (filter.getPlatformOrderNo() != null && !filter.getPlatformOrderNo().trim().isEmpty()) {
|
||||
wrapper.like(BrushOrderPO::getPlatformOrderNo, filter.getPlatformOrderNo());
|
||||
}
|
||||
if (filter.getMinBrushAmount() != null) {
|
||||
wrapper.ge(BrushOrderPO::getBrushAmount, filter.getMinBrushAmount());
|
||||
}
|
||||
if (filter.getMaxBrushAmount() != null) {
|
||||
wrapper.le(BrushOrderPO::getBrushAmount, filter.getMaxBrushAmount());
|
||||
}
|
||||
if (filter.getStartBrushTime() != null) {
|
||||
wrapper.ge(BrushOrderPO::getBrushTime, filter.getStartBrushTime());
|
||||
}
|
||||
if (filter.getEndBrushTime() != null) {
|
||||
wrapper.le(BrushOrderPO::getBrushTime, filter.getEndBrushTime());
|
||||
}
|
||||
}
|
||||
|
||||
// 排序
|
||||
wrapper.orderByDesc(BrushOrderPO::getBrushTime)
|
||||
.orderByDesc(BrushOrderPO::getCreateTime);
|
||||
|
||||
// 执行分页查询
|
||||
IPage<BrushOrderPO> pageResult = this.page(page, wrapper);
|
||||
|
||||
// 转换为VO
|
||||
List<BrushOrderVO> voList = pageResult.getRecords().stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 构建分页结果
|
||||
return PageResultVO.create(voList, pageResult.getTotal(), pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询刷单记录
|
||||
*
|
||||
* @param id 刷单记录ID
|
||||
* @return 刷单记录VO
|
||||
*/
|
||||
@Override
|
||||
public BrushOrderVO getBrushOrderById(Long id) {
|
||||
// 从token中获取公司ID
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
// 验证刷单记录是否存在
|
||||
BrushOrderPO brushOrder = this.getById(id);
|
||||
if (brushOrder == null || !brushOrder.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("刷单记录不存在");
|
||||
}
|
||||
|
||||
// 转换为VO并返回
|
||||
return convertToVO(brushOrder);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为VO
|
||||
*/
|
||||
private BrushOrderVO convertToVO(BrushOrderPO brushOrder) {
|
||||
BrushOrderVO brushOrderVO = new BrushOrderVO();
|
||||
BeanUtils.copyProperties(brushOrder, brushOrderVO);
|
||||
|
||||
// 设置店铺名称
|
||||
ShopPO shop = shopService.getById(brushOrder.getShopId());
|
||||
if (shop != null) {
|
||||
brushOrderVO.setShopName(shop.getName());
|
||||
}
|
||||
|
||||
// 设置商品名称和规格名称(如果存在)
|
||||
if (brushOrder.getProductId() != null) {
|
||||
ProductPO product = productService.getById(brushOrder.getProductId());
|
||||
if (product != null) {
|
||||
brushOrderVO.setProductName(product.getName());
|
||||
}
|
||||
|
||||
if (brushOrder.getProductSpecId() != null) {
|
||||
ProductSpecPO productSpec = productSpecService.getById(brushOrder.getProductSpecId());
|
||||
if (productSpec != null) {
|
||||
brushOrderVO.setProductSpecName(productSpec.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return brushOrderVO;
|
||||
}
|
||||
}
|
||||
|
||||
+516
@@ -0,0 +1,516 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.mapper.BrushOrderMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.mapper.OrderMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.mapper.PromotionFeeMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.overview.CompanyOverviewQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.BrushOrderPO;
|
||||
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.PromotionFeePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ShopPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.CompanyOverviewVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.service.CompanyOverviewService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.service.OrderStatusService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.service.ShopService;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 全店铺概览服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
|
||||
private static final BigDecimal TAX_RATE = new BigDecimal("0.06"); // 税率6%
|
||||
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final OrderMapper orderMapper;
|
||||
private final PromotionFeeMapper promotionFeeMapper;
|
||||
private final BrushOrderMapper brushOrderMapper;
|
||||
private final ShopService shopService;
|
||||
private final OrderStatusService orderStatusService;
|
||||
|
||||
public CompanyOverviewServiceImpl(CurrentUserContext currentUserContext,
|
||||
OrderMapper orderMapper,
|
||||
PromotionFeeMapper promotionFeeMapper,
|
||||
BrushOrderMapper brushOrderMapper,
|
||||
ShopService shopService,
|
||||
OrderStatusService orderStatusService) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.orderMapper = orderMapper;
|
||||
this.promotionFeeMapper = promotionFeeMapper;
|
||||
this.brushOrderMapper = brushOrderMapper;
|
||||
this.shopService = shopService;
|
||||
this.orderStatusService = orderStatusService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompanyOverviewVO getCompanyOverview(CompanyOverviewQueryDTO queryDTO) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
// 解析日期范围
|
||||
LocalDate startDate;
|
||||
LocalDate endDate;
|
||||
if (queryDTO.getDateRange().size() == 1) {
|
||||
// 只有一个日期,返回当天数据
|
||||
startDate = queryDTO.getDateRange().get(0);
|
||||
endDate = startDate;
|
||||
} else {
|
||||
startDate = queryDTO.getDateRange().get(0);
|
||||
endDate = queryDTO.getDateRange().get(1);
|
||||
if (startDate.isAfter(endDate)) {
|
||||
throw new BusinessException("开始日期不能晚于结束日期");
|
||||
}
|
||||
}
|
||||
|
||||
LocalDateTime startDateTime = startDate.atStartOfDay();
|
||||
LocalDateTime endDateTime = endDate.atTime(23, 59, 59);
|
||||
|
||||
// 查询所有店铺
|
||||
LambdaQueryWrapper<ShopPO> shopWrapper = new LambdaQueryWrapper<>();
|
||||
shopWrapper.eq(ShopPO::getCompanyId, companyId);
|
||||
List<ShopPO> shops = shopService.list(shopWrapper);
|
||||
if (shops.isEmpty()) {
|
||||
throw new BusinessException("当前公司没有店铺");
|
||||
}
|
||||
|
||||
// 查询订单数据(所有店铺)
|
||||
LambdaQueryWrapper<OrderPO> orderWrapper = new LambdaQueryWrapper<>();
|
||||
orderWrapper.eq(OrderPO::getCompanyId, companyId)
|
||||
.ge(OrderPO::getOrderTime, startDateTime)
|
||||
.le(OrderPO::getOrderTime, endDateTime);
|
||||
List<OrderPO> orders = orderMapper.selectList(orderWrapper);
|
||||
|
||||
// 查询推广费数据(所有店铺)
|
||||
LambdaQueryWrapper<PromotionFeePO> promotionWrapper = new LambdaQueryWrapper<>();
|
||||
promotionWrapper.eq(PromotionFeePO::getCompanyId, companyId)
|
||||
.ge(PromotionFeePO::getFeeDate, startDate)
|
||||
.le(PromotionFeePO::getFeeDate, endDate);
|
||||
List<PromotionFeePO> promotionFees = promotionFeeMapper.selectList(promotionWrapper);
|
||||
|
||||
// 查询刷单费数据(所有店铺)
|
||||
LambdaQueryWrapper<BrushOrderPO> brushWrapper = new LambdaQueryWrapper<>();
|
||||
brushWrapper.eq(BrushOrderPO::getCompanyId, companyId)
|
||||
.ge(BrushOrderPO::getBrushTime, startDateTime)
|
||||
.le(BrushOrderPO::getBrushTime, endDateTime);
|
||||
List<BrushOrderPO> brushOrders = brushOrderMapper.selectList(brushWrapper);
|
||||
|
||||
// 获取退款状态ID
|
||||
Long refundStatusId = getRefundStatusId();
|
||||
|
||||
// 计算上月同期数据(用于增长百分比)
|
||||
LocalDate lastMonthStartDate = startDate.minusMonths(1);
|
||||
LocalDate lastMonthEndDate = endDate.minusMonths(1);
|
||||
LocalDateTime lastMonthStartDateTime = lastMonthStartDate.atStartOfDay();
|
||||
LocalDateTime lastMonthEndDateTime = lastMonthEndDate.atTime(23, 59, 59);
|
||||
|
||||
LambdaQueryWrapper<OrderPO> lastMonthOrderWrapper = new LambdaQueryWrapper<>();
|
||||
lastMonthOrderWrapper.eq(OrderPO::getCompanyId, companyId)
|
||||
.ge(OrderPO::getOrderTime, lastMonthStartDateTime)
|
||||
.le(OrderPO::getOrderTime, lastMonthEndDateTime);
|
||||
List<OrderPO> lastMonthOrders = orderMapper.selectList(lastMonthOrderWrapper);
|
||||
|
||||
// 构建返回对象
|
||||
CompanyOverviewVO overviewVO = new CompanyOverviewVO();
|
||||
|
||||
// 1. 计算全店总销售额
|
||||
BigDecimal totalSalesAmount = orders.stream()
|
||||
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
overviewVO.setTotalSalesAmount(totalSalesAmount);
|
||||
|
||||
// 2. 计算较上月同期增长百分比
|
||||
BigDecimal lastMonthSalesAmount = lastMonthOrders.stream()
|
||||
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
BigDecimal monthOverMonthGrowth = BigDecimal.ZERO;
|
||||
if (lastMonthSalesAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
monthOverMonthGrowth = totalSalesAmount.subtract(lastMonthSalesAmount)
|
||||
.divide(lastMonthSalesAmount, 4, RoundingMode.HALF_UP)
|
||||
.multiply(new BigDecimal("100"));
|
||||
} else if (totalSalesAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
monthOverMonthGrowth = new BigDecimal("100"); // 上月为0,本月有数据,增长100%
|
||||
}
|
||||
overviewVO.setMonthOverMonthGrowth(monthOverMonthGrowth);
|
||||
|
||||
// 3. 计算全店总单量
|
||||
int totalOrderCount = orders.size();
|
||||
overviewVO.setTotalOrderCount(totalOrderCount);
|
||||
|
||||
// 4. 计算总推广费支出
|
||||
BigDecimal totalPromotionFee = promotionFees.stream()
|
||||
.map(fee -> fee.getFeeAmount() != null ? fee.getFeeAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
overviewVO.setTotalPromotionFee(totalPromotionFee);
|
||||
|
||||
// 5. 计算平均费比
|
||||
BigDecimal averageFeeRatio = BigDecimal.ZERO;
|
||||
if (totalSalesAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
averageFeeRatio = totalPromotionFee.divide(totalSalesAmount, 4, RoundingMode.HALF_UP);
|
||||
}
|
||||
overviewVO.setAverageFeeRatio(averageFeeRatio);
|
||||
|
||||
// 6. 计算全店总净利(税后)和总税额
|
||||
BigDecimal totalProfitBeforeTax = calculateTotalProfit(orders);
|
||||
BigDecimal totalTaxAmount = totalProfitBeforeTax.multiply(TAX_RATE);
|
||||
BigDecimal totalNetProfitAfterTax = totalProfitBeforeTax.subtract(totalTaxAmount);
|
||||
overviewVO.setTotalNetProfitAfterTax(totalNetProfitAfterTax);
|
||||
overviewVO.setTotalTaxAmount(totalTaxAmount);
|
||||
|
||||
// 7. 计算各店铺销售占比排行
|
||||
List<CompanyOverviewVO.ShopSalesRatio> shopSalesRatios = calculateShopSalesRatios(shops, orders, totalSalesAmount);
|
||||
overviewVO.setShopSalesRatios(shopSalesRatios);
|
||||
|
||||
// 8. 计算店铺效率象限(ROI vs 净利)
|
||||
List<CompanyOverviewVO.ShopEfficiencyQuadrant> shopEfficiencyQuadrants = calculateShopEfficiencyQuadrants(
|
||||
shops, orders, promotionFees, brushOrders, refundStatusId);
|
||||
overviewVO.setShopEfficiencyQuadrants(shopEfficiencyQuadrants);
|
||||
|
||||
// 9. 多店铺数据横向对比(16维度)
|
||||
List<CompanyOverviewVO.ShopComparison> shopComparisons = calculateShopComparisons(
|
||||
shops, orders, promotionFees, brushOrders, refundStatusId);
|
||||
overviewVO.setShopComparisons(shopComparisons);
|
||||
|
||||
// 10. 汇总ROI和总税后盈亏
|
||||
BigDecimal totalROI = calculateTotalROI(orders, promotionFees, brushOrders);
|
||||
overviewVO.setTotalROI(totalROI);
|
||||
overviewVO.setTotalProfitAfterTax(totalNetProfitAfterTax);
|
||||
|
||||
return overviewVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算总利润(税前)
|
||||
*/
|
||||
private BigDecimal calculateTotalProfit(List<OrderPO> orders) {
|
||||
return orders.stream()
|
||||
.map(order -> {
|
||||
BigDecimal receivedAmount = order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO;
|
||||
BigDecimal productCost = order.getProductCost() != null ? order.getProductCost() : BigDecimal.ZERO;
|
||||
BigDecimal shippingCost = order.getShippingCost() != null ? order.getShippingCost() : BigDecimal.ZERO;
|
||||
BigDecimal otherCost = order.getOtherCost() != null ? order.getOtherCost() : BigDecimal.ZERO;
|
||||
Integer quantity = order.getQuantity() != null ? order.getQuantity() : 1;
|
||||
BigDecimal totalCost = productCost.add(shippingCost).add(otherCost).multiply(new BigDecimal(quantity));
|
||||
return receivedAmount.subtract(totalCost);
|
||||
})
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算各店铺销售占比排行
|
||||
*/
|
||||
private List<CompanyOverviewVO.ShopSalesRatio> calculateShopSalesRatios(
|
||||
List<ShopPO> shops, List<OrderPO> orders, BigDecimal totalSalesAmount) {
|
||||
Map<Long, BigDecimal> shopSalesMap = orders.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
OrderPO::getShopId,
|
||||
Collectors.reducing(
|
||||
BigDecimal.ZERO,
|
||||
order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO,
|
||||
BigDecimal::add)));
|
||||
|
||||
List<CompanyOverviewVO.ShopSalesRatio> ratios = new ArrayList<>();
|
||||
for (ShopPO shop : shops) {
|
||||
BigDecimal salesAmount = shopSalesMap.getOrDefault(shop.getId(), BigDecimal.ZERO);
|
||||
BigDecimal ratio = BigDecimal.ZERO;
|
||||
if (totalSalesAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
ratio = salesAmount.divide(totalSalesAmount, 4, RoundingMode.HALF_UP)
|
||||
.multiply(new BigDecimal("100"));
|
||||
}
|
||||
|
||||
CompanyOverviewVO.ShopSalesRatio shopRatio = new CompanyOverviewVO.ShopSalesRatio();
|
||||
shopRatio.setShopId(shop.getId());
|
||||
shopRatio.setShopName(shop.getName());
|
||||
shopRatio.setSalesAmount(salesAmount);
|
||||
shopRatio.setRatio(ratio);
|
||||
ratios.add(shopRatio);
|
||||
}
|
||||
|
||||
// 按销售额降序排序
|
||||
ratios.sort(Comparator.comparing(CompanyOverviewVO.ShopSalesRatio::getSalesAmount).reversed());
|
||||
return ratios;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算店铺效率象限(ROI vs 净利)
|
||||
*/
|
||||
private List<CompanyOverviewVO.ShopEfficiencyQuadrant> calculateShopEfficiencyQuadrants(
|
||||
List<ShopPO> shops, List<OrderPO> orders, List<PromotionFeePO> promotionFees,
|
||||
List<BrushOrderPO> brushOrders, Long refundStatusId) {
|
||||
List<CompanyOverviewVO.ShopEfficiencyQuadrant> quadrants = new ArrayList<>();
|
||||
|
||||
// 按店铺分组数据
|
||||
Map<Long, List<OrderPO>> ordersByShop = orders.stream()
|
||||
.collect(Collectors.groupingBy(OrderPO::getShopId));
|
||||
Map<Long, List<PromotionFeePO>> promotionFeesByShop = promotionFees.stream()
|
||||
.collect(Collectors.groupingBy(PromotionFeePO::getShopId));
|
||||
Map<Long, List<BrushOrderPO>> brushOrdersByShop = brushOrders.stream()
|
||||
.collect(Collectors.groupingBy(BrushOrderPO::getShopId));
|
||||
|
||||
// 计算所有店铺的平均ROI和平均净利(用于划分象限)
|
||||
List<BigDecimal> allROIs = new ArrayList<>();
|
||||
List<BigDecimal> allNetProfits = new ArrayList<>();
|
||||
|
||||
for (ShopPO shop : shops) {
|
||||
List<OrderPO> shopOrders = ordersByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
||||
List<PromotionFeePO> shopPromotionFees = promotionFeesByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
||||
List<BrushOrderPO> shopBrushOrders = brushOrdersByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
||||
|
||||
BigDecimal profit = calculateShopProfit(shopOrders, refundStatusId);
|
||||
BigDecimal totalCost = calculateShopTotalCost(shopPromotionFees, shopBrushOrders);
|
||||
BigDecimal roi = calculateShopROI(profit, totalCost);
|
||||
BigDecimal netProfit = calculateShopNetProfit(profit);
|
||||
|
||||
allROIs.add(roi);
|
||||
allNetProfits.add(netProfit);
|
||||
}
|
||||
|
||||
BigDecimal avgROI = allROIs.isEmpty() ? BigDecimal.ZERO :
|
||||
allROIs.stream().reduce(BigDecimal.ZERO, BigDecimal::add)
|
||||
.divide(new BigDecimal(allROIs.size()), 4, RoundingMode.HALF_UP);
|
||||
BigDecimal avgNetProfit = allNetProfits.isEmpty() ? BigDecimal.ZERO :
|
||||
allNetProfits.stream().reduce(BigDecimal.ZERO, BigDecimal::add)
|
||||
.divide(new BigDecimal(allNetProfits.size()), 4, RoundingMode.HALF_UP);
|
||||
|
||||
// 计算每个店铺的象限
|
||||
for (ShopPO shop : shops) {
|
||||
List<OrderPO> shopOrders = ordersByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
||||
List<PromotionFeePO> shopPromotionFees = promotionFeesByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
||||
List<BrushOrderPO> shopBrushOrders = brushOrdersByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
||||
|
||||
BigDecimal profit = calculateShopProfit(shopOrders, refundStatusId);
|
||||
BigDecimal totalCost = calculateShopTotalCost(shopPromotionFees, shopBrushOrders);
|
||||
BigDecimal roi = calculateShopROI(profit, totalCost);
|
||||
BigDecimal netProfit = calculateShopNetProfit(profit);
|
||||
|
||||
int quadrant;
|
||||
if (roi.compareTo(avgROI) >= 0 && netProfit.compareTo(avgNetProfit) >= 0) {
|
||||
quadrant = 1; // 高ROI高净利
|
||||
} else if (roi.compareTo(avgROI) >= 0 && netProfit.compareTo(avgNetProfit) < 0) {
|
||||
quadrant = 2; // 高ROI低净利
|
||||
} else if (roi.compareTo(avgROI) < 0 && netProfit.compareTo(avgNetProfit) >= 0) {
|
||||
quadrant = 3; // 低ROI高净利
|
||||
} else {
|
||||
quadrant = 4; // 低ROI低净利
|
||||
}
|
||||
|
||||
CompanyOverviewVO.ShopEfficiencyQuadrant shopQuadrant = new CompanyOverviewVO.ShopEfficiencyQuadrant();
|
||||
shopQuadrant.setShopId(shop.getId());
|
||||
shopQuadrant.setShopName(shop.getName());
|
||||
shopQuadrant.setRoi(roi);
|
||||
shopQuadrant.setNetProfit(netProfit);
|
||||
shopQuadrant.setQuadrant(quadrant);
|
||||
quadrants.add(shopQuadrant);
|
||||
}
|
||||
|
||||
return quadrants;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算多店铺数据横向对比(16维度)
|
||||
*/
|
||||
private List<CompanyOverviewVO.ShopComparison> calculateShopComparisons(
|
||||
List<ShopPO> shops, List<OrderPO> orders, List<PromotionFeePO> promotionFees,
|
||||
List<BrushOrderPO> brushOrders, Long refundStatusId) {
|
||||
List<CompanyOverviewVO.ShopComparison> comparisons = new ArrayList<>();
|
||||
|
||||
// 按店铺分组数据
|
||||
Map<Long, List<OrderPO>> ordersByShop = orders.stream()
|
||||
.collect(Collectors.groupingBy(OrderPO::getShopId));
|
||||
Map<Long, List<PromotionFeePO>> promotionFeesByShop = promotionFees.stream()
|
||||
.collect(Collectors.groupingBy(PromotionFeePO::getShopId));
|
||||
Map<Long, List<BrushOrderPO>> brushOrdersByShop = brushOrders.stream()
|
||||
.collect(Collectors.groupingBy(BrushOrderPO::getShopId));
|
||||
|
||||
for (ShopPO shop : shops) {
|
||||
List<OrderPO> shopOrders = ordersByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
||||
List<PromotionFeePO> shopPromotionFees = promotionFeesByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
||||
List<BrushOrderPO> shopBrushOrders = brushOrdersByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
||||
|
||||
// 计算各项指标
|
||||
BigDecimal salesAmount = shopOrders.stream()
|
||||
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
BigDecimal refundAmount = shopOrders.stream()
|
||||
.filter(order -> refundStatusId != null && refundStatusId.equals(order.getStatusId()))
|
||||
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
BigDecimal brushFee = shopBrushOrders.stream()
|
||||
.map(brush -> brush.getBrushAmount() != null ? brush.getBrushAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
BigDecimal totalPromotionFee = shopPromotionFees.stream()
|
||||
.map(fee -> fee.getFeeAmount() != null ? fee.getFeeAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
BigDecimal totalCost = calculateShopTotalCost(shopOrders);
|
||||
BigDecimal profitBeforeTax = salesAmount.subtract(totalCost).subtract(refundAmount);
|
||||
BigDecimal taxAmount = profitBeforeTax.multiply(TAX_RATE);
|
||||
BigDecimal profitAfterTax = profitBeforeTax.subtract(taxAmount);
|
||||
|
||||
BigDecimal totalCostForROI = totalPromotionFee.add(brushFee);
|
||||
BigDecimal roi = calculateShopROI(profitBeforeTax, totalCostForROI);
|
||||
|
||||
BigDecimal feeRatio = BigDecimal.ZERO;
|
||||
if (salesAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
feeRatio = totalPromotionFee.divide(salesAmount, 4, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
BigDecimal averageOrderValue = BigDecimal.ZERO;
|
||||
int orderCount = shopOrders.size();
|
||||
if (orderCount > 0) {
|
||||
averageOrderValue = salesAmount.divide(new BigDecimal(orderCount), 2, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
BigDecimal profitMargin = BigDecimal.ZERO;
|
||||
if (salesAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
profitMargin = profitBeforeTax.divide(salesAmount, 4, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
BigDecimal promotionFeeRatio = BigDecimal.ZERO;
|
||||
if (salesAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
promotionFeeRatio = totalPromotionFee.divide(salesAmount, 4, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
BigDecimal refundRate = BigDecimal.ZERO;
|
||||
if (salesAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
refundRate = refundAmount.divide(salesAmount, 4, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
CompanyOverviewVO.ShopComparison comparison = new CompanyOverviewVO.ShopComparison();
|
||||
comparison.setShopId(shop.getId());
|
||||
comparison.setShopName(shop.getName());
|
||||
comparison.setPlatform(shop.getPlatform());
|
||||
comparison.setSalesAmount(salesAmount);
|
||||
comparison.setRoi(roi);
|
||||
comparison.setRefundAmount(refundAmount);
|
||||
comparison.setBrushFee(brushFee);
|
||||
comparison.setTotalPromotionFee(totalPromotionFee);
|
||||
comparison.setProfitAfterTax(profitAfterTax);
|
||||
comparison.setOrderCount(orderCount);
|
||||
comparison.setTotalCost(totalCost);
|
||||
comparison.setTotalProfitBeforeTax(profitBeforeTax);
|
||||
comparison.setTaxAmount(taxAmount);
|
||||
comparison.setFeeRatio(feeRatio);
|
||||
comparison.setAverageOrderValue(averageOrderValue);
|
||||
comparison.setProfitMargin(profitMargin);
|
||||
comparison.setPromotionFeeRatio(promotionFeeRatio);
|
||||
comparison.setRefundRate(refundRate);
|
||||
comparisons.add(comparison);
|
||||
}
|
||||
|
||||
// 按销售额降序排序
|
||||
comparisons.sort(Comparator.comparing(CompanyOverviewVO.ShopComparison::getSalesAmount).reversed());
|
||||
return comparisons;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算店铺利润(扣除退款)
|
||||
*/
|
||||
private BigDecimal calculateShopProfit(List<OrderPO> orders, Long refundStatusId) {
|
||||
BigDecimal totalSales = orders.stream()
|
||||
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
BigDecimal refundAmount = orders.stream()
|
||||
.filter(order -> refundStatusId != null && refundStatusId.equals(order.getStatusId()))
|
||||
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
BigDecimal totalCost = calculateShopTotalCost(orders);
|
||||
return totalSales.subtract(totalCost).subtract(refundAmount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算店铺总成本(订单成本)
|
||||
*/
|
||||
private BigDecimal calculateShopTotalCost(List<OrderPO> orders) {
|
||||
return orders.stream()
|
||||
.map(order -> {
|
||||
BigDecimal productCost = order.getProductCost() != null ? order.getProductCost() : BigDecimal.ZERO;
|
||||
BigDecimal shippingCost = order.getShippingCost() != null ? order.getShippingCost() : BigDecimal.ZERO;
|
||||
BigDecimal otherCost = order.getOtherCost() != null ? order.getOtherCost() : BigDecimal.ZERO;
|
||||
Integer quantity = order.getQuantity() != null ? order.getQuantity() : 1;
|
||||
return productCost.add(shippingCost).add(otherCost).multiply(new BigDecimal(quantity));
|
||||
})
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算店铺总成本(推广费+刷单费)
|
||||
*/
|
||||
private BigDecimal calculateShopTotalCost(List<PromotionFeePO> promotionFees, List<BrushOrderPO> brushOrders) {
|
||||
BigDecimal promotionFee = promotionFees.stream()
|
||||
.map(fee -> fee.getFeeAmount() != null ? fee.getFeeAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
BigDecimal brushFee = brushOrders.stream()
|
||||
.map(brush -> brush.getBrushAmount() != null ? brush.getBrushAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
return promotionFee.add(brushFee);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算店铺ROI
|
||||
*/
|
||||
private BigDecimal calculateShopROI(BigDecimal profit, BigDecimal totalCost) {
|
||||
if (totalCost.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
return profit.divide(totalCost, 4, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算店铺净利(税后)
|
||||
*/
|
||||
private BigDecimal calculateShopNetProfit(BigDecimal profitBeforeTax) {
|
||||
BigDecimal taxAmount = profitBeforeTax.multiply(TAX_RATE);
|
||||
return profitBeforeTax.subtract(taxAmount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算汇总ROI
|
||||
*/
|
||||
private BigDecimal calculateTotalROI(List<OrderPO> orders, List<PromotionFeePO> promotionFees,
|
||||
List<BrushOrderPO> brushOrders) {
|
||||
BigDecimal totalProfit = calculateTotalProfit(orders);
|
||||
BigDecimal totalPromotionFee = promotionFees.stream()
|
||||
.map(fee -> fee.getFeeAmount() != null ? fee.getFeeAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
BigDecimal totalBrushFee = brushOrders.stream()
|
||||
.map(brush -> brush.getBrushAmount() != null ? brush.getBrushAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
BigDecimal totalCost = totalPromotionFee.add(totalBrushFee);
|
||||
return calculateShopROI(totalProfit, totalCost);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取退款状态ID
|
||||
*/
|
||||
private Long getRefundStatusId() {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
LambdaQueryWrapper<OrderStatusPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(OrderStatusPO::getCompanyId, companyId)
|
||||
.eq(OrderStatusPO::getStatusName, "已退款")
|
||||
.last("LIMIT 1");
|
||||
OrderStatusPO status = orderStatusService.getOne(wrapper);
|
||||
return status != null ? status.getId() : null;
|
||||
}
|
||||
}
|
||||
|
||||
+228
-162
@@ -5,8 +5,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.commons.csv.CSVFormat;
|
||||
import org.apache.commons.csv.CSVParser;
|
||||
import org.apache.commons.csv.CSVRecord;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
@@ -151,8 +149,6 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
}
|
||||
}
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ImportTaskProcessorServiceImpl.class);
|
||||
|
||||
private final ImportTaskService importTaskService;
|
||||
private final ProductSpecService productSpecService;
|
||||
private final OrderMapper orderMapper;
|
||||
@@ -194,10 +190,9 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
@Transactional
|
||||
public void processImportTask(Long taskId) {
|
||||
ImportTaskPO task = importTaskService.getById(taskId);
|
||||
if (task == null) {
|
||||
logger.error("导入任务不存在,taskId: {}", taskId);
|
||||
return;
|
||||
}
|
||||
if (task == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 更新任务状态为处理中
|
||||
updateTaskStatus(taskId, "processing", null, 0, 0, 0);
|
||||
@@ -211,7 +206,6 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
processOrderImport(task);
|
||||
} else if ("product".equals(task.getType())) {
|
||||
// 商品导入逻辑待实现
|
||||
logger.warn("商品导入功能暂未实现,taskId: {}", taskId);
|
||||
updateTaskStatus(taskId, "failed", "商品导入功能暂未实现", 0, 0, 0);
|
||||
} else {
|
||||
throw new BusinessException("不支持的导入类型: " + task.getType());
|
||||
@@ -222,7 +216,6 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
notifyTaskProgress(task.getCreateBy(), convertToVO(completedTask));
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("处理导入任务失败,taskId: {}", taskId, e);
|
||||
updateTaskStatus(taskId, "failed", "处理失败: " + e.getMessage(), 0, 0, 0);
|
||||
ImportTaskPO failedTask = importTaskService.getById(taskId);
|
||||
notifyTaskProgress(task.getCreateBy(), convertToVO(failedTask));
|
||||
@@ -280,7 +273,6 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
|
||||
// 尝试多种编码读取CSV文件(常见的中文编码)
|
||||
java.nio.charset.Charset charset = detectFileEncoding(csvFile);
|
||||
logger.info("检测到CSV文件编码: {}", charset);
|
||||
|
||||
try (java.io.InputStreamReader reader = new java.io.InputStreamReader(
|
||||
new java.io.FileInputStream(csvFile), charset);
|
||||
@@ -291,11 +283,6 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
.setTrim(true) // 自动去除表头和值的前后空格
|
||||
.build())) {
|
||||
|
||||
// 记录CSV表头,用于调试
|
||||
Map<String, Integer> headerMap = csvParser.getHeaderMap();
|
||||
logger.info("CSV表头信息: {}", headerMap);
|
||||
logger.info("字段映射信息: {}", fieldMapping);
|
||||
logger.info("状态映射信息: {}", statusMapping);
|
||||
|
||||
List<CSVRecord> records = csvParser.getRecords();
|
||||
totalCount = records.size();
|
||||
@@ -312,7 +299,7 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
CreateOrderDTO orderDTO = parseOrderFromCSV(record, fieldMapping, statusMapping, task.getShopId(), defaultStatusId, companyId, task.getCreateBy());
|
||||
|
||||
// 创建订单(复用OrderService.createOrder的业务逻辑,但不依赖CurrentUserContext)
|
||||
createOrderWithoutContext(orderDTO, companyId, task.getCreateBy());
|
||||
createOrderWithoutContext(orderDTO, companyId, task.getCreateBy(), task.getId());
|
||||
successCount++;
|
||||
|
||||
// 每处理10条记录通知一次进度
|
||||
@@ -324,9 +311,8 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
|
||||
} catch (Exception e) {
|
||||
failCount++;
|
||||
String errorMsg = String.format("第%d行处理失败: %s", rowNumber, e.getMessage());
|
||||
errorMessages.append(errorMsg).append("; ");
|
||||
logger.error("处理订单导入第{}行失败", rowNumber, e);
|
||||
String errorMsg = String.format("第%d行:%s", rowNumber, e.getMessage());
|
||||
errorMessages.append(errorMsg).append(System.lineSeparator());
|
||||
|
||||
// 更新失败计数
|
||||
updateTaskStatus(task.getId(), "processing", null, totalCount, successCount, failCount);
|
||||
@@ -358,61 +344,83 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
// "statusMapping": [...]
|
||||
// }
|
||||
// 使用JsonNode先解析,然后手动构建对象,避免内部类反序列化问题
|
||||
com.fasterxml.jackson.databind.JsonNode rootNode = objectMapper.readTree(mappingJson);
|
||||
com.fasterxml.jackson.databind.JsonNode rootNode;
|
||||
try {
|
||||
rootNode = objectMapper.readTree(mappingJson);
|
||||
} catch (com.fasterxml.jackson.core.JsonProcessingException e) {
|
||||
throw new BusinessException("解析字段映射失败: JSON格式错误 - " + e.getMessage() + ",JSON内容: " + mappingJson);
|
||||
}
|
||||
|
||||
if (!rootNode.isObject()) {
|
||||
throw new BusinessException("解析字段映射失败: 映射配置必须是JSON对象,当前类型: " + rootNode.getNodeType());
|
||||
}
|
||||
|
||||
MappingConfig config = new MappingConfig();
|
||||
|
||||
// 解析字段映射
|
||||
com.fasterxml.jackson.databind.JsonNode fieldMappingNode = rootNode.get("fieldMapping");
|
||||
if (fieldMappingNode != null && fieldMappingNode.isArray()) {
|
||||
List<MappingField> mappingFields = new java.util.ArrayList<>();
|
||||
for (com.fasterxml.jackson.databind.JsonNode fieldNode : fieldMappingNode) {
|
||||
MappingField field = new MappingField();
|
||||
if (fieldNode.has("required")) {
|
||||
field.setRequired(fieldNode.get("required").asBoolean());
|
||||
}
|
||||
if (fieldNode.has("fieldName")) {
|
||||
field.setFieldName(fieldNode.get("fieldName").asText());
|
||||
}
|
||||
if (fieldNode.has("fieldLabel")) {
|
||||
field.setFieldLabel(fieldNode.get("fieldLabel").asText());
|
||||
}
|
||||
if (fieldNode.has("fileFieldName")) {
|
||||
field.setFileFieldName(fieldNode.get("fileFieldName").asText());
|
||||
}
|
||||
mappingFields.add(field);
|
||||
}
|
||||
config.setFieldMapping(mappingFields);
|
||||
if (fieldMappingNode == null) {
|
||||
throw new BusinessException("解析字段映射失败: 缺少fieldMapping字段");
|
||||
}
|
||||
|
||||
// 解析状态映射
|
||||
if (!fieldMappingNode.isArray()) {
|
||||
throw new BusinessException("解析字段映射失败: fieldMapping必须是数组类型,当前类型: " + fieldMappingNode.getNodeType());
|
||||
}
|
||||
|
||||
List<MappingField> mappingFields = new java.util.ArrayList<>();
|
||||
for (com.fasterxml.jackson.databind.JsonNode fieldNode : fieldMappingNode) {
|
||||
if (!fieldNode.isObject()) {
|
||||
continue;
|
||||
}
|
||||
MappingField field = new MappingField();
|
||||
if (fieldNode.has("required")) {
|
||||
field.setRequired(fieldNode.get("required").asBoolean());
|
||||
}
|
||||
if (fieldNode.has("fieldName")) {
|
||||
field.setFieldName(fieldNode.get("fieldName").asText());
|
||||
}
|
||||
if (fieldNode.has("fieldLabel")) {
|
||||
field.setFieldLabel(fieldNode.get("fieldLabel").asText());
|
||||
}
|
||||
if (fieldNode.has("fileFieldName")) {
|
||||
field.setFileFieldName(fieldNode.get("fileFieldName").asText());
|
||||
}
|
||||
mappingFields.add(field);
|
||||
}
|
||||
config.setFieldMapping(mappingFields);
|
||||
|
||||
// 解析状态映射(可选)
|
||||
com.fasterxml.jackson.databind.JsonNode statusMappingNode = rootNode.get("statusMapping");
|
||||
if (statusMappingNode != null && statusMappingNode.isArray()) {
|
||||
List<StatusMapping> statusMappings = new java.util.ArrayList<>();
|
||||
for (com.fasterxml.jackson.databind.JsonNode statusNode : statusMappingNode) {
|
||||
StatusMapping statusMapping = new StatusMapping();
|
||||
if (statusNode.has("csvStatus")) {
|
||||
statusMapping.setCsvStatus(statusNode.get("csvStatus").asText());
|
||||
if (statusMappingNode != null) {
|
||||
if (statusMappingNode.isArray()) {
|
||||
List<StatusMapping> statusMappings = new java.util.ArrayList<>();
|
||||
for (com.fasterxml.jackson.databind.JsonNode statusNode : statusMappingNode) {
|
||||
if (!statusNode.isObject()) {
|
||||
continue;
|
||||
}
|
||||
StatusMapping statusMapping = new StatusMapping();
|
||||
if (statusNode.has("csvStatus")) {
|
||||
statusMapping.setCsvStatus(statusNode.get("csvStatus").asText());
|
||||
}
|
||||
if (statusNode.has("mappedStatusId")) {
|
||||
statusMapping.setMappedStatusId(statusNode.get("mappedStatusId").asLong());
|
||||
}
|
||||
statusMappings.add(statusMapping);
|
||||
}
|
||||
if (statusNode.has("mappedStatusId")) {
|
||||
statusMapping.setMappedStatusId(statusNode.get("mappedStatusId").asLong());
|
||||
}
|
||||
statusMappings.add(statusMapping);
|
||||
config.setStatusMapping(statusMappings);
|
||||
}
|
||||
config.setStatusMapping(statusMappings);
|
||||
}
|
||||
|
||||
if (config.getFieldMapping() == null || config.getFieldMapping().isEmpty()) {
|
||||
throw new BusinessException("字段映射不能为空");
|
||||
throw new BusinessException("解析字段映射失败: 字段映射不能为空");
|
||||
}
|
||||
|
||||
return config;
|
||||
} catch (com.fasterxml.jackson.core.JsonProcessingException e) {
|
||||
logger.error("解析映射配置失败(JSON格式错误),JSON: {}", mappingJson, e);
|
||||
throw new BusinessException("解析映射配置失败: JSON格式错误 - " + e.getMessage());
|
||||
} catch (BusinessException e) {
|
||||
// 业务异常直接抛出
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
logger.error("解析映射配置失败,JSON: {}", mappingJson, e);
|
||||
throw new BusinessException("解析映射配置失败: " + e.getMessage());
|
||||
throw new BusinessException("解析字段映射失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -446,14 +454,6 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
MappingField platformOrderNoField = fieldMapping.get("platform_order_no"); // 平台订单号
|
||||
MappingField orderDateField = fieldMapping.get("order_time"); // 下单时间
|
||||
|
||||
// 调试日志:记录字段映射
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("字段映射 - spec_code: {}, received_amount: {}, product_quantity: {}",
|
||||
specCodeField != null ? specCodeField.getFileFieldName() : null,
|
||||
receivedAmountField != null ? receivedAmountField.getFileFieldName() : null,
|
||||
productQuantityField != null ? productQuantityField.getFileFieldName() : null);
|
||||
}
|
||||
|
||||
// 必填字段验证
|
||||
String specCode = getValue(record, specCodeField);
|
||||
if (specCode == null || specCode.trim().isEmpty()) {
|
||||
@@ -508,18 +508,36 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
throw new BusinessException("商品数量不能为空");
|
||||
}
|
||||
|
||||
// 解析可选字段(先解析,用于后续创建商品和规格)
|
||||
String productName = getValue(record, linkProductNameField);
|
||||
productName = productName != null ? productName.trim() : null;
|
||||
// 解析可选字段(优先使用链接商品名称和链接规格名称)
|
||||
// 这些字段来自CSV中的 link_product_name 和 link_spec_name,用于创建商品和规格时的命名
|
||||
String linkProductName = getValue(record, linkProductNameField);
|
||||
// trim并转换空字符串为null
|
||||
if (linkProductName != null) {
|
||||
linkProductName = linkProductName.trim();
|
||||
if (linkProductName.isEmpty()) {
|
||||
linkProductName = null;
|
||||
}
|
||||
}
|
||||
|
||||
String productCode = getValue(record, productCodeField);
|
||||
productCode = productCode != null ? productCode.trim() : null;
|
||||
if (productCode != null) {
|
||||
productCode = productCode.trim();
|
||||
if (productCode.isEmpty()) {
|
||||
productCode = null;
|
||||
}
|
||||
}
|
||||
|
||||
String specName = getValue(record, linkSpecNameField);
|
||||
specName = specName != null ? specName.trim() : null;
|
||||
String linkSpecName = getValue(record, linkSpecNameField);
|
||||
if (linkSpecName != null) {
|
||||
linkSpecName = linkSpecName.trim();
|
||||
if (linkSpecName.isEmpty()) {
|
||||
linkSpecName = null;
|
||||
}
|
||||
}
|
||||
|
||||
// 首先通过规格编码查找商品规格
|
||||
ProductSpecPO productSpec = findProductSpecBySpecCode(specCode.trim(), companyId);
|
||||
boolean isNewSpecCreated = false; // 标记是否创建了新规格
|
||||
|
||||
// 如果找不到规格,则尝试通过商品编码或商品名称查找商品,然后创建规格
|
||||
if (productSpec == null) {
|
||||
@@ -528,63 +546,61 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
// 优先使用商品编码查找商品
|
||||
if (productCode != null && !productCode.isEmpty()) {
|
||||
product = findProductByProductCode(productCode, companyId);
|
||||
if (product != null) {
|
||||
logger.info("未找到规格编码 '{}',但通过商品编码 '{}' 找到了商品 '{}' (ID: {})",
|
||||
specCode, productCode, product.getName(), product.getId());
|
||||
}
|
||||
}
|
||||
|
||||
// 如果商品编码查找失败,使用商品名称精准查找商品
|
||||
if (product == null && productName != null && !productName.isEmpty()) {
|
||||
product = findProductByName(productName, companyId);
|
||||
if (product != null) {
|
||||
logger.info("未找到规格编码 '{}',但通过商品名称 '{}' 找到了商品 (ID: {})",
|
||||
specCode, productName, product.getId());
|
||||
}
|
||||
// 如果商品编码查找失败,使用链接商品名称精准查找商品
|
||||
if (product == null && linkProductName != null && !linkProductName.isEmpty()) {
|
||||
product = findProductByName(linkProductName, companyId);
|
||||
}
|
||||
|
||||
// 如果找到了商品,创建规格
|
||||
if (product != null) {
|
||||
if (specName == null || specName.isEmpty()) {
|
||||
throw new BusinessException("未找到规格编码对应的商品规格: " + specCode +
|
||||
",且未提供规格名称,无法创建规格");
|
||||
}
|
||||
logger.info("为商品 '{}' (ID: {}) 创建规格 '{}' (编码: {})",
|
||||
product.getName(), product.getId(), specName, specCode);
|
||||
productSpec = createSpecForProduct(companyId, product.getId(), specName, specCode.trim(), createBy);
|
||||
// 优先使用链接规格名称,如果没有则使用"未知规格"
|
||||
String finalSpecName = (linkSpecName != null && !linkSpecName.isEmpty()) ? linkSpecName : "未知规格";
|
||||
productSpec = createSpecForProduct(companyId, product.getId(), finalSpecName, specCode.trim(), createBy);
|
||||
isNewSpecCreated = true;
|
||||
}
|
||||
// 如果没有找到商品,但有商品名称和规格名称,则自动创建商品和规格
|
||||
else if (productName != null && !productName.isEmpty() &&
|
||||
specName != null && !specName.isEmpty()) {
|
||||
logger.info("未找到规格编码 '{}',也未找到商品,将自动创建商品 '{}' 和规格 '{}'",
|
||||
specCode, productName, specName);
|
||||
productSpec = createProductAndSpecIfNotExists(companyId, productName, productCode, specName, specCode.trim(), createBy);
|
||||
} else {
|
||||
throw new BusinessException("未找到规格编码对应的商品规格: " + specCode +
|
||||
(productCode == null || productCode.isEmpty() ? "" : ",商品编码 '" + productCode + "' 未找到商品") +
|
||||
(productName == null || productName.isEmpty() ? ",且未提供商品名称" : "") +
|
||||
(specName == null || specName.isEmpty() ? ",且未提供规格名称" : ""));
|
||||
// 如果没有找到商品,则自动创建商品和规格
|
||||
else {
|
||||
// 优先使用链接商品名称,如果没有则使用"未知商品"
|
||||
String finalProductName = (linkProductName != null && !linkProductName.isEmpty()) ? linkProductName : "未知商品";
|
||||
// 优先使用链接规格名称,如果没有则使用"未知规格"
|
||||
String finalSpecName = (linkSpecName != null && !linkSpecName.isEmpty()) ? linkSpecName : "未知规格";
|
||||
productSpec = createProductAndSpecIfNotExists(companyId, finalProductName, productCode, finalSpecName, specCode.trim(), createBy);
|
||||
isNewSpecCreated = true;
|
||||
}
|
||||
}
|
||||
|
||||
orderDTO.setProductId(productSpec.getProductId());
|
||||
orderDTO.setProductSpecId(productSpec.getId());
|
||||
orderDTO.setCostPrice(productSpec.getCostPrice());
|
||||
// 设置单件成本(从商品规格中获取,作为下单时快照)
|
||||
orderDTO.setProductCost(productSpec.getProductCost() != null ? productSpec.getProductCost() : BigDecimal.ZERO);
|
||||
orderDTO.setShippingCost(productSpec.getShippingCost() != null ? productSpec.getShippingCost() : BigDecimal.ZERO);
|
||||
orderDTO.setOtherCost(productSpec.getOtherCost() != null ? productSpec.getOtherCost() : BigDecimal.ZERO);
|
||||
|
||||
// 设置链接商品名称和链接规格名称
|
||||
if (productName != null && !productName.isEmpty()) {
|
||||
orderDTO.setLinkProductName(productName);
|
||||
// 优先使用CSV中的链接商品名称和链接规格名称,如果没有则使用创建的商品/规格名称
|
||||
if (linkProductName != null && !linkProductName.isEmpty()) {
|
||||
orderDTO.setLinkProductName(linkProductName);
|
||||
} else {
|
||||
// 如果CSV中没有商品名称,从商品规格关联的商品中获取
|
||||
ProductPO product = productMapper.selectById(productSpec.getProductId());
|
||||
orderDTO.setLinkProductName(product != null ? product.getName() : "");
|
||||
orderDTO.setLinkProductName(product != null ? product.getName() : "未知商品");
|
||||
}
|
||||
|
||||
if (specName != null && !specName.isEmpty()) {
|
||||
orderDTO.setLinkSpecName(specName);
|
||||
// 优先使用CSV中的链接规格名称,如果没有则使用规格的名称
|
||||
if (linkSpecName != null && !linkSpecName.isEmpty()) {
|
||||
orderDTO.setLinkSpecName(linkSpecName);
|
||||
} else {
|
||||
orderDTO.setLinkSpecName(productSpec.getName());
|
||||
}
|
||||
|
||||
// 如果创建了新规格,订单的确认状态设为0(需要用户手动确认)
|
||||
if (isNewSpecCreated) {
|
||||
orderDTO.setConfirm(0);
|
||||
} else {
|
||||
// 如果找到已存在的规格,订单的确认状态设为1(已确认)
|
||||
orderDTO.setConfirm(1);
|
||||
}
|
||||
|
||||
String platformOrderNo = getValue(record, platformOrderNoField);
|
||||
if (platformOrderNo != null && !platformOrderNo.trim().isEmpty()) {
|
||||
@@ -606,25 +622,20 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
// 首先尝试通过状态映射转换(statusMapping中存储的是状态ID)
|
||||
if (statusMapping != null && !statusMapping.isEmpty()) {
|
||||
statusId = statusMapping.get(trimmedStatus);
|
||||
if (statusId != null) {
|
||||
logger.debug("通过状态映射转换: '{}' -> ID: {}", trimmedStatus, statusId);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果状态映射没有找到,尝试直接通过状态名称查找
|
||||
if (statusId == null) {
|
||||
statusId = findOrderStatusIdByName(companyId, trimmedStatus);
|
||||
if (statusId != null) {
|
||||
logger.debug("通过状态名称匹配订单状态: '{}' -> ID: {}", trimmedStatus, statusId);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果找到了有效的状态,则使用;否则使用默认状态
|
||||
// 如果找到了有效的状态,则使用;否则自动创建新状态
|
||||
if (statusId != null) {
|
||||
orderDTO.setStatusId(statusId);
|
||||
} else {
|
||||
logger.warn("无法识别订单状态: '{}',使用默认状态ID: {}", trimmedStatus, defaultStatusId);
|
||||
orderDTO.setStatusId(defaultStatusId);
|
||||
// 用户没有做映射,且数据库中该公司没有当前状态名称,自动创建新的订单状态
|
||||
statusId = createOrderStatusIfNotExists(companyId, trimmedStatus, createBy);
|
||||
orderDTO.setStatusId(statusId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -634,14 +645,11 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
LocalDateTime orderTime = parseDateTime(orderDateStr.trim());
|
||||
if (orderTime != null) {
|
||||
orderDTO.setOrderTime(orderTime);
|
||||
logger.info("成功解析下单时间: '{}' -> {}", orderDateStr.trim(), orderTime);
|
||||
} else {
|
||||
logger.warn("无法解析下单时间: '{}' (可能格式不支持),使用当前时间", orderDateStr);
|
||||
orderDTO.setOrderTime(LocalDateTime.now());
|
||||
}
|
||||
} else {
|
||||
// 如果没有提供下单时间,使用当前时间
|
||||
logger.debug("未提供下单时间字段,使用当前时间");
|
||||
orderDTO.setOrderTime(LocalDateTime.now());
|
||||
}
|
||||
|
||||
@@ -708,29 +716,17 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
try {
|
||||
if (pattern.hasTime) {
|
||||
// 包含时间部分,直接解析为LocalDateTime
|
||||
LocalDateTime result = LocalDateTime.parse(dateTimeStr, pattern.formatter);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("成功使用格式 '{}' 解析时间 '{}' -> {}", pattern.pattern, dateTimeStr, result);
|
||||
}
|
||||
return result;
|
||||
return LocalDateTime.parse(dateTimeStr, pattern.formatter);
|
||||
} else {
|
||||
// 只有日期部分,解析为LocalDate后转换为LocalDateTime(时间为00:00:00)
|
||||
LocalDateTime result = java.time.LocalDate.parse(dateTimeStr, pattern.formatter).atStartOfDay();
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("成功使用格式 '{}' 解析日期 '{}' -> {}", pattern.pattern, dateTimeStr, result);
|
||||
}
|
||||
return result;
|
||||
return java.time.LocalDate.parse(dateTimeStr, pattern.formatter).atStartOfDay();
|
||||
}
|
||||
} catch (DateTimeParseException e) {
|
||||
// 当前格式不匹配,尝试下一个(trace级别,避免太多日志)
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("尝试使用格式 '{}' 解析时间 '{}' 失败: {}", pattern.pattern, dateTimeStr, e.getMessage());
|
||||
}
|
||||
// 当前格式不匹配,尝试下一个
|
||||
}
|
||||
}
|
||||
|
||||
// 所有格式都失败
|
||||
logger.warn("无法解析日期时间字符串: '{}',支持的格式包括: yyyy/MM/dd HH:mm:ss, yyyy-MM-dd HH:mm:ss 等", dateTimeStr);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -743,7 +739,6 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
*/
|
||||
private String getValue(CSVRecord record, MappingField mappingField) {
|
||||
if (mappingField == null || mappingField.getFileFieldName() == null || mappingField.getFileFieldName().trim().isEmpty()) {
|
||||
logger.debug("映射字段为空或文件字段名为空,无法获取值");
|
||||
return null;
|
||||
}
|
||||
return getValue(record, mappingField.getFileFieldName());
|
||||
@@ -758,31 +753,67 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
*/
|
||||
private String getValue(CSVRecord record, String header) {
|
||||
if (header == null || header.trim().isEmpty()) {
|
||||
logger.debug("表头名称为空,无法获取值");
|
||||
return null;
|
||||
}
|
||||
|
||||
String trimmedHeader = header.trim();
|
||||
Map<String, Integer> headerMap = record.getParser().getHeaderMap();
|
||||
|
||||
// 首先尝试精确匹配(考虑CSV解析器已经设置了setTrim(true))
|
||||
try {
|
||||
String trimmedHeader = header.trim();
|
||||
String value = record.get(trimmedHeader);
|
||||
logger.debug("从表头 '{}' 获取值: '{}'", trimmedHeader, value);
|
||||
return value;
|
||||
return record.get(trimmedHeader);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// 表头不存在,尝试忽略大小写匹配
|
||||
Map<String, Integer> headerMap = record.getParser().getHeaderMap();
|
||||
// 精确匹配失败,尝试忽略大小写匹配
|
||||
String matchedHeader = headerMap.keySet().stream()
|
||||
.filter(h -> h.trim().equalsIgnoreCase(header.trim()))
|
||||
.filter(h -> h.trim().equalsIgnoreCase(trimmedHeader))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (matchedHeader != null) {
|
||||
return record.get(matchedHeader);
|
||||
}
|
||||
|
||||
// 如果还是找不到,尝试包含匹配(处理可能的空格或特殊字符)
|
||||
matchedHeader = headerMap.keySet().stream()
|
||||
.filter(h -> h.trim().equalsIgnoreCase(trimmedHeader) ||
|
||||
h.trim().replaceAll("\\s+", "").equalsIgnoreCase(trimmedHeader.replaceAll("\\s+", "")))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (matchedHeader != null) {
|
||||
return record.get(matchedHeader);
|
||||
}
|
||||
|
||||
// 处理BOM字符:尝试去除BOM后匹配(BOM字符是\uFEFF)
|
||||
matchedHeader = headerMap.keySet().stream()
|
||||
.filter(h -> removeBOM(h).trim().equalsIgnoreCase(trimmedHeader))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (matchedHeader != null) {
|
||||
logger.debug("表头 '{}' 不存在,但找到忽略大小写的匹配: '{}'", header, matchedHeader);
|
||||
return record.get(matchedHeader);
|
||||
}
|
||||
|
||||
logger.warn("表头 '{}' 不存在,可用的表头: {}", header, headerMap.keySet());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 去除字符串开头的BOM字符
|
||||
*
|
||||
* @param s 字符串
|
||||
* @return 去除BOM后的字符串
|
||||
*/
|
||||
private String removeBOM(String s) {
|
||||
if (s == null || s.isEmpty()) {
|
||||
return s;
|
||||
}
|
||||
// BOM字符是 \uFEFF
|
||||
if (s.charAt(0) == '\uFEFF') {
|
||||
return s.substring(1);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过规格编码查找商品规格
|
||||
@@ -872,10 +903,11 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
productSpec.setProductId(productId);
|
||||
productSpec.setName(specName);
|
||||
productSpec.setSpecCode(specCode);
|
||||
productSpec.setCostPrice(BigDecimal.ZERO); // 默认成本价为0,后续可以手动更新
|
||||
productSpec.setProductCost(BigDecimal.ZERO); // 默认商品成本为0,后续可以手动更新
|
||||
productSpec.setShippingCost(BigDecimal.ZERO); // 默认运费成本为0
|
||||
productSpec.setOtherCost(BigDecimal.ZERO); // 默认其他成本为0
|
||||
productSpec.setCreateBy(createBy);
|
||||
productSpecService.save(productSpec);
|
||||
logger.info("为商品 (ID: {}) 创建规格: {} (编码: {}, ID: {})", productId, specName, specCode, productSpec.getId());
|
||||
|
||||
return productSpec;
|
||||
}
|
||||
@@ -916,7 +948,6 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
// 在检查期间商品被创建了,重新查询
|
||||
product = productMapper.selectOne(productWrapper);
|
||||
productId = product.getId();
|
||||
logger.debug("商品在检查期间被创建: {} (ID: {})", productName, productId);
|
||||
} else {
|
||||
// 创建新商品(复用ProductService.createProduct的逻辑)
|
||||
product = new ProductPO();
|
||||
@@ -936,12 +967,9 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
product.setCreateBy(createBy);
|
||||
productMapper.insert(product);
|
||||
productId = product.getId();
|
||||
logger.info("自动创建商品: {} (ID: {})" + (productCode != null && !productCode.isEmpty() ? ", 商品编码: " + productCode : ""),
|
||||
productName, productId);
|
||||
}
|
||||
} else {
|
||||
productId = product.getId();
|
||||
logger.debug("商品已存在: {} (ID: {})", productName, productId);
|
||||
}
|
||||
|
||||
// 2. 创建商品规格(复用ProductSpecService.createProductSpec的逻辑)
|
||||
@@ -954,9 +982,10 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
* @param createOrderDTO 创建订单DTO
|
||||
* @param companyId 公司ID
|
||||
* @param createBy 创建人ID
|
||||
* @param importTaskId 导入任务ID(可选,如果为null则表示手动创建)
|
||||
* @return 订单VO
|
||||
*/
|
||||
private OrderVO createOrderWithoutContext(CreateOrderDTO createOrderDTO, Long companyId, Long createBy) {
|
||||
private OrderVO createOrderWithoutContext(CreateOrderDTO createOrderDTO, Long companyId, Long createBy, Long importTaskId) {
|
||||
// 复用OrderService.createOrder的验证逻辑
|
||||
|
||||
// 验证店铺是否存在且属于当前公司
|
||||
@@ -1007,10 +1036,17 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
order.setLinkSpecName(createOrderDTO.getLinkSpecName());
|
||||
order.setQuantity(createOrderDTO.getQuantity());
|
||||
order.setUnitPrice(createOrderDTO.getUnitPrice());
|
||||
order.setCostPrice(createOrderDTO.getCostPrice());
|
||||
order.setProductCost(createOrderDTO.getProductCost());
|
||||
order.setShippingCost(createOrderDTO.getShippingCost());
|
||||
order.setOtherCost(createOrderDTO.getOtherCost());
|
||||
// 备注不复制,订单导入时不设置备注字段
|
||||
order.setReceivedAmount(createOrderDTO.getReceivedAmount());
|
||||
order.setOrderTime(createOrderDTO.getOrderTime());
|
||||
order.setCreateBy(createBy);
|
||||
// 设置导入任务ID和确认状态
|
||||
order.setImportTaskId(importTaskId);
|
||||
// 使用DTO中的确认状态(如果DTO中指定了值则使用指定值,否则默认为1)
|
||||
order.setConfirm(createOrderDTO.getConfirm() != null ? createOrderDTO.getConfirm() : 1);
|
||||
|
||||
// 保存订单
|
||||
orderMapper.insert(order);
|
||||
@@ -1058,9 +1094,6 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
relation.setSortOrder(0); // 默认排序为0
|
||||
relation.setCreateBy(createBy);
|
||||
shopProductRelationMapper.insert(relation);
|
||||
logger.info("创建店铺商品关联: 店铺ID={}, 商品ID={}", shopId, productId);
|
||||
} else {
|
||||
logger.debug("店铺商品关联已存在: 店铺ID={}, 商品ID={}", shopId, productId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1105,7 +1138,7 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
try {
|
||||
sseNotificationService.sendTaskProgress(userId, taskVO);
|
||||
} catch (Exception e) {
|
||||
logger.warn("发送任务进度通知失败,userId: {}, taskId: {}", userId, taskVO != null ? taskVO.getId() : null, e);
|
||||
// 静默处理通知失败
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1152,17 +1185,15 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
if (content.contains("商家") || content.contains("编码") ||
|
||||
content.contains("商品") || content.contains("订单") ||
|
||||
content.contains("规格") || content.contains("金额")) {
|
||||
logger.debug("检测到编码 {} 可能正确,内容预览: {}", charset, content.substring(0, Math.min(100, content.length())));
|
||||
return charset;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.debug("尝试编码 {} 失败: {}", charset, e.getMessage());
|
||||
// 忽略编码检测错误
|
||||
}
|
||||
}
|
||||
|
||||
// 默认返回GBK(中文CSV文件最常用)
|
||||
logger.warn("无法确定文件编码,使用默认GBK");
|
||||
return java.nio.charset.Charset.forName("GBK");
|
||||
}
|
||||
|
||||
@@ -1188,7 +1219,6 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
.last("LIMIT 1");
|
||||
OrderStatusPO firstStatus = orderStatusService.getOne(wrapper);
|
||||
if (firstStatus != null) {
|
||||
logger.info("未找到'未知状态',使用第一个状态: {} (ID: {})", firstStatus.getStatusName(), firstStatus.getId());
|
||||
return firstStatus.getId();
|
||||
}
|
||||
|
||||
@@ -1213,5 +1243,41 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
OrderStatusPO status = orderStatusService.getOne(wrapper);
|
||||
return status != null ? status.getId() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果订单状态不存在,则自动创建(不依赖CurrentUserContext)
|
||||
*
|
||||
* @param companyId 公司ID
|
||||
* @param statusName 状态名称
|
||||
* @param createBy 创建人ID
|
||||
* @return 订单状态ID
|
||||
*/
|
||||
private Long createOrderStatusIfNotExists(Long companyId, String statusName, Long createBy) {
|
||||
if (statusName == null || statusName.trim().isEmpty()) {
|
||||
throw new BusinessException("订单状态名称不能为空");
|
||||
}
|
||||
|
||||
String trimmedStatusName = statusName.trim();
|
||||
|
||||
// 再次检查状态是否已存在(避免并发创建)
|
||||
Long existingStatusId = findOrderStatusIdByName(companyId, trimmedStatusName);
|
||||
if (existingStatusId != null) {
|
||||
return existingStatusId;
|
||||
}
|
||||
|
||||
// 创建新的订单状态
|
||||
OrderStatusPO orderStatus = new OrderStatusPO();
|
||||
orderStatus.setCompanyId(companyId);
|
||||
orderStatus.setStatusName(trimmedStatusName);
|
||||
orderStatus.setDescription("自动创建的状态");
|
||||
orderStatus.setSortOrder(0);
|
||||
orderStatus.setAutoStatistics(0); // 自动参与统计字段设置为否(0)
|
||||
orderStatus.setCreateBy(createBy);
|
||||
|
||||
// 保存订单状态
|
||||
orderStatusService.save(orderStatus);
|
||||
|
||||
return orderStatus.getId();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+13
-1
@@ -116,10 +116,16 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
|
||||
order.setLinkSpecName(createOrderDTO.getLinkSpecName());
|
||||
order.setQuantity(createOrderDTO.getQuantity());
|
||||
order.setUnitPrice(createOrderDTO.getUnitPrice());
|
||||
order.setCostPrice(createOrderDTO.getCostPrice());
|
||||
order.setProductCost(createOrderDTO.getProductCost());
|
||||
order.setShippingCost(createOrderDTO.getShippingCost());
|
||||
order.setOtherCost(createOrderDTO.getOtherCost());
|
||||
order.setRemark(createOrderDTO.getRemark());
|
||||
order.setReceivedAmount(createOrderDTO.getReceivedAmount());
|
||||
order.setOrderTime(createOrderDTO.getOrderTime());
|
||||
order.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
// 设置导入任务ID和确认状态(默认已确认)
|
||||
order.setImportTaskId(createOrderDTO.getImportTaskId());
|
||||
order.setConfirm(createOrderDTO.getConfirm() != null ? createOrderDTO.getConfirm() : 1);
|
||||
|
||||
// 保存订单
|
||||
this.save(order);
|
||||
@@ -240,6 +246,12 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
|
||||
if (filter.getEndOrderTime() != null) {
|
||||
wrapper.le(OrderPO::getOrderTime, filter.getEndOrderTime());
|
||||
}
|
||||
if (filter.getImportTaskId() != null) {
|
||||
wrapper.eq(OrderPO::getImportTaskId, filter.getImportTaskId());
|
||||
}
|
||||
if (filter.getConfirm() != null) {
|
||||
wrapper.eq(OrderPO::getConfirm, filter.getConfirm());
|
||||
}
|
||||
}
|
||||
|
||||
// 排序
|
||||
|
||||
+2
-2
@@ -58,8 +58,8 @@ public class OrderStatusServiceImpl extends ServiceImpl<OrderStatusMapper, Order
|
||||
if (orderStatus.getSortOrder() == null) {
|
||||
orderStatus.setSortOrder(0);
|
||||
}
|
||||
if (orderStatus.getIsDefaultStat() == null) {
|
||||
orderStatus.setIsDefaultStat(1);
|
||||
if (orderStatus.getAutoStatistics() == null) {
|
||||
orderStatus.setAutoStatistics(1);
|
||||
}
|
||||
|
||||
// 设置创建人ID
|
||||
|
||||
+8
-2
@@ -103,7 +103,10 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
|
||||
productSpec.setProductId(product.getId());
|
||||
productSpec.setName(specDTO.getName());
|
||||
productSpec.setSpecCode(specDTO.getSpecCode());
|
||||
productSpec.setCostPrice(specDTO.getCostPrice());
|
||||
productSpec.setProductCost(specDTO.getProductCost());
|
||||
productSpec.setShippingCost(specDTO.getShippingCost());
|
||||
productSpec.setOtherCost(specDTO.getOtherCost());
|
||||
productSpec.setRemark(specDTO.getRemark());
|
||||
productSpec.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
productSpecService.save(productSpec);
|
||||
@@ -211,7 +214,10 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
|
||||
productSpec.setId(specDTO.getId());
|
||||
productSpec.setName(specDTO.getName());
|
||||
productSpec.setSpecCode(specDTO.getSpecCode());
|
||||
productSpec.setCostPrice(specDTO.getCostPrice());
|
||||
productSpec.setProductCost(specDTO.getProductCost());
|
||||
productSpec.setShippingCost(specDTO.getShippingCost());
|
||||
productSpec.setOtherCost(specDTO.getOtherCost());
|
||||
productSpec.setRemark(specDTO.getRemark());
|
||||
productSpec.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
productSpecService.updateById(productSpec);
|
||||
|
||||
+11
-5
@@ -485,12 +485,15 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
|
||||
Map<LocalDate, List<OrderPO>> ordersByDate, List<LocalDate> dateList, List<OrderPO> allOrders) {
|
||||
ShopOverviewVO.DailyStatistics stats = new ShopOverviewVO.DailyStatistics();
|
||||
|
||||
// 计算总成本
|
||||
// 计算总成本(单件商品成本 + 单件运费成本 + 单件其他成本) * 数量
|
||||
BigDecimal total = allOrders.stream()
|
||||
.map(order -> {
|
||||
BigDecimal cost = order.getCostPrice() != null ? order.getCostPrice() : BigDecimal.ZERO;
|
||||
BigDecimal productCost = order.getProductCost() != null ? order.getProductCost() : BigDecimal.ZERO;
|
||||
BigDecimal shippingCost = order.getShippingCost() != null ? order.getShippingCost() : BigDecimal.ZERO;
|
||||
BigDecimal otherCost = order.getOtherCost() != null ? order.getOtherCost() : BigDecimal.ZERO;
|
||||
BigDecimal unitCost = productCost.add(shippingCost).add(otherCost);
|
||||
Integer quantity = order.getQuantity() != null ? order.getQuantity() : 0;
|
||||
return cost.multiply(BigDecimal.valueOf(quantity));
|
||||
return unitCost.multiply(BigDecimal.valueOf(quantity));
|
||||
})
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
stats.setTotal(total);
|
||||
@@ -503,9 +506,12 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
|
||||
List<OrderPO> dayOrders = ordersByDate.getOrDefault(date, List.of());
|
||||
BigDecimal dayCost = dayOrders.stream()
|
||||
.map(order -> {
|
||||
BigDecimal cost = order.getCostPrice() != null ? order.getCostPrice() : BigDecimal.ZERO;
|
||||
BigDecimal productCost = order.getProductCost() != null ? order.getProductCost() : BigDecimal.ZERO;
|
||||
BigDecimal shippingCost = order.getShippingCost() != null ? order.getShippingCost() : BigDecimal.ZERO;
|
||||
BigDecimal otherCost = order.getOtherCost() != null ? order.getOtherCost() : BigDecimal.ZERO;
|
||||
BigDecimal unitCost = productCost.add(shippingCost).add(otherCost);
|
||||
Integer quantity = order.getQuantity() != null ? order.getQuantity() : 0;
|
||||
return cost.multiply(BigDecimal.valueOf(quantity));
|
||||
return unitCost.multiply(BigDecimal.valueOf(quantity));
|
||||
})
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
dailyData.setValue(dayCost);
|
||||
|
||||
@@ -52,7 +52,10 @@ CREATE TABLE `ec_product_spec` (
|
||||
`product_id` BIGINT UNSIGNED NOT NULL COMMENT '商品ID',
|
||||
`name` VARCHAR(200) NOT NULL COMMENT '规格名称',
|
||||
`spec_code` VARCHAR(100) DEFAULT NULL COMMENT '规格编码',
|
||||
`cost_price` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '成本价',
|
||||
`product_cost` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '商品成本',
|
||||
`shipping_cost` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '运费成本',
|
||||
`other_cost` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '其他成本',
|
||||
`remark` VARCHAR(500) DEFAULT NULL 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',
|
||||
@@ -76,7 +79,7 @@ CREATE TABLE `ec_order_status` (
|
||||
`status_name` VARCHAR(100) NOT NULL COMMENT '状态名称(中文)',
|
||||
`description` VARCHAR(200) DEFAULT NULL COMMENT '状态描述',
|
||||
`sort_order` INT NOT NULL DEFAULT 0 COMMENT '排序',
|
||||
`is_default_stat` TINYINT NOT NULL DEFAULT 1 COMMENT '是否默认参与统计 0不参与 1参与',
|
||||
`auto_statistics` TINYINT NOT NULL DEFAULT 1 COMMENT '是否自动参与统计 0不参与 1参与',
|
||||
`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',
|
||||
@@ -85,7 +88,7 @@ CREATE TABLE `ec_order_status` (
|
||||
KEY `idx_company_id` (`company_id`),
|
||||
UNIQUE KEY `uk_company_status_name` (`company_id`, `status_name`),
|
||||
KEY `idx_sort_order` (`sort_order`),
|
||||
KEY `idx_is_default_stat` (`is_default_stat`),
|
||||
KEY `idx_auto_statistics` (`auto_statistics`),
|
||||
KEY `fk_ec_order_status_creator` (`create_by`),
|
||||
KEY `fk_ec_order_status_updater` (`update_by`),
|
||||
CONSTRAINT `fk_ec_order_status_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
@@ -107,7 +110,12 @@ CREATE TABLE `ec_order` (
|
||||
`received_amount` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '商家实收金额',
|
||||
`quantity` INT NOT NULL DEFAULT 1 COMMENT '数量',
|
||||
`unit_price` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '销售单价',
|
||||
`cost_price` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '成本价(下单时快照)',
|
||||
`product_cost` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '单件商品成本(下单时快照)',
|
||||
`shipping_cost` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '单件运费成本(下单时快照)',
|
||||
`other_cost` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '单件其他成本(下单时快照)',
|
||||
`remark` VARCHAR(500) DEFAULT NULL COMMENT '备注',
|
||||
`import_task_id` BIGINT UNSIGNED DEFAULT NULL COMMENT '导入任务ID',
|
||||
`confirm` TINYINT NOT NULL DEFAULT 1 COMMENT '确认(0-否 1-是)',
|
||||
`order_time` TIMESTAMP NOT NULL COMMENT '下单时间',
|
||||
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
@@ -119,6 +127,8 @@ CREATE TABLE `ec_order` (
|
||||
KEY `idx_platform_order_no` (`platform_order_no`),
|
||||
KEY `idx_product_id` (`product_id`),
|
||||
KEY `idx_product_spec_id` (`product_spec_id`),
|
||||
KEY `idx_import_task_id` (`import_task_id`),
|
||||
KEY `idx_confirm` (`confirm`),
|
||||
KEY `fk_ec_order_creator` (`create_by`),
|
||||
KEY `fk_ec_order_updater` (`update_by`),
|
||||
CONSTRAINT `fk_ec_order_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
@@ -126,6 +136,7 @@ CREATE TABLE `ec_order` (
|
||||
CONSTRAINT `fk_ec_order_product` FOREIGN KEY (`product_id`) REFERENCES `ec_product` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_product_spec` FOREIGN KEY (`product_spec_id`) REFERENCES `ec_product_spec` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_status` FOREIGN KEY (`status_id`) REFERENCES `ec_order_status` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_import_task` FOREIGN KEY (`import_task_id`) REFERENCES `ec_import_tasks` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-订单表(含商品明细)';
|
||||
@@ -282,3 +293,37 @@ CREATE TABLE `ec_shop_product_relation` (
|
||||
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='电商-店铺商品关联表';
|
||||
|
||||
-- 刷单记录表
|
||||
CREATE TABLE `ec_brush_order` (
|
||||
`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 DEFAULT NULL COMMENT '商品ID(可选)',
|
||||
`product_spec_id` BIGINT UNSIGNED DEFAULT NULL COMMENT '商品规格ID(可选)',
|
||||
`brush_amount` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '刷单金额',
|
||||
`brush_time` TIMESTAMP NOT NULL COMMENT '刷单时间',
|
||||
`platform_order_no` VARCHAR(100) DEFAULT NULL COMMENT '平台订单号(可选)',
|
||||
`quantity` INT DEFAULT 1 COMMENT '刷单数量',
|
||||
`remark` VARCHAR(500) DEFAULT NULL 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`),
|
||||
KEY `idx_company_id` (`company_id`),
|
||||
KEY `idx_shop_id` (`shop_id`),
|
||||
KEY `idx_product_id` (`product_id`),
|
||||
KEY `idx_product_spec_id` (`product_spec_id`),
|
||||
KEY `idx_brush_time` (`brush_time`),
|
||||
KEY `idx_platform_order_no` (`platform_order_no`),
|
||||
KEY `idx_company_shop_time` (`company_id`, `shop_id`, `brush_time`),
|
||||
KEY `fk_ec_brush_order_creator` (`create_by`),
|
||||
KEY `fk_ec_brush_order_updater` (`update_by`),
|
||||
CONSTRAINT `fk_ec_brush_order_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_brush_order_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_brush_order_product` FOREIGN KEY (`product_id`) REFERENCES `ec_product` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_brush_order_product_spec` FOREIGN KEY (`product_spec_id`) REFERENCES `ec_product_spec` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_brush_order_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_brush_order_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-刷单记录表';
|
||||
|
||||
Reference in New Issue
Block a user