zhoushihao
2024-10-11 d5d0d1c7a84b996b9bbcebfaf2c2c95f1a5a3678
hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/job/DownLoadCacheGlassTask.java
@@ -30,6 +30,7 @@
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -96,7 +97,6 @@
        log.info("1、获取到的请求字为:{},获取到的扫描ID为:{},获取到的确认字为:{},获取到的出片状态分别为:g06:{}、g08:{}、g11:{}、g13:{},当前格子号为:{}",
                requestWord, glassIdeValue, confirmationWrodValue, out06Glassstate, out08Glassstate, out11Glassstate, out13Glassstate, currentSlot);
        if ("0".equals(requestWord)) {
            if ("0".equals(confirmationWrodValue)) {
                log.info("2、获取到的请求字为0,且确认字为0,不执行任务");
@@ -131,10 +131,12 @@
    @Scheduled(fixedDelay = 300)
    public void plcShelfFull() {
        List<DownWorkstation> list = downGlassInfoService.queryWorkStationIsFull();
        S7control s7control = S7object.getinstance().plccontrol;
        PlcParameterObject plcMesObject = S7object.getinstance().PlcMesObject;
        if (CollectionUtils.isNotEmpty(list)) {
            S7control s7control = S7object.getinstance().plccontrol;
            PlcParameterObject plcMesObject = S7object.getinstance().PlcMesObject;
            s7control.writeWord(plcMesObject.getPlcParameter("alarm_signal").getAddress(), 1);
        } else {
            s7control.writeWord(plcMesObject.getPlcParameter("alarm_signal").getAddress(), 0);
        }
    }
@@ -149,6 +151,20 @@
            List<String> glassList = downGlassTaskList.stream().map(DownGlassTask::getGlassId).collect(Collectors.toList());
            //将任务表中的数据删除
            downGlassTaskService.remove(new LambdaQueryWrapper<DownGlassTask>().in(DownGlassTask::getTaskType, Const.GLASS_CACHE_TYPE_OUT_ALL).in(DownGlassTask::getGlassId, glassList));
            //清除下片玻璃信息表数据
            downGlassInfoService.remove(new LambdaQueryWrapper<DownGlassInfo>().in(DownGlassInfo::getGlassId, glassList));
            //下片数量-1
            for (DownGlassTask downGlassTask : downGlassTaskList
            ) {
                if (Const.GLASS_CACHE_TYPE_OUT_ALL.equals(downGlassTask.getTaskType())) {
                    downWorkstationService.update(
                            new LambdaUpdateWrapper<DownWorkstation>()
                                    .setSql("racks_number = racks_number-1")
                                    .eq(DownWorkstation::getWorkstationId, downGlassTask.getEndCell())
                    );
                }
            }
            List<Damage> damageList = downGlassTaskList.stream().map(e -> {
                Damage damage = new Damage();
                damage.setGlassId(e.getGlassId());
@@ -181,7 +197,10 @@
            //更新工位其他玻璃信息的数量
            QueryWrapper<Damage> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("process_id", downWorkstation.getFlowCardId());
            queryWrapper.eq("technology_number", downWorkstation.getLayer());
            queryWrapper.gt("type", 3);
            if (downWorkstation.getLayer() != 0) {
                queryWrapper.eq("technology_number", downWorkstation.getLayer());
            }
            int otherNumber = damageService.count(queryWrapper);
            downWorkstationService.update(new LambdaUpdateWrapper<DownWorkstation>().set(DownWorkstation::getOtherNumber, otherNumber)
                    .eq(DownWorkstation::getWorkstationId, downWorkstation.getWorkstationId()));
@@ -211,9 +230,16 @@
        } else {
            log.info("该玻璃尺寸非人工下片");
            //获取该玻璃的流程卡是否已绑定架子
            DownWorkstation one = downWorkstationService.getOne(new LambdaQueryWrapper<DownWorkstation>()
                    .eq(DownWorkstation::getLayer, glassInfo.getLayer())
                    .eq(DownWorkstation::getFlowCardId, glassInfo.getFlowCardId()));
            DownWorkstation one;
            if (glassInfo.getCombine() != 0) {
                one = downWorkstationService.getOne(new LambdaQueryWrapper<DownWorkstation>()
                        .eq(DownWorkstation::getFlowCardId, glassInfo.getFlowCardId()));
            } else {
                one = downWorkstationService.getOne(new LambdaQueryWrapper<DownWorkstation>()
                        .eq(DownWorkstation::getLayer, glassInfo.getLayer())
                        .eq(DownWorkstation::getFlowCardId, glassInfo.getFlowCardId()));
            }
            //是否已经绑定   true:已绑定    false:未绑定
            Boolean isBind = Boolean.FALSE;
            if (null != one) {
@@ -228,7 +254,12 @@
                if (CollectionUtils.isNotEmpty(list)) {
                    log.info("有空架子,将流程卡与架子好绑定,执行进片任务 结束");
                    //绑定流程卡
                    downWorkstationService.updateFlowCardIdAndCount(glassInfo.getFlowCardId(), list.get(0).getWorkstationId(), glassInfo.getLayer());
                    if (glassInfo.getCombine() == 0) {
                        downWorkstationService.updateFlowCardIdAndCount(glassInfo.getFlowCardId(), list.get(0).getWorkstationId(), glassInfo.getLayer());
                    } else {
                        downWorkstationService.updateFlowCardIdAndCount(glassInfo.getFlowCardId(), list.get(0).getWorkstationId(), 0);
                    }
//                      downWorkstationService.updateFlowCardIdAndCount(glassInfo.getFlowCardId(), list.get(0).getId(), glassInfo.getLayer());
                    checkFlag = Boolean.TRUE;
                }
            }
@@ -277,12 +308,18 @@
        //将任务插入理片笼详情表
        DownStorageCageDetails downStorageCageDetails = new DownStorageCageDetails();
        BeanUtils.copyProperties(glassInfo, downStorageCageDetails);
        //当需要合并落架时不绑定层号
        if (glassInfo.getCombine() != 0) {
            downStorageCageDetails.setLayer(0);
        }
        downStorageCageDetails.setState(Const.GLASS_STATE_IN);
        downStorageCageDetails.setSlot(nearestEmpty.getSlot());
        downStorageCageDetails.setDeviceId(nearestEmpty.getDeviceId());
        downStorageCageDetailsService.save(downStorageCageDetails);
        //        生成进片任务
        initDownGlassTask(glassInfo, 0, nearestEmpty.getSlot(), Const.GLASS_CACHE_TYPE_IN);
        //删除理片笼表拿走/破损数据数据
        damageService.deleteByGlassId(glassInfo.getGlassId());
    }
    public Boolean outTo(String glassStatus06, String out08Glassstate, String glassStatus11, String
@@ -299,6 +336,10 @@
        if (StringUtils.isNotBlank(glassId)) {
            GlassInfo glassInfo = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>().eq(GlassInfo::getGlassId, glassId));
            BeanUtils.copyProperties(glassInfo, cageDetails);
            //当需要合并落架时不绑定层号
            if (glassInfo.getCombine() != 0) {
                cageDetails.setLayer(0);
            }
            //获取当前笼子空格信息
            DownStorageCage empty = downStorageCageService.selectCacheEmpty(Integer.parseInt(currentSlot), Boolean.TRUE);
            cageDetails.setSlot(empty.getSlot());
@@ -315,6 +356,7 @@
        //2、08台空闲,先走扔工下片或2号机械臂,无玻璃出片 在走1号机械臂
        //机械臂被禁用的情况下不能继续向禁用的机械臂放玻璃
        Boolean flag08 = "1".equals(out08Glassstate) ? Boolean.TRUE : Boolean.FALSE;
        flag08 = true;
        if (!flag08) {
            generateTaskByShelf(glassStatus06, glassStatus11, flag08, glassStatus13, tempList, cageDetails, glassId);
        } else {
@@ -367,11 +409,21 @@
        List<Integer> workList = new ArrayList();
        if (flag08) {
            if (!"2".equals(glassStatus11)) {
                workList.addAll(Const.G11_WORK_STATION);
                List<Integer> wroklistOne = downWorkstationService.list(new LambdaQueryWrapper<DownWorkstation>()
                        .eq(DownWorkstation::getEnableState, Const.SLOT_ON).in(DownWorkstation::getWorkstationId, Const.G11_WORK_STATION))
                        .stream()
                        .map(DownWorkstation::getWorkstationId)
                        .collect(Collectors.toList());
                workList.addAll(wroklistOne);
            }
        } else {
            if (!"2".equals(glassStatus06)) {
                workList.addAll(Const.G06_WORK_STATION);
                List<Integer> wroklistTwo = downWorkstationService.list(new LambdaQueryWrapper<DownWorkstation>()
                        .eq(DownWorkstation::getEnableState, Const.SLOT_ON).in(DownWorkstation::getWorkstationId, Const.G06_WORK_STATION))
                        .stream()
                        .map(DownWorkstation::getWorkstationId)
                        .collect(Collectors.toList());
                workList.addAll(wroklistTwo);
            }
        }
        List<Integer> workStationAll = Arrays.asList(1, 2, 3, 4, 5, 6);
@@ -405,6 +457,7 @@
                    Map<String, List<DownWorkstation>> listMap = downWorkstationList.stream()
                            .filter(item -> StringUtils.isNotBlank(item.getFlowCardId())).collect(Collectors.groupingBy(item -> item.getFlowCardId() + ":" + item.getLayer()));
                    //过滤筛选获取架子上对应流程卡+层数的笼子内的玻璃信息
                    list = tempList.stream().filter(item -> listMap.containsKey(item.getFlowCardId() + ":" + item.getLayer())).collect(Collectors.toList());
                    if (CollectionUtils.isEmpty(list) && flag08 && !"2".equals(glassStatus13)) {
                        list = tempList.stream().filter(item -> {
@@ -580,15 +633,27 @@
            if (null != emptyDownWorkstation) {
                log.info("获取到空架子信息,绑定流程卡");
                downWorkstationService.updateFlowCardIdAndCount(downStorageCageDetails.getFlowCardId(), emptyDownWorkstation.getWorkstationId(), downStorageCageDetails.getLayer());
//                downWorkstationService.updateFlowCardIdAndCount(downStorageCageDetails.getFlowCardId(), emptyDownWorkstation.getId(), downStorageCageDetails.getLayer());
                endCell = emptyDownWorkstation.getWorkstationId();
            } else {
                //todo:增加虚拟工位,绑定流程卡
//                downWorkstationService.insertDownWorkstation();
//                endCell = Const.G13_WORK_STATION;
//                downWorkstationService.updateFlowCardIdAndCount(downStorageCageDetails.getFlowCardId(), emptyDownWorkstation.getId(), downStorageCageDetails.getLayer());
                log.info("没有空架子信息,无法绑定流程卡");
                return Boolean.FALSE;
            }
        } else {
            DownWorkstation workstation = downWorkstationService.getOne(new LambdaUpdateWrapper<DownWorkstation>()
                    .eq(DownWorkstation::getFlowCardId, downStorageCageDetails.getFlowCardId()).eq(DownWorkstation::getLayer, downStorageCageDetails.getLayer()));
            endCell = workstation.getWorkstationId();
            double firstLength = Math.max(downStorageCageDetails.getWidth(), downStorageCageDetails.getHeight());
            double secondLength = Math.min(downStorageCageDetails.getWidth(), downStorageCageDetails.getHeight());
            if (firstLength > maxWidth || secondLength > maxHeight) {
                endCell = Const.G13_WORK_STATION;
            } else {
                DownWorkstation workstation;
                workstation = downWorkstationService.getOne(new LambdaUpdateWrapper<DownWorkstation>()
                        .eq(DownWorkstation::getFlowCardId, downStorageCageDetails.getFlowCardId()).eq(DownWorkstation::getLayer, downStorageCageDetails.getLayer()));
                endCell = workstation.getWorkstationId();
            }
        }
        //更新落架玻璃数量
        if (endCell == Const.G13_WORK_STATION) {
@@ -603,13 +668,31 @@
        DownGlassInfo downGlassInfo = new DownGlassInfo();
        BeanUtils.copyProperties(downStorageCageDetails, downGlassInfo);
        //落架片序
        downGlassInfo.setSequence(downGlassInfoService.queryMaxSequence(downGlassInfo.getFlowCardId(), downGlassInfo.getLayer()));
        LambdaQueryWrapper<DownGlassInfo> wrapper = new LambdaQueryWrapper<DownGlassInfo>();
        wrapper.eq(DownGlassInfo::getFlowCardId, downGlassInfo.getFlowCardId())
                .orderByDesc(DownGlassInfo::getSequence)
                .last("limit 1");
        if (downStorageCageDetails.getLayer() != 0) {
            wrapper.eq(DownGlassInfo::getLayer, downGlassInfo.getLayer());
        }
//        downGlassInfo.setSequence(downGlassInfoService.queryMaxSequence(downGlassInfo.getFlowCardId(), downGlassInfo.getLayer()));
        int k = 0;
        DownGlassInfo downGlassInfo1 = downGlassInfoService.getOne(wrapper);
        if (downGlassInfo1 != null) {
            k = 1;
        } else {
            k = 1;
        }
        downGlassInfo.setSequence(k);
        downGlassInfo.setWorkStationId(endCell);
        downGlassInfo.setGmtCreate(new Date());
        downGlassInfoService.save(downGlassInfo);
        //生成任务信息
        GlassInfo glassInfo = new GlassInfo();
        downStorageCageDetails.setLayer(0);
        BeanUtils.copyProperties(downStorageCageDetails, glassInfo);
        //删除理片笼表拿走/破损数据数据
        damageService.deleteByGlassId(glassInfo.getGlassId());
        return initDownGlassTask(glassInfo, downStorageCageDetails.getSlot(), endCell, taskType);
    }
@@ -627,6 +710,14 @@
        downGlassTask.setTaskStatus(0);
        downGlassTask.setCreateTime(new Date());
        downGlassTaskService.save(downGlassTask);
        //添加报工数据
        Damage damage = new Damage();
        damage.setGlassId(glassInfo.getGlassId());
        damage.setWorkingProcedure("钢化");
        damage.setLine(4001);
        damage.setType(1);
        damage.setRemark("钢化后卧式理片");
        damageService.insertDamage(damage);
        //向plc发送命令
        return sendMessageToPlc((int) glassInfo.getWidth(), (int) glassInfo.getHeight(), (int) glassInfo.getThickness(),
                startCell, endCell, taskType);