增加单项监测日月年统计,本月本年拼接

This commit is contained in:
zy 2025-11-27 16:28:39 +08:00
parent 2a861d2e3a
commit 90064f6936
8 changed files with 516 additions and 12 deletions

View File

@ -26,6 +26,7 @@ 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.IotCommonP2ServiceImpl;
import org.jeecg.modules.appmana.service.impl.IotCommonP3ServiceImpl;
import org.jeecg.modules.appmana.service.impl.IotCommonServiceImpl;
import org.jeecg.modules.appmana.utils.CommonUtils;
import org.jeecg.modules.appmana.utils.Iotutils;
@ -129,6 +130,10 @@ public class BigScreenController {
@Lazy
private IotCommonP2ServiceImpl commonP2Service;
@Autowired
@Lazy
private IotCommonP3ServiceImpl commonP3Service;
@ApiOperation("获取萤石云token")
@PostMapping(value = "/getYsToken")
public Result getToken(){
@ -375,8 +380,11 @@ public class BigScreenController {
JSONArray returnArrs= new JSONArray();
JSONObject jsonObject = new JSONObject();
List<CommonDataTrans> listFinal = new ArrayList<>();
Map<String,String> stationMap = new HashMap<>();//设备map
if(stationList!=null&&stationList.size()>0){
for (SurvStationInfo survStationInfo : stationList) {
stationMap.put(survStationInfo.getStationCode(),survStationInfo.getStationName());
if(survStationInfo.getDeviceList()!=null&&survStationInfo.getDeviceList().size()>0){
List<SurvDeviceDeploy> remainList = new ArrayList<>();
List<String> airList = new ArrayList<>();
@ -384,7 +392,7 @@ public class BigScreenController {
List<String> orientList = new ArrayList<>();
List<String> liveList = new ArrayList<>();
List<SurvDeviceDeploy> waterList = new ArrayList<>();
Map<String,SurvDeviceDeploy> map = new HashMap<>();
Map<String,SurvDeviceDeploy> deployMap = new HashMap<>();//设备map
for (SurvDeviceDeploy survDeviceDeploy : survStationInfo.getDeviceList()) {
if(PollutionConstants.SOIL_SURV.equals(survDeviceDeploy.getDeployType())){//土壤设备
soilList.add(survDeviceDeploy.getDeployCode());
@ -400,7 +408,7 @@ public class BigScreenController {
//只保留摄像头的数据
// remainList.add(survDeviceDeploy);
}
map.put(survDeviceDeploy.getDeployCode(),survDeviceDeploy);
deployMap.put(survDeviceDeploy.getDeployCode(),survDeviceDeploy);
}
// if(PollutionConstants.SOIL_SURV.equals(survDeviceDeploy.getDeployType())){//土壤设备
@ -464,7 +472,7 @@ public class BigScreenController {
noent.setStationCode(survStationInfo.getStationCode());
noent.setSurvItem(PollutionEnum.dataWaterNo.getCode());
String deployId = map.get(transdataOrientwaterVo.getDeviceCode()).getId();
String deployId = deployMap.get(transdataOrientwaterVo.getDeviceCode()).getId();
tpent.setValue(transdataOrientwaterVo.getDataWaterTp());
tpent.setDeployId(deployId);
@ -532,7 +540,7 @@ public class BigScreenController {
codent.setStationCode(survStationInfo.getStationCode());
codent.setSurvItem(PollutionEnum.dataWaterCod.getCode());
String deployId = map.get(transdataLivestockwaterVo.getDeviceCode()).getId();
String deployId = deployMap.get(transdataLivestockwaterVo.getDeviceCode()).getId();
tpent.setValue(transdataLivestockwaterVo.getDataWaterTp());
tpent.setDeployId(deployId);
@ -589,6 +597,7 @@ public class BigScreenController {
List<String> waterIds = new ArrayList<>();
List<String> soilIds = new ArrayList<>();
List<String> airIds = new ArrayList<>();
Map<String,SurvDeviceDeploy> deviceMap = new HashMap<>();//设备map
if(!deploys.isEmpty()){
for (SurvDeviceDeploy deploy : deploys) {
if(PollutionConstants.SOIL_SURV.equals(deploy.getDeployType())){//土壤设备
@ -598,6 +607,7 @@ public class BigScreenController {
}else if(PollutionConstants.WATER_QULITY.equals(deploy.getDeployType())){//水设备
waterIds.add(deploy.getId());
}
deviceMap.put(deploy.getId(),deploy);
}
}
List<CommonDataTrans> soilDataTrans = new ArrayList<>();
@ -608,6 +618,7 @@ public class BigScreenController {
for (SurvTransdataSoil datas : soildsData) {
List<CommonDataTrans> trans = CommonUtils.constructSoil(datas);
trans = commonP3Service.processName(stationMap,deviceMap,trans);
soilDataTrans.addAll(trans);
}
}
@ -620,6 +631,7 @@ public class BigScreenController {
for (SurvTransdataAir datas : airsData) {
List<CommonDataTrans> trans = CommonUtils.constructAir(datas);
trans = commonP3Service.processName(stationMap,deviceMap,trans);
airDataTrans.addAll(trans);
}
}
@ -633,6 +645,7 @@ public class BigScreenController {
for (SurvTransdataSoil datas : waterData) {
List<CommonDataTrans> trans = CommonUtils.constructSoil(datas);
trans = commonP3Service.processName(stationMap,deviceMap,trans);
waterDataTrans.addAll(trans);
}
}

View File

@ -28,6 +28,7 @@ import org.jeecg.common.vo.VOBigScreenSurvQ;
import org.jeecg.common.vo.VOHisFormResult;
import org.jeecg.common.vo.VOHisResult;
import org.jeecg.modules.appmana.service.impl.IotCommonP2ServiceImpl;
import org.jeecg.modules.appmana.service.impl.IotCommonP3ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -52,8 +53,11 @@ public class BigScreenControllerP2 {
@Autowired
private IotCommonP2ServiceImpl iotCommonP2Service;
@Autowired
private IotCommonP3ServiceImpl iotCommonP3Service;
@Autowired
private ISurvMaintainRecordService maintainRecordService;
@ApiOperationSupport(order = 1)
@ApiOperation(value = "01. 查询设备下各检测项的历史数据", notes = "")
@PostMapping(value = "/survItemSummary")
@ -73,6 +77,42 @@ public class BigScreenControllerP2 {
.last("limit 1"));
}
Assert.notNull(deploy, "无效的设备");
VOHisResult voHisResult = iotCommonP3Service.iotSurvSummary(voBigScreenSurvQ);
List<VOHisFormResult> voHisFormResults = new ArrayList<>();
if(!voHisResult.getDataList().isEmpty()){
for (int i=0;i<voHisResult.getDataList().size();i++) {
VOHisFormResult voHisFormResult = new VOHisFormResult();
voHisFormResult.setDate(voHisResult.getTimeList().get(i));
voHisFormResult.setName(voHisResult.getDataList().get(i));
voHisFormResults.add(voHisFormResult);
}
}
voHisResult.setFormList(voHisFormResults);
return Result.OK(voHisResult);
}
@ApiOperationSupport(order = 2)
@ApiOperation(value = "01-1. 查询设备下各检测项的历史数据", notes = "")
@PostMapping(value = "/survItemSummary2")
public Result<VOHisResult> survItemSummary2(@RequestBody VOBigScreenSurvQ voBigScreenSurvQ) {
PollutionEnum pollutionEnum = PollutionEnum.catchPollution(voBigScreenSurvQ.getSurvItem());
SurvDeviceDeploy deploy = null;
if(StringUtils.isNotBlank(voBigScreenSurvQ.getStationCode())){
deploy = survDeviceDeployService.getOne(Wrappers.<SurvDeviceDeploy>lambdaQuery()
.eq(SurvDeviceDeploy::getStationCode,voBigScreenSurvQ.getStationCode())
.like(SurvDeviceDeploy::getDeployType,pollutionEnum.getType())
.last("limit 1"));
} else if (StringUtils.isNotBlank(voBigScreenSurvQ.getDeployId())) {
deploy = survDeviceDeployService.getById(voBigScreenSurvQ.getDeployId());
}else {
deploy = survDeviceDeployService.getOne(Wrappers.<SurvDeviceDeploy>lambdaQuery()
.like(SurvDeviceDeploy::getDeployType,pollutionEnum.getType())
.last("limit 1"));
}
Assert.notNull(deploy, "无效的设备");
LocalDateTime startDateTime = null;
LocalDateTime endDateTime = null;

View File

@ -1,5 +1,6 @@
package org.jeecg.modules.appmana.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONUtil;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
@ -7,29 +8,29 @@ import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.constant.IotConstants;
import org.jeecg.common.constant.enums.PollutionEnum;
import org.jeecg.common.constant.enums.ScreenIndexSummaryEnum;
import org.jeecg.common.entity.SurvDeviceDeploy;
import org.jeecg.common.iot.common.VOIntegrateStatistic;
import org.jeecg.common.iot.common.VOSurvIntegrateParam;
import org.jeecg.common.iot.common.VOSurvIntegrateResult;
import org.jeecg.common.iot.common.VOWaterSurvIntegrateParam;
import org.jeecg.common.util.DateUtilTools;
import org.jeecg.common.vo.VOHisFormResult;
import org.jeecg.common.vo.VOHisResult;
import org.jeecg.common.vo.statistic.DeploySummaryVo;
import org.jeecg.common.vo.statistic.ScreenIndexSummaryDetailVo;
import org.jeecg.common.vo.statistic.ScreenSummaryVo;
import org.jeecg.common.vo.statistic.*;
import org.jeecg.modules.appmana.mapper.IOTStatisticMapper;
import org.jeecg.modules.appmana.utils.Iotutils;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
@Service
@ -59,6 +60,86 @@ public class IotCommonP2ServiceImpl {
}
public VOHisResult summaryByDays(DTOIotSummray dtoIotSummray) {
VOHisResult voHisResult = new VOHisResult();
if (Iotutils.isAccumulate(dtoIotSummray.getSurvItem())) {
voHisResult = constructVoDate(iotStatisticMapper.summaryMaxByDays(dtoIotSummray));
}else{
voHisResult = constructVoDate(iotStatisticMapper.summaryByDays(dtoIotSummray));
}
return voHisResult;
}
public VOHisResult summaryYearMonth(SurvDeviceDeploy deploy, String tableName, String survItem, String years) {
VOHisResult voHisResult = new VOHisResult();
if (Iotutils.isAccumulate(survItem)) {
voHisResult = summaryYearMonthAccumulateData(deploy, tableName, survItem, years);
}else{
voHisResult = constructVo(iotStatisticMapper.summaryYearMonth(deploy.getDeployCode(), tableName, survItem, years));
}
return voHisResult;
}
public VOHisResult summaryYearMonthAccumulateData(SurvDeviceDeploy deploy, String tableName, String survItem, String startTime) {
VOHisResult voHisResult = new VOHisResult();
//step 1:查询范围内所有日数据
//换算时间
LocalDateTime nowTime = LocalDateTime.now();
LocalDateTime sDate = LocalDateTime.of(nowTime.getYear(),1,1,0,0,0);
LocalDateTime eDate = LocalDateTime.of(nowTime.getYear(),12,31,23,59,59);
DateTimeFormatter dateTimeFormatter3 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
DTOIotSummray dtoIotSummray = new DTOIotSummray();
dtoIotSummray.setSurvItem(survItem);
dtoIotSummray.setDeployCode(deploy.getDeployCode());
dtoIotSummray.setStartTime(sDate.format(dateTimeFormatter3));
dtoIotSummray.setEndTime(eDate.format(dateTimeFormatter3));
dtoIotSummray.setTableName(tableName);
List<VOHisDateFormResult> dayResults = iotStatisticMapper.summaryMaxByDays(dtoIotSummray);
//step 2:使用日数据计算每月累计值
if(!dayResults.isEmpty()){
LinkedHashMap<String, BigDecimal> dataMap = new LinkedHashMap<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
for (VOHisDateFormResult dayResult : dayResults) {
String cKey = sdf.format(dayResult.getDate());
BigDecimal dayValue = dataMap.get(cKey);
BigDecimal cValue = new BigDecimal(dayResult.getName());
if(dayValue!=null){//无数据为本月第一条数据开始初始化
dataMap.put(cKey,dayValue.add(cValue));
}else{
dataMap.put(cKey,cValue);
}
}
List<String> dataList = new LinkedList<>();
List<String> timeList = new LinkedList<>();
for (String month : dataMap.keySet()) {
BigDecimal monthValue = dataMap.get(month);
timeList.add(month);
dataList.add(Iotutils.toStringData(monthValue));
}
voHisResult.setDataList(dataList);
voHisResult.setTimeList(timeList);
}
return voHisResult;
}
public VOHisResult constructVoDate(List<VOHisDateFormResult> voHisDateFormResults) {
VOHisResult voHisResult = new VOHisResult();
if (!voHisDateFormResults.isEmpty()) {
List<String> dateList = new ArrayList<>();
List<String> valueList = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("M.d");
for (VOHisDateFormResult voHisDateFormResult : voHisDateFormResults) {
dateList.add(sdf.format(voHisDateFormResult.getDate()));
valueList.add(voHisDateFormResult.getName());
}
voHisResult.setDataList(valueList);
voHisResult.setTimeList(dateList);
}
return voHisResult;
}
public VOHisResult constructVo(List<VOHisFormResult> voHisFormResultList) {
VOHisResult voHisResult = new VOHisResult();
if (!voHisFormResultList.isEmpty()) {
@ -458,4 +539,87 @@ public class IotCommonP2ServiceImpl {
}
return newData;
}
public VOHisResult summarySevenDayHours(String deployCode, String tableName, String survItem, LocalDate startDay, LocalDate endDay) {
List<LocalDate> dateList = DateUtilTools.getDatesBetween(startDay, endDay);
LocalDateTime nowTime = LocalDateTime.now();
DateTimeFormatter sdf = DateTimeFormatter.ofPattern("M.d");
List<String> totalTimeList = new ArrayList<>();
List<String> totalDataList = new ArrayList<>();
for (LocalDate localDate : dateList) {
LocalDateTime startDate = LocalDateTime.of(localDate, LocalTime.MIN);
LocalDateTime endDate = LocalDateTime.of(localDate, LocalTime.MAX).withNano(999999000);
List<VOHisFormResult> results = new ArrayList<>();
if(Iotutils.isAccumulate(survItem)){
results = iotStatisticMapper.summaryMaxDayHours(deployCode, tableName, survItem, startDate, endDate);
VOHisResult tempvo = constructVo(results);
List<String> newData = processDelta(tempvo.getDataList());
totalDataList.addAll(newData);
List<String> newTime = new ArrayList<>();
for (String vtime : tempvo.getTimeList()) {
String s = localDate.format(sdf) + " " + vtime + "";
newTime.add(s);
}
totalTimeList.addAll(newTime);
}else{
results = iotStatisticMapper.summaryDayHours(deployCode, tableName, survItem, startDate, endDate);
VOHisResult tempRe = constructVo(results);
totalDataList.addAll(tempRe.getDataList());
List<String> newTime1 = new ArrayList<>();
for (String vtime : tempRe.getTimeList()) {
String s = localDate.format(sdf) + " " + vtime + "";
newTime1.add(s);
}
totalTimeList.addAll(newTime1);
}
}
VOHisResult hoursData = new VOHisResult();
hoursData.setDataList(totalDataList);
hoursData.setTimeList(totalTimeList);
List<String> secDataList = new ArrayList<>();
List<String> secTimeList = new ArrayList<>();
int sizeOfData = hoursData.getDataList().size();
secDataList = CollectionUtil.sub(hoursData.getDataList(), nowTime.getHour() + 1, sizeOfData);
secTimeList = CollectionUtil.sub(hoursData.getTimeList(), nowTime.getHour() + 1, sizeOfData);
List<String> finalData = CollectionUtil.sub(hoursData.getDataList(), 0, nowTime.getHour() + 1);
List<String> finalTime = CollectionUtil.sub(hoursData.getTimeList(), 0, nowTime.getHour() + 1);
finalData.addAll(secDataList);
finalTime.addAll(secTimeList);
hoursData.setDataList(finalData);
hoursData.setTimeList(finalTime);
return hoursData;
}
/**
* 计算小时数据间的差值为各个小时的增量数据
* @param dataList
*/
public List<String> processDelta(List<String> dataList) {
List<String> result = new ArrayList<>();
if(dataList!=null && !dataList.isEmpty()){
int counts = 0;
Map<Integer, BigDecimal> map = new HashMap<>();
for (String s : dataList) {
BigDecimal cbig= new BigDecimal(s);
//保存数据
map.put(counts,cbig);
BigDecimal finalData= null ;
if(counts==0){//第一个数据直接减0
finalData=cbig.subtract(BigDecimal.ZERO);
}else{
//上个数据
BigDecimal lastData = map.get(counts-1);
finalData=cbig.subtract(lastData);
}
result.add(Iotutils.toStringData(finalData));
counts++;
}
}
return result;
}
}

View File

@ -0,0 +1,261 @@
package org.jeecg.modules.appmana.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Assert;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.constant.IotConstants;
import org.jeecg.common.constant.PollutionConstants;
import org.jeecg.common.constant.enums.PollutionEnum;
import org.jeecg.common.entity.SurvDeviceDeploy;
import org.jeecg.common.vo.CommonDataTrans;
import org.jeecg.common.vo.VOBigScreenSurvQ;
import org.jeecg.common.vo.VOHisResult;
import org.jeecg.common.vo.statistic.DTOIotSummray;
import org.jeecg.modules.appmana.utils.Iotutils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class IotCommonP3ServiceImpl {
@Autowired
@Lazy
private IotCommonServiceImpl iotCommonService;
@Autowired
@Lazy
private CommonServiceImpl commonService;
@Autowired
@Lazy
private SurvDeviceDeployServiceImpl deviceDeployService;
@Autowired
@Lazy
private IotCommonP2ServiceImpl iotCommonP2Service;
/**
* 物联网设备统计
* @param voBigScreenSurvQ
* @return
*/
public VOHisResult iotSurvSummary(VOBigScreenSurvQ voBigScreenSurvQ){
SurvDeviceDeploy deploy = deviceDeployService.getById(voBigScreenSurvQ.getDeployId());
Assert.notNull(deploy, "无效的设备");
LocalDateTime startDateTime = null;
LocalDateTime endDateTime = null;
VOHisResult results = new VOHisResult();
DateTimeFormatter dateTimeFormatter3 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
DateTimeFormatter dateTimeFormatter4 = DateTimeFormatter.ofPattern("yyyy-MM");
DateTimeFormatter showTime = DateTimeFormatter.ofPattern("M.d");
LocalDateTime nowTime = LocalDateTime.now();
String tableName = "";
PollutionEnum pollutionEnum = PollutionEnum.catchMessage(voBigScreenSurvQ.getSurvItem());
if (PollutionConstants.AIR_SURV.equals(pollutionEnum.getType())) {
tableName = PollutionConstants.TABLE_AIR;
} else if (PollutionConstants.SOIL_SURV.equals(pollutionEnum.getType())) {
tableName = PollutionConstants.TABLE_SOIL;
}else if(PollutionConstants.PEST_LIGHT.equals(pollutionEnum.getType())){
tableName = PollutionConstants.TABLE_PEST;
}else if(PollutionConstants.WATER_QULITY.equals(pollutionEnum.getType())){
tableName = PollutionConstants.TABLE_SOIL;
}
if (StringUtils.isBlank(tableName)) {
return results;
}
LocalDate now = LocalDate.now();
if(StringUtils.isBlank(voBigScreenSurvQ.getSummrayMode())){
voBigScreenSurvQ.setSummrayMode(IotConstants.day_hours);//默认小时模式
}
//原始数据
if (IotConstants.day_origins.equals(voBigScreenSurvQ.getSummrayMode())
|| StringUtils.isBlank(voBigScreenSurvQ.getSummrayMode())) {//一天原始数据未传入模式时默认
Boolean isSearch = Boolean.FALSE;
if (StringUtils.isNotBlank(voBigScreenSurvQ.getStartTime()) && StringUtils.isNotBlank(voBigScreenSurvQ.getEndTime())) {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
startDateTime = LocalDateTime.parse(voBigScreenSurvQ.getStartTime() + " 00:00:00", dtf);
endDateTime = LocalDateTime.parse(voBigScreenSurvQ.getEndTime() + " 23:59:59", dtf);
isSearch = Boolean.TRUE;
} else {
//默认两周
startDateTime = LocalDateTime.of(now.plusDays(-0), LocalTime.MIN);
endDateTime = LocalDateTime.of(now, LocalTime.MAX);
}
List<String> dataList = new ArrayList<>();
List<String> timeList = new ArrayList<>();
results = commonService.getSurvDeviceData(deploy, voBigScreenSurvQ.getSurvItem(), dataList, timeList, startDateTime, endDateTime,isSearch);
}
else if (IotConstants.day_hours.equals(voBigScreenSurvQ.getSummrayMode())) {
if (StringUtils.isNotBlank(voBigScreenSurvQ.getStartTime())) {
String isValid = Iotutils.isValidTimeFormat(voBigScreenSurvQ.getStartTime(), "yyyy-MM-dd");
Assert.notNull(isValid, "时间格式不正确");
voBigScreenSurvQ.setStartTime(isValid);
} else {
voBigScreenSurvQ.setStartTime(now.format(dateTimeFormatter3));
}
results = iotCommonP2Service.summaryDayHours(deploy.getDeployCode(), tableName, Iotutils.humpToLine(voBigScreenSurvQ.getSurvItem()), voBigScreenSurvQ.getStartTime());
//累计类型的数据需要计算每小时的差值转换为每小时的增量统计
if(Iotutils.isEntityAccumulate(voBigScreenSurvQ.getSurvItem())){
results.setDataList(iotCommonP2Service.processDelta(results.getDataList()));
}
LocalDate localDate = LocalDate.parse(voBigScreenSurvQ.getStartTime());
if (!results.getTimeList().isEmpty()) {
List<String> newcTimes = new ArrayList<>();
for (String cti : results.getTimeList()) {
String cnti = localDate.format(showTime) + " " + cti + "";
newcTimes.add(cnti);
}
results.setTimeList(newcTimes);
}
if (localDate.isEqual(now)) {//判断是否为今天
List<String> secDataList = new ArrayList<>();
List<String> secTimeList = new ArrayList<>();
//提取昨天的数据补充为完整的24小时
LocalDate yesterDayTime = now.plusDays(-1);
String yesterDay = yesterDayTime.format(dateTimeFormatter3);
VOHisResult hoursData = iotCommonP2Service.summaryDayHours(deploy.getDeployCode(), tableName, Iotutils.humpToLine(voBigScreenSurvQ.getSurvItem()), yesterDay);
//累计类型的数据需要计算每小时的差值转换为每小时的增量统计
if(Iotutils.isEntityAccumulate(voBigScreenSurvQ.getSurvItem())) {
hoursData.setDataList(iotCommonP2Service.processDelta(hoursData.getDataList()));
}
if (!hoursData.getTimeList().isEmpty()) {
List<String> newTimes = new ArrayList<>();
for (String ti : hoursData.getTimeList()) {
String nti = yesterDayTime.format(showTime) + " " + ti + "";
newTimes.add(nti);
}
hoursData.setTimeList(newTimes);
}
int sizeOfData = hoursData.getDataList().size();
secDataList = CollectionUtil.sub(hoursData.getDataList(), nowTime.getHour() + 1, sizeOfData);
secTimeList = CollectionUtil.sub(hoursData.getTimeList(), nowTime.getHour() + 1, sizeOfData);
secDataList.addAll(CollectionUtil.sub(results.getDataList(), 0, nowTime.getHour() + 1));
secTimeList.addAll(CollectionUtil.sub(results.getTimeList(), 0, nowTime.getHour() + 1));
results.setDataList(secDataList);
results.setTimeList(secTimeList);
}
}
else if (IotConstants.seven_days.equals(voBigScreenSurvQ.getSummrayMode())) {
//近一周
LocalDate endDate = now;
LocalDate startDate = now.plusWeeks(-1);
if (StringUtils.isNotBlank(voBigScreenSurvQ.getStartTime())) {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate orgDate = LocalDate.parse(voBigScreenSurvQ.getStartTime(), dtf);
endDate = orgDate;
startDate = orgDate.plusDays(-6);
}
startDateTime = LocalDateTime.of(startDate, LocalTime.MIN);
endDateTime = LocalDateTime.of(endDate, LocalTime.MAX).withNano(999999000);
DTOIotSummray dtoIotSummray = new DTOIotSummray();
dtoIotSummray.setSurvItem(Iotutils.humpToLine(voBigScreenSurvQ.getSurvItem()));
dtoIotSummray.setDeployCode(deploy.getDeployCode());
dtoIotSummray.setStartTime(startDateTime.format(dateTimeFormatter3));
dtoIotSummray.setEndTime(endDateTime.format(dateTimeFormatter3));
dtoIotSummray.setTableName(tableName);
results = iotCommonP2Service.summaryByDays(dtoIotSummray);
}
else if (IotConstants.seven_day_hours.equals(voBigScreenSurvQ.getSummrayMode())) {
//近一周
LocalDate endDate = now;
LocalDate startDate = now.plusWeeks(-1);
if (StringUtils.isNotBlank(voBigScreenSurvQ.getStartTime())) {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate orgDate = LocalDate.parse(voBigScreenSurvQ.getStartTime(), dtf);
endDate = orgDate;
startDate = orgDate.plusWeeks(-1);
}
results = iotCommonP2Service.summarySevenDayHours(deploy.getDeployCode(), tableName, Iotutils.humpToLine(voBigScreenSurvQ.getSurvItem()), startDate, endDate);
}
else if (IotConstants.month_days.equals(voBigScreenSurvQ.getSummrayMode())) {
if (StringUtils.isNotBlank(voBigScreenSurvQ.getStartTime())) {
String isValid = Iotutils.isValidTimeFormat(voBigScreenSurvQ.getStartTime(), "yyyy-MM");
Assert.notNull(isValid, "时间格式不正确");
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
voBigScreenSurvQ.setStartTime(isValid);
startDateTime = LocalDateTime.parse(voBigScreenSurvQ.getStartTime() + "-01 00:00:00", dtf);
endDateTime = LocalDateTime.of(startDateTime.with(TemporalAdjusters.lastDayOfMonth()).toLocalDate(), LocalTime.MAX).withNano(999999000);
} else {
startDateTime = LocalDateTime.of(now.plusDays(-29), LocalTime.MIN);
endDateTime = LocalDateTime.of(now, LocalTime.MAX);
voBigScreenSurvQ.setStartTime(startDateTime.format(dateTimeFormatter4));
}
DTOIotSummray dtoIotSummray = new DTOIotSummray();
dtoIotSummray.setSurvItem(Iotutils.humpToLine(voBigScreenSurvQ.getSurvItem()));
dtoIotSummray.setDeployCode(deploy.getDeployCode());
dtoIotSummray.setStartTime(startDateTime.format(dateTimeFormatter3));
dtoIotSummray.setEndTime(endDateTime.format(dateTimeFormatter3));
dtoIotSummray.setTableName(tableName);
results = iotCommonP2Service.summaryByDays(dtoIotSummray);
LocalDate paramsData = LocalDate.parse(voBigScreenSurvQ.getStartTime() + "-01");
if (isThisMonth(paramsData)) {//判断是否为本月
results.setDataList(CollectionUtil.sub(results.getDataList(), 0, nowTime.getDayOfMonth()));
results.setTimeList(CollectionUtil.sub(results.getTimeList(), 0, nowTime.getDayOfMonth()));
}
for (int i = 0; i < results.getTimeList().size(); i++) {
results.getTimeList().set(i, results.getTimeList().get(i).replace(".", "") + "");
}
}
else if (IotConstants.year_months.equals(voBigScreenSurvQ.getSummrayMode())) {
String dateFormat= "yyyy";
if (StringUtils.isNotBlank(voBigScreenSurvQ.getStartTime())) {
String isValid = Iotutils.isValidTimeFormat(voBigScreenSurvQ.getStartTime(), dateFormat);
Assert.notNull(isValid, "时间格式不正确");
voBigScreenSurvQ.setStartTime(isValid);
} else {
DateTimeFormatter yeardf = DateTimeFormatter.ofPattern(dateFormat);
voBigScreenSurvQ.setStartTime(now.format(yeardf));
}
results = iotCommonP2Service.summaryYearMonth(deploy, tableName, Iotutils.humpToLine(voBigScreenSurvQ.getSurvItem()), voBigScreenSurvQ.getStartTime());
if (String.valueOf(now.getYear()).equals(voBigScreenSurvQ.getStartTime())) {//判断是否为本年
results.setDataList(CollectionUtil.sub(results.getDataList(), 0, nowTime.getMonthValue()));
results.setTimeList(CollectionUtil.sub(results.getTimeList(), 0, nowTime.getMonthValue()));
}
for (int i = 0; i < results.getTimeList().size(); i++) {
results.getTimeList().set(i, results.getTimeList().get(i) + "");
}
}
results.setFDeviceDeploy(deploy);
results.setPollutionEnum(pollutionEnum);
return results;
}
public static boolean isThisMonth(LocalDate date) {
LocalDate now = LocalDate.now();
return date.getMonthValue() == now.getMonthValue() && date.getYear() == now.getYear();
}
public List<CommonDataTrans> processName(Map<String, String> stationMap, Map<String, SurvDeviceDeploy> deployMap, List<CommonDataTrans> trans) {
List<CommonDataTrans> results = new ArrayList<>();
if(trans!=null && !trans.isEmpty()){
for (CommonDataTrans tran : trans) {
SurvDeviceDeploy deploy = deployMap.get(tran.getDeployId());
String stationCode = stationMap.get(deploy.getStationCode());
tran.setStationName(StringUtils.isNotBlank(stationCode)?stationMap.get(stationCode):"站点");
tran.setDeployRemark(deploy!=null?deploy.getDeployDes():"设备");
results.add(tran);
}
}
return results;
}
}

View File

@ -24,6 +24,8 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Component
public class Iotutils {
@ -294,4 +296,24 @@ public class Iotutils {
}
return pollutionSetVos;
}
private static Pattern humpPattern = Pattern.compile("[A-Z]");
/**
* 驼峰转下划线
*
* @param str
* @return
*/
public static String humpToLine(String str) {
if(PollutionEnum.dataPm25.getCode().equals(str)) {
return "DATA_PM_25";
}
Matcher matcher = humpPattern.matcher(str);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(sb, "_" + matcher.group(0).toUpperCase());
}
matcher.appendTail(sb);
return sb.toString();
}
}

View File

@ -15,5 +15,7 @@ public class VOBigScreenSurvQ {
private String startTime;
@ApiModelProperty("结束时间")
private String endTime;
@ApiModelProperty("统计模式")
private String summrayMode;
}

View File

@ -2,6 +2,8 @@ package org.jeecg.common.vo;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import org.jeecg.common.constant.enums.PollutionEnum;
import org.jeecg.common.entity.SurvDeviceDeploy;
import java.util.List;
@ -11,4 +13,6 @@ public class VOHisResult {
private List<String> timeList;
private List<String> dataList;
private List<VOHisFormResult> formList;
private SurvDeviceDeploy fDeviceDeploy;
private PollutionEnum pollutionEnum;
}

View File

@ -7,8 +7,6 @@ import lombok.Data;
public class DTOIotSummray {
@ApiModelProperty("设备部署编码")
private String deployCode;
@ApiModelProperty("农场ID")
private String farmId;
@ApiModelProperty("检测项的变量名")
private String survItem;
@ApiModelProperty("表名")