feat(ecom-dmb): ec_platform 表增加 company_id 字段

- ec_platform 表增加 company_id 字段,关联 org_company
- PlatformPO/VO/DTO 增加 companyId 字段
- PlatformServiceImpl 所有查询增加 companyId 过滤
- CompanyOverviewServiceImpl/ExportServiceImpl/ShopServiceImpl 平台查询增加 companyId 限制
- 数据库已更新,所有平台绑定到公司ID=3(秦华科技有限公司)
This commit is contained in:
小蟑螂
2026-04-23 12:12:43 +08:00
parent cfc0078aba
commit 51c5e38b58
11 changed files with 154 additions and 80 deletions
@@ -592,7 +592,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
CompanyOverviewVO.ShopComparison comparison = new CompanyOverviewVO.ShopComparison();
comparison.setShopId(shop.getId());
comparison.setShopName(shop.getName());
comparison.setPlatform(shop.getPlatformId() != null ? platformMapper.selectById(shop.getPlatformId()).getPlatformName() : null);
comparison.setPlatform(shop.getPlatformId() != null ? getPlatformNameById(shop.getPlatformId()) : null);
comparison.setTargetOrderCount(targetOrderCount);
comparison.setOrderCountAchievementRate(orderCountAchievementRate);
comparison.setTargetAmount(targetAmount);
@@ -913,8 +913,10 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
List<CompanyOverviewVO.PlatformSummary> platformSummaries = new ArrayList<>();
// 获取所有平台
List<PlatformPO> allPlatforms = platformMapper.selectList(null);
// 获取当前公司的所有平台
LambdaQueryWrapper<PlatformPO> platformWrapper = new LambdaQueryWrapper<>();
platformWrapper.eq(PlatformPO::getCompanyId, companyId);
List<PlatformPO> allPlatforms = platformMapper.selectList(platformWrapper);
Map<Long, PlatformPO> platformMap = allPlatforms.stream()
.collect(Collectors.toMap(PlatformPO::getId, p -> p));
@@ -1108,5 +1110,15 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
platformSummaries.sort(Comparator.comparing(CompanyOverviewVO.PlatformSummary::getSalesAmount).reversed());
return platformSummaries;
}
private String getPlatformNameById(Long platformId) {
if (platformId == null) return null;
Long companyId = currentUserContext.getCurrentCompanyId();
LambdaQueryWrapper<PlatformPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PlatformPO::getId, platformId)
.eq(PlatformPO::getCompanyId, companyId);
PlatformPO platform = platformMapper.selectOne(wrapper);
return platform != null ? platform.getPlatformName() : null;
}
}
@@ -1157,7 +1157,7 @@ public class ExportServiceImpl implements ExportService {
Map<String, Object> data = new HashMap<>();
data.put("shopName", shop.getName());
data.put("platform", shop.getPlatformId() != null ? platformMapper.selectById(shop.getPlatformId()).getPlatformName() : null);
data.put("platform", shop.getPlatformId() != null ? getPlatformNameById(shop.getPlatformId()) : null);
data.put("salesAmount", salesAmount);
data.put("orderCount", orderCount);
data.put("avgOrderValue", avgOrderValue);
@@ -1315,8 +1315,10 @@ public class ExportServiceImpl implements ExportService {
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
// 获取所有平台信息
List<PlatformPO> allPlatforms = platformMapper.selectList(null);
// 获取当前公司的所有平台信息
LambdaQueryWrapper<PlatformPO> platformWrapper = new LambdaQueryWrapper<>();
platformWrapper.eq(PlatformPO::getCompanyId, companyId);
List<PlatformPO> allPlatforms = platformMapper.selectList(platformWrapper);
Map<Long, PlatformPO> platformMap = allPlatforms.stream()
.collect(Collectors.toMap(PlatformPO::getId, p -> p));
@@ -1570,4 +1572,14 @@ public class ExportServiceImpl implements ExportService {
sheet.setColumnWidth(i, 3200);
}
}
private String getPlatformNameById(Long platformId) {
if (platformId == null) return null;
Long companyId = currentUserContext.getCurrentCompanyId();
LambdaQueryWrapper<PlatformPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PlatformPO::getId, platformId)
.eq(PlatformPO::getCompanyId, companyId);
PlatformPO platform = platformMapper.selectOne(wrapper);
return platform != null ? platform.getPlatformName() : null;
}
}
@@ -42,4 +42,10 @@ public class CreatePlatformDTO {
*/
@Schema(description = "是否启用 0禁用 1启用", example = "1")
private Integer isActive;
/**
* 所属公司ID
*/
@Schema(description = "所属公司ID", example = "1")
private Long companyId;
}
@@ -27,4 +27,10 @@ public class PlatformFilterDTO {
*/
@Schema(description = "是否启用 0禁用 1启用", example = "1")
private Integer isActive;
/**
* 所属公司ID
*/
@Schema(description = "所属公司ID", example = "1")
private Long companyId;
}
@@ -45,4 +45,10 @@ public class UpdatePlatformDTO {
@Schema(description = "是否启用 0禁用 1启用", example = "1")
@NotNull(message = "是否启用不能为空")
private Integer isActive;
/**
* 所属公司ID
*/
@Schema(description = "所属公司ID", example = "1")
private Long companyId;
}
@@ -20,6 +20,12 @@ public class PlatformPO {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 所属公司ID
*/
@TableField("company_id")
private Long companyId;
/**
* 平台名称(如淘宝、京东、拼多多、抖音)
*/
@@ -18,6 +18,12 @@ public class PlatformVO {
@Schema(description = "平台ID", example = "1")
private Long id;
/**
* 所属公司ID
*/
@Schema(description = "所属公司ID", example = "1")
private Long companyId;
/**
* 平台名称
*/
@@ -34,25 +34,23 @@ public class PlatformServiceImpl extends ServiceImpl<PlatformMapper, PlatformPO>
this.currentUserContext = currentUserContext;
}
/**
* 创建平台
*
* @param createPlatformDTO 创建平台DTO
* @return 平台VO
*/
@Override
@Transactional
public PlatformVO createPlatform(CreatePlatformDTO createPlatformDTO) {
// 验证平台名称是否重复
Long companyId = currentUserContext.getCurrentCompanyId();
// 验证平台名称是否重复(同一公司下)
LambdaQueryWrapper<PlatformPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PlatformPO::getPlatformName, createPlatformDTO.getPlatformName());
wrapper.eq(PlatformPO::getCompanyId, companyId)
.eq(PlatformPO::getPlatformName, createPlatformDTO.getPlatformName());
if (this.count(wrapper) > 0) {
throw new BusinessException("平台名称已存在");
}
// 验证平台代码是否重复
// 验证平台代码是否重复(同一公司下)
wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PlatformPO::getPlatformCode, createPlatformDTO.getPlatformCode());
wrapper.eq(PlatformPO::getCompanyId, companyId)
.eq(PlatformPO::getPlatformCode, createPlatformDTO.getPlatformCode());
if (this.count(wrapper) > 0) {
throw new BusinessException("平台代码已存在");
}
@@ -60,6 +58,7 @@ public class PlatformServiceImpl extends ServiceImpl<PlatformMapper, PlatformPO>
// 创建平台
PlatformPO platform = new PlatformPO();
BeanUtils.copyProperties(createPlatformDTO, platform);
platform.setCompanyId(companyId);
// 设置默认值
if (platform.getSortOrder() == null) {
@@ -79,33 +78,30 @@ public class PlatformServiceImpl extends ServiceImpl<PlatformMapper, PlatformPO>
return convertToVO(platform);
}
/**
* 更新平台
*
* @param updatePlatformDTO 更新平台DTO
* @param id 平台ID
* @return 平台VO
*/
@Override
@Transactional
public PlatformVO updatePlatform(UpdatePlatformDTO updatePlatformDTO, Long id) {
Long companyId = currentUserContext.getCurrentCompanyId();
// 验证平台是否存在
PlatformPO existingPlatform = this.getById(id);
if (existingPlatform == null) {
throw new BusinessException("平台不存在");
}
// 验证平台名称是否重复(排除当前平台)
// 验证平台名称是否重复(排除当前平台,同一公司下)
LambdaQueryWrapper<PlatformPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PlatformPO::getPlatformName, updatePlatformDTO.getPlatformName())
wrapper.eq(PlatformPO::getCompanyId, companyId)
.eq(PlatformPO::getPlatformName, updatePlatformDTO.getPlatformName())
.ne(PlatformPO::getId, id);
if (this.count(wrapper) > 0) {
throw new BusinessException("平台名称已存在");
}
// 验证平台代码是否重复(排除当前平台)
// 验证平台代码是否重复(排除当前平台,同一公司下)
wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PlatformPO::getPlatformCode, updatePlatformDTO.getPlatformCode())
wrapper.eq(PlatformPO::getCompanyId, companyId)
.eq(PlatformPO::getPlatformCode, updatePlatformDTO.getPlatformCode())
.ne(PlatformPO::getId, id);
if (this.count(wrapper) > 0) {
throw new BusinessException("平台代码已存在");
@@ -115,6 +111,7 @@ public class PlatformServiceImpl extends ServiceImpl<PlatformMapper, PlatformPO>
PlatformPO platform = new PlatformPO();
BeanUtils.copyProperties(updatePlatformDTO, platform);
platform.setId(id);
platform.setCompanyId(companyId);
// 设置更新人ID
platform.setUpdateBy(currentUserContext.getCurrentUserId());
@@ -126,11 +123,6 @@ public class PlatformServiceImpl extends ServiceImpl<PlatformMapper, PlatformPO>
return convertToVO(platform);
}
/**
* 删除平台
*
* @param id 平台ID
*/
@Override
@Transactional
public void deletePlatform(Long id) {
@@ -144,18 +136,14 @@ public class PlatformServiceImpl extends ServiceImpl<PlatformMapper, PlatformPO>
this.removeById(id);
}
/**
* 分页获取平台列表
*
* @param pageQueryDTO 分页查询DTO
* @return 分页结果
*/
@Override
public PageResultVO<PlatformVO> getPlatformPage(PageQueryDTO<PlatformFilterDTO> pageQueryDTO) {
Long companyId = currentUserContext.getCurrentCompanyId();
PlatformFilterDTO filter = pageQueryDTO.getFilters() != null ? pageQueryDTO.getFilters() : new PlatformFilterDTO();
// 构建查询条件
LambdaQueryWrapper<PlatformPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PlatformPO::getCompanyId, companyId);
if (filter.getPlatformName() != null && !filter.getPlatformName().isEmpty()) {
wrapper.like(PlatformPO::getPlatformName, filter.getPlatformName());
}
@@ -182,15 +170,12 @@ public class PlatformServiceImpl extends ServiceImpl<PlatformMapper, PlatformPO>
return PageResultVO.create(voList, result.getTotal(), (int) pageQueryDTO.getPage(), (int) pageQueryDTO.getPageSize());
}
/**
* 获取所有启用的平台列表
*
* @return 平台列表
*/
@Override
public List<PlatformVO> getActivePlatforms() {
Long companyId = currentUserContext.getCurrentCompanyId();
LambdaQueryWrapper<PlatformPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PlatformPO::getIsActive, 1)
wrapper.eq(PlatformPO::getCompanyId, companyId)
.eq(PlatformPO::getIsActive, 1)
.orderByAsc(PlatformPO::getSortOrder);
return this.list(wrapper).stream()
@@ -198,51 +183,35 @@ public class PlatformServiceImpl extends ServiceImpl<PlatformMapper, PlatformPO>
.collect(Collectors.toList());
}
/**
* 转换为VO
*
* @param platform 平台实体
* @return 平台VO
*/
private PlatformVO convertToVO(PlatformPO platform) {
PlatformVO vo = new PlatformVO();
BeanUtils.copyProperties(platform, vo);
return vo;
}
/**
* 为新公司初始化平台数据(确保全局平台数据存在)
* 如果平台表为空,则插入初始平台数据
*
* @param companyId 公司ID(预留参数,用于未来公司级平台配置扩展)
* @param creatorId 创建人ID
*/
@Override
public void initPlatformsForCompany(Long companyId, Long creatorId) {
// 检查是否已经有平台数据
if (this.count() > 0) {
// 检查该公司是否已有平台数据
LambdaQueryWrapper<PlatformPO> checkWrapper = new LambdaQueryWrapper<>();
checkWrapper.eq(PlatformPO::getCompanyId, companyId);
if (this.count(checkWrapper) > 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)
createPlatform(companyId, "淘宝", "taobao", 1, creatorId),
createPlatform(companyId, "京东", "jd", 2, creatorId),
createPlatform(companyId, "拼多多", "pdd", 3, creatorId),
createPlatform(companyId, "抖音", "douyin", 4, creatorId),
createPlatform(companyId, "快手", "kuaishou", 5, creatorId),
createPlatform(companyId, "小红书", "xiaohongshu", 6, creatorId),
createPlatform(companyId, "天猫", "tmall", 7, creatorId),
createPlatform(companyId, "唯品会", "vip", 8, creatorId),
createPlatform(companyId, "苏宁", "suning", 9, creatorId),
createPlatform(companyId, "1688", "1688", 10, creatorId)
);
this.saveBatch(initialPlatforms);
}
private PlatformPO createPlatform(String name, String code, int sortOrder, Long creatorId) {
private PlatformPO createPlatform(Long companyId, String name, String code, int sortOrder, Long creatorId) {
PlatformPO platform = new PlatformPO();
platform.setCompanyId(companyId);
platform.setPlatformName(name);
platform.setPlatformCode(code);
platform.setSortOrder(sortOrder);
@@ -251,4 +220,10 @@ public class PlatformServiceImpl extends ServiceImpl<PlatformMapper, PlatformPO>
platform.setUpdateBy(creatorId);
return platform;
}
private PlatformVO convertToVO(PlatformPO platform) {
PlatformVO vo = new PlatformVO();
BeanUtils.copyProperties(platform, vo);
return vo;
}
}
@@ -272,7 +272,11 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
// 获取平台名称
if (shop.getPlatformId() != null) {
PlatformPO platform = platformMapper.selectById(shop.getPlatformId());
Long companyId = currentUserContext.getCurrentCompanyId();
LambdaQueryWrapper<PlatformPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PlatformPO::getId, shop.getPlatformId())
.eq(PlatformPO::getCompanyId, companyId);
PlatformPO platform = platformMapper.selectOne(wrapper);
if (platform != null) {
shopVO.setPlatformName(platform.getPlatformName());
}