cl
21 小时以前 8943a4e9f5ee1455c56ac4af60d941fa23731051
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java
@@ -4,7 +4,6 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.cfg.CoercionAction;
import com.fasterxml.jackson.databind.cfg.CoercionInputShape;
@@ -13,6 +12,7 @@
import com.vincent.rsf.server.api.config.RemotesInfoProperties;
import com.vincent.rsf.server.api.controller.erp.params.InOutResultReportParam;
import com.vincent.rsf.server.api.controller.erp.params.TaskInParam;
import com.vincent.rsf.server.api.service.RcsBusTaskNoticeService;
import com.vincent.rsf.server.api.entity.CommonResponse;
import com.vincent.rsf.server.api.entity.constant.RcsConstant;
import com.vincent.rsf.server.api.entity.dto.InTaskMsgDto;
@@ -55,8 +55,11 @@
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
@@ -131,6 +134,8 @@
    private CloudWmsNotifyLogService cloudWmsNotifyLogService;
    @Autowired
    private WarehouseService warehouseService;
    @Autowired
    private RcsBusTaskNoticeService rcsBusTaskNoticeService;
    @Override
    @Transactional(rollbackFor = Exception.class)
@@ -172,7 +177,9 @@
                throw new CoolException("任务保存失败!!");
            }
            if (!locService.update(new LambdaUpdateWrapper<Loc>().eq(Loc::getCode, task.getTargLoc())
                    .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_S.type).set(Loc::getBarcode, pakin.getBarcode()))) {
                    .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_S.type)
                    .set(Loc::getBarcode, pakin.getBarcode())
                    .set(Loc::getWeight, task.getWeight()))) {
                throw new CoolException("库位预约失败!!");
            }
            /**获取组拖明细**/
@@ -261,7 +268,8 @@
                    .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_S.type)
                    .set(Loc::getUpdateBy, loginUserId)
                    .set(Loc::getUpdateTime, new Date())
                    .set(Loc::getBarcode, pakin.getBarcode()))) {
                    .set(Loc::getBarcode, pakin.getBarcode())
                    .set(Loc::getWeight, task.getWeight()))) {
                throw new CoolException("库位预约失败!!");
            }
            /**获取组拖明细**/
@@ -403,7 +411,9 @@
            if (!locService.update(new LambdaUpdateWrapper<Loc>().eq(Loc::getCode, task.getTargLoc())
                    .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_S.type).set(Loc::getBarcode, pakin.getBarcode()))) {
                    .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_S.type)
                    .set(Loc::getBarcode, pakin.getBarcode())
                    .set(Loc::getWeight, task.getWeight()))) {
                throw new CoolException("库位预约失败!!");
            }
            /**获取组拖明细**/
