From 6d5ee2bbf65a6b7bb12a9d84b3aa98c6505d4998 Mon Sep 17 00:00:00 2001 From: wangfei <3597712270@qq.com> Date: 星期二, 13 八月 2024 14:17:50 +0800 Subject: [PATCH] Merge branch 'master' of http://10.153.19.25:10101/r/HangZhouMes --- hangzhoumesParent/moduleService/TemperingGlassModule/src/main/java/com/mes/job/TemperingTask.java | 89 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 88 insertions(+), 1 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 6b27ad0..ac92054 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 @@ -1,29 +1,116 @@ package com.mes.job; -import com.mes.tempering_record.service.TemperingRecordService; +import cn.smallbun.screw.core.util.CollectionUtils; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.mes.common.S7object; +import com.mes.common.config.Const; +import com.mes.damage.entity.Damage; +import com.mes.damage.service.DamageService; +import com.mes.device.PlcParameterObject; +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 lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; /** * @Author : zhoush * @Date: 2024/7/17 12:47 * @Description: */ +@Component +@Slf4j public class TemperingTask { @Autowired private TemperingRecordService temporalRecordService; + @Autowired + private TemperingGlassInfoService temporaryGlassInfoService; + + @Autowired + private DamageService damageService; + + private static final String ALONE_STATE = "0"; + @Scheduled(fixedDelay = 1000) public void temperingGlassBefore() { + Date startDate = new Date(); + log.info("鏈浠诲姟寮�濮嬫墽琛屾椂闂达細{}", startDate); + PlcParameterObject plcParameterObject = S7object.getinstance().PlcMesObject; + String state = plcParameterObject.getPlcParameter("state").getValue(); +// 褰撳墠杩炵嚎鐘舵�佷负 + if (ALONE_STATE.equals(state)) { + log.info("褰撳墠閽㈠寲鐐夎繛绾挎ā寮忎负锛歿},涓嶆墽琛岃浠诲姟", 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)) { + 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("褰撳墠绯荤粺娌℃湁闇�瑕侀挗鍖栫殑鐜荤拑淇℃伅"); + return; + } + List<Integer> temperingLayoutIdList = list.stream().map(TemperingGlassInfo::getTemperingLayoutId).distinct().collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(temperRecordIdList)) { + temperingLayoutIdList.removeAll(temperRecordIdList); + } + if (CollectionUtils.isEmpty(temperingLayoutIdList)) { + log.info("褰撳墠鐜荤拑鏈夋鍦ㄩ挗鍖栫殑浠诲姟"); + } +// 鑾峰彇閽㈠寲涓嬬墖琛ㄧ姸鎬佷负2鐨勭幓鐠冧俊鎭� + //瀹屾垚浠诲姟灏嗙‘璁ゅ瓧缃负1 + S7object.getinstance().plccontrol.writeWord(plcParameterObject.getPlcParameter("confirmationWord").getAddress(), 1); } @Scheduled(fixedDelay = 1000) public void temperingGlassAfter() { } + + @Scheduled(fixedDelay = 1000) + public void dealDamageTask() { + Date startDate = new Date(); + log.info("閽㈠寲鐮存崯鐜荤拑娓呴櫎浠诲姟寮�濮嬫墽琛屾椂闂达細{}", startDate); + List<TemperingGlassInfo> temperingGlassInfoList = temporaryGlassInfoService.list(new LambdaQueryWrapper<TemperingGlassInfo>().in(TemperingGlassInfo::getState, Const.GLASS_STATE_DAMAGE_TAKE)); + if (CollectionUtils.isNotEmpty(temperingGlassInfoList)) { + //鑾峰彇鐮存崯/鎷胯蛋鐜荤拑id + List<String> glassList = temperingGlassInfoList.stream().map(TemperingGlassInfo::getGlassId).collect(Collectors.toList()); + //灏嗕换鍔¤〃涓殑鏁版嵁鍒犻櫎 + temporaryGlassInfoService.remove(new LambdaQueryWrapper<TemperingGlassInfo>().in(TemperingGlassInfo::getGlassId, glassList)); + List<Damage> damageList = temperingGlassInfoList.stream().map(e -> { + Damage damage = new Damage(); + damage.setGlassId(e.getGlassId()); + damage.setLine(Const.TEMPERING_OUT_TARGET_POSITION); + damage.setWorkingProcedure("閽㈠寲"); + damage.setRemark("閽㈠寲"); + damage.setStatus(0); + damage.setType(e.getState()); + return damage; + }).collect(Collectors.toList()); + damageService.batchInsertDamage(damageList); + } + Date endDate = new Date(); + log.info("鏈浠诲姟缁撴潫鏃堕棿锛歿}锛屽叡鑰楁椂锛歿}ms", endDate, endDate.getTime() - startDate.getTime()); + } } -- Gitblit v1.8.0