|
|
@@ -29,6 +29,7 @@ import org.springblade.core.secure.utils.SecureUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.deliver.goods.entity.Delivery;
|
|
|
import org.springblade.deliver.goods.entity.DeliveryItems;
|
|
|
+import org.springblade.deliver.goods.enums.DeliveryEnum;
|
|
|
import org.springblade.deliver.goods.vo.DeliveryItemsVO;
|
|
|
import org.springblade.deliver.goods.mapper.DeliveryItemsMapper;
|
|
|
import org.springblade.deliver.goods.service.IDeliveryItemsService;
|
|
|
@@ -114,9 +115,10 @@ public class DeliveryItemsServiceImpl extends ServiceImpl<DeliveryItemsMapper, D
|
|
|
* 提交发货信息
|
|
|
* @param pId
|
|
|
* @param deliveryItemsList
|
|
|
+ * @param type 操作类型 发货 1 撤销发货 2
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<DeliveryItems> affirmDeliveryItemsList(Long pId,Delivery delivery,List<DeliveryItems> deliveryItemsList){
|
|
|
+ public List<DeliveryItems> affirmDeliveryItemsList(Long pId,Delivery delivery,List<DeliveryItems> deliveryItemsList,int type){
|
|
|
for (DeliveryItems deliveryItems : deliveryItemsList) {
|
|
|
deliveryItems.setPid(pId);//父级ID
|
|
|
deliveryItems.setTenantId(SecureUtil.getTenantId());//租户id
|
|
|
@@ -130,15 +132,17 @@ public class DeliveryItemsServiceImpl extends ServiceImpl<DeliveryItemsMapper, D
|
|
|
baseMapper.updateById(deliveryItems);
|
|
|
}
|
|
|
StockGoodsVO stock = this.getStock(delivery.getTradeType(), delivery.getCorpId(), delivery.getStorageId(), deliveryItems);
|
|
|
- if (stock != null){
|
|
|
+ if (stock != null && delivery.getDeliveryType() == DeliveryEnum.DELIVER.getType()){//发货
|
|
|
//更新库存账
|
|
|
this.deliverGoods(delivery.getTradeType(),stock.getId(),deliveryItems);
|
|
|
+ }else if (stock != null && delivery.getDeliveryType() == DeliveryEnum.REPEAL.getType()){ //撤销发货
|
|
|
+
|
|
|
}else {
|
|
|
//新增库存账
|
|
|
throw new RuntimeException("库存为空");
|
|
|
}
|
|
|
// todo 更新订单明细中发货数量 采购和销售可能需要调不同接口
|
|
|
- R actualQuantity = orderItemsClient.updateActualQuantity(deliveryItems.getSrcId(), deliveryItems.getActualQuantity());
|
|
|
+ R actualQuantity = orderItemsClient.updateActualQuantity(deliveryItems.getSrcId(), deliveryItems.getActualQuantity(),delivery.getDeliveryType());
|
|
|
if (!actualQuantity.isSuccess()){
|
|
|
throw new RuntimeException("更新订单发货数量出错," + actualQuantity.getMsg());
|
|
|
}
|
|
|
@@ -189,35 +193,35 @@ public class DeliveryItemsServiceImpl extends ServiceImpl<DeliveryItemsMapper, D
|
|
|
StockGoods stockGoods = stockById.getData();
|
|
|
//判断出库数量和结余数量的大小
|
|
|
if (stockGoods.getBalanceQuantity().compareTo(deliveryItems.getActualQuantity()) < 0){
|
|
|
- throw new RuntimeException("当前结余数量为:"+stockGoods.getBalanceQuantity() +"小于出库数量,出库数量为:" +deliveryItems.getActualQuantity());
|
|
|
+ throw new RuntimeException("当前结余数量为:"+stockGoods.getBalanceQuantity() +"小于发货数量,发货数量为:" +deliveryItems.getActualQuantity());
|
|
|
}
|
|
|
if (stockGoods.getLockingQuantity().compareTo(deliveryItems.getActualQuantity()) < 0){
|
|
|
- throw new RuntimeException("当前可用数量为:"+stockGoods.getLockingQuantity() +"小于出库数量,出库数量为:" +deliveryItems.getActualQuantity());
|
|
|
+ throw new RuntimeException("当前可用数量为:"+stockGoods.getLockingQuantity() +"小于发货数量,发货数量为:" +deliveryItems.getActualQuantity());
|
|
|
}
|
|
|
stockGoods.setOutQuantity(stockGoods.getOutQuantity().add( deliveryItems.getActualQuantity()));//出库数量 加
|
|
|
- stockGoods.setLockingQuantity(stockGoods.getLockingQuantity().subtract(deliveryItems.getActualQuantity()));//锁定数量 减
|
|
|
+ //stockGoods.setLockingQuantity(stockGoods.getLockingQuantity().subtract(deliveryItems.getActualQuantity()));//锁定数量 减
|
|
|
stockGoods.setBalanceQuantity(stockGoods.getBalanceQuantity().subtract(deliveryItems.getActualQuantity()));//结余数量 减
|
|
|
stockGoods.setSurplusRouteQuantity(stockGoods.getSurplusRouteQuantity().subtract(deliveryItems.getActualQuantity()));//可用数量 减
|
|
|
if (tradeType.equals(OrderTypeEnum.IMPORT.getType())){
|
|
|
//判断出库发票重量和结余发票重量
|
|
|
if (stockGoods.getBalanceWeight().compareTo(deliveryItems.getInvoiceWeight()) < 0){
|
|
|
- throw new RuntimeException("当前结余发票重量为:"+stockGoods.getBalanceWeight() +"小于出库发票重量,出库发票重量为:" +deliveryItems.getInvoiceWeight());
|
|
|
+ throw new RuntimeException("当前结余发票重量为:"+stockGoods.getBalanceWeight() +"小于发货发票重量,发货发票重量为:" +deliveryItems.getInvoiceWeight());
|
|
|
}
|
|
|
if (stockGoods.getLockingWeight().compareTo(deliveryItems.getInvoiceWeight()) < 0){
|
|
|
- throw new RuntimeException("当前结余发票重量为:"+stockGoods.getLockingWeight() +"小于出库发票重量,出库发票重量为:" +deliveryItems.getInvoiceWeight());
|
|
|
+ throw new RuntimeException("当前结余发票重量为:"+stockGoods.getLockingWeight() +"小于发货发票重量,发货发票重量为:" +deliveryItems.getInvoiceWeight());
|
|
|
}
|
|
|
stockGoods.setOutWeight(stockGoods.getOutWeight().add(deliveryItems.getInvoiceWeight()));//出库发票重量
|
|
|
- stockGoods.setLockingWeight(stockGoods.getLockingWeight().subtract(deliveryItems.getInvoiceWeight()));//锁定发票重量
|
|
|
+ //stockGoods.setLockingWeight(stockGoods.getLockingWeight().subtract(deliveryItems.getInvoiceWeight()));//锁定发票重量
|
|
|
stockGoods.setBalanceWeight(stockGoods.getBalanceWeight().subtract(deliveryItems.getInvoiceWeight()));//结余发票重量
|
|
|
//判断出库码单重量和结余码单重量
|
|
|
if (stockGoods.getBalanceVolumn().compareTo(deliveryItems.getBillWeight()) < 0){
|
|
|
- throw new RuntimeException("当前结余码单重量为:"+stockGoods.getBalanceVolumn() +"小于出库码单重量,出库码单重量为:" +deliveryItems.getBillWeight());
|
|
|
+ throw new RuntimeException("当前结余码单重量为:"+stockGoods.getBalanceVolumn() +"小于发货码单重量,发货码单重量为:" +deliveryItems.getBillWeight());
|
|
|
}
|
|
|
if (stockGoods.getLockingVolumn().compareTo(deliveryItems.getBillWeight()) < 0){
|
|
|
- throw new RuntimeException("当前结余码单重量为:"+stockGoods.getLockingVolumn() +"小于出库码单重量,出库码单重量为:" +deliveryItems.getBillWeight());
|
|
|
+ throw new RuntimeException("当前结余码单重量为:"+stockGoods.getLockingVolumn() +"小于发货码单重量,发货码单重量为:" +deliveryItems.getBillWeight());
|
|
|
}
|
|
|
stockGoods.setOutVolumn(stockGoods.getOutVolumn().add(deliveryItems.getBillWeight()));//出库码单重量
|
|
|
- stockGoods.setLockingVolumn(stockGoods.getLockingVolumn().subtract(deliveryItems.getBillWeight()));//锁定码单重量
|
|
|
+ //stockGoods.setLockingVolumn(stockGoods.getLockingVolumn().subtract(deliveryItems.getBillWeight()));//锁定码单重量
|
|
|
stockGoods.setBalanceVolumn(stockGoods.getBalanceVolumn().subtract(deliveryItems.getBillWeight()));//结余码单重量
|
|
|
}
|
|
|
stockGoods.setUpdateTime(new Date());
|
|
|
@@ -228,6 +232,53 @@ public class DeliveryItemsServiceImpl extends ServiceImpl<DeliveryItemsMapper, D
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
|
+ * 撤销发货
|
|
|
+ * @param tradeType 单据类型 进口、出口、国内
|
|
|
+ * @param stockId 库存账id
|
|
|
+ * @param deliveryItems 货物明细信息
|
|
|
+ */
|
|
|
+ public void revocationDeliverGoods(String tradeType,Long stockId,DeliveryItems deliveryItems){
|
|
|
+ //查询库存账
|
|
|
+ R<StockGoods> stockById = stockGoodsClient.getStockById(stockId);
|
|
|
+ if (!stockById.isSuccess()){
|
|
|
+ throw new RuntimeException("查询库存账出错");
|
|
|
+ }
|
|
|
+ if (stockById.getData() == null){
|
|
|
+ throw new RuntimeException("库存账不存在");
|
|
|
+ }
|
|
|
+ StockGoods stockGoods = stockById.getData();
|
|
|
+ //判断出库数量和结余数量的大小
|
|
|
+ if (stockGoods.getOutQuantity().compareTo(deliveryItems.getActualQuantity()) < 0){
|
|
|
+ throw new RuntimeException("当前可减少出库数量为:"+stockGoods.getOutQuantity() +"小于发货数量,发货数量为:" +deliveryItems.getActualQuantity());
|
|
|
+ }
|
|
|
+ stockGoods.setOutQuantity(stockGoods.getOutQuantity().subtract( deliveryItems.getActualQuantity()));//出库数量 加
|
|
|
+ //stockGoods.setLockingQuantity(stockGoods.getLockingQuantity().add(deliveryItems.getActualQuantity()));//锁定数量 减
|
|
|
+ stockGoods.setBalanceQuantity(stockGoods.getBalanceQuantity().add(deliveryItems.getActualQuantity()));//结余数量 减
|
|
|
+ stockGoods.setSurplusRouteQuantity(stockGoods.getSurplusRouteQuantity().add(deliveryItems.getActualQuantity()));//可用数量 减
|
|
|
+ if (tradeType.equals(OrderTypeEnum.IMPORT.getType())){
|
|
|
+ //判断出库发票重量和结余发票重量
|
|
|
+ if (stockGoods.getOutWeight().compareTo(deliveryItems.getInvoiceWeight()) < 0){
|
|
|
+ throw new RuntimeException("当前出库发票重量为:"+stockGoods.getOutWeight() +"小于发货发票重量,发货发票重量为:" +deliveryItems.getInvoiceWeight());
|
|
|
+ }
|
|
|
+ stockGoods.setOutWeight(stockGoods.getOutWeight().subtract(deliveryItems.getInvoiceWeight()));//出库发票重量
|
|
|
+ //stockGoods.setLockingWeight(stockGoods.getLockingWeight().add(deliveryItems.getInvoiceWeight()));//锁定发票重量
|
|
|
+ stockGoods.setBalanceWeight(stockGoods.getBalanceWeight().add(deliveryItems.getInvoiceWeight()));//结余发票重量
|
|
|
+ //判断出库码单重量和结余码单重量
|
|
|
+ if (stockGoods.getOutVolumn().compareTo(deliveryItems.getBillWeight()) < 0){
|
|
|
+ throw new RuntimeException("当前出库码单重量为:"+stockGoods.getOutVolumn() +"小于发货码单重量,发货码单重量为:" +deliveryItems.getBillWeight());
|
|
|
+ }
|
|
|
+ stockGoods.setOutVolumn(stockGoods.getOutVolumn().subtract(deliveryItems.getBillWeight()));//出库码单重量
|
|
|
+ //stockGoods.setLockingVolumn(stockGoods.getLockingVolumn().add(deliveryItems.getBillWeight()));//锁定码单重量
|
|
|
+ stockGoods.setBalanceVolumn(stockGoods.getBalanceVolumn().add(deliveryItems.getBillWeight()));//结余码单重量
|
|
|
+ }
|
|
|
+ stockGoods.setUpdateTime(new Date());
|
|
|
+ stockGoods.setUpdateUser(SecureUtil.getUserId());
|
|
|
+ R updateStock = stockGoodsClient.updateStock(stockGoods);
|
|
|
+ if (!updateStock.isSuccess()){
|
|
|
+ throw new RuntimeException("更新库存总账失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
* 收货单新增库存账
|
|
|
* @param tradeType 单据类型 进口、出口、国内
|
|
|
* @param stockId 库存账id
|