skyouc
3 天以前 0215b398a204449d28d42f77362327e408b2f823
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java
@@ -453,25 +453,21 @@
     * @throws Exception
     */
    @Override
    public void complateInTask(List<Task> tasks) throws Exception {
    public void complateInTask(List<Task> tasks) {
        AtomicBoolean success = new AtomicBoolean(false);
        if (success.compareAndSet(false, true)) {
            Long loginUserId = SystemAuthUtils.getLoginUserId();
            for (Task task : tasks) {
                try {
                    if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)) {
                        //1.入库
                        complateInstock(task, loginUserId);
                    } else if (task.getTaskType().equals(TaskType.TASK_TYPE_PICK_IN.type) || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)) {
                        //53.拣料再入库
                        //57.盘点再入库
                        pickComplateInStock(task, loginUserId);
                    } else if (task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
                        //移库
                        moveInStock(task, loginUserId);
                    }
                } catch (Exception ex) {
                    log.error(ex.getMessage(), ex);
                if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)) {
                    //1.入库
                    complateInstock(task, loginUserId);
                } else if (task.getTaskType().equals(TaskType.TASK_TYPE_PICK_IN.type) || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)) {
                    //53.拣料再入库
                    //57.盘点再入库
                    pickComplateInStock(task, loginUserId);
                } else if (task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
                    //移库
                    moveInStock(task, loginUserId);
                }
            }
        }
@@ -707,7 +703,7 @@
     * @param loginUserId
     */
    @Transactional(rollbackFor = Exception.class)
    public void pickComplateInStock(Task task, Long loginUserId) throws Exception {
    public void pickComplateInStock(Task task, Long loginUserId) {
        if (Objects.isNull(task)) {
            return;
        }
@@ -737,16 +733,16 @@
            LocItemWorking locWorking = locItemWorkingService.getOne(new LambdaQueryWrapper<LocItemWorking>()
                    .eq(LocItemWorking::getTaskId, taskItem.getTaskId())
                    .eq(LocItemWorking::getFieldsIndex, taskItem.getFieldsIndex())
                    .eq(StringUtils.isNotBlank(taskItem.getBatch()), LocItemWorking::getBatch, taskItem.getBatch())
                    .eq(StringUtils.isNotEmpty(taskItem.getBatch()), LocItemWorking::getBatch, taskItem.getBatch())
                    .eq(LocItemWorking::getMatnrId, taskItem.getMatnrId()));
            if (Objects.isNull(locWorking)) {
                throw new CoolException("数据错误,作业中库存数据丢失!!");
               continue;
            }
            if (task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)) {
                locWorking.setAnfme(taskItem.getAnfme());
            }
            BeanUtils.copyProperties(locWorking, locItem);
            locItem.setWorkQty(0.0).setLocCode(loc.getCode()).setLocId(loc.getId()).setId(null).setUpdateBy(loginUserId).setUpdateTime(new Date());
            locItem.setWorkQty(0.0).setQty(0.0).setLocCode(loc.getCode()).setLocId(loc.getId()).setId(null).setUpdateBy(loginUserId).setUpdateTime(new Date());
            items.add(locItem);
        }
@@ -756,7 +752,7 @@
        TaskItem taskItem = taskItems.stream().findFirst().get();
        //保存入出库流水
        saveStockItems(taskItems, task, null, null, taskItem.getWkType(), taskItem.getOrderType(), loginUserId);
        saveStockItems(taskItems, task, null, null, taskItem.getWkType(), OrderType.ORDER_IN.type, loginUserId);
        locItemWorkingService.remove(new LambdaQueryWrapper<LocItemWorking>().eq(LocItemWorking::getTaskId, task.getId()));
@@ -899,7 +895,7 @@
                            if (Objects.isNull(waveItem)) {
                                throw new CoolException("波次明细不存在!!");
                            }
                            Double workQty = Math.round((waveItem.getWorkQty() - item.getAnfme()) * 100) / 100.0;
                            Double workQty = Math.round((waveItem.getWorkQty() - item.getAnfme()) * 1000000) / 1000000.0;
                            waveItem.setWorkQty(workQty).setExceStatus(WaveItemExceStatus.WAVE_ITEM_EXCE_STATUS_UN.val);
                            if (!waveItemService.updateById(waveItem)) {
                                throw new CoolException("波次明细更新失败!!");
@@ -923,7 +919,7 @@
                            if (Objects.isNull(wkOrder)) {
                                throw new CoolException("数据错误:单据已不存在!!");
                            }
                            Double workQty = Math.round((wkOrder.getWorkQty() - item.getAnfme()) * 100) / 100.0;
                            Double workQty = Math.round((wkOrder.getWorkQty() - item.getAnfme()) * 1000000) / 1000000.0;
                            wkOrder.setExceStatus(AsnExceStatus.OUT_STOCK_STATUS_TASK_INIT.val)
                                    .setWorkQty(workQty.compareTo(0.00) > 0 ? workQty : 0.00)
@@ -938,7 +934,7 @@
                                throw new CoolException("数据错误:单据明细已不存在!!");
                            }
                            Double workItmQty = Math.round((orderItem.getWorkQty() - item.getAnfme()) * 100) / 100.0;
                            Double workItmQty = Math.round((orderItem.getWorkQty() - item.getAnfme()) * 1000000) / 1000000.0;
                            orderItem.setWorkQty(workItmQty);
                            if (!outStockItemService.updateById(orderItem)) {
@@ -1048,12 +1044,12 @@
        tempLocs.forEach(working -> {
            taskItems.forEach(taskItem -> {
                if (taskItem.getId().equals(working.getMatnrId()) && taskItem.getFieldsIndex().equals(working.getFieldsIndex())) {
                if (taskItem.getFieldsIndex().equals(working.getFieldsIndex())) {
                    Double minQty = taskItem.getAnfme();
                    if (!task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)) {
                        minQty = Math.round((working.getAnfme() - taskItem.getAnfme()) * 100) / 100.0;
                        minQty = Math.round((working.getAnfme() - taskItem.getQty()) * 1000000) / 1000000.0;
                    }
                    if (minQty.compareTo(0.0) > 0) {
                    if (minQty.compareTo(0.0) >= 0) {
                        taskItem.setAnfme(minQty);
                        if (!taskItemService.updateById(taskItem)) {
                            throw new CoolException("任务明细修改失败!!");
@@ -1075,7 +1071,6 @@
            TaskItem taskItem = taskItems.stream().findFirst().get();
            taskItem.setMatnrId(working.getMatnrId())
                    .setMaktx(working.getMaktx())
                    .setMatnrId(working.getMatnrId())
                    .setMatnrCode(working.getMatnrCode())
                    .setSpec(working.getSpec())
                    .setAnfme(working.getAnfme())
@@ -1104,6 +1099,7 @@
                LocItemWorking itemWorking = new LocItemWorking();
                BeanUtils.copyProperties(taskItem, itemWorking);
                itemWorking.setTaskId(task.getId())
                        .setQty(0.0)
                        .setLocId(loc1.getId())
                        .setLocCode(loc1.getCode());
                workings.add(itemWorking);
@@ -1309,7 +1305,7 @@
            stock.setSourceId(waveItem.getId()).setType(OrderType.ORDER_OUT.type);
        } else if (!Objects.isNull(orderItem) && StringUtils.isNotBlank(orderItem.getId() + "")) {
            WkOrder wkOrder = asnOrderService.getById(orderItem.getOrderId());
            Double qty = Math.round((wkOrder.getQty() + sum) * 100) / 100.0;
            Double qty = Math.round((wkOrder.getQty() + sum) * 1000000) / 1000000.0;
            wkOrder.setExceStatus(AsnExceStatus.OUT_STOCK_STATUS_TASK_WORKING.val)
                    .setQty(qty);
            if (!asnOrderService.updateById(wkOrder)) {
@@ -1584,12 +1580,9 @@
        if (taskItems.isEmpty()) {
            throw new CoolException("任务明细不存在!!");
        }
        try {
            //更新库位明细
            saveLocItem(taskItems, task.getId(), loginUserId);
        } catch (Exception e) {
            throw new CoolException("库位明细更新失败!!");
        }
        //更新库位明细
        saveLocItem(taskItems, task.getId(), loginUserId);
        /**对任务明细按组拖明细进行分组*/
        Map<Long, List<TaskItem>> orderMap = taskItems.stream().collect(Collectors.groupingBy(TaskItem::getSource));
@@ -1599,15 +1592,10 @@
                throw new CoolException("数据错误:组拖数据不存在,请联系管理员!!");
            }
            List<TaskItem> items = orderMap.get(key);
            try {
                //保存库存明细
                saveStockItems(items, task, pakinItem.getId(), pakinItem.getAsnCode(), pakinItem.getWkType(), pakinItem.getType(), loginUserId);
                //移出收货区库存, 修改组托状态
                removeReceiptStock(pakinItem, loginUserId);
            } catch (Exception e) {
                logger.error("<UNK>", e);
                throw new CoolException(e.getMessage());
            }
            //保存入出库明细
            saveStockItems(items, task, pakinItem.getId(), pakinItem.getAsnCode(), pakinItem.getWkType(), pakinItem.getType(), loginUserId);
            //移出收货区库存, 修改组托状态
            removeReceiptStock(pakinItem, loginUserId);
        });
        /**修改库位状态为F.在库*/
        if (!locService.update(new LambdaUpdateWrapper<Loc>().set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_F.type).eq(Loc::getCode, task.getTargLoc()))) {
@@ -1633,8 +1621,8 @@
        if (Objects.isNull(itemServiceOne)) {
            throw new CoolException("数据错误:请查看请货区库存是否存在!!");
        }
        Double workQty = Math.round((itemServiceOne.getWorkQty() - pakinItem.getAnfme()) * 100) / 100.0;
        Double qty = Math.round((itemServiceOne.getQty() + pakinItem.getAnfme()) * 100) / 100.0;
        Double workQty = Math.round((itemServiceOne.getWorkQty() - pakinItem.getAnfme()) * 1000000) / 1000000.0;
        Double qty = Math.round((itemServiceOne.getQty() + pakinItem.getAnfme()) * 1000000) / 1000000.0;
        itemServiceOne.setWorkQty(workQty).setQty(qty);
        if (!waitPakinService.update(new LambdaUpdateWrapper<WaitPakin>()
@@ -1665,7 +1653,7 @@
     * @time 2025/4/15 15:28
     */
    @Transactional(rollbackFor = Exception.class)
    public synchronized void saveLocItem(List<TaskItem> items, Long taskId, Long loginUserId) throws Exception {
    public synchronized void saveLocItem(List<TaskItem> items, Long taskId, Long loginUserId) {
        Task task = this.getById(taskId);
        if (Objects.isNull(task)) {
            throw new CoolException("任务不存在!!");
@@ -1681,8 +1669,8 @@
            LocItem locItem = locItemService.getOne(new LambdaQueryWrapper<LocItem>()
                    .eq(LocItem::getMatnrId, taskItem.getMatnrId())
                    .eq(LocItem::getLocId, loc.getId())
                    .eq(StringUtils.isNoneBlank(taskItem.getBatch()), LocItem::getBatch, taskItem.getBatch())
                    .eq(StringUtils.isNoneBlank(taskItem.getFieldsIndex()), LocItem::getFieldsIndex, taskItem.getFieldsIndex()));
                    .eq(StringUtils.isNotBlank(taskItem.getBatch()), LocItem::getBatch, taskItem.getBatch())
                    .eq(StringUtils.isNotBlank(taskItem.getFieldsIndex()), LocItem::getFieldsIndex, taskItem.getFieldsIndex()));
            if (Objects.isNull(locItem)) {
                BeanUtils.copyProperties(taskItem, item);
                item.setLocCode(loc.getCode())
@@ -1691,16 +1679,20 @@
                        .setUpdateBy(loginUserId)
                        .setWkType(taskItem.getWkType())
                        .setType(taskItem.getOrderType());
                locItems.add(item);
                if (!locItemService.saveOrUpdate(item)) {
                    throw new CoolException("库位明细更新失败!!");
                }
            } else {
                locItem.setAnfme(Math.round((locItem.getAnfme() + taskItem.getAnfme()) * 100) / 100.0)
                        .setUpdateTime(new Date());
                locItems.add(locItem);
                logger.error("当前票号:"  + locItem.getFieldsIndex()  + " 已在库内,请检查后再操作!!");
//                throw new CoolException("当前票号已在库内,请检查后再操作!!");
//                locItem.setAnfme(Math.round((locItem.getAnfme() + taskItem.getAnfme()) * 1000000) / 1000000.0)
//                        .setUpdateTime(new Date());
//                if (!locItemService.saveOrUpdate(locItem)) {
//                    throw new CoolException("库位明细更新失败!!");
//                }
            }
        });
        if (!locItemService.saveBatch(locItems)) {
            throw new CoolException("库位明细更新失败!!");
        }
    }
    /**