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 00b222e9
authored
Mar 22, 2021
by
111-PC\111
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]代码整改
1 parent
2cc9d4c6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
71 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/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 @
00b222e
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.Function
;
import
cn.com.glsx.modules.service.DeviceService
;
import
cn.com.glsx.modules.service.abs.BaseDeviceService
;
import
com.alibaba.fastjson.JSONObject
;
import
com.glsx.plat.core.web.R
;
import
io.swagger.annotations.Api
;
...
...
@@ -17,7 +15,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
java.util.List
;
/**
* @author zhouhaibao
...
...
@@ -40,8 +37,7 @@ public class DeviceController {
@ResponseBody
@ApiOperation
(
value
=
"获取用户下的设备列表"
)
public
R
getAllDevicesByUser
(
@PathVariable
String
uid
)
{
List
<
DeviceInfo
>
list
=
deviceService
.
getAllDevicesByUser
(
uid
);
return
R
.
ok
(
JSONObject
.
toJSONString
(
list
));
return
deviceService
.
getAllDevicesByUser
(
uid
);
}
/**
...
...
@@ -53,8 +49,7 @@ public class DeviceController {
@ResponseBody
@ApiOperation
(
value
=
"根据id获取设备"
)
public
R
getDevicesById
(
@PathVariable
String
device_id
)
{
DeviceInfo
deviceInfo
=
deviceService
.
getDevicesById
(
device_id
);
return
R
.
ok
(
JSONObject
.
toJSONString
(
deviceInfo
));
return
deviceService
.
getDevicesById
(
device_id
);
}
...
...
@@ -67,8 +62,7 @@ public class DeviceController {
@ResponseBody
@ApiOperation
(
value
=
"根据id获取指令集"
)
public
R
getFunctionsById
(
@PathVariable
String
device_id
)
{
Function
function
=
deviceService
.
getFunctionsById
(
device_id
);
return
R
.
ok
(
JSONObject
.
toJSONString
(
function
));
return
deviceService
.
getFunctionsById
(
device_id
);
}
/**
...
...
@@ -80,8 +74,7 @@ public class DeviceController {
@ResponseBody
@ApiOperation
(
value
=
"根据品类获取指令集"
)
public
R
getFunctionsByCat
(
@PathVariable
String
category
)
{
Function
function
=
deviceService
.
getFunctionsByCat
(
category
);
return
R
.
ok
(
JSONObject
.
toJSONString
(
function
));
return
deviceService
.
getFunctionsByCat
(
category
);
}
/**
...
...
@@ -93,10 +86,6 @@ public class DeviceController {
@ResponseBody
@ApiOperation
(
value
=
"根据设备下发指令"
)
public
R
instructionIssue
(
@PathVariable
String
device_id
,
@RequestBody
String
insjson
)
{
String
message
=
deviceService
.
instructionIssue
(
device_id
,
insjson
);
if
((
"下发成功"
).
equals
(
message
))
{
return
R
.
ok
(
message
);
}
return
R
.
error
(
message
);
return
deviceService
.
instructionIssue
(
device_id
,
insjson
);
}
}
src/main/java/cn/com/glsx/modules/controller/UserController.java
View file @
00b222e
...
...
@@ -36,11 +36,7 @@ public class UserController {
@ResponseBody
@ApiOperation
(
value
=
"注册用户"
)
public
R
registerUser
(
@RequestBody
UserBo
userBo
)
{
String
uid
=
userService
.
registerUser
(
userBo
);
if
(
StringUtils
.
isNotBlank
(
uid
)){
return
R
.
ok
(
uid
);
}
return
R
.
error
();
return
userService
.
registerUser
(
userBo
);
}
...
...
@@ -54,7 +50,6 @@ public class UserController {
@ResponseBody
@ApiOperation
(
value
=
"查询用户"
)
public
R
getUserInfo
(
@PathVariable
String
id
)
{
UserInfo
userInfo
=
userService
.
getUserInfo
(
id
);
return
R
.
ok
(
JSONObject
.
toJSONString
(
userInfo
));
return
userService
.
getUserInfo
(
id
);
}
}
src/main/java/cn/com/glsx/modules/service/DeviceService.java
View file @
00b222e
...
...
@@ -5,6 +5,7 @@ import cn.com.glsx.modules.model.param.Function;
import
cn.com.glsx.modules.model.param.ResponseBody
;
import
cn.com.glsx.modules.service.abs.BaseDeviceService
;
import
com.alibaba.fastjson.JSONObject
;
import
com.glsx.plat.core.web.R
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
...
...
@@ -18,7 +19,7 @@ import java.util.List;
*/
@Service
@Slf4j
public
class
DeviceService
extends
BaseDeviceService
{
public
class
DeviceService
{
@Value
(
"${tuya.getAllDevicesByUserUrl}"
)
private
String
getAllDevicesByUserUrl
;
...
...
@@ -38,68 +39,54 @@ public class DeviceService extends BaseDeviceService {
@Autowired
private
SendRequestService
sendRequestService
;
@Override
public
List
<
DeviceInfo
>
getAllDevicesByUser
(
String
uid
)
{
List
<
DeviceInfo
>
userInfo
=
null
;
public
R
getAllDevicesByUser
(
String
uid
)
{
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getAllDevicesByUserUrl
.
replace
(
"{uid}"
,
uid
));
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
String
result
=
responseBody
.
getResult
();
userInfo
=
JSONObject
.
parseArray
(
result
,
DeviceInfo
.
class
);
}
else
{
log
.
info
(
"调用涂鸦获取用户设备接口失败"
);
return
R
.
ok
(
result
);
}
return
userInfo
;
String
errorMessage
=
responseBody
==
null
?
"调用涂鸦失败"
:
responseBody
.
getMessage
();
return
R
.
error
(
errorMessage
);
}
@Override
public
DeviceInfo
getDevicesById
(
String
device_id
)
{
DeviceInfo
deviceInfo
=
null
;
public
R
getDevicesById
(
String
device_id
)
{
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getDevicesByIdUrl
.
replace
(
"{device_id}"
,
device_id
));
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
String
result
=
responseBody
.
getResult
();
deviceInfo
=
JSONObject
.
parseObject
(
result
,
DeviceInfo
.
class
);
}
else
{
log
.
info
(
"调用涂鸦获取设备接口失败"
);
return
R
.
ok
(
result
);
}
return
deviceInfo
;
String
errorMessage
=
responseBody
==
null
?
"调用涂鸦失败"
:
responseBody
.
getMessage
();
return
R
.
error
(
errorMessage
);
}
@Override
public
Function
getFunctionsById
(
String
device_id
)
{
Function
function
=
null
;
public
R
getFunctionsById
(
String
device_id
)
{
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getFunctionsByIdUrl
.
replace
(
"{device_id}"
,
device_id
));
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
String
result
=
responseBody
.
getResult
();
function
=
JSONObject
.
parseObject
(
result
,
Function
.
class
);
}
else
{
log
.
info
(
"调用涂鸦获取用户设备接口失败"
);
return
R
.
ok
(
result
);
}
return
function
;
String
errorMessage
=
responseBody
==
null
?
"调用涂鸦失败"
:
responseBody
.
getMessage
();
return
R
.
error
(
errorMessage
);
}
@Override
public
Function
getFunctionsByCat
(
String
category
)
{
public
R
getFunctionsByCat
(
String
category
)
{
Function
function
=
null
;
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getFunctionsByCatUrl
.
replace
(
"{category}"
,
category
));
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
String
result
=
responseBody
.
getResult
();
function
=
JSONObject
.
parseObject
(
result
,
Function
.
class
);
}
else
{
log
.
info
(
"调用涂鸦获取用户设备接口失败"
);
return
R
.
ok
(
result
);
}
return
function
;
String
errorMessage
=
responseBody
==
null
?
"调用涂鸦失败"
:
responseBody
.
getMessage
();
return
R
.
error
(
errorMessage
);
}
@Override
public
String
instructionIssue
(
String
device_id
,
String
insjson
)
{
String
message
=
null
;
public
R
instructionIssue
(
String
device_id
,
String
insjson
)
{
ResponseBody
responseBody
=
sendRequestService
.
sendRequestPost
(
instructionIssue
.
replace
(
"{device_id}"
,
device_id
),
insjson
);
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
message
=
"下发成功"
;
}
else
{
message
=
responseBody
.
getMsg
();
return
R
.
ok
();
}
return
message
;
String
errorMessage
=
responseBody
==
null
?
"调用涂鸦失败"
:
responseBody
.
getMessage
();
return
R
.
error
(
errorMessage
);
}
}
src/main/java/cn/com/glsx/modules/service/UserService.java
View file @
00b222e
...
...
@@ -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.UserInfo
;
import
com.alibaba.fastjson.JSONObject
;
import
com.glsx.plat.core.web.R
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
...
...
@@ -32,18 +34,15 @@ public class UserService {
*
* @param userBo 用户
*/
public
String
registerUser
(
UserBo
userBo
)
{
public
R
registerUser
(
UserBo
userBo
)
{
//获取令牌
String
uid
=
null
;
ResponseBody
responseBody
=
sendRequestService
.
sendRequestPost
(
registerUserUrl
,
JSONObject
.
toJSONString
(
userBo
));
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
String
result
=
responseBody
.
getResult
();
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
result
);
uid
=
jsonObject
.
getString
(
"uid"
);
}
else
{
log
.
info
(
"调用涂鸦失败"
);
return
R
.
ok
(
result
);
}
return
uid
;
String
errorMessage
=
responseBody
==
null
?
"调用涂鸦失败"
:
responseBody
.
getMessage
();
return
R
.
error
(
errorMessage
);
}
/**
...
...
@@ -51,16 +50,14 @@ public class UserService {
*
* @param id 用户 ID
*/
public
UserInfo
getUserInfo
(
String
id
)
{
UserInfo
userInfo
=
null
;
public
R
getUserInfo
(
String
id
)
{
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getUserInfoUrl
.
replace
(
"{uid}"
,
id
));
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
String
result
=
responseBody
.
getResult
()
+
""
;
userInfo
=
JSONObject
.
parseObject
(
result
,
UserInfo
.
class
);
}
else
{
log
.
info
(
"调用涂鸦用户信息接口失败"
);
return
R
.
ok
(
result
);
}
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