feat: 优化店铺相关

This commit is contained in:
2026-08-14 11:44:22 +08:00
parent 3322b0542b
commit 8921c6b122
37 changed files with 558 additions and 241 deletions
@@ -23,16 +23,6 @@ public final class OrderMqConstants {
public static final String QUEUE_ORDER_CONVERT_PDD_INC = "order.convert.pdd.inc";
public static final String QUEUE_ORDER_CONVERT_PDD_INC_DLQ = "order.convert.pdd.inc.dlq";
/** @deprecated 已拆为 full/inc;保留供旧队列排水 */
@Deprecated
public static final String RK_ORDER_CONVERT_PDD = "order.convert.pdd";
/** @deprecated 已拆为 full/inc;保留供旧队列排水 */
@Deprecated
public static final String QUEUE_ORDER_CONVERT_PDD = "order.convert.pdd";
/** @deprecated */
@Deprecated
public static final String QUEUE_ORDER_CONVERT_PDD_DLQ = "order.convert.pdd.dlq";
public static final String RK_BI_STAT_FULL = "bi.stat.full";
public static final String QUEUE_BI_STAT_FULL = "bi.stat.full";
public static final String QUEUE_BI_STAT_FULL_DLQ = "bi.stat.full.dlq";
@@ -83,27 +83,6 @@ public class RabbitBiConfig {
.with(OrderMqConstants.RK_ORDER_CONVERT_PDD_INC);
}
/** 旧共用队列:仅排水,新消息不再写入 */
@Bean
public Queue orderConvertPddQueue() {
return QueueBuilder.durable(OrderMqConstants.QUEUE_ORDER_CONVERT_PDD)
.withArgument("x-dead-letter-exchange", "")
.withArgument("x-dead-letter-routing-key", OrderMqConstants.QUEUE_ORDER_CONVERT_PDD_DLQ)
.build();
}
@Bean
public Queue orderConvertPddDlq() {
return QueueBuilder.durable(OrderMqConstants.QUEUE_ORDER_CONVERT_PDD_DLQ).build();
}
@Bean
public Binding orderConvertPddBinding(Queue orderConvertPddQueue, TopicExchange orderTopicExchange) {
return BindingBuilder.bind(orderConvertPddQueue)
.to(orderTopicExchange)
.with(OrderMqConstants.RK_ORDER_CONVERT_PDD);
}
@Bean
public Queue orderProductAutoCreatePddQueue() {
return QueueBuilder.durable(OrderMqConstants.QUEUE_ORDER_PRODUCT_AUTO_CREATE_PDD)
@@ -0,0 +1,41 @@
package top.xyquan.ecomdmbbackend.modules.channel.pdd.auth.model.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 拼多多授权信息(对外展示,不含 token / raw_response)
*/
@Data
@Schema(description = "拼多多授权信息VO")
public class PddAuthVO {
@Schema(description = "授权主键ID")
private Long id;
@Schema(description = "公司ID")
private Long companyId;
@Schema(description = "拼多多授权主体ID(owner_id)")
private String ownerId;
@Schema(description = "access_token 过期时间")
private LocalDateTime expiresAt;
@Schema(description = "refresh_token 过期时间")
private LocalDateTime refreshTokenExpiresAt;
@Schema(description = "授权 scope(JSON 数组字符串)")
private String scope;
@Schema(description = "状态:0=失效 1=正常 2=已撤销")
private Integer status;
@Schema(description = "创建时间")
private LocalDateTime createTime;
@Schema(description = "更新时间")
private LocalDateTime updateTime;
}
@@ -181,7 +181,14 @@ public class PddAuthServiceImpl implements PddAuthService {
}
upsertPddShop(companyId, auth.getId(), mallId, mallInfo, tokenResponse.getOwnerName());
bindInternalShop(companyId, userId, shopId, mallId, mallInfo);
PddShopPO pddShop = pddShopMapper.selectOne(new LambdaQueryWrapper<PddShopPO>()
.eq(PddShopPO::getCompanyId, companyId)
.eq(PddShopPO::getMallId, mallId)
.last("LIMIT 1"));
if (pddShop == null || pddShop.getId() == null) {
return buildResultHtml(false, "同步拼多多店铺失败");
}
bindInternalShop(companyId, userId, shopId, pddShop.getId(), mallInfo);
String shopName = firstNonBlank(
mallInfo != null ? mallInfo.getMallName() : null,
@@ -326,12 +333,12 @@ public class PddAuthServiceImpl implements PddAuthService {
}
/**
* 将拼多多 mall_id 写入指定内部店铺的 external_shop_id;若已被其他内部店占用则先解绑再改绑。
* 将 channel_pdd_shop 主键写入指定内部店铺的 external_shop_id;若已被其他内部店占用则先解绑再改绑。
*/
private void bindInternalShop(Long companyId,
Long userId,
Long shopId,
Long mallId,
Long channelPddShopId,
PddMallApiSnapshot mallInfo) {
ShopPO shop = shopMapper.selectById(shopId);
if (shop == null || !companyId.equals(shop.getCompanyId())) {
@@ -342,13 +349,11 @@ public class PddAuthServiceImpl implements PddAuthService {
throw new BusinessException("内部店铺不是拼多多平台,无法绑定");
}
String externalShopId = String.valueOf(mallId);
// 同一公司+平台下外部店 ID 唯一:若已被其他内部店占用则解绑
// 同一公司+平台下外部店主键唯一:若已被其他内部店占用则解绑
ShopPO occupied = shopMapper.selectOne(new LambdaQueryWrapper<ShopPO>()
.eq(ShopPO::getCompanyId, companyId)
.eq(ShopPO::getPlatformCode, shop.getPlatformCode())
.eq(ShopPO::getExternalShopId, externalShopId)
.eq(ShopPO::getExternalShopId, channelPddShopId)
.ne(ShopPO::getId, shopId)
.last("LIMIT 1"));
if (occupied != null) {
@@ -356,10 +361,10 @@ public class PddAuthServiceImpl implements PddAuthService {
.eq(ShopPO::getId, occupied.getId())
.set(ShopPO::getExternalShopId, null)
.set(ShopPO::getUpdateBy, userId));
log.info("拼多多外部店 {} 从内部店 {} 解绑,改绑至 {}", externalShopId, occupied.getId(), shopId);
log.info("拼多多平台店铺 {} 从内部店 {} 解绑,改绑至 {}", channelPddShopId, occupied.getId(), shopId);
}
shop.setExternalShopId(externalShopId);
shop.setExternalShopId(channelPddShopId);
// 无系统内部 logo 时,用授权店铺 logo 填充外链(与商品渠道图口径一致)
if (shop.getLogoImageId() == null
&& !StringUtils.hasText(shop.getLogoUrl())
@@ -1,35 +0,0 @@
package top.xyquan.ecomdmbbackend.modules.channel.pdd.order.convert.consumer;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;
import top.xyquan.ecomdmbbackend.common.mq.OrderConvertMessage;
import top.xyquan.ecomdmbbackend.common.mq.OrderConvertMode;
import top.xyquan.ecomdmbbackend.common.mq.OrderMqConstants;
/**
* 旧共用队列排水:按 mode 转发到 full/inc 新队列后丢弃本消息。
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class PddOrderConvertLegacyDrainConsumer {
private final RabbitTemplate rabbitTemplate;
@RabbitListener(queues = OrderMqConstants.QUEUE_ORDER_CONVERT_PDD)
public void onMessage(OrderConvertMessage message) {
if (message == null || message.getMode() == null) {
log.warn("旧转换队列消息非法,丢弃: {}", message);
return;
}
String rk = message.getMode() == OrderConvertMode.FULL_DAY
? OrderMqConstants.RK_ORDER_CONVERT_PDD_FULL
: OrderMqConstants.RK_ORDER_CONVERT_PDD_INC;
rabbitTemplate.convertAndSend(OrderMqConstants.EXCHANGE, rk, message);
log.info("旧转换队列已转发 mode={} shopId={} messageId={} -> {}",
message.getMode(), message.getShopId(), message.getMessageId(), rk);
}
}
@@ -40,8 +40,7 @@ public class PddOrderIncrementalSyncJob {
List<ShopPO> shops = shopMapper.selectList(new LambdaQueryWrapper<ShopPO>()
.eq(ShopPO::getPlatformCode, PlatformCode.PDD.getCode())
.eq(ShopPO::getOrderIncSyncEnabled, 1)
.isNotNull(ShopPO::getExternalShopId)
.ne(ShopPO::getExternalShopId, ""));
.isNotNull(ShopPO::getExternalShopId));
Set<Long> done = new HashSet<>();
for (ShopPO shop : shops) {
if (!done.add(shop.getId())) {
@@ -48,19 +48,13 @@ public class PddOrderSyncContextResolver {
if (!PlatformCode.PDD.getCode().equals(shop.getPlatformCode())) {
throw new BusinessException("仅支持拼多多平台店铺同步订单");
}
if (!StringUtils.hasText(shop.getExternalShopId())) {
if (shop.getExternalShopId() == null) {
throw new BusinessException("店铺尚未绑定拼多多外部店,请先完成授权");
}
Long mallId;
try {
mallId = Long.parseLong(shop.getExternalShopId().trim());
} catch (NumberFormatException e) {
throw new BusinessException("外部店铺 ID 非法: " + shop.getExternalShopId());
}
PddShopPO pddShop = pddShopMapper.selectOne(new LambdaQueryWrapper<PddShopPO>()
.eq(PddShopPO::getId, shop.getExternalShopId())
.eq(PddShopPO::getCompanyId, companyId)
.eq(PddShopPO::getMallId, mallId)
.last("LIMIT 1"));
if (pddShop == null || pddShop.getPddAuthId() == null) {
throw new BusinessException("未找到拼多多店铺授权绑定,请重新授权");
@@ -77,7 +71,7 @@ public class PddOrderSyncContextResolver {
.auth(auth)
.companyId(companyId)
.shopId(shopId)
.mallId(mallId)
.mallId(pddShop.getMallId())
.accessToken(auth.getAccessToken())
.build();
}
@@ -171,8 +171,7 @@ public class PddOrderSyncService {
public List<ShopPO> listBoundPddShops(Long companyId) {
return shopMapper.selectList(new LambdaQueryWrapper<ShopPO>()
.eq(ShopPO::getCompanyId, companyId)
.isNotNull(ShopPO::getExternalShopId)
.ne(ShopPO::getExternalShopId, ""));
.isNotNull(ShopPO::getExternalShopId));
}
public PddOrderSyncResultVO syncByConfirmDateForTask(Long companyId, Long shopId, LocalDate day, Long taskId) {
@@ -60,7 +60,7 @@ public class PddShopController {
return ApiResponse.success("获取成功", result);
}
@Operation(summary = "详情", description = "根据ID获取拼多多店铺详情")
@Operation(summary = "详情", description = "根据ID获取拼多多店铺详情(含授权信息,不含 token)")
@GetMapping("/detail/{id}")
@RequirePermission(value = "biz:pdd:shop:read", description = "查询拼多多店铺详情", allowSuper = true)
public ApiResponse<PddShopVO> getPddShopDetail(@Parameter(description = "店铺ID") @PathVariable Long id) {
@@ -2,6 +2,7 @@ package top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.model.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import top.xyquan.ecomdmbbackend.modules.channel.pdd.auth.model.vo.PddAuthVO;
import java.time.LocalDateTime;
@@ -18,6 +19,9 @@ public class PddShopVO {
@Schema(description = "拼多多授权ID(channel_pdd_auth.id)")
private Long pddAuthId;
@Schema(description = "关联的拼多多授权信息(有 pddAuthId 时返回,不含 token)")
private PddAuthVO auth;
@Schema(description = "拼多多店铺ID(mall_id)")
private Long mallId;
@@ -9,6 +9,8 @@ import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.model.dto.UpdatePddSho
import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.model.po.PddShopPO;
import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.model.vo.PddShopVO;
import java.util.List;
public interface PddShopService extends IService<PddShopPO> {
PddShopVO createPddShop(CreatePddShopDTO createPddShopDTO);
@@ -20,4 +22,14 @@ public interface PddShopService extends IService<PddShopPO> {
PageResultVO<PddShopVO> getPddShopPage(PageQueryDTO<PddShopFilterDTO> pageQueryDTO);
PddShopVO getPddShopDetail(Long id);
/** 转为 VO;withAuth=true 时按 pddAuthId 嵌套授权信息(不含 token) */
PddShopVO toVo(PddShopPO shop, boolean withAuth);
List<PddShopVO> toVoList(List<PddShopPO> shops, boolean withAuth);
/** 列表用简要信息(不含描述/类型/授权详情等) */
PddShopVO toBriefVo(PddShopPO shop);
List<PddShopVO> toBriefVoList(List<PddShopPO> shops);
}
@@ -10,6 +10,9 @@ 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.channel.pdd.auth.mapper.PddAuthMapper;
import top.xyquan.ecomdmbbackend.modules.channel.pdd.auth.model.po.PddAuthPO;
import top.xyquan.ecomdmbbackend.modules.channel.pdd.auth.model.vo.PddAuthVO;
import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.mapper.PddShopMapper;
import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.model.dto.CreatePddShopDTO;
import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.model.dto.PddShopFilterDTO;
@@ -20,15 +23,20 @@ import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.service.PddShopService
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
@Service
public class PddShopServiceImpl extends ServiceImpl<PddShopMapper, PddShopPO> implements PddShopService {
private final CurrentUserContext currentUserContext;
private final PddAuthMapper pddAuthMapper;
public PddShopServiceImpl(CurrentUserContext currentUserContext) {
public PddShopServiceImpl(CurrentUserContext currentUserContext, PddAuthMapper pddAuthMapper) {
this.currentUserContext = currentUserContext;
this.pddAuthMapper = pddAuthMapper;
}
@Override
@@ -59,7 +67,7 @@ public class PddShopServiceImpl extends ServiceImpl<PddShopMapper, PddShopPO> im
}
this.save(shop);
return convertToVO(shop);
return toVo(shop, true);
}
@Override
@@ -95,7 +103,7 @@ public class PddShopServiceImpl extends ServiceImpl<PddShopMapper, PddShopPO> im
shop.setCompanyId(companyId);
this.updateById(shop);
return convertToVO(shop);
return toVo(this.getById(id), true);
}
@Override
@@ -135,9 +143,7 @@ public class PddShopServiceImpl extends ServiceImpl<PddShopMapper, PddShopPO> im
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());
List<PddShopVO> voList = toBriefVoList(result.getRecords());
return PageResultVO.create(voList, result.getTotal(),
(int) pageQueryDTO.getPage(), (int) pageQueryDTO.getPageSize());
@@ -149,12 +155,90 @@ public class PddShopServiceImpl extends ServiceImpl<PddShopMapper, PddShopPO> im
if (shop == null) {
throw new BusinessException("拼多多店铺不存在");
}
return convertToVO(shop);
Long companyId = currentUserContext.getCurrentCompanyId();
if (!companyId.equals(shop.getCompanyId())) {
throw new BusinessException("拼多多店铺不存在");
}
return toVo(shop, true);
}
private PddShopVO convertToVO(PddShopPO shop) {
@Override
public PddShopVO toVo(PddShopPO shop, boolean withAuth) {
if (shop == null) {
return null;
}
PddShopVO vo = new PddShopVO();
BeanCopyUtils.copyProperties(shop, vo);
if (withAuth && shop.getPddAuthId() != null) {
vo.setAuth(toAuthVo(pddAuthMapper.selectById(shop.getPddAuthId())));
}
return vo;
}
@Override
public List<PddShopVO> toVoList(List<PddShopPO> shops, boolean withAuth) {
if (shops == null || shops.isEmpty()) {
return List.of();
}
Map<Long, PddAuthVO> authById = Map.of();
if (withAuth) {
Set<Long> authIds = shops.stream()
.map(PddShopPO::getPddAuthId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
if (!authIds.isEmpty()) {
authById = pddAuthMapper.selectBatchIds(authIds).stream()
.collect(Collectors.toMap(PddAuthPO::getId, this::toAuthVo, (a, b) -> a));
}
}
Map<Long, PddAuthVO> finalAuthById = authById;
return shops.stream().map(shop -> {
PddShopVO vo = new PddShopVO();
BeanCopyUtils.copyProperties(shop, vo);
if (withAuth && shop.getPddAuthId() != null) {
vo.setAuth(finalAuthById.get(shop.getPddAuthId()));
}
return vo;
}).collect(Collectors.toList());
}
@Override
public PddShopVO toBriefVo(PddShopPO shop) {
if (shop == null) {
return null;
}
PddShopVO vo = new PddShopVO();
vo.setId(shop.getId());
vo.setCompanyId(shop.getCompanyId());
vo.setMallId(shop.getMallId());
vo.setMallName(shop.getMallName());
vo.setLogo(shop.getLogo());
vo.setPddAuthId(shop.getPddAuthId());
return vo;
}
@Override
public List<PddShopVO> toBriefVoList(List<PddShopPO> shops) {
if (shops == null || shops.isEmpty()) {
return List.of();
}
return shops.stream().map(this::toBriefVo).collect(Collectors.toList());
}
private PddAuthVO toAuthVo(PddAuthPO auth) {
if (auth == null) {
return null;
}
PddAuthVO vo = new PddAuthVO();
vo.setId(auth.getId());
vo.setCompanyId(auth.getCompanyId());
vo.setOwnerId(auth.getOwnerId());
vo.setExpiresAt(auth.getExpiresAt());
vo.setRefreshTokenExpiresAt(auth.getRefreshTokenExpiresAt());
vo.setScope(auth.getScope());
vo.setStatus(auth.getStatus());
vo.setCreateTime(auth.getCreateTime());
vo.setUpdateTime(auth.getUpdateTime());
return vo;
}
}
@@ -4,8 +4,6 @@ import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.ibatis.session.SqlSessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
import top.xyquan.ecomdmbbackend.modules.ec.importtask.model.po.ImportTaskPO;
@@ -36,7 +34,6 @@ import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CodingErrorAction;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@@ -46,8 +43,6 @@ import java.util.stream.Collectors;
@Service
public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorService {
private static final Logger log = LoggerFactory.getLogger(ImportTaskProcessorServiceImpl.class);
private final ImportTaskService importTaskService;
private final OrderMapper orderMapper;
private final RealtimeSseService realtimeSseService;
@@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Select;
import top.xyquan.ecomdmbbackend.modules.ec.order.model.dto.OrderListQueryParam;
import top.xyquan.ecomdmbbackend.modules.ec.order.model.po.OrderPO;
import java.math.BigDecimal;
@@ -26,7 +26,6 @@ import top.xyquan.ecomdmbbackend.modules.ec.shop.model.po.ShopPO;
import top.xyquan.ecomdmbbackend.modules.ec.order.model.vo.BatchImportResultVO;
import top.xyquan.ecomdmbbackend.modules.ec.order.model.vo.OrderItemVO;
import top.xyquan.ecomdmbbackend.modules.ec.order.model.vo.OrderVO;
import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductSkuVO;
import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductVO;
import top.xyquan.ecomdmbbackend.modules.ec.order.service.OrderService;
import top.xyquan.ecomdmbbackend.modules.ec.order.status.model.enums.OrderStatus;
@@ -43,10 +42,8 @@ import org.slf4j.Logger;
import java.math.BigDecimal;
import org.slf4j.LoggerFactory;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -171,8 +168,6 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
@Override
@Transactional
public void deleteOrder(Long id) {
Long companyId = currentUserContext.getCurrentCompanyId();
OrderPO existingOrder = requireOrder(id, companyId);
orderItemMapper.delete(new LambdaQueryWrapper<OrderItemPO>().eq(OrderItemPO::getOrderId, id));
this.removeById(id);
}
@@ -278,7 +273,6 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
java.math.BigDecimal shippingCost, java.math.BigDecimal otherCost,
java.time.LocalDateTime startTime, java.time.LocalDateTime endTime) {
try {
ProductSkuPO sku = productSkuService.getById(skuId);
int n = baseMapper.updateCostFields(productCost, shippingCost, otherCost, skuId, startTime, endTime);
return n;
} catch (Exception ex) {
@@ -1,7 +1,6 @@
package top.xyquan.ecomdmbbackend.modules.ec.order.status.support;
import org.springframework.stereotype.Component;
import top.xyquan.ecomdmbbackend.modules.ec.order.status.model.enums.OrderStatus;
/**
* 解析订单统计状态集合。去表后全局固定,忽略 companyId。
@@ -10,7 +10,6 @@ import top.xyquan.ecomdmbbackend.modules.ec.product.model.po.ProductPO;
import top.xyquan.ecomdmbbackend.modules.ec.product.model.po.ProductSkuPO;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
/**
@@ -1,6 +1,5 @@
package top.xyquan.ecomdmbbackend.modules.ec.product.controller;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -30,7 +30,6 @@ import top.xyquan.ecomdmbbackend.modules.sys.file.model.po.SysFilePO;
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
import top.xyquan.ecomdmbbackend.utils.SysFileUtils;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
@@ -61,7 +61,7 @@ public class ShopController {
return ApiResponse.success("店铺删除成功");
}
@Operation(summary = "分页获取店铺列表", description = "分页获取店铺列表,支持条件过滤;已绑定外部店时附带对应外部店铺 VO(如 pddShop)")
@Operation(summary = "分页获取店铺列表", description = "分页获取店铺列表;已绑定外部店时仅附带渠道店简要信息(id/名称/logo 等),详情请调渠道店铺详情接口")
@PostMapping("/list")
@RequirePermission(value = "ecom:shop:read", description = "查询店铺列表", allowSuper = true)
public ApiResponse<PageResultVO<ShopVO>> getShopPage(
@@ -70,6 +70,14 @@ public class ShopController {
return ApiResponse.success("获取店铺列表成功", result);
}
@Operation(summary = "店铺详情", description = "根据内部店铺ID获取详情;按 platformCode 嵌套平台店铺简要信息,完整渠道店/授权请再调渠道店铺详情")
@GetMapping("/detail/{id}")
@RequirePermission(value = "ecom:shop:read", description = "查询店铺详情", allowSuper = true)
public ApiResponse<ShopVO> getShopDetail(@Parameter(description = "店铺ID") @PathVariable Long id) {
ShopVO vo = shopService.getShopDetail(id);
return ApiResponse.success("获取成功", vo);
}
@Operation(summary = "上传店铺Logo", description = "上传店铺Logo图片,支持跨公司共享")
@PostMapping("/upload-logo")
@RequirePermission(value = "ecom:shop:manage", description = "上传店铺Logo", allowSuper = true)
@@ -31,8 +31,8 @@ public class CreateShopDTO {
private String platformCode;
/**
* 外部店铺ID(平台侧店铺标识,如拼多多 mall_id)
* 外部/平台店铺表主键 ID(如 channel_pdd_shop.id)
*/
@Schema(description = "外部店铺ID(平台侧店铺标识,如拼多多 mall_id)", example = "123456789")
private String externalShopId;
@Schema(description = "外部/平台店铺表主键ID(如 channel_pdd_shop.id)", example = "1")
private Long externalShopId;
}
@@ -31,8 +31,8 @@ public class UpdateShopDTO {
private String platformCode;
/**
* 外部店铺ID(平台侧店铺标识,如拼多多 mall_id)
* 外部/平台店铺表主键 ID(如 channel_pdd_shop.id)
*/
@Schema(description = "外部店铺ID(平台侧店铺标识,如拼多多 mall_id)", example = "123456789")
private String externalShopId;
@Schema(description = "外部/平台店铺表主键ID(如 channel_pdd_shop.id)", example = "1")
private Long externalShopId;
}
@@ -51,10 +51,10 @@ public class ShopPO {
private String platformCode;
/**
* 外部店铺ID(如拼多多 mall_id;与 platform_code 组合关联平台店铺)
* 外部/平台店铺表主键 ID(如 channel_pdd_shop.id;与 platform_code 组合关联)
*/
@TableField("external_shop_id")
private String externalShopId;
private Long externalShopId;
/**
* 订单增量同步开关:0关 1开
@@ -44,10 +44,10 @@ public class ShopVO {
private String platformCode;
/**
* 外部店铺ID(平台侧店铺标识,如拼多多 mall_id)
* 外部/平台店铺表主键 ID(如 channel_pdd_shop.id)
*/
@Schema(description = "外部店铺ID(平台侧店铺标识,如拼多多 mall_id)", example = "123456789")
private String externalShopId;
@Schema(description = "外部/平台店铺表主键ID(如 channel_pdd_shop.id)", example = "1")
private Long externalShopId;
/**
* 关联的拼多多外部店铺(仅 platform=pdd 且已绑定 externalShopId 时有值)
@@ -50,6 +50,14 @@ public interface ShopService extends IService<ShopPO> {
*/
PageResultVO<ShopVO> getShopPage(PageQueryDTO<ShopFilterDTO> pageQueryDTO);
/**
* 店铺详情(按平台编码嵌套平台店铺及授权信息)
*
* @param id 店铺ID
* @return 店铺VO
*/
ShopVO getShopDetail(Long id);
/**
* 上传店铺Logo
*
@@ -13,6 +13,7 @@ import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.mapper.PddShopMapper;
import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.model.po.PddShopPO;
import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.model.vo.PddShopVO;
import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.service.PddShopService;
import top.xyquan.ecomdmbbackend.modules.ec.product.mapper.ProductMapper;
import top.xyquan.ecomdmbbackend.modules.ec.platform.model.enums.PlatformCode;
import top.xyquan.ecomdmbbackend.modules.ec.shop.mapper.ShopMapper;
@@ -56,17 +57,19 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
private final ShopProductRelationMapper shopProductRelationMapper;
private final ProductSkuService productSkuService;
private final PddShopMapper pddShopMapper;
private final PddShopService pddShopService;
public ShopServiceImpl(CurrentUserContext currentUserContext, SysFileService sysFileService,
ProductMapper productMapper,
ShopProductRelationMapper shopProductRelationMapper, ProductSkuService productSkuService,
PddShopMapper pddShopMapper) {
PddShopMapper pddShopMapper, PddShopService pddShopService) {
this.currentUserContext = currentUserContext;
this.sysFileService = sysFileService;
this.productMapper = productMapper;
this.shopProductRelationMapper = shopProductRelationMapper;
this.productSkuService = productSkuService;
this.pddShopMapper = pddShopMapper;
this.pddShopService = pddShopService;
}
/**
@@ -103,8 +106,9 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
// 保存店铺
this.save(shop);
// 转换为VO并返回
return convertToVO(shop);
ShopVO vo = convertToVO(shop);
attachExternalShop(vo, shop);
return vo;
}
/**
@@ -148,8 +152,10 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
// 更新店铺
this.updateById(shop);
// 转换为VO并返回
return convertToVO(shop);
ShopPO updated = this.getById(id);
ShopVO vo = convertToVO(updated);
attachExternalShop(vo, updated);
return vo;
}
/**
@@ -251,20 +257,35 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
if (shop.getPlatformCode() != null && !shop.getPlatformCode().isBlank()) {
shopVO.setPlatformName(PlatformCode.labelOf(shop.getPlatformCode()));
}
return shopVO;
}
private void attachExternalShop(ShopVO shopVO, ShopPO shop) {
if (shopVO == null || shop == null) {
return;
}
if (PLATFORM_CODE_PDD.equals(shop.getPlatformCode())
&& shop.getExternalShopId() != null && !shop.getExternalShopId().isBlank()) {
Long mallId = parseMallId(shop.getExternalShopId());
if (mallId != null) {
PddShopPO pddShop = pddShopMapper.selectOne(new LambdaQueryWrapper<PddShopPO>()
.eq(PddShopPO::getCompanyId, shop.getCompanyId())
.eq(PddShopPO::getMallId, mallId)
.last("LIMIT 1"));
if (pddShop != null) {
shopVO.setPddShop(convertPddShopToVO(pddShop));
}
&& shop.getExternalShopId() != null) {
PddShopPO pddShop = pddShopMapper.selectOne(new LambdaQueryWrapper<PddShopPO>()
.eq(PddShopPO::getId, shop.getExternalShopId())
.eq(PddShopPO::getCompanyId, shop.getCompanyId())
.last("LIMIT 1"));
if (pddShop != null) {
shopVO.setPddShop(pddShopService.toBriefVo(pddShop));
}
}
return shopVO;
}
@Override
public ShopVO getShopDetail(Long id) {
Long companyId = currentUserContext.getCurrentCompanyId();
ShopPO shop = this.getById(id);
if (shop == null || !companyId.equals(shop.getCompanyId())) {
throw new BusinessException("店铺不存在");
}
ShopVO vo = convertToVO(shop);
attachExternalShop(vo, shop);
return vo;
}
private static void validatePlatformCode(String platformCode) {
@@ -287,52 +308,35 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
.filter(v -> v.getId() != null)
.collect(Collectors.toMap(ShopVO::getId, Function.identity(), (a, b) -> a));
Map<Long, Long> shopIdToMallId = new HashMap<>();
Map<Long, Long> shopIdToExternalId = new HashMap<>();
for (ShopPO shop : shops) {
if (shop.getExternalShopId() == null || shop.getExternalShopId().isBlank()) {
if (shop.getExternalShopId() == null) {
continue;
}
if (!PLATFORM_CODE_PDD.equals(shop.getPlatformCode())) {
continue;
}
Long mallId = parseMallId(shop.getExternalShopId());
if (mallId != null) {
shopIdToMallId.put(shop.getId(), mallId);
}
shopIdToExternalId.put(shop.getId(), shop.getExternalShopId());
}
if (shopIdToMallId.isEmpty()) {
if (shopIdToExternalId.isEmpty()) {
return;
}
List<PddShopPO> pddShops = pddShopMapper.selectList(new LambdaQueryWrapper<PddShopPO>()
.eq(PddShopPO::getCompanyId, companyId)
.in(PddShopPO::getMallId, shopIdToMallId.values()));
Map<Long, PddShopVO> pddByMallId = pddShops.stream()
.collect(Collectors.toMap(PddShopPO::getMallId, this::convertPddShopToVO, (a, b) -> a));
.in(PddShopPO::getId, shopIdToExternalId.values()));
Map<Long, PddShopVO> pddById = pddShopService.toBriefVoList(pddShops).stream()
.collect(Collectors.toMap(PddShopVO::getId, Function.identity(), (a, b) -> a));
shopIdToMallId.forEach((shopId, mallId) -> {
shopIdToExternalId.forEach((shopId, externalId) -> {
ShopVO vo = voById.get(shopId);
PddShopVO pddShop = pddByMallId.get(mallId);
PddShopVO pddShop = pddById.get(externalId);
if (vo != null && pddShop != null) {
vo.setPddShop(pddShop);
}
});
}
private static Long parseMallId(String externalShopId) {
try {
return Long.parseLong(externalShopId.trim());
} catch (NumberFormatException e) {
return null;
}
}
private PddShopVO convertPddShopToVO(PddShopPO pddShop) {
PddShopVO vo = new PddShopVO();
BeanCopyUtils.copyProperties(pddShop, vo);
return vo;
}
/**
* 分页获取店铺商品信息
*/