|
|
@ -8,9 +8,7 @@ import com.glxp.sale.admin.constant.ConstantType;
|
|
|
|
import com.glxp.sale.admin.dao.inout.*;
|
|
|
|
import com.glxp.sale.admin.dao.inout.*;
|
|
|
|
import com.glxp.sale.admin.dao.inventory.InvProductDao;
|
|
|
|
import com.glxp.sale.admin.dao.inventory.InvProductDao;
|
|
|
|
import com.glxp.sale.admin.dao.inventory.InvProductDetailDao;
|
|
|
|
import com.glxp.sale.admin.dao.inventory.InvProductDetailDao;
|
|
|
|
import com.glxp.sale.admin.entity.inout.FilterErpOrderRequest;
|
|
|
|
import com.glxp.sale.admin.entity.inout.*;
|
|
|
|
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.InvProductDetailEntity;
|
|
|
|
import com.glxp.sale.admin.entity.inventory.InvProductEntity;
|
|
|
|
import com.glxp.sale.admin.entity.inventory.InvProductEntity;
|
|
|
|
import com.glxp.sale.admin.req.inout.CodesReplaceRequest;
|
|
|
|
import com.glxp.sale.admin.req.inout.CodesReplaceRequest;
|
|
|
@ -177,89 +175,123 @@ public class CodesServiceImpl implements CodesService {
|
|
|
|
warehouseQueryRequest.setCode(codesReplaceRequest.getCode());
|
|
|
|
warehouseQueryRequest.setCode(codesReplaceRequest.getCode());
|
|
|
|
List<WarehouseEntity> warehouseEntities = codesDao.findByOrderId(warehouseQueryRequest);
|
|
|
|
List<WarehouseEntity> warehouseEntities = codesDao.findByOrderId(warehouseQueryRequest);
|
|
|
|
if (CollUtil.isNotEmpty(warehouseEntities)) {
|
|
|
|
if (CollUtil.isNotEmpty(warehouseEntities)) {
|
|
|
|
for (WarehouseEntity warehouseEntity : warehouseEntities) {
|
|
|
|
WarehouseEntity warehouseEntity = warehouseEntities.get(0);
|
|
|
|
//删除码详情
|
|
|
|
if (warehouseEntity.getCount() > 1) {
|
|
|
|
codesDao.deleteByOrderIdAndCode(warehouseEntity.getOrderId(), warehouseEntity.getCode());
|
|
|
|
//删除一个条码
|
|
|
|
|
|
|
|
warehouseEntity.setCount(warehouseEntity.getCount() - 1);
|
|
|
|
if (order.getStatus().equals(ConstantStatus.ORDER_STATUS_SUCCESS)) {
|
|
|
|
codesDao.updateCode(warehouseEntity); //更新码详情
|
|
|
|
//查询库存详情
|
|
|
|
} else {
|
|
|
|
FilterInvProductDetailRequest filterInvProductDetailRequest = new FilterInvProductDetailRequest();
|
|
|
|
//如果数量扣减之后为0,直接删除此条码
|
|
|
|
filterInvProductDetailRequest.setOriginCode(codesReplaceRequest.getCode());
|
|
|
|
codesDao.deleteById(warehouseEntity.getId());
|
|
|
|
filterInvProductDetailRequest.setProductIdFk(warehouseEntity.getRelId());
|
|
|
|
}
|
|
|
|
filterInvProductDetailRequest.setOrderIdFk(order.getId());
|
|
|
|
|
|
|
|
if (StrUtil.isNotBlank(warehouseEntity.getBatchNo())) {
|
|
|
|
//库存详情扣减1
|
|
|
|
filterInvProductDetailRequest.setBatchNo(warehouseEntity.getBatchNo());
|
|
|
|
if (order.getStatus().equals(ConstantStatus.ORDER_STATUS_SUCCESS)) {
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (invProductDetailEntity.getCount() > 1) {
|
|
|
|
|
|
|
|
invProductDetailEntity.setCount(invProductDetailEntity.getCount() - 1); //更新库存
|
|
|
|
|
|
|
|
invProductDetailDao.updateInvProductDetail(invProductDetailEntity);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//库存详情扣减之后等于0,删除库存详情
|
|
|
|
|
|
|
|
invProductDetailDao.deleteByOrderIdAndCode(order.getId(), warehouseEntity.getCode());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//查询原库存详情和新的库存详情
|
|
|
|
|
|
|
|
FilterInvProductRequest filterInvProductRequest = new FilterInvProductRequest();
|
|
|
|
|
|
|
|
filterInvProductRequest.setRelIdFk(invProductDetailEntity.getProductIdFk());
|
|
|
|
|
|
|
|
filterInvProductRequest.setSupId(invProductDetailEntity.getSupId());
|
|
|
|
|
|
|
|
filterInvProductRequest.setInvStorageCode(invProductDetailEntity.getInvStorageCode());
|
|
|
|
|
|
|
|
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_PUT)) {
|
|
|
|
|
|
|
|
//入库
|
|
|
|
|
|
|
|
invProductEntity.setInCount(invProductEntity.getInCount() - 1);
|
|
|
|
|
|
|
|
} else if (invProductDetailEntity.getMainAction().equals(ConstantType.TYPE_OUT)) {
|
|
|
|
|
|
|
|
//出库
|
|
|
|
|
|
|
|
invProductEntity.setOutCount(invProductEntity.getOutCount() - 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//查询库存码详情,如果库存码详情为空,则删除此库存
|
|
|
|
|
|
|
|
FilterInvProductDetailRequest detailParams = new FilterInvProductDetailRequest();
|
|
|
|
|
|
|
|
detailParams.setBatchNo(invProductEntity.getBatchNo());
|
|
|
|
|
|
|
|
detailParams.setInvCodes(Collections.singletonList(invProductEntity.getInvStorageCode()));
|
|
|
|
|
|
|
|
detailParams.setProductIdFk(invProductEntity.getRelIdFk());
|
|
|
|
|
|
|
|
int count = invProductDetailDao.statCount(detailParams);
|
|
|
|
|
|
|
|
if (count == 0) {
|
|
|
|
|
|
|
|
//如果库存码详情为空,则删除此库存
|
|
|
|
|
|
|
|
invProductDao.deleteById(String.valueOf(invProductEntity.getId()));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
filterInvProductDetailRequest.setBatchNo("empty");
|
|
|
|
//更新库存
|
|
|
|
|
|
|
|
invProductDao.updateInvProduct(invProductEntity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<InvProductDetailEntity> invProductDetailEntities = invProductDetailDao.filterInvProductDetail(filterInvProductDetailRequest);
|
|
|
|
|
|
|
|
if (CollUtil.isNotEmpty(invProductDetailEntities)) {
|
|
|
|
//查询扫码单据详情
|
|
|
|
//库存详情不为空,单据已验收,更新库存
|
|
|
|
FilterErpOrderRequest orderDetailRequest = new FilterErpOrderRequest();
|
|
|
|
InvProductDetailEntity invProductDetailEntity = invProductDetailEntities.get(0); //库存
|
|
|
|
orderDetailRequest.setOrderIdFk(order.getId());
|
|
|
|
|
|
|
|
orderDetailRequest.setGoodsid(warehouseEntity.getRelId());
|
|
|
|
//删除库存详情
|
|
|
|
orderDetailRequest.setBatchNo(warehouseEntity.getBatchNo());
|
|
|
|
invProductDetailDao.deleteByOrderIdAndCode(warehouseEntity.getOrderId(), codesReplaceRequest.getCode());
|
|
|
|
List<ErpOrderEntity> erpOrderEntities = orderDetailDao.filterErpOrder(orderDetailRequest);
|
|
|
|
//查询原库存详情和新的库存详情
|
|
|
|
if (CollUtil.isNotEmpty(erpOrderEntities)) {
|
|
|
|
FilterInvProductRequest filterInvProductRequest = new FilterInvProductRequest();
|
|
|
|
ErpOrderEntity erpOrderEntity = erpOrderEntities.get(0);
|
|
|
|
filterInvProductRequest.setRelIdFk(invProductDetailEntity.getProductIdFk());
|
|
|
|
if (erpOrderEntity.getReCount() > 1) {
|
|
|
|
filterInvProductRequest.setSupId(invProductDetailEntity.getSupId());
|
|
|
|
erpOrderEntity.setReCount(erpOrderEntity.getReCount() - 1); //应收数量 - 1
|
|
|
|
filterInvProductRequest.setInvStorageCode(invProductDetailEntity.getInvStorageCode());
|
|
|
|
erpOrderEntity.setCount(erpOrderEntity.getCount() - 1); //实际数量 - 1
|
|
|
|
if (StrUtil.isBlank(invProductDetailEntity.getBatchNo())) {
|
|
|
|
//更新扫码单据详情
|
|
|
|
filterInvProductRequest.setBatchNo("empty");
|
|
|
|
orderDetailDao.updateErpOrder(erpOrderEntity);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
filterInvProductRequest.setBatchNo(invProductDetailEntity.getBatchNo());
|
|
|
|
orderDetailDao.deleteByPrimiyId(String.valueOf(erpOrderEntity.getId()));
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//查询库存码详情,如果库存码详情为空,则删除此库存
|
|
|
|
//查询业务单据详情
|
|
|
|
FilterInvProductDetailRequest detailParams = new FilterInvProductDetailRequest();
|
|
|
|
StockOrderDetailFilterRequest stockOrderDetailFilterRequest = new StockOrderDetailFilterRequest();
|
|
|
|
detailParams.setBatchNo(invProductEntity.getBatchNo());
|
|
|
|
stockOrderDetailFilterRequest.setProductId(warehouseEntity.getRelId());
|
|
|
|
detailParams.setInvCodes(Collections.singletonList(invProductEntity.getInvStorageCode()));
|
|
|
|
stockOrderDetailFilterRequest.setBatchNo(warehouseEntity.getBatchNo());
|
|
|
|
detailParams.setProductIdFk(invProductEntity.getRelIdFk());
|
|
|
|
//查询业务单据数据ID
|
|
|
|
int count = invProductDetailDao.statCount(detailParams);
|
|
|
|
Integer stockOrderId = stockOrderDao.selectIdByOrderIdFk(order.getId());
|
|
|
|
if (count == 0) {
|
|
|
|
stockOrderDetailFilterRequest.setOrderIdFk(String.valueOf(stockOrderId));
|
|
|
|
//如果库存码详情为空,则删除此库存
|
|
|
|
List<StockOrderDetailEntity> stockOrderDetailEntities = stockOrderDetailDao.filterStockOrderDetail3(stockOrderDetailFilterRequest);
|
|
|
|
invProductDao.deleteById(String.valueOf(invProductEntity.getId()));
|
|
|
|
if (CollUtil.isNotEmpty(stockOrderDetailEntities)) {
|
|
|
|
|
|
|
|
StockOrderDetailEntity stockOrderDetailEntity = stockOrderDetailEntities.get(0);
|
|
|
|
|
|
|
|
if (Integer.parseInt(stockOrderDetailEntity.getReCount()) > 1) {
|
|
|
|
|
|
|
|
stockOrderDetailEntity.setReCount(String.valueOf(Integer.parseInt(stockOrderDetailEntity.getReCount()) - 1)); //实际数量 - 1
|
|
|
|
|
|
|
|
stockOrderDetailEntity.setSweepCount(String.valueOf(Integer.parseInt(stockOrderDetailEntity.getSweepCount()) - 1)); //扫码数量 -1
|
|
|
|
|
|
|
|
//更新业务单据详情
|
|
|
|
|
|
|
|
stockOrderDetailDao.updateById(stockOrderDetailEntity);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
//更新库存
|
|
|
|
//删除业务单据详情
|
|
|
|
invProductDao.updateInvProduct(invProductEntity);
|
|
|
|
stockOrderDetailDao.deleteById(stockOrderDetailEntity.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//删除单据详情
|
|
|
|
//若扫码单据详情已全部被删除,关联删除扫码单据和业务单据
|
|
|
|
FilterErpOrderRequest deleteOrderDetailParam = new FilterErpOrderRequest();
|
|
|
|
int orderDetailCount = orderDetailDao.countByOrderId(order.getId());
|
|
|
|
deleteOrderDetailParam.setOrderIdFk(order.getId());
|
|
|
|
if (orderDetailCount == 0) {
|
|
|
|
deleteOrderDetailParam.setGoodsid(warehouseEntity.getRelId());
|
|
|
|
//当单据详情数量为0时,删除扫码单据和业务单据
|
|
|
|
deleteOrderDetailParam.setBatchNo(warehouseEntity.getBatchNo());
|
|
|
|
orderDao.deleteById(order.getId());
|
|
|
|
orderDetailDao.deleteOrder(deleteOrderDetailParam); //删除扫码单据详情
|
|
|
|
stockOrderDao.deleteByOrderIdFk(order.getId());
|
|
|
|
|
|
|
|
}
|
|
|
|
StockOrderDetailFilterRequest deleteStockOrderDetailParam = new StockOrderDetailFilterRequest();
|
|
|
|
}
|
|
|
|
deleteStockOrderDetailParam.setProductId(warehouseEntity.getRelId());
|
|
|
|
|
|
|
|
deleteStockOrderDetailParam.setBatchNo(warehouseEntity.getBatchNo());
|
|
|
|
|
|
|
|
deleteStockOrderDetailParam.setOrderIdFk(order.getId());
|
|
|
|
|
|
|
|
stockOrderDetailDao.deleteStockOrderDetail(deleteStockOrderDetailParam); //删除业务单据详情
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int orderDetailCount = orderDetailDao.countByOrderId(order.getId());
|
|
|
|
|
|
|
|
if (orderDetailCount == 0) {
|
|
|
|
|
|
|
|
//当单据详情数量为0时,删除扫码单据和业务单据
|
|
|
|
|
|
|
|
orderDao.deleteById(order.getId());
|
|
|
|
|
|
|
|
stockOrderDao.deleteByOrderIdFk(order.getId());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|