自动化立体仓库 - WMS系统
*
lsh
3 天以前 49f306cb470a8ee824204b701796d1d8f63ff223
src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java
@@ -23,6 +23,8 @@
import com.zy.common.properties.SlaveProperties;
import com.zy.common.service.CommonService;
import com.zy.common.web.WcsController;
import com.zy.system.entity.Config;
import com.zy.system.service.ConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -74,6 +76,8 @@
    @Autowired
    private OrderDetlService orderDetlService;
    @Autowired
    private ConfigService configService;
    @Autowired
    private WcsController wcsController;
    @Autowired
    private RowLastnoService rowLastnoService;
@@ -93,6 +97,12 @@
    @Resource
    private OrderPakoutService orderPakOutService;
    @Resource
    private BasAgvLocDetlService basAgvLocDetlService;
    @Resource
    private BasAgvWrkDetlService basAgvWrkDetlService;
    @Override
    @Transactional
@@ -307,6 +317,8 @@
                dtos.add(new OutLocDto(locNo, locDetlDto));
            }
        }
        Config configAutoMPArea = configService.selectConfigByCode("AutoMPArea");
        Integer ioType = null;
        // 生成工作档
        for (OutLocDto dto : dtos) {
@@ -328,6 +340,10 @@
            // 获取路径
            StaDesc staDesc = staDescService.queryCrnStn(ioType, locMast.getCrnNo(), outSta);
            if(ioType.equals(107)){
                staDesc = staDescService.queryCrnStnCheck(ioType, locMast.getCrnNo(), outSta);
            }
            // 生成工作号
            int workNo = commonService.getWorkNo(WorkNoType.getWorkNoType(ioType));
            // 生成工作档
@@ -347,6 +363,26 @@
            wrkMast.setEmptyMk("N"); // 空板
            wrkMast.setLinkMis("N");
            wrkMast.setBarcode(locMast.getBarcode());
            wrkMast.setTakeNone("0");  //0非自动
            List<BasAgvWrkDetl> basAgvWrkDetls = null;
            List<BasAgvLocDetl> basAgvLocDetls = null;
            try{
                if (Boolean.parseBoolean(configAutoMPArea.getValue())){
                    if (wrkMast.getStaNoAgvSign()){
                        if (ioType==101){
                            // 全板出库
                            basAgvLocDetls = new ArrayList<>();
                        } else {
                            // 拣料出库
                            basAgvWrkDetls = new ArrayList<>();
                        }
                        wrkMast.setTakeNone("1"); //等待下发
                    } else {
                        wrkMast.setTakeNone("3");  //无需AGV搬运
                    }
                }
            } catch (Exception e) {}  //配置项不存在,不做处理
            wrkMast.setAppeUser(userId); // 操作人员数据
            wrkMast.setAppeTime(now);
            wrkMast.setModiUser(userId);
@@ -354,6 +390,7 @@
            if (!wrkMastService.insert(wrkMast)) {
                throw new CoolException("保存工作档失败,出库库位号:"+dto.getLocNo());
            }
            // 生成工作档明细
            for (LocDetlDto detlDto : dto.getLocDetlDtos()) {
                if (detlDto.getCount()==null || detlDto.getCount() <= 0.0D) {continue;}
@@ -368,13 +405,48 @@
                wrkDetl.setAppeUser(userId);
                wrkDetl.setModiTime(now);
                wrkDetl.setModiUser(userId);
                try{
                    if (basAgvWrkDetls != null){
                        BasAgvWrkDetl basAgvWrkDetl = new BasAgvWrkDetl();
                        basAgvWrkDetl.sync(wrkDetl);
                        basAgvWrkDetls.add(basAgvWrkDetl);
                    }
                } catch (Exception e) {}  //配置项不存在,不做处理
                if (!wrkDetlService.insert(wrkDetl)) {
                    throw new CoolException("保存工作档明细失败");
                }
            }
//            if(locMastRgv !=null){
//                if (Boolean.parseBoolean(config.getValue()) && locMastRgv.getLocNo() != null && ioType != 107) {  //若有空库位且配置允许则绑定其备料库位号
//                    //修改agv备料区状态
//                    if(locMastRgv.getLocSts().equals("O") && ioType != 107){
//                        locMastRgv.setLocSts("S");
//                        locMastRgv.setModiUser(userId);
//                        locMastRgv.setModiTime(now);
//                        if (!locMastService.updateById(locMastRgv)) {
//                            throw new CoolException("预约agv备料区库位状态失败,库位号:"+locMastRgv.getLocNo());
//                        }
//                    }
//                }
//            }
            // 修改库位状态:   F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中
            locMast = locMastService.selectById(dto.getLocNo());
            if (locMast.getLocSts().equals("F")) {
                try{
                    if (basAgvLocDetls != null){
                        List<LocDetl> locDetlList = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", locMast.getLocNo()));
                        for (LocDetl locDetl : locDetlList) {
                            BasAgvLocDetl basAgvLocDetl = new BasAgvLocDetl();
                            basAgvLocDetl.sync(locDetl);
                            basAgvLocDetls.add(basAgvLocDetl);
                        }
                    }
                } catch (Exception e) {}  //配置项不存在,不做处理
                locMast.setLocSts(ioType==101?"R":"P");
                locMast.setModiUser(userId);
                locMast.setModiTime(now);
@@ -384,6 +456,21 @@
            } else {
                throw new CoolException(dto.getLocNo() + "库位不是在库状态");
            }
            try{
                // 增加AGV库存中转数量
                if (basAgvLocDetls != null){
                    for (BasAgvLocDetl basAgvLocDetl : basAgvLocDetls) {
                        basAgvLocDetlService.insert(basAgvLocDetl);
                    }
                }
                if (basAgvWrkDetls != null){
                    for (BasAgvWrkDetl basAgvWrkDetl : basAgvWrkDetls) {
                        basAgvWrkDetlService.insert(basAgvWrkDetl);
                    }
                }
            }catch (Exception e){}
        }
    }
