严智鑫
2024-05-29 62c74409a587d9921df1a2248ce23b3b0375fbd1
hangzhoumesParent/moduleService/LoadGlassModule/src/main/java/com/mes/job/PlcLoadGlassTask.java
@@ -44,34 +44,40 @@
     * fixedDelay : 上一个调用结束后再次调用的延时
     */
    @Scheduled(fixedDelay = 300)
    @Scheduled(fixedDelay = 3000000)
    public void plcLoadGlassTask() throws InterruptedException {
        try {
            //获取联机状态
            String inkageStatus =plcParameterObject.getPlcParameter("MesToPlc").getValue();
            //获取是否有上片请求
            String loadRequest = plcParameterObject.getPlcParameter("loadRequest").getValue();
            //mes状态
            String mesToPlc = plcParameterObject.getPlcParameter("MesToPlc").getValue();
            //判断开始上片的工程号
            Engineering engineering = engineeringService.selectInitiate(1);
            if ("1".equals(loadRequest) && engineering != null) {
                log.info("开始上片任务");
                UpPattenUsage upPattenUsage = upWorkstationService.selectPriority(engineering);
                log.info("当有请求时查询当前上片顺序的玻璃信息{}", upPattenUsage);
                UpWorkstation upwork = upWorkstationService.selectWorkstation(upPattenUsage);
                log.info("符合的尺寸的工位玻璃:{}", upwork);
                if (upwork != null) {
                    int workId = upwork.getWorkstationId();//工位id
                    double width = upwork.getPatternWidth();//宽度
                    double height = upwork.getPatternHeight();//高度
                    S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("WorkId").getAddress(), workId);
                    S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("GlassWidth").getAddress(), (long) width);
                    S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("GlassHeight").getAddress(), (long) height);
                    S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("MesToPlc").getAddress(), 1);
                    //更改上片表状态
                    upPattenUsageService.updateUpPattenUsageState(upPattenUsage, workId);
            if("1".equals(inkageStatus)&&"1".equals(loadRequest)) {
                //判断开始上片的工程号
                Engineering engineering = engineeringService.selectInitiate(1);
                if (engineering != null) {
                    log.info("开始上片任务");
                    UpPattenUsage upPattenUsage = upWorkstationService.selectPriority(engineering);
                    log.info("当有请求时查询当前上片顺序的玻璃信息{}", upPattenUsage);
                    UpWorkstation upwork = upWorkstationService.selectWorkstation(upPattenUsage);
                    log.info("符合的尺寸的工位玻璃:{}", upwork);
                    if (upwork != null) {
                        int workId = upwork.getWorkstationId();//工位id
                        double width = upwork.getPatternWidth();//宽度
                        double height = upwork.getPatternHeight();//高度
                        S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("WorkId").getAddress(), workId);
                        S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("GlassWidth").getAddress(), (long) width);
                        S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("GlassHeight").getAddress(), (long) height);
                        S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("MesToPlc").getAddress(), 1);
                        //更改上片表状态
                        upPattenUsageService.updateUpPattenUsageState(upPattenUsage, workId);
                    }
                }
            }
            if("1".equals(mesToPlc)&& "0".equals(loadRequest)){
            if ("1".equals(mesToPlc) && "0".equals(loadRequest)) {
                //请求字为零时,任务字清零
                S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("MesToPlc").getAddress(), 0);
            }
@@ -82,7 +88,7 @@
        }
    }
    @Scheduled(fixedDelay = 300)
    @Scheduled(fixedDelay = 30000000)
    public void plcLoadGlassReport(){
        //获取是否有汇报
        String loadStatus = plcParameterObject.getPlcParameter("PlcStatus").getValue();
@@ -110,7 +116,7 @@
        }
    }
    @Scheduled(fixedDelay = 300)
    @Scheduled(fixedDelay = 1000)
    public void loadGlassHome(){
        JSONObject jsonObject = new JSONObject();
        //正在进行的任务
@@ -135,6 +141,29 @@
            }
        }
    }
    @Scheduled(fixedDelay = 5000)
    public void loadGlassStatus(){
        JSONObject jsonObject = new JSONObject();
        //正在进行的任务
        //String inkageStatus =plcParameterObject.getPlcParameter("MesToPlc").getValue();
        String inkageStatus ="1";
        jsonObject.append("InkageStatus", inkageStatus);
        ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("loadGlass");
        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");
                }
            }
        }
    }
    public void overTask(String loadStatus, int state)  {