|
@@ -2,7 +2,10 @@ package com.huimv.eartag2.manage.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.huimv.eartag2.common.dao.entity.EartagDeviceOnlineEntity;
|
|
|
+import com.huimv.eartag2.common.dao.entity.EartagDeviceRegisterEntity;
|
|
|
import com.huimv.eartag2.common.dao.entity.EartarFarmAllStatusEntity;
|
|
|
+import com.huimv.eartag2.common.dao.repo.EartagDeviceOnlineRepo;
|
|
|
import com.huimv.eartag2.common.dao.repo.EartagDeviceRegisterRepo;
|
|
|
import com.huimv.eartag2.common.dao.repo.EartagEartagRegisterRepo;
|
|
|
import com.huimv.eartag2.common.dao.repo.EartarFarmAllStatusRepo;
|
|
@@ -16,6 +19,7 @@ import com.huimv.eartag2.manage.service.ICacheService;
|
|
|
import com.huimv.eartag2.manage.service.IDeviceService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -46,6 +50,81 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
private EartagDeviceRegisterRepo deviceRegisterRepo;
|
|
|
@Autowired
|
|
|
private EartagEartagRegisterRepo eartagRegisterRepo;
|
|
|
+ @Value("${device.online.access_mode}")
|
|
|
+ private String deviceOnlineAccessMode;
|
|
|
+ @Autowired
|
|
|
+ private EartagDeviceOnlineRepo deviceOnlineRepo;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Method : getDeviceRegisterByDeviceCode
|
|
|
+ * @Description : 通过设备编号显示设备注册信息
|
|
|
+ * @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){
|
|
|
+ log.error(BizConst.MSG_REGISTER_NO_EXIST);
|
|
|
+ return new Result(BizConst.CODE_REGISTER_NO_EXIST,BizConst.MSG_REGISTER_NO_EXIST,false);
|
|
|
+ }else{
|
|
|
+ return new Result(ResultCode.SUCCESS,JSONObject.toJSONString(deviceRegisterEntity));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Method : listOnlineDevice
|
|
|
+ * @Description : 显示在线设备记录
|
|
|
+ * @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")){
|
|
|
+ //
|
|
|
+ return listDeviceOnlineFromMySQL(farmId,todayDate);
|
|
|
+ }else{
|
|
|
+ //
|
|
|
+ return listDeviceOnlineFromCache(farmId,todayDate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //从缓存读取在线记录(后期优化)
|
|
|
+ private Result listDeviceOnlineFromCache(String farmId, String todayDate) {
|
|
|
+
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ //从数据库读取在线记录
|
|
|
+ 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_ONLINE_NO_EXIST,BizConst.MSG_ONLINE_NO_EXIST,false);
|
|
|
+ }else{
|
|
|
+// for(EartagDeviceOnlineEntity deviceOnlineEntity:deviceOnlineEntityList){
|
|
|
+// deviceOnlineEntity.setHeartbeatFirstTime(du.formatDatetimeText());
|
|
|
+// }
|
|
|
+ return new Result(ResultCode.SUCCESS,JSONObject.toJSONString(deviceOnlineEntityList));
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public Result getNowAllStatus(String farmId) throws ParseException {
|
|
@@ -117,7 +196,7 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
newJo.put("rate", farmAllStatusEntity.getDeviceRate());
|
|
|
newJo.put("offline", farmAllStatusEntity.getDeviceOffline());
|
|
|
}
|
|
|
- return new Result(ResultCode.SUCCESS,JSONObject.toJSONString(dataJa));
|
|
|
+ return new Result(ResultCode.SUCCESS,dataJa.toJSONString());
|
|
|
}
|
|
|
|
|
|
//计算注册设备数量
|