|
|
|
@ -3,11 +3,13 @@ package com.glxp.sale.admin.service.inout.impl;
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
|
import com.glxp.sale.admin.constant.ConstantStatus;
|
|
|
|
|
import com.glxp.sale.admin.constant.ConstantType;
|
|
|
|
|
import com.glxp.sale.admin.dao.inout.*;
|
|
|
|
|
import com.glxp.sale.admin.dao.inventory.InvProductDao;
|
|
|
|
|
import com.glxp.sale.admin.dao.inventory.InvProductDetailDao;
|
|
|
|
|
import com.glxp.sale.admin.entity.inout.FilterErpOrderRequest;
|
|
|
|
|
import com.glxp.sale.admin.entity.inout.OrderEntity;
|
|
|
|
|
import com.glxp.sale.admin.entity.inout.WarehouseEntity;
|
|
|
|
|
import com.glxp.sale.admin.entity.inventory.InvProductDetailEntity;
|
|
|
|
|
import com.glxp.sale.admin.entity.inventory.InvProductEntity;
|
|
|
|
@ -17,10 +19,12 @@ import com.glxp.sale.admin.req.inout.WarehouseQueryRequest;
|
|
|
|
|
import com.glxp.sale.admin.req.inventory.FilterInvProductDetailRequest;
|
|
|
|
|
import com.glxp.sale.admin.req.inventory.FilterInvProductRequest;
|
|
|
|
|
import com.glxp.sale.admin.service.inout.CodesService;
|
|
|
|
|
import com.glxp.sale.admin.service.inout.OrderService;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
@ -41,6 +45,8 @@ public class CodesServiceImpl implements CodesService {
|
|
|
|
|
private OrderDao orderDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private StockOrderDao stockOrderDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private OrderService orderService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<WarehouseEntity> listWarehouse(WarehouseQueryRequest warehouseQueryRequest) {
|
|
|
|
@ -158,75 +164,89 @@ public class CodesServiceImpl implements CodesService {
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
@Override
|
|
|
|
|
public void replaceCodes(CodesReplaceRequest codesReplaceRequest) {
|
|
|
|
|
List<WarehouseEntity> codeList = codesDao.findByCode(codesReplaceRequest.getCode());
|
|
|
|
|
|
|
|
|
|
//删除码表,添加新的条码,并更新库存
|
|
|
|
|
for (WarehouseEntity warehouseEntity : codeList) {
|
|
|
|
|
//删除码详情
|
|
|
|
|
codesDao.deleteByOrderIdAndCode(warehouseEntity.getOrderId(), warehouseEntity.getCode());
|
|
|
|
|
|
|
|
|
|
//查询库存详情
|
|
|
|
|
FilterInvProductDetailRequest filterInvProductDetailRequest = new FilterInvProductDetailRequest();
|
|
|
|
|
filterInvProductDetailRequest.setOriginCode(codesReplaceRequest.getCode());
|
|
|
|
|
filterInvProductDetailRequest.setProductIdFk(warehouseEntity.getRelId());
|
|
|
|
|
filterInvProductDetailRequest.setOrderIdFk(warehouseEntity.getOrderId());
|
|
|
|
|
if (StrUtil.isNotBlank(warehouseEntity.getBatchNo())) {
|
|
|
|
|
filterInvProductDetailRequest.setBatchNo(warehouseEntity.getBatchNo());
|
|
|
|
|
} else {
|
|
|
|
|
filterInvProductDetailRequest.setBatchNo("empty");
|
|
|
|
|
}
|
|
|
|
|
List<InvProductDetailEntity> invProductDetailEntities = invProductDetailDao.filterInvProductDetail(filterInvProductDetailRequest);
|
|
|
|
|
if (CollUtil.isNotEmpty(invProductDetailEntities)) {
|
|
|
|
|
//库存详情不为空,单据已验收,更新库存
|
|
|
|
|
InvProductDetailEntity invProductDetailEntity = invProductDetailEntities.get(0); //库存
|
|
|
|
|
|
|
|
|
|
//删除库存详情
|
|
|
|
|
invProductDetailDao.deleteByOrderIdAndCode(warehouseEntity.getOrderId(), codesReplaceRequest.getCode());
|
|
|
|
|
//查询原库存详情和新的库存详情
|
|
|
|
|
FilterInvProductRequest filterInvProductRequest = new FilterInvProductRequest();
|
|
|
|
|
filterInvProductRequest.setRelIdFk(invProductDetailEntity.getProductIdFk());
|
|
|
|
|
if (StrUtil.isBlank(invProductDetailEntity.getBatchNo())) {
|
|
|
|
|
filterInvProductRequest.setBatchNo("empty");
|
|
|
|
|
} else {
|
|
|
|
|
filterInvProductRequest.setBatchNo(invProductDetailEntity.getBatchNo());
|
|
|
|
|
OrderEntity orderEntity = orderDao.selectByBillNo(codesReplaceRequest.getOrderId());
|
|
|
|
|
//查询所有单据
|
|
|
|
|
List<OrderEntity> orderList = new ArrayList<>();
|
|
|
|
|
orderList.add(orderEntity);
|
|
|
|
|
orderService.getAllOrder(orderEntity, orderList);
|
|
|
|
|
|
|
|
|
|
for (OrderEntity order : orderList) {
|
|
|
|
|
//查询条码
|
|
|
|
|
WarehouseQueryRequest warehouseQueryRequest = new WarehouseQueryRequest();
|
|
|
|
|
warehouseQueryRequest.setOrderId(order.getId());
|
|
|
|
|
warehouseQueryRequest.setCode(codesReplaceRequest.getCode());
|
|
|
|
|
List<WarehouseEntity> warehouseEntities = codesDao.findByOrderId(warehouseQueryRequest);
|
|
|
|
|
if (CollUtil.isNotEmpty(warehouseEntities)) {
|
|
|
|
|
for (WarehouseEntity warehouseEntity : warehouseEntities) {
|
|
|
|
|
//删除码详情
|
|
|
|
|
codesDao.deleteByOrderIdAndCode(warehouseEntity.getOrderId(), warehouseEntity.getCode());
|
|
|
|
|
|
|
|
|
|
if (order.getStatus().equals(ConstantStatus.ORDER_STATUS_PROCESS)) {
|
|
|
|
|
//查询库存详情
|
|
|
|
|
FilterInvProductDetailRequest filterInvProductDetailRequest = new FilterInvProductDetailRequest();
|
|
|
|
|
filterInvProductDetailRequest.setOriginCode(codesReplaceRequest.getCode());
|
|
|
|
|
filterInvProductDetailRequest.setProductIdFk(warehouseEntity.getRelId());
|
|
|
|
|
filterInvProductDetailRequest.setOrderIdFk(order.getId());
|
|
|
|
|
if (StrUtil.isNotBlank(warehouseEntity.getBatchNo())) {
|
|
|
|
|
filterInvProductDetailRequest.setBatchNo(warehouseEntity.getBatchNo());
|
|
|
|
|
} else {
|
|
|
|
|
filterInvProductDetailRequest.setBatchNo("empty");
|
|
|
|
|
}
|
|
|
|
|
List<InvProductDetailEntity> invProductDetailEntities = invProductDetailDao.filterInvProductDetail(filterInvProductDetailRequest);
|
|
|
|
|
if (CollUtil.isNotEmpty(invProductDetailEntities)) {
|
|
|
|
|
//库存详情不为空,单据已验收,更新库存
|
|
|
|
|
InvProductDetailEntity invProductDetailEntity = invProductDetailEntities.get(0); //库存
|
|
|
|
|
|
|
|
|
|
//删除库存详情
|
|
|
|
|
invProductDetailDao.deleteByOrderIdAndCode(warehouseEntity.getOrderId(), codesReplaceRequest.getCode());
|
|
|
|
|
//查询原库存详情和新的库存详情
|
|
|
|
|
FilterInvProductRequest filterInvProductRequest = new FilterInvProductRequest();
|
|
|
|
|
filterInvProductRequest.setRelIdFk(invProductDetailEntity.getProductIdFk());
|
|
|
|
|
if (StrUtil.isBlank(invProductDetailEntity.getBatchNo())) {
|
|
|
|
|
filterInvProductRequest.setBatchNo("empty");
|
|
|
|
|
} else {
|
|
|
|
|
filterInvProductRequest.setBatchNo(invProductDetailEntity.getBatchNo());
|
|
|
|
|
}
|
|
|
|
|
InvProductEntity invProductEntity = invProductDao.filterInvProduct(filterInvProductRequest).get(0);
|
|
|
|
|
|
|
|
|
|
if (invProductDetailEntity.getMainAction().equals(ConstantType.TYPE_OUT)) {
|
|
|
|
|
//出库
|
|
|
|
|
int count = invProductEntity.getOutCount() + invProductDetailEntity.getCount();
|
|
|
|
|
invProductEntity.setOutCount(count);
|
|
|
|
|
} else if (invProductDetailEntity.getMainAction().equals(ConstantType.TYPE_PUT)) {
|
|
|
|
|
//入库
|
|
|
|
|
int count = invProductEntity.getInCount() - invProductDetailEntity.getCount();
|
|
|
|
|
invProductEntity.setInCount(count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//更新库存
|
|
|
|
|
invProductDao.updateInvProduct(invProductEntity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//删除单据详情
|
|
|
|
|
FilterErpOrderRequest deleteOrderDetailParam = new FilterErpOrderRequest();
|
|
|
|
|
deleteOrderDetailParam.setOrderIdFk(order.getId());
|
|
|
|
|
deleteOrderDetailParam.setGoodsid(warehouseEntity.getRelId());
|
|
|
|
|
deleteOrderDetailParam.setBatchNo(warehouseEntity.getBatchNo());
|
|
|
|
|
orderDetailDao.deleteOrder(deleteOrderDetailParam); //删除扫码单据详情
|
|
|
|
|
|
|
|
|
|
StockOrderDetailFilterRequest deleteStockOrderDetailParam = new StockOrderDetailFilterRequest();
|
|
|
|
|
deleteStockOrderDetailParam.setProductId(warehouseEntity.getRelId());
|
|
|
|
|
deleteStockOrderDetailParam.setBatchNo(warehouseEntity.getBatchNo());
|
|
|
|
|
deleteStockOrderDetailParam.setOrderIdFk(order.getId());
|
|
|
|
|
stockOrderDetailDao.deleteStockOrderDetail(deleteStockOrderDetailParam); //删除业务单据详情
|
|
|
|
|
}
|
|
|
|
|
InvProductEntity invProductEntity = invProductDao.filterInvProduct(filterInvProductRequest).get(0);
|
|
|
|
|
|
|
|
|
|
if (invProductDetailEntity.getMainAction().equals(ConstantType.TYPE_OUT)) {
|
|
|
|
|
//出库
|
|
|
|
|
int count = invProductEntity.getOutCount() + invProductDetailEntity.getCount();
|
|
|
|
|
invProductEntity.setOutCount(count);
|
|
|
|
|
} else if (invProductDetailEntity.getMainAction().equals(ConstantType.TYPE_PUT)) {
|
|
|
|
|
//入库
|
|
|
|
|
int count = invProductEntity.getInCount() - invProductDetailEntity.getCount();
|
|
|
|
|
invProductEntity.setInCount(count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//更新库存
|
|
|
|
|
invProductDao.updateInvProduct(invProductEntity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//删除单据详情
|
|
|
|
|
FilterErpOrderRequest deleteOrderDetailParam = new FilterErpOrderRequest();
|
|
|
|
|
deleteOrderDetailParam.setOrderIdFk(warehouseEntity.getOrderId());
|
|
|
|
|
deleteOrderDetailParam.setGoodsid(warehouseEntity.getRelId());
|
|
|
|
|
deleteOrderDetailParam.setBatchNo(warehouseEntity.getBatchNo());
|
|
|
|
|
orderDetailDao.deleteOrder(deleteOrderDetailParam); //删除扫码单据详情
|
|
|
|
|
|
|
|
|
|
StockOrderDetailFilterRequest deleteStockOrderDetailParam = new StockOrderDetailFilterRequest();
|
|
|
|
|
deleteStockOrderDetailParam.setProductId(warehouseEntity.getRelId());
|
|
|
|
|
deleteStockOrderDetailParam.setBatchNo(warehouseEntity.getBatchNo());
|
|
|
|
|
deleteStockOrderDetailParam.setOrderIdFk(warehouseEntity.getOrderId());
|
|
|
|
|
stockOrderDetailDao.deleteStockOrderDetail(deleteStockOrderDetailParam); //删除业务单据详情
|
|
|
|
|
|
|
|
|
|
int orderDetailCount = orderDetailDao.countByOrderId(warehouseEntity.getOrderId());
|
|
|
|
|
if (orderDetailCount == 0) {
|
|
|
|
|
//当单据详情数量为0时,删除扫码单据和业务单据
|
|
|
|
|
orderDao.deleteById(warehouseEntity.getOrderId());
|
|
|
|
|
stockOrderDao.deleteByOrderIdFk(warehouseEntity.getOrderId());
|
|
|
|
|
int orderDetailCount = orderDetailDao.countByOrderId(order.getId());
|
|
|
|
|
if (orderDetailCount == 0) {
|
|
|
|
|
//当单据详情数量为0时,删除扫码单据和业务单据
|
|
|
|
|
orderDao.deleteById(order.getId());
|
|
|
|
|
stockOrderDao.deleteByOrderIdFk(order.getId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|