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 ca1b1cdb
authored
Mar 22, 2021
by
周海宝
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'dev' into 'master'
Dev See merge request
!4
2 parents
d106981f
f9f48f50
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
81 deletions
src/main/java/cn/com/glsx/modules/controller/DeviceController.java
src/main/java/cn/com/glsx/modules/controller/UserController.java
src/main/java/cn/com/glsx/modules/model/param/ResponseBody.java
src/main/java/cn/com/glsx/modules/service/DeviceService.java
src/main/java/cn/com/glsx/modules/service/UserService.java
src/main/java/cn/com/glsx/modules/controller/DeviceController.java
View file @
ca1b1cd
package
cn
.
com
.
glsx
.
modules
.
controller
;
package
cn
.
com
.
glsx
.
modules
.
controller
;
import
cn.com.glsx.common.BussinessFactory.BussinessFactory
;
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.service.DeviceService
;
import
cn.com.glsx.modules.service.DeviceService
;
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
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
...
@@ -17,7 +15,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
...
@@ -17,7 +15,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
java.util.List
;
/**
/**
* @author zhouhaibao
* @author zhouhaibao
...
@@ -39,9 +36,8 @@ public class DeviceController {
...
@@ -39,9 +36,8 @@ public class DeviceController {
@RequestMapping
(
value
=
"/{uid}/devices"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/{uid}/devices"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
@ResponseBody
@ApiOperation
(
value
=
"获取用户下的设备列表"
)
@ApiOperation
(
value
=
"获取用户下的设备列表"
)
public
R
getAllDevicesByUser
(
@PathVariable
String
uid
){
public
R
getAllDevicesByUser
(
@PathVariable
String
uid
)
{
List
<
DeviceInfo
>
list
=
deviceService
.
getAllDevicesByUser
(
uid
);
return
deviceService
.
getAllDevicesByUser
(
uid
);
return
R
.
ok
(
JSONObject
.
toJSONString
(
list
));
}
}
/**
/**
...
@@ -52,9 +48,8 @@ public class DeviceController {
...
@@ -52,9 +48,8 @@ public class DeviceController {
@RequestMapping
(
value
=
"/devices/{device_id}"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/devices/{device_id}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
@ResponseBody
@ApiOperation
(
value
=
"根据id获取设备"
)
@ApiOperation
(
value
=
"根据id获取设备"
)
public
R
getDevicesById
(
@PathVariable
String
device_id
){
public
R
getDevicesById
(
@PathVariable
String
device_id
)
{
DeviceInfo
deviceInfo
=
deviceService
.
getDevicesById
(
device_id
);
return
deviceService
.
getDevicesById
(
device_id
);
return
R
.
ok
(
JSONObject
.
toJSONString
(
deviceInfo
));
}
}
...
@@ -66,9 +61,8 @@ public class DeviceController {
...
@@ -66,9 +61,8 @@ public class DeviceController {
@RequestMapping
(
value
=
"/devices/{device_id}/functions"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/devices/{device_id}/functions"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
@ResponseBody
@ApiOperation
(
value
=
"根据id获取指令集"
)
@ApiOperation
(
value
=
"根据id获取指令集"
)
public
R
getFunctionsById
(
@PathVariable
String
device_id
){
public
R
getFunctionsById
(
@PathVariable
String
device_id
)
{
Function
function
=
deviceService
.
getFunctionsById
(
device_id
);
return
deviceService
.
getFunctionsById
(
device_id
);
return
R
.
ok
(
JSONObject
.
toJSONString
(
function
));
}
}
/**
/**
...
@@ -79,9 +73,8 @@ public class DeviceController {
...
@@ -79,9 +73,8 @@ public class DeviceController {
@RequestMapping
(
value
=
"/functions/{category}"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/functions/{category}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
@ResponseBody
@ApiOperation
(
value
=
"根据品类获取指令集"
)
@ApiOperation
(
value
=
"根据品类获取指令集"
)
public
R
getFunctionsByCat
(
@PathVariable
String
category
){
public
R
getFunctionsByCat
(
@PathVariable
String
category
)
{
Function
function
=
deviceService
.
getFunctionsByCat
(
category
);
return
deviceService
.
getFunctionsByCat
(
category
);
return
R
.
ok
(
JSONObject
.
toJSONString
(
function
));
}
}
/**
/**
...
@@ -92,8 +85,7 @@ public class DeviceController {
...
@@ -92,8 +85,7 @@ public class DeviceController {
@RequestMapping
(
value
=
"/devices/{device_id}/commands"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/devices/{device_id}/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
,
@RequestBody
String
insjson
)
{
String
message
=
deviceService
.
instructionIssue
(
device_id
,
insjson
);
return
deviceService
.
instructionIssue
(
device_id
,
insjson
);
return
R
.
ok
(
JSONObject
.
toJSONString
(
message
));
}
}
}
}
src/main/java/cn/com/glsx/modules/controller/UserController.java
View file @
ca1b1cd
...
@@ -36,11 +36,7 @@ public class UserController {
...
@@ -36,11 +36,7 @@ public class UserController {
@ResponseBody
@ResponseBody
@ApiOperation
(
value
=
"注册用户"
)
@ApiOperation
(
value
=
"注册用户"
)
public
R
registerUser
(
@RequestBody
UserBo
userBo
)
{
public
R
registerUser
(
@RequestBody
UserBo
userBo
)
{
String
uid
=
userService
.
registerUser
(
userBo
);
return
userService
.
registerUser
(
userBo
);
if
(
StringUtils
.
isNotBlank
(
uid
)){
return
R
.
ok
(
uid
);
}
return
R
.
error
();
}
}
...
@@ -54,7 +50,6 @@ public class UserController {
...
@@ -54,7 +50,6 @@ public class UserController {
@ResponseBody
@ResponseBody
@ApiOperation
(
value
=
"查询用户"
)
@ApiOperation
(
value
=
"查询用户"
)
public
R
getUserInfo
(
@PathVariable
String
id
)
{
public
R
getUserInfo
(
@PathVariable
String
id
)
{
UserInfo
userInfo
=
userService
.
getUserInfo
(
id
);
return
userService
.
getUserInfo
(
id
);
return
R
.
ok
(
JSONObject
.
toJSONString
(
userInfo
));
}
}
}
}
src/main/java/cn/com/glsx/modules/model/param/ResponseBody.java
View file @
ca1b1cd
...
@@ -26,4 +26,6 @@ public class ResponseBody {
...
@@ -26,4 +26,6 @@ public class ResponseBody {
* 返回message
* 返回message
*/
*/
private
String
message
;
private
String
message
;
private
String
msg
;
}
}
src/main/java/cn/com/glsx/modules/service/DeviceService.java
View file @
ca1b1cd
package
cn
.
com
.
glsx
.
modules
.
service
;
package
cn
.
com
.
glsx
.
modules
.
service
;
import
cn.com.glsx.modules.model.param.DeviceInfo
;
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
cn.com.glsx.modules.service.abs.BaseDeviceService
;
import
com.glsx.plat.core.web.R
;
import
com.alibaba.fastjson.JSONObject
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
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
;
import
java.util.List
;
/**
/**
* @author zhouhaibao
* @author zhouhaibao
* @date 2021/3/5 10:17
* @date 2021/3/5 10:17
*/
*/
@Service
@Service
@Slf4j
@Slf4j
public
class
DeviceService
extends
BaseDeviceService
{
public
class
DeviceService
{
@Value
(
"${tuya.getAllDevicesByUserUrl}"
)
@Value
(
"${tuya.getAllDevicesByUserUrl}"
)
private
String
getAllDevicesByUserUrl
;
private
String
getAllDevicesByUserUrl
;
...
@@ -38,68 +33,53 @@ public class DeviceService extends BaseDeviceService {
...
@@ -38,68 +33,53 @@ public class DeviceService extends BaseDeviceService {
@Autowired
@Autowired
private
SendRequestService
sendRequestService
;
private
SendRequestService
sendRequestService
;
@Override
public
R
getAllDevicesByUser
(
String
uid
)
{
public
List
<
DeviceInfo
>
getAllDevicesByUser
(
String
uid
)
{
List
<
DeviceInfo
>
userInfo
=
null
;
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getAllDevicesByUserUrl
.
replace
(
"{uid}"
,
uid
));
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getAllDevicesByUserUrl
.
replace
(
"{uid}"
,
uid
));
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
String
result
=
responseBody
.
getResult
();
String
result
=
responseBody
.
getResult
();
userInfo
=
JSONObject
.
parseArray
(
result
,
DeviceInfo
.
class
);
return
R
.
ok
(
result
);
}
else
{
log
.
info
(
"调用涂鸦获取用户设备接口失败"
);
}
}
return
userInfo
;
String
errorMessage
=
responseBody
==
null
?
"调用涂鸦失败"
:
responseBody
.
getMessage
();
return
R
.
error
(
errorMessage
);
}
}
@Override
public
R
getDevicesById
(
String
device_id
)
{
public
DeviceInfo
getDevicesById
(
String
device_id
)
{
DeviceInfo
deviceInfo
=
null
;
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getDevicesByIdUrl
.
replace
(
"{device_id}"
,
device_id
));
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getDevicesByIdUrl
.
replace
(
"{device_id}"
,
device_id
));
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
String
result
=
responseBody
.
getResult
();
String
result
=
responseBody
.
getResult
();
deviceInfo
=
JSONObject
.
parseObject
(
result
,
DeviceInfo
.
class
);
return
R
.
ok
(
result
);
}
else
{
log
.
info
(
"调用涂鸦获取设备接口失败"
);
}
}
return
deviceInfo
;
String
errorMessage
=
responseBody
==
null
?
"调用涂鸦失败"
:
responseBody
.
getMessage
();
return
R
.
error
(
errorMessage
);
}
}
@Override
public
R
getFunctionsById
(
String
device_id
)
{
public
Function
getFunctionsById
(
String
device_id
)
{
Function
function
=
null
;
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getFunctionsByIdUrl
.
replace
(
"{device_id}"
,
device_id
));
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getFunctionsByIdUrl
.
replace
(
"{device_id}"
,
device_id
));
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
String
result
=
responseBody
.
getResult
();
String
result
=
responseBody
.
getResult
();
function
=
JSONObject
.
parseObject
(
result
,
Function
.
class
);
return
R
.
ok
(
result
);
}
else
{
log
.
info
(
"调用涂鸦获取用户设备接口失败"
);
}
}
return
function
;
String
errorMessage
=
responseBody
==
null
?
"调用涂鸦失败"
:
responseBody
.
getMessage
();
return
R
.
error
(
errorMessage
);
}
}
@Override
public
R
getFunctionsByCat
(
String
category
)
{
public
Function
getFunctionsByCat
(
String
category
)
{
Function
function
=
null
;
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getFunctionsByCatUrl
.
replace
(
"{category}"
,
category
));
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getFunctionsByCatUrl
.
replace
(
"{category}"
,
category
));
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
String
result
=
responseBody
.
getResult
();
String
result
=
responseBody
.
getResult
();
function
=
JSONObject
.
parseObject
(
result
,
Function
.
class
);
return
R
.
ok
(
result
);
}
else
{
log
.
info
(
"调用涂鸦获取用户设备接口失败"
);
}
}
return
function
;
String
errorMessage
=
responseBody
==
null
?
"调用涂鸦失败"
:
responseBody
.
getMessage
();
return
R
.
error
(
errorMessage
);
}
}
@Override
public
R
instructionIssue
(
String
device_id
,
String
insjson
)
{
public
String
instructionIssue
(
String
device_id
,
String
insjson
)
{
String
message
=
null
;
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
())
{
message
=
"下发成功"
;
return
R
.
ok
();
}
else
{
message
=
"下发失败"
;
}
}
return
message
;
String
errorMessage
=
responseBody
==
null
?
"调用涂鸦失败"
:
responseBody
.
getMessage
();
return
R
.
error
(
errorMessage
);
}
}
}
}
src/main/java/cn/com/glsx/modules/service/UserService.java
View file @
ca1b1cd
...
@@ -4,7 +4,9 @@ import cn.com.glsx.modules.model.param.ResponseBody;
...
@@ -4,7 +4,9 @@ import cn.com.glsx.modules.model.param.ResponseBody;
import
cn.com.glsx.modules.model.param.UserBo
;
import
cn.com.glsx.modules.model.param.UserBo
;
import
cn.com.glsx.modules.model.param.UserInfo
;
import
cn.com.glsx.modules.model.param.UserInfo
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.glsx.plat.core.web.R
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
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
;
...
@@ -32,19 +34,15 @@ public class UserService {
...
@@ -32,19 +34,15 @@ public class UserService {
*
*
* @param userBo 用户
* @param userBo 用户
*/
*/
public
String
registerUser
(
UserBo
userBo
)
{
public
R
registerUser
(
UserBo
userBo
)
{
//获取令牌
//获取令牌
String
uid
=
null
;
ResponseBody
responseBody
=
sendRequestService
.
sendRequestPost
(
registerUserUrl
,
JSONObject
.
toJSONString
(
userBo
));
ResponseBody
responseBody
=
sendRequestService
.
sendRequestPost
(
registerUserUrl
,
JSONObject
.
toJSONString
(
userBo
));
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
String
result
=
responseBody
.
getResult
();
String
result
=
responseBody
.
getResult
();
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
result
);
return
R
.
ok
(
result
);
uid
=
jsonObject
.
getString
(
"uid"
);
}
else
{
log
.
info
(
"调用涂鸦失败"
);
}
}
String
errorMessage
=
responseBody
==
null
?
"调用涂鸦失败"
:
responseBody
.
getMessage
();
return
uid
;
return
R
.
error
(
errorMessage
)
;
}
}
/**
/**
...
@@ -52,16 +50,14 @@ public class UserService {
...
@@ -52,16 +50,14 @@ public class UserService {
*
*
* @param id 用户 ID
* @param id 用户 ID
*/
*/
public
UserInfo
getUserInfo
(
String
id
)
{
public
R
getUserInfo
(
String
id
)
{
UserInfo
userInfo
=
null
;
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getUserInfoUrl
.
replace
(
"{uid}"
,
id
));
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getUserInfoUrl
.
replace
(
"{uid}"
,
id
));
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
String
result
=
responseBody
.
getResult
()
+
""
;
String
result
=
responseBody
.
getResult
()
+
""
;
userInfo
=
JSONObject
.
parseObject
(
result
,
UserInfo
.
class
);
return
R
.
ok
(
result
);
}
else
{
log
.
info
(
"调用涂鸦用户信息接口失败"
);
}
}
return
userInfo
;
String
errorMessage
=
responseBody
==
null
?
"调用涂鸦失败"
:
responseBody
.
getMessage
();
return
R
.
error
(
errorMessage
);
}
}
}
}
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