5.9新需求修改

This commit is contained in:
dev 2025-06-20 18:07:55 +08:00
parent 51ae89fe59
commit ba66f30750
19 changed files with 406 additions and 20 deletions

View File

@ -6,6 +6,7 @@ import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*; import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaCheckPermission;
import org.asinkj.amz.domain.bo.BatchRelDTO;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.asinkj.common.idempotent.annotation.RepeatSubmit; import org.asinkj.common.idempotent.annotation.RepeatSubmit;
@ -103,4 +104,13 @@ public class BizSendShipmentRelController extends BaseController {
@PathVariable Long[] ids) { @PathVariable Long[] ids) {
return toAjax(bizSendShipmentRelService.deleteWithValidByIds(List.of(ids), true)); return toAjax(bizSendShipmentRelService.deleteWithValidByIds(List.of(ids), true));
} }
@PostMapping("/createBatchRelations")
public R<Void> createBatchRelations(
@RequestBody BatchRelDTO dto) {
bizSendShipmentRelService.batchCreateRelations(dto);
return R.ok();
}
} }

View File

@ -28,6 +28,7 @@ public class BizSendOrder extends TenantEntity {
/** /**
* 主键ID * 主键ID
*/ */
@TableId
private Long id; private Long id;
/** /**

View File

@ -14,9 +14,9 @@ import java.io.Serial;
* @date 2025-06-20 * @date 2025-06-20
*/ */
@Data @Data
@EqualsAndHashCode(callSuper = true) //@EqualsAndHashCode(callSuper = true)
@TableName("biz_send_shipment_rel") @TableName("biz_send_shipment_rel")
public class BizSendShipmentRel extends BaseEntity { public class BizSendShipmentRel {
@Serial @Serial
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

View File

@ -0,0 +1,13 @@
package org.asinkj.amz.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class OrderShipmentRelation {
private Long sendOrderId; // 发货单ID
private Long shipmentId; // 货运计划ID
}

View File

@ -0,0 +1,9 @@
package org.asinkj.amz.domain;
import lombok.Data;
@Data
public class OrderWithShipment {
private Long shipmentPlanId;
private BizSendOrder order;
}

View File

@ -0,0 +1,11 @@
package org.asinkj.amz.domain;
import lombok.Data;
import java.util.List;
@Data
public class OrderWithShipmentGroup {
private Long shipmentPlanId;
private List<BizSendOrder> orders;
}

View File

@ -6,6 +6,7 @@ import org.asinkj.amz.domain.BizLogisticsOrder;
import org.asinkj.amz.domain.BizSendOrder; import org.asinkj.amz.domain.BizSendOrder;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelProperty;
import org.asinkj.amz.domain.BizShipmentPlan;
import org.asinkj.common.excel.annotation.ExcelDictFormat; import org.asinkj.common.excel.annotation.ExcelDictFormat;
import org.asinkj.common.excel.convert.ExcelDictConvert; import org.asinkj.common.excel.convert.ExcelDictConvert;
import io.github.linpeilie.annotations.AutoMapper; import io.github.linpeilie.annotations.AutoMapper;
@ -13,6 +14,7 @@ import lombok.Data;
import java.io.Serial; import java.io.Serial;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
/** /**
@ -126,5 +128,6 @@ public class BizSendOrderVo implements Serializable {
private BizLogisticsOrder bizLogisticsOrder; private BizLogisticsOrder bizLogisticsOrder;
private List<BizShipmentPlan> bizShipmentPlans;
} }

View File

@ -220,6 +220,7 @@ public class BizShipmentPlanVo implements Serializable {
private Long sendOrderId; private Long sendOrderId;
private BizSendOrder sendOrder; private BizSendOrder sendOrder;
private List<BizSendOrder> sendOrders;
private List<BizShipmentItem> itemVoList; private List<BizShipmentItem> itemVoList;

View File

@ -1,9 +1,16 @@
package org.asinkj.amz.mapper; package org.asinkj.amz.mapper;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;
import org.asinkj.amz.domain.BizSendOrder; import org.asinkj.amz.domain.BizSendOrder;
import org.asinkj.amz.domain.OrderWithShipment;
import org.asinkj.amz.domain.vo.BizSendOrderVo; import org.asinkj.amz.domain.vo.BizSendOrderVo;
import org.asinkj.common.mybatis.core.mapper.BaseMapperPlus; import org.asinkj.common.mybatis.core.mapper.BaseMapperPlus;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/** /**
* 供应商创建的发货单Mapper接口 * 供应商创建的发货单Mapper接口
* *
@ -11,5 +18,7 @@ import org.asinkj.common.mybatis.core.mapper.BaseMapperPlus;
* @date 2025-05-14 * @date 2025-05-14
*/ */
public interface BizSendOrderMapper extends BaseMapperPlus<BizSendOrder, BizSendOrderVo> { public interface BizSendOrderMapper extends BaseMapperPlus<BizSendOrder, BizSendOrderVo> {
List<OrderWithShipment> selectOrdersWithShipmentIds(
@Param("shipmentIds") Collection<Long> shipmentIds
);
} }

View File

@ -1,10 +1,13 @@
package org.asinkj.amz.mapper; package org.asinkj.amz.mapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.asinkj.amz.domain.BizSendShipmentRel; import org.asinkj.amz.domain.BizSendShipmentRel;
import org.asinkj.amz.domain.vo.BizSendShipmentRelVo; import org.asinkj.amz.domain.vo.BizSendShipmentRelVo;
import org.asinkj.common.mybatis.core.mapper.BaseMapperPlus; import org.asinkj.common.mybatis.core.mapper.BaseMapperPlus;
import java.util.List;
/** /**
* 发货单与货运计划多对多关联Mapper接口 * 发货单与货运计划多对多关联Mapper接口
* *
@ -13,5 +16,21 @@ import org.asinkj.common.mybatis.core.mapper.BaseMapperPlus;
*/ */
@Mapper @Mapper
public interface BizSendShipmentRelMapper extends BaseMapperPlus<BizSendShipmentRel, BizSendShipmentRelVo> { public interface BizSendShipmentRelMapper extends BaseMapperPlus<BizSendShipmentRel, BizSendShipmentRelVo> {
/**
* 批量插入关联关系避免重复
* @param relations 关联关系列表
* @return 成功插入的记录数
*/
int batchInsertRelations(@Param("relations") List<BizSendShipmentRel> relations);
/**
* 批量删除关联关系多对多组合
* @param sendOrderIds 发货单ID列表
* @param shipmentIds 货运计划ID列表
* @return 成功删除的记录数
*/
int batchDeleteRelations(
@Param("sendOrderIds") List<Long> sendOrderIds,
@Param("shipmentIds") List<Long> shipmentIds
);
} }

View File

@ -4,11 +4,13 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.asinkj.amz.domain.BizShipmentPlan; import org.asinkj.amz.domain.BizShipmentPlan;
import org.asinkj.amz.domain.BizShipmentPlanFileData; import org.asinkj.amz.domain.BizShipmentPlanFileData;
import org.asinkj.amz.domain.OrderShipmentRelation;
import org.asinkj.amz.domain.vo.BizShipmentPlanVo; import org.asinkj.amz.domain.vo.BizShipmentPlanVo;
import org.asinkj.common.mybatis.core.mapper.BaseMapperPlus; import org.asinkj.common.mybatis.core.mapper.BaseMapperPlus;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* 货件计划Mapper接口 * 货件计划Mapper接口
@ -22,4 +24,9 @@ public interface BizShipmentPlanMapper extends BaseMapperPlus<BizShipmentPlan, B
List<String> selectExistingShipmentIds(@Param("batchIds") Collection<String> batchIds); List<String> selectExistingShipmentIds(@Param("batchIds") Collection<String> batchIds);
void updateByFbaShipmentId(List<BizShipmentPlanFileData> bizShipmentPlanFileDataList); void updateByFbaShipmentId(List<BizShipmentPlanFileData> bizShipmentPlanFileDataList);
List<OrderShipmentRelation> findOrderShipmentRelations(@Param("sendOrderIds") Collection<Long> sendOrderIds);
List<BizShipmentPlan> findByIds(@Param("ids") Collection<Long> ids);
} }

View File

@ -1,10 +1,12 @@
package org.asinkj.amz.service; package org.asinkj.amz.service;
import org.asinkj.amz.domain.BizSendShipmentRel; import org.asinkj.amz.domain.BizSendShipmentRel;
import org.asinkj.amz.domain.bo.BatchRelDTO;
import org.asinkj.amz.domain.vo.BizSendShipmentRelVo; import org.asinkj.amz.domain.vo.BizSendShipmentRelVo;
import org.asinkj.amz.domain.bo.BizSendShipmentRelBo; import org.asinkj.amz.domain.bo.BizSendShipmentRelBo;
import org.asinkj.common.mybatis.core.page.TableDataInfo; import org.asinkj.common.mybatis.core.page.TableDataInfo;
import org.asinkj.common.mybatis.core.page.PageQuery; import org.asinkj.common.mybatis.core.page.PageQuery;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -66,4 +68,7 @@ public interface IBizSendShipmentRelService {
* @return 是否删除成功 * @return 是否删除成功
*/ */
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid); Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
@Transactional
void batchCreateRelations(BatchRelDTO dto);
} }

