|
@@ -1,37 +1,43 @@
|
|
package com.hys.app.service.erp.impl;
|
|
package com.hys.app.service.erp.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.io.IoUtil;
|
|
import cn.hutool.core.io.IoUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
import cn.hutool.poi.excel.ExcelWriter;
|
|
import cn.hutool.poi.excel.ExcelWriter;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.hys.app.converter.erp.WarehouseOutConverter;
|
|
import com.hys.app.converter.erp.WarehouseOutConverter;
|
|
import com.hys.app.converter.erp.WarehouseOutItemConverter;
|
|
import com.hys.app.converter.erp.WarehouseOutItemConverter;
|
|
|
|
+import com.hys.app.framework.database.BaseQueryParam;
|
|
import com.hys.app.framework.database.WebPage;
|
|
import com.hys.app.framework.database.WebPage;
|
|
import com.hys.app.framework.exception.ServiceException;
|
|
import com.hys.app.framework.exception.ServiceException;
|
|
import com.hys.app.framework.database.mybatisplus.base.BaseServiceImpl;
|
|
import com.hys.app.framework.database.mybatisplus.base.BaseServiceImpl;
|
|
import com.hys.app.framework.rabbitmq.MessageSender;
|
|
import com.hys.app.framework.rabbitmq.MessageSender;
|
|
import com.hys.app.framework.rabbitmq.MqMessage;
|
|
import com.hys.app.framework.rabbitmq.MqMessage;
|
|
|
|
+import com.hys.app.framework.util.BeanUtils;
|
|
import com.hys.app.framework.util.DateUtil;
|
|
import com.hys.app.framework.util.DateUtil;
|
|
import com.hys.app.framework.util.PageConvert;
|
|
import com.hys.app.framework.util.PageConvert;
|
|
import com.hys.app.framework.util.StringUtil;
|
|
import com.hys.app.framework.util.StringUtil;
|
|
import com.hys.app.mapper.erp.WarehouseOutMapper;
|
|
import com.hys.app.mapper.erp.WarehouseOutMapper;
|
|
|
|
+import com.hys.app.mapper.goods.GoodsMapper;
|
|
import com.hys.app.model.base.rabbitmq.AmqpExchange;
|
|
import com.hys.app.model.base.rabbitmq.AmqpExchange;
|
|
import com.hys.app.model.erp.dos.*;
|
|
import com.hys.app.model.erp.dos.*;
|
|
import com.hys.app.model.erp.dto.*;
|
|
import com.hys.app.model.erp.dto.*;
|
|
import com.hys.app.model.erp.dto.message.WarehouseOutShipMessage;
|
|
import com.hys.app.model.erp.dto.message.WarehouseOutShipMessage;
|
|
import com.hys.app.model.erp.enums.*;
|
|
import com.hys.app.model.erp.enums.*;
|
|
-import com.hys.app.model.erp.vo.OrderAllowable;
|
|
|
|
-import com.hys.app.model.erp.vo.WarehouseOutAllowable;
|
|
|
|
-import com.hys.app.model.erp.vo.WarehouseOutStatistics;
|
|
|
|
-import com.hys.app.model.erp.vo.WarehouseOutVO;
|
|
|
|
|
|
+import com.hys.app.model.erp.vo.*;
|
|
import com.hys.app.model.system.dos.AdminUser;
|
|
import com.hys.app.model.system.dos.AdminUser;
|
|
import com.hys.app.model.system.dos.LogisticsCompanyDO;
|
|
import com.hys.app.model.system.dos.LogisticsCompanyDO;
|
|
import com.hys.app.service.erp.*;
|
|
import com.hys.app.service.erp.*;
|
|
|
|
+import com.hys.app.service.kuaidiniao.KuaiDiNiaoService;
|
|
|
|
+import com.hys.app.service.kuaidiniao.entity.PreOrderModel;
|
|
import com.hys.app.service.system.AdminUserManager;
|
|
import com.hys.app.service.system.AdminUserManager;
|
|
import com.hys.app.service.system.LogisticsCompanyManager;
|
|
import com.hys.app.service.system.LogisticsCompanyManager;
|
|
|
|
+import io.swagger.annotations.ApiModelProperty;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -57,9 +63,6 @@ public class WarehouseOutManagerImpl extends BaseServiceImpl<WarehouseOutMapper,
|
|
@Autowired
|
|
@Autowired
|
|
private WarehouseOutConverter converter;
|
|
private WarehouseOutConverter converter;
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private WarehouseOutItemConverter itemConverter;
|
|
|
|
-
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private OrderManager orderManager;
|
|
private OrderManager orderManager;
|
|
|
|
|
|
@@ -72,9 +75,6 @@ public class WarehouseOutManagerImpl extends BaseServiceImpl<WarehouseOutMapper,
|
|
@Autowired
|
|
@Autowired
|
|
private WarehouseEntryBatchManager batchManager;
|
|
private WarehouseEntryBatchManager batchManager;
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private LogisticsCompanyManager logisticsCompanyManager;
|
|
|
|
-
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private WarehouseOutMapper warehouseOutMapper;
|
|
private WarehouseOutMapper warehouseOutMapper;
|
|
|
|
|
|
@@ -85,105 +85,131 @@ public class WarehouseOutManagerImpl extends BaseServiceImpl<WarehouseOutMapper,
|
|
private AdminUserManager adminUserManager;
|
|
private AdminUserManager adminUserManager;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- private OrderItemManager orderItemManager;
|
|
|
|
|
|
+ private GoodsMapper goodsMapper;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private FinanceItemManager financeItemManager;
|
|
private FinanceItemManager financeItemManager;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private KuaiDiNiaoService kuaiDiNiaoService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ProductStockManager productStockManager;
|
|
|
|
+
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public WebPage<WarehouseOutVO> list(WarehouseOutQueryParams queryParams) {
|
|
public WebPage<WarehouseOutVO> list(WarehouseOutQueryParams queryParams) {
|
|
WebPage<WarehouseOutDO> webPage = baseMapper.selectPage(queryParams);
|
|
WebPage<WarehouseOutDO> webPage = baseMapper.selectPage(queryParams);
|
|
- return converter.convert(webPage);
|
|
|
|
|
|
+ WebPage<WarehouseOutVO> convert = converter.convert(webPage);
|
|
|
|
+ return convert;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public void add(WarehouseOutDTO warehouseOutDTO) {
|
|
public void add(WarehouseOutDTO warehouseOutDTO) {
|
|
- // 校验参数
|
|
|
|
- checkAddOrEdit(warehouseOutDTO);
|
|
|
|
-
|
|
|
|
// 保存出库单
|
|
// 保存出库单
|
|
- WarehouseOutDO warehouseOutDO = converter.combination(warehouseOutDTO);
|
|
|
|
|
|
+ WarehouseOutDO warehouseOutDO = BeanUtil.copyProperties(warehouseOutDTO, WarehouseOutDO.class);
|
|
warehouseOutDO.setSn(noGenerateManager.generate(NoBusinessTypeEnum.WarehouseOut, warehouseOutDO.getDeptId()));
|
|
warehouseOutDO.setSn(noGenerateManager.generate(NoBusinessTypeEnum.WarehouseOut, warehouseOutDO.getDeptId()));
|
|
- warehouseOutDO.setStatus(WarehouseOutStatusEnum.WAIT_AUDIT);
|
|
|
|
warehouseOutDO.setCreateBy(adminUserManager.getCurrUserName());
|
|
warehouseOutDO.setCreateBy(adminUserManager.getCurrUserName());
|
|
save(warehouseOutDO);
|
|
save(warehouseOutDO);
|
|
-
|
|
|
|
// 保存出库单明细
|
|
// 保存出库单明细
|
|
warehouseOutDTO.setId(warehouseOutDO.getId());
|
|
warehouseOutDTO.setId(warehouseOutDO.getId());
|
|
- List<WarehouseOutItemDO> productList = itemConverter.combination(warehouseOutDTO);
|
|
|
|
|
|
+ List<WarehouseOutItemDO> productList = BeanUtils.toBean(warehouseOutDTO.getProductList(), WarehouseOutItemDO.class);
|
|
|
|
+ productList.forEach(item->item.setWarehouseOutId(warehouseOutDO.getId()));
|
|
warehouseOutItemManager.saveBatch(productList);
|
|
warehouseOutItemManager.saveBatch(productList);
|
|
-
|
|
|
|
- // 将订单改为已出库状态
|
|
|
|
- orderManager.warehouseOut(warehouseOutDO.getOrderIdList(), warehouseOutDO.getId());
|
|
|
|
|
|
+ //如果是出库就要扣减库存
|
|
|
|
+ if ("submit".equals(warehouseOutDTO.getSaveOrSubmit())) {
|
|
|
|
+ updateStock(warehouseOutDTO, warehouseOutDO);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void edit(WarehouseOutDTO warehouseOutDTO) {
|
|
public void edit(WarehouseOutDTO warehouseOutDTO) {
|
|
- WarehouseOutDO old = getById(warehouseOutDTO.getId());
|
|
|
|
- if (!new WarehouseOutAllowable(old).getEdit()) {
|
|
|
|
- throw new ServiceException("当前状态不允许进行编辑操作");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (!convertSet(warehouseOutDTO.getOrderList(), WarehouseOutDTO.Order::getOrderId).equals(new HashSet<>(old.getOrderIdList()))) {
|
|
|
|
- throw new ServiceException("订单和出库单已有订单不一致");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 校验参数
|
|
|
|
- checkAddOrEdit(warehouseOutDTO);
|
|
|
|
-
|
|
|
|
// 保存出库单
|
|
// 保存出库单
|
|
- WarehouseOutDO warehouseOutDO = converter.combination(warehouseOutDTO);
|
|
|
|
|
|
+ WarehouseOutDO warehouseOutDO = BeanUtil.copyProperties(warehouseOutDTO, WarehouseOutDO.class);
|
|
updateById(warehouseOutDO);
|
|
updateById(warehouseOutDO);
|
|
-
|
|
|
|
// 保存出库单明细
|
|
// 保存出库单明细
|
|
- List<WarehouseOutItemDO> productList = itemConverter.combination(warehouseOutDTO);
|
|
|
|
|
|
+ List<WarehouseOutItemDO> productList = BeanUtils.toBean(warehouseOutDTO.getProductList(), WarehouseOutItemDO.class);
|
|
|
|
+ productList.forEach(item->item.setWarehouseOutId(warehouseOutDO.getId()));
|
|
warehouseOutItemManager.deleteByWarehouseOutId(Collections.singletonList(warehouseOutDTO.getId()));
|
|
warehouseOutItemManager.deleteByWarehouseOutId(Collections.singletonList(warehouseOutDTO.getId()));
|
|
warehouseOutItemManager.saveBatch(productList);
|
|
warehouseOutItemManager.saveBatch(productList);
|
|
|
|
+ //如果是出库就要扣减库存
|
|
|
|
+ if ("submit".equals(warehouseOutDTO.getSaveOrSubmit())) {
|
|
|
|
+ updateStock(warehouseOutDTO, warehouseOutDO);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void updateStock(WarehouseOutDTO warehouseOutDTO, WarehouseOutDO warehouseOutDO) {
|
|
|
|
+ if ("Y".equals(warehouseOutDO.getHasSubmit())) {
|
|
|
|
+ throw new ServiceException("数据已出库,请勿重复操作");
|
|
|
|
+ }
|
|
|
|
+ List<Long> collect = warehouseOutDTO.getProductList().stream().map(WarehouseOutProductDTO::getGoodsId).collect(Collectors.toList());
|
|
|
|
+ List<ProductStockDO> stockDOList = productStockManager.list(new LambdaQueryWrapper<ProductStockDO>()
|
|
|
|
+ .eq(ProductStockDO::getWarehouseId, warehouseOutDTO.getWarehouseId()).in(ProductStockDO::getGoodsId, collect));
|
|
|
|
+ for (ProductStockDO aDo : stockDOList) {
|
|
|
|
+ WarehouseOutProductDTO productDO = warehouseOutDTO.getProductList().stream().filter(item -> item.getGoodsId().equals(aDo.getGoodsId())).findFirst().get();
|
|
|
|
+ if (productDO.getOutNum() > aDo.getUsableStock()) {
|
|
|
|
+ throw new ServiceException(productDO.getGoodName() + "的可用库存不够,请核对数据");
|
|
|
|
+ }
|
|
|
|
+ //循环判断每一条数据可用库存够不够扣减
|
|
|
|
+ aDo.setUsableStock(aDo.getUsableStock() - productDO.getOutNum());
|
|
|
|
+ aDo.setActualStock(aDo.getActualStock() - productDO.getOutNum());
|
|
|
|
+ }
|
|
|
|
+ productStockManager.updateBatchById(stockDOList);
|
|
|
|
+ //入库之后数据不能被操作
|
|
|
|
+ warehouseOutDO.setHasSubmit("Y");
|
|
|
|
+ updateById(warehouseOutDO);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public WarehouseOutVO getDetail(Long id) {
|
|
public WarehouseOutVO getDetail(Long id) {
|
|
WarehouseOutDO warehouseOutDO = getById(id);
|
|
WarehouseOutDO warehouseOutDO = getById(id);
|
|
-
|
|
|
|
|
|
+ WarehouseOutVO outVO = BeanUtil.copyProperties(warehouseOutDO, WarehouseOutVO.class);
|
|
// 查询出库明细
|
|
// 查询出库明细
|
|
- List<WarehouseOutItemDO> itemList = warehouseOutItemManager.listByWarehouseOutId(id);
|
|
|
|
- // 查询批次信息(回显批次剩余库存)
|
|
|
|
- List<WarehouseEntryBatchDO> batchList = batchManager.listByIds(convertList(itemList, WarehouseOutItemDO::getWarehouseEntryBatchId));
|
|
|
|
-
|
|
|
|
- return converter.convert(warehouseOutDO, itemList, batchList);
|
|
|
|
|
|
+ List<WarehouseOutItemDO> itemList = warehouseOutItemManager.list(new LambdaQueryWrapper<WarehouseOutItemDO>().eq(WarehouseOutItemDO::getWarehouseOutId,id));
|
|
|
|
+ List<WarehouseOutProductDTO> productList = BeanUtils.toBean(itemList, WarehouseOutProductDTO.class);
|
|
|
|
+
|
|
|
|
+ List<Long> goodIdlist = itemList.stream().map(WarehouseOutItemDO::getGoodsId).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ //所有的商品信息
|
|
|
|
+ List<GoodsDO> goodsDOS = goodsMapper.selectList(new LambdaQueryWrapper<GoodsDO>().in(GoodsDO::getId, goodIdlist));
|
|
|
|
+ List<ProductStockDO> stockDOList = productStockManager.list(new LambdaQueryWrapper<ProductStockDO>()
|
|
|
|
+ .eq(ProductStockDO::getWarehouseId, warehouseOutDO.getWarehouseId()).in(ProductStockDO::getGoodsId, goodIdlist));
|
|
|
|
+ for (WarehouseOutProductDTO dto : productList) {
|
|
|
|
+ GoodsVO goodsVO = BeanUtil.copyProperties(goodsDOS.stream().filter(item -> item.getId().equals(dto.getGoodsId())).findFirst().get(), GoodsVO.class);
|
|
|
|
+ goodsVO.setUsableStock(stockDOList.stream().filter(item -> item.getGoodsId().equals(dto.getGoodsId())).findFirst().get().getUsableStock());
|
|
|
|
+ dto.setGoodsVO(goodsVO);
|
|
|
|
+ }
|
|
|
|
+ outVO.setProductList(productList);
|
|
|
|
+ return outVO;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
- public void delete(List<String> ids) {
|
|
|
|
- List<WarehouseOutDO> warehouseOutList = listByIds(ids);
|
|
|
|
- for (WarehouseOutDO warehouseOutDO : warehouseOutList) {
|
|
|
|
- if (!new WarehouseOutAllowable(warehouseOutDO).getDelete()) {
|
|
|
|
- throw new ServiceException(warehouseOutDO.getSn() + "不能进行删除操作");
|
|
|
|
- }
|
|
|
|
|
|
+ public void delete(Long id) {
|
|
|
|
+ WarehouseOutDO aDo = getById(id);
|
|
|
|
+ if ("Y".equals(aDo.getHasSubmit())) {
|
|
|
|
+ throw new ServiceException("该数据已提交,不能删除");
|
|
}
|
|
}
|
|
-
|
|
|
|
- // 删除
|
|
|
|
- removeBatchByIds(ids);
|
|
|
|
|
|
+ removeById(id);
|
|
// 删除明细
|
|
// 删除明细
|
|
- warehouseOutItemManager.deleteByWarehouseOutId(ids);
|
|
|
|
- // 订单改为未出库
|
|
|
|
- orderManager.warehouseOutDelete(ids);
|
|
|
|
|
|
+ warehouseOutItemManager.remove(new LambdaQueryWrapper<WarehouseOutItemDO>().eq(WarehouseOutItemDO::getWarehouseOutId, id));
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public WarehouseOutVO preview(WarehouseOutPreviewDTO warehouseOutPreviewDTO) {
|
|
public WarehouseOutVO preview(WarehouseOutPreviewDTO warehouseOutPreviewDTO) {
|
|
- // 校验订单编号是否正确
|
|
|
|
- List<OrderDO> orderList = checkOrderData(warehouseOutPreviewDTO.getOrderIdList());
|
|
|
|
-
|
|
|
|
- // 查询订单明细
|
|
|
|
- List<OrderItemDO> orderItemList = orderItemManager.listByOrderIds(warehouseOutPreviewDTO.getOrderIdList());
|
|
|
|
-
|
|
|
|
- // 查询这些商品的可用入库批次
|
|
|
|
- List<Long> productIds = convertList(orderItemList, OrderItemDO::getProductId);
|
|
|
|
- Map<Long, List<WarehouseEntryBatchDO>> warehouseBatchMap = batchManager.listAvailableBatch(orderList.get(0).getWarehouseId(), productIds);
|
|
|
|
- return converter.convertPreview(orderList, orderItemList, warehouseBatchMap);
|
|
|
|
|
|
+// // 校验订单编号是否正确
|
|
|
|
+// List<OrderDO> orderList = checkOrderData(warehouseOutPreviewDTO.getOrderIdList());
|
|
|
|
+//
|
|
|
|
+// // 查询订单明细
|
|
|
|
+// List<OrderItemDO> orderItemList = orderItemManager.listByOrderIds(warehouseOutPreviewDTO.getOrderIdList());
|
|
|
|
+//
|
|
|
|
+// // 查询这些商品的可用入库批次
|
|
|
|
+// List<Long> productIds = convertList(orderItemList, OrderItemDO::getProductId);
|
|
|
|
+// Map<Long, List<WarehouseEntryBatchDO>> warehouseBatchMap = batchManager.listAvailableBatch(orderList.get(0).getWarehouseId(), productIds);
|
|
|
|
+// return converter.convertPreview(orderList, orderItemList, warehouseBatchMap);
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -194,10 +220,6 @@ public class WarehouseOutManagerImpl extends BaseServiceImpl<WarehouseOutMapper,
|
|
if (!new WarehouseOutAllowable(warehouseOutDO).getShip()) {
|
|
if (!new WarehouseOutAllowable(warehouseOutDO).getShip()) {
|
|
throw new ServiceException("当前状态不能进行发货操作");
|
|
throw new ServiceException("当前状态不能进行发货操作");
|
|
}
|
|
}
|
|
-
|
|
|
|
- // 校验参数并填充数据到shipDTO
|
|
|
|
- checkShipParams(warehouseOutDO.getDeliveryType(), shipDTO);
|
|
|
|
-
|
|
|
|
// 扣减批次库存
|
|
// 扣减批次库存
|
|
List<WarehouseOutItemDO> productList = warehouseOutItemManager.listByWarehouseOutId(id);
|
|
List<WarehouseOutItemDO> productList = warehouseOutItemManager.listByWarehouseOutId(id);
|
|
List<StockUpdateDTO> stockUpdateList = converter.convertStockUpdateList(productList);
|
|
List<StockUpdateDTO> stockUpdateList = converter.convertStockUpdateList(productList);
|
|
@@ -312,139 +334,32 @@ public class WarehouseOutManagerImpl extends BaseServiceImpl<WarehouseOutMapper,
|
|
.update();
|
|
.update();
|
|
}
|
|
}
|
|
|
|
|
|
- private void checkAddOrEdit(WarehouseOutDTO warehouseOutDTO) {
|
|
|
|
- List<WarehouseOutDTO.Order> orderDTOList = warehouseOutDTO.getOrderList();
|
|
|
|
- // 1. 校验订单
|
|
|
|
- List<String> orderIds = convertList(orderDTOList, WarehouseOutDTO.Order::getOrderId);
|
|
|
|
- List<OrderDO> orderList = checkOrderData(orderIds);
|
|
|
|
- warehouseOutDTO.setOrderMap(convertMap(orderList, OrderDO::getId, Function.identity()));
|
|
|
|
-
|
|
|
|
- // 2. 校验订单明细和批次
|
|
|
|
- // 2.1 查询订单项
|
|
|
|
- List<String> orderItemIds = orderDTOList.stream().flatMap(orderDTO -> orderDTO.getOrderItemList().stream())
|
|
|
|
- .map(WarehouseOutDTO.OrderItem::getOrderItemId).collect(Collectors.toList());
|
|
|
|
- Map<String, OrderItemDO> orderItemMap = orderItemManager.listAndConvertMap(orderItemIds, OrderItemDO::getId);
|
|
|
|
- warehouseOutDTO.setOrderItemMap(orderItemMap);
|
|
|
|
- // 2.2 查询批次
|
|
|
|
- List<String> batchIds = orderDTOList.stream()
|
|
|
|
- .flatMap(orderDTO -> orderDTO.getOrderItemList().stream().flatMap(orderItemDTO -> orderItemDTO.getBatchList().stream()))
|
|
|
|
- .map(WarehouseOutDTO.StockBatch::getBatchId).collect(Collectors.toList());
|
|
|
|
- Map<String, WarehouseEntryBatchDO> batchMap = batchManager.listAndConvertMap(batchIds, WarehouseEntryBatchDO::getId);
|
|
|
|
- warehouseOutDTO.setBatchMap(batchMap);
|
|
|
|
- // 2.3 循环校验订单明细和批次
|
|
|
|
- for (WarehouseOutDTO.Order order : orderDTOList) {
|
|
|
|
- for (WarehouseOutDTO.OrderItem orderItem : order.getOrderItemList()) {
|
|
|
|
-
|
|
|
|
- // 校验订单明细
|
|
|
|
- OrderItemDO orderItemDO = orderItemMap.get(orderItem.getOrderItemId());
|
|
|
|
- if (orderItemDO == null) {
|
|
|
|
- throw new ServiceException(StrUtil.format("订单项【{}】不存在", orderItem.getOrderItemId()));
|
|
|
|
- }
|
|
|
|
- if (!orderItemDO.getOrderId().equals(order.getOrderId())) {
|
|
|
|
- throw new ServiceException(StrUtil.format("订单项【{}】不属于订单【{}】", orderItem.getOrderItemId(), order.getOrderId()));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 校验批次
|
|
|
|
- for (WarehouseOutDTO.StockBatch stockBatch : orderItem.getBatchList()) {
|
|
|
|
- WarehouseEntryBatchDO batchDO = batchMap.get(stockBatch.getBatchId());
|
|
|
|
- if (batchDO == null) {
|
|
|
|
- throw new ServiceException(StrUtil.format("批次【{}】不存在", stockBatch.getBatchId()));
|
|
|
|
- }
|
|
|
|
- if (!batchDO.getProductId().equals(orderItemDO.getProductId())) {
|
|
|
|
- throw new ServiceException(StrUtil.format("批次【{}】不属于商品【{}】", batchDO.getId(), orderItemDO.getProductId()));
|
|
|
|
- }
|
|
|
|
- if (!batchDO.getWarehouseId().equals(orderList.get(0).getWarehouseId())) {
|
|
|
|
- throw new ServiceException(StrUtil.format("批次【{}】不属于仓库【{}】", batchDO.getId(), orderList.get(0).getWarehouseId()));
|
|
|
|
- }
|
|
|
|
- // 这里先前置校验一下,后续发货时会真正校验库存
|
|
|
|
- if (batchDO.getRemainNum() < stockBatch.getOutNum()) {
|
|
|
|
- throw new ServiceException(StrUtil.format("批次【{}】的剩余库存数不足", batchDO.getSn()));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 校验orderItem的销售数量和批次的出库数量是否一致
|
|
|
|
- if (orderItemDO.getNum() != orderItem.getBatchList().stream().mapToInt(WarehouseOutDTO.StockBatch::getOutNum).sum()) {
|
|
|
|
- throw new ServiceException(StrUtil.format("商品【{}】的销售数量和出库数量不一致", orderItemDO.getProductName()));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 仓库提货人
|
|
|
|
- AdminUser warehouseConsignee = adminUserManager.getModel(warehouseOutDTO.getWarehouseConsigneeId());
|
|
|
|
- if (warehouseConsignee == null) {
|
|
|
|
- throw new ServiceException("仓库提货人不存在");
|
|
|
|
- }
|
|
|
|
- warehouseOutDTO.setWarehouseConsignee(warehouseConsignee);
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void checkShipParams(OrderDeliveryType deliveryType, WarehouseOutShipDTO shipDTO) {
|
|
|
|
- if (deliveryType == OrderDeliveryType.express) {
|
|
|
|
- if (shipDTO.getLogisticsCompanyId() == null) {
|
|
|
|
- throw new ServiceException("请选择物流公司");
|
|
|
|
- }
|
|
|
|
- if (StringUtil.isEmpty(shipDTO.getTrackingNumber())) {
|
|
|
|
- throw new ServiceException("物流单号不能为空");
|
|
|
|
- }
|
|
|
|
- LogisticsCompanyDO logisticsCompanyDO = logisticsCompanyManager.getModel(shipDTO.getLogisticsCompanyId());
|
|
|
|
- if (logisticsCompanyDO == null) {
|
|
|
|
- throw new ServiceException("物流公司不存在");
|
|
|
|
- }
|
|
|
|
- shipDTO.setLogisticsCompanyName(logisticsCompanyDO.getName());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public void kdShip(PreOrderModel preOrderModel) {
|
|
|
|
+ kuaiDiNiaoService.preOrder(preOrderModel);
|
|
}
|
|
}
|
|
|
|
|
|
- private List<OrderDO> checkOrderData(List<String> orderIds) {
|
|
|
|
- // 校验订单存在
|
|
|
|
- List<OrderDO> orderList = orderManager.listByIds(orderIds);
|
|
|
|
- Map<String, OrderDO> orderMap = convertMap(orderList, OrderDO::getId, Function.identity());
|
|
|
|
- for (String orderId : orderIds) {
|
|
|
|
- OrderDO orderDO = orderMap.get(orderId);
|
|
|
|
- if (orderDO == null) {
|
|
|
|
- throw new ServiceException(StrUtil.format("订单【{}】不存在", orderId));
|
|
|
|
- }
|
|
|
|
- if (!new OrderAllowable(orderDO).getWarehouseOut()) {
|
|
|
|
- throw new ServiceException(StrUtil.format("订单【{}】不允许进行出库操作", orderDO.getSn()));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 校验是否是同一仓库的订单
|
|
|
|
- Map<Long, List<OrderDO>> groupByWarehouse = orderList.stream().collect(Collectors.groupingBy(OrderDO::getWarehouseId));
|
|
|
|
- if (groupByWarehouse.size() != 1) {
|
|
|
|
- throw new ServiceException("只能选择同一个仓库的订单");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 校验是否是同一会员的订单
|
|
|
|
- Map<Long, List<OrderDO>> groupByMember = orderList.stream().collect(Collectors.groupingBy(OrderDO::getMemberId));
|
|
|
|
- if (groupByMember.size() != 1) {
|
|
|
|
- throw new ServiceException("只能选择同一个会员的订单");
|
|
|
|
- }
|
|
|
|
- // 校验所有订单的配送方式是否相同
|
|
|
|
- Map<OrderDeliveryType, List<OrderDO>> groupByShippingType = orderList.stream().collect(Collectors.groupingBy(OrderDO::getDeliveryType));
|
|
|
|
- if (groupByShippingType.size() != 1) {
|
|
|
|
- throw new ServiceException("不能同时选择物流和自提订单");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-// // 如果是物流的话,校验是否是同一收货地址
|
|
|
|
-// if (OrderDeliveryType.express.name().equals(orderList.get(0).getShippingType())) {
|
|
|
|
-// Map<String, List<OrderDO>> groupByAddress = orderList.stream().collect(Collectors.groupingBy(orderDO -> orderDO.getShipCountyId() + "_" + orderDO.getShipTownId()));
|
|
|
|
-// if (groupByAddress.size() != 1) {
|
|
|
|
-// throw new ServiceException("只能选择同一收货地址的订单");
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
- // 如果是自提的话,校验是否是同一门店
|
|
|
|
- if (orderList.get(0).getDeliveryType() == OrderDeliveryType.self_pick) {
|
|
|
|
- Map<Long, List<OrderDO>> groupByBranch = orderList.stream().collect(Collectors.groupingBy(OrderDO::getStoreId));
|
|
|
|
- if (groupByBranch.size() != 1) {
|
|
|
|
- throw new ServiceException("只能选择同一自提门店的订单");
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public Page<GoodsVO> getGoodByWarehouse(Long warehouseId, BaseQueryParam queryParam) {
|
|
|
|
+ IPage<ProductStockDO> page = new Page<>(queryParam.getPageNo(), queryParam.getPageSize());
|
|
|
|
+ IPage<ProductStockDO> page1 = productStockManager.page(page, new LambdaQueryWrapper<ProductStockDO>()
|
|
|
|
+ .eq(ProductStockDO::getWarehouseId, warehouseId)
|
|
|
|
+ .gt(ProductStockDO::getUsableStock, 0));
|
|
|
|
+ List<Long> collect = page1.getRecords().stream().map(ProductStockDO::getGoodsId).collect(Collectors.toList());
|
|
|
|
+ if (CollectionUtil.isNotEmpty(collect)) {
|
|
|
|
+ List<GoodsDO> goodsDOS = goodsMapper.selectList(new LambdaQueryWrapper<GoodsDO>().in(GoodsDO::getId, collect));
|
|
|
|
+ List<GoodsVO> beanVo = BeanUtils.toBean(goodsDOS, GoodsVO.class);
|
|
|
|
+ for (GoodsVO goodsVO : beanVo) {
|
|
|
|
+ goodsVO.setUsableStock(page1.getRecords().stream().filter(item -> item.getGoodsId().equals(goodsVO.getId())).findFirst().get().getUsableStock());
|
|
}
|
|
}
|
|
|
|
+ Page<GoodsVO> pageVo = new Page<>(queryParam.getPageNo(), queryParam.getPageNo());
|
|
|
|
+ pageVo.setPages(page1.getPages());
|
|
|
|
+ pageVo.setSize(page1.getSize());
|
|
|
|
+ pageVo.setTotal(page1.getTotal());
|
|
|
|
+ pageVo.setRecords(beanVo);
|
|
|
|
+ return pageVo;
|
|
}
|
|
}
|
|
-
|
|
|
|
- return orderList;
|
|
|
|
|
|
+ return new Page<>();
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|