@@ -509,7 +519,7 @@
    }
    /**
     * 手动完成任务
     * 手动完成任务:入库类置 98、出库类置 198,库位/单据扣减与上报由对应定时任务执行
     *
     * @param id
     * @param loginUserId
@@ -549,13 +559,22 @@
        }
        modiftyTaskSort(task, loginUserId);
        // 如果任务状态已经是AWAIT (196),再次点击完结时,直接完成
        if (task.getTaskStatus().equals(TaskStsType.AWAIT.id)) {
            // AWAIT状态的任务再次完结,直接设置为出库完成
        // 入库:->98,出库:-> 198,由 complateOutStock 定时任务 更新库存
        if (task.getTaskType() < 100) {
            task.setTaskStatus(TaskStsType.COMPLETE_IN.id);
            if (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("入库站点状态修改失败!!");
                    }
                }
            }
        } else {
            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()));
@@ -566,28 +585,17 @@
                    }
                }
            }
        } 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("入库站点状态修改失败!!");
                    }
                }
            }
        }
        // 原:196 时再点一次才置 198;出库首次点击曾置 196(AWAIT)
        // if (task.getTaskStatus().equals(TaskStsType.AWAIT.id)) { task.setTaskStatus(TaskStsType.COMPLETE_OUT.id); ... }
        // else { Integer newStatus = task.getTaskType() < 100 ? COMPLETE_IN.id : AWAIT.id; ... }
        
        if (!this.updateById(task)) {
            throw new CoolException("完成任务失败");
        }
        // 管理后台「完成任务」通知 RCS
        if (StringUtils.isNotBlank(task.getTaskCode())) {
            rcsBusTaskNoticeService.notifyTaskStatus(task.getTaskCode(), task.getTaskStatus());
        }
        return task;
    }
@@ -597,11 +605,12 @@
     *
     * @param id 任务ID
     * @param loginUserId 登录用户ID
     * @param notifyRcsFromAdmin 管理后台全版出库完结接口为 true 时通知 RCS;定时/PDA 等为 false
     * @return 任务对象
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Task completeFullOutStock(Long id, Long loginUserId) {
    public Task completeFullOutStock(Long id, Long loginUserId, boolean notifyRcsFromAdmin) {
        // 查询任务
        Task task = taskService.getOne(new LambdaQueryWrapper<Task>()
                .eq(Task::getId, id));
@@ -641,6 +650,7 @@
        // 将库位状态设为空(O状态)
        if (!locService.update(new LambdaUpdateWrapper<Loc>()
                .set(Loc::getBarcode, null)
                .set(Loc::getWeight, null)
                .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
                .set(Loc::getUpdateBy, loginUserId)
                .set(Loc::getUpdateTime, new Date())
@@ -668,6 +678,9 @@
        if (!this.updateById(task)) {
            throw new CoolException("任务状态更新失败!!");
        }
        if (notifyRcsFromAdmin && StringUtils.isNotBlank(task.getTaskCode())) {
            rcsBusTaskNoticeService.notifyTaskStatus(task.getTaskCode(), TaskStsType.UPDATED_OUT.id);
        }
        return task;
    }
@@ -682,6 +695,11 @@
        String curLoc;
        if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)) {
            curLoc = task.getTargLoc();
        } else if (task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_IN.type)) {
            curLoc = task.getTargLoc();
            if (StringUtils.isBlank(curLoc)) {
                return task;
            }
        } else {
            curLoc = task.getOrgLoc();
        }
@@ -792,6 +810,7 @@
        /**修改库位状态为F.在库*/
        if (!locService.update(new LambdaUpdateWrapper<Loc>()
                .set(Loc::getBarcode, task.getBarcode())
                .set(Loc::getWeight, task.getWeight())
                .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_F.type)
                .set(Loc::getUpdateBy, loginUserId)
                .set(Loc::getUpdateTime, new Date())
@@ -801,6 +820,7 @@
        if (!locService.update(new LambdaUpdateWrapper<Loc>()
                .set(Loc::getBarcode, null)
                .set(Loc::getWeight, null)
                .set(Loc::getUpdateBy, loginUserId)
                .set(Loc::getUpdateTime, new Date())
                .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
@@ -863,6 +883,7 @@
//        }
        loc.setUseStatus(LocStsType.LOC_STS_TYPE_F.type)
                .setBarcode(task.getBarcode())
                .setWeight(task.getWeight())
                .setUpdateBy(loginUserId).setUpdateTime(new Date());
        if (!locService.updateById(loc)) {
@@ -935,14 +956,24 @@
        List<Integer> list = Arrays.asList(TaskType.TASK_TYPE_IN.type, TaskType.TASK_TYPE_OUT.type, TaskType.TASK_TYPE_PICK_AGAIN_OUT.type,
                TaskType.TASK_TYPE_CHECK_OUT.type, TaskType.TASK_TYPE_EMPITY_IN.type, TaskType.TASK_TYPE_LOC_MOVE.type,
                TaskType.TASK_TYPE_EMPITY_OUT.type, TaskType.TASK_TYPE_MERGE_OUT.type);
        List<Task> allTasks = this.list(new LambdaQueryWrapper<Task>()
                .in(Task::getTaskType, list)
                .in(Task::getId, (Object[]) ids));
        if (allTasks.isEmpty()) {
        List<Task> tasksById = this.list(new LambdaQueryWrapper<Task>().in(Task::getId, (Object[]) ids));
        if (tasksById.isEmpty()) {
            throw new CoolException("任务不存在!!");
        }
        // 拣料出库/盘点出库进入再入库阶段后禁止取消(任务类型已由 103/107 变为再入库)
        for (Task t : tasksById) {
            if (TaskType.TASK_TYPE_PICK_IN.type.equals(t.getTaskType())
                    || TaskType.TASK_TYPE_CHECK_IN.type.equals(t.getTaskType())) {
                throw new CoolException("拣料/盘点出库已进入再入库阶段,禁止取消!!");
            }
        }
        List<Task> allTasks = tasksById.stream()
                .filter(t -> list.contains(t.getTaskType()))
                .collect(Collectors.toList());
        if (allTasks.isEmpty()) {
            throw new CoolException("当前任务类型不支持取消!!");
        }
        // 收集需要取消的RCS任务编号和批次编号(不限制状态,只要已下发到RCS就需要取消)
        List<String> rcsTaskCodes = new ArrayList<>();
        String batchNo = null;
@@ -979,59 +1010,60 @@
            }
        }
        
        // 如果有任务已下发到RCS,先调用RCS取消接口
        // 已下发 RCS 的工作档:必须先调 RCS 取消接口成功,否则不允许取消工作档
        boolean rcsCancelSuccess = false;
        if (!rcsTaskCodes.isEmpty()) {
            // 检查 RCS API 配置是否有效
            if (rcsApi == null || StringUtils.isBlank(rcsApi.getHost()) || StringUtils.isBlank(rcsApi.getPort())) {
                log.error("========== RCS任务取消失败 ==========");
                log.error("RCS API 配置无效!host: {}, port: {}",
                        rcsApi != null ? rcsApi.getHost() : "null",
                        rcsApi != null ? rcsApi.getPort() : "null");
                // 即使配置无效,也继续执行任务删除操作
            } else {
                try {
                    log.info("========== 开始取消RCS任务 ==========");
                    log.info("需要取消的RCS任务编号:{}", rcsTaskCodes);
                    String rcsUrl = rcsApi.getHost() + ":" + rcsApi.getPort() + RcsConstant.cancelTask;
                    log.info("RCS取消任务请求地址:{}", rcsUrl);
                // 如果没有批次编号,使用第一个任务编号作为批次编号
                if (StringUtils.isBlank(batchNo) && !rcsTaskCodes.isEmpty()) {
                throw new CoolException("任务已下发RCS,但未配置RCS地址,无法取消!!");
            }
            if (restTemplate == null) {
                throw new CoolException("任务已下发RCS,但无法调用RCS取消接口,无法取消!!");
            }
            try {
                log.info("========== 开始取消RCS任务 ==========");
                log.info("需要取消的RCS任务编号:{}", rcsTaskCodes);
                String rcsUrl = rcsApi.getHost() + ":" + rcsApi.getPort() + RcsConstant.cancelTask;
                log.info("RCS取消任务请求地址:{}", rcsUrl);
                if (StringUtils.isBlank(batchNo)) {
                    batchNo = rcsTaskCodes.get(0);
                }
                Map<String, Object> cancelParams = new HashMap<>();
                cancelParams.put("tasks", rcsTaskCodes);
                if (StringUtils.isNotBlank(batchNo)) {
                    cancelParams.put("batchNo", batchNo);
                }
                log.info("RCS取消任务请求参数:{}", JSONObject.toJSONString(cancelParams));
                HttpHeaders headers = new HttpHeaders();
                headers.add("Content-Type", "application/json");
                headers.add("api-version", "v2.0");
                HttpEntity<Map<String, Object>> httpEntity = new HttpEntity<>(cancelParams, headers);
                long startTime = System.currentTimeMillis();
                ResponseEntity<String> exchange = restTemplate.exchange(rcsUrl, HttpMethod.POST, httpEntity, String.class);
                long endTime = System.currentTimeMillis();
                log.info("RCS取消任务响应耗时:{}ms", (endTime - startTime));
                log.info("RCS取消任务响应状态码:{}", exchange.getStatusCode());
                log.info("RCS取消任务响应体:{}", exchange.getBody());
                if (!exchange.getStatusCode().is2xxSuccessful()) {
                    throw new CoolException("RCS取消任务失败:HTTP " + exchange.getStatusCode().value());
                }
                if (Objects.isNull(exchange.getBody())) {
                    log.error("RCS取消任务失败:响应体为空");
                    throw new CoolException("RCS取消任务失败:响应体为空");
                }
                ObjectMapper objectMapper = new ObjectMapper();
                objectMapper.coercionConfigDefaults()
                        .setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
                CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
                if (result.getCode() == 200) {
                    log.info("========== RCS任务取消成功 ==========");
                    log.info("成功取消的RCS任务编号:{}", rcsTaskCodes);
@@ -1040,22 +1072,28 @@
                    log.error("RCS取消任务失败:{}", result.getMsg());
                    throw new CoolException("RCS取消任务失败:" + result.getMsg());
                }
                } catch (JsonProcessingException e) {
                    log.error("RCS取消任务响应解析失败:{}", e.getMessage(), e);
                    throw new CoolException("RCS取消任务响应解析失败:" + e.getMessage());
                } catch (Exception e) {
                    log.error("RCS取消任务异常:{}", e.getMessage(), e);
                    throw new CoolException("RCS取消任务异常:" + e.getMessage());
                }
            } catch (CoolException e) {
                throw e;
            } catch (JsonProcessingException e) {
                log.error("RCS取消任务响应解析失败:{}", e.getMessage(), e);
                throw new CoolException("RCS取消任务响应解析失败:" + e.getMessage());
            } catch (Exception e) {
                log.error("RCS取消任务异常:{}", e.getMessage(), e);
                throw new CoolException("RCS取消任务异常:" + e.getMessage());
            }
        }
        
        // 查询符合取消条件的任务(状态为1、101、199)
        List<Integer> allowedStatuses = Arrays.asList(TaskStsType.GENERATE_IN.id, TaskStsType.GENERATE_OUT.id, TaskStsType.WAVE_SEED.id);
        // 可取消状态:原 1/101(不含 199);拣料/盘点出库 RCS 执行中(<198);再入库(53/57)在方法入口已禁止取消
        List<Task> tasks = this.list(new LambdaQueryWrapper<Task>()
                .in(Task::getTaskType, list)
                .in(Task::getId, (Object[]) ids)
                .in(Task::getTaskStatus, allowedStatuses));
                .and(w -> w
                        .in(Task::getTaskStatus, Arrays.asList(
                                TaskStsType.GENERATE_IN.id,
                                TaskStsType.GENERATE_OUT.id))
                        .or(w2 -> w2
                                .in(Task::getTaskType, TaskType.TASK_TYPE_PICK_AGAIN_OUT.type, TaskType.TASK_TYPE_CHECK_OUT.type)
                                .lt(Task::getTaskStatus, TaskStsType.COMPLETE_OUT.id))));
        
        // 如果符合取消条件的任务为空,但RCS取消成功,允许继续(可能是任务状态已变更)
        if (tasks.isEmpty() && !rcsCancelSuccess) {
@@ -1077,7 +1115,9 @@
                }
                if (!locService.update(new LambdaUpdateWrapper<Loc>()
                        .eq(Loc::getCode, task.getTargLoc())
                        .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type))) {
                        .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
                        .set(Loc::getBarcode, null)
                        .set(Loc::getWeight, null))) {
                    throw new CoolException("移库目标库位状态修改失败!!");
                }
@@ -1165,6 +1205,7 @@
                        }
                        loc.setUseStatus(LocStsType.LOC_STS_TYPE_F.type)
                                .setBarcode(task.getBarcode())
                                .setWeight(task.getWeight())
                                .setUpdateBy(loginUserId)
                                .setUpdateTime(new Date());
                        if (!locService.updateById(loc)) {
@@ -1239,7 +1280,9 @@
                        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))) {
                            loc.setUseStatus(LocStsType.LOC_STS_TYPE_O.type);
                            loc.setUseStatus(LocStsType.LOC_STS_TYPE_O.type)
                                    .setBarcode(null)
                                    .setWeight(null);
                            if (!locService.updateById(loc)) {
                                throw new CoolException("更新库位状态失败!!");
                            }
@@ -1478,7 +1521,8 @@
                throw new CoolException("临时库存更新失败!!");
            }
        }
        loc1.setUseStatus(LocStsType.LOC_STS_TYPE_S.type);
        loc1.setUseStatus(LocStsType.LOC_STS_TYPE_S.type)
                .setWeight(task.getWeight());
        locService.updateById(loc1);
