mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 19:49:28 +08:00
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:
@@ -356,6 +356,7 @@ CREATE TABLE `ec_promotion_fee_type` (
|
|||||||
DROP TABLE IF EXISTS `ec_platform`;
|
DROP TABLE IF EXISTS `ec_platform`;
|
||||||
CREATE TABLE `ec_platform` (
|
CREATE TABLE `ec_platform` (
|
||||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '平台ID',
|
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '平台ID',
|
||||||
|
`company_id` bigint UNSIGNED NOT NULL COMMENT '所属公司ID',
|
||||||
`platform_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '平台名称(如淘宝、京东、拼多多、抖音)',
|
`platform_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '平台名称(如淘宝、京东、拼多多、抖音)',
|
||||||
`platform_code` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '平台代码(如 taobao、jd、pdd、douyin)',
|
`platform_code` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '平台代码(如 taobao、jd、pdd、douyin)',
|
||||||
`logo_url` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '平台Logo URL',
|
`logo_url` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '平台Logo URL',
|
||||||
@@ -366,12 +367,13 @@ CREATE TABLE `ec_platform` (
|
|||||||
`create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人ID',
|
`create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人ID',
|
||||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||||
PRIMARY KEY (`id`) USING BTREE,
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
UNIQUE INDEX `uk_platform_name`(`platform_name` ASC) USING BTREE,
|
INDEX `idx_company_id`(`company_id` ASC) USING BTREE,
|
||||||
UNIQUE INDEX `uk_platform_code`(`platform_code` ASC) USING BTREE,
|
|
||||||
INDEX `idx_sort_order`(`sort_order` ASC) USING BTREE,
|
INDEX `idx_sort_order`(`sort_order` ASC) USING BTREE,
|
||||||
INDEX `idx_is_active`(`is_active` ASC) USING BTREE,
|
INDEX `idx_is_active`(`is_active` ASC) USING BTREE,
|
||||||
|
INDEX `fk_ec_platform_company`(`company_id` ASC) USING BTREE,
|
||||||
INDEX `fk_ec_platform_creator`(`create_by` ASC) USING BTREE,
|
INDEX `fk_ec_platform_creator`(`create_by` ASC) USING BTREE,
|
||||||
INDEX `fk_ec_platform_updater`(`update_by` ASC) USING BTREE,
|
INDEX `fk_ec_platform_updater`(`update_by` ASC) USING BTREE,
|
||||||
|
CONSTRAINT `fk_ec_platform_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
CONSTRAINT `fk_ec_platform_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
CONSTRAINT `fk_ec_platform_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||||
CONSTRAINT `fk_ec_platform_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
CONSTRAINT `fk_ec_platform_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-平台表' ;
|
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-平台表' ;
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
-- ============================================================
|
||||||
|
-- ec_platform 表添加 company_id 字段
|
||||||
|
-- 执行前请先备份数据库!
|
||||||
|
-- ============================================================
|
||||||
|
|
||||||
|
-- 1. 添加 company_id 字段(NOT NULL 需要先设置默认值,再改回来)
|
||||||
|
ALTER TABLE ec_platform
|
||||||
|
ADD COLUMN company_id bigint UNSIGNED NOT NULL DEFAULT 1 COMMENT '所属公司ID' AFTER id;
|
||||||
|
|
||||||
|
-- 2. 添加外键约束
|
||||||
|
ALTER TABLE ec_platform
|
||||||
|
ADD CONSTRAINT fk_ec_platform_company
|
||||||
|
FOREIGN KEY (company_id) REFERENCES org_company(id)
|
||||||
|
ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- 3. 添加索引
|
||||||
|
ALTER TABLE ec_platform ADD INDEX idx_company_id(company_id);
|
||||||
|
|
||||||
|
-- 4. 查看现有公司(确认要绑定到哪个公司)
|
||||||
|
-- SELECT id, company_name FROM org_company;
|
||||||
|
|
||||||
|
-- 5. 如果只有一个公司,直接更新所有平台绑定到该公司
|
||||||
|
-- (替换下面的 1 为实际的公司ID)
|
||||||
|
-- UPDATE ec_platform SET company_id = 1;
|
||||||
|
|
||||||
|
-- 6. 如果需要创建新公司并绑定,参考以下SQL:
|
||||||
|
/*
|
||||||
|
-- 创建测试公司(如果需要)
|
||||||
|
INSERT INTO org_company (company_name, contact_name, contact_phone, address, is_active, create_by)
|
||||||
|
SELECT '默认公司', '管理员', '13800138000', '地址待填', 1, 1
|
||||||
|
WHERE NOT EXISTS (SELECT 1 FROM org_company LIMIT 1);
|
||||||
|
|
||||||
|
-- 获取公司ID并更新平台
|
||||||
|
SET @company_id = (SELECT id FROM org_company LIMIT 1);
|
||||||
|
UPDATE ec_platform SET company_id = @company_id;
|
||||||
|
*/
|
||||||
|
|
||||||
|
-- 7. 确认更新结果
|
||||||
|
-- SELECT id, company_id, platform_name FROM ec_platform;
|
||||||
+15
-3
@@ -592,7 +592,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
|||||||
CompanyOverviewVO.ShopComparison comparison = new CompanyOverviewVO.ShopComparison();
|
CompanyOverviewVO.ShopComparison comparison = new CompanyOverviewVO.ShopComparison();
|
||||||
comparison.setShopId(shop.getId());
|
comparison.setShopId(shop.getId());
|
||||||
comparison.setShopName(shop.getName());
|
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.setTargetOrderCount(targetOrderCount);
|
||||||
comparison.setOrderCountAchievementRate(orderCountAchievementRate);
|
comparison.setOrderCountAchievementRate(orderCountAchievementRate);
|
||||||
comparison.setTargetAmount(targetAmount);
|
comparison.setTargetAmount(targetAmount);
|
||||||
@@ -913,8 +913,10 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
|||||||
|
|
||||||
List<CompanyOverviewVO.PlatformSummary> platformSummaries = new ArrayList<>();
|
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()
|
Map<Long, PlatformPO> platformMap = allPlatforms.stream()
|
||||||
.collect(Collectors.toMap(PlatformPO::getId, p -> p));
|
.collect(Collectors.toMap(PlatformPO::getId, p -> p));
|
||||||
|
|
||||||
@@ -1108,5 +1110,15 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
|||||||
platformSummaries.sort(Comparator.comparing(CompanyOverviewVO.PlatformSummary::getSalesAmount).reversed());
|
platformSummaries.sort(Comparator.comparing(CompanyOverviewVO.PlatformSummary::getSalesAmount).reversed());
|
||||||
return platformSummaries;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+15
-3
@@ -1157,7 +1157,7 @@ public class ExportServiceImpl implements ExportService {
|
|||||||
|
|
||||||
Map<String, Object> data = new HashMap<>();
|
Map<String, Object> data = new HashMap<>();
|
||||||
data.put("shopName", shop.getName());
|
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("salesAmount", salesAmount);
|
||||||
data.put("orderCount", orderCount);
|
data.put("orderCount", orderCount);
|
||||||
data.put("avgOrderValue", avgOrderValue);
|
data.put("avgOrderValue", avgOrderValue);
|
||||||
@@ -1315,8 +1315,10 @@ public class ExportServiceImpl implements ExportService {
|
|||||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
.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()
|
Map<Long, PlatformPO> platformMap = allPlatforms.stream()
|
||||||
.collect(Collectors.toMap(PlatformPO::getId, p -> p));
|
.collect(Collectors.toMap(PlatformPO::getId, p -> p));
|
||||||
|
|
||||||
@@ -1570,4 +1572,14 @@ public class ExportServiceImpl implements ExportService {
|
|||||||
sheet.setColumnWidth(i, 3200);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+6
@@ -42,4 +42,10 @@ public class CreatePlatformDTO {
|
|||||||
*/
|
*/
|
||||||
@Schema(description = "是否启用 0禁用 1启用", example = "1")
|
@Schema(description = "是否启用 0禁用 1启用", example = "1")
|
||||||
private Integer isActive;
|
private Integer isActive;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所属公司ID
|
||||||
|
*/
|
||||||
|
@Schema(description = "所属公司ID", example = "1")
|
||||||
|
private Long companyId;
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -27,4 +27,10 @@ public class PlatformFilterDTO {
|
|||||||
*/
|
*/
|
||||||
@Schema(description = "是否启用 0禁用 1启用", example = "1")
|
@Schema(description = "是否启用 0禁用 1启用", example = "1")
|
||||||
private Integer isActive;
|
private Integer isActive;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所属公司ID
|
||||||
|
*/
|
||||||
|
@Schema(description = "所属公司ID", example = "1")
|
||||||
|
private Long companyId;
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -45,4 +45,10 @@ public class UpdatePlatformDTO {
|
|||||||
@Schema(description = "是否启用 0禁用 1启用", example = "1")
|
@Schema(description = "是否启用 0禁用 1启用", example = "1")
|
||||||
@NotNull(message = "是否启用不能为空")
|
@NotNull(message = "是否启用不能为空")
|
||||||
private Integer isActive;
|
private Integer isActive;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所属公司ID
|
||||||
|
*/
|
||||||
|
@Schema(description = "所属公司ID", example = "1")
|
||||||
|
private Long companyId;
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -20,6 +20,12 @@ public class PlatformPO {
|
|||||||
@TableId(value = "id", type = IdType.AUTO)
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所属公司ID
|
||||||
|
*/
|
||||||
|
@TableField("company_id")
|
||||||
|
private Long companyId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 平台名称(如淘宝、京东、拼多多、抖音)
|
* 平台名称(如淘宝、京东、拼多多、抖音)
|
||||||
*/
|
*/
|
||||||
|
|||||||
+6
@@ -18,6 +18,12 @@ public class PlatformVO {
|
|||||||
@Schema(description = "平台ID", example = "1")
|
@Schema(description = "平台ID", example = "1")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所属公司ID
|
||||||
|
*/
|
||||||
|
@Schema(description = "所属公司ID", example = "1")
|
||||||
|
private Long companyId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 平台名称
|
* 平台名称
|
||||||
*/
|
*/
|
||||||
|
|||||||
+46
-71
@@ -34,25 +34,23 @@ public class PlatformServiceImpl extends ServiceImpl<PlatformMapper, PlatformPO>
|
|||||||
this.currentUserContext = currentUserContext;
|
this.currentUserContext = currentUserContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建平台
|
|
||||||
*
|
|
||||||
* @param createPlatformDTO 创建平台DTO
|
|
||||||
* @return 平台VO
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public PlatformVO createPlatform(CreatePlatformDTO createPlatformDTO) {
|
public PlatformVO createPlatform(CreatePlatformDTO createPlatformDTO) {
|
||||||
// 验证平台名称是否重复
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
|
|
||||||
|
// 验证平台名称是否重复(同一公司下)
|
||||||
LambdaQueryWrapper<PlatformPO> wrapper = new LambdaQueryWrapper<>();
|
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) {
|
if (this.count(wrapper) > 0) {
|
||||||
throw new BusinessException("平台名称已存在");
|
throw new BusinessException("平台名称已存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 验证平台代码是否重复
|
// 验证平台代码是否重复(同一公司下)
|
||||||
wrapper = new LambdaQueryWrapper<>();
|
wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.eq(PlatformPO::getPlatformCode, createPlatformDTO.getPlatformCode());
|
wrapper.eq(PlatformPO::getCompanyId, companyId)
|
||||||
|
.eq(PlatformPO::getPlatformCode, createPlatformDTO.getPlatformCode());
|
||||||
if (this.count(wrapper) > 0) {
|
if (this.count(wrapper) > 0) {
|
||||||
throw new BusinessException("平台代码已存在");
|
throw new BusinessException("平台代码已存在");
|
||||||
}
|
}
|
||||||
@@ -60,6 +58,7 @@ public class PlatformServiceImpl extends ServiceImpl<PlatformMapper, PlatformPO>
|
|||||||
// 创建平台
|
// 创建平台
|
||||||
PlatformPO platform = new PlatformPO();
|
PlatformPO platform = new PlatformPO();
|
||||||
BeanUtils.copyProperties(createPlatformDTO, platform);
|
BeanUtils.copyProperties(createPlatformDTO, platform);
|
||||||
|
platform.setCompanyId(companyId);
|
||||||
|
|
||||||
// 设置默认值
|
// 设置默认值
|
||||||
if (platform.getSortOrder() == null) {
|
if (platform.getSortOrder() == null) {
|
||||||
@@ -79,33 +78,30 @@ public class PlatformServiceImpl extends ServiceImpl<PlatformMapper, PlatformPO>
|
|||||||
return convertToVO(platform);
|
return convertToVO(platform);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新平台
|
|
||||||
*
|
|
||||||
* @param updatePlatformDTO 更新平台DTO
|
|
||||||
* @param id 平台ID
|
|
||||||
* @return 平台VO
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public PlatformVO updatePlatform(UpdatePlatformDTO updatePlatformDTO, Long id) {
|
public PlatformVO updatePlatform(UpdatePlatformDTO updatePlatformDTO, Long id) {
|
||||||
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
|
|
||||||
// 验证平台是否存在
|
// 验证平台是否存在
|
||||||
PlatformPO existingPlatform = this.getById(id);
|
PlatformPO existingPlatform = this.getById(id);
|
||||||
if (existingPlatform == null) {
|
if (existingPlatform == null) {
|
||||||
throw new BusinessException("平台不存在");
|
throw new BusinessException("平台不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 验证平台名称是否重复(排除当前平台)
|
// 验证平台名称是否重复(排除当前平台,同一公司下)
|
||||||
LambdaQueryWrapper<PlatformPO> wrapper = new LambdaQueryWrapper<>();
|
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);
|
.ne(PlatformPO::getId, id);
|
||||||
if (this.count(wrapper) > 0) {
|
if (this.count(wrapper) > 0) {
|
||||||
throw new BusinessException("平台名称已存在");
|
throw new BusinessException("平台名称已存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 验证平台代码是否重复(排除当前平台)
|
// 验证平台代码是否重复(排除当前平台,同一公司下)
|
||||||
wrapper = new LambdaQueryWrapper<>();
|
wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.eq(PlatformPO::getPlatformCode, updatePlatformDTO.getPlatformCode())
|
wrapper.eq(PlatformPO::getCompanyId, companyId)
|
||||||
|
.eq(PlatformPO::getPlatformCode, updatePlatformDTO.getPlatformCode())
|
||||||
.ne(PlatformPO::getId, id);
|
.ne(PlatformPO::getId, id);
|
||||||
if (this.count(wrapper) > 0) {
|
if (this.count(wrapper) > 0) {
|
||||||
throw new BusinessException("平台代码已存在");
|
throw new BusinessException("平台代码已存在");
|
||||||
@@ -115,6 +111,7 @@ public class PlatformServiceImpl extends ServiceImpl<PlatformMapper, PlatformPO>
|
|||||||
PlatformPO platform = new PlatformPO();
|
PlatformPO platform = new PlatformPO();
|
||||||
BeanUtils.copyProperties(updatePlatformDTO, platform);
|
BeanUtils.copyProperties(updatePlatformDTO, platform);
|
||||||
platform.setId(id);
|
platform.setId(id);
|
||||||
|
platform.setCompanyId(companyId);
|
||||||
|
|
||||||
// 设置更新人ID
|
// 设置更新人ID
|
||||||
platform.setUpdateBy(currentUserContext.getCurrentUserId());
|
platform.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||||
@@ -126,11 +123,6 @@ public class PlatformServiceImpl extends ServiceImpl<PlatformMapper, PlatformPO>
|
|||||||
return convertToVO(platform);
|
return convertToVO(platform);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除平台
|
|
||||||
*
|
|
||||||
* @param id 平台ID
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void deletePlatform(Long id) {
|
public void deletePlatform(Long id) {
|
||||||
@@ -144,18 +136,14 @@ public class PlatformServiceImpl extends ServiceImpl<PlatformMapper, PlatformPO>
|
|||||||
this.removeById(id);
|
this.removeById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 分页获取平台列表
|
|
||||||
*
|
|
||||||
* @param pageQueryDTO 分页查询DTO
|
|
||||||
* @return 分页结果
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public PageResultVO<PlatformVO> getPlatformPage(PageQueryDTO<PlatformFilterDTO> pageQueryDTO) {
|
public PageResultVO<PlatformVO> getPlatformPage(PageQueryDTO<PlatformFilterDTO> pageQueryDTO) {
|
||||||
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
PlatformFilterDTO filter = pageQueryDTO.getFilters() != null ? pageQueryDTO.getFilters() : new PlatformFilterDTO();
|
PlatformFilterDTO filter = pageQueryDTO.getFilters() != null ? pageQueryDTO.getFilters() : new PlatformFilterDTO();
|
||||||
|
|
||||||
// 构建查询条件
|
// 构建查询条件
|
||||||
LambdaQueryWrapper<PlatformPO> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<PlatformPO> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(PlatformPO::getCompanyId, companyId);
|
||||||
if (filter.getPlatformName() != null && !filter.getPlatformName().isEmpty()) {
|
if (filter.getPlatformName() != null && !filter.getPlatformName().isEmpty()) {
|
||||||
wrapper.like(PlatformPO::getPlatformName, filter.getPlatformName());
|
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 PageResultVO.create(voList, result.getTotal(), (int) pageQueryDTO.getPage(), (int) pageQueryDTO.getPageSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取所有启用的平台列表
|
|
||||||
*
|
|
||||||
* @return 平台列表
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public List<PlatformVO> getActivePlatforms() {
|
public List<PlatformVO> getActivePlatforms() {
|
||||||
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
LambdaQueryWrapper<PlatformPO> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<PlatformPO> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.eq(PlatformPO::getIsActive, 1)
|
wrapper.eq(PlatformPO::getCompanyId, companyId)
|
||||||
|
.eq(PlatformPO::getIsActive, 1)
|
||||||
.orderByAsc(PlatformPO::getSortOrder);
|
.orderByAsc(PlatformPO::getSortOrder);
|
||||||
|
|
||||||
return this.list(wrapper).stream()
|
return this.list(wrapper).stream()
|
||||||
@@ -198,51 +183,35 @@ public class PlatformServiceImpl extends ServiceImpl<PlatformMapper, PlatformPO>
|
|||||||
.collect(Collectors.toList());
|
.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
|
@Override
|
||||||
public void initPlatformsForCompany(Long companyId, Long creatorId) {
|
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; // 已有平台数据,无需初始化
|
return; // 已有平台数据,无需初始化
|
||||||
}
|
}
|
||||||
|
|
||||||
// 插入初始平台数据
|
// 插入初始平台数据(绑定到公司)
|
||||||
List<PlatformPO> initialPlatforms = List.of(
|
List<PlatformPO> initialPlatforms = List.of(
|
||||||
createPlatform("淘宝", "taobao", 1, creatorId),
|
createPlatform(companyId, "淘宝", "taobao", 1, creatorId),
|
||||||
createPlatform("京东", "jd", 2, creatorId),
|
createPlatform(companyId, "京东", "jd", 2, creatorId),
|
||||||
createPlatform("拼多多", "pdd", 3, creatorId),
|
createPlatform(companyId, "拼多多", "pdd", 3, creatorId),
|
||||||
createPlatform("抖音", "douyin", 4, creatorId),
|
createPlatform(companyId, "抖音", "douyin", 4, creatorId),
|
||||||
createPlatform("快手", "kuaishou", 5, creatorId),
|
createPlatform(companyId, "快手", "kuaishou", 5, creatorId),
|
||||||
createPlatform("小红书", "xiaohongshu", 6, creatorId),
|
createPlatform(companyId, "小红书", "xiaohongshu", 6, creatorId),
|
||||||
createPlatform("天猫", "tmall", 7, creatorId),
|
createPlatform(companyId, "天猫", "tmall", 7, creatorId),
|
||||||
createPlatform("唯品会", "vip", 8, creatorId),
|
createPlatform(companyId, "唯品会", "vip", 8, creatorId),
|
||||||
createPlatform("苏宁", "suning", 9, creatorId),
|
createPlatform(companyId, "苏宁", "suning", 9, creatorId),
|
||||||
createPlatform("1688", "1688", 10, creatorId)
|
createPlatform(companyId, "1688", "1688", 10, creatorId)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.saveBatch(initialPlatforms);
|
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();
|
PlatformPO platform = new PlatformPO();
|
||||||
|
platform.setCompanyId(companyId);
|
||||||
platform.setPlatformName(name);
|
platform.setPlatformName(name);
|
||||||
platform.setPlatformCode(code);
|
platform.setPlatformCode(code);
|
||||||
platform.setSortOrder(sortOrder);
|
platform.setSortOrder(sortOrder);
|
||||||
@@ -251,4 +220,10 @@ public class PlatformServiceImpl extends ServiceImpl<PlatformMapper, PlatformPO>
|
|||||||
platform.setUpdateBy(creatorId);
|
platform.setUpdateBy(creatorId);
|
||||||
return platform;
|
return platform;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PlatformVO convertToVO(PlatformPO platform) {
|
||||||
|
PlatformVO vo = new PlatformVO();
|
||||||
|
BeanUtils.copyProperties(platform, vo);
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -272,7 +272,11 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
|
|||||||
|
|
||||||
// 获取平台名称
|
// 获取平台名称
|
||||||
if (shop.getPlatformId() != null) {
|
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) {
|
if (platform != null) {
|
||||||
shopVO.setPlatformName(platform.getPlatformName());
|
shopVO.setPlatformName(platform.getPlatformName());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user