skyouc
2 天以前 03f63637e706283f1a95b7d0d6d631901ae359b2
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java
@@ -83,6 +83,14 @@
    private OutStockService outStockService;
    @Autowired
    private OutStockItemService outStockItemService;
    @Autowired
    private CheckOrderItemService checkOrderItemService;
    @Autowired
    private CheckOrderService checkOrderService;
    @Autowired
    private CheckDiffService checkDiffService;
    @Autowired
    private CheckDiffItemService checkDiffItemService;
    @Override
    @Transactional(rollbackFor = Exception.class)
@@ -681,7 +689,7 @@
            LocItemWorking locWorking = locItemWorkingService.getOne(new LambdaQueryWrapper<LocItemWorking>()
                    .eq(LocItemWorking::getTaskId, taskItem.getTaskId())
                    .eq(StringUtils.isNotBlank(taskItem.getBatch()), LocItemWorking::getBatch, taskItem.getBatch())
                    .eq(StringUtils.isNotBlank(taskItem.getFieldsIndex()), LocItemWorking::getFieldsIndex, taskItem.getFieldsIndex())
//                    .eq(StringUtils.isNotBlank(taskItem.getFieldsIndex()), LocItemWorking::getFieldsIndex, taskItem.getFieldsIndex())
                    .eq(LocItemWorking::getMatnrId, taskItem.getMatnrId()));
            if (Objects.isNull(locWorking)) {
                throw new CoolException("数据错误,作业中库存数据丢失!!");
@@ -742,7 +750,9 @@
                        .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_F.type))) {
                    throw new CoolException("源库位状态修改失败!!");
                }
                if (!locService.update(new LambdaUpdateWrapper<Loc>().eq(Loc::getCode, task.getTargLoc()).set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type))) {
                if (!locService.update(new LambdaUpdateWrapper<Loc>()
                        .eq(Loc::getCode, task.getTargLoc())
                        .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type))) {
                    throw new CoolException("移库目标库位状态修改失败!!");
                }
