From cd6377eae5326d1d80c9a9de431584e4b40965b8 Mon Sep 17 00:00:00 2001 From: wanggeng888 <450292408@qq.com> Date: Fri, 26 Mar 2021 13:19:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=A4=A7=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PollutantDataApplication.java | 4 + .../controller/api/count/CountController.java | 18 +- .../dao/dataminute/IDataMinuteDao.java | 10 + .../pollutantdata/enums/QnRtdEnum.java | 6 +- .../manager/CollectorManager.java | 15 +- .../dtos/dataminute/EnterprisePollDTO.java | 26 + .../service/count/ICountService.java | 9 +- .../service/count/impl/CountServiceImpl.java | 30 +- .../dataminute/IDataMinuteService.java | 9 + .../impl/DataMinuteServiceImpl.java | 6 + .../pollutantdata/utils/net/TCPHandler.java | 17 +- .../pollutantdata/utils/net/TCPServer.java | 8 +- .../utils/net/handle/RealDataHandler.java | 26 +- src/main/resources/application.yml | 2 +- .../mapper/collector/collector-mapper.xml | 8 +- .../mapper/dataMinute/dataMinute-mapper.xml | 38 + .../assets/bigdata/style1/css/comon0.css | 7 + .../static/route/bigdata/style1/index.html | 981 +++++------------- .../com/tenlion/pollutantdata/HJ212Test.java | 15 +- 19 files changed, 454 insertions(+), 781 deletions(-) create mode 100644 src/main/java/com/cm/tenlion/pollutantdata/pojo/dtos/dataminute/EnterprisePollDTO.java diff --git a/src/main/java/com/cm/tenlion/pollutantdata/PollutantDataApplication.java b/src/main/java/com/cm/tenlion/pollutantdata/PollutantDataApplication.java index 2b3124c..0f0b58b 100644 --- a/src/main/java/com/cm/tenlion/pollutantdata/PollutantDataApplication.java +++ b/src/main/java/com/cm/tenlion/pollutantdata/PollutantDataApplication.java @@ -4,6 +4,7 @@ import com.cm.tenlion.pollutantdata.manager.CollectorManager; import com.cm.tenlion.pollutantdata.service.alarmlog.IAlarmLogService; import com.cm.tenlion.pollutantdata.service.collector.ICollectorService; import com.cm.tenlion.pollutantdata.service.dataminute.IDataMinuteService; +import com.cm.tenlion.pollutantdata.service.enterprise.IEnterpriseService; import com.cm.tenlion.pollutantdata.service.instrument.IInstrumentService; import com.cm.tenlion.pollutantdata.service.poll.IPollService; import com.cm.tenlion.pollutantdata.utils.net.TCPServer; @@ -22,6 +23,8 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; @SpringBootApplication(scanBasePackages = {"com.cm"}) @MapperScan({"com.cm.**.dao"}) public class PollutantDataApplication { + @Autowired + private IEnterpriseService enterpriseService; @Autowired private IInstrumentService instrumentService; @Autowired @@ -49,6 +52,7 @@ public class PollutantDataApplication { new Thread(() -> { try { TCPServer tcpServer = new TCPServer(6666); + tcpServer.setEnterpriseService(enterpriseService); tcpServer.setInstrumentService(instrumentService); tcpServer.setCollectorService(collectorService); tcpServer.setDataMinuteService(dataMinuteService); diff --git a/src/main/java/com/cm/tenlion/pollutantdata/controller/api/count/CountController.java b/src/main/java/com/cm/tenlion/pollutantdata/controller/api/count/CountController.java index f90ed36..7e297c1 100644 --- a/src/main/java/com/cm/tenlion/pollutantdata/controller/api/count/CountController.java +++ b/src/main/java/com/cm/tenlion/pollutantdata/controller/api/count/CountController.java @@ -3,6 +3,7 @@ package com.cm.tenlion.pollutantdata.controller.api.count; import com.cm.common.constants.ISystemConstant; import com.cm.common.result.ErrorResult; import com.cm.common.result.SuccessResultData; +import com.cm.tenlion.pollutantdata.pojo.dtos.dataminute.EnterprisePollDTO; import com.cm.tenlion.pollutantdata.service.count.ICountService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -55,10 +56,10 @@ public class CountController { @ApiOperation(value = "污染因子列表", notes = "污染因子列表接口") @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) - @GetMapping("list-pollid/{type}") - public List listPollId(@PathVariable("type") Integer type, - @RequestParam(name = "enterpriseId", required = false) String enterpriseId) { - return countService.listPollId(type, enterpriseId); + @GetMapping("list-enterprise-pollid/{type}") + public List listPollId(@PathVariable("type") Integer type, + @RequestParam(name = "enterpriseId", required = false) String enterpriseId) { + return countService.listEnterprisePollId(type, enterpriseId); } @ApiOperation(value = "历史数据1", notes = "历史数据1接口") @@ -66,8 +67,15 @@ public class CountController { @GetMapping("count-history-value/{type}/{pollId}/{enterpriseId}") public SuccessResultData> countHistoryValue1(@PathVariable("type") Integer type, @PathVariable("pollId") String pollId, - @RequestParam(name = "enterpriseId", required = false) String enterpriseId) { + @PathVariable("enterpriseId") String enterpriseId) { return countService.countHistoryValue1(type, pollId, enterpriseId); } + @ApiOperation(value = "统计污染因子上报数量", notes = "统计污染因子上报数量接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("count-report-pollid") + public SuccessResultData> countReportPollId() { + return countService.countReportPollId(); + } + } diff --git a/src/main/java/com/cm/tenlion/pollutantdata/dao/dataminute/IDataMinuteDao.java b/src/main/java/com/cm/tenlion/pollutantdata/dao/dataminute/IDataMinuteDao.java index df75204..5f1eadc 100644 --- a/src/main/java/com/cm/tenlion/pollutantdata/dao/dataminute/IDataMinuteDao.java +++ b/src/main/java/com/cm/tenlion/pollutantdata/dao/dataminute/IDataMinuteDao.java @@ -2,6 +2,7 @@ package com.cm.tenlion.pollutantdata.dao.dataminute; import com.cm.tenlion.pollutantdata.pojo.bos.dataminute.DataMinuteBO; import com.cm.tenlion.pollutantdata.pojo.dtos.dataminute.DataMinuteDTO; +import com.cm.tenlion.pollutantdata.pojo.dtos.dataminute.EnterprisePollDTO; import com.cm.tenlion.pollutantdata.pojo.pos.dataminute.DataMinutePO; import com.cm.common.exception.RemoveException; import com.cm.common.exception.SaveException; @@ -135,6 +136,15 @@ public interface IDataMinuteDao { */ List listPollId(Map params) throws SearchException; + /** + * 企业污染因子列表 + * + * @param params + * @return + * @throws SearchException + */ + List listEnterprisePollId(Map params) throws SearchException; + /** * 最新实时数据 * diff --git a/src/main/java/com/cm/tenlion/pollutantdata/enums/QnRtdEnum.java b/src/main/java/com/cm/tenlion/pollutantdata/enums/QnRtdEnum.java index 633081d..c044de8 100644 --- a/src/main/java/com/cm/tenlion/pollutantdata/enums/QnRtdEnum.java +++ b/src/main/java/com/cm/tenlion/pollutantdata/enums/QnRtdEnum.java @@ -75,7 +75,11 @@ public enum QnRtdEnum { /** * 采集器编码空 */ - CUSTOM_CP_SN_ERROR(110006); + CUSTOM_CP_SN_ERROR(110006), + /** + * 企业不存在 + */ + CUSTOM_ENTERPRISE_ERROR(110007); private int value; diff --git a/src/main/java/com/cm/tenlion/pollutantdata/manager/CollectorManager.java b/src/main/java/com/cm/tenlion/pollutantdata/manager/CollectorManager.java index 3485862..79c4c68 100644 --- a/src/main/java/com/cm/tenlion/pollutantdata/manager/CollectorManager.java +++ b/src/main/java/com/cm/tenlion/pollutantdata/manager/CollectorManager.java @@ -1,5 +1,7 @@ package com.cm.tenlion.pollutantdata.manager; +import com.cm.tenlion.pollutantdata.enums.BigDataTypeEnum; +import com.cm.tenlion.pollutantdata.pojo.BigDataWebSocketData; import com.cm.tenlion.pollutantdata.pojo.OnlineCollector; import com.cm.tenlion.pollutantdata.pojo.dtos.collector.CollectorDTO; import lombok.extern.slf4j.Slf4j; @@ -47,15 +49,12 @@ public class CollectorManager { public void addCollector(String channelId, CollectorDTO collectorDTO) { OnlineCollector onlineCollector = getCollector(channelId); if (onlineCollector == null) { - log.debug("{} 采集器设备接入", onlineCollector.getCollectorDTO().getCollectorMn()); + log.debug("{} 采集器设备接入", collectorDTO.getCollectorMn()); onlineCollector = new OnlineCollector(); onlineCollector.setChannelId(channelId); onlineCollector.setCollectorDTO(collectorDTO); onlineCollector.setLastUploadDataTime(System.currentTimeMillis()); collectors.put(channelId, onlineCollector); - - // 通知有统计的页面刷新 - // WebSocketManager.getInstance().sendMessage(new BigDataWebSocketData<>(BigDataTypeEnum.ONLINE_COUNT, collectors.size())); return; } onlineCollector.setLastUploadDataTime(System.currentTimeMillis()); @@ -137,7 +136,13 @@ public class CollectorManager { public void deleteCollector(String channelId) { OnlineCollector onlineCollector = getCollector(channelId); if (onlineCollector != null) { - log.debug("{} 采集器设备离线", onlineCollector.getCollectorDTO().getCollectorMn()); + String message = String.format("%s %s 采集仪的 %s 采集器离线", + onlineCollector.getCollectorDTO().getEnterpriseName(), + onlineCollector.getCollectorDTO().getInstrumentName(), + onlineCollector.getCollectorDTO().getCollectorMn()); + log.debug(message); + // 通知有统计的页面刷新 + WebSocketManager.getInstance().sendMessage(new BigDataWebSocketData<>(BigDataTypeEnum.OFFLINE_MESSAGE, message)); collectors.remove(channelId); } } diff --git a/src/main/java/com/cm/tenlion/pollutantdata/pojo/dtos/dataminute/EnterprisePollDTO.java b/src/main/java/com/cm/tenlion/pollutantdata/pojo/dtos/dataminute/EnterprisePollDTO.java new file mode 100644 index 0000000..4d33772 --- /dev/null +++ b/src/main/java/com/cm/tenlion/pollutantdata/pojo/dtos/dataminute/EnterprisePollDTO.java @@ -0,0 +1,26 @@ +package com.cm.tenlion.pollutantdata.pojo.dtos.dataminute; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: EnterprisePollDTO + * @Description: 企业污染因子列表 + * @Author: wanggeng + * @Date: 2021/3/26 9:40 上午 + * @Version: 1.0 + */ +@ApiModel +@Data +public class EnterprisePollDTO { + + @ApiModelProperty(name = "enterpriseId", value = "企业ID") + private String enterpriseId; + @ApiModelProperty(name = "pollId", value = "污染因子编码") + private String pollId; + +} diff --git a/src/main/java/com/cm/tenlion/pollutantdata/service/count/ICountService.java b/src/main/java/com/cm/tenlion/pollutantdata/service/count/ICountService.java index d4d0259..a4a7123 100644 --- a/src/main/java/com/cm/tenlion/pollutantdata/service/count/ICountService.java +++ b/src/main/java/com/cm/tenlion/pollutantdata/service/count/ICountService.java @@ -1,6 +1,7 @@ package com.cm.tenlion.pollutantdata.service.count; import com.cm.common.result.SuccessResultData; +import com.cm.tenlion.pollutantdata.pojo.dtos.dataminute.EnterprisePollDTO; import java.util.List; import java.util.Map; @@ -46,7 +47,7 @@ public interface ICountService { * @param enterpriseId * @return */ - List listPollId(Integer type, String enterpriseId); + List listEnterprisePollId(Integer type, String enterpriseId); /** * 历史数据1 @@ -58,4 +59,10 @@ public interface ICountService { */ SuccessResultData> countHistoryValue1(Integer type, String pollId, String enterpriseId); + /** + * 统计污染因子上报数量 + * + * @return + */ + SuccessResultData> countReportPollId(); } diff --git a/src/main/java/com/cm/tenlion/pollutantdata/service/count/impl/CountServiceImpl.java b/src/main/java/com/cm/tenlion/pollutantdata/service/count/impl/CountServiceImpl.java index 6971a9c..9bb292c 100644 --- a/src/main/java/com/cm/tenlion/pollutantdata/service/count/impl/CountServiceImpl.java +++ b/src/main/java/com/cm/tenlion/pollutantdata/service/count/impl/CountServiceImpl.java @@ -5,6 +5,7 @@ import com.cm.common.constants.ISystemConstant; import com.cm.common.result.SuccessResultData; import com.cm.common.utils.DateUtil; import com.cm.tenlion.pollutantdata.manager.CollectorManager; +import com.cm.tenlion.pollutantdata.pojo.dtos.dataminute.EnterprisePollDTO; import com.cm.tenlion.pollutantdata.pojo.pos.dataminute.DataMinutePO; import com.cm.tenlion.pollutantdata.service.alarmlog.IAlarmLogService; import com.cm.tenlion.pollutantdata.service.collector.ICollectorService; @@ -142,12 +143,12 @@ public class CountServiceImpl extends AbstractService implements ICountService { } @Override - public List listPollId(Integer type, String enterpriseId) { + public List listEnterprisePollId(Integer type, String enterpriseId) { Map params = getHashMap(8); params.put("startTime", getStartTime(type)); params.put("enterpriseId", enterpriseId); // 污染物因子列表 - return dataMinuteService.listPollId(params); + return dataMinuteService.listEnterprisePollId(params); } @Override @@ -175,9 +176,9 @@ public class CountServiceImpl extends AbstractService implements ICountService { rtdData.put("data", yRtdData); yList.add(rtdData); Map zsRtdData = getHashMap(6); - rtdData.put("name", "折算实时数据"); - rtdData.put("type", "line"); - rtdData.put("data", yZsRtdData); + zsRtdData.put("name", "折算实时数据"); + zsRtdData.put("type", "line"); + zsRtdData.put("data", yZsRtdData); yList.add(zsRtdData); params.clear(); params.put("xList", xList); @@ -185,6 +186,25 @@ public class CountServiceImpl extends AbstractService implements ICountService { return new SuccessResultData<>(params); } + @Override + public SuccessResultData> countReportPollId() { + Map param = getHashMap(2); + List pollIds = dataMinuteService.listPollId(param); + + List> pollDatas = new ArrayList<>(); + for (String pollId : pollIds) { + param.put("pollId", pollId); + Integer count = dataMinuteService.count(param); + Map pollData = getHashMap(4); + pollData.put("name", pollId); + pollData.put("value", count); + pollDatas.add(pollData); + } + param.clear(); + param.put("pollDatas", pollDatas); + return new SuccessResultData<>(param); + } + /** * 获取开始时间 * diff --git a/src/main/java/com/cm/tenlion/pollutantdata/service/dataminute/IDataMinuteService.java b/src/main/java/com/cm/tenlion/pollutantdata/service/dataminute/IDataMinuteService.java index 8d2eb01..962d3bc 100644 --- a/src/main/java/com/cm/tenlion/pollutantdata/service/dataminute/IDataMinuteService.java +++ b/src/main/java/com/cm/tenlion/pollutantdata/service/dataminute/IDataMinuteService.java @@ -2,6 +2,7 @@ package com.cm.tenlion.pollutantdata.service.dataminute; import com.cm.tenlion.pollutantdata.pojo.bos.dataminute.DataMinuteBO; import com.cm.tenlion.pollutantdata.pojo.dtos.dataminute.DataMinuteDTO; +import com.cm.tenlion.pollutantdata.pojo.dtos.dataminute.EnterprisePollDTO; import com.cm.tenlion.pollutantdata.pojo.pos.dataminute.DataMinutePO; import com.cm.tenlion.pollutantdata.pojo.vos.dataminute.DataMinuteVO; import com.cm.common.pojo.ListPage; @@ -201,6 +202,14 @@ public interface IDataMinuteService { */ List listPollId(Map params); + /** + * 污染因子列表 + * + * @param params + * @return + */ + List listEnterprisePollId(Map params); + /** * 最新实时数据 * diff --git a/src/main/java/com/cm/tenlion/pollutantdata/service/dataminute/impl/DataMinuteServiceImpl.java b/src/main/java/com/cm/tenlion/pollutantdata/service/dataminute/impl/DataMinuteServiceImpl.java index 0c30c08..f5377bb 100644 --- a/src/main/java/com/cm/tenlion/pollutantdata/service/dataminute/impl/DataMinuteServiceImpl.java +++ b/src/main/java/com/cm/tenlion/pollutantdata/service/dataminute/impl/DataMinuteServiceImpl.java @@ -3,6 +3,7 @@ package com.cm.tenlion.pollutantdata.service.dataminute.impl; import com.cm.tenlion.pollutantdata.dao.dataminute.IDataMinuteDao; import com.cm.tenlion.pollutantdata.pojo.bos.dataminute.DataMinuteBO; import com.cm.tenlion.pollutantdata.pojo.dtos.dataminute.DataMinuteDTO; +import com.cm.tenlion.pollutantdata.pojo.dtos.dataminute.EnterprisePollDTO; import com.cm.tenlion.pollutantdata.pojo.pos.dataminute.DataMinutePO; import com.cm.tenlion.pollutantdata.pojo.vos.dataminute.DataMinuteVO; import com.cm.tenlion.pollutantdata.service.dataminute.IDataMinuteService; @@ -182,6 +183,11 @@ public class DataMinuteServiceImpl extends AbstractService implements IDataMinut return dataMinuteDao.listPollId(params); } + @Override + public List listEnterprisePollId(Map params) { + return dataMinuteDao.listEnterprisePollId(params); + } + @Override public Double getLastRtd(Map params) { return dataMinuteDao.getLastRtd(params); diff --git a/src/main/java/com/cm/tenlion/pollutantdata/utils/net/TCPHandler.java b/src/main/java/com/cm/tenlion/pollutantdata/utils/net/TCPHandler.java index 6931869..393783b 100644 --- a/src/main/java/com/cm/tenlion/pollutantdata/utils/net/TCPHandler.java +++ b/src/main/java/com/cm/tenlion/pollutantdata/utils/net/TCPHandler.java @@ -3,10 +3,12 @@ package com.cm.tenlion.pollutantdata.utils.net; import com.cm.common.utils.RegexUtil; import com.cm.tenlion.pollutantdata.enums.*; import com.cm.tenlion.pollutantdata.manager.CollectorManager; +import com.cm.tenlion.pollutantdata.pojo.dtos.enterprise.EnterpriseDTO; import com.cm.tenlion.pollutantdata.pojo.dtos.instrument.InstrumentDTO; import com.cm.tenlion.pollutantdata.service.alarmlog.IAlarmLogService; import com.cm.tenlion.pollutantdata.service.collector.ICollectorService; import com.cm.tenlion.pollutantdata.service.dataminute.IDataMinuteService; +import com.cm.tenlion.pollutantdata.service.enterprise.IEnterpriseService; import com.cm.tenlion.pollutantdata.service.instrument.IInstrumentService; import com.cm.tenlion.pollutantdata.service.poll.IPollService; import com.cm.tenlion.pollutantdata.utils.HJ212DataUtil; @@ -40,17 +42,20 @@ import java.net.InetSocketAddress; @Slf4j public class TCPHandler extends SimpleChannelInboundHandler { + private IEnterpriseService enterpriseService; private IInstrumentService instrumentService; private ICollectorService collectorService; private IDataMinuteService dataMinuteService; private IPollService pollService; private IAlarmLogService alarmLogService; - public TCPHandler(IInstrumentService instrumentService, + public TCPHandler(IEnterpriseService enterpriseService, + IInstrumentService instrumentService, ICollectorService collectorService, IDataMinuteService dataMinuteService, IPollService pollService, IAlarmLogService alarmLogService) { + this.enterpriseService = enterpriseService; this.instrumentService = instrumentService; this.collectorService = collectorService; this.dataMinuteService = dataMinuteService; @@ -102,7 +107,7 @@ public class TCPHandler extends SimpleChannelInboundHandler { } InstrumentDTO instrumentDTO = instrumentService.getByMn(data.getMn()); if (instrumentDTO == null) { - log.debug("设备不存在"); + log.debug("采集仪不存在"); new ResponseDefault(ctx, QnRtdEnum.MN_ERROR, ExeRtnEnum.COMMAND_ERROR, needResponse).response(data); return; } @@ -116,6 +121,12 @@ public class TCPHandler extends SimpleChannelInboundHandler { new ResponseDefault(ctx, QnRtdEnum.ST_ERROR, ExeRtnEnum.COMMAND_ERROR, needResponse).response(data); return; } + EnterpriseDTO enterpriseDTO = enterpriseService.get(instrumentDTO.getEnterpriseId()); + if (enterpriseDTO == null) { + log.debug("采集仪的企业不存在"); + new ResponseDefault(ctx, QnRtdEnum.CUSTOM_ENTERPRISE_ERROR, ExeRtnEnum.COMMAND_ERROR, needResponse).response(data); + return; + } if (CnEnum.REAL_TIME.getValue() == data.getCn()) { log.debug("保存实时数据"); RealDataHandler realDataHandler = new RealDataHandler(); @@ -123,7 +134,9 @@ public class TCPHandler extends SimpleChannelInboundHandler { realDataHandler.setPollService(pollService); realDataHandler.setDataMinuteService(dataMinuteService); realDataHandler.setCollectorService(collectorService); + realDataHandler.setAlarmLogService(alarmLogService); realDataHandler.setInstrumentDTO(instrumentDTO); + realDataHandler.setEnterpriseDTO(enterpriseDTO); realDataHandler.handle(data, needResponse, ctx); return; } diff --git a/src/main/java/com/cm/tenlion/pollutantdata/utils/net/TCPServer.java b/src/main/java/com/cm/tenlion/pollutantdata/utils/net/TCPServer.java index f1c6e99..e1624ed 100644 --- a/src/main/java/com/cm/tenlion/pollutantdata/utils/net/TCPServer.java +++ b/src/main/java/com/cm/tenlion/pollutantdata/utils/net/TCPServer.java @@ -3,6 +3,7 @@ package com.cm.tenlion.pollutantdata.utils.net; import com.cm.tenlion.pollutantdata.service.alarmlog.IAlarmLogService; import com.cm.tenlion.pollutantdata.service.collector.ICollectorService; import com.cm.tenlion.pollutantdata.service.dataminute.IDataMinuteService; +import com.cm.tenlion.pollutantdata.service.enterprise.IEnterpriseService; import com.cm.tenlion.pollutantdata.service.instrument.IInstrumentService; import com.cm.tenlion.pollutantdata.service.poll.IPollService; import io.netty.bootstrap.ServerBootstrap; @@ -30,6 +31,7 @@ import java.util.concurrent.TimeUnit; **/ public class TCPServer { + private IEnterpriseService enterpriseService; private IInstrumentService instrumentService; private ICollectorService collectorService; private IDataMinuteService dataMinuteService; @@ -82,7 +84,7 @@ public class TCPServer { } }); // 这里的对象必须new,否则只有第一次有效,其余无法连接,每次执行的后都需要new - pipeline.addLast(new TCPHandler(instrumentService, collectorService, dataMinuteService, pollService, alarmLogService)); + pipeline.addLast(new TCPHandler(enterpriseService, instrumentService, collectorService, dataMinuteService, pollService, alarmLogService)); } }); @@ -101,6 +103,10 @@ public class TCPServer { } } + public void setEnterpriseService(IEnterpriseService enterpriseService) { + this.enterpriseService = enterpriseService; + } + public void setInstrumentService(IInstrumentService instrumentService) { this.instrumentService = instrumentService; } diff --git a/src/main/java/com/cm/tenlion/pollutantdata/utils/net/handle/RealDataHandler.java b/src/main/java/com/cm/tenlion/pollutantdata/utils/net/handle/RealDataHandler.java index 52796e6..72fa78d 100644 --- a/src/main/java/com/cm/tenlion/pollutantdata/utils/net/handle/RealDataHandler.java +++ b/src/main/java/com/cm/tenlion/pollutantdata/utils/net/handle/RealDataHandler.java @@ -1,11 +1,15 @@ package com.cm.tenlion.pollutantdata.utils.net.handle; import com.cm.common.utils.RegexUtil; +import com.cm.tenlion.pollutantdata.enums.BigDataTypeEnum; import com.cm.tenlion.pollutantdata.enums.DataCpFlagEnum; import com.cm.tenlion.pollutantdata.enums.ExeRtnEnum; import com.cm.tenlion.pollutantdata.enums.QnRtdEnum; import com.cm.tenlion.pollutantdata.manager.CollectorManager; +import com.cm.tenlion.pollutantdata.manager.WebSocketManager; +import com.cm.tenlion.pollutantdata.pojo.BigDataWebSocketData; import com.cm.tenlion.pollutantdata.pojo.dtos.collector.CollectorDTO; +import com.cm.tenlion.pollutantdata.pojo.dtos.enterprise.EnterpriseDTO; import com.cm.tenlion.pollutantdata.pojo.dtos.instrument.InstrumentDTO; import com.cm.tenlion.pollutantdata.pojo.pos.poll.PollPO; import com.cm.tenlion.pollutantdata.pojo.vos.alarmlog.AlarmLogVO; @@ -40,6 +44,7 @@ public class RealDataHandler implements IDataHandle { private ICollectorService collectorService; private IPollService pollService; private IDataMinuteService dataMinuteService; + private EnterpriseDTO enterpriseDTO; private InstrumentDTO instrumentDTO; private IAlarmLogService alarmLogService; private String ipAddress; @@ -93,6 +98,8 @@ public class RealDataHandler implements IDataHandle { new ResponseDefault(ctx, QnRtdEnum.CUSTOM_CP_SN_ERROR, ExeRtnEnum.COMMAND_ERROR, isRepo).response(data); return; } + collectorDTO.setEnterpriseName(enterpriseDTO.getEnterpriseName()); + collectorDTO.setInstrumentName(instrumentDTO.getInstrumentName()); DataMinuteVO dataMinuteVO = new DataMinuteVO(); dataMinuteVO.setEnterpriseId(instrumentDTO.getEnterpriseId()); @@ -110,7 +117,7 @@ public class RealDataHandler implements IDataHandle { CollectorManager.getInstance().addCollector(ctx.channel().id().toString(), collectorDTO); // 超过报警值,记录报警日志 if (dataMinuteVO.getRtd() > collectorDTO.getAlarmValue()) { - saveAlarmLog(dataMinuteVO, collectorDTO.getAlarmValue()); + saveAlarmLog(dataMinuteVO, collectorDTO); } new ResponseDefault(ctx, QnRtdEnum.READY, ExeRtnEnum.SUCCESS, isRepo).response(data); @@ -120,10 +127,10 @@ public class RealDataHandler implements IDataHandle { * 保存报警日志 * * @param dataMinuteVO - * @param alarmValue + * @param collectorDTO */ - private void saveAlarmLog(DataMinuteVO dataMinuteVO, double alarmValue) throws Exception { - if (alarmValue < 0) { + private void saveAlarmLog(DataMinuteVO dataMinuteVO, CollectorDTO collectorDTO) throws Exception { + if (collectorDTO.getAlarmValue() < 0) { return; } AlarmLogVO alarmLogVO = new AlarmLogVO(); @@ -132,9 +139,14 @@ public class RealDataHandler implements IDataHandle { alarmLogVO.setCollectorId(dataMinuteVO.getCollectorId()); alarmLogVO.setRtd(dataMinuteVO.getRtd()); alarmLogVO.setZsRtd(dataMinuteVO.getZsRtd()); - alarmLogVO.setAlarmValue(alarmValue); + alarmLogVO.setAlarmValue(collectorDTO.getAlarmValue()); alarmLogVO.setPollId(dataMinuteVO.getPollId()); alarmLogService.save(alarmLogVO); + + // 通知 + String message = String.format("%s %s 的 %s 采集仪数据超标报警", + collectorDTO.getEnterpriseName(), collectorDTO.getInstrumentName(), collectorDTO.getCollectorMn()); + WebSocketManager.getInstance().sendMessage(new BigDataWebSocketData<>(BigDataTypeEnum.ALARM_MESSAGE, message)); } /** @@ -183,6 +195,10 @@ public class RealDataHandler implements IDataHandle { this.dataMinuteService = dataMinuteService; } + public void setEnterpriseDTO(EnterpriseDTO enterpriseDTO) { + this.enterpriseDTO = enterpriseDTO; + } + public void setInstrumentDTO(InstrumentDTO instrumentDTO) { this.instrumentDTO = instrumentDTO; } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index dc7fd1d..cd9b632 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -62,7 +62,7 @@ api-path: # 安全 security: oauth2: - oauth-server: http://192.168.0.106:7001/usercenter + oauth-server: http://192.168.0.103:7001/usercenter oauth-logout: ${security.oauth2.oauth-server}/logout?redirect_uri=${server.url} client: client-id: 74e4b55ad48840f9b4de86ce5da58b53 diff --git a/src/main/resources/mybatis/mapper/collector/collector-mapper.xml b/src/main/resources/mybatis/mapper/collector/collector-mapper.xml index acf862b..803c1d8 100644 --- a/src/main/resources/mybatis/mapper/collector/collector-mapper.xml +++ b/src/main/resources/mybatis/mapper/collector/collector-mapper.xml @@ -176,10 +176,14 @@ pollute_collector t1 WHERE t1.is_delete = 0 - + AND t1.collector_id = #{collectorId} - + + + AND + t1.collector_mn = #{collectorMn} + diff --git a/src/main/resources/mybatis/mapper/dataMinute/dataMinute-mapper.xml b/src/main/resources/mybatis/mapper/dataMinute/dataMinute-mapper.xml index 1fae326..112e39a 100644 --- a/src/main/resources/mybatis/mapper/dataMinute/dataMinute-mapper.xml +++ b/src/main/resources/mybatis/mapper/dataMinute/dataMinute-mapper.xml @@ -68,6 +68,11 @@ + + + + + INSERT INTO pollute_data_minute ( @@ -429,6 +434,10 @@ AND t1.enterprise_id = #{enterpriseId} + + AND + t1.poll_id = #{pollId} + @@ -475,6 +484,35 @@ poll_id + + +