diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/platform/service/PlatformService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/platform/service/PlatformService.java index 04e7c5ba..934d9305 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/platform/service/PlatformService.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/platform/service/PlatformService.java @@ -54,4 +54,12 @@ public interface PlatformService extends IService { * @return 平台列表 */ List getActivePlatforms(); + + /** + * 为新公司初始化平台数据(从平台公共数据复制) + * + * @param companyId 公司ID + * @param creatorId 创建人ID + */ + void initPlatformsForCompany(Long companyId, Long creatorId); } diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/platform/service/impl/PlatformServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/platform/service/impl/PlatformServiceImpl.java index 58b4dd3a..7516fa33 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/platform/service/impl/PlatformServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/platform/service/impl/PlatformServiceImpl.java @@ -209,4 +209,46 @@ public class PlatformServiceImpl extends ServiceImpl BeanUtils.copyProperties(platform, vo); return vo; } + + /** + * 为新公司初始化平台数据(确保全局平台数据存在) + * 如果平台表为空,则插入初始平台数据 + * + * @param companyId 公司ID(预留参数,用于未来公司级平台配置扩展) + * @param creatorId 创建人ID + */ + @Override + public void initPlatformsForCompany(Long companyId, Long creatorId) { + // 检查是否已经有平台数据 + if (this.count() > 0) { + return; // 已有平台数据,无需初始化 + } + + // 插入初始平台数据 + List initialPlatforms = List.of( + createPlatform("淘宝", "taobao", 1, creatorId), + createPlatform("京东", "jd", 2, creatorId), + createPlatform("拼多多", "pdd", 3, creatorId), + createPlatform("抖音", "douyin", 4, creatorId), + createPlatform("快手", "kuaishou", 5, creatorId), + createPlatform("小红书", "xiaohongshu", 6, creatorId), + createPlatform("天猫", "tmall", 7, creatorId), + createPlatform("唯品会", "vip", 8, creatorId), + createPlatform("苏宁", "suning", 9, creatorId), + createPlatform("1688", "1688", 10, creatorId) + ); + + this.saveBatch(initialPlatforms); + } + + private PlatformPO createPlatform(String name, String code, int sortOrder, Long creatorId) { + PlatformPO platform = new PlatformPO(); + platform.setPlatformName(name); + platform.setPlatformCode(code); + platform.setSortOrder(sortOrder); + platform.setIsActive(1); + platform.setCreateBy(creatorId); + platform.setUpdateBy(creatorId); + return platform; + } } diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/company/service/impl/CompanyServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/company/service/impl/CompanyServiceImpl.java index a3f5d3cc..1300b063 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/company/service/impl/CompanyServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/company/service/impl/CompanyServiceImpl.java @@ -19,6 +19,7 @@ import top.xyquan.ecomdmbbackend.modules.org.company.model.vo.CompanyVO; import top.xyquan.ecomdmbbackend.modules.org.company.service.CompanyService; import top.xyquan.ecomdmbbackend.modules.sys.file.service.SysFileService; import top.xyquan.ecomdmbbackend.modules.sys.file.model.vo.SysFileUploadVO; +import top.xyquan.ecomdmbbackend.modules.ecom.platform.service.PlatformService; import top.xyquan.ecomdmbbackend.modules.ecom.promotion.service.PromotionFeeTypeService; import top.xyquan.ecomdmbbackend.modules.org.company.menu.service.CompanyMenuService; import top.xyquan.ecomdmbbackend.modules.org.department.service.DepartmentService; @@ -52,6 +53,7 @@ public class CompanyServiceImpl extends ServiceImpl im private final CurrentUserContext currentUserContext; private final SysFileService sysFileService; private final PromotionFeeTypeService promotionFeeTypeService; + private final PlatformService platformService; private final CompanyMenuService companyMenuService; private final DepartmentService departmentService; private final PositionService positionService; @@ -62,6 +64,7 @@ public class CompanyServiceImpl extends ServiceImpl im public CompanyServiceImpl(@Lazy CurrentUserContext currentUserContext, SysFileService sysFileService, PromotionFeeTypeService promotionFeeTypeService, + PlatformService platformService, CompanyMenuService companyMenuService, DepartmentService departmentService, PositionService positionService, MenuService menuService, @Lazy UserService userService, @Lazy CompanyMemberService companyMemberService, @@ -69,6 +72,7 @@ public class CompanyServiceImpl extends ServiceImpl im this.currentUserContext = currentUserContext; this.sysFileService = sysFileService; this.promotionFeeTypeService = promotionFeeTypeService; + this.platformService = platformService; this.companyMenuService = companyMenuService; this.departmentService = departmentService; this.positionService = positionService; @@ -135,6 +139,9 @@ public class CompanyServiceImpl extends ServiceImpl im // 初始化推广费类型数据 promotionFeeTypeService.initPromotionFeeTypeForCompany(company.getId(), creatorId); + // 初始化平台数据(确保全局平台数据存在) + platformService.initPlatformsForCompany(company.getId(), creatorId); + // 初始化公司菜单(非超级菜单) initCompanyMenus(company.getId());