浏览代码

优化:主页余额类,月收款数统计获取缓存为空判断

liupeng 2 天之前
父节点
当前提交
c8287607f6
共有 1 个文件被更改,包括 20 次插入11 次删除
  1. 20 11
      fs-admin/src/main/java/com/fs/api/controller/IndexStatisticsController.java

+ 20 - 11
fs-admin/src/main/java/com/fs/api/controller/IndexStatisticsController.java

@@ -156,6 +156,8 @@ public class IndexStatisticsController {
             Long[] companyIds = companyService.selectCompanyList(company).stream().map(Company::getCompanyId).toArray(Long[]::new);
             for(Long companyId : companyIds){
                 ConsumptionBalanceDataDTO clildDTO = redisCache.getCacheObject(String.format("%s:%d",DATA_OVERVIEW_DEALER_BALANCE,companyId));
+                //判断缓存是否为空
+                if (clildDTO != null) {
                 consumptionBalanceDataDTO.setBalance(
                     (consumptionBalanceDataDTO.getBalance() == null ? BigDecimal.ZERO : consumptionBalanceDataDTO.getBalance())
                     .add(clildDTO.getBalance() == null ? BigDecimal.ZERO : clildDTO.getBalance())
@@ -169,6 +171,7 @@ public class IndexStatisticsController {
                     .add(clildDTO.getYesterdayComsumption() == null ? BigDecimal.ZERO : clildDTO.getYesterdayComsumption())
                 );
             }
+                }
         }
 
         return R.ok().put("data", consumptionBalanceDataDTO);
@@ -763,11 +766,14 @@ public class IndexStatisticsController {
             List<Integer> payPriceList = new ArrayList<>();
             for(Long companyId : companyIds) {
                 R result = redisCache.getCacheObject(String.format("%s:%d", THIS_MONTH_ORDER_COUNT, companyId));
-                Object datas = result.get("datas");
-                Object orderCount = result.get("orderCount");
-                Object payPrice = result.get("payPrice");
-                if(datas != null){
-                    mergeDataListsForInteger(datesList, orderCountList, payPriceList, (List<String>)datas, (List<Integer>)orderCount, (List<Integer>)payPrice);
+                //缓存判断
+                if (result != null) {
+                    Object datas = result.get("datas");
+                    Object orderCount = result.get("orderCount");
+                    Object payPrice = result.get("payPrice");
+                    if(datas != null){
+                        mergeDataListsForInteger(datesList, orderCountList, payPriceList, (List<String>)datas, (List<Integer>)orderCount, (List<Integer>)payPrice);
+                    }
                 }
             }
             return R.ok().put("dates", datesList).put("orderCount", orderCountList).put("payPrice", payPriceList);
@@ -796,12 +802,15 @@ public class IndexStatisticsController {
             List<Float> payMoneyList = new ArrayList<>();
             for(Long companyId : companyIds) {
                R result = redisCache.getCacheObject(String.format("%s:%d", THIS_MONTH_RECV_COUNT, companyId));
-               Object datas = result.get("datas");
-               Object orderCount = result.get("orderCount");
-               Object payMoney = result.get("payMoney");
-               if(datas != null){
-                   mergeDataLists(datesList, orderCountList, payMoneyList, (List<String>)datas, (List<Integer>)orderCount, (List<Float>)payMoney);
-               }
+               //判断缓存为空
+              if (result!=null){
+                  Object datas = result.get("datas");
+                  Object orderCount = result.get("orderCount");
+                  Object payMoney = result.get("payMoney");
+                  if(datas != null){
+                      mergeDataLists(datesList, orderCountList, payMoneyList, (List<String>)datas, (List<Integer>)orderCount, (List<Float>)payMoney);
+                  }
+              }
             }
             return R.ok().put("dates", datesList).put("orderCount", orderCountList).put("payMoney", payMoneyList);
         }