自动化立体仓库 - WMS系统
zhou zhou
2025-12-30 0eab67f624c2b3349002860b408942265a076b9e
src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
@@ -9,10 +9,15 @@
import com.zy.asrs.entity.*;
import com.zy.asrs.entity.param.*;
import com.zy.asrs.enums.LocStsType;
import com.zy.asrs.enums.TaskIOType;
import com.zy.asrs.mapper.BasDevpMapper;
import com.zy.asrs.mapper.BasStationMapper;
import com.zy.asrs.mapper.LocMastMapper;
import com.zy.asrs.mapper.ManLocDetlMapper;
import com.zy.asrs.service.*;
import com.zy.asrs.task.core.ReturnT;
import com.zy.asrs.utils.MatUtils;
import com.zy.common.constant.ApiInterfaceConstant;
import com.zy.common.constant.MesConstant;
import com.zy.common.entity.Parameter;
import com.zy.common.model.DetlDto;
@@ -21,6 +26,7 @@
import com.zy.common.service.CommonService;
import com.zy.common.utils.HttpHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -109,6 +115,137 @@
    private BasStationService basStationService;
    @Autowired
    private BasContainerService basContainerService;
    @Resource
    private BasStationMapper basStationMapper;
    @Resource
    private BasDevpMapper basDevpMapper;
    @Override
    public R inLocCallAgv(CallAgvParam param,Long userId) {
        int type = param.getType();
        String sourceSite = param.getSourceSite();
        String barcode = param.getBarcode();
        int ioType;
        LocCache locCache = locCacheService.selectOne(new EntityWrapper<LocCache>().eq("loc_no", sourceSite));
        if (null == locCache) {
            throw new CoolException("站点不存在:" + sourceSite);
        }
        switch (type) {
            case 1:
                // 判断有没有组托
                int count = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", barcode));
                if (count == 0) {
                    throw new CoolException("条码未组托:" + barcode);
                }
                ioType = 101;
                locCache.setLocSts(LocStsType.LOC_STS_TYPE_R.type);
                locCacheService.updateById(locCache);
                break;
            case 2:
                // 判断是拣选回库托盘
                WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("barcode", barcode));
                if (wrkMast == null) {
                    throw new CoolException("条码不存在:" + barcode);
                }
                if (wrkMast.getIoType() != 103 && wrkMast.getIoType() != 107) {
                    throw new CoolException("条码不需要回库:" + barcode);
                }
                ioType = wrkMast.getIoType() - 50;
                locCache.setLocSts(LocStsType.LOC_STS_TYPE_R.type);
                locCacheService.updateById(locCache);
                break;
            case 3:
                // 判断条码在wms不存在,是空托盘
                // 已组托
                int waitPakInCount = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", barcode));
                if (waitPakInCount != 0) {
                    throw new CoolException("条码组托档已存在:" + barcode);
                }
                // 有任务
                int wrkMastCount = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("barcode", barcode));
                if (wrkMastCount != 0) {
                    throw new CoolException("条码任务档已存在:" + barcode);
                }
                // 有库存
                int locDetlCount = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet", barcode));
                if (locDetlCount != 0) {
                    throw new CoolException("条码库存已存在:" + barcode);
                }
                ioType = 10;
                break;
            default:
                throw new CoolException("入库类型错误,type:" + type);
        }
        // 条码存在agv任务
        int count = taskService.selectCount(new EntityWrapper<Task>().eq("barcode", barcode));
        if (count > 0) {
            throw new CoolException(barcode+ ":条码存在agv搬运任务!");
        }
        // 判断能入站点
        List<Integer> sites = basDevpMapper.selectList(
                new EntityWrapper<BasDevp>()
                        .eq("canining", "Y")
                        .in("dev_no", type == 1 ? Arrays.asList(1003, 1005, 1007) : Arrays.asList(1044, 1046, 1048))
        ).stream().map(BasDevp::getDevNo).collect(Collectors.toList());
        if (sites.isEmpty()) {
            throw new CoolException("没有能入站点,type:" + type);
        }
        // 获取没有出库任务的站点
        List<Integer> canInSites = basDevpMapper.getCanInSites(sites);
        if (canInSites.isEmpty()) {
            throw new CoolException("请等待出库完成,type:" + type);
        }
        // 寻找入库任务最少的站点
        List<BasDevp> devList = basDevpMapper.selectList(new EntityWrapper<BasDevp>().in("dev_no", canInSites));
        // 入库任务数排序
        devList.sort(Comparator.comparing(BasDevp::getInQty));
        // 取入库任务最少站点
        BasDevp basDevp = devList.get(0);
        int endSite = basDevp.getDevNo();
        // 入库暂存+1
        basDevpMapper.incrementInQty(endSite);
        // 获取工作号
        int workNo = commonService.getWorkNo(WorkNoType.PICK.type);
        // 保存工作档
        Task task = new Task();
        Date now = new Date();
        task.setWrkNo(workNo)
                .setIoTime(now)
                .setWrkSts(7L) // 工作状态:11.生成出库ID
                .setIoType(ioType) // 入出库状态: 1.入库
                .setTaskType("agv")
                .setIoPri(10D)
                .setStaNo(String.valueOf(endSite))
                .setFullPlt(ioType != 10 ? "N" : "Y")// 满板:Y
                .setPicking("N") // 拣料
                .setExitMk("N")// 退出
                .setSourceLocNo(sourceSite)
                .setEmptyMk(ioType == 10 ? "Y" : "N")// 空板
                .setBarcode(barcode)// 托盘码
                .setLinkMis("N")
                .setAppeTime(now)
                .setModiTime(now);
        if (!taskService.insert(task)) {
            throw new CoolException("保存工作档失败");
        }
        // 更新暂存位状态为 R.出库预约
        basStationMapper.updateLocStsBatch( Collections.singletonList(String.valueOf(sourceSite)), "R");
        return R.ok("agv任务生成成功!");
    }
    @Override
    @Transactional
