大屏首页统计支持日月年
This commit is contained in:
parent
849d1bf564
commit
fb4c2f4cab
|
|
@ -15,16 +15,21 @@ import org.jeecg.common.constant.PollutionConstants;
|
|||
import org.jeecg.common.constant.enums.ScreenIndexSummaryEnum;
|
||||
import org.jeecg.common.entity.*;
|
||||
import org.jeecg.common.constant.enums.PollutionEnum;
|
||||
import org.jeecg.common.iot.common.VOSurvIntegrateOrientDetail;
|
||||
import org.jeecg.common.iot.common.VOSurvIntegrateResult;
|
||||
import org.jeecg.common.iot.common.VOWaterSurvIntegrateParam;
|
||||
import org.jeecg.common.util.R;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.common.vo.*;
|
||||
import org.jeecg.common.vo.statistic.ScreenIndexSummaryDetailVo;
|
||||
import org.jeecg.common.vo.statistic.ScreenSummaryVo;
|
||||
import org.jeecg.modules.appmana.service.*;
|
||||
import org.jeecg.modules.appmana.service.impl.IotCommonServiceImpl;
|
||||
import org.jeecg.modules.appmana.utils.Iotutils;
|
||||
import org.jeecg.modules.appmana.utils.YSUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
|
|
@ -37,7 +42,10 @@ import java.time.LocalDate;
|
|||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Api(tags="大屏接口")
|
||||
@RestController
|
||||
|
|
@ -110,6 +118,9 @@ public class BigScreenController {
|
|||
@Autowired
|
||||
private ISurvConfigService survConfigService;
|
||||
|
||||
@Autowired
|
||||
@Lazy
|
||||
private IotCommonServiceImpl commonService;
|
||||
|
||||
@ApiOperation("获取萤石云token")
|
||||
@PostMapping(value = "/getYsToken")
|
||||
|
|
@ -560,6 +571,36 @@ public class BigScreenController {
|
|||
wholeTime=tempWholeTime;
|
||||
}
|
||||
|
||||
//默认日数据
|
||||
if(StringUtils.isBlank(screenSummaryVo.getSummrayMode())){
|
||||
screenSummaryVo.setSummrayMode(IotConstants.day_hours);
|
||||
}
|
||||
LocalDateTime nowDay = LocalDateTime.now();
|
||||
String startTime = screenSummaryVo.getStartTime();
|
||||
String endTime = screenSummaryVo.getEndTime();
|
||||
LocalDateTime startDay = null;
|
||||
|
||||
if(StringUtils.isBlank(screenSummaryVo.getStartTime())){
|
||||
if(IotConstants.day_hours.equals(screenSummaryVo.getSummrayMode())){//默认日
|
||||
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
startDay = LocalDateTime.of(nowDay.toLocalDate(),LocalTime.MIN);
|
||||
startTime = startDay.format(dtf);
|
||||
endTime = LocalDateTime.of(nowDay.toLocalDate(),LocalTime.MAX).withNano(999999000).format(dtf);
|
||||
}else if(IotConstants.month_days.equals(screenSummaryVo.getSummrayMode())){
|
||||
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM");
|
||||
startDay = nowDay.with(TemporalAdjusters.firstDayOfMonth()).with(LocalTime.MIN);
|
||||
startTime = startDay.format(dtf);
|
||||
endTime = nowDay.with(TemporalAdjusters.lastDayOfMonth()).with(LocalTime.MAX).withNano(999999000).format(dtf);
|
||||
}else if(IotConstants.year_months.equals(screenSummaryVo.getSummrayMode())){
|
||||
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy");
|
||||
startDay = nowDay.with(TemporalAdjusters.firstDayOfYear()).with(LocalTime.MIN);
|
||||
startTime = startDay.format(dtf);
|
||||
endTime = nowDay.with(TemporalAdjusters.lastDayOfYear()).with(LocalTime.MAX).withNano(999999000).format(dtf);
|
||||
}
|
||||
}else{
|
||||
curYear = screenSummaryVo.getStartTime();
|
||||
}
|
||||
|
||||
if(stationList!=null&&stationList.size()>0){
|
||||
// Map<String,List<String>> deviceMap = new HashMap<>();
|
||||
for (SurvStationInfo survStationInfo : stationList) {
|
||||
|
|
@ -570,6 +611,8 @@ public class BigScreenController {
|
|||
List<String> soilList = new ArrayList<>();
|
||||
List<String> orientList = new ArrayList<>();
|
||||
List<String> liveList = new ArrayList<>();
|
||||
List<String> orientIdList = new ArrayList<>();
|
||||
List<String> liveIdList = new ArrayList<>();
|
||||
for (SurvDeviceDeploy survDeviceDeploy : survStationInfo.getDeviceList()) {
|
||||
if(PollutionConstants.SOIL_SURV.equals(survDeviceDeploy.getDeployType())){//土壤设备
|
||||
soilList.add(survDeviceDeploy.getDeployCode());
|
||||
|
|
@ -577,8 +620,10 @@ public class BigScreenController {
|
|||
airList.add(survDeviceDeploy.getDeployCode());
|
||||
}else if(PollutionConstants.WATER_ORIENT.equals(survDeviceDeploy.getDeployType())) {//面源
|
||||
orientList.add(survDeviceDeploy.getDeployCode());
|
||||
orientIdList.add(survDeviceDeploy.getId());
|
||||
}else if(PollutionConstants.WATER_LIVE.equals(survDeviceDeploy.getDeployType())) {//畜禽
|
||||
liveList.add(survDeviceDeploy.getDeployCode());
|
||||
liveIdList.add(survDeviceDeploy.getId());
|
||||
}else if(PollutionConstants.CAMERA.equals(survDeviceDeploy.getDeployType())) {//摄像头
|
||||
//只保留摄像头的数据
|
||||
// remainList.add(survDeviceDeploy);
|
||||
|
|
@ -603,6 +648,57 @@ public class BigScreenController {
|
|||
|
||||
List<Double> avgNH = new ArrayList<>();//填充数据用
|
||||
List<Double> avgCOD = new ArrayList<>();//填充数据用
|
||||
if(IotConstants.day_hours.equals(screenSummaryVo.getSummrayMode()) || IotConstants.month_days.equals(screenSummaryVo.getSummrayMode())) {//小时、日
|
||||
VOWaterSurvIntegrateParam voSurvIntegrateParam = new VOWaterSurvIntegrateParam();
|
||||
voSurvIntegrateParam.setDeployIds(orientIdList);
|
||||
voSurvIntegrateParam.setSummrayMode(screenSummaryVo.getSummrayMode());
|
||||
voSurvIntegrateParam.setStartTime(startTime);
|
||||
voSurvIntegrateParam.setEndTime(endTime);
|
||||
VOSurvIntegrateResult survIntegrateResult = commonService.WaterIntegrateStatistic(voSurvIntegrateParam);
|
||||
//数据
|
||||
LinkedHashMap<String, List<Double>> maps = new LinkedHashMap<>();
|
||||
LinkedHashMap<String,List<String>> survResult = survIntegrateResult.getSurvResult();
|
||||
List<String> tnDatas = survResult.get(PollutionEnum.dataWaterTn.getCode());
|
||||
List<String> tpDatas = survResult.get(PollutionEnum.dataWaterTp.getCode());
|
||||
List<String> noDatas =survResult.get(PollutionEnum.dataWaterNo.getCode());
|
||||
List<String> codDatas =survResult.get(PollutionEnum.dataWaterCod.getCode());
|
||||
List<String> nhDatas = survResult.get(PollutionEnum.dataWaterNh.getCode());
|
||||
if(tnDatas!=null) {
|
||||
avgTN = tnDatas.stream()
|
||||
.map(Double::parseDouble)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
if(tpDatas!=null) {
|
||||
avgTP = tpDatas.stream()
|
||||
.map(Double::parseDouble)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
if(noDatas!=null) {
|
||||
avgNO = noDatas.stream()
|
||||
.map(Double::parseDouble)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
if(codDatas!=null) {
|
||||
avgCOD = codDatas.stream()
|
||||
.map(Double::parseDouble)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
if(nhDatas!=null) {
|
||||
avgNH = nhDatas.stream()
|
||||
.map(Double::parseDouble)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
maps.put(ScreenIndexSummaryEnum.TNSummry.getDesc(),avgTN);
|
||||
maps.put(ScreenIndexSummaryEnum.TPSummry.getDesc(),avgTP);
|
||||
maps.put(ScreenIndexSummaryEnum.NOSummry.getDesc(),avgNO);
|
||||
maps.put(ScreenIndexSummaryEnum.CODSummry.getDesc(),avgCOD);
|
||||
maps.put(ScreenIndexSummaryEnum.NHSummry.getDesc(),avgNH);
|
||||
|
||||
screenIndexSummaryDetailVo.setDatas(maps);
|
||||
//时间
|
||||
screenIndexSummaryDetailVo.setDateStr(survIntegrateResult.getIndexs());
|
||||
}else if(IotConstants.year_months.equals(screenSummaryVo.getSummrayMode())){
|
||||
screenIndexSummaryDetailVo.setDateStr(wholeTime);
|
||||
if(curMonth>0) {//如果本年是一月份,则只需要查询去年的
|
||||
List<OrientDataTrans> orientSummry = hisdataOrientwaterService.getMonthSummry(orientList,curYear);
|
||||
for (int i= 0;i<curMonth;i++) {
|
||||
|
|
@ -644,6 +740,8 @@ public class BigScreenController {
|
|||
avgNH = lastavgNH;
|
||||
avgCOD = lastavgCOD;
|
||||
}
|
||||
}
|
||||
|
||||
// StationSummry stationSummry =new StationSummry();
|
||||
LinkedHashMap<String, List<Double>> maps = new LinkedHashMap<>();
|
||||
maps.put(ScreenIndexSummaryEnum.TNSummry.getDesc(),avgTN);
|
||||
|
|
@ -653,13 +751,13 @@ public class BigScreenController {
|
|||
maps.put(ScreenIndexSummaryEnum.NHSummry.getDesc(),avgNH);
|
||||
|
||||
screenIndexSummaryDetailVo.setDatas(maps);
|
||||
screenIndexSummaryDetailVo.setDateStr(wholeTime);
|
||||
|
||||
screenIndexSummaryDetailVo.setGroupId(survStationInfo.getGroupId());
|
||||
screenIndexSummaryDetailVo.setGroupName(survStationInfo.getGroupName());
|
||||
screenIndexSummaryDetailVo.setStationName(survStationInfo.getStationName());
|
||||
results.add(screenIndexSummaryDetailVo);
|
||||
}
|
||||
if(liveList.size()>0){
|
||||
if(liveList.size()>0) {
|
||||
|
||||
List<Double> avgTN = new ArrayList<>();
|
||||
List<Double> avgTP = new ArrayList<>();
|
||||
|
|
@ -667,9 +765,60 @@ public class BigScreenController {
|
|||
List<Double> avgCOD = new ArrayList<>();
|
||||
|
||||
List<Double> avgNO = new ArrayList<>(); //填充数据用
|
||||
if(curMonth>0) {//如果本年是一月份,则只需要查询去年的
|
||||
List<LiveDataTrans> liveSummry = hisdataLivestockwaterService.getMonthSummry(liveList,curYear);
|
||||
for (int i= 0;i<curMonth;i++) {
|
||||
if(IotConstants.day_hours.equals(screenSummaryVo.getSummrayMode()) || IotConstants.month_days.equals(screenSummaryVo.getSummrayMode())) {//小时、日
|
||||
VOWaterSurvIntegrateParam voSurvIntegrateParam = new VOWaterSurvIntegrateParam();
|
||||
voSurvIntegrateParam.setDeployIds(liveIdList);
|
||||
voSurvIntegrateParam.setSummrayMode(screenSummaryVo.getSummrayMode());
|
||||
voSurvIntegrateParam.setStartTime(startTime);
|
||||
voSurvIntegrateParam.setEndTime(endTime);
|
||||
VOSurvIntegrateResult survIntegrateResult = commonService.WaterIntegrateStatistic(voSurvIntegrateParam);
|
||||
//数据
|
||||
LinkedHashMap<String, List<Double>> maps = new LinkedHashMap<>();
|
||||
LinkedHashMap<String,List<String>> survResult = survIntegrateResult.getSurvResult();
|
||||
List<String> tnDatas = survResult.get(PollutionEnum.dataWaterTn.getCode());
|
||||
List<String> tpDatas = survResult.get(PollutionEnum.dataWaterTp.getCode());
|
||||
List<String> noDatas =survResult.get(PollutionEnum.dataWaterNo.getCode());
|
||||
List<String> codDatas =survResult.get(PollutionEnum.dataWaterCod.getCode());
|
||||
List<String> nhDatas = survResult.get(PollutionEnum.dataWaterNh.getCode());
|
||||
if(tnDatas!=null) {
|
||||
avgTN = tnDatas.stream()
|
||||
.map(Double::parseDouble)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
if(tpDatas!=null) {
|
||||
avgTP = tpDatas.stream()
|
||||
.map(Double::parseDouble)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
if(noDatas!=null) {
|
||||
avgNO = noDatas.stream()
|
||||
.map(Double::parseDouble)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
if(codDatas!=null) {
|
||||
avgCOD = codDatas.stream()
|
||||
.map(Double::parseDouble)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
if(nhDatas!=null) {
|
||||
avgNH = nhDatas.stream()
|
||||
.map(Double::parseDouble)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
maps.put(ScreenIndexSummaryEnum.TNSummry.getDesc(),avgTN);
|
||||
maps.put(ScreenIndexSummaryEnum.TPSummry.getDesc(),avgTP);
|
||||
maps.put(ScreenIndexSummaryEnum.NOSummry.getDesc(),avgNO);
|
||||
maps.put(ScreenIndexSummaryEnum.CODSummry.getDesc(),avgCOD);
|
||||
maps.put(ScreenIndexSummaryEnum.NHSummry.getDesc(),avgNH);
|
||||
|
||||
screenIndexSummaryDetailVo.setDatas(maps);
|
||||
//时间
|
||||
screenIndexSummaryDetailVo.setDateStr(survIntegrateResult.getIndexs());
|
||||
}else if(IotConstants.year_months.equals(screenSummaryVo.getSummrayMode())) {
|
||||
screenIndexSummaryDetailVo.setDateStr(wholeTime);
|
||||
if (curMonth > 0) {//如果本年是一月份,则只需要查询去年的
|
||||
List<LiveDataTrans> liveSummry = hisdataLivestockwaterService.getMonthSummry(liveList, curYear);
|
||||
for (int i = 0; i < curMonth; i++) {
|
||||
avgTN.add(liveSummry.get(i).getAvgTN());
|
||||
avgTP.add(liveSummry.get(i).getAvgTP());
|
||||
avgNH.add(liveSummry.get(i).getAvgNH());
|
||||
|
|
@ -679,16 +828,16 @@ public class BigScreenController {
|
|||
}
|
||||
}
|
||||
|
||||
if(isNeedLastYear){
|
||||
List<LiveDataTrans> lastYearSummry = hisdataLivestockwaterService.getMonthSummry(liveList,lastYear);
|
||||
if (isNeedLastYear) {
|
||||
List<LiveDataTrans> lastYearSummry = hisdataLivestockwaterService.getMonthSummry(liveList, lastYear);
|
||||
List<Double> lastavgTN = new ArrayList<>();
|
||||
List<Double> lastavgTP = new ArrayList<>();
|
||||
List<Double> lastavgNH = new ArrayList<>();
|
||||
List<Double> lastavgCOD = new ArrayList<>();
|
||||
|
||||
List<Double> lastavgNO = new ArrayList<>(); //填充数据用
|
||||
int startMonth = 12-lastYearMonth;
|
||||
for (int j= startMonth;j<12;j++) {
|
||||
int startMonth = 12 - lastYearMonth;
|
||||
for (int j = startMonth; j < 12; j++) {
|
||||
lastavgTN.add(lastYearSummry.get(j).getAvgTN());
|
||||
lastavgTP.add(lastYearSummry.get(j).getAvgTP());
|
||||
lastavgNH.add(lastYearSummry.get(j).getAvgNH());
|
||||
|
|
@ -709,6 +858,7 @@ public class BigScreenController {
|
|||
avgCOD = lastavgCOD;
|
||||
avgNO = lastavgNO;
|
||||
}
|
||||
}
|
||||
LinkedHashMap<String, List<Double>> maps = new LinkedHashMap<>();
|
||||
|
||||
maps.put(ScreenIndexSummaryEnum.TNSummry.getDesc(),avgTN);
|
||||
|
|
@ -718,7 +868,7 @@ public class BigScreenController {
|
|||
maps.put(ScreenIndexSummaryEnum.NHSummry.getDesc(),avgNH);
|
||||
|
||||
screenIndexSummaryDetailVo.setDatas(maps);
|
||||
screenIndexSummaryDetailVo.setDateStr(wholeTime);
|
||||
|
||||
screenIndexSummaryDetailVo.setGroupId(survStationInfo.getGroupId());
|
||||
screenIndexSummaryDetailVo.setGroupName(survStationInfo.getGroupName());
|
||||
screenIndexSummaryDetailVo.setStationName(survStationInfo.getStationName());
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public class BigScreenControllerP2 {
|
|||
isSearch=Boolean.TRUE;
|
||||
} else {
|
||||
//默认今天
|
||||
startDateTime = LocalDateTime.of(LocalDate.now(), LocalTime.MIN).withNano(999999000);
|
||||
startDateTime = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
|
||||
endDateTime = LocalDateTime.of(LocalDate.now(), LocalTime.MAX).withNano(999999000);
|
||||
}
|
||||
List<String> dataList = new ArrayList<>();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
package org.jeecg.modules.appmana.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.jeecg.common.vo.VOHisFormResult;
|
||||
import org.jeecg.common.vo.statistic.DTOIotCusSummray;
|
||||
import org.jeecg.common.vo.statistic.DTOIotSummray;
|
||||
import org.jeecg.common.vo.statistic.StringFormResultVo;
|
||||
import org.jeecg.common.vo.statistic.VOHisDateFormResult;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
public interface IOTStatisticMapper {
|
||||
List<VOHisFormResult> summaryDayHours(@Param("deployCode") String deployCode, @Param("tables") String tables, @Param("survItem") String survItem, @Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate);
|
||||
|
||||
List<VOHisDateFormResult> summaryByDays(@Param("query") DTOIotSummray dtoIotSummray);
|
||||
|
||||
List<VOHisFormResult> summaryYearMonth(@Param("deployCode") String deployCode, @Param("tables") String tables, @Param("survItem") String survItem, @Param("years") String years);
|
||||
|
||||
//公共月每日统计,可跨年
|
||||
List<StringFormResultVo> summaryByCusDays(@Param("query") DTOIotCusSummray dtoIotCusSummray);
|
||||
|
||||
//公共年月份统计,可跨年
|
||||
List<StringFormResultVo> summaryYearMonthCusMonth(@Param("query") DTOIotCusSummray dtoIotSummray);
|
||||
|
||||
//公共年度统计,可跨年
|
||||
List<StringFormResultVo> summaryYearCusMonth(@Param("query")DTOIotCusSummray dtoIotCusSummray);
|
||||
|
||||
List<VOHisFormResult> summaryMaxDayHours(@Param("deployCode") String deployCode, @Param("tables") String tables, @Param("survItem") String survItem, @Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate);
|
||||
|
||||
List<VOHisDateFormResult> summaryMaxByDays(@Param("query") DTOIotSummray dtoIotSummray);
|
||||
|
||||
List<VOHisFormResult> summaryMaxYearMonth(@Param("deployCode") String deployCode, @Param("tables") String tables, @Param("survItem") String survItem, @Param("years") String years);
|
||||
}
|
||||
|
|
@ -0,0 +1,148 @@
|
|||
<?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="org.jeecg.modules.appmana.mapper.IOTStatisticMapper">
|
||||
|
||||
<select id="summaryDayHours" resultType="org.jeecg.common.vo.VOHisFormResult">
|
||||
SELECT CAST(t1.`index` as CHAR) as date,IFNULL(t2.survItem,0) as name
|
||||
FROM (
|
||||
SELECT @a := @a + 1 AS `index` FROM mysql.help_topic, (SELECT @a := -1) temp LIMIT 24
|
||||
) t1
|
||||
LEFT JOIN (
|
||||
SELECT ROUND(AVG(cast(${survItem} as decimal(10,1))), 4) as survItem, date_format(t.DATA_DATE_TIME, '%H') as hours
|
||||
FROM ${tables} t where DATA_DATE_TIME between #{startDate} AND #{endDate} AND DEPLOY_CODE = #{deployCode}
|
||||
GROUP BY date_format(t.DATA_DATE_TIME, '%H')
|
||||
) t2
|
||||
ON t1.index = t2.hours
|
||||
ORDER BY t1.index asc
|
||||
</select>
|
||||
|
||||
<select id="summaryByDays" resultType="org.jeecg.common.vo.statistic.VOHisDateFormResult">
|
||||
SELECT t1.dateTime as date,IFNULL(t2.nums,0) as name
|
||||
FROM (
|
||||
SELECT date_add( DATE_SUB(#{query.startTime}, INTERVAL 1 DAY ), INTERVAL ( cast ( help_topic_id AS signed INTEGER ) + 1 ) DAY ) dateTime
|
||||
FROM mysql.help_topic WHERE help_topic_id < DATEDIFF(#{query.endTime}, date_sub( #{query.startTime}, INTERVAL 1 DAY ))
|
||||
) t1
|
||||
LEFT JOIN (
|
||||
SELECT date_format(td.DATA_DATE_TIME, '%Y-%m-%d') AS month, ROUND(AVG (cast(${query.survItem} as decimal(10,1))), 4) as nums FROM ${query.tableName} td
|
||||
WHERE
|
||||
td.DATA_DATE_TIME BETWEEN concat(#{query.startTime}, ' 00:00:00') AND concat(#{query.endTime}, ' 23:59:59') AND DEPLOY_CODE = #{query.deployCode}
|
||||
group by date_format(td.DATA_DATE_TIME, '%Y-%m-%d')
|
||||
) t2
|
||||
ON t1.dateTime = t2.month
|
||||
ORDER BY t1.dateTime asc
|
||||
</select>
|
||||
|
||||
<select id="summaryYearMonth" resultType="org.jeecg.common.vo.VOHisFormResult">
|
||||
SELECT CAST(t1.`index` as CHAR) as date,IFNULL(t2.survItem,0) as name
|
||||
FROM (
|
||||
SELECT @a := @a + 1 AS `index` FROM mysql.help_topic, (SELECT @a := 0) temp LIMIT 12
|
||||
) t1
|
||||
LEFT JOIN (
|
||||
SELECT ROUND(AVG (cast(${survItem} as decimal(10,1))), 4) as survItem, date_format(t.DATA_DATE_TIME, '%m') as months
|
||||
FROM ${tables} t where DATE_FORMAT(DATA_DATE_TIME, '%Y') = #{years}
|
||||
AND DEPLOY_CODE = #{deployCode}
|
||||
GROUP BY date_format(t.DATA_DATE_TIME, '%m')
|
||||
) t2
|
||||
ON t1.index = t2.months
|
||||
ORDER BY t1.index asc
|
||||
</select>
|
||||
|
||||
<select id="summaryByCusDays" resultType="org.jeecg.common.vo.statistic.StringFormResultVo">
|
||||
select a.click_date as summaryTime ,IFNULL(b.count,0) as summaryCounts,IFNULL(b.totprice,0) as summaryData
|
||||
from(
|
||||
<foreach item="items" collection="query.timeList" separator="union all" >
|
||||
SELECT #{items} as click_date
|
||||
</foreach>
|
||||
) a left join (
|
||||
select DATE_FORMAT(${query.timeColum},'%Y-%m-%d') as datetime, count(*) as count,sum(${query.dataColum}) as totprice
|
||||
from ${query.tableName}
|
||||
<where>
|
||||
<if test="query.condition != null and query.condition != ''">
|
||||
AND ${query.condition}
|
||||
</if>
|
||||
AND ${query.timeColum} BETWEEN concat(#{query.startTime}, ' 00:00:00') AND concat(#{query.endTime}, ' 23:59:59')
|
||||
</where>
|
||||
group by datetime) b on a.click_date = b.datetime
|
||||
</select>
|
||||
|
||||
<select id="summaryYearMonthCusMonth" resultType="org.jeecg.common.vo.statistic.StringFormResultVo">
|
||||
select a.click_date as summaryTime ,IFNULL(b.count,0) as summaryCounts,IFNULL(b.totprice,0) as summaryData
|
||||
from(
|
||||
<foreach item="items" collection="query.timeList" separator="union all" >
|
||||
SELECT #{items} as click_date
|
||||
</foreach>
|
||||
) a left join (
|
||||
select DATE_FORMAT(${query.timeColum},'%Y-%m') as datetime, count(*) as count,sum(${query.dataColum}) as totprice
|
||||
from ${query.tableName}
|
||||
<where>
|
||||
<if test="query.condition != null and query.condition != ''">
|
||||
AND ${query.condition}
|
||||
</if>
|
||||
AND ${query.timeColum} BETWEEN concat(#{query.startTime}, ' 00:00:00') AND concat(#{query.endTime}, ' 23:59:59')
|
||||
</where>
|
||||
group by datetime) b on a.click_date = b.datetime
|
||||
</select>
|
||||
|
||||
<select id="summaryYearCusMonth" resultType="org.jeecg.common.vo.statistic.StringFormResultVo">
|
||||
select a.click_date as summaryTime ,IFNULL(b.count,0) as summaryCounts,IFNULL(b.totprice,0) as summaryData
|
||||
from(
|
||||
<foreach item="items" collection="query.timeList" separator="union all" >
|
||||
SELECT #{items} as click_date
|
||||
</foreach>
|
||||
) a left join (
|
||||
select DATE_FORMAT(${query.timeColum},'%Y') as datetime, count(*) as count,sum(${query.dataColum}) as totprice
|
||||
from ${query.tableName}
|
||||
<where>
|
||||
<if test="query.condition != null and query.condition != ''">
|
||||
AND ${query.condition}
|
||||
</if>
|
||||
AND ${query.timeColum} BETWEEN concat(#{query.startTime}, ' 00:00:00') AND concat(#{query.endTime}, ' 23:59:59')
|
||||
</where>
|
||||
group by datetime) b on a.click_date = b.datetime
|
||||
</select>
|
||||
|
||||
<select id="summaryMaxDayHours" resultType="org.jeecg.common.vo.VOHisFormResult">
|
||||
SELECT CAST(t1.`index` as CHAR) as date,IFNULL(t2.survItem,0) as name
|
||||
FROM (
|
||||
SELECT @a := @a + 1 AS `index` FROM mysql.help_topic, (SELECT @a := -1) temp LIMIT 24
|
||||
) t1
|
||||
LEFT JOIN (
|
||||
SELECT ROUND(MAX(cast(${survItem} as decimal(10,1))), 4) as survItem, date_format(t.DATA_DATE_TIME, '%H') as hours
|
||||
FROM ${tables} t where DATA_DATE_TIME between #{startDate} AND #{endDate} AND DEPLOY_CODE = #{deployCode}
|
||||
GROUP BY date_format(t.DATA_DATE_TIME, '%H')
|
||||
) t2
|
||||
ON t1.index = t2.hours
|
||||
ORDER BY t1.index asc
|
||||
</select>
|
||||
|
||||
<select id="summaryMaxByDays" resultType="org.jeecg.common.vo.statistic.VOHisDateFormResult">
|
||||
SELECT t1.dateTime as date,IFNULL(t2.nums,0) as name
|
||||
FROM (
|
||||
SELECT date_add( DATE_SUB(#{query.startTime}, INTERVAL 1 DAY ), INTERVAL ( cast ( help_topic_id AS signed INTEGER ) + 1 ) DAY ) dateTime
|
||||
FROM mysql.help_topic WHERE help_topic_id < DATEDIFF(#{query.endTime}, date_sub( #{query.startTime}, INTERVAL 1 DAY ))
|
||||
) t1
|
||||
LEFT JOIN (
|
||||
SELECT date_format(td.DATA_DATE_TIME, '%Y-%m-%d') AS month, ROUND(MAX(cast(${query.survItem} as decimal(10,1))), 4) as nums FROM ${query.tableName} td
|
||||
WHERE
|
||||
td.DATA_DATE_TIME BETWEEN concat(#{query.startTime}, ' 00:00:00') AND concat(#{query.endTime}, ' 23:59:59') AND DEPLOY_CODE = #{query.deployCode}
|
||||
group by date_format(td.DATA_DATE_TIME, '%Y-%m-%d')
|
||||
) t2
|
||||
ON t1.dateTime = t2.month
|
||||
ORDER BY t1.dateTime asc
|
||||
</select>
|
||||
|
||||
<select id="summaryMaxYearMonth" resultType="org.jeecg.common.vo.VOHisFormResult">
|
||||
SELECT CAST(t1.`index` as CHAR) as date,IFNULL(t2.survItem,0) as name
|
||||
FROM (
|
||||
SELECT @a := @a + 1 AS `index` FROM mysql.help_topic, (SELECT @a := 0) temp LIMIT 12
|
||||
) t1
|
||||
LEFT JOIN (
|
||||
SELECT ROUND(MAX(cast(${survItem} as decimal(10,1))), 4) as survItem, date_format(t.DATA_DATE_TIME, '%m') as months
|
||||
FROM ${tables} t where DATE_FORMAT(DATA_DATE_TIME, '%Y') = #{years}
|
||||
AND DEPLOY_CODE = #{deployCode}
|
||||
GROUP BY date_format(t.DATA_DATE_TIME, '%m')
|
||||
) t2
|
||||
ON t1.index = t2.months
|
||||
ORDER BY t1.index asc
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
@ -34,5 +34,5 @@ public interface ISurvDeviceDeployService extends IService<SurvDeviceDeploy> {
|
|||
|
||||
List<SurvDeviceDeploy> getByIdsWithZhiBiao(List<String> deployId);
|
||||
|
||||
List<SurvDeviceDeploy> getAllDevice(List<String> deployTypes);
|
||||
List<SurvDeviceDeploy> getAllDevice(String stationCode,List<String> deployTypes);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ public class CommonServiceImpl {
|
|||
SurvHisdataOrientwater survHisdataOrientwater = hisdataOrientwaterService.getRecentDate(deploy.getDeployCode());
|
||||
String timeStr = sdf.format(survHisdataOrientwater.getDataDateTime());
|
||||
LocalDateTime dates = LocalDateTime.parse(timeStr,dateTimeFormatter3);
|
||||
startDateTime = LocalDateTime.of(dates.toLocalDate(), LocalTime.MIN).withNano(999999000);
|
||||
startDateTime = LocalDateTime.of(dates.toLocalDate(), LocalTime.MIN);
|
||||
endDateTime = LocalDateTime.of(dates.toLocalDate(),LocalTime.MAX).withNano(999999000);
|
||||
}
|
||||
|
||||
|
|
@ -103,7 +103,7 @@ public class CommonServiceImpl {
|
|||
SurvHisdataLivestockwater survHisdataLivestockwater = hisdataLivestockwaterService.getRecentDate(deploy.getDeployCode());
|
||||
String timeStr = sdf.format(survHisdataLivestockwater.getDataDateTime());
|
||||
LocalDateTime dates = LocalDateTime.parse(timeStr,dateTimeFormatter3);
|
||||
startDateTime = LocalDateTime.of(dates.toLocalDate(), LocalTime.MIN).withNano(999999000);
|
||||
startDateTime = LocalDateTime.of(dates.toLocalDate(), LocalTime.MIN);
|
||||
endDateTime = LocalDateTime.of(dates.toLocalDate(),LocalTime.MAX).withNano(999999000);
|
||||
}
|
||||
List<SurvHisdataLivestockwater> liveList = hisdataLivestockwaterService.listByParams(deploy.getDeployCode(),startDateTime,endDateTime);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,56 @@
|
|||
package org.jeecg.modules.appmana.service.impl;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.common.vo.VOHisFormResult;
|
||||
import org.jeecg.common.vo.VOHisResult;
|
||||
import org.jeecg.modules.appmana.mapper.IOTStatisticMapper;
|
||||
import org.jeecg.modules.appmana.utils.Iotutils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class IotCommonP2ServiceImpl {
|
||||
|
||||
@Resource
|
||||
private IOTStatisticMapper iotStatisticMapper;
|
||||
|
||||
public VOHisResult summaryDayHours(String deployCode, String tableName, String survItem, String dateStr) {
|
||||
DateTimeFormatter sdf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
LocalDate orgDate = LocalDate.parse(dateStr, sdf);
|
||||
|
||||
LocalDateTime startDate = LocalDateTime.of(orgDate, LocalTime.MIN);
|
||||
LocalDateTime endDate = LocalDateTime.of(orgDate, LocalTime.MAX).withNano(999999000);
|
||||
VOHisResult voHisResult = new VOHisResult();
|
||||
//如果查询累计类型的监测项,则取最高
|
||||
if (Iotutils.isAccumulate(survItem)) {
|
||||
voHisResult = constructVo(iotStatisticMapper.summaryMaxDayHours(deployCode, tableName, survItem, startDate, endDate));
|
||||
}else{
|
||||
voHisResult = constructVo(iotStatisticMapper.summaryDayHours(deployCode, tableName, survItem, startDate, endDate));
|
||||
}
|
||||
return voHisResult;
|
||||
}
|
||||
|
||||
|
||||
public VOHisResult constructVo(List<VOHisFormResult> voHisFormResultList) {
|
||||
VOHisResult voHisResult = new VOHisResult();
|
||||
if (!voHisFormResultList.isEmpty()) {
|
||||
List<String> dateList = new ArrayList<>();
|
||||
List<String> valueList = new ArrayList<>();
|
||||
for (VOHisFormResult voHisFormResult : voHisFormResultList) {
|
||||
dateList.add(voHisFormResult.getDate());
|
||||
valueList.add(voHisFormResult.getName());
|
||||
}
|
||||
voHisResult.setDataList(valueList);
|
||||
voHisResult.setTimeList(dateList);
|
||||
}
|
||||
return voHisResult;
|
||||
}
|
||||
}
|
||||
|
|
@ -59,7 +59,7 @@ public class IotCommonServiceImpl {
|
|||
List<String> deployTypes = new ArrayList<>();
|
||||
deployTypes.add(PollutionConstants.AIR_SURV);
|
||||
deployTypes.add(PollutionConstants.SOIL_SURV);
|
||||
List<SurvDeviceDeploy> deploys = fDeviceDeployService.getAllDevice(deployTypes);
|
||||
List<SurvDeviceDeploy> deploys = fDeviceDeployService.getAllDevice(voSurvIntegrateParam.getStationCode(),deployTypes);
|
||||
VOIntegrateStatistic voIntegrateStatistic = new VOIntegrateStatistic();
|
||||
if(!deploys.isEmpty()){
|
||||
voSurvIntegrateParam.setDeployIds(deploys.stream().map(SurvDeviceDeploy::getId).collect(Collectors.toList()));
|
||||
|
|
@ -82,7 +82,7 @@ public class IotCommonServiceImpl {
|
|||
List<String> deployTypes = new ArrayList<>();
|
||||
deployTypes.add(PollutionConstants.WATER_ORIENT);
|
||||
deployTypes.add(PollutionConstants.WATER_LIVE);
|
||||
List<SurvDeviceDeploy> deploys = fDeviceDeployService.getAllDevice(deployTypes);
|
||||
List<SurvDeviceDeploy> deploys = fDeviceDeployService.getAllDevice(voSurvIntegrateParam.getStationCode(),deployTypes);
|
||||
VOIntegrateStatistic voIntegrateStatistic = new VOIntegrateStatistic();
|
||||
if(!deploys.isEmpty()) {
|
||||
voSurvIntegrateParam.setDeployIds(deploys.stream().map(SurvDeviceDeploy::getId).collect(Collectors.toList()));
|
||||
|
|
|
|||
|
|
@ -399,8 +399,9 @@ public class SurvDeviceDeployServiceImpl extends ServiceImpl<SurvDeviceDeployMap
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<SurvDeviceDeploy> getAllDevice(List<String> deployTypes) {
|
||||
public List<SurvDeviceDeploy> getAllDevice(String stationCode,List<String> deployTypes) {
|
||||
List<SurvDeviceDeploy> deploys = lambdaQuery()
|
||||
.eq(StringUtils.isNotBlank(stationCode),SurvDeviceDeploy::getStationCode,stationCode)
|
||||
.in(SurvDeviceDeploy::getDeployType,deployTypes)
|
||||
.eq(SurvDeviceDeploy::getIsDel,0)
|
||||
.eq(SurvDeviceDeploy::getRunStatus,0)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import java.util.List;
|
|||
|
||||
@Data
|
||||
public class VOSurvIntegrateParam {
|
||||
@ApiModelProperty("站点编号")
|
||||
private String stationCode;
|
||||
@ApiModelProperty("设备部署id")
|
||||
private List<String> deployIds;
|
||||
@ApiModelProperty("开始时间")
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import java.util.List;
|
|||
|
||||
@Data
|
||||
public class VOWaterSurvIntegrateParam {
|
||||
@ApiModelProperty("站点编号")
|
||||
private String stationCode;
|
||||
@ApiModelProperty("设备部署id")
|
||||
private List<String> deployIds;
|
||||
@ApiModelProperty("开始时间")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
package org.jeecg.common.vo.statistic;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class DTOIotCusSummray {
|
||||
/**
|
||||
* 被统计字段
|
||||
*/
|
||||
@ApiModelProperty("被统计字段")
|
||||
private String dataColum;
|
||||
/**
|
||||
* 被统计字段
|
||||
*/
|
||||
@ApiModelProperty("表名")
|
||||
private String tableName;
|
||||
/**
|
||||
* 被统计字段
|
||||
*/
|
||||
@ApiModelProperty("时间字段")
|
||||
private String timeColum;
|
||||
/**
|
||||
* java代为处理所有需统计的月份集合,按照需要的排序传入
|
||||
*/
|
||||
@ApiModelProperty("待统计月份集合")
|
||||
private List<String> timeList;
|
||||
/**
|
||||
* 开始时间
|
||||
*/
|
||||
@ApiModelProperty("开始时间")
|
||||
private String startTime;
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
@ApiModelProperty("结束时间")
|
||||
private String endTime;
|
||||
/**
|
||||
* 其他查询条件
|
||||
*/
|
||||
@ApiModelProperty("其他查询条件")
|
||||
private String condition;
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package org.jeecg.common.vo.statistic;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class DTOIotSummray {
|
||||
@ApiModelProperty("设备部署编码")
|
||||
private String deployCode;
|
||||
@ApiModelProperty("农场ID")
|
||||
private String farmId;
|
||||
@ApiModelProperty("检测项的变量名")
|
||||
private String survItem;
|
||||
@ApiModelProperty("表名")
|
||||
private String tableName;
|
||||
@ApiModelProperty("开始时间")
|
||||
private String startTime;
|
||||
@ApiModelProperty("结束时间")
|
||||
private String endTime;
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package org.jeecg.common.vo.statistic;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class StringFormResultVo {
|
||||
private String summaryTime;
|
||||
private String summaryData;
|
||||
private String summaryCounts;
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package org.jeecg.common.vo.statistic;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class VOHisDateFormResult {
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "M月d日")
|
||||
@DateTimeFormat(pattern = "M月d日")
|
||||
private Date date;
|
||||
private String name;
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue