Selaa lähdekoodia

新建分页查询在线设备功能

zhuoning 3 vuotta sitten
vanhempi
commit
41020a81b9

+ 10 - 1
huimv-eartag2-platform/huimv-eartag2-common/src/main/java/com/huimv/eartag2/common/utils/DateUtil.java

@@ -76,7 +76,7 @@ public class DateUtil {
         return sdf.parse(dateText);
     }
 
-    public Long parseDateTimeLong(String dateText) throws ParseException {
+    public Long parseDateTimeTextToLong(String dateText) throws ParseException {
         if(dateText.indexOf("T") != -1){
             dateText = dateText.replace("T"," ");
         }
@@ -85,6 +85,15 @@ public class DateUtil {
         return date.getTime();
     }
 
+    public Long parseDateTextToLong(String dateText) throws ParseException {
+        if(dateText.indexOf("T") != -1){
+            dateText = dateText.replace("T"," ");
+        }
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        Date date = sdf.parse(dateText);
+        return date.getTime();
+    }
+
     //
     public Date getTodayDate() throws ParseException {
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

+ 27 - 0
huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/controller/DeviceController.java

@@ -90,6 +90,33 @@ public class DeviceController {
     }
 
     /**
+     * @Method      : listOnlineDeviceByPager
+     * @Description : 分页显示N天在线记录
+     * @Params      : [farmId, deviceCode, alias, addDate, pageNo, pageSize]
+     * @Return      : com.huimv.eartag2.common.utils.Result
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2022/3/7       
+     * @Time        : 20:22
+     */
+    @RequestMapping(value = "/listOnlineDeviceByPager",method = RequestMethod.GET)
+    public Result listOnlineDeviceByPager(@RequestParam(value = "farmId",required = true) String farmId,
+                                    @RequestParam(value = "deviceCode",required = false) String deviceCode,
+                                    @RequestParam(value = "alias",required = false) String alias,
+                                    @RequestParam(value = "addDate",required = false) String addDate,
+                                    @RequestParam(value = "pageNo",required = true) Integer pageNo,
+                                    @RequestParam(value = "pageSize",required = true) Integer pageSize) throws ParseException {
+        log.info("<listOnlineDevice>输入参数 farmId>>"+farmId);
+        log.info("<listOnlineDevice>输入参数 deviceCode>>"+deviceCode);
+        log.info("<listOnlineDevice>输入参数 alias>>"+alias);
+        log.info("<listOnlineDevice>输入参数 addDate>>"+addDate);
+        log.info("<listOnlineDevice>输入参数 pageNo>>"+pageNo);
+        log.info("<listOnlineDevice>输入参数 pageSize>>"+pageSize);
+        //
+        return deviceService.listOnlineDevice(farmId,deviceCode,alias,addDate,pageNo,pageSize);
+    }
+
+    /**
      * @Method      : getDeviceRegisterByDeviceCode
      * @Description : 通过设备编码查询设备注册信息
      * @Params      : [deviceCode]

+ 3 - 3
huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/controller/EartagController.java

@@ -28,7 +28,7 @@ public class EartagController {
 
     /**
      * @Method      : getEartagRegisterByEarmark
-     * @Description : 读取耳标注册信息
+     * @Description : 读取耳标注册信息,设备在线页面调用
      * @Params      : [earmark]
      * @Return      : com.huimv.eartag2.common.utils.Result
      * 
@@ -45,7 +45,7 @@ public class EartagController {
 
     /**
      * @Method      : getEartagFlowByEarmarkAndToday
-     * @Description :读取耳标今天所有耳标流水
+     * @Description :读取耳标今天所有耳标流水,设备在线页面调用
      * @Params      : [earmark]
      * @Return      : com.huimv.eartag2.common.utils.Result
      * 
@@ -62,7 +62,7 @@ public class EartagController {
 
     /**
      * @Method      : listEartagFlowByDeviceCodeAndEarmarkAndToday
-     * @Description : 读取设备下和该耳标今天所有耳标流水
+     * @Description : 读取设备下和该耳标今天所有耳标流水,设备在线页面调用
      * @Params      : [earmark, deviceCode]
      * @Return      : com.huimv.eartag2.common.utils.Result
      * 

+ 3 - 0
huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/service/IDeviceService.java

@@ -25,4 +25,7 @@ public interface IDeviceService {
 
     //查询设备关联的在线耳标统计
     Result listDeviceEartagOnlineCountByDeviceCode(String deviceCode) throws ParseException;
+
+    //查询在线设备
+    Result listOnlineDevice(String farmId, String deviceCode, String alias, String addDate, Integer pageNo, Integer pageSize) throws ParseException;
 }

+ 162 - 104
huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/service/impl/DeviceServiceImpl.java

@@ -16,11 +16,18 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.*;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.stereotype.Service;
+
+import javax.persistence.criteria.*;
 
 import java.math.BigDecimal;
 import java.sql.Date;
 import java.sql.Timestamp;
 import java.text.ParseException;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -35,6 +42,8 @@ import java.util.Map;
 @Service
 @Slf4j
 public class DeviceServiceImpl implements IDeviceService {
+    @Value("${device.online.access_mode}")
+    private String deviceOnlineAccessMode;
     @Autowired
     private ICacheService cacheService;
     @Autowired
@@ -43,8 +52,6 @@ public class DeviceServiceImpl implements IDeviceService {
     private EartagDeviceRegisterRepo deviceRegisterRepo;
     @Autowired
     private EartagEartagRegisterRepo eartagRegisterRepo;
-    @Value("${device.online.access_mode}")
-    private String deviceOnlineAccessMode;
     @Autowired
     private EartagDeviceOnlineRepo deviceOnlineRepo;
     @Autowired
@@ -52,38 +59,95 @@ public class DeviceServiceImpl implements IDeviceService {
     @Autowired
     private EartagDeviceEartagCountRepo deviceEartagCountRepo;
 
+
+    @Override
+    public Result listOnlineDevice(String farmId, String deviceCode, String alias, String addDate, Integer pageNo, Integer pageSize) throws ParseException {
+        DateUtil dateUtil = new DateUtil();
+        String todayDate = dateUtil.getTodayDateText();
+        //* 这里提供2种方式:1、从数据库读取 2、从缓存中取数(后期优化),但是同时提供2种方式都可用,防止缓存方式失效 */
+        System.out.println("deviceOnlineAccessMode>>" + deviceOnlineAccessMode);
+        if (deviceOnlineAccessMode.trim().equalsIgnoreCase("mysql")) {
+            //
+            return listDeviceOnlineFromMySQL(farmId,addDate , deviceCode, alias, pageNo, pageSize);
+        } else {
+            //
+            return listDeviceOnlineFromCache(farmId, todayDate);
+        }
+    }
+
+    //
+    private Result listDeviceOnlineFromMySQL(String farmId, String addDate, String deviceCode, String alias, Integer pageNo, Integer pageSize) {
+//        //
+//        List<EartagDeviceOnlineEntity> deviceOnlineEntityList = deviceOnlineRepo.getDeviceOnlineByFarmIdAndCreateDate(farmId,addDate);
+//        if(deviceOnlineEntityList.size()==0){
+//            return new Result(BizConst.CODE_DEVICE_ONLINE_NO_EXIST,BizConst.MSG_DEVICE_ONLINE_NO_EXIST,false);
+//        }else{
+//            return new Result(ResultCode.SUCCESS,JSONObject.toJSONString(deviceOnlineEntityList));
+//        }
+        DateUtil dateUtil = new DateUtil();
+        //
+        Specification<EartagDeviceOnlineEntity> sf = (Specification<EartagDeviceOnlineEntity>) (root, criteriaQuery, criteriaBuilder) -> {
+            //
+            List<Predicate> predList = new ArrayList<>();
+            if (null != farmId) {
+                predList.add(criteriaBuilder.equal(root.get("farmId").as(String.class), farmId));
+            }
+            if (null != deviceCode) {
+                predList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("deviceCode").as(String.class), deviceCode));
+            }
+            if (null != addDate) {
+                try {
+                    predList.add(criteriaBuilder.lessThanOrEqualTo(root.get("addDate").as(Date.class), new Date(dateUtil.parseDateTextToLong(addDate))));
+                } catch (ParseException e) {
+                    e.printStackTrace();
+                }
+            }
+            if (null != alias) {
+                predList.add(criteriaBuilder.equal(root.get("alias").as(String.class), alias));
+            }
+            Predicate[] pred = new Predicate[predList.size()];
+            Predicate and = criteriaBuilder.and(predList.toArray(pred));
+            criteriaQuery.where(and);
+            //
+            List<Order> orders = new ArrayList<>();
+            orders.add(criteriaBuilder.desc(root.get("id")));
+            return criteriaQuery.orderBy(orders).getRestriction();
+        };
+        Pageable pageable = PageRequest.of(pageNo - 1, pageSize);
+//        return new Result(ResultCode.SUCCESS,applyRepo.listApply(pageable,applyId));
+        return new Result(ResultCode.SUCCESS, deviceOnlineRepo.findAll(sf, pageable));
+    }
+
     /**
-     * @Method      : listDeviceEartagOnlineCountByDeviceCode
-     * @Description : 
-     * @Params      : [deviceCode]
-     * @Return      : com.huimv.eartag2.common.utils.Result
-     * 
-     * @Author      : ZhuoNing
-     * @Date        : 2022/3/7       
-     * @Time        : 17:13
+     * @Method : listDeviceEartagOnlineCountByDeviceCode
+     * @Description :
+     * @Params : [deviceCode]
+     * @Return : com.huimv.eartag2.common.utils.Result
+     * @Author : ZhuoNing
+     * @Date : 2022/3/7
+     * @Time : 17:13
      */
     @Override
     public Result listDeviceEartagOnlineCountByDeviceCode(String deviceCode) throws ParseException {
         DateUtil du = new DateUtil();
         String todayDateText = du.getTodayDateText();
         //
-        List<EartagDeviceEartagCountEntity> deviceEartagCountEntityList = deviceEartagCountRepo.getOnlineEartagByDeviceCode(deviceCode,todayDateText);
-        if(deviceEartagCountEntityList.size()==0){
-            return new Result(BizConst.CODE_DEVICE_EARTAG_COUNT_NO_EXIST,BizConst.MSG_DEVICE_EARTAG_COUNT_NO_EXIST,false);
-        }else{
-            return new Result(ResultCode.SUCCESS,JSONObject.toJSONString(deviceEartagCountEntityList));
+        List<EartagDeviceEartagCountEntity> deviceEartagCountEntityList = deviceEartagCountRepo.getOnlineEartagByDeviceCode(deviceCode, todayDateText);
+        if (deviceEartagCountEntityList.size() == 0) {
+            return new Result(BizConst.CODE_DEVICE_EARTAG_COUNT_NO_EXIST, BizConst.MSG_DEVICE_EARTAG_COUNT_NO_EXIST, false);
+        } else {
+            return new Result(ResultCode.SUCCESS, JSONObject.toJSONString(deviceEartagCountEntityList));
         }
     }
 
     /**
-     * @Method      : listDeviceOnlineStatusByDeviceCode
+     * @Method : listDeviceOnlineStatusByDeviceCode
      * @Description : 列表在线设备关联在线耳标统计
-     * @Params      : [deviceCode, pastDays]
-     * @Return      : com.huimv.eartag2.common.utils.Result
-     * 
-     * @Author      : ZhuoNing
-     * @Date        : 2022/3/7       
-     * @Time        : 17:13
+     * @Params : [deviceCode, pastDays]
+     * @Return : com.huimv.eartag2.common.utils.Result
+     * @Author : ZhuoNing
+     * @Date : 2022/3/7
+     * @Time : 17:13
      */
     @Override
     public Result listDeviceOnlineStatusByDeviceCode(String deviceCode, Integer pastDays) throws ParseException {
@@ -92,114 +156,109 @@ public class DeviceServiceImpl implements IDeviceService {
         String pastDate = dateUtil.getPastDate(pastDays);
         String todayDate = dateUtil.getTodayDateText();
         //
-        List<EartagDeviceOnlineEntity> deviceOnlineEntityList = deviceOnlineRepo.getDeviceOnlineByDeviceCode(deviceCode,pastDate,todayDate);
-        if(deviceOnlineEntityList.size()>0){
+        List<EartagDeviceOnlineEntity> deviceOnlineEntityList = deviceOnlineRepo.getDeviceOnlineByDeviceCode(deviceCode, pastDate, todayDate);
+        if (deviceOnlineEntityList.size() > 0) {
             List<String> pastDateList = du.getPastIntervalsASC(pastDays);
             JSONArray dataJa = new JSONArray();
-            for(String pastDayDate:pastDateList){
+            for (String pastDayDate : pastDateList) {
                 JSONObject newJo = new JSONObject();
                 dataJa.add(newJo);
-                newJo.put("time",pastDayDate);
+                newJo.put("time", pastDayDate);
                 boolean ieFound = false;
-                for(EartagDeviceOnlineEntity deviceOnlineEntity:deviceOnlineEntityList)
-                {
+                for (EartagDeviceOnlineEntity deviceOnlineEntity : deviceOnlineEntityList) {
                     int compareTo = du.parseDate(pastDayDate).compareTo(deviceOnlineEntity.getAddDate());
-                    if(compareTo == 0){
-                        newJo.put("value",1);
+                    if (compareTo == 0) {
+                        newJo.put("value", 1);
                         ieFound = true;
                         break;
                     }
                 }
-                if(!ieFound){
-                    newJo.put("value",0);
+                if (!ieFound) {
+                    newJo.put("value", 0);
                 }
             }
-            return new Result(ResultCode.SUCCESS,dataJa);
-        }else{
-            return new Result(BizConst.CODE_DEVICE_ONLINE_NO_EXIST,BizConst.MSG_DEVICE_ONLINE_NO_EXIST,false);
+            return new Result(ResultCode.SUCCESS, dataJa);
+        } else {
+            return new Result(BizConst.CODE_DEVICE_ONLINE_NO_EXIST, BizConst.MSG_DEVICE_ONLINE_NO_EXIST, false);
         }
     }
 
-     /**
-     * @Method      : listDeviceOnlineByDeviceCode
+    /**
+     * @Method : listDeviceOnlineByDeviceCode
      * @Description : 查询单个设备N天在线记录
-     * @Params      : [deviceCode]
-     * @Return      : com.huimv.eartag2.common.utils.Result
-     * 
-     * @Author      : ZhuoNing
-     * @Date        : 2022/3/7
-     * @Time        : 14:08
+     * @Params : [deviceCode]
+     * @Return : com.huimv.eartag2.common.utils.Result
+     * @Author : ZhuoNing
+     * @Date : 2022/3/7
+     * @Time : 14:08
      */
     @Override
-    public Result listDeviceOnlineCountByDeviceCode(String deviceCode, Integer pastDays,Integer showMode) throws ParseException {
+    public Result listDeviceOnlineCountByDeviceCode(String deviceCode, Integer pastDays, Integer showMode) throws ParseException {
         DateUtil dateUtil = new DateUtil();
         String pastDate = dateUtil.getPastDate(pastDays);
         String todayDate = dateUtil.getTodayDateText();
         //
-        List<EartagDeviceOnlineEntity> deviceOnlineEntityList = deviceOnlineRepo.getDeviceOnlineByDeviceCode(deviceCode,pastDate,todayDate);
-        if(deviceOnlineEntityList.size()>0){
-            if(showMode == 1){
-                return new Result(ResultCode.SUCCESS,JSONObject.toJSONString(deviceOnlineEntityList));
-            }else{
+        List<EartagDeviceOnlineEntity> deviceOnlineEntityList = deviceOnlineRepo.getDeviceOnlineByDeviceCode(deviceCode, pastDate, todayDate);
+        if (deviceOnlineEntityList.size() > 0) {
+            if (showMode == 1) {
+                return new Result(ResultCode.SUCCESS, JSONObject.toJSONString(deviceOnlineEntityList));
+            } else {
                 JSONArray dataJa = new JSONArray();
-                for(EartagDeviceOnlineEntity deviceOnlineEntity:deviceOnlineEntityList)
-                {
+                for (EartagDeviceOnlineEntity deviceOnlineEntity : deviceOnlineEntityList) {
                     JSONObject newJo = new JSONObject();
                     dataJa.add(newJo);
-                    newJo.put("time",dateUtil.formatDateText(deviceOnlineEntity.getAddDate()));
-                    newJo.put("value",deviceOnlineEntity.getEartagTotal());
+                    newJo.put("time", dateUtil.formatDateText(deviceOnlineEntity.getAddDate()));
+                    newJo.put("value", deviceOnlineEntity.getEartagTotal());
                 }
-                return new Result(ResultCode.SUCCESS,dataJa.toJSONString());
+                return new Result(ResultCode.SUCCESS, dataJa.toJSONString());
             }
-        }else{
-            return new Result(BizConst.CODE_DEVICE_ONLINE_NO_EXIST,BizConst.MSG_DEVICE_ONLINE_NO_EXIST,false);
+        } else {
+            return new Result(BizConst.CODE_DEVICE_ONLINE_NO_EXIST, BizConst.MSG_DEVICE_ONLINE_NO_EXIST, false);
         }
     }
 
     /**
-     * @Method      : getDeviceRegisterByDeviceCode
+     * @Method : getDeviceRegisterByDeviceCode
      * @Description : 通过设备编号显示设备注册信息
-     * @Params      : [deviceCode]
-     * @Return      : void
-     * 
-     * @Author      : ZhuoNing
-     * @Date        : 2022/3/7       
-     * @Time        : 13:55
+     * @Params : [deviceCode]
+     * @Return : void
+     * @Author : ZhuoNing
+     * @Date : 2022/3/7
+     * @Time : 13:55
      */
     @Override
     public Result getDeviceRegisterByDeviceCode(String deviceCode) {
         //
         EartagDeviceRegisterEntity deviceRegisterEntity = deviceRegisterRepo.getDeviceRegister(deviceCode);
-        if(deviceRegisterEntity == null){
+        if (deviceRegisterEntity == null) {
             log.error(BizConst.MSG_DEVICE_REGISTER_NO_EXIST);
-            return new Result(BizConst.CODE_DEVICE_REGISTER_NO_EXIST,BizConst.MSG_DEVICE_REGISTER_NO_EXIST,false);
-        }else{
-            return new Result(ResultCode.SUCCESS,JSONObject.toJSONString(deviceRegisterEntity));
+            return new Result(BizConst.CODE_DEVICE_REGISTER_NO_EXIST, BizConst.MSG_DEVICE_REGISTER_NO_EXIST, false);
+        } else {
+            return new Result(ResultCode.SUCCESS, JSONObject.toJSONString(deviceRegisterEntity));
         }
     }
 
     /**
-     * @Method      : listOnlineDevice
+     * @Method : listOnlineDevice
      * @Description : 显示在线设备记录
-     * @Params      : [farmId]
-     * @Return      : com.huimv.eartag2.common.utils.Result
-     *
-     * @Author      : ZhuoNing
-     * @Date        : 2022/3/7
-     * @Time        : 13:21
+     * @Params : [farmId]
+     * @Return : com.huimv.eartag2.common.utils.Result
+     * @Author : ZhuoNing
+     * @Date : 2022/3/7
+     * @Time : 13:21
      */
     @Override
     public Result listOnlineDevice(String farmId) throws ParseException {
         DateUtil dateUtil = new DateUtil();
         String todayDate = dateUtil.getTodayDateText();
         //* 这里提供2种方式:1、从数据库读取 2、从缓存中取数(后期优化),但是同时提供2种方式都可用,防止缓存方式失效 */
-        System.out.println("deviceOnlineAccessMode>>"+deviceOnlineAccessMode);
-        if(deviceOnlineAccessMode.trim().equalsIgnoreCase("mysql")){
+        System.out.println("deviceOnlineAccessMode>>" + deviceOnlineAccessMode);
+        if (deviceOnlineAccessMode.trim().equalsIgnoreCase("mysql")) {
             //
-            return listDeviceOnlineFromMySQL(farmId,todayDate);
-        }else{
+            return listDeviceOnlineFromMySQL(farmId, todayDate);
+        } else {
             //
-            return listDeviceOnlineFromCache(farmId,todayDate);
+            return listDeviceOnlineFromCache(farmId, todayDate);
         }
     }
 
@@ -215,14 +274,14 @@ public class DeviceServiceImpl implements IDeviceService {
     private Result listDeviceOnlineFromMySQL(String farmId, String todayDate) throws ParseException {
         DateUtil du = new DateUtil();
         //
-        List<EartagDeviceOnlineEntity> deviceOnlineEntityList = deviceOnlineRepo.getDeviceOnlineByFarmIdAndCreateDate(farmId,todayDate);
-        if(deviceOnlineEntityList.size()==0){
-            return new Result(BizConst.CODE_DEVICE_ONLINE_NO_EXIST,BizConst.MSG_DEVICE_ONLINE_NO_EXIST,false);
-        }else{
+        List<EartagDeviceOnlineEntity> deviceOnlineEntityList = deviceOnlineRepo.getDeviceOnlineByFarmIdAndCreateDate(farmId, todayDate);
+        if (deviceOnlineEntityList.size() == 0) {
+            return new Result(BizConst.CODE_DEVICE_ONLINE_NO_EXIST, BizConst.MSG_DEVICE_ONLINE_NO_EXIST, false);
+        } else {
 //            for(EartagDeviceOnlineEntity deviceOnlineEntity:deviceOnlineEntityList){
 //                deviceOnlineEntity.setHeartbeatFirstTime(du.formatDatetimeText());
 //            }
-            return new Result(ResultCode.SUCCESS,JSONObject.toJSONString(deviceOnlineEntityList));
+            return new Result(ResultCode.SUCCESS, JSONObject.toJSONString(deviceOnlineEntityList));
         }
     }
 
@@ -239,27 +298,27 @@ public class DeviceServiceImpl implements IDeviceService {
         //{从总状态缓存钟读取缓存数据}
         DateUtil dateUtil = new DateUtil();
         Map farmAllStatusMap = cacheService.getFarmAllStatusByFarmId(farmId);
-        if(farmAllStatusMap.size()>0){
+        if (farmAllStatusMap.size() > 0) {
             log.info("返回缓存数据.");
-            return new Result(ResultCode.SUCCESS,JSONObject.toJSONString(farmAllStatusMap));
-        }else{
+            return new Result(ResultCode.SUCCESS, JSONObject.toJSONString(farmAllStatusMap));
+        } else {
             //#从数据库读取总状态表
             String todayDateText = dateUtil.getTodayDateText();
             Date todayDate = dateUtil.getTodayMySQLDate();
             Timestamp timestamp = dateUtil.getTimestamp();
-            EartarFarmAllStatusEntity farmAllStatusEntity = farmAllStatusRepo.getOneByFarmIdAndCreateDate(farmId,todayDateText);
-            if(farmAllStatusEntity != null){
+            EartarFarmAllStatusEntity farmAllStatusEntity = farmAllStatusRepo.getOneByFarmIdAndCreateDate(farmId, todayDateText);
+            if (farmAllStatusEntity != null) {
                 //#初始化总状态缓存
-                cacheService.putFarmAllStatusCache(farmId,farmAllStatusEntity);
-                return new Result(ResultCode.SUCCESS,JSONObject.toJSONString(farmAllStatusEntity));
-            }else{
+                cacheService.putFarmAllStatusCache(farmId, farmAllStatusEntity);
+                return new Result(ResultCode.SUCCESS, JSONObject.toJSONString(farmAllStatusEntity));
+            } else {
                 //*构建总状态数据 */
                 int deviceTotal = getDeviceCancelTotalFromDeviceRegister(farmId);
                 int eartagTotal = getEartagRegTotalByFarmId(farmId);
-                int deviceOnlineTotal = cacheService.getDeviceOnlineTotal(farmId,todayDateText);
-                int eartagOnlineTotal = cacheService.getEartagOnlineTotal(farmId,todayDateText);
+                int deviceOnlineTotal = cacheService.getDeviceOnlineTotal(farmId, todayDateText);
+                int eartagOnlineTotal = cacheService.getEartagOnlineTotal(farmId, todayDateText);
                 int deviceOffline = deviceTotal - deviceOnlineTotal;
-                BigDecimal rateBd= new BigDecimal(deviceOnlineTotal).divide(new BigDecimal(deviceTotal),1,BigDecimal.ROUND_HALF_UP);
+                BigDecimal rateBd = new BigDecimal(deviceOnlineTotal).divide(new BigDecimal(deviceTotal), 1, BigDecimal.ROUND_HALF_UP);
                 EartarFarmAllStatusEntity newFarmAllStatusEntity = new EartarFarmAllStatusEntity();
                 newFarmAllStatusEntity.setDeviceTotal(deviceTotal);
                 newFarmAllStatusEntity.setDeviceOnline(deviceOnlineTotal);
@@ -272,8 +331,8 @@ public class DeviceServiceImpl implements IDeviceService {
                 newFarmAllStatusEntity.setCreateDate(todayDate);
                 farmAllStatusRepo.saveAndFlush(newFarmAllStatusEntity);
                 //*初始化总状态缓存*/
-                cacheService.putFarmAllStatusCache(farmId,newFarmAllStatusEntity);
-                return new Result(ResultCode.SUCCESS,JSONObject.toJSONString(newFarmAllStatusEntity));
+                cacheService.putFarmAllStatusCache(farmId, newFarmAllStatusEntity);
+                return new Result(ResultCode.SUCCESS, JSONObject.toJSONString(newFarmAllStatusEntity));
             }
         }
 
@@ -284,19 +343,18 @@ public class DeviceServiceImpl implements IDeviceService {
         DateUtil dateUtil = new DateUtil();
         String pastDate = dateUtil.getPastDate(days);
         String todayDate = dateUtil.getTodayDateText();
-        List<EartarFarmAllStatusEntity> FarmAllStatusEntityList = farmAllStatusRepo.getOneByFarmIdAndCreateDateAndPastDate(farmId,pastDate,todayDate);
+        List<EartarFarmAllStatusEntity> FarmAllStatusEntityList = farmAllStatusRepo.getOneByFarmIdAndCreateDateAndPastDate(farmId, pastDate, todayDate);
         JSONArray dataJa = new JSONArray();
-        for(EartarFarmAllStatusEntity farmAllStatusEntity:FarmAllStatusEntityList)
-        {
+        for (EartarFarmAllStatusEntity farmAllStatusEntity : FarmAllStatusEntityList) {
             JSONObject newJo = new JSONObject();
             dataJa.add(newJo);
-            newJo.put("time",dateUtil.formatDateText(farmAllStatusEntity.getCreateDate()));
-            newJo.put("value",farmAllStatusEntity.getDeviceOnline());
+            newJo.put("time", dateUtil.formatDateText(farmAllStatusEntity.getCreateDate()));
+            newJo.put("value", farmAllStatusEntity.getDeviceOnline());
             newJo.put("total", farmAllStatusEntity.getDeviceTotal());
             newJo.put("rate", farmAllStatusEntity.getDeviceRate());
             newJo.put("offline", farmAllStatusEntity.getDeviceOffline());
         }
-        return new Result(ResultCode.SUCCESS,dataJa.toJSONString());
+        return new Result(ResultCode.SUCCESS, dataJa.toJSONString());
     }
 
     //计算注册设备数量
@@ -308,7 +366,7 @@ public class DeviceServiceImpl implements IDeviceService {
     }
 
     //计算注册耳标数量
-    public Integer getEartagRegTotalByFarmId(String farmId){
+    public Integer getEartagRegTotalByFarmId(String farmId) {
         int eartagTotal = 0;
         List<Object[]> eartagRegList = eartagRegisterRepo.getEartagCountByFarmId(farmId);
         Object[] eartagRegObj = (Object[]) eartagRegList.get(0);