From c377d90fe2a01c2118f6c69c3c177f75be7c318b Mon Sep 17 00:00:00 2001 From: wangfei <3597712270@qq.com> Date: 星期五, 29 十一月 2024 15:20:51 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- hangzhoumesParent/moduleService/TemperingGlassModule/src/main/java/com/mes/job/TemperingTask.java | 94 +++++++++++++++++++++++++++++++++++----------- 1 files changed, 71 insertions(+), 23 deletions(-) diff --git a/hangzhoumesParent/moduleService/TemperingGlassModule/src/main/java/com/mes/job/TemperingTask.java b/hangzhoumesParent/moduleService/TemperingGlassModule/src/main/java/com/mes/job/TemperingTask.java index ac92054..6330ac4 100644 --- a/hangzhoumesParent/moduleService/TemperingGlassModule/src/main/java/com/mes/job/TemperingTask.java +++ b/hangzhoumesParent/moduleService/TemperingGlassModule/src/main/java/com/mes/job/TemperingTask.java @@ -8,15 +8,21 @@ import com.mes.damage.entity.Damage; import com.mes.damage.service.DamageService; import com.mes.device.PlcParameterObject; +import com.mes.sysdict.entity.SysDictData; +import com.mes.sysdict.service.SysDictDataService; import com.mes.temperingglass.entity.TemperingGlassInfo; import com.mes.temperingglass.service.TemperingGlassInfoService; import com.mes.temperingrecord.entity.TemperingRecord; import com.mes.temperingrecord.service.TemperingRecordService; +import com.mes.tools.S7control; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; 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.Comparator; import java.util.Date; import java.util.List; import java.util.stream.Collectors; @@ -31,7 +37,7 @@ public class TemperingTask { @Autowired - private TemperingRecordService temporalRecordService; + private TemperingRecordService temperingRecordService; @Autowired private TemperingGlassInfoService temporaryGlassInfoService; @@ -39,53 +45,95 @@ @Autowired private DamageService damageService; + @Autowired + private SysDictDataService sysDictDataService; + private static final String ALONE_STATE = "0"; + @Value("${mes.width}") + private Integer temperingWidth; + @Value("${mes.height}") + private Integer temperingHeight; @Scheduled(fixedDelay = 1000) public void temperingGlassBefore() { Date startDate = new Date(); log.info("鏈浠诲姟寮�濮嬫墽琛屾椂闂达細{}", startDate); PlcParameterObject plcParameterObject = S7object.getinstance().PlcMesObject; + S7control plcControl = S7object.getinstance().plccontrol; String state = plcParameterObject.getPlcParameter("state").getValue(); // 褰撳墠杩炵嚎鐘舵�佷负 if (ALONE_STATE.equals(state)) { - log.info("褰撳墠閽㈠寲鐐夎繛绾挎ā寮忎负锛歿},涓嶆墽琛岃浠诲姟", state); + log.info("褰撳墠閽㈠寲鐐夎繛绾挎ā寮忎负锛歿}锛�(0锛氭墜鍔紱1锛氳繛绾�),涓嶆墽琛岃浠诲姟", state); return; } //灏嗙‘璁ゅ瓧缃负0 - S7object.getinstance().plccontrol.writeWord(plcParameterObject.getPlcParameter("confirmationWord").getAddress(), 0); - - //todo:鑾峰彇閽㈠寲鐗堝浘涓姸鎬佷负2鐨勶紙杩涚倝瀹屾垚鐨勭幓鐠冧俊鎭級 涓斾笉瀛樺湪閽㈠寲璁板綍琛ㄥ唴鐨� - List<Object> temperRecordIdListObj = temporalRecordService.listObjs(new QueryWrapper<TemperingRecord>().select("distinct tempering_layout_id")); - - List<String> temperRecordIdList = temperRecordIdListObj.stream().map(String::valueOf).collect(Collectors.toList()); - if (CollectionUtils.isEmpty(temperRecordIdList)) { + plcControl.writeWord(plcParameterObject.getPlcParameter("confirmationWord").getAddress(), 0); + //鍙兘鏈夊嚑鐐夌幓鐠冨悓鏃跺湪閽紝闇�瑕佽幏鍙栭挗鍖栧皬鐗囪〃涓殑鏁版嵁淇℃伅鐘舵�佷负2锛堟棆杞彴鐜荤拑宸查�佸嚭鏈挗鍖栵紝姝e湪閽㈠寲锛� + List<TemperingGlassInfo> temperingGlassInfoList = temporaryGlassInfoService.list( + new LambdaQueryWrapper<TemperingGlassInfo>() + .inSql(TemperingGlassInfo::getTemperingLayoutId, "select distinct tempering_layout_id from tempering_glass_info where state=1") + .lt(TemperingGlassInfo::getState, Const.TEMPERING_START) + ); + if (CollectionUtils.isEmpty(temperingGlassInfoList)) { log.info("褰撳墠绯荤粺娌℃湁闇�瑕侀挗鍖栫殑鐜荤拑淇℃伅"); return; } - List<TemperingGlassInfo> list = temporaryGlassInfoService.list(new LambdaQueryWrapper<TemperingGlassInfo>() - .eq(TemperingGlassInfo::getState, Const.TEMPERING_START).notIn(TemperingGlassInfo::getTemperingLayoutId, temperRecordIdList)); - if (CollectionUtils.isEmpty(list)) { - log.info("褰撳墠绯荤粺娌℃湁闇�瑕侀挗鍖栫殑鐜荤拑淇℃伅"); + TemperingGlassInfo minGlassInfo = temperingGlassInfoList.stream().min(Comparator.comparingLong(TemperingGlassInfo::getState)).get(); + if (minGlassInfo.getState() < Const.TEMPERING_DROP) { + log.info("褰撳墠鐐夌幓鐠冩湭鍒伴綈锛岀◢鍚庡湪鎵ц"); return; } - List<Integer> temperingLayoutIdList = list.stream().map(TemperingGlassInfo::getTemperingLayoutId).distinct().collect(Collectors.toList()); - if (CollectionUtils.isNotEmpty(temperRecordIdList)) { - temperingLayoutIdList.removeAll(temperRecordIdList); + //鎷垮埌宸ョ▼id鍙婄倝鍙� + TemperingGlassInfo maxGlassInfo = temperingGlassInfoList.stream().max(Comparator.comparingLong(TemperingGlassInfo::getId)).get(); + //灏嗘鍦ㄩ挗鍖栫殑鐐夊彿杩囨护鎺夛紝浠呰幏鍙栧緟閽㈠寲鐨勭幓鐠�:鍒ゆ柇寰呴挗鐨勭幓鐠冩槸鍚﹀凡鍙戦�佸鎺ユ暟鎹� + List<TemperingRecord> temperingRecordList = temperingRecordService.list(new LambdaQueryWrapper<TemperingRecord>().eq(TemperingRecord::getEngineerId, maxGlassInfo.getEngineerId()) + .eq(TemperingRecord::getTemperingLayoutId, maxGlassInfo.getTemperingLayoutId())); + if (CollectionUtils.isNotEmpty(temperingRecordList)) { + log.info("娌℃湁寰呴挗鍖栫殑浠诲姟锛岀粨鏉�"); + return; } - if (CollectionUtils.isEmpty(temperingLayoutIdList)) { - log.info("褰撳墠鐜荤拑鏈夋鍦ㄩ挗鍖栫殑浠诲姟"); - } -// 鑾峰彇閽㈠寲涓嬬墖琛ㄧ姸鎬佷负2鐨勭幓鐠冧俊鎭� + //鑾峰彇寰呴挗鍖栫殑鎵�鏈夌幓鐠冧俊鎭� + List<TemperingGlassInfo> temperingGlassList = temperingGlassInfoList.stream() + .filter(e -> e.getEngineerId().equals(maxGlassInfo.getEngineerId()) + && e.getTemperingLayoutId().equals(maxGlassInfo.getTemperingLayoutId())) + .sorted(Comparator.comparing(TemperingGlassInfo::getTemperingFeedSequence)).collect(Collectors.toList()); + //鎸夌収鑶滅郴鑾峰彇鐜荤拑鏉愯川 + SysDictData glassTypeSysDictData = sysDictDataService.getOne(new QueryWrapper<SysDictData>() + .eq(StringUtils.isNotBlank(temperingGlassList.get(0).getFilmsid()), "dict_label", temperingGlassList.get(0).getFilmsid())); + double sumArea = temperingGlassList.stream().mapToDouble(e -> e.getWidth() * e.getHeight()).sum(); + double maxArea = temperingGlassList.stream().mapToDouble(e -> e.getWidth() * e.getHeight()).max().orElse(0.0); + double minArea = temperingGlassList.stream().mapToDouble(e -> e.getWidth() * e.getHeight()).min().orElse(0.0); + double areaDifference = (10000 * (maxArea - minArea) / maxArea); + double loadingRate = (int) (10000 * sumArea / (temperingHeight * temperingWidth)); + TemperingRecord temperingRecord = new TemperingRecord(); + temperingRecord.setEngineerId(maxGlassInfo.getEngineerId()); + temperingRecord.setTemperingLayoutId(maxGlassInfo.getTemperingLayoutId()); + temperingRecord.setGlassType(Integer.parseInt(glassTypeSysDictData.getDictTypeValue())); + temperingRecord.setTemperingType(1);//鍏ㄩ挗 + temperingRecord.setThickness(temperingGlassList.get(0).getThickness()); + temperingRecord.setAreaDifference(areaDifference); + temperingRecord.setLoadingRate(loadingRate); + temperingRecord.setState(Const.GLASS_STATE_NEW); + //濡傛灉鍑虹幇鍚屼竴鐐夐噸璇昏澶勭悊锛屼富閿洿鎺ュ紓甯稿鐞嗭紝涓嶄細鍙戠粰plc閽㈠寲淇℃伅 + temperingRecordService.save(temperingRecord); +// 鍚憄lc鍙戦�侀挗鍖栦俊鎭� + plcControl.writeWord(plcParameterObject.getPlcParameter("temperingLayoutId").getAddress(), maxGlassInfo.getTemperingLayoutId()); + plcControl.writeWord(plcParameterObject.getPlcParameter("filmsid").getAddress(), Integer.parseInt(glassTypeSysDictData.getDictTypeValue())); + plcControl.writeWord(plcParameterObject.getPlcParameter("temperingType").getAddress(), 1); + plcControl.writeWord(plcParameterObject.getPlcParameter("thickness").getAddress(), (int) (temperingGlassList.get(0).getThickness() * 10)); + plcControl.writeWord(plcParameterObject.getPlcParameter("areaDifference").getAddress(), (int) areaDifference); + plcControl.writeWord(plcParameterObject.getPlcParameter("loadingRate").getAddress(), (int) loadingRate); //瀹屾垚浠诲姟灏嗙‘璁ゅ瓧缃负1 - S7object.getinstance().plccontrol.writeWord(plcParameterObject.getPlcParameter("confirmationWord").getAddress(), 1); + plcControl.writeWord(plcParameterObject.getPlcParameter("confirmationWord").getAddress(), 1); + Date endDate = new Date(); + log.info("鏈浠诲姟缁撴潫鏃堕棿锛歿}锛屽叡鑰楁椂锛歿}ms", endDate, endDate.getTime() - startDate.getTime()); } @Scheduled(fixedDelay = 1000) public void temperingGlassAfter() { - + //鏆備笉澶勭悊 } @Scheduled(fixedDelay = 1000) @@ -104,7 +152,7 @@ damage.setLine(Const.TEMPERING_OUT_TARGET_POSITION); damage.setWorkingProcedure("閽㈠寲"); damage.setRemark("閽㈠寲"); - damage.setStatus(0); + damage.setStatus(1); damage.setType(e.getState()); return damage; }).collect(Collectors.toList()); -- Gitblit v1.8.0