Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
smf-core
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 10f6f035
由
zshaohui
编写于
2023-12-28 16:35:20 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
1.客户端上传msg修改
2.http post 请求后 releaseConnection
1 个父辈
4b1661ef
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
45 行增加
和
22 行删除
src/main/java/com/neotel/smfcore/common/utils/HttpHelper.java
src/main/java/com/neotel/smfcore/core/device/bean/StatusBean.java
src/main/java/com/neotel/smfcore/core/device/handler/impl/BaseDeviceHandler.java
src/main/java/com/neotel/smfcore/core/system/util/DevicesStatusUtil.java
src/main/java/com/neotel/smfcore/common/utils/HttpHelper.java
查看文件 @
10f6f03
...
...
@@ -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
();
}
}
}
...
...
src/main/java/com/neotel/smfcore/core/device/bean/StatusBean.java
查看文件 @
10f6f03
...
...
@@ -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
.
m
ergeM
sgList
))
{
return
""
;
}
String
returnMsg
=
""
;
for
(
MsgInfo
msg
:
msgList
)
{
m
ergeM
sgList
)
{
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
)
{
m
sgList
.
add
(
new
MsgInfo
(
msg
,
msgType
,
msgEn
,
msgJp
,
msgCode
,
msgParam
,
""
,
""
));
m
ergeMsgList
.
add
(
new
MsgInfo
(
msg
,
msgType
,
msgEn
,
msgJp
,
msgCode
,
msgParam
,
""
,
""
));
}
else
{
msgList
.
add
(
new
MsgInfo
(
msg
,
msgType
));
m
ergeM
sgList
.
add
(
new
MsgInfo
(
msg
,
msgType
));
}
}
}
}
setMergeMsgList
(
mergeMsgList
);
return
mergeMsgList
;
}
public
void
setRMsg
(
String
msgKey
,
String
[]
msgParam
,
String
message
)
{
...
...
src/main/java/com/neotel/smfcore/core/device/handler/impl/BaseDeviceHandler.java
查看文件 @
10f6f03
...
...
@@ -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
.
m
sgList
.
size
()>
0
)
{
DevicesStatusUtil
.
updateClientMsg
(
statusBean
.
getCid
(),
statusBean
.
m
sgList
);
if
(
ObjectUtil
.
isNotEmpty
(
mergeMsgList
)&&
mergeM
sgList
.
size
()>
0
)
{
DevicesStatusUtil
.
updateClientMsg
(
statusBean
.
getCid
(),
mergeM
sgList
);
}
// //判断是否刚刚上线
// 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
());
/**
* 已解除的报警信息存到数据库中
...
...
src/main/java/com/neotel/smfcore/core/system/util/DevicesStatusUtil.java
查看文件 @
10f6f03
...
...
@@ -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!
Cancel
请
注册
或
登录
后发表评论