chen.lin
16 小时以前 409a68481bf07e3c3628d2b04cdbd113c72ac210
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java
@@ -508,22 +508,74 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Task operateComplete(Long id, Long loginUserId) {
        List<Integer> longs = Arrays.asList(TaskStsType.GENERATE_IN.id, TaskStsType.GENERATE_OUT.id);
        // 先查询任务,不限制状态
        Task task = taskService.getOne(new LambdaQueryWrapper<Task>()
                .eq(Task::getId, id)
                .in(Task::getTaskStatus, longs));
                .eq(Task::getId, id));
        if (Objects.isNull(task)) {
            throw new CoolException("数据错误:当前任务不可执行完结操作!!");
            throw new CoolException("任务不存在!!");
        }
        // 根据前端逻辑判断是否允许完成:
        // 前端条件:((taskStatus < 98) || (taskType >= 101 && taskStatus < 198)) || (taskType == 11 && taskStatus == 101)
        // 1. 任何任务状态 < 98 都可以完成
        // 2. 出库任务(taskType >= 101)且状态 < 198 可以完成
        // 3. 库格移载(taskType == 11)且状态 == 101 可以完成
        boolean canComplete = false;
        if (task.getTaskStatus() < TaskStsType.COMPLETE_IN.id) {
            // 任何任务状态 < 98 都可以完成
            canComplete = true;
        } else if (task.getTaskType() >= 101 && task.getTaskStatus() < TaskStsType.COMPLETE_OUT.id) {
            // 出库任务且状态 < 198
            canComplete = true;
        } else if (task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)
                && task.getTaskStatus().equals(TaskStsType.GENERATE_OUT.id)) {
            // 库格移载且状态 == 101
            canComplete = true;
        }
        if (!canComplete) {
            throw new CoolException("数据错误:当前任务不可执行完结操作!!任务类型:" + task.getTaskType() + ",任务状态:" + task.getTaskStatus());
        }
        modiftyTaskSort(task, loginUserId);
        //
//        if (task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
//            task.setTaskStatus(TaskStsType.COMPLETE_OUT.id);
//        } else {
        task.setTaskStatus(task.getTaskType() < 100 ? TaskStsType.COMPLETE_IN.id : TaskStsType.AWAIT.id);
//        }
        // 如果任务状态已经是AWAIT (196),再次点击完结时,直接完成
        if (task.getTaskStatus().equals(TaskStsType.AWAIT.id)) {
            // AWAIT状态的任务再次完结,直接设置为出库完成
            task.setTaskStatus(TaskStsType.COMPLETE_OUT.id);
            // 更新出库站点状态(与RCS通知完结保持一致)
            if (task.getTaskType() >= TaskType.TASK_TYPE_OUT.type && StringUtils.isNotBlank(task.getTargSite())) {
                BasStation station = basStationService.getOne(new LambdaQueryWrapper<BasStation>()
                        .eq(BasStation::getStationName, task.getTargSite()));
                if (Objects.nonNull(station) && station.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) {
                    station.setUseStatus(LocStsType.LOC_STS_TYPE_F.type);
                    if (!basStationService.updateById(station)) {
                        throw new CoolException("出库站点状态修改失败!!");
                    }
                }
            }
        } else {
            // 其他情况按原有逻辑处理
            // 入库任务(taskType < 100):设置为入库完成
            // 出库任务(taskType >= 100):设置为等待确认
            Integer newStatus = task.getTaskType() < 100 ? TaskStsType.COMPLETE_IN.id : TaskStsType.AWAIT.id;
            task.setTaskStatus(newStatus);
            // 如果是入库任务完成,更新入库站点状态(与RCS通知完结保持一致)
            if (newStatus.equals(TaskStsType.COMPLETE_IN.id) && StringUtils.isNotBlank(task.getOrgSite())) {
                BasStation station = basStationService.getOne(new LambdaQueryWrapper<BasStation>()
                        .eq(BasStation::getStationName, task.getOrgSite()));
                if (Objects.nonNull(station) && station.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) {
                    station.setUseStatus(LocStsType.LOC_STS_TYPE_O.type);
                    if (!basStationService.updateById(station)) {
                        throw new CoolException("入库站点状态修改失败!!");
                    }
                }
            }
        }
        if (!this.updateById(task)) {
            throw new CoolException("完成任务失败");
        }
@@ -733,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)) {
@@ -1165,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;
@@ -1183,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();
@@ -1264,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());
            }
        }
        //添加出入库记录信息
@@ -1845,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()));
    }
    /**
@@ -1889,8 +1942,10 @@
            List<TaskItem> items = orderMap.get(key);
            //保存入出库明细
            saveStockItems(items, task, pakinItem.getId(), pakinItem.getAsnCode(), pakinItem.getWkType(), pakinItem.getType(), loginUserId);
            //移出收货区库存, 修改组托状态
            removeReceiptStock(pakinItem, loginUserId);
            //移出收货区库存, 修改组托状态(只有当source不为null时才需要移除收货区库存)
            if (Objects.nonNull(pakinItem.getSource())) {
                removeReceiptStock(pakinItem, loginUserId);
            }
        });
        Set<Long> pkinItemIds = taskItems.stream().map(TaskItem::getSource).collect(Collectors.toSet());
@@ -1926,6 +1981,10 @@
     */
    @Transactional(rollbackFor = Exception.class)
    public synchronized void removeReceiptStock(WaitPakinItem pakinItem, Long loginUserId) {
        // 如果source为null,说明组托明细不在收货区,无需移除收货区库存
        if (Objects.isNull(pakinItem.getSource())) {
            return;
        }
        WarehouseAreasItem itemServiceOne = warehouseAreasItemService.getOne(new LambdaQueryWrapper<WarehouseAreasItem>()
                .eq(WarehouseAreasItem::getId, pakinItem.getSource()));
        if (Objects.isNull(itemServiceOne)) {
@@ -1973,7 +2032,8 @@
                    .eq(LocItem::getMatnrId, taskItem.getMatnrId())
                    .eq(LocItem::getLocId, loc.getId())
                    .eq(StringUtils.isNotBlank(taskItem.getBatch()), LocItem::getBatch, taskItem.getBatch())
                    .eq(StringUtils.isNotBlank(taskItem.getFieldsIndex()), LocItem::getFieldsIndex, taskItem.getFieldsIndex()));
                    .eq(StringUtils.isNotBlank(taskItem.getFieldsIndex()), LocItem::getFieldsIndex, taskItem.getFieldsIndex())
            );
            if (Objects.isNull(locItem)) {
                BeanUtils.copyProperties(taskItem, item);
                item.setLocCode(loc.getCode())
@@ -1986,7 +2046,7 @@
                    throw new CoolException("库位明细更新失败!!");
                }
            } else {
                logger.error("当前票号:"  + locItem.getFieldsIndex()  + " 已在库内,请检查后再操作!!");
//                logger.error("当前票号:"  + locItem.getFieldsIndex()  + " 已在库内,请检查后再操作!!");
//                throw new CoolException("当前票号已在库内,请检查后再操作!!");
//                locItem.setAnfme(Math.round((locItem.getAnfme() + taskItem.getAnfme()) * 1000000) / 1000000.0)
//                        .setUpdateTime(new Date());