Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
谢明辉
/
fanxing3-integration
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 2e054773
authored
Apr 25, 2022
by
毛树良
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
<feat>:增加同步设备给星河
1 parent
91c2fb98
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
242 additions
and
0 deletions
fanxing-integration-jiaoguansuo/src/main/java/com/viontech/integration/jiaoguansuo/config/RestTemplateConfig.java
fanxing-integration-jiaoguansuo/src/main/java/com/viontech/integration/jiaoguansuo/controller/MainController.java
fanxing-integration-jiaoguansuo/src/main/java/com/viontech/integration/jiaoguansuo/model/DeviceDO.java
fanxing-integration-jiaoguansuo/src/main/java/com/viontech/integration/jiaoguansuo/service/MainService.java
fanxing-integration-jiaoguansuo/src/main/java/com/viontech/integration/jiaoguansuo/service/XingheDeviceService.java
fanxing-integration-jiaoguansuo/src/main/resources/application.yml
fanxing-integration-jiaoguansuo/src/main/java/com/viontech/integration/jiaoguansuo/config/RestTemplateConfig.java
0 → 100644
View file @
2e05477
package
com
.
viontech
.
integration
.
jiaoguansuo
.
config
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.client.ClientHttpRequestFactory
;
import
org.springframework.http.client.SimpleClientHttpRequestFactory
;
import
org.springframework.web.client.RestTemplate
;
@Configuration
public
class
RestTemplateConfig
{
@Bean
public
RestTemplate
restTemplate
(
ClientHttpRequestFactory
factory
)
{
return
new
RestTemplate
(
factory
);
}
@Bean
public
ClientHttpRequestFactory
simpleClientHttpRequestFactory
()
{
SimpleClientHttpRequestFactory
factory
=
new
SimpleClientHttpRequestFactory
();
factory
.
setReadTimeout
(
60000
);
//ms
factory
.
setConnectTimeout
(
20000
);
//ms
return
factory
;
}
}
fanxing-integration-jiaoguansuo/src/main/java/com/viontech/integration/jiaoguansuo/controller/MainController.java
View file @
2e05477
...
@@ -10,6 +10,7 @@ import com.viontech.integration.jiaoguansuo.entity.Code;
...
@@ -10,6 +10,7 @@ import com.viontech.integration.jiaoguansuo.entity.Code;
import
com.viontech.integration.jiaoguansuo.entity.Message
;
import
com.viontech.integration.jiaoguansuo.entity.Message
;
import
com.viontech.integration.jiaoguansuo.entity.VideoEntity
;
import
com.viontech.integration.jiaoguansuo.entity.VideoEntity
;
import
com.viontech.integration.jiaoguansuo.service.MainService
;
import
com.viontech.integration.jiaoguansuo.service.MainService
;
import
com.viontech.integration.jiaoguansuo.service.XingheDeviceService
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
...
@@ -30,6 +31,8 @@ public class MainController {
...
@@ -30,6 +31,8 @@ public class MainController {
@Resource
@Resource
private
MainService
mainService
;
private
MainService
mainService
;
@Resource
private
XingheDeviceService
xingheDeviceService
;
/**
/**
* 1. 添加对应视频信息
* 1. 添加对应视频信息
...
@@ -65,6 +68,7 @@ public class MainController {
...
@@ -65,6 +68,7 @@ public class MainController {
mainService
.
removeTask
(
task
.
getId
());
mainService
.
removeTask
(
task
.
getId
());
}
}
mainService
.
removeChannel
(
channel
.
getId
());
mainService
.
removeChannel
(
channel
.
getId
());
xingheDeviceService
.
deleteDevice
(
videoEntity
);
throw
e
;
throw
e
;
}
}
return
Message
.
success
();
return
Message
.
success
();
...
@@ -104,6 +108,7 @@ public class MainController {
...
@@ -104,6 +108,7 @@ public class MainController {
}
}
mainService
.
removeChannel
(
channel
.
getId
());
mainService
.
removeChannel
(
channel
.
getId
());
xingheDeviceService
.
deleteDevice
(
videoEntity
);
}
}
return
Message
.
success
();
return
Message
.
success
();
}
}
...
...
fanxing-integration-jiaoguansuo/src/main/java/com/viontech/integration/jiaoguansuo/model/DeviceDO.java
0 → 100644
View file @
2e05477
package
com
.
viontech
.
integration
.
jiaoguansuo
.
model
;
import
lombok.Getter
;
import
lombok.Setter
;
import
java.util.Date
;
@Getter
@Setter
public
class
DeviceDO
{
private
Integer
id
;
//设备编号
private
String
sbbh
;
//设备名称
private
String
sbmc
;
//设备ip
private
String
sbip
;
//设备mac地址
private
String
sbmac
;
//所属监控点id
private
Integer
jkdId
;
//设备厂家
private
String
sbcj
;
//设备类型
private
String
sblx
;
//是否球机
private
Integer
sfqj
;
//设备端口号
private
Integer
sbdkh
;
//设备协议
private
String
sbxy
;
//设备流地址
private
String
sbldz
;
//设备用户名
private
String
sbyhm
;
//设备密码
private
String
sbmm
;
//设备软件版本
private
String
sbrjbb
;
//设备硬件版本
private
String
sbyjbb
;
//设备状态
private
Integer
sbzt
;
//设备经度
private
String
sbjd
;
//设备纬度
private
String
sbwd
;
//是否删除
private
Integer
sfsc
;
private
String
unionId
;
//集指备案号
private
String
jzbah
;
@Deprecated
private
String
wbId
;
private
Date
createTime
;
private
Date
modifyTime
;
/**是否巡检*/
private
Short
sfxj
;
/**项目id*/
private
Integer
projectId
;
//设备巡检编号
private
String
sbxjbh
;
/**电表户号*/
private
String
dbhh
;
/**排序号*/
private
Integer
pxbh
;
/**光纤通信地址*/
private
String
gxtxdz
;
/**组织id*/
private
Integer
orgId
;
/**离线时间*/
private
Date
lxsj
;
/**运维单位*/
private
String
ywdw
;
}
\ No newline at end of file
\ No newline at end of file
fanxing-integration-jiaoguansuo/src/main/java/com/viontech/integration/jiaoguansuo/service/MainService.java
View file @
2e05477
...
@@ -38,6 +38,8 @@ public class MainService {
...
@@ -38,6 +38,8 @@ public class MainService {
private
OpsClient
opsClient
;
private
OpsClient
opsClient
;
@Value
(
"${vion.storage-config-id}"
)
@Value
(
"${vion.storage-config-id}"
)
private
Long
storageConfigId
;
private
Long
storageConfigId
;
@Resource
private
XingheDeviceService
xingheDeviceService
;
public
List
<
Channel
>
getChannels
(
Channel
channel
)
{
public
List
<
Channel
>
getChannels
(
Channel
channel
)
{
JsonMessageUtil
.
JsonMessage
<
List
<
Channel
>>
channels
=
opsClient
.
getChannels
(
channel
);
JsonMessageUtil
.
JsonMessage
<
List
<
Channel
>>
channels
=
opsClient
.
getChannels
(
channel
);
...
@@ -68,6 +70,8 @@ public class MainService {
...
@@ -68,6 +70,8 @@ public class MainService {
channel
.
setType
(
ChannelType
.
MANUALLY
.
value
);
channel
.
setType
(
ChannelType
.
MANUALLY
.
value
);
JsonMessageUtil
.
JsonMessage
<
Channel
>
add
=
opsClient
.
add
(
channel
);
JsonMessageUtil
.
JsonMessage
<
Channel
>
add
=
opsClient
.
add
(
channel
);
if
(
add
.
isSuccess
())
{
if
(
add
.
isSuccess
())
{
//星河平台同步新增设备
xingheDeviceService
.
addDevice
(
addVideo
);
return
add
.
getData
();
return
add
.
getData
();
}
else
{
}
else
{
throw
new
RuntimeException
(
add
.
getMsg
());
throw
new
RuntimeException
(
add
.
getMsg
());
...
...
fanxing-integration-jiaoguansuo/src/main/java/com/viontech/integration/jiaoguansuo/service/XingheDeviceService.java
0 → 100644
View file @
2e05477
package
com
.
viontech
.
integration
.
jiaoguansuo
.
service
;
import
com.alibaba.fastjson.JSON
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.viontech.integration.jiaoguansuo.entity.VideoEntity
;
import
com.viontech.integration.jiaoguansuo.model.DeviceDO
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.*
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.RestTemplate
;
import
javax.annotation.Resource
;
import
java.net.URLDecoder
;
import
java.util.List
;
import
java.util.Map
;
/**
* msl
* 星河平台:设备服务
*/
@Service
@Slf4j
public
class
XingheDeviceService
{
@Value
(
"${xinghe.device.syncSwitch:0}"
)
private
String
deviceSyncSwitch
;
@Value
(
"${xinghe.device.addUrl:}"
)
private
String
deviceAddUrl
;
@Value
(
"${xinghe.device.delUrl:}"
)
private
String
deviceDelUrl
;
@Value
(
"${xinghe.device.queryUrl:}"
)
private
String
deviceQueryUrl
;
@Resource
private
RestTemplate
restTemplate
;
@Autowired
private
ObjectMapper
objectMapper
;
/**
* 添加设备
*
* @param addVideo
*/
public
DeviceDO
addDevice
(
VideoEntity
addVideo
)
{
if
(!
"1"
.
equals
(
deviceSyncSwitch
))
{
return
null
;
}
if
(
StringUtils
.
isBlank
(
deviceAddUrl
))
{
log
.
warn
(
"deviceAddUrl is null"
);
return
null
;
}
DeviceDO
deviceDO
=
new
DeviceDO
();
try
{
deviceDO
.
setSbcj
(
"02"
);
deviceDO
.
setJkdId
(
0
);
deviceDO
.
setSbmc
(
"无锡所ADD"
);
deviceDO
.
setSbip
(
"0.0.0.0"
);
deviceDO
.
setSbbh
(
addVideo
.
getSxjbh
());
deviceDO
.
setSbldz
(
addVideo
.
getJkdz
());
log
.
info
(
"addDevice.data={}"
,
JSON
.
toJSONString
(
deviceDO
));
//保存设备信息
HttpHeaders
headers
=
new
HttpHeaders
();
MediaType
type
=
MediaType
.
parseMediaType
(
"application/json; charset=UTF-8"
);
headers
.
setContentType
(
type
);
HttpEntity
<
DeviceDO
>
httpEntity
=
new
HttpEntity
<>(
deviceDO
,
headers
);
ResponseEntity
<
Map
>
resEntity
=
restTemplate
.
exchange
(
deviceAddUrl
,
HttpMethod
.
PUT
,
httpEntity
,
Map
.
class
);
log
.
info
(
"addDevice.result={}"
,
JSON
.
toJSONString
(
resEntity
.
getBody
()));
}
catch
(
Exception
e
)
{
log
.
error
(
"addDevice.Exception"
,
e
);
}
return
deviceDO
;
}
/**
* 删除设备
*
* @param delVideo
*/
public
void
deleteDevice
(
VideoEntity
delVideo
)
{
if
(!
"1"
.
equals
(
deviceSyncSwitch
))
{
return
;
}
if
(
StringUtils
.
isBlank
(
delVideo
.
getSxjbh
()))
{
log
.
warn
(
"sxjbh is null"
);
return
;
}
if
(
StringUtils
.
isBlank
(
deviceQueryUrl
)
||
StringUtils
.
isBlank
(
deviceDelUrl
))
{
log
.
warn
(
"deviceQueryUrl,deviceDelUrl is null"
);
return
;
}
//查询出设备
Integer
deviceId
=
null
;
try
{
String
requestUrl
=
deviceQueryUrl
+
"?pageSize=50&pageNum=1&sbbh="
+
delVideo
.
getSxjbh
();
ResponseEntity
<
String
>
responseEntity
=
restTemplate
.
getForEntity
(
URLDecoder
.
decode
(
requestUrl
,
"UTF-8"
),
String
.
class
);
Map
resultMap
=
objectMapper
.
readValue
(
responseEntity
.
getBody
(),
Map
.
class
);
if
(
resultMap
.
containsKey
(
"data"
)
&&
resultMap
.
get
(
"data"
)
!=
null
)
{
Map
map
=
(
Map
)
resultMap
.
get
(
"data"
);
if
(
map
.
get
(
"list"
)
!=
null
)
{
List
<
Map
>
mapList
=
(
List
<
Map
>)
map
.
get
(
"list"
);
for
(
Map
deviceMap
:
mapList
)
{
if
(
delVideo
.
getSxjbh
().
equals
(
deviceMap
.
get
(
"sbbh"
)))
{
deviceId
=
(
Integer
)
deviceMap
.
get
(
"id"
);
break
;
}
}
}
}
log
.
info
(
"deleteDevice.id={}"
,
deviceId
);
if
(
deviceId
==
null
||
deviceId
<=
0
)
{
return
;
}
//删除设备信息
String
delUrl
=
String
.
format
(
deviceDelUrl
,
deviceId
+
""
);
restTemplate
.
delete
(
delUrl
);
log
.
info
(
"deleteDevice.id={},success"
,
deviceId
);
}
catch
(
Exception
e
)
{
log
.
error
(
"deleteDevice.Exception"
,
e
);
}
return
;
}
}
fanxing-integration-jiaoguansuo/src/main/resources/application.yml
View file @
2e05477
...
@@ -39,3 +39,9 @@ logging:
...
@@ -39,3 +39,9 @@ logging:
config
:
classpath:logback-${spring.profiles.active}.xml
config
:
classpath:logback-${spring.profiles.active}.xml
vion
:
vion
:
storage-config-id
:
17
storage-config-id
:
17
xinghe
:
device
:
syncSwitch
:
1
addUrl
:
http://127.0.0.1:8001/device
delUrl
:
http://127.0.0.1:8001/device/%s
queryUrl
:
http://127.0.0.1:8001/device/select
\ No newline at end of file
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment