Commit 10f6f035 zshaohui

1.客户端上传msg修改

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