|
@@ -21,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.time.Duration;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
@@ -162,8 +163,8 @@ public class DeviceLogServiceImpl extends ServiceImpl<DeviceLogMapper, DeviceLog
|
|
|
|
|
|
Duration duration = Duration.between(group[0], group[1]);
|
|
|
double hours = duration.toMinutes() / 60.0; // 转换为小时
|
|
|
- // 四舍五入保留一位小数
|
|
|
- hours = Math.round(hours * 10.0) / 10.0;
|
|
|
+ // 四舍五入保留二位小数
|
|
|
+ hours = new BigDecimal(hours).setScale(2, RoundingMode.HALF_UP).doubleValue();
|
|
|
String createDate = group[0].format(formatterDate);
|
|
|
System.out.println("开始时间: " + formatStart + ", 结束时间: " + formatEnd+",时间差:"+hours+",日期:"+createDate);
|
|
|
}
|
|
@@ -175,7 +176,7 @@ public class DeviceLogServiceImpl extends ServiceImpl<DeviceLogMapper, DeviceLog
|
|
|
Duration duration = Duration.between(deviceLog.getStartTime(), deviceLog.getEndTime());
|
|
|
double hours = duration.toMinutes() / 60.0; // 转换为小时
|
|
|
// 四舍五入保留一位小数
|
|
|
- hours = Math.round(hours * 10.0) / 10.0;
|
|
|
+ hours = new BigDecimal(hours).setScale(2, RoundingMode.HALF_UP).doubleValue();
|
|
|
|
|
|
deviceLogMapper.update(null,new UpdateWrapper<DeviceLog>()
|
|
|
.set("start_time",deviceLog.getStartTime())
|
|
@@ -197,7 +198,7 @@ public class DeviceLogServiceImpl extends ServiceImpl<DeviceLogMapper, DeviceLog
|
|
|
Duration duration = Duration.between(groupedTimes.get(i)[0], groupedTimes.get(i)[1]);
|
|
|
double hours = duration.toMinutes() / 60.0; // 转换为小时
|
|
|
// 四舍五入保留一位小数
|
|
|
- hours = Math.round(hours * 10.0) / 10.0;
|
|
|
+ hours = new BigDecimal(hours).setScale(2, RoundingMode.HALF_UP).doubleValue();
|
|
|
String createDate = groupedTimes.get(i)[0].format(formatterDate);
|
|
|
|
|
|
deviceLog.setStartTime(LocalDateTime.parse(formatStart, formatter));
|
|
@@ -219,7 +220,7 @@ public class DeviceLogServiceImpl extends ServiceImpl<DeviceLogMapper, DeviceLog
|
|
|
Duration duration = Duration.between(groupedTimes.get(i)[0], groupedTimes.get(i)[1]);
|
|
|
double hours = duration.toMinutes() / 60.0; // 转换为小时
|
|
|
// 四舍五入保留一位小数
|
|
|
- hours = Math.round(hours * 10.0) / 10.0;
|
|
|
+ hours = new BigDecimal(hours).setScale(2, RoundingMode.HALF_UP).doubleValue();
|
|
|
String createDate = groupedTimes.get(i)[0].format(formatterDate);
|
|
|
|
|
|
DeviceLog deviceLogNew = new DeviceLog();
|