@@ -762,7 +772,40 @@
                    }
                }
            } else if (task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type)) {
                List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().in(TaskItem::getTaskId, Arrays.asList(ids)));
                if (!taskItems.isEmpty()) {
                    taskItems.forEach(taskItem -> {
                        if (!checkOrderItemService.update(new LambdaUpdateWrapper<WkOrderItem>()
                                .eq(WkOrderItem::getId, taskItem.getOrderItemId())
                                .setSql("work_qty = work_qty - " + taskItem.getAnfme()))) {
                            throw new CoolException("明细数量修改失败!!");
                        }
                        if (!checkOrderService.update(new LambdaUpdateWrapper<WkOrder>()
                                .eq(WkOrder::getId, taskItem.getOrderId())
                                .setSql("work_qty = work_qty - " + taskItem.getAnfme()))) {
                            throw new CoolException("盘点单执行数量修改失败!!");
                        }
                        List<CheckDiffItem> diffItems = checkDiffItemService
                                .list(new LambdaQueryWrapper<CheckDiffItem>()
                                .eq(CheckDiffItem::getTaskItemId, taskItem.getTaskId()));
                        if (!diffItems.isEmpty()) {
                            CheckDiffItem item = diffItems.stream().findFirst().get();
                            List<CheckDiffItem> items = checkDiffItemService.list(new LambdaQueryWrapper<CheckDiffItem>()
                                    .eq(CheckDiffItem::getId, item.getCheckId()));
                            if (items.isEmpty()) {
                                checkDiffService.removeById(item.getCheckId());
                            }
                        }
                    });
                }
                if (!locService.update(new LambdaUpdateWrapper<Loc>()
                        .eq(Loc::getCode, task.getOrgLoc())
                        .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_F.type))) {
                    throw new CoolException("源库位状态修改失败!!");
                }
            }
            if (!Objects.isNull(task.getWarehType()) && task.getWarehType().equals(WarehType.WAREHOUSE_TYPE_AGV.val)) {
@@ -797,7 +840,10 @@
                        if (Objects.isNull(loc)) {
                            throw new CoolException("数据错误:库位信息不存在!!");
                        }
                        loc.setUseStatus(LocStsType.LOC_STS_TYPE_F.type).setBarcode(task.getBarcode()).setUpdateBy(loginUserId).setUpdateTime(new Date());
                        loc.setUseStatus(LocStsType.LOC_STS_TYPE_F.type)
                                .setBarcode(task.getBarcode())
                                .setUpdateBy(loginUserId)
                                .setUpdateTime(new Date());
                        if (!locService.updateById(loc)) {
                            throw new CoolException("库位信息修改失败!!");
                        }
@@ -868,7 +914,8 @@
                        }
                        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, task.getTaskType() < TaskStsType.UPDATED_IN.id ? task.getTargLoc() : task.getOrgLoc()));
                        if (null != loc && (loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_S.type) || loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_R.type))) {
                        if (null != loc && (loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_S.type)
                                || loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_R.type))) {
                            loc.setUseStatus(LocStsType.LOC_STS_TYPE_O.type);
                            if (!locService.updateById(loc)) {
                                throw new CoolException("更新库位状态失败!!");
@@ -951,7 +998,7 @@
            LocItemWorking locWorking = locItemWorkingService.getOne(new LambdaQueryWrapper<LocItemWorking>()
                    .eq(LocItemWorking::getTaskId, taskItem.getTaskId())
                    .eq(StringUtils.isNotBlank(taskItem.getBatch()), LocItemWorking::getBatch, taskItem.getBatch())
                    .eq(StringUtils.isNotBlank(taskItem.getFieldsIndex()), LocItemWorking::getFieldsIndex, taskItem.getFieldsIndex())
//                    .eq(StringUtils.isNotBlank(taskItem.getFieldsIndex()), LocItemWorking::getFieldsIndex, taskItem.getFieldsIndex())
                    .eq(LocItemWorking::getMatnrId, taskItem.getMatnrId()));
            if (Objects.isNull(locWorking)) {
                throw new CoolException("数据错误,作业中库存数据丢失!!");
@@ -1051,32 +1098,32 @@
         * */
        List<TaskItem> list = listMap.get(Short.parseShort(OrderWorkType.ORDER_WORK_TYPE_STOCK_OUT.type));
        if (Objects.isNull(list) || list.isEmpty()) {
            Map<Long, List<TaskItem>> maps = taskItems.stream().collect(Collectors.groupingBy(TaskItem::getSource));
            maps.keySet().forEach(key -> {
                if (task.getResource().equals(TaskResouceType.TASK_RESOUCE_WAVE_TYPE.val)) {
                    WaveItem waveItem = waveItemService.getById(key);
                    if (Objects.isNull(waveItem)) {
                        throw new CoolException("波次明细不存在!!");
                    }
                    try {
                        saveOutStockItem(maps.get(key), null, waveItem, loginUserId);
                    } catch (Exception e) {
                        throw new CoolException(e.getMessage());
                    }
                } else if (task.getResource().equals(TaskResouceType.TASK_RESOUCE_ORDER_TYPE.val)) {
                    WkOrderItem orderItem = asnOrderItemService.getById(key);
                    if (Objects.isNull(orderItem)) {
                        throw new CoolException("单据明细不存在!!");
                    }
                    try {
                        saveOutStockItem(maps.get(key), orderItem, null, loginUserId);
                    } catch (Exception e) {
                        throw new CoolException(e.getMessage());
                    }
                } else {
                Map<Long, List<TaskItem>> maps = taskItems.stream().collect(Collectors.groupingBy(TaskItem::getSource));
                maps.keySet().forEach(key -> {
                    if (task.getResource().equals(TaskResouceType.TASK_RESOUCE_WAVE_TYPE.val)) {
                        WaveItem waveItem = waveItemService.getById(key);
                        if (Objects.isNull(waveItem)) {
                            throw new CoolException("波次明细不存在!!");
                        }
                        try {
                            saveOutStockItem(maps.get(key), null, waveItem, loginUserId);
                        } catch (Exception e) {
                            throw new CoolException(e.getMessage());
                        }
                    } else if (task.getResource().equals(TaskResouceType.TASK_RESOUCE_ORDER_TYPE.val) || task.getResource().equals(TaskResouceType.TASK_RESOUCE_CHECK_TYPE.val)) {
                        WkOrderItem orderItem = asnOrderItemService.getById(key);
                        if (Objects.isNull(orderItem)) {
                            throw new CoolException("单据明细不存在!!");
                        }
                        try {
                            saveOutStockItem(maps.get(key), orderItem, null, loginUserId);
                        } catch (Exception e) {
                            throw new CoolException(e.getMessage());
                        }
                    } else {
                }
            });
                    }
                });
        } else {
            try {
                saveOutStockItem(taskItems, null, null, loginUserId);