| | |
| | | package com.mes.job; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.json.JSONObject; |
| | | import com.mes.temperingglass.service.TemperingGlassInfoService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.github.xingshuangs.iot.protocol.s7.serializer.S7Serializer; |
| | | import com.mes.common.config.Const; |
| | | import com.mes.damage.service.DamageService; |
| | | import com.mes.largenscreen.entity.PieChartVO; |
| | | import com.mes.s7.entity.S7DataGHTwo; |
| | | import com.mes.temperingglass.entity.TemperingGlassInfo; |
| | | import com.mes.tools.WebSocketServer; |
| | | import com.mes.temperingglass.service.TemperingGlassInfoService; |
| | | import com.mes.tools.WebSocketUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDate; |
| | | import java.time.ZoneId; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author SNG-010 |
| | |
| | | public class PlcTemperingGlassTask { |
| | | |
| | | @Autowired |
| | | private TemperingGlassInfoService temperingAgoService; |
| | | private TemperingGlassInfoService temperingGlassInfoService; |
| | | @Autowired |
| | | private DamageService damageService; |
| | | |
| | | @Autowired |
| | | @Qualifier("s7SerializerGHTwo") |
| | | private S7Serializer s7SerializerGHTwo; |
| | | @Resource |
| | | private WebSocketUtils webSocketUtils; |
| | | |
| | | |
| | | @Scheduled(fixedDelay = 1000) |
| | | public void temperingGlassHome() { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | //正在等待进片的玻璃 |
| | | List<TemperingGlassInfo> waitingGlass = new ArrayList<>(); |
| | | try { |
| | | waitingGlass = selectWaitingGlassByOpc(); |
| | | if (CollectionUtil.isNotEmpty(waitingGlass)) { |
| | | jsonObject.append("waitingGlass", waitingGlass); |
| | | } |
| | | } catch (Exception e) { |
| | | log.info("钢化前获取异常:{}", e.getMessage()); |
| | | } |
| | | try { |
| | | List<TemperingGlassInfo> intoGlass = selectIntoGlass(waitingGlass); |
| | | if (CollectionUtil.isNotEmpty(intoGlass)) { |
| | | for (int i = 0; i < intoGlass.size(); i++) { |
| | | String jsonName = "intoGlass"; |
| | | if (i != 0) { |
| | | jsonName = jsonName + i; |
| | | } |
| | | jsonObject.append(jsonName, temperingGlassInfoService.list(new LambdaQueryWrapper<TemperingGlassInfo>() |
| | | .eq(TemperingGlassInfo::getEngineerId, intoGlass.get(i).getEngineerId()) |
| | | .eq(TemperingGlassInfo::getTemperingLayoutId, intoGlass.get(i).getTemperingLayoutId()))); |
| | | } |
| | | |
| | | } |
| | | } catch (Exception e) { |
| | | log.info("钢化前获取异常:{}", e.getMessage()); |
| | | } |
| | | try { |
| | | //出炉后的玻璃 |
| | | List<TemperingGlassInfo> outGlass = temperingGlassInfoService.selectOutGlass(); |
| | | if (CollectionUtil.isNotEmpty(outGlass)) { |
| | | jsonObject.append("outGlass", outGlass); |
| | | } |
| | | } catch (Exception e) { |
| | | log.info("钢化前获取异常:{}", e.getMessage()); |
| | | } |
| | | webSocketUtils.sendToWeb("temperingGlass", jsonObject); |
| | | |
| | | } |
| | | |
| | | @Scheduled(fixedDelay = 1000) |
| | | public void temperingIsRun() { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | //正在进行的任务 |
| | | List<TemperingGlassInfo> temperingTaskType = temperingGlassInfoService.selectTaskType(); |
| | | jsonObject.append("temperingTaskType", temperingTaskType); |
| | | webSocketUtils.sendToWeb("temperingIsRun", jsonObject); |
| | | } |
| | | |
| | | @Scheduled(fixedDelay = 1000) |
| | | public void largenScreen() { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | //大屏钢化信息 |
| | | Date startOfToday = new Date(LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli()); |
| | | |
| | | Integer putGlass = temperingGlassInfoService.count( |
| | | new QueryWrapper<TemperingGlassInfo>() |
| | | .eq("state", Const.TEMPERING_NEW) |
| | | .gt("create_time", startOfToday) |
| | | ); |
| | | jsonObject.append("temperingTaskType", putGlass); |
| | | //大屏钢化信息 |
| | | List<TemperingGlassInfo> temperingGlassInfoList = temperingGlassInfoService.list( |
| | | new QueryWrapper<TemperingGlassInfo>() |
| | | .select("engineer_id", "tempering_layout_id") |
| | | .eq("state", Const.TEMPERING_START) |
| | | .gt("create_time", startOfToday) |
| | | .groupBy("engineer_id", "tempering_layout_id") |
| | | ); |
| | | jsonObject.append("temperingGlassInfoList", temperingGlassInfoList.size()); |
| | | //大屏钢化信息 |
| | | List<TemperingGlassInfo> temperingGlassInfoInList = temperingGlassInfoService.list( |
| | | new LambdaQueryWrapper<TemperingGlassInfo>() |
| | | .select(TemperingGlassInfo::getEngineerId, TemperingGlassInfo::getTemperingLayoutId) // 选择要去重的字段 |
| | | .eq(TemperingGlassInfo::getState, Const.TEMPERING_DROP) |
| | | .groupBy(TemperingGlassInfo::getEngineerId, TemperingGlassInfo::getTemperingLayoutId) // 按 engineerId 和 temperingLayoutId 分组 |
| | | ); |
| | | jsonObject.append("temperingGlassInfoInList", temperingGlassInfoInList.size()); |
| | | //钢化饼图数据 |
| | | List<PieChartVO> pieChartVOS = temperingGlassInfoService.queryPieChart(); |
| | | jsonObject.append("pieChartVOS", pieChartVOS); |
| | | webSocketUtils.sendToWeb("largenScreen", jsonObject); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * fixedRate : 上一个调用开始后再次调用的延时(不用等待上一次调用完成) |
| | | * fixedDelay : 上一个调用结束后再次调用的延时 |
| | | */ |
| | | |
| | | @Scheduled(fixedDelay = 1000) |
| | | public void temperingGlassHome(){ |
| | | JSONObject jsonObject = new JSONObject(); |
| | | //正在等待进片的玻璃 |
| | | List<TemperingGlassInfo> waitingGlass = temperingAgoService.selectWaitingGlass(); |
| | | jsonObject.append("waitingGlass", waitingGlass); |
| | | //获取整在炉中的两个版图id |
| | | List<TemperingGlassInfo> layoutId = temperingAgoService.selectLayoutId(); |
| | | //进炉中的玻璃 |
| | | if(!layoutId.isEmpty()) { |
| | | List<TemperingGlassInfo> intoGlass = temperingAgoService.selectIntoGlass(layoutId.get(0)); |
| | | jsonObject.append("intoGlass", intoGlass); |
| | | //进炉中的第二个版图 |
| | | if (layoutId.size() > 1) { |
| | | List<TemperingGlassInfo> intoGlass2 = temperingAgoService.selectIntoGlass(layoutId.get(1)); |
| | | jsonObject.append("intoGlass2", intoGlass2); |
| | | } |
| | | } |
| | | //出炉后的玻璃 |
| | | List<TemperingGlassInfo> outGlass = temperingAgoService.selectOutGlass(); |
| | | jsonObject.append("outGlass", outGlass); |
| | | //过旋转台钢化后的玻璃 |
| | | List<TemperingGlassInfo> overGlass = temperingAgoService.selectOverGlass(); |
| | | |
| | | jsonObject.append("overGlass", overGlass); |
| | | |
| | | ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("temperingGlass"); |
| | | if (sendwServer != null) { |
| | | for (WebSocketServer webserver : sendwServer) { |
| | | if (webserver != null) { |
| | | webserver.sendMessage(jsonObject.toString()); |
| | | } else { |
| | | log.info("Home is closed"); |
| | | private List<TemperingGlassInfo> selectWaitingGlassByOpc() { |
| | | //获取等待进炉中的玻璃信息 |
| | | try { |
| | | S7DataGHTwo s7DataGHTwo = s7SerializerGHTwo.read(S7DataGHTwo.class); |
| | | String engineerEntity = s7DataGHTwo.getF09EngineerId(); |
| | | Integer temperingLayoutIdEntity = s7DataGHTwo.getF09TemperingLayoutId(); |
| | | if (null == engineerEntity || null == temperingLayoutIdEntity) { |
| | | engineerEntity = s7DataGHTwo.getF08EngineerId(); |
| | | temperingLayoutIdEntity = s7DataGHTwo.getF08TemperingLayoutId(); |
| | | if (null == engineerEntity || null == temperingLayoutIdEntity) { |
| | | log.info("获取参数异常,结束本次任务"); |
| | | return new ArrayList<>(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | @Scheduled(fixedDelay = 1000) |
| | | public void temperingIsRun(){ |
| | | JSONObject jsonObject = new JSONObject(); |
| | | //正在进行的任务 |
| | | List<TemperingGlassInfo>temperingTaskType=temperingAgoService.selectTaskType(); |
| | | jsonObject.append("temperingTaskType", temperingTaskType); |
| | | ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("isRun"); |
| | | if (sendwServer != null) { |
| | | for (WebSocketServer webserver : sendwServer) { |
| | | if (webserver != null) { |
| | | webserver.sendMessage(jsonObject.toString()); |
| | | } else { |
| | | log.info("Home is closed"); |
| | | } |
| | | } |
| | | return temperingGlassInfoService.list(new LambdaQueryWrapper<TemperingGlassInfo>() |
| | | .eq(TemperingGlassInfo::getEngineerId, engineerEntity) |
| | | .eq(TemperingGlassInfo::getTemperingLayoutId, temperingLayoutIdEntity)); |
| | | } catch (Exception e) { |
| | | log.info("获取钢化参数异常:{}", e); |
| | | return new ArrayList<>(); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取正在钢化的版图信息:获取3炉已经摆好的玻璃小片,排除正在摆的 |
| | | * |
| | | * @param list |
| | | * @return |
| | | */ |
| | | private List<TemperingGlassInfo> selectIntoGlass(List<TemperingGlassInfo> list) { |
| | | List<TemperingGlassInfo> temperingGlassInfoList = temperingGlassInfoService.queryEngineerAndLayoutId(); |
| | | log.info("钢化中获取到的数据为{}", temperingGlassInfoList); |
| | | if (CollectionUtil.isEmpty(temperingGlassInfoList)) { |
| | | return new ArrayList<>(); |
| | | } |
| | | if (CollectionUtil.isEmpty(list)) { |
| | | return temperingGlassInfoList; |
| | | } else { |
| | | String engineerId = list.get(0).getEngineerId(); |
| | | int temperingLayoutId = list.get(0).getTemperingLayoutId(); |
| | | List<TemperingGlassInfo> tempList = temperingGlassInfoList.stream().filter(e -> !(e.getEngineerId().equals(engineerId) && temperingLayoutId == e.getTemperingLayoutId())).collect(Collectors.toList()); |
| | | return tempList; |
| | | } |
| | | } |
| | | } |