skyouc
2 天以前 83bebf33f2a141a13a7adef66d09b43145fc29e9
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java
@@ -545,7 +545,7 @@
        TaskItem taskItem = taskItems.stream().findFirst().get();
        //保存入出库流水
        saveStockItems(taskItems, null, null, taskItem.getWkType(), taskItem.getOrderType());
        saveStockItems(taskItems, task, null, null, taskItem.getWkType(), taskItem.getOrderType());
        if (!locItemWorkingService.remove(new LambdaQueryWrapper<LocItemWorking>().eq(LocItemWorking::getTaskId, task.getId()))) {
@@ -687,6 +687,38 @@
            throw new CoolException("任务状态更新失败!!");
        }
        List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()));
        for (int i = 0; i < taskItems.size(); i++) {
            TaskItem taskItem = taskItems.get(i);
            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(LocItemWorking::getMatnrId, taskItem.getMatnrId()));
            if (Objects.isNull(locWorking)) {
                throw new CoolException("数据错误,作业中库存数据丢失!!");
            }
            if (task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)) {
                locWorking.setWorkQty(0.0);
                locWorking.setAnfme(taskItem.getAnfme());
            } else {
                if (locWorking.getAnfme().compareTo(taskItem.getAnfme()) >= 0) {
                    locWorking.setWorkQty(0.0);
                    locWorking.setAnfme(Math.round((locWorking.getAnfme() - taskItem.getAnfme()) * 10000) / 10000.0);
                } else {
                    continue;
                }
            }
            if (!locItemWorkingService.updateById(locWorking)) {
                throw new CoolException("临时库存更新失败!!");
            }
            taskItems.get(i).setAnfme(locWorking.getAnfme());
        }
        if (!taskItemService.updateBatchById(taskItems)) {
            throw new CoolException("任务明细更新失败!!");
        }
        Loc one = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, task.getTargLoc()));
        if (Objects.isNull(one)) {
            throw new CoolException("目标库位不存在!!");
@@ -780,6 +812,7 @@
        /**修改为库位状态为O.空库*/
        if (!locService.update(new LambdaUpdateWrapper<Loc>()
                .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
                .set(Loc::getBarcode, null)
                .eq(Loc::getId, loc.getId()))) {
            throw new CoolException("库位状态修改失败!!");
        }
@@ -796,6 +829,11 @@
                    .set(Task::getTaskStatus, TaskStsType.UPDATED_OUT.id))) {
                throw new CoolException("库存状态更新失败!!");
            }
            //全板出库,删除临时库存
           if (!locItemWorkingService.remove(new LambdaQueryWrapper<LocItemWorking>().eq(LocItemWorking::getTaskId, task.getId()))) {
               throw new CoolException("临时库存清除失败!!");
           }
        }
@@ -900,7 +938,7 @@
            List<TaskItem> items = orderMap.get(key);
            try {
                //保存库存明细
                saveStockItems(items, pakinItem.getId(), pakinItem.getAsnCode(), pakinItem.getWkType(), pakinItem.getType());
                saveStockItems(items, task,  pakinItem.getId(), pakinItem.getAsnCode(), pakinItem.getWkType(), pakinItem.getType());
                //移出收货区库存, 修改组托状态
                removeReceiptStock(pakinItem);
            } catch (Exception e) {
@@ -988,7 +1026,7 @@
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public void saveStockItems(List<TaskItem> items, Long id, String code, Short wkType, String type) throws
    public void saveStockItems(List<TaskItem> items, Task task, Long id, String code, Short wkType, String type) throws
            Exception {
        Stock stock = new Stock();
        String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_STOCK_CODE, null);
@@ -1001,7 +1039,17 @@
                .setSourceCode(code)
                .setAnfme(sum)
                .setWkType(wkType)
                .setBarcode(task.getBarcode())
                .setType(type);
        if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type) ||
                task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_IN.type) ||
                task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type) ||
                task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_IN.type) ||
                task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type) ) {
            stock.setLocCode(task.getTargLoc());
        } else {
            stock.setLocCode(task.getOrgLoc());
        }
        if (!stockService.save(stock)) {
            throw new CoolException("库存保存失败!!");
        }
@@ -1013,6 +1061,7 @@
            BeanUtils.copyProperties(item, stockItem);
            stockItem.setSourceItemId(item.getOrderItemId())
                    .setStockCode(stock.getCode())
                    .setBarcode(task.getBarcode())
                    .setSourceItemId(item.getOrderItemId())
                    .setId(null)
                    .setStockId(stock.getId());