@@ -397,6 +484,8 @@
                throw new CoolException("订单出库异常,请联系管理员");
            }
        }
        Config configAutoMPArea = configService.selectConfigByCode("AutoMPArea");
        // 获取库位
        LocMast locMast = locMastService.selectById(taskDto.getLocNo());
        // 判断是否是盘点单
@@ -404,6 +493,16 @@
        OrderPakout orderPakout = orderPakOutService.selectByNo(orderNo);
        int ioType = orderPakout.getDocType() == 8 ? 107 : (taskDto.isAll() ? 101 : 103);
        StaDesc staDesc = staDescService.queryCrnStnAuto(ioType, locMast.getCrnNo(), staNo.getDevNo());
        List<LocMast> list = locMastMapper.selectList(
                new EntityWrapper<LocMast>()
                        .eq("whs_type", 5)
                        .eq("loc_sts", "O")
        );
        LocMast locMastRgv = list.isEmpty() ? null : list.get(0);
        // 生成工作号
        int workNo = commonService.getWorkNo(WorkNoType.getWorkNoType(ioType));
        // 生成工作档
@@ -417,6 +516,27 @@
        wrkMast.setSourceStaNo(staDesc.getCrnStn()); // 源站
        wrkMast.setStaNo(staDesc.getStnNo()); // 目标站
        wrkMast.setSourceLocNo(taskDto.getLocNo()); // 源库位
        wrkMast.setTakeNone("0");  //0非自动
        List<BasAgvWrkDetl> basAgvWrkDetls = null;
        List<BasAgvLocDetl> basAgvLocDetls = null;
        try{
            if (Boolean.parseBoolean(configAutoMPArea.getValue())){
                if (wrkMast.getStaNoAgvSign()){
                    if (ioType==101){
                        // 全板出库
                        basAgvLocDetls = new ArrayList<>();
                    } else {
                        // 拣料出库
                        basAgvWrkDetls = new ArrayList<>();
                    }
                    wrkMast.setTakeNone("1"); //等待下发
                } else {
                    wrkMast.setTakeNone("3");  //无需AGV搬运
                }
            }
        } catch (Exception e) {}  //配置项不存在,不做处理
        wrkMast.setFullPlt("Y"); // 满板:Y
        wrkMast.setPicking("N"); // 拣料
        wrkMast.setExitMk("N"); // 退出
@@ -453,6 +573,15 @@
            wrkDetl.setAppeUser(userId);
            wrkDetl.setModiTime(now);
            wrkDetl.setModiUser(userId);
            try{
                if (basAgvWrkDetls != null){
                    BasAgvWrkDetl basAgvWrkDetl = new BasAgvWrkDetl();
                    basAgvWrkDetl.sync(wrkDetl);
                    basAgvWrkDetls.add(basAgvWrkDetl);
                }
            } catch (Exception e) {}  //配置项不存在,不做处理
            if (!wrkDetlService.insert(wrkDetl)) {
                throw new CoolException("保存工作档明细失败");
            }
