From d5d0d1c7a84b996b9bbcebfaf2c2c95f1a5a3678 Mon Sep 17 00:00:00 2001
From: zhoushihao <zsh19950802@163.com>
Date: 星期五, 11 十月 2024 08:39:15 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/job/Downpush.java |   78 +++++++++++++++++++++++++++++++++++++-
 1 files changed, 75 insertions(+), 3 deletions(-)

diff --git a/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/job/Downpush.java b/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/job/Downpush.java
index 38bf52e..ad8e5a3 100644
--- a/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/job/Downpush.java
+++ b/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/job/Downpush.java
@@ -1,26 +1,40 @@
 package com.mes.job;
 
 import cn.hutool.json.JSONObject;
+import cn.smallbun.screw.core.util.CollectionUtils;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.mes.common.config.Const;
 import com.mes.common.utils.RedisUtil;
 import com.mes.downglassinfo.entity.DownGlassInfo;
+import com.mes.downglassinfo.entity.DownGlassTask;
 import com.mes.downglassinfo.entity.request.DownGlassInfoRequest;
 import com.mes.downglassinfo.service.DownGlassInfoService;
+import com.mes.downglassinfo.service.DownGlassTaskService;
 import com.mes.downstorage.service.DownStorageCageService;
 import com.mes.downworkstation.entity.DownWorkstation;
 import com.mes.downworkstation.service.DownWorkstationService;
+import com.mes.glassinfo.entity.GlassInfo;
+import com.mes.glassinfo.service.GlassInfoService;
+import com.mes.tools.DateUtil;
 import com.mes.tools.WebSocketServer;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.TaskScheduler;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.InetSocketAddress;
+import java.net.Socket;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.*;
 import java.util.stream.Collectors;
 
 @Slf4j
@@ -33,6 +47,16 @@
     private DownStorageCageService downStorageCageService;
     @Autowired
     private DownGlassInfoService downGlassInfoService;
+    @Autowired
+    private DownGlassTaskService downGlassTaskService;
+    @Autowired
+    private GlassInfoService glassInfoService;
+
+    @Value("${mes.scan.ip}")
+    private String scanIp;
+
+    @Value("${mes.scan.port}")
+    private Integer scanPort;
 
     @Autowired
     private RedisUtil redisUtil;
@@ -42,7 +66,7 @@
         log.info("鍙戦�佸伐浣嶇幓鐠冧俊鎭�");
         JSONObject jsonObject = new JSONObject();
 
-        List<DownWorkstation> data = downWorkstationService.getoneDownWorkstations(1, 6);
+        List<DownWorkstation> data = downWorkstationService.list();
         jsonObject.append("params", data);
         log.info(jsonObject.toString());
         ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("unloadglass");
@@ -113,6 +137,10 @@
         if (null == request) {
             request = new DownGlassInfoRequest();
         }
+        if (request.getBeginDate() == null) {
+            request.setBeginDate(DateUtil.getBeginDate());
+            request.setEndDate(DateUtil.getEndDate());
+        }
         log.info("鍙戦�佸綋鍓嶆鍦ㄦ墽琛屽伐绋嬪凡钀芥灦鐨勭幓鐠冧俊鎭�");
         LambdaQueryWrapper<DownGlassInfo> wrapper = new LambdaQueryWrapper<DownGlassInfo>()
                 .between(null != request.getBeginDate(), DownGlassInfo::getGmtCreate, request.getBeginDate(), request.getEndDate())
@@ -123,11 +151,11 @@
             wrapper.eq(DownGlassInfo::getWorkStationId, request.getWorkStationId());
         }
         List<DownGlassInfo> downGlassInfos = downGlassInfoService.list(wrapper);
-        Map<Integer, List<DownGlassInfo>> listMap = downGlassInfos.stream().collect(Collectors.groupingBy(DownGlassInfo::getWorkStationId));
+//        Map<Integer, List<DownGlassInfo>> listMap = downGlassInfos.stream().collect(Collectors.groupingBy(DownGlassInfo::getWorkStationId));
         List<Object> engineerIdListTemp = downGlassInfoService.listObjs(new QueryWrapper<DownGlassInfo>().select("distinct engineer_id"));
         List<String> engineerIdList = engineerIdListTemp.stream().map(String::valueOf).collect(Collectors.toList());
         JSONObject jsonObject4 = new JSONObject();
-        jsonObject4.append("downGlassInfos", listMap);
+        jsonObject4.append("downGlassInfos", downGlassInfos);
         jsonObject4.append("engineerIdList", engineerIdList);
 
         //閽㈠寲寮�鍏�
@@ -138,6 +166,17 @@
             autoPrint = redisUtil.getCacheObject("autoPrint");
         }
         jsonObject4.append("autoPrint", autoPrint);
+        //浜哄伐涓嬬墖浣嶇疆鏈�鍚庝竴鐗�
+        DownGlassTask takeGlass = downGlassTaskService.getOne(
+                new QueryWrapper<DownGlassTask>()
+                        .select("Top 1 *")
+                        .eq("end_cell", Const.G13_WORK_STATION)
+                        .lt("task_status", Const.UNLOAD_GLASS_DOWN)
+                        .orderByAsc("id")
+        );
+        if(takeGlass!=null){
+            jsonObject4.append("takeGlass", takeGlass);
+        }
 
         ArrayList<WebSocketServer> sendwServer4 = WebSocketServer.sessionMap.get("unloadglass");
         if (sendwServer4 != null) {
@@ -155,6 +194,8 @@
         //姝e湪杩涜鐨勪换鍔�
         List<DownWorkstation> downWorkstation = downWorkstationService.getoneDownWorkstations(1, 6);
         jsonObject.append("downWorkstation", downWorkstation);
+        List<DownGlassTask> downGlassTask = downGlassTaskService.selectOutTaskCache();
+        jsonObject.append("downGlassTask", downGlassTask);
         ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("unLoadGlassIsRun");
         if (sendwServer != null) {
             for (WebSocketServer webserver : sendwServer) {
@@ -166,4 +207,35 @@
             }
         }
     }
+
+    @Scheduled(fixedDelay = Long.MAX_VALUE)
+    public void scanCodeTask() {
+        log.info("鎵弿浠诲姟宸插惎鍔�");
+        while (true) {
+            JSONObject jsonObject = new JSONObject();
+            try (Socket socket = new Socket(scanIp, scanPort);
+                 BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()))) {
+                // 鎺ユ敹鏈嶅姟鍣ㄥ搷搴�
+                log.info("绛夊緟鎵爜涓�......");
+                String glassId = in.readLine();
+                log.info("鎵弿鍒扮殑鐜荤拑id锛歿}", glassId);
+                List<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("unloadglass");
+                if (CollectionUtils.isNotEmpty(sendwServer)) {
+                    //鎸夌収鐜荤拑id鑾峰彇鐜荤拑淇℃伅杩斿洖缁欏墠绔晫闈紝鍏蜂綋闇�瑕佸摢浜涙暟鎹緟纭
+                    GlassInfo glassInfo = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>()
+                            .eq(GlassInfo::getGlassId, glassId).last("limit 1"));
+                    if (null == glassInfo) {
+                        log.info("鎸夌収鐜荤拑id锛歿}锛屾棤娉曟壘鍒扮幓鐠冧俊鎭�", glassId);
+                    } else {
+                        for (WebSocketServer webserver : sendwServer) {
+                                jsonObject.append("scanGlass", glassInfo);
+                                webserver.sendMessage(jsonObject.toString());
+                        }
+                    }
+                }
+            } catch (Exception exception) {
+                log.info("璇诲彇寮傚父锛屽師鍥犱负{}", exception.getMessage());
+            }
+        }
+    }
 }

--
Gitblit v1.8.0