wangfei
2024-10-31 f99ff750a82209b1b34b72f2ff78bfe448a1d66a
义乌上片功能(部分)
2个文件已修改
1个文件已添加
208 ■■■■ 已修改文件
UI-Project/src/views/Returns/upreturns.vue 91 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hangzhoumesParent/moduleService/LoadGlassModule/src/main/java/com/mes/engineering/entity/Engineering.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hangzhoumesParent/moduleService/LoadGlassModule/src/main/java/com/mes/job/PlcUpLoadGlassTask.java 111 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
UI-Project/src/views/Returns/upreturns.vue
@@ -1,16 +1,14 @@
<script lang="ts" setup>
import {Search} from "@element-plus/icons-vue";
import {reactive} from "vue";
import {onBeforeUnmount, onMounted, onUnmounted, reactive, ref} from "vue";
import {useRouter} from "vue-router"
const router = useRouter()
import type { TableColumnCtx } from 'element-plus'
import { ElMessage, ElMessageBox } from 'element-plus'
import {ElMessage} from 'element-plus'
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
import { WebSocketHost ,host} from '@/utils/constants'
import {host, WebSocketHost} from '@/utils/constants'
import request from "@/utils/request"
import { initializeWebSocket, closeWebSocket } from '@/utils/WebSocketService';
import { ref, onMounted, onUnmounted, onBeforeUnmount } from "vue";
import {closeWebSocket, initializeWebSocket} from '@/utils/WebSocketService';
const router = useRouter()
const {t} = useI18n()
const selectValuesa = reactive([]);
const selectedProjectNo = ref(''); // 当前选中的工程号  
const loadingline = ref(''); // 当前选中的上片线
@@ -59,12 +57,16 @@
};
const selectproject = () => {
  dialogFormVisible.value = true;
  selectgong();
};
 
 
onMounted(() => {
  // socket = initializeWebSocket(socketUrl, handleMessage);
  socket = initializeWebSocket(socketUrl, handleMessage);
});
const handleMessage = (data) => {
}
  onUnmounted(() => {
    if (socket) {
    closeWebSocket(socket);
@@ -72,60 +74,35 @@
    });
//定义接收加载表头下拉数据
const titleSelectJson = ref({
  processType: [],
})
const titleSelectJsona = ref({
  processTypea: [],
  engineerId: [],
})
let socket = null;
const socketUrl = `ws://${WebSocketHost}:${host}/api/loadGlass/api/talk/loadGlass`;
const socketUrl = `ws://${WebSocketHost}:${host}/api/loadGlass/api/talk/uploadGlass`;
// 定义消息处理函数,更新 receivedData 变量
const requestData = {
  state: 100
};
 
onBeforeUnmount(() => {
  closeWebSocket();
});
const selectgong = async () => {
  try {
    const response = await request.post('/loadGlass/upEngineering/selectTask')
    if (response.code == 200) {
      titleSelectJson.value.engineerId = response.data;
    } else {
      ElMessage.error(response.message);
    }
  } catch (error) {
    // 处理错误
    console.error(error);
  }
}
// 添加
const handleBindRack = (row) => {
  workstationId.value = row.workstationId; // 假设rackNumber是架号字段的属性名
  ida.value = row.id;
  add.value = true; // 打开绑定架子对话框
};
// 暂停
const handlea = async () => {
  try  {
  let engineeringId = window.localStorage.getItem('engineeringId')
console.log(engineeringId);
if (engineeringId !== '') {
  const response = await request.post('/loadGlass/engineering/engineering/pauseTask', {
      engineeringId: engineeringId,
      state: 0,
    })
    if (response.code == 200) {
      ElMessage.success(response.message);
      blinda.value = false;
      // tableData.splice([]);
    } else {
      // 请求失败,显示错误消息
      ElMessage.error(response.message);
    }
  }
    else  {
      ElMessage({
        type: 'info',
        message: t('basicData.infonull'),
      })
    }
}
catch (error) {
    // 处理错误
    console.error(error);
  }
}
function getStatusText(state: number) {
  switch (state) {
    case 0:  
@@ -163,11 +140,7 @@
  blindb.value = true; 
};
 
// 删除
const handleBindRacka = (row) => {
  workstationId.value = row.workstationId;
  adda.value = true;
};
const toggleEnableState = async (row: any) => {  
  // 检查 id 是否为空  
  if (!row.id) {  
@@ -488,10 +461,10 @@
           @input="handleInputChange"  
         >  
      <el-option  
         v-for="item in titleSelectJson['processType']"
              v-for="item in titleSelectJson['engineerId']"
         :key="item.id"  
         :label="item.projectNo"
         :value="item.projectNo"
              :label="item.engineerId"
              :value="item.engineerId"
      />  
    </el-select>  
              </el-form-item>
hangzhoumesParent/moduleService/LoadGlassModule/src/main/java/com/mes/engineering/entity/Engineering.java
@@ -31,6 +31,12 @@
     * 工程号
     */
    private String  engineerId;
    /**
     * 设备
     */
    private String stationCell;
    /**
     * 工程名称
hangzhoumesParent/moduleService/LoadGlassModule/src/main/java/com/mes/job/PlcUpLoadGlassTask.java
New file
@@ -0,0 +1,111 @@
package com.mes.job;
import cn.hutool.json.JSONObject;
import com.mes.common.S7object;
import com.mes.device.PlcParameterObject;
import com.mes.engineering.entity.Engineering;
import com.mes.engineering.service.EngineeringService;
import com.mes.tools.WebSocketServer;
import com.mes.uppattenusage.entity.UpPattenUsage;
import com.mes.uppattenusage.service.UpPattenUsageService;
import com.mes.workstation.entity.UpWorkstation;
import com.mes.workstation.service.UpWorkstationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
 * @author SNG-010
 */
@Component
@Slf4j
public class PlcUpGlassTask {
    @Autowired
    private UpPattenUsageService upPattenUsageService;
    @Autowired
    private UpWorkstationService upWorkstationService;
    @Autowired
    private EngineeringService engineeringService;
    PlcParameterObject plcParameterObject = S7object.getinstance().PlcMesObject;
    /**
     * fixedRate : 上一个调用开始后再次调用的延时(不用等待上一次调用完成)
     * fixedDelay : 上一个调用结束后再次调用的延时
     */
//    @Scheduled(fixedDelay = 300)
    public void plcLoadGlassTask() throws InterruptedException {
        try {
            //先判断是否有正在开始的工程
            Engineering engineering = engineeringService.selectInitiate(1, 1);
            //获取是否有上片请求
            String loadRequest1 = plcParameterObject.getPlcParameter("loadRequest").getValue();
            //当同时有上片请求和有正在开始的工程时进入上片判断
            if (loadRequest1.equals(1) && engineering != null) {
                //获取当前开始的工程号
                UpPattenUsage upPattenUsage = upWorkstationService.selectPriority(engineering);
                //用工程号查询本次上片的尺寸信息获取工位位置
                //UpWorkstation upwork = upWorkstationService.selectWorkstation(upPattenUsage);
            }
            //执行后休眠300毫秒
            //Thread.sleep(300);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //    @Scheduled(fixedDelay = 300)
    public void plcLoadGlassTask2() throws InterruptedException {
        try {
            //先判断是否有正在开始的工程
            Engineering engineering = engineeringService.selectInitiate(2, 1);
            //获取是否有上片请求
            String loadRequest2 = plcParameterObject.getPlcParameter("loadRequest").getValue();
            //当同时有上片请求和有正在开始的工程时进入上片判断
            if (loadRequest2.equals(1) && engineering != null) {
                //获取当前开始的工程号
                UpPattenUsage upPattenUsage = upWorkstationService.selectPriority(engineering);
                //用工程号查询本次上片的尺寸信息获取工位位置
                //UpWorkstation upwork = upWorkstationService.selectWorkstation(upPattenUsage);
            }
            //执行后休眠300毫秒
            //Thread.sleep(300);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @Scheduled(fixedDelay = 3000)
    public void loadGlassHome() {
        JSONObject jsonObject = new JSONObject();
        //正在进行的任务
        //工位信息
        List<UpWorkstation> upWorkstations = upWorkstationService.list();
        jsonObject.append("list", upWorkstations);
        ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("uploadGlass");
        if (sendwServer != null) {
            for (WebSocketServer webserver : sendwServer) {
                if (webserver != null) {
                    webserver.sendMessage(jsonObject.toString());
//                    List<String> messages = webserver.getMessages();
//                    if (!messages.isEmpty()) {
//                        // // 将最后一个消息转换为整数类型的列表
//                        webserver.clearMessages();
//                    }
                } else {
                    log.info("Home is closed");
                }
            }
        }
    }
}