| | |
| | | import com.moral.api.utils.GetCenterPointFromListOfCoordinates; |
| | | import com.moral.constant.Constants; |
| | | 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.function.Supplier; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.DoubleStream; |
| | | import java.util.stream.Stream; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | .in("mac", macs); |
| | | return historyMonthlyMapper.selectList(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public Double calculatedValue(List<HistoryMonthly> list, String sensorCode, String type) { |
| | | Supplier<Stream<HistoryMonthly>> 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; |
| | | } |
| | | double aDouble = Double.parseDouble(sensorValue.toString()); |
| | | return DoubleStream.of(aDouble); |
| | | }); |
| | | Double result = null; |
| | | OptionalDouble optionalDouble = null; |
| | | if ("sum".equals(type)) { |
| | | result = doubleStream.sum(); |
| | | } else { |
| | | if ("min".equals(type)) { |
| | | optionalDouble = doubleStream.average(); |
| | | |
| | | } else if ("max".equals(type)) { |
| | | optionalDouble = doubleStream.min(); |
| | | |
| | | } else if ("avg".equals(type)) { |
| | | optionalDouble = doubleStream.max(); |
| | | } |
| | | |
| | | if (optionalDouble.isPresent()) { |
| | | result = optionalDouble.getAsDouble(); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | } |