fix:修改仓储入库单据相关接口

main
HuangHuiKang 6 days ago
parent ef7c95bcac
commit f10deea93a

@ -13,9 +13,11 @@ import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stock.ErpStockPageR
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.ErpStockService;
import cn.iocoder.yudao.module.erp.service.stock.ErpWarehouseService;
import cn.iocoder.yudao.module.erp.service.warehousearea.WarehouseAreaService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
@ -51,6 +53,8 @@ public class ErpStockController {
private ErpProductService productService;
@Resource
private ErpWarehouseService warehouseService;
@Resource
private WarehouseAreaService warehouseAreaService;
@GetMapping("/get")
@Operation(summary = "获得产品库存")
@ -62,9 +66,10 @@ public class ErpStockController {
@PreAuthorize("@ss.hasPermission('erp:stock:query')")
public CommonResult<ErpStockRespVO> getStock(@RequestParam(value = "id", required = false) Long id,
@RequestParam(value = "productId", required = false) Long productId,
@RequestParam(value = "warehouseId", required = false) Long warehouseId) {
ErpStockDO stock = id != null ? stockService.getStock(id) : stockService.getStock(productId, warehouseId);
return success(BeanUtils.toBean(stock, ErpStockRespVO.class));
@RequestParam(value = "warehouseId", required = false) Long warehouseId,
@RequestParam(value = "areaId", required = false) Long areaId) {
ErpStockDO stock = id != null ? stockService.getStock(id) : stockService.getStock(productId, warehouseId, areaId);
return success(buildStockRespVO(stock));
}
@GetMapping("/get-count")
@ -102,12 +107,43 @@ public class ErpStockController {
convertSet(pageResult.getList(), ErpStockDO::getProductId));
Map<Long, ErpWarehouseDO> warehouseMap = warehouseService.getWarehouseMap(
convertSet(pageResult.getList(), ErpStockDO::getWarehouseId));
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(warehouseMap, stock.getWarehouseId(), warehouse -> stock.setWarehouseName(warehouse.getName()));
if (stock.getAreaName() == null) {
MapUtils.findAndThen(areaMap, stock.getAreaId(), area -> stock.setAreaName(area.getAreaName()));
}
});
}
private ErpStockRespVO buildStockRespVO(ErpStockDO stock) {
if (stock == null) {
return null;
}
ErpStockRespVO respVO = BeanUtils.toBean(stock, ErpStockRespVO.class);
ErpProductRespVO product = productService.getProduct(stock.getProductId());
if (product != null) {
respVO.setProductName(product.getName());
respVO.setBarCode(product.getBarCode());
respVO.setCategoryName(product.getCategoryName());
respVO.setUnitName(product.getUnitName());
respVO.setCategoryType(product.getCategoryType());
}
ErpWarehouseDO warehouse = warehouseService.getWarehouse(stock.getWarehouseId());
if (warehouse != null) {
respVO.setWarehouseName(warehouse.getName());
}
if (respVO.getAreaName() == null && respVO.getAreaId() != null) {
WarehouseAreaDO area = warehouseAreaService.getWarehouseArea(respVO.getAreaId());
if (area != null) {
respVO.setAreaName(area.getAreaName());
}
}
return respVO;
}
}

@ -224,7 +224,7 @@ public class ErpStockInController {
convertSet(stockInItemList, ErpStockInItemDO::getMoldSetId));
stockInVO.setItems(convertList(stockInItemList, source -> {
ErpStockInRespVO.Item item = BeanUtils.toBean(source, ErpStockInRespVO.Item.class);
ErpStockDO stock = stockService.getStock(source.getMoldSetId(), source.getWarehouseId());
ErpStockDO stock = stockService.getStock(source.getMoldSetId(), source.getWarehouseId(), source.getAreaId());
item.setStockCount(stock != null ? stock.getCount() : BigDecimal.ZERO);
item.setMoldList(moldListMap.getOrDefault(source.getMoldSetId(), new ArrayList<>()));
fillWarehouseInfo(item, source, warehouseMap, areaMap);
@ -241,7 +241,7 @@ public class ErpStockInController {
Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap(
convertSet(stockInItemList, ErpStockInItemDO::getProductId));
stockInVO.setItems(BeanUtils.toBean(stockInItemList, ErpStockInRespVO.Item.class, item -> {
ErpStockDO stock = stockService.getStock(item.getProductId(), item.getWarehouseId());
ErpStockDO stock = stockService.getStock(item.getProductId(), item.getWarehouseId(), item.getAreaId());
item.setStockCount(stock != null ? stock.getCount() : BigDecimal.ZERO);
if (StringUtils.isBlank(item.getWarehouseName())) {
MapUtils.findAndThen(warehouseMap, item.getWarehouseId(), warehouse -> item.setWarehouseName(warehouse.getName()));

@ -228,7 +228,7 @@ public class ErpStockOutController {
convertSet(stockOutItemList, ErpStockOutItemDO::getMoldSetId));
stockOutVO.setItems(convertList(stockOutItemList, source -> {
ErpStockOutRespVO.Item item = BeanUtils.toBean(source, ErpStockOutRespVO.Item.class);
ErpStockDO stock = stockService.getStock(source.getMoldSetId(), source.getWarehouseId());
ErpStockDO stock = stockService.getStock(source.getMoldSetId(), source.getWarehouseId(), source.getAreaId());
item.setStockCount(stock != null ? stock.getCount() : BigDecimal.ZERO);
item.setMoldList(moldListMap.getOrDefault(source.getMoldSetId(), new ArrayList<>()));
MapUtils.findAndThen(moldMap, source.getMoldSetId(), mold -> {
@ -244,7 +244,7 @@ public class ErpStockOutController {
Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap(
convertSet(stockOutItemList, ErpStockOutItemDO::getProductId));
stockOutVO.setItems(BeanUtils.toBean(stockOutItemList, ErpStockOutRespVO.Item.class, item -> {
ErpStockDO stock = stockService.getStock(item.getProductId(), item.getWarehouseId());
ErpStockDO stock = stockService.getStock(item.getProductId(), item.getWarehouseId(), item.getAreaId());
item.setStockCount(stock != null ? stock.getCount() : BigDecimal.ZERO);
MapUtils.findAndThen(productMap, item.getProductId(), product -> {
item.setProductName(product.getName());

@ -13,9 +13,11 @@ import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.record.ErpStockReco
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.record.ErpStockRecordRespVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockRecordDO;
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.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;
@ -51,6 +53,8 @@ public class ErpStockRecordController {
private ErpProductService productService;
@Resource
private ErpWarehouseService warehouseService;
@Resource
private WarehouseAreaService warehouseAreaService;
@Resource
private AdminUserApi adminUserApi;
@ -61,7 +65,7 @@ public class ErpStockRecordController {
@PreAuthorize("@ss.hasPermission('erp:stock-record:query')")
public CommonResult<ErpStockRecordRespVO> getStockRecord(@RequestParam("id") Long id) {
ErpStockRecordDO stockRecord = stockRecordService.getStockRecord(id);
return success(BeanUtils.toBean(stockRecord, ErpStockRecordRespVO.class));
return success(buildStockRecordRespVO(stockRecord));
}
@GetMapping("/page")
@ -92,6 +96,8 @@ public class ErpStockRecordController {
convertSet(pageResult.getList(), ErpStockRecordDO::getProductId));
Map<Long, ErpWarehouseDO> warehouseMap = warehouseService.getWarehouseMap(
convertSet(pageResult.getList(), ErpStockRecordDO::getWarehouseId));
Map<Long, WarehouseAreaDO> areaMap = warehouseAreaService.getWarehouseAreaMap(
convertSet(pageResult.getList(), ErpStockRecordDO::getAreaId));
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
convertSet(pageResult.getList(), record -> Long.parseLong(record.getCreator())));
return BeanUtils.toBean(pageResult, ErpStockRecordRespVO.class, stock -> {
@ -99,8 +105,42 @@ public class ErpStockRecordController {
.setCategoryName(product.getCategoryName()).setUnitName(product.getUnitName())
.setCategoryType(product.getCategoryType()));
MapUtils.findAndThen(warehouseMap, stock.getWarehouseId(), warehouse -> stock.setWarehouseName(warehouse.getName()));
if (stock.getAreaName() == null) {
MapUtils.findAndThen(areaMap, stock.getAreaId(), area -> stock.setAreaName(area.getAreaName()));
}
MapUtils.findAndThen(userMap, Long.parseLong(stock.getCreator()), user -> stock.setCreatorName(user.getNickname()));
});
}
private ErpStockRecordRespVO buildStockRecordRespVO(ErpStockRecordDO stockRecord) {
if (stockRecord == null) {
return null;
}
ErpStockRecordRespVO respVO = BeanUtils.toBean(stockRecord, ErpStockRecordRespVO.class);
ErpProductRespVO product = productService.getProduct(stockRecord.getProductId());
if (product != null) {
respVO.setProductName(product.getName());
respVO.setCategoryName(product.getCategoryName());
respVO.setUnitName(product.getUnitName());
respVO.setCategoryType(product.getCategoryType());
}
ErpWarehouseDO warehouse = warehouseService.getWarehouse(stockRecord.getWarehouseId());
if (warehouse != null) {
respVO.setWarehouseName(warehouse.getName());
}
if (respVO.getAreaName() == null && respVO.getAreaId() != null) {
WarehouseAreaDO area = warehouseAreaService.getWarehouseArea(respVO.getAreaId());
if (area != null) {
respVO.setAreaName(area.getAreaName());
}
}
if (respVO.getCreator() != null) {
AdminUserRespDTO user = adminUserApi.getUser(Long.parseLong(respVO.getCreator()));
if (user != null) {
respVO.setCreatorName(user.getNickname());
}
}
return respVO;
}
}

@ -117,6 +117,12 @@ public class ErpStockOutRespVO {
@Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
private Long warehouseId;
@Schema(description = "库区编号", example = "1")
private Long areaId;
@Schema(description = "库区名称", example = "A区")
private String areaName;
@Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
private Long productId;

@ -59,6 +59,9 @@ public class ErpStockOutSaveReqVO {
@Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
private Long warehouseId;
@Schema(description = "库区编号", example = "1")
private Long areaId;
@Schema(description = "产品 id", example = "3113")
private Long productId;

@ -22,8 +22,12 @@ public class ErpStockRecordPageReqVO extends PageParam {
@Schema(description = "仓库编号", example = "32407")
private Long warehouseId;
@Schema(description = "库区编号", example = "1")
private Long areaId;
@Schema(description = "产品分类", example = "32407")
private Long categoryId;
@Schema(description = "产品分类类型", example = "1")
private Integer categoryType;
@Schema(description = "业务类型", example = "10")
private Integer bizType;
@ -40,4 +44,4 @@ public class ErpStockRecordPageReqVO extends PageParam {
@Schema(description = "id集合导出用")
private String ids;
}
}

@ -31,6 +31,13 @@ public class ErpStockRecordRespVO {
@Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "32407")
private Long warehouseId;
@Schema(description = "库区编号", example = "1")
private Long areaId;
@Schema(description = "库区名称", example = "A区")
@ExcelProperty("库区名称")
private String areaName;
@Schema(description = "出入库数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "11084")
@ExcelProperty("出入库数量")
private BigDecimal count;

@ -18,6 +18,9 @@ public class ErpStockPageReqVO extends PageParam {
@Schema(description = "仓库编号", example = "2802")
private Long warehouseId;
@Schema(description = "库区编号", example = "1")
private Long areaId;
@Schema(description = "产品分类", example = "2802")
private Long categoryId;

@ -26,6 +26,13 @@ public class ErpStockRespVO {
@Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2802")
private Long warehouseId;
@Schema(description = "库区编号", example = "1")
private Long areaId;
@Schema(description = "库区名称", example = "A区")
@ExcelProperty("库区名称")
private String areaName;
@Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "21935")
@ExcelProperty("库存数量")
private BigDecimal count;

@ -42,6 +42,14 @@ public class ErpStockDO extends BaseDO {
* {@link ErpWarehouseDO#getId()}
*/
private Long warehouseId;
/**
*
*/
private Long areaId;
/**
*
*/
private String areaName;
/**
*
*/

@ -43,6 +43,14 @@ public class ErpStockOutItemDO extends BaseDO {
* {@link ErpWarehouseDO#getId()}
*/
private Long warehouseId;
/**
*
*/
private Long areaId;
/**
*
*/
private String areaName;
/**
*
*
@ -78,4 +86,4 @@ public class ErpStockOutItemDO extends BaseDO {
* {@link ErpProductDO#getId()}
*/
private Long deviceId;
}
}

@ -53,6 +53,14 @@ public class ErpStockRecordDO extends BaseDO {
* {@link ErpWarehouseDO#getId()}
*/
private Long warehouseId;
/**
*
*/
private Long areaId;
/**
*
*/
private String areaName;
/**
*
*

@ -33,6 +33,7 @@ public interface ErpStockMapper extends BaseMapperX<ErpStockDO> {
LambdaQueryWrapperX<ErpStockDO> erpStockDOLambdaQueryWrapperX = new LambdaQueryWrapperX<ErpStockDO>()
.eqIfPresent(ErpStockDO::getProductId, reqVO.getProductId())
.eqIfPresent(ErpStockDO::getWarehouseId, reqVO.getWarehouseId())
.eqIfPresent(ErpStockDO::getAreaId, reqVO.getAreaId())
.eqIfPresent(ErpStockDO::getCategoryId, reqVO.getCategoryId())
.eqIfPresent(ErpStockDO::getCategoryType, reqVO.getCategoryType())
.orderByDesc(ErpStockDO::getId);
@ -52,8 +53,15 @@ public interface ErpStockMapper extends BaseMapperX<ErpStockDO> {
}
default ErpStockDO selectByProductIdAndWarehouseId(Long productId, Long warehouseId) {
return selectOne(ErpStockDO::getProductId, productId,
ErpStockDO::getWarehouseId, warehouseId);
return selectByProductIdAndWarehouseIdAndAreaId(productId, warehouseId, null);
}
default ErpStockDO selectByProductIdAndWarehouseIdAndAreaId(Long productId, Long warehouseId, Long areaId) {
return selectOne(new LambdaQueryWrapperX<ErpStockDO>()
.eq(ErpStockDO::getProductId, productId)
.eq(ErpStockDO::getWarehouseId, warehouseId)
.eq(areaId != null, ErpStockDO::getAreaId, areaId)
.isNull(areaId == null, ErpStockDO::getAreaId));
}
default ErpStockDO selectByProductIdAndWarehouseIdAndCategoryType(Long productId, Long warehouseId, Integer categoryType) {

@ -26,7 +26,9 @@ public interface ErpStockRecordMapper extends BaseMapperX<ErpStockRecordDO> {
LambdaQueryWrapperX<ErpStockRecordDO> erpStockRecordDOLambdaQueryWrapperX = new LambdaQueryWrapperX<ErpStockRecordDO>()
.eqIfPresent(ErpStockRecordDO::getProductId, reqVO.getProductId())
.eqIfPresent(ErpStockRecordDO::getCategoryId, reqVO.getCategoryId())
.eqIfPresent(ErpStockRecordDO::getCategoryType, reqVO.getCategoryType())
.eqIfPresent(ErpStockRecordDO::getWarehouseId, reqVO.getWarehouseId())
.eqIfPresent(ErpStockRecordDO::getAreaId, reqVO.getAreaId())
.eqIfPresent(ErpStockRecordDO::getBizType, reqVO.getBizType())
.likeIfPresent(ErpStockRecordDO::getBizNo, reqVO.getBizNo())
.betweenIfPresent(ErpStockRecordDO::getCreateTime, reqVO.getCreateTime())
@ -46,4 +48,4 @@ public interface ErpStockRecordMapper extends BaseMapperX<ErpStockRecordDO> {
return selectPage(reqVO,erpStockRecordDOLambdaQueryWrapperX);
}
}
}

@ -564,11 +564,12 @@ public class ErpProductServiceImpl implements ErpProductService {
if (CollUtil.isEmpty(list)) {
return Collections.emptyList();
}
Map<Long, List<ProductPackagingSchemeRespVO>> packagingSchemeMap = convertMap(
productPackagingSchemeRelMapper.selectListByProductIds(convertSet(list, ErpProductDO::getId)),
ProductPackagingSchemeRelDO::getProductId,
rel -> BeanUtils.toBean(rel, ProductPackagingSchemeRespVO.class),
Collectors.toList());
Map<Long, List<ProductPackagingSchemeRespVO>> packagingSchemeMap =
productPackagingSchemeRelMapper.selectListByProductIds(convertSet(list, ErpProductDO::getId))
.stream()
.collect(Collectors.groupingBy(ProductPackagingSchemeRelDO::getProductId,
Collectors.mapping(rel -> BeanUtils.toBean(rel, ProductPackagingSchemeRespVO.class),
Collectors.toList())));
Map<Long, ErpProductCategoryDO> categoryMap = productCategoryService.getProductCategoryMap(
convertSet(list, ErpProductDO::getCategoryId));
Map<Long, ErpProductCategoryDO> subCategoryMap = productCategoryService.getProductCategoryMap(

@ -121,7 +121,7 @@ public class ErpStockInServiceImpl implements ErpStockInService {
}
boolean needAudit = needAudit();
Integer status = ErpAuditStatus.DRAFT.getStatus();
Integer status = ErpAuditStatus.DRAFT.getStatus();
ErpStockInDO stockIn = BeanUtils.toBean(createReqVO, ErpStockInDO.class, in -> in
.setNo(no)
.setNeedAudit(needAudit)
@ -132,13 +132,14 @@ public class ErpStockInServiceImpl implements ErpStockInService {
stockInItems.forEach(item -> item.setInId(stockIn.getId()));
stockInItemMapper.insertBatch(stockInItems);
if (createReqVO.getInType().equals("模具入库")){
//修改模具组状态
for (ErpStockInSaveReqVO.Item item : createReqVO.getItems()) {
MoldBrandDO moldBrandDO = moldBrandMapper.selectById(item.getMoldSetId());
moldBrandDO.setStatus(MoldBrandStatusEnum.IN_STOCK.getStatus());
moldBrandMapper.updateById(moldBrandDO);
//修改模具组状态
for (ErpStockInSaveReqVO.Item item : createReqVO.getItems()) {
MoldBrandDO moldBrandDO = moldBrandMapper.selectById(item.getMoldSetId());
moldBrandDO.setStatus(MoldBrandStatusEnum.IN_STOCK.getStatus());
moldBrandMapper.updateById(moldBrandDO);
}
}
@ -356,7 +357,8 @@ public class ErpStockInServiceImpl implements ErpStockInService {
: (approve ? ErpStockRecordBizTypeEnum.OTHER_IN.getType()
: ErpStockRecordBizTypeEnum.OTHER_IN_CANCEL.getType());
stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO(
stockInItem.getProductId(), moldDO.getId(), null, stockInItem.getWarehouseId(), count,
stockInItem.getProductId(), moldDO.getId(), null, stockInItem.getWarehouseId(),
stockInItem.getAreaId(), stockInItem.getAreaName(), count,
recordBizType, stockInItem.getInId(), stockInItem.getId(), stockIn.getNo(), stockIn.getInTime()));
if (approve && itemNeedUpdateMoldStatus(moldDO)) {
moldDO.setStatus(MoldBrandStatusEnum.STANDBY.getStatus());
@ -368,7 +370,8 @@ public class ErpStockInServiceImpl implements ErpStockInService {
: (approve ? ErpStockRecordBizTypeEnum.getTypeByName(stockIn.getInType())
: ErpStockRecordBizTypeEnum.getTypeByName(stockIn.getInType(), 10));
stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO(
stockInItem.getProductId(), productDO.getCategoryId(), productDO.getCategoryType(), stockInItem.getWarehouseId(), count,
stockInItem.getProductId(), productDO.getCategoryId(), productDO.getCategoryType(), stockInItem.getWarehouseId(),
stockInItem.getAreaId(), stockInItem.getAreaName(), count,
recordBizType, stockInItem.getInId(), stockInItem.getId(), stockIn.getNo(), stockIn.getInTime()));
}
});

@ -19,6 +19,8 @@ import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutApproveRecordDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutItemDO;
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.ErpStockOutApproveRecordMapper;
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockOutItemMapper;
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockOutMapper;
@ -31,6 +33,7 @@ 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.sale.ErpCustomerService;
import cn.iocoder.yudao.module.erp.service.stock.bo.ErpStockRecordCreateReqBO;
import cn.iocoder.yudao.module.erp.service.warehousearea.WarehouseAreaService;
import cn.iocoder.yudao.module.infra.api.config.ConfigApi;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import org.springframework.stereotype.Service;
@ -84,6 +87,8 @@ public class ErpStockOutServiceImpl implements ErpStockOutService {
@Resource
private ErpStockRecordService stockRecordService;
@Resource
private WarehouseAreaService warehouseAreaService;
@Resource
private AdminUserApi adminUserApi;
@Resource
private ConfigApi configApi;
@ -118,16 +123,16 @@ public class ErpStockOutServiceImpl implements ErpStockOutService {
stockOutItems.forEach(item -> item.setOutId(stockOut.getId()));
stockOutItemMapper.insertBatch(stockOutItems);
if (createReqVO.getOutType().equals("模具出库")) {
//修改模具组状态
for (ErpStockOutSaveReqVO.Item item : createReqVO.getItems()) {
MoldBrandDO moldBrandDO = moldBrandMapper.selectById(item.getMoldSetId());
moldBrandDO.setStatus(MoldBrandStatusEnum.STANDBY.getStatus());
moldBrandMapper.updateById(moldBrandDO);
}
//修改模具组状态
for (ErpStockOutSaveReqVO.Item item : createReqVO.getItems()) {
MoldBrandDO moldBrandDO = moldBrandMapper.selectById(item.getMoldSetId());
moldBrandDO.setStatus(MoldBrandStatusEnum.STANDBY.getStatus());
moldBrandMapper.updateById(moldBrandDO);
}
return stockOut.getId();
}
@ -350,7 +355,8 @@ public class ErpStockOutServiceImpl implements ErpStockOutService {
: (approve ? ErpStockRecordBizTypeEnum.OTHER_OUT.getType()
: ErpStockRecordBizTypeEnum.OTHER_OUT_CANCEL.getType());
stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO(
stockOutItem.getProductId(), moldDO.getId(), null, stockOutItem.getWarehouseId(), count,
stockOutItem.getProductId(), moldDO.getId(), null, stockOutItem.getWarehouseId(),
stockOutItem.getAreaId(), stockOutItem.getAreaName(), count,
recordBizType, stockOutItem.getOutId(), stockOutItem.getId(), stockOut.getNo(), stockOut.getOutTime()));
if (approve && itemNeedUpdateMoldStatus(moldDO)) {
moldDO.setStatus(3);
@ -362,7 +368,8 @@ public class ErpStockOutServiceImpl implements ErpStockOutService {
: (approve ? ErpStockRecordBizTypeEnum.getTypeByName(stockOut.getOutType())
: ErpStockRecordBizTypeEnum.getTypeByName(stockOut.getOutType(), 10));
stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO(
stockOutItem.getProductId(), product.getCategoryId(), product.getCategoryType(), stockOutItem.getWarehouseId(), count,
stockOutItem.getProductId(), product.getCategoryId(), product.getCategoryType(), stockOutItem.getWarehouseId(),
stockOutItem.getAreaId(), stockOutItem.getAreaName(), count,
recordBizType, stockOutItem.getOutId(), stockOutItem.getId(), stockOut.getNo(), stockOut.getOutTime()));
}
});
@ -392,9 +399,12 @@ public class ErpStockOutServiceImpl implements ErpStockOutService {
}
private List<ErpStockOutItemDO> validateStockOutItems(List<ErpStockOutSaveReqVO.Item> list, String outType) {
validateWarehouseAreas(list);
if (Objects.equals(outType, "模具出库")) {
List<MoldBrandDO> moldList = moldBrandService.validMoldList(convertSet(list, ErpStockOutSaveReqVO.Item::getMoldSetId));
Map<Long, MoldBrandDO> moldMap = convertMap(moldList, MoldBrandDO::getId);
Map<Long, WarehouseAreaDO> areaMap = warehouseAreaService.getWarehouseAreaMap(
convertSet(list, ErpStockOutSaveReqVO.Item::getAreaId));
return convertList(list, item -> {
MoldBrandDO moldBrand = moldMap.get(item.getMoldSetId());
return ErpStockOutItemDO.builder()
@ -402,6 +412,8 @@ public class ErpStockOutServiceImpl implements ErpStockOutService {
.moldSetId(moldBrand.getId())
.moldSetName(moldBrand.getName())
.warehouseId(item.getWarehouseId())
.areaId(item.getAreaId())
.areaName(areaMap.containsKey(item.getAreaId()) ? areaMap.get(item.getAreaId()).getAreaName() : null)
.productId(moldBrand.getId())
.productUnitId(null)
.productPrice(item.getProductPrice())
@ -413,11 +425,35 @@ public class ErpStockOutServiceImpl implements ErpStockOutService {
}
List<ErpProductDO> productList = productService.validProductList(convertSet(list, ErpStockOutSaveReqVO.Item::getProductId));
Map<Long, ErpProductDO> productMap = convertMap(productList, ErpProductDO::getId);
Map<Long, WarehouseAreaDO> areaMap = warehouseAreaService.getWarehouseAreaMap(
convertSet(list, ErpStockOutSaveReqVO.Item::getAreaId));
return convertList(list, item -> BeanUtils.toBean(item, ErpStockOutItemDO.class, target -> target
.setAreaName(areaMap.containsKey(target.getAreaId()) ? areaMap.get(target.getAreaId()).getAreaName() : null)
.setProductUnitId(productMap.get(target.getProductId()).getUnitId())
.setTotalPrice(MoneyUtils.priceMultiply(target.getProductPrice(), target.getCount()))));
}
private void validateWarehouseAreas(List<ErpStockOutSaveReqVO.Item> list) {
Map<Long, ErpWarehouseDO> warehouseMap = convertMap(
warehouseService.validWarehouseList(convertSet(list, ErpStockOutSaveReqVO.Item::getWarehouseId)),
ErpWarehouseDO::getId);
Map<Long, WarehouseAreaDO> areaMap = warehouseAreaService.getWarehouseAreaMap(
convertSet(list, ErpStockOutSaveReqVO.Item::getAreaId));
list.forEach(item -> {
if (item.getAreaId() == null) {
return;
}
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 updateStockOutItemList(Long id, List<ErpStockOutItemDO> newList) {
boolean moldStockOut = CollUtil.isNotEmpty(newList)
&& newList.stream().anyMatch(item -> item.getMoldSetId() != null);

@ -48,7 +48,8 @@ public class ErpStockRecordServiceImpl implements ErpStockRecordService {
public void createStockRecord(ErpStockRecordCreateReqBO createReqBO) {
// 1. 更新库存
BigDecimal totalCount = stockService.updateStockCountIncrement(createReqBO.getCategoryId(),
createReqBO.getProductId(), createReqBO.getWarehouseId(), createReqBO.getCount());
createReqBO.getProductId(), createReqBO.getWarehouseId(), createReqBO.getAreaId(),
createReqBO.getAreaName(), createReqBO.getCount());
Integer categoryType = createReqBO.getCategoryType();
if (categoryType == null) {
ErpProductRespVO product = productService.getProduct(createReqBO.getProductId());

@ -39,6 +39,8 @@ public interface ErpStockService {
*/
ErpStockDO getStock(Long productId, Long warehouseId);
ErpStockDO getStock(Long productId, Long warehouseId, Long areaId);
/**
*
* 0
@ -64,6 +66,7 @@ public interface ErpStockService {
* @param count
* @return
*/
BigDecimal updateStockCountIncrement(Long categoryId, Long productId, Long warehouseId, BigDecimal count);
BigDecimal updateStockCountIncrement(Long categoryId, Long productId, Long warehouseId, Long areaId,
String areaName, BigDecimal count);
}
}

@ -55,7 +55,12 @@ public class ErpStockServiceImpl implements ErpStockService {
@Override
public ErpStockDO getStock(Long productId, Long warehouseId) {
ErpStockDO stock = stockMapper.selectByProductIdAndWarehouseId(productId, warehouseId);
return getStock(productId, warehouseId, null);
}
@Override
public ErpStockDO getStock(Long productId, Long warehouseId, Long areaId) {
ErpStockDO stock = stockMapper.selectByProductIdAndWarehouseIdAndAreaId(productId, warehouseId, areaId);
if (stock != null && stock.getCategoryType() == null) {
ErpProductRespVO product = productService.getProduct(productId);
if (product != null) {
@ -81,19 +86,24 @@ public class ErpStockServiceImpl implements ErpStockService {
}
@Override
public BigDecimal updateStockCountIncrement(Long categoryId,Long productId, Long warehouseId, BigDecimal count) {
public BigDecimal updateStockCountIncrement(Long categoryId, Long productId, Long warehouseId, Long areaId,
String areaName, BigDecimal count) {
ErpProductRespVO product = productService.getProduct(productId);
Integer categoryType = product != null ? product.getCategoryType() : null;
// 1.1 查询当前库存
ErpStockDO stock = stockMapper.selectByProductIdAndWarehouseId(productId, warehouseId);
ErpStockDO stock = stockMapper.selectByProductIdAndWarehouseIdAndAreaId(productId, warehouseId, areaId);
if (stock == null) {
stock = new ErpStockDO().setProductId(productId).setWarehouseId(warehouseId).setCount(BigDecimal.ZERO)
.setCategoryType(categoryType);
stock = new ErpStockDO().setProductId(productId).setWarehouseId(warehouseId).setAreaId(areaId)
.setAreaName(areaName).setCount(BigDecimal.ZERO).setCategoryType(categoryType);
stock.setCategoryId(categoryId);
stockMapper.insert(stock);
} else if (stock.getCategoryType() == null) {
stock.setCategoryType(categoryType);
stockMapper.updateById(new ErpStockDO().setId(stock.getId()).setCategoryType(categoryType));
} else if (stock.getAreaId() != null && (stock.getAreaName() == null || stock.getAreaName().isEmpty())
&& areaName != null && !areaName.isEmpty()) {
stock.setAreaName(areaName);
stockMapper.updateById(new ErpStockDO().setId(stock.getId()).setAreaName(areaName));
}
// 1.2 校验库存是否充足
if (!NEGATIVE_STOCK_COUNT_ENABLE && stock.getCount().add(count).compareTo(BigDecimal.ZERO) < 0) {

@ -1,6 +1,5 @@
package cn.iocoder.yudao.module.erp.service.stock.bo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@ -15,7 +14,6 @@ import java.time.LocalDateTime;
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ErpStockRecordCreateReqBO {
/**
@ -37,6 +35,14 @@ public class ErpStockRecordCreateReqBO {
*/
@NotNull(message = "仓库编号不能为空")
private Long warehouseId;
/**
*
*/
private Long areaId;
/**
*
*/
private String areaName;
/**
*
*
@ -72,6 +78,29 @@ public class ErpStockRecordCreateReqBO {
public ErpStockRecordCreateReqBO(Long productId, Long categoryId, Long warehouseId, BigDecimal count,
Integer bizType, Long bizId, Long bizItemId, String bizNo,
LocalDateTime recordTime) {
this(productId, categoryId, null, warehouseId, count, bizType, bizId, bizItemId, bizNo, recordTime);
this(productId, categoryId, null, warehouseId, null, null, count, bizType, bizId, bizItemId, bizNo, recordTime);
}
public ErpStockRecordCreateReqBO(Long productId, Long categoryId, Integer categoryType, Long warehouseId,
BigDecimal count, Integer bizType, Long bizId, Long bizItemId,
String bizNo, LocalDateTime recordTime) {
this(productId, categoryId, categoryType, warehouseId, null, null, count, bizType, bizId, bizItemId, bizNo, recordTime);
}
public ErpStockRecordCreateReqBO(Long productId, Long categoryId, Integer categoryType, Long warehouseId,
Long areaId, String areaName, BigDecimal count, Integer bizType, Long bizId,
Long bizItemId, String bizNo, LocalDateTime recordTime) {
this.productId = productId;
this.categoryId = categoryId;
this.categoryType = categoryType;
this.warehouseId = warehouseId;
this.areaId = areaId;
this.areaName = areaName;
this.count = count;
this.bizType = bizType;
this.bizId = bizId;
this.bizItemId = bizItemId;
this.bizNo = bizNo;
this.recordTime = recordTime;
}
}

Loading…
Cancel
Save