Browse Source

去掉末尾小数点 获取规格名称

yuejiaying 4 years ago
parent
commit
d45fb616fc

+ 5 - 2
sms_water/src/main/java/com/huaxu/controller/OnlineMonitorController.java

@@ -23,6 +23,7 @@ import io.swagger.annotations.ApiParam;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.text.DecimalFormat;
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.List;
@@ -174,7 +175,8 @@ public class OnlineMonitorController {
                         monData.setDataValue(attributeEntity.getDataValue());
                         monData.setUnit(attributeEntity.getUnit());
                         if (monData.getAttributeType() != null && (monData.getAttributeType().equals("1") || monData.getAttributeType().equals("2"))) {//如果是状态值 需转换
-                            String specsValue = attributeEntity.getDataValue() == null ? null : attributeEntity.getDataValue().toString();
+                            DecimalFormat decimalFormat = new DecimalFormat("###################.###########");//去掉末尾小数点
+                            String specsValue = attributeEntity.getDataValue() == null ? null : decimalFormat.format(attributeEntity.getDataValue());
                             monData.setSpecsName(specsValue == null ? null : deviceAttributeSpecsService.selectSpecsName(attributeEntity.getAttributeId(), specsValue));
                         }
                     }
@@ -295,7 +297,8 @@ public class OnlineMonitorController {
                                         monDataCol.setInstantFlow(monitorData);
                                         break;
                                     case "2"://水泵状态
-                                        String specsValue = attributeEntity.getDataValue() == null ? null : attributeEntity.getDataValue().toString();
+                                        DecimalFormat decimalFormat = new DecimalFormat("###################.###########");//去掉末尾小数点
+                                        String specsValue = attributeEntity.getDataValue() == null ? null : decimalFormat.format(attributeEntity.getDataValue());
                                         monitorData.setSpecsName(specsValue == null ? null : deviceAttributeSpecsService.selectSpecsName(attributeEntity.getAttributeId(), specsValue));
                                         pumpStatus.add(monitorData);
                                         monDataCol.setPumpStatus(pumpStatus);