Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
smf-core
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 4d907fdc
由
LN
编写于
2023-03-29 18:12:15 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
麦康尼料仓离线时不发任务。备份数据库增加判断条件。
1 个父辈
e6019de3
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
85 行增加
和
3 行删除
src/main/java/com/neotel/smfcore/common/config/mongodb/MongoDbConfig.java
src/main/java/com/neotel/smfcore/common/utils/NetwrokUtils.java
src/main/java/com/neotel/smfcore/core/device/bean/StatusBean.java
src/main/java/com/neotel/smfcore/core/device/enums/BOX_STATUS.java
src/main/java/com/neotel/smfcore/core/system/util/DevicesStatusUtil.java
src/main/java/com/neotel/smfcore/common/config/mongodb/MongoDbConfig.java
查看文件 @
4d907fd
...
@@ -7,7 +7,9 @@ import com.mongodb.client.MongoClients;
...
@@ -7,7 +7,9 @@ import com.mongodb.client.MongoClients;
import
com.mongodb.connection.ClusterConnectionMode
;
import
com.mongodb.connection.ClusterConnectionMode
;
import
com.mongodb.connection.ClusterType
;
import
com.mongodb.connection.ClusterType
;
import
com.neotel.smfcore.common.config.mongodb.bean.CustomMongoProperties
;
import
com.neotel.smfcore.common.config.mongodb.bean.CustomMongoProperties
;
import
com.neotel.smfcore.common.utils.NetwrokUtils
;
import
com.neotel.smfcore.common.utils.StringUtils
;
import
com.neotel.smfcore.common.utils.StringUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
...
@@ -22,6 +24,7 @@ import java.util.ArrayList;
...
@@ -22,6 +24,7 @@ import java.util.ArrayList;
import
java.util.List
;
import
java.util.List
;
@Configuration
@Configuration
@Slf4j
public
class
MongoDbConfig
{
public
class
MongoDbConfig
{
private
static
final
String
NO_HOST
=
"none"
;
private
static
final
String
NO_HOST
=
"none"
;
private
static
final
Integer
NO_PORT
=
0
;
private
static
final
Integer
NO_PORT
=
0
;
...
@@ -48,11 +51,31 @@ public class MongoDbConfig {
...
@@ -48,11 +51,31 @@ public class MongoDbConfig {
@Bean
(
name
=
"backUpMongoTemplate"
)
@Bean
(
name
=
"backUpMongoTemplate"
)
public
MongoTemplate
backUpMongoTemplate
(
@Qualifier
(
"backUpMongoProperties"
)
CustomMongoProperties
mongoProperties
)
{
public
MongoTemplate
backUpMongoTemplate
(
@Qualifier
(
"backUpMongoProperties"
)
CustomMongoProperties
mongoProperties
)
{
//如果配置的备份为本机,不需要备份
List
<
String
>
ipList
=
NetwrokUtils
.
getIpList
();
String
baseDatabase
=
masterMongoProperties
().
getDatabase
();
//如果没有配置的话,则模板返回为空
//如果没有配置的话,则模板返回为空
if
(
StringUtils
.
isBlank
(
mongoProperties
.
getHost
()))
{
if
(
StringUtils
.
isBlank
(
mongoProperties
.
getHost
()))
{
mongoProperties
.
setHost
(
NO_HOST
);
mongoProperties
.
setHost
(
NO_HOST
);
mongoProperties
.
setPort
(
NO_PORT
);
mongoProperties
.
setPort
(
NO_PORT
);
mongoProperties
.
setDatabase
(
NO_DATABASE
);
mongoProperties
.
setDatabase
(
NO_DATABASE
);
log
.
warn
(
"backUpMongoTemplate no Config"
);
}
else
if
(
ipList
.
contains
(
mongoProperties
.
getHost
())
&&
mongoProperties
.
getDatabase
().
equals
(
baseDatabase
))
{
log
.
warn
(
"backUpMongoTemplate 不可用,配置的是本机: ip["
+
mongoProperties
.
getHost
()
+
"] db ["
+
mongoProperties
.
getDatabase
()
+
"] baseDb["
+
baseDatabase
+
"] "
);
mongoProperties
.
setHost
(
NO_HOST
);
mongoProperties
.
setPort
(
NO_PORT
);
mongoProperties
.
setDatabase
(
NO_DATABASE
);
}
//如果配置的IP 不通,也不需要备份
else
if
(!
NetwrokUtils
.
pingIPAddress
(
mongoProperties
.
getHost
()))
{
log
.
warn
(
"backUpMongoTemplate 不可用,地址ping不通 ip["
+
mongoProperties
.
getHost
()
+
"] "
);
mongoProperties
.
setHost
(
NO_HOST
);
mongoProperties
.
setPort
(
NO_PORT
);
mongoProperties
.
setDatabase
(
NO_DATABASE
);
}
else
{
log
.
info
(
"backUpMongoTemplate 可用:ip["
+
mongoProperties
.
getHost
()
+
"] db ["
+
mongoProperties
.
getDatabase
()
+
"] "
);
}
}
return
new
MongoTemplate
(
mongoDbFactory
(
mongoProperties
));
return
new
MongoTemplate
(
mongoDbFactory
(
mongoProperties
));
}
}
...
...
src/main/java/com/neotel/smfcore/common/utils/NetwrokUtils.java
0 → 100644
查看文件 @
4d907fd
package
com
.
neotel
.
smfcore
.
common
.
utils
;
import
lombok.extern.slf4j.Slf4j
;
import
java.io.IOException
;
import
java.net.InetAddress
;
import
java.net.NetworkInterface
;
import
java.net.SocketException
;
import
java.util.ArrayList
;
import
java.util.Enumeration
;
import
java.util.List
;
@Slf4j
public
class
NetwrokUtils
{
public
static
List
<
String
>
getIpList
()
{
List
<
String
>
ipList
=
new
ArrayList
<>();
try
{
Enumeration
<
NetworkInterface
>
allNetInterfaces
=
NetworkInterface
.
getNetworkInterfaces
();
InetAddress
ip
=
null
;
while
(
allNetInterfaces
.
hasMoreElements
())
{
NetworkInterface
netInterface
=
(
NetworkInterface
)
allNetInterfaces
.
nextElement
();
if
(
netInterface
.
isLoopback
()
||
netInterface
.
isVirtual
()
||
!
netInterface
.
isUp
())
{
continue
;
}
else
{
Enumeration
<
InetAddress
>
addresses
=
netInterface
.
getInetAddresses
();
while
(
addresses
.
hasMoreElements
())
{
ip
=
addresses
.
nextElement
();
if
(
ip
!=
null
&&
ip
.
getHostAddress
().
indexOf
(
":"
)
==
-
1
)
{
log
.
info
(
"获取到本机IP地址:"
+
ip
.
getHostAddress
());
ipList
.
add
(
ip
.
getHostAddress
());
}
}
}
}
}
catch
(
SocketException
e
)
{
e
.
printStackTrace
();
}
return
ipList
;
}
public
static
boolean
pingIPAddress
(
String
ipAddress
)
{
try
{
InetAddress
inet
=
InetAddress
.
getByName
(
ipAddress
);
boolean
status
=
inet
.
isReachable
(
2000
);
// 判断是否能够ping通,超时时间为5秒
if
(
status
)
{
log
.
info
(
ipAddress
+
" is reachable."
);
return
true
;
}
else
{
log
.
info
(
ipAddress
+
" is not reachable."
);
}
}
catch
(
IOException
e
)
{
log
.
info
(
"pingIPAddress "
+
ipAddress
+
" error :"
+
e
.
toString
());
}
return
false
;
}
}
src/main/java/com/neotel/smfcore/core/device/bean/StatusBean.java
查看文件 @
4d907fd
...
@@ -421,8 +421,8 @@ public class StatusBean {
...
@@ -421,8 +421,8 @@ public class StatusBean {
// }
// }
public
boolean
isAvailable
(){
public
boolean
isAvailable
(){
if
(!
timeOut
()){
if
(!
timeOut
())
{
return
status
!=
BOX_STATUS
.
EMERGENCY
&&
status
!=
BOX_STATUS
.
PROBLEM
&&
status
!=
BOX_STATUS
.
DEBUG
;
return
status
!=
BOX_STATUS
.
OFFLINE
&&
status
!=
BOX_STATUS
.
EMERGENCY
&&
status
!=
BOX_STATUS
.
PROBLEM
&&
status
!=
BOX_STATUS
.
DEBUG
;
}
}
return
false
;
return
false
;
}
}
...
...
src/main/java/com/neotel/smfcore/core/device/enums/BOX_STATUS.java
查看文件 @
4d907fd
...
@@ -4,6 +4,7 @@ package com.neotel.smfcore.core.device.enums;
...
@@ -4,6 +4,7 @@ package com.neotel.smfcore.core.device.enums;
* Created by sunke on 2021/7/13.
* Created by sunke on 2021/7/13.
*/
*/
public
class
BOX_STATUS
{
public
class
BOX_STATUS
{
public
final
static
int
OFFLINE
=
0
;
/**
/**
* 1=准备就绪
* 1=准备就绪
*/
*/
...
...
src/main/java/com/neotel/smfcore/core/system/util/DevicesStatusUtil.java
查看文件 @
4d907fd
...
@@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil;
...
@@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil;
import
com.google.common.collect.Maps
;
import
com.google.common.collect.Maps
;
import
com.neotel.smfcore.common.utils.SecurityUtils
;
import
com.neotel.smfcore.common.utils.SecurityUtils
;
import
com.neotel.smfcore.core.device.bean.StatusBean
;
import
com.neotel.smfcore.core.device.bean.StatusBean
;
import
com.neotel.smfcore.core.device.enums.BOX_STATUS
;
import
com.neotel.smfcore.core.message.enums.MessageType
;
import
com.neotel.smfcore.core.message.enums.MessageType
;
import
com.neotel.smfcore.core.message.util.DeviceMessageUtil
;
import
com.neotel.smfcore.core.message.util.DeviceMessageUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
@@ -211,7 +212,7 @@ public class DevicesStatusUtil {
...
@@ -211,7 +212,7 @@ public class DevicesStatusUtil {
cids
)
{
cids
)
{
StatusBean
bean
=
getStatusBean
(
cid
);
StatusBean
bean
=
getStatusBean
(
cid
);
if
(
bean
!=
null
)
{
if
(
bean
!=
null
)
{
if
(
bean
.
getOfflineTime
()
==
-
1
&&
bean
.
timeOut
(
))
{
if
(
bean
.
getOfflineTime
()
==
-
1
&&
(
bean
.
timeOut
()||
bean
.
getStatus
()==
BOX_STATUS
.
OFFLINE
))
{
bean
.
setOfflineTime
(
System
.
currentTimeMillis
());
bean
.
setOfflineTime
(
System
.
currentTimeMillis
());
DeviceMessageUtil
.
addOfflineMessage
(
bean
.
getCid
(),
""
);
DeviceMessageUtil
.
addOfflineMessage
(
bean
.
getCid
(),
""
);
}
}
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论