自动化立体仓库 - WMS系统
#
whycq
2024-05-21 0039eea93ca5fc77b2b9d0b0ab7babefe2316034
src/main/java/com/zy/asrs/service/impl/AgvMobileServiceImpl.java
@@ -7,13 +7,11 @@
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.LocMoveParam;
import com.zy.asrs.entity.param.MobileAdjustParam;
import com.zy.asrs.entity.param.PickParam;
import com.zy.asrs.entity.param.*;
import com.zy.asrs.service.*;
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;
@@ -55,6 +53,10 @@
    private AgvLocMastService agvLocMastService;
    @Autowired
    private AgvCommonService agvCommonService;
    @Autowired
    private AgvWrkMastLogService agvWrkMastLogService;
    @Autowired
    private AgvWrkDetlLogService agvWrkDetlLogService;
    /*
@@ -449,6 +451,126 @@
    }
    /*
       调拨离场
    */
    @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("工作档中没有此站点任务");
        }
        //生成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()));
        AgvBasDevp agvBasDevp = agvBasDevpService.selectByDevNo(param.getDevNo());
        if (Cools.isEmpty(agvWrkMast)) {
            throw new CoolException("工作档中没有此货架任务");
        }
        if (agvWrkMast.getCrnNo() != agvBasDevp.getFloor()) {
            throw new CoolException("请移动到->" + agvWrkMast.getCrnNo() + "楼入库点入库");
        }
        //工作状态
        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("更新工作档失败");
        }
        // 更新源库位状态
        agvBasDevpService.updateLocStsAndBarcodeByDevNo(param.getDevNo(),"F",agvWrkMast.getBarcode(),agvWrkMast.getWhsType().shortValue());
        //删除AGV工作档
        return "ok";
    }
    /*
     * 站点回退
    */
    @Override
    @Transactional
    public String doBack(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 (!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){
@@ -456,4 +578,41 @@
        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;
    }
}