|
|
|
|
@ -10,19 +10,24 @@ import cn.iocoder.yudao.module.common.controller.admin.mold.vo.MoldBrandSaveReqV
|
|
|
|
|
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.pallet.enums.ErpPalletStatusEnum;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInAuditReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInPageReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInSaveReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInSubmitReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.dataobject.pallet.ErpPalletDO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInApproveRecordDO;
|
|
|
|
|
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.ErpStockInItemPalletDO;
|
|
|
|
|
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.pallet.ErpPalletMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockInApproveRecordMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockInItemMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockInItemPalletMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockInMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.redis.no.ErpNoRedisDAO;
|
|
|
|
|
@ -49,9 +54,11 @@ import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertListByFlatMap;
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
|
|
|
|
|
@ -71,6 +78,7 @@ import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.STOCK_IN_SUBM
|
|
|
|
|
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.STOCK_IN_SUBMIT_FAIL_USER;
|
|
|
|
|
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.STOCK_IN_UPDATE_FAIL_APPROVE;
|
|
|
|
|
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.STOCK_IN_UPDATE_FAIL_PROCESS;
|
|
|
|
|
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.PALLET_NOT_EXISTS;
|
|
|
|
|
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.WAREHOUSE_AREA_NOT_EXISTS;
|
|
|
|
|
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.WAREHOUSE_LOCATION_WAREHOUSE_AREA_NOT_MATCH;
|
|
|
|
|
|
|
|
|
|
@ -85,10 +93,14 @@ public class ErpStockInServiceImpl implements ErpStockInService {
|
|
|
|
|
@Resource
|
|
|
|
|
private ErpStockInItemMapper stockInItemMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private ErpStockInItemPalletMapper stockInItemPalletMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private ErpStockInApproveRecordMapper stockInApproveRecordMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private ErpStockMapper erpStockMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private ErpPalletMapper palletMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private ErpNoRedisDAO noRedisDAO;
|
|
|
|
|
@Resource
|
|
|
|
|
private ErpProductService productService;
|
|
|
|
|
@ -135,6 +147,7 @@ public class ErpStockInServiceImpl implements ErpStockInService {
|
|
|
|
|
stockInMapper.insert(stockIn);
|
|
|
|
|
stockInItems.forEach(item -> item.setInId(stockIn.getId()));
|
|
|
|
|
stockInItemMapper.insertBatch(stockInItems);
|
|
|
|
|
saveStockInItemPallets(stockIn.getId(), stockInItems, createReqVO.getItems());
|
|
|
|
|
|
|
|
|
|
if (createReqVO.getInType().equals("模具入库")){
|
|
|
|
|
//修改模具组状态
|
|
|
|
|
@ -174,6 +187,7 @@ public class ErpStockInServiceImpl implements ErpStockInService {
|
|
|
|
|
.setTotalPrice(getSumValue(stockInItems, ErpStockInItemDO::getTotalPrice, BigDecimal::add, BigDecimal.ZERO)));
|
|
|
|
|
stockInMapper.updateById(updateObj);
|
|
|
|
|
updateStockInItemList(updateReqVO.getId(), stockInItems);
|
|
|
|
|
saveStockInItemPallets(updateReqVO.getId(), stockInItems, updateReqVO.getItems());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@ -215,27 +229,12 @@ public class ErpStockInServiceImpl implements ErpStockInService {
|
|
|
|
|
throw exception(STOCK_IN_SUBMIT_FAIL_STATUS);
|
|
|
|
|
}
|
|
|
|
|
Integer fromStatus = stockIn.getStatus();
|
|
|
|
|
if (!Boolean.TRUE.equals(stockIn.getNeedAudit())) {
|
|
|
|
|
int updateCount = stockInMapper.updateByIdAndStatus(stockIn.getId(), fromStatus,
|
|
|
|
|
new ErpStockInDO().setStatus(ErpAuditStatus.APPROVE.getStatus()));
|
|
|
|
|
if (updateCount == 0) {
|
|
|
|
|
throw exception(STOCK_IN_SUBMIT_FAIL_STATUS);
|
|
|
|
|
}
|
|
|
|
|
List<ErpStockInItemDO> stockInItems = stockInItemMapper.selectListByInId(stockIn.getId());
|
|
|
|
|
applyStockInEffect(stockIn, stockInItems, null);
|
|
|
|
|
createApproveRecord(stockIn.getId(), ErpStockInApproveActionEnum.AUTO_APPROVE, fromStatus,
|
|
|
|
|
ErpAuditStatus.APPROVE.getStatus(), null,
|
|
|
|
|
submitReqVO.getRemark() != null ? submitReqVO.getRemark() : "无需审核,提交后自动入库");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Long auditUserId = submitReqVO.getAuditUserId() != null ? submitReqVO.getAuditUserId() : stockIn.getAuditUserId();
|
|
|
|
|
if (auditUserId == null) {
|
|
|
|
|
throw exception(STOCK_IN_SUBMIT_FAIL_AUDIT_USER_EMPTY);
|
|
|
|
|
if (auditUserId != null) {
|
|
|
|
|
adminUserApi.validateUser(auditUserId);
|
|
|
|
|
}
|
|
|
|
|
adminUserApi.validateUser(auditUserId);
|
|
|
|
|
ErpStockInDO updateObj = new ErpStockInDO()
|
|
|
|
|
.setAuditUserId(auditUserId)
|
|
|
|
|
.setNeedAudit(true)
|
|
|
|
|
.setStatus(ErpAuditStatus.PROCESS.getStatus());
|
|
|
|
|
int updateCount = stockInMapper.updateByIdAndStatus(stockIn.getId(), fromStatus, updateObj);
|
|
|
|
|
if (updateCount == 0) {
|
|
|
|
|
@ -249,8 +248,23 @@ public class ErpStockInServiceImpl implements ErpStockInService {
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void auditStockIn(ErpStockInAuditReqVO auditReqVO) {
|
|
|
|
|
ErpStockInDO stockIn = validateStockInExists(auditReqVO.getId());
|
|
|
|
|
if (!ErpAuditStatus.PROCESS.getStatus().equals(stockIn.getStatus())) {
|
|
|
|
|
throw exception(STOCK_IN_AUDIT_FAIL_STATUS);
|
|
|
|
|
// if (!ErpAuditStatus.PROCESS.getStatus().equals(stockIn.getStatus())) {
|
|
|
|
|
// throw exception(STOCK_IN_AUDIT_FAIL_STATUS);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
Integer fromStatus = stockIn.getStatus();
|
|
|
|
|
if (!needAudit()) {
|
|
|
|
|
int updateCount = stockInMapper.updateByIdAndStatus(stockIn.getId(), fromStatus,
|
|
|
|
|
new ErpStockInDO().setNeedAudit(false).setStatus(ErpAuditStatus.APPROVE.getStatus()));
|
|
|
|
|
if (updateCount == 0) {
|
|
|
|
|
throw exception(STOCK_IN_AUDIT_FAIL_STATUS);
|
|
|
|
|
}
|
|
|
|
|
List<ErpStockInItemDO> stockInItems = stockInItemMapper.selectListByInId(stockIn.getId());
|
|
|
|
|
applyStockInEffect(stockIn, stockInItems, null);
|
|
|
|
|
createApproveRecord(stockIn.getId(), ErpStockInApproveActionEnum.AUTO_APPROVE, fromStatus,
|
|
|
|
|
ErpAuditStatus.APPROVE.getStatus(), NumberUtils.parseLong(stockIn.getCreator()),
|
|
|
|
|
auditReqVO.getRemark() != null ? auditReqVO.getRemark() : "无需审核,审核时自动入库");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
|
|
|
|
|
boolean adminCanAudit = permissionApi.hasAnyRoles(loginUserId, RoleCodeEnum.SUPER_ADMIN.getCode());
|
|
|
|
|
@ -262,9 +276,8 @@ public class ErpStockInServiceImpl implements ErpStockInService {
|
|
|
|
|
throw exception(STOCK_IN_AUDIT_FAIL_RESULT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Integer fromStatus = stockIn.getStatus();
|
|
|
|
|
int updateCount = stockInMapper.updateByIdAndStatus(stockIn.getId(), fromStatus,
|
|
|
|
|
new ErpStockInDO().setStatus(auditReqVO.getStatus()));
|
|
|
|
|
new ErpStockInDO().setNeedAudit(true).setStatus(auditReqVO.getStatus()));
|
|
|
|
|
if (updateCount == 0) {
|
|
|
|
|
throw exception(STOCK_IN_AUDIT_FAIL_STATUS);
|
|
|
|
|
}
|
|
|
|
|
@ -297,6 +310,7 @@ public class ErpStockInServiceImpl implements ErpStockInService {
|
|
|
|
|
stockIns.forEach(stockIn -> {
|
|
|
|
|
stockInMapper.deleteById(stockIn.getId());
|
|
|
|
|
stockInItemMapper.deleteByInId(stockIn.getId());
|
|
|
|
|
stockInItemPalletMapper.deleteByInId(stockIn.getId());
|
|
|
|
|
stockInApproveRecordMapper.deleteByStockInId(stockIn.getId());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
@ -340,6 +354,19 @@ public class ErpStockInServiceImpl implements ErpStockInService {
|
|
|
|
|
return stockInItemMapper.selectListByInIds(inIds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<ErpStockInItemPalletDO> getStockInItemPalletListByInId(Long inId) {
|
|
|
|
|
return stockInItemPalletMapper.selectListByInId(inId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<ErpStockInItemPalletDO> getStockInItemPalletListByInIds(Collection<Long> inIds) {
|
|
|
|
|
if (CollUtil.isEmpty(inIds)) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
return stockInItemPalletMapper.selectListByInIds(inIds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<ErpStockInApproveRecordDO> getStockInApproveRecordList(Long stockInId) {
|
|
|
|
|
return stockInApproveRecordMapper.selectListByStockInId(stockInId);
|
|
|
|
|
@ -386,6 +413,7 @@ public class ErpStockInServiceImpl implements ErpStockInService {
|
|
|
|
|
recordBizType, stockInItem.getInId(), stockInItem.getId(), stockIn.getNo(), stockIn.getInTime()));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
operateStockInPalletEffect(stockIn.getId(), stockInItems, approve);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Integer resolveRecordBizType(String inType, boolean approve, Integer bizType) {
|
|
|
|
|
@ -445,6 +473,8 @@ public class ErpStockInServiceImpl implements ErpStockInService {
|
|
|
|
|
.packagingSchemeId(item.getPackagingSchemeId())
|
|
|
|
|
.inputUnitType(item.getInputUnitType())
|
|
|
|
|
.inputCount(item.getInputCount())
|
|
|
|
|
.relateTask(item.getRelateTask())
|
|
|
|
|
.taskId(item.getTaskId())
|
|
|
|
|
.totalPrice(MoneyUtils.priceMultiply(item.getProductPrice(), item.getCount()))
|
|
|
|
|
.remark(item.getRemark())
|
|
|
|
|
.deviceId(item.getDeviceId())
|
|
|
|
|
@ -452,6 +482,7 @@ public class ErpStockInServiceImpl implements ErpStockInService {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
validateWarehouseAreas(list);
|
|
|
|
|
validatePallets(list);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<ErpProductDO> productList = productService.validProductList(convertSet(list, ErpStockInSaveReqVO.Item::getProductId));
|
|
|
|
|
@ -468,6 +499,20 @@ public class ErpStockInServiceImpl implements ErpStockInService {
|
|
|
|
|
.setTotalPrice(MoneyUtils.priceMultiply(target.getProductPrice(), target.getCount()))));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void validatePallets(List<ErpStockInSaveReqVO.Item> list) {
|
|
|
|
|
List<Long> palletIds = convertListByFlatMap(list, item -> item.getPallets() == null ? java.util.stream.Stream.empty()
|
|
|
|
|
: item.getPallets().stream().map(ErpStockInSaveReqVO.Item.PalletItem::getPalletId));
|
|
|
|
|
if (CollUtil.isEmpty(palletIds)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Map<Long, ErpPalletDO> palletMap = convertMap(palletMapper.selectBatchIds(palletIds), ErpPalletDO::getId);
|
|
|
|
|
palletIds.forEach(palletId -> {
|
|
|
|
|
if (!palletMap.containsKey(palletId)) {
|
|
|
|
|
throw exception(PALLET_NOT_EXISTS);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void validateWarehouseAreas(List<ErpStockInSaveReqVO.Item> list) {
|
|
|
|
|
Map<Long, ErpWarehouseDO> warehouseMap = convertMap(
|
|
|
|
|
warehouseService.validWarehouseList(convertSet(list, ErpStockInSaveReqVO.Item::getWarehouseId)),
|
|
|
|
|
@ -513,4 +558,72 @@ public class ErpStockInServiceImpl implements ErpStockInService {
|
|
|
|
|
stockInItemMapper.deleteBatchIds(convertList(diffList.get(2), ErpStockInItemDO::getId));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void saveStockInItemPallets(Long inId, List<ErpStockInItemDO> stockInItems,
|
|
|
|
|
List<ErpStockInSaveReqVO.Item> reqItems) {
|
|
|
|
|
stockInItemPalletMapper.deleteByInId(inId);
|
|
|
|
|
if (CollUtil.isEmpty(stockInItems) || CollUtil.isEmpty(reqItems)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
List<ErpStockInItemPalletDO> palletRelations = CollUtil.newArrayList();
|
|
|
|
|
for (int i = 0; i < Math.min(stockInItems.size(), reqItems.size()); i++) {
|
|
|
|
|
ErpStockInItemDO stockInItem = stockInItems.get(i);
|
|
|
|
|
ErpStockInSaveReqVO.Item reqItem = reqItems.get(i);
|
|
|
|
|
if (stockInItem.getId() == null || CollUtil.isEmpty(reqItem.getPallets())) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
reqItem.getPallets().forEach(pallet -> palletRelations.add(ErpStockInItemPalletDO.builder()
|
|
|
|
|
.inId(inId)
|
|
|
|
|
.inItemId(stockInItem.getId())
|
|
|
|
|
.palletId(pallet.getPalletId())
|
|
|
|
|
.packageCount(defaultPackageCount(pallet.getPackageCount(), stockInItem.getCount()))
|
|
|
|
|
.build()));
|
|
|
|
|
}
|
|
|
|
|
if (CollUtil.isNotEmpty(palletRelations)) {
|
|
|
|
|
stockInItemPalletMapper.insertBatch(palletRelations);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void operateStockInPalletEffect(Long inId, List<ErpStockInItemDO> stockInItems, boolean approve) {
|
|
|
|
|
List<ErpStockInItemPalletDO> palletRelations = stockInItemPalletMapper.selectListByInId(inId);
|
|
|
|
|
if (CollUtil.isEmpty(palletRelations)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Map<Long, ErpStockInItemDO> itemMap = convertMap(stockInItems, ErpStockInItemDO::getId);
|
|
|
|
|
Map<Long, ErpPalletDO> palletMap = convertMap(palletMapper.selectBatchIds(
|
|
|
|
|
convertSet(palletRelations, ErpStockInItemPalletDO::getPalletId)), ErpPalletDO::getId);
|
|
|
|
|
palletRelations.forEach(relation -> {
|
|
|
|
|
ErpStockInItemDO item = itemMap.get(relation.getInItemId());
|
|
|
|
|
ErpPalletDO pallet = palletMap.get(relation.getPalletId());
|
|
|
|
|
if (item == null || pallet == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
BigDecimal packageCount = defaultZero(relation.getPackageCount());
|
|
|
|
|
if (approve) {
|
|
|
|
|
pallet.setStatus(ErpPalletStatusEnum.OCCUPIED.getStatus());
|
|
|
|
|
pallet.setProductId(item.getProductId());
|
|
|
|
|
pallet.setProductCount(defaultZero(pallet.getProductCount()).add(packageCount));
|
|
|
|
|
pallet.setWarehouseId(item.getWarehouseId());
|
|
|
|
|
pallet.setAreaId(item.getAreaId());
|
|
|
|
|
} else {
|
|
|
|
|
BigDecimal remainCount = defaultZero(pallet.getProductCount()).subtract(packageCount);
|
|
|
|
|
if (remainCount.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
|
pallet.setStatus(ErpPalletStatusEnum.IDLE.getStatus());
|
|
|
|
|
pallet.setProductId(null);
|
|
|
|
|
pallet.setProductCount(BigDecimal.ZERO);
|
|
|
|
|
} else {
|
|
|
|
|
pallet.setProductCount(remainCount);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
palletMapper.updateById(pallet);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private BigDecimal defaultPackageCount(BigDecimal packageCount, BigDecimal itemCount) {
|
|
|
|
|
return packageCount != null ? packageCount : defaultZero(itemCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private BigDecimal defaultZero(BigDecimal value) {
|
|
|
|
|
return value != null ? value : BigDecimal.ZERO;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|