最近一丢丢

This commit is contained in:
ah--desktop
2025-09-16 23:01:25 +08:00
parent 2b750585d1
commit dde50d2bd6
30 changed files with 1518 additions and 659 deletions
@@ -18,7 +18,7 @@ import java.util.List;
* 订单状态控制器
*/
@RestController
@RequestMapping("/api/ec/order-status")
@RequestMapping("/ec/order-status")
@RequiredArgsConstructor
@Tag(name = "电商-订单状态管理", description = "订单状态相关接口")
public class OrderStatusController {
@@ -68,4 +68,12 @@ public class OrderStatusController {
List<OrderStatusVO> list = orderStatusService.getAllOrderStatusList();
return ApiResponse.success(list);
}
@PostMapping("/init")
@Operation(summary = "初始化订单状态数据", description = "为当前公司初始化默认的订单状态数据")
public ApiResponse<Void> initOrderStatus() {
// 这里需要从CurrentUserContext获取当前公司ID,但为了保持接口简洁,我们修改服务层方法
orderStatusService.initOrderStatusForCurrentCompany();
return ApiResponse.success();
}
}
@@ -19,7 +19,7 @@ import top.xyquan.ecomdmbbackend.modules.ec.service.PromotionFeeService;
* 推广费记录控制器
*/
@RestController
@RequestMapping("/api/ec/promotion-fee")
@RequestMapping("/ec/promotion-fee")
@RequiredArgsConstructor
@Tag(name = "电商-推广费记录管理", description = "推广费记录相关接口")
public class PromotionFeeController {
@@ -18,7 +18,7 @@ import java.util.List;
* 推广费类型控制器
*/
@RestController
@RequestMapping("/api/ec/promotion-fee-type")
@RequestMapping("/ec/promotion-fee-type")
@RequiredArgsConstructor
@Tag(name = "电商-推广费类型管理", description = "推广费类型相关接口")
public class PromotionFeeTypeController {
@@ -68,4 +68,11 @@ public class PromotionFeeTypeController {
List<PromotionFeeTypeVO> list = promotionFeeTypeService.getAllPromotionFeeTypeList();
return ApiResponse.success(list);
}
@PostMapping("/init")
@Operation(summary = "初始化推广费类型数据", description = "为当前公司初始化默认的推广费类型数据")
public ApiResponse<Void> initPromotionFeeType() {
promotionFeeTypeService.initPromotionFeeTypeForCurrentCompany();
return ApiResponse.success();
}
}
@@ -20,6 +20,12 @@ public class OrderStatusPO {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 公司ID
*/
@TableField("company_id")
private Long companyId;
/**
* 状态码
*/
@@ -20,6 +20,12 @@ public class PromotionFeeTypePO {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 公司ID
*/
@TableField("company_id")
private Long companyId;
/**
* 类型编码
*/
@@ -18,6 +18,12 @@ public class OrderStatusVO {
@Schema(description = "状态ID", example = "1")
private Long id;
/**
* 公司ID
*/
@Schema(description = "公司ID", example = "1")
private Long companyId;
/**
* 状态码
*/
@@ -18,6 +18,12 @@ public class PromotionFeeTypeVO {
@Schema(description = "推广费类型ID", example = "1")
private Long id;
/**
* 公司ID
*/
@Schema(description = "公司ID", example = "1")
private Long companyId;
/**
* 类型编码
*/
@@ -40,4 +40,14 @@ public interface OrderStatusService {
* 查询所有订单状态列表
*/
List<OrderStatusVO> getAllOrderStatusList();
/**
* 初始化公司订单状态数据
*/
void initOrderStatusForCompany(Long companyId);
/**
* 初始化当前公司订单状态数据
*/
void initOrderStatusForCurrentCompany();
}
@@ -40,4 +40,14 @@ public interface PromotionFeeTypeService {
* 查询所有推广费类型列表
*/
List<PromotionFeeTypeVO> getAllPromotionFeeTypeList();
/**
* 初始化公司推广费类型数据
*/
void initPromotionFeeTypeForCompany(Long companyId);
/**
* 初始化当前公司推广费类型数据
*/
void initPromotionFeeTypeForCurrentCompany();
}
@@ -29,8 +29,18 @@ 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);
if (orderStatusMapper.selectCount(wrapper) > 0) {
throw new RuntimeException("该状态码已存在");
}
OrderStatusPO po = new OrderStatusPO();
BeanUtils.copyProperties(dto, po);
po.setCompanyId(currentUserContext.getCurrentCompanyId());
po.setCreateBy(currentUserContext.getCurrentUserId());
po.setUpdateBy(currentUserContext.getCurrentUserId());
@@ -74,7 +84,8 @@ public class OrderStatusServiceImpl implements OrderStatusService {
@Override
public List<OrderStatusVO> getActiveOrderStatusList() {
LambdaQueryWrapper<OrderStatusPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(OrderStatusPO::getIsActive, 1) // 1表示启用状态
wrapper.eq(OrderStatusPO::getCompanyId, currentUserContext.getCurrentCompanyId())
.eq(OrderStatusPO::getIsActive, 1) // 1表示启用状态
.isNull(OrderStatusPO::getDeleteTime)
.orderByAsc(OrderStatusPO::getSortOrder);
@@ -91,7 +102,8 @@ public class OrderStatusServiceImpl implements OrderStatusService {
@Override
public List<OrderStatusVO> getAllOrderStatusList() {
LambdaQueryWrapper<OrderStatusPO> wrapper = new LambdaQueryWrapper<>();
wrapper.isNull(OrderStatusPO::getDeleteTime)
wrapper.eq(OrderStatusPO::getCompanyId, currentUserContext.getCurrentCompanyId())
.isNull(OrderStatusPO::getDeleteTime)
.orderByAsc(OrderStatusPO::getSortOrder);
List<OrderStatusPO> poList = orderStatusMapper.selectList(wrapper);
@@ -103,4 +115,63 @@ public class OrderStatusServiceImpl implements OrderStatusService {
})
.collect(Collectors.toList());
}
/**
* 初始化公司订单状态数据
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void initOrderStatusForCompany(Long companyId) {
// 检查是否已经初始化过
LambdaQueryWrapper<OrderStatusPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(OrderStatusPO::getCompanyId, companyId)
.isNull(OrderStatusPO::getDeleteTime);
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)
);
// 批量插入
for (OrderStatusPO status : initialStatuses) {
orderStatusMapper.insert(status);
}
}
/**
* 初始化当前公司订单状态数据
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void initOrderStatusForCurrentCompany() {
Long companyId = currentUserContext.getCurrentCompanyId();
if (companyId == null) {
throw new RuntimeException("用户未关联公司");
}
initOrderStatusForCompany(companyId);
}
/**
* 创建订单状态PO对象
*/
private OrderStatusPO createOrderStatusPO(Long companyId, Integer statusCode, 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);
po.setIsActive(1);
po.setCreateBy(1L); // 系统初始化
po.setUpdateBy(1L);
return po;
}
}
@@ -29,8 +29,18 @@ 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);
if (promotionFeeTypeMapper.selectCount(wrapper) > 0) {
throw new RuntimeException("该类型编码已存在");
}
PromotionFeeTypePO po = new PromotionFeeTypePO();
BeanUtils.copyProperties(dto, po);
po.setCompanyId(currentUserContext.getCurrentCompanyId());
po.setCreateBy(currentUserContext.getCurrentUserId());
po.setUpdateBy(currentUserContext.getCurrentUserId());
@@ -95,7 +105,13 @@ public class PromotionFeeTypeServiceImpl implements PromotionFeeTypeService {
@Override
public List<PromotionFeeTypeVO> getActivePromotionFeeTypeList() {
List<PromotionFeeTypePO> poList = promotionFeeTypeMapper.selectActiveTypeList();
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);
return poList.stream()
.map(po -> {
PromotionFeeTypeVO vo = new PromotionFeeTypeVO();
@@ -130,7 +146,8 @@ public class PromotionFeeTypeServiceImpl implements PromotionFeeTypeService {
@Override
public List<PromotionFeeTypeVO> getAllPromotionFeeTypeList() {
LambdaQueryWrapper<PromotionFeeTypePO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PromotionFeeTypePO::getDeleteTime, null)
wrapper.eq(PromotionFeeTypePO::getCompanyId, currentUserContext.getCurrentCompanyId())
.isNull(PromotionFeeTypePO::getDeleteTime)
.orderByAsc(PromotionFeeTypePO::getSortOrder);
List<PromotionFeeTypePO> poList = promotionFeeTypeMapper.selectList(wrapper);
@@ -164,4 +181,66 @@ public class PromotionFeeTypeServiceImpl implements PromotionFeeTypeService {
})
.collect(Collectors.toList());
}
/**
* 初始化公司推广费类型数据
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void initPromotionFeeTypeForCompany(Long companyId) {
// 检查是否已经初始化过
LambdaQueryWrapper<PromotionFeeTypePO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PromotionFeeTypePO::getCompanyId, companyId)
.isNull(PromotionFeeTypePO::getDeleteTime);
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)
);
// 批量插入
for (PromotionFeeTypePO type : initialTypes) {
promotionFeeTypeMapper.insert(type);
}
}
/**
* 初始化当前公司推广费类型数据
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void initPromotionFeeTypeForCurrentCompany() {
Long companyId = currentUserContext.getCurrentCompanyId();
if (companyId == null) {
throw new RuntimeException("用户未关联公司");
}
initPromotionFeeTypeForCompany(companyId);
}
/**
* 创建推广费类型PO对象
*/
private PromotionFeeTypePO createPromotionFeeTypePO(Long companyId, String typeCode, 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);
po.setSortOrder(sortOrder);
po.setIsActive(1);
po.setCreateBy(1L); // 系统初始化
po.setUpdateBy(1L);
return po;
}
}
@@ -19,6 +19,8 @@ import top.xyquan.ecomdmbbackend.modules.org.model.vo.CompanyVO;
import top.xyquan.ecomdmbbackend.modules.org.service.CompanyService;
import top.xyquan.ecomdmbbackend.modules.media.service.MediaImageService;
import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaImageVO;
import top.xyquan.ecomdmbbackend.modules.ec.service.OrderStatusService;
import top.xyquan.ecomdmbbackend.modules.ec.service.PromotionFeeTypeService;
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
import org.springframework.web.multipart.MultipartFile;
@@ -34,10 +36,14 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, CompanyPO> im
private final CurrentUserContext currentUserContext;
private final MediaImageService mediaImageService;
private final OrderStatusService orderStatusService;
private final PromotionFeeTypeService promotionFeeTypeService;
public CompanyServiceImpl(CurrentUserContext currentUserContext, MediaImageService mediaImageService) {
public CompanyServiceImpl(CurrentUserContext currentUserContext, MediaImageService mediaImageService, OrderStatusService orderStatusService, PromotionFeeTypeService promotionFeeTypeService) {
this.currentUserContext = currentUserContext;
this.mediaImageService = mediaImageService;
this.orderStatusService = orderStatusService;
this.promotionFeeTypeService = promotionFeeTypeService;
}
@Override
@@ -73,6 +79,12 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, CompanyPO> im
// 保存公司
this.save(company);
// 初始化订单状态数据
orderStatusService.initOrderStatusForCompany(company.getId());
// 初始化推广费类型数据
promotionFeeTypeService.initPromotionFeeTypeForCompany(company.getId());
// 转换为VO并返回
return convertToVO(company);
}
@@ -82,6 +82,7 @@ CREATE TABLE `ec_product_spec` (
-- 订单状态表
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 '状态描述',
@@ -94,26 +95,19 @@ CREATE TABLE `ec_order_status` (
`update_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '更新人ID',
`delete_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '删除人ID',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_status_code` (`status_code`),
KEY `idx_company_id` (`company_id`),
UNIQUE KEY `uk_company_status_code` (`company_id`, `status_code`),
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
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-订单状态表';
-- 插入订单状态初始数据
INSERT INTO `ec_order_status` (`status_code`, `status_name`, `description`, `sort_order`, `is_active`) VALUES
(0, '待发货', '订单已创建,等待发货', 1, 1),
(1, '已发货', '商品已发出,运输中', 2, 1),
(2, '已完成', '订单已完成,交易成功', 3, 1),
(3, '已取消', '订单已取消', 4, 1),
(4, '退款中', '正在处理退款', 5, 1),
(5, '已退款', '退款已完成', 6, 1);
-- 订单表
CREATE TABLE `ec_order` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '订单ID',
@@ -182,6 +176,7 @@ CREATE TABLE `ec_order_item` (
-- 推广费类型表
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 '类型描述',
@@ -195,12 +190,14 @@ CREATE TABLE `ec_promotion_fee_type` (
`update_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '更新人ID',
`delete_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '删除人ID',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_type_code` (`type_code`),
KEY `idx_company_id` (`company_id`),
UNIQUE KEY `uk_company_type_code` (`company_id`, `type_code`),
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
@@ -246,13 +243,4 @@ CREATE TABLE `ec_promotion_fee` (
CONSTRAINT `fk_ec_promotion_fee_deleter` FOREIGN KEY (`delete_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-推广费记录表';
-- 插入推广费类型初始数据
INSERT INTO `ec_promotion_fee_type` (`type_code`, `type_name`, `description`, `calculation_method`, `sort_order`, `is_active`) VALUES
('DIRECT_TRAFFIC', '直通车', '淘宝直通车推广费用', 3, 1, 1),
('DIAMOND_DISPLAY', '钻展', '钻石展位推广费用', 4, 2, 1),
('SUPER_RECOMMEND', '超级推荐', '超级推荐推广费用', 3, 3, 1),
('PLATFORM_COMMISSION', '平台佣金', '平台交易佣金', 2, 4, 1),
('DISTRIBUTION_COMMISSION', '分销佣金', '分销商佣金', 2, 5, 1),
('ACTIVITY_FEE', '活动费用', '平台活动参与费用', 1, 6, 1),
('EXTERNAL_AD', '站外广告', '站外广告投放费用', 1, 7, 1),
('LIVE_STREAMING', '直播推广', '直播推广费用', 1, 8, 1);
-- 注意:推广费类型初始数据现在通过服务层方法按公司插入,不再在此处插入