自动化立体仓库 - WMS系统
whycq
2024-06-04 ed0a79ffec5d25dae6b0b24393c331ab36d7d50b
src/main/java/com/zy/asrs/service/impl/AgvMobileServiceImpl.java
@@ -1,14 +1,18 @@
package com.zy.asrs.service.impl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.annotations.ManagerAuth;
import com.core.common.BaseRes;
import com.core.common.Cools;
import com.core.common.R;
import com.core.exception.CoolException;
import com.zy.asrs.entity.*;
import com.zy.asrs.entity.param.CombParam;
import com.zy.asrs.entity.param.MobileAdjustParam;
import com.zy.asrs.entity.param.*;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.CodeDetectionUtil;
import com.zy.common.model.DetlDto;
import com.zy.common.service.AgvCommonService;
import lombok.Synchronized;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -44,6 +48,16 @@
    private AgvWrkMastService agvWrkMastService;
    @Autowired
    private AgvWorkService agvWorkService;
    @Autowired
    private AgvWrkDetlService agvWrkDetlService;
    @Autowired
    private AgvLocMastService agvLocMastService;
    @Autowired
    private AgvCommonService agvCommonService;
    @Autowired
    private AgvWrkMastLogService agvWrkMastLogService;
    @Autowired
    private AgvWrkDetlLogService agvWrkDetlLogService;
    /*
@@ -55,21 +69,29 @@
        if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) {
            throw new CoolException(BaseRes.PARAM);
        }
        if (!CodeDetectionUtil.barcodeDetection(param.getBarcode())){
            throw new CoolException(param.getBarcode() + "货架码有误,请正确扫码!!!");
        }
        param.setContainerType(Short.valueOf(param.getBarcode().substring(0,2)));
        //检查是否已存在相同的托盘条码,存在则抛出异常
        if (agvWaitPakinService.selectCount(new EntityWrapper<AgvWaitPakin>().eq("supp_code", param.getBarcode())) > 0) {
            throw new CoolException(param.getBarcode() + "料想码已存在AGV入库通知档中");
        }
//        //检查是否已存在相同的货架条码,存在则抛出异常
//        if (agvWaitPakinService.selectCount(new EntityWrapper<AgvWaitPakin>().eq("supp_code", param.getBarcode())) > 0) {
//            throw new CoolException(param.getBarcode() + "料想码已存在AGV入库通知档中");
//        }
        //检查库存是否有相同料箱,存在则抛出异常
        //检查库存是否有相同货架,存在则抛出异常
        if(!Cools.isEmpty(agvLocDetlService.selectOne(new EntityWrapper<AgvLocDetl>().eq("supp_code",param.getBarcode())))){
            throw new CoolException(param.getBarcode() + "料箱码已存在AGV库存明细中");
            throw new CoolException(param.getBarcode() + "货架码已存在AGV库存明细中");
        }
        //查看工作档是否有相同料箱,存在则抛出异常
        //检查库存是否有相同货架,存在则抛出异常
        if(!Cools.isEmpty(agvLocMastService.selectOne(new EntityWrapper<AgvLocMast>().eq("barcode",param.getBarcode())))){
            throw new CoolException(param.getBarcode() + "货架码已存在AGV库存主档中");
        }
        //查看工作档是否有相同货架,存在则抛出异常
        if(!Cools.isEmpty(agvWrkMastService.selectByContainerCode(param.getBarcode()))){
            throw new CoolException(param.getBarcode() + "料箱码已存在AGV工作档中");
            throw new CoolException(param.getBarcode() + "货架码已存在AGV工作档中");
        }
        if (Cools.isEmpty(param.getOrderNo())) {
@@ -90,17 +112,93 @@
    }
    /*
    再次拣料
     */
    @Override
    @Transactional
    public String pickAgain(PickParam pickParams, Long userId) {
        Date now = new Date();
        List<AgvLocDetl> agvLocDetls = agvLocDetlService.selectList(new EntityWrapper<AgvLocDetl>().eq("loc_no", pickParams.getLocNo()));
        AgvWrkMast agvWrkMast = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("wrk_no", pickParams.getWrkNo()));
        if (Cools.isEmpty(agvWrkMast)){
            return "失败,未查到工作主档,工作号:"+pickParams.getWrkNo();
        }
        for (PickParam.Pick pick : pickParams.getPicks()) {
            if (pick.getCount().equals(0D)) continue;
            Double count = 0.0D;
            AgvWrkDetl agvWrkDetl = agvWrkDetlService.selectOne(new EntityWrapper<AgvWrkDetl>().eq("matnr", pick.getMatnr()).eq("three_code", pick.getThreeCode()).eq("supp_code",pick.getSuppCode()));
            if (Cools.isEmpty(agvWrkDetl)) {
                AgvWrkDetl wrkDetl = new AgvWrkDetl();
                Mat mat = matService.selectByMatnr(pick.getMatnr());
                if (Cools.isEmpty(mat)) {
                    throw new CoolException(pick.getMatnr() + "商品不存在");
                }
                wrkDetl.sync(mat);
                wrkDetl.setWrkNo(pickParams.getWrkNo());
                wrkDetl.setOrderNo(pick.getOrderNo());
                wrkDetl.setIoTime(agvWrkMast.getIoTime());
                wrkDetl.setAnfme(pick.getCount()); // 数量
                wrkDetl.setSuppCode(pick.getSuppCode()); // 货架条码
                wrkDetl.setAppeUser(userId);
                wrkDetl.setAppeTime(now);
                wrkDetl.setModiUser(userId);
                wrkDetl.setModiTime(now);
                wrkDetl.setThreeCode(pick.getThreeCode());
                agvWrkDetlService.insert(wrkDetl);
            } else {
                Double anfme = agvWrkDetl.getAnfme() + pick.getCount();
                agvWrkDetl.setAnfme(anfme);
                agvWrkDetlService.update(agvWrkDetl,new EntityWrapper<AgvWrkDetl>().eq("matnr",agvWrkDetl.getMatnr()).eq("three_code",agvWrkDetl.getThreeCode()).eq("supp_code",pick.getSuppCode()));
            }
            // 更新订单
            OrderDetl orderDetl = orderDetlService.selectOne(new EntityWrapper<OrderDetl>().eq("order_no", pick.getOrderNo()).eq("matnr", pick.getMatnr()).eq("three_code",pick.getThreeCode()));
            orderDetl.setQty(orderDetl.getQty() + pick.getCount());
            if (!orderDetlService.update(orderDetl,new EntityWrapper<OrderDetl>().eq("order_no", pick.getOrderNo()).eq("matnr", pick.getMatnr()).eq("three_code",pick.getThreeCode()))){
                throw new CoolException("修改订单明细失败,请联系管理员"+pick.getOrderNo()+pick.getMatnr());
            }
        }
        //  确认是否全部出库
        int sameNumber = 0;
        List<AgvWrkDetl> agvWrkDetls = agvWrkDetlService.selectList(new EntityWrapper<AgvWrkDetl>().eq("wrk_no", pickParams.getWrkNo()));
        for (AgvLocDetl agvLocDetl : agvLocDetls) {
            for (AgvWrkDetl agvWrkDetl : agvWrkDetls) {
                if (agvLocDetl.getMatnr().equals(agvWrkDetl.getMatnr())
                    && agvLocDetl.getThreeCode().equals(agvWrkDetl.getThreeCode())
                    && agvLocDetl.getSuppCode().equals(agvWrkDetl.getSuppCode())
                    && agvLocDetl.getAnfme().equals(agvWrkDetl.getAnfme())) {
                    sameNumber++;
                }
            }
        }
        if (agvLocDetls.size() == sameNumber) {
            agvWrkMast.setIoType(101);
            agvWrkMastService.update(agvWrkMast,new EntityWrapper<AgvWrkMast>().eq("wrk_no", pickParams.getWrkNo()));
        }
        return "组托成功,绑定站点成功";
    }
    /*
    AGV无单组托
     */
    private void NoOrderComb(CombParam param, Long userId){
        List<DetlDto> detlDtos = mappingDetlDtoByCombMat(param,null);
        //用于统一一个托盘下的入库通知档的生成时间
        //用于统一一个货架下的入库通知档的生成时间
        Date now = new Date();
        detlDtos.forEach(detlDto -> {
            syncWaitPakin(detlDto,"",param.getBarcode(),userId,now);
        });
    }
    /*
    AGV有单组托
@@ -117,7 +215,7 @@
        }
        // 用于生成入库通知档所需参数
        List<DetlDto> detlDtos = mappingDetlDtoByCombMat(param,order);
        //用于统一一个托盘下的入库通知档的生成时间
        //用于统一一个货架下的入库通知档的生成时间
        Date now = new Date();
        for (DetlDto detlDto : detlDtos) {
            //同步生成入库通知档
@@ -140,9 +238,9 @@
            }
            DetlDto detlDto = new DetlDto(combMat.getMatnr(), combMat.getBatch(), combMat.getAnfme(), combMat.getCsocode(), combMat.getIsoseq(),combMat.getContainerCode(),param.getLocType());
            //同一托盘下相同物料信息和批号转为一个入库通知档
            //同一货架下相同物料信息和批号转为一个入库通知档
            if (DetlDto.has(detlDtos, detlDto)) {
                DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch(), detlDto.getCsocode(), detlDto.getIsoseq(),null);
                DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch(), detlDto.getCsocode(), detlDto.getIsoseq(),detlDto.getContainerCode());
                assert one != null;
                one.setAnfme(one.getAnfme() + detlDto.getAnfme());
            } else {
@@ -183,8 +281,8 @@
        waitPakin.sync(mat);
        waitPakin.setOrderNo(orderNo);   // 单据编号
        waitPakin.setBatch(detlDto.getBatch());     // 序列码
        //waitPakin.setZpallet(zpallet);   // 托盘码
        waitPakin.setSuppCode(zpallet);   // 托盘码
        //waitPakin.setZpallet(zpallet);   // 货架码
        waitPakin.setSuppCode(zpallet);   // 货架码
        waitPakin.setIoStatus("N");     // 入出状态
        waitPakin.setAnfme(detlDto.getAnfme());  // 数量
        waitPakin.setStatus("Y");    // 状态
@@ -229,7 +327,7 @@
        }
        if(Cools.isEmpty(agvWaitPakinService.selectByContainerCode(barcode))){
            throw new CoolException("该料箱未组托,无法绑定站点");
            throw new CoolException("该货架未组托,无法绑定站点");
        }
        AgvBasDevp agvBasDevp1 = agvBasDevpService.selectOne(new EntityWrapper<AgvBasDevp>().eq("barcode", barcode));
@@ -280,4 +378,363 @@
    }
    /*
       手动移库
    */
    @Override
    @Transactional
    public String handControlLocMove(LocMoveParam param, Long userId) {
        String fl = String.valueOf(param.getFloor());
        short floor =(short)Integer.parseInt(fl.substring(0, 1));
        Integer ioType = 0;
        AgvLocMast agvLocMast = agvLocMastService.selectOne(new EntityWrapper<AgvLocMast>().eq("loc_no", param.getLocNo()));
        if (Cools.isEmpty(agvLocMast)) {
            throw new CoolException("当前库位为空,请检查库位!");
        }
//        if (agvLocMast.getLocSts() == "F") {
//            return R.error("当前库位不为在库,或者空货架,不支持移库");
        // 校验楼层
        if (agvLocMast.getLocType1() != 3) { // 不为箱壳区域
            if (agvLocMast.getFloor() != floor) {
                throw new CoolException("当前库位不支持跨楼层转移");
            } else {
                ioType = 11;
            }
        } else {
            if (agvLocMast.getFloor() != floor) {
//                if (floor==1 && agvLocMast.getFloor()!=1){
//                    ioType = 121;
//                }else {
                    if (agvLocMast.getFloor() == 1) {
                        throw new CoolException("当前库位请选择调拨单调拨!");
                    } else {
                        ioType = 12;
                    }
//                }
            } else {
                ioType = 11;
            }
        }
        Date now = new Date();
        //查询工作档
        AgvWrkMast agvWrkMast = agvWrkMastService.selectByContainerCode(agvLocMast.getBarcode());
        if(!Cools.isEmpty(agvWrkMast)){
            throw new CoolException("当前"+agvLocMast.getBarcode()+"货架码已在工作档中");
        }
        //检索库位,选择合适的库位
        AgvLocMast locMast = agvCommonService.getLocNo(agvLocMast.getLocType1(),floor);
        if (Cools.isEmpty(locMast)) {
            throw new CoolException("当前楼层没有空库位");
        }
        //生成工作档
        AgvWrkMast mast = new AgvWrkMast();
        //工作状态
        if (ioType==121) {
            mast.setWrkSts(11L);
        }else {
            mast.setWrkSts(201L);
        }
        //入出库类型
        mast.setIoType(ioType);
        mast.setIoTime(now);
        //优先级
        mast.setIoPri(300.0);
        //源站点
        mast.setSourceLocNo(agvLocMast.getLocNo());
        //目标站点
        mast.setLocNo(locMast.getLocNo());
        //货架编码
        mast.setBarcode(agvLocMast.getBarcode());
        //货架类型
        mast.setWhsType(30);
        mast.setAppeUser(userId);
        mast.setAppeTime(now);
        mast.setModiUser(userId);
        mast.setModiTime(now);
        if (!agvWrkMastService.insertByIncrease(mast)) {
            throw new CoolException("保存工作档失败");
        }
        if (agvLocMast.getLocSts().equals("F")) {
            AgvWrkMast mast1 = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("loc_no", locMast.getLocNo()).eq("source_loc_no",agvLocMast.getLocNo()));
            //生成工作档明细
            List<AgvLocDetl> agvLocDetls = agvLocDetlService.selectList(new EntityWrapper<AgvLocDetl>().eq("loc_no", agvLocMast.getLocNo()));
            agvLocDetls.forEach(agvLocDetl -> {
                AgvWrkDetl wrkDetl = new AgvWrkDetl();
                wrkDetl.setWrkNo(mast1.getWrkNo());
                wrkDetl.sync(agvLocDetl);
                wrkDetl.setSuppCode(agvLocDetl.getSuppCode());
                wrkDetl.setIoTime(now);
                wrkDetl.setAppeUser(9527L);
                wrkDetl.setAppeTime(now);
                wrkDetl.setModiUser(9527L);
                wrkDetl.setModiTime(now);
                if (!agvWrkDetlService.insert(wrkDetl)) {
                    throw new CoolException("保存工作明细失败");
                }
            });
        }
        // 如果当前任务是箱壳二三楼回退一楼的 回滚调拨单
        if (ioType == 12 && locMast.getFloor() == 1) {
            List<AgvLocDetl> agvLocDetls = agvLocDetlService.selectList(new EntityWrapper<AgvLocDetl>().eq("loc_no", agvLocMast.getLocNo()));
            for (AgvLocDetl agvLocDetl : agvLocDetls) {
                OrderDetl orderDetl = orderDetlService.selectOne(new EntityWrapper<OrderDetl>().eq("three_code", agvLocDetl.getThreeCode()).eq("matnr", agvLocDetl.getMatnr()).eq("order_no", "DB" + agvLocDetl.getOrderNo()));
                orderDetl.setQty(orderDetl.getQty() - agvLocDetl.getAnfme());
                if (!orderDetlService.updateById(orderDetl)) {
                    throw new CoolException("保存工作明细失败");
                }
            }
        }
        //更新目标库位状态
        updateAgvLocMast(agvLocMast,"P");
        updateAgvLocMast(locMast,"Q");
        return "ok";
    }
    /*
       调拨离场
    */
    @Override
    @Transactional
    @Synchronized
    public String allocationOut(AgvMobileStartPakin param, Long userId) {
        Date now = new Date();
        AgvWrkMast agvWrkMast = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("loc_no", param.getDevNo()));
        Integer oldWrkNo = agvWrkMast.getWrkNo();
        if (Cools.isEmpty(agvWrkMast)) {
            throw new CoolException("工作档中没有此站点任务");
        }
        if (!agvWrkMast.getWrkSts().equals(207L)) {
            throw new CoolException("工作状态不符合离场条件");
        }
        //生成AGV工作历史档 + 生成AGV工作明细历史档
        agvWrkMastLogService.save(agvWrkMast);
        agvWrkDetlLogService.save(agvWrkMast.getWrkNo());
        //删除AGV工作档
        agvWrkMastService.deleteById(agvWrkMast);
        //生成工作档
        AgvWrkMast wrkMast = createWrkMast(111, 210L, "", "", agvWrkMast.getBarcode(), now, userId, 30, agvWrkMast.getCrnNo());
        // 更新工作明细
        List<AgvWrkDetl> agvWrkDetls = agvWrkDetlService.selectList(new EntityWrapper<AgvWrkDetl>().eq("supp_code", agvWrkMast.getBarcode()));
        for (AgvWrkDetl agvWrkDetl : agvWrkDetls) {
            agvWrkDetl.setWrkNo(wrkMast.getWrkNo());
            // 保持工作档明细
            agvWrkDetl.setWrkNo(wrkMast.getWrkNo());
            agvWrkDetl.setModiUser(userId);
            agvWrkDetl.setModiTime(now);
            if (!agvWrkDetlService.insert(agvWrkDetl)) {
                throw new CoolException("保存工作明细失败");
            }
        }
        // 更新站点状态
        agvLocMastService.updateLocStsByLocNo(agvWrkMast.getSourceLocNo(),"O","",null);
        // 更新源库位状态
        agvBasDevpService.updateLocStsAndBarcodeByDevNo(agvWrkMast.getLocNo(),"O","",agvWrkMast.getWhsType().shortValue());
        //删除AGV工作明细档
        agvWrkDetlService.delete(new EntityWrapper<AgvWrkDetl>().eq("wrk_no",oldWrkNo));
        return "ok";
    }
    /*
       调拨进场
    */
    @Override
    @Transactional
    public String allocationIn(AgvMobileStartPakin param, Long userId) {
        Date now = new Date();
        AgvWrkMast agvWrkMast = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("barcode", param.getBarcode()));
        if (agvWrkMast.getIoType() != 111) {
            throw new CoolException("非手动调拨任务,不支持次功能");
        }
        AgvBasDevp agvBasDevp = agvBasDevpService.selectByDevNo(param.getDevNo());
        if (Cools.isEmpty(agvWrkMast)) {
            throw new CoolException("工作档中没有此货架任务");
        }
        if (agvWrkMast.getCrnNo() != agvBasDevp.getFloor()) {
            throw new CoolException("请移动到->" + agvWrkMast.getCrnNo() + "楼入库点入库");
        }
        AgvLocMast locNo = agvCommonService.getLocNo(3, 1);
        //工作状态
        agvWrkMast.setWrkSts(211L);
        //入出库类型
        agvWrkMast.setIoType(112);
        agvWrkMast.setSourceLocNo(param.getDevNo());
        agvWrkMast.setModiUser(userId);
        agvWrkMast.setModiTime(now);
        if (!agvWrkMastService.update(agvWrkMast,new EntityWrapper<AgvWrkMast>().eq("wrk_no",agvWrkMast.getWrkNo()))) {
            throw new CoolException("更新工作档失败");
        }
        //
        agvLocMastService.updateLocStsByLocNo(locNo.getLocNo(),"S",agvWrkMast.getBarcode(),agvWrkMast.getWhsType().shortValue());
        // 更新源库位状态
        agvBasDevpService.updateLocStsAndBarcodeByDevNo(param.getDevNo(),"R",agvWrkMast.getBarcode(),agvWrkMast.getWhsType().shortValue());
        //删除AGV工作档
        return "ok";
    }
    /*
       空架离场
    */
    @Override
    @Transactional
    @Synchronized
    public String empOut(AgvMobileStartPakin param, Long userId) {
        Date now = new Date();
        AgvWrkMast agvWrkMast = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("source_loc_no", param.getDevNo()));
        Integer oldWrkNo = agvWrkMast.getWrkNo();
        if (Cools.isEmpty(agvWrkMast)) {
            throw new CoolException("工作档中没有此站点任务");
        }
        agvWrkMast.setWrkSts(213L);
        agvWrkMast.setSourceLocNo("");
        if (!agvWrkMastService.update(agvWrkMast,new EntityWrapper<AgvWrkMast>().eq("wrk_no",agvWrkMast.getWrkNo()))) {
            throw new CoolException("更新工作档失败");
        }
        // 更新源库位状态
        agvBasDevpService.updateLocStsAndBarcodeByDevNo(param.getDevNo(),"O","",agvWrkMast.getWhsType().shortValue());
        return "ok";
    }
    /*
       空架进场
    */
    @Override
    @Transactional
    @Synchronized
    public String empIn(AgvMobileStartPakin param, Long userId) {
        Date now = new Date();
        AgvWrkMast agvWrkMast = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("barcode", param.getBarcode()));
        if (Cools.isEmpty(agvWrkMast)) {
            throw new CoolException("工作档中没有此站点任务");
        }
        agvWrkMast.setWrkSts(214L);
        agvWrkMast.setSourceLocNo(param.getDevNo());
        if (!agvWrkMastService.update(agvWrkMast,new EntityWrapper<AgvWrkMast>().eq("wrk_no",agvWrkMast.getWrkNo()))) {
            throw new CoolException("更新工作档失败");
        }
        // 更新源库位状态
        agvBasDevpService.updateLocStsAndBarcodeByDevNo(param.getDevNo(),"F",param.getBarcode(),agvWrkMast.getWhsType().shortValue());
        return "ok";
    }
    /*
     * 站点回退
    */
    @Override
    @Transactional
    public String handBack(AgvMobileStartPakin param, Long userId) {
        Date now = new Date();
        AgvWrkMast agvWrkMast = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("source_loc_no", param.getDevNo()));
        agvWrkMast.setIoType(113);
        agvWrkMast.setModiUser(userId);
        agvWrkMast.setModiTime(now);
        if (!agvWrkMastService.update(agvWrkMast,new EntityWrapper<AgvWrkMast>().eq("wrk_no",agvWrkMast.getWrkNo()))) {
            throw new CoolException("更新工作档失败");
        }
        return "ok";
    }
    /*
     * 站点回退
     */
    @Override
    @Transactional
    public String doBack(AgvMobileStartPakin param, Long userId) {
        if (Cools.isEmpty(param.getBarcode()) || !CodeDetectionUtil.barcodeDetection(param.getBarcode())){
            throw new CoolException(param.getBarcode() + "货架码有误,请正确扫码!!!");
        }
        if (Cools.isEmpty(param.getDevNo()) || !CodeDetectionUtil.carCodeDetection(param.getDevNo())){
            throw new CoolException(param.getDevNo() + "小车地码有误,请正确扫码!!!");
        }
        Date now = new Date();
        AgvWrkMast agvWrkMast = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("loc_no", param.getDevNo()));
        AgvWrkMast agvWrkMastSource = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("source_loc_no", param.getDevNo()));
        if (!Cools.isEmpty(agvWrkMastSource)) {
            throw new CoolException("当前站点已有退库任务");
        }
        Integer oldWrkNo = agvWrkMast.getWrkNo();
        if (!agvWrkMast.getBarcode().equals(param.getBarcode())) {
            throw new CoolException("回退任务的货架码与当前货架码不一致!");
        }
        if (agvWrkMast.getWrkSts() != 205) {
            throw new CoolException("出库任务未完成!");
        }
        // 新建回退工作档
        AgvWrkMast wrkMast = createWrkMast(58, 201L, agvWrkMast.getLocNo(), agvWrkMast.getSourceLocNo(), agvWrkMast.getBarcode(), now, userId, agvWrkMast.getWhsType(), 0);
        // 更新接驳位,更新库位状态
        agvLocMastService.updateLocStsByLocNo(wrkMast.getLocNo(),"S",wrkMast.getBarcode(),wrkMast.getWhsType().shortValue());
        agvBasDevpService.updateLocStsAndBarcodeByDevNo(wrkMast.getSourceLocNo(),"R",wrkMast.getBarcode(),agvWrkMast.getWhsType().shortValue());
        // 更新工作明细
        List<AgvWrkDetl> agvWrkDetls = agvWrkDetlService.selectList(new EntityWrapper<AgvWrkDetl>().eq("supp_code", agvWrkMast.getBarcode()));
        for (AgvWrkDetl agvWrkDetl : agvWrkDetls) {
            agvWrkDetl.setWrkNo(wrkMast.getWrkNo());
            // 保持工作档明细
            agvWrkDetl.setWrkNo(wrkMast.getWrkNo());
            agvWrkDetl.setModiUser(userId);
            agvWrkDetl.setModiTime(now);
            if (!agvWrkDetlService.insert(agvWrkDetl)) {
                throw new CoolException("保存工作明细失败");
            }
            // 同步订单数量
            OrderDetl orderDetl = orderDetlService.selectOne(new EntityWrapper<OrderDetl>().eq("matnr", agvWrkDetl.getMatnr()).eq("three_code",agvWrkDetl.getThreeCode()).in("source",18,31,34));
            orderDetl.setQty(orderDetl.getQty() - agvWrkDetl.getAnfme());
            if (!orderDetlService.update(orderDetl,new EntityWrapper<OrderDetl>().eq("order_no",orderDetl.getOrderNo()).eq("matnr", orderDetl.getMatnr()).eq("three_code",orderDetl.getThreeCode()))){
                throw new CoolException("修改订单明细失败,请联系管理员"+orderDetl.getOrderNo()+orderDetl.getMatnr());
            }
        }
        //生成AGV工作历史档 + 生成AGV工作明细历史档
        agvWrkMastLogService.save(agvWrkMast);
        agvWrkDetlLogService.save(agvWrkMast.getWrkNo());
        //删除AGV工作档
        agvWrkMastService.deleteById(agvWrkMast);
        //删除AGV工作明细档
        agvWrkDetlService.delete(new EntityWrapper<AgvWrkDetl>().eq("wrk_no",oldWrkNo));
        return "ok";
    }
    /*
   更新目标库位信息
    */
    private void updateAgvLocMast(AgvLocMast locMast, String locSts){
        locMast.setLocSts(locSts);
        agvLocMastService.updateById(locMast);
    }
    /*
   生成工作档
    */
    private AgvWrkMast createWrkMast(int ioType, long wrkSts, String sourceLocNo, String locNo, String barcode,  Date now, Long userId, int containerType,int floor){
        AgvWrkMast wrkMast = new AgvWrkMast();
        //工作状态
        wrkMast.setWrkSts(wrkSts);
        //入出库类型
        wrkMast.setIoType(ioType);
        wrkMast.setIoTime(now);
        //优先级
        wrkMast.setIoPri(300.0);
        //源站点
        wrkMast.setSourceLocNo(sourceLocNo);
        //目标站点
        wrkMast.setLocNo(locNo);
        //货架编码
        wrkMast.setBarcode(barcode);
        //货架类型
        wrkMast.setWhsType(containerType);
        // 目标楼层
        wrkMast.setCrnNo(floor);
        wrkMast.setAppeUser(userId);
        wrkMast.setAppeTime(now);
        wrkMast.setModiUser(userId);
        wrkMast.setModiTime(now);
        if (!agvWrkMastService.insertByIncrease(wrkMast)) {
            throw new CoolException("保存工作档失败");
        }
        wrkMast = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("loc_no", locNo).eq("source_loc_no",sourceLocNo).eq("barcode",barcode).orderBy("modi_time",false));
        return wrkMast;
    }
}