| | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.lang.Assert; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.github.xingshuangs.iot.protocol.s7.serializer.S7Serializer; |
| | | import com.github.xingshuangs.iot.protocol.s7.service.S7PLC; |
| | | import com.github.yulichang.toolkit.JoinWrappers; |
| | | import com.kangaroohy.milo.model.ReadWriteEntity; |
| | | import com.kangaroohy.milo.service.MiloService; |
| | |
| | | @Autowired |
| | | @Qualifier("s7SerializerDLPTwo") |
| | | private S7Serializer s7SerializerDLPTwo; |
| | | @Autowired |
| | | @Qualifier("s7plcWZL") |
| | | private S7PLC s7plcWZL; |
| | | |
| | | @Resource |
| | | SysConfigService sysConfigService; |
| | |
| | | private static final String ALARM_TYPE = "钢化大理片"; |
| | | private static final String ALARM_CODE_SIZE = "sizeSame"; |
| | | private static final String ALARM_CODE_ID = "idSame"; |
| | | private static final String ALARM_CODE_SLOT = "slotLess"; |
| | | private static final String ALARM_CODE_OVER = "overSize"; |
| | | |
| | | @Resource |
| | | private RedisUtil redisUtil; |
| | |
| | | String fromOpcUa = s7DataDLPOne.getFrom1().toString(); |
| | | |
| | | List<String> ids = s7DataDLPOne.getIds(); |
| | | log.info("获取到进片任务 玻璃id:{}", ids); |
| | | List<String> glassIdList = new ArrayList<>(); |
| | | for (int i = 0; i < 6; i++) { |
| | | String requestWord = ids.get(i); |
| | | if (null != requestWord && !requestWord.isEmpty()) { |
| | | if (StringUtils.isNotBlank(requestWord)) { |
| | | log.info("玻璃id{}加入进片任务", requestWord); |
| | | BigStorageCageTask task = new BigStorageCageTask(); |
| | | task.setGlassId(requestWord); |
| | | task.setStartSlot(Integer.parseInt(fromOpcUa)); |
| | | inTaskList.add(task); |
| | | glassIdList.add(requestWord); |
| | | break; |
| | | } |
| | | } |
| | | if (CollectionUtil.isEmpty(inTaskList)) { |
| | |
| | | for (Map.Entry<Double, Long> entry : thickCountMap.entrySet()) { |
| | | int count = bigStorageCageService.count(new LambdaQueryWrapper<BigStorageCage>() |
| | | .eq(BigStorageCage::getEnableState, Const.SLOT_ON).eq(BigStorageCage::getRemainWidth, slotWidth) |
| | | .ge(BigStorageCage::getDeviceId, 4) |
| | | .le(BigStorageCage::getDeviceId, 4) |
| | | .le(BigStorageCage::getMinThickness, entry.getKey()) |
| | | .ge(BigStorageCage::getMaxThickness, entry.getKey())); |
| | | if (count < entry.getValue()) { |
| | | log.info("笼内格子剩余数量不足,结束本次进片"); |
| | | ProductAlarmInfo alarmInfo = new ProductAlarmInfo(); |
| | | alarmInfo.setState(Const.LOAD_RAW_GLASS_NEW); |
| | | alarmInfo.setAlarmModule(ALARM_MODULE); |
| | | alarmInfo.setAlarmType(ALARM_TYPE); |
| | | alarmInfo.setAlarmCode(ALARM_CODE_SLOT); |
| | | alarmInfo.setAlarmMessage(count + ""); |
| | | productAlarmInfoService.save(alarmInfo); |
| | | //向plc发送报警:笼内格子剩余数量不足 |
| | | // miloService.writeToOpcWord(generateReadWriteEntity("DLP1A.DLP1A.alarmSignal", 16)); |
| | | s7DataDLPOne = new S7DataDLPOne(); |
| | |
| | | .in(BigStorageCageDetails::getState, Const.GLASS_STATE_IN_ALL)); |
| | | if (count > 0) { |
| | | log.info("直通片台存在玻璃,结束本次进片"); |
| | | ProductAlarmInfo alarmInfo = new ProductAlarmInfo(); |
| | | alarmInfo.setState(Const.LOAD_RAW_GLASS_NEW); |
| | | alarmInfo.setAlarmModule(ALARM_MODULE); |
| | | alarmInfo.setAlarmType(ALARM_TYPE); |
| | | alarmInfo.setAlarmCode(ALARM_CODE_OVER); |
| | | alarmInfo.setAlarmMessage(""); |
| | | productAlarmInfoService.save(alarmInfo); |
| | | //向plc发送报警:直通片台存在玻璃,无法继续直通 |
| | | // miloService.writeToOpcWord(generateReadWriteEntity("DLP1A.DLP1A.alarmSignal", 64)); |
| | | s7DataDLPOne = new S7DataDLPOne(); |
| | |
| | | log.info("当前未收到出片请求,结束出片任务"); |
| | | return; |
| | | } |
| | | int outRequest = s7plcWZL.readUInt16("DB51.8"); |
| | | if (outRequest == 0){ |
| | | log.info("当前未收到卧转立允许出片请求,结束出片任务"); |
| | | return; |
| | | } |
| | | //获取出片任务表 |
| | | List<BigStorageCageTask> outTaskList = getOutTaskList(s7DataWLTwo); |
| | | if (CollectionUtil.isNotEmpty(outTaskList)) { |
| | |
| | | LambdaQueryWrapper<BigStorageCage> queryWrapper = new LambdaQueryWrapper<BigStorageCage>() |
| | | .eq(BigStorageCage::getRemainWidth, slotWidth) |
| | | .eq(BigStorageCage::getEnableState, Const.SLOT_ON) |
| | | .le(BigStorageCage::getMinThickness, info.getThickness()) |
| | | .ge(BigStorageCage::getMaxThickness, info.getThickness()) |
| | | .orderByAsc(BigStorageCage::getDeviceId).orderByAsc(BigStorageCage::getSlot) |
| | | .last("limit 1"); |
| | | |
| | |
| | | cageDetails.setFilmsId(info.getFilmsId()); |
| | | cageDetails.setId(null); |
| | | bigStorageCageDetailsService.save(cageDetails); |
| | | info.setState(Const.GLASS_STATE_OUT); |
| | | bigStorageCageDetailsService.updateById(info); |
| | | } |
| | | //历史数据入库 |
| | | bigStorageCageHistoryTaskService.saveBatch(historyTasks); |
| | | extracted(taskList); |
| | | S7DataDLPTwo s7DataDLPTwo = new S7DataDLPTwo(); |
| | | s7DataDLPTwo.setMesReply(1); |
| | | s7SerializerDLPTwo.write(s7DataDLPTwo); |
| | | return; |
| | | } |
| | | |
| | |
| | | |
| | | String temperingEngineerId = redisUtil.getCacheObject("temperingEngineerId"); |
| | | if (StringUtils.isNotBlank(temperingEngineerId)) { |
| | | TemperingGlassInfo temperingGlassInfo = temperingGlassInfoService.getOne(new QueryWrapper<TemperingGlassInfo>() |
| | | .select("Top 1 *") |
| | | .eq("engineer_id", temperingEngineerId) |
| | | .orderByDesc("tempering_layout_id")); |
| | | List<TemperingGlassInfo> temperingGlassInfoList = temperingGlassInfoService.list( |
| | | new LambdaQueryWrapper<TemperingGlassInfo>() |
| | | .eq(TemperingGlassInfo::getEngineerId, temperingEngineerId) |
| | | .orderByAsc(TemperingGlassInfo::getId) |
| | | ); |
| | | int temperingLayoutId = 1; |
| | | if (temperingGlassInfo != null) { |
| | | temperingLayoutId = temperingGlassInfo.getTemperingLayoutId() + 1; |
| | | if (CollectionUtils.isEmpty(temperingGlassInfoList)) { |
| | | temperingLayoutId = 1; |
| | | } else { |
| | | List<Integer> tempIds = temperingGlassInfoList.stream() |
| | | .map(TemperingGlassInfo::getTemperingLayoutId) |
| | | .distinct() |
| | | .sorted() |
| | | .collect(Collectors.toList()); |
| | | |
| | | int expected = 1; |
| | | for (int current : tempIds) { |
| | | if (current > expected) { |
| | | break; // 找到第一个缺失值,跳出循环 |
| | | } else if (current == expected) { |
| | | expected++; // 连续则递增期望的值 |
| | | } |
| | | } |
| | | temperingLayoutId = expected; // 缺失则为expected,连续则为max+1 |
| | | } |
| | | List<GlassInfo> glassInfos = glassInfoService.list(new LambdaQueryWrapper<GlassInfo>().eq(GlassInfo::getEngineerId, temperingEngineerId).eq(GlassInfo::getTemperingLayoutId, temperingLayoutId)); |
| | | if (CollectionUtil.isEmpty(glassInfos)) { |
| | |
| | | .last("limit 1")); |
| | | List<Integer> slotList = sequenceDTOList.stream().map(BigStorageSequenceDTO::getSlot).collect(Collectors.toList()); |
| | | list = bigStorageCageDetailsService.list(new LambdaQueryWrapper<BigStorageCageDetails>() |
| | | .eq(BigStorageCageDetails::getState, Const.GLASS_STATE_IN).in(BigStorageCageDetails::getSlot, slotList)); |
| | | .eq(BigStorageCageDetails::getState, Const.GLASS_STATE_IN) |
| | | .in(BigStorageCageDetails::getSlot, slotList) |
| | | .orderByAsc(BigStorageCageDetails::getTemperingFeedSequence) |
| | | ); |
| | | computeOutGlassInfoByVirtualSlot(list, "big_storage_cage_out_one_task", |
| | | bigStorageCage.getSlot(), Const.GLASS_STATE_SCHEDULE_ING, Const.BIG_STORAGE_BEFORE_DISPATCH); |
| | | slotList.add(bigStorageCage.getSlot()); |
| | | updateSlotRemainBySlots(slotList); |
| | | return; |
| | | } |
| | | //有:统一往5号笼子送 |
| | | // 无 4号笼子使用数量是否超过阈值 有 生成调度任务按照组号组序由1开始依次往5号笼子送小片 |
| | |
| | | .eq(BigStorageCage::getEnableState, Const.SLOT_ON)); |
| | | //定义10个格子为阈值 |
| | | if (count <= 10) { |
| | | log.info("笼子超过阈值,执行4号笼子调度逻辑"); |
| | | //获取序号为1的格子 将格子内的所有玻璃送到对应的笼子 |
| | | BigStorageCage bigStorageCage = bigStorageCageService.getOne(new LambdaQueryWrapper<BigStorageCage>() |
| | | .eq(BigStorageCage::getRemainWidth, slotWidth) |
| | |
| | | .in(BigStorageCage::getDeviceId, Arrays.asList(5, 6)) |
| | | .orderByAsc(BigStorageCage::getDeviceId).orderByAsc(BigStorageCage::getSlot) |
| | | .last("limit 1")); |
| | | |
| | | list = bigStorageCageDetailsService.queryNeedDispatch(); |
| | | computeOutGlassInfoByVirtualSlot(list, "big_storage_cage_out_one_task", |
| | | bigStorageCage.getSlot(), Const.GLASS_STATE_SCHEDULE_ING, Const.BIG_STORAGE_BEFORE_DISPATCH); |
| | | List<Integer> slotList = new ArrayList<>(); |
| | | slotList.add(bigStorageCage.getSlot()); |
| | | slotList.add(list.get(0).getSlot()); |
| | | updateSlotRemainBySlots(slotList); |
| | | return; |
| | | if (null != bigStorageCage) { |
| | | list = bigStorageCageDetailsService.queryNeedDispatch(); |
| | | if (CollectionUtil.isNotEmpty(list)) { |
| | | computeOutGlassInfoByVirtualSlot(list, "big_storage_cage_out_one_task", |
| | | bigStorageCage.getSlot(), Const.GLASS_STATE_SCHEDULE_ING, Const.BIG_STORAGE_BEFORE_DISPATCH); |
| | | List<Integer> slotList = new ArrayList<>(); |
| | | slotList.add(bigStorageCage.getSlot()); |
| | | slotList.add(list.get(0).getSlot()); |
| | | updateSlotRemainBySlots(slotList); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | //生成调度任务按照组号组序由1开始依次往5号笼子送小片 |
| | | BigStorageSlotDTO slotDTO = bigStorageCageDetailsService.queryNeedDispatchSlotBySequence(); |
| | | if (null != slotDTO) { |
| | | list = bigStorageCageDetailsService.list(new LambdaQueryWrapper<BigStorageCageDetails>() |
| | | .eq(BigStorageCageDetails::getState, Const.GLASS_STATE_IN).in(BigStorageCageDetails::getSlot, slotDTO.getStartSlot())); |
| | | .eq(BigStorageCageDetails::getState, Const.GLASS_STATE_IN) |
| | | .in(BigStorageCageDetails::getSlot, slotDTO.getStartSlot()) |
| | | .orderByAsc(BigStorageCageDetails::getTemperingFeedSequence) |
| | | ); |
| | | computeOutGlassInfoByVirtualSlot(list, "big_storage_cage_out_one_task", |
| | | slotDTO.getTargetSlot(), Const.GLASS_STATE_SCHEDULE_ING, Const.BIG_STORAGE_BEFORE_DISPATCH); |
| | | List<Integer> slotList = new ArrayList<>(); |
| | |
| | | * @return |
| | | */ |
| | | private Boolean extracted(List<BigStorageCageTask> bigStorageCageTaskList) { |
| | | resetOutTask(); |
| | | // resetOutTask(); |
| | | S7DataDLPTwo s7DataDLPTwo = new S7DataDLPTwo(); |
| | | for (int i = 0; i < bigStorageCageTaskList.size() && i < 6; i++) { |
| | | String glassId = bigStorageCageTaskList.get(i).getGlassId(); |