zhoushihao
2024-07-03 22f5cee4b4f9a717df573456f3b149be697b17d1
hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/PlcStorageCageTask.java
@@ -72,25 +72,28 @@
    @Value("${mes.slotWidth}")
    private Integer slotWidth;
    @Value("${mes.carMaxSize}")
    private Integer carMaxSize;
    @Value("${mes.inCarMaxSize}")
    private Integer inCarMaxSize;
    @Value("${mes.outCarMaxSize}")
    private Integer outCarMaxSize;
    @Value("${mes.galssGap}")
    private Integer galssGap;
    //    @Scheduled(fixedDelay = 5000)
    @Scheduled(fixedDelay = 5000)
    public void plcToHomeEdgScan() {
        PlcParameterObject plcParameterObject = S7object.getinstance().PlcMesObject;
        String d01Id = plcParameterObject.getPlcParameter("D01ID").getValue();
        String d02Id = plcParameterObject.getPlcParameter("D02ID").getValue();
        String d04Id = plcParameterObject.getPlcParameter("D04ID").getValue();
        String d03State = plcParameterObject.getPlcParameter("D03State").getValue();
        String d05State = plcParameterObject.getPlcParameter("D05State").getValue();
        String mesD03Address = plcParameterObject.getPlcParameter("MESToD03").getAddress();
        String mesD05Address = plcParameterObject.getPlcParameter("MESToD05").getAddress();
        log.info("1、获取d01Id扫描ID为:{};获取d02Id扫描ID为:{};", d01Id, d02Id);
        if (StringUtils.isBlank(d01Id) && StringUtils.isBlank(d02Id)) {
        log.info("1、获取d01Id扫描ID为:{};获取d04Id扫描ID为:{};", d01Id, d04Id);
        if (StringUtils.isBlank(d01Id) && StringUtils.isBlank(d04Id)) {
            log.info("两条线未收到进片任务,结束本次扫描进卧转立任务");
            return;
        }
@@ -104,8 +107,8 @@
        if (StringUtils.isNotBlank(d01Id) && !REQUEST_WORD.equals(d03State)) {
            judgeGlassTypeStatus(d01Id, Const.A09_OUT_TARGET_POSITION, mesD03Address);
        }
        if (StringUtils.isNotBlank(d02Id) && !REQUEST_WORD.equals(d05State)) {
            judgeGlassTypeStatus(d02Id, Const.A10_OUT_TARGET_POSITION, mesD05Address);
        if (StringUtils.isNotBlank(d04Id) && !REQUEST_WORD.equals(d05State)) {
            judgeGlassTypeStatus(d04Id, Const.A10_OUT_TARGET_POSITION, mesD05Address);
        }
        log.info("结束扫码任务");
//        if (flag01 && flag04) {
@@ -146,10 +149,10 @@
            }
        }
        String d01Id = plcParameterObject.getPlcParameter("D01ID").getValue();
        String d02Id = plcParameterObject.getPlcParameter("D02ID").getValue();
        log.info("1、获取d01Id扫描ID为:{};获取d02Id扫描ID为:{};", d01Id, d02Id);
        String d04Id = plcParameterObject.getPlcParameter("D04ID").getValue();
        log.info("1、获取d01Id扫描ID为:{};获取d04Id扫描ID为:{};", d01Id, d04Id);
        //两条线都有进卧转立任务,直接结束
//        if (StringUtils.isNotBlank(d01Id) && StringUtils.isNotBlank(d02Id)) {
//        if (StringUtils.isNotBlank(d01Id) && StringUtils.isNotBlank(d04Id)) {
//            log.info("两条线都存在进片任务,结束任务");
//            return;
//        }
@@ -160,7 +163,7 @@
            return;
        }
        Integer lineFirst = lineList.get(0);
        String lineGlassId = lineFirst.equals(Const.A09_OUT_TARGET_POSITION) ? d01Id : d02Id;
        String lineGlassId = lineFirst.equals(Const.A09_OUT_TARGET_POSITION) ? d01Id : d04Id;
        //仅有一条先符合启动启动条件
        if (lineList.size() == 1) {
            //如果进片请求但玻璃为空,计算任务表进片格子 发送进片任务
@@ -176,22 +179,22 @@
            return;
        }
        //两条先均可执行进片任务,判断两条线是否进片请求是否都为空
        if (StringUtils.isBlank(d01Id) && StringUtils.isBlank(d02Id)) {
        if (StringUtils.isBlank(d01Id) && StringUtils.isBlank(d04Id)) {
            //比较最早一片任务的版图id及版序 求出卧转立的线路
            Integer line = getStartLine();
            //计算任务表进片格子 发送进片任务
            computeTargetByLine(line);
            return;
        } else if (StringUtils.isNotBlank(d01Id) && StringUtils.isNotBlank(d02Id)) {
        } else if (StringUtils.isNotBlank(d01Id) && StringUtils.isNotBlank(d04Id)) {
//            todo:两个都有进片玻璃
            if (computeIsRun(Const.A09_OUT_TARGET_POSITION, d01Id) && computeIsRun(Const.A10_OUT_TARGET_POSITION, d02Id)) {
            if (computeIsRun(Const.A09_OUT_TARGET_POSITION, d01Id) && computeIsRun(Const.A10_OUT_TARGET_POSITION, d04Id)) {
                //比较最早一片任务的版图id及版序 求出卧转立的线路
                Integer line = getStartLine();
                //计算任务表进片格子 发送进片任务
                computeTargetByLine(line);
            } else if (computeIsRun(Const.A09_OUT_TARGET_POSITION, d01Id)) {
                computeTargetByLine(Const.A09_OUT_TARGET_POSITION);
            } else if (computeIsRun(Const.A10_OUT_TARGET_POSITION, d02Id)) {
            } else if (computeIsRun(Const.A10_OUT_TARGET_POSITION, d04Id)) {
                computeTargetByLine(Const.A10_OUT_TARGET_POSITION);
            } else {
                return;
@@ -221,14 +224,14 @@
                .orderBy(Boolean.TRUE, sequenceOrder, TemperingGlassInfo::getTemperingFeedSequence));
        if (CollectionUtils.isNotEmpty(temperingGlassInfoList)) {
            log.info("有正在出片的钢化任务");
            computeOutGlassInfo(temperingGlassInfoList);
            computeOutGlassInfo(temperingGlassInfoList, Boolean.TRUE);
            return;
        }
        //是否有人工下片任务   有直接出
        List<BigStorageCageDetails> artificialList = bigStorageCageDetailsService.list(new LambdaQueryWrapper<BigStorageCageDetails>()
                .eq(BigStorageCageDetails::getState, Const.GLASS_STATE_ARTIFICIAL).orderByDesc(BigStorageCageDetails::getWidth));
        if (CollectionUtils.isNotEmpty(artificialList)) {
            computeOutGlassInfo(temperingGlassInfoList);
            computeOutGlassInfo(temperingGlassInfoList, Boolean.FALSE);
            return;
        }
        //钢化优先:获取理片笼  玻璃小片  破损表 数量   判断笼内版图是否到齐
@@ -245,7 +248,7 @@
                    .eq(GlassInfo::getTemperingLayoutId, temperingLayoutDTO.getTemperingLayoutId())
                    .eq(GlassInfo::getEngineerId, temperingLayoutDTO.getEngineerId()));
            temperingGlassInfoService.saveBatch(temperingGlassInfos);
            computeOutGlassInfo(temperingGlassInfoList);
            computeOutGlassInfo(temperingGlassInfoList, Boolean.TRUE);
            return;
        }
        //未到齐 执行内部调度任务
@@ -309,7 +312,7 @@
            Integer widthSecond = edgGlassTaskInfoList.get(1).getWidth();
            if (remainWidth >= widthFirst) {
                if (remainWidth - widthFirst - galssGap >= widthSecond) {
                    if (glassCount <= carMaxSize - 1) {
                    if (glassCount <= inCarMaxSize - 1) {
                        addFeedTask(glassId, line, Const.BIG_STORAGE_IN_WAIT, widthFirst);
                    } else {
                        addFeedTask(glassId, line, Const.BIG_STORAGE_IN_RUN, widthFirst);
@@ -398,7 +401,7 @@
            //2、获取目标格子信息
            BigStorageDTO bigStorageDTO = bigStorageCageDetailsService.queryTargetSlotByTempering(info);
            //3、更新大理片笼表剩余宽度
            bigStorageCageService.update(new LambdaUpdateWrapper<BigStorageCage>().set(BigStorageCage::getRemainWidth, bigStorageDTO.getWidth())
            bigStorageCageService.update(new LambdaUpdateWrapper<BigStorageCage>().set(BigStorageCage::getRemainWidth, bigStorageDTO.getWidth() - info.getWidth())
                    .eq(BigStorageCage::getSlot, bigStorageDTO.getSlot()));
            //4、更新进片任务表,目标格子及状态(状态改为2 电气扫到自行处理)  遇到问题:无法批量更新,批量更新无法走指定从库
            e.setTargetSlot(bigStorageDTO.getSlot());
@@ -421,24 +424,30 @@
        String mesD05Address = plcMesObject.getPlcParameter("MESToD05").getAddress();
        String outLine = line.equals(Const.A09_OUT_TARGET_POSITION) ? mesD03Address : mesD05Address;
        for (int i = 1; i <= taskList.size(); i++) {
            s7control.writeWord(plcMesObject.getPlcParameter("StartAddToImport" + i).getAddress(), (short) taskList.get(i).getLine());
            s7control.writeWord(plcMesObject.getPlcParameter("TargetAddToImport1" + i).getAddress(), (short) taskList.get(i).getTargetSlot());
            s7control.writeWord(plcMesObject.getPlcParameter("StartAddToImport" + i).getAddress(), (short) taskList.get(i - 1).getLine());
            s7control.writeWord(plcMesObject.getPlcParameter("TargetAddToImport" + i).getAddress(), (short) taskList.get(i - 1).getTargetSlot());
        }
        s7control.writeWord(outLine, (short) 1);
    }
    private <T extends BigStorageCageBaseInfo> Boolean computeOutGlassInfo(List<T> list) {
    private <T extends BigStorageCageBaseInfo> Boolean computeOutGlassInfo(List<T> list, Boolean isTempering) {
        //任务数据  获取车子存放玻璃最大数量  玻璃间隔
        List<BigStorageCageOutTask> bigStorageCageOutTaskList = new ArrayList<>();
        //打车剩余尺寸
        Integer remainWidth = carWidth;
        for (T e : list) {
            if (bigStorageCageOutTaskList.size() > carMaxSize || e.getWidth() > remainWidth) {
            if (bigStorageCageOutTaskList.size() > outCarMaxSize || e.getWidth() > remainWidth) {
                break;
            }
            remainWidth = remainWidth - (int) e.getWidth() - galssGap;
            bigStorageCageOutTaskList.add(new BigStorageCageOutTask(e.getGlassId(), e.getSlot(), Const.A09_OUT_TARGET_POSITION,
                    (int) e.getWidth(), 0, 0, 1));
            if (isTempering) {
                bigStorageCageOutTaskList.add(new BigStorageCageOutTask(e.getGlassId(), e.getSlot(), Const.TEMPERING_OUT_TARGET_POSITION,
                        (int) e.getWidth() * 10, 0, 0, 1));
            } else {
                bigStorageCageOutTaskList.add(new BigStorageCageOutTask(e.getGlassId(), e.getSlot(), Const.ARTIFICIAL_OUT_TARGET_POSITION,
                        (int) e.getWidth() * 10, 0, 0, 1));
            }
        }
        Assert.isFalse(CollectionUtils.isEmpty(bigStorageCageOutTaskList), "未获取出片数据,结束出片任务");
        log.info("获取出片任务数据{}条,执行保存", bigStorageCageOutTaskList.size());