|
@@ -0,0 +1,76 @@
|
|
|
+package com.huimv.env.service.impl;
|
|
|
+
|
|
|
+import com.huimv.common.utils.Result;
|
|
|
+import com.huimv.common.utils.ResultCode;
|
|
|
+import com.huimv.env.dao.entity.BaseWarningInfoEntity;
|
|
|
+import com.huimv.env.dao.repo.BaseWarningInfoRepo;
|
|
|
+import com.huimv.env.service.IAlarm;
|
|
|
+import com.huimv.env.utils.DateUtil;
|
|
|
+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.text.ParseException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Project : huimv.shiwan
|
|
|
+ * @Package : com.huimv.biosafety.uface.controller
|
|
|
+ * @Description : TODO
|
|
|
+ * @Version : 1.0
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Create : 2020-12-25
|
|
|
+ **/
|
|
|
+@Service
|
|
|
+public class AlarmImpl implements IAlarm {
|
|
|
+ @Autowired
|
|
|
+ private BaseWarningInfoRepo warningInfoRepo;
|
|
|
+ @Autowired
|
|
|
+ private DateUtil dateUtil;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result getAlarm(Integer farmId, Integer alarmType, String alarmDateText, Integer pageNo, Integer pageSize) throws ParseException {
|
|
|
+ //转换为日期才能比较
|
|
|
+ Date alarmDate = dateUtil.formatDate(alarmDateText);
|
|
|
+ Specification<BaseWarningInfoEntity> sf = (Specification<BaseWarningInfoEntity>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
+ //
|
|
|
+ List<Predicate> predList = new ArrayList<>();
|
|
|
+ if (null != farmId) {
|
|
|
+ predList.add(criteriaBuilder.equal(root.get("farmId").as(Integer.class), farmId));
|
|
|
+ }
|
|
|
+ if (null != alarmType) {
|
|
|
+ predList.add(criteriaBuilder.equal(root.get("alarmType").as(Integer.class), alarmType));
|
|
|
+ }
|
|
|
+ if (null != alarmDate) {
|
|
|
+ predList.add(criteriaBuilder.equal(root.get("warningTime").as(Date.class), alarmDate));
|
|
|
+ }
|
|
|
+// if (null != returnState) {
|
|
|
+// predList.add(criteriaBuilder.equal(root.get("returnState").as(Integer.class), returnState));
|
|
|
+// }
|
|
|
+// if (null != deliverState) {
|
|
|
+// predList.add(criteriaBuilder.equal(root.get("deliverState").as(Integer.class), deliverState));
|
|
|
+// }
|
|
|
+ //
|
|
|
+ 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));
|
|
|
+ Page<BaseWarningInfoEntity> warningInfoEntityPage = warningInfoRepo.findAll(sf, pageable);
|
|
|
+ //格式化日期
|
|
|
+// List<BaseWarningInfoEntity> warningInfoEntityList = warningInfoEntityPage.getContent();
|
|
|
+// for(BaseWarningInfoEntity warningInfoEntity:warningInfoEntityList){
|
|
|
+// warningInfoEntity.setWarningTime(new Timestamp(dateUtil.formatDate(dateUtil.fromLongToDate(warningInfoEntity.getWarningTime().getTime(),"yyyy-MM-dd")).getTime()));
|
|
|
+// warningInfoEntity.setUploadTime(new Timestamp(dateUtil.formatDate(dateUtil.fromLongToDate(warningInfoEntity.getUploadTime().getTime(),"yyyy-MM-dd")).getTime()));
|
|
|
+// }
|
|
|
+ return new Result(ResultCode.SUCCESS, warningInfoEntityPage);
|
|
|
+ }
|
|
|
+}
|