|
@@ -59,45 +59,42 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
private EartagHeartbeatRepo heartbeatRepo;
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
- * @Method : listDeviceEnvtempByDeviceCode
|
|
|
- * @Description :
|
|
|
- * @Params : [deviceCode]
|
|
|
- * @Return : com.huimv.eartag2.common.utils.Result
|
|
|
- *
|
|
|
- * @Author : ZhuoNing
|
|
|
- * @Date : 2022/3/8
|
|
|
- * @Time : 20:55
|
|
|
+ * @Method : listDeviceEnvtempByDeviceCode
|
|
|
+ * @Description :
|
|
|
+ * @Params : [deviceCode]
|
|
|
+ * @Return : com.huimv.eartag2.common.utils.Result
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2022/3/8
|
|
|
+ * @Time : 20:55
|
|
|
*/
|
|
|
@Override
|
|
|
public Result listDeviceEnvtempByDeviceCode(String deviceCode) throws ParseException {
|
|
|
DateUtil du = new DateUtil();
|
|
|
String todayDateText = du.getTodayDateText();
|
|
|
//
|
|
|
- List<EartagEnvEntity> eartagEnvEntityList = eartagEnvRepo.getDeviceEnvtempByDeviceCode(deviceCode,todayDateText);
|
|
|
- if(eartagEnvEntityList.size()==0){
|
|
|
- return new Result(BizConst.CODE_ENVTEMP_FLOW_NO_EXIST,BizConst.MSG_ENVTEMP_FLOW_NO_EXIST,false);
|
|
|
- }else{
|
|
|
+ List<EartagEnvEntity> eartagEnvEntityList = eartagEnvRepo.getDeviceEnvtempByDeviceCode(deviceCode, todayDateText);
|
|
|
+ if (eartagEnvEntityList.size() == 0) {
|
|
|
+ return new Result(BizConst.CODE_ENVTEMP_FLOW_NO_EXIST, BizConst.MSG_ENVTEMP_FLOW_NO_EXIST, false);
|
|
|
+ } else {
|
|
|
JSONArray dataJa = new JSONArray();
|
|
|
- for(EartagEnvEntity eartagEnvEntity:eartagEnvEntityList){
|
|
|
+ for (EartagEnvEntity eartagEnvEntity : eartagEnvEntityList) {
|
|
|
JSONObject eartagEnvJo = JSONUtil.convertEntityToJSONObject(eartagEnvEntity);
|
|
|
- eartagEnvJo.put("addTime",du.formatDatetimeText(eartagEnvJo.getDate("addTime")));
|
|
|
+ eartagEnvJo.put("addTime", du.formatDatetimeText(eartagEnvJo.getDate("addTime")));
|
|
|
dataJa.add(eartagEnvJo);
|
|
|
}
|
|
|
- return new Result(ResultCode.SUCCESS,dataJa);
|
|
|
+ return new Result(ResultCode.SUCCESS, dataJa);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @Method : listDeviceEartagOnlineCountByDeviceCodeInPager
|
|
|
+ * @Method : listDeviceEartagOnlineCountByDeviceCodeInPager
|
|
|
* @Description : 显示设备关联耳标统计(带分页)
|
|
|
- * @Params : [deviceCode, earmark, addDate, pageNo, pageSize]
|
|
|
- * @Return : com.huimv.eartag2.common.utils.Result
|
|
|
- *
|
|
|
- * @Author : ZhuoNing
|
|
|
- * @Date : 2022/3/9
|
|
|
- * @Time : 20:08
|
|
|
+ * @Params : [deviceCode, earmark, addDate, pageNo, pageSize]
|
|
|
+ * @Return : com.huimv.eartag2.common.utils.Result
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2022/3/9
|
|
|
+ * @Time : 20:08
|
|
|
*/
|
|
|
@Override
|
|
|
public Result listDeviceEartagOnlineCountByDeviceCodeInPager(String deviceCode, String earmark, String addDate, Integer pageNo, Integer pageSize) throws ParseException {
|
|
@@ -105,15 +102,15 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
Specification<EartagDeviceEartagCountEntity> sf = (Specification<EartagDeviceEartagCountEntity>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
//
|
|
|
List<Predicate> predList = new ArrayList<>();
|
|
|
- if (null != earmark && earmark.trim().length()>0) {
|
|
|
+ if (null != earmark && earmark.trim().length() > 0) {
|
|
|
predList.add(criteriaBuilder.equal(root.get("earmark").as(String.class), earmark));
|
|
|
}
|
|
|
//
|
|
|
- if (null != deviceCode && deviceCode.trim().length()>0) {
|
|
|
+ if (null != deviceCode && deviceCode.trim().length() > 0) {
|
|
|
predList.add(criteriaBuilder.equal(root.get("deviceCode").as(String.class), deviceCode));
|
|
|
}
|
|
|
//
|
|
|
- if (null != addDate && addDate.trim().length()>0) {
|
|
|
+ if (null != addDate && addDate.trim().length() > 0) {
|
|
|
try {
|
|
|
predList.add(criteriaBuilder.equal(root.get("createDate").as(Date.class), new Date(new DateUtil().parseDateTextToLong(addDate))));
|
|
|
} catch (ParseException e) {
|
|
@@ -134,17 +131,17 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
|
|
|
@Override
|
|
|
public Result listHeartbeatByDeviceCodeAndDateInPager(String deviceCode, String addDate, Integer pageNo, Integer pageSize) {
|
|
|
- System.out.println("## addDate>>"+addDate);
|
|
|
+ System.out.println("## addDate>>" + addDate);
|
|
|
//
|
|
|
Specification<EartagHeartbeatEntity> sf = (Specification<EartagHeartbeatEntity>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
//
|
|
|
List<Predicate> predList = new ArrayList<>();
|
|
|
//
|
|
|
- if (null != deviceCode && deviceCode.trim().length()>0) {
|
|
|
+ if (null != deviceCode && deviceCode.trim().length() > 0) {
|
|
|
predList.add(criteriaBuilder.equal(root.get("deviceCode").as(String.class), deviceCode));
|
|
|
}
|
|
|
//
|
|
|
- if (null != addDate && addDate.trim().length()>0) {
|
|
|
+ if (null != addDate && addDate.trim().length() > 0) {
|
|
|
try {
|
|
|
predList.add(criteriaBuilder.equal(root.get("createDate").as(Date.class), new Date(new DateUtil().parseDateTextToLong(addDate))));
|
|
|
} catch (ParseException e) {
|
|
@@ -164,14 +161,13 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @Method : listDeviceEnvtempByDeviceCodeInPager
|
|
|
+ * @Method : listDeviceEnvtempByDeviceCodeInPager
|
|
|
* @Description : 分页查询设备温度
|
|
|
- * @Params : [deviceCode, addDate, pageNo, pageSize]
|
|
|
- * @Return : com.huimv.eartag2.common.utils.Result
|
|
|
- *
|
|
|
- * @Author : ZhuoNing
|
|
|
- * @Date : 2022/3/9
|
|
|
- * @Time : 21:27
|
|
|
+ * @Params : [deviceCode, addDate, pageNo, pageSize]
|
|
|
+ * @Return : com.huimv.eartag2.common.utils.Result
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2022/3/9
|
|
|
+ * @Time : 21:27
|
|
|
*/
|
|
|
@Override
|
|
|
public Result listDeviceEnvtempByDeviceCodeInPager(String deviceCode, String addDate, Integer pageNo, Integer pageSize) {
|
|
@@ -180,11 +176,11 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
//
|
|
|
List<Predicate> predList = new ArrayList<>();
|
|
|
//
|
|
|
- if (null != deviceCode && deviceCode.trim().length()>0) {
|
|
|
+ if (null != deviceCode && deviceCode.trim().length() > 0) {
|
|
|
predList.add(criteriaBuilder.equal(root.get("deviceCode").as(String.class), deviceCode));
|
|
|
}
|
|
|
//
|
|
|
- if (null != addDate && addDate.trim().length()>0) {
|
|
|
+ if (null != addDate && addDate.trim().length() > 0) {
|
|
|
try {
|
|
|
predList.add(criteriaBuilder.equal(root.get("createDate").as(Date.class), new Date(new DateUtil().parseDateTextToLong(addDate))));
|
|
|
} catch (ParseException e) {
|
|
@@ -204,14 +200,13 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @Method : listDeviceRegisterInPager
|
|
|
+ * @Method : listDeviceRegisterInPager
|
|
|
* @Description : 列表查询分页信息(分页)
|
|
|
- * @Params : [farmId, deviceCode, alias, startDate, endDate, activeStatus, liveStatus, pageNo, pageSize]
|
|
|
- * @Return : com.huimv.eartag2.common.utils.Result
|
|
|
- *
|
|
|
- * @Author : ZhuoNing
|
|
|
- * @Date : 2022/3/9
|
|
|
- * @Time : 22:28
|
|
|
+ * @Params : [farmId, deviceCode, alias, startDate, endDate, activeStatus, liveStatus, pageNo, pageSize]
|
|
|
+ * @Return : com.huimv.eartag2.common.utils.Result
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2022/3/9
|
|
|
+ * @Time : 22:28
|
|
|
*/
|
|
|
@Override
|
|
|
public Result listDeviceRegisterInPager(String farmId, String deviceCode, String alias, String startDate, String endDate, Integer activeStatus, Integer liveStatus, Integer pageNo, Integer pageSize) throws ParseException {
|
|
@@ -229,19 +224,19 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
//
|
|
|
List<Predicate> predList = new ArrayList<>();
|
|
|
//farmId
|
|
|
- if (null != farmId && farmId.trim().length()>0) {
|
|
|
+ if (null != farmId && farmId.trim().length() > 0) {
|
|
|
predList.add(criteriaBuilder.equal(root.get("farmId").as(String.class), farmId));
|
|
|
}
|
|
|
//deviceCode
|
|
|
- if (null != deviceCode && deviceCode.trim().length()>0) {
|
|
|
+ if (null != deviceCode && deviceCode.trim().length() > 0) {
|
|
|
predList.add(criteriaBuilder.equal(root.get("deviceCode").as(String.class), deviceCode));
|
|
|
}
|
|
|
//alias
|
|
|
- if (null != alias && alias.trim().length()>0) {
|
|
|
+ if (null != alias && alias.trim().length() > 0) {
|
|
|
predList.add(criteriaBuilder.like(root.get("deviceAlias").as(String.class), alias));
|
|
|
}
|
|
|
//startDate
|
|
|
- if (null != startDate && startDate.trim().length()>0) {
|
|
|
+ if (null != startDate && startDate.trim().length() > 0) {
|
|
|
try {
|
|
|
predList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("createDate").as(Date.class), new Date(new DateUtil().parseDateTextToLong(startDate))));
|
|
|
} catch (ParseException e) {
|
|
@@ -249,7 +244,7 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
}
|
|
|
}
|
|
|
//endDate
|
|
|
- if (null != endDate && endDate.trim().length()>0) {
|
|
|
+ if (null != endDate && endDate.trim().length() > 0) {
|
|
|
try {
|
|
|
predList.add(criteriaBuilder.lessThanOrEqualTo(root.get("createDate").as(Date.class), new Date(new DateUtil().parseDateTextToLong(endDate))));
|
|
|
} catch (ParseException e) {
|
|
@@ -277,58 +272,132 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
//{}
|
|
|
Page<EartagDeviceRegisterEntity> pageDeviceRegister = deviceRegisterRepo.findAll(sf, pageable);
|
|
|
JSONObject outDataJo = new JSONObject();
|
|
|
- outDataJo.put("pageable",pageDeviceRegister.getPageable());
|
|
|
- outDataJo.put("last",pageDeviceRegister.isLast());
|
|
|
- outDataJo.put("totalElements",pageDeviceRegister.getTotalElements());
|
|
|
- outDataJo.put("totalPages",pageDeviceRegister.getTotalPages());
|
|
|
- outDataJo.put("number",pageDeviceRegister.getNumber());
|
|
|
- outDataJo.put("size",pageDeviceRegister.getSize());
|
|
|
- outDataJo.put("sort",pageDeviceRegister.getSort());
|
|
|
- outDataJo.put("numberOfElements",pageDeviceRegister.getNumberOfElements());
|
|
|
- outDataJo.put("first",pageDeviceRegister.isFirst());
|
|
|
- outDataJo.put("empty",pageDeviceRegister.isEmpty());
|
|
|
+ outDataJo.put("pageable", pageDeviceRegister.getPageable());
|
|
|
+ outDataJo.put("last", pageDeviceRegister.isLast());
|
|
|
+ outDataJo.put("totalElements", pageDeviceRegister.getTotalElements());
|
|
|
+ outDataJo.put("totalPages", pageDeviceRegister.getTotalPages());
|
|
|
+ outDataJo.put("number", pageDeviceRegister.getNumber());
|
|
|
+ outDataJo.put("size", pageDeviceRegister.getSize());
|
|
|
+ outDataJo.put("sort", pageDeviceRegister.getSort());
|
|
|
+ outDataJo.put("numberOfElements", pageDeviceRegister.getNumberOfElements());
|
|
|
+ outDataJo.put("first", pageDeviceRegister.isFirst());
|
|
|
+ outDataJo.put("empty", pageDeviceRegister.isEmpty());
|
|
|
|
|
|
List<EartagDeviceRegisterEntity> deviceRegisterEntityList = pageDeviceRegister.getContent();
|
|
|
// System.out.println("## deviceRegisterEntityList.size>>"+deviceRegisterEntityList.size());
|
|
|
JSONArray outJa = new JSONArray();
|
|
|
- outDataJo.put("content",outJa);
|
|
|
- for(EartagDeviceRegisterEntity deviceRegisterEntity:deviceRegisterEntityList){
|
|
|
+ outDataJo.put("content", outJa);
|
|
|
+ for (EartagDeviceRegisterEntity deviceRegisterEntity : deviceRegisterEntityList) {
|
|
|
JSONObject outJo = new JSONObject();
|
|
|
outJa.add(outJo);
|
|
|
- outJo.put("id",deviceRegisterEntity.getId());
|
|
|
- outJo.put("deviceCode",deviceRegisterEntity.getDeviceCode());
|
|
|
- outJo.put("countyCode",deviceRegisterEntity.getCountyCode());
|
|
|
- outJo.put("countyName",deviceRegisterEntity.getCountyName());
|
|
|
- outJo.put("farmId",deviceRegisterEntity.getFarmId());
|
|
|
- outJo.put("farmName",deviceRegisterEntity.getFarmName());
|
|
|
- outJo.put("typeF",deviceRegisterEntity.getTypeF());
|
|
|
- outJo.put("stage",deviceRegisterEntity.getStage());
|
|
|
- outJo.put("pigpenId",deviceRegisterEntity.getPigpenId());
|
|
|
- outJo.put("unitId",deviceRegisterEntity.getUnitId());
|
|
|
- outJo.put("registerTime",deviceRegisterEntity.getRegisterTime());
|
|
|
- outJo.put("lastTime",deviceRegisterEntity.getLastTime());
|
|
|
- outJo.put("activeStatus",deviceRegisterEntity.getActiveStatus());
|
|
|
- outJo.put("activeTime",dateUtil.formatDatetimeText(deviceRegisterEntity.getActiveTime()));
|
|
|
- outJo.put("deviceStatus",deviceRegisterEntity.getDeviceStatus());
|
|
|
- outJo.put("deviceAlias",deviceRegisterEntity.getDeviceAlias());
|
|
|
- outJo.put("location",deviceRegisterEntity.getLocation());
|
|
|
- outJo.put("remark",deviceRegisterEntity.getRemark());
|
|
|
- outJo.put("createDate",deviceRegisterEntity.getCreateDate());
|
|
|
- outJo.put("updateType",deviceRegisterEntity.getUpdateType());
|
|
|
+ outJo.put("id", deviceRegisterEntity.getId());
|
|
|
+ outJo.put("deviceCode", deviceRegisterEntity.getDeviceCode());
|
|
|
+ outJo.put("countyCode", deviceRegisterEntity.getCountyCode());
|
|
|
+ outJo.put("countyName", deviceRegisterEntity.getCountyName());
|
|
|
+ outJo.put("farmId", deviceRegisterEntity.getFarmId());
|
|
|
+ outJo.put("farmName", deviceRegisterEntity.getFarmName());
|
|
|
+ outJo.put("typeF", deviceRegisterEntity.getTypeF());
|
|
|
+ outJo.put("stage", deviceRegisterEntity.getStage());
|
|
|
+ outJo.put("pigpenId", deviceRegisterEntity.getPigpenId());
|
|
|
+ outJo.put("unitId", deviceRegisterEntity.getUnitId());
|
|
|
+ outJo.put("registerTime", deviceRegisterEntity.getRegisterTime());
|
|
|
+ outJo.put("lastTime", deviceRegisterEntity.getLastTime());
|
|
|
+ outJo.put("activeStatus", deviceRegisterEntity.getActiveStatus());
|
|
|
+ outJo.put("activeTime", dateUtil.formatDatetimeText(deviceRegisterEntity.getActiveTime()));
|
|
|
+ outJo.put("deviceStatus", deviceRegisterEntity.getDeviceStatus());
|
|
|
+ outJo.put("deviceAlias", deviceRegisterEntity.getDeviceAlias());
|
|
|
+ outJo.put("location", deviceRegisterEntity.getLocation());
|
|
|
+ outJo.put("remark", deviceRegisterEntity.getRemark());
|
|
|
+ outJo.put("createDate", deviceRegisterEntity.getCreateDate());
|
|
|
+ outJo.put("updateType", deviceRegisterEntity.getUpdateType());
|
|
|
}
|
|
|
return new Result(ResultCode.SUCCESS, outDataJo);
|
|
|
// return new Result(ResultCode.SUCCESS, deviceRegisterRepo.findAll(sf, pageable));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result listDeviceOnlineCountByDeviceCodeInPager(String deviceCode, String startDate, String endDate, Integer pageNo, Integer pageSize) throws ParseException {
|
|
|
+ //
|
|
|
+ Specification<EartagDeviceOnlineEntity> sf = (Specification<EartagDeviceOnlineEntity>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
+ List<Predicate> predList = new ArrayList<>();
|
|
|
+ //deviceCode
|
|
|
+ if (null != deviceCode && deviceCode.trim().length() > 0) {
|
|
|
+ predList.add(criteriaBuilder.equal(root.get("deviceCode").as(String.class), deviceCode));
|
|
|
+ }
|
|
|
+ //startDate
|
|
|
+ if (null != startDate && startDate.trim().length() > 0) {
|
|
|
+ try {
|
|
|
+ predList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("addDate").as(Date.class), new Date(new DateUtil().parseDateTextToLong(startDate))));
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //endDate
|
|
|
+ if (null != endDate && endDate.trim().length() > 0) {
|
|
|
+ try {
|
|
|
+ predList.add(criteriaBuilder.lessThanOrEqualTo(root.get("addDate").as(Date.class), new Date(new DateUtil().parseDateTextToLong(endDate))));
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ DateUtil dateUtil = new DateUtil();
|
|
|
+ //{}
|
|
|
+ Page<EartagDeviceOnlineEntity> pageDeviceOnline = deviceOnlineRepo.findAll(sf, pageable);
|
|
|
+ JSONObject outDataJo = new JSONObject();
|
|
|
+ JSONArray outJa = new JSONArray();
|
|
|
+ outDataJo.put("content", outJa);
|
|
|
+ List<EartagDeviceOnlineEntity> deviceRegisterEntityList = pageDeviceOnline.getContent();
|
|
|
+// System.out.println("## deviceRegisterEntityList.size>>"+deviceRegisterEntityList.size());
|
|
|
+ for (EartagDeviceOnlineEntity deviceRegisterEntity : deviceRegisterEntityList) {
|
|
|
+ JSONObject outJo = new JSONObject();
|
|
|
+ outJa.add(outJo);
|
|
|
+ outJo.put("id", deviceRegisterEntity.getId());
|
|
|
+ outJo.put("deviceCode", deviceRegisterEntity.getDeviceCode());
|
|
|
+ outJo.put("alias", deviceRegisterEntity.getAlias());
|
|
|
+ outJo.put("heartbeatTotal", deviceRegisterEntity.getHeartbeatTotal());
|
|
|
+ outJo.put("envtempTotal", deviceRegisterEntity.getEnvtempTotal());
|
|
|
+ outJo.put("eartagTotal", deviceRegisterEntity.getEartagTotal());
|
|
|
+ outJo.put("lastEnvtemp", deviceRegisterEntity.getLastEnvtemp());
|
|
|
+ outJo.put("lastEartag", deviceRegisterEntity.getLastEartag());
|
|
|
+ outJo.put("heartbeatFirstTime", dateUtil.formatDatetimeText(deviceRegisterEntity.getHeartbeatFirstTime()));
|
|
|
+ outJo.put("heartbeatLastTime", dateUtil.formatDatetimeText(deviceRegisterEntity.getHeartbeatLastTime()));
|
|
|
+ outJo.put("envtempFirstTime", dateUtil.formatDatetimeText(deviceRegisterEntity.getEnvtempFirstTime()));
|
|
|
+ outJo.put("envtempLastTime", dateUtil.formatDatetimeText(deviceRegisterEntity.getEnvtempLastTime()));
|
|
|
+ outJo.put("eartagFirstTime", dateUtil.formatDatetimeText(deviceRegisterEntity.getEartagFirstTime()));
|
|
|
+ outJo.put("eartagLastTime", dateUtil.formatDatetimeText(deviceRegisterEntity.getEartagLastTime()));
|
|
|
+ outJo.put("addDate", deviceRegisterEntity.getAddDate());
|
|
|
+ outJo.put("farmId", deviceRegisterEntity.getFarmId());
|
|
|
+ }
|
|
|
+ outDataJo.put("pageable", pageDeviceOnline.getPageable());
|
|
|
+ outDataJo.put("last", pageDeviceOnline.isLast());
|
|
|
+ outDataJo.put("totalElements", pageDeviceOnline.getTotalElements());
|
|
|
+ outDataJo.put("totalPages", pageDeviceOnline.getTotalPages());
|
|
|
+ outDataJo.put("number", pageDeviceOnline.getNumber());
|
|
|
+ outDataJo.put("size", pageDeviceOnline.getSize());
|
|
|
+ outDataJo.put("sort", pageDeviceOnline.getSort());
|
|
|
+ outDataJo.put("numberOfElements", pageDeviceOnline.getNumberOfElements());
|
|
|
+ outDataJo.put("first", pageDeviceOnline.isFirst());
|
|
|
+ outDataJo.put("empty", pageDeviceOnline.isEmpty());
|
|
|
+ return new Result(ResultCode.SUCCESS, outDataJo);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
- * @Method : listOnlineDevice
|
|
|
- * @Description :
|
|
|
- * @Params : [farmId, deviceCode, alias, addDate, pageNo, pageSize]
|
|
|
- * @Return : com.huimv.eartag2.common.utils.Result
|
|
|
- *
|
|
|
- * @Author : ZhuoNing
|
|
|
- * @Date : 2022/3/8
|
|
|
- * @Time : 20:55
|
|
|
+ * @Method : listOnlineDevice
|
|
|
+ * @Description :
|
|
|
+ * @Params : [farmId, deviceCode, alias, addDate, pageNo, pageSize]
|
|
|
+ * @Return : com.huimv.eartag2.common.utils.Result
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2022/3/8
|
|
|
+ * @Time : 20:55
|
|
|
*/
|
|
|
@Override
|
|
|
public Result listOnlineDevice(String farmId, String deviceCode, String alias, String addDate, Integer pageNo, Integer pageSize) throws ParseException {
|
|
@@ -338,7 +407,7 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
System.out.println("deviceOnlineAccessMode>>" + deviceOnlineAccessMode);
|
|
|
if (deviceOnlineAccessMode.trim().equalsIgnoreCase("mysql")) {
|
|
|
//
|
|
|
- return listDeviceOnlineFromMySQL(farmId,addDate , deviceCode, alias, pageNo, pageSize);
|
|
|
+ return listDeviceOnlineFromMySQL(farmId, addDate, deviceCode, alias, pageNo, pageSize);
|
|
|
} else {
|
|
|
//
|
|
|
return listDeviceOnlineFromCache(farmId, todayDate);
|
|
@@ -360,15 +429,15 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
//
|
|
|
List<Predicate> predList = new ArrayList<>();
|
|
|
//
|
|
|
- if (null != farmId && farmId.trim().length()>0) {
|
|
|
+ if (null != farmId && farmId.trim().length() > 0) {
|
|
|
predList.add(criteriaBuilder.equal(root.get("farmId").as(String.class), farmId));
|
|
|
}
|
|
|
//
|
|
|
- if (null != deviceCode && deviceCode.trim().length()>0) {
|
|
|
+ if (null != deviceCode && deviceCode.trim().length() > 0) {
|
|
|
predList.add(criteriaBuilder.equal(root.get("deviceCode").as(String.class), deviceCode));
|
|
|
}
|
|
|
//
|
|
|
- if (null != addDate && addDate.trim().length()>0) {
|
|
|
+ if (null != addDate && addDate.trim().length() > 0) {
|
|
|
try {
|
|
|
predList.add(criteriaBuilder.equal(root.get("addDate").as(Date.class), new Date(dateUtil.parseDateTextToLong(addDate))));
|
|
|
} catch (ParseException e) {
|
|
@@ -376,7 +445,7 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
}
|
|
|
}
|
|
|
//
|
|
|
- if (null != alias && alias.trim().length()>0) {
|
|
|
+ if (null != alias && alias.trim().length() > 0) {
|
|
|
predList.add(criteriaBuilder.equal(root.get("alias").as(String.class), alias));
|
|
|
}
|
|
|
Predicate[] pred = new Predicate[predList.size()];
|
|
@@ -391,7 +460,7 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
Page<EartagDeviceOnlineEntity> pageDeviceOnlineEntity = deviceOnlineRepo.findAll(sf, pageable);
|
|
|
|
|
|
List<EartagDeviceOnlineEntity> deviceOnlineEntityList = pageDeviceOnlineEntity.getContent();
|
|
|
- for(EartagDeviceOnlineEntity deviceOnlineEntity:deviceOnlineEntityList){
|
|
|
+ for (EartagDeviceOnlineEntity deviceOnlineEntity : deviceOnlineEntityList) {
|
|
|
|
|
|
}
|
|
|
|
|
@@ -473,22 +542,12 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
* @Time : 14:08
|
|
|
*/
|
|
|
@Override
|
|
|
- public Result listDeviceOnlineCountByDeviceCode(String deviceCode, Integer pastDays, Integer showMode) throws ParseException {
|
|
|
+ public Result listDeviceOnlineCountByDeviceCode(String deviceCode, Integer pastDays) 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) {
|
|
|
- JSONArray resultJa = (JSONArray) JSON.toJSON(deviceOnlineEntityList);
|
|
|
- for(int a=0;a<resultJa.size();a++){
|
|
|
- JSONObject resultJo = resultJa.getJSONObject(a);
|
|
|
- resultJo.put("envtempFirstTime",dateUtil.formatDatetimeText(resultJo.getDate("envtempFirstTime")));
|
|
|
- resultJo.put("envtempLastTime",dateUtil.formatDatetimeText(resultJo.getDate("envtempLastTime")));
|
|
|
- }
|
|
|
- return new Result(ResultCode.SUCCESS, resultJa);
|
|
|
- } else {
|
|
|
+ List<EartagDeviceOnlineEntity> deviceOnlineEntityList = deviceOnlineRepo.getDeviceOnlineByDeviceCode(deviceCode, pastDate, todayDate);
|
|
|
+ if (deviceOnlineEntityList.size() > 0) {
|
|
|
JSONArray dataJa = new JSONArray();
|
|
|
for (EartagDeviceOnlineEntity deviceOnlineEntity : deviceOnlineEntityList) {
|
|
|
JSONObject newJo = new JSONObject();
|
|
@@ -497,10 +556,9 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
newJo.put("value", deviceOnlineEntity.getEartagTotal());
|
|
|
}
|
|
|
return new Result(ResultCode.SUCCESS, dataJa);
|
|
|
+ } 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);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -522,7 +580,7 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
return new Result(BizConst.CODE_DEVICE_REGISTER_NO_EXIST, BizConst.MSG_DEVICE_REGISTER_NO_EXIST, false);
|
|
|
} else {
|
|
|
JSONObject resultJo = (JSONObject) JSON.toJSON(deviceRegisterEntity);
|
|
|
- resultJo.put("activeTime",dateUtil.formatDatetimeText(resultJo.getDate("activeTime")));
|
|
|
+ resultJo.put("activeTime", dateUtil.formatDatetimeText(resultJo.getDate("activeTime")));
|
|
|
|
|
|
return new Result(ResultCode.SUCCESS, resultJo);
|
|
|
}
|
|
@@ -538,9 +596,9 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
* @Time : 13:21
|
|
|
*/
|
|
|
@Override
|
|
|
- public Result listOnlineDevice(String farmId,String date) throws ParseException {
|
|
|
+ public Result listOnlineDevice(String farmId, String date) throws ParseException {
|
|
|
DateUtil dateUtil = new DateUtil();
|
|
|
- if(date == null){
|
|
|
+ if (date == null) {
|
|
|
date = dateUtil.getTodayDateText();
|
|
|
}
|
|
|
//* 这里提供2种方式:1、从数据库读取 2、从缓存中取数(后期优化),但是同时提供2种方式都可用,防止缓存方式失效 */
|
|
@@ -574,10 +632,10 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
// deviceOnlineEntity.setHeartbeatFirstTime(du.formatDatetimeText());
|
|
|
// }
|
|
|
JSONArray resultJa = (JSONArray) JSON.toJSON(deviceOnlineEntityList);
|
|
|
- for(int a=0;a<resultJa.size();a++){
|
|
|
+ for (int a = 0; a < resultJa.size(); a++) {
|
|
|
JSONObject resultJo = resultJa.getJSONObject(a);
|
|
|
- resultJo.put("envtempFirstTime",du.formatDateText(resultJo.getTimestamp("envtempFirstTime")));
|
|
|
- resultJo.put("envtempLastTime",du.formatDateText(resultJo.getTimestamp("envtempLastTime")));
|
|
|
+ resultJo.put("envtempFirstTime", du.formatDateText(resultJo.getTimestamp("envtempFirstTime")));
|
|
|
+ resultJo.put("envtempLastTime", du.formatDateText(resultJo.getTimestamp("envtempLastTime")));
|
|
|
}
|
|
|
return new Result(ResultCode.SUCCESS, resultJa);
|
|
|
}
|