@@ -601,9 +738,9 @@
                if (Cools.isEmpty(mat)) {
                    throw new CoolException(detlDto.getMatnr() + "商品档案不存在");
                }
                if (mat.getUpQty().compareTo(detlDto.getAnfme()) < 0) {
                    throw new CoolException("物料:" + detlDto.getMatnr() + "单次最大组托上限为:" + mat.getUpQty());
                }
//                if (mat.getUpQty().compareTo(detlDto.getAnfme()) < 0) {
//                    throw new CoolException("物料:" + detlDto.getMatnr() + "单次最大组托上限为:" + mat.getUpQty());
//                }
                WaitPakin waitPakin = new WaitPakin();
                BeanUtils.copyProperties(mat, waitPakin);
                waitPakin.setBatch(detlDto.getBatch());
@@ -626,7 +763,7 @@
            param.getCombMats().forEach(elem -> {
                OrderPakin order = orderPakinService.selectByNo(elem.getOrderNo());
                if (Cools.isEmpty(order) || order.getSettle() > 2) {
                    throw new CoolException("单据编号已过期");
                    throw new CoolException("单据正在作业中");
                }
                // 订单明细数量校验
                OrderDetlPakin detls = orderDetlPakinService.selectOne(new EntityWrapper<OrderDetlPakin>()
@@ -655,38 +792,38 @@
                }
            });
            BasContainer container = basContainerService.selectOne(new EntityWrapper<BasContainer>().eq("barcode", param.getBarcode()));
            if (Objects.isNull(container)) {
                throw new CoolException("数据错误:容器码不存在!!");
            }
            if (container.getMixMax() < detlDtos.size()) {
                throw new CoolException("超出容器最大混装数量,当前容器最大数量为:" + container.getMixMax() + "!!");
            }
            Set<String> matnrs = detlDtos.stream().map(DetlDto::getMatnr).collect(Collectors.toSet());
            List<Mat> mats = matService.selectList(new EntityWrapper<Mat>().in("matnr", matnrs));
            Set<Long> tagIds = mats.stream().map(Mat::getTagId).collect(Collectors.toSet());
            if (tagIds.size() > 1) {
                throw new CoolException("组托物料类型不一致,只有相同的物料分类才可以组托!!");
            }
            //还可以放入多少种物料
            Integer suplus = container.getMixMax();
//            BasContainer container = basContainerService.selectOne(new EntityWrapper<BasContainer>().eq("barcode", param.getBarcode()));
//            if (Objects.isNull(container)) {
//                throw new CoolException("数据错误:容器码不存在!!");
//            }
//            if (container.getMixMax() < detlDtos.size()) {
//                throw new CoolException("超出容器最大混装数量,当前容器最大数量为:" + container.getMixMax() + "!!");
//            }
//            Set<String> matnrs = detlDtos.stream().map(DetlDto::getMatnr).collect(Collectors.toSet());
//            List<Mat> mats = matService.selectList(new EntityWrapper<Mat>().in("matnr", matnrs));
//            Set<Long> tagIds = mats.stream().map(Mat::getTagId).collect(Collectors.toSet());
//            if (tagIds.size() > 1) {
//                throw new CoolException("组托物料类型不一致,只有相同的物料分类才可以组托!!");
//            }
//            //还可以放入多少种物料
//            Integer suplus = container.getMixMax();
            for (DetlDto detlDto : detlDtos) {
                Mat mat = matService.selectByMatnr(detlDto.getMatnr());
                if (Cools.isEmpty(mat)) {
                    throw new CoolException(detlDto.getMatnr() + "商品档案不存在");
                }
                //最多可放数量
                Double singleMax = mat.getUpQty() * suplus;
                if (singleMax.compareTo(detlDto.getAnfme()) < 0) {
                    throw new CoolException("物料:" + detlDto.getMatnr() + "单次组托上限为:" + mat.getUpQty() + ",当前总量超出托盘装载上限!!");
                }
                BigDecimal decimal = new BigDecimal(detlDto.getAnfme() / mat.getUpQty());
                //当前物料需要占用料箱格数
                Integer curr = decimal.setScale(0, RoundingMode.CEILING).intValue();
                suplus = suplus - curr;
                if (suplus < 0) {
                    throw new CoolException("物料:" + detlDto.getMatnr() + ", 超出当前托盘装载上限!!");
                }
//                //最多可放数量
//                Double singleMax = mat.getUpQty() * suplus;
//                if (singleMax.compareTo(detlDto.getAnfme()) < 0) {
//                    throw new CoolException("物料:" + detlDto.getMatnr() + "单次组托上限为:" + mat.getUpQty() + ",当前总量超出托盘装载上限!!");
//                }
//                BigDecimal decimal = new BigDecimal(detlDto.getAnfme() / mat.getUpQty());
//                //当前物料需要占用料箱格数
//                Integer curr = decimal.setScale(0, RoundingMode.CEILING).intValue();
//                suplus = suplus - curr;
//                if (suplus < 0) {
//                    throw new CoolException("物料:" + detlDto.getMatnr() + ", 超出当前托盘装载上限!!");
//                }
                WaitPakin waitPakin = new WaitPakin();
                BeanUtils.copyProperties(mat, waitPakin);
@@ -914,7 +1051,7 @@
                boolean success = false;
                try {
                    response = new HttpHandler.Builder()
                            .setUri(MesConstant.URL)
                            .setUri(MesConstant.URI)
                            .setPath(MesConstant.PACK_DOWN_URL)
                            .setJson(JSON.toJSONString(mesCombParam))
                            .build()
@@ -923,10 +1060,10 @@
                    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, JSON.toJSONString(mesCombParam), response);
                        log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URI + MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response);
                        throw new CoolException(jsonObject.getString("msg"));
                    } else {
                        log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL + MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response);
                        log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URI + MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response);
                        throw new CoolException("上报mes系统失败");
                    }
                } catch (Exception e) {
@@ -937,7 +1074,7 @@
                        // 保存接口日志
                        apiLogService.save(
                                "打包下线帮托上报",
                                MesConstant.URL + MesConstant.PACK_DOWN_URL,
                                MesConstant.URI + MesConstant.PACK_DOWN_URL,
                                null,
                                "127.0.0.1",
                                JSON.toJSONString(mesCombParam),