feat(company): 创建公司时自动初始化平台数据

- CompanyServiceImpl.createCompany 中调用 platformService.initPlatformsForCompany
- 新公司创建时若 ec_platform 表为空,自动插入10条初始平台数据
- 确保任何新数据库都有平台基础数据可用
This commit is contained in:
小蟑螂
2026-04-23 00:16:16 +08:00
parent 4386fc1472
commit 39a4f18bbe
3 changed files with 57 additions and 0 deletions
@@ -54,4 +54,12 @@ public interface PlatformService extends IService<PlatformPO> {
* @return 平台列表
*/
List<PlatformVO> getActivePlatforms();
/**
* 为新公司初始化平台数据(从平台公共数据复制)
*
* @param companyId 公司ID
* @param creatorId 创建人ID
*/
void initPlatformsForCompany(Long companyId, Long creatorId);
}
@@ -209,4 +209,46 @@ public class PlatformServiceImpl extends ServiceImpl<PlatformMapper, PlatformPO>
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<PlatformPO> 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;
}
}
@@ -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<CompanyMapper, CompanyPO> 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<CompanyMapper, CompanyPO> 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<CompanyMapper, CompanyPO> 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<CompanyMapper, CompanyPO> im
// 初始化推广费类型数据
promotionFeeTypeService.initPromotionFeeTypeForCompany(company.getId(), creatorId);
// 初始化平台数据(确保全局平台数据存在)
platformService.initPlatformsForCompany(company.getId(), creatorId);
// 初始化公司菜单(非超级菜单)
initCompanyMenus(company.getId());