Browse Source

遂昌版本替换

遂昌项目
liangfan 6 months ago
parent
commit
a0205e6213
  1. 81
      hzims-service/suichang/pom.xml
  2. 32
      hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/SuiChangApplication.java
  3. 111
      hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/controller/EcologicalFlowController.java
  4. 72
      hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/controller/ExamController.java
  5. 41
      hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/controller/FlowWarnController.java
  6. 69
      hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/controller/ImageAndVideoController.java
  7. 56
      hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/controller/StatisticsFlowDataController.java
  8. 43
      hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/feign/SuichangClient.java
  9. 33
      hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/mapper/EcologicalFlowMapper.java
  10. 104
      hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/mapper/EcologicalFlowMapper.xml
  11. 39
      hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/mapper/ImageAndVideoMapper.java
  12. 61
      hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/mapper/ImageAndVideoMapper.xml
  13. 36
      hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/service/EcologicalFlowService.java
  14. 37
      hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/service/ExamStationDataService.java
  15. 26
      hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/service/FlowWarnService.java
  16. 53
      hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/service/ImageAndVideoService.java
  17. 56
      hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/service/RealMonitorService.java
  18. 20
      hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/service/StatisticsDataService.java
  19. 491
      hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/service/impl/EcologicalFlowServiceImpl.java
  20. 274
      hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/service/impl/ExamStationDataServiceImpl.java
  21. 75
      hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/service/impl/FlowWarnServiceImpl.java
  22. 198
      hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/service/impl/ImageAndVideoServiceImpl.java
  23. 419
      hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/service/impl/RealMonitorServiceImpl.java
  24. 169
      hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/service/impl/StatisticsDataServiceImpl.java
  25. 16
      hzims-service/suichang/src/main/resources/application.yml

81
hzims-service/suichang/pom.xml

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.hnac.hzims</groupId>
<artifactId>hzims-service</artifactId>
<version>4.0.0-SNAPSHOT</version>
</parent>
<artifactId>suichang</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-core-boot</artifactId>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-starter-swagger</artifactId>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-starter-oss-all</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-core-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-core-auto</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.hnac.hzims</groupId>
<artifactId>suichang-api</artifactId>
<version>${hzims.project.version}</version>
</dependency>
<dependency>
<groupId>com.hnac.hzinfo.data</groupId>
<artifactId>hzinfo-data-sdk</artifactId>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-resource-api</artifactId>
</dependency>
<dependency>
<groupId>com.hnac.hzims</groupId>
<artifactId>hzims-operational-api</artifactId>
<version>${hzims.project.version}</version>
</dependency>
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>com.hnac.hzims</groupId>
<artifactId>message-alarm-api</artifactId>
<version>${hzims.project.version}</version>
</dependency>
</dependencies>
</project>

32
hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/SuiChangApplication.java

