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();
|
}
|
|
|
}
|