| | |
| | | |
| | | import cn.hutool.json.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.kangaroohy.milo.model.ReadWriteEntity; |
| | | import com.github.xingshuangs.iot.protocol.s7.serializer.S7Serializer; |
| | | import com.kangaroohy.milo.service.MiloService; |
| | | import com.mes.alarm.entity.ProductAlarmInfo; |
| | | import com.mes.alarm.service.ProductAlarmInfoService; |
| | | import com.mes.bigstorage.entity.BigStorageCageDetails; |
| | | import com.mes.bigstorage.entity.dto.BigStorageSummaryDTO; |
| | | import com.mes.bigstorage.service.BigStorageCageDetailsService; |
| | | import com.mes.bigstorage.service.BigStorageCageService; |
| | | import com.mes.bigstoragecagetask.entity.BigStorageCageTask; |
| | | import com.mes.bigstoragecagetask.entity.BigStorageTaskVO; |
| | | import com.mes.bigstoragecagetask.service.BigStorageCageHistoryTaskService; |
| | | import com.mes.bigstoragecagetask.service.BigStorageCageTaskService; |
| | | import com.mes.common.config.Const; |
| | | import com.mes.glassinfo.service.GlassInfoService; |
| | | import com.mes.largenscreen.entity.PieChartVO; |
| | | import com.mes.largenscreen.entity.RunTime; |
| | | import com.mes.s7.entity.S7DataDLPOne; |
| | | import com.mes.s7.entity.S7DataDLPTwo; |
| | | import com.mes.temperingglass.entity.TemperingGlassInfo; |
| | | import com.mes.temperingglass.service.TemperingGlassInfoService; |
| | | import com.mes.tools.WebSocketServer; |
| | | import com.mes.tools.WebSocketUtils; |
| | | import com.mes.utils.RedisUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | private GlassInfoService glassInfoService; |
| | | @Resource |
| | | private BigStorageCageTaskService bigStorageCageTaskService; |
| | | @Resource |
| | | private BigStorageCageHistoryTaskService bigStorageCageHistoryTaskService; |
| | | |
| | | @Autowired(required = false) |
| | | MiloService miloService; |
| | | |
| | | @Autowired |
| | | @Qualifier("s7SerializerDLPOne") |
| | | private S7Serializer s7SerializerDLPOne; |
| | | |
| | | @Autowired |
| | | @Qualifier("s7SerializerDLPTwo") |
| | | private S7Serializer s7SerializerDLPTwo; |
| | | |
| | | @Resource |
| | | private WebSocketUtils webSocketUtils; |
| | | |
| | | @Resource |
| | | private ProductAlarmInfoService productAlarmInfoService; |
| | | |
| | | |
| | | private static final String ALARM_MODULE = "钢化"; |
| | | private static final String ALARM_TYPE = "钢化大理片"; |
| | | private static final String ALARM_CODE_SIZE = "sizeSame"; |
| | | private static final String ALARM_CODE_ID = "idSame"; |
| | | |
| | | private JSONObject jsonObject = new JSONObject(); |
| | | |
| | | public void queryDataSource1() throws Exception { |
| | | jsonObject.append("alarmInfo", productAlarmInfoService.list(new LambdaQueryWrapper<ProductAlarmInfo>() |
| | | .eq(ProductAlarmInfo::getState, Const.LOAD_RAW_GLASS_NEW) |
| | | .eq(ProductAlarmInfo::getAlarmModule, ALARM_MODULE) |
| | | .eq(ProductAlarmInfo::getAlarmType, ALARM_TYPE))); |
| | | List<Double> carPostion = new ArrayList<>(); |
| | | carPostion.add(0.25); |
| | | carPostion.add(0.5); |
| | |
| | | //界面展示笼子信息 |
| | | jsonObject.append("bigStorageCageInfos", bigStorageCageDetailsService.querybigStorageCageDetail()); |
| | | |
| | | S7DataDLPOne s7DataDLPOne = s7SerializerDLPOne.read(S7DataDLPOne.class); |
| | | S7DataDLPTwo s7DataWLTwo = s7SerializerDLPTwo.read(S7DataDLPTwo.class); |
| | | try { |
| | | //进片任务数据 |
| | | List<BigStorageTaskVO> inTaskList = new ArrayList(); |
| | | ReadWriteEntity fromOpcUa = miloService.readFromOpcUa("DLP1A.DLP1A.FROM1"); |
| | | String fromOpcUa = s7DataDLPOne.getFrom1().toString(); |
| | | List<Integer> states = s7DataDLPOne.getStates(); |
| | | List<Integer> tos = s7DataDLPOne.getTos(); |
| | | List<String> ids = s7DataDLPOne.getIds(); |
| | | for (int i = 1; i <= 6; i++) { |
| | | ReadWriteEntity requestWord = miloService.readFromOpcUa("DLP1A.DLP1A.DI" + i); |
| | | ReadWriteEntity targetSlotWord = miloService.readFromOpcUa("DLP1A.DLP1A.TO" + i); |
| | | ReadWriteEntity stateWord = miloService.readFromOpcUa("DLP1A.DLP1A.STATE" + i); |
| | | if (null != requestWord.getValue()) { |
| | | String requestWord = ids.get(i - 1); |
| | | String targetSlotWord = tos.get(i - 1).toString(); |
| | | String stateWord = states.get(i - 1).toString(); |
| | | if (StringUtils.isNotEmpty(requestWord)) { |
| | | BigStorageTaskVO task = new BigStorageTaskVO(); |
| | | task.setGlassId(requestWord.getValue() + ""); |
| | | task.setGlassId(requestWord); |
| | | int isExistCount = bigStorageCageDetailsService.count(new LambdaQueryWrapper<BigStorageCageDetails>().in(BigStorageCageDetails::getGlassId, task.getGlassId()) |
| | | .in(BigStorageCageDetails::getState, Const.GLASS_STATE_IN_ALL_ZERO)); |
| | | .in(BigStorageCageDetails::getState, Const.GLASS_STATE_IN_ALL)); |
| | | if (isExistCount > 0) { |
| | | task.setIsSame(1); |
| | | } else { |
| | | task.setIsSame(0); |
| | | } |
| | | task.setStartSlot(Integer.parseInt(fromOpcUa.getValue() + "")); |
| | | task.setTargetSlot(Integer.parseInt(targetSlotWord.getValue() + "")); |
| | | task.setTaskState(Integer.parseInt(stateWord.getValue() + "")); |
| | | task.setStartSlot(Integer.parseInt(fromOpcUa)); |
| | | task.setTargetSlot(Integer.parseInt(targetSlotWord)); |
| | | task.setTaskState(Integer.parseInt(stateWord)); |
| | | inTaskList.add(task); |
| | | continue; |
| | | } |
| | |
| | | } |
| | | try { |
| | | //进片联机 |
| | | ReadWriteEntity inkageEntity = miloService.readFromOpcUa("DLP1A.DLP1A.mesControl"); |
| | | jsonObject.append("inkageEntity", inkageEntity.getValue()); |
| | | Boolean inkageEntity = s7DataDLPOne.getMesControl(); |
| | | jsonObject.append("inkageEntity", inkageEntity); |
| | | //进片请求 |
| | | ReadWriteEntity requestEntity = miloService.readFromOpcUa("DLP1A.DLP1A.RequestMes"); |
| | | jsonObject.append("requestEntity", requestEntity.getValue()); |
| | | String requestEntity = s7DataDLPOne.getRequestMes().toString(); |
| | | jsonObject.append("requestEntity", requestEntity); |
| | | //启动命令 |
| | | ReadWriteEntity mesReplyEntity = miloService.readFromOpcUa("DLP1A.DLP1A.MesReply"); |
| | | jsonObject.append("mesReplyEntity", mesReplyEntity.getValue()); |
| | | String mesReplyEntity = s7DataDLPOne.getMesReply().toString(); |
| | | jsonObject.append("mesReplyEntity", mesReplyEntity); |
| | | //出片联机 |
| | | ReadWriteEntity outInkageEntity = miloService.readFromOpcUa("DLP1B.DLP1B.mesControl"); |
| | | jsonObject.append("outInkageEntity", outInkageEntity.getValue()); |
| | | Boolean outInkageEntity = s7DataWLTwo.getMesControl(); |
| | | jsonObject.append("outInkageEntity", outInkageEntity); |
| | | //出片请求 |
| | | ReadWriteEntity outRequestEntity = miloService.readFromOpcUa("DLP1B.DLP1B.RequestMes"); |
| | | jsonObject.append("outRequestEntity", outRequestEntity.getValue()); |
| | | String outRequestEntity = s7DataWLTwo.getRequestMes().toString(); |
| | | jsonObject.append("outRequestEntity", outRequestEntity); |
| | | |
| | | |
| | | //出片任务数据 |
| | | List<BigStorageCageTask> outTaskList = bigStorageCageTaskService.queryTaskMessage("big_storage_cage_out_one_task"); |
| | | List<BigStorageCageTask> outTaskList = new ArrayList<>(); |
| | | for (int i = 0; i < 6; i++) { |
| | | |
| | | BigStorageCageTask bigStorageCageTask = new BigStorageCageTask(); |
| | | String glassId = ""; |
| | | Integer startSlot = 0; |
| | | Integer targetSlot = 0; |
| | | Integer taskState = 0; |
| | | switch (i) { |
| | | case 0: |
| | | glassId = s7DataWLTwo.getId1(); |
| | | startSlot = s7DataWLTwo.getFrom1(); |
| | | targetSlot = s7DataWLTwo.getTo1(); |
| | | taskState = s7DataWLTwo.getState1(); |
| | | ; |
| | | break; |
| | | case 1: |
| | | glassId = s7DataWLTwo.getId2(); |
| | | startSlot = s7DataWLTwo.getFrom2(); |
| | | targetSlot = s7DataWLTwo.getTo2(); |
| | | taskState = s7DataWLTwo.getState2(); |
| | | break; |
| | | case 2: |
| | | glassId = s7DataWLTwo.getId3(); |
| | | startSlot = s7DataWLTwo.getFrom3(); |
| | | targetSlot = s7DataWLTwo.getTo3(); |
| | | taskState = s7DataWLTwo.getState3(); |
| | | break; |
| | | case 3: |
| | | glassId = s7DataWLTwo.getId4(); |
| | | startSlot = s7DataWLTwo.getFrom4(); |
| | | targetSlot = s7DataWLTwo.getTo4(); |
| | | taskState = s7DataWLTwo.getState4(); |
| | | break; |
| | | case 4: |
| | | glassId = s7DataWLTwo.getId5(); |
| | | startSlot = s7DataWLTwo.getFrom5(); |
| | | targetSlot = s7DataWLTwo.getTo5(); |
| | | taskState = s7DataWLTwo.getState5(); |
| | | break; |
| | | case 5: |
| | | glassId = s7DataWLTwo.getId6(); |
| | | startSlot = s7DataWLTwo.getFrom6(); |
| | | targetSlot = s7DataWLTwo.getTo6(); |
| | | taskState = s7DataWLTwo.getState6(); |
| | | break; |
| | | } |
| | | if (StringUtils.isNotEmpty(glassId)) { |
| | | bigStorageCageTask.setGlassId(glassId); |
| | | bigStorageCageTask.setStartSlot(startSlot); |
| | | bigStorageCageTask.setTargetSlot(targetSlot); |
| | | bigStorageCageTask.setTaskState(taskState); |
| | | outTaskList.add(bigStorageCageTask); |
| | | } |
| | | } |
| | | jsonObject.append("bigStorageCageDetailsOutTask", outTaskList); |
| | | } catch (Exception e) { |
| | | //todo:不做任务处理 |
| | |
| | | jsonObject.append("autoPrint", autoPrint); |
| | | |
| | | //当前指定工程 |
| | | String temperingengineerId = ""; |
| | | if (redisUtil.getCacheObject("temperingengineerId") == null) { |
| | | redisUtil.setCacheObject("temperingengineerId", temperingengineerId); |
| | | } else { |
| | | temperingengineerId = redisUtil.getCacheObject("temperingengineerId"); |
| | | } |
| | | jsonObject.append("temperingengineerId", temperingengineerId); |
| | | jsonObject.append("temperingEngineerId", redisUtil.getCacheObject("temperingEngineerId")); |
| | | |
| | | |
| | | } |
| | |
| | | * fixedDelay : 上一个调用结束后再次调用的延时 |
| | | */ |
| | | @Scheduled(fixedDelay = 3000) |
| | | public void plcStorageCageTask() throws InterruptedException { |
| | | public void plcStorageCageTask() throws Exception { |
| | | jsonObject = new JSONObject(); |
| | | try { |
| | | //查询使用数据源1查询数据 |
| | | queryDataSource1(); |
| | | //查询使用数据源2查询数据 |
| | | //查询使用数据源1查询数据 |
| | | queryDataSource1(); |
| | | //查询使用数据源2查询数据 |
| | | // queryDataSource2(); |
| | | webSocketUtils.sendToWeb("slicecage", jsonObject); |
| | | } |
| | | |
| | | ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("slicecage"); |
| | | 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"); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | @Scheduled(fixedDelay = 1000) |
| | | public void largenScreen() { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | //理片笼使用情况 |
| | | List<Map<String, Object>> bigStorageCageUsage = bigStorageCageService.selectBigStorageCageUsage(); |
| | | jsonObject.append("bigStorageCageUsage", bigStorageCageUsage); |
| | | List<PieChartVO> pieChartVOS = bigStorageCageService.queryPieChart(); |
| | | jsonObject.append("pieChartVOS", pieChartVOS); |
| | | List<RunTime> tempRunTimes = bigStorageCageHistoryTaskService.queryRunTimes(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); |
| | | jsonObject.append("tempRunTimes", tempRunTimes); |
| | | webSocketUtils.sendToWeb("largenScreen", jsonObject); |
| | | } |
| | | } |