|
@@ -2,6 +2,7 @@ package com.fjhx.wms.service.stock.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -13,8 +14,10 @@ import com.fjhx.wms.entity.stock.dto.StockWaitSelectDto;
|
|
|
import com.fjhx.wms.entity.stock.po.*;
|
|
|
import com.fjhx.wms.entity.stock.vo.StockWaitDetailsVo;
|
|
|
import com.fjhx.wms.entity.stock.vo.StockWaitVo;
|
|
|
+import com.fjhx.wms.entity.warehouse.po.Warehouse;
|
|
|
import com.fjhx.wms.mapper.stock.StockWaitMapper;
|
|
|
import com.fjhx.wms.service.stock.*;
|
|
|
+import com.fjhx.wms.service.warehouse.WarehouseService;
|
|
|
import com.obs.services.internal.ServiceException;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
import com.ruoyi.system.utils.UserUtil;
|
|
@@ -22,9 +25,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@@ -49,6 +55,8 @@ public class StockWaitServiceImpl extends ServiceImpl<StockWaitMapper, StockWait
|
|
|
StockJournalDetailsService stockJournalDetailsService;
|
|
|
@Autowired
|
|
|
StockWaitDetailsService stockWaitDetailsService;
|
|
|
+ @Autowired
|
|
|
+ WarehouseService warehouseService;
|
|
|
|
|
|
@Override
|
|
|
public Page<StockWaitVo> getPage(StockWaitSelectDto dto) {
|
|
@@ -87,7 +95,33 @@ public class StockWaitServiceImpl extends ServiceImpl<StockWaitMapper, StockWait
|
|
|
|
|
|
List<StockWaitVo> records = page.getRecords();
|
|
|
//赋值操作人
|
|
|
- UserUtil.assignmentNickName(records,StockWaitVo::getCreateUser,StockWaitVo::setOperatorName);
|
|
|
+ UserUtil.assignmentNickName(records, StockWaitVo::getCreateUser, StockWaitVo::setOperatorName);
|
|
|
+ //赋值仓库名称和id
|
|
|
+ List<Long> wids = new ArrayList<>();
|
|
|
+ for (StockWaitVo stockWaitVo : records) {
|
|
|
+ String victoriatouristJson = stockWaitVo.getVictoriatouristJson();
|
|
|
+ if (ObjectUtil.isEmpty(victoriatouristJson)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject json = JSONObject.parseObject(victoriatouristJson);
|
|
|
+ if (!json.containsKey("receiptWarehouseId")) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ wids.add(json.getLong("receiptWarehouseId"));
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isEmpty(wids)) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+ List<Warehouse> warehouses = warehouseService.listByIds(wids);
|
|
|
+ Map<Long, String> warehousesMap = warehouses.stream().collect(Collectors.toMap(Warehouse::getId, Warehouse::getName));
|
|
|
+ for (StockWaitVo stockWaitVo : records) {
|
|
|
+ String victoriatouristJson = stockWaitVo.getVictoriatouristJson();
|
|
|
+ if (ObjectUtil.isEmpty(victoriatouristJson)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject json = JSONObject.parseObject(victoriatouristJson);
|
|
|
+ json.put("receiptWarehouseName", warehousesMap.get(json.getLong("receiptWarehouseId")));
|
|
|
+ }
|
|
|
|
|
|
return page;
|
|
|
}
|
|
@@ -101,18 +135,28 @@ public class StockWaitServiceImpl extends ServiceImpl<StockWaitMapper, StockWait
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
public StockWaitVo detailByWdly(Long id) {
|
|
|
- StockWaitVo detail = detail(id);
|
|
|
+ StockWait stockWait = this.getById(id);
|
|
|
+ StockWaitVo result = BeanUtil.toBean(stockWait, StockWaitVo.class);
|
|
|
List<StockWaitDetails> list = stockWaitDetailsService.list(q -> q.eq(StockWaitDetails::getStockWaitId, id));
|
|
|
List<StockWaitDetailsVo> stockWaitDetailsVos = BeanUtil.copyToList(list, StockWaitDetailsVo.class);
|
|
|
- //根据业务id(到货id)查询采购单id
|
|
|
+ //根据业务id(到货id)查询采购单明细信息
|
|
|
|
|
|
- //赋值物品信息和采购信息
|
|
|
- for (StockWaitDetails stockWaitDetails : stockWaitDetailsVos) {
|
|
|
|
|
|
+ //赋值物品信息和采购信息
|
|
|
+ List<Long> pids = stockWaitDetailsVos.stream().map(StockWaitDetails::getProductId).collect(Collectors.toList());
|
|
|
+ if (ObjectUtil.isNotEmpty(pids)) {
|
|
|
+ List<ProductInfo> productInfos = productInfoService.listByIds(pids);
|
|
|
+ Map<Long, ProductInfo> productInfoMap = productInfos.stream().collect(Collectors.toMap(ProductInfo::getId, Function.identity()));
|
|
|
+ for (StockWaitDetailsVo stockWaitDetails : stockWaitDetailsVos) {
|
|
|
+ ProductInfo productInfo = productInfoMap.get(stockWaitDetails.getProductId());
|
|
|
+ stockWaitDetails.setProductName(productInfo.getName());
|
|
|
+ stockWaitDetails.setProductCode(productInfo.getCode());
|
|
|
+ }
|
|
|
}
|
|
|
- detail.setStockWaitDetailsList(stockWaitDetailsVos);
|
|
|
- return detail;
|
|
|
+ result.setStockWaitDetailsList(stockWaitDetailsVos);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -141,6 +185,45 @@ public class StockWaitServiceImpl extends ServiceImpl<StockWaitMapper, StockWait
|
|
|
stockJournalDetailsService.saveBatch(stockJournalDetailsList);
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void addByWdly(StockWaitDto stockWaitDto) {
|
|
|
+ List<Stock> stockList = new ArrayList<>();
|
|
|
+
|
|
|
+ List<StockWaitDetails> stockWaitDetailsList = stockWaitDto.getStockWaitDetailsList();
|
|
|
+ List<Long> dids = stockWaitDetailsList.stream().map(StockWaitDetails::getId).collect(Collectors.toList());
|
|
|
+ Map<Long, StockWaitDetails> stockWaitDetailsMap = stockWaitDetailsList.stream().collect(Collectors.toMap(StockWaitDetails::getId, Function.identity()));
|
|
|
+ List<StockWaitDetails> stockWaitDetails = stockWaitDetailsService.listByIds(dids);
|
|
|
+ for (StockWaitDetails stockWaitDetail : stockWaitDetails) {
|
|
|
+ StockWaitDetails temp = stockWaitDetailsMap.get(stockWaitDetail.getId());
|
|
|
+ //更新已入库数量
|
|
|
+ BigDecimal receiptQuantity = stockWaitDetail.getReceiptQuantity() == null ? BigDecimal.ZERO : stockWaitDetail.getReceiptQuantity();
|
|
|
+ stockWaitDetail.setReceiptQuantity(receiptQuantity.add(temp.getQuantity()));
|
|
|
+ if (stockWaitDetail.getReceiptQuantity().compareTo(stockWaitDetail.getQuantity()) > 0) {
|
|
|
+ throw new ServiceException("入库数量+已入库数量不能大于待采购数量");
|
|
|
+ }
|
|
|
+
|
|
|
+ //操作库存
|
|
|
+ Stock stock = new Stock();
|
|
|
+ stock.setQuantity(stockWaitDto.getQuantity());
|
|
|
+ stock.setProductId(stockWaitDetail.getProductId());
|
|
|
+ stockList.add(stock);
|
|
|
+ }
|
|
|
+ stockWaitDetailsService.updateBatchById(stockWaitDetails);
|
|
|
+
|
|
|
+ //创建出入库记录
|
|
|
+ StockJournal stockJournal = new StockJournal();
|
|
|
+ stockJournal.setType(stockWaitDto.getType() == 1 ? 4 : 5);
|
|
|
+ stockJournal.setWarehouseId(stockWaitDto.getWarehouseId());
|
|
|
+ stockJournal.setBusinessId(stockWaitDto.getId());
|
|
|
+ //保存出入库记录
|
|
|
+ stockJournalService.save(stockJournal);
|
|
|
+
|
|
|
+ List<StockJournalDetails> stockJournalDetailsList = stockService.ModifyInventory(stockJournal.getId(), 3, stockList, stockWaitDto.getWarehouseId());
|
|
|
+ //保存出入库明细
|
|
|
+ stockJournalDetailsService.saveBatch(stockJournalDetailsList);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void edit(StockWaitDto stockWaitDto) {
|
|
|
this.updateById(stockWaitDto);
|