package com.terra.lfdcexp.entity; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.terra.lfdcexp.service.WeilanMonService; import com.terra.lfdcexp.util.HttpClientUtil; import com.terra.lfdcexp.util.JsonUtils; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @Data @Slf4j public class FenceEntityVo { @Value("${http.alertinfo}") private String http_alertinfo; @Value("${http.topost}") private String topost_alertinfo; @Autowired WeilanMonService weilanMonService ; private List fenceEntityList; private void parser(String json) { if (fenceEntityList == null) { fenceEntityList = new ArrayList(); } fenceEntityList = JSON.parseArray(json, FenceEntity.class); System.out.println("parse fenceEntity" + fenceEntityList.size()); } public List isAlert(String msg) { parser(msg); if (fenceEntityList == null) return new ArrayList(); List fenceList = fenceEntityList.stream().filter(line -> (line.getEvents().indexOf("21") > -1)) // 过滤掉cjavapy .collect(Collectors.toList()); //code = 21 报警 /** * 报警围栏数组与报警信息数据,通过usrname比较,相同的发送 */ if (fenceList.size() > 0) { String alertInfoJson = HttpClientUtil.doGet(http_alertinfo); AlertInfoVo alertInfoVo = new AlertInfoVo(); alertInfoVo.parser(alertInfoJson); List alertInfoInList = alertInfoVo.getStatusInList(); if (alertInfoInList != null && alertInfoInList.size() > 0) for (FenceEntity f : fenceList) { for(AlertInfo a: alertInfoInList){ if( a.getUserName().equals(f.getUserName())){ //通过围栏获取摄像头id,这里只获取一个摄像头 WeilanMonEntity w = weilanMonService.getOne(new QueryWrapper().eq("f_id",a.getWtId())); WarnEntity warnEntity = new WarnEntity(); if( w != null) { warnEntity.setCameraCode(w.getGId()); warnEntity.setType("3"); warnEntity.setSource("1"); warnEntity.setStartDate(a.getStartTime()); warnEntity.setWarnName(f.getUserName() + "进入" + a.getName() + "围栏"); String retFromTopost = HttpClientUtil.doPostJson(topost_alertinfo, JsonUtils.toJson(warnEntity)); log.info(retFromTopost+"\n"+JsonUtils.toJson(warnEntity)+"\n"); } } } } } return null; } }