| New file |
| | |
| | | package com.mes.job; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.kangaroohy.milo.model.ReadWriteEntity; |
| | | import com.kangaroohy.milo.service.MiloService; |
| | | import com.mes.glassinfo.entity.GlassInfo; |
| | | import com.mes.glassinfo.service.GlassInfoService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Author : zhoush |
| | | * @Date: 2024/10/10 8:05 |
| | | * @Description: |
| | | */ |
| | | @Component |
| | | @Slf4j |
| | | public class OpcEdgTask { |
| | | |
| | | |
| | | @Autowired(required = false) |
| | | MiloService miloService; |
| | | |
| | | @Resource |
| | | GlassInfoService glassInfoService; |
| | | |
| | | |
| | | @Scheduled(fixedDelay = 2000) |
| | | public void startOneEdgTask() throws Exception { |
| | | startEdgTaskChild("01"); |
| | | } |
| | | |
| | | @Scheduled(fixedDelay = 2000) |
| | | public void startTwoEdgTask() throws Exception { |
| | | startEdgTaskChild("02"); |
| | | } |
| | | |
| | | private void startEdgTaskChild(String cell) throws Exception { |
| | | ReadWriteEntity request = miloService.readFromOpcUa("MB04.MB04.request" + cell); |
| | | if (null == request || "0".equals(request.getValue() + "")) { |
| | | log.info("未收到玻璃请求,结束本次任务"); |
| | | return; |
| | | } |
| | | ReadWriteEntity glassIdEntity = miloService.readFromOpcUa("MB04.MB04.plc_glass_id_" + cell); |
| | | |
| | | if (null == glassIdEntity || StringUtils.isEmpty(glassIdEntity.getValue() + "")) { |
| | | log.info("有请求但玻璃id为空,结束本次任务"); |
| | | return; |
| | | } |
| | | String glassId = glassIdEntity.getValue() + ""; |
| | | log.info("获取到{}线的玻璃id:{}", cell, glassId); |
| | | GlassInfo glassInfo = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>().eq(GlassInfo::getGlassId, glassId).last("limit 1")); |
| | | |
| | | List<ReadWriteEntity> ualist = new ArrayList<>(); |
| | | miloService.writeToOpcUa(generateReadWriteEntity("MB04.MB04.mes_glass_Id_" + cell, glassId)); |
| | | ualist.add(generateReadWriteEntity("MB04.MB04.width" + cell, (int) Math.max(glassInfo.getWidth() * 10, glassInfo.getHeight() * 10))); |
| | | ualist.add(generateReadWriteEntity("MB04.MB04.height" + cell, (int) Math.min(glassInfo.getWidth() * 10, glassInfo.getHeight() * 10))); |
| | | ualist.add(generateReadWriteEntity("MB04.MB04.thickness" + cell, (int) glassInfo.getThickness() * 10)); |
| | | miloService.writeToOpcWord(ualist); |
| | | } |
| | | |
| | | private ReadWriteEntity generateReadWriteEntity(String identifier, Object value) { |
| | | return ReadWriteEntity.builder() |
| | | .identifier(identifier) |
| | | //Kep中是Long类型,即:Int32,Java中的int类型 |
| | | .value(value) |
| | | .build(); |
| | | } |
| | | |
| | | } |