New file |
| | |
| | | package com.mes.job; |
| | | |
| | | |
| | | import com.kangaroohy.milo.model.ReadWriteEntity; |
| | | import com.kangaroohy.milo.service.MiloService; |
| | | import com.mes.pp.entity.OptimizeHeatDetail; |
| | | import com.mes.pp.entity.OptimizeHeatLayout; |
| | | import com.mes.pp.service.OptimizeHeatDetailService; |
| | | import com.mes.pp.service.OptimizeHeatLayoutService; |
| | | import com.mes.temperingglass.entity.TemperingGlass; |
| | | import com.mes.temperingglass.entity.TemperingGlassInfo; |
| | | import com.mes.temperingglass.service.TemperingGlassInfoService; |
| | | 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.Comparator; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | |
| | | |
| | | @Component |
| | | @Slf4j |
| | | public class OpcNGTemperingTask { |
| | | |
| | | @Autowired(required = false) |
| | | MiloService miloService; |
| | | |
| | | @Autowired |
| | | private TemperingGlassInfoService temperingAgoService; |
| | | |
| | | @Autowired |
| | | private OptimizeHeatLayoutService optimizeHeatLayoutService; |
| | | |
| | | @Autowired |
| | | private OptimizeHeatDetailService optimizeHeatDetailService; |
| | | |
| | | /** |
| | | * 摆片台请求进片逻辑处理 |
| | | * fixedRate : 上一个调用开始后再次调用的延时(不用等待上一次调用完成) |
| | | * fixedDelay : 上一个调用结束后再次调用的延时 |
| | | */ |
| | | //@Scheduled(fixedDelay = 1000) |
| | | public void requestTemperingTask() throws Exception { |
| | | ReadWriteEntity requestInTempering = miloService.readFromOpcUa("GH1S7.GH1S7.requestInTempering");//请求进片 |
| | | ReadWriteEntity requestTemperingId = miloService.readFromOpcUa("GH1S7.GH1S7.requestTemperingId");//请求进片 炉号ID |
| | | Integer request = Integer.parseInt(requestInTempering.getValue().toString()); |
| | | Integer id = Integer.parseInt(requestTemperingId.getValue().toString()); |
| | | if (request == 0) { |
| | | miloService.writeToOpcUa(generateReadWriteEntity("GH1S7.GH1S7.responseInTempering", 0));//允许送片清零 |
| | | } else { |
| | | ReadWriteEntity placedNumber = miloService.readFromOpcUa("GH1S7.GH1S7.placedNumber");//已摆片数量 |
| | | List<TemperingGlassInfo> glassList = temperingAgoService.selectGlassInfoById(id); |
| | | if (glassList.size() == Integer.parseInt(placedNumber.getValue().toString())) { |
| | | miloService.writeToOpcUa(generateReadWriteEntity("GH1S7.GH1S7.responseInTempering", 1));//写入允许送片 |
| | | } else { |
| | | miloService.writeToOpcUa(generateReadWriteEntity("GH1S7.GH1S7.responseInTempering", 2));//不满足进炉条件 |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 钢化上片台下发参数逻辑处理 |
| | | * fixedRate : 上一个调用开始后再次调用的延时(不用等待上一次调用完成) |
| | | * fixedDelay : 上一个调用结束后再次调用的延时 |
| | | */ |
| | | //@Scheduled(fixedDelay = 1000) |
| | | public void loadTemperingTask() throws Exception { |
| | | ReadWriteEntity loadTemperingId = miloService.readFromOpcUa("GH1S7.GH1S7.loadTemperingId");//进片完成 炉号ID |
| | | getNewTemperingID(Integer.parseInt(loadTemperingId.getValue().toString()));//进片完成 下发参数 |
| | | } |
| | | |
| | | //获取到炉号id执行参数下发任务 |
| | | private void getNewTemperingID(Integer temperingid) throws Exception { |
| | | ReadWriteEntity AutoStatus = miloService.readFromOpcUa("GH1.GH1.AutoStatus"); |
| | | if (1 != Integer.parseInt(AutoStatus.getValue().toString())) { |
| | | log.info("当前为非联机状态,结束钢化下发参数任务"); |
| | | return; |
| | | } |
| | | ReadWriteEntity QandA = miloService.readFromOpcUa("GH1.GH1.QandA"); |
| | | ReadWriteEntity RecipeStatus = miloService.readFromOpcUa("GH1.GH1.RecipeStatus"); |
| | | if (1 == Integer.parseInt(QandA.getValue().toString()) && 2 == Integer.parseInt(RecipeStatus.getValue().toString())) { |
| | | log.info("版面信息已经下发,并且已经匹配参数,结束钢化下发参数任务"); |
| | | return; |
| | | } |
| | | List<TemperingGlassInfo> glassList = temperingAgoService.selectGlassInfoById(temperingid); |
| | | if (glassList != null && glassList.size() > 0) { |
| | | int glasstype = GetGlassType(glassList.get(0).getFilmsid());//膜系 |
| | | int process = 0;//钢化类型 |
| | | int thiness = (int) glassList.get(0).getThickness();//厚度 |
| | | String engineerId = glassList.get(0).getEngineerId(); |
| | | Integer temperingLayoutId = glassList.get(0).getTemperingLayoutId(); |
| | | OptimizeHeatLayout heatLayoutinfo = optimizeHeatLayoutService.selectHeatLayoutInfo(engineerId, temperingLayoutId); |
| | | int loadingRate = (int) (heatLayoutinfo.getLayoutRate() * 100); //装载率 |
| | | loadingRate = loadingRate > 10000 ? 10000 : loadingRate; |
| | | List<OptimizeHeatDetail> heatDetailGlassInfoList = optimizeHeatDetailService.selectHeatDetailGlassInfo(engineerId, temperingLayoutId); |
| | | |
| | | Optional<Double> maxProductOpt = heatDetailGlassInfoList.stream() |
| | | .map(ohd -> ohd.getWidth() * ohd.getHeight()) |
| | | .max(Double::compareTo); |
| | | double totalarea = heatDetailGlassInfoList.stream().mapToDouble(ohd -> ohd.getWidth() * ohd.getHeight()).sum(); |
| | | |
| | | int shape = 0; //最大片占总面积的比例 |
| | | if (maxProductOpt.isPresent()) { |
| | | shape = (int) (maxProductOpt.get() / totalarea * 100); |
| | | } |
| | | shape = shape > 10000 ? 10000 : shape; |
| | | int workmode = 0; //工位数 |
| | | int furmode = 0; //双室/联室 |
| | | |
| | | miloService.writeToOpcUa(generateReadWriteEntity("GH1.GH1.TemperingId", temperingid));//写入炉号 |
| | | miloService.writeToOpcUa(generateReadWriteEntity("GH1.GH1.GlassType", glasstype));//写入玻璃类型 |
| | | miloService.writeToOpcUa(generateReadWriteEntity("GH1.GH1.Process", process));//写入钢化类型 全钢 半钢 防火 |
| | | miloService.writeToOpcUa(generateReadWriteEntity("GH1.GH1.Thickness", thiness));//写入厚度 |
| | | miloService.writeToOpcUa(generateReadWriteEntity("GH1.GH1.LoadingRate", loadingRate));//写入装载率 |
| | | miloService.writeToOpcUa(generateReadWriteEntity("GH1.GH1.Shape", shape));//写入大片比例 |
| | | miloService.writeToOpcUa(generateReadWriteEntity("GH1.GH1.WorkMode", workmode));//写入工位数 |
| | | miloService.writeToOpcUa(generateReadWriteEntity("GH1.GH1.FurnaceMode", furmode));//写入炉体工作方式 |
| | | log.info("炉号" + temperingid + "版面信息尝试下发"); |
| | | } |
| | | } |
| | | |
| | | |
| | | //根据膜系返回玻璃类型 |
| | | private int GetGlassType(String glasstype) { |
| | | int result = 0; |
| | | String str = glasstype.toLowerCase(); |
| | | if (str.contains("白玻")) { |
| | | result = 0; |
| | | } |
| | | if (str.contains("超白")) { |
| | | result = 4; |
| | | } |
| | | if (str.contains("lowe") || str.contains("low-e")) { |
| | | result = 1; |
| | | } |
| | | if (str.contains("双银")) { |
| | | result = 2; |
| | | } |
| | | if (str.contains("三银")) { |
| | | result = 3; |
| | | } |
| | | if (str.contains("热反射")) { |
| | | result = 5; |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private ReadWriteEntity generateReadWriteEntity(String identifier, Object value) { |
| | | return ReadWriteEntity.builder() |
| | | .identifier(identifier) |
| | | //Kep中是Long类型,即:Int32,Java中的int类型 |
| | | .value(value) |
| | | .build(); |
| | | } |
| | | } |