|
@@ -1,6 +1,5 @@
|
|
|
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.*;
|
|
@@ -13,10 +12,8 @@ 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.*;
|
|
|
|
|
@@ -57,6 +54,8 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
private EartagDeviceEartagCountRepo deviceEartagCountRepo;
|
|
|
@Autowired
|
|
|
private EartagEnvRepo eartagEnvRepo;
|
|
|
+ @Autowired
|
|
|
+ private EartagHeartbeatRepo heartbeatRepo;
|
|
|
|
|
|
/**
|
|
|
* @Method : listDeviceEnvtempByDeviceCode
|
|
@@ -88,6 +87,80 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * @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
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result listDeviceEartagOnlineCountByDeviceCodeInPager(String deviceCode, String earmark, String addDate, Integer pageNo, Integer pageSize) throws ParseException {
|
|
|
+ //
|
|
|
+ Specification<EartagDeviceEartagCountEntity> sf = (Specification<EartagDeviceEartagCountEntity>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
+ //
|
|
|
+ List<Predicate> predList = new ArrayList<>();
|
|
|
+ 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) {
|
|
|
+ predList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("deviceCode").as(String.class), deviceCode));
|
|
|
+ }
|
|
|
+ //
|
|
|
+ if (null != addDate && addDate.trim().length()>0) {
|
|
|
+ try {
|
|
|
+ predList.add(criteriaBuilder.lessThanOrEqualTo(root.get("createDate").as(Date.class), new Date(new DateUtil().parseDateTextToLong(addDate))));
|
|
|
+ } 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);
|
|
|
+ return new Result(ResultCode.SUCCESS, deviceEartagCountRepo.findAll(sf, pageable));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result listHeartbeatByDeviceCodeAndDateInPager(String deviceCode, String addDate, Integer pageNo, Integer pageSize) {
|
|
|
+ //
|
|
|
+ Specification<EartagHeartbeatEntity> sf = (Specification<EartagHeartbeatEntity>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
+ //
|
|
|
+ List<Predicate> predList = new ArrayList<>();
|
|
|
+ //
|
|
|
+ if (null != deviceCode && deviceCode.trim().length()>0) {
|
|
|
+ predList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("deviceCode").as(String.class), deviceCode));
|
|
|
+ }
|
|
|
+ //
|
|
|
+ if (null != addDate && addDate.trim().length()>0) {
|
|
|
+ try {
|
|
|
+ predList.add(criteriaBuilder.lessThanOrEqualTo(root.get("createDate").as(Date.class), new Date(new DateUtil().parseDateTextToLong(addDate))));
|
|
|
+ } 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);
|
|
|
+ return new Result(ResultCode.SUCCESS, heartbeatRepo.findAll(sf, pageable));
|
|
|
+ /////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* @Method : listOnlineDevice
|
|
|
* @Description :
|
|
|
* @Params : [farmId, deviceCode, alias, addDate, pageNo, pageSize]
|