#
zhou zhou
1 天以前 2ce6327ec49e7fe73cc1cd3bcc2b63b28d89d38f
rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/PdaOutStockServiceImpl.java
@@ -24,7 +24,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import jakarta.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
@@ -115,6 +115,9 @@
        if (!task.getResource().equals(TaskResouceType.TASK_RESOUCE_STOCK_UP.val)) {
            throw new CoolException("当前托盘不是备货出库任务");
        }
        if (Cools.isEmpty(param.getTaskItemList())) {
            throw new CoolException("任务明细为空");
        }
        WaitPakin waitPakin = waitPakinService
                .getOne(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getBarcode, param.getNewContainerNo()));
@@ -125,7 +128,7 @@
                throw new CoolException("编码规则错误: 编码规则「SYS_WAIT_PAKIN_CODE」规则是不存在");
            }
            waitPakin1.setCode(ruleCode)
                    .setIoStatus(PakinIOStatus.PAKIN_IO_STATUS_HOLD.val)
                    .setIoStatus(PakinIOStatus.PAKIN_IO_STATUS_DONE.val)
                    .setAnfme(param.getTaskItemList().stream()
                            .map(TaskItem::getInputQty)
                            .filter(Objects::nonNull)
@@ -236,6 +239,63 @@
            }
        }
        Map<Long, BigDecimal> taskItemInputQtyMap = param.getTaskItemList().stream()
                .filter(Objects::nonNull)
                .filter(e -> !Objects.isNull(e.getId()))
                .collect(Collectors.toMap(TaskItem::getId,
                        e -> Objects.isNull(e.getInputQty()) ? BigDecimal.ZERO : e.getInputQty(),
                        BigDecimal::add));
        if (taskItemInputQtyMap.isEmpty()) {
            throw new CoolException("任务明细参数错误");
        }
        List<TaskItem> toUpdateTaskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>()
                .eq(TaskItem::getTaskId, task.getId())
                .in(TaskItem::getId, taskItemInputQtyMap.keySet()));
        if (Cools.isEmpty(toUpdateTaskItems) || toUpdateTaskItems.size() != taskItemInputQtyMap.size()) {
            throw new CoolException("未找到对应任务明细");
        }
        toUpdateTaskItems.forEach(item -> {
            double currentWorkQty = Objects.isNull(item.getWorkQty()) ? 0D : item.getWorkQty();
            BigDecimal inputQty = taskItemInputQtyMap.getOrDefault(item.getId(), BigDecimal.ZERO);
            item.setWorkQty(BigDecimal.valueOf(currentWorkQty).add(inputQty).doubleValue())
                    .setUpdateBy(userId);
        });
        if (!taskItemService.updateBatchById(toUpdateTaskItems)) {
            throw new CoolException("任务明细更新失败");
        }
        //判断任务明细是否全部完成
        List<TaskItem> allTaskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>()
                .eq(TaskItem::getTaskId, task.getId()));
        if (Cools.isEmpty(allTaskItems)) {
            throw new CoolException("未找到任务明细");
        }
        boolean allTaskItemsFinished = allTaskItems.stream().allMatch(item -> {
            BigDecimal workQty = BigDecimal.valueOf(Objects.isNull(item.getWorkQty()) ? 0D : item.getWorkQty());
            BigDecimal qty = BigDecimal.valueOf(Objects.isNull(item.getAnfme()) ? 0D : item.getAnfme());
            return workQty.compareTo(qty) == 0;
        });
        if (allTaskItemsFinished) {
            task.setTaskStatus(TaskStsType.COMPLETE_OUT.id)
                    .setUpdateBy(userId)
                    .setUpdateTime(new Date());
            if (!taskService.updateById(task)) {
                throw new CoolException("任务状态更新失败");
            }
            if (task.getTaskType().equals(TaskType.TASK_TYPE_OUT.type)) {
                BasStation basStation = basStationService.getOne(new LambdaQueryWrapper<BasStation>()
                        .eq(BasStation::getBarcode, param.getContainerNo()));
                if (!Cools.isEmpty(basStation)) {
                    basStation.setUseStatus(LocStsType.LOC_STS_TYPE_D.type);
                    basStation.setUpdateTime(new Date());
                    if (!basStationService.updateById(basStation)){
                        throw new CoolException("站点状态更新失败");
                    }
                }
            }
        }
        return R.ok();
    }
@@ -244,7 +304,10 @@
        if (Cools.isEmpty(param.getContainerNo())) {
            throw new CoolException("无容器号");
        }
        Task task = taskService.getOne(new LambdaQueryWrapper<Task>().eq(Task::getBarcode, param.getContainerNo()));
        Task task = taskService.getOne(new LambdaQueryWrapper<Task>()
                .eq(Task::getBarcode, param.getContainerNo())
                .eq(Task::getTaskStatus, TaskStsType.AWAIT.id)
        );
        if (null == task) {
            throw new CoolException("未找到任务");
        }
@@ -417,7 +480,9 @@
            throw new CoolException("站点状态不为空闲");
        }
        List<Long> areaList = basStation.getCrossZoneArea();
        List<Long> areaList = basStation.getCrossZoneArea().stream()
                .map(Integer::longValue)
                .collect(Collectors.toList());
        if (Cools.isEmpty(areaList)) {
            throw new CoolException("当前站点库区未配置");
        }
@@ -471,3 +536,4 @@
                item -> new BigDecimal(item.getAnfme().toString()).equals(new BigDecimal(item.getQty().toString())));
    }
}