|
|
@@ -6257,7 +6257,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
if (ship.getBizTypeName().equals(OrderTypeEnum.SCDD.getType())) {
|
|
|
ship.setStatusName(OrderTypeEnum.PRODUCTION_IN.getType());
|
|
|
} else if (ship.getBizTypeName().equals(OrderTypeEnum.SCLL.getType())) {
|
|
|
- ship.setStatusName(OrderTypeEnum.TOBESHIPPEDOUT.getType());
|
|
|
+ ship.setStatusName(OrderTypeEnum.STAY_PICKING.getType());
|
|
|
}
|
|
|
ship.setBillno(billNo);
|
|
|
ship.setCreateTime(new Date());
|
|
|
@@ -6279,7 +6279,6 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
List<PjShipItems> shipItemsList = new ArrayList<>();
|
|
|
if (CollectionUtils.isNotEmpty(ship.getShipItemsList())) {
|
|
|
ship.getShipItemsList().forEach(item -> {
|
|
|
- item.setCostprie(item.getSendNum().multiply(item.getCostpriePrice()));
|
|
|
if (item.getId() == null) {
|
|
|
item.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
item.setCreateTime(new Date());
|
|
|
@@ -6363,12 +6362,638 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
|
|
|
@Override
|
|
|
public R completed(PjShip ship) {
|
|
|
- return null;
|
|
|
+ // 保存订单明细
|
|
|
+ List<PjShipItems> shipItemsList = new ArrayList<>();
|
|
|
+ List<PjStockDesc> pjStockDescArrayListSave = new ArrayList<>();
|
|
|
+ List<PjStockDesc> pjStockDescArrayListUpdate = new ArrayList<>();
|
|
|
+ List<PjProductLaunch> pjProductLaunchList = new ArrayList<>();
|
|
|
+ if (CollectionUtils.isNotEmpty(ship.getShipItemsList())) {
|
|
|
+ ship.setSendTotalNum(ship.getShipItemsList().stream().map(PjShipItems::getSendNum).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ List<Long> goodIds = ship.getShipItemsList().stream().map(PjShipItems::getGoodsId).distinct().collect(Collectors.toList());
|
|
|
+ List<PjGoodsDesc> pjGoodsDescList = goodsDescMapper.selectList(new LambdaQueryWrapper<PjGoodsDesc>()
|
|
|
+ .eq(PjGoodsDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjGoodsDesc::getIsDeleted, 0)
|
|
|
+ .in(PjGoodsDesc::getId, goodIds));
|
|
|
+ //修改库存账
|
|
|
+ LambdaQueryWrapper<PjStockDesc> stockLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ stockLambdaQueryWrapper
|
|
|
+ .eq(PjStockDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjStockDesc::getIsDeleted, 0)
|
|
|
+ .eq(PjStockDesc::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
+ .in(PjStockDesc::getGoodsId, goodIds);
|
|
|
+ List<PjStockDesc> pjStockDescList = iStockDescService.list(stockLambdaQueryWrapper);
|
|
|
+ List<PjGoodsType> pjGoodsTypeList = goodsTypeMapper.selectList(new LambdaQueryWrapper<PjGoodsType>()
|
|
|
+ .eq(PjGoodsType::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjGoodsType::getIsDeleted, 0)
|
|
|
+ .in(PjGoodsType::getId, goodIds)
|
|
|
+ );
|
|
|
+ List<PjOrderItems> orderItemsList = orderItemsService.list(new LambdaQueryWrapper<PjOrderItems>()
|
|
|
+ .eq(PjOrderItems::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjOrderItems::getIsDeleted, 0)
|
|
|
+ .eq(PjOrderItems::getBsType, "PD")
|
|
|
+ .ne(PjOrderItems::getStatus, "已确认")
|
|
|
+ .in(PjOrderItems::getGoodsId, goodIds)
|
|
|
+ );
|
|
|
+ StringBuilder msg1 = new StringBuilder();
|
|
|
+ //获得仓库
|
|
|
+ PjStorageDesc storageDesc = storageDescMapper.selectById(ship.getStorageId());
|
|
|
+ for (PjShipItems item : ship.getShipItemsList()) {
|
|
|
+ if (item.getId() == null) {
|
|
|
+ item.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ item.setCreateTime(new Date());
|
|
|
+ item.setCreateUser(AuthUtil.getUserId());
|
|
|
+ item.setPid(ship.getId());
|
|
|
+ item.setTenantId(AuthUtil.getTenantId());
|
|
|
+ } else {
|
|
|
+ item.setUpdateTime(new Date());
|
|
|
+ item.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ item.setPid(ship.getId());
|
|
|
+ }
|
|
|
+ item.setSendNum(item.getGoodsNum());
|
|
|
+ item.setSendNumHave(item.getGoodsNum());
|
|
|
+ List<PjOrderItems> pjOrderItemsList1 = orderItemsList.stream().filter(e -> e.getGoodsId().equals(item.getGoodsId())).collect(Collectors.toList());
|
|
|
+ if (!pjOrderItemsList1.isEmpty()) {
|
|
|
+ msg1.append(item.getGoodsName()).append(",");
|
|
|
+ }
|
|
|
+ //获得商品
|
|
|
+ PjGoodsDesc goodsDesc = pjGoodsDescList.stream().filter(e -> e.getId().equals(item.getGoodsId())).findFirst().orElse(null);
|
|
|
+ if (ObjectUtil.isEmpty(goodsDesc)) {
|
|
|
+ throw new RuntimeException("商品数据异常");
|
|
|
+ }
|
|
|
+ if ("1".equals(goodsDesc.getWhether()) && ObjectUtils.isNull(item.getDot())) {
|
|
|
+ throw new RuntimeException("商品:" + goodsDesc.getCname() + ",请选择批次号");
|
|
|
+ }
|
|
|
+ //生成库存账
|
|
|
+ PjStockDesc stockDesc = new PjStockDesc();
|
|
|
+ stockDesc.setSalesCompanyId(ship.getSalesCompanyId());
|
|
|
+ stockDesc.setSalesCompanyName(ship.getSalesCompanyName());
|
|
|
+ stockDesc.setGoodsTypeId(goodsDesc.getGoodsTypeId());
|
|
|
+ if (ObjectUtils.isNotNull(goodsDesc.getGoodsTypeId())) {
|
|
|
+ PjGoodsType goodsType = pjGoodsTypeList.stream().filter(e -> (e.getId() + "").equals(goodsDesc.getGoodsTypeId())).findFirst().orElse(null);
|
|
|
+ if (goodsType != null) {
|
|
|
+ stockDesc.setGoodsTypeName(goodsType.getCname());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ stockDesc.setGoodsId(goodsDesc.getId());
|
|
|
+ stockDesc.setCode(item.getGoodsNo());
|
|
|
+ stockDesc.setCname(goodsDesc.getCname());
|
|
|
+ stockDesc.setInventoryAlert(goodsDesc.getInventoryAlert());
|
|
|
+ stockDesc.setBrandId(goodsDesc.getBrandId());
|
|
|
+ stockDesc.setBrandName(goodsDesc.getBrandName());
|
|
|
+ stockDesc.setTypeno(item.getPropertyName());
|
|
|
+ stockDesc.setBrandItem(item.getPattern());
|
|
|
+ stockDesc.setProductDescription(item.getGoodsDescription());
|
|
|
+ stockDesc.setDot(item.getDot());
|
|
|
+ stockDesc.setTenantId(AuthUtil.getTenantId());
|
|
|
+ stockDesc.setCnameInt(goodsDesc.getCnameInt());
|
|
|
+
|
|
|
+ //管理批次号
|
|
|
+ PjStockDesc stockOne;
|
|
|
+ if (ObjectUtil.isNotEmpty(goodsDesc.getWhether()) && "1".equals(goodsDesc.getWhether())) {
|
|
|
+ stockOne = pjStockDescList.stream()
|
|
|
+ .filter(e -> e.getGoodsId().equals(item.getGoodsId())
|
|
|
+ && e.getStorageId().equals(ship.getStorageId())
|
|
|
+ && e.getDot().equals(item.getDot())).findFirst().orElse(null);
|
|
|
+ } else {
|
|
|
+ stockOne = pjStockDescList.stream()
|
|
|
+ .filter(e -> e.getGoodsId().equals(item.getGoodsId())
|
|
|
+ && e.getStorageId().equals(ship.getStorageId())
|
|
|
+ && ObjectUtils.isNull(e.getDot())).findFirst().orElse(null);
|
|
|
+ }
|
|
|
+ if (stockOne == null) {
|
|
|
+ if (ObjectUtil.isNotEmpty(storageDesc)) {
|
|
|
+ stockDesc.setStorageId(storageDesc.getId());
|
|
|
+ stockDesc.setStorageName(storageDesc.getCname());
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("仓库数据异常");
|
|
|
+ }
|
|
|
+ stockDesc.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ stockDesc.setCreateTime(new Date());
|
|
|
+ stockDesc.setCreateUser(AuthUtil.getUserId());
|
|
|
+ stockDesc.setBalanceQuantity(item.getSendNum());
|
|
|
+ stockDesc.setBalanceQuantityHave(item.getSendNum());
|
|
|
+ stockDesc.setStoreInventory(item.getSendNum());
|
|
|
+ stockDesc.setInventoryAmount(item.getSendNum().multiply(item.getPrice()));
|
|
|
+ stockDesc.setInventoryCostPrice(item.getPrice());
|
|
|
+ pjStockDescArrayListSave.add(stockDesc);
|
|
|
+ } else {
|
|
|
+ stockDesc.setId(stockOne.getId());
|
|
|
+ stockDesc.setUpdateTime(new Date());
|
|
|
+ stockDesc.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ stockDesc.setBalanceQuantity(stockOne.getBalanceQuantity().add(item.getSendNum()));
|
|
|
+ stockDesc.setBalanceQuantityHave(stockOne.getBalanceQuantityHave().add(item.getSendNum()));
|
|
|
+ stockDesc.setStoreInventory(stockDesc.getBalanceQuantity());
|
|
|
+ stockDesc.setInventoryAmount(item.getSendNum().multiply(item.getPrice()));
|
|
|
+ stockDesc.setInventoryAmount(stockDesc.getInventoryAmount().add(stockOne.getInventoryAmount()));
|
|
|
+ if (stockDesc.getBalanceQuantity().compareTo(new BigDecimal("0")) != 0) {
|
|
|
+ stockDesc.setInventoryCostPrice(stockDesc.getInventoryAmount().divide(stockDesc.getBalanceQuantity(), MathContext.DECIMAL32).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ }
|
|
|
+ stockDesc.setVersion(stockOne.getVersion());
|
|
|
+ pjStockDescArrayListUpdate.add(stockDesc);
|
|
|
+ }
|
|
|
+ shipItemsList.add(item);
|
|
|
+ }
|
|
|
+ if (msg1.length() > 0) {
|
|
|
+ throw new RuntimeException("商品:" + msg1 + "正在盘点中,操作失败");
|
|
|
+ }
|
|
|
+ shipItemsService.saveOrUpdateBatch(shipItemsList);
|
|
|
+ if (!pjStockDescArrayListSave.isEmpty()) {
|
|
|
+ iStockDescService.saveBatch(pjStockDescArrayListSave);
|
|
|
+ }
|
|
|
+ if (!pjStockDescArrayListUpdate.isEmpty()) {
|
|
|
+ iStockDescService.updateBatchById(pjStockDescArrayListUpdate);
|
|
|
+ }
|
|
|
+ //查询所有上架商品
|
|
|
+ LambdaQueryWrapper<PjProductLaunch> productLaunchQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ productLaunchQueryWrapper.eq(PjProductLaunch::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjProductLaunch::getIsDeleted, 0)
|
|
|
+ .isNull(PjProductLaunch::getSourceId)
|
|
|
+ .eq(PjProductLaunch::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
+ .in(PjProductLaunch::getGoodsId, goodIds);
|
|
|
+ List<PjProductLaunch> productLaunch = productLaunchService.list(productLaunchQueryWrapper);
|
|
|
+ for (PjShipItems item : ship.getShipItemsList()) {
|
|
|
+ //获得商品
|
|
|
+ PjGoodsDesc goodsDesc = pjGoodsDescList.stream().filter(e -> e.getId().equals(item.getGoodsId())).findFirst().orElse(null);
|
|
|
+ if (ObjectUtil.isEmpty(goodsDesc)) {
|
|
|
+ throw new RuntimeException("商品数据异常");
|
|
|
+ }
|
|
|
+ PjProductLaunch pjProductLaunches = productLaunch.stream()
|
|
|
+ .filter(i -> i.getGoodsId().equals(goodsDesc.getId())).findFirst().orElse(null);
|
|
|
+ //修改上架数量
|
|
|
+ if (pjProductLaunches != null) {
|
|
|
+ if (ObjectUtils.isNotNull(pjProductLaunches.getInventory())) {
|
|
|
+ pjProductLaunches.setInventory(pjProductLaunches.getInventory().add(item.getSendNumHave()));
|
|
|
+ } else {
|
|
|
+ pjProductLaunches.setInventory(item.getSendNumHave());
|
|
|
+ }
|
|
|
+ pjProductLaunchList.add(pjProductLaunches);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ R res = productLaunchService.updateBatchById(pjProductLaunchList);
|
|
|
+ if (!res.isSuccess()) {
|
|
|
+ throw new RuntimeException(res.getMsg());
|
|
|
+ }
|
|
|
+ ship.setShipItemsList(ship.getShipItemsList());
|
|
|
+ ship.setNumberRows(ship.getShipItemsList().size());
|
|
|
+ }
|
|
|
+ ship.setStatusName(OrderTypeEnum.PRODUCTION_COMPLETED.getType());
|
|
|
+ baseMapper.updateById(ship);
|
|
|
+ return R.data(ship);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public R revokeCompleted(PjShip ship) {
|
|
|
- return null;
|
|
|
+ PjShip shipVersion = baseMapper.selectById(ship.getId());
|
|
|
+ if (shipVersion != null && !shipVersion.getVersion().equals(ship.getVersion())) {
|
|
|
+ throw new RuntimeException("数据已被修改,请返回列表重新操作!");
|
|
|
+ }
|
|
|
+ // 保存订单明细
|
|
|
+ List<PjShipItems> shipItemsList = new ArrayList<>();
|
|
|
+ if (CollectionUtils.isNotEmpty(ship.getShipItemsList())) {
|
|
|
+ List<Long> goodIds = ship.getShipItemsList().stream().map(PjShipItems::getGoodsId).distinct().collect(Collectors.toList());
|
|
|
+ List<PjGoodsDesc> pjGoodsDescList = goodsDescMapper.selectList(new LambdaQueryWrapper<PjGoodsDesc>()
|
|
|
+ .eq(PjGoodsDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjGoodsDesc::getIsDeleted, 0)
|
|
|
+ .in(PjGoodsDesc::getId, goodIds));
|
|
|
+ //修改库存账
|
|
|
+ LambdaQueryWrapper<PjStockDesc> stockLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ stockLambdaQueryWrapper
|
|
|
+ .eq(PjStockDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjStockDesc::getIsDeleted, 0)
|
|
|
+ .eq(PjStockDesc::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
+ .in(PjStockDesc::getGoodsId, goodIds);
|
|
|
+ List<PjStockDesc> pjStockDescList = iStockDescService.list(stockLambdaQueryWrapper);
|
|
|
+ List<PjStockDesc> pjStockDescArrayList = new ArrayList<>();
|
|
|
+ List<PjStockDesc> pjStockDescArrayDelete = new ArrayList<>();
|
|
|
+ List<PjOrderItems> orderItemsList = orderItemsService.list(new LambdaQueryWrapper<PjOrderItems>()
|
|
|
+ .eq(PjOrderItems::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjOrderItems::getIsDeleted, 0)
|
|
|
+ .eq(PjOrderItems::getBsType, "PD")
|
|
|
+ .ne(PjOrderItems::getStatus, "已确认")
|
|
|
+ .in(PjOrderItems::getGoodsId, goodIds)
|
|
|
+ );
|
|
|
+ StringBuilder msg1 = new StringBuilder();
|
|
|
+ for (PjShipItems item : ship.getShipItemsList()) {
|
|
|
+ item.setSendNumHave(item.getSendNum());
|
|
|
+ item.setSendNum(new BigDecimal("0"));
|
|
|
+ //获得商品
|
|
|
+ PjGoodsDesc goodsDesc = pjGoodsDescList.stream().filter(e -> e.getId().equals(item.getGoodsId())).findFirst().orElse(null);
|
|
|
+ if (ObjectUtil.isEmpty(goodsDesc)) {
|
|
|
+ throw new RuntimeException("商品数据异常");
|
|
|
+ }
|
|
|
+ List<PjOrderItems> pjOrderItemsList1 = orderItemsList.stream().filter(e -> e.getGoodsId().equals(item.getGoodsId())).collect(Collectors.toList());
|
|
|
+ if (!pjOrderItemsList1.isEmpty()) {
|
|
|
+ msg1.append(item.getGoodsName()).append(",");
|
|
|
+ }
|
|
|
+ //管理批次号
|
|
|
+ PjStockDesc stockOne;
|
|
|
+ if (ObjectUtil.isNotEmpty(goodsDesc.getWhether()) && "1".equals(goodsDesc.getWhether())) {
|
|
|
+ stockOne = pjStockDescList.stream()
|
|
|
+ .filter(e -> e.getGoodsId().equals(item.getGoodsId())
|
|
|
+ && e.getStorageId().equals(ship.getStorageId())
|
|
|
+ && e.getDot().equals(item.getDot())).findFirst().orElse(null);
|
|
|
+ } else {
|
|
|
+ stockOne = pjStockDescList.stream()
|
|
|
+ .filter(e -> e.getGoodsId().equals(item.getGoodsId())
|
|
|
+ && e.getStorageId().equals(ship.getStorageId())
|
|
|
+ && ObjectUtils.isNull(e.getDot())).findFirst().orElse(null);
|
|
|
+ }
|
|
|
+ if (stockOne != null) {
|
|
|
+ if (stockOne.getBalanceQuantity().compareTo(item.getSendNum()) < 0) {
|
|
|
+ throw new RuntimeException(goodsDesc.getCname() + "库存不足,禁止撤销");
|
|
|
+ }
|
|
|
+ stockOne.setUpdateTime(new Date());
|
|
|
+ stockOne.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ stockOne.setBalanceQuantity(stockOne.getBalanceQuantity().subtract(item.getSendNum()));
|
|
|
+ if (stockOne.getBalanceQuantityHave().compareTo(item.getSendNum()) < 0) {
|
|
|
+ throw new RuntimeException("库存不足");
|
|
|
+ }
|
|
|
+ stockOne.setBalanceQuantityHave(stockOne.getBalanceQuantityHave().subtract(item.getSendNum()));
|
|
|
+ stockOne.setStoreInventory(stockOne.getBalanceQuantity());
|
|
|
+ BigDecimal inventoryAmount = item.getSendNum().multiply(item.getPrice());
|
|
|
+ stockOne.setInventoryAmount(stockOne.getInventoryAmount().subtract(inventoryAmount));
|
|
|
+ if (new BigDecimal("0.00").compareTo(stockOne.getInventoryAmount()) == 0 || new BigDecimal("0.00").compareTo(stockOne.getBalanceQuantity()) == 0) {
|
|
|
+ stockOne.setInventoryCostPrice(new BigDecimal("0.00"));
|
|
|
+ } else {
|
|
|
+ stockOne.setInventoryCostPrice(stockOne.getInventoryAmount().divide(stockOne.getBalanceQuantity(), MathContext.DECIMAL32).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ }
|
|
|
+ stockOne.setVersion(stockOne.getVersion());
|
|
|
+ if (new BigDecimal("0.00").compareTo(stockOne.getBalanceQuantity()) == 0
|
|
|
+ && new BigDecimal("0.00").compareTo(stockOne.getBalanceQuantityHave()) == 0
|
|
|
+ && 1 == stockOne.getVersion()) {
|
|
|
+ pjStockDescArrayDelete.add(stockOne);
|
|
|
+ } else {
|
|
|
+ pjStockDescArrayList.add(stockOne);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("未查到库存数据");
|
|
|
+ }
|
|
|
+ shipItemsList.add(item);
|
|
|
+ }
|
|
|
+ if (msg1.length() > 0) {
|
|
|
+ throw new RuntimeException("商品:" + msg1 + "正在盘点中,操作失败");
|
|
|
+ }
|
|
|
+ shipItemsService.saveOrUpdateBatch(shipItemsList);
|
|
|
+ if (!pjStockDescArrayList.isEmpty()) {
|
|
|
+ iStockDescService.updateBatchByIdNew(pjStockDescArrayList);
|
|
|
+ }
|
|
|
+ if (!pjStockDescArrayDelete.isEmpty()) {
|
|
|
+ iStockDescService.removeByIds(pjStockDescArrayDelete.stream().map(PjStockDesc::getId).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ List<PjProductLaunch> pjProductLaunchList = new ArrayList<>();
|
|
|
+ //查询所有上架商品
|
|
|
+ LambdaQueryWrapper<PjProductLaunch> productLaunchQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ productLaunchQueryWrapper.eq(PjProductLaunch::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjProductLaunch::getIsDeleted, 0)
|
|
|
+ .isNull(PjProductLaunch::getSourceId)
|
|
|
+ .eq(PjProductLaunch::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
+ .in(PjProductLaunch::getGoodsId, goodIds);
|
|
|
+ List<PjProductLaunch> productLaunch = productLaunchService.list(productLaunchQueryWrapper);
|
|
|
+ for (PjShipItems item : ship.getShipItemsList()) {
|
|
|
+ PjProductLaunch pjProductLaunches = productLaunch.stream()
|
|
|
+ .filter(i -> i.getGoodsId().equals(item.getGoodsId())).findFirst().orElse(null);
|
|
|
+ //修改上架数量
|
|
|
+ if (pjProductLaunches != null) {
|
|
|
+ pjProductLaunches.setInventory(pjProductLaunches.getInventory().subtract(item.getSendNumHave()));
|
|
|
+ pjProductLaunchList.add(pjProductLaunches);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ R res = productLaunchService.updateBatchById(pjProductLaunchList);
|
|
|
+ if (!res.isSuccess()) {
|
|
|
+ throw new RuntimeException(res.getMsg());
|
|
|
+ }
|
|
|
+ ship.setShipItemsList(ship.getShipItemsList());
|
|
|
+ ship.setNumberRows(ship.getShipItemsList().size());
|
|
|
+ }
|
|
|
+ ship.setStatusName(OrderTypeEnum.PRODUCTION_IN.getType());
|
|
|
+ baseMapper.updateById(ship);
|
|
|
+ return R.data(ship);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R confirmPicking(PjShip ship) {
|
|
|
+ ship.setStatusName(OrderTypeEnum.STOP_PICKING.getType());
|
|
|
+ if (ObjectUtils.isNull(ship.getStorageId())) {
|
|
|
+ throw new RuntimeException("请先选择仓库");
|
|
|
+ }
|
|
|
+ ship.setGoodsTotalNum(ship.getShipItemsList().stream().map(PjShipItems::getGoodsNum).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ if (ship.getId() == null) {
|
|
|
+ // 获取系统编号
|
|
|
+ String billNo = serialService.getBillNo(OrderTypeEnum.FHGD.getType(), OrderTypeEnum.FHGD.getType(), OrderTypeEnum.FHGD.getType());
|
|
|
+ if (ObjectUtils.isNull(billNo)) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return R.fail(500, "生成系统编号失败");
|
|
|
+ }
|
|
|
+ ship.setBillno(billNo);
|
|
|
+ ship.setCreateTime(new Date());
|
|
|
+ ship.setCreateUser(AuthUtil.getUserId());
|
|
|
+ ship.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ ship.setTenantId(AuthUtil.getTenantId());
|
|
|
+ baseMapper.insert(ship);
|
|
|
+ } else {
|
|
|
+ ship.setVersion(ship.getVersion() + 1);
|
|
|
+ ship.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ ship.setUpdateTime(new Date());
|
|
|
+ ship.setStorageName(storageDescMapper.selectById(ship.getStorageId()).getCname());
|
|
|
+ baseMapper.updateById(ship);
|
|
|
+ }
|
|
|
+ // 保存订单明细
|
|
|
+ List<PjShipItems> shipItemsList = new ArrayList<>();
|
|
|
+ List<PjStockDesc> pjStockDescArrayList = new ArrayList<>();
|
|
|
+ if (CollectionUtils.isNotEmpty(ship.getShipItemsList())) {
|
|
|
+ List<Long> goodIds = ship.getShipItemsList().stream().map(PjShipItems::getGoodsId).distinct().collect(Collectors.toList());
|
|
|
+ List<PjGoodsDesc> pjGoodsDescList = goodsDescMapper.selectList(new LambdaQueryWrapper<PjGoodsDesc>()
|
|
|
+ .eq(PjGoodsDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjGoodsDesc::getIsDeleted, 0)
|
|
|
+ .in(PjGoodsDesc::getId, goodIds));
|
|
|
+ //修改库存账
|
|
|
+ LambdaQueryWrapper<PjStockDesc> stockLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ stockLambdaQueryWrapper
|
|
|
+ .eq(PjStockDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjStockDesc::getIsDeleted, 0)
|
|
|
+ .eq(PjStockDesc::getStorageId, ship.getStorageId())
|
|
|
+ .eq(PjStockDesc::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
+ .in(PjStockDesc::getGoodsId, goodIds);
|
|
|
+ List<PjStockDesc> pjStockDescList = iStockDescService.list(stockLambdaQueryWrapper);
|
|
|
+ String msg = "";
|
|
|
+ List<PjOrderItems> orderItemsList = orderItemsService.list(new LambdaQueryWrapper<PjOrderItems>()
|
|
|
+ .eq(PjOrderItems::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjOrderItems::getIsDeleted, 0)
|
|
|
+ .eq(PjOrderItems::getBsType, "PD")
|
|
|
+ .ne(PjOrderItems::getStatus, "已确认")
|
|
|
+ .in(PjOrderItems::getGoodsId, goodIds)
|
|
|
+ );
|
|
|
+ StringBuilder msg1 = new StringBuilder();
|
|
|
+ for (PjShipItems item : ship.getShipItemsList()) {
|
|
|
+ item.setSendNum(item.getGoodsNum());
|
|
|
+ if (item.getId() == null) {
|
|
|
+ item.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ item.setCreateTime(new Date());
|
|
|
+ item.setCreateUser(AuthUtil.getUserId());
|
|
|
+ item.setPid(ship.getId());
|
|
|
+ item.setTenantId(AuthUtil.getTenantId());
|
|
|
+ } else {
|
|
|
+ item.setUpdateTime(new Date());
|
|
|
+ item.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ item.setPid(ship.getId());
|
|
|
+ }
|
|
|
+ //获得商品
|
|
|
+ List<PjOrderItems> pjOrderItemsList1 = orderItemsList.stream().filter(e -> e.getGoodsId().equals(item.getGoodsId())).collect(Collectors.toList());
|
|
|
+ if (!pjOrderItemsList1.isEmpty()) {
|
|
|
+ msg1.append(item.getGoodsName()).append(",");
|
|
|
+ }
|
|
|
+ PjGoodsDesc goodsDesc = pjGoodsDescList.stream().filter(e -> e.getId().equals(item.getGoodsId())).findFirst().orElse(null);
|
|
|
+ if (ObjectUtil.isEmpty(goodsDesc)) {
|
|
|
+ throw new RuntimeException("商品数据异常");
|
|
|
+ }
|
|
|
+ if ("1".equals(goodsDesc.getWhether()) && ObjectUtils.isNull(item.getDot())) {
|
|
|
+ throw new RuntimeException("商品:" + goodsDesc.getCname() + ",请选择批次号");
|
|
|
+ }
|
|
|
+ //管理批次号
|
|
|
+ PjStockDesc stockOne = null;
|
|
|
+ if (ObjectUtil.isNotEmpty(goodsDesc.getWhether()) && "1".equals(goodsDesc.getWhether())) {
|
|
|
+ stockOne = pjStockDescList.stream()
|
|
|
+ .filter(e -> e.getGoodsId().equals(item.getGoodsId())
|
|
|
+ && e.getDot().equals(item.getDot())).findFirst().orElse(null);
|
|
|
+ } else {
|
|
|
+ stockOne = pjStockDescList.stream()
|
|
|
+ .filter(e -> e.getGoodsId().equals(item.getGoodsId())
|
|
|
+ && ObjectUtils.isNull(e.getDot())).findFirst().orElse(null);
|
|
|
+ }
|
|
|
+ if (stockOne != null) {
|
|
|
+ if (stockOne.getBalanceQuantity().compareTo(item.getSendNum()) < 0) {
|
|
|
+ msg += goodsDesc.getCname() + ",";
|
|
|
+ } else {
|
|
|
+ stockOne.setBalanceQuantity(stockOne.getBalanceQuantity().subtract(item.getSendNum()));
|
|
|
+ if (stockOne.getBalanceQuantityHave().compareTo(item.getSendNum()) < 0) {
|
|
|
+ throw new RuntimeException("商品:" + goodsDesc.getCname() + "库存不足,出库失败");
|
|
|
+ }
|
|
|
+ stockOne.setBalanceQuantityHave(stockOne.getBalanceQuantityHave().subtract(item.getSendNum()));
|
|
|
+ item.setSendNumHave(item.getSendNum());
|
|
|
+ }
|
|
|
+ stockOne.setStoreInventory(stockOne.getBalanceQuantity());
|
|
|
+ BigDecimal inventoryAmount = item.getSendNum().multiply(stockOne.getInventoryCostPrice());
|
|
|
+ stockOne.setInventoryAmount(stockOne.getInventoryAmount().subtract(inventoryAmount));
|
|
|
+ stockOne.setVersion(stockOne.getVersion());
|
|
|
+ pjStockDescArrayList.add(stockOne);
|
|
|
+ item.setCostprie(item.getSendNum().multiply(stockOne.getInventoryCostPrice()));
|
|
|
+ item.setCostpriePrice(stockOne.getInventoryCostPrice());
|
|
|
+ item.setProfit(item.getSubTotalMoney().subtract(item.getCostprie()));
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("商品:" + goodsDesc.getCname() + "未查到库存账");
|
|
|
+ }
|
|
|
+ shipItemsList.add(item);
|
|
|
+ }
|
|
|
+ if (!msg.isEmpty()) {
|
|
|
+ throw new RuntimeException("商品:" + msg + "库存不足,出库失败");
|
|
|
+ }
|
|
|
+ if (msg1.length() > 0) {
|
|
|
+ throw new RuntimeException("商品:" + msg1 + "正在盘点中,操作失败");
|
|
|
+ }
|
|
|
+ R res = iStockDescService.updateBatchByIdNew(pjStockDescArrayList);
|
|
|
+ if (!res.isSuccess()) {
|
|
|
+ throw new RuntimeException(res.getMsg());
|
|
|
+ }
|
|
|
+ List<PjProductLaunch> pjProductLaunchList = new ArrayList<>();
|
|
|
+ //查询所有上架商品
|
|
|
+ LambdaQueryWrapper<PjProductLaunch> productLaunchQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ productLaunchQueryWrapper.eq(PjProductLaunch::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjProductLaunch::getIsDeleted, 0)
|
|
|
+ .isNull(PjProductLaunch::getSourceId)
|
|
|
+ .eq(PjProductLaunch::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
+ .in(PjProductLaunch::getGoodsId, goodIds);
|
|
|
+ List<PjProductLaunch> productLaunch = productLaunchService.list(productLaunchQueryWrapper);
|
|
|
+ for (PjShipItems item : ship.getShipItemsList()) {
|
|
|
+ PjProductLaunch pjProductLaunches = productLaunch.stream()
|
|
|
+ .filter(i -> i.getGoodsId().equals(item.getGoodsId())).findFirst().orElse(null);
|
|
|
+ //修改上架数量
|
|
|
+ if (pjProductLaunches != null) {
|
|
|
+ pjProductLaunches.setInventory(pjProductLaunches.getInventory().subtract(item.getSendNumHave()));
|
|
|
+ pjProductLaunchList.add(pjProductLaunches);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ R res1 = productLaunchService.updateBatchById(pjProductLaunchList);
|
|
|
+ if (!res1.isSuccess()) {
|
|
|
+ throw new RuntimeException(res.getMsg());
|
|
|
+ }
|
|
|
+ ship.setShipItemsList(ship.getShipItemsList());
|
|
|
+ ship.setNumberRows(ship.getShipItemsList().size());
|
|
|
+ ship.setSendTotalNum(ship.getShipItemsList().stream().map(PjShipItems::getSendNum).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("出库明细不能为空");
|
|
|
+ }
|
|
|
+ shipItemsService.saveOrUpdateBatch(shipItemsList);
|
|
|
+ return R.data(ship);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R revokePicking(PjShip ship) {
|
|
|
+ ship.setStatusName(OrderTypeEnum.STAY_PICKING.getType());
|
|
|
+ ship.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ ship.setUpdateTime(new Date());
|
|
|
+ PjShip shipVersion = baseMapper.selectById(ship.getId());
|
|
|
+ if (shipVersion != null && !shipVersion.getVersion().equals(ship.getVersion())) {
|
|
|
+ throw new RuntimeException("数据已被修改,请返回列表重新操作!");
|
|
|
+ }
|
|
|
+ baseMapper.updateById(ship);
|
|
|
+ // 保存订单明细
|
|
|
+ List<PjShipItems> itemsList = new ArrayList<>();
|
|
|
+ List<PjStockDesc> pjStockDescArrayList = new ArrayList<>();
|
|
|
+ if (CollectionUtils.isNotEmpty(ship.getShipItemsList())) {
|
|
|
+ List<Long> goodIds = ship.getShipItemsList().stream().map(PjShipItems::getGoodsId).distinct().collect(Collectors.toList());
|
|
|
+ List<PjGoodsDesc> pjGoodsDescList = goodsDescMapper.selectList(new LambdaQueryWrapper<PjGoodsDesc>()
|
|
|
+ .eq(PjGoodsDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjGoodsDesc::getIsDeleted, 0)
|
|
|
+ .in(PjGoodsDesc::getId, goodIds));
|
|
|
+ //修改库存账
|
|
|
+ LambdaQueryWrapper<PjStockDesc> stockLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ stockLambdaQueryWrapper
|
|
|
+ .eq(PjStockDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjStockDesc::getIsDeleted, 0)
|
|
|
+ .eq(PjStockDesc::getStorageId, ship.getStorageId())
|
|
|
+ .eq(PjStockDesc::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
+ .in(PjStockDesc::getGoodsId, goodIds);
|
|
|
+ List<PjStockDesc> pjStockDescList = iStockDescService.list(stockLambdaQueryWrapper);
|
|
|
+ List<PjOrderItems> orderItemsList = orderItemsService.list(new LambdaQueryWrapper<PjOrderItems>()
|
|
|
+ .eq(PjOrderItems::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjOrderItems::getIsDeleted, 0)
|
|
|
+ .eq(PjOrderItems::getBsType, "PD")
|
|
|
+ .ne(PjOrderItems::getStatus, "已确认")
|
|
|
+ .in(PjOrderItems::getGoodsId, goodIds)
|
|
|
+ );
|
|
|
+ StringBuilder msg1 = new StringBuilder();
|
|
|
+ for (PjShipItems item : ship.getShipItemsList()) {
|
|
|
+ item.setSendNumHave(item.getSendNum());
|
|
|
+ item.setSendNum(new BigDecimal("0"));
|
|
|
+ //获得商品
|
|
|
+ PjGoodsDesc goodsDesc = pjGoodsDescList.stream().filter(e -> e.getId().equals(item.getGoodsId())).findFirst().orElse(null);
|
|
|
+ if (ObjectUtil.isEmpty(goodsDesc)) {
|
|
|
+ throw new RuntimeException("商品数据异常");
|
|
|
+ }
|
|
|
+ List<PjOrderItems> pjOrderItemsList1 = orderItemsList.stream().filter(e -> e.getGoodsId().equals(item.getGoodsId())).collect(Collectors.toList());
|
|
|
+ if (!pjOrderItemsList1.isEmpty()) {
|
|
|
+ msg1.append(item.getGoodsName()).append(",");
|
|
|
+ }
|
|
|
+ //管理批次号
|
|
|
+ PjStockDesc stockOne;
|
|
|
+ if (ObjectUtil.isNotEmpty(goodsDesc.getWhether()) && "1".equals(goodsDesc.getWhether())) {
|
|
|
+ stockOne = pjStockDescList.stream()
|
|
|
+ .filter(e -> e.getGoodsId().equals(item.getGoodsId())
|
|
|
+ && e.getDot().equals(item.getDot())).findFirst().orElse(null);
|
|
|
+ } else {
|
|
|
+ stockOne = pjStockDescList.stream()
|
|
|
+ .filter(e -> e.getGoodsId().equals(item.getGoodsId())
|
|
|
+ && ObjectUtils.isNull(e.getDot())).findFirst().orElse(null);
|
|
|
+ }
|
|
|
+ if (stockOne != null) {
|
|
|
+ stockOne.setBalanceQuantity(stockOne.getBalanceQuantity().add(item.getSendNum()));
|
|
|
+ stockOne.setBalanceQuantityHave(stockOne.getBalanceQuantityHave().add(item.getSendNumHave()));
|
|
|
+ stockOne.setStoreInventory(stockOne.getBalanceQuantity());
|
|
|
+ BigDecimal inventoryAmount = item.getSendNum().multiply(stockOne.getInventoryCostPrice());
|
|
|
+ stockOne.setInventoryAmount(stockOne.getInventoryAmount().add(inventoryAmount));
|
|
|
+ stockOne.setVersion(stockOne.getVersion());
|
|
|
+ pjStockDescArrayList.add(stockOne);
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("未查到库存账");
|
|
|
+ }
|
|
|
+ itemsList.add(item);
|
|
|
+ }
|
|
|
+ if (msg1.length() > 0) {
|
|
|
+ throw new RuntimeException("商品:" + msg1 + "正在盘点中,操作失败");
|
|
|
+ }
|
|
|
+ R res = iStockDescService.updateBatchByIdNew(pjStockDescArrayList);
|
|
|
+ if (!res.isSuccess()) {
|
|
|
+ throw new RuntimeException(res.getMsg());
|
|
|
+ }
|
|
|
+ shipItemsService.updateBatchById(itemsList);
|
|
|
+ //查询所有上架商品
|
|
|
+ LambdaQueryWrapper<PjProductLaunch> productLaunchQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ productLaunchQueryWrapper.eq(PjProductLaunch::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjProductLaunch::getIsDeleted, 0)
|
|
|
+ .isNull(PjProductLaunch::getSourceId)
|
|
|
+ .eq(PjProductLaunch::getSalesCompanyId, ship.getSalesCompanyId())
|
|
|
+ .in(PjProductLaunch::getGoodsId, goodIds);
|
|
|
+ List<PjProductLaunch> productLaunch = productLaunchService.list(productLaunchQueryWrapper);
|
|
|
+ List<PjProductLaunch> pjProductLaunchList = new ArrayList<>();
|
|
|
+ for (PjShipItems item : ship.getShipItemsList()) {
|
|
|
+ //获得商品
|
|
|
+ PjGoodsDesc goodsDesc = pjGoodsDescList.stream().filter(e -> e.getId().equals(item.getGoodsId())).findFirst().orElse(null);
|
|
|
+ if (ObjectUtil.isEmpty(goodsDesc)) {
|
|
|
+ throw new RuntimeException("商品数据异常");
|
|
|
+ }
|
|
|
+ PjProductLaunch pjProductLaunches = productLaunch.stream()
|
|
|
+ .filter(i -> i.getGoodsId().equals(goodsDesc.getId())).findFirst().orElse(null);
|
|
|
+ //修改上架数量
|
|
|
+ if (pjProductLaunches != null) {
|
|
|
+ if (ObjectUtils.isNotNull(pjProductLaunches.getInventory())) {
|
|
|
+ pjProductLaunches.setInventory(pjProductLaunches.getInventory().add(item.getSendNumHave()));
|
|
|
+ } else {
|
|
|
+ pjProductLaunches.setInventory(item.getSendNumHave());
|
|
|
+ }
|
|
|
+ pjProductLaunchList.add(pjProductLaunches);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ R res1 = productLaunchService.updateBatchById(pjProductLaunchList);
|
|
|
+ if (!res1.isSuccess()) {
|
|
|
+ throw new RuntimeException(res1.getMsg());
|
|
|
+ }
|
|
|
+ ship.setShipItemsList(ship.getShipItemsList());
|
|
|
+ ship.setNumberRows(ship.getShipItemsList().size());
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("出库明细不能为空");
|
|
|
+ }
|
|
|
+ return R.data(ship);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R generatePicking(PjShip ship) {
|
|
|
+ PjShip picking = new PjShip();
|
|
|
+ PjShip detail = baseMapper.selectById(ship.getId());
|
|
|
+ BeanUtil.copyProperties(detail, picking);
|
|
|
+ //明细
|
|
|
+ LambdaQueryWrapper<PjShipItems> itemsLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ itemsLambdaQueryWrapper.eq(PjShipItems::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjShipItems::getIsDeleted, 0)
|
|
|
+ .eq(PjShipItems::getPid, detail.getId());
|
|
|
+ List<PjShipItems> shipItemsList = shipItemsService.list(itemsLambdaQueryWrapper);
|
|
|
+ picking.setSalesCompanyId(detail.getSalesCompanyId());
|
|
|
+ picking.setSalesCompanyName(detail.getSalesCompanyName());
|
|
|
+ // 获取系统编号
|
|
|
+ String billNo = serialService.getBillNo(OrderTypeEnum.SCLL.getType(), OrderTypeEnum.SCLL.getType(), OrderTypeEnum.SCLL.getType());
|
|
|
+ if (ObjectUtils.isNull(billNo)) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return R.fail(500, "生成系统编号失败");
|
|
|
+ }
|
|
|
+ picking.setStatusName(OrderTypeEnum.STAY_PICKING.getType());
|
|
|
+ picking.setId(null);
|
|
|
+ picking.setBillno(billNo);
|
|
|
+ picking.setBizTypeName(OrderTypeEnum.SCLL.getType());
|
|
|
+ picking.setSrcOrdNo(detail.getOrdNo());
|
|
|
+ picking.setCreateTime(new Date());
|
|
|
+ picking.setCreateUser(AuthUtil.getUserId());
|
|
|
+ picking.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ picking.setTenantId(AuthUtil.getTenantId());
|
|
|
+ picking.setUpdateTime(null);
|
|
|
+ picking.setUpdateUser(null);
|
|
|
+ baseMapper.insert(picking);
|
|
|
+ // 保存订单明细
|
|
|
+ List<PjShipItems> shipItemsListNew = new ArrayList<>();
|
|
|
+ if (CollectionUtils.isNotEmpty(shipItemsList)) {
|
|
|
+ shipItemsList.forEach(item -> {
|
|
|
+ item.setId(null);
|
|
|
+ item.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ item.setCreateTime(new Date());
|
|
|
+ item.setCreateUser(AuthUtil.getUserId());
|
|
|
+ item.setPid(picking.getId());
|
|
|
+ item.setTenantId(AuthUtil.getTenantId());
|
|
|
+ item.setUpdateTime(null);
|
|
|
+ item.setUpdateUser(null);
|
|
|
+ shipItemsListNew.add(item);
|
|
|
+ });
|
|
|
+ shipItemsService.saveOrUpdateBatch(shipItemsListNew);
|
|
|
+ }
|
|
|
+ picking.setShipItemsList(shipItemsListNew);
|
|
|
+ return R.data(picking);
|
|
|
}
|
|
|
|
|
|
}
|