From f6ecfd331ec959d7daea3fa5ebc262e7a50e4e01 Mon Sep 17 00:00:00 2001 From: jinpengyong <jpy123456> Date: Fri, 14 Jan 2022 15:20:54 +0800 Subject: [PATCH] 图片上传测试 --- screen-api/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java | 129 +++++++++++++++++++++++++++++++++--------- 1 files changed, 101 insertions(+), 28 deletions(-) diff --git a/screen-api/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java index 5c01832..734b4dd 100644 --- a/screen-api/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java +++ b/screen-api/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java @@ -1,13 +1,36 @@ package com.moral.api.service.impl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.ObjectUtils; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.OptionalDouble; +import java.util.function.Supplier; +import java.util.stream.Collectors; +import java.util.stream.DoubleStream; +import java.util.stream.Stream; + import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.moral.api.config.mybatis.MybatisPlusConfig; -import com.moral.api.entity.*; +import com.moral.api.entity.Device; +import com.moral.api.entity.GeoCoordinate; +import com.moral.api.entity.HistoryHourly; +import com.moral.api.entity.Organization; import com.moral.api.mapper.DeviceMapper; import com.moral.api.mapper.HistoryHourlyMapper; import com.moral.api.service.HistoryHourlyService; import com.moral.api.service.OrganizationService; +import com.moral.api.service.SensorService; import com.moral.api.utils.GetCenterPointFromListOfCoordinates; import com.moral.constant.Constants; import com.moral.constant.SeparateTableType; @@ -16,15 +39,6 @@ import com.moral.util.DateUtils; import com.moral.util.MybatisPLUSUtils; import com.moral.util.PollutantUtils; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.util.ObjectUtils; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.*; -import java.util.stream.Collectors; /** * <p> @@ -532,23 +546,26 @@ String mac = map.get("mac").toString(); String sensorCode = map.get("sensor_code").toString(); String date = map.get("date").toString(); - String dateTime = date.replace("-",""); - String timeUnits = dateTime.substring(0,6)+"_complete"; - Map<String,Object> params = new HashMap<>(); - params.put("timeUnits",timeUnits); - params.put("mac",mac); + String dateTime = date.replace("-", ""); + String timeUnits = dateTime.substring(0, 6) + "_complete"; + Map<String, Object> params = new HashMap<>(); + params.put("timeUnits", timeUnits); + params.put("mac", mac); List resultList = new ArrayList(); - for (int i = 0; i < 13; i++) { - Map<String,Object> oneHourDateMap = new HashMap<>(); + for (int i = 0; i < 24; i++) { + Map<String, Object> oneHourDateMap = new HashMap<>(); String j; - if (i<10){ - j = " 0"+i+":00:00"; - }else { - j = " "+i+":00:00"; + if (i < 10) { + j = " 0" + i + ":00:00"; + } else { + j = " " + i + ":00:00"; } - String time = date+j; - params.put("time",time); - if (ObjectUtils.isEmpty(historyHourlyMapper.selectHourlyData(params))){ + String time = date + j; + params.put("time", time); + String resultTime = time.substring(0, 13); + if (ObjectUtils.isEmpty(historyHourlyMapper.selectHourlyData(params))) { + oneHourDateMap.put("time", resultTime); + oneHourDateMap.put("values", new ArrayList<>()); resultList.add(oneHourDateMap); continue; } @@ -556,11 +573,11 @@ oneHourlyData = historyHourlyMapper.selectHourlyData(params); JSONObject js = JSONObject.parseObject(oneHourlyData); String sensorDate = js.get(sensorCode).toString(); - sensorDate = sensorDate.replace("[",""); - sensorDate = sensorDate.replace("]",""); + sensorDate = sensorDate.replace("[", ""); + sensorDate = sensorDate.replace("]", ""); String[] split = sensorDate.split(","); - oneHourDateMap.put("time",time); - oneHourDateMap.put("values",split); + oneHourDateMap.put("time", resultTime); + oneHourDateMap.put("values", split); resultList.add(oneHourDateMap); } return resultList; @@ -594,6 +611,62 @@ return multiTableQuery(queryWrapper, tableNames); } + @Override + public Double calculatedValue(List<HistoryHourly> list, String sensorCode, String type, Double lower, Double upper) { + Supplier<Stream<HistoryHourly>> supplier = list::stream; + DoubleStream doubleStream = supplier.get() + .flatMapToDouble(v -> { + Map<String, Object> dataValue = JSONObject.parseObject(v.getValue(), Map.class); + Object sensorValue = dataValue.get(sensorCode); + + if (ObjectUtils.isEmpty(sensorValue)) { + return null; + } + + //��������������������� + Object flag = dataValue.get(sensorCode + "-" + Constants.MARKER_BIT_KEY); + if (!Constants.MARKER_BIT_TRUE.equals(flag)) { + return null; + } + + double aDouble = Double.parseDouble(sensorValue.toString()); + + //������������������������������ + if (!ObjectUtils.isEmpty(lower)) { + if (aDouble < lower) { + return null; + } + } + if (!ObjectUtils.isEmpty(upper)) { + if (aDouble > upper) { + return null; + } + } + + return DoubleStream.of(aDouble); + }); + Double result = null; + OptionalDouble optionalDouble = null; + if ("sum".equals(type)) { + result = doubleStream.sum(); + } else { + if ("min".equals(type)) { + optionalDouble = doubleStream.min(); + + } else if ("max".equals(type)) { + optionalDouble = doubleStream.max(); + + } else if ("avg".equals(type)) { + optionalDouble = doubleStream.average(); + } + + if (optionalDouble.isPresent()) { + result = optionalDouble.getAsDouble(); + } + } + return result; + } + /** * @Description: ������������������������������������������������wrapper��������������� * @Param: [wrapper, tableNames] -- Gitblit v1.8.0