refactor: 调整拼多多模块位置

This commit is contained in:
2026-07-24 13:52:56 +08:00
parent 611257dbf0
commit 39559b9751
45 changed files with 2272 additions and 52 deletions
@@ -0,0 +1,70 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.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.pdd.goods.model.dto.CreatePddGoodsDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.model.dto.PddGoodsFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.model.dto.UpdatePddGoodsDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.model.vo.PddGoodsVO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.service.PddGoodsService;
@Tag(name = "拼多多-商品管理", description = "拼多多商品的增删改查接口")
@RestController
@RequestMapping("/ec/pdd/goods")
public class PddGoodsController {
private final PddGoodsService pddGoodsService;
public PddGoodsController(PddGoodsService pddGoodsService) {
this.pddGoodsService = pddGoodsService;
}
@Operation(summary = "创建", description = "创建新的拼多多商品及SKU明细")
@PostMapping("/create")
@RequirePermission(value = "biz:pdd:goods:manage", description = "创建拼多多商品", allowSuper = true)
public ApiResponse<PddGoodsVO> createPddGoods(@Valid @RequestBody CreatePddGoodsDTO createPddGoodsDTO) {
PddGoodsVO vo = pddGoodsService.createPddGoods(createPddGoodsDTO);
return ApiResponse.success("创建成功", vo);
}
@Operation(summary = "更新", description = "更新现有拼多多商品信息")
@PutMapping("/update/{id}")
@RequirePermission(value = "biz:pdd:goods:manage", description = "更新拼多多商品", allowSuper = true)
public ApiResponse<PddGoodsVO> updatePddGoods(@Valid @RequestBody UpdatePddGoodsDTO updatePddGoodsDTO,
@Parameter(description = "商品ID") @PathVariable Long id) {
PddGoodsVO vo = pddGoodsService.updatePddGoods(updatePddGoodsDTO, id);
return ApiResponse.success("更新成功", vo);
}
@Operation(summary = "删除", description = "删除指定拼多多商品及SKU明细")
@DeleteMapping("/delete/{id}")
@RequirePermission(value = "biz:pdd:goods:manage", description = "删除拼多多商品", allowSuper = true)
public ApiResponse<Void> deletePddGoods(@Parameter(description = "商品ID") @PathVariable Long id) {
pddGoodsService.deletePddGoods(id);
return ApiResponse.success("删除成功");
}
@Operation(summary = "分页列表", description = "分页获取拼多多商品列表,支持条件过滤")
@PostMapping("/list")
@RequirePermission(value = "biz:pdd:goods:read", description = "查询拼多多商品列表", allowSuper = true)
public ApiResponse<PageResultVO<PddGoodsVO>> getPddGoodsPage(
@Valid @RequestBody PageQueryDTO<PddGoodsFilterDTO> pageQueryDTO) {
PageResultVO<PddGoodsVO> result = pddGoodsService.getPddGoodsPage(pageQueryDTO);
return ApiResponse.success("获取成功", result);
}
@Operation(summary = "详情", description = "根据ID获取拼多多商品详情,含SKU明细")
@GetMapping("/detail/{id}")
@RequirePermission(value = "biz:pdd:goods:read", description = "查询拼多多商品详情", allowSuper = true)
public ApiResponse<PddGoodsVO> getPddGoodsDetail(@Parameter(description = "商品ID") @PathVariable Long id) {
PddGoodsVO vo = pddGoodsService.getPddGoodsDetail(id);
return ApiResponse.success("获取成功", vo);
}
}
@@ -0,0 +1,11 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.model.po.PddGoodsPO;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface PddGoodsMapper extends BaseMapper<PddGoodsPO> {
}
@@ -0,0 +1,11 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.model.po.PddGoodsSkuPO;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface PddGoodsSkuMapper extends BaseMapper<PddGoodsSkuPO> {
}
@@ -0,0 +1,60 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.model.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.List;
@Data
@Schema(description = "创建拼多多商品DTO")
public class CreatePddGoodsDTO {
@Schema(description = "店铺ID(ec_shop.id)", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "店铺ID不能为空")
private Long shopId;
@Schema(description = "拼多多授权ID")
private Long pddAuthId;
@Schema(description = "拼多多商品ID", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "商品ID不能为空")
private String goodsId;
@Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "商品名称不能为空")
private String goodsName;
@Schema(description = "商品总库存")
private Integer goodsQuantity;
@Schema(description = "商品预扣库存")
private Integer goodsReserveQuantity;
@Schema(description = "商品主图")
private String imageUrl;
@Schema(description = "商品缩略图")
private String thumbUrl;
@Schema(description = "是否多SKU 0否 1是")
private Integer isMoreSku;
@Schema(description = "是否在架 0否 1是")
private Integer isOnsale;
@Schema(description = "拼多多创建时间")
private LocalDateTime pddCreatedAt;
@Schema(description = "商品完整JSON")
private String rawResponse;
@Schema(description = "最近一次同步时间", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "同步时间不能为空")
private LocalDateTime lastSyncTime;
@Schema(description = "SKU明细列表")
private List<CreatePddGoodsSkuDTO> skus;
}
@@ -0,0 +1,39 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.model.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
@Data
@Schema(description = "创建拼多多商品SKU明细DTO")
public class CreatePddGoodsSkuDTO {
@Schema(description = "拼多多商品ID(冗余)", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "商品ID不能为空")
private String goodsId;
@Schema(description = "拼多多SKU ID", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "SKU ID不能为空")
private String skuId;
@Schema(description = "规格描述")
private String spec;
@Schema(description = "规格明细JSON")
private String specDetails;
@Schema(description = "SKU库存")
private Integer skuQuantity;
@Schema(description = "SKU预扣库存")
private Integer reserveQuantity;
@Schema(description = "SKU是否在架 0否 1是")
private Integer isSkuOnsale;
@Schema(description = "商家外部商品编码")
private String outerGoodsId;
@Schema(description = "商家外部SKU编码")
private String outerId;
}
@@ -0,0 +1,24 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.model.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
@Schema(description = "拼多多商品过滤DTO")
public class PddGoodsFilterDTO {
@Schema(description = "店铺ID")
private Long shopId;
@Schema(description = "商品名称")
private String goodsName;
@Schema(description = "拼多多商品ID")
private String goodsId;
@Schema(description = "是否在架 0否 1是")
private Integer isOnsale;
@Schema(description = "是否多SKU 0否 1是")
private Integer isMoreSku;
}
@@ -0,0 +1,60 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.model.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.List;
@Data
@Schema(description = "更新拼多多商品DTO")
public class UpdatePddGoodsDTO {
@Schema(description = "店铺ID(ec_shop.id)", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "店铺ID不能为空")
private Long shopId;
@Schema(description = "拼多多授权ID")
private Long pddAuthId;
@Schema(description = "拼多多商品ID", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "商品ID不能为空")
private String goodsId;
@Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "商品名称不能为空")
private String goodsName;
@Schema(description = "商品总库存")
private Integer goodsQuantity;
@Schema(description = "商品预扣库存")
private Integer goodsReserveQuantity;
@Schema(description = "商品主图")
private String imageUrl;
@Schema(description = "商品缩略图")
private String thumbUrl;
@Schema(description = "是否多SKU 0否 1是")
private Integer isMoreSku;
@Schema(description = "是否在架 0否 1是")
private Integer isOnsale;
@Schema(description = "拼多多创建时间")
private LocalDateTime pddCreatedAt;
@Schema(description = "商品完整JSON")
private String rawResponse;
@Schema(description = "最近一次同步时间", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "同步时间不能为空")
private LocalDateTime lastSyncTime;
@Schema(description = "SKU明细列表")
private List<CreatePddGoodsSkuDTO> skus;
}
@@ -0,0 +1,62 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.model.po;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import java.time.LocalDateTime;
@Data
@TableName("ec_pdd_goods")
public class PddGoodsPO {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@TableField("company_id")
private Long companyId;
@TableField("shop_id")
private Long shopId;
@TableField("pdd_auth_id")
private Long pddAuthId;
@TableField("goods_id")
private String goodsId;
@TableField("goods_name")
private String goodsName;
@TableField("goods_quantity")
private Integer goodsQuantity;
@TableField("goods_reserve_quantity")
private Integer goodsReserveQuantity;
@TableField("image_url")
private String imageUrl;
@TableField("thumb_url")
private String thumbUrl;
@TableField("is_more_sku")
private Integer isMoreSku;
@TableField("is_onsale")
private Integer isOnsale;
@TableField("pdd_created_at")
private LocalDateTime pddCreatedAt;
@TableField("raw_response")
private String rawResponse;
@TableField("last_sync_time")
private LocalDateTime lastSyncTime;
@TableField(value = "create_time", fill = FieldFill.INSERT)
private LocalDateTime createTime;
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
}
@@ -0,0 +1,53 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.model.po;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import java.time.LocalDateTime;
@Data
@TableName("ec_pdd_goods_sku")
public class PddGoodsSkuPO {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@TableField("goods_row_id")
private Long goodsRowId;
@TableField("company_id")
private Long companyId;
@TableField("goods_id")
private String goodsId;
@TableField("sku_id")
private String skuId;
@TableField("spec")
private String spec;
@TableField("spec_details")
private String specDetails;
@TableField("sku_quantity")
private Integer skuQuantity;
@TableField("reserve_quantity")
private Integer reserveQuantity;
@TableField("is_sku_onsale")
private Integer isSkuOnsale;
@TableField("outer_goods_id")
private String outerGoodsId;
@TableField("outer_id")
private String outerId;
@TableField(value = "create_time", fill = FieldFill.INSERT)
private LocalDateTime createTime;
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
}
@@ -0,0 +1,42 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.model.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
@Schema(description = "拼多多商品SKU明细VO")
public class PddGoodsSkuVO {
@Schema(description = "主键ID")
private Long id;
@Schema(description = "商品主表ID")
private Long goodsRowId;
@Schema(description = "拼多多商品ID")
private String goodsId;
@Schema(description = "拼多多SKU ID")
private String skuId;
@Schema(description = "规格描述")
private String spec;
@Schema(description = "规格明细JSON")
private String specDetails;
@Schema(description = "SKU库存")
private Integer skuQuantity;
@Schema(description = "SKU预扣库存")
private Integer reserveQuantity;
@Schema(description = "SKU是否在架")
private Integer isSkuOnsale;
@Schema(description = "商家外部商品编码")
private String outerGoodsId;
@Schema(description = "商家外部SKU编码")
private String outerId;
}
@@ -0,0 +1,63 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.model.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.List;
@Data
@Schema(description = "拼多多商品VO")
public class PddGoodsVO {
@Schema(description = "主键ID")
private Long id;
@Schema(description = "公司ID")
private Long companyId;
@Schema(description = "店铺ID")
private Long shopId;
@Schema(description = "拼多多授权ID")
private Long pddAuthId;
@Schema(description = "拼多多商品ID")
private String goodsId;
@Schema(description = "商品名称")
private String goodsName;
@Schema(description = "商品总库存")
private Integer goodsQuantity;
@Schema(description = "商品预扣库存")
private Integer goodsReserveQuantity;
@Schema(description = "商品主图")
private String imageUrl;
@Schema(description = "商品缩略图")
private String thumbUrl;
@Schema(description = "是否多SKU")
private Integer isMoreSku;
@Schema(description = "是否在架")
private Integer isOnsale;
@Schema(description = "拼多多创建时间")
private LocalDateTime pddCreatedAt;
@Schema(description = "最近一次同步时间")
private LocalDateTime lastSyncTime;
@Schema(description = "创建时间")
private LocalDateTime createTime;
@Schema(description = "更新时间")
private LocalDateTime updateTime;
@Schema(description = "SKU明细列表")
private List<PddGoodsSkuVO> skus;
}
@@ -0,0 +1,23 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.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.pdd.goods.model.dto.CreatePddGoodsDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.model.dto.PddGoodsFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.model.dto.UpdatePddGoodsDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.model.po.PddGoodsPO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.model.vo.PddGoodsVO;
public interface PddGoodsService extends IService<PddGoodsPO> {
PddGoodsVO createPddGoods(CreatePddGoodsDTO createPddGoodsDTO);
PddGoodsVO updatePddGoods(UpdatePddGoodsDTO updatePddGoodsDTO, Long id);
void deletePddGoods(Long id);
PageResultVO<PddGoodsVO> getPddGoodsPage(PageQueryDTO<PddGoodsFilterDTO> pageQueryDTO);
PddGoodsVO getPddGoodsDetail(Long id);
}
@@ -0,0 +1,201 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.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.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.common.utils.BeanCopyUtils;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.mapper.PddGoodsMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.mapper.PddGoodsSkuMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.model.dto.CreatePddGoodsDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.model.dto.CreatePddGoodsSkuDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.model.dto.PddGoodsFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.model.dto.UpdatePddGoodsDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.model.po.PddGoodsPO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.model.po.PddGoodsSkuPO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.model.vo.PddGoodsSkuVO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.model.vo.PddGoodsVO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.goods.service.PddGoodsService;
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class PddGoodsServiceImpl extends ServiceImpl<PddGoodsMapper, PddGoodsPO> implements PddGoodsService {
private final PddGoodsSkuMapper pddGoodsSkuMapper;
private final CurrentUserContext currentUserContext;
public PddGoodsServiceImpl(PddGoodsSkuMapper pddGoodsSkuMapper, CurrentUserContext currentUserContext) {
this.pddGoodsSkuMapper = pddGoodsSkuMapper;
this.currentUserContext = currentUserContext;
}
@Override
@Transactional
public PddGoodsVO createPddGoods(CreatePddGoodsDTO createPddGoodsDTO) {
Long companyId = currentUserContext.getCurrentCompanyId();
LambdaQueryWrapper<PddGoodsPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PddGoodsPO::getCompanyId, companyId)
.eq(PddGoodsPO::getGoodsId, createPddGoodsDTO.getGoodsId());
if (this.count(wrapper) > 0) {
throw new BusinessException("该商品已存在");
}
PddGoodsPO goods = new PddGoodsPO();
BeanCopyUtils.copyProperties(createPddGoodsDTO, goods);
goods.setCompanyId(companyId);
this.save(goods);
if (createPddGoodsDTO.getSkus() != null && !createPddGoodsDTO.getSkus().isEmpty()) {
List<PddGoodsSkuPO> skus = createPddGoodsDTO.getSkus().stream()
.map(skuDTO -> convertToSkuPO(skuDTO, goods.getId(), companyId))
.collect(Collectors.toList());
skus.forEach(pddGoodsSkuMapper::insert);
}
return convertToVO(goods);
}
@Override
@Transactional
public PddGoodsVO updatePddGoods(UpdatePddGoodsDTO updatePddGoodsDTO, Long id) {
Long companyId = currentUserContext.getCurrentCompanyId();
PddGoodsPO existing = this.getById(id);
if (existing == null) {
throw new BusinessException("商品不存在");
}
LambdaQueryWrapper<PddGoodsPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PddGoodsPO::getCompanyId, companyId)
.eq(PddGoodsPO::getGoodsId, updatePddGoodsDTO.getGoodsId())
.ne(PddGoodsPO::getId, id);
if (this.count(wrapper) > 0) {
throw new BusinessException("该商品已存在");
}
PddGoodsPO goods = new PddGoodsPO();
BeanCopyUtils.copyProperties(updatePddGoodsDTO, goods);
goods.setId(id);
goods.setCompanyId(companyId);
this.updateById(goods);
LambdaQueryWrapper<PddGoodsSkuPO> deleteWrapper = new LambdaQueryWrapper<>();
deleteWrapper.eq(PddGoodsSkuPO::getGoodsRowId, id);
pddGoodsSkuMapper.delete(deleteWrapper);
if (updatePddGoodsDTO.getSkus() != null && !updatePddGoodsDTO.getSkus().isEmpty()) {
List<PddGoodsSkuPO> skus = updatePddGoodsDTO.getSkus().stream()
.map(skuDTO -> convertToSkuPO(skuDTO, id, companyId))
.collect(Collectors.toList());
skus.forEach(pddGoodsSkuMapper::insert);
}
return convertToVO(goods);
}
@Override
@Transactional
public void deletePddGoods(Long id) {
PddGoodsPO existing = this.getById(id);
if (existing == null) {
throw new BusinessException("商品不存在");
}
LambdaQueryWrapper<PddGoodsSkuPO> deleteWrapper = new LambdaQueryWrapper<>();
deleteWrapper.eq(PddGoodsSkuPO::getGoodsRowId, id);
pddGoodsSkuMapper.delete(deleteWrapper);
this.removeById(id);
}
@Override
public PageResultVO<PddGoodsVO> getPddGoodsPage(PageQueryDTO<PddGoodsFilterDTO> pageQueryDTO) {
Long companyId = currentUserContext.getCurrentCompanyId();
PddGoodsFilterDTO filter = pageQueryDTO.getFilters() != null
? pageQueryDTO.getFilters() : new PddGoodsFilterDTO();
LambdaQueryWrapper<PddGoodsPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PddGoodsPO::getCompanyId, companyId);
if (filter.getShopId() != null) {
wrapper.eq(PddGoodsPO::getShopId, filter.getShopId());
}
if (filter.getGoodsName() != null && !filter.getGoodsName().isEmpty()) {
wrapper.like(PddGoodsPO::getGoodsName, filter.getGoodsName());
}
if (filter.getGoodsId() != null && !filter.getGoodsId().isEmpty()) {
wrapper.eq(PddGoodsPO::getGoodsId, filter.getGoodsId());
}
if (filter.getIsOnsale() != null) {
wrapper.eq(PddGoodsPO::getIsOnsale, filter.getIsOnsale());
}
if (filter.getIsMoreSku() != null) {
wrapper.eq(PddGoodsPO::getIsMoreSku, filter.getIsMoreSku());
}
wrapper.orderByDesc(PddGoodsPO::getCreateTime);
IPage<PddGoodsPO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
IPage<PddGoodsPO> result = this.page(page, wrapper);
List<PddGoodsVO> voList = result.getRecords().stream()
.map(this::convertToVO)
.collect(Collectors.toList());
return PageResultVO.create(voList, result.getTotal(),
(int) pageQueryDTO.getPage(), (int) pageQueryDTO.getPageSize());
}
@Override
public PddGoodsVO getPddGoodsDetail(Long id) {
PddGoodsPO goods = this.getById(id);
if (goods == null) {
throw new BusinessException("商品不存在");
}
return convertToVO(goods);
}
private PddGoodsSkuPO convertToSkuPO(CreatePddGoodsSkuDTO dto, Long goodsRowId, Long companyId) {
PddGoodsSkuPO sku = new PddGoodsSkuPO();
BeanCopyUtils.copyProperties(dto, sku);
sku.setGoodsRowId(goodsRowId);
sku.setCompanyId(companyId);
return sku;
}
private PddGoodsVO convertToVO(PddGoodsPO goods) {
PddGoodsVO vo = new PddGoodsVO();
BeanCopyUtils.copyProperties(goods, vo);
LambdaQueryWrapper<PddGoodsSkuPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PddGoodsSkuPO::getGoodsRowId, goods.getId());
List<PddGoodsSkuPO> skus = pddGoodsSkuMapper.selectList(wrapper);
if (skus != null && !skus.isEmpty()) {
List<PddGoodsSkuVO> skuVOs = skus.stream()
.map(this::convertToSkuVO)
.collect(Collectors.toList());
vo.setSkus(skuVOs);
} else {
vo.setSkus(Collections.emptyList());
}
return vo;
}
private PddGoodsSkuVO convertToSkuVO(PddGoodsSkuPO sku) {
PddGoodsSkuVO vo = new PddGoodsSkuVO();
BeanCopyUtils.copyProperties(sku, vo);
return vo;
}
}
@@ -0,0 +1,70 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.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.pdd.order.model.dto.CreatePddOrderDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.model.dto.PddOrderFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.model.dto.UpdatePddOrderDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.model.vo.PddOrderVO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.service.PddOrderService;
@Tag(name = "拼多多-订单管理", description = "拼多多订单的增删改查接口")
@RestController
@RequestMapping("/ec/pdd/order")
public class PddOrderController {
private final PddOrderService pddOrderService;
public PddOrderController(PddOrderService pddOrderService) {
this.pddOrderService = pddOrderService;
}
@Operation(summary = "创建", description = "创建新的拼多多订单及商品明细")
@PostMapping("/create")
@RequirePermission(value = "biz:pdd:order:manage", description = "创建拼多多订单", allowSuper = true)
public ApiResponse<PddOrderVO> createPddOrder(@Valid @RequestBody CreatePddOrderDTO createPddOrderDTO) {
PddOrderVO vo = pddOrderService.createPddOrder(createPddOrderDTO);
return ApiResponse.success("创建成功", vo);
}
@Operation(summary = "更新", description = "更新现有拼多多订单信息")
@PutMapping("/update/{id}")
@RequirePermission(value = "biz:pdd:order:manage", description = "更新拼多多订单", allowSuper = true)
public ApiResponse<PddOrderVO> updatePddOrder(@Valid @RequestBody UpdatePddOrderDTO updatePddOrderDTO,
@Parameter(description = "订单ID") @PathVariable Long id) {
PddOrderVO vo = pddOrderService.updatePddOrder(updatePddOrderDTO, id);
return ApiResponse.success("更新成功", vo);
}
@Operation(summary = "删除", description = "删除指定拼多多订单及商品明细")
@DeleteMapping("/delete/{id}")
@RequirePermission(value = "biz:pdd:order:manage", description = "删除拼多多订单", allowSuper = true)
public ApiResponse<Void> deletePddOrder(@Parameter(description = "订单ID") @PathVariable Long id) {
pddOrderService.deletePddOrder(id);
return ApiResponse.success("删除成功");
}
@Operation(summary = "分页列表", description = "分页获取拼多多订单列表,支持条件过滤")
@PostMapping("/list")
@RequirePermission(value = "biz:pdd:order:read", description = "查询拼多多订单列表", allowSuper = true)
public ApiResponse<PageResultVO<PddOrderVO>> getPddOrderPage(
@Valid @RequestBody PageQueryDTO<PddOrderFilterDTO> pageQueryDTO) {
PageResultVO<PddOrderVO> result = pddOrderService.getPddOrderPage(pageQueryDTO);
return ApiResponse.success("获取成功", result);
}
@Operation(summary = "详情", description = "根据ID获取拼多多订单详情,含商品明细")
@GetMapping("/detail/{id}")
@RequirePermission(value = "biz:pdd:order:read", description = "查询拼多多订单详情", allowSuper = true)
public ApiResponse<PddOrderVO> getPddOrderDetail(@Parameter(description = "订单ID") @PathVariable Long id) {
PddOrderVO vo = pddOrderService.getPddOrderDetail(id);
return ApiResponse.success("获取成功", vo);
}
}
@@ -0,0 +1,11 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.model.po.PddOrderItemPO;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface PddOrderItemMapper extends BaseMapper<PddOrderItemPO> {
}
@@ -0,0 +1,11 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.model.po.PddOrderPO;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface PddOrderMapper extends BaseMapper<PddOrderPO> {
}
@@ -0,0 +1,128 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.model.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
@Data
@Schema(description = "创建拼多多订单DTO")
public class CreatePddOrderDTO {
@Schema(description = "店铺ID(ec_shop.id)", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "店铺ID不能为空")
private Long shopId;
@Schema(description = "拼多多授权ID")
private Long pddAuthId;
@Schema(description = "拼多多订单号", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "拼多多订单号不能为空")
private String orderSn;
@Schema(description = "订单状态:1待发货 2已发货待签收 3已签收", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "订单状态不能为空")
private Integer orderStatus;
@Schema(description = "退款状态")
private Integer refundStatus;
@Schema(description = "售后状态")
private Integer afterSalesStatus;
@Schema(description = "成交状态")
private Integer confirmStatus;
@Schema(description = "实付金额")
private BigDecimal payAmount;
@Schema(description = "商品金额")
private BigDecimal goodsAmount;
@Schema(description = "折扣金额")
private BigDecimal discountAmount;
@Schema(description = "邮费")
private BigDecimal postage;
@Schema(description = "平台优惠")
private BigDecimal platformDiscount;
@Schema(description = "商家优惠")
private BigDecimal sellerDiscount;
@Schema(description = "快递公司编码")
private Long logisticsId;
@Schema(description = "快递运单号")
private String trackingNumber;
@Schema(description = "下单时间", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "下单时间不能为空")
private LocalDateTime createdTime;
@Schema(description = "支付时间")
private LocalDateTime payTime;
@Schema(description = "成交时间")
private LocalDateTime confirmTime;
@Schema(description = "发货时间")
private LocalDateTime shippingTime;
@Schema(description = "签收时间")
private LocalDateTime receiveTime;
@Schema(description = "承诺发货时间")
private LocalDateTime lastShipTime;
@Schema(description = "拼多多订单更新时间")
private LocalDateTime pddUpdatedAt;
@Schema(description = "省份")
private String province;
@Schema(description = "城市")
private String city;
@Schema(description = "区县")
private String town;
@Schema(description = "收件人姓名脱敏")
private String receiverNameMask;
@Schema(description = "收件人手机脱敏")
private String receiverPhoneMask;
@Schema(description = "收件地址脱敏")
private String receiverAddressMask;
@Schema(description = "买家留言")
private String buyerMemo;
@Schema(description = "商家备注")
private String remark;
@Schema(description = "交易类型")
private Integer tradeType;
@Schema(description = "是否预售 0否 1是")
private Integer isPreSale;
@Schema(description = "拼团状态")
private Integer groupStatus;
@Schema(description = "订单完整JSON")
private String rawResponse;
@Schema(description = "最近一次同步时间", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "同步时间不能为空")
private LocalDateTime lastSyncTime;
@Schema(description = "订单商品明细")
private List<CreatePddOrderItemDTO> items;
}
@@ -0,0 +1,44 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.model.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.math.BigDecimal;
@Data
@Schema(description = "创建拼多多订单商品明细DTO")
public class CreatePddOrderItemDTO {
@Schema(description = "拼多多商品ID", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "商品ID不能为空")
private String goodsId;
@Schema(description = "拼多多SKU ID", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "SKU ID不能为空")
private String skuId;
@Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "商品名称不能为空")
private String goodsName;
@Schema(description = "商品规格")
private String goodsSpec;
@Schema(description = "商品图片")
private String goodsImg;
@Schema(description = "商品数量")
@NotNull(message = "商品数量不能为空")
private Integer goodsCount;
@Schema(description = "商品单价")
private BigDecimal goodsPrice;
@Schema(description = "商家外部商品编码")
private String outerGoodsId;
@Schema(description = "商家外部SKU编码")
private String outerId;
}
@@ -0,0 +1,38 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.model.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
@Data
@Schema(description = "拼多多订单过滤DTO")
public class PddOrderFilterDTO {
@Schema(description = "店铺ID")
private Long shopId;
@Schema(description = "拼多多订单号")
private String orderSn;
@Schema(description = "订单状态")
private Integer orderStatus;
@Schema(description = "退款状态")
private Integer refundStatus;
@Schema(description = "售后状态")
private Integer afterSalesStatus;
@Schema(description = "下单时间-开始")
private LocalDateTime createdTimeStart;
@Schema(description = "下单时间-结束")
private LocalDateTime createdTimeEnd;
@Schema(description = "支付时间-开始")
private LocalDateTime payTimeStart;
@Schema(description = "支付时间-结束")
private LocalDateTime payTimeEnd;
}
@@ -0,0 +1,128 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.model.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
@Data
@Schema(description = "更新拼多多订单DTO")
public class UpdatePddOrderDTO {
@Schema(description = "店铺ID(ec_shop.id)", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "店铺ID不能为空")
private Long shopId;
@Schema(description = "拼多多授权ID")
private Long pddAuthId;
@Schema(description = "拼多多订单号", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "拼多多订单号不能为空")
private String orderSn;
@Schema(description = "订单状态:1待发货 2已发货待签收 3已签收", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "订单状态不能为空")
private Integer orderStatus;
@Schema(description = "退款状态")
private Integer refundStatus;
@Schema(description = "售后状态")
private Integer afterSalesStatus;
@Schema(description = "成交状态")
private Integer confirmStatus;
@Schema(description = "实付金额")
private BigDecimal payAmount;
@Schema(description = "商品金额")
private BigDecimal goodsAmount;
@Schema(description = "折扣金额")
private BigDecimal discountAmount;
@Schema(description = "邮费")
private BigDecimal postage;
@Schema(description = "平台优惠")
private BigDecimal platformDiscount;
@Schema(description = "商家优惠")
private BigDecimal sellerDiscount;
@Schema(description = "快递公司编码")
private Long logisticsId;
@Schema(description = "快递运单号")
private String trackingNumber;
@Schema(description = "下单时间", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "下单时间不能为空")
private LocalDateTime createdTime;
@Schema(description = "支付时间")
private LocalDateTime payTime;
@Schema(description = "成交时间")
private LocalDateTime confirmTime;
@Schema(description = "发货时间")
private LocalDateTime shippingTime;
@Schema(description = "签收时间")
private LocalDateTime receiveTime;
@Schema(description = "承诺发货时间")
private LocalDateTime lastShipTime;
@Schema(description = "拼多多订单更新时间")
private LocalDateTime pddUpdatedAt;
@Schema(description = "省份")
private String province;
@Schema(description = "城市")
private String city;
@Schema(description = "区县")
private String town;
@Schema(description = "收件人姓名脱敏")
private String receiverNameMask;
@Schema(description = "收件人手机脱敏")
private String receiverPhoneMask;
@Schema(description = "收件地址脱敏")
private String receiverAddressMask;
@Schema(description = "买家留言")
private String buyerMemo;
@Schema(description = "商家备注")
private String remark;
@Schema(description = "交易类型")
private Integer tradeType;
@Schema(description = "是否预售 0否 1是")
private Integer isPreSale;
@Schema(description = "拼团状态")
private Integer groupStatus;
@Schema(description = "订单完整JSON")
private String rawResponse;
@Schema(description = "最近一次同步时间", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "同步时间不能为空")
private LocalDateTime lastSyncTime;
@Schema(description = "订单商品明细")
private List<CreatePddOrderItemDTO> items;
}
@@ -0,0 +1,57 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.model.po;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data
@TableName("ec_pdd_order_item")
public class PddOrderItemPO {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@TableField("order_id")
private Long orderId;
@TableField("company_id")
private Long companyId;
@TableField("order_sn")
private String orderSn;
@TableField("goods_id")
private String goodsId;
@TableField("sku_id")
private String skuId;
@TableField("goods_name")
private String goodsName;
@TableField("goods_spec")
private String goodsSpec;
@TableField("goods_img")
private String goodsImg;
@TableField("goods_count")
private Integer goodsCount;
@TableField("goods_price")
private BigDecimal goodsPrice;
@TableField("outer_goods_id")
private String outerGoodsId;
@TableField("outer_id")
private String outerId;
@TableField(value = "create_time", fill = FieldFill.INSERT)
private LocalDateTime createTime;
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
}
@@ -0,0 +1,129 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.model.po;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data
@TableName("ec_pdd_order")
public class PddOrderPO {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@TableField("company_id")
private Long companyId;
@TableField("shop_id")
private Long shopId;
@TableField("pdd_auth_id")
private Long pddAuthId;
@TableField("order_sn")
private String orderSn;
@TableField("order_status")
private Integer orderStatus;
@TableField("refund_status")
private Integer refundStatus;
@TableField("after_sales_status")
private Integer afterSalesStatus;
@TableField("confirm_status")
private Integer confirmStatus;
@TableField("pay_amount")
private BigDecimal payAmount;
@TableField("goods_amount")
private BigDecimal goodsAmount;
@TableField("discount_amount")
private BigDecimal discountAmount;
@TableField("postage")
private BigDecimal postage;
@TableField("platform_discount")
private BigDecimal platformDiscount;
@TableField("seller_discount")
private BigDecimal sellerDiscount;
@TableField("logistics_id")
private Long logisticsId;
@TableField("tracking_number")
private String trackingNumber;
@TableField("created_time")
private LocalDateTime createdTime;
@TableField("pay_time")
private LocalDateTime payTime;
@TableField("confirm_time")
private LocalDateTime confirmTime;
@TableField("shipping_time")
private LocalDateTime shippingTime;
@TableField("receive_time")
private LocalDateTime receiveTime;
@TableField("last_ship_time")
private LocalDateTime lastShipTime;
@TableField("pdd_updated_at")
private LocalDateTime pddUpdatedAt;
@TableField("province")
private String province;
@TableField("city")
private String city;
@TableField("town")
private String town;
@TableField("receiver_name_mask")
private String receiverNameMask;
@TableField("receiver_phone_mask")
private String receiverPhoneMask;
@TableField("receiver_address_mask")
private String receiverAddressMask;
@TableField("buyer_memo")
private String buyerMemo;
@TableField("remark")
private String remark;
@TableField("trade_type")
private Integer tradeType;
@TableField("is_pre_sale")
private Integer isPreSale;
@TableField("group_status")
private Integer groupStatus;
@TableField("raw_response")
private String rawResponse;
@TableField("last_sync_time")
private LocalDateTime lastSyncTime;
@TableField(value = "create_time", fill = FieldFill.INSERT)
private LocalDateTime createTime;
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
}
@@ -0,0 +1,47 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.model.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;
@Data
@Schema(description = "拼多多订单商品明细VO")
public class PddOrderItemVO {
@Schema(description = "主键ID")
private Long id;
@Schema(description = "订单ID")
private Long orderId;
@Schema(description = "拼多多订单号")
private String orderSn;
@Schema(description = "拼多多商品ID")
private String goodsId;
@Schema(description = "拼多多SKU ID")
private String skuId;
@Schema(description = "商品名称")
private String goodsName;
@Schema(description = "商品规格")
private String goodsSpec;
@Schema(description = "商品图片")
private String goodsImg;
@Schema(description = "商品数量")
private Integer goodsCount;
@Schema(description = "商品单价")
private BigDecimal goodsPrice;
@Schema(description = "商家外部商品编码")
private String outerGoodsId;
@Schema(description = "商家外部SKU编码")
private String outerId;
}
@@ -0,0 +1,124 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.model.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
@Data
@Schema(description = "拼多多订单VO")
public class PddOrderVO {
@Schema(description = "主键ID")
private Long id;
@Schema(description = "公司ID")
private Long companyId;
@Schema(description = "店铺ID")
private Long shopId;
@Schema(description = "拼多多授权ID")
private Long pddAuthId;
@Schema(description = "拼多多订单号")
private String orderSn;
@Schema(description = "订单状态:1待发货 2已发货待签收 3已签收")
private Integer orderStatus;
@Schema(description = "退款状态")
private Integer refundStatus;
@Schema(description = "售后状态")
private Integer afterSalesStatus;
@Schema(description = "成交状态")
private Integer confirmStatus;
@Schema(description = "实付金额")
private BigDecimal payAmount;
@Schema(description = "商品金额")
private BigDecimal goodsAmount;
@Schema(description = "折扣金额")
private BigDecimal discountAmount;
@Schema(description = "邮费")
private BigDecimal postage;
@Schema(description = "平台优惠")
private BigDecimal platformDiscount;
@Schema(description = "商家优惠")
private BigDecimal sellerDiscount;
@Schema(description = "快递公司编码")
private Long logisticsId;
@Schema(description = "快递运单号")
private String trackingNumber;
@Schema(description = "下单时间")
private LocalDateTime createdTime;
@Schema(description = "支付时间")
private LocalDateTime payTime;
@Schema(description = "成交时间")
private LocalDateTime confirmTime;
@Schema(description = "发货时间")
private LocalDateTime shippingTime;
@Schema(description = "签收时间")
private LocalDateTime receiveTime;
@Schema(description = "省份")
private String province;
@Schema(description = "城市")
private String city;
@Schema(description = "区县")
private String town;
@Schema(description = "收件人姓名脱敏")
private String receiverNameMask;
@Schema(description = "收件人手机脱敏")
private String receiverPhoneMask;
@Schema(description = "收件地址脱敏")
private String receiverAddressMask;
@Schema(description = "买家留言")
private String buyerMemo;
@Schema(description = "商家备注")
private String remark;
@Schema(description = "交易类型")
private Integer tradeType;
@Schema(description = "是否预售")
private Integer isPreSale;
@Schema(description = "拼团状态")
private Integer groupStatus;
@Schema(description = "最近一次同步时间")
private LocalDateTime lastSyncTime;
@Schema(description = "创建时间")
private LocalDateTime createTime;
@Schema(description = "更新时间")
private LocalDateTime updateTime;
@Schema(description = "订单商品明细")
private List<PddOrderItemVO> items;
}
@@ -0,0 +1,23 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.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.pdd.order.model.dto.CreatePddOrderDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.model.dto.PddOrderFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.model.dto.UpdatePddOrderDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.model.po.PddOrderPO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.model.vo.PddOrderVO;
public interface PddOrderService extends IService<PddOrderPO> {
PddOrderVO createPddOrder(CreatePddOrderDTO createPddOrderDTO);
PddOrderVO updatePddOrder(UpdatePddOrderDTO updatePddOrderDTO, Long id);
void deletePddOrder(Long id);
PageResultVO<PddOrderVO> getPddOrderPage(PageQueryDTO<PddOrderFilterDTO> pageQueryDTO);
PddOrderVO getPddOrderDetail(Long id);
}
@@ -0,0 +1,214 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.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.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.common.utils.BeanCopyUtils;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.mapper.PddOrderItemMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.mapper.PddOrderMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.model.dto.CreatePddOrderDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.model.dto.CreatePddOrderItemDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.model.dto.PddOrderFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.model.dto.UpdatePddOrderDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.model.po.PddOrderItemPO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.model.po.PddOrderPO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.model.vo.PddOrderItemVO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.model.vo.PddOrderVO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.service.PddOrderService;
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class PddOrderServiceImpl extends ServiceImpl<PddOrderMapper, PddOrderPO> implements PddOrderService {
private final PddOrderItemMapper pddOrderItemMapper;
private final CurrentUserContext currentUserContext;
public PddOrderServiceImpl(PddOrderItemMapper pddOrderItemMapper, CurrentUserContext currentUserContext) {
this.pddOrderItemMapper = pddOrderItemMapper;
this.currentUserContext = currentUserContext;
}
@Override
@Transactional
public PddOrderVO createPddOrder(CreatePddOrderDTO createPddOrderDTO) {
Long companyId = currentUserContext.getCurrentCompanyId();
LambdaQueryWrapper<PddOrderPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PddOrderPO::getCompanyId, companyId)
.eq(PddOrderPO::getOrderSn, createPddOrderDTO.getOrderSn());
if (this.count(wrapper) > 0) {
throw new BusinessException("该订单号已存在");
}
PddOrderPO order = new PddOrderPO();
BeanCopyUtils.copyProperties(createPddOrderDTO, order);
order.setCompanyId(companyId);
this.save(order);
if (createPddOrderDTO.getItems() != null && !createPddOrderDTO.getItems().isEmpty()) {
List<PddOrderItemPO> items = createPddOrderDTO.getItems().stream()
.map(itemDTO -> convertToItemPO(itemDTO, order.getId(), companyId, order.getOrderSn()))
.collect(Collectors.toList());
items.forEach(pddOrderItemMapper::insert);
}
return convertToVO(order);
}
@Override
@Transactional
public PddOrderVO updatePddOrder(UpdatePddOrderDTO updatePddOrderDTO, Long id) {
Long companyId = currentUserContext.getCurrentCompanyId();
PddOrderPO existing = this.getById(id);
if (existing == null) {
throw new BusinessException("订单不存在");
}
LambdaQueryWrapper<PddOrderPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PddOrderPO::getCompanyId, companyId)
.eq(PddOrderPO::getOrderSn, updatePddOrderDTO.getOrderSn())
.ne(PddOrderPO::getId, id);
if (this.count(wrapper) > 0) {
throw new BusinessException("该订单号已存在");
}
PddOrderPO order = new PddOrderPO();
BeanCopyUtils.copyProperties(updatePddOrderDTO, order);
order.setId(id);
order.setCompanyId(companyId);
this.updateById(order);
LambdaQueryWrapper<PddOrderItemPO> deleteWrapper = new LambdaQueryWrapper<>();
deleteWrapper.eq(PddOrderItemPO::getOrderId, id);
pddOrderItemMapper.delete(deleteWrapper);
if (updatePddOrderDTO.getItems() != null && !updatePddOrderDTO.getItems().isEmpty()) {
List<PddOrderItemPO> items = updatePddOrderDTO.getItems().stream()
.map(itemDTO -> convertToItemPO(itemDTO, id, companyId, order.getOrderSn()))
.collect(Collectors.toList());
items.forEach(pddOrderItemMapper::insert);
}
return convertToVO(order);
}
@Override
@Transactional
public void deletePddOrder(Long id) {
PddOrderPO existing = this.getById(id);
if (existing == null) {
throw new BusinessException("订单不存在");
}
LambdaQueryWrapper<PddOrderItemPO> deleteWrapper = new LambdaQueryWrapper<>();
deleteWrapper.eq(PddOrderItemPO::getOrderId, id);
pddOrderItemMapper.delete(deleteWrapper);
this.removeById(id);
}
@Override
public PageResultVO<PddOrderVO> getPddOrderPage(PageQueryDTO<PddOrderFilterDTO> pageQueryDTO) {
Long companyId = currentUserContext.getCurrentCompanyId();
PddOrderFilterDTO filter = pageQueryDTO.getFilters() != null
? pageQueryDTO.getFilters() : new PddOrderFilterDTO();
LambdaQueryWrapper<PddOrderPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PddOrderPO::getCompanyId, companyId);
if (filter.getShopId() != null) {
wrapper.eq(PddOrderPO::getShopId, filter.getShopId());
}
if (filter.getOrderSn() != null && !filter.getOrderSn().isEmpty()) {
wrapper.eq(PddOrderPO::getOrderSn, filter.getOrderSn());
}
if (filter.getOrderStatus() != null) {
wrapper.eq(PddOrderPO::getOrderStatus, filter.getOrderStatus());
}
if (filter.getRefundStatus() != null) {
wrapper.eq(PddOrderPO::getRefundStatus, filter.getRefundStatus());
}
if (filter.getAfterSalesStatus() != null) {
wrapper.eq(PddOrderPO::getAfterSalesStatus, filter.getAfterSalesStatus());
}
if (filter.getCreatedTimeStart() != null) {
wrapper.ge(PddOrderPO::getCreatedTime, filter.getCreatedTimeStart());
}
if (filter.getCreatedTimeEnd() != null) {
wrapper.le(PddOrderPO::getCreatedTime, filter.getCreatedTimeEnd());
}
if (filter.getPayTimeStart() != null) {
wrapper.ge(PddOrderPO::getPayTime, filter.getPayTimeStart());
}
if (filter.getPayTimeEnd() != null) {
wrapper.le(PddOrderPO::getPayTime, filter.getPayTimeEnd());
}
wrapper.orderByDesc(PddOrderPO::getCreatedTime);
IPage<PddOrderPO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
IPage<PddOrderPO> result = this.page(page, wrapper);
List<PddOrderVO> voList = result.getRecords().stream()
.map(this::convertToVO)
.collect(Collectors.toList());
return PageResultVO.create(voList, result.getTotal(),
(int) pageQueryDTO.getPage(), (int) pageQueryDTO.getPageSize());
}
@Override
public PddOrderVO getPddOrderDetail(Long id) {
PddOrderPO order = this.getById(id);
if (order == null) {
throw new BusinessException("订单不存在");
}
return convertToVO(order);
}
private PddOrderItemPO convertToItemPO(CreatePddOrderItemDTO dto, Long orderId, Long companyId, String orderSn) {
PddOrderItemPO item = new PddOrderItemPO();
BeanCopyUtils.copyProperties(dto, item);
item.setOrderId(orderId);
item.setCompanyId(companyId);
item.setOrderSn(orderSn);
return item;
}
private PddOrderVO convertToVO(PddOrderPO order) {
PddOrderVO vo = new PddOrderVO();
BeanCopyUtils.copyProperties(order, vo);
LambdaQueryWrapper<PddOrderItemPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PddOrderItemPO::getOrderId, order.getId());
List<PddOrderItemPO> items = pddOrderItemMapper.selectList(wrapper);
if (items != null && !items.isEmpty()) {
List<PddOrderItemVO> itemVOs = items.stream()
.map(this::convertToItemVO)
.collect(Collectors.toList());
vo.setItems(itemVOs);
} else {
vo.setItems(Collections.emptyList());
}
return vo;
}
private PddOrderItemVO convertToItemVO(PddOrderItemPO item) {
PddOrderItemVO vo = new PddOrderItemVO();
BeanCopyUtils.copyProperties(item, vo);
return vo;
}
}
@@ -0,0 +1,70 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.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.pdd.shop.model.dto.CreatePddShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.model.dto.PddShopFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.model.dto.UpdatePddShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.model.vo.PddShopVO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.service.PddShopService;
@Tag(name = "拼多多-店铺管理", description = "拼多多店铺信息的增删改查接口")
@RestController
@RequestMapping("/ec/pdd/shop")
public class PddShopController {
private final PddShopService pddShopService;
public PddShopController(PddShopService pddShopService) {
this.pddShopService = pddShopService;
}
@Operation(summary = "创建", description = "创建新的拼多多店铺信息")
@PostMapping("/create")
@RequirePermission(value = "biz:pdd:shop:manage", description = "创建拼多多店铺", allowSuper = true)
public ApiResponse<PddShopVO> createPddShop(@Valid @RequestBody CreatePddShopDTO createPddShopDTO) {
PddShopVO vo = pddShopService.createPddShop(createPddShopDTO);
return ApiResponse.success("创建成功", vo);
}
@Operation(summary = "更新", description = "更新现有拼多多店铺信息")
@PutMapping("/update/{id}")
@RequirePermission(value = "biz:pdd:shop:manage", description = "更新拼多多店铺", allowSuper = true)
public ApiResponse<PddShopVO> updatePddShop(@Valid @RequestBody UpdatePddShopDTO updatePddShopDTO,
@Parameter(description = "店铺ID") @PathVariable Long id) {
PddShopVO vo = pddShopService.updatePddShop(updatePddShopDTO, id);
return ApiResponse.success("更新成功", vo);
}
@Operation(summary = "删除", description = "删除指定拼多多店铺")
@DeleteMapping("/delete/{id}")
@RequirePermission(value = "biz:pdd:shop:manage", description = "删除拼多多店铺", allowSuper = true)
public ApiResponse<Void> deletePddShop(@Parameter(description = "店铺ID") @PathVariable Long id) {
pddShopService.deletePddShop(id);
return ApiResponse.success("删除成功");
}
@Operation(summary = "分页列表", description = "分页获取拼多多店铺列表,支持条件过滤")
@PostMapping("/list")
@RequirePermission(value = "biz:pdd:shop:read", description = "查询拼多多店铺列表", allowSuper = true)
public ApiResponse<PageResultVO<PddShopVO>> getPddShopPage(
@Valid @RequestBody PageQueryDTO<PddShopFilterDTO> pageQueryDTO) {
PageResultVO<PddShopVO> result = pddShopService.getPddShopPage(pageQueryDTO);
return ApiResponse.success("获取成功", result);
}
@Operation(summary = "详情", description = "根据ID获取拼多多店铺详情")
@GetMapping("/detail/{id}")
@RequirePermission(value = "biz:pdd:shop:read", description = "查询拼多多店铺详情", allowSuper = true)
public ApiResponse<PddShopVO> getPddShopDetail(@Parameter(description = "店铺ID") @PathVariable Long id) {
PddShopVO vo = pddShopService.getPddShopDetail(id);
return ApiResponse.success("获取成功", vo);
}
}
@@ -0,0 +1,11 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.model.po.PddShopPO;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface PddShopMapper extends BaseMapper<PddShopPO> {
}
@@ -0,0 +1,44 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.model.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.time.LocalDateTime;
@Data
@Schema(description = "创建拼多多店铺DTO")
public class CreatePddShopDTO {
@Schema(description = "内部店铺ID(ec_shop.id)")
private Long shopId;
@Schema(description = "拼多多授权ID(open_pdd_auth.id)")
private Long pddAuthId;
@Schema(description = "拼多多店铺ID(mall_id)", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "拼多多店铺ID不能为空")
private Long mallId;
@Schema(description = "店铺名称", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "店铺名称不能为空")
private String mallName;
@Schema(description = "店铺logo")
private String logo;
@Schema(description = "店铺描述")
private String mallDesc;
@Schema(description = "店铺类型:1个人 2企业 3旗舰店 4专卖店 5专营店 6普通店", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "店铺类型不能为空")
private Integer merchantType;
@Schema(description = "店铺身份:0厂商 1分销商 2都不是 3都是")
private Integer mallCharacter;
@Schema(description = "最近一次同步时间", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "同步时间不能为空")
private LocalDateTime lastSyncTime;
}
@@ -0,0 +1,24 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.model.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
@Schema(description = "拼多多店铺过滤DTO")
public class PddShopFilterDTO {
@Schema(description = "店铺名称")
private String mallName;
@Schema(description = "店铺类型")
private Integer merchantType;
@Schema(description = "店铺身份")
private Integer mallCharacter;
@Schema(description = "内部店铺ID")
private Long shopId;
@Schema(description = "拼多多授权ID")
private Long pddAuthId;
}
@@ -0,0 +1,44 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.model.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.time.LocalDateTime;
@Data
@Schema(description = "更新拼多多店铺DTO")
public class UpdatePddShopDTO {
@Schema(description = "内部店铺ID(ec_shop.id)")
private Long shopId;
@Schema(description = "拼多多授权ID(open_pdd_auth.id)")
private Long pddAuthId;
@Schema(description = "拼多多店铺ID(mall_id)", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "拼多多店铺ID不能为空")
private Long mallId;
@Schema(description = "店铺名称", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "店铺名称不能为空")
private String mallName;
@Schema(description = "店铺logo")
private String logo;
@Schema(description = "店铺描述")
private String mallDesc;
@Schema(description = "店铺类型:1个人 2企业 3旗舰店 4专卖店 5专营店 6普通店", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "店铺类型不能为空")
private Integer merchantType;
@Schema(description = "店铺身份:0厂商 1分销商 2都不是 3都是")
private Integer mallCharacter;
@Schema(description = "最近一次同步时间", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "同步时间不能为空")
private LocalDateTime lastSyncTime;
}
@@ -0,0 +1,50 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.model.po;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import java.time.LocalDateTime;
@Data
@TableName("ec_pdd_shop")
public class PddShopPO {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@TableField("company_id")
private Long companyId;
@TableField("shop_id")
private Long shopId;
@TableField("pdd_auth_id")
private Long pddAuthId;
@TableField("mall_id")
private Long mallId;
@TableField("mall_name")
private String mallName;
@TableField("logo")
private String logo;
@TableField("mall_desc")
private String mallDesc;
@TableField("merchant_type")
private Integer merchantType;
@TableField("mall_character")
private Integer mallCharacter;
@TableField("last_sync_time")
private LocalDateTime lastSyncTime;
@TableField(value = "create_time", fill = FieldFill.INSERT)
private LocalDateTime createTime;
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
}
@@ -0,0 +1,50 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.model.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
@Data
@Schema(description = "拼多多店铺VO")
public class PddShopVO {
@Schema(description = "主键ID")
private Long id;
@Schema(description = "公司ID")
private Long companyId;
@Schema(description = "内部店铺ID(ec_shop.id)")
private Long shopId;
@Schema(description = "拼多多授权ID(open_pdd_auth.id)")
private Long pddAuthId;
@Schema(description = "拼多多店铺ID(mall_id)")
private Long mallId;
@Schema(description = "店铺名称")
private String mallName;
@Schema(description = "店铺logo")
private String logo;
@Schema(description = "店铺描述")
private String mallDesc;
@Schema(description = "店铺类型:1个人 2企业 3旗舰店 4专卖店 5专营店 6普通店")
private Integer merchantType;
@Schema(description = "店铺身份:0厂商 1分销商 2都不是 3都是")
private Integer mallCharacter;
@Schema(description = "最近一次同步时间")
private LocalDateTime lastSyncTime;
@Schema(description = "创建时间")
private LocalDateTime createTime;
@Schema(description = "更新时间")
private LocalDateTime updateTime;
}
@@ -0,0 +1,23 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.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.pdd.shop.model.dto.CreatePddShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.model.dto.PddShopFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.model.dto.UpdatePddShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.model.po.PddShopPO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.model.vo.PddShopVO;
public interface PddShopService extends IService<PddShopPO> {
PddShopVO createPddShop(CreatePddShopDTO createPddShopDTO);
PddShopVO updatePddShop(UpdatePddShopDTO updatePddShopDTO, Long id);
void deletePddShop(Long id);
PageResultVO<PddShopVO> getPddShopPage(PageQueryDTO<PddShopFilterDTO> pageQueryDTO);
PddShopVO getPddShopDetail(Long id);
}
@@ -0,0 +1,163 @@
package top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.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.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.common.utils.BeanCopyUtils;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.mapper.PddShopMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.model.dto.CreatePddShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.model.dto.PddShopFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.model.dto.UpdatePddShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.model.po.PddShopPO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.model.vo.PddShopVO;
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.service.PddShopService;
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class PddShopServiceImpl extends ServiceImpl<PddShopMapper, PddShopPO> implements PddShopService {
private final CurrentUserContext currentUserContext;
public PddShopServiceImpl(CurrentUserContext currentUserContext) {
this.currentUserContext = currentUserContext;
}
@Override
@Transactional
public PddShopVO createPddShop(CreatePddShopDTO createPddShopDTO) {
Long companyId = currentUserContext.getCurrentCompanyId();
LambdaQueryWrapper<PddShopPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PddShopPO::getCompanyId, companyId)
.eq(PddShopPO::getMallId, createPddShopDTO.getMallId());
if (this.count(wrapper) > 0) {
throw new BusinessException("该拼多多店铺已存在");
}
if (createPddShopDTO.getPddAuthId() != null) {
wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PddShopPO::getPddAuthId, createPddShopDTO.getPddAuthId());
if (this.count(wrapper) > 0) {
throw new BusinessException("该授权已绑定其他店铺");
}
}
PddShopPO shop = new PddShopPO();
BeanCopyUtils.copyProperties(createPddShopDTO, shop);
shop.setCompanyId(companyId);
if (shop.getMallCharacter() == null) {
shop.setMallCharacter(2);
}
this.save(shop);
return convertToVO(shop);
}
@Override
@Transactional
public PddShopVO updatePddShop(UpdatePddShopDTO updatePddShopDTO, Long id) {
Long companyId = currentUserContext.getCurrentCompanyId();
PddShopPO existing = this.getById(id);
if (existing == null) {
throw new BusinessException("拼多多店铺不存在");
}
LambdaQueryWrapper<PddShopPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PddShopPO::getCompanyId, companyId)
.eq(PddShopPO::getMallId, updatePddShopDTO.getMallId())
.ne(PddShopPO::getId, id);
if (this.count(wrapper) > 0) {
throw new BusinessException("该拼多多店铺已存在");
}
if (updatePddShopDTO.getPddAuthId() != null) {
wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PddShopPO::getPddAuthId, updatePddShopDTO.getPddAuthId())
.ne(PddShopPO::getId, id);
if (this.count(wrapper) > 0) {
throw new BusinessException("该授权已绑定其他店铺");
}
}
PddShopPO shop = new PddShopPO();
BeanCopyUtils.copyProperties(updatePddShopDTO, shop);
shop.setId(id);
shop.setCompanyId(companyId);
this.updateById(shop);
return convertToVO(shop);
}
@Override
@Transactional
public void deletePddShop(Long id) {
PddShopPO existing = this.getById(id);
if (existing == null) {
throw new BusinessException("拼多多店铺不存在");
}
this.removeById(id);
}
@Override
public PageResultVO<PddShopVO> getPddShopPage(PageQueryDTO<PddShopFilterDTO> pageQueryDTO) {
Long companyId = currentUserContext.getCurrentCompanyId();
PddShopFilterDTO filter = pageQueryDTO.getFilters() != null
? pageQueryDTO.getFilters() : new PddShopFilterDTO();
LambdaQueryWrapper<PddShopPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PddShopPO::getCompanyId, companyId);
if (filter.getMallName() != null && !filter.getMallName().isEmpty()) {
wrapper.like(PddShopPO::getMallName, filter.getMallName());
}
if (filter.getMerchantType() != null) {
wrapper.eq(PddShopPO::getMerchantType, filter.getMerchantType());
}
if (filter.getMallCharacter() != null) {
wrapper.eq(PddShopPO::getMallCharacter, filter.getMallCharacter());
}
if (filter.getShopId() != null) {
wrapper.eq(PddShopPO::getShopId, filter.getShopId());
}
if (filter.getPddAuthId() != null) {
wrapper.eq(PddShopPO::getPddAuthId, filter.getPddAuthId());
}
wrapper.orderByDesc(PddShopPO::getCreateTime);
IPage<PddShopPO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
IPage<PddShopPO> result = this.page(page, wrapper);
List<PddShopVO> voList = result.getRecords().stream()
.map(this::convertToVO)
.collect(Collectors.toList());
return PageResultVO.create(voList, result.getTotal(),
(int) pageQueryDTO.getPage(), (int) pageQueryDTO.getPageSize());
}
@Override
public PddShopVO getPddShopDetail(Long id) {
PddShopPO shop = this.getById(id);
if (shop == null) {
throw new BusinessException("拼多多店铺不存在");
}
return convertToVO(shop);
}
private PddShopVO convertToVO(PddShopPO shop) {
PddShopVO vo = new PddShopVO();
BeanCopyUtils.copyProperties(shop, vo);
return vo;
}
}