IntelligentRecognition/ah-jjsp-service/.svn/pristine/23/23e7e57e4802dd71584d470ad03...

312 lines
11 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.securityControl.task.domain.vo;
import com.securityControl.task.util.DateTimeHelper;
import lombok.extern.slf4j.Slf4j;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
@Slf4j
public class PostXml {
public static String 检测未带安全帽="0";
public static String 启动安全生产="0";
public static String 检测抽烟="0";
public static String 检测未戴口罩="0";
public static String 检测工作服="0";
public static String 检测石油制服="0";
public static String 检测消防制服="0";
public static String 检测露胳膊="0";
public static String 检测三色马甲="0";
public static String 检测绝缘手套和绝缘靴="0";
/**
* 获取3d云台报文
* @param Sx 开始横坐标
* @param Sy 开始y坐标
* @param Ex 结束点很坐标
* @param Ey 结束点 y坐标
* @return
*/
public static String get3DyunXmlData(String Sx, String Sy, String Ex, String Ey){
StringBuffer builder=new StringBuffer();
try{
builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
builder.append("<M Type=\"ComReq\">");
builder.append("<C Type=\"C\" Prio=\"1\" EPID=\"system\">");
builder.append("<Res Type=\"PTZ\" Idx=\"0\" OptID=\"C_PTZ_SelectZoom\">");
builder.append("<Param BeginX=\""+Sx+"\" BeginY=\""+Sy+"\" EndX=\""+Ex+"\" EndY=\""+Ey+"\"></Param>");
builder.append("</Res>");
builder.append("</C>");
builder.append("</M>");
}catch (Exception e){
log.error(e.toString(),e);
}
return builder.toString();
}
/**
* 设置水印
* @param value
* @return
*/
public static String getOsDText(String value){
StringBuffer builder=new StringBuffer();
try{
builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
builder.append("<M Type=\"ComReq\">");
builder.append("<C Type=\"S\" Prio=\"1\" EPID=\"system\">");
builder.append("<Res Type=\"IV\" Idx=\"0\" OptID=\"F_IV_TextAdd\">");
builder.append("<Param Value=\""+value+"\"/>");
builder.append("</Res>");
builder.append("</C>");
builder.append("</M>");
}catch (Exception e){
log.error(e.toString(),e);
}
return builder.toString();
}
public static String getDeviceNameXml(String value){
StringBuffer builder=new StringBuffer();
try{
builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
builder.append("<M Type=\"ComReq\">");
builder.append("<C Type=\"S\" Prio=\"1\" EPID=\"system\">");
builder.append("<Res Type=\"ST\" Idx=\"0\" OptID=\"F_RES_Desc\">");
builder.append("<Param>");
builder.append("<Res Name=\""+value+"\" Desc=\"\" Enable=\"1\" Usable=\"1\"/>");
builder.append("</Param> ");
builder.append("</Res>");
builder.append("</C>");
builder.append("</M>");
}catch (Exception e){
log.error(e.toString(),e);
}
return builder.toString();
}
public static String getDeviceCameraXml(String value){
StringBuffer builder=new StringBuffer();
try{
builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
builder.append("<M Type=\"ComReq\">");
builder.append("<C Type=\"S\" Prio=\"1\" EPID=\"system\">");
builder.append("<Res Type=\"IV\" Idx=\"0\" OptID=\"F_RES_Desc\">");
builder.append("<Param>");
builder.append("<Res Name=\""+value+"\" Desc=\"\" Enable=\"1\" Usable=\"1\"/>");
builder.append("</Param> ");
builder.append("</Res>");
builder.append("</C>");
builder.append("</M>");
}catch (Exception e){
log.error(e.toString(),e);
}
return builder.toString();
}
/**
* 获取球机信号数据
* @return
*/
public static String getQJXhXml(String idx){
StringBuffer builder=new StringBuffer();
try{
builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
builder.append("<M Type=\"ComReq\">");
builder.append("<C Type=\"G\" Prio=\"2\" EPID=\"system\" Lang=\"zh_CN\">");
builder.append("<Res Type=\"WM\" Idx=\""+idx+"\" OptID=\"F_WM_Signal\">");
builder.append("<Param></Param>");
builder.append("</Res>");
builder.append("</C>");
builder.append("</M>");
}catch (Exception e){
log.error(e.toString(),e);
}
return builder.toString();
}
/**
* puid
* 清晰上下线
* 开始时间
*
* @param puid
* @param startTime 开始时间//时间戳
* @param endTime 结束时间//时间戳
* @return
*/
public static String getXmlData(String puid, String startTime, String endTime) {
StringBuffer builder = new StringBuffer();
builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
builder.append("<M Type=\"ComReq\">");
builder.append("<C Type=\"C\" Prio=\"1\" EPID=\"system\">");
builder.append("<Res Type=\"ST\" Idx=\"0\" OptID=\"C_LOG_QueryEventLog\">");
builder.append("<Param Offset=\"0\" Count=\"200\" Begin=\"" + startTime + "\" End=\"" + endTime + "\">");
builder.append("<ID>E_PU_Online</ID>");
builder.append("<ID>E_PU_Offline</ID>");
builder.append("</Param>");
builder.append("</Res>");
builder.append("</C>");
builder.append("<OSets>");
builder.append("<Res OType=\"201\" OID=\"" + puid + "\" Type=\"ST\" Idx=\"0\">");
builder.append("</Res>");
builder.append("</OSets>");
builder.append("</M>");
return builder.toString();
}
/**
* xml解析数据
*
* @return
*/
public static List<BallUpDownEntity> getXmlData(String xml) {
List<BallUpDownEntity> list = new ArrayList<BallUpDownEntity>();
Document doc = null;
try {
doc = DocumentHelper.parseText(xml); // 将字符串转为XML
Element rootElt = doc.getRootElement(); // 获取根节点
// System.out.println("根节点:" + rootElt.getName()); // 拿到根节点的名称
Element C = rootElt.element("C");
// System.out.println("子节点:" + C.getName()); // 拿到子节点名称
Element Res = C.element("Res");
// System.out.println("子节点:" + Res.getName()); // 拿到子节点名称
Element Param = Res.element("Param");
Iterator iter = Param.elementIterator("Event"); // 获取结果点下的返回数据集合
Iterator lengthLeg = Param.elementIterator("Event"); // 获取结果点下的返回数据集合
int length = 0;
while (lengthLeg.hasNext()) {
Element Event = (Element) lengthLeg.next();//子节点名//父类节点
length++;
}
BallUpDownEntity entity = null;
while (iter.hasNext()) {
entity = new BallUpDownEntity();
Element Event = (Element) iter.next();//子节点名//父类节点
Element M = Event.element("M");
String type = M.attributeValue("Type");
if ("Event".equals(type)) {//type参数
Element E = M.element("E");//E参数
String ID = E.attributeValue("ID");//获取上下线类型
String time = E.attributeValue("Time");//获取到时间
String date = DateTimeHelper.stampToDate(time);//时间转换
if ("E_PU_Online".equals(ID)) {//
entity.setOnLineTime(date);
entity.setType("1");
} else if ("E_PU_Offline".equals(ID)) {//球机下线
entity.setOffLineTime(date);
entity.setType("2");
}
list.add(entity);
}
}
} catch (Exception e) {
log.error("xml解析失败", e);
}
return list;
}
public static String sedPostXml(String postUrl, String xmlString) throws IOException {
String postURL;
PostMethod postMethod = null;
postMethod = new PostMethod(postUrl) ;
postMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8") ;
//参数设置需要注意的就是里边不能传NULL要传空字符串
NameValuePair[] data = {
new NameValuePair("xml",xmlString),
};
postMethod.setRequestBody(data);
org.apache.commons.httpclient.HttpClient httpClient = new org.apache.commons.httpclient.HttpClient();
int response = httpClient.executeMethod(postMethod); // 执行POST方法
// String result = postMethod.getResponseBodyAsString() ;
InputStream is = postMethod.getResponseBodyAsStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
StringBuffer sb = new StringBuffer();
String str= "";
while((str = br.readLine()) != null){
sb.append(str);
}
String result = sb.toString();
return result;
}
/**
* xml解析
* @return
*/
public static String getqjxhData(String xml){
String Value=null;
try{
Document doc = DocumentHelper.parseText(xml); // 将字符串转为XML
Element rootElt = doc.getRootElement(); // 获取根节点
Element C=rootElt.element("C");
Element Res=C.element("Res");
Element Param=Res.element("Param");
Value = Param.attributeValue("Value");
}catch (Exception e){
Value=null;
}
return Value;
}
/**
* xml解析
* @return
*/
public static String getXml3dYunConfigData(String xml){
String msg="设置成功";
try{
Document doc = DocumentHelper.parseText(xml); // 将字符串转为XML
Element rootElt = doc.getRootElement(); // 获取根节点
// System.out.println("根节点:" + rootElt.getName()); // 拿到根节点的名称
Element C=rootElt.element("C");
// System.out.println("子节点:" + C.getName()); // 拿到子节点名称
Iterator iter = C.elementIterator("Res"); // 获取结果点下的返回数据集合
while (iter.hasNext()) {
Element Event = (Element) iter.next();//子节点名//父类节点
// System.out.println("根节点:" + Event.getName()); // 拿到根节点的名称
String type = Event.attributeValue("Type");
if(!"PTZ".equals(type)){
msg="设置失败";
}
}
}catch (Exception e){
msg="设置失败";
}
return msg;
}
}