From c823892f961b266199731ddd365d2dd4af4bf382 Mon Sep 17 00:00:00 2001 From: zhoushihao <zsh19950802@163.com> Date: 星期二, 03 十二月 2024 08:50:27 +0800 Subject: [PATCH] 1、中空线初步版本,待优化 2、fixbug 钢化后摆片顺序错乱 --- hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/OpcPlcStorageCageTask.java | 129 ++++++++++++++++++++++++++++--------------- 1 files changed, 84 insertions(+), 45 deletions(-) diff --git a/hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/OpcPlcStorageCageTask.java b/hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/OpcPlcStorageCageTask.java index d4c3372..865eb34 100644 --- a/hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/OpcPlcStorageCageTask.java +++ b/hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/OpcPlcStorageCageTask.java @@ -1,17 +1,16 @@ 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; @@ -26,16 +25,14 @@ 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; @@ -51,7 +48,7 @@ @Resource private BigStorageCageDetailsService bigStorageCageDetailsService; @Resource - private TemperingGlassService temperingGlassService; + private TemperingGlassInfoService temperingGlassInfoService; @Resource private DamageService damageService; @Resource @@ -84,8 +81,13 @@ @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() + "")) { @@ -104,11 +106,27 @@ } //鑾峰彇杩涚墖浠诲姟琛� 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("鑾峰彇浠诲姟鐨勭幓鐠僫d锛歿}", 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:鍚憄lc鍙戦�佹姤璀� + 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:鍚憄lc鍙戦�佹姤璀� + 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)); @@ -148,7 +166,7 @@ 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"); @@ -163,36 +181,41 @@ } //鑾峰彇鍑虹墖浠诲姟琛� 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) @@ -201,9 +224,9 @@ .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; @@ -217,15 +240,15 @@ .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()); @@ -236,14 +259,16 @@ 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鎶ラ敊锛屾敼涓烘甯镐娇鐢↙ist + List<Integer> slotList = new ArrayList<>(); + slotList.add(second.getSlot()); + updateSlotRemainBySlots(slotList); break loop; } } @@ -254,7 +279,7 @@ 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() + "")) { @@ -263,12 +288,12 @@ } //鑾峰彇杩涚墖浠诲姟琛� 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; } @@ -312,7 +337,7 @@ 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() + "")) { @@ -321,12 +346,12 @@ } //鑾峰彇杩涚墖浠诲姟琛� 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; } @@ -377,6 +402,20 @@ .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"); @@ -505,7 +544,7 @@ 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(); @@ -545,7 +584,7 @@ .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))); @@ -558,7 +597,7 @@ //杩囨护涓嶅瓨鍦ㄧ幓鐠冪殑鏍煎瓙 灏嗗搴﹂噸缃负鍘熷瀹藉害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)); } -- Gitblit v1.8.0