Browse Source

转小时,保留一位小数

master
sunyuchao 4 years ago
parent
commit
204b4482dd
  1. 9
      epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/epmetuser/impl/EpmetUserServiceImpl.java

9
epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/epmetuser/impl/EpmetUserServiceImpl.java

@ -25,6 +25,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.*;
import java.util.stream.Collectors;
@ -270,14 +272,17 @@ public class EpmetUserServiceImpl implements EpmetUserService {
//3.封装数据并返回
resultList.forEach(re -> list.stream().filter(l -> re.getGridId().equals(l.getId())).forEach(s -> re.setGridName(s.getGridName())));
NumberFormat numberFormat = NumberFormat.getInstance();
numberFormat.setMaximumFractionDigits(NumConstant.ONE);
resultList.forEach(re -> {
String totalTime = "0分钟";
/*String totalTime = "0分钟";
if (re.getTimeNum() > NumConstant.ZERO) {
int hour = re.getTimeNum() / 3600;
int minute = re.getTimeNum() % 3600;
totalTime = (hour < 1 ? "" : hour + "小时") + (minute < 1 ? "" : minute + "分钟");
}
re.setTotalTime(totalTime == "" ? "0分钟" : totalTime);
re.setTotalTime(totalTime == "" ? "0分钟" : totalTime);*/
re.setTotalTime(re.getTimeNum() < 1 ? BigDecimal.ZERO + "h" : new BigDecimal(numberFormat.format((float) re.getTimeNum() / (float) 3600)) + "h");
list.stream().filter(l -> re.getGridId().equals(l.getId())).forEach(s -> re.setGridName(s.getGridName()));
});

Loading…
Cancel
Save