//        if (!locService.updateById(loc1)) {
//            throw new CoolException("库位预约入库失败!!");
@@ -1603,11 +1647,13 @@
            if (!workings.isEmpty()) {
                locItemWorkingService.saveBatch(workings);
            }
            loc.setUseStatus(LocStsType.LOC_STS_TYPE_S.type);
            loc.setUseStatus(LocStsType.LOC_STS_TYPE_S.type)
                    .setWeight(first.getWeight());
            locService.updateById(loc);
        } else {
            loc.setUseStatus(LocStsType.LOC_STS_TYPE_O.type);
            loc.setBarcode(null);
            loc.setWeight(null);
            loc.setUpdateBy(loginUserId);
            loc.setUpdateTime(new Date());
            locService.updateById(loc);
@@ -1646,6 +1692,7 @@
                        .eq(Loc::getId, loc.getId())
                        .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
                        .set(Loc::getBarcode, null)
                        .set(Loc::getWeight, null)
                        .set(Loc::getUpdateBy, loginUserId)
                        .set(Loc::getUpdateTime, new Date()))) {
                    throw new CoolException("空板出库库位状态更新失败!!");
@@ -1788,6 +1835,7 @@
            if (!locService.update(new LambdaUpdateWrapper<Loc>()
                    .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
                    .set(Loc::getBarcode, null)
                    .set(Loc::getWeight, null)
                    .set(Loc::getUpdateBy, loginUserId)
                    .set(Loc::getUpdateTime, new Date())
                    .eq(Loc::getId, loc.getId()))) {
@@ -2206,6 +2254,13 @@
                    log.error("RCS资源访问异常,任务下发失败!任务编码:{},错误信息:{}", task.getTaskCode(), errorMsg);
                }
                continue;
            } catch (HttpStatusCodeException e) {
                long endTime = System.currentTimeMillis();
                log.error("========== RCS任务下发异常 ==========");
                log.error("请求RCS-HTTP状态异常,耗时:{}ms,任务编码:{},status:{},body:{}", (endTime - startTime), task.getTaskCode(), e.getRawStatusCode(), e.getResponseBodyAsString(), e);
                log.error("请求RCS-地址:{}", pubTakUrl);
                log.error("请求RCS-参数:{}", JSONObject.toJSONString(taskParams));
                continue;
            } catch (Exception e) {
                long endTime = System.currentTimeMillis();
                log.error("========== RCS任务下发异常 ==========");
@@ -2421,6 +2476,21 @@
        }
        List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()));
        // 空板入库无任务明细,仅更新库位为空板(D)、任务状态为库存更新完成
        if (TaskType.TASK_TYPE_EMPITY_IN.type.equals(task.getTaskType())) {
            if (!locService.update(new LambdaUpdateWrapper<Loc>().eq(Loc::getCode, task.getTargLoc())
                    .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_D.type)
                    .set(Loc::getWeight, task.getWeight())
                    .set(Loc::getUpdateBy, loginUserId)
                    .set(Loc::getUpdateTime, new Date()))) {
                throw new CoolException("空板入库库位状态修改失败!!");
            }
            if (!this.update(new LambdaUpdateWrapper<Task>().eq(Task::getId, task.getId()).set(Task::getTaskStatus, TaskStsType.UPDATED_IN.id))) {
                throw new CoolException("空板入库任务状态修改失败!!");
            }
            reportInOutResultToCloud(task, loc, Collections.emptyList(), null, true);
            return;
        }
        if (taskItems.isEmpty()) {
            throw new CoolException("任务明细不存在!!");
        }