@ -0,0 +1,32 @@
package com.hnac.hzims.suichang;
import org.mybatis.spring.annotation.MapperScan;
import org.springblade.core.cloud.feign.EnableBladeFeign;
import org.springblade.core.launch.BladeApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.context.annotation.ComponentScan;
@EnableBladeFeign(basePackages = {"org.springblade", "com.hnac"})
@SpringCloudApplication
@MapperScan("com.hnac.hzims.**.mapper.**")
@ComponentScan(basePackages = {"com.hnac.hzims.*"})
public class SuiChangApplication extends SpringBootServletInitializer {
public final static String APP_NAME = "suichang";
// static {
// System.setProperty("spring.cloud.nacos.discovery.server-addr", "http://43.139.178.151:8848");
// System.setProperty("spring.cloud.nacos.config.server-addr", "http://43.139.178.151:8848");
// System.setProperty("spring.cloud.nacos.username", "nacos");
// System.setProperty("spring.cloud.nacos.password", "nacos");
// }
public static void main(String[] args) {
BladeApplication.run(APP_NAME, SuiChangApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return BladeApplication.createSpringApplicationBuilder(builder, APP_NAME, SuiChangApplication.class);
}
}

111
hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/controller/EcologicalFlowController.java

@ -0,0 +1,111 @@
package com.hnac.hzims.suichang.controller;
import com.hnac.hzims.suichang.service.EcologicalFlowService;
import com.hnac.hzims.suichang.service.RealMonitorService;
import com.hnac.hzims.suichang.util.MemoryPagination;
import com.hnac.hzims.suichang.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
/**
* 遂昌生态流量
*
* @author liangfan
*/
@RestController
@RequestMapping("/ecologicalFlow")
@Api(value = "遂昌生态流量", tags = "遂昌生态流量接口")
public class EcologicalFlowController {
@Autowired
private EcologicalFlowService ecologicalFlowService;
@Autowired
private RealMonitorService realMonitorService;
@RequestMapping(value = "/getEcologicalFlowIndexInfo", method = {RequestMethod.POST})
@ApiOperation(notes = "遂昌生态流量", value = "遂昌生态流量")
public R getEcologicalFlowIndexInfo() {
EcologicalFlowVo vo = ecologicalFlowService.getEcologicalFlowIndexInfo();
return R.data(vo);
}
@RequestMapping(value = "/getAvgMonitorInfo", method = {RequestMethod.POST})
@ApiOperation(notes = "实时监测日均流量", value = "实时监测日均流量")
public R getAvgMonitorInfo() {
return R.data(realMonitorService.getAvgMonitorInfo());
}
@RequestMapping(value = "/getAvgMonitorCountInfo", method = {RequestMethod.POST})
@ApiOperation(notes = "生态流量监管-日均流量", value = "生态流量监管-日均流量")
public R getAvgMonitorCountInfo(@RequestBody AvgMonitorReq req) {
List<AvgMonitorCountVo> resultList = realMonitorService.getAvgMonitorCountInfo(req);
// 内存分页
HashMap<String, Object> map = new HashMap<>();
resultList = MemoryPagination.pagination(resultList, req.getCurrent(), req.getSize());
map.put("records", resultList);
map.put("total", resultList.size());
return R.data(map);
}
@RequestMapping(value = "/getRealMonitorInfo", method = {RequestMethod.GET})
@ApiOperation(notes = "实时流量页面", value = "实时流量页面")
public R getRealMonitorInfo(String name, Query query) {
RealMonitorRes res = realMonitorService.getRealMonitorInfo(name);
List<RealMonitorVo> resultList = res.getRealMonitorVos();
HashMap<String, Object> map = new HashMap<>();
resultList = MemoryPagination.pagination(resultList, query.getCurrent(), query.getSize());
map.put("records", resultList);
map.put("total", resultList.size());
map.put("reportCount", res.getReportCount());
return R.data(map);
}
@RequestMapping(value = "/getRealMonitorSingleInfo", method = {RequestMethod.POST})
@ApiOperation(notes = "单个电站实时流量明细", value = "单个电站实时流量明细")
public R getRealMonitorSingleInfo(@RequestBody RealMonitorSingleInfoReq req) {
List<RealMonitorSingleInfoVo> resultList = realMonitorService.getRealMonitorSingleInfo(req);
HashMap<String, Object> map = new HashMap<>();
resultList = MemoryPagination.pagination(resultList, req.getCurrent(), req.getSize());
map.put("records", resultList);
map.put("total", resultList.size());
return R.data(map);
}
@RequestMapping(value = "/exportRealMonitorInfo", method = {RequestMethod.GET})
@ApiOperation(notes = "导出实时流量页面数据", value = "导出实时流量页面数据")
public void exportRealMonitorInfo(HttpServletResponse response, String name) {
realMonitorService.exportRealMonitorInfo(response, name);
}
@RequestMapping(value = "/exportRealMonitorSingleInfo", method = {RequestMethod.GET})
@ApiOperation(notes = "导出单个电站实时流量明细", value = "导出单个电站实时流量明细")
public void exportRealMonitorSingleInfo(HttpServletResponse response, RealMonitorSingleInfoReq req) {
realMonitorService.exportRealMonitorSingleInfo(response, req);
}
@RequestMapping(value = "/exportAvgMonitorCountInfo", method = {RequestMethod.GET})
@ApiOperation(notes = "导出生态流量监管-日均流量", value = "导出生态流量监管-日均流量")
public void exportAvgMonitorCountInfo(HttpServletResponse response, AvgMonitorReq req) {
realMonitorService.exportAvgMonitorCountInfo(response, req);
}
@RequestMapping(value = "/getRealData", method = {RequestMethod.GET})
public R test(String deviceCode) {
return R.data(realMonitorService.getRealData(deviceCode));
}
}

72
hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/controller/ExamController.java

@ -0,0 +1,72 @@
package com.hnac.hzims.suichang.controller;
import com.hnac.hzims.common.logs.utils.StringUtils;
import com.hnac.hzims.suichang.service.ExamStationDataService;
import com.hnac.hzims.suichang.util.MemoryPagination;
import com.hnac.hzims.suichang.vo.ExamStationFlowDataReq;
import com.hnac.hzims.suichang.vo.ExamStationFlowReportDayVo;
import com.hnac.hzims.suichang.vo.ExamStationFlowReportVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
/**
* @Author: liangfan
* @Date: 2024-03-15 15:08
* @Description:
*/
@RestController
@RequestMapping("/exam")
@Api(value = "遂昌生态流量-考核管理", tags = "遂昌生态流量-考核管理")
public class ExamController {
@Autowired
private ExamStationDataService examStationDataService;
@RequestMapping(value = "/examStationFlowReportByTime", method = {RequestMethod.GET})
@ApiOperation(notes = "电站月考核", value = "电站月考核")
public R examStatisticsFlowReportByTime(ExamStationFlowDataReq req) {
List<ExamStationFlowReportVo> resultList =
examStationDataService.examStationFlowReportByTime(req);
HashMap<String, Object> map = new HashMap<>();
resultList = MemoryPagination.pagination(resultList, req.getCurrent(), req.getSize());
map.put("records", resultList);
map.put("total", resultList.size());
return R.data(map);
}
@RequestMapping(value = "/exportExamStationFlowReportByTime", method = {RequestMethod.GET})
@ApiOperation(notes = "电站月考核", value = "电站月考核")
public void exportExamStationFlowReportByTime(HttpServletResponse response, ExamStationFlowDataReq req) {
examStationDataService.exportExamStationFlowReportByTime(response, req);
}
@RequestMapping(value = "/examStationFlowReportOfDay", method = {RequestMethod.GET})
@ApiOperation(notes = "电站日考核", value = "电站日考核")
public R examStationFlowReportOfDay(ExamStationFlowDataReq req) {
List<ExamStationFlowReportDayVo> resultList = examStationDataService.examStationFlowReportOfDay(req);
String isPass = req.getIsPass();
// 条件过滤
if (StringUtils.isNotBlank(req.getIsPass())) {
resultList =
resultList.stream().filter(o -> o.getStatus().equals(isPass)).collect(Collectors.toList());
}
HashMap<String, Object> map = new HashMap<>();
resultList = MemoryPagination.pagination(resultList, req.getCurrent(), req.getSize());
map.put("records", resultList);
map.put("total", resultList.size());
return R.data(map);
}
}

41
hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/controller/FlowWarnController.java

@ -0,0 +1,41 @@
package com.hnac.hzims.suichang.controller;
import com.hnac.hzims.suichang.service.FlowWarnService;
import com.hnac.hzims.suichang.vo.FlowWarnQueryDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* 遂昌生态流量
*
* @author liangfan
*/
@RestController
@RequestMapping("/flowWarn")
@Api(value = "遂昌生态流量预警信息", tags = "遂昌生态流量预警信息")
public class FlowWarnController {
@Autowired
private FlowWarnService flowWarnService;
@RequestMapping(value = "/getFlowWarnList", method = {RequestMethod.GET})
@ApiOperation(notes = "大屏遂昌生态流量预警信息", value = "大屏遂昌生态流量预警信息")
public R getFlowWarnList(FlowWarnQueryDTO dto, Query query) {
return R.data(flowWarnService.getFlowWarnList(dto, query));
}
@RequestMapping(value = "/warningPush", method = {RequestMethod.GET})
@ApiOperation(notes = "大屏遂昌生态流量预警信息", value = "大屏遂昌生态流量预警信息")
public R warningPush(FlowWarnQueryDTO dto) {
return R.data(flowWarnService.warningPush(dto));
}
}

69
hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/controller/ImageAndVideoController.java

@ -0,0 +1,69 @@
package com.hnac.hzims.suichang.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hnac.hzims.suichang.service.ImageAndVideoService;
import com.hnac.hzims.suichang.vo.ImageReq;
import com.hnac.hzims.suichang.vo.MissingImagesRes;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
* @Author: liangfan
* @Date: 2024-03-15 15:08
* @Description:
*/
@RestController
@RequestMapping("/imageAndVideo")
@Api(value = "图片和视频", tags = "图片和视频")
public class ImageAndVideoController {
@Autowired
private ImageAndVideoService imageAndVideoService;
@RequestMapping(value = "/getMissingImagesInfo", method = {RequestMethod.GET})
@ApiOperation(notes = "照片缺失率", value = "照片缺失率")
public R<IPage<MissingImagesRes>> getMissingImagesInfo(ImageReq req, Query query) {
return R.data(imageAndVideoService.getMissingImagesInfo(req, query));
}
@RequestMapping(value = "/missingPush", method = {RequestMethod.GET})
@ApiOperation(notes = "照片缺失日期及数据", value = "照片缺失日期及数据")
public R missingPush(ImageReq req) {
return R.data(imageAndVideoService.missingPush(req));
}
@RequestMapping(value = "/getImageInfoStatus", method = {RequestMethod.POST})
@ApiOperation(notes = "照片缺失率详情", value = "照片缺失率详情")
public R getImageInfoStatus(@RequestBody ImageReq req) {
return R.data(imageAndVideoService.getImageInfoStatus(req));
}
@RequestMapping(value = "/getImageInfoByDeviceCode", method = {RequestMethod.GET})
@ApiOperation(notes = "根据DeviceCode及时间查询照片", value = "根据DeviceCode及时间查询照片")
public R getImageInfoByDeviceCode(ImageReq req, Query query) {
return R.data(imageAndVideoService.getImageInfoByDeviceCode(req, query));
}
@RequestMapping(value = "/selectNewestImage", method = {RequestMethod.GET})
@ApiOperation(notes = "泄放照片", value = "泄放照片")
public R selectNewestImage(ImageReq req, Query query) {
return R.data(imageAndVideoService.selectNewestImage(req, query));
}
@RequestMapping(value = "/getStationVideoType", method = {RequestMethod.GET, RequestMethod.POST})
@ApiOperation(value = "获取视频byType", notes = "获取视频byType")
public R getStationTree(String videoType) {
return R.data(imageAndVideoService.getStationVideoType(videoType));
}
}

56
hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/controller/StatisticsFlowDataController.java

@ -0,0 +1,56 @@
package com.hnac.hzims.suichang.controller;
import com.hnac.hzims.suichang.service.StatisticsDataService;
import com.hnac.hzims.suichang.util.MemoryPagination;
import com.hnac.hzims.suichang.vo.StatisticsFlowDataDetailVo;
import com.hnac.hzims.suichang.vo.StatisticsFlowDataReq;
import com.hnac.hzims.suichang.vo.StatisticsFlowDataVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
/**
* @Author: liangfan
* @Date: 2024-03-14 16:18
* @Description:
*/
@RestController
@RequestMapping("/statisticsData")
@Api(value = "遂昌生态流量-统计报表", tags = "遂昌生态流量-统计报表")
public class StatisticsFlowDataController {
@Autowired
private StatisticsDataService statisticsDataService;
@RequestMapping(value = "/statisticsFlowReportByTime", method = {RequestMethod.GET})
@ApiOperation(notes = "", value = "")
public R statisticsFlowReportByTime(StatisticsFlowDataReq req) {
StatisticsFlowDataVo res = statisticsDataService.statisticsFlowReportByTime(req);
List<StatisticsFlowDataDetailVo> resultList = res.getDetail();
HashMap<String, Object> map = new HashMap<>();
// 内存分页
resultList = MemoryPagination.pagination(resultList, req.getCurrent(), req.getSize());
map.put("areaName", res.getAreaName());
map.put("examCount", res.getExamCount());
map.put("passCount", res.getPassCount());
map.put("passPre", res.getPassPre());
map.put("records", resultList);
map.put("total", resultList.size());
return R.data(map);
}
@RequestMapping(value = "/exportStatisticsFlowReportByTime", method = {RequestMethod.GET})
@ApiOperation(notes = "", value = "")
public void exportStatisticsFlowReportByTime(HttpServletResponse response, StatisticsFlowDataReq req) {
statisticsDataService.exportStatisticsFlowReportByTime(response, req);
}
}

43
hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/feign/SuichangClient.java

@ -0,0 +1,43 @@
package com.hnac.hzims.suichang.feign;
import com.hnac.hzims.suichang.mapper.EcologicalFlowMapper;
import com.hnac.hzims.suichang.service.EcologicalFlowService;
import com.hnac.hzims.suichang.vo.StationQueryReq;
import com.hnac.hzims.suichang.vo.StationVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/suichangClient")
@Slf4j
@RequiredArgsConstructor
public class SuichangClient implements ISuichangClient {
@Autowired
private EcologicalFlowMapper ecologicalFlowMapper;
@Autowired
private EcologicalFlowService ecologicalFlowService;
@Override
@PostMapping(GET_STATION_BY_REQ)
public List<StationVo> getStationListByReq(StationQueryReq req) {
return ecologicalFlowMapper.getStationListByReq(req);
}
@Override
@PostMapping(GET_DATA)
public List<Map<String, Object>> getData(String stcd, Integer accessRules, Integer saveTimeType, Integer timeInterval,
LocalDateTime startTime, LocalDateTime endTime) {
return ecologicalFlowService.getData(stcd, accessRules, saveTimeType, timeInterval,
startTime, endTime);
}
}

33
hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/mapper/EcologicalFlowMapper.java

@ -0,0 +1,33 @@
package com.hnac.hzims.suichang.mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hnac.hzims.message_alarm.entity.MessageAlarmInfo;
import com.hnac.hzims.message_alarm.entity.MessageReceiveInfo;
import com.hnac.hzims.suichang.vo.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springblade.system.user.entity.User;
import java.util.List;
/**
* 遂昌生态流量
*
* @author liangfan
*/
@Mapper
public interface EcologicalFlowMapper {
List<StationVo> getStationListByName(String name);
IPage<StationVo> getStationListByNamePage(StationQueryReq req, IPage page);
List<StationVo> getStationListByReq(@Param("req") StationQueryReq req);
IPage<FlowWarnVo> getFlowWarnList(FlowWarnQueryDTO dto, IPage page);
List<FlowWarnVo> getFlowWarnCount(FlowWarnQueryDTO dto);
}

104
hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/mapper/EcologicalFlowMapper.xml

@ -0,0 +1,104 @@
<?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.hnac.hzims.suichang.mapper.EcologicalFlowMapper">
<sql id="Base_Station_Select" >
SELECT
a.name as name,
a.code as deviceCode,
a.discharge as flowValue,
a.type as stationType,
a.LGTD as lgtd,
a.LTTD as lttd
FROM
hzims_operation.hzims_station a
WHERE
a.IS_DELETED = '0'
</sql>
<select id="getStationListByName" resultType="com.hnac.hzims.suichang.vo.StationVo">
<include refid="Base_Station_Select"/>
<if test="name != null and name != ''">
AND a.name like concat('%',#{name},'%')
</if>
</select>
<select id="getStationListByNamePage" resultType="com.hnac.hzims.suichang.vo.StationVo">
<include refid="Base_Station_Select"/>
<if test="req.name != null and req.name != ''">
AND a.name like concat('%',#{req.name},'%')
</if>
</select>
<select id="getStationListByReq" resultType="com.hnac.hzims.suichang.vo.StationVo">
<include refid="Base_Station_Select"/>
<if test="req.name != null and req.name != ''">
AND a.name like concat('%',#{req.name},'%')
</if>
<if test="req.stationType != null and req.stationType != ''">
AND a.type = #{req.stationType}
</if>
</select>
<select id="getFlowWarnList" resultType="com.hnac.hzims.suichang.vo.FlowWarnVo">
SELECT
c.`NAME`,
a.content,
a.send_time as sendTime,
b.receive_user_id as receiveUserId,
b.receive_user_name as receiveUserName,
a.object_source as objectSource,
a.object_code as objectCode,
a.alarm_level as alarmLevel
FROM
message_alarm.`message_alarm_info` a
JOIN message_alarm.`message_receive_info` b ON a.id = b.message_id
LEFT JOIN hzims_operation.hzims_station c ON c.`CODE` = a.object_code
WHERE
b.message_type = 'flowWarn'
<if test="dto.startTime != null and dto.startTime != ''">
AND a.send_time &gt;= #{dto.startTime}
</if>
<if test="dto.endTime != null and dto.endTime != ''">
AND a.send_time &lt;= #{dto.endTime}
</if>
<if test="dto.objectCode != null and dto.objectCode != ''">
AND a.object_code = #{dto.objectCode}
</if>
</select>
<select id="getFlowWarnCount" resultType="com.hnac.hzims.suichang.vo.FlowWarnVo">
SELECT
c.`NAME`,
a.content,
a.send_time as sendTime,
b.receive_user_id as receiveUserId,
b.receive_user_name as receiveUserName,
a.object_source as objectSource,
a.object_code as objectCode,
a.alarm_level as alarmLevel
FROM
message_alarm.`message_alarm_info` a
JOIN message_alarm.`message_receive_info` b ON a.id = b.message_id
LEFT JOIN hzims_operation.hzims_station c ON c.`CODE` = a.object_code
WHERE
b.message_type = 'flowWarn'
<if test="startTime != null and startTime != ''">
AND a.send_time &gt;= #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND a.send_time &lt;= #{endTime}
</if>
<if test="objectCode != null and objectCode != ''">
AND a.object_code = #{objectCode}
</if>
GROUP BY
a.id
</select>
</mapper>

39
hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/mapper/ImageAndVideoMapper.java

@ -0,0 +1,39 @@
package com.hnac.hzims.suichang.mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hnac.hzims.suichang.vo.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 遂昌生态流量
*
* @author liangfan
*/
@Mapper
public interface ImageAndVideoMapper {
IPage<ImageVo> getImageInfo(ImageReq req, IPage page);
/**
* 根据设备stcds查询各个设备最新图片信息
* @param req
* @param page
* @return
*/
IPage<ImageVo> selectNewestImage(ImageReq req, IPage page);
/**
* 查询视频点位
* @param videoType
* @return
*/
List<StationTypeVo> selectStationTypeByOwerType(String videoType);
}

61
hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/mapper/ImageAndVideoMapper.xml

@ -0,0 +1,61 @@
<?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.hnac.hzims.suichang.mapper.ImageAndVideoMapper">
<select id="getImageInfo" resultType="com.hnac.hzims.suichang.vo.ImageVo">
SELECT
b.`name`,
a.*
FROM
base_info.`image_info` a
LEFT JOIN hzinfo_data.hzinfo_data_device b ON a.STCD = b.CODE
WHERE
1 = 1
AND b.is_deleted = '0'
AND a.`DATA` IS NOT NULL
<if test="req.startTime != null and req.startTime != ''">
AND a.time &gt;= #{req.startTime}
</if>
<if test="req.endTime != null and req.endTime != ''">
AND a.time &lt;= #{req.endTime}
</if>
<if test="req.deviceCode != null and req.deviceCode != ''">
AND a.stcd = #{req.deviceCode}
</if>
ORDER BY a.time asc
</select>
<select id="selectNewestImage" resultType="com.hnac.hzims.suichang.vo.ImageVo">
SELECT
c.`name`,
a.*
FROM
base_info.image_info AS a
JOIN hzinfo_data.hzinfo_data_device c ON a.STCD = c.`CODE`
JOIN ( SELECT stcd, max( b.time ) AS time FROM base_info.image_info AS b WHERE DATA IS NOT NULL GROUP BY b.stcd ) AS b ON a.stcd = b.stcd
WHERE
1 = 1
AND a.time = b.time
AND c.is_deleted = '0'
<if test="req.deviceCode != null and req.deviceCode != ''">
AND a.stcd = #{req.deviceCode}
</if>
</select>
<select id="selectStationTypeByOwerType" resultType="com.hnac.hzims.suichang.vo.StationTypeVo">
SELECT
*
FROM
hzims_operation.hzims_station_video_type
WHERE
is_deleted = 0
<if test="type != null and type != ''">
AND video_type = #{videoType}
</if>
ORDER BY
sort
</select>
</mapper>

36
hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/service/EcologicalFlowService.java

@ -0,0 +1,36 @@
package com.hnac.hzims.suichang.service;
import com.hnac.hzims.suichang.vo.EcologicalFlowVo;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
/**
* @Author: liangfan
* @Date: 2024-03-08 15:06
* @Description:
*/
public interface EcologicalFlowService {
/**
* 首页生态流量
*
* @return
*/
EcologicalFlowVo getEcologicalFlowIndexInfo();
/**
* 查询历史数据
* @param stcd
* @param accessRules 取数规则0=最早值1=最大值2=最小值3=平均值4=(累计值/和值)5=(变化值/差值)6=最新值")
* @param saveTimeType 周期类型: 0-> s() 1->m()2->h(小时) 3->d() 4->w() 5->n(自然月)6->y(自然年)
* @param timeInterval
* @param startTime
* @param endTime
* @return
*/
List<Map<String, Object>> getData(String stcd, Integer accessRules, Integer saveTimeType, Integer timeInterval,
LocalDateTime startTime, LocalDateTime endTime);
}

37
hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/service/ExamStationDataService.java

@ -0,0 +1,37 @@
package com.hnac.hzims.suichang.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hnac.hzims.suichang.vo.*;
import org.springblade.core.mp.support.Query;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* @Author: liangfan
* @Date: 2024-03-08 15:06
* @Description:
*/
public interface ExamStationDataService {
/**
* 电站月考核
* @param req
* @return
*/
List<ExamStationFlowReportVo> examStationFlowReportByTime(ExamStationFlowDataReq req);
/**
* 电站月考核 导出
* @param req
* @return
*/
void exportExamStationFlowReportByTime(HttpServletResponse response, ExamStationFlowDataReq req);
/**
* 流量计电站日考核
* @param req
* @return
*/
List<ExamStationFlowReportDayVo> examStationFlowReportOfDay(ExamStationFlowDataReq req);
}

26
hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/service/FlowWarnService.java

@ -0,0 +1,26 @@
package com.hnac.hzims.suichang.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hnac.hzims.suichang.vo.FlowWarnQueryDTO;
import com.hnac.hzims.suichang.vo.FlowWarnVo;
import org.springblade.core.mp.support.Query;
import java.util.List;
import java.util.Map;
/**
* @author liangfan
*/
public interface FlowWarnService {
IPage<FlowWarnVo> getFlowWarnList(FlowWarnQueryDTO dto, Query query);
/**
* 分页查询预警信息及告警信息
* @param dto
* @return
*/
Map<String, Map<String, Integer>> warningPush(FlowWarnQueryDTO dto);
}

53
hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/service/ImageAndVideoService.java

@ -0,0 +1,53 @@
package com.hnac.hzims.suichang.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hnac.hzims.suichang.vo.*;
import org.springblade.core.mp.support.Query;
import java.util.List;
import java.util.Map;
/**
* @Author: liangfan
* @Date: 2024-03-08 15:06
* @Description:
*/
public interface ImageAndVideoService {
/**
* 照片缺失率信息
* @param req
* @param query
* @return
*/
IPage<MissingImagesRes> getMissingImagesInfo(ImageReq req, Query query);
/**
* 照片条数 日期
* @param req
* @return
*/
Map<String, Map<String, Integer>> missingPush(ImageReq req);
/**
* 泄放照片详情
* @param req
* @param query
* @return
*/
IPage<ImageVo> getImageInfoByDeviceCode(ImageReq req, Query query);
/**
* 照片缺失率详情
* @param req
* @return
*/
List<ImageVo> getImageInfoStatus(ImageReq req);
IPage<ImageVo> selectNewestImage(ImageReq req, Query query);
List<StationTreeRes> getStationVideoType(String videoType);
}

56
hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/service/RealMonitorService.java

@ -0,0 +1,56 @@
package com.hnac.hzims.suichang.service;
import com.hnac.hzims.suichang.vo.*;
import com.hnac.hzinfo.datasearch.analyse.domain.FieldsData;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
* @Author: liangfan
* @Date: 2024-03-13 16:37
* @Description:
*/
public interface RealMonitorService {
/**
* 查询日均流量数据
*/
List<AvgMonitorVo> getAvgMonitorInfo();
/**
* 查询一段时间的日均流量数据
* @param req
* @return
*/
List<AvgMonitorCountVo> getAvgMonitorCountInfo(AvgMonitorReq req);
/**
* 实时流量列表页面
* @return
*/
RealMonitorRes getRealMonitorInfo(String name);
void exportRealMonitorInfo(HttpServletResponse response, String name);
void exportRealMonitorSingleInfo(HttpServletResponse response, RealMonitorSingleInfoReq req);
void exportAvgMonitorCountInfo(HttpServletResponse response, AvgMonitorReq req);
/**
* 实时流量列表页面单个电站
* @return
*/
List<RealMonitorSingleInfoVo> getRealMonitorSingleInfo(RealMonitorSingleInfoReq req);
/**
* 查询实时流量数据
* @param stcd
* @return
*/
String getRealData(String stcd, String signage);
String getRealData(String stcd);
}

20
hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/service/StatisticsDataService.java

@ -0,0 +1,20 @@
package com.hnac.hzims.suichang.service;
import com.hnac.hzims.suichang.vo.StatisticsFlowDataReq;
import com.hnac.hzims.suichang.vo.StatisticsFlowDataVo;
import javax.servlet.http.HttpServletResponse;
/**
* @Author: liangfan
* @Date: 2024-03-08 15:06
* @Description:
*/
public interface StatisticsDataService {
StatisticsFlowDataVo statisticsFlowReportByTime(StatisticsFlowDataReq req);
void exportStatisticsFlowReportByTime(HttpServletResponse response, StatisticsFlowDataReq req);
}

491
hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/service/impl/EcologicalFlowServiceImpl.java

@ -0,0 +1,491 @@
package com.hnac.hzims.suichang.service.impl;
import com.hnac.hzims.entity.ReportData;
import com.hnac.hzims.suichang.mapper.EcologicalFlowMapper;
import com.hnac.hzims.suichang.service.EcologicalFlowService;
import com.hnac.hzims.suichang.util.DateUtil;
import com.hnac.hzims.suichang.vo.EcologicalFlowVo;
import com.hnac.hzims.suichang.vo.FlowWarnQueryDTO;
import com.hnac.hzims.suichang.vo.FlowWarnVo;
import com.hnac.hzims.suichang.vo.StationVo;
import com.hnac.hzims.util.CommonUtil;
import com.hnac.hzinfo.datasearch.analyse.po.AnalyseCodeByAnalyseDataPO;
import com.hnac.hzinfo.datasearch.analyse.po.AnalyzeDataConditionPO;
import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO;
import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeDataConditionVO;
import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeInstanceFieldVO;
import com.hnac.hzinfo.sdk.analyse.AnalyseDataSearchClient;
import com.hnac.hzinfo.sdk.core.response.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.*;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
/**
* @Author: liangfan
* @Date: 2024-03-08 15:06
* @Description:
*/
@Slf4j
@Service
public class EcologicalFlowServiceImpl implements EcologicalFlowService {
@Autowired
AnalyseDataSearchClient analyseDataSearchClient;
@Autowired
private EcologicalFlowMapper ecologicalFlowMapper;
@Value("${suichang.signage}")
String signage;
@Override
public EcologicalFlowVo getEcologicalFlowIndexInfo() {
LocalDateTime startTime = LocalDateTime.now();
EcologicalFlowVo ecologicalFlowVo = new EcologicalFlowVo();
// 监测电站数 无节制电站 流量计电站 1.无节制电站 2.流量计电站
List<StationVo> stationInfoList = ecologicalFlowMapper.getStationListByName(null);
List<StationVo> noLimitStationListSize = stationInfoList.stream().filter(o -> "1".equals(o.getStationType())).collect(Collectors.toList());
List<StationVo> flowStationListSize = stationInfoList.stream().filter(o -> "2".equals(o.getStationType())).collect(Collectors.toList());
if (CollectionUtils.isEmpty(stationInfoList)) {
return ecologicalFlowVo;
}
ecologicalFlowVo.setAllStationListSize(stationInfoList.size());
ecologicalFlowVo.setNoLimitStationListSize(noLimitStationListSize.size());
ecologicalFlowVo.setFlowStationListSize(flowStationListSize.size());
int yesterdayFinishCount = 0, weekCount = 0, monthFinishCount = 0, quarterCount = 0, halfYearCount = 0, yearCount = 0,
reportTodayCount = 0, reportYesTerdayCount = 0, warnTodayCount = 0, warnYesTerdayCount = 0;
// 得到所有设备实例code及核定下限流量
log.info("站点信息list:{}", stationInfoList);
// 多线程优化
List<CompletableFuture<Integer>> yesterdayFinishCountList = new ArrayList<>();
List<CompletableFuture<Integer>> weekCountList = new ArrayList<>();
List<CompletableFuture<Integer>> monthFinishCountList = new ArrayList<>();
List<CompletableFuture<Integer>> quarterCountList = new ArrayList<>();
List<CompletableFuture<Integer>> halfYearCountList = new ArrayList<>();
List<CompletableFuture<Integer>> yearCountList = new ArrayList<>();
List<CompletableFuture<Map<String, Integer>>> reportAndWarnTodayMapList = new ArrayList<>();
List<CompletableFuture<Map<String, Integer>>> reportAndWarnYesTerdayMapList = new ArrayList<>();
// 多线程 调用平台方法
buildCompletableFutureList(stationInfoList, yesterdayFinishCountList, weekCountList, monthFinishCountList,
quarterCountList, halfYearCountList, yearCountList, reportAndWarnTodayMapList, reportAndWarnYesTerdayMapList);
try {
for (int i = 0; i < stationInfoList.size(); i++) {
// 1.昨日达标情况 达标率就是有没有达到核定下限流量
yesterdayFinishCount = yesterdayFinishCountList.get(i).get() + yesterdayFinishCount;
// 2.上月达标情况
weekCount = weekCountList.get(i).get() + weekCount;
// 3.上周达标情况
monthFinishCount = monthFinishCountList.get(i).get() + monthFinishCount;
// 4.季度达标情况
quarterCount = quarterCountList.get(i).get() + quarterCount;
// 5.半年达标情况
halfYearCount = halfYearCountList.get(i).get() + halfYearCount;
// 6.年达标情况
yearCount = yearCountList.get(i).get() + yearCount;
// 7.今日 预警数 上报率
Map<String, Integer> reportAndWarnTodayMap = reportAndWarnTodayMapList.get(i).get();
reportTodayCount = reportTodayCount + reportAndWarnTodayMap.get("count");
warnTodayCount = warnTodayCount + reportAndWarnTodayMap.get("warnCount");
// 8.昨日 预警数 上报率
Map<String, Integer> reportAndWarnYesTerdayMap = reportAndWarnYesTerdayMapList.get(i).get();
reportYesTerdayCount = reportYesTerdayCount + reportAndWarnYesTerdayMap.get("count");
warnYesTerdayCount = warnYesTerdayCount + reportAndWarnYesTerdayMap.get("warnCount");
}
} catch (Exception e) {
e.printStackTrace();
}
log.info("yesterdayFinishCount = {}, weekCount = {}, monthFinishCount = {}, quarterCount = {}, halfYearCount = {}, yearCount = {}",
yesterdayFinishCount, weekCount, monthFinishCount, quarterCount, halfYearCount, yearCount);
// build返回信息
buildRestultInfo(ecologicalFlowVo, stationInfoList.size(),
yesterdayFinishCount, monthFinishCount, weekCount, quarterCount, halfYearCount,
yearCount, reportTodayCount, warnTodayCount, reportYesTerdayCount, warnYesTerdayCount);
LocalDateTime endTime = LocalDateTime.now();
log.info("耗时:{}", ChronoUnit.SECONDS.between(startTime, endTime));
return ecologicalFlowVo;
}
@Override
public List<Map<String, Object>> getData(String stcd, Integer accessRules, Integer saveTimeType, Integer timeInterval,
LocalDateTime startTime, LocalDateTime endTime) {
List<Map<String, Object>> list = new ArrayList<>();
List<AnalyzeInstanceFieldVO> vos = getSignages(stcd);
if (vos == null || vos.isEmpty()) {
return null;
}
Map<String, List<ReportData>> map = new HashMap<>();
int count = 0;
for (AnalyzeInstanceFieldVO vo : vos) {
// accessRules 取数规则:0=最早值、1=最大值、2=最小值、3=平均值、4=(累计值/和值)、5=(变化值/差值)6=最新值")
// SaveTimeType 周期类型: 0-> s(秒) 1->、m(分)、2->h(小时) 3->、d(天) 4->、w(周) 5->、n(自然月)、6->y(自然年)
List<ReportData> reportDataList =
getDataByDeviceCode(stcd, accessRules, saveTimeType, timeInterval, startTime, endTime, vo.getSignage());
map.put(vo.getSignage(), reportDataList);
count = reportDataList.size();
}
for (int i = 0; i < count; i++) {
Map<String, Object> res = new HashMap<>();
for (AnalyzeInstanceFieldVO vo : vos) {
List<ReportData> reportDataList = map.get(vo.getSignage());
ReportData reportData = reportDataList.get(i);
res.put("tm", reportData.getKeyStr());
res.put(vo.getSignage(), reportData.getVal());
}
list.add(res);
}
return list;
}
List<ReportData> getDataByDeviceCode(String deviceCode, Integer accessRules, Integer saveTimeType, Integer timeInterval,
LocalDateTime start, LocalDateTime end, String col) {
List<ReportData> reportData = new ArrayList<>();
AnalyseCodeByAnalyseDataPO po = new AnalyseCodeByAnalyseDataPO();
po.setDeviceCode(deviceCode);
List<AnalyzeDataConditionPO> signboardConditions = new ArrayList<>();
AnalyzeDataConditionPO conditionPO = new AnalyzeDataConditionPO();
conditionPO.setBeginTime(start);
conditionPO.setEndTime(end);
conditionPO.setSignages(col);
// conditionPO.setKeepFigures(3);
conditionPO.setAccessRules(accessRules);
conditionPO.setSaveTimeType(saveTimeType);
conditionPO.setTimeInterval(timeInterval);
conditionPO.setFull(1);
signboardConditions.add(conditionPO);
po.setSignboardConditions(signboardConditions);
Result<List<AnalyzeDataConditionVO>> result = analyseDataSearchClient.getAnalyzeDataByAnalyzeCodeAndSignages(po);
if (result == null || !result.isSuccess()) {
return reportData;
}
List<AnalyzeDataConditionVO> datas = result.getData();
if (datas == null || datas.isEmpty()) {
return reportData;
}
for (AnalyzeDataConditionVO vo : datas) {
List<AnalyseDataTaosVO> dataTaosVOs = vo.getList();
for (AnalyseDataTaosVO vv : dataTaosVOs) {
if (vo.getSignage().equals(col)) {
ReportData data = new ReportData();
data.setKeyStr(CommonUtil.getKeyBySaveTimeType(vv.getTs(), saveTimeType));
String val = vv.getVal();
data.setStcd(deviceCode);
data.setVal(val);
if (val != null && !"".equals(val)) {
data.setValue(Double.valueOf(vv.getVal()));
} else {
data.setValue(0.0);
}
data.setName(vo.getName());
reportData.add(data);
}
}
}
return reportData;
}
public List<AnalyzeInstanceFieldVO> getSignages(String stcd) {
//查询列
Result<List<AnalyzeInstanceFieldVO>> result =
analyseDataSearchClient.getInstanceFieldByAnalyseCode(stcd, 1, "");
if (result == null || !result.isSuccess()) {
return null;
}
List<AnalyzeInstanceFieldVO> analyzeInstanceFieldVOS = result.getData();
return analyzeInstanceFieldVOS;
}
int getDayInfo(String stcd, BigDecimal discharge) {
// 获取当前时间
LocalDateTime now = LocalDateTime.now();
// 获取昨天的日期
LocalDateTime last = now.minusDays(1);
// 昨天的开始时间(00:00) 昨天的结束时间(00:00)yesterday: 2024-03-10 00:00:00 yesterday: 2024-03-11 00:00:00
LocalDateTime startTime = last.withHour(0).withMinute(0).withSecond(0).withNano(0);
LocalDateTime endTime = last.plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
// 昨日达标情况 达标率就是有没有达到核定下限流量
// accessRules 取数规则:0=最早值、1=最大值、2=最小值、3=平均值、4=(累计值/和值)、5=(变化值/差值)6=最新值")
// SaveTimeType 周期类型: 0-> s(秒) 1->、m(分)、2->h(小时) 3->、d(天) 4->、w(周) 5->、n(自然月)、6->y(自然年)
List<Map<String, Object>> dataList = getData(stcd, 3, 3, 1, startTime, endTime);
log.info("昨日达标情况data: {}, 设备编码为:{}", dataList, stcd);
return getCount(dataList, discharge);
}
int getWeekInfo(String stcd, BigDecimal discharge) {
LocalDate today = LocalDate.now();
// 获取上周的星期一(假设周一是周的开始)
LocalDate lastWeekMonday = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)).minusWeeks(1);
// 上周的开始时间:上周星期一的00:00
LocalDateTime startTime = LocalDateTime.of(lastWeekMonday, LocalTime.MIN);
LocalDateTime endTime = startTime.plusDays(7).withHour(0).withMinute(0).withSecond(0).withNano(0);
// 周达标情况 达标率就是有没有达到核定下限流量
// accessRules 取数规则:0=最早值、1=最大值、2=最小值、3=平均值、4=(累计值/和值)、5=(变化值/差值)6=最新值")
// SaveTimeType 周期类型: 0-> s(秒) 1->、m(分)、2->h(小时) 3->、d(天) 4->、w(周) 5->、n(自然月)、6->y(自然年)
List<Map<String, Object>> dataList = getData(stcd, 3, 4, 1, startTime, endTime);
log.info("周达标情况data: {}, 设备编码为:{}", dataList, stcd);
return getCount(dataList, discharge);
}
int getMouthInfo(String stcd, BigDecimal discharge) {
// 获取当前时间
LocalDateTime now = LocalDateTime.now();
// 获取上个月的开始日期
LocalDateTime last = now.minusMonths(1);
// 上个月的开始时间(00:00) 上个月的结束时间(00:00)
LocalDateTime startTime = last.withHour(0).withDayOfMonth(1).withMinute(0).withSecond(0).withNano(0);
LocalDateTime endTime = last.plusMonths(1).withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
// 上月达标情况 达标率就是有没有达到核定下限流量
// accessRules 取数规则:0=最早值、1=最大值、2=最小值、3=平均值、4=(累计值/和值)、5=(变化值/差值)6=最新值")
// SaveTimeType 周期类型: 0-> s(秒) 1->、m(分)、2->h(小时) 3->、d(天) 4->、w(周) 5->、n(自然月)、6->y(自然年)
List<Map<String, Object>> dataList = getData(stcd, 3, 5, 1, startTime, endTime);
log.info("月达标情况data: {}, 设备编码为:{}", dataList, stcd);
return getCount(dataList, discharge);
}
int getQuarterInfo(String stcd, BigDecimal discharge) {
LocalDateTime now = LocalDateTime.now();
LocalDateTime startTime = DateUtil.getStartOfLastQuarter(now);
LocalDateTime endTime = DateUtil.getEndOfLastQuarter(now);
// 周达标情况 达标率就是有没有达到核定下限流量
// accessRules 取数规则:0=最早值、1=最大值、2=最小值、3=平均值、4=(累计值/和值)、5=(变化值/差值)6=最新值")
// SaveTimeType 周期类型: 0-> s(秒) 1->、m(分)、2->h(小时) 3->、d(天) 4->、w(周) 5->、n(自然月)、6->y(自然年)
List<Map<String, Object>> dataList = getData(stcd, 3, 5, 3, startTime, endTime);
log.info("季度达标情况data: {}, 设备编码为:{}", dataList, stcd);
return getCount(dataList, discharge);
}
int getHaltYearInfo(String stcd, BigDecimal discharge) {
LocalDateTime now = LocalDateTime.now();
LocalDateTime startTime = DateUtil.getStartOfHalfYear(now);
LocalDateTime endTime = DateUtil.getEndOfHalfYear(now);
// 上月达标情况 达标率就是有没有达到核定下限流量
// accessRules 取数规则:0=最早值、1=最大值、2=最小值、3=平均值、4=(累计值/和值)、5=(变化值/差值)6=最新值")
// SaveTimeType 周期类型: 0-> s(秒) 1->、m(分)、2->h(小时) 3->、d(天) 4->、w(周) 5->、n(自然月)、6->y(自然年)
List<Map<String, Object>> dataList = getData(stcd, 3, 5, 6, startTime, endTime);
log.info("半年达标情况data: {}, 设备编码为:{}", dataList, stcd);
return getCount(dataList, discharge);
}
int getYearInfo(String stcd, BigDecimal discharge) {
LocalDateTime startTime = LocalDateTime.of(Year.now().getValue() - 1, Month.JANUARY, 1, 0, 0);
LocalDateTime endTime = LocalDateTime.of(Year.now().getValue(), Month.JANUARY, 1, 0, 0, 0);
// 上月达标情况 达标率就是有没有达到核定下限流量
// accessRules 取数规则:0=最早值、1=最大值、2=最小值、3=平均值、4=(累计值/和值)、5=(变化值/差值)6=最新值")
// SaveTimeType 周期类型: 0-> s(秒) 1->、m(分)、2->h(小时) 3->、d(天) 4->、w(周) 5->、n(自然月)、6->y(自然年)
List<Map<String, Object>> dataList = getData(stcd, 3, 6, 1, startTime, endTime);
log.info("去年达标情况data: {}, 设备编码为:{}", dataList, stcd);
return getCount(dataList, discharge);
}
Map<String, Integer> reportAndWarnToday(String stcd) {
// 获取当前时间
LocalDateTime now = LocalDateTime.now();
LocalDateTime startTime = now.withHour(0).withMinute(0).withSecond(0).withNano(0);
LocalDateTime endTime = now;
// accessRules 取数规则:0=最早值、1=最大值、2=最小值、3=平均值、4=(累计值/和值)、5=(变化值/差值)6=最新值")
// SaveTimeType 周期类型: 0-> s(秒) 1->、m(分)、2->h(小时) 3->、d(天) 4->、w(周) 5->、n(自然月)、6->y(自然年)
List<Map<String, Object>> dataList = getData(stcd, 3, 2, 1, startTime, endTime);
log.info("今天上报data: {}, 设备编码为:{}", dataList, stcd);
int count = 0;
if (!CollectionUtils.isEmpty(dataList)) {
for (Map<String, Object> info : dataList) {
String ecologicalFlowValue = null == info.get(signage) ? null :
info.get(signage).toString();
log.info("ecologicalFlowValue的值: {}", ecologicalFlowValue);
if (StringUtils.isNotBlank(ecologicalFlowValue)) {
count++;
}
}
}
HashMap<String, Integer> map = new HashMap<>();
map.put("count", count);
FlowWarnQueryDTO dto = new FlowWarnQueryDTO();
dto.setStartTime(DateUtil.getStringTime(startTime));
dto.setEndTime(DateUtil.getStringTime(endTime));
dto.setObjectCode(stcd);
List<FlowWarnVo> flowWarnList = ecologicalFlowMapper.getFlowWarnCount(dto);
if (CollectionUtils.isEmpty(flowWarnList)) {
map.put("warnCount", 0);
} else {
map.put("warnCount", flowWarnList.size());
}
return map;
}
Map<String, Integer> reportAndWarnYesTerday(String stcd) {
// 获取当前时间
LocalDateTime now = LocalDateTime.now();
// 获取昨天的日期
LocalDateTime last = now.minusDays(1);
// 昨天的开始时间(00:00) 昨天的结束时间(00:00)yesterday: 2024-03-10 00:00:00 yesterday: 2024-03-11 00:00:00
LocalDateTime startTime = last.withHour(0).withMinute(0).withSecond(0).withNano(0);
LocalDateTime endTime = last.plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
// accessRules 取数规则:0=最早值、1=最大值、2=最小值、3=平均值、4=(累计值/和值)、5=(变化值/差值)6=最新值")
// SaveTimeType 周期类型: 0-> s(秒) 1->、m(分)、2->h(小时) 3->、d(天) 4->、w(周) 5->、n(自然月)、6->y(自然年)
List<Map<String, Object>> dataList = getData(stcd, 3, 2, 1, startTime, endTime);
log.info("昨天上报data: {}, 设备编码为:{}", dataList, stcd);
int count = 0;
if (!CollectionUtils.isEmpty(dataList)) {
for (Map<String, Object> info : dataList) {
String ecologicalFlowValue = null == info.get(signage) ? null :
info.get(signage).toString();
log.info("ecologicalFlowValue的值: {}", ecologicalFlowValue);
if (StringUtils.isNotBlank(ecologicalFlowValue)) {
count++;
}
}
}
HashMap<String, Integer> map = new HashMap<>();
map.put("count", count);
FlowWarnQueryDTO dto = new FlowWarnQueryDTO();
dto.setStartTime(DateUtil.getStringTime(startTime));
dto.setEndTime(DateUtil.getStringTime(endTime));
dto.setObjectCode(stcd);
Query query = new Query();
query.setCurrent(1);
query.setSize(10000);
List<FlowWarnVo> flowWarnList = ecologicalFlowMapper.getFlowWarnList(dto, Condition.getPage(query)).getRecords();
if (CollectionUtils.isEmpty(flowWarnList)) {
map.put("warnCount", 0);
} else {
map.put("warnCount", flowWarnList.size());
}
return map;
}
int getCount(List<Map<String, Object>> dataList, BigDecimal discharge) {
int count = 0;
if (!CollectionUtils.isEmpty(dataList)) {
Map<String, Object> info = dataList.get(dataList.size() - 1);
String ecologicalFlowValue = null == info.get(signage) ? "0" :
info.get(signage).toString();
log.info("ecologicalFlowValue的值: {}", ecologicalFlowValue);
if (new BigDecimal(ecologicalFlowValue).compareTo(discharge) >= 0) {
count++;
}
}
return count;
}
/**
* bulid info
* @param stationInfoList
* @param yesterdayFinishCountList
* @param weekCountList
* @param monthFinishCountList
* @param quarterCountList
* @param halfYearCountList
* @param yearCountList
* @param reportAndWarnTodayMapList
* @param reportAndWarnYesTerdayMapList
*/
void buildCompletableFutureList(List<StationVo> stationInfoList,
List<CompletableFuture<Integer>> yesterdayFinishCountList ,
List<CompletableFuture<Integer>> weekCountList ,
List<CompletableFuture<Integer>> monthFinishCountList ,
List<CompletableFuture<Integer>> quarterCountList ,
List<CompletableFuture<Integer>> halfYearCountList ,
List<CompletableFuture<Integer>> yearCountList ,
List<CompletableFuture<Map<String, Integer>>> reportAndWarnTodayMapList ,
List<CompletableFuture<Map<String, Integer>>> reportAndWarnYesTerdayMapList ){
for (int i = 0; i < stationInfoList.size(); i++) {
StationVo vo = stationInfoList.get(i);
// String stcd = "JSCZ001";
// 设备编号 核定流量
String stcd = vo.getDeviceCode();
BigDecimal discharge = vo.getFlowValue();
// 1.昨日达标情况 达标率就是有没有达到核定下限流量
yesterdayFinishCountList.add(CompletableFuture.supplyAsync(() -> getDayInfo(stcd, discharge)));
// 2.上周达标情况
weekCountList.add(CompletableFuture.supplyAsync(() -> getMouthInfo(stcd, discharge)));
// 3.上月达标情况
monthFinishCountList.add(CompletableFuture.supplyAsync(() -> getWeekInfo(stcd, discharge)));
// 4.季度达标情况
quarterCountList.add(CompletableFuture.supplyAsync(() -> getQuarterInfo(stcd, discharge)));
// 5.半年达标情况
halfYearCountList.add(CompletableFuture.supplyAsync(() -> getHaltYearInfo(stcd, discharge)));
// 6.年达标情况
yearCountList.add(CompletableFuture.supplyAsync(() -> getYearInfo(stcd, discharge)));
// 7.今日 预警数 上报率
reportAndWarnTodayMapList.add(CompletableFuture.supplyAsync(() -> reportAndWarnToday(stcd)));
// 8.昨日 预警数 上报率
reportAndWarnYesTerdayMapList.add(CompletableFuture.supplyAsync(() -> reportAndWarnYesTerday(stcd)));
}
}
void buildRestultInfo(EcologicalFlowVo ecologicalFlowVo, Integer size, Integer yesterdayFinishCount,
Integer monthFinishCount, Integer weekCount, Integer quarterCount, Integer halfYearCount,
Integer yearCount, Integer reportTodayCount, Integer warnTodayCount,
Integer reportYesTerdayCount, Integer warnYesTerdayCount) {
// 昨日
BigDecimal yesterdayFinishPer = BigDecimal.valueOf(yesterdayFinishCount).divide(BigDecimal.valueOf(size), 2, RoundingMode.HALF_UP);
ecologicalFlowVo.setYesterdayFinishPer(yesterdayFinishPer.multiply(BigDecimal.valueOf(100)) + "%");
ecologicalFlowVo.setYesterdayFinishCount(yesterdayFinishCount);
// 上月
BigDecimal monthFinishPer = BigDecimal.valueOf(monthFinishCount).divide(BigDecimal.valueOf(size), 2, RoundingMode.HALF_UP);
ecologicalFlowVo.setMonthFinishPer(monthFinishPer.multiply(BigDecimal.valueOf(100)) + "%");
ecologicalFlowVo.setMonthFinishCount(monthFinishCount);
// 上周
BigDecimal weekFinishPer = BigDecimal.valueOf(weekCount).divide(BigDecimal.valueOf(size), 2, RoundingMode.HALF_UP);
ecologicalFlowVo.setWeekFinishPer(weekFinishPer.multiply(BigDecimal.valueOf(100)) + "%");
// 季度
BigDecimal quarterFinishPer = BigDecimal.valueOf(quarterCount).divide(BigDecimal.valueOf(size), 2, RoundingMode.HALF_UP);
ecologicalFlowVo.setQuarterFinishPer(quarterFinishPer.multiply(BigDecimal.valueOf(100)) + "%");
// 半年
BigDecimal halfYearFinishPer = BigDecimal.valueOf(halfYearCount).divide(BigDecimal.valueOf(size), 2, RoundingMode.HALF_UP);
ecologicalFlowVo.setHalfYearFinishPer(halfYearFinishPer.multiply(BigDecimal.valueOf(100)) + "%");
// 一年
BigDecimal yearFinishPer = BigDecimal.valueOf(yearCount).divide(BigDecimal.valueOf(size), 2, RoundingMode.HALF_UP);
ecologicalFlowVo.setYearFinishPer(yearFinishPer.multiply(BigDecimal.valueOf(100)) + "%");
// 今天预警数 上报率
// 计算几天过了几个小时
long hoursPassedToday = DateUtil.getHoursPassedToday() + 1;
BigDecimal reportTodayPre;
reportTodayPre = BigDecimal.valueOf(reportTodayCount).divide(BigDecimal.valueOf(hoursPassedToday * size), 2, RoundingMode.HALF_UP);
ecologicalFlowVo.setReportTodayPre(reportTodayPre.multiply(BigDecimal.valueOf(100)) + "%");
ecologicalFlowVo.setWarnTodayCount(warnTodayCount);
// 昨天预警数 上报率
BigDecimal reportYesTerdayPre = BigDecimal.valueOf(reportYesTerdayCount).divide(BigDecimal.valueOf(24L * size), 2, RoundingMode.HALF_UP);
ecologicalFlowVo.setReportYesTerdayPre(reportYesTerdayPre.multiply(BigDecimal.valueOf(100)) + "%");
ecologicalFlowVo.setWarnYesTerdayCount(warnYesTerdayCount);
}
}

274
hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/service/impl/ExamStationDataServiceImpl.java

@ -0,0 +1,274 @@
package com.hnac.hzims.suichang.service.impl;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.hnac.hzims.suichang.mapper.EcologicalFlowMapper;
import com.hnac.hzims.suichang.service.EcologicalFlowService;
import com.hnac.hzims.suichang.service.ExamStationDataService;
import com.hnac.hzims.suichang.service.RealMonitorService;
import com.hnac.hzims.suichang.util.DateUtil;
import com.hnac.hzims.suichang.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
/**
* @Author: liangfan
* @Date: 2024-03-14 16:19
* @Description:
*/
@Slf4j
@Service
public class ExamStationDataServiceImpl implements ExamStationDataService {
@Autowired
private EcologicalFlowMapper ecologicalFlowMapper;
@Autowired
private EcologicalFlowService ecologicalFlowService;
@Autowired
private RealMonitorService realMonitorService;
@Value("${suichang.signage}")
String signage;
@Value("${suichang.passPreValue}")
String passPreValue;
@Value("${suichang.timeSignage}")
String timeSignage;
@Override
public List<ExamStationFlowReportVo> examStationFlowReportByTime(ExamStationFlowDataReq req) {
StationQueryReq queryReq = new StationQueryReq();
queryReq.setStationType(req.getStationType());
queryReq.setName(req.getName());
// 查询电站
List<StationVo> list = ecologicalFlowMapper.getStationListByReq(queryReq);
List<ExamStationFlowReportVo> result = new ArrayList<>();
// 根据电站查询日均流量
for (StationVo stationRelationVo : list) {
// String stcd = "JSCZ001";
String stcd = stationRelationVo.getDeviceCode();
LocalDateTime startTime = DateUtil.getStartTime(req.getStartTime());
LocalDateTime endTime = DateUtil.getEndTimeByDay(req.getEndTime());
// accessRules 取数规则:0=最早值、1=最大值、2=最小值、3=平均值、4=(累计值/和值)、5=(变化值/差值)6=最新值")
// SaveTimeType 周期类型: 0-> s(秒) 1->、m(分)、2->h(小时) 3->、d(天) 4->、w(周) 5->、n(自然月)、6->y(自然年)
List<Map<String, Object>> dataList = ecologicalFlowService.getData(stcd, 3, 3, 1, startTime, endTime);
long days = ChronoUnit.DAYS.between(startTime, endTime);
log.info("dataList: {}, 设备编码为:{}, 天数:{}", dataList, stcd, days);
// 合格情况
BigDecimal flowValue = stationRelationVo.getFlowValue();
List<ExamStationFlowReportDetailVo> infos = new ArrayList<>();
int passCount = 0;
if (!CollectionUtils.isEmpty(dataList)) {
// 为了处理特殊返回情况 多查出一条数据的问题
if (dataList.size() > days) {
dataList.remove(0);
}
for (Map<String, Object> info : dataList) {
ExamStationFlowReportDetailVo detailVo = new ExamStationFlowReportDetailVo();
detailVo.setIsPass("不合格");
String ecologicalFlowValue = null == info.get(signage) ? "0" :
info.get(signage).toString();
log.info("ecologicalFlowValue的值: {}", ecologicalFlowValue);
if (new BigDecimal(ecologicalFlowValue).compareTo(flowValue) >= 0) {
passCount++;
detailVo.setIsPass("合格");
}
detailVo.setFlowValue(flowValue);
detailVo.setEcologicalFlowValue(new BigDecimal(ecologicalFlowValue));
detailVo.setTm(info.get(timeSignage).toString());
infos.add(detailVo);
}
}
ExamStationFlowReportVo examStationFlowReportVo = new ExamStationFlowReportVo();
examStationFlowReportVo.setName(stationRelationVo.getName());
examStationFlowReportVo.setAreaName("遂昌县");
examStationFlowReportVo.setFlowValue(flowValue);
examStationFlowReportVo.setInfos(infos);
examStationFlowReportVo.setPassCount(passCount);
examStationFlowReportVo.setCount(days);
BigDecimal pre = BigDecimal.valueOf(passCount).divide(BigDecimal.valueOf(days), 2, RoundingMode.HALF_UP);
examStationFlowReportVo.setPassPre(pre.multiply(BigDecimal.valueOf(100)) + "%");
String isPass = pre.compareTo(new BigDecimal(passPreValue)) >= 0 ? "合格" : "不合格";
examStationFlowReportVo.setIsPass(isPass);
result.add(examStationFlowReportVo);
}
return result;
}
@Override
public void exportExamStationFlowReportByTime(HttpServletResponse response, ExamStationFlowDataReq req) {
List<ExamStationFlowReportVo> examStationFlowReportVos = this.examStationFlowReportByTime(req);
// 动态生成的表头
List<String> firstHead = new ArrayList<>(Arrays.asList("电站名称", "所属区域", "核定流量"));
List<String> endHead = new ArrayList<>(Arrays.asList("合格天数(天)", "考核天数(天)", "合格率", "是否合格"));
List<String> allList = new ArrayList<>();
allList.addAll(firstHead);
if (!CollectionUtils.isEmpty(examStationFlowReportVos)) {
ExamStationFlowReportVo examStationFlowReportVo = examStationFlowReportVos.get(0);
List<ExamStationFlowReportDetailVo> infos = examStationFlowReportVo.getInfos();
List<String> mindHead = infos.stream().map(ExamStationFlowReportDetailVo::getTm).collect(Collectors.toList());
allList.addAll(mindHead);
}
allList.addAll(endHead);
List<List<String>> head = allList.stream().map(v -> {
List<String> list = new ArrayList<>();
list.add(v);
return list;
}).collect(Collectors.toList());
// 组合数据
List<List<String>> contentLists = new ArrayList<>();
examStationFlowReportVos.forEach(o -> {
List<String> list = new ArrayList<>();
list.add(o.getName());
list.add(o.getAreaName());
list.add(o.getFlowValue().toString());
List<ExamStationFlowReportDetailVo> exVo = o.getInfos();
exVo.forEach(k -> {
list.add(k.getIsPass());
});
list.add(o.getPassCount().toString());
list.add(o.getCount().toString());
list.add(o.getPassPre());
list.add(o.getIsPass());
contentLists.add(list);
});
try {
//设置xlsx格式
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("电站月考核" + ".xlsx", "UTF-8"));
EasyExcel.write(response.getOutputStream()).autoCloseStream(Boolean.TRUE).head(head).autoTrim(true)
.sheet(1, "电站月考核").registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
.doWrite(contentLists);
response.getOutputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public List<ExamStationFlowReportDayVo> examStationFlowReportOfDay(ExamStationFlowDataReq req) {
LocalDateTime startYesTodayTime = DateUtil.getStartTime(req.getStartTime()).minusDays(1);
LocalDateTime endYesTodayTime = DateUtil.getEndTimeByDay(req.getStartTime()).minusDays(1);
LocalDateTime startTime = DateUtil.getStartTime(req.getStartTime());
LocalDateTime endTime = DateUtil.getEndTimeByDay(req.getStartTime());
StationQueryReq queryReq = new StationQueryReq();
queryReq.setStationType(req.getStationType());
queryReq.setName(req.getName());
// 查询电站
List<StationVo> list = ecologicalFlowMapper.getStationListByReq(queryReq);
List<ExamStationFlowReportDayVo> result = new ArrayList<>();
if (!CollectionUtils.isEmpty(list)) {
// 多线程优化
List<CompletableFuture<BigDecimal>> yesTerDayAvgFlowValueList = new ArrayList<>();
List<CompletableFuture<BigDecimal>> todayAvgFlowValueList = new ArrayList<>();
List<CompletableFuture<String>> realFlowValueList = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
String stcd = list.get(i).getDeviceCode();
yesTerDayAvgFlowValueList.add(CompletableFuture.supplyAsync(() -> getAvgOneDayData(stcd, startYesTodayTime, endYesTodayTime)));
todayAvgFlowValueList.add(CompletableFuture.supplyAsync(() -> getAvgOneDayData(stcd, startTime, endTime)));
realFlowValueList.add(CompletableFuture.supplyAsync(() -> realMonitorService.getRealData(stcd, signage)));
}
for (int i = 0; i < list.size(); i++) {
BigDecimal yesTerDayAvgFlowValue = null;
BigDecimal todayAvgFlowValue = null;
String realFlowValue = null;
try {
// 前日日均流量
yesTerDayAvgFlowValue = yesTerDayAvgFlowValueList.get(i).get();
// 当日日均流量
todayAvgFlowValue = todayAvgFlowValueList.get(i).get();
// 实时流量
realFlowValue = realFlowValueList.get(i).get();
} catch (Exception e) {
e.printStackTrace();
}
result.add(buildVo(list.get(i), yesTerDayAvgFlowValue, realFlowValue, todayAvgFlowValue));
}
}
return result;
}
/**
* 计算单日日均流量
*
* @param stcd
* @return
*/
BigDecimal getAvgOneDayData(String stcd, LocalDateTime startTime, LocalDateTime endTime) {
long days = ChronoUnit.DAYS.between(startTime, endTime);
// accessRules 取数规则:0=最早值、1=最大值、2=最小值、3=平均值、4=(累计值/和值)、5=(变化值/差值)6=最新值")
// SaveTimeType 周期类型: 0-> s(秒) 1->、m(分)、2->h(小时) 3->、d(天) 4->、w(周) 5->、n(自然月)、6->y(自然年)
List<Map<String, Object>> dataList =
ecologicalFlowService.getData(stcd, 3, 3, 1, startTime, endTime);
log.info("dataList: {}, 设备编码为:{}, 开始:{}, 结束 {}, 天数:{}", dataList, stcd, startTime, endTime, days);
if (!CollectionUtils.isEmpty(dataList)) {
// 为了处理特殊返回情况 多查出一条数据的问题
if (dataList.size() > days) {
dataList.remove(0);
}
Map<String, Object> info = dataList.get(0);
String ecologicalFlowValue = null == info.get(signage) ? "0" :
info.get(signage).toString();
log.info("ecologicalFlowValue的值: {}", ecologicalFlowValue);
return new BigDecimal(ecologicalFlowValue);
}
return BigDecimal.ZERO;
}
/**
* build vo
* @param stationRelationVo
* @param yesTerDayAvgFlowValue
* @param realFlowValue
* @param todayAvgFlowValue
* @return
*/
ExamStationFlowReportDayVo buildVo(StationVo stationRelationVo, BigDecimal yesTerDayAvgFlowValue, String realFlowValue, BigDecimal todayAvgFlowValue) {
ExamStationFlowReportDayVo vo = new ExamStationFlowReportDayVo();
vo.setName(stationRelationVo.getName());
vo.setAreaName("遂昌县");
vo.setFlowValue(stationRelationVo.getFlowValue());
vo.setYesTerDayAvgFlowValue(yesTerDayAvgFlowValue);
vo.setRealFlowValue(new BigDecimal(realFlowValue));
vo.setToDayAvgFlowValue(todayAvgFlowValue);
BigDecimal realOutFlow = todayAvgFlowValue.multiply(new BigDecimal(86400));
BigDecimal outFlow = stationRelationVo.getFlowValue().multiply(new BigDecimal(86400));
vo.setRealOutFlow(realOutFlow);
vo.setOutFlow(outFlow);
BigDecimal dayOutFlowPre = realOutFlow.divide(outFlow, 2, RoundingMode.HALF_UP);
String status = "未达标";
if (dayOutFlowPre.compareTo(new BigDecimal(passPreValue)) >= 0) {
status = "达标";
}
vo.setStatus(status);
vo.setDayOutFlowPre(dayOutFlowPre.multiply(new BigDecimal(100)) + "%");
return vo;
}
}

75
hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/service/impl/FlowWarnServiceImpl.java

@ -0,0 +1,75 @@
package com.hnac.hzims.suichang.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hnac.hzims.suichang.mapper.EcologicalFlowMapper;
import com.hnac.hzims.suichang.service.FlowWarnService;
import com.hnac.hzims.suichang.vo.FlowWarnQueryDTO;
import com.hnac.hzims.suichang.vo.FlowWarnVo;
import com.hnac.hzims.suichang.vo.StationQueryReq;
import com.hnac.hzims.suichang.vo.StationVo;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.utils.Func;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Service
public class FlowWarnServiceImpl implements FlowWarnService {
@Autowired
private EcologicalFlowMapper ecologicalFlowMapper;
@Override
public IPage<FlowWarnVo> getFlowWarnList(FlowWarnQueryDTO dto, Query query) {
return ecologicalFlowMapper.getFlowWarnList(dto, Condition.getPage(query));
}
@Override
public Map<String, Map<String, Integer>> warningPush(FlowWarnQueryDTO dto) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
List<StationVo> stationList = ecologicalFlowMapper.getStationListByReq(new StationQueryReq());
LocalDateTime startTime = LocalDateTime.parse(dto.getStartTime(), formatter);
LocalDateTime endTime = LocalDateTime.parse(dto.getEndTime(), formatter);
List<LocalDateTime> dayList = new ArrayList<>();
while (!startTime.isAfter(endTime)) {
dayList.add(startTime);
startTime = startTime.plusDays(1);
}
Query query = new Query();
query.setCurrent(1);
query.setSize(10000);
List<FlowWarnVo> list = ecologicalFlowMapper.getFlowWarnList(dto, Condition.getPage(query)).getRecords();
Map<String, Map<String, Integer>> stationMap = new HashMap<>();
for (StationVo station : stationList) {
Map<String, Integer> dayMap = new LinkedHashMap<>();
List<FlowWarnVo> flowWarnVos =
list.stream().filter(var -> var.getObjectCode().equals(station.getDeviceCode())).collect(Collectors.toList());
for (int i = 0; i < dayList.size() - 1; i++) {
int degree = 0;
for (FlowWarnVo flowWarnVo : flowWarnVos) {
LocalDateTime warningTime =
LocalDateTime.parse(flowWarnVo.getSendTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
if (Func.isEmpty(warningTime)) {
continue;
}
if (warningTime.isAfter(dayList.get(i)) && warningTime.isBefore(dayList.get(i + 1))) {
degree = degree + 1;
}
}
dayMap.put(dayList.get(i).format(formatter), degree);
}
stationMap.put(station.getDeviceCode(), dayMap);
}
return stationMap;
}
}

198
hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/service/impl/ImageAndVideoServiceImpl.java

@ -0,0 +1,198 @@
package com.hnac.hzims.suichang.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hnac.hzims.suichang.mapper.EcologicalFlowMapper;
import com.hnac.hzims.suichang.mapper.ImageAndVideoMapper;
import com.hnac.hzims.suichang.service.ImageAndVideoService;
import com.hnac.hzims.suichang.util.DateUtil;
import com.hnac.hzims.suichang.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Author: liangfan
* @Date: 2024-03-14 16:19
* @Description:
*/
@Slf4j
@Service
public class ImageAndVideoServiceImpl implements ImageAndVideoService {
@Autowired
private EcologicalFlowMapper ecologicalFlowMapper;
@Autowired
private ImageAndVideoMapper imageAndVideoMapper;
@Override
public Page<MissingImagesRes> getMissingImagesInfo(ImageReq req, Query query) {
StationQueryReq stationQueryReq = new StationQueryReq();
stationQueryReq.setName(req.getName());
// 拿到电站列表
IPage<StationVo> stationListByNamePage =
ecologicalFlowMapper.getStationListByNamePage(stationQueryReq, Condition.getPage(query));
Page<MissingImagesRes> page = new Page<>();
BeanUtils.copyProperties(stationListByNamePage, page);
List<MissingImagesRes> resultList = new ArrayList<>();
DateTimeFormatter customFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime dateTime = LocalDateTime.parse(req.getStartTime(), customFormatter);
// 结合 LocalDate 和 LocalTime 创建 LocalDateTime 对象
stationListByNamePage.getRecords().forEach(o -> {
MissingImagesRes res = new MissingImagesRes();
res.setDeviceCode(o.getDeviceCode());
res.setName(o.getName());
res.setArea("遂昌县");
res.setMonth(String.valueOf(dateTime.getMonthValue()));
resultList.add(res);
});
page.setRecords(resultList);
return page;
}
@Override
public Map<String, Map<String, Integer>> missingPush(ImageReq req) {
StationQueryReq stationQueryReq = new StationQueryReq();
stationQueryReq.setName(req.getName());
List<StationVo> stationList = ecologicalFlowMapper.getStationListByReq(stationQueryReq);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime startTime = LocalDateTime.parse(req.getStartTime(), formatter);
LocalDateTime endTime = LocalDateTime.parse(req.getEndTime(), formatter);
List<LocalDateTime> dayList = new ArrayList<>();
while (!startTime.isAfter(endTime)) {
dayList.add(startTime);
startTime = startTime.plusDays(1);
}
// 查询时间段内的所有照片数据
Query query = new Query();
query.setCurrent(1);
query.setSize(10000);
List<ImageVo> imageInfoList = imageAndVideoMapper.getImageInfo(req, Condition.getPage(query)).getRecords();
Map<String, Map<String, Integer>> stationMap = new HashMap<>();
for (StationVo station : stationList) {
Map<String, Integer> dayMap = new LinkedHashMap<>();
List<ImageVo> infos =
imageInfoList.stream().filter(o -> o.getStcd().equals(station.getDeviceCode())).collect(Collectors.toList());
for (int i = 0; i < dayList.size() - 1; i++) {
int degree = 0;
for (ImageVo info : infos) {
LocalDateTime warningTime =
LocalDateTime.parse(info.getTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
if (Func.isEmpty(warningTime)) {
continue;
}
if (!warningTime.isBefore(dayList.get(i)) && !warningTime.isAfter(dayList.get(i + 1))) {
degree = degree + 1;
}
}
dayMap.put(dayList.get(i).format(formatter), degree);
}
stationMap.put(station.getDeviceCode(), dayMap);
}
return stationMap;
}
@Override
public IPage<ImageVo> getImageInfoByDeviceCode(ImageReq req, Query query) {
// 根据deviceCode和时间段查询照片列表
return imageAndVideoMapper.getImageInfo(req, Condition.getPage(query));
}
@Override
public List<ImageVo> getImageInfoStatus(ImageReq req) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime startTime = LocalDateTime.parse(req.getStartTime(), formatter);
LocalDateTime endTime = LocalDateTime.parse(req.getEndTime(), formatter);
Query query = new Query();
query.setCurrent(1);
query.setSize(10000);
List<ImageVo> records = imageAndVideoMapper.getImageInfo(req, Condition.getPage(query)).getRecords();
List<LocalDateTime> hourList = new ArrayList<>();
while (!startTime.isAfter(endTime)) {
hourList.add(startTime);
startTime = startTime.plusHours(1);
}
List<ImageVo> resultList = new ArrayList<>();
for (int i = 0; i < hourList.size() - 1; i++) {
String stringTime = DateUtil.getStringTime(hourList.get(i));
boolean notHasInfo = true;
for (ImageVo vo : records) {
LocalDateTime warningTime =
LocalDateTime.parse(vo.getTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
if (Func.isEmpty(warningTime)) {
continue;
}
if (warningTime.isAfter(hourList.get(i)) && warningTime.isBefore(hourList.get(i + 1))) {
vo.setTime(stringTime);
vo.setStatus("正常");
resultList.add(vo);
notHasInfo = false;
}
}
if (notHasInfo) {
ImageVo imageVo = new ImageVo();
imageVo.setTime(stringTime);
imageVo.setName("暂无图片详情");
imageVo.setStatus("异常");
resultList.add(imageVo);
}
}
// 筛选
if (StringUtil.isNotBlank(req.getStatus())) {
resultList = resultList.stream().filter(o -> o.getStatus().equals(req.getStatus())).collect(Collectors.toList());
}
return resultList;
}
@Override
public IPage<ImageVo> selectNewestImage(ImageReq req, Query query) {
return imageAndVideoMapper.selectNewestImage(req, Condition.getPage(query));
}
@Override
public List<StationTreeRes> getStationVideoType(String videoType) {
// 查询所有站点
List<StationVo> stationList = ecologicalFlowMapper.getStationListByReq(new StationQueryReq());
// 根据类型查询所有视频点位
List<StationTypeVo> videoList = imageAndVideoMapper.selectStationTypeByOwerType(videoType);
// 组装数据
List<StationTreeRes> resultList = new ArrayList<>();
for (StationVo stationVo : stationList) {
StationTreeRes stationTreeRes = new StationTreeRes();
List<StationTypeVo> child = videoList.stream().filter(o ->
o.getStationId().equals(stationVo.getDeviceCode())
).collect(Collectors.toList());
if (CollectionUtils.isEmpty(child)) {
continue;
}
stationTreeRes.setChild(child);
stationTreeRes.setCount(child.size());
stationTreeRes.setStationVo(stationVo);
resultList.add(stationTreeRes);
}
return resultList;
}
}

419
hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/service/impl/RealMonitorServiceImpl.java

@ -0,0 +1,419 @@
package com.hnac.hzims.suichang.service.impl;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.hnac.hzims.suichang.mapper.EcologicalFlowMapper;
import com.hnac.hzims.suichang.service.EcologicalFlowService;
import com.hnac.hzims.suichang.service.RealMonitorService;
import com.hnac.hzims.suichang.util.DateUtil;
import com.hnac.hzims.suichang.vo.*;
import com.hnac.hzinfo.datasearch.analyse.domain.FieldsData;
import com.hnac.hzinfo.datasearch.real.po.RealDataSearchPO;
import com.hnac.hzinfo.sdk.core.response.Result;
import com.hnac.hzinfo.sdk.real.RealDataSearchClient;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Author: liangfan
* @Date: 2024-03-08 15:06
* @Description:
*/
@Slf4j
@Service
public class RealMonitorServiceImpl implements RealMonitorService {
@Autowired
private EcologicalFlowService ecologicalFlowService;
@Autowired
private EcologicalFlowMapper ecologicalFlowMapper;
@Autowired
RealDataSearchClient realDataSearchClient;
@Value("${suichang.signage}")
String signage;
@Value("${suichang.timeSignage}")
String timeSignage;
@Override
public List<AvgMonitorVo> getAvgMonitorInfo() {
// 获取当前时间
LocalDateTime now = LocalDateTime.now();
// 昨天的开始时间(00:00) 昨天的结束时间(00:00)yesterday: 2024-03-12 00:00:00 yesterday: 2024-03-13 00:00:00
LocalDateTime startTime = now.withHour(0).withMinute(0).withSecond(0).withNano(0);
LocalDateTime endTime = now.withMinute(0).withSecond(0).withNano(0);
int hours = (int)ChronoUnit.HOURS.between(startTime, endTime);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String dateNow = now.format(formatter);
List<StationVo> stationRelationList = ecologicalFlowMapper.getStationListByName(null);
List<AvgMonitorVo> resultList = new ArrayList<>();
for (StationVo vo : stationRelationList) {
String stcd = vo.getDeviceCode();
// accessRules 取数规则:0=最早值、1=最大值、2=最小值、3=平均值、4=(累计值/和值)、5=(变化值/差值)6=最新值")
// SaveTimeType 周期类型: 0-> s(秒) 1->、m(分)、2->h(小时) 3->、d(天) 4->、w(周) 5->、n(自然月)、6->y(自然年)
List<Map<String, Object>> dataList = ecologicalFlowService.getData(
stcd, 3, 2, hours, startTime, endTime);
String realFlowValue = getRealData(stcd, signage);
log.info("dataList: {}, 实时流量为:{},设备编码为:{}", dataList, realFlowValue, stcd);
Map<String, Object> info = new HashMap<>();
if (!CollectionUtils.isEmpty(dataList)) {
// 为了处理特殊返回情况 多查出一条数据的问题
if (dataList.size() > 1) {
dataList.remove(0);
}
info = dataList.get(0);
}
AvgMonitorVo realMonitorVo = new AvgMonitorVo();
BeanUtils.copyProperties(vo, realMonitorVo);
realMonitorVo.setRealFlow(realFlowValue);
String ecologicalFlowValue = null == info.get(signage) ? "0" :
info.get(signage).toString();
log.info("info: {}, key:{}, 值:{}", info, signage, ecologicalFlowValue);
realMonitorVo.setAvgFlow(ecologicalFlowValue);
realMonitorVo.setDateNow(dateNow);
// 上报率
List<Map<String, Object>> reportList = ecologicalFlowService.getData(
stcd, 3, 2, 1, startTime, endTime);
int reportCount = 0;
if (!CollectionUtils.isEmpty(reportList)) {
// 为了处理特殊返回情况 多查出一条数据的问题
if (reportList.size() > hours) {
reportList.remove(0);
}
for (Map<String, Object> map : reportList) {
if (null != map.get(signage)) {
reportCount++;
}
}
}
BigDecimal pre = BigDecimal.valueOf(reportCount).divide(BigDecimal.valueOf(hours), 2, RoundingMode.HALF_UP);
pre = pre.compareTo(BigDecimal.ONE) >= 1 ? BigDecimal.ONE : pre;
realMonitorVo.setPassPre(pre.multiply(new BigDecimal(100))+ "%");
resultList.add(realMonitorVo);
}
return resultList;
}
@Override
public List<AvgMonitorCountVo> getAvgMonitorCountInfo(AvgMonitorReq req) {
// 昨日传2024-03-13 2024-03-13 时间段 2024-03-10 2024-03-13
String dateString = req.getStartTime() + " 00:00:00";
String endString = req.getEndTime() + " 00:00:00";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime startTime = LocalDateTime.parse(dateString, formatter);
LocalDateTime endTime = LocalDateTime.parse(endString, formatter).plusDays(1);
long days = ChronoUnit.DAYS.between(startTime, endTime);
log.info("开始结束时间: {}, {},相差天数:{}", startTime, endTime, days);
List<StationVo> stationRelationList = ecologicalFlowMapper.getStationListByName(req.getName());
List<AvgMonitorCountVo> resultList = new ArrayList<>();
for (StationVo vo : stationRelationList) {
// String stcd = "JSCZ001";
String stcd = vo.getDeviceCode();
// accessRules 取数规则:0=最早值、1=最大值、2=最小值、3=平均值、4=(累计值/和值)、5=(变化值/差值)6=最新值")
// SaveTimeType 周期类型: 0-> s(秒) 1->、m(分)、2->h(小时) 3->、d(天) 4->、w(周) 5->、n(自然月)、6->y(自然年)
List<Map<String, Object>> dataList = ecologicalFlowService.getData(
stcd, 3, 3, 1, startTime, endTime);
log.info("dataList: {}, 设备编码为:{}", dataList, stcd);
if (!CollectionUtils.isEmpty(dataList)) {
int passCount = 0;
// 为了处理特殊返回情况 多查出一条数据的问题
if (dataList.size() > days) {
dataList.remove(0);
}
List<RealMonitorSingleInfoVo> infos = new ArrayList<>();
AvgMonitorCountVo realMonitorVo = new AvgMonitorCountVo();
for (int j = 0 ; j < dataList.size(); j++) {
Map<String, Object> info = dataList.get(j);
log.info("info: {}, key:{}, 值:{}", info, signage, info.get(signage));
String ecologicalFlowValue = null == info.get(signage) ? "0" :
info.get(signage).toString();
if (vo.getFlowValue().compareTo(new BigDecimal(ecologicalFlowValue)) <= 0) {
passCount++;
}
RealMonitorSingleInfoVo realInfo = new RealMonitorSingleInfoVo();
realInfo.setTm(info.get(timeSignage).toString());
realInfo.setValue(ecologicalFlowValue);
infos.add(realInfo);
}
realMonitorVo.setName(vo.getName());
realMonitorVo.setFlowValue(vo.getFlowValue());
realMonitorVo.setCount(days);
realMonitorVo.setPassCount(passCount);
BigDecimal pre = BigDecimal.valueOf(passCount).divide(BigDecimal.valueOf(days), 2, RoundingMode.HALF_UP);
realMonitorVo.setPassPre(pre.multiply(BigDecimal.valueOf(100)) + "%");
realMonitorVo.setInfos(infos);
resultList.add(realMonitorVo);
}
}
return resultList;
}
@Override
public RealMonitorRes getRealMonitorInfo(String name) {
// 创建一个 DateTimeFormatter 对象来指定输出格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String dateNow = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0).format(formatter);
// 查询所有站点
List<StationVo> infos = ecologicalFlowMapper.getStationListByName(name);
// 查询每个站点的名称,核定流量,实时流量,上报个数 时间
List<RealMonitorVo> resultList = new ArrayList<>();
for (StationVo info : infos) {
// String stcd = "JSCZ001";
String stcd = info.getDeviceCode();
String stationName = info.getName();
BigDecimal flowValue = info.getFlowValue();
// 查询实时数据
String realFlowValue = getRealData(stcd, signage);
// 查询历史条数(上报条数)
int historyDataCount = getHistoryDataCount(stcd);
RealMonitorVo realMonitorVo = new RealMonitorVo();
realMonitorVo.setName(stationName);
realMonitorVo.setDeviceCode(stcd);
realMonitorVo.setFlowValue(flowValue);
realMonitorVo.setRealFlow(realFlowValue);
realMonitorVo.setReportCount(historyDataCount);
realMonitorVo.setDateNow(dateNow);
realMonitorVo.setAreaName("遂昌县");
resultList.add(realMonitorVo);
}
// 应上报个数
long hoursPassedToday = DateUtil.getHoursPassedToday() + 1;
RealMonitorRes realMonitorRes = new RealMonitorRes();
realMonitorRes.setRealMonitorVos(resultList);
realMonitorRes.setReportCount(hoursPassedToday);
return realMonitorRes;
}
@Override
public void exportRealMonitorInfo(HttpServletResponse response, String name) {
RealMonitorRes realMonitorInfo = this.getRealMonitorInfo(name);
List<RealMonitorVo> list = realMonitorInfo.getRealMonitorVos();
List<RealMonitorExportDTO> result = list.stream().map(o -> {
RealMonitorExportDTO dto = new RealMonitorExportDTO();
BeanUtils.copyProperties(o, dto);
return dto;
}).collect(Collectors.toList());
// 下载导出
String filename = "实时流量";
// 设置头信息
response.setCharacterEncoding("UTF-8");
response.setContentType("application/vnd.ms-excel");
try {
//设置xlsx格式
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename + ".xlsx", "UTF-8"));
//创建一个输出流
EasyExcel.write(response.getOutputStream(), RealMonitorExportDTO.class)
.autoCloseStream(Boolean.TRUE).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
.sheet(1,"实时流量")
.doWrite(result);
response.getOutputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void exportRealMonitorSingleInfo(HttpServletResponse response, RealMonitorSingleInfoReq req) {
List<RealMonitorSingleInfoVo> realMonitorSingleInfos = getRealMonitorSingleInfo(req);
for (RealMonitorSingleInfoVo realMonitorSingleInfo : realMonitorSingleInfos) {
realMonitorSingleInfo.setTm(realMonitorSingleInfo.getTm() + ":00:00");
}
// 下载导出
String filename = "站点流量详情";
// 设置头信息
response.setCharacterEncoding("UTF-8");
response.setContentType("application/vnd.ms-excel");
try {
//设置xlsx格式
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename + ".xlsx", "UTF-8"));
//创建一个输出流
EasyExcel.write(response.getOutputStream(), RealMonitorSingleInfoVo.class)
.autoCloseStream(Boolean.TRUE)
.sheet(1,"站点流量详情").registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
.doWrite(realMonitorSingleInfos);
response.getOutputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public List<RealMonitorSingleInfoVo> getRealMonitorSingleInfo(RealMonitorSingleInfoReq req) {
String stcd = req.getDeviceCode();
LocalDateTime startTime = DateUtil.getStartTime(req.getStartTime());
LocalDateTime endTime = DateUtil.getEndTime(req.getEndTime());
log.info("开始时间结束时间: {}, {}", startTime, endTime);
// 昨日达标情况 达标率就是有没有达到核定下限流量
// accessRules 取数规则:0=最早值、1=最大值、2=最小值、3=平均值、4=(累计值/和值)、5=(变化值/差值)6=最新值")
// SaveTimeType 周期类型: 0-> s(秒) 1->、m(分)、2->h(小时) 3->、d(天) 4->、w(周) 5->、n(自然月)、6->y(自然年)
List<Map<String, Object>> dataList = ecologicalFlowService.getData(
stcd, 3, 2, 1, startTime, endTime);
log.info("拿到getHistoryDataCount dataList: {}, 设备编码为:{}", dataList, stcd);
List<RealMonitorSingleInfoVo> resultList = new ArrayList<>();
if (!CollectionUtils.isEmpty(dataList)) {
resultList = dataList.stream().map(info -> {
String value = null == info.get(signage) ? "0" :
info.get(signage).toString();
String time = null == info.get(timeSignage) ? "" :
info.get(timeSignage).toString() + ":00:00";
RealMonitorSingleInfoVo vo = new RealMonitorSingleInfoVo();
vo.setValue(value);
vo.setTm(time);
return vo;
}).collect(Collectors.toList());
}
return resultList;
}
@Override
public String getRealData(String stcd, String signage) {
RealDataSearchPO po = new RealDataSearchPO();
po.setAnalyzeCode(stcd);
List<String> signages = new ArrayList<>();
signages.add(signage);
po.setSignages(signages);
Result<List<FieldsData>> result = realDataSearchClient.getRealDataByDeviceCode(po);
log.info("result: {}, 设备编码为:{}", result, stcd);
if (result == null || !result.isSuccess()) {
return null;
}
String value = "0";
List<FieldsData> data = result.getData();
if (!CollectionUtils.isEmpty(data)) {
value = data.get(0).getValue();
}
return value;
}
@Override
public void exportAvgMonitorCountInfo(HttpServletResponse response, AvgMonitorReq req) {
List<AvgMonitorCountVo> avgMonitorCountInfo = getAvgMonitorCountInfo(req);
// 动态生成的表头
List<String> firstHead = new ArrayList<>(Arrays.asList("电站名称", "核定流量"));
List<String> endHead = new ArrayList<>(Arrays.asList("考核天数", "合格天数", "合格率"));
List<String> allList = new ArrayList<>();
allList.addAll(firstHead);
if (avgMonitorCountInfo.size() > 0) {
AvgMonitorCountVo avgMonitorCountVo = avgMonitorCountInfo.get(0);
List<RealMonitorSingleInfoVo> infos = avgMonitorCountVo.getInfos();
List<String> mindHead = infos.stream().map(RealMonitorSingleInfoVo::getTm).collect(Collectors.toList());
allList.addAll(mindHead);
}
allList.addAll(endHead);
List<List<String>> head = allList.stream().map(v -> {
List<String> list = new ArrayList<>();
list.add(v);
return list;
}).collect(Collectors.toList());
// 组合数据
List<List<String>> contentLists = new ArrayList<>();
avgMonitorCountInfo.forEach(o -> {
List<String> list = new ArrayList<>();
list.add(o.getName());
list.add(o.getFlowValue().toString());
List<RealMonitorSingleInfoVo> rsVo = o.getInfos();
rsVo.forEach(k -> {
list.add(k.getValue());
});
list.add(o.getCount().toString());
list.add(o.getPassCount().toString());
list.add(o.getPassPre());
contentLists.add(list);
});
try {
//设置xlsx格式
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("日均流量" + ".xlsx", "UTF-8"));
EasyExcel.write(response.getOutputStream()).autoCloseStream(Boolean.TRUE).head(head)
.sheet(1,"日均流量").registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
.doWrite(contentLists);
response.getOutputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
int getHistoryDataCount(String stcd) {
// 获取当前时间
LocalDateTime now = LocalDateTime.now();
LocalDateTime startTime = now.withHour(0).withMinute(0).withSecond(0).withNano(0);
LocalDateTime endTime = now;
// 昨日达标情况 达标率就是有没有达到核定下限流量
// accessRules 取数规则:0=最早值、1=最大值、2=最小值、3=平均值、4=(累计值/和值)、5=(变化值/差值)6=最新值")
// SaveTimeType 周期类型: 0-> s(秒) 1->、m(分)、2->h(小时) 3->、d(天) 4->、w(周) 5->、n(自然月)、6->y(自然年)
List<Map<String, Object>> dataList = ecologicalFlowService.getData(
stcd, 3, 2, 1, startTime, endTime);
log.info("拿到getHistoryDataCount dataList: {}, 设备编码为:{}", dataList, stcd);
int count = 0;
if (!CollectionUtils.isEmpty(dataList)) {
for (Map<String, Object> info : dataList) {
String ecologicalFlowValue = null == info.get(signage) ? null :
info.get(signage).toString();
log.info("ecologicalFlowValue的值: {}", ecologicalFlowValue);
if (StringUtils.isNotBlank(ecologicalFlowValue)) {
count++;
}
}
}
return count;
}
@Override
public String getRealData(String stcd) {
RealDataSearchPO po = new RealDataSearchPO();
po.setAnalyzeCode(stcd);
List<String> signages = new ArrayList<>();
signages.add(signage);
po.setSignages(signages);
Result<List<FieldsData>> result = realDataSearchClient.getRealDataByDeviceCode(po);
log.info("result: {}, 设备编码为:{}", result, stcd);
if (result == null || !result.isSuccess()) {
return null;
}
String value = "0";
List<FieldsData> data = result.getData();
if (!CollectionUtils.isEmpty(data)) {
value = data.get(0).getValue();
}
return value;
}
}

169
hzims-service/suichang/src/main/java/com/hnac/hzims/suichang/service/impl/StatisticsDataServiceImpl.java

@ -0,0 +1,169 @@
package com.hnac.hzims.suichang.service.impl;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.hnac.hzims.suichang.mapper.EcologicalFlowMapper;
import com.hnac.hzims.suichang.service.EcologicalFlowService;
import com.hnac.hzims.suichang.service.StatisticsDataService;
import com.hnac.hzims.suichang.util.DateUtil;
import com.hnac.hzims.suichang.vo.StationVo;
import com.hnac.hzims.suichang.vo.StatisticsFlowDataDetailVo;
import com.hnac.hzims.suichang.vo.StatisticsFlowDataReq;
import com.hnac.hzims.suichang.vo.StatisticsFlowDataVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* @Author: liangfan
* @Date: 2024-03-14 16:19
* @Description:
*/
@Slf4j
@Service
public class StatisticsDataServiceImpl implements StatisticsDataService {
@Autowired
private EcologicalFlowMapper ecologicalFlowMapper;
@Autowired
private EcologicalFlowService ecologicalFlowService;
@Value("${suichang.signage}")
String signage;
@Value("${suichang.passPreValue}")
String passPreValueInfo;
@Override
public StatisticsFlowDataVo statisticsFlowReportByTime(StatisticsFlowDataReq req) {
// 查询所有站点
List<StationVo> infos = ecologicalFlowMapper.getStationListByName(req.getName());
// 电站信息
List<StatisticsFlowDataDetailVo> dataDetailVos = new ArrayList<>();
// 构建detail 并返回达标数
int stationPassCount = buildInfos(req, infos, dataDetailVos, passPreValueInfo);
// 总览信息
StatisticsFlowDataVo result = new StatisticsFlowDataVo();
result.setAreaName("遂昌县");
result.setExamCount(infos.size());
result.setPassCount(stationPassCount);
BigDecimal pre = BigDecimal.valueOf(stationPassCount).divide(BigDecimal.valueOf(infos.size()), 2, RoundingMode.HALF_UP);
result.setPassPre(pre.multiply(BigDecimal.valueOf(100)) + "%");
result.setDetail(dataDetailVos);
return result;
}
@Override
public void exportStatisticsFlowReportByTime(HttpServletResponse response, StatisticsFlowDataReq req) {
StatisticsFlowDataVo statisticsFlowDataVo = statisticsFlowReportByTime(req);
// 动态生成的表头
String areaName = statisticsFlowDataVo.getAreaName();
Integer examCount = statisticsFlowDataVo.getExamCount();
Integer passCount = statisticsFlowDataVo.getPassCount();
String passPre = statisticsFlowDataVo.getPassPre();
List<String> firstHead = new ArrayList<>(Arrays.asList("区域名称:" + areaName, "考核电站数:" + examCount,
"达标电站数:" + passCount, "达标率(%):" + passPre, "安装流量计的电站数:" + examCount));
List<String> endHead = new ArrayList<>(Arrays.asList("电站名称", "核定生态流量", "考核天数", "合格天数", "合格率"));
// 构建表头
List<List<String>> head = new ArrayList<>();
for (int i = 0; i < endHead.size(); i++) {
List<String> list = new ArrayList<>();
list.add(firstHead.get(i));
list.add(endHead.get(i));
head.add(list);
}
// 组合数据
List<List<String>> contentLists = new ArrayList<>();
List<StatisticsFlowDataDetailVo> detail = statisticsFlowDataVo.getDetail();
detail.forEach(o -> {
List<String> list = new ArrayList<>();
list.add(o.getName());
list.add(o.getFlowValue());
list.add(o.getExamDays().toString());
list.add(o.getExamPassDays().toString());
list.add(o.getExamPassDayPre());
contentLists.add(list);
});
try {
//设置xlsx格式
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("报表" + ".xlsx", "UTF-8"));
EasyExcel.write(response.getOutputStream()).autoCloseStream(Boolean.TRUE).head(head).autoTrim(true)
.sheet(1, "报表").registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
.doWrite(contentLists);
response.getOutputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
int buildInfos(StatisticsFlowDataReq req, List<StationVo> infos,
List<StatisticsFlowDataDetailVo> dataDetailVos, String passPreValue) {
int stationPassCount = 0;
for (StationVo stationRelationVo : infos) {
// String stcd = "JSCZ001";
String stcd = stationRelationVo.getDeviceCode();
BigDecimal flowValue = stationRelationVo.getFlowValue();
LocalDateTime startTime = DateUtil.getStartTime(req.getStartTime());
LocalDateTime endTime = DateUtil.getEndTimeByDay(req.getEndTime());
int days = (int) ChronoUnit.DAYS.between(startTime, endTime);
log.info("开始时间结束时间: {}, {},相差天数:{}", startTime, endTime, days);
// 查询单个站点一个时间段的日均数据
// accessRules 取数规则:0=最早值、1=最大值、2=最小值、3=平均值、4=(累计值/和值)、5=(变化值/差值)6=最新值")
// SaveTimeType 周期类型: 0-> s(秒) 1->、m(分)、2->h(小时) 3->、d(天) 4->、w(周) 5->、n(自然月)、6->y(自然年)
List<Map<String, Object>> dataList = ecologicalFlowService.getData(
stcd, 3, 3, 1, startTime, endTime);
log.info("dataList: {}, 设备编码为:{}", dataList, stcd);
StatisticsFlowDataDetailVo detailVo = new StatisticsFlowDataDetailVo();
if (!CollectionUtils.isEmpty(dataList)) {
int passCount = 0;
// 为了处理特殊返回情况 多查出一条数据的问题 跳过第一条
if (dataList.size() > days) {
dataList.remove(0);
}
for (int j = 0; j < dataList.size(); j++) {
Map<String, Object> info = dataList.get(j);
log.info("info: {}, key:{}, 值:{}", info, signage, info.get(signage));
String ecologicalFlowValue = null == info.get(signage) ? "0" :
info.get(signage).toString();
if (flowValue.compareTo(new BigDecimal(ecologicalFlowValue)) <= 0) {
passCount++;
}
}
// 计算合格率
BigDecimal singlePassPre = BigDecimal.valueOf(passCount).divide(BigDecimal.valueOf(days), 2, RoundingMode.HALF_UP);
if (new BigDecimal(passPreValue).compareTo(singlePassPre) <= 0) {
stationPassCount++;
}
detailVo.setExamPassDays(passCount);
detailVo.setExamPassDayPre(singlePassPre.multiply(BigDecimal.valueOf(100)) + "%");
}
// 组装数据
detailVo.setName(stationRelationVo.getName());
detailVo.setFlowValue(stationRelationVo.getFlowValue().toString());
detailVo.setExamDays(days);
dataDetailVos.add(detailVo);
}
return stationPassCount;
}
}

16
hzims-service/suichang/src/main/resources/application.yml

@ -0,0 +1,16 @@
#mybatis-plus配置
mybatis-plus:
mapper-locations: classpath:com/hnac/hzims/**/mapper/*Mapper.xml
#实体扫描,多个package用逗号或者分号分隔
typeAliasesPackage: com.hnac.hzims.**.entity
#swagger扫描路径配置
swagger:
base-packages:
- org.springbalde
- com.hnac
#服务器端口
server:
port: 18999
Loading…
Cancel
Save