|
@@ -69,18 +69,14 @@ public class StockWaitServiceImpl extends ServiceImpl<StockWaitMapper, StockWait
|
|
|
Page<StockWaitVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
|
|
|
List<StockWaitVo> records = page.getRecords();
|
|
|
- List<Long> productIds = records.stream().map(StockWaitVo::getProductId).collect(Collectors.toList());
|
|
|
- if (ObjectUtil.isNotEmpty(productIds)) {
|
|
|
- List<ProductInfo> productInfos = productInfoService.listByIds(productIds);
|
|
|
- Map<Long, ProductInfo> productInfoMap = productInfos.stream().collect(Collectors.groupingBy(ProductInfo::getId,
|
|
|
- Collectors.collectingAndThen(Collectors.toList(), value -> value.get(0))));
|
|
|
- for (StockWaitVo stockWaitVo : records) {
|
|
|
- ProductInfo productInfo = productInfoMap.get(stockWaitVo.getProductId());
|
|
|
- if (ObjectUtil.isNotEmpty(productInfo)) {
|
|
|
- stockWaitVo.setProductName(productInfo.getName());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ // 赋值产品属性
|
|
|
+ productInfoService.attributeAssign(records, StockWaitVo::getProductId, (item, productInfo) -> {
|
|
|
+ item.setProductCode(productInfo.getCode());
|
|
|
+ item.setProductUnit(productInfo.getUnit());
|
|
|
+ item.setProductType(productInfo.getType());
|
|
|
+ item.setProductName(productInfo.getName());
|
|
|
+ item.setProductSpec(productInfo.getSpec());
|
|
|
+ });
|
|
|
|
|
|
return page;
|
|
|
}
|
|
@@ -131,10 +127,12 @@ public class StockWaitServiceImpl extends ServiceImpl<StockWaitMapper, StockWait
|
|
|
|
|
|
@Override
|
|
|
public StockWaitVo detail(Long id) {
|
|
|
- StockWait stockWait = this.getById(id);
|
|
|
+ StockWaitDetails stockWaitDetails = stockWaitDetailsService.getById(id);
|
|
|
+ StockWait stockWait = this.getById(stockWaitDetails.getStockWaitId());
|
|
|
StockWaitVo result = BeanUtil.toBean(stockWait, StockWaitVo.class);
|
|
|
- ProductInfo byId = productInfoService.getById(result.getProductId());
|
|
|
+ ProductInfo byId = productInfoService.getById(stockWaitDetails.getProductId());
|
|
|
result.setProductName(byId.getName());
|
|
|
+ result.setQuantity(stockWaitDetails.getQuantity());
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -168,13 +166,16 @@ public class StockWaitServiceImpl extends ServiceImpl<StockWaitMapper, StockWait
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void add(StockWaitDto stockWaitDto) {
|
|
|
- //更新已入库数量
|
|
|
- StockWait byId = getById(stockWaitDto.getId());
|
|
|
- byId.setReceiptQuantity(byId.getReceiptQuantity().add(stockWaitDto.getQuantity()));
|
|
|
- if (byId.getReceiptQuantity().compareTo(byId.getQuantity()) > 0) {
|
|
|
+ //更新已入库数量 根据明细id
|
|
|
+// StockWait byId = getById(stockWaitDto.getId());
|
|
|
+ StockWaitDetails stockWaitDetails = stockWaitDetailsService.getById(stockWaitDto.getId());
|
|
|
+ stockWaitDetails.setReceiptQuantity(stockWaitDetails.getReceiptQuantity().add(stockWaitDto.getQuantity()));
|
|
|
+ if (stockWaitDetails.getReceiptQuantity().compareTo(stockWaitDetails.getQuantity()) > 0) {
|
|
|
throw new ServiceException("入库数量+已入库数量不能大于待采购数量");
|
|
|
}
|
|
|
- updateById(byId);
|
|
|
+// updateById(byId);
|
|
|
+ stockWaitDetailsService.updateById(stockWaitDetails);
|
|
|
+ StockWait byId = getById(stockWaitDetails.getStockWaitId());
|
|
|
//创建出入库记录
|
|
|
StockJournal stockJournal = new StockJournal();
|
|
|
stockJournal.setType(byId.getType() == 1 ? 4 : 5);
|
|
@@ -186,7 +187,7 @@ public class StockWaitServiceImpl extends ServiceImpl<StockWaitMapper, StockWait
|
|
|
//操作库存
|
|
|
Stock stock = new Stock();
|
|
|
stock.setQuantity(stockWaitDto.getQuantity());
|
|
|
- stock.setProductId(byId.getProductId());
|
|
|
+ stock.setProductId(stockWaitDetails.getProductId());
|
|
|
List<StockJournalDetails> stockJournalDetailsList = stockService.ModifyInventory(stockJournal.getId(), byId.getType(), Arrays.asList(stock), stockWaitDto.getWarehouseId());
|
|
|
//保存出入库明细
|
|
|
stockJournalDetailsService.saveBatch(stockJournalDetailsList);
|