From c7093edbf1fb3c91107c457ea13935305e1a9458 Mon Sep 17 00:00:00 2001 From: 严智鑫 <test> Date: 星期五, 05 七月 2024 14:58:50 +0800 Subject: [PATCH] Merge branch 'master' of http://10.153.19.25:10101/r/HangZhouMes --- hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/job/DownLoadCacheGlassTask.java | 520 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 520 insertions(+), 0 deletions(-) diff --git a/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/job/DownLoadCacheGlassTask.java b/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/job/DownLoadCacheGlassTask.java new file mode 100644 index 0000000..e9503b4 --- /dev/null +++ b/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/job/DownLoadCacheGlassTask.java @@ -0,0 +1,520 @@ +package com.mes.job; + +import cn.hutool.core.lang.Assert; +import cn.smallbun.screw.core.util.CollectionUtils; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.mes.common.S7object; +import com.mes.common.config.Const; +import com.mes.device.PlcParameterObject; +import com.mes.downglassinfo.entity.DownGlassInfo; +import com.mes.downglassinfo.entity.DownGlassTask; +import com.mes.downglassinfo.service.DownGlassInfoService; +import com.mes.downglassinfo.service.DownGlassTaskService; +import com.mes.downstorage.entity.DownStorageCage; +import com.mes.downstorage.entity.DownStorageCageDetails; +import com.mes.downstorage.service.DownStorageCageDetailsService; +import com.mes.downstorage.service.DownStorageCageService; +import com.mes.downworkstation.entity.DownWorkstation; +import com.mes.downworkstation.entity.dto.DownGlassInfoDTO; +import com.mes.downworkstation.service.DownWorkstationService; +import com.mes.glassinfo.entity.GlassInfo; +import com.mes.glassinfo.service.GlassInfoService; +import com.mes.tools.S7control; +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 java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * @Author : zhoush + * @Date: 2024/5/8 8:17 + * @Description: + */ +@Component +@Slf4j +public class DownLoadCacheGlassTask { + + @Autowired + DownGlassTaskService downGlassTaskService; + @Autowired + GlassInfoService glassInfoService; + @Autowired + DownStorageCageDetailsService downStorageCageDetailsService; + @Autowired + DownStorageCageService downStorageCageService; + @Autowired + DownWorkstationService downWorkstationService; + @Autowired + DownGlassInfoService downGlassInfoService; + + @Value("${mes.threshold}") + private Integer threshold; + + @Value("${mes.throughWidth}") + private Integer throughWidth; + + @Value("${mes.throughHeight}") + private Integer throughHeight; + + @Value("${mes.maxWidth}") + private Integer maxWidth; + + @Value("${mes.maxHeight}") + private Integer maxHeight; + + + @Scheduled(fixedDelay = 1000) + public void plcHomeEdgTask() { + PlcParameterObject plcParameterObject = S7object.getinstance().PlcMesObject; + String requestWord = plcParameterObject.getPlcParameter("requestWord").getValue(); + String glassIdeValue = plcParameterObject.getPlcParameter("requestID").getValue(); + //A08 A09琛ㄧず绾胯矾鐩稿悓 鍙仛绛変环 鏃犳暟鎹浆int寮傚父 + String out06Glassstate = plcParameterObject.getPlcParameter("glassStatus06").getValue(); + String out08Glassstate = plcParameterObject.getPlcParameter("glassStatus08").getValue(); + String out11Glassstate = plcParameterObject.getPlcParameter("glassStatus11").getValue(); + String out13Glassstate = plcParameterObject.getPlcParameter("glassStatus13").getValue(); + String confirmationWrodValue = plcParameterObject.getPlcParameter("confirmationWord").getValue(); + String confirmationWrodAddress = plcParameterObject.getPlcParameter("confirmationWord").getAddress(); + String currentSlot = plcParameterObject.getPlcParameter("currentCell").getValue(); + + log.info("1銆佽幏鍙栧埌鐨勮姹傚瓧涓猴細{}锛岃幏鍙栧埌鐨勬壂鎻廔D涓猴細{}锛岃幏鍙栧埌鐨勭‘璁ゅ瓧涓猴細{}锛岃幏鍙栧埌鐨勫嚭鐗囩姸鎬佸垎鍒负锛歡06:{}銆乬08:{}銆乬11:{}銆乬13:{},褰撳墠鏍煎瓙鍙蜂负锛歿}", + requestWord, glassIdeValue, confirmationWrodValue, out06Glassstate, out08Glassstate, out11Glassstate, out13Glassstate, currentSlot); + + if ("0".equals(requestWord)) { + if ("0".equals(confirmationWrodValue)) { + log.info("2銆佽幏鍙栧埌鐨勮姹傚瓧涓�0锛屼笖纭瀛椾负0锛屼笉鎵ц浠诲姟"); + return; + } + log.info("2銆佽幏鍙栧埌鐨勮姹傚瓧涓�0锛屽皢纭瀛楁敼涓�0"); + S7object.getinstance().plccontrol.writeWord(confirmationWrodAddress, 0); + return; + } + if (!"0".equals(confirmationWrodValue)) { + log.info("2銆佽幏鍙栧埌鐨勮姹傚瓧涓嶄负0锛屽皢纭瀛椾笉涓�0锛岀洿鎺ョ粨鏉�"); + return; + } + if ("1".equals(requestWord)) { + log.info("2銆佽繘鐗囪姹傦紝涓旂‘璁ゅ瓧涓�0锛屾墽琛岃繘鐗囦换鍔�"); + inTo(glassIdeValue, requestWord, currentSlot); + } else if ("2".equals(requestWord)) { + //09绌洪棽 锛�1 10绌洪棽 锛�2 閮界┖闂诧細3 鍏朵粬0 + log.info("2銆佸嚭鐗囪姹傦紝涓旂‘璁ゅ瓧涓�0锛屾墽琛岃繘鐗囦换鍔�"); + outTo(out06Glassstate, out08Glassstate, out11Glassstate, out13Glassstate, glassIdeValue, currentSlot); + } else if ("3".equals(requestWord)) { + log.info("2銆佽繘鐗囧拰鍑虹墖閮界┖闂诧紝鎵ц鍑虹墖浠诲姟"); + //鍔犵瀛愰噷闈㈡槸鍚︽湁鐜荤拑锛屾湁鍏堝嚭锛屾棤鐜荤拑鍏堣繘 + boolean outFlase = outTo(out06Glassstate, out08Glassstate, out11Glassstate, out13Glassstate, glassIdeValue, currentSlot); + log.info("鍑虹墖浠诲姟鏄惁瀹屾垚锛歿},澶辫触涓旂幓鐠僫d:{}涓嶄负绌哄垯鎵ц杩涚墖浠诲姟", outFlase, glassIdeValue); + if (!outFlase && StringUtils.isNotBlank(glassIdeValue)) { + inTo(glassIdeValue, requestWord, currentSlot); + } + } + } + + public void inTo(String glassId, String requestWord, String currentSlot) { + log.info("1銆佹寜鐓х幓鐠僫d:{}鑾峰彇鐜荤拑灏忕墖淇℃伅,褰撳墠鏍煎瓙涓�:{}", glassId, currentSlot); + //娣诲姞杩涚墖浠诲姟 鏌ユ壘绌烘牸 + DownStorageCage nearestEmpty = downStorageCageService.selectCacheEmpty(Integer.parseInt(currentSlot), Boolean.FALSE); + Assert.isTrue(null != nearestEmpty, "鏍煎瓙宸叉弧,鏃犳硶鎵ц杩涚墖鎿嶄綔"); + log.info("2銆佹煡璇㈠崸寮忕悊鐗囩閲岄潰鐨勭┖鏍�:{}", nearestEmpty); + GlassInfo glassInfo = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>().eq(GlassInfo::getGlassId, glassId)); + Assert.isFalse(null == glassInfo, "鐜荤拑淇℃伅涓嶅瓨鍦�"); + if ("1".equals(requestWord) && (glassInfo.getWidth() > throughWidth || glassInfo.getHeight() > throughHeight)) { + log.info("鐜荤拑褰撳墠灏哄瀹斤細{}锛岄珮锛歿}鍙兘鐩撮�氾紝褰撳墠杩涚墖浠诲姟闇�绛夊緟", glassInfo.getWidth(), glassInfo.getHeight()); + return; + } + Boolean checkFlag = Boolean.FALSE; + //鐜荤拑灏哄鏄惁璧颁汉宸ヤ笅鐗� + if (glassInfo.getWidth() > maxWidth || glassInfo.getHeight() > maxHeight) { + log.info("璇ョ幓鐠冨昂瀵歌蛋浜哄伐涓嬬墖,鐩存帴杩涚墖"); + } else { + log.info("璇ョ幓鐠冨昂瀵搁潪浜哄伐涓嬬墖"); + //鑾峰彇璇ョ幓鐠冪殑娴佺▼鍗℃槸鍚﹀凡缁戝畾鏋跺瓙 + DownWorkstation one = downWorkstationService.getOne(new LambdaQueryWrapper<DownWorkstation>() + .eq(DownWorkstation::getLayer, glassInfo.getLayer()) + .eq(DownWorkstation::getFlowCardId, glassInfo.getFlowCardId())); + Boolean isBind = Boolean.FALSE; + if (null != one) { + log.info("璇ユ祦绋嬪崱宸茬粦瀹氭灦瀛�"); + isBind = Boolean.TRUE; + checkFlag = multilayerCheck(glassInfo, isBind); + } + if (!checkFlag && !isBind) { + log.info("璇ョ幓鐠冪殑娴佺▼鍗℃湭缁戝畾鏋跺瓙锛岃幏鍙栨槸鍚︽湁绌烘灦瀛�"); + List<DownWorkstation> list = downWorkstationService.list(new LambdaQueryWrapper<DownWorkstation>() + .isNull(DownWorkstation::getFlowCardId)); + 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())); + checkFlag = Boolean.TRUE; + } + } + if (!checkFlag) { + log.info("鏃犵┖鏋跺瓙,鑾峰彇宸茬粦瀹氭灦瀛愮殑娴佺▼鍗′俊鎭�,鏌ョ湅鐜荤拑淇℃伅鏄惁鍙瀵硅皟"); + List<DownGlassInfoDTO> downGlassInfoDTOList = downGlassInfoService.queryWorkStationIsIn(Boolean.FALSE); + log.info("鑾峰彇鏋跺瓙涓婂凡缁戝畾娴佺▼鍗¤惤鏋剁殑鏁伴噺鍙婃湭钀芥灦鐨勭幓鐠冩暟鎹細{}", downGlassInfoDTOList); + if (CollectionUtils.isEmpty(downGlassInfoDTOList)) { + log.info("宸茬粦瀹氭祦绋嬪崱鍧囨棤鏈惤鏋剁幓鐠冿紝璇峰強鏃跺鐞嗘灦瀛愪笂鐨勭幓鐠冿紝娓呴櫎娴佺▼鍗�,鎵ц杩涚墖浠诲姟"); + } else { + //鏇挎崲鐜荤拑淇℃伅 + 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; + } + } + } + } + } + } + } + //灏嗕换鍔℃彃鍏ョ悊鐗囩璇︽儏琛� + DownStorageCageDetails downStorageCageDetails = new DownStorageCageDetails(); + BeanUtils.copyProperties(glassInfo, downStorageCageDetails); + 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) { + if ("2".equals(glassStatus06) && "2".equals(glassStatus11) && "2".equals(glassStatus13)) { + log.info("G06銆丟11銆丟13鍒嗗埆涓簕},{}銆亄}闈炶嚜鍔ㄧ姸鎬侊紝鏃犳硶鍑虹墖", glassStatus06, glassStatus11, glassStatus13); + return Boolean.FALSE; + } + + List<DownStorageCageDetails> tempList = downStorageCageDetailsService.list(new LambdaQueryWrapper<DownStorageCageDetails>() + .eq(DownStorageCageDetails::getState, Const.GLASS_STATE_IN)); + //鑾峰彇寰呰繘鐗囩幓鐠� + DownStorageCageDetails cageDetails = new DownStorageCageDetails(); + if (StringUtils.isNotBlank(glassId)) { + GlassInfo glassInfo = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>().eq(GlassInfo::getGlassId, glassId)); + BeanUtils.copyProperties(glassInfo, cageDetails); + //鑾峰彇褰撳墠绗煎瓙绌烘牸淇℃伅 + DownStorageCage empty = downStorageCageService.selectCacheEmpty(Integer.parseInt(currentSlot), Boolean.TRUE); + cageDetails.setSlot(empty.getSlot()); + tempList.add(cageDetails); + } + + log.info("绗煎唴鐜荤拑鐨勬暟鎹湁锛歿}", tempList); + if (CollectionUtils.isEmpty(tempList)) { + log.info("绗煎唴娌℃湁鐜荤拑,鏃犳硶鎵ц鍑虹墖"); + return Boolean.FALSE; + } + Boolean flag08 = "1".equals(out08Glassstate) ? Boolean.TRUE : Boolean.FALSE; + if (!generateTaskByShelf(glassStatus11, flag08, glassStatus13, tempList, cageDetails)) { + return generateTaskByShelf(glassStatus11, !flag08, glassStatus13, tempList, cageDetails); + } + return Boolean.TRUE; + } + + private Boolean multilayerCheck(GlassInfo glassInfo, boolean isBind) { + //鏌ヨ璇ユ祦绋嬪崱鏄惁涓哄灞� + if (glassInfo.getTotalLayer() > 1) { + log.info("鎸夌収娴佺▼鍗¤幏鍙栧綋鍓嶆祦绋嬪崱鍚勫眰宸茶惤鏋舵暟閲�"); + DownGlassInfoDTO downGlassInfoDTO = downGlassInfoService.queryDownGlassMaxLayer(glassInfo.getFlowCardId()); + if (null == downGlassInfoDTO) { + if (isBind) { + return Boolean.TRUE; + } else { + log.info("鏋跺瓙宸茬粡鍗犳弧锛屽灞傜幓鐠冩棤娉曟壘鍒板搴旂殑鏍煎瓙锛岄渶鎵ц鏇挎崲鐜荤拑鐨勬搷浣�"); + return Boolean.FALSE; + } + + } + if (downGlassInfoDTO.getLayer().equals(glassInfo.getLayer())) { + log.info("褰撳墠鐜荤拑鐨勬祦绋嬪湪鏋跺瓙涓婅惤鏋舵渶澶� 鐩存帴杩涚墖"); + return Boolean.TRUE; + } + Integer sequence = downGlassInfoService.queryMaxSequence(glassInfo.getFlowCardId(), glassInfo.getLayer()); + log.info("鑾峰彇褰撳墠鐜荤拑闇�瑕佹斁鐨勬搴忥細绗煎唴鍚屾祦绋� 鍚屽眰鏁扮殑閫氳揪娆″簭+1:{}", sequence); + DownGlassInfo downGlassInfo = downGlassInfoService.getOne(new LambdaQueryWrapper<DownGlassInfo>() + .eq(DownGlassInfo::getFlowCardId, downGlassInfoDTO.getFlowCardId()) + .eq(DownGlassInfo::getLayer, downGlassInfoDTO.getLayer()).eq(DownGlassInfo::getSequence, sequence)); + log.info("鎷垮綋鍓嶇増搴忚幏鍙栫幓鐠冧俊鎭瘂}锛屾寜鐓ф搴忓垽鏂綋鍓嶇幓鐠冩槸鍚﹀昂瀵稿搴旂殑涓婏紙涓庢暟閲忔渶澶氱殑娆″簭姣旇緝锛夈��", downGlassInfo); + if (null != downGlassInfoDTO && downGlassInfo.getWidth() == glassInfo.getWidth() && downGlassInfo.getHeight() == glassInfo.getHeight()) { + log.info("鐩稿悓娆″簭鐜荤拑瀵瑰簲涓婏紝鍙墽琛岃繘鐗囦换鍔�"); + return Boolean.TRUE; + } else { + log.info("鍚屾搴忕幓鐠冨搴斾笉涓婏紝闇�鎵ц鏇挎崲鐜荤拑鐨勬搷浣�"); + return Boolean.FALSE; + } + } else { + log.info("闈炲灞傜幓鐠冿紝鐩存帴杩涚墖"); + return Boolean.TRUE; + } + } + + private Boolean generateTaskByShelf(String glassStatus, Boolean flag08, String glassStatus13, List<DownStorageCageDetails> tempList, DownStorageCageDetails cageDetails) { + //鑾峰彇2涓満姊拌噦鑼冨洿鍐呯殑鏋跺瓙缁戝畾鐨勬祦绋嬪崱淇℃伅 + List<Integer> workList = new ArrayList(); + + if (flag08) { + if (!"2".equals(glassStatus)) { + workList.addAll(Const.G11_WORK_STATION); + } + } else { + if (!"2".equals(glassStatus)) { + workList.addAll(Const.G06_WORK_STATION); + } + } + List<DownStorageCageDetails> list = new ArrayList(); + Boolean isEmptyShelf = Boolean.FALSE; + //瀵圭鍐呯幓鐠冭繘琛岃繃婊わ紝浠呭嚭绗﹀悎閫昏緫鐨勭幓鐠� + if (CollectionUtils.isNotEmpty(workList)) { + List<DownWorkstation> downWorkstationList = downWorkstationService.list(new LambdaQueryWrapper<DownWorkstation>() + .eq(DownWorkstation::getEnableState, 0).in(DownWorkstation::getWorkstationId, workList)); + log.info("鏋跺瓙琚鐢紝鏃犳硶鍑虹墖钀芥灦"); + if (CollectionUtils.isEmpty(downWorkstationList)) { + log.info("绗煎瓙琚鐢紝鏃犳硶璧版満姊拌噦涓嬬墖"); + //璧颁汉宸ヤ笅鐗� + if (!"2".equals(glassStatus13)) { + 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())); + if (CollectionUtils.isEmpty(workstationsIsNotBind)) { + log.info("涓嶅瓨鍦ㄦ湭缁戝畾娴佺▼鍗℃灦瀛�"); + //绛涢�夊嚭瀵瑰簲鏋跺瓙宸茬粦瀹氭祦绋嬪崱鍙笅鐗囩殑鐜荤拑 + list = tempList.stream().filter(item -> listMap.containsKey(item.getFlowCardId() + ":" + item.getLayer())).collect(Collectors.toList()); + } else { + log.info("瀛樺湪鏈粦瀹氭祦绋嬪崱鏋跺瓙锛岀洿鎺ヨ幏鍙栫鍐呮墍鏈夌幓鐠�"); + isEmptyShelf = Boolean.TRUE; + //todo:濡傛灉绂佺敤鏋跺瓙宸茬粦瀹氭祦绋嬪崱锛屽洜涓烘椂闂翠笉纭畾锛岀瀛愬唴鐨勭幓鐠冨彲閲嶆柊缁戝畾鏂版灦瀛� +// list = tempList.stream().filter(item -> !listMap.containsKey(item.getFlowCardId() + ":" + item.getLayer())).collect(Collectors.toList()); + list = tempList; + } + } + } else { + if (flag08 && !"2".equals(glassStatus13)) { + //鐩存帴璧颁汉宸ヤ笅鐗� + list = tempList.stream().filter(item -> item.getWidth() > maxWidth || item.getHeight() > maxHeight).collect(Collectors.toList()); + } + } + if (CollectionUtils.isEmpty(list)) { + log.info("绗煎唴鐜荤拑鏃犳硶鎵ц鍑虹墖"); + return Boolean.FALSE; + } + String tempGlassId = null; + Boolean isBind = Boolean.FALSE; + + for (DownStorageCageDetails item : list) { + if (item.getWidth() > maxWidth || item.getHeight() > maxHeight) { + if (flag08 && !"2".equals(glassStatus13)) { + log.info("鐜荤拑瀹藉害鎴栭珮搴﹁秴鍑洪槇鍊硷紝鎵ц浜哄伐涓嬬墖"); + tempGlassId = item.getGlassId(); + break; + } + } + } + loop: + if (tempGlassId == null) { + //鑾峰彇姝e湪钀芥灦鐨勭粦瀹氭祦绋嬪崱鐨勪俊鎭�(娴佺▼鍗°�佸眰鏁般�佽惤鏋舵暟閲�) + 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)) { + //鏋跺瓙閮芥湭缁戝畾娴佺▼鍗★紝鍑虹鍐呭瓙鏁伴噺鏈�澶氬昂瀵告渶澶х殑鐜荤拑 + DownStorageCageDetails downStorageCageDetails = downStorageCageDetailsService.getGlassInfoMaxCount(); + //缁戝畾娴佺▼鍗★紝鏇存柊鐜荤拑鐘舵�侊紝鐢熸垚鍑虹墖浠诲姟锛� + tempGlassId = downStorageCageDetails.getGlassId(); + isBind = Boolean.TRUE; + break loop; + } + //灏嗙瀛愬唴鐨勭幓鐠冭繘琛岃繃婊わ紝浠呰幏鍙栨棤娉曡惤鏋剁殑娴佺▼鍗$幓鐠� + 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) { + DownStorageCageDetails downStorageCageDetails = downStorageCageDetailsService.getGlassInfoMaxCount(); + //缁戝畾娴佺▼鍗★紝鏇存柊鐜荤拑鐘舵�侊紝鐢熸垚鍑虹墖浠诲姟 + tempGlassId = downStorageCageDetails.getGlassId(); + isBind = Boolean.TRUE; + break loop; + } + } + //灏嗙瀛愬唴鐨勭幓鐠冭繘琛岃繃婊わ紝浠呰幏鍙栧彲钀芥灦鐨勬祦绋嬪崱鐜荤拑 + List<DownStorageCageDetails> downLoadList = list.stream().filter(item -> downGlassFlowList.contains(item.getFlowCardId() + ":" + item.getLayer())).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(downLoadList)) { + //涓嶆墽琛屽嚭鐗囦换鍔★紝绗煎唴娌℃湁鍚堥�傜殑鍑虹墖鐜荤拑 + return Boolean.FALSE; + } + //灏嗙鍐呯幓鐠冪殑娴佺▼鍗�+灞傚彿 鍜岃惤鏋剁殑娴佺▼鍗� 鍘婚噸锛屽緱鍑哄睍绀烘棤娉曡惤鏋剁殑鐜荤拑锛屽垽鏂幓鐠冩暟鏄惁瓒呰繃闃堝�� + //绗煎唴鐜荤拑鏄惁鍙惤鏋�:绗煎唴鏄惁鏈夐渶瑕佷腑绌虹殑 + List<DownStorageCageDetails> multiLayerList = list.stream().filter(item -> item.getTotalLayer() >= 2).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(multiLayerList)) { + for (DownStorageCageDetails item : multiLayerList) { + DownGlassInfoDTO downGlassInfoDTO = downGlassInfoService.queryDownGlassMaxLayer(item.getFlowCardId()); + if (null == downGlassInfoDTO) { +// 鍘嗗彶钀芥灦鐜荤拑鎸夌収鐩稿叧娴佺▼鍗″彇鏁版嵁搴撴湭鎵惧埌鏈�澶氱幓鐠冧俊鎭紝琛ㄦ槑褰撳墠娴佺▼鍗′笅鐨勬湁灞傜殑鐜荤拑鍧囨湭钀芥灦锛岀洿鎺ュ彲鍑哄綋鍓嶇幓鐠� + log.info(""); + isBind = Boolean.FALSE; + tempGlassId = item.getGlassId(); + break loop; + } + if (downGlassInfoDTO.getLayer().equals(downGlassInfoDTO.getLayer())) { + log.info("褰撳墠鐜荤拑鐨勬祦绋嬪湪鏋跺瓙涓婅惤鏋舵渶澶�,鐩存帴鍑虹墖"); + //鏇存柊鐜荤拑鐘舵�侊紝鐢熸垚鍑虹墖浠诲姟 + tempGlassId = item.getGlassId(); + isBind = Boolean.FALSE; + break loop; + } + Integer sequence = downGlassInfoService.queryMaxSequence(item.getFlowCardId(), item.getLayer()); + log.info("鑾峰彇褰撳墠鐜荤拑闇�瑕佹斁鐨勬搴忥細绗煎唴鍚屾祦绋� 鍚屽眰鏁扮殑閫氳揪娆″簭+1:{}", sequence); + DownGlassInfo downGlassInfo = downGlassInfoService.getOne(new LambdaQueryWrapper<DownGlassInfo>() + .eq(DownGlassInfo::getFlowCardId, downGlassInfoDTO.getFlowCardId()) + .eq(DownGlassInfo::getLayer, downGlassInfoDTO.getLayer()).eq(DownGlassInfo::getSequence, sequence)); + if (null != downGlassInfoDTO && downGlassInfo.getWidth() == item.getWidth() && downGlassInfo.getHeight() == item.getHeight()) { + log.info("鐩稿悓娆″簭鐜荤拑瀵瑰簲涓婏紝鍙墽琛岃繘鐗囦换鍔�"); + //鏇存柊鐜荤拑鐘舵�侊紝鐢熸垚鍑虹墖浠诲姟 + tempGlassId = item.getGlassId(); + isBind = Boolean.FALSE; + 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 (CollectionUtils.isNotEmpty(singleLayerMap)) { + //鑾峰彇宸茶惤鏋舵祦绋嬪崱淇℃伅锛屾寜钀芥灦鏁伴噺鎺掑簭 + for (DownGlassInfoDTO e : downGlassInfoDTOList) { + List<DownStorageCageDetails> downStorageCageDetails = singleLayerMap.get(e.getFlowCardId() + e.getLayer()); + if (CollectionUtils.isNotEmpty(downStorageCageDetails)) { + tempGlassId = downStorageCageDetails.get(0).getGlassId(); + isBind = Boolean.FALSE; + break; + } + } + } + } + } + if (tempGlassId == null) { + log.info("娌℃湁鎵惧埌鍙互涓嬬墖鐨勭殑鐜荤拑锛岀粨鏉熶换鍔�"); + return Boolean.FALSE; + } else { + //鎸夌収鍑虹墖鐨勭幓鐠僫d鏇存柊绗煎唴鐨勭幓鐠冪姸鎬佷负宸插嚭鐗� + return generateDownGlassOutTask(tempGlassId, Const.GLASS_CACHE_TYPE_OUT, isBind, cageDetails); + } + } + + public Boolean generateDownGlassOutTask(String glassId, Integer taskType, Boolean isBind, DownStorageCageDetails cageDetails) { + //鎸夌幓鐠僫d鑾峰彇鐜荤拑淇℃伅 + DownStorageCageDetails downStorageCageDetails = null; + if (glassId.equals(cageDetails.getGlassId())) { + downStorageCageDetails = cageDetails; + taskType = 3; + } else { + downStorageCageDetails = downStorageCageDetailsService.getOne(new LambdaQueryWrapper<DownStorageCageDetails>() + .eq(DownStorageCageDetails::getGlassId, glassId)); + } + + Integer endCell = null; + if (isBind) { + //鑾峰彇绌烘灦瀛愪俊鎭紝灏嗙┖鏋跺瓙淇℃伅缁戝畾娴佺▼鍗� + DownWorkstation emptyDownWorkstation = downWorkstationService.getOne(new LambdaQueryWrapper<DownWorkstation>() + .isNull(DownWorkstation::getFlowCardId).orderByDesc(DownWorkstation::getWorkstationId).last("limit 1")); + if (null != emptyDownWorkstation) { + log.info("鑾峰彇鍒扮┖鏋跺瓙淇℃伅锛岀粦瀹氭祦绋嬪崱"); + emptyDownWorkstation.setFlowCardId(downStorageCageDetails.getFlowCardId()); + emptyDownWorkstation.setLayer(downStorageCageDetails.getLayer()); + downWorkstationService.updateById(emptyDownWorkstation); + endCell = emptyDownWorkstation.getWorkstationId(); + } else { + log.info("娌℃湁绌烘灦瀛愪俊鎭紝鏃犳硶缁戝畾娴佺▼鍗�"); + return Boolean.FALSE; + } + } else { + DownWorkstation workstation = downWorkstationService.getOne(new LambdaUpdateWrapper<DownWorkstation>() + .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; + } + //鏇存柊钀芥灦鐜荤拑鏁伴噺 + + //鐢熸垚浠诲姟淇℃伅 + DownGlassInfo downGlassInfo = new DownGlassInfo(); + BeanUtils.copyProperties(downStorageCageDetails, downGlassInfo); + downGlassInfoService.save(downGlassInfo); + //鐢熸垚浠诲姟淇℃伅 + GlassInfo glassInfo = new GlassInfo(); + BeanUtils.copyProperties(downStorageCageDetails, glassInfo); + return initDownGlassTask(glassInfo, downStorageCageDetails.getSlot(), endCell, taskType); + } + + public Boolean initDownGlassTask(GlassInfo glassInfo, Integer startCell, Integer endCell, Integer taskType) { + log.info("鐜荤拑{}鐢熸垚杩涚墖浠诲姟", glassInfo.getGlassId()); + DownGlassTask downGlassTask = new DownGlassTask(); + downGlassTask.setStartCell(startCell); + downGlassTask.setGlassId(glassInfo.getGlassId()); + downGlassTask.setEndCell(endCell); + downGlassTask.setTaskType(taskType + ""); + downGlassTask.setWidth((int) glassInfo.getWidth()); + downGlassTask.setHeight((int) glassInfo.getHeight()); + downGlassTask.setFlowCardId(glassInfo.getFlowCardId()); + downGlassTask.setLayer(glassInfo.getLayer()); + downGlassTask.setTaskStauts(0); + downGlassTask.setCreateTime(new Date()); + downGlassTaskService.save(downGlassTask); + //鍚憄lc鍙戦�佸懡浠� + return sendMessageToPlc((int) glassInfo.getWidth(), (int) glassInfo.getHeight(), (int) glassInfo.getThickness(), + startCell, endCell, 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); + s7control.writeWord(plcMesObject.getPlcParameter("Glass_height").getAddress(), height); + s7control.writeWord(plcMesObject.getPlcParameter("Glass_thickness").getAddress(), thickness); + s7control.writeWord(plcMesObject.getPlcParameter("Start_cell").getAddress(), startCell); + s7control.writeWord(plcMesObject.getPlcParameter("End_cell").getAddress(), endCell); + s7control.writeWord(plcMesObject.getPlcParameter("task_type").getAddress(), taskType); + s7control.writeWord(plcMesObject.getPlcParameter("confirmationWord").getAddress(), 1); + return Boolean.TRUE; + } +} -- Gitblit v1.8.0