zhoushihao
2024-05-09 47a468a30e24567783c1319cbd7874ef1226ddd5
hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/job/CacheGlassTask.java
@@ -45,47 +45,59 @@
    @Value("${mes.threshold}")
    private int threshold;
    @Scheduled(fixedDelay = 10000)
    @Scheduled(fixedDelay = 1000)
    public void plcHomeEdgTask() {
        PlcParameterObject plcParameterObject = S7object.getinstance().PlcMesObject;
        String taskRequestTypeValue = plcParameterObject.getPlcParameter("A06_request_word").getValue();
        String glassIdeValue = plcParameterObject.getPlcParameter("A05_scanning_ID").getValue();
        String confirmationWrodValue = plcParameterObject.getPlcParameter("MES_confirmation_word").getValue();
//        1为A09空闲,2为A10空闲,3为A09A10都空闲,0为A09A10都有玻璃
        String outGlassstate = plcParameterObject.getPlcParameter("A09_glass_status").getValue();
        String confirmationWrodAddress = plcParameterObject.getPlcParameter("MES_confirmation_word").getAddress();
        String currentSlot = plcParameterObject.getPlcParameter("Current_slot").getValue();
        log.info("1、获取到的请求字为:{},获取到的扫描ID为:{},获取到的确认字为:{},获取到的出片状态为:{},当前格子号为:{}",
                taskRequestTypeValue, glassIdeValue, confirmationWrodValue, outGlassstate, currentSlot);
        if ("0".equals(taskRequestTypeValue)) {
            log.info("1、获取到的请求字为0,将确认字改为0");
            if ("0".equals(confirmationWrodValue)) {
                log.info("2、获取到的请求字为0,且确认字为0,不执行任务");
                return;
            }
            log.info("2、获取到的请求字为0,将确认字改为0");
            S7object.getinstance().plccontrol.WriteWord(confirmationWrodAddress, (short) 0);
            return;
        }
        if (!"0".equals(confirmationWrodValue)) {
            log.info("1、获取到的请求字不为0,将确认字改为0");
            log.info("2、获取到的请求字不为0,将确认字改为0");
            S7object.getinstance().plccontrol.WriteWord(confirmationWrodAddress, (short) 0);
            return;
        }
        if ("1".equals(taskRequestTypeValue)) {
            log.info("2、进片请求,且确认字为0,执行进片任务");
            inTo(glassIdeValue, confirmationWrodAddress);
            log.info("3、进片请求,且确认字为0,执行进片任务");
            inTo(glassIdeValue, confirmationWrodAddress, currentSlot);
        } else if ("2".equals(taskRequestTypeValue)) {
            //09空闲 :1      10空闲 :2        都空闲:3    其他0
            log.info("2、出片请求,且确认字为0,执行进片任务");
            outTo(Integer.parseInt(outGlassstate), confirmationWrodAddress);
            log.info("3、出片请求,且确认字为0,执行进片任务");
            outTo(Integer.parseInt(outGlassstate), confirmationWrodAddress, currentSlot);
        } else if ("3".equals(taskRequestTypeValue)) {
            log.info("2、进片和出片都空闲,执行出片任务");
            log.info("3、进片和出片都空闲,执行出片任务");
            if ("0".equals(outGlassstate)) {
                inTo(glassIdeValue, confirmationWrodAddress);
                inTo(glassIdeValue, confirmationWrodAddress, currentSlot);
            } else {
                outTo(Integer.parseInt(outGlassstate), confirmationWrodAddress);
                outTo(Integer.parseInt(outGlassstate), confirmationWrodAddress, currentSlot);
            }
        }
    }
    private void inTo(String glassId, String confirmationWrodAddress) {
        log.info("1、按照玻璃id:{}获取玻璃小片信息", glassId);
    /**
     * 进片任务
     * @param glassId
     * @param confirmationWrodAddress
     * @param currentSlot
     */
    private void inTo(String glassId, String confirmationWrodAddress, String currentSlot) {
        log.info("1、按照玻璃id:{}获取玻璃小片信息,当前格子为:{}", glassId, currentSlot);
        GlassInfo glassInfo = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>().eq(GlassInfo::getGlassId, glassId));
        if (glassInfo == null) {
            log.info("2、此玻璃编号不存在");
@@ -93,39 +105,43 @@
        }
        log.info("2、获取到的玻璃信息为{}", glassInfo);
        //添加进片任务  查找空格
        List<EdgStorageCage> list = edgStorageCageService.selectCacheEmpty();
        log.info("3、查询卧式理片笼里面的空格:{}", list);
        if (CollectionUtil.isEmpty(list)) {
            log.info("4、不存在空格");
            return;
        }
        log.info("4、将玻璃信息插入卧式理片笼:{}", glassInfo);
        EdgStorageCage nearestEmpty = edgStorageCageService.selectNearestEmpty(Integer.parseInt(currentSlot));
        Assert.isTrue(nearestEmpty == null, "格子已满");
        log.info("3、查询卧式理片笼里面的空格:{}", nearestEmpty);
        log.info("4、将玻璃信息插入卧式理片笼,当前玻璃信息:{}", glassInfo);
        EdgStorageCageDetails details = new EdgStorageCageDetails();
        BeanUtils.copyProperties(glassInfo, details);
        details.setState(100);
        Integer slot = list.get(0).getSlot();
        Integer deviceId = list.get(0).getDeviceId();
        log.info("5、获取空闲格子为:{},设备号为{}", slot, deviceId);
        details.setSlot(slot);
        details.setDeviceId(deviceId);
        details.setState(Const.GLASS_STATE_IN);
        details.setSlot(nearestEmpty.getSlot());
        details.setDeviceId(nearestEmpty.getDeviceId());
        edgStorageCageDetailsService.save(details);
        log.info("5、玻璃信息已存入理片笼详情表,玻璃信息为{}", details);
        log.info("6、生成进片任务信息存入任务表");
        //添加进片任务
        TaskCache taskCache = new TaskCache();
        taskCache.setGlassId(glassId);
        taskCache.setTaskStatus(0);
        taskCache.setStartCell(0);
        taskCache.setEndCell(slot);
        taskCache.setEndCell(nearestEmpty.getSlot());
        taskCache.setTaskType(1);
        taskCache.setCreateTime(new Date());
        taskCacheService.insertTaskCache(taskCache);
        log.info("6、发送确认字");
        log.info("6、生成进片任务信息存入任务表{}", taskCache);
        S7object.getinstance().plccontrol.WriteWord(confirmationWrodAddress, (short) 1);
        log.info("7、发送确认字完成");
    }
    private void outTo(int line, String confirmationWrodAddress) {
    /**
     * 出片任务
     * @param line
     * @param confirmationWrodAddress
     * @param currentSlot
     */
    private void outTo(int line, String confirmationWrodAddress, String currentSlot) {
        Assert.isTrue(line != 0, "A09、A10都有玻璃,无法出片");
        log.info("1、出片任务出【{}】号线,备注(09空闲:1;10空闲:2;都空闲:3)", line);
        int endcell = 0;