| | |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | @Autowired(required = false) |
| | | MiloService miloService; |
| | | |
| | | |
| | | // @Resource(name = "cacheGlassStartCallback") |
| | | // SubscriptionCallback cacheGlassStartCallback; |
| | | // |
| | | // @Resource(name = "cacheGlassTestCallback") |
| | | // SubscriptionCallback cacheGlassTestCallback; |
| | | |
| | | @Resource |
| | | EdgStorageDeviceTaskService edgStorageDeviceTaskService; |
| | | // @Resource |
| | | // EdgGlassTaskQueueInfoService edgGlassTaskQueueInfoService; |
| | | @Autowired |
| | | EdgGlassTaskInfoService edgGlassTaskInfoService; |
| | | |
| | | @Resource |
| | | GlassInfoService glassInfoService; |
| | | @Resource |
| | |
| | | @Resource |
| | | DamageService damageService; |
| | | |
| | | @Value("${mes.glassGap}") |
| | | // @Value("${mes.glassGap}") |
| | | private int glassGap; |
| | | @Value("${mes.threshold}") |
| | | // @Value("${mes.threshold}") |
| | | private int threshold; |
| | | @Value("${mes.cellLength}") |
| | | // @Value("${mes.cellLength}") |
| | | private int cellLength; |
| | | @Value("${mes.ratio}") |
| | | // @Value("${mes.ratio}") |
| | | private int ratio; |
| | | |
| | | @Value("${mes.min.one.firstLength}") |
| | | // @Value("${mes.min.one.firstLength}") |
| | | private int minOneFirstLength; |
| | | |
| | | @Value("${mes.min.one.secondLength}") |
| | | // @Value("${mes.min.one.secondLength}") |
| | | private int minOneSecondLength; |
| | | |
| | | @Value("${mes.min.two.firstLength}") |
| | | // @Value("${mes.min.two.firstLength}") |
| | | private int minTwoFirstLength; |
| | | |
| | | @Value("${mes.min.two.secondLength}") |
| | | // @Value("${mes.min.two.secondLength}") |
| | | private int minTwoSecondLength; |
| | | |
| | | private String glassInIdOne = ""; |
| | |
| | | private String glassIdOne = ""; |
| | | private String glassIdTwo = ""; |
| | | |
| | | // @Scheduled(fixedDelay = Long.MAX_VALUE) |
| | | // public void startOneOpcTask() throws Exception { |
| | | // miloService.subscriptionFromOpcUa(Arrays.asList("mes.WL1.edg_storage_device_one_task[1].task_state"), cacheGlassStartCallback); |
| | | // } |
| | | // |
| | | // @Scheduled(fixedDelay = Long.MAX_VALUE) |
| | | // public void startTwoOpcTask() throws Exception { |
| | | // miloService.subscriptionFromOpcUa(Arrays.asList("mes.WL2.edg_storage_device_two_task[1].task_state"), cacheGlassStartCallback); |
| | | // } |
| | | |
| | | @Scheduled(fixedDelay = 1000) |
| | | // @Scheduled(fixedDelay = 1000) |
| | | public void startOneOpcTask() { |
| | | startOneOpcTaskChild(EDG_STORAGE_DEVICE_ONE_TASK, 1); |
| | | } |
| | | |
| | | @Scheduled(fixedDelay = 1000) |
| | | // @Scheduled(fixedDelay = 1000) |
| | | public void startTwoOpcTask() { |
| | | startOneOpcTaskChild(EDG_STORAGE_DEVICE_TWO_TASK, 2); |
| | | } |
| | |
| | | log.info("将启动子改为4"); |
| | | task.setTaskRunning(Const.GLASS_CACHE_TYPE_RUNNING); |
| | | edgStorageDeviceTaskService.updateTaskMessage(tableName, task); |
| | | } else { |
| | | } else if (request == 5) { |
| | | log.info("设备:{}状态:{}", device, request); |
| | | finishTask(task, tableName); |
| | | } else { |
| | | log.info("玻璃异常处理"); |
| | | damageTask(task, tableName); |
| | | } |
| | | // } catch (Exception e) { |
| | | // log.info("执行任务过程中发生异常,任务字{},{}", task.getTaskState(), e.getMessage()); |
| | |
| | | } |
| | | |
| | | |
| | | @Scheduled(fixedDelay = 1000) |
| | | // @Scheduled(fixedDelay = 1000) |
| | | public void edgOneOpcTask() throws Exception { |
| | | EdgStorageDeviceTask task = edgStorageDeviceTaskService.queryTaskMessage(EDG_STORAGE_DEVICE_ONE_TASK); |
| | | String glassId = task.getGlassId(); |
| | |
| | | edgTaskChild(glassId, 1); |
| | | } |
| | | |
| | | @Scheduled(fixedDelay = 1000) |
| | | // @Scheduled(fixedDelay = 1000) |
| | | public void edgTwoOpcTask() throws Exception { |
| | | EdgStorageDeviceTask task = edgStorageDeviceTaskService.queryTaskMessage(EDG_STORAGE_DEVICE_TWO_TASK); |
| | | String glassId = task.getGlassId(); |
| | |
| | | if (null != edgeData) { |
| | | GlassInfo glassOutInfo = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>().eq(GlassInfo::getGlassId, edgeData.getGlassIdOut())); |
| | | //笼内的玻璃的尺寸是否和上一次任务一致 |
| | | edgStorageCageDetails = edgStorageCageDetailsService.queryEdgStorageDetailsBySize(deviceId, task.getCurrentCell(), glassOutInfo.getWidth(), glassOutInfo.getHeight()); |
| | | edgStorageCageDetails = edgStorageCageDetailsService.queryEdgStorageDetailsBySize(deviceId, task.getCurrentCell(), glassOutInfo.getWidth(), glassOutInfo.getHeight(), 0, 0); |
| | | if (null == edgStorageCageDetails && StringUtils.isNotBlank(task.getGlassIdIn())) { |
| | | GlassInfo glassInInfo = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>() |
| | | .eq(GlassInfo::getGlassId, task.getGlassIdIn()) |
| | |
| | | } |
| | | } |
| | | if (null == edgStorageCageDetails) { |
| | | edgStorageCageDetails = edgStorageCageDetailsService.queryEdgStorageDetailsBySize(deviceId, task.getCurrentCell(), 0, 0); |
| | | edgStorageCageDetails = edgStorageCageDetailsService.queryEdgStorageDetailsBySize(deviceId, task.getCurrentCell(), 0, 0, 0, 0); |
| | | } |
| | | if (edgStorageCageDetails == null && StringUtils.isNotBlank(task.getGlassIdIn())) { |
| | | //和上次任务不存在相同尺寸 |
| | |
| | | Date startDate = new Date(); |
| | | log.info("开始执行完成任务后清除动作,任务信息为:{},表名为:{},开始时间:{}", task, tableName, startDate); |
| | | Integer cell = task.getStartCell(); |
| | | Integer state = task.getTaskState(); |
| | | task.setTaskRunning(Const.GLASS_CACHE_TYPE_EMPTY); |
| | | task.setGlassIdOut(""); |
| | | task.setStartCell(0); |
| | |
| | | edgStorageDeviceTaskHistoryService.update(new LambdaUpdateWrapper<EdgStorageDeviceTaskHistory>() |
| | | .eq(EdgStorageDeviceTaskHistory::getTaskState, Const.RAW_GLASS_TASK_NEW) |
| | | .eq(EdgStorageDeviceTaskHistory::getDeviceId, device) |
| | | .set(EdgStorageDeviceTaskHistory::getTaskState, |
| | | Const.GLASS_CACHE_TYPE_FINISH.equals(state) ? Const.RAW_GLASS_TASK_SUCCESS : Const.RAW_GLASS_TASK_FAILURE) |
| | | .set(EdgStorageDeviceTaskHistory::getTaskState, Const.RAW_GLASS_TASK_SUCCESS) |
| | | ); |
| | | //最后更新任务,保证任务前的动作都做完 |
| | | edgStorageDeviceTaskService.updateTaskMessage(tableName, task); |
| | | Date endDate = new Date(); |
| | | log.info("结束完成任务后清除动作,表名为:{},结束时间为:{},共耗时:{}ms", tableName, endDate, endDate.getTime() - startDate.getTime()); |
| | | return Boolean.TRUE; |
| | | } |
| | | |
| | | private boolean damageTask(EdgStorageDeviceTask task, String tableName) { |
| | | if (task.getTaskState() <= 5) { |
| | | log.info("任务未发生异常清空,任务结束,电气状态{},mes状态{}", task.getTaskState(), task.getTaskRunning()); |
| | | return Boolean.FALSE; |
| | | } |
| | | Date startDate = new Date(); |
| | | log.info("开始执行异常处理任务后清除动作,任务信息为:{},表名为:{},开始时间:{}", task, tableName, startDate); |
| | | int device = tableName.equals("edg_storage_device_one_task") ? 1 : 2; |
| | | EdgStorageDeviceTaskHistory taskHistory = edgStorageDeviceTaskHistoryService.getOne(new LambdaQueryWrapper<EdgStorageDeviceTaskHistory>() |
| | | .eq(EdgStorageDeviceTaskHistory::getTaskState, Const.RAW_GLASS_TASK_NEW) |
| | | .eq(EdgStorageDeviceTaskHistory::getDeviceId, device) |
| | | .orderByDesc(EdgStorageDeviceTaskHistory::getCreateTime).last("limit 1")); |
| | | Integer cell = taskHistory.getStartCell(); |
| | | Integer taskType = taskHistory.getTaskType(); |
| | | if (Const.GLASS_CACHE_TYPE_IN_ALL.contains(taskType)) { |
| | | String glassId = taskHistory.getGlassIdIn(); |
| | | edgStorageCageDetailsService.remove(new LambdaQueryWrapper<EdgStorageCageDetails>() |
| | | .eq(EdgStorageCageDetails::getDeviceId, device) |
| | | .eq(EdgStorageCageDetails::getSlot, cell) |
| | | .eq(EdgStorageCageDetails::getGlassId, glassId)); |
| | | } else { |
| | | String glassId = taskHistory.getGlassIdOut(); |
| | | edgStorageCageDetailsService.update(new LambdaUpdateWrapper<EdgStorageCageDetails>() |
| | | .set(EdgStorageCageDetails::getState, Const.GLASS_STATE_IN) |
| | | .eq(EdgStorageCageDetails::getDeviceId, device) |
| | | .eq(EdgStorageCageDetails::getSlot, cell) |
| | | .eq(EdgStorageCageDetails::getGlassId, glassId)); |
| | | } |
| | | |
| | | updateCellRemainWidth(cell, device, taskHistory); |
| | | edgStorageDeviceTaskHistoryService.update(new LambdaUpdateWrapper<EdgStorageDeviceTaskHistory>() |
| | | .eq(EdgStorageDeviceTaskHistory::getTaskState, Const.RAW_GLASS_TASK_NEW) |
| | | .eq(EdgStorageDeviceTaskHistory::getDeviceId, device) |
| | | .set(EdgStorageDeviceTaskHistory::getTaskState, Const.RAW_GLASS_TASK_FAILURE) |
| | | ); |
| | | //最后更新任务,保证任务前的动作都做完 |
| | | task.setTaskRunning(Const.GLASS_CACHE_TYPE_EMPTY); |
| | | task.setGlassIdOut(""); |
| | | task.setStartCell(0); |
| | | edgStorageDeviceTaskService.updateTaskMessage(tableName, task); |
| | | Date endDate = new Date(); |
| | | log.info("完成执行异常处理任务后清除动作,表名为:{},结束时间为:{},共耗时:{}ms", tableName, endDate, endDate.getTime() - startDate.getTime()); |
| | | return Boolean.TRUE; |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | return Boolean.TRUE; |
| | | } |
| | | |
| | | private boolean updateCellRemainWidth(int slot, int device, EdgStorageDeviceTaskHistory taskHistory) { |
| | | public boolean updateCellRemainWidth(int slot, int device, EdgStorageDeviceTaskHistory taskHistory) { |
| | | List<EdgStorageCageDetails> list = edgStorageCageDetailsService.list(new LambdaQueryWrapper<EdgStorageCageDetails>().eq(EdgStorageCageDetails::getSlot, slot) |
| | | .eq(EdgStorageCageDetails::getState, Const.GLASS_STATE_IN)); |
| | | int remainWidth = cellLength; |
| | |
| | | if (2 == taskHistory.getTaskType()) { |
| | | remainWidth = 0; |
| | | } else { |
| | | EdgStorageCage storageCage = edgStorageCageService.getOne(new LambdaQueryWrapper<EdgStorageCage>() |
| | | .eq(EdgStorageCage::getDeviceId, device).eq(EdgStorageCage::getSlot, slot)); |
| | | EdgStorageCageDetails bigDetails = list.stream().filter(e -> e.getGlassId().equals(taskHistory.getGlassIdIn())).findFirst().orElse(null); |
| | | remainWidth = storageCage.getRemainWidth() - glassGap - (int) Math.max(bigDetails.getWidth(), bigDetails.getHeight()); |
| | | for (EdgStorageCageDetails item : list) { |
| | | remainWidth = remainWidth - glassGap - (int) Math.max(item.getWidth(), item.getHeight()); |
| | | } |
| | | if (remainWidth <= 0) { |
| | | remainWidth = 0; |
| | | } |