Commit 10f6f035 zshaohui

1.客户端上传msg修改

2.http post 请求后 releaseConnection
1 个父辈 4b1661ef
...@@ -148,26 +148,30 @@ public class HttpHelper { ...@@ -148,26 +148,30 @@ public class HttpHelper {
} }
public static String postJsonWithAuth(String url, Object params, String auth) throws ApiException { public static String postJsonWithAuth(String url, Object params, String auth) throws ApiException {
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("Content-Type", "application/json;charset=utf-8"); String requestBody = "";
if (auth != null && !auth.isEmpty()) {
httpPost.addHeader("Authorization", auth);
}
// 设置请求参数 // 设置请求参数
if (params != null) { if (params != null) {
try { try {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
String requestBody = mapper.writeValueAsString(params); requestBody = mapper.writeValueAsString(params);
httpPost.setEntity(new StringEntity(requestBody, CONTENT_CHARSET));
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
throw new ApiException("Request params to [" + url + "] Json failed:" + e.getMessage()); throw new ApiException("Request params to [" + url + "] Json failed:" + e.getMessage());
} catch (Exception e) { } catch (Exception e) {
throw new ApiException("Request params to [" + url + "] json exception:" + e.getMessage()); throw new ApiException("Request params to [" + url + "] json exception:" + e.getMessage());
} }
} }
HttpPost httpPost = null;
CloseableHttpClient httpClient = null; CloseableHttpClient httpClient = null;
CloseableHttpResponse response = null; CloseableHttpResponse response = null;
try { try {
httpPost = new HttpPost(url);
httpPost.addHeader("Content-Type", "application/json;charset=utf-8");
if (auth != null && !auth.isEmpty()) {
httpPost.addHeader("Authorization", auth);
}
httpPost.setEntity(new StringEntity(requestBody, CONTENT_CHARSET));
httpClient = HttpClients.createDefault(); httpClient = HttpClients.createDefault();
response = httpClient.execute(httpPost); response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity(); HttpEntity entity = response.getEntity();
...@@ -188,6 +192,9 @@ public class HttpHelper { ...@@ -188,6 +192,9 @@ public class HttpHelper {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
if (httpPost != null) {
httpPost.releaseConnection();
}
} }
} }
...@@ -211,11 +218,12 @@ public class HttpHelper { ...@@ -211,11 +218,12 @@ public class HttpHelper {
// 设置请求参数 // 设置请求参数
CloseableHttpClient httpClient = null; CloseableHttpClient httpClient = null;
CloseableHttpResponse response = null; CloseableHttpResponse response = null;
HttpPost httpPost = null;
try { try {
List<NameValuePair> params = toNameValuePair(paramMap); List<NameValuePair> params = toNameValuePair(paramMap);
URI uri = new URIBuilder(url).setParameters(params).build(); URI uri = new URIBuilder(url).setParameters(params).build();
log.info("执行请求:" + uri.toString()); log.info("执行请求:" + uri.toString());
HttpPost httpPost = new HttpPost(uri); httpPost = new HttpPost(uri);
httpPost.addHeader("Content-Type", contentType); httpPost.addHeader("Content-Type", contentType);
// httpPost.setEntity(new UrlEncodedFormEntity(params, CONTENT_CHARSET)); // httpPost.setEntity(new UrlEncodedFormEntity(params, CONTENT_CHARSET));
httpClient = HttpClients.createDefault(); httpClient = HttpClients.createDefault();
...@@ -238,6 +246,9 @@ public class HttpHelper { ...@@ -238,6 +246,9 @@ public class HttpHelper {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
if (httpPost != null){
httpPost.releaseConnection();
}
} }
} }
......
...@@ -118,6 +118,12 @@ public class StatusBean { ...@@ -118,6 +118,12 @@ public class StatusBean {
* 消息集合 * 消息集合
*/ */
public List<MsgInfo> msgList; public List<MsgInfo> msgList;
/**
* 消息合并
*/
public List<MsgInfo> mergeMsgList;
/** /**
* 料仓类型 * 料仓类型
*/ */
...@@ -656,12 +662,12 @@ public class StatusBean { ...@@ -656,12 +662,12 @@ public class StatusBean {
} }
public String getShowMsg(Locale locale) { public String getShowMsg(Locale locale) {
if (ObjectUtil.isEmpty(this.msgList)) { if (ObjectUtil.isEmpty(this.mergeMsgList)) {
return ""; return "";
} }
String returnMsg = ""; String returnMsg = "";
for (MsgInfo msg : for (MsgInfo msg :
msgList) { mergeMsgList) {
String mMsg = GetMsgStr(msg,locale); String mMsg = GetMsgStr(msg,locale);
if (ObjectUtil.isEmpty(returnMsg)) { if (ObjectUtil.isEmpty(returnMsg)) {
returnMsg = mMsg; returnMsg = mMsg;
...@@ -701,13 +707,15 @@ public class StatusBean { ...@@ -701,13 +707,15 @@ public class StatusBean {
} }
public void MsgDataProcess() { public List<MsgInfo> MsgDataProcess() {
//消息格式处理 List<MsgInfo> mergeMsgList = new ArrayList<>();
if( getMsgList()==null&& ObjectUtil.isNotEmpty(msg)){ if (msgList != null && !msgList.isEmpty()) {
msgList=new ArrayList<>(); mergeMsgList.addAll(msgList);
}
if (ObjectUtil.isNotEmpty(msg)) {
//判断是否有换行 //判断是否有换行
String[] msgArray=this.msg.split("\r\n"); String[] msgArray = this.msg.split("\r\n");
if(msgArray.length>0) { if (msgArray.length > 0) {
for (String msg : for (String msg :
msgArray) { msgArray) {
if (ObjectUtil.isEmpty(msg)) { if (ObjectUtil.isEmpty(msg)) {
...@@ -726,13 +734,15 @@ public class StatusBean { ...@@ -726,13 +734,15 @@ public class StatusBean {
} }
if (msgArray.length == 1) { if (msgArray.length == 1) {
msgList.add(new MsgInfo(msg, msgType,msgEn,msgJp,msgCode,msgParam,"","")); mergeMsgList.add(new MsgInfo(msg, msgType, msgEn, msgJp, msgCode, msgParam, "", ""));
} else { } else {
msgList.add(new MsgInfo(msg, msgType)); mergeMsgList.add(new MsgInfo(msg, msgType));
} }
} }
} }
} }
setMergeMsgList(mergeMsgList);
return mergeMsgList;
} }
public void setRMsg(String msgKey, String[] msgParam, String message) { public void setRMsg(String msgKey, String[] msgParam, String message) {
......
...@@ -17,6 +17,7 @@ import com.neotel.smfcore.core.barcode.service.po.Barcode; ...@@ -17,6 +17,7 @@ import com.neotel.smfcore.core.barcode.service.po.Barcode;
import com.neotel.smfcore.core.barcode.service.po.Component; import com.neotel.smfcore.core.barcode.service.po.Component;
import com.neotel.smfcore.core.barcode.utils.CodeResolve; import com.neotel.smfcore.core.barcode.utils.CodeResolve;
import com.neotel.smfcore.core.device.bean.BoxStatusBean; import com.neotel.smfcore.core.device.bean.BoxStatusBean;
import com.neotel.smfcore.core.device.bean.MsgInfo;
import com.neotel.smfcore.core.device.enums.BOX_STATUS; import com.neotel.smfcore.core.device.enums.BOX_STATUS;
import com.neotel.smfcore.core.device.enums.OP; import com.neotel.smfcore.core.device.enums.OP;
import com.neotel.smfcore.core.device.enums.OP_STATUS; import com.neotel.smfcore.core.device.enums.OP_STATUS;
...@@ -844,7 +845,7 @@ public class BaseDeviceHandler implements IDeviceHandler { ...@@ -844,7 +845,7 @@ public class BaseDeviceHandler implements IDeviceHandler {
try { try {
//转换为新格式 //转换为新格式
statusBean.MsgDataProcess(); List<MsgInfo> mergeMsgList = statusBean.MsgDataProcess();
//判断是否刚刚上线 //判断是否刚刚上线
StatusBean bean = DevicesStatusUtil.getStatusBean(statusBean.getCid()); StatusBean bean = DevicesStatusUtil.getStatusBean(statusBean.getCid());
if (bean == null || bean.getBoxStatus() == null) { if (bean == null || bean.getBoxStatus() == null) {
...@@ -854,8 +855,8 @@ public class BaseDeviceHandler implements IDeviceHandler { ...@@ -854,8 +855,8 @@ public class BaseDeviceHandler implements IDeviceHandler {
DeviceMessageUtil.addOnlineMessage(statusBean.getCid(), "",statusBean.getClientIp()); DeviceMessageUtil.addOnlineMessage(statusBean.getCid(), "",statusBean.getClientIp());
DevicesStatusUtil.updateClientMsg(statusBean.getCid(), new ArrayList<>()); DevicesStatusUtil.updateClientMsg(statusBean.getCid(), new ArrayList<>());
} }
if(ObjectUtil.isNotEmpty(statusBean.msgList)&& statusBean.msgList.size()>0) { if(ObjectUtil.isNotEmpty(mergeMsgList)&& mergeMsgList.size()>0) {
DevicesStatusUtil.updateClientMsg(statusBean.getCid(), statusBean.msgList); DevicesStatusUtil.updateClientMsg(statusBean.getCid(), mergeMsgList);
} }
// //判断是否刚刚上线 // //判断是否刚刚上线
// StatusBean bean = DevicesStatusUtil.getStatusBean(statusBean.getCid()); // StatusBean bean = DevicesStatusUtil.getStatusBean(statusBean.getCid());
...@@ -908,6 +909,7 @@ public class BaseDeviceHandler implements IDeviceHandler { ...@@ -908,6 +909,7 @@ public class BaseDeviceHandler implements IDeviceHandler {
statusBean.setOp(statusBeanToSave.getOp()); statusBean.setOp(statusBeanToSave.getOp());
statusBean.setSeq(statusBeanToSave.getSeq()); statusBean.setSeq(statusBeanToSave.getSeq());
statusBean.setClientIp(statusBeanToSave.getClientIp()); statusBean.setClientIp(statusBeanToSave.getClientIp());
statusBean.setMergeMsgList(statusBeanToSave.getMergeMsgList());
/** /**
* 已解除的报警信息存到数据库中 * 已解除的报警信息存到数据库中
......
...@@ -158,7 +158,7 @@ public class DevicesStatusUtil { ...@@ -158,7 +158,7 @@ public class DevicesStatusUtil {
StatusBean statusBean = new StatusBean(); StatusBean statusBean = new StatusBean();
statusBean.setCid(cid); statusBean.setCid(cid);
statusBean.setTime(System.currentTimeMillis()); statusBean.setTime(System.currentTimeMillis());
statusBean.setMsgList(msgs); //statusBean.setMsgList(msgs);
clientMsgs.put(cid, statusBean); clientMsgs.put(cid, statusBean);
return statusBean; return statusBean;
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!