| | |
| | | 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.tools.DateUtil; |
| | | 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.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | |
| | | private UpPattenUsageService upPattenUsageService; |
| | | @Autowired |
| | | private OptimizeProjectService optimizeProjectService; |
| | | |
| | | @Autowired |
| | | RedisUtil redisUtil; |
| | | @Resource |
| | | private LoadGlassDeviceTaskService loadGlassDeviceTaskService; |
| | | |
| | | 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 { |
| | | //获取联机状态 |
| | | String inkageStatus =plcParameterObject.getPlcParameter("MesToPlc").getValue(); |
| | | String inkageStatus = plcParameterObject.getPlcParameter("InkageStatus").getValue(); |
| | | //获取是否有上片请求 |
| | | String loadRequest = plcParameterObject.getPlcParameter("loadRequest").getValue(); |
| | | //mes状态 |
| | | String mesToPlc = plcParameterObject.getPlcParameter("MesToPlc").getValue(); |
| | | if("1".equals(inkageStatus)&&"1".equals(loadRequest)) { |
| | | if ("1".equals(inkageStatus) && "1".equals(loadRequest)) { |
| | | //判断开始上片的工程号 |
| | | Engineering engineering = engineeringService.selectInitiate(1); |
| | | if (engineering != 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); |
| | | S7object.getinstance().plccontrol.writeWord(plcParameterObject.getPlcParameter("WorkId").getAddress(), workId); |
| | | S7object.getinstance().plccontrol.writeWord(plcParameterObject.getPlcParameter("GlassWidth").getAddress(), (int) width); |
| | | S7object.getinstance().plccontrol.writeWord(plcParameterObject.getPlcParameter("GlassHeight").getAddress(), (int) height); |
| | | S7object.getinstance().plccontrol.writeWord(plcParameterObject.getPlcParameter("MesToPlc").getAddress(), 1); |
| | | //更改上片表状态 |
| | | upPattenUsageService.updateUpPattenUsageState(upPattenUsage, workId); |
| | | |
| | |
| | | } |
| | | if ("1".equals(mesToPlc) && "0".equals(loadRequest)) { |
| | | //请求字为零时,任务字清零 |
| | | S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("MesToPlc").getAddress(), 0); |
| | | S7object.getinstance().plccontrol.writeWord(plcParameterObject.getPlcParameter("MesToPlc").getAddress(), 0); |
| | | } |
| | | //执行后休眠300毫秒 |
| | | //Thread.sleep(300); |
| | |
| | | } |
| | | } |
| | | |
| | | @Scheduled(fixedDelay = 300) |
| | | public void plcLoadGlassReport(){ |
| | | // @Scheduled(fixedDelay = 300) |
| | | public void plcLoadGlassReport() { |
| | | //获取是否有汇报 |
| | | String loadStatus = plcParameterObject.getPlcParameter("PlcStatus").getValue(); |
| | | if (loadStatus != null) { |
| | |
| | | overTask(loadStatus, 0); |
| | | break; |
| | | case "0": |
| | | S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("MesToPlcStatus").getAddress(), 0); |
| | | S7object.getinstance().plccontrol.writeWord(plcParameterObject.getPlcParameter("MesToPlcStatus").getAddress(), 0); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Scheduled(fixedDelay = 1000) |
| | | public void loadGlassHome(){ |
| | | JSONObject jsonObject = new JSONObject(); |
| | | //正在进行的任务 |
| | | List<UpPattenUsage> upPattenUsages = upPattenUsageService.prioritylist(); |
| | | if(upPattenUsages!=null){ |
| | | jsonObject.append("prioritylist", upPattenUsages); |
| | | public void loadGlassHome() { |
| | | try { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | //正在进行的任务 |
| | | List<UpPattenUsage> upPattenUsages = upPattenUsageService.prioritylist(); |
| | | if(upPattenUsages!=null){ |
| | | jsonObject.append("prioritylist", upPattenUsages); |
| | | } |
| | | //查询1号线的任务 |
| | | Engineering request = redisUtil.getCacheObject("loadGlassRequest"); |
| | | if (request == null) { |
| | | request = new Engineering(); |
| | | request.setStationCell(5); |
| | | } |
| | | List<UpPattenUsage> upPattenUsages1 = upPattenUsageService.selectLoadTask(request); |
| | | jsonObject.append("loadTask1", upPattenUsages1); |
| | | //查询2号线的任务 |
| | | Engineering request2 = redisUtil.getCacheObject("loadGlassRequest2"); |
| | | if (request2 == null) { |
| | | request2 = new Engineering(); |
| | | request2.setStationCell(6); |
| | | } |
| | | List<UpPattenUsage> upPattenUsages2 = upPattenUsageService.selectLoadTask(request2); |
| | | jsonObject.append("loadTask2", upPattenUsages2); |
| | | // 查询工位任务 |
| | | //联机状态 |
| | | LoadGlassDeviceTask LoadOneState = loadGlassDeviceTaskService.queryTaskMessage(LOAD_GLASS_DEVICE_ONE_TASK); |
| | | LoadGlassDeviceTask LoadTwoState = loadGlassDeviceTaskService.queryTaskMessage(LOAD_GLASS_DEVICE_TWO_TASK); |
| | | jsonObject.append("LoadOneState", LoadOneState.getInkageState()); |
| | | jsonObject.append("LoadTwoervice", LoadTwoState.getInkageState()); |
| | | |
| | | //工位信息 |
| | | List<UpWorkstation> upWorkstations = upWorkstationService.list(); |
| | | jsonObject.append("list", upWorkstations); |
| | | |
| | | |
| | | ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("loadGlass"); |
| | | 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(); |
| | | } |
| | | |
| | | //工位信息 |
| | | List<UpWorkstation> upWorkstations = upWorkstationService.list(); |
| | | jsonObject.append("list", upWorkstations); |
| | | ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("loadGlass"); |
| | | } |
| | | |
| | | @Scheduled(fixedDelay = 1000) |
| | | public void send() { |
| | | ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("mainMes"); |
| | | if (sendwServer != null) { |
| | | //推送服务器当前时间 |
| | | JSONObject jsonObject = new JSONObject(); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | jsonObject.append("globalDate", sdf.format(DateUtil.getEndDate())); |
| | | 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"); |
| | | log.info("mainMes is closed"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | @Scheduled(fixedDelay = 5000) |
| | | public void loadGlassStatus(){ |
| | | |
| | | // @Scheduled(fixedDelay = 5000) |
| | | public void loadGlassStatus() { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | //正在进行的任务 |
| | | String inkageStatus =plcParameterObject.getPlcParameter("MesToPlc").getValue(); |
| | | String inkageStatus =plcParameterObject.getPlcParameter("InkageStatus").getValue(); |
| | | // String inkageStatus ="1"; |
| | | jsonObject.append("InkageStatus", inkageStatus); |
| | | ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("loadGlass"); |
| | |
| | | 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); |
| | | jsonObject.append("engineering", engineering); |
| | | //工位信息 |
| | | List<UpWorkstation> upWorkstations = upWorkstationService.list(); |
| | | jsonObject.append("list", upWorkstations); |
| | | ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("loadGlassIsRun"); |
| | | if (sendwServer != null) { |
| | | for (WebSocketServer webserver : sendwServer) { |
| | | if (webserver != null) { |
| | | webserver.sendMessage(jsonObject.toString()); |
| | | } else { |
| | | log.info("loadGlassIsRun is closed"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void overTask(String loadStatus, int state) { |
| | | public void overTask(String loadStatus, int state) { |
| | | |
| | | UpPattenUsage upPattenUsage = upPattenUsageService.selectOverTask(); |
| | | if (upPattenUsage != null) { |
| | |
| | | //完成上片表状态 |
| | | upPattenUsageService.updateUpPattenUsageState(upPattenUsage, state); |
| | | //判断是否是最后一块玻璃 |
| | | UpPattenUsage sequence=upPattenUsageService.selectSequence(upPattenUsage); |
| | | UpPattenUsage sequence = upPattenUsageService.selectSequence(upPattenUsage); |
| | | //如果是最后一块时完成工程任务 |
| | | optimizeProjectService.overTask(sequence,300); |
| | | optimizeProjectService.overTask(sequence, 300); |
| | | } |
| | | S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("MesToPlcStatus").getAddress(), 1); |
| | | S7object.getinstance().plccontrol.writeWord(plcParameterObject.getPlcParameter("MesToPlcStatus").getAddress(), 1); |
| | | } |
| | | |
| | | } |