| | |
| | | package com.mes.job; |
| | | |
| | | import cn.hutool.json.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | 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.opctask.entity.LoadGlassDeviceTask; |
| | | import com.mes.opctask.service.LoadGlassDeviceTaskService; |
| | | import com.mes.pp.service.OptimizeProjectService; |
| | | import com.mes.rawglassdetails.entity.RawGlassStorageDetails; |
| | | import com.mes.rawglassstation.service.RawGlassStorageStationService; |
| | | import com.mes.tools.WebSocketServer; |
| | | import com.mes.uppattenusage.entity.UpPattenUsage; |
| | | import com.mes.uppattenusage.service.UpPattenUsageService; |
| | | import com.mes.utils.RedisUtil; |
| | | import com.mes.workstation.entity.UpWorkstation; |
| | | import com.mes.workstation.service.UpWorkstationService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author SNG-010 |
| | |
| | | private UpPattenUsageService upPattenUsageService; |
| | | @Autowired |
| | | private OptimizeProjectService optimizeProjectService; |
| | | |
| | | @Autowired |
| | | RedisUtil redisUtil; |
| | | @Resource |
| | | private LoadGlassDeviceTaskService loadGlassDeviceTaskService; |
| | | @Resource |
| | | private RawGlassStorageStationService rawGlassStorageStationService; |
| | | |
| | | PlcParameterObject plcParameterObject = S7object.getinstance().PlcMesObject; |
| | | |
| | | private static final String LOAD_GLASS_DEVICE_ONE_TASK = "load_glass_device_one_task"; |
| | | |
| | | private static final String LOAD_GLASS_DEVICE_TWO_TASK = "load_glass_device_two_task"; |
| | | |
| | | /** |
| | | * fixedRate : 上一个调用开始后再次调用的延时(不用等待上一次调用完成) |
| | | * fixedDelay : 上一个调用结束后再次调用的延时 |
| | | */ |
| | | |
| | | @Scheduled(fixedDelay = 300) |
| | | // @Scheduled(fixedDelay = 300) |
| | | public void plcLoadGlassTask() throws InterruptedException { |
| | | try { |
| | | //获取联机状态 |
| | |
| | | } |
| | | } |
| | | |
| | | @Scheduled(fixedDelay = 300) |
| | | // @Scheduled(fixedDelay = 300) |
| | | public void plcLoadGlassReport() { |
| | | //获取是否有汇报 |
| | | String loadStatus = plcParameterObject.getPlcParameter("PlcStatus").getValue(); |
| | |
| | | } |
| | | } |
| | | |
| | | @Scheduled(fixedDelay = 1000) |
| | | public void loadGlassHome() { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | //正在进行的任务 |
| | | List<UpPattenUsage> upPattenUsages = upPattenUsageService.prioritylist(); |
| | | if(upPattenUsages!=null){ |
| | | jsonObject.append("prioritylist", upPattenUsages); |
| | | } |
| | | @Scheduled(fixedDelay = 10000) |
| | | public void loadOneGlass() { |
| | | loadGlassChild("loadGlassRequestOne", 5, LOAD_GLASS_DEVICE_ONE_TASK, "loadGlassOne"); |
| | | } |
| | | |
| | | //工位信息 |
| | | List<UpWorkstation> upWorkstations = upWorkstationService.list(); |
| | | jsonObject.append("list", upWorkstations); |
| | | //是否开始工程 |
| | | Engineering engineering = engineeringService.selectInitiate(1); |
| | | if (engineering != null){ |
| | | jsonObject.append("engineering", engineering); |
| | | }else { |
| | | jsonObject.append("engineering", "0"); |
| | | } |
| | | 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"); |
| | | @Scheduled(fixedDelay = 10000) |
| | | public void loadTwoGlass() { |
| | | loadGlassChild("loadGlassRequestTwo", 6, LOAD_GLASS_DEVICE_TWO_TASK, "loadGlassTwo"); |
| | | } |
| | | |
| | | |
| | | private void loadGlassChild(String redisRequest, int stationCell, String tableName, String webSocketName) { |
| | | try { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | //当前线路正在执行的工程 |
| | | Engineering engineering = engineeringService.getOne(new LambdaQueryWrapper<Engineering>().eq(Engineering::getStationCell, stationCell) |
| | | .eq(Engineering::getState, 1).last("limit 1")); |
| | | if (null != engineering) { |
| | | jsonObject.append("engineering", engineering); |
| | | } |
| | | //获取当前线路正在执行的工程原片信息 |
| | | Engineering request = redisUtil.getCacheObject(redisRequest); |
| | | if (request == null) { |
| | | request = new Engineering(); |
| | | request.setStationCell(stationCell); |
| | | } |
| | | List<UpPattenUsage> upPattenUsages = upPattenUsageService.selectLoadTask(request); |
| | | jsonObject.append("upPattenUsages", upPattenUsages); |
| | | |
| | | //联机状态 |
| | | LoadGlassDeviceTask LoadTask = loadGlassDeviceTaskService.queryTaskMessage(tableName); |
| | | jsonObject.append("inkageState", LoadTask.getInkageState()); |
| | | //工位信息 |
| | | List<RawGlassStorageDetails> rawGlassStorageDetailList = rawGlassStorageStationService.listRawGlassDetails(); |
| | | List<RawGlassStorageDetails> stationList = rawGlassStorageDetailList.stream().filter(item -> item.getDeviceId() == stationCell).collect(Collectors.toList()); |
| | | jsonObject.append("stationList", stationList); |
| | | |
| | | ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get(webSocketName); |
| | | if (sendwServer != null) { |
| | | for (WebSocketServer webserver : sendwServer) { |
| | | if (webserver != null) { |
| | | webserver.sendMessage(jsonObject.toString()); |
| | | } else { |
| | | log.info("loadGlass is closed"); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | @Scheduled(fixedDelay = 5000) |
| | | |
| | | // @Scheduled(fixedDelay = 5000) |
| | | public void loadGlassStatus() { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | //正在进行的任务 |
| | | String inkageStatus =plcParameterObject.getPlcParameter("InkageStatus").getValue(); |
| | | //String inkageStatus ="1"; |
| | | String inkageStatus = plcParameterObject.getPlcParameter("InkageStatus").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()); |
| | | } else { |
| | | log.info("Home is closed"); |
| | | log.info("loadGlass is closed"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | @Scheduled(fixedDelay = 1000) |
| | | public void loadGlassIsRun() { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | Engineering engineering = engineeringService.selectInitiate(1); |
| | | if (engineering != null){ |
| | | jsonObject.append("engineering", engineering); |
| | | }else { |
| | | jsonObject.append("engineering", "0"); |
| | | } |
| | | ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("IsRun"); |
| | | if (sendwServer != null) { |
| | | for (WebSocketServer webserver : sendwServer) { |
| | | if (webserver != null) { |
| | | webserver.sendMessage(jsonObject.toString()); |
| | | } else { |
| | | log.info("Home is closed"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | public void overTask(String loadStatus, int state) { |
| | | |