|
@@ -5,6 +5,7 @@ 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.Const;
|
|
|
import com.huimv.env.utils.DateUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.*;
|
|
@@ -73,4 +74,76 @@ public class AlarmImpl implements IAlarm {
|
|
|
// }
|
|
|
return new Result(ResultCode.SUCCESS, warningInfoEntityPage);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result getAlarm(Integer farmId, Integer alarmType, String alarmDateText,Integer quantity) throws ParseException {
|
|
|
+ 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 != alarmDateText) {
|
|
|
+ //转换为日期才能比较
|
|
|
+ Date alarmDate = null;
|
|
|
+ try {
|
|
|
+ alarmDate = dateUtil.formatDate(alarmDateText);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ 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();
|
|
|
+ };
|
|
|
+// return new Result(ResultCode.SUCCESS,applyRepo.listApply(pageable,applyId));
|
|
|
+ List<BaseWarningInfoEntity> warningInfoEntityList = warningInfoRepo.findAll(sf);
|
|
|
+ System.out.println("warningInfoEntityList.size="+warningInfoEntityList.size());
|
|
|
+ //格式化日期
|
|
|
+// 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, warningInfoEntityList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Method : getAlarm
|
|
|
+ * @Description : 查询今天的警报
|
|
|
+ * @Params : [farmId, quantity]
|
|
|
+ * @Return : com.huimv.common.utils.Result
|
|
|
+ *
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2021/12/5
|
|
|
+ * @Time : 14:54
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result getAlarm(Integer farmId, Integer quantity) throws ParseException {
|
|
|
+ String today = dateUtil.getTodayDateText();
|
|
|
+ System.out.println("today>>"+today);
|
|
|
+ //
|
|
|
+ List<BaseWarningInfoEntity> warningInfoEntityList = warningInfoRepo.findTodayAlarm(farmId,today,quantity);
|
|
|
+ System.out.println("size>>"+warningInfoEntityList.size());
|
|
|
+ if(warningInfoEntityList.size()>0){
|
|
|
+ return new Result(ResultCode.SUCCESS,warningInfoEntityList);
|
|
|
+ }else{
|
|
|
+ return new Result(Const.ERROR_CODE_NOTEXIST,Const.ERROR_MSG_NOTEXIST,false);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|