Explorar o código

修复空指针

Newspaper hai 1 ano
pai
achega
168bdc6072

+ 10 - 2
huimv-farm-datacenter-egg/huimv-farm-environ/src/main/java/com/huimv/environ/eco/service/impl/FeedConsumeServiceImpl.java

@@ -22,6 +22,7 @@ import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpMethod;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.client.RestTemplate;
 
 import java.math.BigDecimal;
@@ -165,6 +166,7 @@ public class FeedConsumeServiceImpl extends ServiceImpl<FeedConsumeMapper, FeedC
     }
 
     @Override
+    @Transactional
     public Result analysis(Map<String, String> map) {
         String startDate = map.get("startDate");
         String endDate = map.get("endDate");
@@ -216,12 +218,18 @@ public class FeedConsumeServiceImpl extends ServiceImpl<FeedConsumeMapper, FeedC
             }
         }
 
+        BigDecimal totalConsume = BigDecimal.ZERO;
+        BigDecimal totalUsed = BigDecimal.ZERO;
         FeedAnalysisVo feedAnalysisVo = new FeedAnalysisVo();
         FeedConsumeChartVo feedConsumeChartVo= feedConsumeMapper.getTotal(startDate, endDate);
         FeedUsedChartVo feedUsedChartVo = feedUsageMapper.getTotal(startDate, endDate,unitName);
         BigDecimal gapRate = BigDecimal.ZERO;
-        BigDecimal totalConsume = feedConsumeChartVo.getTotalConsume();
-        BigDecimal totalUsed = feedUsedChartVo.getTotalUsed();
+        if (ObjectUtil.isNotEmpty(feedConsumeChartVo)){
+            totalConsume = feedConsumeChartVo.getTotalConsume();
+        }
+        if (ObjectUtil.isNotEmpty(feedUsedChartVo.getTotalUsed())){
+            totalUsed = feedUsedChartVo.getTotalUsed();
+        }
         BigDecimal gap = totalConsume.subtract(totalUsed);
         if (totalConsume.compareTo(BigDecimal.ZERO) > 0) {
             gapRate = gap.divide(totalConsume,4,RoundingMode.UP).multiply(BigDecimal.valueOf(100));

+ 1 - 1
huimv-farm-datacenter-egg/huimv-farm-environ/src/main/java/com/huimv/environ/eco/timer/FeedConsumeTimer.java

@@ -31,7 +31,7 @@ public class FeedConsumeTimer {
     private static  final  String TOKEN= "72438b180e9168fe90db126e3310cd0b20a7196d";
     private static  final  String CURRENT_LIST= "current/list/?code=";
     private static  final  String HISTORY_LIST= "history/list/?code=";
-    private static final String FARM_CODE = "2022011710";
+    private static  final  String FARM_CODE = "2022011710";
 
     @Autowired
     private IFeedUsageService feedUsageService;