@@ -467,9 +596,32 @@
                    , locDto.getAnfme());
            OrderInAndOutUtil.updateOrder(Boolean.FALSE,orderDetl.getOrderId(), 2L, userId);
        }
        //修改agv备料区状态
        if(locMastRgv.getLocSts().equals("O")){
            locMastRgv.setLocSts("S");
            locMastRgv.setModiUser(userId);
            locMastRgv.setModiTime(now);
            if (!locMastService.updateById(locMastRgv)) {
                throw new CoolException("预约agv备料区库位状态失败,库位号:"+locMastRgv.getLocNo());
            }
        }else{
            throw new CoolException(locMastRgv.getLocNo() + "备料区不是空库位状态");
        }
        // 修改库位状态:   F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中
        locMast = locMastService.selectById(taskDto.getLocNo());
        if (locMast.getLocSts().equals("F")) {
            try{
                if (basAgvLocDetls != null){
                    List<LocDetl> locDetlList = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", locMast.getLocNo()));
                    for (LocDetl locDetl : locDetlList) {
                        BasAgvLocDetl basAgvLocDetl = new BasAgvLocDetl();
                        basAgvLocDetl.sync(locDetl);
                        basAgvLocDetls.add(basAgvLocDetl);
                    }
                }
            } catch (Exception e) {}  //配置项不存在,不做处理
            locMast.setLocSts(ioType==101?"R":"P");
            locMast.setModiUser(userId);
            locMast.setModiTime(now);
@@ -479,6 +631,23 @@
        } else {
            throw new CoolException(taskDto.getLocNo() + "库位不是在库状态");
        }
        try{
            // 增加AGV库存中转数量
            if (basAgvLocDetls != null){
                for (BasAgvLocDetl basAgvLocDetl : basAgvLocDetls) {
                    basAgvLocDetlService.insert(basAgvLocDetl);
                }
            }
            if (basAgvWrkDetls != null){
                for (BasAgvWrkDetl basAgvWrkDetl : basAgvWrkDetls) {
                    basAgvWrkDetlService.insert(basAgvWrkDetl);
                }
            }
        }catch (Exception e){}
    }
    @Override
@@ -1128,6 +1297,16 @@
        //取消出库工作档时,查询单据管理表,回滚作业中数量
        if(wrkMast.getIoType() == 101 || wrkMast.getIoType() == 103) {
            List<WrkDetl> wrkDetls = wrkDetlService.selectByWrkNo(wrkMast.getWrkNo());
            if(wrkMast.getLocNo() != null){
                LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
                locMast.setLocSts("O");
                locMast.setModiTime(now);
                locMast.setModiUser(userId);
                boolean locMastRes = locMastService.updateById(locMast);
                if (!locMastRes) {
                    throw new CoolException("保存数据失败");
                }
            }
            for (WrkDetl wrkDetl : wrkDetls) {
                if (!Cools.isEmpty(wrkDetl.getOrderNo())) {
//                    if (!orderDetlService.decrease(wrkDetl.getOrderNo(), wrkDetl.getMatnr(), wrkDetl.getBatch(), wrkDetl.getAnfme())) {
@@ -1201,15 +1380,17 @@
        // 修改库位状态
        LocMast locMast = locMastService.selectById(locNo);
        if (Cools.isEmpty(locMast)) {
        if (Cools.isEmpty(locMast) && wrkMast.getIoType() != 12) {
            throw new CoolException("取消工作档失败,库位不存在:"+ locNo);
        }
        locMast.setLocSts(locSts);
        locMast.setModiTime(now);
        locMast.setModiUser(userId);
        boolean locMastRes = locMastService.updateById(locMast);
        if (!wrkMastRes || !locMastRes) {
            throw new CoolException("保存数据失败");
        if(wrkMast.getIoType() != 12){
            locMast.setLocSts(locSts);
            locMast.setModiTime(now);
            locMast.setModiUser(userId);
            boolean locMastRes = locMastService.updateById(locMast);
            if (!wrkMastRes || !locMastRes) {
                throw new CoolException("保存数据失败");
            }
        }
    }