自动化立体仓库 - WMS系统
IZCD4L12RTSW0VZ\Administrator
昨天 290e5fd2e74efe19326f56e38c3391aaae23ffc5
src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
@@ -700,13 +700,13 @@
                OrderInAndOutUtil.increaseWorkQty(Boolean.TRUE, order.getId(), elem.getMatnr(), elem.getBatch(),
                        elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(),
                        elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme());
                DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(),
                DetlDto detlDto = new DetlDto(order.getOrderNo(), elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(),
                        elem.getStandby2(), elem.getStandby3(),
                        elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme(),
                        elem.getThreeCode());
                detlDto.setOrderId(order.getId());
                detlDto.setOrderNo(order.getOrderNo());
                if (DetlDto.has(detlDtos, detlDto)) {
                if (DetlDto.hasOrder(detlDtos, detlDto)) {
                    DetlDto one = DetlDto.findDto(detlDtos, detlDto);
                    assert one != null;
                    one.setAnfme(one.getAnfme() + detlDto.getAnfme());
@@ -991,7 +991,7 @@
                try {
                    response = new HttpHandler.Builder()
                            .setUri(MesConstant.URL)
                            .setPath(MesConstant.PACK_DOWN_URL)
                            .setPath(MesConstant.IN_DISPATCH_RESULT)
                            .setJson(JSON.toJSONString(mesCombParam))
                            .build()
                            .doPost();
@@ -999,11 +999,11 @@
                    if (jsonObject.getInteger("code").equals(200)) {
                        success = true;
                    } else if (jsonObject.getInteger("code").equals(500)) {
                        log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL + MesConstant.PACK_DOWN_URL,
                        log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL + MesConstant.IN_DISPATCH_RESULT,
                                JSON.toJSONString(mesCombParam), response);
                        throw new CoolException(jsonObject.getString("msg"));
                    } else {
                        log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL + MesConstant.PACK_DOWN_URL,
                        log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL + MesConstant.IN_DISPATCH_RESULT,
                                JSON.toJSONString(mesCombParam), response);
                        throw new CoolException("上报mes系统失败");
                    }
@@ -1015,7 +1015,7 @@
                        // 保存接口日志
                        apiLogService.save(
                                "打包下线帮托上报",
                                MesConstant.URL + MesConstant.PACK_DOWN_URL,
                                MesConstant.URL + MesConstant.IN_DISPATCH_RESULT,
                                null,
                                "127.0.0.1",
                                JSON.toJSONString(mesCombParam),
@@ -1741,6 +1741,7 @@
                    throw new CoolException("数据错误,站点不存在!!");
                }
                station.setLocSts(LocStsType.LOC_STS_TYPE_O.type);
                station.setBarcode("");
                if (!basStationService.updateById(station)) {
                    throw new CoolException("站点状态更新失败!!");
                }
@@ -1785,6 +1786,7 @@
        }
        station.setLocSts(LocStsType.LOC_STS_TYPE_O.type);
        station.setBarcode("");
        if (!basStationService.updateById(station)) {
            throw new CoolException("站点状态修改失败!");
        }
@@ -1806,6 +1808,13 @@
        generateCrnInTask(waitPakins, station, param.getLocType1(), userId);
    }
    /**
     * SO/EO 区组托
     * @author Ryan
     * @date 2025/12/18 15:19
     * @param params
     * @return com.core.common.R
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R collectionPakin(CollectionPakinParams params, Long userId) {
@@ -2186,8 +2195,14 @@
                    .eq("loc_sts", LocStsType.LOC_STS_TYPE_D.type)
                    .orderAsc(Arrays.asList("row1", "bay1", "lev1"))
                    .last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY"));
            if (Objects.isNull(locMast)) {
                throw new CoolException("未查询到可用的空板信息!!");
            }
            CrnTaskDetlDTO crnTaskDetlDTO = new CrnTaskDetlDTO().setLocNo(locMast.getLocNo()).setLocDetlList(locDetls);
            locMasts.add(crnTaskDetlDTO);
            // 空板出库
            generateTask(locMasts, TaskIOType.MERGE_OUT.type, basDevp, userId, station);
        }
@@ -2295,7 +2310,7 @@
        Task task = new Task();
        task.setWrkNo(workNo)
                .setIoTime(new Date())
                .setWrkSts(11L) // 工作状态:11.生成出库ID
                .setWrkSts(301L) // 工作状态:11.生成出库ID
                .setIoType(loc.getLocSts().equals("D") ? 110 : 101) // 入出库状态: 11.库格移载
                .setTaskType("agv")
                .setIoPri(10D)
@@ -2372,11 +2387,6 @@
     */
    @Transactional(rollbackFor = Exception.class)
    public void generateAgvTask(String type, LocCache loc, String orgSite, String barcode, Long userId) {
        List<WaitPakin> pakins = waitPakinService.selectList(new EntityWrapper<WaitPakin>().eq("zpallet", barcode));
        if (Objects.isNull(pakins) || pakins.isEmpty()) {
            throw new CoolException("组托信息不存在!!");
        }
        List<Task> tasks = taskService.selectList(new EntityWrapper<Task>().eq("barcode", barcode));
        if (!tasks.isEmpty()) {
            throw new CoolException("托盘已在任务执行中..");
@@ -2387,7 +2397,7 @@
        Task task = new Task();
        task.setWrkNo(workNo)
                .setIoTime(new Date())
                .setWrkSts(1L) // 工作状态:11.生成出库ID
                .setWrkSts(201L) // 工作状态:11.生成出库ID
                .setIoType(1) // 入出库状态: 11.库格移载
                .setTaskType("agv")
                .setIoPri(10D)
@@ -2405,6 +2415,12 @@
                .setModiTime(new Date());
        if (!taskService.insert(task)) {
            throw new CoolException("保存工作档失败");
        }
        if (!type.equals("agv_back")) {
            List<WaitPakin> pakins = waitPakinService.selectList(new EntityWrapper<WaitPakin>().eq("zpallet", barcode));
            if (Objects.isNull(pakins) || pakins.isEmpty()) {
                throw new CoolException("组托信息不存在!!");
        }
        for (WaitPakin pakin : pakins) {
@@ -2435,6 +2451,7 @@
                throw new CoolException("更新组托信息失败");
            }
        }
        }
        // 修改目标库位状态
        if (loc.getLocSts().equals(LocStsType.LOC_STS_TYPE_O.type)) {
@@ -2454,9 +2471,9 @@
            throw new CoolException("站点不存在!!");
        }
        if (station.getLocSts().equals(LocStsType.LOC_STS_TYPE_O.type)) {
        if (station.getLocSts().equals(LocStsType.LOC_STS_TYPE_O.type) || station.getLocSts().equals(LocStsType.LOC_STS_TYPE_D.type)) {
            station.setLocSts("R"); // S.入库预约
//            station.setBarcode(barcode);
            station.setBarcode(barcode);
            station.setModiTime(new Date());
            station.setModiUser(userId);
            if (!basStationService.updateById(station)) {
@@ -2520,4 +2537,76 @@
        }
        return result;
    }
    /**
     * 呼叫AGV空台车返回
     * @author Ryan
     * @date 2025/9/24
     * @param callAgvBackParam
     * @return com.core.common.R
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R agvCallback(AgvCallParams callAgvBackParam, Long userId) {
        if (Objects.isNull(callAgvBackParam.getOrgSite())) {
            return R.error("参数不能为空!!");
        }
        // 按当前查找库位顺序,查到一个后,不再往下查询
        LocCache locCache = findPriorityLocCache();
        if (Objects.isNull(locCache)) {
            return R.error("未查询到可用库位");
        }
        // 修改目标站点信息
        BasStation station = basStationService.selectOne(new EntityWrapper<BasStation>().eq("dev_no", callAgvBackParam.getOrgSite()));
        if (Objects.isNull(station)) {
            throw new CoolException("站点不存在!!");
        }
        try {
            //空台车回库
            generateAgvTask("agv_back", locCache, callAgvBackParam.getOrgSite(), station.getBarcode(), userId);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
        }
        return R.ok(locCache);
    }
    /**
     * 按优先级查找可用库位
     * 顺序:入库缓存区 -> SO区 -> EO区
     */
    private LocCache findPriorityLocCache() {
        // 1. Try Inbound Cache Area
        LocCache loc = findAvailableLocByAreaType(LocAreaType.LOC_AREA_TYPE_IN_CACHE);
        if (loc != null) return loc;
        // 2. Try SO Area
        loc = findAvailableLocByAreaType(LocAreaType.LOC_AREA_TYPE_SO);
        if (loc != null) return loc;
        // 3. Try EO Area
        loc = findAvailableLocByAreaType(LocAreaType.LOC_AREA_TYPE_EO);
        return loc;
    }
    /**
     * 根据区域类型查找可用库位
     */
    private LocCache findAvailableLocByAreaType(LocAreaType areaType) {
        BasAreas area = basAreasService.selectOne(new EntityWrapper<BasAreas>().eq("whs_type_id", areaType.type));
        if (area == null) {
            return null;
        }
        return locCacheService.selectOne(new EntityWrapper<LocCache>()
                .eq("area_id", area.getId())
                .eq("frozen", 0)
                .eq("loc_sts", LocStsType.LOC_STS_TYPE_O.type)
                .orderAsc(Arrays.asList("loc_no"))
                .last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY"));
    }
}