重构电商模块

This commit is contained in:
ah--desktop
2025-09-19 23:54:16 +08:00
parent e0e31510d1
commit 543b6a0ad3
25 changed files with 295 additions and 715 deletions
@@ -51,6 +51,7 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
SecurityContextHolder.getContext().setAuthentication(authentication);
logger.debug("JWT认证成功,用户ID: " + userId);
logger.debug("JWT认证成功,公司ID: " + companyId);
logger.debug("JWT认证成功,Token: " + token);
}
} else {
logger.debug("JWT Token无效或为空");
@@ -1,12 +0,0 @@
package top.xyquan.ecomdmbbackend.modules.ec.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import top.xyquan.ecomdmbbackend.modules.ec.model.po.OrderItemPO;
/**
* 订单明细Mapper接口
*/
@Mapper
public interface OrderItemMapper extends BaseMapper<OrderItemPO> {
}
@@ -65,10 +65,22 @@ public class CreateOrderDTO {
/**
* 商品规格ID
*/
@Schema(description = "商品规格ID", example = "1", required = true)
@NotNull(message = "商品规格ID不能为空")
@Schema(description = "商品规格ID", example = "1")
private Long productSpecId;
/**
* 商品名称(冗余存储)
*/
@Schema(description = "商品名称", example = "iPhone 15 Pro", required = true)
@NotNull(message = "商品名称不能为空")
private String productName;
/**
* 规格名称(冗余存储)
*/
@Schema(description = "规格名称", example = "256GB 深空黑色")
private String specName;
/**
* 数量
*/
@@ -76,4 +88,25 @@ public class CreateOrderDTO {
@NotNull(message = "数量不能为空")
@Positive(message = "数量必须大于0")
private Integer quantity;
/**
* 销售单价
*/
@Schema(description = "销售单价", example = "9999.00", required = true)
@NotNull(message = "销售单价不能为空")
private BigDecimal unitPrice;
/**
* 成本价(下单时快照)
*/
@Schema(description = "成本价", example = "8000.00", required = true)
@NotNull(message = "成本价不能为空")
private BigDecimal costPrice;
/**
* 成本小计
*/
@Schema(description = "成本小计", example = "8000.00", required = true)
@NotNull(message = "成本小计不能为空")
private BigDecimal costTotal;
}
@@ -1,79 +0,0 @@
package top.xyquan.ecomdmbbackend.modules.ec.model.dto.order;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import lombok.Data;
import java.math.BigDecimal;
/**
* 创建订单明细DTO
*/
@Data
@Schema(description = "创建订单明细DTO")
public class CreateOrderItemDTO {
/**
* 商品ID
*/
@Schema(description = "商品ID", example = "1", required = true)
@NotNull(message = "商品ID不能为空")
private Long productId;
/**
* 商品规格ID
*/
@Schema(description = "商品规格ID", example = "1")
private Long productSpecId;
/**
* 商品名称(冗余存储)
*/
@Schema(description = "商品名称", example = "iPhone 15 Pro", required = true)
@NotBlank(message = "商品名称不能为空")
private String productName;
/**
* 规格名称(冗余存储)
*/
@Schema(description = "规格名称", example = "128GB 深空黑色")
private String specName;
/**
* 数量
*/
@Schema(description = "数量", example = "1", required = true)
@NotNull(message = "数量不能为空")
@Positive(message = "数量必须大于0")
private Integer quantity;
/**
* 销售单价
*/
@Schema(description = "销售单价", example = "9999.00", required = true)
@NotNull(message = "销售单价不能为空")
private BigDecimal unitPrice;
/**
* 成本价(下单时快照)
*/
@Schema(description = "成本价", example = "8000.00", required = true)
@NotNull(message = "成本价不能为空")
private BigDecimal costPrice;
/**
* 小计金额
*/
@Schema(description = "小计金额", example = "9999.00", required = true)
@NotNull(message = "小计金额不能为空")
private BigDecimal subtotal;
/**
* 成本小计
*/
@Schema(description = "成本小计", example = "8000.00", required = true)
@NotNull(message = "成本小计不能为空")
private BigDecimal costTotal;
}
@@ -52,4 +52,52 @@ public class UpdateOrderDTO {
@Schema(description = "下单时间", example = "2024-01-01T10:00:00", required = true)
@NotNull(message = "下单时间不能为空")
private LocalDateTime orderDate;
/**
* 商品ID
*/
@Schema(description = "商品ID", example = "1")
private Long productId;
/**
* 商品规格ID
*/
@Schema(description = "商品规格ID", example = "1")
private Long productSpecId;
/**
* 商品名称(冗余存储)
*/
@Schema(description = "商品名称", example = "iPhone 15 Pro")
private String productName;
/**
* 规格名称(冗余存储)
*/
@Schema(description = "规格名称", example = "256GB 深空黑色")
private String specName;
/**
* 数量
*/
@Schema(description = "数量", example = "1")
private Integer quantity;
/**
* 销售单价
*/
@Schema(description = "销售单价", example = "9999.00")
private BigDecimal unitPrice;
/**
* 成本价(下单时快照)
*/
@Schema(description = "成本价", example = "8000.00")
private BigDecimal costPrice;
/**
* 成本小计
*/
@Schema(description = "成本小计", example = "8000.00")
private BigDecimal costTotal;
}
@@ -1,119 +0,0 @@
package top.xyquan.ecomdmbbackend.modules.ec.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_order_item")
public class OrderItemPO {
/**
* 订单明细ID
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 订单ID
*/
@TableField("order_id")
private Long orderId;
/**
* 商品ID
*/
@TableField("product_id")
private Long productId;
/**
* 商品规格ID
*/
@TableField("product_spec_id")
private Long productSpecId;
/**
* 商品名称(冗余存储)
*/
@TableField("product_name")
private String productName;
/**
* 规格名称(冗余存储)
*/
@TableField("spec_name")
private String specName;
/**
* 数量
*/
@TableField("quantity")
private Integer quantity;
/**
* 销售单价
*/
@TableField("unit_price")
private BigDecimal unitPrice;
/**
* 成本价(下单时快照)
*/
@TableField("cost_price")
private BigDecimal costPrice;
/**
* 小计金额
*/
@TableField("subtotal")
private BigDecimal subtotal;
/**
* 成本小计
*/
@TableField("cost_total")
private BigDecimal costTotal;
/**
* 创建时间
*/
@TableField(value = "create_time", fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 删除时间
*/
@TableField("delete_time")
private LocalDateTime deleteTime;
/**
* 创建人ID
*/
@TableField("create_by")
private Long createBy;
/**
* 更新人ID
*/
@TableField("update_by")
private Long updateBy;
/**
* 删除人ID
*/
@TableField("delete_by")
private Long deleteBy;
}
@@ -8,7 +8,7 @@ import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 电商-订单实体
* 电商-订单实体(含商品明细)
*/
@Data
@EqualsAndHashCode(callSuper = false)
@@ -45,6 +45,54 @@ public class OrderPO {
@TableField("status_id")
private Long statusId;
/**
* 商品ID
*/
@TableField("product_id")
private Long productId;
/**
* 商品规格ID
*/
@TableField("product_spec_id")
private Long productSpecId;
/**
* 商品名称(冗余存储)
*/
@TableField("product_name")
private String productName;
/**
* 规格名称(冗余存储)
*/
@TableField("spec_name")
private String specName;
/**
* 数量
*/
@TableField("quantity")
private Integer quantity;
/**
* 销售单价
*/
@TableField("unit_price")
private BigDecimal unitPrice;
/**
* 成本价(下单时快照)
*/
@TableField("cost_price")
private BigDecimal costPrice;
/**
* 成本小计
*/
@TableField("cost_total")
private BigDecimal costTotal;
/**
* 商家实收金额
*/
@@ -75,12 +123,6 @@ public class OrderPO {
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 删除时间
*/
@TableField("delete_time")
private LocalDateTime deleteTime;
/**
* 创建人ID
*/
@@ -92,10 +134,4 @@ public class OrderPO {
*/
@TableField("update_by")
private Long updateBy;
/**
* 删除人ID
*/
@TableField("delete_by")
private Long deleteBy;
}
@@ -26,12 +26,6 @@ public class OrderStatusPO {
@TableField("company_id")
private Long companyId;
/**
* 状态码
*/
@TableField("status_code")
private Integer statusCode;
/**
* 状态名称
*/
@@ -68,12 +62,6 @@ public class OrderStatusPO {
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 删除时间
*/
@TableField("delete_time")
private LocalDateTime deleteTime;
/**
* 创建人ID
*/
@@ -85,10 +73,4 @@ public class OrderStatusPO {
*/
@TableField("update_by")
private Long updateBy;
/**
* 删除人ID
*/
@TableField("delete_by")
private Long deleteBy;
}
@@ -56,12 +56,6 @@ public class ProductPO {
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 删除时间
*/
@TableField("delete_time")
private LocalDateTime deleteTime;
/**
* 创建人ID
*/
@@ -73,10 +67,4 @@ public class ProductPO {
*/
@TableField("update_by")
private Long updateBy;
/**
* 删除人ID
*/
@TableField("delete_by")
private Long deleteBy;
}
@@ -63,12 +63,6 @@ public class ProductSpecPO {
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 删除时间
*/
@TableField("delete_time")
private LocalDateTime deleteTime;
/**
* 创建人ID
*/
@@ -80,10 +74,4 @@ public class ProductSpecPO {
*/
@TableField("update_by")
private Long updateBy;
/**
* 删除人ID
*/
@TableField("delete_by")
private Long deleteBy;
}
@@ -118,12 +118,6 @@ public class PromotionFeePO {
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 删除时间
*/
@TableField("delete_time")
private LocalDateTime deleteTime;
/**
* 创建人ID
*/
@@ -135,10 +129,4 @@ public class PromotionFeePO {
*/
@TableField("update_by")
private Long updateBy;
/**
* 删除人ID
*/
@TableField("delete_by")
private Long deleteBy;
}
@@ -26,12 +26,6 @@ public class PromotionFeeTypePO {
@TableField("company_id")
private Long companyId;
/**
* 类型编码
*/
@TableField("type_code")
private String typeCode;
/**
* 类型名称
*/
@@ -74,12 +68,6 @@ public class PromotionFeeTypePO {
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 删除时间
*/
@TableField("delete_time")
private LocalDateTime deleteTime;
/**
* 创建人ID
*/
@@ -91,10 +79,4 @@ public class PromotionFeeTypePO {
*/
@TableField("update_by")
private Long updateBy;
/**
* 删除人ID
*/
@TableField("delete_by")
private Long deleteBy;
}
@@ -62,12 +62,6 @@ public class ShopPO {
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 删除时间
*/
@TableField("delete_time")
private LocalDateTime deleteTime;
/**
* 创建人ID
*/
@@ -79,10 +73,4 @@ public class ShopPO {
*/
@TableField("update_by")
private Long updateBy;
/**
* 删除人ID
*/
@TableField("delete_by")
private Long deleteBy;
}
@@ -1,99 +0,0 @@
package top.xyquan.ecomdmbbackend.modules.ec.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 OrderItemVO {
/**
* 订单明细ID
*/
@Schema(description = "订单明细ID", example = "1")
private Long id;
/**
* 订单ID
*/
@Schema(description = "订单ID", example = "1")
private Long orderId;
/**
* 商品ID
*/
@Schema(description = "商品ID", example = "1")
private Long productId;
/**
* 商品规格ID
*/
@Schema(description = "商品规格ID", example = "1")
private Long productSpecId;
/**
* 商品名称(冗余存储)
*/
@Schema(description = "商品名称", example = "iPhone 15 Pro")
private String productName;
/**
* 规格名称(冗余存储)
*/
@Schema(description = "规格名称", example = "128GB 深空黑色")
private String specName;
/**
* 商品主图
*/
@Schema(description = "商品主图", example = "https://example.com/product.jpg")
private String productImage;
/**
* 数量
*/
@Schema(description = "数量", example = "1")
private Integer quantity;
/**
* 销售单价
*/
@Schema(description = "销售单价", example = "9999.00")
private BigDecimal unitPrice;
/**
* 成本价(下单时快照)
*/
@Schema(description = "成本价", example = "8000.00")
private BigDecimal costPrice;
/**
* 小计金额
*/
@Schema(description = "小计金额", example = "9999.00")
private BigDecimal subtotal;
/**
* 成本小计
*/
@Schema(description = "成本小计", example = "8000.00")
private BigDecimal costTotal;
/**
* 创建时间
*/
@Schema(description = "创建时间", example = "2024-01-01T10:00:00")
private LocalDateTime createTime;
/**
* 更新时间
*/
@Schema(description = "更新时间", example = "2024-01-01T10:00:00")
private LocalDateTime updateTime;
}
@@ -98,8 +98,50 @@ public class OrderVO {
private Long updateBy;
/**
* 订单明细
* 商品ID
*/
@Schema(description = "订单明细")
private OrderItemVO orderItem;
@Schema(description = "商品ID", example = "1")
private Long productId;
/**
* 商品规格ID
*/
@Schema(description = "商品规格ID", example = "1")
private Long productSpecId;
/**
* 商品名称(冗余存储)
*/
@Schema(description = "商品名称", example = "iPhone 15 Pro")
private String productName;
/**
* 规格名称(冗余存储)
*/
@Schema(description = "规格名称", example = "256GB 深空黑色")
private String specName;
/**
* 数量
*/
@Schema(description = "数量", example = "1")
private Integer quantity;
/**
* 销售单价
*/
@Schema(description = "销售单价", example = "9999.00")
private BigDecimal unitPrice;
/**
* 成本价(下单时快照)
*/
@Schema(description = "成本价", example = "8000.00")
private BigDecimal costPrice;
/**
* 成本小计
*/
@Schema(description = "成本小计", example = "8000.00")
private BigDecimal costTotal;
}
@@ -10,19 +10,16 @@ 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.ec.mapper.OrderItemMapper;
import top.xyquan.ecomdmbbackend.modules.ec.mapper.OrderMapper;
import top.xyquan.ecomdmbbackend.modules.ec.model.dto.order.BatchImportOrderDTO;
import top.xyquan.ecomdmbbackend.modules.ec.model.dto.order.CreateOrderDTO;
import top.xyquan.ecomdmbbackend.modules.ec.model.dto.order.OrderFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ec.model.dto.order.UpdateOrderDTO;
import top.xyquan.ecomdmbbackend.modules.ec.model.po.OrderItemPO;
import top.xyquan.ecomdmbbackend.modules.ec.model.po.OrderPO;
import top.xyquan.ecomdmbbackend.modules.ec.model.po.ProductPO;
import top.xyquan.ecomdmbbackend.modules.ec.model.po.ProductSpecPO;
import top.xyquan.ecomdmbbackend.modules.ec.model.po.ShopPO;
import top.xyquan.ecomdmbbackend.modules.ec.model.vo.BatchImportResultVO;
import top.xyquan.ecomdmbbackend.modules.ec.model.vo.OrderItemVO;
import top.xyquan.ecomdmbbackend.modules.ec.model.vo.OrderVO;
import top.xyquan.ecomdmbbackend.modules.ec.service.OrderService;
import top.xyquan.ecomdmbbackend.modules.ec.service.ProductService;
@@ -45,16 +42,13 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
private final ShopService shopService;
private final ProductService productService;
private final ProductSpecService productSpecService;
private final OrderItemMapper orderItemMapper;
public OrderServiceImpl(CurrentUserContext currentUserContext, ShopService shopService,
ProductService productService, ProductSpecService productSpecService,
OrderItemMapper orderItemMapper) {
ProductService productService, ProductSpecService productSpecService) {
this.currentUserContext = currentUserContext;
this.shopService = shopService;
this.productService = productService;
this.productSpecService = productSpecService;
this.orderItemMapper = orderItemMapper;
}
@Override
@@ -75,30 +69,40 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
throw new BusinessException("商品不存在");
}
// 验证商品规格是否存在且属于当前公司
ProductSpecPO productSpec = productSpecService.getById(createOrderDTO.getProductSpecId());
if (productSpec == null || !productSpec.getCompanyId().equals(companyId) ||
!productSpec.getProductId().equals(createOrderDTO.getProductId())) {
throw new BusinessException("商品规格不存在或不属于该商品");
// 验证商品规格是否存在且属于当前公司(如果提供了规格ID)
ProductSpecPO productSpec = null;
if (createOrderDTO.getProductSpecId() != null) {
productSpec = productSpecService.getById(createOrderDTO.getProductSpecId());
if (productSpec == null || !productSpec.getCompanyId().equals(companyId) ||
!productSpec.getProductId().equals(createOrderDTO.getProductId())) {
throw new BusinessException("商品规格不存在或不属于该商品");
}
}
// 验证平台订单号是否重复(如果提供了的话)
if (createOrderDTO.getPlatformOrderNo() != null && !createOrderDTO.getPlatformOrderNo().trim().isEmpty()) {
LambdaQueryWrapper<OrderPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(OrderPO::getPlatformOrderNo, createOrderDTO.getPlatformOrderNo())
.eq(OrderPO::getCompanyId, companyId)
.isNull(OrderPO::getDeleteTime);
.eq(OrderPO::getCompanyId, companyId);
if (this.count(wrapper) > 0) {
throw new BusinessException("平台订单号已存在");
}
}
// 创建订单
// 创建订单(包含商品明细)
OrderPO order = new OrderPO();
order.setCompanyId(companyId);
order.setShopId(createOrderDTO.getShopId());
order.setPlatformOrderNo(createOrderDTO.getPlatformOrderNo());
order.setStatusId(createOrderDTO.getStatusId());
order.setProductId(createOrderDTO.getProductId());
order.setProductSpecId(createOrderDTO.getProductSpecId());
order.setProductName(createOrderDTO.getProductName());
order.setSpecName(createOrderDTO.getSpecName());
order.setQuantity(createOrderDTO.getQuantity());
order.setUnitPrice(createOrderDTO.getUnitPrice());
order.setCostPrice(createOrderDTO.getCostPrice());
order.setCostTotal(createOrderDTO.getCostTotal());
order.setReceivedAmount(createOrderDTO.getReceivedAmount());
order.setShippingFee(createOrderDTO.getShippingFee() != null ? createOrderDTO.getShippingFee() : java.math.BigDecimal.ZERO);
order.setOrderDate(createOrderDTO.getOrderDate());
@@ -107,29 +111,6 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
// 保存订单
this.save(order);
// 计算订单明细相关字段
java.math.BigDecimal unitPrice = createOrderDTO.getReceivedAmount().divide(
java.math.BigDecimal.valueOf(createOrderDTO.getQuantity()), 2, java.math.RoundingMode.HALF_UP);
java.math.BigDecimal costPrice = productSpec.getCostPrice();
java.math.BigDecimal subtotal = unitPrice.multiply(java.math.BigDecimal.valueOf(createOrderDTO.getQuantity()));
java.math.BigDecimal costTotal = costPrice.multiply(java.math.BigDecimal.valueOf(createOrderDTO.getQuantity()));
// 创建订单明细
OrderItemPO orderItem = new OrderItemPO();
orderItem.setOrderId(order.getId());
orderItem.setProductId(createOrderDTO.getProductId());
orderItem.setProductSpecId(createOrderDTO.getProductSpecId());
orderItem.setProductName(product.getName()); // 冗余存储商品名称
orderItem.setSpecName(productSpec.getName()); // 冗余存储规格名称
orderItem.setQuantity(createOrderDTO.getQuantity());
orderItem.setUnitPrice(unitPrice); // 销售单价 = 实收金额 / 数量
orderItem.setCostPrice(costPrice); // 成本价(下单时快照)
orderItem.setSubtotal(subtotal); // 小计金额 = 销售单价 × 数量
orderItem.setCostTotal(costTotal); // 成本小计 = 成本价 × 数量
orderItem.setCreateBy(currentUserContext.getCurrentUserId());
orderItemMapper.insert(orderItem);
// 转换为VO并返回
return convertToVO(order);
}
@@ -157,8 +138,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
LambdaQueryWrapper<OrderPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(OrderPO::getPlatformOrderNo, updateOrderDTO.getPlatformOrderNo())
.eq(OrderPO::getCompanyId, companyId)
.ne(OrderPO::getId, id)
.isNull(OrderPO::getDeleteTime);
.ne(OrderPO::getId, id);
if (this.count(wrapper) > 0) {
throw new BusinessException("平台订单号已存在");
}
@@ -192,24 +172,8 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
throw new BusinessException("订单不存在");
}
// 软删除订单
OrderPO order = new OrderPO();
order.setId(id);
order.setDeleteTime(LocalDateTime.now());
order.setDeleteBy(currentUserContext.getCurrentUserId());
this.updateById(order);
// 软删除订单明细
LambdaQueryWrapper<OrderItemPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(OrderItemPO::getOrderId, id)
.isNull(OrderItemPO::getDeleteTime);
List<OrderItemPO> orderItems = orderItemMapper.selectList(wrapper);
for (OrderItemPO orderItem : orderItems) {
orderItem.setDeleteTime(LocalDateTime.now());
orderItem.setDeleteBy(currentUserContext.getCurrentUserId());
orderItemMapper.updateById(orderItem);
}
// 硬删除订单(外键约束会自动处理相关数据)
this.removeById(id);
}
@Override
@@ -222,8 +186,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
// 构建查询条件
LambdaQueryWrapper<OrderPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(OrderPO::getCompanyId, companyId)
.isNull(OrderPO::getDeleteTime);
wrapper.eq(OrderPO::getCompanyId, companyId);
// 添加过滤条件
OrderFilterDTO filter = pageQueryDTO.getFilters();
@@ -258,25 +221,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
// 执行分页查询
IPage<OrderPO> pageResult = this.page(page, wrapper);
// 转换为VO并加载订单明细
// 转换为VO
List<OrderVO> voList = pageResult.getRecords().stream()
.map(order -> {
OrderVO orderVO = convertToVO(order);
// 查询订单明细(只取第一条)
LambdaQueryWrapper<OrderItemPO> itemWrapper = new LambdaQueryWrapper<>();
itemWrapper.eq(OrderItemPO::getOrderId, order.getId())
.isNull(OrderItemPO::getDeleteTime)
.orderByAsc(OrderItemPO::getCreateTime)
.last("LIMIT 1");
OrderItemPO orderItem = orderItemMapper.selectOne(itemWrapper);
// 转换为VO
if (orderItem != null) {
OrderItemVO orderItemVO = convertOrderItemToVO(orderItem);
orderVO.setOrderItem(orderItemVO);
}
return orderVO;
})
.map(this::convertToVO)
.collect(Collectors.toList());
// 构建分页结果
@@ -294,24 +241,8 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
throw new BusinessException("订单不存在");
}
// 转换为VO
OrderVO orderVO = convertToVO(order);
// 查询订单明细(只取第一条)
LambdaQueryWrapper<OrderItemPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(OrderItemPO::getOrderId, id)
.isNull(OrderItemPO::getDeleteTime)
.orderByAsc(OrderItemPO::getCreateTime)
.last("LIMIT 1");
OrderItemPO orderItem = orderItemMapper.selectOne(wrapper);
// 转换为VO
if (orderItem != null) {
OrderItemVO orderItemVO = convertOrderItemToVO(orderItem);
orderVO.setOrderItem(orderItemVO);
}
return orderVO;
// 转换为VO并返回
return convertToVO(order);
}
@Override
@@ -376,13 +307,4 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
return orderVO;
}
/**
* 转换订单明细为VO
*/
private OrderItemVO convertOrderItemToVO(OrderItemPO orderItem) {
OrderItemVO orderItemVO = new OrderItemVO();
BeanUtils.copyProperties(orderItem, orderItemVO);
return orderItemVO;
}
}
@@ -29,13 +29,12 @@ public class OrderStatusServiceImpl implements OrderStatusService {
@Override
@Transactional(rollbackFor = Exception.class)
public Long createOrderStatus(CreateOrderStatusDTO dto) {
// 检查状态码是否重复
// 检查状态名称是否重复
LambdaQueryWrapper<OrderStatusPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(OrderStatusPO::getCompanyId, currentUserContext.getCurrentCompanyId())
.eq(OrderStatusPO::getStatusCode, dto.getStatusCode())
.isNull(OrderStatusPO::getDeleteTime);
.eq(OrderStatusPO::getStatusName, dto.getStatusName());
if (orderStatusMapper.selectCount(wrapper) > 0) {
throw new RuntimeException("该状态码已存在");
throw new RuntimeException("该状态名称已存在");
}
OrderStatusPO po = new OrderStatusPO();
@@ -61,12 +60,8 @@ public class OrderStatusServiceImpl implements OrderStatusService {
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteOrderStatus(Long id) {
OrderStatusPO po = new OrderStatusPO();
po.setId(id);
po.setDeleteBy(currentUserContext.getCurrentUserId());
po.setDeleteTime(java.time.LocalDateTime.now());
orderStatusMapper.updateById(po);
// 硬删除订单状态(外键约束会自动处理相关数据)
orderStatusMapper.deleteById(id);
}
@Override
@@ -86,7 +81,6 @@ public class OrderStatusServiceImpl implements OrderStatusService {
LambdaQueryWrapper<OrderStatusPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(OrderStatusPO::getCompanyId, currentUserContext.getCurrentCompanyId())
.eq(OrderStatusPO::getIsActive, 1) // 1表示启用状态
.isNull(OrderStatusPO::getDeleteTime)
.orderByAsc(OrderStatusPO::getSortOrder);
List<OrderStatusPO> poList = orderStatusMapper.selectList(wrapper);
@@ -103,7 +97,6 @@ public class OrderStatusServiceImpl implements OrderStatusService {
public List<OrderStatusVO> getAllOrderStatusList() {
LambdaQueryWrapper<OrderStatusPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(OrderStatusPO::getCompanyId, currentUserContext.getCurrentCompanyId())
.isNull(OrderStatusPO::getDeleteTime)
.orderByAsc(OrderStatusPO::getSortOrder);
List<OrderStatusPO> poList = orderStatusMapper.selectList(wrapper);
@@ -124,20 +117,19 @@ public class OrderStatusServiceImpl implements OrderStatusService {
public void initOrderStatusForCompany(Long companyId) {
// 检查是否已经初始化过
LambdaQueryWrapper<OrderStatusPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(OrderStatusPO::getCompanyId, companyId)
.isNull(OrderStatusPO::getDeleteTime);
wrapper.eq(OrderStatusPO::getCompanyId, companyId);
if (orderStatusMapper.selectCount(wrapper) > 0) {
return; // 已经初始化过,直接返回
}
// 初始化订单状态数据
List<OrderStatusPO> initialStatuses = List.of(
createOrderStatusPO(companyId, 0, "待发货", "订单已创建,等待发货", 1),
createOrderStatusPO(companyId, 1, "已发货", "商品已发出,运输中", 2),
createOrderStatusPO(companyId, 2, "已完成", "订单已完成,交易成功", 3),
createOrderStatusPO(companyId, 3, "已取消", "订单已取消", 4),
createOrderStatusPO(companyId, 4, "退款中", "正在处理退款", 5),
createOrderStatusPO(companyId, 5, "已退款", "退款已完成", 6)
createOrderStatusPO(companyId, "待发货", "订单已创建,等待发货", 1),
createOrderStatusPO(companyId, "已发货", "商品已发出,运输中", 2),
createOrderStatusPO(companyId, "已完成", "订单已完成,交易成功", 3),
createOrderStatusPO(companyId, "已取消", "订单已取消", 4),
createOrderStatusPO(companyId, "退款中", "正在处理退款", 5),
createOrderStatusPO(companyId, "已退款", "退款已完成", 6)
);
// 批量插入
@@ -162,10 +154,9 @@ public class OrderStatusServiceImpl implements OrderStatusService {
/**
* 创建订单状态PO对象
*/
private OrderStatusPO createOrderStatusPO(Long companyId, Integer statusCode, String statusName, String description, Integer sortOrder) {
private OrderStatusPO createOrderStatusPO(Long companyId, String statusName, String description, Integer sortOrder) {
OrderStatusPO po = new OrderStatusPO();
po.setCompanyId(companyId);
po.setStatusCode(statusCode);
po.setStatusName(statusName);
po.setDescription(description);
po.setSortOrder(sortOrder);
@@ -26,7 +26,6 @@ import top.xyquan.ecomdmbbackend.modules.media.service.MediaImageService;
import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaImageVO;
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
@@ -55,8 +54,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
// 验证商品名称是否重复
LambdaQueryWrapper<ProductPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ProductPO::getName, createProductDTO.getName())
.eq(ProductPO::getCompanyId, companyId)
.isNull(ProductPO::getDeleteTime);
.eq(ProductPO::getCompanyId, companyId);
if (this.count(wrapper) > 0) {
throw new BusinessException("商品名称已存在");
}
@@ -104,8 +102,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
LambdaQueryWrapper<ProductPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ProductPO::getName, updateProductDTO.getName())
.eq(ProductPO::getCompanyId, companyId)
.ne(ProductPO::getId, id)
.isNull(ProductPO::getDeleteTime);
.ne(ProductPO::getId, id);
if (this.count(wrapper) > 0) {
throw new BusinessException("商品名称已存在");
}
@@ -148,13 +145,8 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
throw new BusinessException("商品不存在");
}
// 软删除商品
ProductPO product = new ProductPO();
product.setId(id);
product.setDeleteTime(LocalDateTime.now());
product.setDeleteBy(currentUserContext.getCurrentUserId());
this.updateById(product);
// 硬删除商品(外键约束会自动处理相关数据)
this.removeById(id);
}
@Override
@@ -167,8 +159,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
// 构建查询条件
LambdaQueryWrapper<ProductPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ProductPO::getCompanyId, companyId)
.isNull(ProductPO::getDeleteTime);
wrapper.eq(ProductPO::getCompanyId, companyId);
// 添加过滤条件
ProductFilterDTO filter = pageQueryDTO.getFilters();
@@ -202,8 +193,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
// 验证商品名称是否重复
LambdaQueryWrapper<ProductPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ProductPO::getName, createProductWithSpecsDTO.getName())
.eq(ProductPO::getCompanyId, companyId)
.isNull(ProductPO::getDeleteTime);
.eq(ProductPO::getCompanyId, companyId);
if (this.count(wrapper) > 0) {
throw new BusinessException("商品名称已存在");
}
@@ -257,7 +247,6 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
LambdaQueryWrapper<ProductSpecPO> specWrapper = new LambdaQueryWrapper<>();
specWrapper.eq(ProductSpecPO::getProductId, product.getId())
.eq(ProductSpecPO::getCompanyId, product.getCompanyId())
.isNull(ProductSpecPO::getDeleteTime)
.orderByAsc(ProductSpecPO::getCreateTime);
List<ProductSpecPO> specPOs = productSpecService.list(specWrapper);
@@ -277,8 +266,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
// 根据名称精准查询商品
LambdaQueryWrapper<ProductPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ProductPO::getName, name)
.eq(ProductPO::getCompanyId, companyId)
.isNull(ProductPO::getDeleteTime);
.eq(ProductPO::getCompanyId, companyId);
ProductPO product = this.getOne(wrapper);
if (product == null) {
@@ -301,7 +289,6 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
LambdaQueryWrapper<ProductPO> wrapper = new LambdaQueryWrapper<>();
wrapper.in(ProductPO::getName, names)
.eq(ProductPO::getCompanyId, companyId)
.isNull(ProductPO::getDeleteTime)
.orderByAsc(ProductPO::getName);
List<ProductPO> products = this.list(wrapper);
@@ -22,7 +22,6 @@ import top.xyquan.ecomdmbbackend.modules.ec.service.ProductService;
import top.xyquan.ecomdmbbackend.modules.ec.service.ProductSpecService;
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
@@ -47,20 +46,16 @@ public class ProductSpecServiceImpl extends ServiceImpl<ProductSpecMapper, Produ
Long companyId = currentUserContext.getCurrentCompanyId();
// 验证商品是否存在
LambdaQueryWrapper<ProductSpecPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ProductSpecPO::getProductId, createProductSpecDTO.getProductId())
.eq(ProductSpecPO::getCompanyId, companyId)
.isNull(ProductSpecPO::getDeleteTime);
if (this.count(wrapper) == 0) {
ProductPO product = productService.getById(createProductSpecDTO.getProductId());
if (product == null || !product.getCompanyId().equals(companyId)) {
throw new BusinessException("商品不存在");
}
// 验证规格名称是否重复
wrapper.clear();
LambdaQueryWrapper<ProductSpecPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ProductSpecPO::getProductId, createProductSpecDTO.getProductId())
.eq(ProductSpecPO::getName, createProductSpecDTO.getName())
.eq(ProductSpecPO::getCompanyId, companyId)
.isNull(ProductSpecPO::getDeleteTime);
.eq(ProductSpecPO::getCompanyId, companyId);
if (this.count(wrapper) > 0) {
throw new BusinessException("规格名称已存在");
}
@@ -97,8 +92,7 @@ public class ProductSpecServiceImpl extends ServiceImpl<ProductSpecMapper, Produ
wrapper.eq(ProductSpecPO::getProductId, existingProductSpec.getProductId())
.eq(ProductSpecPO::getName, updateProductSpecDTO.getName())
.eq(ProductSpecPO::getCompanyId, companyId)
.ne(ProductSpecPO::getId, id)
.isNull(ProductSpecPO::getDeleteTime);
.ne(ProductSpecPO::getId, id);
if (this.count(wrapper) > 0) {
throw new BusinessException("规格名称已存在");
}
@@ -132,13 +126,8 @@ public class ProductSpecServiceImpl extends ServiceImpl<ProductSpecMapper, Produ
throw new BusinessException("商品规格不存在");
}
// 软删除商品规格
ProductSpecPO productSpec = new ProductSpecPO();
productSpec.setId(id);
productSpec.setDeleteTime(LocalDateTime.now());
productSpec.setDeleteBy(currentUserContext.getCurrentUserId());
this.updateById(productSpec);
// 硬删除商品规格(外键约束会自动处理相关数据)
this.removeById(id);
}
@Override
@@ -151,8 +140,7 @@ public class ProductSpecServiceImpl extends ServiceImpl<ProductSpecMapper, Produ
// 构建查询条件
LambdaQueryWrapper<ProductSpecPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ProductSpecPO::getCompanyId, companyId)
.isNull(ProductSpecPO::getDeleteTime);
wrapper.eq(ProductSpecPO::getCompanyId, companyId);
// 添加过滤条件
ProductSpecFilterDTO filter = pageQueryDTO.getFilters();
@@ -188,8 +176,7 @@ public class ProductSpecServiceImpl extends ServiceImpl<ProductSpecMapper, Produ
// 先根据商品名称查询商品
LambdaQueryWrapper<ProductPO> productWrapper = new LambdaQueryWrapper<>();
productWrapper.eq(ProductPO::getName, productName)
.eq(ProductPO::getCompanyId, companyId)
.isNull(ProductPO::getDeleteTime);
.eq(ProductPO::getCompanyId, companyId);
ProductPO product = productService.getOne(productWrapper);
if (product == null) {
@@ -200,8 +187,7 @@ public class ProductSpecServiceImpl extends ServiceImpl<ProductSpecMapper, Produ
LambdaQueryWrapper<ProductSpecPO> specWrapper = new LambdaQueryWrapper<>();
specWrapper.eq(ProductSpecPO::getProductId, product.getId())
.eq(ProductSpecPO::getSpecCode, specCode)
.eq(ProductSpecPO::getCompanyId, companyId)
.isNull(ProductSpecPO::getDeleteTime);
.eq(ProductSpecPO::getCompanyId, companyId);
ProductSpecPO productSpec = this.getOne(specWrapper);
if (productSpec == null) {
@@ -212,7 +198,7 @@ public class ProductSpecServiceImpl extends ServiceImpl<ProductSpecMapper, Produ
}
@Override
public List<ProductVO> getProductSpecsByProductAndSpecs(List<ProductSpecQueryDTO> queries) {
public List<ProductVO> getProductSpecsByProductAndSpecs(List<ProductSpecService.ProductSpecQueryDTO> queries) {
if (queries == null || queries.isEmpty()) {
return List.of();
}
@@ -222,15 +208,14 @@ public class ProductSpecServiceImpl extends ServiceImpl<ProductSpecMapper, Produ
// 收集所有商品名称
List<String> productNames = queries.stream()
.map(ProductSpecQueryDTO::getProductName)
.map(ProductSpecService.ProductSpecQueryDTO::getProductName)
.distinct()
.collect(Collectors.toList());
// 批量查询商品
LambdaQueryWrapper<ProductPO> productWrapper = new LambdaQueryWrapper<>();
productWrapper.in(ProductPO::getName, productNames)
.eq(ProductPO::getCompanyId, companyId)
.isNull(ProductPO::getDeleteTime);
.eq(ProductPO::getCompanyId, companyId);
List<ProductPO> products = productService.list(productWrapper);
if (products.isEmpty()) {
@@ -243,7 +228,7 @@ public class ProductSpecServiceImpl extends ServiceImpl<ProductSpecMapper, Produ
// 收集所有规格编码
List<String> specCodes = queries.stream()
.map(ProductSpecQueryDTO::getSpecCode)
.map(ProductSpecService.ProductSpecQueryDTO::getSpecCode)
.distinct()
.collect(Collectors.toList());
@@ -251,8 +236,7 @@ public class ProductSpecServiceImpl extends ServiceImpl<ProductSpecMapper, Produ
LambdaQueryWrapper<ProductSpecPO> specWrapper = new LambdaQueryWrapper<>();
specWrapper.in(ProductSpecPO::getSpecCode, specCodes)
.in(ProductSpecPO::getProductId, productNameToIdMap.values())
.eq(ProductSpecPO::getCompanyId, companyId)
.isNull(ProductSpecPO::getDeleteTime);
.eq(ProductSpecPO::getCompanyId, companyId);
List<ProductSpecPO> productSpecs = this.list(specWrapper);
@@ -54,12 +54,8 @@ public class PromotionFeeServiceImpl implements PromotionFeeService {
@Override
@Transactional(rollbackFor = Exception.class)
public void deletePromotionFee(Long id) {
PromotionFeePO po = new PromotionFeePO();
po.setId(id);
po.setDeleteBy(currentUserContext.getCurrentUserId());
po.setDeleteTime(java.time.LocalDateTime.now());
promotionFeeMapper.updateById(po);
// 硬删除推广费记录(外键约束会自动处理相关数据)
promotionFeeMapper.deleteById(id);
}
@Override
@@ -29,13 +29,12 @@ public class PromotionFeeTypeServiceImpl implements PromotionFeeTypeService {
@Override
@Transactional(rollbackFor = Exception.class)
public Long createPromotionFeeType(CreatePromotionFeeTypeDTO dto) {
// 检查类型编码是否重复
// 检查类型名称是否重复
LambdaQueryWrapper<PromotionFeeTypePO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PromotionFeeTypePO::getCompanyId, currentUserContext.getCurrentCompanyId())
.eq(PromotionFeeTypePO::getTypeCode, dto.getTypeCode())
.isNull(PromotionFeeTypePO::getDeleteTime);
.eq(PromotionFeeTypePO::getTypeName, dto.getTypeName());
if (promotionFeeTypeMapper.selectCount(wrapper) > 0) {
throw new RuntimeException("该类型编码已存在");
throw new RuntimeException("该类型名称已存在");
}
PromotionFeeTypePO po = new PromotionFeeTypePO();
@@ -61,12 +60,8 @@ public class PromotionFeeTypeServiceImpl implements PromotionFeeTypeService {
@Override
@Transactional(rollbackFor = Exception.class)
public void deletePromotionFeeType(Long id) {
PromotionFeeTypePO po = new PromotionFeeTypePO();
po.setId(id);
po.setDeleteBy(currentUserContext.getCurrentUserId());
po.setDeleteTime(java.time.LocalDateTime.now());
promotionFeeTypeMapper.updateById(po);
// 硬删除推广费类型(外键约束会自动处理相关数据)
promotionFeeTypeMapper.deleteById(id);
}
@Override
@@ -108,7 +103,6 @@ public class PromotionFeeTypeServiceImpl implements PromotionFeeTypeService {
LambdaQueryWrapper<PromotionFeeTypePO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PromotionFeeTypePO::getCompanyId, currentUserContext.getCurrentCompanyId())
.eq(PromotionFeeTypePO::getIsActive, 1)
.isNull(PromotionFeeTypePO::getDeleteTime)
.orderByAsc(PromotionFeeTypePO::getSortOrder);
List<PromotionFeeTypePO> poList = promotionFeeTypeMapper.selectList(wrapper);
@@ -147,7 +141,6 @@ public class PromotionFeeTypeServiceImpl implements PromotionFeeTypeService {
public List<PromotionFeeTypeVO> getAllPromotionFeeTypeList() {
LambdaQueryWrapper<PromotionFeeTypePO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PromotionFeeTypePO::getCompanyId, currentUserContext.getCurrentCompanyId())
.isNull(PromotionFeeTypePO::getDeleteTime)
.orderByAsc(PromotionFeeTypePO::getSortOrder);
List<PromotionFeeTypePO> poList = promotionFeeTypeMapper.selectList(wrapper);
@@ -190,22 +183,21 @@ public class PromotionFeeTypeServiceImpl implements PromotionFeeTypeService {
public void initPromotionFeeTypeForCompany(Long companyId) {
// 检查是否已经初始化过
LambdaQueryWrapper<PromotionFeeTypePO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PromotionFeeTypePO::getCompanyId, companyId)
.isNull(PromotionFeeTypePO::getDeleteTime);
wrapper.eq(PromotionFeeTypePO::getCompanyId, companyId);
if (promotionFeeTypeMapper.selectCount(wrapper) > 0) {
return; // 已经初始化过,直接返回
}
// 初始化推广费类型数据
List<PromotionFeeTypePO> initialTypes = List.of(
createPromotionFeeTypePO(companyId, "DIRECT_TRAFFIC", "直通车", "淘宝直通车推广费用", 3, 1),
createPromotionFeeTypePO(companyId, "DIAMOND_DISPLAY", "钻展", "钻石展位推广费用", 4, 2),
createPromotionFeeTypePO(companyId, "SUPER_RECOMMEND", "超级推荐", "超级推荐推广费用", 3, 3),
createPromotionFeeTypePO(companyId, "PLATFORM_COMMISSION", "平台佣金", "平台交易佣金", 2, 4),
createPromotionFeeTypePO(companyId, "DISTRIBUTION_COMMISSION", "分销佣金", "分销商佣金", 2, 5),
createPromotionFeeTypePO(companyId, "ACTIVITY_FEE", "活动费用", "平台活动参与费用", 1, 6),
createPromotionFeeTypePO(companyId, "EXTERNAL_AD", "站外广告", "站外广告投放费用", 1, 7),
createPromotionFeeTypePO(companyId, "LIVE_STREAMING", "直播推广", "直播推广费用", 1, 8)
createPromotionFeeTypePO(companyId, "直通车", "淘宝直通车推广费用", 3, 1),
createPromotionFeeTypePO(companyId, "钻展", "钻石展位推广费用", 4, 2),
createPromotionFeeTypePO(companyId, "超级推荐", "超级推荐推广费用", 3, 3),
createPromotionFeeTypePO(companyId, "平台佣金", "平台交易佣金", 2, 4),
createPromotionFeeTypePO(companyId, "分销佣金", "分销商佣金", 2, 5),
createPromotionFeeTypePO(companyId, "活动费用", "平台活动参与费用", 1, 6),
createPromotionFeeTypePO(companyId, "站外广告", "站外广告投放费用", 1, 7),
createPromotionFeeTypePO(companyId, "直播推广", "直播推广费用", 1, 8)
);
// 批量插入
@@ -230,10 +222,9 @@ public class PromotionFeeTypeServiceImpl implements PromotionFeeTypeService {
/**
* 创建推广费类型PO对象
*/
private PromotionFeeTypePO createPromotionFeeTypePO(Long companyId, String typeCode, String typeName, String description, Integer calculationMethod, Integer sortOrder) {
private PromotionFeeTypePO createPromotionFeeTypePO(Long companyId, String typeName, String description, Integer calculationMethod, Integer sortOrder) {
PromotionFeeTypePO po = new PromotionFeeTypePO();
po.setCompanyId(companyId);
po.setTypeCode(typeCode);
po.setTypeName(typeName);
po.setDescription(description);
po.setCalculationMethod(calculationMethod);
@@ -22,7 +22,6 @@ import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaImageVO;
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
import org.springframework.web.multipart.MultipartFile;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
@@ -49,8 +48,7 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
// 验证店铺名称是否重复
LambdaQueryWrapper<ShopPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ShopPO::getName, createShopDTO.getName())
.eq(ShopPO::getCompanyId, companyId)
.isNull(ShopPO::getDeleteTime);
.eq(ShopPO::getCompanyId, companyId);
if (this.count(wrapper) > 0) {
throw new BusinessException("店铺名称已存在");
}
@@ -97,8 +95,7 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
LambdaQueryWrapper<ShopPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ShopPO::getName, updateShopDTO.getName())
.eq(ShopPO::getCompanyId, companyId)
.ne(ShopPO::getId, id)
.isNull(ShopPO::getDeleteTime);
.ne(ShopPO::getId, id);
if (this.count(wrapper) > 0) {
throw new BusinessException("店铺名称已存在");
}
@@ -140,13 +137,8 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
throw new BusinessException("店铺不存在");
}
// 软删除店铺
ShopPO shop = new ShopPO();
shop.setId(id);
shop.setDeleteTime(LocalDateTime.now());
shop.setDeleteBy(currentUserContext.getCurrentUserId());
this.updateById(shop);
// 硬删除店铺(外键约束会自动处理相关数据)
this.removeById(id);
}
@Override
@@ -159,8 +151,7 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
// 构建查询条件
LambdaQueryWrapper<ShopPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ShopPO::getCompanyId, companyId)
.isNull(ShopPO::getDeleteTime);
wrapper.eq(ShopPO::getCompanyId, companyId);
// 添加过滤条件
ShopFilterDTO filter = pageQueryDTO.getFilters();
@@ -202,8 +193,7 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
// 根据名称精准查询店铺
LambdaQueryWrapper<ShopPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ShopPO::getName, name)
.eq(ShopPO::getCompanyId, companyId)
.isNull(ShopPO::getDeleteTime);
.eq(ShopPO::getCompanyId, companyId);
ShopPO shop = this.getOne(wrapper);
if (shop == null) {
@@ -226,7 +216,6 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
LambdaQueryWrapper<ShopPO> wrapper = new LambdaQueryWrapper<>();
wrapper.in(ShopPO::getName, names)
.eq(ShopPO::getCompanyId, companyId)
.isNull(ShopPO::getDeleteTime)
.orderByAsc(ShopPO::getName);
List<ShopPO> shops = this.list(wrapper);
@@ -8,21 +8,17 @@ CREATE TABLE `ec_shop` (
`platform` VARCHAR(50) 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 '更新时间',
`delete_time` TIMESTAMP NULL DEFAULT NULL COMMENT '删除时间',
`create_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '创建人ID',
`update_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '更新人ID',
`delete_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '删除人ID',
PRIMARY KEY (`id`),
KEY `idx_company_id` (`company_id`),
KEY `fk_ec_shop_logo_image` (`logo_image_id`),
KEY `fk_ec_shop_creator` (`create_by`),
KEY `fk_ec_shop_updater` (`update_by`),
KEY `fk_ec_shop_deleter` (`delete_by`),
CONSTRAINT `fk_ec_shop_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_shop_logo_image` FOREIGN KEY (`logo_image_id`) REFERENCES `media_image` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_shop_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_shop_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_shop_deleter` FOREIGN KEY (`delete_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
CONSTRAINT `fk_ec_shop_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-店铺表';
-- 商品表
@@ -34,21 +30,17 @@ CREATE TABLE `ec_product` (
`main_image_id` BIGINT UNSIGNED DEFAULT NULL COMMENT '主图图片ID',
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`delete_time` TIMESTAMP NULL DEFAULT NULL COMMENT '删除时间',
`create_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '创建人ID',
`update_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '更新人ID',
`delete_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '删除人ID',
PRIMARY KEY (`id`),
KEY `idx_company_id` (`company_id`),
KEY `fk_ec_product_main_image` (`main_image_id`),
KEY `fk_ec_product_creator` (`create_by`),
KEY `fk_ec_product_updater` (`update_by`),
KEY `fk_ec_product_deleter` (`delete_by`),
CONSTRAINT `fk_ec_product_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_product_main_image` FOREIGN KEY (`main_image_id`) REFERENCES `media_image` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_product_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_product_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_product_deleter` FOREIGN KEY (`delete_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
CONSTRAINT `fk_ec_product_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-商品表(含成本价)';
-- 商品规格表
@@ -61,51 +53,42 @@ CREATE TABLE `ec_product_spec` (
`cost_price` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '成本价',
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`delete_time` TIMESTAMP NULL DEFAULT NULL COMMENT '删除时间',
`create_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '创建人ID',
`update_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '更新人ID',
`delete_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '删除人ID',
PRIMARY KEY (`id`),
KEY `idx_company_id` (`company_id`),
KEY `idx_product_id` (`product_id`),
KEY `idx_spec_code` (`spec_code`),
KEY `fk_ec_spec_creator` (`create_by`),
KEY `fk_ec_spec_updater` (`update_by`),
KEY `fk_ec_spec_deleter` (`delete_by`),
CONSTRAINT `fk_ec_spec_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_spec_product` FOREIGN KEY (`product_id`) REFERENCES `ec_product` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_spec_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_spec_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_spec_deleter` FOREIGN KEY (`delete_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
CONSTRAINT `fk_ec_spec_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_order_status` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '状态ID',
`company_id` BIGINT UNSIGNED NOT NULL COMMENT '公司ID',
`status_code` TINYINT NOT NULL COMMENT '状态码',
`status_name` VARCHAR(50) NOT NULL COMMENT '状态名称',
`description` VARCHAR(200) DEFAULT NULL COMMENT '状态描述',
`sort_order` INT NOT NULL DEFAULT 0 COMMENT '排序',
`is_active` 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 '更新时间',
`delete_time` TIMESTAMP NULL DEFAULT NULL COMMENT '删除时间',
`create_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '创建人ID',
`update_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '更新人ID',
`delete_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '删除人ID',
PRIMARY KEY (`id`),
KEY `idx_company_id` (`company_id`),
UNIQUE KEY `uk_company_status_code` (`company_id`, `status_code`),
UNIQUE KEY `uk_company_status_name` (`company_id`, `status_name`),
KEY `idx_sort_order` (`sort_order`),
KEY `idx_is_active` (`is_active`),
KEY `fk_ec_order_status_creator` (`create_by`),
KEY `fk_ec_order_status_updater` (`update_by`),
KEY `fk_ec_order_status_deleter` (`delete_by`),
CONSTRAINT `fk_ec_order_status_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_order_status_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_order_status_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_order_status_deleter` FOREIGN KEY (`delete_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
CONSTRAINT `fk_ec_order_status_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-订单状态表';
-- 订单表
@@ -115,34 +98,6 @@ CREATE TABLE `ec_order` (
`shop_id` BIGINT UNSIGNED NOT NULL COMMENT '店铺ID',
`platform_order_no` VARCHAR(100) DEFAULT NULL COMMENT '平台订单号',
`status_id` BIGINT UNSIGNED NOT NULL COMMENT '订单状态ID',
`received_amount` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '商家实收金额',
`shipping_fee` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '运费',
`order_date` 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 '更新时间',
`delete_time` TIMESTAMP NULL DEFAULT NULL COMMENT '删除时间',
`create_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '创建人ID',
`update_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '更新人ID',
`delete_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '删除人ID',
PRIMARY KEY (`id`),
KEY `idx_company_shop_date` (`company_id`, `shop_id`, `order_date`),
KEY `idx_status_id` (`status_id`),
KEY `idx_platform_order_no` (`platform_order_no`),
KEY `fk_ec_order_creator` (`create_by`),
KEY `fk_ec_order_updater` (`update_by`),
KEY `fk_ec_order_deleter` (`delete_by`),
CONSTRAINT `fk_ec_order_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_order_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE 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_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,
CONSTRAINT `fk_ec_order_deleter` FOREIGN KEY (`delete_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-订单表';
-- 订单明细表
CREATE TABLE `ec_order_item` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '订单明细ID',
`order_id` BIGINT UNSIGNED NOT NULL COMMENT '订单ID',
`product_id` BIGINT UNSIGNED NOT NULL COMMENT '商品ID',
`product_spec_id` BIGINT UNSIGNED DEFAULT NULL COMMENT '商品规格ID',
`product_name` VARCHAR(255) NOT NULL COMMENT '商品名称(冗余存储)',
@@ -150,34 +105,36 @@ CREATE TABLE `ec_order_item` (
`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 '成本价(下单时快照)',
`subtotal` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '小计金额',
`cost_total` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '成本小计',
`received_amount` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '商家实收金额',
`shipping_fee` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '运费',
`order_date` 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 '更新时间',
`delete_time` TIMESTAMP NULL DEFAULT NULL COMMENT '删除时间',
`create_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '创建人ID',
`update_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '更新人ID',
`delete_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '删除人ID',
PRIMARY KEY (`id`),
KEY `idx_order_id` (`order_id`),
KEY `idx_company_shop_date` (`company_id`, `shop_id`, `order_date`),
KEY `idx_status_id` (`status_id`),
KEY `idx_platform_order_no` (`platform_order_no`),
KEY `idx_product_id` (`product_id`),
KEY `idx_product_spec_id` (`product_spec_id`),
KEY `fk_ec_order_item_creator` (`create_by`),
KEY `fk_ec_order_item_updater` (`update_by`),
KEY `fk_ec_order_item_deleter` (`delete_by`),
CONSTRAINT `fk_ec_order_item_order` FOREIGN KEY (`order_id`) REFERENCES `ec_order` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_order_item_product` FOREIGN KEY (`product_id`) REFERENCES `ec_product` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_order_item_product_spec` FOREIGN KEY (`product_spec_id`) REFERENCES `ec_product_spec` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_order_item_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_order_item_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_order_item_deleter` FOREIGN KEY (`delete_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-订单明细表';
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,
CONSTRAINT `fk_ec_order_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE 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_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_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='电商-订单表(含商品明细)';
-- 推广费类型表
CREATE TABLE `ec_promotion_fee_type` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '推广费类型ID',
`company_id` BIGINT UNSIGNED NOT NULL COMMENT '公司ID',
`type_code` VARCHAR(50) NOT NULL COMMENT '类型编码',
`type_name` VARCHAR(100) NOT NULL COMMENT '类型名称',
`description` VARCHAR(200) DEFAULT NULL COMMENT '类型描述',
`calculation_method` TINYINT NOT NULL DEFAULT 1 COMMENT '计算方式 1固定金额 2按比例 3按点击 4按展示',
@@ -185,22 +142,18 @@ CREATE TABLE `ec_promotion_fee_type` (
`is_active` 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 '更新时间',
`delete_time` TIMESTAMP NULL DEFAULT NULL COMMENT '删除时间',
`create_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '创建人ID',
`update_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '更新人ID',
`delete_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '删除人ID',
PRIMARY KEY (`id`),
KEY `idx_company_id` (`company_id`),
UNIQUE KEY `uk_company_type_code` (`company_id`, `type_code`),
UNIQUE KEY `uk_company_type_name` (`company_id`, `type_name`),
KEY `idx_sort_order` (`sort_order`),
KEY `idx_is_active` (`is_active`),
KEY `fk_ec_promotion_fee_type_creator` (`create_by`),
KEY `fk_ec_promotion_fee_type_updater` (`update_by`),
KEY `fk_ec_promotion_fee_type_deleter` (`delete_by`),
CONSTRAINT `fk_ec_promotion_fee_type_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_promotion_fee_type_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_promotion_fee_type_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_promotion_fee_type_deleter` FOREIGN KEY (`delete_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
CONSTRAINT `fk_ec_promotion_fee_type_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-推广费类型表';
-- 推广费记录表
@@ -222,10 +175,8 @@ CREATE TABLE `ec_promotion_fee` (
`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 '更新时间',
`delete_time` TIMESTAMP NULL DEFAULT NULL COMMENT '删除时间',
`create_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '创建人ID',
`update_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '更新人ID',
`delete_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '删除人ID',
PRIMARY KEY (`id`),
KEY `idx_company_id` (`company_id`),
KEY `idx_shop_id` (`shop_id`),
@@ -234,13 +185,11 @@ CREATE TABLE `ec_promotion_fee` (
KEY `idx_platform` (`platform`),
KEY `fk_ec_promotion_fee_creator` (`create_by`),
KEY `fk_ec_promotion_fee_updater` (`update_by`),
KEY `fk_ec_promotion_fee_deleter` (`delete_by`),
CONSTRAINT `fk_ec_promotion_fee_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_promotion_fee_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_promotion_fee_type` FOREIGN KEY (`fee_type_id`) REFERENCES `ec_promotion_fee_type` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT `fk_ec_promotion_fee_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_promotion_fee_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_promotion_fee_deleter` FOREIGN KEY (`delete_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
CONSTRAINT `fk_ec_promotion_fee_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-推广费记录表';
-- 注意:推广费类型初始数据现在通过服务层方法按公司插入,不再在此处插入
@@ -26,8 +26,12 @@ public class CurrentUserContext {
*/
public TokenPayload getCurrentUserPayload() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null || authentication.getCredentials() == null) {
throw new BusinessException("用户未登录");
if (authentication == null) {
throw new BusinessException("用户未登录 - 认证信息为空");
}
if (authentication.getCredentials() == null) {
throw new BusinessException("用户未登录 - Token信息为空");
}
String token = authentication.getCredentials().toString();