|
|
|
@ -63,8 +63,8 @@ public class ErpStockController {
|
|
|
|
@GetMapping("/get")
|
|
|
|
@GetMapping("/get")
|
|
|
|
@Operation(summary = "获得产品库存")
|
|
|
|
@Operation(summary = "获得产品库存")
|
|
|
|
@Parameters({
|
|
|
|
@Parameters({
|
|
|
|
@Parameter(name = "id", description = "编号", example = "1"), // 方案一:传递 id
|
|
|
|
@Parameter(name = "id", description = "编号", example = "1"),
|
|
|
|
@Parameter(name = "productId", description = "产品编号", example = "10"), // 方案二:传递 productId + warehouseId
|
|
|
|
@Parameter(name = "productId", description = "产品编号", example = "10"),
|
|
|
|
@Parameter(name = "warehouseId", description = "仓库编号", example = "2")
|
|
|
|
@Parameter(name = "warehouseId", description = "仓库编号", example = "2")
|
|
|
|
})
|
|
|
|
})
|
|
|
|
@PreAuthorize("@ss.hasPermission('erp:stock:query')")
|
|
|
|
@PreAuthorize("@ss.hasPermission('erp:stock:query')")
|
|
|
|
@ -96,10 +96,9 @@ public class ErpStockController {
|
|
|
|
@PreAuthorize("@ss.hasPermission('erp:stock:export')")
|
|
|
|
@PreAuthorize("@ss.hasPermission('erp:stock:export')")
|
|
|
|
@ApiAccessLog(operateType = EXPORT)
|
|
|
|
@ApiAccessLog(operateType = EXPORT)
|
|
|
|
public void exportStockExcel(@Valid ErpStockPageReqVO pageReqVO,
|
|
|
|
public void exportStockExcel(@Valid ErpStockPageReqVO pageReqVO,
|
|
|
|
HttpServletResponse response) throws IOException {
|
|
|
|
HttpServletResponse response) throws IOException {
|
|
|
|
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
|
|
|
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
|
|
|
List<ErpStockRespVO> list = buildStockVOPageResult(stockService.getStockPage(pageReqVO)).getList();
|
|
|
|
List<ErpStockRespVO> list = buildStockVOPageResult(stockService.getStockPage(pageReqVO)).getList();
|
|
|
|
// 导出 Excel
|
|
|
|
|
|
|
|
ExcelUtils.write(response, "产品库存.xls", "数据", ErpStockRespVO.class, list);
|
|
|
|
ExcelUtils.write(response, "产品库存.xls", "数据", ErpStockRespVO.class, list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -119,7 +118,10 @@ public class ErpStockController {
|
|
|
|
.setCategoryName(product.getCategoryName()).setUnitName(product.getUnitName())
|
|
|
|
.setCategoryName(product.getCategoryName()).setUnitName(product.getUnitName())
|
|
|
|
.setCategoryType(product.getCategoryType());
|
|
|
|
.setCategoryType(product.getCategoryType());
|
|
|
|
fillProductExtraInfo(stock, product);
|
|
|
|
fillProductExtraInfo(stock, product);
|
|
|
|
|
|
|
|
fillPackagingSnapshot(stock, product);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
stock.setPackagingRule(buildPackagingRule(stock));
|
|
|
|
|
|
|
|
stock.setStockDisplay(buildStockDisplay(stock));
|
|
|
|
MapUtils.findAndThen(warehouseMap, stock.getWarehouseId(), warehouse -> stock.setWarehouseName(warehouse.getName()));
|
|
|
|
MapUtils.findAndThen(warehouseMap, stock.getWarehouseId(), warehouse -> stock.setWarehouseName(warehouse.getName()));
|
|
|
|
if (stock.getAreaName() == null) {
|
|
|
|
if (stock.getAreaName() == null) {
|
|
|
|
MapUtils.findAndThen(areaMap, stock.getAreaId(), area -> stock.setAreaName(area.getAreaName()));
|
|
|
|
MapUtils.findAndThen(areaMap, stock.getAreaId(), area -> stock.setAreaName(area.getAreaName()));
|
|
|
|
@ -138,10 +140,18 @@ public class ErpStockController {
|
|
|
|
respVO.setProductName(product.getName());
|
|
|
|
respVO.setProductName(product.getName());
|
|
|
|
respVO.setBarCode(product.getBarCode());
|
|
|
|
respVO.setBarCode(product.getBarCode());
|
|
|
|
respVO.setCategoryName(product.getCategoryName());
|
|
|
|
respVO.setCategoryName(product.getCategoryName());
|
|
|
|
respVO.setUnitName(product.getUnitName());
|
|
|
|
if (respVO.getUnitName() == null) {
|
|
|
|
respVO.setCategoryType(product.getCategoryType());
|
|
|
|
respVO.setUnitName(product.getUnitName());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (respVO.getCategoryType() == null) {
|
|
|
|
|
|
|
|
respVO.setCategoryType(product.getCategoryType());
|
|
|
|
|
|
|
|
}
|
|
|
|
fillProductExtraInfo(respVO, product);
|
|
|
|
fillProductExtraInfo(respVO, product);
|
|
|
|
|
|
|
|
fillPackagingSnapshot(respVO, product);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fillDerivedFields(respVO);
|
|
|
|
|
|
|
|
respVO.setPackagingRule(buildPackagingRule(respVO));
|
|
|
|
|
|
|
|
respVO.setStockDisplay(buildStockDisplay(respVO));
|
|
|
|
ErpWarehouseDO warehouse = warehouseService.getWarehouse(stock.getWarehouseId());
|
|
|
|
ErpWarehouseDO warehouse = warehouseService.getWarehouse(stock.getWarehouseId());
|
|
|
|
if (warehouse != null) {
|
|
|
|
if (warehouse != null) {
|
|
|
|
respVO.setWarehouseName(warehouse.getName());
|
|
|
|
respVO.setWarehouseName(warehouse.getName());
|
|
|
|
@ -162,16 +172,64 @@ public class ErpStockController {
|
|
|
|
stock.setRecentOutTime(stockRecordService.getLatestRecordTime(
|
|
|
|
stock.setRecentOutTime(stockRecordService.getLatestRecordTime(
|
|
|
|
stock.getProductId(), stock.getWarehouseId(), stock.getAreaId(), false));
|
|
|
|
stock.getProductId(), stock.getWarehouseId(), stock.getAreaId(), false));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void fillProductExtraInfo(ErpStockRespVO stock, ErpProductRespVO product) {
|
|
|
|
private void fillProductExtraInfo(ErpStockRespVO stock, ErpProductRespVO product) {
|
|
|
|
stock.setUnitId(product.getUnitId());
|
|
|
|
if (stock.getUnitId() == null) {
|
|
|
|
stock.setPurchaseUnitId(product.getPurchaseUnitId());
|
|
|
|
stock.setUnitId(product.getUnitId());
|
|
|
|
stock.setPurchaseUnitName(product.getPurchaseUnitName());
|
|
|
|
}
|
|
|
|
stock.setPurchaseUnitConvertQuantity(product.getPurchaseUnitConvertQuantity());
|
|
|
|
if (stock.getPurchaseUnitId() == null) {
|
|
|
|
stock.setDefaultPackagingSchemeId(product.getDefaultPackagingSchemeId());
|
|
|
|
stock.setPurchaseUnitId(product.getPurchaseUnitId());
|
|
|
|
stock.setDefaultPackagingScheme(findDefaultPackagingScheme(product));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stock.getPurchaseUnitName() == null) {
|
|
|
|
|
|
|
|
stock.setPurchaseUnitName(product.getPurchaseUnitName());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stock.getPurchaseUnitConvertQuantity() == null) {
|
|
|
|
|
|
|
|
stock.setPurchaseUnitConvertQuantity(product.getPurchaseUnitConvertQuantity());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stock.getDefaultPackagingSchemeId() == null) {
|
|
|
|
|
|
|
|
stock.setDefaultPackagingSchemeId(product.getDefaultPackagingSchemeId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stock.getDefaultPackagingScheme() == null) {
|
|
|
|
|
|
|
|
stock.setDefaultPackagingScheme(findDefaultPackagingScheme(product));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void fillPackagingSnapshot(ErpStockRespVO stock, ErpProductRespVO product) {
|
|
|
|
|
|
|
|
if (stock.getDefaultPackagingSchemeName() != null
|
|
|
|
|
|
|
|
&& stock.getPackageQuantity() != null
|
|
|
|
|
|
|
|
&& stock.getPalletPackageQuantity() != null
|
|
|
|
|
|
|
|
&& stock.getPalletTotalQuantity() != null) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ProductPackagingSchemeRespVO defaultScheme = findDefaultPackagingScheme(product);
|
|
|
|
|
|
|
|
if (defaultScheme == null) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stock.getDefaultPackagingSchemeName() == null) {
|
|
|
|
|
|
|
|
stock.setDefaultPackagingSchemeName(defaultScheme.getPackagingSchemeName());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stock.getPackageQuantity() == null) {
|
|
|
|
|
|
|
|
stock.setPackageQuantity(defaultScheme.getPackageQuantity());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stock.getPalletPackageQuantity() == null) {
|
|
|
|
|
|
|
|
stock.setPalletPackageQuantity(defaultScheme.getPalletPackageQuantity());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stock.getPalletTotalQuantity() == null) {
|
|
|
|
|
|
|
|
stock.setPalletTotalQuantity(defaultScheme.getPalletTotalQuantity());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void fillDerivedFields(ErpStockRespVO stock) {
|
|
|
|
|
|
|
|
if (stock.getUnitName() == null && stock.getUnitId() != null) {
|
|
|
|
|
|
|
|
// no-op: 目前库存单位名称只能从产品侧回填
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stock.getDefaultPackagingSchemeId() == null && stock.getDefaultPackagingScheme() != null) {
|
|
|
|
|
|
|
|
stock.setDefaultPackagingSchemeId(stock.getDefaultPackagingScheme().getPackagingSchemeId());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private ProductPackagingSchemeRespVO findDefaultPackagingScheme(ErpProductRespVO product) {
|
|
|
|
private ProductPackagingSchemeRespVO findDefaultPackagingScheme(ErpProductRespVO product) {
|
|
|
|
if (product.getDefaultPackagingSchemeId() == null || CollUtil.isEmpty(product.getPackagingSchemes())) {
|
|
|
|
if (product == null || product.getDefaultPackagingSchemeId() == null || CollUtil.isEmpty(product.getPackagingSchemes())) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return product.getPackagingSchemes().stream()
|
|
|
|
return product.getPackagingSchemes().stream()
|
|
|
|
@ -179,4 +237,68 @@ public class ErpStockController {
|
|
|
|
.findFirst()
|
|
|
|
.findFirst()
|
|
|
|
.orElse(null);
|
|
|
|
.orElse(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String buildPackagingRule(ErpStockRespVO stock) {
|
|
|
|
|
|
|
|
if (stock == null) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isProductType(stock.getCategoryType())) {
|
|
|
|
|
|
|
|
if (stock.getPackageQuantity() == null || stock.getPalletPackageQuantity() == null) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return "1托=" + formatNumber(stock.getPalletPackageQuantity()) + "包 1包=" + formatNumber(stock.getPackageQuantity()) + "个";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stock.getPurchaseUnitName() == null || stock.getPurchaseUnitConvertQuantity() == null) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return "1" + stock.getPurchaseUnitName() + "=" + formatNumber(stock.getPurchaseUnitConvertQuantity()) + "个";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String buildStockDisplay(ErpStockRespVO stock) {
|
|
|
|
|
|
|
|
if (stock == null || stock.getCount() == null) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isProductType(stock.getCategoryType())) {
|
|
|
|
|
|
|
|
if (stock.getPalletTotalQuantity() == null || stock.getPalletTotalQuantity().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
|
|
|
|
return formatNumber(stock.getCount()) + stock.getUnitName();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
BigDecimal palletCount = stock.getCount().divideToIntegralValue(stock.getPalletTotalQuantity());
|
|
|
|
|
|
|
|
return formatNumber(palletCount) + "托,0包,0个";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stock.getPurchaseUnitConvertQuantity() == null || stock.getPurchaseUnitConvertQuantity().compareTo(BigDecimal.ZERO) <= 0
|
|
|
|
|
|
|
|
|| stock.getPurchaseUnitName() == null || stock.getUnitName() == null) {
|
|
|
|
|
|
|
|
return formatNumber(stock.getCount()) + stock.getUnitName();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
BigDecimal purchaseCount = stock.getCount().divideToIntegralValue(stock.getPurchaseUnitConvertQuantity());
|
|
|
|
|
|
|
|
BigDecimal unitCount = stock.getCount().remainder(stock.getPurchaseUnitConvertQuantity());
|
|
|
|
|
|
|
|
StringBuilder display = new StringBuilder();
|
|
|
|
|
|
|
|
appendQuantity(display, purchaseCount, stock.getPurchaseUnitName(), true);
|
|
|
|
|
|
|
|
appendQuantity(display, unitCount, stock.getUnitName(), false);
|
|
|
|
|
|
|
|
return display.length() > 0 ? display.toString() : formatNumber(stock.getCount()) + stock.getUnitName();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void appendQuantity(StringBuilder display, BigDecimal quantity, String unitName, boolean keepZero) {
|
|
|
|
|
|
|
|
if (quantity == null || quantity.compareTo(BigDecimal.ZERO) <= 0 || unitName == null) {
|
|
|
|
|
|
|
|
if (!keepZero) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (display.length() > 0) {
|
|
|
|
|
|
|
|
display.append(",");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
display.append("0").append(unitName);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (display.length() > 0) {
|
|
|
|
|
|
|
|
display.append(",");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
display.append(formatNumber(quantity)).append(unitName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isProductType(Integer categoryType) {
|
|
|
|
|
|
|
|
return Integer.valueOf(1).equals(categoryType);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String formatNumber(BigDecimal value) {
|
|
|
|
|
|
|
|
return value == null ? "0" : value.stripTrailingZeros().toPlainString();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|