|
@@ -12,6 +12,7 @@ import com.huaxu.service.OnlineMonitorService;
|
|
|
import com.huaxu.util.ByteArrayUtils;
|
|
|
import com.huaxu.util.RedisUtil;
|
|
|
import com.huaxu.util.UserUtil;
|
|
|
+import io.swagger.annotations.ApiModelProperty;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -203,35 +204,7 @@ public class OnlineMonitorImpl implements OnlineMonitorService {
|
|
|
//1是公司,2是公司及以下,3部门,4部门及以下,5自定义
|
|
|
monitorDataCollectDto.setPermissonType(loginUser.getPermissonType());
|
|
|
List<MonitorDataCollectDto> result=onlineMonitorMapper.selectDeviceMapParam(monitorDataCollectDto);
|
|
|
- for(MonitorDataCollectDto monDataCol :result) {
|
|
|
- //取缓存里的数据
|
|
|
- byte[] bytes = redisUtil.get(("sms_water_" + monDataCol.getDeviceCode()).getBytes());
|
|
|
- MonitorDataEntity monitorDataEntity = null;
|
|
|
- if (bytes != null && bytes.length > 0) {
|
|
|
- monitorDataEntity = (MonitorDataEntity) ByteArrayUtils.bytesToObject(bytes).get();
|
|
|
- SimpleDateFormat formatdate = new SimpleDateFormat("YYYY-MM-dd");//日期算换格式
|
|
|
- monDataCol.setCollectDate(monitorDataEntity.getCollectDate());
|
|
|
- }
|
|
|
- for (MonitorDataDto monData : monDataCol.getMonitorDataEntities()) {
|
|
|
- if (monitorDataEntity != null) {
|
|
|
- //筛选该设备相同属性的值
|
|
|
- List<MonitorDataValueEntity> attributeEntities = monitorDataEntity.getDataValues().stream().filter((MonitorDataValueEntity m)
|
|
|
- -> m.getAttributeId().equals(monData.getAttributeId())).collect(Collectors.toList());
|
|
|
- MonitorDataValueEntity attributeEntity = attributeEntities.size() > 0 ? attributeEntities.get(0) : null;
|
|
|
- if (attributeEntity != null) {
|
|
|
- //赋值
|
|
|
- monData.setDataValue(attributeEntity.getDataValue());
|
|
|
- monData.setUnit(attributeEntity.getUnit());
|
|
|
- if (monData.getAttributeType() != null && (monData.getAttributeType().equals("1") || monData.getAttributeType().equals("2"))) {//如果是状态值 需转换
|
|
|
- DecimalFormat decimalFormat = new DecimalFormat("###################.###########");//去掉末尾小数点
|
|
|
- String specsValue = attributeEntity.getDataValue() == null ? null : decimalFormat.format(attributeEntity.getDataValue());
|
|
|
- monData.setSpecsName(specsValue == null ? null : deviceAttributeSpecsService.selectSpecsName(attributeEntity.getAttributeId(), specsValue));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ GetCalMonitorData(result,new ArrayList<MonitorDataCollectDto>());
|
|
|
return result;
|
|
|
}
|
|
|
/**
|
|
@@ -271,35 +244,7 @@ public class OnlineMonitorImpl implements OnlineMonitorService {
|
|
|
onlineDataDto.setPermissonType(loginUser.getPermissonType());
|
|
|
|
|
|
List<MonitorDataCollectDto> result=onlineMonitorMapper.statsDeviceParm(onlineDataDto);
|
|
|
- for(MonitorDataCollectDto monDataCol :result) {
|
|
|
- //取缓存里的数据
|
|
|
- byte[] bytes = redisUtil.get(("sms_water_" + monDataCol.getDeviceCode()).getBytes());
|
|
|
- MonitorDataEntity monitorDataEntity = null;
|
|
|
- if (bytes != null && bytes.length > 0) {
|
|
|
- monitorDataEntity = (MonitorDataEntity) ByteArrayUtils.bytesToObject(bytes).get();
|
|
|
- SimpleDateFormat formatdate = new SimpleDateFormat("YYYY-MM-dd");//日期算换格式
|
|
|
- monDataCol.setCollectDate(monitorDataEntity.getCollectDate());
|
|
|
- }
|
|
|
- for (MonitorDataDto monitorData : monDataCol.getMonitorDataEntities()) {
|
|
|
- if (monitorDataEntity != null) {
|
|
|
- SimpleDateFormat formatdate = new SimpleDateFormat("YYYY-MM-dd");//日期算换格式
|
|
|
- //计算今日数据
|
|
|
- if (formatdate.format(new Date()).equals(formatdate.format(monitorDataEntity.getCollectDate()))) {
|
|
|
- //筛选该设备相同属性的值
|
|
|
- List<MonitorDataValueEntity> attributeEntities = monitorDataEntity.getDataValues().stream().filter((MonitorDataValueEntity m)
|
|
|
- -> m.getAttributeId().equals(monitorData.getAttributeId())).collect(Collectors.toList());
|
|
|
- MonitorDataValueEntity attributeEntity = attributeEntities.size() > 0 ? attributeEntities.get(0) : null;
|
|
|
- if (attributeEntity != null) {
|
|
|
- Double attributeValue = 0d;
|
|
|
- if (attributeEntity.getDataValue() != null && monitorData.getLatestValue() != null) {
|
|
|
- attributeValue = attributeEntity.getDataValue() - monitorData.getLatestValue();
|
|
|
- }
|
|
|
- monDataCol.setYieldWaterUsage(monDataCol.getYieldWaterUsage() != null ? monDataCol.getYieldWaterUsage() + attributeValue : attributeValue);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ GetCalMonitorData(result,result);
|
|
|
return result;
|
|
|
}
|
|
|
/**
|
|
@@ -320,6 +265,8 @@ public class OnlineMonitorImpl implements OnlineMonitorService {
|
|
|
if(onlineDataDto.getSceneTypeName().equals("压力")){
|
|
|
deviceCount=new int[5];
|
|
|
}
|
|
|
+ Double avgValue=null,maxValue=null,minValue=null;
|
|
|
+ String maxDeviceName=null,minDeviceName=null;
|
|
|
List<MonitorDataCollectDto> result=onlineMonitorMapper.statsDeviceParm(onlineDataDto);
|
|
|
for(MonitorDataCollectDto monDataCol :result) {
|
|
|
//取缓存里的数据
|
|
@@ -327,11 +274,10 @@ public class OnlineMonitorImpl implements OnlineMonitorService {
|
|
|
MonitorDataEntity monitorDataEntity = null;
|
|
|
if (bytes != null && bytes.length > 0) {
|
|
|
monitorDataEntity = (MonitorDataEntity) ByteArrayUtils.bytesToObject(bytes).get();
|
|
|
- SimpleDateFormat formatdate = new SimpleDateFormat("YYYY-MM-dd");//日期算换格式
|
|
|
- monDataCol.setCollectDate(monitorDataEntity.getCollectDate());
|
|
|
}
|
|
|
for (MonitorDataDto monitorData : monDataCol.getMonitorDataEntities()) {
|
|
|
if (monitorDataEntity != null) {
|
|
|
+ monDataCol.setCollectDate(monitorDataEntity.getCollectDate());
|
|
|
SimpleDateFormat formatdate = new SimpleDateFormat("YYYY-MM-dd");//日期算换格式
|
|
|
//筛选该设备相同属性的值
|
|
|
List<MonitorDataValueEntity> attributeEntities = monitorDataEntity.getDataValues().stream().filter((MonitorDataValueEntity m)
|
|
@@ -341,6 +287,22 @@ public class OnlineMonitorImpl implements OnlineMonitorService {
|
|
|
Double dataValue= attributeEntity.getDataValue();
|
|
|
if(dataValue!=null){
|
|
|
if(onlineDataDto.getSceneTypeName().equals("压力")){
|
|
|
+ avgValue=avgValue==null?dataValue:(avgValue+dataValue)/2;
|
|
|
+ boolean isMaxEquals=dataValue.equals(maxValue);
|
|
|
+ boolean isMinEquals=dataValue.equals(minValue);
|
|
|
+ if(isMaxEquals) {
|
|
|
+ maxDeviceName += monDataCol.getDeviceName();
|
|
|
+ }else if(isMinEquals){
|
|
|
+ minDeviceName+=monDataCol.getDeviceName();
|
|
|
+ }
|
|
|
+ maxValue=Math.max(maxValue==null?dataValue:maxValue,dataValue);
|
|
|
+ minValue=Math.min(minValue==null?dataValue:minValue,dataValue);
|
|
|
+ if(maxValue.equals(dataValue)&&!isMaxEquals) {
|
|
|
+ maxDeviceName = monDataCol.getDeviceName();
|
|
|
+ }
|
|
|
+ if(minValue.equals(dataValue)&&!isMinEquals) {
|
|
|
+ minDeviceName = monDataCol.getDeviceName();
|
|
|
+ }
|
|
|
if(dataValue<=0.2){
|
|
|
deviceCount[0]++;
|
|
|
}else if(dataValue<=0.25) {
|
|
@@ -374,6 +336,11 @@ public class OnlineMonitorImpl implements OnlineMonitorService {
|
|
|
}
|
|
|
DistributeIntervalDto distributeIntervalDto=new DistributeIntervalDto();
|
|
|
distributeIntervalDto.setDistributeValue(deviceCount);
|
|
|
+ distributeIntervalDto.setAvgValue(avgValue);
|
|
|
+ distributeIntervalDto.setMaxValue(maxValue);
|
|
|
+ distributeIntervalDto.setMinValue(minValue);
|
|
|
+ distributeIntervalDto.setMaxDeviceName(maxDeviceName);
|
|
|
+ distributeIntervalDto.setMinDeviceName(minDeviceName);
|
|
|
return distributeIntervalDto;
|
|
|
}
|
|
|
/**
|
|
@@ -420,14 +387,23 @@ public class OnlineMonitorImpl implements OnlineMonitorService {
|
|
|
*/
|
|
|
public void GetCalMonitorData(List<MonitorDataCollectDto> result,List<MonitorDataCollectDto> calculateRes){
|
|
|
for(MonitorDataCollectDto monDataCol : result) {
|
|
|
+ MonitorDataEntity monitorDataEntity =null;
|
|
|
+ if(monDataCol.getDeviceId()!=null) {
|
|
|
+ //取缓存里的数据
|
|
|
+ byte[] bytes = redisUtil.get(("sms_water_"+monDataCol.getDeviceCode()).getBytes());
|
|
|
+ if(bytes != null && bytes.length>0) {
|
|
|
+ monitorDataEntity = (MonitorDataEntity) ByteArrayUtils.bytesToObject(bytes).get();}
|
|
|
+ }
|
|
|
//获取最新数据 更新
|
|
|
for(MonitorDataDto monData : monDataCol.getMonitorDataEntities()) {
|
|
|
- //取缓存里的数据
|
|
|
- byte[] bytes = redisUtil.get(("sms_water_"+monData.getDeviceCode()).getBytes());
|
|
|
- if(bytes != null && bytes.length>0){
|
|
|
- MonitorDataEntity monitorDataEntity= (MonitorDataEntity) ByteArrayUtils.bytesToObject(bytes).get();
|
|
|
- SimpleDateFormat formatdate = new SimpleDateFormat("YYYY-MM-dd");//日期算换格式
|
|
|
+ if(monDataCol.getDeviceId()==null) {
|
|
|
+ byte[] bytes = redisUtil.get(("sms_water_"+monData.getDeviceCode()).getBytes());
|
|
|
+ if(bytes != null && bytes.length>0) {
|
|
|
+ monitorDataEntity = (MonitorDataEntity) ByteArrayUtils.bytesToObject(bytes).get();}
|
|
|
+ }
|
|
|
+ if(monitorDataEntity != null) {
|
|
|
monDataCol.setCollectDate(monitorDataEntity.getCollectDate());
|
|
|
+ SimpleDateFormat formatdate = new SimpleDateFormat("YYYY-MM-dd");//日期算换格式
|
|
|
//筛选该设备相同属性的值
|
|
|
List<MonitorDataValueEntity> attributeEntities=monitorDataEntity.getDataValues().stream().filter((MonitorDataValueEntity m)
|
|
|
->m.getAttributeId().equals(monData.getAttributeId())).collect(Collectors.toList());
|
|
@@ -446,13 +422,16 @@ public class OnlineMonitorImpl implements OnlineMonitorService {
|
|
|
}
|
|
|
//计算数据 更新
|
|
|
for(MonitorDataCollectDto calculate :calculateRes ) {
|
|
|
- //相同场景 则计算
|
|
|
- if(monDataCol.getSceneId().equals(calculate.getSceneId())) {
|
|
|
+ //相同场景或设备 则取值计算
|
|
|
+ if((monDataCol.getDeviceId()==null&&monDataCol.getSceneId().equals(calculate.getSceneId()))||
|
|
|
+ (monDataCol.getDeviceId()!=null&&monDataCol.getDeviceId().equals(calculate.getDeviceId()))) {
|
|
|
for(MonitorDataDto monitorData : calculate.getMonitorDataEntities()){
|
|
|
- //取缓存里的数据
|
|
|
- byte[] bytes = redisUtil.get(("sms_water_"+monitorData.getDeviceCode()).getBytes());
|
|
|
- if(bytes != null && bytes.length>0) {
|
|
|
- MonitorDataEntity monitorDataEntity = (MonitorDataEntity) ByteArrayUtils.bytesToObject(bytes).get();
|
|
|
+ if(monDataCol.getDeviceId()==null) {
|
|
|
+ byte[] bytes = redisUtil.get(("sms_water_"+monitorData.getDeviceCode()).getBytes());
|
|
|
+ if(bytes != null && bytes.length>0) {
|
|
|
+ monitorDataEntity = (MonitorDataEntity) ByteArrayUtils.bytesToObject(bytes).get();}
|
|
|
+ }
|
|
|
+ if(monitorDataEntity != null) {
|
|
|
SimpleDateFormat formatdate = new SimpleDateFormat("YYYY-MM-dd");//日期算换格式
|
|
|
//计算今日数据
|
|
|
if(formatdate.format(new Date()).equals(formatdate.format(monitorDataEntity.getCollectDate()))) {
|
|
@@ -467,6 +446,7 @@ public class OnlineMonitorImpl implements OnlineMonitorService {
|
|
|
}
|
|
|
switch (monitorData.getAttributeType()) {
|
|
|
case "3":
|
|
|
+ case "16":
|
|
|
monDataCol.setYieldWaterUsage(monDataCol.getYieldWaterUsage() != null ? monDataCol.getYieldWaterUsage() + attributeValue : attributeValue);
|
|
|
break;
|
|
|
case "4":
|
|
@@ -492,17 +472,17 @@ public class OnlineMonitorImpl implements OnlineMonitorService {
|
|
|
*/
|
|
|
public void GetCalOnlineData(List<OnlineDataDto> result,List<MonitorDataCollectDto> calculateRes){
|
|
|
for(MonitorDataCollectDto calculate :calculateRes ) {
|
|
|
+ MonitorDataEntity monitorDataEntity =null;
|
|
|
+ if(calculate.getDeviceId()!=null) {
|
|
|
+ //取缓存里的数据
|
|
|
+ byte[] bytes = redisUtil.get(("sms_water_"+calculate.getDeviceCode()).getBytes());
|
|
|
+ if(bytes != null && bytes.length>0) {
|
|
|
+ monitorDataEntity = (MonitorDataEntity) ByteArrayUtils.bytesToObject(bytes).get();}
|
|
|
+ }
|
|
|
for(OnlineDataDto monDataCol : result) {
|
|
|
- //相同场景 则取值计算
|
|
|
+ //相同场景或设备 则取值计算
|
|
|
if((monDataCol.getDeviceId()==null&&monDataCol.getSceneId().equals(calculate.getSceneId()))||
|
|
|
(monDataCol.getDeviceId()!=null&&monDataCol.getDeviceId().equals(calculate.getDeviceId()))) {
|
|
|
- MonitorDataEntity monitorDataEntity =null;
|
|
|
- if(monDataCol.getDeviceId()!=null) {
|
|
|
- //取缓存里的数据
|
|
|
- byte[] bytes = redisUtil.get(("sms_water_"+monDataCol.getDeviceCode()).getBytes());
|
|
|
- if(bytes != null && bytes.length>0) {
|
|
|
- monitorDataEntity = (MonitorDataEntity) ByteArrayUtils.bytesToObject(bytes).get();}
|
|
|
- }
|
|
|
List<MonitorDataDto> pumpStatus=new ArrayList<>(0);//水泵状态
|
|
|
for(MonitorDataDto monitorData : calculate.getMonitorDataEntities()){
|
|
|
if(monDataCol.getDeviceId()==null) {
|