From e3307d42a20a6f6305cb55b559a0065db3cebc75 Mon Sep 17 00:00:00 2001
From: zhoushihao <zsh19950802@163.com>
Date: 星期三, 20 十一月 2024 08:41:14 +0800
Subject: [PATCH] 1、大理片笼历史任务功能开发 2、大理片笼任务表4张、历史任务表一张脚本 3、大理片笼进片任务功能开发 4、解决卧理生产中遇到的bug

---
 hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/job/OpcCacheGlassTask.java |  120 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 110 insertions(+), 10 deletions(-)

diff --git a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/job/OpcCacheGlassTask.java b/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/job/OpcCacheGlassTask.java
index 165ff7f..f2aac7c 100644
--- a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/job/OpcCacheGlassTask.java
+++ b/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/job/OpcCacheGlassTask.java
@@ -1,11 +1,27 @@
 package com.mes.job;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+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.glassinfo.entity.GlassInfo;
+import com.mes.glassinfo.service.GlassInfoService;
+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.ArrayList;
 import java.util.Arrays;
+import java.util.List;
 
 /**
  * @Author : zhoush
@@ -16,14 +32,98 @@
 @Slf4j
 public class OpcCacheGlassTask {
 
-//    @Autowired
-//    MiloService miloService;
-//
-//    @Autowired
-//    SubscriptionCallback cacheGlassSubscriptionCallback;
-//
-//    @Scheduled(fixedDelay = Long.MAX_VALUE)
-//    public void startOpcTask() throws Exception {
-//        miloService.subscriptionFromOpcUa(Arrays.asList("my.device.x1", "my.device.x2"), cacheGlassSubscriptionCallback);
-//    }
+    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;
+
+    @Resource(name = "cacheGlassTestCallback")
+    SubscriptionCallback cacheGlassTestCallback;
+
+    @Resource
+    EdgStorageDeviceTaskService edgStorageDeviceTaskService;
+    @Resource
+    EdgGlassTaskQueueInfoService edgGlassTaskQueueInfoService;
+
+    @Resource
+    GlassInfoService glassInfoService;
+
+    private String glassIdOne = "";
+    private String glassIdTwo = "";
+
+    @Scheduled(fixedDelay = Long.MAX_VALUE)
+    public void startOneOpcTask() throws Exception {
+        miloService.subscriptionFromOpcUa(Arrays.asList("mes.WL1.edg_storage_device_one_task[1].task_state"), cacheGlassStartCallback);
+    }
+
+    @Scheduled(fixedDelay = Long.MAX_VALUE)
+    public void startTwoOpcTask() throws Exception {
+        miloService.subscriptionFromOpcUa(Arrays.asList("mes.WL2.edg_storage_device_two_task[1].task_state", "PLC.WL2.plc_task_tate"), cacheGlassStartCallback);
+    }
+
+    @Scheduled(fixedDelay = 1000)
+    public void edgOneOpcTask() throws Exception {
+        EdgStorageDeviceTask task = edgStorageDeviceTaskService.queryTaskMessage(EDG_STORAGE_DEVICE_ONE_TASK);
+        String glassId = task.getGlassId();
+        if (StringUtils.isBlank(glassId) || glassId.equals(glassIdOne)) {
+            log.info("{}鍙风嚎纾ㄨ竟鍓嶇幓鐠冩湭灏变綅锛岀粨鏉熸湰娆′换鍔�", 1);
+            return;
+        }
+        edgTaskChild(glassId, 1);
+    }
+
+    @Scheduled(fixedDelay = 1000)
+    public void edgTwoOpcTask() throws Exception {
+        EdgStorageDeviceTask task = edgStorageDeviceTaskService.queryTaskMessage(EDG_STORAGE_DEVICE_TWO_TASK);
+        String glassId = task.getGlassId();
+        if (StringUtils.isBlank(glassId) || glassId.equals(glassIdTwo)) {
+            log.info("{}鍙风嚎纾ㄨ竟鍓嶇幓鐠冩湭灏变綅锛岀粨鏉熸湰娆′换鍔�", 2);
+            return;
+        }
+        edgTaskChild(glassId, 2);
+    }
+
+    private void edgTaskChild(String glassId, int cell) throws Exception {
+        GlassInfo glassInfo = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>().eq(GlassInfo::getGlassId, glassId).last("limit 1"));
+        if (glassInfo == null) {
+            log.info("瀵瑰垪琛ㄤ腑鐨勭幓鐠僫d閿欒锛岃妫�鏌ユ暟鎹紝鐜荤拑id锛歿}", glassId);
+            return;
+        }
+        String toEndingId = glassInfo.getTemperingLayoutId() + "" + glassInfo.getTemperingFeedSequence();
+        List<ReadWriteEntity> list = new ArrayList<>();
+//        list.add(generateReadWriteEntity("PLC.MB" + cell + ".mesControl", true));
+        list.add(generateReadWriteEntity("PLC.MB" + cell + ".glassId", Integer.parseInt(toEndingId)));
+        list.add(generateReadWriteEntity("PLC.MB" + cell + ".toEdingId", Integer.parseInt(toEndingId)));
+        list.add(generateReadWriteEntity("PLC.MB" + cell + ".width", (int) Math.max(glassInfo.getWidth() * 10, glassInfo.getHeight() * 10)));
+        list.add(generateReadWriteEntity("PLC.MB" + cell + ".height", (int) Math.min(glassInfo.getWidth() * 10, glassInfo.getHeight() * 10)));
+
+        miloService.writeToOpcUa(list);
+        miloService.writeToOpcWord(generateReadWriteEntity("PLC.MB" + cell + ".thickness", (int) glassInfo.getThickness() * 10));
+        //淇敼纾ㄨ竟瀵瑰垪涓殑纾ㄨ竟绾胯矾鍙婄姸鎬�
+        edgGlassTaskQueueInfoService.update(new LambdaUpdateWrapper<EdgGlassTaskQueueInfo>()
+                .set(EdgGlassTaskQueueInfo::getLine, cell)
+                .set(EdgGlassTaskQueueInfo::getState, 1)
+                .eq(EdgGlassTaskQueueInfo::getGlassId, glassId)
+                .eq(EdgGlassTaskQueueInfo::getState, Const.GLASS_STATE_NEW));
+        if (cell == 1) {
+            glassIdOne = glassId;
+        } else {
+            glassIdTwo = glassId;
+        }
+
+    }
+
+    private ReadWriteEntity generateReadWriteEntity(String identifier, Object value) {
+        return ReadWriteEntity.builder()
+                .identifier(identifier)
+                //Kep涓槸Long绫诲瀷锛屽嵆锛欼nt32锛孞ava涓殑int绫诲瀷
+                .value(value)
+                .build();
+    }
 }

--
Gitblit v1.8.0