Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
黄嘉阳
/
iot-platform-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
32e634b0
authored
Dec 01, 2023
by
huangjy
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
feat: 误报推送IOT
parent
794f18da
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
56 additions
and
8 deletions
saas-module/src/main/java/com/makeit/controller/device/SaasDeviceController.java
server-common/src/main/java/com/makeit/module/iot/service/IotCommonService.java
server-common/src/main/java/com/makeit/module/iot/service/IotDevicePropertiesOperateService.java
server-service/src/main/java/com/makeit/entity/platform/device/PlatDeviceLog.java
server-service/src/main/java/com/makeit/service/platform/alarm/impl/PlatAlarmRecordServiceImpl.java
server-service/src/main/java/com/makeit/service/platform/device/PlatDeviceService.java
server-service/src/main/java/com/makeit/service/platform/device/impl/PlatDeviceServiceImpl.java
server-web/src/main/resources/application-dev.yml
server-web/src/main/resources/application-test.yml
saas-module/src/main/java/com/makeit/controller/device/SaasDeviceController.java
View file @
32e634b0
...
@@ -26,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -26,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.List
;
@Api
(
tags
=
"租户管理-租户设备管理"
)
@Api
(
tags
=
"租户管理-租户设备管理"
)
...
@@ -121,8 +122,8 @@ public class SaasDeviceController {
...
@@ -121,8 +122,8 @@ public class SaasDeviceController {
@PostMapping
(
"devicePushLog"
)
@PostMapping
(
"devicePushLog"
)
@TenantIdIgnore
@TenantIdIgnore
@AuthIgnore
@AuthIgnore
public
ApiResponseEntity
devicePushLog
(
@RequestParam
(
value
=
"
file
"
,
required
=
false
)
MultipartFile
multipartFile
,
public
ApiResponseEntity
devicePushLog
(
@RequestParam
(
value
=
"
rawData
"
,
required
=
false
)
MultipartFile
multipartFile
,
@RequestParam
(
value
=
"deviceId"
)
String
deviceId
)
{
@RequestParam
(
value
=
"deviceId"
)
String
deviceId
)
throws
IOException
{
platDeviceService
.
devicePushLog
(
multipartFile
,
deviceId
);
platDeviceService
.
devicePushLog
(
multipartFile
,
deviceId
);
return
ApiResponseUtils
.
success
();
return
ApiResponseUtils
.
success
();
}
}
...
...
server-common/src/main/java/com/makeit/module/iot/service/IotCommonService.java
View file @
32e634b0
...
@@ -31,6 +31,8 @@ public class IotCommonService {
...
@@ -31,6 +31,8 @@ public class IotCommonService {
@Value
(
"${iot.url:}"
)
@Value
(
"${iot.url:}"
)
public
String
iotUrl
;
public
String
iotUrl
;
@Value
(
"${iot.uploadUrl:}"
)
public
String
uploadUrl
;
protected
static
HttpClient
httpClient
=
HttpClientBuilder
.
create
().
build
();
protected
static
HttpClient
httpClient
=
HttpClientBuilder
.
create
().
build
();
...
...
server-common/src/main/java/com/makeit/module/iot/service/IotDevicePropertiesOperateService.java
View file @
32e634b0
...
@@ -101,4 +101,26 @@ public class IotDevicePropertiesOperateService extends IotCommonService {
...
@@ -101,4 +101,26 @@ public class IotDevicePropertiesOperateService extends IotCommonService {
}
}
return
""
;
return
""
;
}
}
public
String
deviceFunctionAttr
(
String
deviceId
,
Long
timestamp
)
{
String
url
=
iotUrl
+
"device/invoked/"
+
deviceId
+
"/function/misinformation"
;
Map
<
String
,
Map
<
String
,
Object
>>
map
=
Maps
.
newHashMap
();
Map
<
String
,
Object
>
reqMap
=
Maps
.
newHashMap
();
reqMap
.
put
(
"timestamp"
,
timestamp
);
reqMap
.
put
(
"url"
,
uploadUrl
);
map
.
put
(
"misinformationNotify"
,
reqMap
);
HttpRequest
request
=
buildRequest
(
url
,
JSON
.
toJSONString
(
map
));
try
{
ResponseMessage
responseMessage
=
sendPut
(
url
,
request
);
log
.
info
(
"发送误报通知到设备返回信息:{}"
,
responseMessage
.
getMessage
());
if
(
responseMessage
.
getStatus
()
!=
200
)
{
String
errorMsg
=
responseMessage
.
getMessage
();
log
.
error
(
"发送误报通知失败:{}"
,
errorMsg
);
return
errorMsg
;
}
}
catch
(
IOException
e
)
{
log
.
error
(
"调用:{}接口异常:{}"
,
url
,
e
.
getMessage
());
}
return
""
;
}
}
}
server-service/src/main/java/com/makeit/entity/platform/device/PlatDeviceLog.java
View file @
32e634b0
...
@@ -36,6 +36,8 @@ public class PlatDeviceLog extends BaseBusEntity {
...
@@ -36,6 +36,8 @@ public class PlatDeviceLog extends BaseBusEntity {
@ApiModelProperty
(
value
=
"日志url"
)
@ApiModelProperty
(
value
=
"日志url"
)
private
String
url
;
private
String
url
;
@ApiModelProperty
(
value
=
"文件名称"
)
private
String
fileName
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
...
...
server-service/src/main/java/com/makeit/service/platform/alarm/impl/PlatAlarmRecordServiceImpl.java
View file @
32e634b0
...
@@ -31,6 +31,7 @@ import com.makeit.enums.CommonEnum;
...
@@ -31,6 +31,7 @@ import com.makeit.enums.CommonEnum;
import
com.makeit.exception.BusinessException
;
import
com.makeit.exception.BusinessException
;
import
com.makeit.global.aspect.tenant.TenantIdIgnore
;
import
com.makeit.global.aspect.tenant.TenantIdIgnore
;
import
com.makeit.mapper.platform.alarm.PlatAlarmRecordMapper
;
import
com.makeit.mapper.platform.alarm.PlatAlarmRecordMapper
;
import
com.makeit.module.iot.service.IotDevicePropertiesOperateService
;
import
com.makeit.service.platform.alarm.PlatAlarmConfigService
;
import
com.makeit.service.platform.alarm.PlatAlarmConfigService
;
import
com.makeit.service.platform.alarm.PlatAlarmRecordService
;
import
com.makeit.service.platform.alarm.PlatAlarmRecordService
;
import
com.makeit.service.platform.auth.PlatOrgService
;
import
com.makeit.service.platform.auth.PlatOrgService
;
...
@@ -66,6 +67,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
...
@@ -66,6 +67,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.sql.Timestamp
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.DateTimeFormatter
;
import
java.util.*
;
import
java.util.*
;
...
@@ -111,9 +113,9 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
...
@@ -111,9 +113,9 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
@Autowired
@Autowired
private
PlatDeviceService
platDeviceService
;
private
PlatDeviceService
platDeviceService
;
@Autowired
@Autowired
private
ShengwangProperties
shengwangProperties
;
@Autowired
private
ShengwangService
shengwangService
;
private
ShengwangService
shengwangService
;
@Autowired
private
IotDevicePropertiesOperateService
iotDevicePropertiesOperateService
;
@Override
@Override
...
@@ -581,7 +583,13 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
...
@@ -581,7 +583,13 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
platAlarmRecord
.
setDealUser
(
user
.
getName
());
platAlarmRecord
.
setDealUser
(
user
.
getName
());
updateById
(
platAlarmRecord
);
updateById
(
platAlarmRecord
);
// todo 误报结果写入设备
String
deviceId
=
platAlarmRecord
.
getDeviceId
();
PlatDevice
platDevice
=
platDeviceService
.
getById
(
deviceId
);
if
(
platDevice
==
null
)
{
throw
new
RuntimeException
(
"找不到告警关联的设备,设备已解绑"
+
deviceId
);
}
Timestamp
timestamp
=
Timestamp
.
valueOf
(
platAlarmRecord
.
getCreateDate
());
iotDevicePropertiesOperateService
.
deviceFunctionAttr
(
platDevice
.
getOriDeviceId
(),
timestamp
.
getTime
());
}
}
@Override
@Override
...
...
server-service/src/main/java/com/makeit/service/platform/device/PlatDeviceService.java
View file @
32e634b0
...
@@ -18,6 +18,7 @@ import com.makeit.vo.platform.device.PlatDeviceListVO;
...
@@ -18,6 +18,7 @@ import com.makeit.vo.platform.device.PlatDeviceListVO;
import
com.makeit.vo.platform.device.PlatDeviceViewVO
;
import
com.makeit.vo.platform.device.PlatDeviceViewVO
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -90,5 +91,5 @@ public interface PlatDeviceService extends IService<PlatDevice> {
...
@@ -90,5 +91,5 @@ public interface PlatDeviceService extends IService<PlatDevice> {
PlatAlarmCallDeviceVO
callingDevice
(
PlatCallingDeviceDTO
dto
);
PlatAlarmCallDeviceVO
callingDevice
(
PlatCallingDeviceDTO
dto
);
void
devicePushLog
(
MultipartFile
multipartFile
,
String
deviceId
);
void
devicePushLog
(
MultipartFile
multipartFile
,
String
deviceId
)
throws
IOException
;
}
}
server-service/src/main/java/com/makeit/service/platform/device/impl/PlatDeviceServiceImpl.java
View file @
32e634b0
...
@@ -3,6 +3,7 @@ package com.makeit.service.platform.device.impl;
...
@@ -3,6 +3,7 @@ package com.makeit.service.platform.device.impl;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.date.DatePattern
;
import
cn.hutool.core.date.DatePattern
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.crypto.SecureUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
...
@@ -81,6 +82,7 @@ import org.springframework.stereotype.Service;
...
@@ -81,6 +82,7 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.IOException
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.time.ZoneOffset
;
import
java.time.ZoneOffset
;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.DateTimeFormatter
;
...
@@ -870,20 +872,28 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
...
@@ -870,20 +872,28 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
}
}
@Override
@Override
public
void
devicePushLog
(
MultipartFile
multipartFile
,
String
deviceId
)
{
public
void
devicePushLog
(
MultipartFile
file
,
String
deviceId
)
throws
IOException
{
log
.
info
(
"接受到设备上传的文件,设备id:{}"
,
deviceId
);
log
.
info
(
"接受到设备上传的文件,设备id:{}"
,
deviceId
);
String
uploadPath
=
DateUtil
.
format
(
new
Date
(),
DatePattern
.
PURE_DATE_FORMAT
);
String
uploadPath
=
DateUtil
.
format
(
new
Date
(),
DatePattern
.
PURE_DATE_FORMAT
);
String
url
=
aliyunOSSRepository
.
save
(
multipartFile
,
deviceId
,
multipartFile
.
getOriginalFilename
());
String
name
=
file
.
getOriginalFilename
();
String
md5
=
SecureUtil
.
md5
(
file
.
getInputStream
()).
substring
(
8
,
24
);
String
type
=
name
.
substring
(
name
.
lastIndexOf
(
"."
));
String
fileName
=
md5
+
type
;
String
url
=
aliyunOSSRepository
.
save
(
file
,
uploadPath
,
fileName
);
PlatDevice
platDevice
=
getOne
(
new
QueryWrapper
<
PlatDevice
>().
lambda
().
eq
(
PlatDevice:
:
getOriDeviceId
,
deviceId
)
PlatDevice
platDevice
=
getOne
(
new
QueryWrapper
<
PlatDevice
>().
lambda
().
eq
(
PlatDevice:
:
getOriDeviceId
,
deviceId
)
.
orderByDesc
(
BaseEntity:
:
getCreateDate
)
.
orderByDesc
(
BaseEntity:
:
getCreateDate
)
.
last
(
"limit 1"
));
.
last
(
"limit 1"
));
if
(
platDevice
==
null
)
{
throw
new
RuntimeException
(
"找不到设备id:"
+
deviceId
);
}
PlatDeviceLog
platDeviceLog
=
new
PlatDeviceLog
();
PlatDeviceLog
platDeviceLog
=
new
PlatDeviceLog
();
platDeviceLog
.
setDeviceId
(
deviceId
);
platDeviceLog
.
setDeviceId
(
deviceId
);
platDeviceLog
.
setProductName
(
platDevice
.
getProductName
());
platDeviceLog
.
setProductName
(
platDevice
.
getProductName
());
platDeviceLog
.
setType
(
"1"
);
platDeviceLog
.
setType
(
"1"
);
platDeviceLog
.
setTenantId
(
platDevice
.
getTenantId
());
platDeviceLog
.
setTenantId
(
platDevice
.
getTenantId
());
platDeviceLog
.
setUrl
(
url
);
platDeviceLog
.
setUrl
(
url
);
platDeviceLog
.
setFileName
(
name
);
platDeviceLogService
.
save
(
platDeviceLog
);
platDeviceLogService
.
save
(
platDeviceLog
);
}
}
}
}
server-web/src/main/resources/application-dev.yml
View file @
32e634b0
...
@@ -114,6 +114,7 @@ libreOffice: C:\\Program Files\\LibreOffice\\program\\soffice
...
@@ -114,6 +114,7 @@ libreOffice: C:\\Program Files\\LibreOffice\\program\\soffice
iot
:
iot
:
url
:
https://iot.qa.insightica.cn/api/
url
:
https://iot.qa.insightica.cn/api/
uploadUrl
:
https://saas.qa.insightica.cn/api/saas/device/devicePushLog
clientId
:
fyxmb5h52iKwE2Hi
clientId
:
fyxmb5h52iKwE2Hi
secureKey
:
22fZbnH36wdHn7ZTyKKHraFw233npcez
secureKey
:
22fZbnH36wdHn7ZTyKKHraFw233npcez
sync
:
sync
:
...
...
server-web/src/main/resources/application-test.yml
View file @
32e634b0
...
@@ -105,6 +105,7 @@ libreOffice: /home/group1_lzy/iot-server/LibreOffice/program/soffice
...
@@ -105,6 +105,7 @@ libreOffice: /home/group1_lzy/iot-server/LibreOffice/program/soffice
iot
:
iot
:
url
:
https://iot.qa.insightica.cn/api/
url
:
https://iot.qa.insightica.cn/api/
uploadUrl
:
https://saas.qa.insightica.cn/api/saas/device/devicePushLog
clientId
:
fyxmb5h52iKwE2Hi
clientId
:
fyxmb5h52iKwE2Hi
secureKey
:
22fZbnH36wdHn7ZTyKKHraFw233npcez
secureKey
:
22fZbnH36wdHn7ZTyKKHraFw233npcez
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment