Commit edffcbec authored by zhouleilei's avatar zhouleilei

控制指令添加异常捕获

parent e7f07544
......@@ -90,7 +90,12 @@ public class ControlCommandServiceImpl implements ControlCommandService {
messageContent.addElement(HttpConstants.COMMAND).setText("0");
}
//相位驻留
String xmlPost = OkHttpClientUtil.xmlPost(hisenseUrl, document.asXML());
String xmlPost = null;
try {
xmlPost = OkHttpClientUtil.xmlPost(hisenseUrl, document.asXML());
} catch (Exception e) {
throw new RuntimeException(e);
}
log.info("第一次锁相/解锁 海信返回msg:{}",xmlPost);
/*String xmlPost = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<systemScription System=\"TCIP\" Version=\"1.0\">\n" +
......@@ -110,8 +115,13 @@ public class ControlCommandServiceImpl implements ControlCommandService {
" </messageContent>\n" +
"</systemScription>";*/
if (StringUtils.isNotBlank(xmlPost)) {
Document extendPost = DocumentHelper.parseText(xmlPost);
String extendResult = extendPost.selectSingleNode(HttpConstants.SYSTEMSCRIPTION_RESULT).getText();
String extendResult = null;
try {
Document extendPost = DocumentHelper.parseText(xmlPost);
extendResult = extendPost.selectSingleNode(HttpConstants.SYSTEMSCRIPTION_RESULT).getText();
} catch (DocumentException e) {
throw new RuntimeException(e);
}
if (HttpConstants.RESULT_1.equals(extendResult) || HttpConstants.RESULT_2.equals(extendResult)) {
if (commandVO.getCommand() == 1){
Integer duration = commandVO.getDuration();
......@@ -167,7 +177,12 @@ public class ControlCommandServiceImpl implements ControlCommandService {
//逻辑:第一次发送步进指令是相位驻留,以后发送才是相位步进,步进成功则取消步进。步进失败,也立即下发取消步进控制
//相位驻留
long start = System.currentTimeMillis();
String xmlPost = OkHttpClientUtil.xmlPost(hisenseUrl, document.asXML());
String xmlPost = null;
try {
xmlPost = OkHttpClientUtil.xmlPost(hisenseUrl, document.asXML());
} catch (Exception e) {
throw new RuntimeException(e);
}
long end = System.currentTimeMillis();
log.info("相位驻留 耗时: {} ms,msg:{}", end - start,xmlPost);
/*String xmlPost = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
......@@ -189,14 +204,24 @@ public class ControlCommandServiceImpl implements ControlCommandService {
"</systemScription>";*/
if (StringUtils.isNotBlank(xmlPost)) {
Document extendPost = DocumentHelper.parseText(xmlPost);
String extendResult = extendPost.selectSingleNode(HttpConstants.SYSTEMSCRIPTION_RESULT).getText();
String extendResult = null;
try {
Document extendPost = DocumentHelper.parseText(xmlPost);
extendResult = extendPost.selectSingleNode(HttpConstants.SYSTEMSCRIPTION_RESULT).getText();
} catch (DocumentException e) {
throw new RuntimeException(e);
}
if (HttpConstants.RESULT_1.equals(extendResult) || HttpConstants.RESULT_2.equals(extendResult)) {
//开始步进
//给海信发送http请求
for (int i = 0; i < stepNum; i++) {
long s = System.currentTimeMillis();
String post = OkHttpClientUtil.xmlPost(hisenseUrl, document.asXML());
String post = null;
try {
post = OkHttpClientUtil.xmlPost(hisenseUrl, document.asXML());
} catch (Exception e) {
throw new RuntimeException(e);
}
long e = System.currentTimeMillis();
log.info("相位步进 耗时: {} ms,msg:{}", e - s,post);
/*String post = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
......@@ -217,8 +242,13 @@ public class ControlCommandServiceImpl implements ControlCommandService {
" </messageContent>\n" +
"</systemScription>";*/
if (StringUtils.isNotBlank(post)) {
Document postResult = DocumentHelper.parseText(post);
String result = postResult.selectSingleNode(HttpConstants.SYSTEMSCRIPTION_RESULT).getText();
String result = null;
try {
Document postResult = DocumentHelper.parseText(post);
result = postResult.selectSingleNode(HttpConstants.SYSTEMSCRIPTION_RESULT).getText();
} catch (DocumentException ex) {
throw new RuntimeException(ex);
}
if (HttpConstants.RESULT_1.equals(result) || HttpConstants.RESULT_2.equals(result)) {
log.info("路口号 :{},第 {} 次步进成功,result:{}", code, i + 1, result);
} else {
......@@ -459,7 +489,12 @@ public class ControlCommandServiceImpl implements ControlCommandService {
messageContent.addElement(HttpConstants.PATTERN).setText("0");
//给海信发送http请求
String post = OkHttpClientUtil.xmlPost(hisenseUrl, document.asXML());
String post = null;
try {
post = OkHttpClientUtil.xmlPost(hisenseUrl, document.asXML());
} catch (Exception e) {
throw new RuntimeException(e);
}
/*String post = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<systemScription System=\"TCIP\" Version=\"1.0\">\n" +
" <subSystem>Hisense</subSystem>\n" +
......@@ -482,8 +517,13 @@ public class ControlCommandServiceImpl implements ControlCommandService {
log.error(" 手动方案控制- 恢复固定配时 失败");
return jsonViewObject.fail(" 手动方案控制- 恢复固定配时 失败");
}
Document postResult = DocumentHelper.parseText(post);
String result = postResult.selectSingleNode(HttpConstants.SYSTEMSCRIPTION_RESULT).getText();
String result = null;
try {
Document postResult = DocumentHelper.parseText(post);
result = postResult.selectSingleNode(HttpConstants.SYSTEMSCRIPTION_RESULT).getText();
} catch (DocumentException e) {
throw new RuntimeException(e);
}
if (HttpConstants.RESULT_1.equals(result)) {
//指令下发成功
......@@ -529,7 +569,12 @@ public class ControlCommandServiceImpl implements ControlCommandService {
messageContent.addElement(HttpConstants.SPLIT).setText(tempSchemeSendVO.getSplit().replaceAll(" ", ","));
//给海信发送http请求
String post = OkHttpClientUtil.xmlPost(hisenseUrl, document.asXML());
String post = null;
try {
post = OkHttpClientUtil.xmlPost(hisenseUrl, document.asXML());
} catch (Exception e) {
throw new RuntimeException(e);
}
/*String post = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<systemScription System=\"TCIP\" Version=\"1.0\">\n" +
" <subSystem>Hisense</subSystem>\n" +
......@@ -552,8 +597,13 @@ public class ControlCommandServiceImpl implements ControlCommandService {
log.error("HTTP请求 5.16. 方案优化控制 失败");
return jsonViewObject.fail("HTTP请求 5.16. 方案优化控制 失败");
}
Document postResult = DocumentHelper.parseText(post);
String result = postResult.selectSingleNode(HttpConstants.SYSTEMSCRIPTION_RESULT).getText();
String result = null;
try {
Document postResult = DocumentHelper.parseText(post);
result = postResult.selectSingleNode(HttpConstants.SYSTEMSCRIPTION_RESULT).getText();
} catch (DocumentException e) {
throw new RuntimeException(e);
}
if (HttpConstants.RESULT_1.equals(result)) {
//指令下发成功
......@@ -728,7 +778,12 @@ public class ControlCommandServiceImpl implements ControlCommandService {
messageContent.addElement(HttpConstants.CTRLSTEP).setText("0");
//给海信发送http请求
String post = OkHttpClientUtil.xmlPost(hisenseUrl, document.asXML());
String post = null;
try {
post = OkHttpClientUtil.xmlPost(hisenseUrl, document.asXML());
} catch (Exception e) {
throw new RuntimeException(e);
}
/*String post = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<systemScription System=\"TCIP\" Version=\"1.0\">\n" +
" <subSystem>Hisense</subSystem>\n" +
......@@ -751,8 +806,13 @@ public class ControlCommandServiceImpl implements ControlCommandService {
log.error("HTTP请求 5.12. 步进及取消控制 失败");
return jsonViewObject.fail("HTTP请求 5.12. 步进及取消控制 失败");
}
Document postResult = DocumentHelper.parseText(post);
String result = postResult.selectSingleNode(HttpConstants.SYSTEMSCRIPTION_RESULT).getText();
String result = null;
try {
Document postResult = DocumentHelper.parseText(post);
result = postResult.selectSingleNode(HttpConstants.SYSTEMSCRIPTION_RESULT).getText();
} catch (DocumentException e) {
throw new RuntimeException(e);
}
if (HttpConstants.RESULT_1.equals(result) || HttpConstants.RESULT_2.equals(result)) {
//执行成功,开始延长
......@@ -760,7 +820,12 @@ public class ControlCommandServiceImpl implements ControlCommandService {
//延长结束,解除步进
messageContent.selectSingleNode(HttpConstants.COMMAND).setText("0");
//给海信发送http请求
String post1 = OkHttpClientUtil.xmlPost(hisenseUrl, document.asXML());
String post1 = null;
try {
post1 = OkHttpClientUtil.xmlPost(hisenseUrl, document.asXML());
} catch (Exception e) {
throw new RuntimeException(e);
}
/*String post1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<systemScription System=\"TCIP\" Version=\"1.0\">\n" +
" <subSystem>Hisense</subSystem>\n" +
......@@ -779,8 +844,13 @@ public class ControlCommandServiceImpl implements ControlCommandService {
" </messageContent>\n" +
"</systemScription>";*/
if (StringUtils.isNotBlank(post1)) {
Document extendPost = DocumentHelper.parseText(post1);
String extendResult = extendPost.selectSingleNode(HttpConstants.SYSTEMSCRIPTION_RESULT).getText();
String extendResult = null;
try {
Document extendPost = DocumentHelper.parseText(post1);
extendResult = extendPost.selectSingleNode(HttpConstants.SYSTEMSCRIPTION_RESULT).getText();
} catch (DocumentException e) {
throw new RuntimeException(e);
}
if (HttpConstants.RESULT_1.equals(extendResult) || HttpConstants.RESULT_2.equals(extendResult)) {
return jsonViewObject.success("延长相位 - 控制成功");
}
......@@ -789,7 +859,12 @@ public class ControlCommandServiceImpl implements ControlCommandService {
log.error("HTTP请求 5.12. 步进及取消控制 失败");
//重新发起三次取消控制请求
for (int j = 0; j < 3; j++) {
String httpPost = OkHttpClientUtil.xmlPost(hisenseUrl, document.asXML());
String httpPost = null;
try {
httpPost = OkHttpClientUtil.xmlPost(hisenseUrl, document.asXML());
} catch (Exception e) {
throw new RuntimeException(e);
}
/*String httpPost = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<systemScription System=\"TCIP\" Version=\"1.0\">\n" +
" <subSystem>Hisense</subSystem>\n" +
......@@ -808,8 +883,13 @@ public class ControlCommandServiceImpl implements ControlCommandService {
" </messageContent>\n" +
"</systemScription>";*/
if (StringUtils.isNotBlank(httpPost)) {
Document extendPost = DocumentHelper.parseText(httpPost);
String extendResult = extendPost.selectSingleNode(HttpConstants.SYSTEMSCRIPTION_RESULT).getText();
String extendResult = null;
try {
Document extendPost = DocumentHelper.parseText(httpPost);
extendResult = extendPost.selectSingleNode(HttpConstants.SYSTEMSCRIPTION_RESULT).getText();
} catch (DocumentException e) {
throw new RuntimeException(e);
}
if (HttpConstants.RESULT_1.equals(extendResult) || HttpConstants.RESULT_2.equals(extendResult)) {
return jsonViewObject.success("延长相位 - 控制成功");
}
......@@ -821,10 +901,20 @@ public class ControlCommandServiceImpl implements ControlCommandService {
messageContent.selectSingleNode(HttpConstants.COMMAND).setText("0");
//重新发起三次取消控制请求
for (int j = 0; j < 3; j++) {
String httpPost = OkHttpClientUtil.xmlPost(hisenseUrl, document.asXML());
String httpPost = null;
try {
httpPost = OkHttpClientUtil.xmlPost(hisenseUrl, document.asXML());
} catch (Exception e) {
throw new RuntimeException(e);
}
if (StringUtils.isNotBlank(httpPost)) {
Document extendPost = DocumentHelper.parseText(httpPost);
String extendResult = extendPost.selectSingleNode(HttpConstants.SYSTEMSCRIPTION_RESULT).getText();
String extendResult = null;
try {
Document extendPost = DocumentHelper.parseText(httpPost);
extendResult = extendPost.selectSingleNode(HttpConstants.SYSTEMSCRIPTION_RESULT).getText();
} catch (DocumentException e) {
throw new RuntimeException(e);
}
if (HttpConstants.RESULT_1.equals(extendResult) || HttpConstants.RESULT_2.equals(extendResult)) {
return jsonViewObject.success("延长相位 - 控制成功");
}
......@@ -864,7 +954,12 @@ public class ControlCommandServiceImpl implements ControlCommandService {
} else if (stepingPhaseDTO.getCommand() == 1) {
//逻辑:第一次发送步进指令是相位驻留,以后发送才是相位步进,步进成功则取消步进。步进失败,也立即下发取消步进控制
//相位驻留
String xmlPost = OkHttpClientUtil.xmlPost(hisenseUrl, document.asXML());
String xmlPost = null;
try {
xmlPost = OkHttpClientUtil.xmlPost(hisenseUrl, document.asXML());
} catch (Exception e) {
throw new RuntimeException(e);
}
/* String xmlPost = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<systemScription System=\"TCIP\" Version=\"1.0\">\n" +
" <subSystem>Hisense</subSystem>\n" +
......@@ -884,13 +979,23 @@ public class ControlCommandServiceImpl implements ControlCommandService {
"</systemScription>";*/
if (StringUtils.isNotBlank(xmlPost)) {
Document extendPost = DocumentHelper.parseText(xmlPost);
String extendResult = extendPost.selectSingleNode(HttpConstants.SYSTEMSCRIPTION_RESULT).getText();
String extendResult = null;
try {
Document extendPost = DocumentHelper.parseText(xmlPost);
extendResult = extendPost.selectSingleNode(HttpConstants.SYSTEMSCRIPTION_RESULT).getText();
} catch (DocumentException e) {
throw new RuntimeException(e);
}
if (HttpConstants.RESULT_1.equals(extendResult) || HttpConstants.RESULT_2.equals(extendResult)) {
//开始步进
//给海信发送http请求
for (int i = 0; i < stepingPhaseDTO.getStepCount(); i++) {
String post = OkHttpClientUtil.xmlPost(hisenseUrl, document.asXML());
String post = null;
try {
post = OkHttpClientUtil.xmlPost(hisenseUrl, document.asXML());
} catch (Exception e) {
throw new RuntimeException(e);
}
/*String post = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<systemScription System=\"TCIP\" Version=\"1.0\">\n" +
" <subSystem>Hisense</subSystem>\n" +
......@@ -909,8 +1014,13 @@ public class ControlCommandServiceImpl implements ControlCommandService {
" </messageContent>\n" +
"</systemScription>";*/
if (StringUtils.isNotBlank(post)) {
Document postResult = DocumentHelper.parseText(post);
String result = postResult.selectSingleNode(HttpConstants.SYSTEMSCRIPTION_RESULT).getText();
String result = null;
try {
Document postResult = DocumentHelper.parseText(post);
result = postResult.selectSingleNode(HttpConstants.SYSTEMSCRIPTION_RESULT).getText();
} catch (DocumentException e) {
throw new RuntimeException(e);
}
if (HttpConstants.RESULT_1.equals(result) || HttpConstants.RESULT_2.equals(result)) {
log.info("路口号 :{},第 {} 次步进成功,result:{}", stepingPhaseDTO.getCrossId(), i + 1, result);
} else {
......@@ -958,20 +1068,35 @@ public class ControlCommandServiceImpl implements ControlCommandService {
}
private boolean sendMesIsOk(String xml) throws DocumentException, InterruptedException {
String post = OkHttpClientUtil.xmlPost(hisenseUrl, xml);
String post = null;
try {
post = OkHttpClientUtil.xmlPost(hisenseUrl, xml);
} catch (Exception e) {
throw new RuntimeException(e);
}
if (StringUtils.isBlank(post)) {
return false;
}
Document postResult = DocumentHelper.parseText(post);
String result = postResult.selectSingleNode(HttpConstants.SYSTEMSCRIPTION_RESULT).getText();
Document postResult = null;
String result = null;
try {
postResult = DocumentHelper.parseText(post);
result = postResult.selectSingleNode(HttpConstants.SYSTEMSCRIPTION_RESULT).getText();
} catch (DocumentException e) {
throw new RuntimeException(e);
}
if (HttpConstants.RESULT_1.equals(result) || HttpConstants.RESULT_2.equals(result)) {
return true;
} else {
//连续重试发三次
for (int i = 0; i < 3; i++) {
post = OkHttpClientUtil.xmlPost(hisenseUrl, xml);
postResult = DocumentHelper.parseText(post);
result = postResult.selectSingleNode(HttpConstants.SYSTEMSCRIPTION_RESULT).getText();
try {
post = OkHttpClientUtil.xmlPost(hisenseUrl, xml);
postResult = DocumentHelper.parseText(post);
result = postResult.selectSingleNode(HttpConstants.SYSTEMSCRIPTION_RESULT).getText();
} catch (DocumentException e) {
throw new RuntimeException(e);
}
if (HttpConstants.RESULT_1.equals(result) || HttpConstants.RESULT_2.equals(result)) {
return true;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment