增加按设备过滤统计项
This commit is contained in:
parent
78a54d67da
commit
5681706a61
|
|
@ -54,9 +54,6 @@ public class BigScreenController {
|
|||
@Autowired
|
||||
private ISurvDisplayInfoService survDisplayInfoService;
|
||||
|
||||
@Autowired
|
||||
private ISurvDeviceInfoService deviceInfoService;
|
||||
|
||||
@Autowired
|
||||
private ISurvStationInfoService survStationInfoService;
|
||||
|
||||
|
|
@ -80,10 +77,9 @@ public class BigScreenController {
|
|||
|
||||
|
||||
@Autowired
|
||||
private ISurvHisdataAirService hisdataAirService;
|
||||
private ISurvHisdataVocsService vocsService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private ISurvHisdataSoilService hisdataSoilService;
|
||||
|
||||
@Autowired
|
||||
private ISurvHisdataOrientwaterService hisdataOrientwaterService;
|
||||
|
|
@ -616,6 +612,7 @@ public class BigScreenController {
|
|||
List<String> orientIdList = new ArrayList<>();
|
||||
List<String> liveIdList = new ArrayList<>();
|
||||
List<String> waterIdList = new ArrayList<>();
|
||||
List<String> stinkList = new ArrayList<>();//恶臭
|
||||
for (SurvDeviceDeploy survDeviceDeploy : survStationInfo.getDeviceList()) {
|
||||
if(PollutionConstants.SOIL_SURV.equals(survDeviceDeploy.getDeployType())){//土壤设备
|
||||
soilList.add(survDeviceDeploy.getDeployCode());
|
||||
|
|
@ -629,6 +626,8 @@ public class BigScreenController {
|
|||
liveIdList.add(survDeviceDeploy.getId());
|
||||
}else if(PollutionConstants.WATER_QULITY.equals(survDeviceDeploy.getDeployType())) {//水质
|
||||
waterIdList.add(survDeviceDeploy.getId());
|
||||
}else if(PollutionConstants.STINK.equals(survDeviceDeploy.getDeployType())) {//水质
|
||||
stinkList.add(survDeviceDeploy.getId());
|
||||
}else if(PollutionConstants.CAMERA.equals(survDeviceDeploy.getDeployType())) {//摄像头
|
||||
//只保留摄像头的数据
|
||||
// remainList.add(survDeviceDeploy);
|
||||
|
|
@ -655,12 +654,10 @@ public class BigScreenController {
|
|||
for (int i= 0;i<curMonth;i++) {
|
||||
avgTN.add(orientSummry.get(i).getAvgTN());
|
||||
avgTP.add(orientSummry.get(i).getAvgTP());
|
||||
// avgNO.add(orientSummry.get(i).getAvgNO());
|
||||
avgNO.add(0D);
|
||||
avgNO.add(orientSummry.get(i).getAvgNO());
|
||||
avgCOD.add(orientSummry.get(i).getAvgCod());
|
||||
avgNH.add(orientSummry.get(i).getAvgNH());
|
||||
|
||||
avgNH.add(0D);
|
||||
// avgCOD.add(0D);
|
||||
avgCOD.add(orientSummry.get(i).getAvgNO());
|
||||
}
|
||||
if(isNeedLastYear){
|
||||
List<OrientDataTrans> lastYearOrientSummry = hisdataOrientwaterService.getMonthSummry(orientList,lastYear);
|
||||
|
|
@ -674,12 +671,10 @@ public class BigScreenController {
|
|||
for (int j= startMonth;j<12;j++) {
|
||||
lastavgTN.add(lastYearOrientSummry.get(j).getAvgTN());
|
||||
lastavgTP.add(lastYearOrientSummry.get(j).getAvgTP());
|
||||
// lastavgNO.add(lastYearOrientSummry.get(j).getAvgNO());
|
||||
lastavgNO.add(0D);
|
||||
|
||||
lastavgNH.add(0D);
|
||||
// lastavgCOD.add(0D);
|
||||
lastavgNO.add(lastYearOrientSummry.get(j).getAvgNO());
|
||||
lastavgCOD.add(lastYearOrientSummry.get(j).getAvgCod());
|
||||
lastavgNH.add(lastYearOrientSummry.get(j).getAvgNH());
|
||||
|
||||
}
|
||||
lastavgTN.addAll(avgTN);
|
||||
lastavgTP.addAll(avgTP);
|
||||
|
|
@ -698,9 +693,9 @@ public class BigScreenController {
|
|||
LinkedHashMap<String, List<Double>> maps = new LinkedHashMap<>();
|
||||
maps.put(ScreenIndexSummaryEnum.TNSummry.getDesc(),avgTN);
|
||||
maps.put(ScreenIndexSummaryEnum.TPSummry.getDesc(),avgTP);
|
||||
// maps.put(ScreenIndexSummaryEnum.NOSummry.getDesc(),avgNO);
|
||||
maps.put(ScreenIndexSummaryEnum.NOSummry.getDesc(),avgNO);
|
||||
maps.put(ScreenIndexSummaryEnum.CODSummry.getDesc(),avgCOD);
|
||||
// maps.put(ScreenIndexSummaryEnum.NHSummry.getDesc(),avgNH);
|
||||
maps.put(ScreenIndexSummaryEnum.NHSummry.getDesc(),avgNH);
|
||||
|
||||
screenIndexSummaryDetailVo.setDatas(maps);
|
||||
}
|
||||
|
|
@ -713,6 +708,7 @@ public class BigScreenController {
|
|||
screenIndexSummaryDetailVo.setGroupId(survStationInfo.getGroupId());
|
||||
screenIndexSummaryDetailVo.setGroupName(survStationInfo.getGroupName());
|
||||
screenIndexSummaryDetailVo.setStationName(survStationInfo.getStationName());
|
||||
screenIndexSummaryDetailVo = iotTools.filterTenantData(orientIdList,screenIndexSummaryDetailVo);
|
||||
results.add(screenIndexSummaryDetailVo);
|
||||
}
|
||||
if(!liveList.isEmpty()) {
|
||||
|
|
@ -788,6 +784,13 @@ public class BigScreenController {
|
|||
screenIndexSummaryDetailVo.setGroupName(survStationInfo.getGroupName());
|
||||
screenIndexSummaryDetailVo.setStationName(survStationInfo.getStationName());
|
||||
screenIndexSummaryDetailVo.setStationShortName(survStationInfo.getStationShortName());
|
||||
screenIndexSummaryDetailVo = iotTools.filterTenantData(liveIdList,screenIndexSummaryDetailVo);
|
||||
results.add(screenIndexSummaryDetailVo);
|
||||
|
||||
}
|
||||
|
||||
if(!stinkList.isEmpty()){
|
||||
screenIndexSummaryDetailVo = vocsService.getStinkSummry(screenSummaryVo,stinkList,startTime,endTime);
|
||||
results.add(screenIndexSummaryDetailVo);
|
||||
}
|
||||
}
|
||||
|
|
@ -797,6 +800,7 @@ public class BigScreenController {
|
|||
// datajob.put("dataStr",wholeTime);
|
||||
// returnArrs.add(datajob);
|
||||
redisTemplate.opsForValue().set(key,JSONArray.parseArray(JSONObject.toJSONString(results)),5, TimeUnit.MINUTES);//增加缓存机制
|
||||
|
||||
return Result.ok(results);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,12 @@
|
|||
package org.jeecg.modules.appmana.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.jeecg.common.entity.SurvHisdataVocs;
|
||||
import org.jeecg.common.iot.common.VOSurvIntegrateStinkDetail;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: 恶臭实时历史数据
|
||||
|
|
@ -11,4 +16,6 @@ import org.jeecg.common.entity.SurvHisdataVocs;
|
|||
*/
|
||||
public interface SurvHisdataVocsMapper extends BaseMapper<SurvHisdataVocs> {
|
||||
|
||||
List<VOSurvIntegrateStinkDetail> integrateSummary(@Param("tenantId")String tenantId, @Param("stinkList") List<String> stinkList, @Param("timeDataFormat") String timeDataFormat, @Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,4 +2,23 @@
|
|||
<!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.SurvHisdataVocsMapper">
|
||||
|
||||
<select id="integrateSummary" resultType="org.jeecg.common.iot.common.VOSurvIntegrateStinkDetail">
|
||||
select date_format(t.DATA_DATE_TIME,#{timeDataFormat}) as dates,
|
||||
ifnull(ROUND(avg(cast(DATA_TVOC as decimal(10,1))), 2),'0') as dataTvoc,
|
||||
ifnull(ROUND(avg(cast(DATA_OU as decimal(10,1))), 2),'0') as dataOu,
|
||||
ifnull(ROUND(avg(cast(DATA_NH3 as decimal(10,1))), 2),'0') as dataNh3,
|
||||
ifnull(ROUND(avg(cast(DATA_H2S as decimal(10,1))), 2),'0') as dataH2s
|
||||
from surv_hisdata_vocs t
|
||||
<where>
|
||||
<if test="tenantId != null and tenantId != ''">
|
||||
AND TENANT_ID = #{tenantId}
|
||||
</if>
|
||||
AND DEPLOY_ID IN
|
||||
<foreach item="id" collection="stinkList" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
and DATA_DATE_TIME between #{startTime} and #{endTime}
|
||||
</where>
|
||||
group by dates order by dates
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
@ -2,6 +2,10 @@ package org.jeecg.modules.appmana.service;
|
|||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.jeecg.common.entity.SurvHisdataVocs;
|
||||
import org.jeecg.common.vo.statistic.ScreenIndexSummaryDetailVo;
|
||||
import org.jeecg.common.vo.statistic.ScreenSummaryVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: 恶臭实时历史数据
|
||||
|
|
@ -11,4 +15,5 @@ import org.jeecg.common.entity.SurvHisdataVocs;
|
|||
*/
|
||||
public interface ISurvHisdataVocsService extends IService<SurvHisdataVocs> {
|
||||
|
||||
ScreenIndexSummaryDetailVo getStinkSummry(ScreenSummaryVo screenSummaryVo, List<String> stinkList, String startTime, String endTime);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import org.jeecg.common.constant.enums.PollutionEnum;
|
|||
import org.jeecg.common.dto.CommonDTO;
|
||||
import org.jeecg.common.entity.*;
|
||||
import org.jeecg.common.vo.VOHisResult;
|
||||
import org.jeecg.common.vo.statistic.ScreenIndexSummaryDetailVo;
|
||||
import org.jeecg.modules.appmana.service.ISurvHisdataAirService;
|
||||
import org.jeecg.modules.appmana.service.ISurvHisdataLivestockwaterService;
|
||||
import org.jeecg.modules.appmana.service.ISurvHisdataOrientwaterService;
|
||||
|
|
@ -24,7 +25,9 @@ import java.text.SimpleDateFormat;
|
|||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
|
|
@ -41,6 +44,9 @@ public class CommonServiceImpl {
|
|||
@Lazy
|
||||
private SurvConfigServiceImpl configService;
|
||||
|
||||
@Autowired
|
||||
@Lazy
|
||||
private ScEquZhibiaoServiceImpl zhibiaoService;
|
||||
/**
|
||||
* 获取监测设备的数据
|
||||
*/
|
||||
|
|
@ -220,4 +226,26 @@ public class CommonServiceImpl {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 按照租户过滤数据
|
||||
* */
|
||||
|
||||
public ScreenIndexSummaryDetailVo filterTenantData(List<String> deployIds,ScreenIndexSummaryDetailVo results) {
|
||||
if(results!=null){
|
||||
List<ScEquZhibiao> zhibiaoList = zhibiaoService.getAllChemical(deployIds);
|
||||
LinkedHashMap<String, List<Double>> datas = new LinkedHashMap<>();
|
||||
if(zhibiaoList!=null && !zhibiaoList.isEmpty()){
|
||||
for (ScEquZhibiao scEquZhibiao : zhibiaoList) {
|
||||
String keys = scEquZhibiao.getName();
|
||||
List<Double> das= results.getDatas().get(keys);
|
||||
if(das!=null){
|
||||
datas.put(keys,das);
|
||||
}
|
||||
}
|
||||
}
|
||||
results.setDatas(datas);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1316,9 +1316,9 @@ public class IotCommonServiceImpl {
|
|||
}
|
||||
maps.put(ScreenIndexSummaryEnum.TNSummry.getDesc(),avgTN);
|
||||
maps.put(ScreenIndexSummaryEnum.TPSummry.getDesc(),avgTP);
|
||||
// maps.put(ScreenIndexSummaryEnum.NOSummry.getDesc(),avgNO);
|
||||
maps.put(ScreenIndexSummaryEnum.NOSummry.getDesc(),avgNO);
|
||||
maps.put(ScreenIndexSummaryEnum.CODSummry.getDesc(),avgCOD);
|
||||
// maps.put(ScreenIndexSummaryEnum.NHSummry.getDesc(),avgNH);
|
||||
maps.put(ScreenIndexSummaryEnum.NHSummry.getDesc(),avgNH);
|
||||
|
||||
screenIndexSummaryDetailVo.setDatas(maps);
|
||||
//时间
|
||||
|
|
|
|||
|
|
@ -1,11 +1,43 @@
|
|||
package org.jeecg.modules.appmana.service.impl;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
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.ScEquZhibiao;
|
||||
import org.jeecg.common.entity.SurvConfig;
|
||||
import org.jeecg.common.entity.SurvDeviceDeploy;
|
||||
import org.jeecg.common.entity.SurvHisdataVocs;
|
||||
import org.jeecg.common.iot.common.VOCommonSurvIntegrateParam;
|
||||
import org.jeecg.common.iot.common.VOSurvElement;
|
||||
import org.jeecg.common.iot.common.VOSurvIntegrateResult;
|
||||
import org.jeecg.common.iot.common.VOSurvIntegrateStinkDetail;
|
||||
import org.jeecg.common.util.DateTimeRangeUtils;
|
||||
import org.jeecg.common.vo.CommonDataTrans;
|
||||
import org.jeecg.common.vo.statistic.ScreenIndexSummaryDetailVo;
|
||||
import org.jeecg.common.vo.statistic.ScreenSummaryVo;
|
||||
import org.jeecg.modules.appmana.mapper.SurvHisdataVocsMapper;
|
||||
import org.jeecg.modules.appmana.service.ISurvDeviceDeployService;
|
||||
import org.jeecg.modules.appmana.service.ISurvHisdataVocsService;
|
||||
import org.jeecg.modules.appmana.utils.CommonUtils;
|
||||
import org.jeecg.modules.appmana.utils.Iotutils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
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.*;
|
||||
|
||||
/**
|
||||
* @Description: 恶臭实时历史数据
|
||||
* @Author: jeecg-boot
|
||||
|
|
@ -15,4 +47,385 @@ import org.springframework.stereotype.Service;
|
|||
@Service
|
||||
public class SurvHisdataVocsServiceImpl extends ServiceImpl<SurvHisdataVocsMapper, SurvHisdataVocs> implements ISurvHisdataVocsService {
|
||||
|
||||
@Autowired
|
||||
@Lazy
|
||||
private ISurvDeviceDeployService fDeviceDeployService;
|
||||
@Autowired
|
||||
@Lazy
|
||||
private SurvConfigServiceImpl configService;
|
||||
|
||||
@Override
|
||||
public ScreenIndexSummaryDetailVo getStinkSummry(ScreenSummaryVo screenSummaryVo, List<String> stinkList, String startTime, String endTime) {
|
||||
VOCommonSurvIntegrateParam voCommonSurvIntegrateParam = new VOCommonSurvIntegrateParam();
|
||||
voCommonSurvIntegrateParam.setDeployIds(stinkList);
|
||||
voCommonSurvIntegrateParam.setStartTime(startTime);
|
||||
voCommonSurvIntegrateParam.setEndTime(endTime);
|
||||
voCommonSurvIntegrateParam.setSummrayMode(screenSummaryVo.getSummrayMode());
|
||||
|
||||
StinkIntegrateStatistic(voCommonSurvIntegrateParam);
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<VOSurvIntegrateStinkDetail> integrateSummary(String tenantId, List<String> stinkList, String timeDataFormat, LocalDateTime startTime, LocalDateTime endTime) {
|
||||
return baseMapper.integrateSummary(tenantId,stinkList,timeDataFormat, startTime, endTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 监测设备综合统计
|
||||
* @param voSurvIntegrateParam
|
||||
* @return
|
||||
*/
|
||||
public VOSurvIntegrateResult StinkIntegrateStatistic(VOCommonSurvIntegrateParam voSurvIntegrateParam) {
|
||||
VOSurvIntegrateResult result = new VOSurvIntegrateResult();
|
||||
//step 1,获取所需查询的设备
|
||||
List<SurvDeviceDeploy> deploys = new ArrayList<>();
|
||||
//当前农场所配置的所有监测项目,只有配置过的。
|
||||
Map<String,String> totalSurvItems = new HashMap<>();
|
||||
|
||||
//0租户
|
||||
String tenantId = "0";
|
||||
List<String> items = new ArrayList<>();
|
||||
if(!CollectionUtils.isEmpty(voSurvIntegrateParam.getDeployIds())){
|
||||
deploys = fDeviceDeployService.getByIdsWithZhiBiao(voSurvIntegrateParam.getDeployIds());
|
||||
if(!deploys.isEmpty()){
|
||||
for (SurvDeviceDeploy deploy : deploys) {
|
||||
if(deploy.getZhibiaos()!=null && !deploy.getZhibiaos().isEmpty()){
|
||||
for (ScEquZhibiao fScEquZhibiao : deploy.getZhibiaos()) {
|
||||
items.add(fScEquZhibiao.getEntityField());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//无设备直接返回
|
||||
if(CollectionUtils.isEmpty(deploys)){
|
||||
return result;
|
||||
}else{
|
||||
if(!items.isEmpty()){
|
||||
for (String item : items) {
|
||||
totalSurvItems.put(item,item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//step 2,获取设备数据
|
||||
List<String> stinkList = voSurvIntegrateParam.getDeployIds();
|
||||
|
||||
|
||||
String timeDataFormat = "";
|
||||
LocalDateTime startDateTime = null;
|
||||
LocalDateTime endDateTime = null;
|
||||
LocalDate now = LocalDate.now();
|
||||
DateTimeFormatter dateTimeFormatter3 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
DateTimeFormatter dateTimeFormatter4 = DateTimeFormatter.ofPattern("yyyy-MM");
|
||||
switch (voSurvIntegrateParam.getSummrayMode()){
|
||||
case IotConstants.day_hours:
|
||||
timeDataFormat = "%Y-%m-%d %H";
|
||||
LocalDate days = null;
|
||||
if (StringUtils.isNotBlank(voSurvIntegrateParam.getStartTime())) {
|
||||
String isValid = Iotutils.isValidTimeFormat(voSurvIntegrateParam.getStartTime(), "yyyy-MM-dd");
|
||||
Assert.notNull(isValid, "时间格式不正确");
|
||||
days = LocalDate.parse(voSurvIntegrateParam.getStartTime(), dateTimeFormatter3);
|
||||
} else {
|
||||
days = now;
|
||||
}
|
||||
startDateTime = LocalDateTime.of(days, LocalTime.MIN);
|
||||
endDateTime = LocalDateTime.of(days, LocalTime.MAX).withNano(999999000);
|
||||
result.setIndexs(DateTimeRangeUtils.getDateTimeRange(
|
||||
startDateTime, endDateTime, DateTimeRangeUtils.TimeUnit.HOUR, "yyyy-MM-dd HH"));
|
||||
break;
|
||||
case IotConstants.month_days:
|
||||
timeDataFormat = "%Y-%m-%d";
|
||||
if (StringUtils.isNotBlank(voSurvIntegrateParam.getStartTime())) {
|
||||
int lengthof = voSurvIntegrateParam.getStartTime().length();
|
||||
if (lengthof == 10) {
|
||||
LocalDate timse = LocalDate.parse(voSurvIntegrateParam.getStartTime(), dateTimeFormatter3);
|
||||
startDateTime = LocalDateTime.of(timse.withDayOfMonth(1), LocalTime.MIN);
|
||||
endDateTime = LocalDateTime.of(startDateTime.with(TemporalAdjusters.lastDayOfMonth()).toLocalDate(), LocalTime.MAX).withNano(999999000);
|
||||
} else {
|
||||
String isValid = Iotutils.isValidTimeFormat(voSurvIntegrateParam.getStartTime(), "yyyy-MM");
|
||||
Assert.notNull(isValid, "时间格式不正确");
|
||||
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
startDateTime = LocalDateTime.parse(voSurvIntegrateParam.getStartTime() + "-01 00:00:00", dtf);
|
||||
endDateTime = LocalDateTime.of(startDateTime.with(TemporalAdjusters.lastDayOfMonth()).toLocalDate(), LocalTime.MAX).withNano(999999000);
|
||||
}
|
||||
} else {
|
||||
LocalDate date = LocalDate.of(now.getYear(), now.getMonth(), 1);
|
||||
startDateTime = LocalDateTime.of(date,LocalTime.MIN);
|
||||
endDateTime = LocalDateTime.of(now, LocalTime.MAX).withNano(999999000);
|
||||
}
|
||||
result.setIndexs(DateTimeRangeUtils.getDateTimeRange(
|
||||
startDateTime, endDateTime, DateTimeRangeUtils.TimeUnit.DAY, "yyyy-MM-dd"));
|
||||
break;
|
||||
case IotConstants.year_months:
|
||||
timeDataFormat = "%Y-%m";
|
||||
Integer year = null;
|
||||
if (StringUtils.isNotBlank(voSurvIntegrateParam.getStartTime())) {
|
||||
String isValid = Iotutils.isValidTimeFormat(voSurvIntegrateParam.getStartTime(), "yyyy");
|
||||
Assert.notNull(isValid, "时间格式不正确");
|
||||
year = Integer.parseInt(voSurvIntegrateParam.getStartTime());
|
||||
} else {
|
||||
year = now.getYear();
|
||||
}
|
||||
LocalDate date = LocalDate.of(year, 1, 1);
|
||||
LocalDate edate = LocalDate.of(year, 12, 31);
|
||||
startDateTime = LocalDateTime.of(date,LocalTime.MIN);
|
||||
endDateTime = LocalDateTime.of(edate, LocalTime.MAX).withNano(999999000);
|
||||
result.setIndexs(DateTimeRangeUtils.getDateTimeRange(
|
||||
startDateTime, endDateTime, DateTimeRangeUtils.TimeUnit.MONTH, "yyyy-MM"));
|
||||
result.setSubIndexs(DateTimeRangeUtils.getDateTimeRange(
|
||||
startDateTime, endDateTime, DateTimeRangeUtils.TimeUnit.DAY, "yyyy-MM-dd"));
|
||||
break;
|
||||
}
|
||||
|
||||
SurvConfig fSurvConfig = configService.getOneByTypeWithTenant(tenantId, IotConstants.surv_itemname);
|
||||
cn.hutool.json.JSONObject configs = null;
|
||||
if (fSurvConfig != null) {
|
||||
configs = fSurvConfig.getConfigJson();
|
||||
}
|
||||
cn.hutool.json.JSONObject desConfig = null;
|
||||
cn.hutool.json.JSONObject iconConfig = null;
|
||||
String bsIconPath = "";
|
||||
String bsIconPath2 = "";
|
||||
String h5IconPath = "";
|
||||
String appIconPath = "";
|
||||
String midIconPath = "";
|
||||
if (configs != null) {
|
||||
desConfig = configs.getJSONObject("des");
|
||||
iconConfig = configs.getJSONObject("icons");
|
||||
bsIconPath = configs.getStr("bsIconPath");
|
||||
bsIconPath2 = configs.getStr("bsIconPath2");
|
||||
h5IconPath = configs.getStr("h5IconPath");
|
||||
appIconPath = configs.getStr("appIconPath");
|
||||
midIconPath = configs.getStr("midIconPath");
|
||||
}
|
||||
|
||||
List<String> survItems = new ArrayList<>();
|
||||
Map<String,Map<String,String>> filterMap = new HashMap<>();
|
||||
Map<String,Map<String,String>> accFilterMap = new HashMap<>();
|
||||
if(!stinkList.isEmpty()) {
|
||||
List<VOSurvIntegrateStinkDetail> stinks = integrateSummary(null, stinkList, timeDataFormat, startDateTime, endDateTime);
|
||||
if (stinks.isEmpty()) {//如果airs为空,即设备未采集任何数据,则补充一条0数据,用于构造
|
||||
VOSurvIntegrateStinkDetail ent = new VOSurvIntegrateStinkDetail();
|
||||
Class<? extends VOSurvIntegrateStinkDetail> stinkClass = ent.getClass();
|
||||
Field[] fields = stinkClass.getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
field.setAccessible(true);
|
||||
if (!"dates".equals(field.getName())) {
|
||||
try {
|
||||
field.set(ent, "0");
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
field.setAccessible(false);
|
||||
}
|
||||
stinks.add(ent);
|
||||
}
|
||||
if (!stinks.isEmpty()) {
|
||||
int counts = 0;
|
||||
for (VOSurvIntegrateStinkDetail st : stinks) {
|
||||
Class<? extends VOSurvIntegrateStinkDetail> personClass = st.getClass();
|
||||
Field[] fields = personClass.getDeclaredFields();
|
||||
try {
|
||||
String curIndex = "";
|
||||
Map<String, String> eleMap = new HashMap<>();
|
||||
for (Field field : fields) {
|
||||
field.setAccessible(true);
|
||||
//过滤,未配置的不要构造进去
|
||||
if (!"dates".equals(field.getName())) {//非dates的未配置不处理
|
||||
if (totalSurvItems.get(field.getName()) == null) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
Object values = field.get(st);
|
||||
if (values != null) {
|
||||
String val = values.toString();
|
||||
|
||||
if (StringUtils.isNotBlank(val)) {
|
||||
if ("dates".equals(field.getName())) {
|
||||
curIndex = val;
|
||||
} else {
|
||||
eleMap.put(field.getName(), val);
|
||||
filterMap.put(curIndex, eleMap);
|
||||
if (counts == 0) {
|
||||
survItems.add(field.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
counts++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//mk2 年月份数据时,需要拉取日数据重新进行计算
|
||||
if(IotConstants.year_months.equals(voSurvIntegrateParam.getSummrayMode())){
|
||||
timeDataFormat = "%Y-%m-%d";
|
||||
if(!stinkList.isEmpty()) {
|
||||
List<VOSurvIntegrateStinkDetail> dayStink = integrateSummary(null, stinkList, timeDataFormat, startDateTime, endDateTime);
|
||||
if (!dayStink.isEmpty()) {
|
||||
for (VOSurvIntegrateStinkDetail dayData : dayStink) {
|
||||
Class<? extends VOSurvIntegrateStinkDetail> personClass = dayData.getClass();
|
||||
Field[] fields = personClass.getDeclaredFields();
|
||||
try {
|
||||
String curIndex = "";
|
||||
Map<String, String> eleMap = new HashMap<>();
|
||||
for (Field field : fields) {
|
||||
field.setAccessible(true);
|
||||
//过滤,未配置的不要构造进去
|
||||
if (!"dates".equals(field.getName())) {//非dates的未配置不处理
|
||||
if (totalSurvItems.get(field.getName()) == null) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
Object values = field.get(dayData);
|
||||
if (values != null) {
|
||||
String val = values.toString();
|
||||
if (StringUtils.isNotBlank(val)) {
|
||||
if ("dates".equals(field.getName())) {
|
||||
curIndex = val;
|
||||
} else {
|
||||
eleMap.put(field.getName(), val);
|
||||
accFilterMap.put(curIndex, eleMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Map<String,String> accItems = new HashMap<>();
|
||||
LinkedHashMap<String,List<String>> dataMap = new LinkedHashMap<>();
|
||||
LinkedHashMap<String, BigDecimal> hisHourData = new LinkedHashMap<>();
|
||||
for (String index : result.getIndexs()) {
|
||||
Map<String,String> ele = filterMap.get(index);
|
||||
for (String survItem : survItems) {
|
||||
List<String> dataList = dataMap.get(survItem);
|
||||
if(dataList == null){
|
||||
dataList = new ArrayList<>();
|
||||
}
|
||||
if(ele != null){
|
||||
String val = ele.get(survItem);
|
||||
if(val==null){//如果配置了此监测项,但是在这个时段没有数据,则补充0
|
||||
val = "0";
|
||||
}
|
||||
BigDecimal cVal = new BigDecimal(val);
|
||||
int dataCounts = dataList.size();
|
||||
if(Iotutils.isEntityAccumulate(survItem)){//累计监测项处理
|
||||
accItems.put(survItem,survItem);//记录需要处理的检测项
|
||||
if(IotConstants.day_hours.equals(voSurvIntegrateParam.getSummrayMode())){//小时模式,处理差值,计算增量
|
||||
BigDecimal finalData = BigDecimal.ZERO;
|
||||
if(dataCounts == 0){//第一条数据,减0
|
||||
finalData = cVal.subtract(BigDecimal.ZERO);
|
||||
}else{
|
||||
int lastKey = dataCounts-1;
|
||||
BigDecimal lastData = hisHourData.get(survItem+"_"+lastKey);
|
||||
finalData = cVal.subtract(lastData);
|
||||
}
|
||||
val = Iotutils.toStringData(finalData);
|
||||
hisHourData.put(survItem+"_"+dataCounts,cVal);
|
||||
}
|
||||
}
|
||||
dataList.add(val!=null?val:"0");
|
||||
}else{//无数据做补充
|
||||
dataList.add("0");
|
||||
}
|
||||
dataMap.put(survItem,dataList);
|
||||
}
|
||||
}
|
||||
//mk2 年月份模式,处理累计型数据
|
||||
if(IotConstants.year_months.equals(voSurvIntegrateParam.getSummrayMode())){
|
||||
Map<String,LinkedHashMap<String,BigDecimal>> dataPool = new LinkedHashMap<>();
|
||||
//step 1 遍历日数据,存入map,统计为每月的各项监测值的和
|
||||
for (String index : result.getSubIndexs()) {
|
||||
Map<String,String> accEle = accFilterMap.get(index);
|
||||
LocalDate indexDate = LocalDate.parse(index,dateTimeFormatter3);
|
||||
String monthKey = indexDate.format(dateTimeFormatter4);
|
||||
LinkedHashMap<String,BigDecimal> hisData = dataPool.get(monthKey);
|
||||
if(hisData == null){
|
||||
hisData = new LinkedHashMap<>();
|
||||
}
|
||||
for (String itemKey : accItems.keySet()) {
|
||||
BigDecimal itemVal = hisData.get(itemKey);
|
||||
if(itemVal==null){
|
||||
itemVal = BigDecimal.ZERO;
|
||||
}
|
||||
if(accEle != null){
|
||||
String val = accEle.get(itemKey);
|
||||
BigDecimal cVal = new BigDecimal(val);
|
||||
BigDecimal finalVal = cVal.add(itemVal);
|
||||
hisData.put(itemKey,finalVal);
|
||||
}else{//无数据时跳过,只处理有数据的
|
||||
|
||||
}
|
||||
dataPool.put(monthKey,hisData);
|
||||
}
|
||||
}
|
||||
|
||||
//将dataMap中填充的均值统计清除,重新处理
|
||||
for (String itemKey : accItems.keySet()) {
|
||||
dataMap.remove(itemKey);
|
||||
}
|
||||
//step 2 组装为月数据
|
||||
for (String index : result.getIndexs()) {
|
||||
LinkedHashMap<String,BigDecimal> monthData = dataPool.get(index);
|
||||
for (String itemKey : accItems.keySet()) {
|
||||
List<String> dataList = dataMap.get(itemKey);
|
||||
if(dataList == null){
|
||||
dataList = new ArrayList<>();
|
||||
}
|
||||
dataList.add(Iotutils.toStringData(monthData.get(itemKey)));
|
||||
dataMap.put(itemKey,dataList);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
result.setSurvResult(dataMap);
|
||||
//遍历数据值,翻译
|
||||
List<VOSurvElement> eleList = new ArrayList<>();
|
||||
if(!dataMap.isEmpty()){
|
||||
for (String s : dataMap.keySet()) {
|
||||
if (s.startsWith("data")) {
|
||||
PollutionEnum pollutionEnum = PollutionEnum.catchPollution(s);
|
||||
String iconFinalName = pollutionEnum.getIconName();
|
||||
String itemFinalName = pollutionEnum.getDescription();
|
||||
String bsIcon = pollutionEnum.getBsIcon();
|
||||
if (configs != null) {
|
||||
String itemName = desConfig != null ? desConfig.getStr(pollutionEnum.getCode()) : "";
|
||||
String iconName = iconConfig != null ? iconConfig.getStr(pollutionEnum.getCode()) : "";
|
||||
if (StringUtils.isNotBlank(itemName)) {
|
||||
itemFinalName = itemName;
|
||||
}
|
||||
if (StringUtils.isNotBlank(iconName)) {
|
||||
iconFinalName = iconName;
|
||||
}
|
||||
if (StringUtils.isNotBlank(bsIconPath)) {
|
||||
bsIcon = bsIconPath + iconFinalName;
|
||||
}
|
||||
}
|
||||
VOSurvElement voSurvElement = new VOSurvElement();
|
||||
voSurvElement.setEleDesc(itemFinalName+"("+pollutionEnum.getUnit()+")");
|
||||
voSurvElement.setEleField(s);
|
||||
eleList.add(voSurvElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
result.setHeaders(eleList);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,10 +14,7 @@ import org.jeecg.common.util.DateUtilTools;
|
|||
import org.jeecg.common.util.SpringContextUtils;
|
||||
import org.jeecg.common.vo.CommonDataTrans;
|
||||
import org.jeecg.common.vo.SurvTransdataStinkVo;
|
||||
import org.jeecg.modules.appmana.service.IScEquZhibiaoService;
|
||||
import org.jeecg.modules.appmana.service.ISurvConfigService;
|
||||
import org.jeecg.modules.appmana.service.ISurvTransdataAirService;
|
||||
import org.jeecg.modules.appmana.service.ISurvTransdataSoilService;
|
||||
import org.jeecg.modules.appmana.service.*;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
package org.jeecg.common.iot.common;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class VOCommonSurvIntegrateParam {
|
||||
@ApiModelProperty("站点编号")
|
||||
private String stationCode;
|
||||
@ApiModelProperty("设备部署id")
|
||||
private List<String> deployIds;
|
||||
@ApiModelProperty("开始时间")
|
||||
private String startTime;
|
||||
@ApiModelProperty("结束时间")
|
||||
private String endTime;
|
||||
@ApiModelProperty("统计模式,dayhours=日小时统计,monthDays=月每日统计,yearMonth=年每月统计")
|
||||
private String summrayMode;
|
||||
@ApiModelProperty("租户号")
|
||||
private String authId;
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package org.jeecg.common.iot.common;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
|
||||
@Data
|
||||
public class VOSurvIntegrateStinkDetail {
|
||||
@ApiModelProperty("时间")
|
||||
private String dates;
|
||||
/**总挥发性有机物*/
|
||||
@Excel(name = "总挥发性有机物", width = 15)
|
||||
@ApiModelProperty(value = "总挥发性有机物")
|
||||
private java.lang.String dataTvoc;
|
||||
/**臭气浓度*/
|
||||
@Excel(name = "臭气浓度", width = 15)
|
||||
@ApiModelProperty(value = "臭气浓度")
|
||||
private java.lang.String dataOu;
|
||||
/**氨气*/
|
||||
@Excel(name = "氨气", width = 15)
|
||||
@ApiModelProperty(value = "氨气")
|
||||
private java.lang.String dataNh3;
|
||||
/**硫化氢*/
|
||||
@Excel(name = "硫化氢", width = 15)
|
||||
@ApiModelProperty(value = "硫化氢")
|
||||
private java.lang.String dataH2s;
|
||||
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue