|
|
|
|
@ -8,6 +8,8 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
|
|
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
|
|
|
|
import cn.iocoder.yudao.module.common.controller.admin.mold.vo.MoldBrandSaveReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldBrandDO;
|
|
|
|
|
import cn.iocoder.yudao.module.common.dal.mysql.mold.MoldBrandMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.common.enums.MoldBrandStatusEnum;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutAuditReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutPageReqVO;
|
|
|
|
|
@ -17,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;
|
|
|
|
|
@ -29,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;
|
|
|
|
|
@ -62,6 +67,8 @@ public class ErpStockOutServiceImpl implements ErpStockOutService {
|
|
|
|
|
@Resource
|
|
|
|
|
private ErpStockOutMapper stockOutMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private MoldBrandMapper moldBrandMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private ErpStockOutItemMapper stockOutItemMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private ErpStockOutApproveRecordMapper stockOutApproveRecordMapper;
|
|
|
|
|
@ -80,6 +87,8 @@ public class ErpStockOutServiceImpl implements ErpStockOutService {
|
|
|
|
|
@Resource
|
|
|
|
|
private ErpStockRecordService stockRecordService;
|
|
|
|
|
@Resource
|
|
|
|
|
private WarehouseAreaService warehouseAreaService;
|
|
|
|
|
@Resource
|
|
|
|
|
private AdminUserApi adminUserApi;
|
|
|
|
|
@Resource
|
|
|
|
|
private ConfigApi configApi;
|
|
|
|
|
@ -103,7 +112,7 @@ public class ErpStockOutServiceImpl implements ErpStockOutService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean needAudit = needAudit();
|
|
|
|
|
Integer status = needAudit ? ErpAuditStatus.DRAFT.getStatus() : ErpAuditStatus.APPROVE.getStatus();
|
|
|
|
|
Integer status = ErpAuditStatus.DRAFT.getStatus();
|
|
|
|
|
ErpStockOutDO stockOut = BeanUtils.toBean(createReqVO, ErpStockOutDO.class, out -> out
|
|
|
|
|
.setNo(no)
|
|
|
|
|
.setNeedAudit(needAudit)
|
|
|
|
|
@ -114,11 +123,16 @@ public class ErpStockOutServiceImpl implements ErpStockOutService {
|
|
|
|
|
stockOutItems.forEach(item -> item.setOutId(stockOut.getId()));
|
|
|
|
|
stockOutItemMapper.insertBatch(stockOutItems);
|
|
|
|
|
|
|
|
|
|
if (!needAudit) {
|
|
|
|
|
applyStockOutEffect(stockOut, stockOutItems, null);
|
|
|
|
|
createApproveRecord(stockOut.getId(), ErpStockOutApproveActionEnum.AUTO_APPROVE, null,
|
|
|
|
|
ErpAuditStatus.APPROVE.getStatus(), null, "无需审核,系统自动出库");
|
|
|
|
|
if (createReqVO.getOutType().equals("模具出库")) {
|
|
|
|
|
//修改模具组状态
|
|
|
|
|
for (ErpStockOutSaveReqVO.Item item : createReqVO.getItems()) {
|
|
|
|
|
MoldBrandDO moldBrandDO = moldBrandMapper.selectById(item.getMoldSetId());
|
|
|
|
|
moldBrandDO.setStatus(MoldBrandStatusEnum.STANDBY.getStatus());
|
|
|
|
|
moldBrandMapper.updateById(moldBrandDO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return stockOut.getId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -189,12 +203,25 @@ public class ErpStockOutServiceImpl implements ErpStockOutService {
|
|
|
|
|
&& !ErpAuditStatus.UN_APPROVE.getStatus().equals(stockOut.getStatus())) {
|
|
|
|
|
throw exception(STOCK_OUT_SUBMIT_FAIL_STATUS);
|
|
|
|
|
}
|
|
|
|
|
Integer fromStatus = stockOut.getStatus();
|
|
|
|
|
if (!Boolean.TRUE.equals(stockOut.getNeedAudit())) {
|
|
|
|
|
int updateCount = stockOutMapper.updateByIdAndStatus(stockOut.getId(), fromStatus,
|
|
|
|
|
new ErpStockOutDO().setStatus(ErpAuditStatus.APPROVE.getStatus()));
|
|
|
|
|
if (updateCount == 0) {
|
|
|
|
|
throw exception(STOCK_OUT_SUBMIT_FAIL_STATUS);
|
|
|
|
|
}
|
|
|
|
|
List<ErpStockOutItemDO> stockOutItems = stockOutItemMapper.selectListByOutId(stockOut.getId());
|
|
|
|
|
applyStockOutEffect(stockOut, stockOutItems, null);
|
|
|
|
|
createApproveRecord(stockOut.getId(), ErpStockOutApproveActionEnum.AUTO_APPROVE, fromStatus,
|
|
|
|
|
ErpAuditStatus.APPROVE.getStatus(), null,
|
|
|
|
|
submitReqVO.getRemark() != null ? submitReqVO.getRemark() : "无需审核,提交后自动出库");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Long auditUserId = submitReqVO.getAuditUserId() != null ? submitReqVO.getAuditUserId() : stockOut.getAuditUserId();
|
|
|
|
|
if (auditUserId == null) {
|
|
|
|
|
throw exception(STOCK_OUT_SUBMIT_FAIL_AUDIT_USER_EMPTY);
|
|
|
|
|
}
|
|
|
|
|
adminUserApi.validateUser(auditUserId);
|
|
|
|
|
Integer fromStatus = stockOut.getStatus();
|
|
|
|
|
ErpStockOutDO updateObj = new ErpStockOutDO()
|
|
|
|
|
.setAuditUserId(auditUserId)
|
|
|
|
|
.setNeedAudit(true)
|
|
|
|
|
@ -328,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(), 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);
|
|
|
|
|
@ -340,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(), 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()));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
@ -370,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()
|
|
|
|
|
@ -380,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())
|
|
|
|
|
@ -391,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);
|
|
|
|
|
|