| | |
| | | package com.mes.job; |
| | | |
| | | import cn.hutool.core.lang.Assert; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.mes.bigstorage.entity.BigStorageCageDetails; |
| | | import com.mes.bigstorage.entity.BigStorageDTO; |
| | | import com.mes.bigstorage.service.BigStorageCageDetailsService; |
| | | import com.mes.bigstorage.service.BigStorageCageService; |
| | | import com.mes.bigstoragetask.entity.BigStorageCageFeedTask; |
| | |
| | | import com.mes.bigstoragetask.service.BigStorageCageFeedTaskService; |
| | | import com.mes.bigstoragetask.service.BigStorageCageOutTaskService; |
| | | import com.mes.common.S7object; |
| | | import com.mes.common.config.Const; |
| | | import com.mes.device.PlcParameterObject; |
| | | import com.mes.edgglasstask.service.EdgGlassTaskInfoService; |
| | | import com.mes.edgstoragetask.service.TaskCacheService; |
| | | import com.mes.glassinfo.entity.GlassInfo; |
| | | import com.mes.glassinfo.service.GlassInfoService; |
| | | import com.mes.temperingglass.service.TemperingGlassInfoService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.atomic.AtomicReference; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author SNG-015 |
| | |
| | | @Resource |
| | | private TemperingGlassInfoService temperingGlassInfoService; |
| | | |
| | | PlcParameterObject plcParameterObject = S7object.getinstance().PlcMesObject; |
| | | @Value("${mes.sequence.order}") |
| | | private boolean sequenceOrder; |
| | | |
| | | public static boolean bigStorageCageFullAlarm = false; |
| | | |
| | | private int line1Time=0; |
| | | private int line2Time=0; |
| | | private int line1Time = 0; |
| | | private int line2Time = 0; |
| | | |
| | | /** |
| | | * fixedRate : 上一个调用开始后再次调用的延时(不用等待上一次调用完成) |
| | |
| | | */ |
| | | @Scheduled(fixedDelay = 5000) |
| | | public void plcStorageCageTask() throws InterruptedException { |
| | | |
| | | PlcParameterObject plcParameterObject = S7object.getinstance().PlcMesObject; |
| | | try { |
| | | |
| | | String plcFeedGlassid = ""; |
| | | String plcFeedReqLine = "0"; |
| | | if ("1".equals(plcParameterObject.getPlcParameter("D01Request").getValue())) { |
| | | plcFeedReqLine = "1"; |
| | | plcFeedGlassid=plcParameterObject.getPlcParameter("D01ID1").getValue(); |
| | | plcFeedGlassid = plcParameterObject.getPlcParameter("D01ID1").getValue(); |
| | | } |
| | | if ("1".equals(plcParameterObject.getPlcParameter("D04Request").getValue())) { |
| | | plcFeedReqLine = "2"; |
| | | plcFeedGlassid=plcParameterObject.getPlcParameter("D04ID1").getValue(); |
| | | plcFeedGlassid = plcParameterObject.getPlcParameter("D04ID1").getValue(); |
| | | } |
| | | line1Time+=1; |
| | | line2Time+=1; |
| | | line1Time += 1; |
| | | line2Time += 1; |
| | | |
| | | if (!("0".equals(plcFeedReqLine))) { |
| | | log.info("1、Plc进片请求时"); |
| | | BigStorageCageDetails bigStorageCageDetails = new BigStorageCageDetails(); |
| | | GlassInfo glassInfo = glassInfoService.getById(plcFeedGlassid); |
| | | log.info("2、根据玻璃id获取玻璃信息" + glassInfo); |
| | | if(bigStorageCageDetailsService.selectGetBoard(plcFeedReqLine)>=0){ |
| | | if (bigStorageCageDetailsService.selectGetBoard(plcFeedReqLine) >= 0) { |
| | | BigStorageCageDetails slotInfo = bigStorageCageService.feedGlass(glassInfo, bigStorageCageDetails); |
| | | if (slotInfo != null) { |
| | | int taskType = edgGlassTaskInfoService.judgeTasktype(plcFeedReqLine); |
| | |
| | | } else { |
| | | bigStorageCageFullAlarm = true; |
| | | } |
| | | }else{ |
| | | } else { |
| | | log.info("当前玻璃宽度不够上车" + glassInfo); |
| | | if(!("1".equals(plcFeedReqLine))){ |
| | | if (!("1".equals(plcFeedReqLine))) { |
| | | S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("D02Go").getAddress(), 1); |
| | | }else{ |
| | | } else { |
| | | S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("D05Go").getAddress(), 1); |
| | | } |
| | | } |
| | |
| | | log.info("7、删除已经完成的进片任务"); |
| | | } |
| | | //启动阈值 |
| | | if(line1Time>=300){ |
| | | if("0".equals(plcParameterObject.getPlcParameter("D05Go").getValue())){ |
| | | if (line1Time >= 300) { |
| | | if ("0".equals(plcParameterObject.getPlcParameter("D05Go").getValue())) { |
| | | S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("D02Go").getAddress(), 1); |
| | | } |
| | | } |
| | | if(line2Time>=300){ |
| | | if("0".equals(plcParameterObject.getPlcParameter("D02Go").getValue())){ |
| | | if (line2Time >= 300) { |
| | | if ("0".equals(plcParameterObject.getPlcParameter("D02Go").getValue())) { |
| | | S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("D05Go").getAddress(), 1); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //查询出片表是否有任务未完成的任务 |
| | | List<BigStorageCageOutTask> bigStorageCageOutTask=bigStorageCageOutTaskService.querybigStorageCageOutTask(0); |
| | | if(bigStorageCageOutTask.size()==0){ |
| | | boolean result=bigStorageCageService.outGlass(); |
| | | List<BigStorageCageOutTask> bigStorageCageOutTask = bigStorageCageOutTaskService.querybigStorageCageOutTask(0); |
| | | if (bigStorageCageOutTask.size() == 0) { |
| | | boolean result = bigStorageCageService.outGlass(); |
| | | log.info("8、没有未完成任务时调用出片接口"); |
| | | if (result==false){ |
| | | if (result == false) { |
| | | temperingGlassInfoService.schedulingTask(); |
| | | } |
| | | } |
| | |
| | | log.info("9、根据任务表状态修改钢化小片表任务状态"); |
| | | |
| | | //来不及送时直接走 |
| | | String line=Integer.toString(edgGlassTaskInfoService.startTask()); |
| | | String line = Integer.toString(edgGlassTaskInfoService.startTask()); |
| | | |
| | | if(!(line.equals(plcFeedReqLine))){ |
| | | if (!(line.equals(plcFeedReqLine))) { |
| | | S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("D02Go").getAddress(), 1); |
| | | }else{ |
| | | } else { |
| | | S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("D05Go").getAddress(), 1); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | @Scheduled(fixedDelay = 5000) |
| | | public void plcToHomeEdgFreeCarTask() { |
| | | PlcParameterObject plcParameterObject = S7object.getinstance().PlcMesObject; |
| | | String freeCar = plcParameterObject.getPlcParameter("freeCar").getValue(); |
| | | if ("1".equals(freeCar)) { |
| | | log.info("大车非空闲"); |
| | | return; |
| | | } |
| | | String d01Request = plcParameterObject.getPlcParameter("D01Request").getValue(); |
| | | String d01ID1 = plcParameterObject.getPlcParameter("D01ID1").getValue(); |
| | | // 0:不干预 ; 1:条件满足情况下立即发车 |
| | | String d04Request = plcParameterObject.getPlcParameter("D04Request").getValue(); |
| | | String d04ID1 = plcParameterObject.getPlcParameter("D04ID1").getValue(); |
| | | log.info("1、获取到的请求字d01为:{},获取到的扫描ID为:{};获取到的请求字d04为:{},获取到的扫描ID为:{};", |
| | | d01Request, d01ID1, d04Request, d04ID1); |
| | | //两条线都有进卧转立任务,直接结束 |
| | | if (Const.BIG_STORAGE_REQUEST_IN.equals(d01Request) |
| | | && Const.BIG_STORAGE_REQUEST_IN.equals(d04Request) |
| | | && StringUtils.isNotBlank(d01ID1) |
| | | && StringUtils.isNotBlank(d04ID1)) { |
| | | log.info("两条线都存在进片任务,结束任务"); |
| | | return; |
| | | } |
| | | //获取两条线卧转立是否有玻璃,且任务状态都为2 |
| | | List<String> lineList = bigStorageCageFeedTaskService.querySitToUpGlass(); |
| | | if (CollectionUtils.isEmpty(lineList)) { |
| | | log.info("两条线卧转立为空或者有进片任务未完成,结束任务"); |
| | | return; |
| | | } |
| | | // 0:不干预 ; 1:条件满足情况下立即发车 |
| | | String d02GoAdress = plcParameterObject.getPlcParameter("D02Go").getAddress(); |
| | | // 0:不干预 ; 1:条件满足情况下立即发车 |
| | | String d05GoAdress = plcParameterObject.getPlcParameter("D05Go").getAddress(); |
| | | String line1 = lineList.get(0); |
| | | String flagLine = line1.equals(Const.A09_OUT_TARGET_POSITION) ? d01ID1 : d04ID1; |
| | | if (lineList.size() == 1) { |
| | | //发送 |
| | | if (StringUtils.isNotBlank(flagLine)) { |
| | | return; |
| | | } |
| | | //计算任务表进片格子 发送进片任务 |
| | | computeTargetByLine(Integer.parseInt(flagLine), d02GoAdress, d05GoAdress); |
| | | } |
| | | if (StringUtils.isBlank(d01ID1) && StringUtils.isBlank(d04ID1)) { |
| | | //比较最早一片任务的版图id及版序 求出卧转立的线路 |
| | | Integer line = getStartLine(); |
| | | //计算任务表进片格子 发送进片任务 |
| | | computeTargetByLine(line, d02GoAdress, d05GoAdress); |
| | | return; |
| | | } |
| | | int outLine = StringUtils.isBlank(d01ID1) ? Const.A09_OUT_TARGET_POSITION : Const.A10_OUT_TARGET_POSITION; |
| | | //计算任务表进片格子 发送进片任务 |
| | | computeTargetByLine(outLine, d02GoAdress, d05GoAdress); |
| | | } |
| | | |
| | | /** |
| | | * 获取需要启动的线路:两条线都可启动 获取第一片玻璃版图id最小 版序最大的线路 |
| | | * |
| | | * @return |
| | | */ |
| | | private Integer getStartLine() { |
| | | List<BigStorageCageFeedTask> taskList = bigStorageCageFeedTaskService.list(new LambdaQueryWrapper<BigStorageCageFeedTask>() |
| | | .inSql(BigStorageCageFeedTask::getId, "select min(id) from big_storage_cage_feed_task where task_state = 2 group by line")); |
| | | Assert.isTrue(CollectionUtils.isEmpty(taskList), "卧转立两条线都没有玻璃进片任务"); |
| | | Map<String, Integer> taskMap = taskList.stream().collect(Collectors.toMap(BigStorageCageFeedTask::getGlassId, |
| | | BigStorageCageFeedTask::getLine)); |
| | | GlassInfo glassInfo = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>() |
| | | .in(GlassInfo::getGlassId, taskMap.keySet()) |
| | | .orderByAsc(GlassInfo::getTemperingLayoutId) |
| | | .orderBy(Boolean.TRUE, sequenceOrder, GlassInfo::getTemperingFeedSequence) |
| | | .last("limit 1")); |
| | | return taskMap.get(glassInfo.getGlassId()); |
| | | } |
| | | |
| | | /** |
| | | * 计算任务表进片线路的目标格子,并启动任务 |
| | | */ |
| | | private boolean computeTargetByLine(Integer line, String d02GoAdress, String d05GoAdress) { |
| | | //1、获取任务表中的所有玻璃(指定线路且已经进卧转立完成) |
| | | List<BigStorageCageFeedTask> taskList = bigStorageCageFeedTaskService.list(new LambdaQueryWrapper<BigStorageCageFeedTask>() |
| | | .eq(BigStorageCageFeedTask::getLine, line) |
| | | .eq(BigStorageCageFeedTask::getTaskState, Const.BIG_STORAGE_IN_UP) |
| | | .orderByAsc(BigStorageCageFeedTask::getId)); |
| | | //2、去笼子内查找是否可以继续存放的笼子 |
| | | List<String> glassIds = taskList.stream().map(BigStorageCageFeedTask::getGlassId).collect(Collectors.toList()); |
| | | List<GlassInfo> glassInfos = glassInfoService.list(new LambdaQueryWrapper<GlassInfo>().in(GlassInfo::getGlassId, glassIds)); |
| | | AtomicReference<Integer> temperingLayoutIdTemp = new AtomicReference<>(0); |
| | | AtomicReference<Integer> temperingFeedSequenceTemp = new AtomicReference<>(0); |
| | | AtomicReference<BigStorageDTO> bigStorageDTO = new AtomicReference<>(new BigStorageDTO()); |
| | | Map<String, GlassInfo> glassInfoMap = glassInfos.stream().collect(Collectors.toMap(GlassInfo::getGlassId, p -> p)); |
| | | taskList.stream().forEach(e -> { |
| | | //按照版图信息获取进片笼子格子号 |
| | | GlassInfo info = glassInfoMap.get(e.getGlassId()); |
| | | if (temperingLayoutIdTemp.equals(info.getTemperingLayoutId()) |
| | | && temperingFeedSequenceTemp.equals(info.getTemperingFeedSequence() + 1) |
| | | && info.getWidth() <= bigStorageDTO.get().getWidth()) { |
| | | bigStorageDTO.get().setWidth(bigStorageDTO.get().getWidth() - info.getWidth().intValue() - Const.BIG_STORAGE_GAP); |
| | | } else { |
| | | bigStorageDTO.set(bigStorageCageDetailsService.queryTargetSlotByTempering(info)); |
| | | } |
| | | e.setTragetSlot(bigStorageDTO.get().getSlot()); |
| | | temperingLayoutIdTemp.set(info.getTemperingLayoutId()); |
| | | temperingFeedSequenceTemp.set(info.getTemperingFeedSequence()); |
| | | }); |
| | | //3、更新进片任务表 |
| | | boolean taskFlag = bigStorageCageFeedTaskService.updateBatchById(taskList); |
| | | if (taskFlag) { |
| | | String lineAddress = line.equals(Const.A09_OUT_TARGET_POSITION) ? d02GoAdress : d05GoAdress; |
| | | S7object.getinstance().plccontrol.writeWord(lineAddress, (short) 1); |
| | | } |
| | | return taskFlag; |
| | | } |
| | | } |