@@ -2458,8 +2528,49 @@
            throw new CoolException("组拖状态修改失败!!");
        }
        // 组托入库完成后累加订单及明细的已收数量,用于后续判断整单是否可置为已完成
        Map<Long, Double> orderIdToAdd = new HashMap<>();
        Map<Long, Double> itemIdToAdd = new HashMap<>();
        for (WaitPakinItem p : pakinItems) {
            if (StringUtils.isBlank(p.getAsnCode())) {
                continue;
            }
            WkOrder order = asnOrderService.getOne(new LambdaQueryWrapper<WkOrder>().eq(WkOrder::getCode, p.getAsnCode()));
            if (order == null) {
                continue;
            }
            double addQty = (p.getAnfme() != null ? p.getAnfme() : 0.0);
            orderIdToAdd.merge(order.getId(), addQty, Double::sum);
            if (p.getAsnItemId() != null) {
                itemIdToAdd.merge(p.getAsnItemId(), addQty, Double::sum);
            }
        }
        for (Map.Entry<Long, Double> e : orderIdToAdd.entrySet()) {
            WkOrder o = asnOrderService.getById(e.getKey());
            if (o != null) {
                Double newQty = QuantityUtils.roundToScale(QuantityUtils.add(o.getQty() != null ? o.getQty() : 0.0, e.getValue()));
                o.setQty(newQty);
                if (!asnOrderService.updateById(o)) {
                    throw new CoolException("入库单完成数量更新失败!!");
                }
            }
        }
        for (Map.Entry<Long, Double> e : itemIdToAdd.entrySet()) {
            WkOrderItem oi = asnOrderItemService.getById(e.getKey());
            if (oi != null) {
                Double newQty = QuantityUtils.roundToScale(QuantityUtils.add(oi.getQty() != null ? oi.getQty() : 0.0, e.getValue()));
                oi.setQty(newQty);
                if (!asnOrderItemService.updateById(oi)) {
                    throw new CoolException("入库单明细完成数量更新失败!!");
                }
            }
        }
        /**修改库位状态为F.在库*/
        if (!locService.update(new LambdaUpdateWrapper<Loc>().set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_F.type).eq(Loc::getCode, task.getTargLoc()))) {
        if (!locService.update(new LambdaUpdateWrapper<Loc>()
                .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_F.type)
                .set(Loc::getWeight, task.getWeight())
                .eq(Loc::getCode, task.getTargLoc()))) {
            throw new CoolException("库位状态修改失败!!");
        }
        if (!this.update(new LambdaUpdateWrapper<Task>().eq(Task::getId, task.getId()).set(Task::getTaskStatus, TaskStsType.UPDATED_IN.id))) {
@@ -2604,12 +2715,27 @@
        } else {
            stock.setLocCode(task.getOrgLoc());
        }
        BigDecimal trayWeight = task.getWeight();
        BigDecimal groupWeight = null;
        if (trayWeight != null && sum > 0) {
            List<TaskItem> allLines = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()));
            double totalQty = allLines.stream().mapToDouble(t -> t.getAnfme() != null ? t.getAnfme() : 0.0).sum();
            if (totalQty > 0) {
                groupWeight = trayWeight.multiply(BigDecimal.valueOf(sum)).divide(BigDecimal.valueOf(totalQty), 4, RoundingMode.HALF_UP);
            } else {
                groupWeight = trayWeight;
            }
            stock.setWeight(groupWeight);
        }
        if (!stockService.save(stock)) {
            throw new CoolException("库存保存失败!!");
        }
        List<StockItem> stockItems = new ArrayList<>();
        for (TaskItem item : items) {
        BigDecimal allocatedWeight = BigDecimal.ZERO;
        BigDecimal sumBd = sum > 0 ? BigDecimal.valueOf(sum) : null;
        for (int i = 0; i < items.size(); i++) {
            TaskItem item = items.get(i);
            /**通过任务明细中的taskId查询,获取TASK的目标库位信息*/
            StockItem stockItem = new StockItem();
            BeanUtils.copyProperties(item, stockItem);
@@ -2620,6 +2746,16 @@
                    .setUpdateBy(loginUserId)
                    .setId(null)
                    .setStockId(stock.getId());
            if (groupWeight != null && sumBd != null) {
                if (i == items.size() - 1) {
                    stockItem.setWeight(groupWeight.subtract(allocatedWeight));
                } else {
                    double lineQty = item.getAnfme() != null ? item.getAnfme() : 0.0;
                    BigDecimal lineW = groupWeight.multiply(BigDecimal.valueOf(lineQty)).divide(sumBd, 4, RoundingMode.HALF_UP);
                    stockItem.setWeight(lineW);
                    allocatedWeight = allocatedWeight.add(lineW);
                }
            }
            stockItems.add(stockItem);
        }
        if (!stockItemService.saveBatch(stockItems)) {
@@ -2682,7 +2818,9 @@
                        .setLocId(locId)
                        .setMatNr(item.getMatnrCode())
                        .setQty(item.getAnfme() != null ? String.valueOf(item.getAnfme()) : "0")
                        .setBatch(item.getBatch());
                        .setBatch(item.getBatch())
                        .setInbound(isInbound)
                        .setBarcode(task.getBarcode());
                try {
                    String requestBody = om.writeValueAsString(param);
                    CloudWmsNotifyLog notifyLog = new CloudWmsNotifyLog()