| | |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | private Integer minHeight; |
| | | |
| | | |
| | | @Scheduled(fixedDelay = 3000) |
| | | @Scheduled(fixedDelay = 300) |
| | | public void plcHomeEdgTask() { |
| | | PlcParameterObject plcParameterObject = S7object.getinstance().PlcMesObject; |
| | | String requestWord = plcParameterObject.getPlcParameter("requestWord").getValue(); |
| | |
| | | if (CollectionUtils.isNotEmpty(list)) { |
| | | log.info("有空架子,将流程卡与架子好绑定,执行进片任务 结束"); |
| | | //绑定流程卡 |
| | | downWorkstationService.update(new LambdaUpdateWrapper<DownWorkstation>() |
| | | .set(DownWorkstation::getFlowCardId, glassInfo.getFlowCardId()) |
| | | .set(DownWorkstation::getLayer, glassInfo.getLayer()) |
| | | .eq(DownWorkstation::getWorkstationId, list.get(0).getWorkstationId())); |
| | | downWorkstationService.updateFlowCardIdAndCount(glassInfo.getFlowCardId(), list.get(0).getWorkstationId(), glassInfo.getLayer()); |
| | | checkFlag = Boolean.TRUE; |
| | | } |
| | | } |
| | |
| | | endLoop: |
| | | for (DownGlassInfoDTO e : downGlassInfoDTOList) { |
| | | List<GlassInfo> glassInfoList = e.getGlassInfoList(); |
| | | for (GlassInfo item : glassInfoList) { |
| | | if (item.getWidth() == glassInfo.getWidth() && item.getHeight() == glassInfo.getHeight() |
| | | && item.getThickness() == glassInfo.getThickness() && item.getFilmsid().equals(glassInfo.getFilmsid())) { |
| | | //玻璃是否为多层 |
| | | checkFlag = multilayerCheck(item, Boolean.FALSE); |
| | | if (checkFlag) { |
| | | //玻璃替换 仅替换流程卡id及层数 |
| | | String tempFlowCardId = item.getFlowCardId(); |
| | | Integer tempLayer = item.getLayer(); |
| | | String flowCardId = glassInfo.getFlowCardId(); |
| | | Integer layer = glassInfo.getLayer(); |
| | | log.info("替换流程卡信息,当前玻璃信息:{}的流程卡号{}及层数{},替换后玻璃信息:{}的流程卡号{}及层数{}", |
| | | item, glassInfo, flowCardId, layer, tempFlowCardId, tempLayer); |
| | | glassInfo.setFlowCardId(tempFlowCardId); |
| | | glassInfo.setLayer(tempLayer); |
| | | glassInfoService.updateById(glassInfo); |
| | | item.setFlowCardId(flowCardId); |
| | | item.setLayer(layer); |
| | | glassInfoService.updateById(item); |
| | | break endLoop; |
| | | } |
| | | Optional<GlassInfo> glassInfoTempOptional = glassInfoList.stream().filter(item -> item.getWidth() == glassInfo.getWidth() && item.getHeight() == glassInfo.getHeight() |
| | | && item.getThickness() == glassInfo.getThickness() && item.getFilmsid().equals(glassInfo.getFilmsid())) |
| | | .findFirst(); |
| | | if (glassInfoTempOptional.isPresent()) { |
| | | GlassInfo item = glassInfoTempOptional.get(); |
| | | //玻璃是否为多层 |
| | | checkFlag = multilayerCheck(item, Boolean.FALSE); |
| | | if (checkFlag) { |
| | | //玻璃替换 仅替换流程卡id及层数 |
| | | String tempFlowCardId = item.getFlowCardId(); |
| | | Integer tempLayer = item.getLayer(); |
| | | String flowCardId = glassInfo.getFlowCardId(); |
| | | Integer layer = glassInfo.getLayer(); |
| | | log.info("替换流程卡信息,当前玻璃信息:{}的流程卡号{}及层数{},替换后玻璃信息:{}的流程卡号{}及层数{}", |
| | | item, glassInfo, flowCardId, layer, tempFlowCardId, tempLayer); |
| | | glassInfo.setFlowCardId(tempFlowCardId); |
| | | glassInfo.setLayer(tempLayer); |
| | | glassInfoService.updateById(glassInfo); |
| | | item.setFlowCardId(flowCardId); |
| | | item.setLayer(layer); |
| | | glassInfoService.updateById(item); |
| | | break endLoop; |
| | | } |
| | | } |
| | | } |
| | |
| | | downStorageCageDetails.setState(Const.GLASS_STATE_IN); |
| | | downStorageCageDetails.setSlot(nearestEmpty.getSlot()); |
| | | downStorageCageDetailsService.save(downStorageCageDetails); |
| | | // 生成进片任务 |
| | | |
| | | // 生成进片任务 |
| | | initDownGlassTask(glassInfo, 0, nearestEmpty.getSlot(), Const.GLASS_CACHE_TYPE_IN); |
| | | } |
| | | |
| | | public Boolean outTo(String glassStatus06, String out08Glassstate, String glassStatus11, String glassStatus13, String glassId, String currentSlot) { |
| | | public Boolean outTo(String glassStatus06, String out08Glassstate, String glassStatus11, String |
| | | glassStatus13, String glassId, String currentSlot) { |
| | | if ("2".equals(glassStatus06) && "2".equals(glassStatus11) && "2".equals(glassStatus13)) { |
| | | log.info("G06、G11、G13分别为{},{}、{}非自动状态,无法出片", glassStatus06, glassStatus11, glassStatus13); |
| | | return Boolean.FALSE; |
| | |
| | | return Boolean.FALSE; |
| | | } |
| | | Boolean flag08 = "1".equals(out08Glassstate) ? Boolean.TRUE : Boolean.FALSE; |
| | | if (!generateTaskByShelf(glassStatus06, glassStatus11, flag08, glassStatus13, tempList, cageDetails, glassId)) { |
| | | return generateTaskByShelf(glassStatus06, glassStatus11, !flag08, glassStatus13, tempList, cageDetails, glassId); |
| | | if (!flag08) { |
| | | generateTaskByShelf(glassStatus06, glassStatus11, flag08, glassStatus13, tempList, cageDetails, glassId); |
| | | } else { |
| | | if (!generateTaskByShelf(glassStatus06, glassStatus11, flag08, glassStatus13, tempList, cageDetails, glassId)) { |
| | | return generateTaskByShelf(glassStatus06, glassStatus11, !flag08, glassStatus13, tempList, cageDetails, glassId); |
| | | } |
| | | } |
| | | |
| | | return Boolean.TRUE; |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | private Boolean generateTaskByShelf(String glassStatus06, String glassStatus11, Boolean flag08, String glassStatus13, List<DownStorageCageDetails> tempList, DownStorageCageDetails cageDetails, String glassId) { |
| | | private Boolean generateTaskByShelf(String glassStatus06, String glassStatus11, Boolean flag08, String |
| | | glassStatus13, List<DownStorageCageDetails> tempList, DownStorageCageDetails cageDetails, String glassId) { |
| | | //获取2个机械臂范围内的架子绑定的流程卡信息 |
| | | List<Integer> workList = new ArrayList(); |
| | | |
| | |
| | | workList.addAll(Const.G06_WORK_STATION); |
| | | } |
| | | } |
| | | List<Integer> workStationAll = Arrays.asList(1, 2, 3, 4, 5, 6); |
| | | List<Integer> offWorkStationList = workStationAll.stream().filter(e -> !workList.contains(e)).collect(Collectors.toList()); |
| | | List<DownStorageCageDetails> list = new ArrayList(); |
| | | Boolean isEmptyShelf = Boolean.FALSE; |
| | | //对笼内玻璃进行过滤,仅出符合逻辑的玻璃 |
| | | if (CollectionUtils.isNotEmpty(workList)) { |
| | | List<DownWorkstation> downWorkstationList = downWorkstationService.list(new LambdaQueryWrapper<DownWorkstation>() |
| | | .eq(DownWorkstation::getEnableState, Const.SLOT_ON).in(DownWorkstation::getWorkstationId, workList)); |
| | | log.info("架子被禁用,无法出片落架"); |
| | | // log.info("架子被禁用,无法出片落架"); |
| | | if (CollectionUtils.isEmpty(downWorkstationList)) { |
| | | log.info("笼子被禁用,无法走机械臂下片"); |
| | | //走人工下片 |
| | |
| | | list = tempList.stream().filter(item -> item.getWidth() > maxWidth || item.getHeight() > maxHeight).collect(Collectors.toList()); |
| | | } |
| | | } else { |
| | | //获取可落架的的架子信息(包括空架子) |
| | | List<DownWorkstation> workstationsIsNotBind = downWorkstationList.stream().filter(item -> null == (item.getFlowCardId())).collect(Collectors.toList()); |
| | | Map<String, List<DownWorkstation>> listMap = downWorkstationList.stream().collect(Collectors.groupingBy(item -> item.getFlowCardId() + ":" + item.getLayer())); |
| | | //将架子的流程卡号及层数作为key |
| | | if (CollectionUtils.isEmpty(workstationsIsNotBind)) { |
| | | log.info("不存在未绑定流程卡架子"); |
| | | //筛选出对应架子已绑定流程卡可下片的玻璃 |
| | | Map<String, List<DownWorkstation>> listMap = downWorkstationList.stream() |
| | | .filter(item -> null != (item.getFlowCardId())).collect(Collectors.groupingBy(item -> item.getFlowCardId() + ":" + item.getLayer())); |
| | | list = tempList.stream().filter(item -> listMap.containsKey(item.getFlowCardId() + ":" + item.getLayer())).collect(Collectors.toList()); |
| | | } else { |
| | | log.info("存在未绑定流程卡架子,直接获取笼内所有玻璃"); |
| | | log.info("存在未绑定流程卡架子,直接获取笼内所有玻璃,且未绑定架子的玻璃信息"); |
| | | //获取禁用架子的流程号,将笼内绑定架子且架子被禁用的流程卡信息 |
| | | |
| | | List<DownWorkstation> downWorkstationOffList = downWorkstationService.list(new LambdaQueryWrapper<DownWorkstation>() |
| | | .and(i -> i.in(DownWorkstation::getWorkstationId, offWorkStationList).or().eq(DownWorkstation::getEnableState, Const.SLOT_OFF))); |
| | | //获取被禁用的流程卡信息 |
| | | if (CollectionUtils.isEmpty(downWorkstationOffList)) { |
| | | list = tempList; |
| | | } else { |
| | | Map<String, List<DownWorkstation>> listOffMap = downWorkstationOffList.stream().filter(item -> null != (item.getFlowCardId())).collect(Collectors.groupingBy(item -> item.getFlowCardId() + ":" + item.getLayer())); |
| | | list = tempList.stream().filter(item -> !listOffMap.containsKey(item.getFlowCardId() + ":" + item.getLayer())).collect(Collectors.toList()); |
| | | } |
| | | isEmptyShelf = Boolean.TRUE; |
| | | //todo:如果禁用架子已绑定流程卡,因为时间不确定,笼子内的玻璃可重新绑定新架子 |
| | | // list = tempList.stream().filter(item -> !listMap.containsKey(item.getFlowCardId() + ":" + item.getLayer())).collect(Collectors.toList()); |
| | | list = tempList; |
| | | |
| | | } |
| | | } |
| | | } else { |
| | |
| | | } |
| | | } |
| | | loop: |
| | | if (tempGlassId == null) { |
| | | if (StringUtils.isBlank(tempGlassId)) { |
| | | //获取正在落架的绑定流程卡的信息(流程卡、层数、落架数量) |
| | | List<DownGlassInfoDTO> downGlassInfoDTOList = downGlassInfoService.queryWorkStationIsIn(Boolean.TRUE); |
| | | List<String> downGlassFlowList = downGlassInfoDTOList.stream().map(item -> item.getFlowCardId() + ":" + item.getLayer()).collect(Collectors.toList()); |
| | | if (CollectionUtils.isEmpty(downGlassFlowList)) { |
| | | //架子都未绑定流程卡,出笼内子数量最多尺寸最大的玻璃id,无 则返回扫描扫到的玻璃id进行出片 |
| | | tempGlassId = downStorageCageDetailsService.getGlassInfoMaxCount(glassId); |
| | | tempGlassId = downStorageCageDetailsService.getGlassInfoMaxCount(glassId, offWorkStationList); |
| | | |
| | | isBind = Boolean.TRUE; |
| | | break loop; |
| | | } |
| | | //将笼子内的玻璃进行过滤,仅获取无法落架的流程卡玻璃 |
| | | List<DownStorageCageDetails> noDownLoadList = list.stream().filter(item -> !downGlassFlowList.contains(item.getFlowCardId() + ":" + item.getLayer())).collect(Collectors.toList()); |
| | | List<DownStorageCageDetails> noDownLoadList = list.stream().filter(item -> !downGlassFlowList.contains(item.getFlowCardId() + ":" + item.getLayer())) |
| | | .collect(Collectors.toList()); |
| | | if (CollectionUtils.isNotEmpty(noDownLoadList)) { |
| | | //是否有空架子 |
| | | // List<DownWorkstation> emptyShelfList = downWorkstationService.list(new LambdaQueryWrapper<DownWorkstation>() |
| | | // .isNull(DownWorkstation::getFlowCardId)); |
| | | if (isEmptyShelf) { |
| | | //架子都未绑定流程卡,出笼内子数量最多尺寸最大的玻璃id,无 则返回扫描扫到的玻璃id进行出片 |
| | | tempGlassId = downStorageCageDetailsService.getGlassInfoMaxCount(glassId); |
| | | tempGlassId = downStorageCageDetailsService.getGlassInfoMaxCount(glassId, offWorkStationList); |
| | | isBind = Boolean.TRUE; |
| | | break loop; |
| | | } |
| | |
| | | |
| | | Map<String, List<DownStorageCageDetails>> singleLayerMap = list.stream().filter(item -> item.getTotalLayer() == 1) |
| | | .collect(Collectors.groupingBy(item -> item.getFlowCardId() + item.getLayer(), Collectors.toList())); |
| | | if (tempGlassId == null) { |
| | | if (StringUtils.isBlank(tempGlassId)) { |
| | | if (CollectionUtils.isNotEmpty(singleLayerMap)) { |
| | | //获取已落架流程卡信息,按落架数量排序 |
| | | for (DownGlassInfoDTO e : downGlassInfoDTOList) { |
| | |
| | | } |
| | | } |
| | | } |
| | | if (tempGlassId == null) { |
| | | if (StringUtils.isBlank(tempGlassId)) { |
| | | log.info("没有找到可以下片的的玻璃,结束任务"); |
| | | return Boolean.FALSE; |
| | | } else { |
| | | //按照出片的玻璃id更新笼内的玻璃状态为已出片 |
| | | return generateDownGlassOutTask(tempGlassId, Const.GLASS_CACHE_TYPE_OUT, isBind, cageDetails); |
| | | return generateDownGlassOutTask(tempGlassId, Const.GLASS_CACHE_TYPE_OUT, isBind, cageDetails, workList); |
| | | } |
| | | } |
| | | |
| | | public Boolean generateDownGlassOutTask(String glassId, Integer taskType, Boolean isBind, DownStorageCageDetails cageDetails) { |
| | | public Boolean generateDownGlassOutTask(String glassId, Integer taskType, Boolean |
| | | isBind, DownStorageCageDetails cageDetails, List<Integer> workList) { |
| | | //按玻璃id获取玻璃信息 |
| | | DownStorageCageDetails downStorageCageDetails = null; |
| | | if (glassId.equals(cageDetails.getGlassId())) { |
| | | downStorageCageDetails = cageDetails; |
| | | taskType = 3; |
| | | //将下片玻璃存入笼子详情信息表中 |
| | | //将任务插入理片笼详情表 |
| | | downStorageCageDetails.setState(Const.GLASS_STATE_OUT); |
| | | downStorageCageDetailsService.save(downStorageCageDetails); |
| | | } else { |
| | | downStorageCageDetails = downStorageCageDetailsService.getOne(new LambdaQueryWrapper<DownStorageCageDetails>() |
| | | .eq(DownStorageCageDetails::getGlassId, glassId)); |
| | | .eq(DownStorageCageDetails::getGlassId, glassId).eq(DownStorageCageDetails::getState, Const.GLASS_STATE_IN)); |
| | | if (downStorageCageDetailsService.update(new LambdaUpdateWrapper<DownStorageCageDetails>() |
| | | .set(DownStorageCageDetails::getState, Const.GLASS_STATE_OUT).eq(DownStorageCageDetails::getGlassId, glassId))) { |
| | | log.info("更新详情表内的状态成功"); |
| | | // return Boolean.TRUE; |
| | | } else { |
| | | log.info("更新详情表内的状态失败"); |
| | | return Boolean.FALSE; |
| | | } |
| | | } |
| | | |
| | | Integer endCell = null; |
| | | if (isBind) { |
| | | //获取空架子信息,将空架子信息绑定流程卡 |
| | | DownWorkstation emptyDownWorkstation = downWorkstationService.getOne(new LambdaQueryWrapper<DownWorkstation>() |
| | | .isNull(DownWorkstation::getFlowCardId).orderByDesc(DownWorkstation::getWorkstationId).last("limit 1")); |
| | | .isNull(DownWorkstation::getFlowCardId).in(DownWorkstation::getWorkstationId, workList).orderByDesc(DownWorkstation::getWorkstationId).last("limit 1")); |
| | | if (null != emptyDownWorkstation) { |
| | | log.info("获取到空架子信息,绑定流程卡"); |
| | | emptyDownWorkstation.setFlowCardId(downStorageCageDetails.getFlowCardId()); |
| | | emptyDownWorkstation.setLayer(downStorageCageDetails.getLayer()); |
| | | downWorkstationService.updateById(emptyDownWorkstation); |
| | | downWorkstationService.updateFlowCardIdAndCount(downStorageCageDetails.getFlowCardId(), emptyDownWorkstation.getWorkstationId(), downStorageCageDetails.getLayer()); |
| | | endCell = emptyDownWorkstation.getWorkstationId(); |
| | | } else { |
| | | log.info("没有空架子信息,无法绑定流程卡"); |
| | |
| | | .eq(DownWorkstation::getFlowCardId, downStorageCageDetails.getFlowCardId()).eq(DownWorkstation::getLayer, downStorageCageDetails.getLayer())); |
| | | endCell = workstation.getWorkstationId(); |
| | | } |
| | | //更新详情表内的状态 |
| | | if (downStorageCageDetailsService.update(new LambdaUpdateWrapper<DownStorageCageDetails>() |
| | | .set(DownStorageCageDetails::getState, Const.GLASS_STATE_OUT).eq(DownStorageCageDetails::getGlassId, glassId))) { |
| | | log.info("更新详情表内的状态成功"); |
| | | } else { |
| | | log.info("更新详情表内的状态失败"); |
| | | return Boolean.FALSE; |
| | | } |
| | | //更新落架玻璃数量 |
| | | if (endCell == 7) { |
| | | downWorkstationService.update(new UpdateWrapper<DownWorkstation>().eq("flow_card_id", downStorageCageDetails.getFlowCardId()) |
| | | .eq("layer", downStorageCageDetails.getLayer()).setSql("artificial_number = artificial_number +1")); |
| | | .eq("layer", downStorageCageDetails.getLayer()).setSql("other_number = other_number +1")); |
| | | } else { |
| | | downWorkstationService.update(new UpdateWrapper<DownWorkstation>().eq("flow_card_id", downStorageCageDetails.getFlowCardId()) |
| | | .eq("layer", downStorageCageDetails.getLayer()).setSql("racks_number = racks_number +1")); |
| | |
| | | //生成任务信息 |
| | | DownGlassInfo downGlassInfo = new DownGlassInfo(); |
| | | BeanUtils.copyProperties(downStorageCageDetails, downGlassInfo); |
| | | //todo:落架片序 |
| | | downGlassInfo.setSequence(downGlassInfoService.queryMaxSequence(downGlassInfo.getFlowCardId(), downGlassInfo.getLayer())); |
| | | downGlassInfoService.save(downGlassInfo); |
| | | //生成任务信息 |
| | | GlassInfo glassInfo = new GlassInfo(); |
| | |
| | | startCell, endCell, taskType); |
| | | } |
| | | |
| | | private Boolean sendMessageToPlc(int width, int height, int thickness, int startCell, int endCell, int taskType) { |
| | | private Boolean sendMessageToPlc(int width, int height, int thickness, int startCell, int endCell, |
| | | int taskType) { |
| | | S7control s7control = S7object.getinstance().plccontrol; |
| | | PlcParameterObject plcMesObject = S7object.getinstance().PlcMesObject; |
| | | s7control.writeWord(plcMesObject.getPlcParameter("Glass_width").getAddress(), width); |