Commit f7064691 by 杨伟程

日睡眠图表

parent 43c81ecb
...@@ -5,13 +5,56 @@ import java.math.RoundingMode; ...@@ -5,13 +5,56 @@ import java.math.RoundingMode;
public class MathUtil { public class MathUtil {
public static BigDecimal divideZero(BigDecimal a, BigDecimal b, int scale, RoundingMode roundingMode) { public static int divideZero(int a, int b) {
if (b == 0) {
return 0;
}
return a / b;
}
public static long divideZero(long a, long b) {
if (b == 0) {
return 0;
}
return a / b;
}
public static Integer divideNull(int a, int b) {
if (b == 0) {
return null;
}
return a / b;
}
public static Long divideNull(long a, long b) {
if (b == 0) {
return null;
}
return a / b;
}
public static BigDecimal divideNull(BigDecimal a, BigDecimal b, int scale, RoundingMode roundingMode) {
if (b.compareTo(BigDecimal.ZERO) == 0) {
return null;
}
return a.divide(b, scale, roundingMode);
}
public static BigDecimal decimalDivideZero(BigDecimal a, BigDecimal b, int scale, RoundingMode roundingMode) {
if (b.compareTo(BigDecimal.ZERO) == 0) { if (b.compareTo(BigDecimal.ZERO) == 0) {
return BigDecimal.ZERO; return BigDecimal.ZERO;
} }
return a.divide(b, scale, roundingMode); return a.divide(b, scale, roundingMode);
} }
public static BigDecimal decimalDivideNull(BigDecimal a, BigDecimal b, int scale, RoundingMode roundingMode) {
if (b.compareTo(BigDecimal.ZERO) == 0) {
return null;
}
return a.divide(b, scale, roundingMode);
}
public static BigDecimal min(BigDecimal a, BigDecimal b) { public static BigDecimal min(BigDecimal a, BigDecimal b) {
BigDecimal min = a; BigDecimal min = a;
...@@ -41,11 +84,12 @@ public class MathUtil { ...@@ -41,11 +84,12 @@ public class MathUtil {
return Math.min(Math.min(a, b), c); return Math.min(Math.min(a, b), c);
} }
public static Long orZero(Long a){ public static Long orZero(Long a) {
return a==null?0L:a; return a == null ? 0L : a;
} }
public static Integer orZero(Integer a){
return a==null?0:a; public static Integer orZero(Integer a) {
return a == null ? 0 : a;
} }
} }
...@@ -491,10 +491,17 @@ public class PlatElderDayReportWeekServiceImpl implements PlatElderDayReportWeek ...@@ -491,10 +491,17 @@ public class PlatElderDayReportWeekServiceImpl implements PlatElderDayReportWeek
platElderBreatheDayStat.setHeartRateMax(breatheList.stream().map(i -> i.getProperties().getHr()).max(Integer::compareTo).orElse(null)); platElderBreatheDayStat.setHeartRateMax(breatheList.stream().map(i -> i.getProperties().getHr()).max(Integer::compareTo).orElse(null));
platElderBreatheDayStat.setHeartRateMin(breatheList.stream().map(i -> i.getProperties().getHr()).min(Integer::compareTo).orElse(null)); platElderBreatheDayStat.setHeartRateMin(breatheList.stream().map(i -> i.getProperties().getHr()).min(Integer::compareTo).orElse(null));
platElderBreatheDayStat.setHeartRateAvg((int) (StreamUtil.reduce(breatheList, i -> (long) i.getProperties().getHr(), 0L, Long::sum) / breatheList.size()));
if (CollectionUtils.isNotEmpty(breatheList)) {
platElderBreatheDayStat.setHeartRateAvg((int) (StreamUtil.reduce(breatheList, i -> (long) i.getProperties().getHr(), 0L, Long::sum) / breatheList.size()));
}
platElderBreatheDayStat.setRespiratoryRateMax(breatheList.stream().map(i -> i.getProperties().getBr()).max(Integer::compareTo).orElse(null)); platElderBreatheDayStat.setRespiratoryRateMax(breatheList.stream().map(i -> i.getProperties().getBr()).max(Integer::compareTo).orElse(null));
platElderBreatheDayStat.setRespiratoryRateMin(breatheList.stream().map(i -> i.getProperties().getBr()).min(Integer::compareTo).orElse(null)); platElderBreatheDayStat.setRespiratoryRateMin(breatheList.stream().map(i -> i.getProperties().getBr()).min(Integer::compareTo).orElse(null));
platElderBreatheDayStat.setRespiratoryRateAvg((int) (StreamUtil.reduce(breatheList, i -> (long) i.getProperties().getBr(), 0L, Long::sum) / breatheList.size()));
if (CollectionUtils.isNotEmpty(breatheList)) {
platElderBreatheDayStat.setRespiratoryRateAvg((int) (StreamUtil.reduce(breatheList, i -> (long) i.getProperties().getBr(), 0L, Long::sum) / breatheList.size()));
}
breatheDayStatList.add(platElderBreatheDayStat); breatheDayStatList.add(platElderBreatheDayStat);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment