| | |
| | | private Float onlineVol; |
| | | @ApiModelProperty(value = "组端电流") |
| | | private Float groupCurr; |
| | | @ApiModelProperty(value = "负载电流") |
| | | private Float loadCurr; |
| | | @ApiModelProperty(value = "单体电压") |
| | | private Float monVol; |
| | | @ApiModelProperty(value = "单体温度") |
New file |
| | |
| | | package com.whyc.dto.Real; |
| | | |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class RealHeart { |
| | | private Integer powerId; |
| | | private Integer battgroupId; |
| | | } |
| | |
| | | package com.whyc.mapper; |
| | | |
| | | import com.whyc.dto.Real.RealDateDTO; |
| | | import com.whyc.pojo.db_ram_db.BattRtstate; |
| | | |
| | | public interface BattRtstateMapper extends CustomMapper<BattRtstate>{ |
| | | //实时推送电池核容设备心跳数据 |
| | | RealDateDTO getBattRealHr(Integer battgroupId); |
| | | } |
| | |
| | | package com.whyc.mapper; |
| | | |
| | | import com.whyc.dto.Real.PwrHisRealAcInDto; |
| | | import com.whyc.dto.Real.PwrHisRealDcoutInDto; |
| | | import com.whyc.pojo.db_ram_db.PwrdevAcdcdata; |
| | | |
| | | public interface PwrdevAcdcdataMapper extends CustomMapper<PwrdevAcdcdata>{ |
| | | //电源心跳数据获取交流输入实时数据 |
| | | PwrHisRealAcInDto getPwrRealAcIn(Integer powerId); |
| | | //电源心跳数据获取电源直流输出数据实时数据 |
| | | PwrHisRealDcoutInDto getPwrRealDcOut(Integer powerId); |
| | | } |
| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.whyc.constant.BattStateEnum; |
| | | import com.whyc.constant.DevStateEnum; |
| | | import com.whyc.dto.Real.PwrHisRealDcoutInDto; |
| | | import com.whyc.dto.Real.RealDateDTO; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.BattRtstateMapper; |
| | | import com.whyc.pojo.db_ram_db.BattRtstate; |
| | |
| | | Map<Integer,String> map= BattStateEnum.getOpInfo(); |
| | | return new Response().setII(1,true,map,"获取电池组工作状态类型(下拉)"); |
| | | } |
| | | |
| | | //实时推送电池核容设备心跳数据 |
| | | public RealDateDTO getBattRealHr(Integer battgroupId) { |
| | | RealDateDTO hrDto=mapper.getBattRealHr(battgroupId); |
| | | return hrDto; |
| | | } |
| | | } |
| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.whyc.dto.Real.PwrHisRealAcInDto; |
| | | import com.whyc.dto.Real.PwrHisRealDcoutInDto; |
| | | import com.whyc.mapper.PwrdevAcdcdataMapper; |
| | | import com.whyc.pojo.db_ram_db.BattRtstate; |
| | | import com.whyc.pojo.db_ram_db.PwrdevAcdcdata; |
| | |
| | | PwrdevAcdcdata pwr=mapper.selectOne(wrapper); |
| | | return pwr; |
| | | } |
| | | //电源心跳数据获取交流输入实时数据 |
| | | public PwrHisRealAcInDto getPwrRealAcIn(Integer powerId) { |
| | | PwrHisRealAcInDto acinDto=mapper.getPwrRealAcIn(powerId); |
| | | return acinDto; |
| | | } |
| | | |
| | | //电源心跳数据获取电源直流输出数据实时数据 |
| | | public PwrHisRealDcoutInDto getPwrRealDcOut(Integer powerId) { |
| | | PwrHisRealDcoutInDto dcoutDto=mapper.getPwrRealDcOut(powerId); |
| | | return dcoutDto; |
| | | } |
| | | |
| | | } |
| | |
| | | } |
| | | //电池数据历史实时处理 |
| | | public List<RealDateDTO> getBattRealDataHis(BattRealdataId realdata, int granularity,Integer maxRecordNum,Integer minRecordNum) { |
| | | String sql=" select record_time, group_vol, online_vol,group_curr, mon_vol, mon_tmp, mon_res, mon_num,record_num " + |
| | | String sql=" select record_time, group_vol, online_vol,group_curr,load_curr, mon_vol, mon_tmp, mon_res, mon_num,record_num " + |
| | | " from db_data_history.tb_batt_realdata_"+realdata.getTableName()+" " + |
| | | " where record_time >= '"+ThreadLocalUtil.format(realdata.getRecordTime(),1)+"' " + |
| | | " and record_time <= '"+ThreadLocalUtil.format(realdata.getRecordTime1(),1)+"' "+ |
| | |
| | | |
| | | //系统概览获取前N笔核容设备信息 |
| | | public List<RealDateDTO> getBattDevData100(String tableName, Integer granularity, Date recordDatetime, Date recordDatetime1,Integer maxRecordNum,Integer minRecordNum) { |
| | | String sql=" select record_time, group_vol, online_vol,group_curr, mon_vol, mon_tmp, mon_res, mon_num,record_num " + |
| | | String sql=" select record_time, group_vol, online_vol,group_curr, load_curr,record_num " + |
| | | " from "+tableName+" " + |
| | | " where record_time >= '"+ThreadLocalUtil.format(recordDatetime,1)+"' " + |
| | | " and record_time <= '"+ThreadLocalUtil.format(recordDatetime1,1)+"' "+ |
| | |
| | | ph.setGroupVol(rs.getFloat("group_vol")); |
| | | ph.setOnlineVol(rs.getFloat("online_vol")); |
| | | ph.setGroupCurr(rs.getFloat("group_curr")); |
| | | ph.setMonVol(rs.getFloat("mon_vol")); |
| | | ph.setMonTmp(rs.getFloat("mon_tmp")); |
| | | ph.setMonRes(rs.getFloat("mon_res")); |
| | | ph.setMonNum(rs.getInt("mon_num")); |
| | | ph.setLoadCurr(rs.getFloat("load_curr")); |
| | | ph.setRecordNum(rs.getInt("record_num")); |
| | | list.add(ph); |
| | | } |
New file |
| | |
| | | package com.whyc.webSocket; |
| | | |
| | | import com.whyc.config.WebSocketConfig; |
| | | import com.whyc.dto.Real.PwrHisRealAcInDto; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.pojo.db_param.PowerheartParam; |
| | | import com.whyc.service.PowerheartParamService; |
| | | import com.whyc.service.PwrdevAcdcdataService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.servlet.http.HttpSession; |
| | | import javax.websocket.*; |
| | | import javax.websocket.server.ServerEndpoint; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 实时推送电源交流输入心跳交流输入数据 |
| | | */ |
| | | @Component |
| | | @ServerEndpoint(value = "/acin",encoders = WebSocketEncoder.class,configurator = WebSocketConfig.class) |
| | | public class HeartAcInSocket { |
| | | private Session session; |
| | | |
| | | private Thread thread; |
| | | |
| | | private static PwrdevAcdcdataService acdcdataService; |
| | | |
| | | private static PowerheartParamService pwrHeartService; |
| | | |
| | | private static HttpSession httpSession; |
| | | |
| | | private volatile boolean runFlag = true; |
| | | |
| | | private volatile Map<String, Thread> threadMap = new HashMap<>(); |
| | | |
| | | private volatile Map<Long,Boolean> threadFlagMap = new HashMap<>(); |
| | | |
| | | @Autowired |
| | | public void setPwrdevAcdcdataService(PwrdevAcdcdataService service) { |
| | | HeartAcInSocket.acdcdataService = service; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setPowerheartParamService(PowerheartParamService service) { |
| | | HeartAcInSocket.pwrHeartService = service; |
| | | } |
| | | |
| | | @OnOpen |
| | | public void onOpen(Session session, EndpointConfig config) { |
| | | this.session = session; |
| | | this.httpSession = (HttpSession) config.getUserProperties().get("httpSession"); |
| | | } |
| | | @OnMessage |
| | | public void onMessage(Session session, String message) { |
| | | Integer powerId = Integer.valueOf(message); |
| | | thread = new Thread("Thread_HeartacinSocket") { |
| | | @Override |
| | | public void run() { |
| | | while (runFlag && !isInterrupted()) { |
| | | Thread thread = currentThread(); |
| | | threadFlagMap.put(thread.getId(), true); |
| | | try { |
| | | PwrHisRealAcInDto acinDto = acdcdataService.getPwrRealAcIn(powerId); |
| | | if (session.isOpen()) { |
| | | //推送信息 |
| | | synchronized (session) { |
| | | session.getBasicRemote().sendObject(new Response<>().setII(1,acinDto!=null,acinDto,"电源交流输入数据")); |
| | | } |
| | | threadFlagMap.put(thread.getId(), false); |
| | | } |
| | | PowerheartParam powerheartParam=pwrHeartService.getHeartParamByPowerId(powerId); |
| | | sleep(1000*60*powerheartParam.getAcinInterverCfg()); |
| | | } catch (Exception e) { |
| | | interrupt(); |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | thread.start(); |
| | | threadFlagMap.put(thread.getId(),true); |
| | | //停止老的socket线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | while (threadFlagMap.get(threadBefore.getId())){ |
| | | } |
| | | threadBefore.interrupt(); |
| | | } |
| | | //将线程存储,便于调用定位 |
| | | threadMap.put(session.getId(), this.thread); |
| | | } |
| | | @OnClose |
| | | public void onClose(CloseReason closeReason){ |
| | | System.err.println("closeReason = " + closeReason); |
| | | runFlag = false; |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | | threadMap.remove(session.getId()); |
| | | } |
| | | |
| | | @OnError |
| | | public void onError(Throwable error) { |
| | | error.printStackTrace(); |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | | threadMap.remove(session.getId()); |
| | | } |
| | | } |
New file |
| | |
| | | package com.whyc.webSocket; |
| | | |
| | | import com.whyc.config.WebSocketConfig; |
| | | import com.whyc.dto.Real.PwrHisRealAcInDto; |
| | | import com.whyc.dto.Real.PwrHisRealDcoutInDto; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.pojo.db_param.PowerheartParam; |
| | | import com.whyc.service.PowerheartParamService; |
| | | import com.whyc.service.PwrdevAcdcdataService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.servlet.http.HttpSession; |
| | | import javax.websocket.*; |
| | | import javax.websocket.server.ServerEndpoint; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 实时推送电源直流输出心跳交流输入数据 |
| | | */ |
| | | @Component |
| | | @ServerEndpoint(value = "/acout",encoders = WebSocketEncoder.class,configurator = WebSocketConfig.class) |
| | | public class HeartAcOutSocket { |
| | | private Session session; |
| | | |
| | | private Thread thread; |
| | | |
| | | private static PwrdevAcdcdataService acdcdataService; |
| | | |
| | | private static PowerheartParamService pwrHeartService; |
| | | |
| | | private static HttpSession httpSession; |
| | | |
| | | private volatile boolean runFlag = true; |
| | | |
| | | private volatile Map<String, Thread> threadMap = new HashMap<>(); |
| | | |
| | | private volatile Map<Long,Boolean> threadFlagMap = new HashMap<>(); |
| | | |
| | | @Autowired |
| | | public void setPwrdevAcdcdataService(PwrdevAcdcdataService service) { |
| | | HeartAcOutSocket.acdcdataService = service; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setPowerheartParamService(PowerheartParamService service) { |
| | | HeartAcOutSocket.pwrHeartService = service; |
| | | } |
| | | |
| | | @OnOpen |
| | | public void onOpen(Session session, EndpointConfig config) { |
| | | this.session = session; |
| | | this.httpSession = (HttpSession) config.getUserProperties().get("httpSession"); |
| | | } |
| | | @OnMessage |
| | | public void onMessage(Session session, String message) { |
| | | Integer powerId = Integer.valueOf(message); |
| | | thread = new Thread("Thread_HeartacoutSocket") { |
| | | @Override |
| | | public void run() { |
| | | while (runFlag && !isInterrupted()) { |
| | | Thread thread = currentThread(); |
| | | threadFlagMap.put(thread.getId(), true); |
| | | try { |
| | | PwrHisRealDcoutInDto dcoutDto = acdcdataService.getPwrRealDcOut(powerId); |
| | | if (session.isOpen()) { |
| | | //推送信息 |
| | | synchronized (session) { |
| | | session.getBasicRemote().sendObject(new Response<>().setII(1,dcoutDto!=null,dcoutDto,"电源直流输出数据")); |
| | | } |
| | | threadFlagMap.put(thread.getId(), false); |
| | | } |
| | | PowerheartParam powerheartParam=pwrHeartService.getHeartParamByPowerId(powerId); |
| | | sleep(1000*60*powerheartParam.getAcoutCountCfg()); |
| | | } catch (Exception e) { |
| | | interrupt(); |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | thread.start(); |
| | | threadFlagMap.put(thread.getId(),true); |
| | | //停止老的socket线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | while (threadFlagMap.get(threadBefore.getId())){ |
| | | } |
| | | threadBefore.interrupt(); |
| | | } |
| | | //将线程存储,便于调用定位 |
| | | threadMap.put(session.getId(), this.thread); |
| | | } |
| | | @OnClose |
| | | public void onClose(CloseReason closeReason){ |
| | | System.err.println("closeReason = " + closeReason); |
| | | runFlag = false; |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | | threadMap.remove(session.getId()); |
| | | } |
| | | |
| | | @OnError |
| | | public void onError(Throwable error) { |
| | | error.printStackTrace(); |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | | threadMap.remove(session.getId()); |
| | | } |
| | | } |
New file |
| | |
| | | package com.whyc.webSocket; |
| | | |
| | | import com.whyc.config.WebSocketConfig; |
| | | import com.whyc.dto.Real.PwrHisRealDcoutInDto; |
| | | import com.whyc.dto.Real.RealDateDTO; |
| | | import com.whyc.dto.Real.RealHeart; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.pojo.db_param.PowerheartParam; |
| | | import com.whyc.pojo.db_ram_db.BattRtdata; |
| | | import com.whyc.pojo.db_ram_db.BattRtstate; |
| | | import com.whyc.service.BattRtdataService; |
| | | import com.whyc.service.BattRtstateService; |
| | | import com.whyc.service.PowerheartParamService; |
| | | import com.whyc.service.PwrdevAcdcdataService; |
| | | import com.whyc.util.ActionUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.servlet.http.HttpSession; |
| | | import javax.websocket.*; |
| | | import javax.websocket.server.ServerEndpoint; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 实时推送电池核容设备心跳数据 |
| | | */ |
| | | @Component |
| | | @ServerEndpoint(value = "/hr",encoders = WebSocketEncoder.class,configurator = WebSocketConfig.class) |
| | | public class HeartHrSocket { |
| | | private Session session; |
| | | |
| | | private Thread thread; |
| | | |
| | | private static BattRtstateService rtstateService; |
| | | |
| | | |
| | | private static PowerheartParamService pwrHeartService; |
| | | |
| | | private static HttpSession httpSession; |
| | | |
| | | private volatile boolean runFlag = true; |
| | | |
| | | private volatile Map<String, Thread> threadMap = new HashMap<>(); |
| | | |
| | | private volatile Map<Long,Boolean> threadFlagMap = new HashMap<>(); |
| | | |
| | | @Autowired |
| | | public void setBattRtstateService(BattRtstateService service) { |
| | | HeartHrSocket.rtstateService = service; |
| | | } |
| | | |
| | | |
| | | @Autowired |
| | | public void setPowerheartParamService(PowerheartParamService service) { |
| | | HeartHrSocket.pwrHeartService = service; |
| | | } |
| | | |
| | | @OnOpen |
| | | public void onOpen(Session session, EndpointConfig config) { |
| | | this.session = session; |
| | | this.httpSession = (HttpSession) config.getUserProperties().get("httpSession"); |
| | | } |
| | | @OnMessage |
| | | public void onMessage(Session session, String message) { |
| | | RealHeart heart= ActionUtil.getGson().fromJson(message,RealHeart.class); |
| | | thread = new Thread("Thread_HeartacoutSocket") { |
| | | @Override |
| | | public void run() { |
| | | while (runFlag && !isInterrupted()) { |
| | | Thread thread = currentThread(); |
| | | threadFlagMap.put(thread.getId(), true); |
| | | try { |
| | | RealDateDTO hrdto=rtstateService.getBattRealHr(heart.getBattgroupId()); |
| | | if (session.isOpen()) { |
| | | //推送信息 |
| | | synchronized (session) { |
| | | session.getBasicRemote().sendObject(new Response<>().setII(1,hrdto!=null,hrdto,"电源直流输出数据")); |
| | | } |
| | | threadFlagMap.put(thread.getId(), false); |
| | | } |
| | | PowerheartParam powerheartParam=pwrHeartService.getHeartParamByPowerId(heart.getPowerId()); |
| | | sleep(1000*60*powerheartParam.getHrInterverCfg()); |
| | | } catch (Exception e) { |
| | | interrupt(); |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | thread.start(); |
| | | threadFlagMap.put(thread.getId(),true); |
| | | //停止老的socket线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | while (threadFlagMap.get(threadBefore.getId())){ |
| | | } |
| | | threadBefore.interrupt(); |
| | | } |
| | | //将线程存储,便于调用定位 |
| | | threadMap.put(session.getId(), this.thread); |
| | | } |
| | | @OnClose |
| | | public void onClose(CloseReason closeReason){ |
| | | System.err.println("closeReason = " + closeReason); |
| | | runFlag = false; |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | | threadMap.remove(session.getId()); |
| | | } |
| | | |
| | | @OnError |
| | | public void onError(Throwable error) { |
| | | error.printStackTrace(); |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | | threadMap.remove(session.getId()); |
| | | } |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.whyc.mapper.BattRtstateMapper"> |
| | | |
| | | <select id="getBattRealHr" resultType="com.whyc.dto.Real.RealDateDTO"> |
| | | select * from db_ram_db.tb_batt_rtstate |
| | | where battgroup_id=#{battgroupId} |
| | | limit 1 |
| | | </select> |
| | | </mapper> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.whyc.mapper.PwrdevAcdcdataMapper"> |
| | | |
| | | <select id="getPwrRealAcIn" resultType="com.whyc.dto.Real.PwrHisRealAcInDto"> |
| | | select record_datetime,acin1_vola,acin1_volb,acin1_volc,acin2_vola,acin2_volb,acin2_volc,acin1_curra,acin1_currb,acin1_currc,acin2_curra,acin2_currb,acin2_currc |
| | | from db_ram_db.tb_pwrdev_acdcdata |
| | | where power_id=#{powerId} |
| | | limit 1 |
| | | </select> |
| | | <select id="getPwrRealDcOut" resultType="com.whyc.dto.Real.PwrHisRealDcoutInDto"> |
| | | select * |
| | | from db_ram_db.tb_pwrdev_acdcdata |
| | | where power_id=#{powerId} |
| | | limit 1 |
| | | </select> |
| | | </mapper> |