| | |
| | | package com.mes.job; |
| | | |
| | | 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.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.github.yulichang.toolkit.JoinWrappers; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import com.kangaroohy.milo.model.ReadWriteEntity; |
| | | import com.kangaroohy.milo.service.MiloService; |
| | | import com.mes.base.entity.BigStorageCageBaseInfo; |
| | | import com.mes.bigstorage.entity.BigStorageCage; |
| | | import com.mes.bigstorage.entity.BigStorageCageDetails; |
| | | import com.mes.bigstorage.entity.BigStorageDTO; |
| | | import com.mes.bigstorage.entity.dto.BigStorageDTO; |
| | | import com.mes.bigstorage.entity.dto.SlotSequenceDTO; |
| | | import com.mes.bigstorage.entity.dto.TemperingLayoutDTO; |
| | | import com.mes.bigstorage.service.BigStorageCageDetailsService; |
| | |
| | | import com.mes.damage.service.DamageService; |
| | | import com.mes.glassinfo.entity.GlassInfo; |
| | | import com.mes.glassinfo.service.GlassInfoService; |
| | | import com.mes.temperingglass.entity.TemperingGlass; |
| | | import com.mes.temperingglass.entity.TemperingGlassInfo; |
| | | import com.mes.temperingglass.service.TemperingGlassService; |
| | | import com.mes.temperingglass.service.TemperingGlassInfoService; |
| | | import com.mes.utils.RedisUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | 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; |
| | |
| | | @Resource |
| | | private BigStorageCageDetailsService bigStorageCageDetailsService; |
| | | @Resource |
| | | private TemperingGlassService temperingGlassService; |
| | | private TemperingGlassInfoService temperingGlassInfoService; |
| | | @Resource |
| | | private DamageService damageService; |
| | | @Resource |
| | |
| | | @Value("${mes.sequence.order}") |
| | | private boolean sequenceOrder; |
| | | |
| | | @Value("${mes.temperingOutTargetPosition}") |
| | | private Integer temperingOutTargetPosition; |
| | | @Value("${mes.artificialOutTargetPosition}") |
| | | private Integer artificialOutTargetPosition; |
| | | |
| | | @Scheduled(fixedDelay = 1000) |
| | | |
| | | // @Scheduled(fixedDelay = 1000) |
| | | public void inBigStorageTask() throws Exception { |
| | | ReadWriteEntity inkageEntity = miloService.readFromOpcUa("DLP1A.DLP1A.mesControl"); |
| | | if (true != Boolean.parseBoolean(inkageEntity.getValue() + "")) { |
| | |
| | | } |
| | | //获取进片任务表 |
| | | List<BigStorageCageTask> inTaskList = bigStorageCageTaskService.queryTaskMessage("big_storage_cage_in_one_task"); |
| | | if (CollectionUtils.isEmpty(inTaskList)) { |
| | | if (CollectionUtil.isEmpty(inTaskList)) { |
| | | log.info("当前大车无进片玻璃,结束进片任务"); |
| | | } |
| | | |
| | | List<String> glassIdList = inTaskList.stream().map(BigStorageCageTask::getGlassId).collect(Collectors.toList()); |
| | | log.info("获取任务的玻璃id:{}", glassIdList); |
| | | Map<String, Long> glassCountMap = glassIdList.stream().collect(Collectors.groupingBy(e -> e, Collectors.counting())); |
| | | for (Map.Entry<String, Long> entry : glassCountMap.entrySet()) { |
| | | if (entry.getValue() > 1) { |
| | | log.info("进片玻璃{}存在相同,结束本次任务", entry.getKey()); |
| | | //todo:向plc发送报警 |
| | | return; |
| | | } |
| | | } |
| | | List<BigStorageCageDetails> detailsList = bigStorageCageDetailsService.list(new LambdaQueryWrapper<BigStorageCageDetails>().in(BigStorageCageDetails::getGlassId, glassIdList) |
| | | .eq(BigStorageCageDetails::getState, Const.GLASS_STATE_IN_ALL)); |
| | | if (CollectionUtil.isNotEmpty(detailsList)) { |
| | | log.info("理片笼存在相同的进片玻璃{},结束本次任务", detailsList); |
| | | //todo:向plc发送报警 |
| | | return; |
| | | } |
| | | List<GlassInfo> glassInfoList = glassInfoService.list(new LambdaQueryWrapper<GlassInfo>().in(GlassInfo::getGlassId, glassIdList)); |
| | | |
| | | Map<String, List<GlassInfo>> glassListMap = glassInfoList.stream().collect(Collectors.groupingBy(GlassInfo::getGlassId)); |
| | |
| | | miloService.writeToOpcWord(generateReadWriteEntity("DLP1A.DLP1A.MesReply", 1)); |
| | | } |
| | | |
| | | // @Scheduled(fixedDelay = 1000) |
| | | // @Scheduled(fixedDelay = 1000) |
| | | public void outBigStorageTask() throws Exception { |
| | | Date startDate = new Date(); |
| | | ReadWriteEntity inkageEntity = miloService.readFromOpcUa("DLP1B.DLP1B.mesControl"); |
| | |
| | | } |
| | | //获取出片任务表 |
| | | List<BigStorageCageTask> outTaskList = bigStorageCageTaskService.queryTaskMessage("big_storage_cage_out_one_task"); |
| | | if (CollectionUtils.isNotEmpty(outTaskList)) { |
| | | if (CollectionUtil.isNotEmpty(outTaskList)) { |
| | | log.info("有正在执行的出片任务,结束本次出片任务"); |
| | | return; |
| | | } |
| | | //todo:是否允许钢化 |
| | | if (redisUtil.getCacheObject("temperingSwitch")) { |
| | | //是否有正在钢化的玻璃:钢化小片表关联历史任务表,筛选未出笼的玻璃信息 |
| | | List<TemperingGlass> temperingGlassList = temperingGlassService.selectJoinList(TemperingGlass.class, new MPJLambdaWrapper<TemperingGlass>() |
| | | .selectAll(TemperingGlass.class) |
| | | .leftJoin(BigStorageCageHistoryTask.class, BigStorageCageHistoryTask::getGlassId, TemperingGlass::getGlassId) |
| | | .eq(TemperingGlass::getState, Const.TEMPERING_NEW) |
| | | .eq(BigStorageCageHistoryTask::getTaskType, Const.BIG_STORAGE_BEFORE_OUT) |
| | | .isNull(BigStorageCageHistoryTask::getGlassId) |
| | | .orderBy(Boolean.TRUE, sequenceOrder, TemperingGlass::getTemperingFeedSequence)); |
| | | //todo:历史任务表 |
| | | if (CollectionUtils.isNotEmpty(temperingGlassList)) { |
| | | log.info("有正在出片的钢化任务"); |
| | | computeOutGlassInfo(temperingGlassList, "big_storage_cage_out_one_task", Const.TEMPERING_OUT_TARGET_POSITION, Const.GLASS_STATE_OUT_ING, Const.BIG_STORAGE_BEFORE_OUT); |
| | | Date endDate = new Date(); |
| | | log.info("大理片笼出片任务结束时间:{},共耗时:{}ms,结束扫码任务", endDate, endDate.getTime() - startDate.getTime()); |
| | | return; |
| | | // 获取当前钢化任务未完成出片的玻璃信息 |
| | | List<TemperingGlassInfo> unFinishTemperingGlassInfoList = temperingGlassInfoService.list(new LambdaQueryWrapper<TemperingGlassInfo>().eq(TemperingGlassInfo::getState, Const.TEMPERING_NEW)); |
| | | if (CollectionUtil.isNotEmpty(unFinishTemperingGlassInfoList)) { |
| | | List<String> glassIdList = unFinishTemperingGlassInfoList.stream().map(TemperingGlassInfo::getGlassId).collect(Collectors.toList()); |
| | | List<BigStorageCageHistoryTask> historyTaskList = bigStorageCageHistoryTaskService.list(new LambdaQueryWrapper<BigStorageCageHistoryTask>() |
| | | .eq(BigStorageCageHistoryTask::getTaskType, Const.BIG_STORAGE_BEFORE_OUT) |
| | | .in(BigStorageCageHistoryTask::getGlassId, glassIdList)); |
| | | List<TemperingGlassInfo> temperingGlassList = unFinishTemperingGlassInfoList; |
| | | if (CollectionUtil.isNotEmpty(historyTaskList)) { |
| | | List<String> taskGlassList = historyTaskList.stream().map(BigStorageCageHistoryTask::getGlassId).collect(Collectors.toList()); |
| | | temperingGlassList = unFinishTemperingGlassInfoList.stream().filter(e -> !taskGlassList.contains(e.getGlassId())).collect(Collectors.toList()); |
| | | } |
| | | if (CollectionUtil.isNotEmpty(temperingGlassList)) { |
| | | log.info("有正在出片的钢化任务"); |
| | | computeOutGlassInfo(temperingGlassList, "big_storage_cage_out_one_task", temperingOutTargetPosition, Const.GLASS_STATE_OUT_ING, Const.BIG_STORAGE_BEFORE_OUT); |
| | | Date endDate = new Date(); |
| | | log.info("大理片笼出片任务结束时间:{},共耗时:{}ms,结束扫码任务", endDate, endDate.getTime() - startDate.getTime()); |
| | | return; |
| | | } |
| | | } |
| | | //钢化优先:获取理片笼 玻璃小片 破损表 数量 判断笼内版图是否到齐 |
| | | List<TemperingLayoutDTO> temperingLayoutDTOList = bigStorageCageDetailsService.temperingIsAll(); |
| | | if (CollectionUtils.isNotEmpty(temperingLayoutDTOList)) { |
| | | if (CollectionUtil.isNotEmpty(temperingLayoutDTOList)) { |
| | | //玻璃到齐包括已出片的 |
| | | //到齐,将玻璃小片数据存入钢化小片表,逻辑生成出片任务 结束 |
| | | for (TemperingLayoutDTO item : temperingLayoutDTOList) { |
| | | // if (item.getEngineerId().equals(redisUtil.getCacheObject("temperingengineerId"))) { |
| | | List<TemperingGlass> temperingGlassInfos = glassInfoService.selectJoinList(TemperingGlass.class, JoinWrappers.lambda(GlassInfo.class) |
| | | List<TemperingGlassInfo> temperingGlassInfos = glassInfoService.selectJoinList(TemperingGlassInfo.class, JoinWrappers.lambda(GlassInfo.class) |
| | | .selectAll(GlassInfo.class) |
| | | .select("-1 as state") |
| | | .selectAs(BigStorageCageDetails::getSlot, TemperingGlassInfo::getSlot) |
| | |
| | | .eq(GlassInfo::getTemperingLayoutId, item.getTemperingLayoutId()) |
| | | .eq(GlassInfo::getEngineerId, item.getEngineerId()) |
| | | .orderBy(Boolean.TRUE, sequenceOrder, GlassInfo::getTemperingFeedSequence)); |
| | | if (CollectionUtils.isNotEmpty(temperingGlassInfos)) { |
| | | temperingGlassService.saveBatch(temperingGlassInfos); |
| | | computeOutGlassInfo(temperingGlassInfos, "big_storage_cage_out_one_task", Const.TEMPERING_OUT_TARGET_POSITION, Const.GLASS_STATE_OUT_ING, Const.BIG_STORAGE_BEFORE_OUT); |
| | | if (CollectionUtil.isNotEmpty(temperingGlassInfos)) { |
| | | temperingGlassInfoService.saveBatch(temperingGlassInfos); |
| | | computeOutGlassInfo(temperingGlassInfos, "big_storage_cage_out_one_task", temperingOutTargetPosition, Const.GLASS_STATE_OUT_ING, Const.BIG_STORAGE_BEFORE_OUT); |
| | | Date endDate = new Date(); |
| | | log.info("大理片笼出片任务结束时间:{},共耗时:{}ms,结束扫码任务", endDate, endDate.getTime() - startDate.getTime()); |
| | | return; |
| | |
| | | .eq(BigStorageCageDetails::getState, Const.GLASS_STATE_ARTIFICIAL) |
| | | .orderByAsc(BigStorageCageDetails::getSlot) |
| | | .orderByAsc(BigStorageCageDetails::getId)); |
| | | if (CollectionUtils.isNotEmpty(artificialList)) { |
| | | computeOutGlassInfo(artificialList, "big_storage_cage_out_one_task", Const.ARTIFICIAL_OUT_TARGET_POSITION, Const.GLASS_STATE_OUT_ING, Const.BIG_STORAGE_BEFORE_OUT); |
| | | if (CollectionUtil.isNotEmpty(artificialList)) { |
| | | computeOutGlassInfo(artificialList, "big_storage_cage_out_one_task", artificialOutTargetPosition, Const.GLASS_STATE_OUT_ING, Const.BIG_STORAGE_BEFORE_OUT); |
| | | Date endDate = new Date(); |
| | | log.info("大理片笼出片任务结束时间:{},共耗时:{}ms,结束扫码任务", endDate, endDate.getTime() - startDate.getTime()); |
| | | return; |
| | | } |
| | | //是否存在需要内部调度的格子:执行内部调度任务 |
| | | List<TemperingLayoutDTO> temperingOccupySlotList = bigStorageCageDetailsService.queryTemperingOccupySlot(); |
| | | if (CollectionUtils.isNotEmpty(temperingOccupySlotList)) { |
| | | if (CollectionUtil.isNotEmpty(temperingOccupySlotList)) { |
| | | loop: |
| | | for (TemperingLayoutDTO temperingOccupySlot : temperingOccupySlotList) { |
| | | List<SlotSequenceDTO> slotSequenceList = bigStorageCageDetailsService.queryGlassMaxAndMin(temperingOccupySlot.getEngineerId(), temperingOccupySlot.getTemperingLayoutId()); |
| | |
| | | int totalCount = first.getGlassCount() + second.getGlassCount(); |
| | | if (totalCount <= 6 && first.getMinSequence() == second.getMaxSequence() + 1 |
| | | && second.getRemainWidth() > slotWidth && slotWidth >= 0) { |
| | | |
| | | List<BigStorageCageDetails> list = bigStorageCageDetailsService.list(new LambdaQueryWrapper<BigStorageCageDetails>() |
| | | .eq(BigStorageCageDetails::getSlot, first.getSlot()).eq(BigStorageCageDetails::getState, Const.GLASS_STATE_IN) |
| | | .orderBy(Boolean.TRUE, sequenceOrder, BigStorageCageDetails::getTemperingFeedSequence)); |
| | | if (CollectionUtils.isNotEmpty(list)) { |
| | | if (CollectionUtil.isNotEmpty(list)) { |
| | | computeOutGlassInfo(list, "big_storage_cage_out_one_task", second.getSlot(), Const.GLASS_STATE_SCHEDULE_ING, Const.BIG_STORAGE_BEFORE_DISPATCH); |
| | | } |
| | | updateSlotRemainBySlots(Arrays.asList(second.getSlot())); |
| | | //使用Arrays.asList() 使用removeAll报错,改为正常使用List |
| | | List<Integer> slotList = new ArrayList<>(); |
| | | slotList.add(second.getSlot()); |
| | | updateSlotRemainBySlots(slotList); |
| | | break loop; |
| | | } |
| | | } |
| | |
| | | return; |
| | | } |
| | | |
| | | @Scheduled(fixedDelay = 1000) |
| | | // @Scheduled(fixedDelay = 1000) |
| | | public void finishInBigStorageTask() throws Exception { |
| | | ReadWriteEntity inkageEntity = miloService.readFromOpcUa("DLP1A.DLP1A.mesControl"); |
| | | if (true != Boolean.parseBoolean(inkageEntity.getValue() + "")) { |
| | |
| | | } |
| | | //获取进片任务表 |
| | | List<BigStorageCageTask> inTaskList = bigStorageCageTaskService.queryTaskMessage("big_storage_cage_in_one_task"); |
| | | if (CollectionUtils.isEmpty(inTaskList)) { |
| | | if (CollectionUtil.isEmpty(inTaskList)) { |
| | | log.info("当前大车无进片玻璃,结束完成进片任务"); |
| | | return; |
| | | } |
| | | List<BigStorageCageTask> unFinishTaskList = inTaskList.stream().filter(e -> e.getTaskState() <= 1 || e.getStartSlot() == 0).collect(Collectors.toList()); |
| | | if (CollectionUtils.isNotEmpty(unFinishTaskList)) { |
| | | if (CollectionUtil.isNotEmpty(unFinishTaskList)) { |
| | | log.info("存在未完成的玻璃信息,玻璃:{}", unFinishTaskList); |
| | | return; |
| | | } |
| | |
| | | miloService.writeToOpcWord(generateReadWriteEntity("DLP1A.DLP1A.MesReply", 0)); |
| | | } |
| | | |
| | | // @Scheduled(fixedDelay = 1000) |
| | | // @Scheduled(fixedDelay = 1000) |
| | | public void finishOutBigStorageTask() throws Exception { |
| | | ReadWriteEntity inkageEntity = miloService.readFromOpcUa("DLP1B.DLP1B.mesControl"); |
| | | if (true != Boolean.parseBoolean(inkageEntity.getValue() + "")) { |
| | |
| | | } |
| | | //获取进片任务表 |
| | | List<BigStorageCageTask> outTaskList = bigStorageCageTaskService.queryTaskMessage("big_storage_cage_out_one_task"); |
| | | if (CollectionUtils.isEmpty(outTaskList)) { |
| | | if (CollectionUtil.isEmpty(outTaskList)) { |
| | | log.info("当前大车无进片玻璃,结束完成进片任务"); |
| | | return; |
| | | } |
| | | List<BigStorageCageTask> unFinishTaskList = outTaskList.stream().filter(e -> e.getTaskState() <= 1 || e.getStartSlot() == 0).collect(Collectors.toList()); |
| | | if (CollectionUtils.isNotEmpty(unFinishTaskList)) { |
| | | if (CollectionUtil.isNotEmpty(unFinishTaskList)) { |
| | | log.info("存在未完成的玻璃信息,玻璃:{}", unFinishTaskList); |
| | | return; |
| | | } |
| | |
| | | .set(BigStorageCageHistoryTask::getTaskState, item.getTaskState()) |
| | | .eq(BigStorageCageHistoryTask::getTaskType, taskType) |
| | | .eq(BigStorageCageHistoryTask::getGlassId, item.getGlassId())); |
| | | //更新钢化小片表 |
| | | Integer taskState = item.getTaskState(); |
| | | if (taskState == 2) { |
| | | temperingGlassInfoService.update(new LambdaUpdateWrapper<TemperingGlassInfo>() |
| | | .set(TemperingGlassInfo::getState, Const.TEMPERING_OUT).eq(TemperingGlassInfo::getGlassId, item.getGlassId())); |
| | | } else if (taskState == 3) { |
| | | // temperingGlassInfoService.remove(new LambdaQueryWrapper<TemperingGlassInfo>().eq(TemperingGlassInfo::getGlassId, item.getGlassId())); |
| | | temperingGlassInfoService.update(new LambdaUpdateWrapper<TemperingGlassInfo>() |
| | | .set(TemperingGlassInfo::getState, Const.TEMPERING_DAMAGE |
| | | ).eq(TemperingGlassInfo::getGlassId, item.getGlassId())); |
| | | |
| | | } else { |
| | | // 空执行 |
| | | } |
| | | } |
| | | // 重置任务表数据 |
| | | bigStorageCageTaskService.updateOutTaskMessage("big_storage_cage_out_one_task"); |
| | |
| | | bigStorageCageTaskList.add(new BigStorageCageTask(e.getGlassId(), e.getSlot(), targetSlot, |
| | | 0)); |
| | | } |
| | | Assert.isFalse(CollectionUtils.isEmpty(bigStorageCageTaskList), "未获取出片数据,结束出片任务"); |
| | | Assert.isFalse(CollectionUtil.isEmpty(bigStorageCageTaskList), "未获取出片数据,结束出片任务"); |
| | | log.info("获取出片任务数据{}条,执行保存", bigStorageCageTaskList.size()); |
| | | List<String> glassIds = bigStorageCageTaskList.stream().map(BigStorageCageTask::getGlassId).collect(Collectors.toList()); |
| | | int glassCount = bigStorageCageTaskList.size(); |
| | |
| | | .in(BigStorageCageDetails::getSlot, slotList).in(BigStorageCageDetails::getState, Const.GLASS_STATE_IN_ALL)); |
| | | Map<Integer, Double> slotRemainMap = new HashMap<>(); |
| | | //是否存在有格子非空的玻璃 |
| | | if (CollectionUtils.isNotEmpty(inSlotGlassList)) { |
| | | if (CollectionUtil.isNotEmpty(inSlotGlassList)) { |
| | | //存在 将格子内的玻璃分别进行更新 |
| | | slotRemainMap = inSlotGlassList.stream() |
| | | .collect(Collectors.groupingBy(BigStorageCageDetails::getSlot, Collectors.summingDouble(item -> Math.max(item.getWidth(), item.getHeight()) + glassGap))); |
| | |
| | | //过滤不存在玻璃的格子 将宽度重置为原始宽度5000 |
| | | Set<Integer> remainSlotList = slotRemainMap.keySet(); |
| | | slotList.removeAll(remainSlotList); |
| | | if (CollectionUtils.isNotEmpty(slotList)) { |
| | | if (CollectionUtil.isNotEmpty(slotList)) { |
| | | bigStorageCageService.update(new LambdaUpdateWrapper<BigStorageCage>().set(BigStorageCage::getRemainWidth, slotWidth) |
| | | .in(BigStorageCage::getSlot, slotList)); |
| | | } |