懒羊羊
2024-01-09 5a6d6b9f3bb00b93e70d316c0fafcb34ddd0c510
工位终端优化
已修改5个文件
已添加4个文件
445 ■■■■■ 文件已修改
jcdm-framework/pom.xml 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-framework/src/main/java/com/jcdm/framework/config/SecurityConfig.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-framework/src/main/java/com/jcdm/framework/websocket/SemaphoreUtils.java 58 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-framework/src/main/java/com/jcdm/framework/websocket/WebSocketConfig.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-framework/src/main/java/com/jcdm/framework/websocket/WebSocketServer.java 103 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-framework/src/main/java/com/jcdm/framework/websocket/WebSocketUsers.java 140 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-ui/src/views/main/cfkb/Instructions/index.vue 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-ui/src/views/main/kb/stationTerminal/index.vue 102 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-ui/src/views/main/rm/repairData/index.vue 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-framework/pom.xml
@@ -59,6 +59,12 @@
            <artifactId>jcdm-system</artifactId>
        </dependency>
        <!-- SpringBoot Websocket -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-websocket</artifactId>
        </dependency>
    </dependencies>
</project>
jcdm-framework/src/main/java/com/jcdm/framework/config/SecurityConfig.java
@@ -111,7 +111,7 @@
                // è¿‡æ»¤è¯·æ±‚
                .authorizeRequests()
                // å¯¹äºŽç™»å½•login æ³¨å†Œregister éªŒè¯ç captchaImage å…è®¸åŒ¿åè®¿é—®
                .antMatchers("/login", "/register", "/captchaImage").permitAll()
                .antMatchers("/login", "/register", "/captchaImage","/websocket/**").permitAll()
                // é™æ€èµ„源,可匿名访问
                .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
                .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
jcdm-framework/src/main/java/com/jcdm/framework/websocket/SemaphoreUtils.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,58 @@
package com.jcdm.framework.websocket;
import java.util.concurrent.Semaphore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 * ä¿¡å·é‡ç›¸å…³å¤„理
 *
 * @author ruoyi
 */
public class SemaphoreUtils
{
    /**
     * SemaphoreUtils æ—¥å¿—控制器
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(SemaphoreUtils.class);
    /**
     * èŽ·å–信号量
     *
     * @param semaphore
     * @return
     */
    public static boolean tryAcquire(Semaphore semaphore)
    {
        boolean flag = false;
        try
        {
            flag = semaphore.tryAcquire();
        }
        catch (Exception e)
        {
            LOGGER.error("获取信号量异常", e);
        }
        return flag;
    }
    /**
     * é‡Šæ”¾ä¿¡å·é‡
     *
     * @param semaphore
     */
    public static void release(Semaphore semaphore)
    {
        try
        {
            semaphore.release();
        }
        catch (Exception e)
        {
            LOGGER.error("释放信号量异常", e);
        }
    }
}
jcdm-framework/src/main/java/com/jcdm/framework/websocket/WebSocketConfig.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,20 @@
package com.jcdm.framework.websocket;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
/**
 * websocket é…ç½®
 *
 * @author ruoyi
 */
@Configuration
public class WebSocketConfig
{
    @Bean
    public ServerEndpointExporter serverEndpointExporter()
    {
        return new ServerEndpointExporter();
    }
}
jcdm-framework/src/main/java/com/jcdm/framework/websocket/WebSocketServer.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,103 @@
package com.jcdm.framework.websocket;
import java.util.concurrent.Semaphore;
import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
/**
 * websocket æ¶ˆæ¯å¤„理
 *
 * @author ruoyi
 */
@Component
@ServerEndpoint("/websocket/message")
public class WebSocketServer
{
    /**
     * WebSocketServer æ—¥å¿—控制器
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketServer.class);
    /**
     * é»˜è®¤æœ€å¤šå…è®¸åŒæ—¶åœ¨çº¿äººæ•°100
     */
    public static int socketMaxOnlineCount = 100;
    private static Semaphore socketSemaphore = new Semaphore(socketMaxOnlineCount);
    /**
     * è¿žæŽ¥å»ºç«‹æˆåŠŸè°ƒç”¨çš„方法
     */
    @OnOpen
    public void onOpen(Session session) throws Exception
    {
        boolean semaphoreFlag = false;
        // å°è¯•èŽ·å–信号量
        semaphoreFlag = SemaphoreUtils.tryAcquire(socketSemaphore);
        if (!semaphoreFlag)
        {
            // æœªèŽ·å–到信号量
            LOGGER.error("\n å½“前在线人数超过限制数- {}", socketMaxOnlineCount);
            WebSocketUsers.sendMessageToUserByText(session, "当前在线人数超过限制数:" + socketMaxOnlineCount);
            session.close();
        }
        else
        {
            // æ·»åŠ ç”¨æˆ·
            WebSocketUsers.put(session.getId(), session);
            LOGGER.info("\n å»ºç«‹è¿žæŽ¥ - {}", session);
            LOGGER.info("\n å½“前人数 - {}", WebSocketUsers.getUsers().size());
            WebSocketUsers.sendMessageToUserByText(session, "连接成功");
        }
    }
    /**
     * è¿žæŽ¥å…³é—­æ—¶å¤„理
     */
    @OnClose
    public void onClose(Session session)
    {
        LOGGER.info("\n å…³é—­è¿žæŽ¥ - {}", session);
        // ç§»é™¤ç”¨æˆ·
        WebSocketUsers.remove(session.getId());
        // èŽ·å–到信号量则需释放
        SemaphoreUtils.release(socketSemaphore);
    }
    /**
     * æŠ›å‡ºå¼‚常时处理
     */
    @OnError
    public void onError(Session session, Throwable exception) throws Exception
    {
        if (session.isOpen())
        {
            // å…³é—­è¿žæŽ¥
            session.close();
        }
        String sessionId = session.getId();
        LOGGER.info("\n è¿žæŽ¥å¼‚常 - {}", sessionId);
        LOGGER.info("\n å¼‚常信息 - {}", exception);
        // ç§»å‡ºç”¨æˆ·
        WebSocketUsers.remove(sessionId);
        // èŽ·å–到信号量则需释放
        SemaphoreUtils.release(socketSemaphore);
    }
    /**
     * æœåŠ¡å™¨æŽ¥æ”¶åˆ°å®¢æˆ·ç«¯æ¶ˆæ¯æ—¶è°ƒç”¨çš„方法
     */
    @OnMessage
    public void onMessage(String message, Session session)
    {
        String msg = message.replace("ä½ ", "我").replace("吗", "");
        WebSocketUsers.sendMessageToUserByText(session, msg);
    }
}
jcdm-framework/src/main/java/com/jcdm/framework/websocket/WebSocketUsers.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,140 @@
package com.jcdm.framework.websocket;
import java.io.IOException;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.websocket.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 * websocket å®¢æˆ·ç«¯ç”¨æˆ·é›†
 *
 * @author ruoyi
 */
public class WebSocketUsers
{
    /**
     * WebSocketUsers æ—¥å¿—控制器
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketUsers.class);
    /**
     * ç”¨æˆ·é›†
     */
    private static Map<String, Session> USERS = new ConcurrentHashMap<String, Session>();
    /**
     * å­˜å‚¨ç”¨æˆ·
     *
     * @param key å”¯ä¸€é”®
     * @param session ç”¨æˆ·ä¿¡æ¯
     */
    public static void put(String key, Session session)
    {
        USERS.put(key, session);
    }
    /**
     * ç§»é™¤ç”¨æˆ·
     *
     * @param session ç”¨æˆ·ä¿¡æ¯
     *
     * @return ç§»é™¤ç»“æžœ
     */
    public static boolean remove(Session session)
    {
        String key = null;
        boolean flag = USERS.containsValue(session);
        if (flag)
        {
            Set<Map.Entry<String, Session>> entries = USERS.entrySet();
            for (Map.Entry<String, Session> entry : entries)
            {
                Session value = entry.getValue();
                if (value.equals(session))
                {
                    key = entry.getKey();
                    break;
                }
            }
        }
        else
        {
            return true;
        }
        return remove(key);
    }
    /**
     * ç§»å‡ºç”¨æˆ·
     *
     * @param key é”®
     */
    public static boolean remove(String key)
    {
        LOGGER.info("\n æ­£åœ¨ç§»å‡ºç”¨æˆ· - {}", key);
        Session remove = USERS.remove(key);
        if (remove != null)
        {
            boolean containsValue = USERS.containsValue(remove);
            LOGGER.info("\n ç§»å‡ºç»“æžœ - {}", containsValue ? "失败" : "成功");
            return containsValue;
        }
        else
        {
            return true;
        }
    }
    /**
     * èŽ·å–在线用户列表
     *
     * @return è¿”回用户集合
     */
    public static Map<String, Session> getUsers()
    {
        return USERS;
    }
    /**
     * ç¾¤å‘消息文本消息
     *
     * @param message æ¶ˆæ¯å†…容
     */
    public static void sendMessageToUsersByText(String message)
    {
        Collection<Session> values = USERS.values();
        for (Session value : values)
        {
            sendMessageToUserByText(value, message);
        }
    }
    /**
     * å‘送文本消息
     *
     * @param userName è‡ªå·±çš„用户名
     * @param message æ¶ˆæ¯å†…容
     */
    public static void sendMessageToUserByText(Session session, String message)
    {
        if (session != null)
        {
            try
            {
                session.getBasicRemote().sendText(message);
            }
            catch (IOException e)
            {
                LOGGER.error("\n[发送消息异常]", e);
            }
        }
        else
        {
            LOGGER.info("\n[你已离线]");
        }
    }
}
jcdm-ui/src/views/main/cfkb/Instructions/index.vue
@@ -75,7 +75,7 @@
import {listFormulaChild} from "@/api/main/bs/formulaChild/formulaChild";
export default {
  name: "index",
  name: "Instructions",
  data() {
    return {
      queryParams: {
@@ -144,6 +144,10 @@
    this.changeProducts(this.productCode)
    // this.autoShow()
  },
  beforeDestroy() {
    clearInterval(this.intervalId)
    this.intervalId = null
  },
  methods: {
    // å®šæ—¶è§¦å‘
    autoShow() {
jcdm-ui/src/views/main/kb/stationTerminal/index.vue
@@ -14,7 +14,7 @@
     <el-col :span="12">
       <el-card shadow="never">
         <span class="head-font">总成编码 : {{headContent.sfcCode}}</span>
         <el-input v-model="input" style="float: right;width: 150px;" placeholder="请输入内容"></el-input>
         <el-input v-model="content" style="float: right;width: 150px;" placeholder="请输入内容"></el-input>
         <el-button @click="scanCompleted" style="float: right" type="primary">扫码完成</el-button>
         <el-button @click="clearClick" style="float: right" type="danger">清除</el-button>
       </el-card>
@@ -86,8 +86,8 @@
     </el-col>
     <el-col :span="18">
       <el-tabs type="border-card"  style="height: 600px">
         <el-tab-pane>
       <el-tabs type="border-card"  style="height: 600px" v-model="activeName" @tab-click="changeMenu">
         <el-tab-pane name="first">
           <span slot="label"> <a class="el-icon-date"></a>首页</span>
           <el-col :span="8">
             <el-table>
@@ -99,26 +99,26 @@
             <el-image style="height: 520px;width: 100%" :src="imgSrc"></el-image>
           </el-col>
         </el-tab-pane>
         <el-tab-pane>
         <el-tab-pane name="second">
           <span slot="label"> <b class="el-icon-date"></b>物料BOM</span>
           <el-empty >
             <span slot="description">暂无数据</span>
           </el-empty>
         </el-tab-pane>
         <el-tab-pane>
           <span slot="label"> <c class="el-icon-date"></c>采集清单</span>
         <el-tab-pane name="third">
           <span slot="label"> <b class="el-icon-date"></b>采集清单</span>
           <el-empty >
             <span slot="description">暂无数据</span>
           </el-empty>
         </el-tab-pane>
         <el-tab-pane>
           <span slot="label"> <d class="el-icon-date"></d>安灯状态</span>
         <el-tab-pane name="fourth">
           <span slot="label"> <b class="el-icon-date"></b>安灯状态</span>
           <el-empty >
             <span slot="description">暂无数据</span>
           </el-empty>
         </el-tab-pane>
         <el-tab-pane>
           <span slot="label"> <e class="el-icon-date"></e>工艺配方</span>
         <el-tab-pane name="fifth">
           <span slot="label"> <b class="el-icon-date"></b>工艺配方</span>
           <el-empty >
             <span slot="description">暂无数据</span>
           </el-empty>
@@ -137,7 +137,6 @@
  data() {
    return {
      ipAddress: '',
      input: null,
      imgSrc: '',
      headContent: {
        processesCode: 'OP1010',
@@ -164,22 +163,26 @@
        scanFinish: 0,
        startWork: 0,
        release: 0 //允许放行
      }
      },
      content: '',
      activeName: 'first'
    }
  },
  created() {
    this.getIPAddress();
    this.getStationConfList();
  },
  methods: {
    changeMenu(tab, event) {
      console.log(tab, event);
    },
    clearClick(){
      this.$message('这是一条清除消息提示');
      this.headContent.sfcCode = null
    },
    scanCompleted(){
      this.$message('扫码完成'+this.input);
      this.headContent.sfcCode = this.input
      this.queryParams.sfcCode = this.input
      this.$message('扫码完成'+this.content);
      this.headContent.sfcCode = this.content
      this.queryParams.sfcCode = this.content
      this.getList()
      this.cakeLamp.scanFinish = 1
    },
@@ -200,9 +203,6 @@
      clearInterval(this.timer);
      this.$message('保存节拍为'+this.workpieceInformation.beat+'秒');
    },
    getIPAddress() {
      this.ipAddress = window.location.hostname;
    },
    /** æŸ¥è¯¢å·¥ä½ç»ˆç«¯é…ç½®åˆ—表 */
    getStationConfList() {
      let queryParams = {
@@ -213,6 +213,10 @@
      });
      listStationConf(queryParams).then(response => {
        let rows = response.rows[0]
        if(response.rows.length===0){
          this.$message('改ip沒有配置工序工位,請重試!');
          return
        }
        this.headContent.processesName = rows.processesName
        this.headContent.processesCode = rows.processesCode
      });
@@ -255,3 +259,63 @@
  font-size: 15px;
}
</style>
<!--<template>-->
<!--  <div>-->
<!--    <el-input v-model="url" type="text" style="width: 20%" /> &nbsp; &nbsp;-->
<!--    <el-button @click="join" type="primary">连接</el-button>-->
<!--    <el-button @click="exit" type="danger">断开</el-button>-->
<!--    <br />-->
<!--    <el-input type="textarea" v-model="message" :rows="9" />-->
<!--    <el-button type="info" @click="send">发送消息</el-button>-->
<!--    <br />-->
<!--    <br />-->
<!--    <el-input type="textarea" v-model="text_content" :rows="9" /> è¿”回内容-->
<!--    <br />-->
<!--    <br />-->
<!--  </div>-->
<!--</template>-->
<!--<script>-->
<!--export default {-->
<!--  data() {-->
<!--    return {-->
<!--      url: "ws://127.0.0.1:8081/websocket/message",-->
<!--      message: "",-->
<!--      text_content: "",-->
<!--      ws: null,-->
<!--    };-->
<!--  },-->
<!--  methods: {-->
<!--    join() {-->
<!--      const wsuri = this.url;-->
<!--      this.ws = new WebSocket(wsuri);-->
<!--      const self = this;-->
<!--      this.ws.onopen = function (event) {-->
<!--        self.text_content = self.text_content + "已经打开连接!" + "\n";-->
<!--      };-->
<!--      this.ws.onmessage = function (event) {-->
<!--        console.log("后端发过来的消息"+event.data)-->
<!--        self.text_content = event.data + "\n";-->
<!--      };-->
<!--      this.ws.onclose = function (event) {-->
<!--        self.text_content = self.text_content + "已经关闭连接!" + "\n";-->
<!--      };-->
<!--    },-->
<!--    exit() {-->
<!--      if (this.ws) {-->
<!--        this.ws.close();-->
<!--        this.ws = null;-->
<!--      }-->
<!--    },-->
<!--    send() {-->
<!--      if (this.ws) {-->
<!--        this.ws.send(this.message);-->
<!--      } else {-->
<!--        alert("未连接到服务器");-->
<!--      }-->
<!--    },-->
<!--  },-->
<!--};-->
<!--</script>-->
jcdm-ui/src/views/main/rm/repairData/index.vue
@@ -144,19 +144,19 @@
          </el-empty>
        </el-tab-pane>
        <el-tab-pane>
          <span slot="label"> <c class="el-icon-date"></c>外漏检测</span>
          <span slot="label"> <b class="el-icon-date"></b>外漏检测</span>
          <el-empty >
            <span slot="description">暂无数据</span>
          </el-empty>
        </el-tab-pane>
        <el-tab-pane>
          <span slot="label"> <d class="el-icon-date"></d>机轴加注</span>
          <span slot="label"> <b class="el-icon-date"></b>机轴加注</span>
          <el-empty >
            <span slot="description">暂无数据</span>
          </el-empty>
        </el-tab-pane>
        <el-tab-pane>
          <span slot="label"> <e class="el-icon-date"></e>工位结果</span>
          <span slot="label"> <b class="el-icon-date"></b>工位结果</span>
          <el-empty >
            <span slot="description">暂无数据</span>
          </el-empty>
@@ -222,7 +222,7 @@
import { listRepairData, getRepairData, delRepairData, addRepairData, updateRepairData } from "@/api/main/rm/repairData/repairData";
export default {
  name: "RepairData",
  name: "rmRepairData",
  dicts: ['qualified_status'],
  data() {
    return {