zsh_root
2024-01-02 7b595546af704983dbafcd0d385c8768ddacefc2
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package http;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
 
import com.alibaba.fastjson.JSONObject;
 
import cn.hutool.http.ContentType;
import cn.hutool.http.HttpUtil;
import cn.hutool.http.server.SimpleServer;
import jiekou.display;
import person.Person;
import person.person_Dell;
import tbDataModel.Tb_forward_data;
public class HTTP_Server {
 
 
    /**{"type": "display", "tagid": "8252", "x":"200", "y": "585", 
     * "z": "150", "floor": "0" ,
     * "biaozhi": "23", "timestamp": "2021-05-31 23:14:14.063"}
     * Êý¾Ý¸ñʽ
     * {"type":"infence","tagid":"2012","fencename":"ΣÏÕÇøÓò",
     * "biaozhi":"1","timestamp":"2021-06-01 18:35:25:624"}
     * ¸ñʽ˵Ã÷
     * type:infence£¨ÀàÐÍ£º½øÈëΣÏÕÇøÓò±¨¾¯£©£»
     * tagid:2012£¨É豸±àºÅ£ºÉ豸Ψһ±àÂ룩£»
     * fencename:ΣÏÕÇøÓò£¨ÇøÓòÃû³Æ£ºÎ£ÏÕÇøÓò£©£»
     * biaozhi:1(±êÖ¾£ºÇø·Ö´Óij¸öÒýÇæÉÏÀ´Êý¾Ý);
     * timestamp:2021-06-01 18:35:25:624(ʱ¼ä´Á£ºÄêÔÂÈÕʱ·ÖÃëºÁÃë¸ñʽ);* */
    public static void  httpget(Tb_forward_data htp) {
        String mark=display.getMark();
        String ip=htp.getIp();
        int port=Integer.parseInt(htp.getPort());
        final SimpleServer server = HttpUtil.createServer(port);
        server.addAction("/"+ip,(request, response)->{
            String aa = request.getQuery();
            String[] bb=aa.split("=");
            if(bb[0].equals("tagid")) {
                if(bb[1].equals("all")) {
                    Vector<Person> prv=person_Dell.getPerson_vector();
                    int size=prv.size();
                    if(size !=0) {
                        List<JSONObject>  list=new ArrayList<JSONObject>();
                        for(int i=0;i<size;i++) {
                            JSONObject json = new JSONObject(true);
                            Person pr=prv.get(i);
                            json.put("type", "display");
                            json.put("tagid", pr.getP_tagid());
                            json.put("x", pr.getP_x());
                            json.put("y", pr.getP_y());
                            json.put("z", pr.getP_z());
                            json.put("floor", pr.getP_floor());
                            json.put("biaozhi",mark);
                            json.put("timestamp",pr.getP_addtiem());
                            list.add(json);
                        }
                        response.write(list.toString(), ContentType.JSON.toString());
                    }
 
                }else {
                    String tagid=bb[1];
                    Person pr=person_Dell.get_Person(tagid);
                    JSONObject json = new JSONObject(true);
                    if(pr!=null) {
                        json.put("type", "display");
                        json.put("tagid", tagid);
                        json.put("x", pr.getP_x());
                        json.put("y", pr.getP_y());
                        json.put("z", pr.getP_z());
                        json.put("floor", pr.getP_floor());
                        json.put("biaozhi",mark);
                        json.put("timestamp",pr.getP_addtiem());
                    }else {
                        json.put("erro", tagid+"±êÇ©²»´æÔÚ");
                    }
                    response.write(json.toString(), ContentType.JSON.toString());
                }
            }else if(bb[0].equals("warning01")) {
                String tagid=bb[1];
                if(tagid.equals("all")) {                    
                    Vector<Person> prv=person_Dell.getPerson_vector();
                    int size=prv.size();
                    if(size !=0) {
                        List<JSONObject>  list=new ArrayList<JSONObject>();
                        for(int i=0;i<size;i++) {
                            Person pr=prv.get(i);
                            String infece=pr.getP_fence();
                            if(infece.equals("1")) {
                                JSONObject json = new JSONObject(true);
                                json.put("type", "infence");
                                json.put("tagid", tagid);
                                json.put("fencename", pr.getP_fencename());
                                json.put("biaozhi",mark);
                                json.put("timestamp",pr.getInwarningtime());
                                list.add(json);
                            }
                            response.write(list.toString(), ContentType.JSON.toString());
                        }
 
                    }else {
 
                    }
 
 
                }else {
                    Person pr=person_Dell.get_Person(tagid);
                    String infece=pr.getP_fence();
                    JSONObject json = new JSONObject(true);
                    if(infece.equals("1")) {                        
                        json.put("type", "infence");
                        json.put("tagid", tagid);
                        json.put("fencename", pr.getP_fencename());
                        json.put("biaozhi",mark);
                        json.put("timestamp",pr.getInwarningtime());
                    }
                    response.write(json.toString(), ContentType.JSON.toString());
                }
            }
 
 
        });
        server.start();
    }
 
 
}