leutu
2024-05-08 7922905e4987789b636abdce1a240f4cee7c971b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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<FenceEntity> fenceEntityList;
 
    private void parser(String json) {
        if (fenceEntityList == null) {
            fenceEntityList = new ArrayList<FenceEntity>();
        }
 
        fenceEntityList = JSON.parseArray(json, FenceEntity.class);
        System.out.println("parse fenceEntity" + fenceEntityList.size());
 
    }
 
    public List<FenceEntity> isAlert(String msg) {
        parser(msg);
        if (fenceEntityList == null) return new ArrayList<FenceEntity>();
        List<FenceEntity> 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<AlertInfo> 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<WeilanMonEntity>().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;
 
    }
}