Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
open-source
/
chejia-smart-api
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 0cf161da
authored
Mar 22, 2021
by
wnb0128
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
车家智能移动端服务 用户第三方设备获取接口--think.wang
1 parent
7a6eb6ee
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
102 additions
and
7 deletions
src/main/java/com/glsx/api/controller/RemoteProductController.java
src/main/java/com/glsx/api/controller/UserController.java
src/main/java/com/glsx/api/exception/ResultEnum.java
src/main/resources/application.properties
src/main/java/com/glsx/api/controller/RemoteProductController.java
0 → 100644
View file @
0cf161d
package
com
.
glsx
.
api
.
controller
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.glsx.api.exception.BusinessException
;
import
com.glsx.api.exception.ResultEnum
;
import
com.glsx.api.pojo.request.UserRelationReq
;
import
com.glsx.api.pojo.response.UserRelationResp
;
import
com.glsx.api.remote.UserFeignClient
;
import
com.glsx.plat.common.utils.HttpUtils
;
import
com.glsx.plat.common.utils.StringUtils
;
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
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
/**
*
* 远程产品服务controller
* 暂时只有涂鸦
*
*/
@Slf4j
@RestController
@RequestMapping
(
"/remoteDevice"
)
public
class
RemoteProductController
{
@Value
(
"${device_remote_url}"
)
private
String
remoteUrl
;
@Autowired
private
UserFeignClient
userFeignClient
;
/**
* 用户获取远程产品列表数据
*
* @return 结果
*/
@RequestMapping
(
value
=
"/getList"
,
method
=
{
RequestMethod
.
POST
})
public
R
getList
(
@RequestBody
UserRelationReq
req
)
{
Long
id
=
req
.
getId
();
if
(
id
==
null
||
id
<=
0L
){
throw
BusinessException
.
create
(
ResultEnum
.
PARAM_ERROR
);
}
UserRelationResp
user
=
userFeignClient
.
getSingle
(
req
);
if
(
user
==
null
){
throw
BusinessException
.
create
(
ResultEnum
.
USER_NOT_EXIST
);
}
return
R
.
ok
().
data
(
this
.
getRemoteDevice
(
user
.
getThirdId
()));
}
private
JSONArray
getRemoteDevice
(
String
thirdId
){
StringBuffer
url
=
new
StringBuffer
(
remoteUrl
);
url
.
append
(
"/device/"
).
append
(
thirdId
).
append
(
"/devices"
);
log
.
info
(
"请求远程设备列表接口地址:{}"
,
url
.
toString
());
try
{
String
result
=
HttpUtils
.
get
(
url
.
toString
());
log
.
info
(
"获取用户设备列表数据返回结果:{}"
,
result
);
if
(
StringUtils
.
isNotEmpty
(
result
))
{
JSONObject
json
=
JSON
.
parseObject
(
result
);
if
(
json
.
getInteger
(
"code"
).
equals
(
200
))
{
JSONArray
list
=
new
JSONArray
();
JSONArray
array
=
json
.
getJSONArray
(
"message"
);
int
len
=
array
.
size
();
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
JSONObject
object
=
array
.
getJSONObject
(
i
);
JSONObject
val
=
new
JSONObject
();
val
.
put
(
"productId"
,
object
.
getString
(
"product_id"
));
val
.
put
(
"uuid"
,
object
.
getString
(
"uuid"
));
val
.
put
(
"productName"
,
object
.
getString
(
"product_name"
));
list
.
add
(
val
);
}
return
list
;
}
}
}
catch
(
Exception
e
){
log
.
error
(
"获取用户设备列表数据失败:{}"
,
e
);
}
return
null
;
}
}
src/main/java/com/glsx/api/controller/UserController.java
View file @
0cf161d
...
...
@@ -37,8 +37,11 @@ import java.util.Date;
@RequestMapping
(
"/user"
)
public
class
UserController
extends
BaseController
{
@Value
(
"${tu_ya_sync_interface}"
)
private
String
syncUserUrl
;
@Value
(
"${device_remote_url}"
)
private
String
remoteUrl
;
@Value
(
"${tuya_user_sync}"
)
private
String
syncUser
;
@Autowired
private
UserFeignClient
userFeignClient
;
...
...
@@ -81,13 +84,15 @@ public class UserController extends BaseController{
object
.
put
(
"username_type"
,
1
);
object
.
put
(
"password"
,
password
);
try
{
log
.
info
(
"请求注册涂鸦平台接口地址:{},参数:{}"
,
syncUserUrl
,
object
.
toJSONString
());
String
result
=
HttpUtils
.
post
(
syncUserUrl
,
object
.
toJSONString
());
StringBuffer
syncUserUrl
=
new
StringBuffer
(
remoteUrl
);
syncUserUrl
.
append
(
syncUser
);
log
.
info
(
"请求注册涂鸦平台接口地址:{},参数:{}"
,
syncUserUrl
.
toString
(),
object
.
toJSONString
());
String
result
=
HttpUtils
.
post
(
syncUserUrl
.
toString
(),
object
.
toJSONString
());
log
.
info
(
"注册涂鸦平台返回结果:{}"
,
result
);
if
(
StringUtils
.
isNotEmpty
(
result
))
{
JSONObject
json
=
JSON
.
parseObject
(
result
);
if
(
json
.
getInteger
(
"code"
).
equals
(
200
))
{
return
json
.
get
String
(
"message
"
);
return
json
.
get
JSONObject
(
"message"
).
getString
(
"uid
"
);
}
}
}
catch
(
Exception
e
)
{
...
...
src/main/java/com/glsx/api/exception/ResultEnum.java
View file @
0cf161d
...
...
@@ -13,6 +13,7 @@ public enum ResultEnum {
PARAM_ERROR
(
1001
,
"参数错误"
),
ID_NOT_FOUND
(
1002
,
"ID不存在"
),
USER_NOT_EXIST
(
1002
,
"用户不存在"
),
PRODUCT_NOT_FOUND
(
2001
,
"产品ID未找到"
),
PRODUCT_NAME_DUPLICATE
(
2002
,
"产品名称重复"
),
...
...
src/main/resources/application.properties
View file @
0cf161d
...
...
@@ -21,6 +21,8 @@ feign.server.url=http://localhost:8209/smartService
dubbo.registry.address
=
zookeeper://192.168.1.36:2181?init.timeout=60000
dubbo.registry.timeout
=
10000
#\u6D82\u9E26\u540C\u6B65\u7528\u6237\u63A5\u53E3
tu_ya_sync_interface
=
http://192.168.3.137:8091/smartApi/sync_user
#\u8BBE\u5907\u8FDC\u7A0B\u8BBF\u95EEurl
device_remote_url
=
http://192.168.3.222:8099/smartDevices-platform-service
#\u6D82\u9E26\u7528\u6237\u6CE8\u518C\u63A5\u53E3
tuya_user_sync
=
/user/registerUser
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