fix:入库单据添加库区id及快照名称

main
HuangHuiKang 1 week ago
parent 3f0b8e3d31
commit 7e9b743544

@ -19,17 +19,22 @@ import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpSupplierDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInItemDO;
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.mold.MoldBrandService;
import cn.iocoder.yudao.module.erp.service.mold.MoldService;
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
import cn.iocoder.yudao.module.erp.service.purchase.ErpSupplierService;
import cn.iocoder.yudao.module.erp.service.stock.ErpStockInService;
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;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
@ -66,6 +71,10 @@ public class ErpStockInController {
private ErpProductService productService;
@Resource
private ErpSupplierService supplierService;
@Resource
private ErpWarehouseService warehouseService;
@Resource
private WarehouseAreaService warehouseAreaService;
@Resource
private MoldBrandService moldBrandService;
@ -120,6 +129,10 @@ public class ErpStockInController {
return success(null);
}
List<ErpStockInItemDO> stockInItemList = stockInService.getStockInItemListByInId(id);
Map<Long, ErpWarehouseDO> warehouseMap = warehouseService.getWarehouseMap(
convertSet(stockInItemList, ErpStockInItemDO::getWarehouseId));
Map<Long, WarehouseAreaDO> areaMap = warehouseAreaService.getWarehouseAreaMap(
convertSet(stockInItemList, ErpStockInItemDO::getAreaId));
if (Objects.equals(stockIn.getInType(), "模具入库")) {
Map<Long, MoldBrandDO> moldMap = moldBrandService.getMoldVOMap(
convertSet(stockInItemList, ErpStockInItemDO::getMoldSetId));
@ -133,6 +146,7 @@ public class ErpStockInController {
ErpStockDO stock = stockService.getStock(source.getMoldSetId(), source.getWarehouseId());
item.setStockCount(stock != null ? stock.getCount() : BigDecimal.ZERO);
item.setMoldList(moldListMap.getOrDefault(source.getMoldSetId(), new ArrayList<>()));
fillWarehouseInfo(item, source, warehouseMap, areaMap);
MapUtils.findAndThen(moldMap, source.getMoldSetId(), mold -> item.setMoldSetName(mold.getName())
.setProductName(mold.getName())
.setProductBarCode(mold.getCode()));
@ -148,6 +162,12 @@ public class ErpStockInController {
stockInVO.setItems(BeanUtils.toBean(stockInItemList, ErpStockInRespVO.Item.class, item -> {
ErpStockDO stock = stockService.getStock(item.getProductId(), item.getWarehouseId());
item.setStockCount(stock != null ? stock.getCount() : BigDecimal.ZERO);
if (StringUtils.isBlank(item.getWarehouseName())) {
MapUtils.findAndThen(warehouseMap, item.getWarehouseId(), warehouse -> item.setWarehouseName(warehouse.getName()));
}
if (StringUtils.isBlank(item.getAreaName())) {
MapUtils.findAndThen(areaMap, item.getAreaId(), area -> item.setAreaName(area.getAreaName()));
}
MapUtils.findAndThen(productMap, item.getProductId(), product -> item.setProductName(product.getName())
.setProductBarCode(product.getBarCode()).setProductUnitName(product.getUnitName()));
}))));
@ -194,6 +214,10 @@ public class ErpStockInController {
convertSet(stockInItemList, ErpStockInItemDO::getProductId));
Map<Long, ErpSupplierDO> supplierMap = supplierService.getSupplierMap(
convertSet(pageResult.getList(), ErpStockInDO::getSupplierId));
Map<Long, ErpWarehouseDO> warehouseMap = warehouseService.getWarehouseMap(
convertSet(stockInItemList, ErpStockInItemDO::getWarehouseId));
Map<Long, WarehouseAreaDO> areaMap = warehouseAreaService.getWarehouseAreaMap(
convertSet(stockInItemList, ErpStockInItemDO::getAreaId));
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
convertSet(pageResult.getList(), stockIn -> Long.parseLong(stockIn.getCreator())));
Map<Long, MoldBrandDO> moldMap = moldBrandService.getMoldVOMap(
@ -209,6 +233,7 @@ public class ErpStockInController {
item.setMoldSetId(source.getMoldSetId());
item.setMoldSetName(source.getMoldSetName());
item.setMoldList(moldListMap.getOrDefault(source.getMoldSetId(), new ArrayList<>()));
fillWarehouseInfo(item, source, warehouseMap, areaMap);
MapUtils.findAndThen(moldMap, source.getMoldSetId(), mold -> item.setMoldSetName(mold.getName())
.setProductName(mold.getName())
.setProductBarCode(mold.getCode()));
@ -220,6 +245,14 @@ public class ErpStockInController {
stockIn.setItems(BeanUtils.toBean(stockInItemMap.get(stockIn.getId()), ErpStockInRespVO.Item.class,
item -> MapUtils.findAndThen(productMap, item.getProductId(), product -> item.setProductName(product.getName())
.setProductBarCode(product.getBarCode()).setProductUnitName(product.getUnitName()))));
stockIn.getItems().forEach(item -> {
if (StringUtils.isBlank(item.getWarehouseName())) {
MapUtils.findAndThen(warehouseMap, item.getWarehouseId(), warehouse -> item.setWarehouseName(warehouse.getName()));
}
if (StringUtils.isBlank(item.getAreaName())) {
MapUtils.findAndThen(areaMap, item.getAreaId(), area -> item.setAreaName(area.getAreaName()));
}
});
stockIn.setProductNames(CollUtil.join(stockIn.getItems(), ",", ErpStockInRespVO.Item::getProductName));
}
@ -228,6 +261,19 @@ public class ErpStockInController {
});
}
private void fillWarehouseInfo(ErpStockInRespVO.Item item, ErpStockInItemDO source,
Map<Long, ErpWarehouseDO> warehouseMap,
Map<Long, WarehouseAreaDO> areaMap) {
item.setWarehouseName(ObjectUtils.defaultIfNull(source.getWarehouseName(), item.getWarehouseName()));
item.setAreaName(ObjectUtils.defaultIfNull(source.getAreaName(), item.getAreaName()));
if (StringUtils.isBlank(item.getWarehouseName())) {
MapUtils.findAndThen(warehouseMap, source.getWarehouseId(), warehouse -> item.setWarehouseName(warehouse.getName()));
}
if (StringUtils.isBlank(item.getAreaName())) {
MapUtils.findAndThen(areaMap, source.getAreaId(), area -> item.setAreaName(area.getAreaName()));
}
}
@PostMapping("/createMesStockIn")
@Operation(summary = "创建生产入库单")
@PreAuthorize("@ss.hasPermission('erp:stock-in:create')")

@ -95,6 +95,9 @@ public class ErpStockInRespVO {
@Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
private Long warehouseId;
@Schema(description = "库区编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
private Long areaId;
@Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
private Long productId;
@ -116,6 +119,12 @@ public class ErpStockInRespVO {
@Schema(description = "产品单位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "盒")
private String productUnitName;
@Schema(description = "仓库名称", example = "A仓")
private String warehouseName;
@Schema(description = "库区名称", example = "A-01")
private String areaName;
@Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
private BigDecimal stockCount;

@ -57,6 +57,10 @@ public class ErpStockInSaveReqVO {
// @NotNull(message = "仓库编号不能为空")
private Long warehouseId;
@Schema(description = "库区编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
@NotNull(message = "库区编号不能为空")
private Long areaId;
@Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
private Long productId;

@ -43,6 +43,9 @@ public class ErpStockInItemDO extends BaseDO {
* {@link ErpWarehouseDO#getId()}
*/
private Long warehouseId;
private String warehouseName;
private Long areaId;
private String areaName;
/**
*
*

@ -14,6 +14,8 @@ import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInItemDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutDO;
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.dal.mysql.stock.ErpStockInItemMapper;
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockInMapper;
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockMapper;
@ -24,6 +26,7 @@ import cn.iocoder.yudao.module.erp.service.mold.MoldBrandService;
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
import cn.iocoder.yudao.module.erp.service.purchase.ErpSupplierService;
import cn.iocoder.yudao.module.erp.service.stock.bo.ErpStockRecordCreateReqBO;
import cn.iocoder.yudao.module.erp.service.warehousearea.WarehouseAreaService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -68,6 +71,8 @@ public class ErpStockInServiceImpl implements ErpStockInService {
private ErpStockRecordService stockRecordService;
@Resource
private MoldBrandService moldBrandService;
@Resource
private WarehouseAreaService warehouseAreaService;
@Override
@Transactional(rollbackFor = Exception.class)
@ -172,10 +177,16 @@ public class ErpStockInServiceImpl implements ErpStockInService {
}
private List<ErpStockInItemDO> validateStockInItems(List<ErpStockInSaveReqVO.Item> list,String outType) {
validateWarehouseAreas(list);
if (Objects.equals(outType, "模具入库")) {
List<MoldBrandDO> moldList = moldBrandService.validMoldList(
convertSet(list, ErpStockInSaveReqVO.Item::getMoldSetId));
Map<Long, MoldBrandDO> moldMap = convertMap(moldList, MoldBrandDO::getId);
Map<Long, ErpWarehouseDO> warehouseMap = convertMap(
warehouseService.getWarehouseList(convertSet(list, ErpStockInSaveReqVO.Item::getWarehouseId)),
ErpWarehouseDO::getId);
Map<Long, WarehouseAreaDO> areaMap = warehouseAreaService.getWarehouseAreaMap(
convertSet(list, ErpStockInSaveReqVO.Item::getAreaId));
return convertList(list, o -> {
MoldBrandDO moldBrand = moldMap.get(o.getMoldSetId());
return ErpStockInItemDO.builder()
@ -183,6 +194,9 @@ public class ErpStockInServiceImpl implements ErpStockInService {
.moldSetId(moldBrand.getId())
.moldSetName(moldBrand.getName())
.warehouseId(o.getWarehouseId())
.warehouseName(warehouseMap.containsKey(o.getWarehouseId()) ? warehouseMap.get(o.getWarehouseId()).getName() : null)
.areaId(o.getAreaId())
.areaName(areaMap.containsKey(o.getAreaId()) ? areaMap.get(o.getAreaId()).getAreaName() : null)
.productId(moldBrand.getId())
.productUnitId(null)
.productPrice(o.getProductPrice())
@ -196,14 +210,37 @@ public class ErpStockInServiceImpl implements ErpStockInService {
List<ErpProductDO> productList = productService.validProductList(
convertSet(list, ErpStockInSaveReqVO.Item::getProductId));
Map<Long, ErpProductDO> productMap = convertMap(productList, ErpProductDO::getId);
warehouseService.validWarehouseList(convertSet(
list, ErpStockInSaveReqVO.Item::getWarehouseId));
Map<Long, ErpWarehouseDO> warehouseMap = convertMap(
warehouseService.getWarehouseList(convertSet(list, ErpStockInSaveReqVO.Item::getWarehouseId)),
ErpWarehouseDO::getId);
Map<Long, WarehouseAreaDO> areaMap = warehouseAreaService.getWarehouseAreaMap(
convertSet(list, ErpStockInSaveReqVO.Item::getAreaId));
return convertList(list, o -> BeanUtils.toBean(o, ErpStockInItemDO.class, item -> item
.setWarehouseName(warehouseMap.containsKey(item.getWarehouseId()) ? warehouseMap.get(item.getWarehouseId()).getName() : null)
.setAreaName(areaMap.containsKey(item.getAreaId()) ? areaMap.get(item.getAreaId()).getAreaName() : null)
.setProductUnitId(productMap.get(item.getProductId()).getUnitId())
.setTotalPrice(MoneyUtils.priceMultiply(item.getProductPrice(), item.getCount()))));
}
}
private void validateWarehouseAreas(List<ErpStockInSaveReqVO.Item> list) {
Map<Long, ErpWarehouseDO> warehouseMap = convertMap(
warehouseService.validWarehouseList(convertSet(list, ErpStockInSaveReqVO.Item::getWarehouseId)),
ErpWarehouseDO::getId);
Map<Long, WarehouseAreaDO> areaMap = warehouseAreaService.getWarehouseAreaMap(
convertSet(list, ErpStockInSaveReqVO.Item::getAreaId));
list.forEach(item -> {
WarehouseAreaDO area = areaMap.get(item.getAreaId());
if (area == null) {
throw exception(WAREHOUSE_AREA_NOT_EXISTS);
}
if (!warehouseMap.containsKey(item.getWarehouseId())
|| !Objects.equals(item.getWarehouseId(), area.getWarehouseId())) {
throw exception(WAREHOUSE_LOCATION_WAREHOUSE_AREA_NOT_MATCH);
}
});
}
private void updateStockInItemList(Long id, List<ErpStockInItemDO> newList) {
boolean moldStockIn = CollUtil.isNotEmpty(newList)
&& newList.stream().anyMatch(item -> item.getMoldSetId() != null);

@ -45,6 +45,16 @@ public interface WarehouseAreaService {
*/
WarehouseAreaDO getWarehouseArea(Long id);
List<WarehouseAreaDO> getWarehouseAreaList(Collection<Long> ids);
default Map<Long, WarehouseAreaDO> getWarehouseAreaMap(Collection<Long> ids) {
if (ids == null || ids.isEmpty()) {
return new HashMap<>();
}
return cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap(
getWarehouseAreaList(ids), WarehouseAreaDO::getId);
}
/**
* ERP
*

@ -13,6 +13,7 @@ import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.ArrayList;
import java.util.List;
@ -72,6 +73,14 @@ public class WarehouseAreaServiceImpl implements WarehouseAreaService {
return warehouseAreaMapper.selectById(id);
}
@Override
public List<WarehouseAreaDO> getWarehouseAreaList(Collection<Long> ids) {
if (ids == null || ids.isEmpty()) {
return new ArrayList<>();
}
return warehouseAreaMapper.selectBatchIds(ids);
}
@Override
public PageResult<WarehouseAreaDO> getWarehouseAreaPage(WarehouseAreaPageReqVO pageReqVO) {
return warehouseAreaMapper.selectPage(pageReqVO);

Loading…
Cancel
Save