chen.lin
4 小时以前 409a68481bf07e3c3628d2b04cdbd113c72ac210
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java
@@ -785,7 +785,7 @@
            LocItem locItem = new LocItem();
            LocItemWorking locWorking = locItemWorkingService.getOne(new LambdaQueryWrapper<LocItemWorking>()
                    .eq(LocItemWorking::getTaskId, taskItem.getTaskId())
                    .eq(LocItemWorking::getFieldsIndex, taskItem.getFieldsIndex())
                    .eq(StringUtils.isNotBlank(taskItem.getFieldsIndex()), LocItemWorking::getFieldsIndex, taskItem.getFieldsIndex())
                    .eq(StringUtils.isNotEmpty(taskItem.getBatch()), LocItemWorking::getBatch, taskItem.getBatch())
                    .eq(LocItemWorking::getMatnrId, taskItem.getMatnrId()));
            if (Objects.isNull(locWorking)) {
@@ -1217,7 +1217,7 @@
        tempLocs.forEach(working -> {
            taskItems.forEach(taskItem -> {
                if (taskItem.getFieldsIndex().equals(working.getFieldsIndex())) {
                if (Objects.equals(taskItem.getFieldsIndex(), working.getFieldsIndex())) {
                    Double minQty = taskItem.getAnfme();
                    if (!task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)) {
                        minQty = Math.round((working.getAnfme() - taskItem.getQty()) * 1000000) / 1000000.0;
@@ -1235,10 +1235,13 @@
                }
            });
        });
        List<String> matnrIds = taskItems.stream().map(TaskItem::getFieldsIndex).collect(Collectors.toList());
        List<String> matnrIds = taskItems.stream()
                .map(TaskItem::getFieldsIndex)
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
        //删除与任务明细重复的库存信息,以任务明细为准
        List<LocItemWorking> itemWorkings = tempLocs.stream()
                .filter(working -> !matnrIds.contains(working.getFieldsIndex()))
                .filter(working -> working.getFieldsIndex() != null && !matnrIds.contains(working.getFieldsIndex()))
                .collect(Collectors.toList());
        itemWorkings.forEach(working -> {
            TaskItem taskItem = taskItems.stream().findFirst().get();
@@ -1316,32 +1319,31 @@
        }
        List<LocItem> locItems = locItemService.list(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocId, loc.getId()));
        if (locItems.isEmpty()) {
            throw new CoolException("库位明细不存在!!");
        }
        // 如果库位明细为空,可能是已经被处理过了,允许继续执行
        if (!locItems.isEmpty()) {
            List<LocItemWorking> workings = new ArrayList<>();
            for (LocItem item : locItems) {
                LocItemWorking working = new LocItemWorking();
                BeanUtils.copyProperties(item, working);
                working.setId(null)
                        .setTaskId(task.getId())
                        .setLocItemId(item.getId())
                        .setUpdateBy(loginUserId)
                        .setUpdateTime(new Date());
                workings.add(working);
            }
        List<LocItemWorking> workings = new ArrayList<>();
        for (LocItem item : locItems) {
            LocItemWorking working = new LocItemWorking();
            BeanUtils.copyProperties(item, working);
            working.setId(null)
                    .setTaskId(task.getId())
                    .setLocItemId(item.getId())
                    .setUpdateBy(loginUserId)
                    .setUpdateTime(new Date());
            workings.add(working);
        }
            if (!workings.isEmpty() && !locItemWorkingService.saveBatch(workings)) {
                throw new CoolException("临时库存保存失败!!");
            }
        if (!locItemWorkingService.saveBatch(workings)) {
            throw new CoolException("临时库存保存失败!!");
        }
        try {
            //更新库位明细
            subtractLocItem(loc);
        } catch (Exception e) {
            logger.error("<UNK>", e);
            throw new CoolException(e.getMessage());
            try {
                //更新库位明细
                subtractLocItem(loc);
            } catch (Exception e) {
                logger.error("<UNK>", e);
                throw new CoolException(e.getMessage());
            }
        }
        //添加出入库记录信息
@@ -1897,9 +1899,8 @@
     */
    @Transactional(rollbackFor = Exception.class)
    public void subtractLocItem(Loc loc) throws Exception {
        if (!locItemService.remove(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocId, loc.getId()))) {
            throw new CoolException("库存明细删除失败!!");
        }
        // 删除库位明细,如果没有记录则忽略(可能已经被删除过了)
        locItemService.remove(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocId, loc.getId()));
    }
    /**