Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
open-source
/
smartDevices-platform-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 e7131a35
authored
Apr 25, 2021
by
111-PC\111
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]aqara代码提交
1 parent
48c9a321
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
66 additions
and
27 deletions
src/main/java/cn/com/glsx/common/ResultEnum.java
src/main/java/cn/com/glsx/modules/controller/AqaraDeviceController.java
src/main/java/cn/com/glsx/modules/controller/DeviceController.java
src/main/java/cn/com/glsx/modules/service/AqaraDeviceService.java
src/main/java/cn/com/glsx/modules/service/DeviceService.java
src/main/java/cn/com/glsx/modules/service/abs/BaseDeviceService.java
src/main/java/cn/com/glsx/common/ResultEnum.java
0 → 100644
View file @
e7131a3
package
cn
.
com
.
glsx
.
common
;
/**
* <p>Description:
* <p>Project: chejia-smart
*
* @author wbh
* @date 2021-03-16
*/
public
enum
ResultEnum
{
SUCCESS
(
200
,
"成功"
),
ERROR
(
500
,
"系统异常"
),
PARAM_ERROR
(
1001
,
"参数错误"
),
ID_NOT_FOUND
(
1002
,
"ID不存在"
);
private
final
Integer
code
;
private
final
String
message
;
ResultEnum
(
Integer
code
,
String
message
)
{
this
.
code
=
code
;
this
.
message
=
message
;
}
public
Integer
getCode
()
{
return
code
;
}
public
String
getMessage
()
{
return
message
;
}
}
src/main/java/cn/com/glsx/modules/controller/AqaraDeviceController.java
View file @
e7131a3
...
@@ -27,21 +27,21 @@ public class AqaraDeviceController {
...
@@ -27,21 +27,21 @@ public class AqaraDeviceController {
@RequestMapping
(
value
=
"/bindKeyGet"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/bindKeyGet"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
@ResponseBody
@ApiOperation
(
value
=
"获取bindKey"
)
@ApiOperation
(
value
=
"获取bindKey"
)
public
R
bindKeyGet
(
@RequestParam
(
required
=
false
)
String
username
){
public
R
bindKeyGet
(
@RequestParam
(
required
=
false
)
String
token
){
return
aqaraDeviceService
.
bindKeyGet
(
username
);
return
aqaraDeviceService
.
bindKeyGet
(
token
);
}
}
@RequestMapping
(
value
=
"/instructionIssue"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/instructionIssue"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
@ResponseBody
@ApiOperation
(
value
=
"下发指令"
)
@ApiOperation
(
value
=
"下发指令"
)
public
R
instructionIssue
(
@RequestBody
String
data
,
@RequestParam
(
required
=
false
)
String
username
){
public
R
instructionIssue
(
@RequestBody
String
data
,
@RequestParam
(
required
=
false
)
String
token
){
return
aqaraDeviceService
.
instructionIssue
(
data
,
username
);
return
aqaraDeviceService
.
instructionIssue
(
data
,
token
);
}
}
@RequestMapping
(
value
=
"/subscriber"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/subscriber"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
@ResponseBody
@ApiOperation
(
value
=
"订阅资源"
)
@ApiOperation
(
value
=
"订阅资源"
)
public
R
subscriber
(
@RequestBody
String
data
,
@RequestParam
(
required
=
false
)
String
username
){
public
R
subscriber
(
@RequestBody
String
data
,
@RequestParam
(
required
=
false
)
String
token
){
return
aqaraDeviceService
.
subscriber
(
data
,
username
);
return
aqaraDeviceService
.
subscriber
(
data
,
token
);
}
}
}
}
src/main/java/cn/com/glsx/modules/controller/DeviceController.java
View file @
e7131a3
package
cn
.
com
.
glsx
.
modules
.
controller
;
package
cn
.
com
.
glsx
.
modules
.
controller
;
import
cn.com.glsx.common.BussinessFactory.BussinessFactory
;
import
cn.com.glsx.modules.service.DeviceService
;
import
cn.com.glsx.modules.service.DeviceService
;
import
cn.com.glsx.modules.service.abs.BaseDeviceService
;
import
com.glsx.plat.core.web.R
;
import
com.glsx.plat.core.web.R
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
...
@@ -81,11 +83,12 @@ public class DeviceController {
...
@@ -81,11 +83,12 @@ public class DeviceController {
*
*
* @return R
* @return R
*/
*/
@RequestMapping
(
value
=
"/devices/{device_id}/commands"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/devices/{device_id}/
{resource}/
commands"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
@ResponseBody
@ApiOperation
(
value
=
"根据设备下发指令"
)
@ApiOperation
(
value
=
"根据设备下发指令"
)
public
R
instructionIssue
(
@PathVariable
String
device_id
,
@RequestBody
String
insjson
)
{
public
R
instructionIssue
(
@PathVariable
String
device_id
,
@PathVariable
String
resource
,
@RequestBody
String
insjson
)
{
return
deviceService
.
instructionIssue
(
device_id
,
insjson
);
BaseDeviceService
instance
=
BussinessFactory
.
getInstance
(
resource
,
BaseDeviceService
.
class
);
return
instance
.
instructionIssue
(
device_id
,
insjson
);
}
}
/**
/**
...
...
src/main/java/cn/com/glsx/modules/service/AqaraDeviceService.java
View file @
e7131a3
package
cn
.
com
.
glsx
.
modules
.
service
;
package
cn
.
com
.
glsx
.
modules
.
service
;
import
cn.com.glsx.common.Constants
;
import
cn.com.glsx.common.Constants
;
import
cn.com.glsx.common.ResultEnum
;
import
cn.com.glsx.common.redis.RedisService
;
import
cn.com.glsx.common.redis.RedisService
;
import
cn.com.glsx.modules.service.abs.BaseDeviceService
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.glsx.plat.core.web.R
;
import
com.glsx.plat.core.web.R
;
import
com.lumi.opencloud.common.AiotConfig
;
import
com.lumi.opencloud.common.AiotConfig
;
...
@@ -27,7 +29,7 @@ import java.util.Map;
...
@@ -27,7 +29,7 @@ import java.util.Map;
*/
*/
@Slf4j
@Slf4j
@Service
@Service
public
class
AqaraDeviceService
{
public
class
AqaraDeviceService
extends
BaseDeviceService
{
@Value
(
"${aqara.clientId}"
)
@Value
(
"${aqara.clientId}"
)
private
String
clientId
;
private
String
clientId
;
...
@@ -44,11 +46,13 @@ public class AqaraDeviceService {
...
@@ -44,11 +46,13 @@ public class AqaraDeviceService {
/**
/**
* 获取bindKey接口
* 获取bindKey接口
*
*
* @param
username
入参
* @param
token
入参
* @return
* @return
*/
*/
public
R
bindKeyGet
(
String
username
)
{
public
R
bindKeyGet
(
String
token
)
{
String
token
=
aqaraTokenService
.
getToken
(
username
);
if
(
StringUtils
.
isEmpty
(
token
)){
R
.
error
(
ResultEnum
.
PARAM_ERROR
.
getCode
(),
ResultEnum
.
PARAM_ERROR
.
getMessage
());
}
DeviceBindGetRequest
deviceBindGetRequest
=
new
DeviceBindGetRequest
();
DeviceBindGetRequest
deviceBindGetRequest
=
new
DeviceBindGetRequest
();
R
home
=
homeService
.
getHome
(
token
);
R
home
=
homeService
.
getHome
(
token
);
if
(
home
.
isSuccess
())
{
if
(
home
.
isSuccess
())
{
...
@@ -69,8 +73,11 @@ public class AqaraDeviceService {
...
@@ -69,8 +73,11 @@ public class AqaraDeviceService {
return
R
.
error
(
responseMsg
.
getMessage
());
return
R
.
error
(
responseMsg
.
getMessage
());
}
}
public
R
instructionIssue
(
String
data
,
String
username
)
{
@Override
String
token
=
aqaraTokenService
.
getToken
(
username
);
public
R
instructionIssue
(
String
token
,
String
data
)
{
if
(
StringUtils
.
isEmpty
(
token
)){
R
.
error
(
ResultEnum
.
PARAM_ERROR
.
getCode
(),
ResultEnum
.
PARAM_ERROR
.
getMessage
());
}
ResourceUpdateRequest
resourceUpdateRequest
=
JSONObject
.
parseObject
(
data
,
ResourceUpdateRequest
.
class
);
ResourceUpdateRequest
resourceUpdateRequest
=
JSONObject
.
parseObject
(
data
,
ResourceUpdateRequest
.
class
);
ResponseMsg
responseMsg
=
ResourceManager
.
update
(
new
AiotConfig
(
clientId
,
null
,
token
,
null
,
domain
),
resourceUpdateRequest
);
ResponseMsg
responseMsg
=
ResourceManager
.
update
(
new
AiotConfig
(
clientId
,
null
,
token
,
null
,
domain
),
resourceUpdateRequest
);
if
(
responseMsg
!=
null
&&
Constants
.
AQARA_RETURN_SUCCESS_CODE
==
responseMsg
.
getCode
())
{
if
(
responseMsg
!=
null
&&
Constants
.
AQARA_RETURN_SUCCESS_CODE
==
responseMsg
.
getCode
())
{
...
@@ -79,8 +86,10 @@ public class AqaraDeviceService {
...
@@ -79,8 +86,10 @@ public class AqaraDeviceService {
return
R
.
error
(
responseMsg
.
getMessage
());
return
R
.
error
(
responseMsg
.
getMessage
());
}
}
public
R
subscriber
(
String
data
,
String
username
)
{
public
R
subscriber
(
String
data
,
String
token
)
{
String
token
=
aqaraTokenService
.
getToken
(
username
);
if
(
StringUtils
.
isEmpty
(
token
)){
R
.
error
(
ResultEnum
.
PARAM_ERROR
.
getCode
(),
ResultEnum
.
PARAM_ERROR
.
getMessage
());
}
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
data
);
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
data
);
List
<
ResourceSubscribeInfo
>
resourceSubscribeInfos
=
JSONObject
.
parseArray
(
jsonObject
.
getString
(
"data"
),
ResourceSubscribeInfo
.
class
);
List
<
ResourceSubscribeInfo
>
resourceSubscribeInfos
=
JSONObject
.
parseArray
(
jsonObject
.
getString
(
"data"
),
ResourceSubscribeInfo
.
class
);
ResponseMsg
responseMsg
=
ResourceManager
.
subscriber
(
new
AiotConfig
(
clientId
,
null
,
token
,
null
,
domain
),
resourceSubscribeInfos
);
ResponseMsg
responseMsg
=
ResourceManager
.
subscriber
(
new
AiotConfig
(
clientId
,
null
,
token
,
null
,
domain
),
resourceSubscribeInfos
);
...
...
src/main/java/cn/com/glsx/modules/service/DeviceService.java
View file @
e7131a3
...
@@ -2,6 +2,7 @@ package cn.com.glsx.modules.service;
...
@@ -2,6 +2,7 @@ package cn.com.glsx.modules.service;
import
cn.com.glsx.common.DeviceErrorEnum
;
import
cn.com.glsx.common.DeviceErrorEnum
;
import
cn.com.glsx.modules.model.param.ResponseBody
;
import
cn.com.glsx.modules.model.param.ResponseBody
;
import
cn.com.glsx.modules.service.abs.BaseDeviceService
;
import
com.glsx.plat.core.web.R
;
import
com.glsx.plat.core.web.R
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -14,7 +15,7 @@ import org.springframework.stereotype.Service;
...
@@ -14,7 +15,7 @@ import org.springframework.stereotype.Service;
*/
*/
@Service
@Service
@Slf4j
@Slf4j
public
class
DeviceService
{
public
class
DeviceService
extends
BaseDeviceService
{
@Value
(
"${tuya.getAllDevicesByUserUrl}"
)
@Value
(
"${tuya.getAllDevicesByUserUrl}"
)
private
String
getAllDevicesByUserUrl
;
private
String
getAllDevicesByUserUrl
;
...
@@ -85,6 +86,7 @@ public class DeviceService {
...
@@ -85,6 +86,7 @@ public class DeviceService {
return
R
.
error
(
errorMessage
);
return
R
.
error
(
errorMessage
);
}
}
@Override
public
R
instructionIssue
(
String
device_id
,
String
insjson
)
{
public
R
instructionIssue
(
String
device_id
,
String
insjson
)
{
ResponseBody
responseBody
=
sendRequestService
.
sendRequestPost
(
instructionIssue
.
replace
(
"{device_id}"
,
device_id
),
insjson
);
ResponseBody
responseBody
=
sendRequestService
.
sendRequestPost
(
instructionIssue
.
replace
(
"{device_id}"
,
device_id
),
insjson
);
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
...
...
src/main/java/cn/com/glsx/modules/service/abs/BaseDeviceService.java
View file @
e7131a3
...
@@ -3,6 +3,7 @@ package cn.com.glsx.modules.service.abs;
...
@@ -3,6 +3,7 @@ package cn.com.glsx.modules.service.abs;
import
cn.com.glsx.modules.model.param.DeviceInfo
;
import
cn.com.glsx.modules.model.param.DeviceInfo
;
import
cn.com.glsx.modules.model.param.Function
;
import
cn.com.glsx.modules.model.param.Function
;
import
cn.com.glsx.modules.model.param.ResponseBody
;
import
cn.com.glsx.modules.model.param.ResponseBody
;
import
com.glsx.plat.core.web.R
;
import
java.util.List
;
import
java.util.List
;
...
@@ -12,13 +13,5 @@ import java.util.List;
...
@@ -12,13 +13,5 @@ import java.util.List;
*/
*/
public
abstract
class
BaseDeviceService
{
public
abstract
class
BaseDeviceService
{
public
abstract
List
<
DeviceInfo
>
getAllDevicesByUser
(
String
uid
);
public
abstract
R
instructionIssue
(
String
device_id
,
String
insjson
);
public
abstract
DeviceInfo
getDevicesById
(
String
deviveid
);
public
abstract
Function
getFunctionsById
(
String
uid
);
public
abstract
Function
getFunctionsByCat
(
String
cat
);
public
abstract
String
instructionIssue
(
String
device_id
,
String
insjson
);
}
}
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