Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
open-source
/
chejia-smart-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 d0b0e45d
authored
Mar 24, 2021
by
wnb0128
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
车家智能数据服务开发 涂鸦产品列表获取开发--think.wang
1 parent
323f9748
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
0 deletions
src/main/java/com/glsx/smart/controller/RemoteProductController.java
src/main/java/com/glsx/smart/controller/RemoteProductController.java
0 → 100644
View file @
d0b0e45
package
com
.
glsx
.
smart
.
controller
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.glsx.plat.common.utils.HttpUtils
;
import
com.glsx.plat.common.utils.StringUtils
;
import
com.glsx.smart.dao.entity.SmartProduct
;
import
com.glsx.smart.dao.entity.SmartUserRelation
;
import
com.glsx.smart.service.SmartProductService
;
import
com.glsx.smart.service.SmartUserRelationService
;
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
;
import
java.util.List
;
/**
*
* 远程产品服务controller
* 暂时只有涂鸦
*
*/
@Slf4j
@RestController
@RequestMapping
(
"/remoteProduct"
)
public
class
RemoteProductController
{
@Value
(
"${device_remote_url}"
)
private
String
remoteUrl
;
@Autowired
private
SmartProductService
productService
;
@Autowired
private
SmartUserRelationService
userRelationService
;
/**
* 用户获取远程产品列表数据
*
* @return 结果
*/
@RequestMapping
(
value
=
"/getList"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
public
JSONArray
getList
(
@RequestBody
SmartUserRelation
request
)
{
SmartUserRelation
user
=
userRelationService
.
getSingle
(
request
);
return
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
();
String
productId
=
object
.
getString
(
"product_id"
);
val
.
put
(
"productId"
,
productId
);
val
.
put
(
"uuid"
,
object
.
getString
(
"uuid"
));
val
.
put
(
"productName"
,
object
.
getString
(
"product_name"
));
val
.
put
(
"iconUrl"
,
this
.
getProductIcon
(
productId
));
list
.
add
(
val
);
}
return
list
;
}
}
}
catch
(
Exception
e
){
log
.
error
(
"获取用户设备列表数据失败:{}"
,
e
);
}
return
null
;
}
/**
* 通过平台产品id获取产品图片
* @param productId
* @return
*/
private
String
getProductIcon
(
String
productId
){
SmartProduct
req
=
new
SmartProduct
();
req
.
setPlatformProductId
(
productId
);
List
<
SmartProduct
>
list
=
productService
.
getListByCondition
(
req
);
if
(!
list
.
isEmpty
()){
return
list
.
get
(
0
).
getIconUrl
();
}
return
null
;
}
}
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