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 1224e427
authored
Apr 23, 2021
by
tyfanchz
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
获取用户 bindKey
1 parent
df111acf
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
0 deletions
src/main/java/com/glsx/smart/controller/UserDeviceController.java
src/main/java/com/glsx/smart/service/SmartUserDeviceService.java
src/main/java/com/glsx/smart/service/impl/SmartUserDeviceServiceImpl.java
src/main/java/com/glsx/smart/controller/UserDeviceController.java
View file @
1224e42
...
...
@@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
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.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
/**
...
...
@@ -72,4 +73,17 @@ public class UserDeviceController {
boolean
success
=
userDeviceService
.
deleteDevice
(
userDevice
)
>
0
;
return
R
.
ok
().
data
(
success
);
}
/**
* 获取用户 bindKey
*
* @param username 用户名
* @return 结果
*/
@RequestMapping
(
value
=
"/getUserBindKey"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
public
R
getUserBindKey
(
@RequestParam
String
username
)
{
log
.
info
(
"$$$$ /userDevice/getUserBindKey param: {}"
,
username
);
String
userBindKey
=
userDeviceService
.
getUserBindKey
(
username
);
return
R
.
ok
().
data
(
userBindKey
);
}
}
src/main/java/com/glsx/smart/service/SmartUserDeviceService.java
View file @
1224e42
...
...
@@ -17,4 +17,6 @@ public interface SmartUserDeviceService {
int
save
(
SmartUserDevice
userDevice
);
int
deleteDevice
(
SmartUserDevice
userDevice
);
String
getUserBindKey
(
String
username
);
}
src/main/java/com/glsx/smart/service/impl/SmartUserDeviceServiceImpl.java
View file @
1224e42
...
...
@@ -4,6 +4,9 @@ import javax.annotation.Resource;
import
javax.transaction.Transactional
;
import
java.util.Date
;
import
java.util.List
;
import
com.alibaba.fastjson.JSON
;
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.SmartUserDevice
;
import
com.glsx.smart.dao.mapper.SmartUserDeviceMapper
;
...
...
@@ -12,6 +15,7 @@ import com.glsx.smart.exception.ResultEnum;
import
com.glsx.smart.service.BaseService
;
import
com.glsx.smart.service.SmartUserDeviceService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
/**
...
...
@@ -24,6 +28,12 @@ import org.springframework.stereotype.Service;
@Slf4j
@Service
public
class
SmartUserDeviceServiceImpl
extends
BaseService
implements
SmartUserDeviceService
{
@Value
(
"${device_remote_url}"
)
private
String
remoteUrl
;
@Value
(
"${user_bind_key}"
)
private
String
userBindKeyApi
;
@Resource
private
SmartUserDeviceMapper
userDeviceMapper
;
...
...
@@ -62,4 +72,18 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
rows
=
userDeviceMapper
.
deleteDevice
(
userDevice
);
return
rows
;
}
@Override
public
String
getUserBindKey
(
String
username
)
{
JSONObject
reqObj
=
new
JSONObject
();
reqObj
.
put
(
"username"
,
username
);
String
url
=
remoteUrl
+
userBindKeyApi
;
log
.
info
(
"$$$$ getUserBindKey url = {}, req = {}"
,
url
,
JSON
.
toJSONString
(
reqObj
));
String
respJson
=
HttpUtils
.
get
(
url
,
reqObj
);
log
.
info
(
"$$$$ getUserBindKey resp = {}"
,
respJson
);
JSONObject
respObj
=
JSON
.
parseObject
(
respJson
);
String
bindKey
=
"200"
.
equals
(
respObj
.
getString
(
"code"
))
?
respObj
.
getJSONObject
(
"message"
).
getString
(
"bindKey"
)
:
null
;
return
bindKey
;
}
}
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