| | |
| | | package com.mes.job; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.kangaroohy.milo.model.ReadWriteEntity; |
| | | import com.kangaroohy.milo.runner.subscription.SubscriptionCallback; |
| | | import com.kangaroohy.milo.service.MiloService; |
| | | import com.mes.common.config.Const; |
| | | import com.mes.edgglasstaskqueueinfo.entity.EdgGlassTaskQueueInfo; |
| | | import com.mes.edgglasstaskqueueinfo.service.EdgGlassTaskQueueInfoService; |
| | | import com.mes.opctask.entity.EdgStorageDeviceTask; |
| | | import com.mes.opctask.service.EdgStorageDeviceTaskService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Arrays; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Author : zhoush |
| | |
| | | @Slf4j |
| | | public class OpcCacheGlassTask { |
| | | |
| | | private static final String EDG_STORAGE_DEVICE_ONE_TASK = "edg_storage_device_one_task"; |
| | | |
| | | private static final String EDG_STORAGE_DEVICE_TWO_TASK = "edg_storage_device_two_task"; |
| | | |
| | | @Autowired(required = false) |
| | | MiloService miloService; |
| | | |
| | | |
| | | @Resource(name = "cacheGlassStartCallback") |
| | | SubscriptionCallback cacheGlassStartCallback; |
| | | |
| | | @Scheduled(fixedDelay = Long.MAX_VALUE) |
| | | @Resource(name = "cacheGlassTestCallback") |
| | | SubscriptionCallback cacheGlassTestCallback; |
| | | |
| | | @Resource |
| | | EdgStorageDeviceTaskService edgStorageDeviceTaskService; |
| | | @Resource |
| | | EdgGlassTaskQueueInfoService edgGlassTaskQueueInfoService; |
| | | private int sum = 0; |
| | | |
| | | @Scheduled(fixedDelay = 10) |
| | | public void startOpcTask() throws Exception { |
| | | // miloService.subscriptionFromOpcUa(Arrays.asList("C101-WL.S7-1200.plc_task_state", "D101-WL.S7-1200.plc_task_state"), cacheGlassStartCallback); |
| | | miloService.subscriptionFromOpcUa(Arrays.asList("mes.dec.edg_storage_device_one_task[1].task_state", "D101-WL.S7-1200.plc_task_state"), cacheGlassStartCallback); |
| | | log.info("--------------------s---------------------------"); |
| | | // miloService.subscriptionFromOpcUa(Arrays.asList("mes.dec.edg_storage_device_one_task[1].task_state", "D101-WL.S7-1200.plc_task_state"), cacheGlassTestCallback); |
| | | // log.info("--------------------s---------------------------"); |
| | | EdgStorageDeviceTask task = edgStorageDeviceTaskService.queryTaskMessage("edg_storage_device_one_task"); |
| | | try { |
| | | if (task == null) { |
| | | log.info("任务表基础数据录入失败,请检查数据是否录入成功"); |
| | | return; |
| | | } |
| | | if (task.getTaskState() == sum) { |
| | | return; |
| | | } |
| | | sum = task.getTaskState(); |
| | | task.setTaskRunning(sum); |
| | | log.info("当前第{}次执行", task.getTaskRunning()); |
| | | // task.setTaskState(task.getTaskRunning()); |
| | | edgStorageDeviceTaskService.updateTaskMessage("edg_storage_device_one_task", task); |
| | | } catch (Exception e) { |
| | | log.info("{}", e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | // mesControlWord glassId |
| | | // width height |
| | | // thickness filmRemove |
| | | // deviceControlWord deviceWarnState |
| | | |
| | | // @Scheduled(fixedDelay = 1000) |
| | | public void edgOpcTask() throws Exception { |
| | | ReadWriteEntity controlEntity = miloService.readFromOpcUa("A001-MB1.dev.deviceControlWord"); |
| | | String deviceControlWord = (String) controlEntity.getValue(); |
| | | if ("0".equals(deviceControlWord)) { |
| | | ReadWriteEntity messageEntity = miloService.readFromOpcUa("A001-MB1.dev.mesControlWord"); |
| | | String messageValue = (String) messageEntity.getValue(); |
| | | if ("1".equals(messageValue)) { |
| | | List<ReadWriteEntity> list = new ArrayList<>(); |
| | | list.add(generateReadWriteEntity("A001-MB1.dev.mesControlWord", 0)); |
| | | miloService.writeToOpcWord(list); |
| | | } |
| | | log.info("当前未收到磨边机的请求任务"); |
| | | return; |
| | | } |
| | | EdgStorageDeviceTask task = edgStorageDeviceTaskService.queryTaskMessage(EDG_STORAGE_DEVICE_ONE_TASK); |
| | | String glassId = task.getGlassId(); |
| | | if (StringUtils.isBlank(glassId)) { |
| | | log.info("磨边前的架子没有玻璃信息"); |
| | | return; |
| | | } |
| | | //获取磨边对列 |
| | | EdgGlassTaskQueueInfo edgInfo = edgGlassTaskQueueInfoService.getOne(new LambdaQueryWrapper<EdgGlassTaskQueueInfo>() |
| | | .eq(EdgGlassTaskQueueInfo::getGlassId, glassId) |
| | | .eq(EdgGlassTaskQueueInfo::getState, Const.GLASS_STATE_NEW)); |
| | | if (edgInfo == null) { |
| | | log.info("对列表中的玻璃id错误,请检查数据,玻璃id:{}", glassId); |
| | | return; |
| | | } |
| | | List<ReadWriteEntity> list = new ArrayList<>(); |
| | | list.add(generateReadWriteEntity("A001-MB1.dev.mesControlWord", 1)); |
| | | list.add(generateReadWriteEntity("A001-MB1.dev.glassId", glassId)); |
| | | list.add(generateReadWriteEntity("A001-MB1.dev.width", edgInfo.getWidth())); |
| | | list.add(generateReadWriteEntity("A001-MB1.dev.height", edgInfo.getHeight())); |
| | | list.add(generateReadWriteEntity("A001-MB1.dev.thickness", edgInfo.getThickness())); |
| | | list.add(generateReadWriteEntity("A001-MB1.dev.filmRemove", 0)); |
| | | miloService.writeToOpcWord(list); |
| | | } |
| | | |
| | | private ReadWriteEntity generateReadWriteEntity(String identifier, Object value) { |
| | | ReadWriteEntity readWriteEntity = new ReadWriteEntity(); |
| | | readWriteEntity.setIdentifier(identifier); |
| | | readWriteEntity.setValue(value); |
| | | return readWriteEntity; |
| | | } |
| | | } |