Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
open-source
/
chejia-smart-service
This project
Loading...
Sign in
Toggle navigation
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 2b28194e
authored
Apr 26, 2021
by
tyfanchz
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
订阅用户设备功能
1 parent
a1df91e7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
0 deletions
src/main/java/com/glsx/smart/exception/ResultEnum.java
src/main/java/com/glsx/smart/service/impl/SmartUserDeviceServiceImpl.java
src/main/java/com/glsx/smart/exception/ResultEnum.java
View file @
2b28194
...
@@ -24,6 +24,7 @@ public enum ResultEnum {
...
@@ -24,6 +24,7 @@ public enum ResultEnum {
DEVICE_NOT_FOUND
(
4001
,
"设备信息不存在"
),
DEVICE_NOT_FOUND
(
4001
,
"设备信息不存在"
),
USER_NOT_FOUND
(
5001
,
"用户信息不存在"
),
USER_NOT_FOUND
(
5001
,
"用户信息不存在"
),
DEVICE_SUBSCRIBE_ERROR
(
5002
,
"用户设备订阅失败"
),
ENCRYPT_EXCEP_1
(
1101
,
"crep加密异常,无法插入"
),
ENCRYPT_EXCEP_1
(
1101
,
"crep加密异常,无法插入"
),
ENCRYPT_EXCEP_2
(
1102
,
"crep加密异常,无法返回钥匙信息"
),
ENCRYPT_EXCEP_2
(
1102
,
"crep加密异常,无法返回钥匙信息"
),
...
...
src/main/java/com/glsx/smart/service/impl/SmartUserDeviceServiceImpl.java
View file @
2b28194
...
@@ -8,15 +8,21 @@ import com.alibaba.fastjson.JSON;
...
@@ -8,15 +8,21 @@ import com.alibaba.fastjson.JSON;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.glsx.plat.common.utils.HttpUtils
;
import
com.glsx.plat.common.utils.HttpUtils
;
import
com.glsx.plat.common.utils.StringUtils
;
import
com.glsx.plat.common.utils.StringUtils
;
import
com.glsx.smart.constant.Constants
;
import
com.glsx.smart.dao.entity.SmartUserChannel
;
import
com.glsx.smart.dao.entity.SmartUserChannel
;
import
com.glsx.smart.dao.entity.SmartUserDevice
;
import
com.glsx.smart.dao.entity.SmartUserDevice
;
import
com.glsx.smart.dao.entity.SmartUserRelation
;
import
com.glsx.smart.dao.mapper.SmartProductMapper
;
import
com.glsx.smart.dao.mapper.SmartUserChannelMapper
;
import
com.glsx.smart.dao.mapper.SmartUserChannelMapper
;
import
com.glsx.smart.dao.mapper.SmartUserDeviceMapper
;
import
com.glsx.smart.dao.mapper.SmartUserDeviceMapper
;
import
com.glsx.smart.dao.mapper.SmartUserRelationMapper
;
import
com.glsx.smart.exception.BusinessException
;
import
com.glsx.smart.exception.BusinessException
;
import
com.glsx.smart.exception.ResultEnum
;
import
com.glsx.smart.exception.ResultEnum
;
import
com.glsx.smart.redis.RedisService
;
import
com.glsx.smart.service.BaseService
;
import
com.glsx.smart.service.BaseService
;
import
com.glsx.smart.service.SmartUserDeviceService
;
import
com.glsx.smart.service.SmartUserDeviceService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -39,12 +45,24 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
...
@@ -39,12 +45,24 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
@Value
(
"${user_send_command}"
)
@Value
(
"${user_send_command}"
)
private
String
userSendCommandApi
;
private
String
userSendCommandApi
;
@Value
(
"${user_device_subscribe}"
)
private
String
userDeviceSubscribeApi
;
@Resource
@Resource
private
SmartUserDeviceMapper
userDeviceMapper
;
private
SmartUserDeviceMapper
userDeviceMapper
;
@Resource
@Resource
private
SmartUserRelationMapper
userRelationMapper
;
@Resource
private
SmartUserChannelMapper
userChannelMapper
;
private
SmartUserChannelMapper
userChannelMapper
;
@Resource
private
SmartProductMapper
productMapper
;
@Autowired
private
RedisService
redisService
;
@Override
@Override
public
List
<
SmartUserDevice
>
getList
(
SmartUserDevice
req
)
{
public
List
<
SmartUserDevice
>
getList
(
SmartUserDevice
req
)
{
return
userDeviceMapper
.
getList
(
req
);
return
userDeviceMapper
.
getList
(
req
);
...
@@ -82,6 +100,7 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
...
@@ -82,6 +100,7 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
req
.
setCreateTime
(
now
);
req
.
setCreateTime
(
now
);
req
.
setUpdateTime
(
now
);
req
.
setUpdateTime
(
now
);
rows
=
userDeviceMapper
.
insertSelective
(
req
);
rows
=
userDeviceMapper
.
insertSelective
(
req
);
this
.
subscribeDevice
(
req
);
}
else
{
}
else
{
if
(
StringUtils
.
isBlank
(
req
.
getDeviceName
()))
{
if
(
StringUtils
.
isBlank
(
req
.
getDeviceName
()))
{
throw
BusinessException
.
create
(
ResultEnum
.
PARAM_EMPTY
,
"deviceName"
);
throw
BusinessException
.
create
(
ResultEnum
.
PARAM_EMPTY
,
"deviceName"
);
...
@@ -125,4 +144,36 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
...
@@ -125,4 +144,36 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
?
respObj
.
getString
(
"result"
)
:
null
;
?
respObj
.
getString
(
"result"
)
:
null
;
return
result
;
return
result
;
}
}
/**
* 订阅用户设备
*
* @param req 请求
*/
private
void
subscribeDevice
(
SmartUserDevice
req
)
{
if
(
Constants
.
USER_CHANNEL_AQARA
.
equals
(
req
.
getChannel
()))
{
// 只有绿米的设备需要订阅
if
(
StringUtils
.
isBlank
(
req
.
getPlatformProductId
()))
{
throw
BusinessException
.
create
(
ResultEnum
.
PARAM_EMPTY
,
"platformProductId"
);
}
SmartUserRelation
userRelation
=
userRelationMapper
.
selectByPrimaryKey
(
req
.
getUserId
());
String
phone
=
userRelation
.
getPhone
();
String
token
=
(
String
)
redisService
.
get
(
phone
+
"_aqara"
);
List
<
String
>
commands
=
productMapper
.
getSupportedCommands
(
req
.
getPlatformProductId
());
JSONObject
reqData
=
new
JSONObject
();
reqData
.
put
(
"did"
,
req
.
getDeviceId
());
reqData
.
put
(
"attrs"
,
commands
);
JSONObject
reqObj
=
new
JSONObject
();
reqObj
.
put
(
"data"
,
reqData
);
reqObj
.
put
(
"token"
,
token
);
String
url
=
remoteUrl
+
userDeviceSubscribeApi
;
log
.
info
(
"$$$$ subscribeDevice url = {}, req = {}"
,
url
,
reqObj
.
toJSONString
());
String
respJson
=
HttpUtils
.
post
(
url
,
reqObj
.
toJSONString
());
log
.
info
(
"$$$$ subscribeDevice resp = {}"
,
respJson
);
JSONObject
respObj
=
JSON
.
parseObject
(
respJson
);
if
(!
"200"
.
equals
(
respObj
.
getString
(
"code"
)))
{
throw
BusinessException
.
create
(
ResultEnum
.
DEVICE_SUBSCRIBE_ERROR
);
}
}
}
}
}
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