|
|
|
|
@ -9,12 +9,14 @@ import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
|
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
|
|
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductPackagingSchemeRespVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stock.ErpStockPageReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stock.ErpStockRespVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.dataobject.warehousearea.WarehouseAreaDO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.service.stock.ErpStockRecordService;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.service.stock.ErpStockService;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.service.stock.ErpWarehouseService;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.service.warehousearea.WarehouseAreaService;
|
|
|
|
|
@ -55,6 +57,8 @@ public class ErpStockController {
|
|
|
|
|
private ErpWarehouseService warehouseService;
|
|
|
|
|
@Resource
|
|
|
|
|
private WarehouseAreaService warehouseAreaService;
|
|
|
|
|
@Resource
|
|
|
|
|
private ErpStockRecordService stockRecordService;
|
|
|
|
|
|
|
|
|
|
@GetMapping("/get")
|
|
|
|
|
@Operation(summary = "获得产品库存")
|
|
|
|
|
@ -110,13 +114,17 @@ public class ErpStockController {
|
|
|
|
|
Map<Long, WarehouseAreaDO> areaMap = warehouseAreaService.getWarehouseAreaMap(
|
|
|
|
|
convertSet(pageResult.getList(), ErpStockDO::getAreaId));
|
|
|
|
|
return BeanUtils.toBean(pageResult, ErpStockRespVO.class, stock -> {
|
|
|
|
|
MapUtils.findAndThen(productMap, stock.getProductId(), product -> stock.setProductName(product.getName()).setBarCode(product.getBarCode())
|
|
|
|
|
.setCategoryName(product.getCategoryName()).setUnitName(product.getUnitName())
|
|
|
|
|
.setCategoryType(product.getCategoryType()));
|
|
|
|
|
MapUtils.findAndThen(productMap, stock.getProductId(), product -> {
|
|
|
|
|
stock.setProductName(product.getName()).setBarCode(product.getBarCode())
|
|
|
|
|
.setCategoryName(product.getCategoryName()).setUnitName(product.getUnitName())
|
|
|
|
|
.setCategoryType(product.getCategoryType());
|
|
|
|
|
fillProductExtraInfo(stock, product);
|
|
|
|
|
});
|
|
|
|
|
MapUtils.findAndThen(warehouseMap, stock.getWarehouseId(), warehouse -> stock.setWarehouseName(warehouse.getName()));
|
|
|
|
|
if (stock.getAreaName() == null) {
|
|
|
|
|
MapUtils.findAndThen(areaMap, stock.getAreaId(), area -> stock.setAreaName(area.getAreaName()));
|
|
|
|
|
}
|
|
|
|
|
fillRecentRecordTime(stock);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -132,6 +140,7 @@ public class ErpStockController {
|
|
|
|
|
respVO.setCategoryName(product.getCategoryName());
|
|
|
|
|
respVO.setUnitName(product.getUnitName());
|
|
|
|
|
respVO.setCategoryType(product.getCategoryType());
|
|
|
|
|
fillProductExtraInfo(respVO, product);
|
|
|
|
|
}
|
|
|
|
|
ErpWarehouseDO warehouse = warehouseService.getWarehouse(stock.getWarehouseId());
|
|
|
|
|
if (warehouse != null) {
|
|
|
|
|
@ -143,7 +152,31 @@ public class ErpStockController {
|
|
|
|
|
respVO.setAreaName(area.getAreaName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fillRecentRecordTime(respVO);
|
|
|
|
|
return respVO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void fillRecentRecordTime(ErpStockRespVO stock) {
|
|
|
|
|
stock.setRecentInTime(stockRecordService.getLatestRecordTime(
|
|
|
|
|
stock.getProductId(), stock.getWarehouseId(), stock.getAreaId(), true));
|
|
|
|
|
stock.setRecentOutTime(stockRecordService.getLatestRecordTime(
|
|
|
|
|
stock.getProductId(), stock.getWarehouseId(), stock.getAreaId(), false));
|
|
|
|
|
}
|
|
|
|
|
private void fillProductExtraInfo(ErpStockRespVO stock, ErpProductRespVO product) {
|
|
|
|
|
stock.setUnitId(product.getUnitId());
|
|
|
|
|
stock.setPurchaseUnitId(product.getPurchaseUnitId());
|
|
|
|
|
stock.setPurchaseUnitName(product.getPurchaseUnitName());
|
|
|
|
|
stock.setPurchaseUnitConvertQuantity(product.getPurchaseUnitConvertQuantity());
|
|
|
|
|
stock.setDefaultPackagingSchemeId(product.getDefaultPackagingSchemeId());
|
|
|
|
|
stock.setDefaultPackagingScheme(findDefaultPackagingScheme(product));
|
|
|
|
|
}
|
|
|
|
|
private ProductPackagingSchemeRespVO findDefaultPackagingScheme(ErpProductRespVO product) {
|
|
|
|
|
if (product.getDefaultPackagingSchemeId() == null || CollUtil.isEmpty(product.getPackagingSchemes())) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return product.getPackagingSchemes().stream()
|
|
|
|
|
.filter(item -> product.getDefaultPackagingSchemeId().equals(item.getPackagingSchemeId()))
|
|
|
|
|
.findFirst()
|
|
|
|
|
.orElse(null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|