View File

@ -12,6 +12,7 @@ import org.asinkj.common.mybatis.core.page.PageQuery;
import java.io.InputStream; import java.io.InputStream;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 货件计划Service接口 * 货件计划Service接口
@ -38,6 +39,8 @@ public interface IBizShipmentPlanService {
*/ */
TableDataInfo<BizShipmentPlanVo> queryPageList(BizShipmentPlanBo bo, PageQuery pageQuery); TableDataInfo<BizShipmentPlanVo> queryPageList(BizShipmentPlanBo bo, PageQuery pageQuery);
// Map<Long, List<BizShipmentPlan>> getShipmentsByOrderIds(Collection<Long> sendOrderIds);
/** /**
* 查询符合条件的货件计划列表 * 查询符合条件的货件计划列表
* *

View File

@ -2,6 +2,7 @@ package org.asinkj.amz.service.impl;
import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboReference;
import org.asinkj.amz.domain.*; import org.asinkj.amz.domain.*;
@ -9,6 +10,8 @@ import org.asinkj.amz.domain.bo.SysAmazonStoreBo;
import org.asinkj.amz.domain.vo.SysAmazonStoreVo; import org.asinkj.amz.domain.vo.SysAmazonStoreVo;
import org.asinkj.amz.mapper.BizLogisticsOrderDetailMapper; import org.asinkj.amz.mapper.BizLogisticsOrderDetailMapper;
import org.asinkj.amz.mapper.BizLogisticsOrderMapper; import org.asinkj.amz.mapper.BizLogisticsOrderMapper;
import org.asinkj.amz.mapper.BizShipmentPlanMapper;
import org.asinkj.amz.service.IBizShipmentPlanService;
import org.asinkj.amz.service.ISysAmazonStoreService; import org.asinkj.amz.service.ISysAmazonStoreService;
import org.asinkj.common.core.utils.MapstructUtils; import org.asinkj.common.core.utils.MapstructUtils;
import org.asinkj.common.core.utils.StringUtils; import org.asinkj.common.core.utils.StringUtils;
@ -21,6 +24,7 @@ import lombok.RequiredArgsConstructor;
import org.asinkj.common.satoken.utils.LoginHelper; import org.asinkj.common.satoken.utils.LoginHelper;
import org.asinkj.system.api.RemoteUserService; import org.asinkj.system.api.RemoteUserService;
import org.asinkj.system.api.domain.vo.RemoteUserVo; import org.asinkj.system.api.domain.vo.RemoteUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.asinkj.amz.domain.bo.BizSendOrderBo; import org.asinkj.amz.domain.bo.BizSendOrderBo;
import org.asinkj.amz.domain.vo.BizSendOrderVo; import org.asinkj.amz.domain.vo.BizSendOrderVo;
@ -28,10 +32,7 @@ import org.asinkj.amz.mapper.BizSendOrderMapper;
import org.asinkj.amz.service.IBizSendOrderService; import org.asinkj.amz.service.IBizSendOrderService;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.*;
import java.util.Map;
import java.util.Collection;
import java.util.Set;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -60,6 +61,10 @@ public class BizSendOrderServiceImpl implements IBizSendOrderService {
@Resource @Resource
private BizLogisticsOrderDetailMapper bizLogisticsOrderDetailMapper; private BizLogisticsOrderDetailMapper bizLogisticsOrderDetailMapper;
@Resource
private BizShipmentPlanMapper bizShipmentPlanMapper;
/** /**
* 查询供应商创建的发货单 * 查询供应商创建的发货单
* *
@ -84,6 +89,8 @@ public class BizSendOrderServiceImpl implements IBizSendOrderService {
Page<BizSendOrderVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw); Page<BizSendOrderVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
List<BizSendOrderVo> records = result.getRecords(); List<BizSendOrderVo> records = result.getRecords();
Set<String> shipmentIds = records.stream().map(BizSendOrderVo::getShipmentId).collect(Collectors.toSet()); Set<String> shipmentIds = records.stream().map(BizSendOrderVo::getShipmentId).collect(Collectors.toSet());
Set<Long> ids = records.stream().map(BizSendOrderVo::getId).collect(Collectors.toSet());
LambdaQueryWrapper<BizLogisticsOrder> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<BizLogisticsOrder> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.in(CollectionUtil.isNotEmpty(shipmentIds), BizLogisticsOrder::getFbaShipmentId, shipmentIds); lambdaQueryWrapper.in(CollectionUtil.isNotEmpty(shipmentIds), BizLogisticsOrder::getFbaShipmentId, shipmentIds);
List<BizLogisticsOrder> bizLogisticsOrders = bizLogisticsOrderMapper.selectList(lambdaQueryWrapper); List<BizLogisticsOrder> bizLogisticsOrders = bizLogisticsOrderMapper.selectList(lambdaQueryWrapper);
@ -100,6 +107,7 @@ public class BizSendOrderServiceImpl implements IBizSendOrderService {
Map<String, BizLogisticsOrder> logisticsOrderMap = bizLogisticsOrders.stream().collect(Collectors.toMap(BizLogisticsOrder::getFbaShipmentId, Function.identity())); Map<String, BizLogisticsOrder> logisticsOrderMap = bizLogisticsOrders.stream().collect(Collectors.toMap(BizLogisticsOrder::getFbaShipmentId, Function.identity()));
Map<Long, List<BizShipmentPlan>> shipmentsByOrderIdsMap = getShipmentsByOrderIds(ids);
List<Long> logicIds = records.stream().map(BizSendOrderVo::getLogisticsProviderId).distinct().toList(); List<Long> logicIds = records.stream().map(BizSendOrderVo::getLogisticsProviderId).distinct().toList();
Map<Long, RemoteUserVo> remoteUserVoMap = remoteUserService.selectListByIds(logicIds).stream().collect(Collectors.toMap(RemoteUserVo::getUserId, Function.identity())); Map<Long, RemoteUserVo> remoteUserVoMap = remoteUserService.selectListByIds(logicIds).stream().collect(Collectors.toMap(RemoteUserVo::getUserId, Function.identity()));
for (BizSendOrderVo record : records) { for (BizSendOrderVo record : records) {
@ -111,10 +119,43 @@ public class BizSendOrderServiceImpl implements IBizSendOrderService {
if (bizLogisticsOrder != null) { if (bizLogisticsOrder != null) {
record.setBizLogisticsOrder(bizLogisticsOrder); record.setBizLogisticsOrder(bizLogisticsOrder);
} }
List<BizShipmentPlan> bizShipmentPlans = shipmentsByOrderIdsMap.get(record.getId());
record.setBizShipmentPlans(bizShipmentPlans);
} }
return TableDataInfo.build(result); return TableDataInfo.build(result);
} }
public Map<Long, List<BizShipmentPlan>> getShipmentsByOrderIds(Collection<Long> sendOrderIds) {
if (CollectionUtil.isEmpty(sendOrderIds)) {
return Collections.emptyMap();
}
List<OrderShipmentRelation> relations = bizShipmentPlanMapper.findOrderShipmentRelations(sendOrderIds);
if (relations.isEmpty()) {
return Collections.emptyMap();
}
Set<Long> shipmentIds = relations.stream()
.map(OrderShipmentRelation::getShipmentId)
.collect(Collectors.toSet());
List<BizShipmentPlan> shipments = bizShipmentPlanMapper.findByIds(shipmentIds);
Map<Long, BizShipmentPlan> shipmentMap = shipments.stream()
.collect(Collectors.toMap(BizShipmentPlan::getId, Function.identity()));
return relations.stream()
.filter(relation -> shipmentMap.containsKey(relation.getShipmentId()))
.collect(Collectors.groupingBy(
OrderShipmentRelation::getSendOrderId,
Collectors.mapping(
relation -> shipmentMap.get(relation.getShipmentId()),
Collectors.toList())
));
}
/** /**
* 查询符合条件的供应商创建的发货单列表 * 查询符合条件的供应商创建的发货单列表
* *
@ -140,7 +181,7 @@ public class BizSendOrderServiceImpl implements IBizSendOrderService {
lqw.eq(StringUtils.isNotBlank(bo.getBoxDimensions()), BizSendOrder::getBoxDimensions, bo.getBoxDimensions()); lqw.eq(StringUtils.isNotBlank(bo.getBoxDimensions()), BizSendOrder::getBoxDimensions, bo.getBoxDimensions());
lqw.eq(bo.getWeightPerBox() != null, BizSendOrder::getWeightPerBox, bo.getWeightPerBox()); lqw.eq(bo.getWeightPerBox() != null, BizSendOrder::getWeightPerBox, bo.getWeightPerBox());
lqw.like(StringUtils.isNotBlank(bo.getRealStoreName()), BizSendOrder::getRealStoreName, bo.getRealStoreName()); lqw.like(StringUtils.isNotBlank(bo.getRealStoreName()), BizSendOrder::getRealStoreName, bo.getRealStoreName());
lqw.eq(StringUtils.isNotBlank(bo.getSendStatus()), BizSendOrder::getSendStatus, bo.getSendStatus()); lqw.in(StringUtils.isNotBlank(bo.getSendStatus()), BizSendOrder::getSendStatus, StrUtil.split(bo.getSendStatus(), ","));
if (StpUtil.hasRole("yunying")) { if (StpUtil.hasRole("yunying")) {
SysAmazonStoreBo sysAmazonStoreBo = new SysAmazonStoreBo(); SysAmazonStoreBo sysAmazonStoreBo = new SysAmazonStoreBo();
sysAmazonStoreBo.setUserId(LoginHelper.getUserId()); sysAmazonStoreBo.setUserId(LoginHelper.getUserId());

View File

@ -3,7 +3,6 @@ package org.asinkj.amz.service.impl;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.asinkj.amz.domain.bo.BatchRelDTO; import org.asinkj.amz.domain.bo.BatchRelDTO;
import org.asinkj.common.core.utils.MapstructUtils; import org.asinkj.common.core.utils.MapstructUtils;
import org.asinkj.common.core.utils.StringUtils;
import org.asinkj.common.mybatis.core.page.TableDataInfo; import org.asinkj.common.mybatis.core.page.TableDataInfo;
import org.asinkj.common.mybatis.core.page.PageQuery; import org.asinkj.common.mybatis.core.page.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -16,6 +15,7 @@ import org.asinkj.amz.domain.vo.BizSendShipmentRelVo;
import org.asinkj.amz.domain.BizSendShipmentRel; import org.asinkj.amz.domain.BizSendShipmentRel;
import org.asinkj.amz.mapper.BizSendShipmentRelMapper; import org.asinkj.amz.mapper.BizSendShipmentRelMapper;
import org.asinkj.amz.service.IBizSendShipmentRelService; import org.asinkj.amz.service.IBizSendShipmentRelService;
import org.springframework.transaction.annotation.Transactional;
import java.util.*; import java.util.*;
@ -173,4 +173,25 @@ public class BizSendShipmentRelServiceImpl implements IBizSendShipmentRelService
return existingKeys; return existingKeys;
} }
@Transactional
@Override
public void batchCreateRelations(BatchRelDTO dto) {
// 1. 参数校验
validateInput(dto);
// 2. 构建笛卡尔积关系列表根据数据量选择策略
List<BizSendShipmentRel> relations = buildCartesianRelations(dto);
// 3. 批量插入
if (!relations.isEmpty()) {
int inserted = baseMapper.batchInsertRelations(relations);
log.info("成功创建 {} 条发货单-货运计划关联关系", inserted);
}
}
private void validateInput(BatchRelDTO dto) {
// todo
}
} }

View File

@ -26,6 +26,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.asinkj.common.satoken.utils.LoginHelper; import org.asinkj.common.satoken.utils.LoginHelper;
import org.asinkj.resource.api.RemoteMessageService; import org.asinkj.resource.api.RemoteMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.asinkj.amz.domain.bo.BizShipmentPlanBo; import org.asinkj.amz.domain.bo.BizShipmentPlanBo;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -59,9 +60,12 @@ public class BizShipmentPlanServiceImpl implements IBizShipmentPlanService {
@Resource @Resource
private SysAmazonStoreMapper sysAmazonStoreMapper; private SysAmazonStoreMapper sysAmazonStoreMapper;
@Resource @Autowired
private IBizSendOrderService iSendOrderService; private IBizSendOrderService iSendOrderService;
@Resource
private BizSendOrderMapper bizSendOrderMapper;
@Resource @Resource
private BizShipmentTrackingMapper bizShipmentTrackingMapper; private BizShipmentTrackingMapper bizShipmentTrackingMapper;
@ -110,16 +114,19 @@ public class BizShipmentPlanServiceImpl implements IBizShipmentPlanService {
Page<BizShipmentPlanVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw); Page<BizShipmentPlanVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
Set<Long> senOrderIds = result.getRecords().stream().map(BizShipmentPlanVo::getSendOrderId).collect(Collectors.toSet()); // Set<Long> senOrderIds = result.getRecords().stream().map(BizShipmentPlanVo::getSendOrderId).collect(Collectors.toSet());
Map<Long, BizSendOrder> sendOrderMap = new HashMap<>(); // Map<Long, BizSendOrder> sendOrderMap = new HashMap<>();
if (CollectionUtil.isNotEmpty(senOrderIds)) { // if (CollectionUtil.isNotEmpty(senOrderIds)) {
sendOrderMap = iSendOrderService.queryBySidList(senOrderIds).stream().collect(Collectors.toMap(BizSendOrder::getId, Function.identity())); // sendOrderMap = iSendOrderService.queryBySidList(senOrderIds).stream().collect(Collectors.toMap(BizSendOrder::getId, Function.identity()));
} // }
Set<String> shipmentIds = result.getRecords().stream().map(BizShipmentPlanVo::getShipmentId).collect(Collectors.toSet()); Set<String> shipmentIds = result.getRecords().stream().map(BizShipmentPlanVo::getShipmentId).collect(Collectors.toSet());
Set<Long> ids = result.getRecords().stream().map(BizShipmentPlanVo::getId).collect(Collectors.toSet());
Map<Long, List<BizSendOrder>> resultOrderMap = getOrdersGroupedByShipmentId(ids);
Set<Long> sids = result.getRecords().stream().map(BizShipmentPlanVo::getSid).collect(Collectors.toSet()); Set<Long> sids = result.getRecords().stream().map(BizShipmentPlanVo::getSid).collect(Collectors.toSet());
Map<Long, String> storeNameMap = new HashMap<>(); Map<Long, String> storeNameMap = new HashMap<>();
if (CollectionUtil.isNotEmpty(sids)) { if (CollectionUtil.isNotEmpty(sids)) {
@ -143,11 +150,12 @@ public class BizShipmentPlanServiceImpl implements IBizShipmentPlanService {
for (BizShipmentPlanVo bizShipmentPlanVo : result.getRecords()) { for (BizShipmentPlanVo bizShipmentPlanVo : result.getRecords()) {
BizSendOrder bizSendOrder = sendOrderMap.get(bizShipmentPlanVo.getSendOrderId()); // BizSendOrder bizSendOrder = sendOrderMap.get(bizShipmentPlanVo.getSendOrderId());
if (bizSendOrder != null) { // if (bizSendOrder != null) {
bizShipmentPlanVo.setSendOrder(sendOrderMap.get(bizShipmentPlanVo.getSendOrderId())); // bizShipmentPlanVo.setSendOrder(sendOrderMap.get(bizShipmentPlanVo.getSendOrderId()));
} // }
List<BizSendOrder> bizSendOrders = resultOrderMap.get(bizShipmentPlanVo.getId());
bizShipmentPlanVo.setSendOrders(bizSendOrders);
Long count = collect.get(bizShipmentPlanVo.getShipmentId()); Long count = collect.get(bizShipmentPlanVo.getShipmentId());
bizShipmentPlanVo.setBoxQuantity(count); bizShipmentPlanVo.setBoxQuantity(count);
bizShipmentPlanVo.setItemVoList(collect1.get(bizShipmentPlanVo.getShipmentId())); bizShipmentPlanVo.setItemVoList(collect1.get(bizShipmentPlanVo.getShipmentId()));
@ -164,6 +172,29 @@ public class BizShipmentPlanServiceImpl implements IBizShipmentPlanService {
return TableDataInfo.build(result); return TableDataInfo.build(result);
} }
@Resource
private BizSendOrderMapper orderMapper;
public Map<Long, List<BizSendOrder>> getOrdersGroupedByShipmentId(Collection<Long> shipmentIds) {
if (CollectionUtil.isEmpty(shipmentIds)) {
return Collections.emptyMap();
}
// 执行查询
List<OrderWithShipment> relations = orderMapper.selectOrdersWithShipmentIds(shipmentIds);
// 使用 Stream API 进行分组
return relations.stream()
.collect(Collectors.groupingBy(
OrderWithShipment::getShipmentPlanId,
Collectors.mapping(OrderWithShipment::getOrder, Collectors.toList())
));
}
/** /**
* 查询符合条件的货件计划列表 * 查询符合条件的货件计划列表
* *

View File

@ -4,4 +4,74 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.asinkj.amz.mapper.BizSendOrderMapper"> <mapper namespace="org.asinkj.amz.mapper.BizSendOrderMapper">
<select id="selectOrdersWithShipmentIds" resultType="org.asinkj.amz.domain.OrderWithShipment">
SELECT
rel.shipment_plan_id AS shipmentPlanId,
o.id AS "order.id",
o.tenant_id AS "order.tenantId",
o.del_flag AS "order.delFlag",
o.create_by AS "order.createBy",
o.create_time AS "order.createTime",
o.update_by AS "order.updateBy",
o.update_time AS "order.updateTime",
o.create_dept AS "order.createDept",
o.order_sn AS "order.orderSn",
o.send_date AS "order.sendDate",
o.store_name AS "order.storeName",
o.product_name AS "order.productName",
o.quantity_send AS "order.quantitySend",
o.quantity_per_box AS "order.quantityPerBox",
o.box_count AS "order.boxCount",
o.box_dimensions AS "order.boxDimensions",
o.weight_per_box AS "order.weightPerBox",
o.real_store_name AS "order.realStoreName",
o.send_status AS "order.sendStatus",
o.send_name AS "order.sendName",
o.send_id AS "order.sendId",
o.logistics_provider_id AS "order.logisticsProviderId",
o.send_detail AS "order.sendDetail",
o.logistics_provider_name AS "order.logisticsProviderName",
o.order_detail_id AS "order.orderDetailId",
o.shipment_id AS "order.shipmentId"
FROM biz_send_order o
INNER JOIN biz_send_shipment_rel rel ON o.id = rel.send_order_id
WHERE rel.shipment_plan_id IN
<foreach item="id" collection="shipmentIds" open="(" separator="," close=")">
#{id}
</foreach>
</select>
<resultMap id="orderWithShipmentMap" type="org.asinkj.amz.domain.OrderWithShipment">
<!-- 使用订单id作为整个OrderWithShipment对象的唯一标识 -->
<id property="order.id" column="oid"/>
<result property="shipmentPlanId" column="shipmentPlanId"/>
<association property="order" javaType="org.asinkj.amz.domain.BizSendOrder">
<id property="id" column="oid"/>
<result property="tenantId" column="tenant_id"/>
<result property="delFlag" column="del_flag"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="createDept" column="create_dept"/>
<result property="orderSn" column="order_sn"/>
<result property="sendDate" column="send_date"/>
<result property="storeName" column="store_name"/>
<result property="productName" column="product_name"/>
<result property="quantitySend" column="quantity_send"/>
<result property="quantityPerBox" column="quantity_per_box"/>
<result property="boxCount" column="box_count"/>
<result property="boxDimensions" column="box_dimensions"/>
<result property="weightPerBox" column="weight_per_box"/>
<result property="realStoreName" column="real_store_name"/>
<result property="sendStatus" column="send_status"/>
<result property="sendName" column="send_name"/>
<result property="sendId" column="send_id"/>
<result property="logisticsProviderId" column="logistics_provider_id"/>
<result property="sendDetail" column="send_detail"/>
<result property="logisticsProviderName" column="logistics_provider_name"/>
<result property="orderDetailId" column="order_detail_id"/>
<result property="shipmentId" column="shipment_id"/>
</association>
</resultMap>
</mapper> </mapper>

View File

@ -3,5 +3,25 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.asinkj.amz.mapper.BizSendShipmentRelMapper"> <mapper namespace="org.asinkj.amz.mapper.BizSendShipmentRelMapper">
<!-- biz_send_shipment_rel_mapper.xml -->
<insert id="batchInsertRelations">
INSERT INTO biz_send_shipment_rel (send_order_id, shipment_plan_id)
VALUES
<foreach collection="relations" item="rel" separator=",">
(#{rel.sendOrderId}, #{rel.shipmentPlanId})
</foreach>
ON CONFLICT (send_order_id, shipment_plan_id) DO NOTHING
</insert>
<delete id="batchDeleteRelations">
DELETE FROM biz_send_shipment_rel
WHERE send_order_id IN
<foreach collection="sendOrderIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
AND shipment_plan_id IN
<foreach collection="shipmentIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper> </mapper>

View File

@ -33,4 +33,116 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{id} #{id}
</foreach> </foreach>
</select> </select>
<resultMap id="shipmentPlanMap" type="org.asinkj.amz.domain.BizShipmentPlan">
<id property="id" column="id"/>
<result property="shipmentId" column="shipment_id"/>
<result property="shipmentName" column="shipment_name"/>
<result property="isClosed" column="is_closed"/>
<result property="shipmentStatus" column="shipment_status"/>
<result property="destination" column="destination"/>
<result property="shippingMode" column="shipping_mode"/>
<result property="shippingSolution" column="shipping_solution"/>
<result property="gmtModified" column="gmt_modified"/>
<result property="gmtCreate" column="gmt_create"/>
<result property="receivingTime" column="receiving_time"/>
<result property="staShipmentDate" column="sta_shipment_date"/>
<result property="staDeliveryStartDate" column="sta_delivery_start_date"/>
<result property="staDeliveryEndDate" column="sta_delivery_end_date"/>
<result property="shipFromAddress" column="ship_from_address"/>
<result property="shipToAddress" column="ship_to_address"/>
<result property="referenceId" column="reference_id"/>
<result property="staInboundPlanId" column="sta_inbound_plan_id"/>
<result property="isSta" column="is_sta"/>
<result property="delFlag" column="del_flag"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="createDept" column="create_dept"/>
<result property="tenantId" column="tenant_id"/>
<result property="shipmentUniqueId" column="shipment_unique_id"/>
<result property="inboundPlanId" column="inbound_plan_id"/>
<result property="fbaStatus" column="fba_status"/>
<result property="boxQuantity" column="box_quantity"/>
<result property="boxSize" column="box_size"/>
<result property="vendorWeight" column="vendor_weight"/>
<result property="setTotal" column="set_total"/>
<result property="channelId" column="channel_id"/>
<result property="channelName" column="channel_name"/>
<!--<result property="shippedTime" column="shipped_time"/>-->
<!--<result property="workingTime" column="working_time"/>-->
<!--<result property="closedTime" column="closed_time"/>-->
<!-- 如果有其他字段,请在此继续添加 -->
</resultMap>
<!-- 查询发货单与 shipment 的关系映射 -->
<resultMap id="orderShipmentRelationMap" type="org.asinkj.amz.domain.OrderShipmentRelation">
<result property="sendOrderId" column="send_order_id"/>
<result property="shipmentId" column="shipment_plan_id"/>
</resultMap>
<!-- 关系查询仅获取ID -->
<select id="findOrderShipmentRelations" resultMap="orderShipmentRelationMap">
SELECT
send_order_id,
shipment_plan_id
FROM biz_send_shipment_rel
WHERE send_order_id IN
<foreach item="id" collection="sendOrderIds" open="(" separator="," close=")">
#{id}
</foreach>
</select>
<!-- 根据ID批量查询 shipment -->
<select id="findByIds" resultMap="shipmentPlanMap">
SELECT
id,
shipment_id,
shipment_name,
is_closed,
shipment_status,
destination,
shipping_mode,
shipping_solution,
gmt_modified,
gmt_create,
receiving_time,
sta_shipment_date,
sta_delivery_start_date,
sta_delivery_end_date,
ship_from_address,
ship_to_address,
reference_id,
sta_inbound_plan_id,
is_sta,
del_flag,
create_by,
create_time,
update_by,
update_time,
create_dept,
tenant_id,
shipment_unique_id,
inbound_plan_id,
fba_status,
box_quantity,
box_size,
vendor_weight,
set_total,
channel_id,
channel_name,
shipped_time,
working_time,
closed_time
FROM biz_shipment_plan
WHERE id IN
<foreach item="id" collection="ids" open="(" separator="," close=")">
#{id}
</foreach>
</select>
</mapper> </mapper>