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 639fc527
authored
Mar 08, 2021
by
111-PC\111
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]代码整改
1 parent
4013dc96
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
131 additions
and
3 deletions
src/main/java/cn/com/glsx/common/BussinessFactory/BussinessFactory.java
src/main/java/cn/com/glsx/common/BussinessFactory/BussinessType.java
src/main/java/cn/com/glsx/modules/controller/DeviceController.java
src/main/java/cn/com/glsx/modules/service/DeviceService.java
src/main/java/cn/com/glsx/modules/service/SendRequestService.java
src/main/java/cn/com/glsx/modules/service/abs/BaseDeviceService.java
src/main/java/cn/com/glsx/common/BussinessFactory/BussinessFactory.java
0 → 100644
View file @
639fc52
package
cn
.
com
.
glsx
.
common
.
BussinessFactory
;
import
org.springframework.beans.BeansException
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
/**
* @author zhouhaibao
* @date 2021/3/8 11:31
*/
public
class
BussinessFactory
implements
ApplicationContextAware
{
//ApplicationContext对象是Spring开源框架的上下文对象实例,在项目运行时自动装载Handler内的所有信息到内存。
private
static
ApplicationContext
applicationContext
;
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
if
(
BussinessFactory
.
applicationContext
==
null
)
{
BussinessFactory
.
applicationContext
=
applicationContext
;
}
}
public
static
<
T
>
T
getInstance
(
String
bustype
,
Class
<
T
>
requiredType
){
String
handerType
=
BussinessType
.
getHanderType
(
bustype
);
if
(
handerType
==
null
){
return
null
;
}
else
{
T
bean
=
applicationContext
.
getBean
(
handerType
,
requiredType
);
return
bean
;
}
}
}
src/main/java/cn/com/glsx/common/BussinessFactory/BussinessType.java
0 → 100644
View file @
639fc52
package
cn
.
com
.
glsx
.
common
.
BussinessFactory
;
/**
* @author zhouhaibao
* @date 2021/3/8 11:32
*/
public
enum
BussinessType
{
tuya_hander
(
"tuya"
,
"deviceService"
),
mhome_hander
(
"mhome"
,
"testService"
);
private
String
busType
;
private
String
handerImp
;
BussinessType
(
String
busType
,
String
handerImp
)
{
this
.
busType
=
busType
;
this
.
handerImp
=
handerImp
;
}
public
String
getBusType
()
{
return
busType
;
}
public
void
setBusType
(
String
busType
)
{
this
.
busType
=
busType
;
}
public
String
getHanderImp
()
{
return
handerImp
;
}
public
void
setHanderImp
(
String
handerImp
)
{
this
.
handerImp
=
handerImp
;
}
public
static
String
getHanderType
(
String
busType
)
{
for
(
BussinessType
m
:
BussinessType
.
values
())
{
if
(
m
.
getBusType
()
==
busType
)
{
return
m
.
getHanderImp
();
}
}
return
null
;
}
}
src/main/java/cn/com/glsx/modules/controller/DeviceController.java
View file @
639fc52
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
;
...
@@ -50,7 +52,8 @@ public class DeviceController {
...
@@ -50,7 +52,8 @@ public class DeviceController {
@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
);
BaseDeviceService
tuya
=
BussinessFactory
.
getInstance
(
"tuya"
,
BaseDeviceService
.
class
);
DeviceInfo
deviceInfo
=
tuya
.
getDevicesById
(
device_id
);
return
R
.
ok
(
JSONObject
.
toJSONString
(
deviceInfo
));
return
R
.
ok
(
JSONObject
.
toJSONString
(
deviceInfo
));
}
}
...
...
src/main/java/cn/com/glsx/modules/service/DeviceService.java
View file @
639fc52
...
@@ -3,6 +3,7 @@ package cn.com.glsx.modules.service;
...
@@ -3,6 +3,7 @@ package cn.com.glsx.modules.service;
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
cn.com.glsx.modules.service.abs.BaseDeviceService
;
import
com.alibaba.fastjson.JSONObject
;
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
;
...
@@ -17,7 +18,7 @@ import java.util.List;
...
@@ -17,7 +18,7 @@ import java.util.List;
*/
*/
@Service
@Service
@Slf4j
@Slf4j
public
class
DeviceService
{
public
class
DeviceService
extends
BaseDeviceService
{
@Value
(
"${tuya.getAllDevicesByUserUrl}"
)
@Value
(
"${tuya.getAllDevicesByUserUrl}"
)
private
String
getAllDevicesByUserUrl
;
private
String
getAllDevicesByUserUrl
;
...
@@ -34,7 +35,7 @@ public class DeviceService {
...
@@ -34,7 +35,7 @@ public class DeviceService {
@Autowired
@Autowired
private
SendRequestService
sendRequestService
;
private
SendRequestService
sendRequestService
;
@Override
public
List
<
DeviceInfo
>
getAllDevicesByUser
(
String
uid
)
{
public
List
<
DeviceInfo
>
getAllDevicesByUser
(
String
uid
)
{
List
<
DeviceInfo
>
userInfo
=
null
;
List
<
DeviceInfo
>
userInfo
=
null
;
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getAllDevicesByUserUrl
.
replace
(
"{uid}"
,
uid
));
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getAllDevicesByUserUrl
.
replace
(
"{uid}"
,
uid
));
...
@@ -47,6 +48,7 @@ public class DeviceService {
...
@@ -47,6 +48,7 @@ public class DeviceService {
return
userInfo
;
return
userInfo
;
}
}
@Override
public
DeviceInfo
getDevicesById
(
String
device_id
)
{
public
DeviceInfo
getDevicesById
(
String
device_id
)
{
DeviceInfo
deviceInfo
=
null
;
DeviceInfo
deviceInfo
=
null
;
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getDevicesByIdUrl
.
replace
(
"{device_id}"
,
device_id
));
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getDevicesByIdUrl
.
replace
(
"{device_id}"
,
device_id
));
...
@@ -59,6 +61,7 @@ public class DeviceService {
...
@@ -59,6 +61,7 @@ public class DeviceService {
return
deviceInfo
;
return
deviceInfo
;
}
}
@Override
public
Function
getFunctionsById
(
String
device_id
)
{
public
Function
getFunctionsById
(
String
device_id
)
{
Function
function
=
null
;
Function
function
=
null
;
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getFunctionsByIdUrl
.
replace
(
"{device_id}"
,
device_id
));
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getFunctionsByIdUrl
.
replace
(
"{device_id}"
,
device_id
));
...
@@ -71,6 +74,7 @@ public class DeviceService {
...
@@ -71,6 +74,7 @@ public class DeviceService {
return
function
;
return
function
;
}
}
@Override
public
Function
getFunctionsByCat
(
String
category
)
{
public
Function
getFunctionsByCat
(
String
category
)
{
Function
function
=
null
;
Function
function
=
null
;
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getFunctionsByCatUrl
.
replace
(
"{category}"
,
category
));
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getFunctionsByCatUrl
.
replace
(
"{category}"
,
category
));
...
...
src/main/java/cn/com/glsx/modules/service/SendRequestService.java
View file @
639fc52
...
@@ -15,6 +15,8 @@ import java.io.IOException;
...
@@ -15,6 +15,8 @@ import java.io.IOException;
import
java.util.Map
;
import
java.util.Map
;
/**
/**
* 发送请求工具类
*
* @author zhouhaibao
* @author zhouhaibao
* @date 2021/3/5 14:37
* @date 2021/3/5 14:37
*/
*/
...
@@ -31,6 +33,13 @@ public class SendRequestService {
...
@@ -31,6 +33,13 @@ public class SendRequestService {
@Autowired
@Autowired
private
AccessTokenService
accessTokenService
;
private
AccessTokenService
accessTokenService
;
/**
* 向涂鸦发送post请求
*
* @param requesturl 请求url
* @param requestBody 请求体
* @return
*/
public
ResponseBody
sendRequestPost
(
String
requesturl
,
String
requestBody
)
{
public
ResponseBody
sendRequestPost
(
String
requesturl
,
String
requestBody
)
{
ResponseBody
responseBody
=
null
;
ResponseBody
responseBody
=
null
;
String
accessToken
=
accessTokenService
.
getAccessToken
();
String
accessToken
=
accessTokenService
.
getAccessToken
();
...
@@ -49,6 +58,12 @@ public class SendRequestService {
...
@@ -49,6 +58,12 @@ public class SendRequestService {
return
responseBody
;
return
responseBody
;
}
}
/**
* 像涂鸦发送get请求
*
* @param requesturl 请求参数
* @return
*/
public
ResponseBody
sendRequestGet
(
String
requesturl
)
{
public
ResponseBody
sendRequestGet
(
String
requesturl
)
{
ResponseBody
responseBody
=
null
;
ResponseBody
responseBody
=
null
;
String
accessToken
=
accessTokenService
.
getAccessToken
();
String
accessToken
=
accessTokenService
.
getAccessToken
();
...
@@ -67,6 +82,12 @@ public class SendRequestService {
...
@@ -67,6 +82,12 @@ public class SendRequestService {
return
responseBody
;
return
responseBody
;
}
}
/**
* 向涂鸦发送获取鉴权token请求
*
* @param requesturl 请求链接
* @return
*/
public
ResponseBody
sendRequestGetOA
(
String
requesturl
)
{
public
ResponseBody
sendRequestGetOA
(
String
requesturl
)
{
ResponseBody
responseBody
=
null
;
ResponseBody
responseBody
=
null
;
Map
<
String
,
String
>
headerParams
=
HeaderParamUtils
.
buildHeaderParams
(
client_id
,
secret
);
Map
<
String
,
String
>
headerParams
=
HeaderParamUtils
.
buildHeaderParams
(
client_id
,
secret
);
...
...
src/main/java/cn/com/glsx/modules/service/abs/BaseDeviceService.java
0 → 100644
View file @
639fc52
package
cn
.
com
.
glsx
.
modules
.
service
.
abs
;
import
cn.com.glsx.modules.model.param.DeviceInfo
;
import
cn.com.glsx.modules.model.param.Function
;
import
java.util.List
;
/**
* @author zhouhaibao
* @date 2021/3/8 9:55
*/
public
abstract
class
BaseDeviceService
{
public
abstract
List
<
DeviceInfo
>
getAllDevicesByUser
(
String
uid
);
public
abstract
DeviceInfo
getDevicesById
(
String
deviveid
);
public
abstract
Function
getFunctionsById
(
String
uid
);
public
abstract
Function
getFunctionsByCat
(
String
cat
);
}
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