|
@@ -1,5 +1,6 @@
|
|
|
package com.huimv.eartag2.manage.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.huimv.eartag2.common.dao.entity.EartagDeviceOnlineEntity;
|
|
@@ -10,7 +11,6 @@ import com.huimv.eartag2.common.dao.repo.EartagDeviceRegisterRepo;
|
|
|
import com.huimv.eartag2.common.dao.repo.EartagEartagRegisterRepo;
|
|
|
import com.huimv.eartag2.common.dao.repo.EartarFarmAllStatusRepo;
|
|
|
//import com.huimv.eartag2.common.service.IDevice;
|
|
|
-import com.huimv.eartag2.common.service.impl.DeviceImpl;
|
|
|
import com.huimv.eartag2.common.utils.BizConst;
|
|
|
import com.huimv.eartag2.common.utils.DateUtil;
|
|
|
import com.huimv.eartag2.common.utils.Result;
|
|
@@ -20,10 +20,8 @@ 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;
|
|
|
|
|
|
-import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.sql.Date;
|
|
|
import java.sql.Timestamp;
|
|
@@ -56,6 +54,79 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
private EartagDeviceOnlineRepo deviceOnlineRepo;
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
+ public Result listDeviceOnlineStatusByDeviceCode(String deviceCode, Integer pastDays) throws ParseException {
|
|
|
+ DateUtil du = new DateUtil();
|
|
|
+ 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){
|
|
|
+ List<String> pastDateList = du.getPastIntervalsASC(pastDays);
|
|
|
+ JSONArray dataJa = new JSONArray();
|
|
|
+ for(String pastDayDate:pastDateList){
|
|
|
+ int compareInt = du.parseDate(pastDayDate).compareTo(du.getTodayDate());
|
|
|
+ JSONObject newJo = new JSONObject();
|
|
|
+ dataJa.add(newJo);
|
|
|
+ newJo.put("time",pastDayDate);
|
|
|
+ boolean ieFound = false;
|
|
|
+ for(EartagDeviceOnlineEntity deviceOnlineEntity:deviceOnlineEntityList)
|
|
|
+ {
|
|
|
+ int compareTo = du.parseDate(pastDayDate).compareTo(deviceOnlineEntity.getAddDate());
|
|
|
+// System.out.println("compareTo>>"+compareTo+" "+du.formatDateText(deviceOnlineEntity.getAddDate()));
|
|
|
+ if(compareTo == 0){
|
|
|
+ newJo.put("value",1);
|
|
|
+ ieFound = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Method : listDeviceOnlineByDeviceCode
|
|
|
+ * @Description : 查询单个设备N天在线记录
|
|
|
+ * @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 {
|
|
|
+ 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{
|
|
|
+ JSONArray dataJa = new JSONArray();
|
|
|
+ for(EartagDeviceOnlineEntity deviceOnlineEntity:deviceOnlineEntityList)
|
|
|
+ {
|
|
|
+ JSONObject newJo = new JSONObject();
|
|
|
+ dataJa.add(newJo);
|
|
|
+ newJo.put("time",dateUtil.formatDateText(deviceOnlineEntity.getAddDate()));
|
|
|
+ newJo.put("value",deviceOnlineEntity.getEartagTotal());
|
|
|
+ }
|
|
|
+ return new Result(ResultCode.SUCCESS,dataJa.toJSONString());
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ return new Result(BizConst.CODE_DEVICE_ONLINE_NO_EXIST,BizConst.MSG_DEVICE_ONLINE_NO_EXIST,false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @Method : getDeviceRegisterByDeviceCode
|
|
|
* @Description : 通过设备编号显示设备注册信息
|
|
@@ -71,8 +142,8 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
//
|
|
|
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);
|
|
|
+ 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));
|
|
|
}
|
|
@@ -117,7 +188,7 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
//
|
|
|
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);
|
|
|
+ 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());
|