mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:59:20 +08:00
feat: 新增电商平台管理模块(ec_platform),店铺表platform改为外键
后端: - 新增 ec_platform 表 + 10条初始平台数据(淘宝/京东/拼多多/抖音等) - ec_shop 表 platform varchar → platform_id bigint 外键 - 新增 Platform 模块:PO/VO/DTO/Mapper/Service/Controller - 修复 ShopServiceImpl/CompanyOverviewServiceImpl/ExportServiceImpl 中 platform 字段引用 前端: - 新增平台管理页面(列表 + 表单弹窗) - 路由注册 /data/platform - 店铺管理:平台选择改为下拉,字段 platform 字符串 → platformId 外键 - 同步更新 ShopVO/ShopDTO 类型定义 数据库: - V20260422__add_ec_platform.sql 迁移文件
This commit is contained in:
+7
-2
@@ -5,6 +5,8 @@ import org.springframework.stereotype.Service;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.brushorder.mapper.BrushOrderMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.mapper.PlatformMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.po.PlatformPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.promotion.mapper.PromotionFeeMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.CompanyOverviewQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.brushorder.model.po.BrushOrderPO;
|
||||
@@ -52,6 +54,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
private final OrderStatusService orderStatusService;
|
||||
private final ProductMapper productMapper;
|
||||
private final CategoryService categoryService;
|
||||
private final PlatformMapper platformMapper;
|
||||
|
||||
public CompanyOverviewServiceImpl(CurrentUserContext currentUserContext,
|
||||
OrderMapper orderMapper,
|
||||
@@ -61,7 +64,8 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
ShopService shopService,
|
||||
OrderStatusService orderStatusService,
|
||||
ProductMapper productMapper,
|
||||
CategoryService categoryService) {
|
||||
CategoryService categoryService,
|
||||
PlatformMapper platformMapper) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.orderMapper = orderMapper;
|
||||
this.promotionFeeMapper = promotionFeeMapper;
|
||||
@@ -71,6 +75,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
this.orderStatusService = orderStatusService;
|
||||
this.productMapper = productMapper;
|
||||
this.categoryService = categoryService;
|
||||
this.platformMapper = platformMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -582,7 +587,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
CompanyOverviewVO.ShopComparison comparison = new CompanyOverviewVO.ShopComparison();
|
||||
comparison.setShopId(shop.getId());
|
||||
comparison.setShopName(shop.getName());
|
||||
comparison.setPlatform(shop.getPlatform());
|
||||
comparison.setPlatform(shop.getPlatformId() != null ? platformMapper.selectById(shop.getPlatformId()).getPlatformName() : null);
|
||||
comparison.setTargetOrderCount(targetOrderCount);
|
||||
comparison.setOrderCountAchievementRate(orderCountAchievementRate);
|
||||
comparison.setTargetAmount(targetAmount);
|
||||
|
||||
+7
-2
@@ -8,6 +8,8 @@ import org.springframework.stereotype.Service;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.brushorder.mapper.BrushOrderMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.mapper.PlatformMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.po.PlatformPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.ShopOverviewQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.vo.CompanyOverviewVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.vo.ShopOverviewStatisticsVO;
|
||||
@@ -60,6 +62,7 @@ public class ExportServiceImpl implements ExportService {
|
||||
private final OrderStatusService orderStatusService;
|
||||
private final ShopOverviewStatisticsService shopOverviewStatisticsService;
|
||||
private final CategoryService categoryService;
|
||||
private final PlatformMapper platformMapper;
|
||||
|
||||
public ExportServiceImpl(CurrentUserContext currentUserContext,
|
||||
OrderMapper orderMapper,
|
||||
@@ -70,7 +73,8 @@ public class ExportServiceImpl implements ExportService {
|
||||
ProductService productService,
|
||||
OrderStatusService orderStatusService,
|
||||
ShopOverviewStatisticsService shopOverviewStatisticsService,
|
||||
CategoryService categoryService) {
|
||||
CategoryService categoryService,
|
||||
PlatformMapper platformMapper) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.orderMapper = orderMapper;
|
||||
this.promotionFeeMapper = promotionFeeMapper;
|
||||
@@ -81,6 +85,7 @@ public class ExportServiceImpl implements ExportService {
|
||||
this.orderStatusService = orderStatusService;
|
||||
this.shopOverviewStatisticsService = shopOverviewStatisticsService;
|
||||
this.categoryService = categoryService;
|
||||
this.platformMapper = platformMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1151,7 +1156,7 @@ public class ExportServiceImpl implements ExportService {
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("shopName", shop.getName());
|
||||
data.put("platform", shop.getPlatform());
|
||||
data.put("platform", shop.getPlatformId() != null ? platformMapper.selectById(shop.getPlatformId()).getPlatformName() : null);
|
||||
data.put("salesAmount", salesAmount);
|
||||
data.put("orderCount", orderCount);
|
||||
data.put("avgOrderValue", avgOrderValue);
|
||||
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.platform.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.dto.CreatePlatformDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.dto.PlatformFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.dto.UpdatePlatformDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.vo.PlatformVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.service.PlatformService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 平台管理控制器
|
||||
*/
|
||||
@Tag(name = "电商-平台管理", description = "平台的增删改查接口")
|
||||
@RestController
|
||||
@RequestMapping("/ec/platform")
|
||||
public class PlatformController {
|
||||
|
||||
private final PlatformService platformService;
|
||||
|
||||
public PlatformController(PlatformService platformService) {
|
||||
this.platformService = platformService;
|
||||
}
|
||||
|
||||
@Operation(summary = "创建平台", description = "创建新的平台")
|
||||
@PostMapping("/create")
|
||||
@RequirePermission(value = "ecom:platform:manage", description = "创建平台", allowSuper = true)
|
||||
public ApiResponse<PlatformVO> createPlatform(@Valid @RequestBody CreatePlatformDTO createPlatformDTO) {
|
||||
PlatformVO platformVO = platformService.createPlatform(createPlatformDTO);
|
||||
return ApiResponse.success(platformVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新平台", description = "更新现有平台信息")
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission(value = "ecom:platform:manage", description = "更新平台", allowSuper = true)
|
||||
public ApiResponse<PlatformVO> updatePlatform(@Valid @RequestBody UpdatePlatformDTO updatePlatformDTO,
|
||||
@Parameter(description = "平台ID") @PathVariable Long id) {
|
||||
PlatformVO platformVO = platformService.updatePlatform(updatePlatformDTO, id);
|
||||
return ApiResponse.success(platformVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除平台", description = "删除指定平台")
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@RequirePermission(value = "ecom:platform:manage", description = "删除平台", allowSuper = true)
|
||||
public ApiResponse<Void> deletePlatform(@Parameter(description = "平台ID") @PathVariable Long id) {
|
||||
platformService.deletePlatform(id);
|
||||
return ApiResponse.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "分页获取平台列表", description = "分页获取平台列表,支持条件过滤")
|
||||
@PostMapping("/page")
|
||||
@RequirePermission(value = "ecom:platform:read", description = "查询平台列表", allowSuper = true)
|
||||
public ApiResponse<PageResultVO<PlatformVO>> getPlatformPage(
|
||||
@Valid @RequestBody PageQueryDTO<PlatformFilterDTO> pageQueryDTO) {
|
||||
PageResultVO<PlatformVO> result = platformService.getPlatformPage(pageQueryDTO);
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取所有启用的平台", description = "获取所有已启用的平台列表,供下拉选择")
|
||||
@GetMapping("/active")
|
||||
@RequirePermission(value = "ecom:platform:read", description = "查询平台列表", allowSuper = true)
|
||||
public ApiResponse<List<PlatformVO>> getActivePlatforms() {
|
||||
List<PlatformVO> result = platformService.getActivePlatforms();
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.platform.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.po.PlatformPO;
|
||||
|
||||
/**
|
||||
* 平台Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface PlatformMapper extends BaseMapper<PlatformPO> {
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.platform.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 创建平台DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "创建平台DTO")
|
||||
public class CreatePlatformDTO {
|
||||
|
||||
/**
|
||||
* 平台名称
|
||||
*/
|
||||
@Schema(description = "平台名称", example = "淘宝", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "平台名称不能为空")
|
||||
private String platformName;
|
||||
|
||||
/**
|
||||
* 平台代码
|
||||
*/
|
||||
@Schema(description = "平台代码", example = "taobao", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "平台代码不能为空")
|
||||
private String platformCode;
|
||||
|
||||
/**
|
||||
* Logo URL
|
||||
*/
|
||||
@Schema(description = "Logo URL")
|
||||
private String logoUrl;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "1")
|
||||
private Integer sortOrder;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
@Schema(description = "是否启用 0禁用 1启用", example = "1")
|
||||
private Integer isActive;
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.platform.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 平台过滤DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "平台过滤DTO")
|
||||
public class PlatformFilterDTO {
|
||||
|
||||
/**
|
||||
* 平台名称
|
||||
*/
|
||||
@Schema(description = "平台名称", example = "淘宝")
|
||||
private String platformName;
|
||||
|
||||
/**
|
||||
* 平台代码
|
||||
*/
|
||||
@Schema(description = "平台代码", example = "taobao")
|
||||
private String platformCode;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
@Schema(description = "是否启用 0禁用 1启用", example = "1")
|
||||
private Integer isActive;
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.platform.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 更新平台DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "更新平台DTO")
|
||||
public class UpdatePlatformDTO {
|
||||
|
||||
/**
|
||||
* 平台名称
|
||||
*/
|
||||
@Schema(description = "平台名称", example = "淘宝", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "平台名称不能为空")
|
||||
private String platformName;
|
||||
|
||||
/**
|
||||
* 平台代码
|
||||
*/
|
||||
@Schema(description = "平台代码", example = "taobao", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "平台代码不能为空")
|
||||
private String platformCode;
|
||||
|
||||
/**
|
||||
* Logo URL
|
||||
*/
|
||||
@Schema(description = "Logo URL")
|
||||
private String logoUrl;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "1")
|
||||
@NotNull(message = "排序不能为空")
|
||||
private Integer sortOrder;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
@Schema(description = "是否启用 0禁用 1启用", example = "1")
|
||||
@NotNull(message = "是否启用不能为空")
|
||||
private Integer isActive;
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.platform.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 电商-平台实体
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("ec_platform")
|
||||
public class PlatformPO {
|
||||
|
||||
/**
|
||||
* 平台ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 平台名称(如淘宝、京东、拼多多、抖音)
|
||||
*/
|
||||
@TableField("platform_name")
|
||||
private String platformName;
|
||||
|
||||
/**
|
||||
* 平台代码(如 taobao、jd、pdd、douyin)
|
||||
*/
|
||||
@TableField("platform_code")
|
||||
private String platformCode;
|
||||
|
||||
/**
|
||||
* 平台Logo URL
|
||||
*/
|
||||
@TableField("logo_url")
|
||||
private String logoUrl;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@TableField("sort_order")
|
||||
private Integer sortOrder;
|
||||
|
||||
/**
|
||||
* 是否启用 0禁用 1启用
|
||||
*/
|
||||
@TableField("is_active")
|
||||
private Integer isActive;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
@TableField("create_by")
|
||||
private Long createBy;
|
||||
|
||||
/**
|
||||
* 更新人ID
|
||||
*/
|
||||
@TableField("update_by")
|
||||
private Long updateBy;
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.platform.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 平台VO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "平台VO")
|
||||
public class PlatformVO {
|
||||
|
||||
/**
|
||||
* 平台ID
|
||||
*/
|
||||
@Schema(description = "平台ID", example = "1")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 平台名称
|
||||
*/
|
||||
@Schema(description = "平台名称", example = "淘宝")
|
||||
private String platformName;
|
||||
|
||||
/**
|
||||
* 平台代码
|
||||
*/
|
||||
@Schema(description = "平台代码", example = "taobao")
|
||||
private String platformCode;
|
||||
|
||||
/**
|
||||
* Logo URL
|
||||
*/
|
||||
@Schema(description = "Logo URL", example = "https://example.com/taobao.png")
|
||||
private String logoUrl;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "1")
|
||||
private Integer sortOrder;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
@Schema(description = "是否启用 0禁用 1启用", example = "1")
|
||||
private Integer isActive;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Schema(description = "创建时间", example = "2024-01-01T10:00:00")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@Schema(description = "更新时间", example = "2024-01-01T10:00:00")
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.platform.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.dto.CreatePlatformDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.dto.PlatformFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.dto.UpdatePlatformDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.po.PlatformPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.vo.PlatformVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 平台服务接口
|
||||
*/
|
||||
public interface PlatformService extends IService<PlatformPO> {
|
||||
|
||||
/**
|
||||
* 创建平台
|
||||
*
|
||||
* @param createPlatformDTO 创建平台DTO
|
||||
* @return 平台VO
|
||||
*/
|
||||
PlatformVO createPlatform(CreatePlatformDTO createPlatformDTO);
|
||||
|
||||
/**
|
||||
* 更新平台
|
||||
*
|
||||
* @param updatePlatformDTO 更新平台DTO
|
||||
* @param id 平台ID
|
||||
* @return 平台VO
|
||||
*/
|
||||
PlatformVO updatePlatform(UpdatePlatformDTO updatePlatformDTO, Long id);
|
||||
|
||||
/**
|
||||
* 删除平台
|
||||
*
|
||||
* @param id 平台ID
|
||||
*/
|
||||
void deletePlatform(Long id);
|
||||
|
||||
/**
|
||||
* 分页获取平台列表
|
||||
*
|
||||
* @param pageQueryDTO 分页查询DTO
|
||||
* @return 分页结果
|
||||
*/
|
||||
PageResultVO<PlatformVO> getPlatformPage(PageQueryDTO<PlatformFilterDTO> pageQueryDTO);
|
||||
|
||||
/**
|
||||
* 获取所有启用的平台列表
|
||||
*
|
||||
* @return 平台列表
|
||||
*/
|
||||
List<PlatformVO> getActivePlatforms();
|
||||
}
|
||||
+212
@@ -0,0 +1,212 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.platform.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.mapper.PlatformMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.dto.CreatePlatformDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.dto.PlatformFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.dto.UpdatePlatformDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.po.PlatformPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.vo.PlatformVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.service.PlatformService;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 平台服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class PlatformServiceImpl extends ServiceImpl<PlatformMapper, PlatformPO> implements PlatformService {
|
||||
|
||||
private final CurrentUserContext currentUserContext;
|
||||
|
||||
public PlatformServiceImpl(CurrentUserContext currentUserContext) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建平台
|
||||
*
|
||||
* @param createPlatformDTO 创建平台DTO
|
||||
* @return 平台VO
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public PlatformVO createPlatform(CreatePlatformDTO createPlatformDTO) {
|
||||
// 验证平台名称是否重复
|
||||
LambdaQueryWrapper<PlatformPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PlatformPO::getPlatformName, createPlatformDTO.getPlatformName());
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("平台名称已存在");
|
||||
}
|
||||
|
||||
// 验证平台代码是否重复
|
||||
wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PlatformPO::getPlatformCode, createPlatformDTO.getPlatformCode());
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("平台代码已存在");
|
||||
}
|
||||
|
||||
// 创建平台
|
||||
PlatformPO platform = new PlatformPO();
|
||||
BeanUtils.copyProperties(createPlatformDTO, platform);
|
||||
|
||||
// 设置默认值
|
||||
if (platform.getSortOrder() == null) {
|
||||
platform.setSortOrder(0);
|
||||
}
|
||||
if (platform.getIsActive() == null) {
|
||||
platform.setIsActive(1);
|
||||
}
|
||||
|
||||
// 设置创建人ID
|
||||
platform.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
// 保存平台
|
||||
this.save(platform);
|
||||
|
||||
// 转换为VO并返回
|
||||
return convertToVO(platform);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新平台
|
||||
*
|
||||
* @param updatePlatformDTO 更新平台DTO
|
||||
* @param id 平台ID
|
||||
* @return 平台VO
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public PlatformVO updatePlatform(UpdatePlatformDTO updatePlatformDTO, Long id) {
|
||||
// 验证平台是否存在
|
||||
PlatformPO existingPlatform = this.getById(id);
|
||||
if (existingPlatform == null) {
|
||||
throw new BusinessException("平台不存在");
|
||||
}
|
||||
|
||||
// 验证平台名称是否重复(排除当前平台)
|
||||
LambdaQueryWrapper<PlatformPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.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())
|
||||
.ne(PlatformPO::getId, id);
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("平台代码已存在");
|
||||
}
|
||||
|
||||
// 更新平台
|
||||
PlatformPO platform = new PlatformPO();
|
||||
BeanUtils.copyProperties(updatePlatformDTO, platform);
|
||||
platform.setId(id);
|
||||
|
||||
// 设置更新人ID
|
||||
platform.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
// 更新平台
|
||||
this.updateById(platform);
|
||||
|
||||
// 转换为VO并返回
|
||||
return convertToVO(platform);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除平台
|
||||
*
|
||||
* @param id 平台ID
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void deletePlatform(Long id) {
|
||||
// 验证平台是否存在
|
||||
PlatformPO existingPlatform = this.getById(id);
|
||||
if (existingPlatform == null) {
|
||||
throw new BusinessException("平台不存在");
|
||||
}
|
||||
|
||||
// 删除平台
|
||||
this.removeById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取平台列表
|
||||
*
|
||||
* @param pageQueryDTO 分页查询DTO
|
||||
* @return 分页结果
|
||||
*/
|
||||
@Override
|
||||
public PageResultVO<PlatformVO> getPlatformPage(PageQueryDTO<PlatformFilterDTO> pageQueryDTO) {
|
||||
PlatformFilterDTO filter = pageQueryDTO.getFilters() != null ? pageQueryDTO.getFilters() : new PlatformFilterDTO();
|
||||
|
||||
// 构建查询条件
|
||||
LambdaQueryWrapper<PlatformPO> wrapper = new LambdaQueryWrapper<>();
|
||||
if (filter.getPlatformName() != null && !filter.getPlatformName().isEmpty()) {
|
||||
wrapper.like(PlatformPO::getPlatformName, filter.getPlatformName());
|
||||
}
|
||||
if (filter.getPlatformCode() != null && !filter.getPlatformCode().isEmpty()) {
|
||||
wrapper.eq(PlatformPO::getPlatformCode, filter.getPlatformCode());
|
||||
}
|
||||
if (filter.getIsActive() != null) {
|
||||
wrapper.eq(PlatformPO::getIsActive, filter.getIsActive());
|
||||
}
|
||||
|
||||
// 按排序字段升序
|
||||
wrapper.orderByAsc(PlatformPO::getSortOrder)
|
||||
.orderByDesc(PlatformPO::getCreateTime);
|
||||
|
||||
// 分页查询
|
||||
IPage<PlatformPO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||
IPage<PlatformPO> result = this.page(page, wrapper);
|
||||
|
||||
// 转换为VO
|
||||
List<PlatformVO> voList = result.getRecords().stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return PageResultVO.create(voList, result.getTotal(), (int) pageQueryDTO.getPage(), (int) pageQueryDTO.getPageSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有启用的平台列表
|
||||
*
|
||||
* @return 平台列表
|
||||
*/
|
||||
@Override
|
||||
public List<PlatformVO> getActivePlatforms() {
|
||||
LambdaQueryWrapper<PlatformPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PlatformPO::getIsActive, 1)
|
||||
.orderByAsc(PlatformPO::getSortOrder);
|
||||
|
||||
return this.list(wrapper).stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为VO
|
||||
*
|
||||
* @param platform 平台实体
|
||||
* @return 平台VO
|
||||
*/
|
||||
private PlatformVO convertToVO(PlatformPO platform) {
|
||||
PlatformVO vo = new PlatformVO();
|
||||
BeanUtils.copyProperties(platform, vo);
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -25,8 +25,8 @@ public class CreateShopDTO {
|
||||
private Long logoImageId;
|
||||
|
||||
/**
|
||||
* 平台(如淘宝、京东、拼多多)
|
||||
* 平台ID
|
||||
*/
|
||||
@Schema(description = "平台", example = "淘宝", allowableValues = {"淘宝", "京东", "拼多多", "天猫"})
|
||||
private String platform;
|
||||
@Schema(description = "平台ID", example = "1")
|
||||
private Long platformId;
|
||||
}
|
||||
|
||||
+3
-3
@@ -17,8 +17,8 @@ public class ShopFilterDTO {
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 平台
|
||||
* 平台ID
|
||||
*/
|
||||
@Schema(description = "平台", example = "淘宝", allowableValues = {"淘宝", "京东", "拼多多", "天猫"})
|
||||
private String platform;
|
||||
@Schema(description = "平台ID", example = "1")
|
||||
private Long platformId;
|
||||
}
|
||||
|
||||
+3
-3
@@ -25,8 +25,8 @@ public class UpdateShopDTO {
|
||||
private Long logoImageId;
|
||||
|
||||
/**
|
||||
* 平台(如淘宝、京东、拼多多)
|
||||
* 平台ID
|
||||
*/
|
||||
@Schema(description = "平台", example = "淘宝", allowableValues = {"淘宝", "京东", "拼多多", "天猫"})
|
||||
private String platform;
|
||||
@Schema(description = "平台ID", example = "1")
|
||||
private Long platformId;
|
||||
}
|
||||
|
||||
+3
-3
@@ -39,10 +39,10 @@ public class ShopPO {
|
||||
private Long logoImageId;
|
||||
|
||||
/**
|
||||
* 平台(如淘宝、京东、拼多多)
|
||||
* 平台ID
|
||||
*/
|
||||
@TableField("platform")
|
||||
private String platform;
|
||||
@TableField("platform_id")
|
||||
private Long platformId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
|
||||
+9
-3
@@ -37,10 +37,16 @@ public class ShopVO {
|
||||
private String logo;
|
||||
|
||||
/**
|
||||
* 平台(如淘宝、京东、拼多多)
|
||||
* 平台ID
|
||||
*/
|
||||
@Schema(description = "平台", example = "淘宝")
|
||||
private String platform;
|
||||
@Schema(description = "平台ID", example = "1")
|
||||
private Long platformId;
|
||||
|
||||
/**
|
||||
* 平台名称
|
||||
*/
|
||||
@Schema(description = "平台名称", example = "淘宝")
|
||||
private String platformName;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
|
||||
+15
-3
@@ -13,6 +13,8 @@ import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.mapper.ProductMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.promotion.mapper.PromotionFeeMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.mapper.PlatformMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.po.PlatformPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.shop.mapper.ShopMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.shop.mapper.ShopProductRelationMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.CreateShopDTO;
|
||||
@@ -68,12 +70,13 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
|
||||
private final ShopProductRelationMapper shopProductRelationMapper;
|
||||
private final ProductSpecService productSpecService;
|
||||
private final OrderStatusService orderStatusService;
|
||||
private final PlatformMapper platformMapper;
|
||||
|
||||
public ShopServiceImpl(CurrentUserContext currentUserContext, SysFileMapper sysFileMapper, SysFileService sysFileService,
|
||||
OrderMapper orderMapper, PromotionFeeMapper promotionFeeMapper,
|
||||
ProductMapper productMapper,
|
||||
ShopProductRelationMapper shopProductRelationMapper, ProductSpecService productSpecService,
|
||||
OrderStatusService orderStatusService) {
|
||||
OrderStatusService orderStatusService, PlatformMapper platformMapper) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.sysFileMapper = sysFileMapper;
|
||||
this.sysFileService = sysFileService;
|
||||
@@ -83,6 +86,7 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
|
||||
this.shopProductRelationMapper = shopProductRelationMapper;
|
||||
this.productSpecService = productSpecService;
|
||||
this.orderStatusService = orderStatusService;
|
||||
this.platformMapper = platformMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,8 +211,8 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
|
||||
if (filter.getName() != null && !filter.getName().trim().isEmpty()) {
|
||||
wrapper.like(ShopPO::getName, filter.getName());
|
||||
}
|
||||
if (filter.getPlatform() != null && !filter.getPlatform().trim().isEmpty()) {
|
||||
wrapper.eq(ShopPO::getPlatform, filter.getPlatform());
|
||||
if (filter.getPlatformId() != null) {
|
||||
wrapper.eq(ShopPO::getPlatformId, filter.getPlatformId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,6 +270,14 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
|
||||
shopVO.setLogo(sysFileService.getFileAccessUrl(shop.getLogoImageId()));
|
||||
}
|
||||
|
||||
// 获取平台名称
|
||||
if (shop.getPlatformId() != null) {
|
||||
PlatformPO platform = platformMapper.selectById(shop.getPlatformId());
|
||||
if (platform != null) {
|
||||
shopVO.setPlatformName(platform.getPlatformName());
|
||||
}
|
||||
}
|
||||
|
||||
return shopVO;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user