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 48116e61
authored
Mar 30, 2021
by
wnb0128
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
车家智能数据服务开发 用户登录--think.wang
1 parent
7b3415cb
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
0 deletions
src/main/java/com/glsx/smart/constant/Constants.java
src/main/java/com/glsx/smart/controller/UserRelationController.java
src/main/java/com/glsx/smart/constant/Constants.java
0 → 100644
View file @
48116e6
package
com
.
glsx
.
smart
.
constant
;
/**
* @Title: Constants.java
* @Description: 常量
* @date 2021年3月12日 上午9:27:06
* @version V1.0
* @Company: glsx.com.cn
* @Copyright Copyright (c) 2021
*/
public
class
Constants
{
public
final
static
String
DEFAULT_PASSWORD
=
"123456"
;
}
src/main/java/com/glsx/smart/controller/UserRelationController.java
View file @
48116e6
package
com
.
glsx
.
smart
.
controller
;
package
com
.
glsx
.
smart
.
controller
;
import
cn.hutool.crypto.digest.MD5
;
import
com.alibaba.fastjson.JSON
;
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.plat.core.web.R
;
import
com.glsx.smart.constant.Constants
;
import
com.glsx.smart.dao.entity.SmartUserRelation
;
import
com.glsx.smart.dao.entity.SmartUserRelation
;
import
com.glsx.smart.service.SmartUserRelationService
;
import
com.glsx.smart.service.SmartUserRelationService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
/**
* @Title: UserRelationController.java
* @Title: UserRelationController.java
* @Description:用户关系控制类
* @Description:用户关系控制类
...
@@ -20,6 +31,12 @@ import org.springframework.web.bind.annotation.*;
...
@@ -20,6 +31,12 @@ import org.springframework.web.bind.annotation.*;
@RequestMapping
(
"/user"
)
@RequestMapping
(
"/user"
)
public
class
UserRelationController
{
public
class
UserRelationController
{
@Value
(
"${device_remote_url}"
)
private
String
remoteUrl
;
@Value
(
"${tuya_user_sync}"
)
private
String
syncUser
;
@Autowired
@Autowired
private
SmartUserRelationService
userRelationService
;
private
SmartUserRelationService
userRelationService
;
...
@@ -43,4 +60,61 @@ public class UserRelationController {
...
@@ -43,4 +60,61 @@ public class UserRelationController {
return
userRelationService
.
updateByPrimaryKeySelective
(
userRelation
);
return
userRelationService
.
updateByPrimaryKeySelective
(
userRelation
);
}
}
@ResponseBody
@RequestMapping
(
value
=
"/login"
,
method
=
{
RequestMethod
.
POST
})
public
R
login
(
@RequestBody
SmartUserRelation
userRelation
){
log
.
info
(
"/user/login保存数据参数:{}"
,
JSON
.
toJSONString
(
userRelation
));
SmartUserRelation
request
=
new
SmartUserRelation
();
request
.
setPhone
(
userRelation
.
getPhone
());
request
.
setChannel
((
byte
)
1
);
//涂鸦
SmartUserRelation
user
=
userRelationService
.
getSingle
(
request
);
if
(
user
!=
null
){
if
(
StringUtils
.
isEmpty
(
user
.
getThirdId
())){
if
(
request
.
getChannel
()
==
1
){
String
tuYaId
=
this
.
syncUser
(
user
.
getPhone
(),
user
.
getPassword
());
request
.
setThirdId
(
tuYaId
);
request
.
setId
(
user
.
getId
());
userRelationService
.
updateByPrimaryKeySelective
(
request
);
}
}
return
R
.
ok
().
data
(
user
.
getId
());
}
String
password
=
MD5
.
create
().
digestHex
(
Constants
.
DEFAULT_PASSWORD
);
request
.
setCreateTime
(
new
Date
());
request
.
setPassword
(
password
);
if
(
request
.
getChannel
()
==
1
){
//渠道为涂鸦
String
tuYaId
=
this
.
syncUser
(
request
.
getPhone
(),
password
);
request
.
setThirdId
(
tuYaId
);
Long
id
=
userRelationService
.
insertSelective
(
request
);
if
(
id
!=
null
&&
id
>
0
){
return
R
.
ok
().
data
(
id
);
}
}
return
R
.
error
();
}
private
String
syncUser
(
String
mobile
,
String
password
){
Map
<
String
,
String
>
object
=
new
HashMap
<>();
object
.
put
(
"country_code"
,
"86"
);
object
.
put
(
"username"
,
mobile
);
object
.
put
(
"username_type"
,
"1"
);
object
.
put
(
"password"
,
password
);
try
{
StringBuffer
syncUserUrl
=
new
StringBuffer
(
remoteUrl
);
syncUserUrl
.
append
(
syncUser
);
log
.
info
(
"请求注册涂鸦平台接口地址:{},参数:{}"
,
syncUserUrl
.
toString
(),
JSON
.
toJSONString
(
object
));
String
result
=
HttpUtils
.
post
(
syncUserUrl
.
toString
(),
JSON
.
toJSONString
(
object
));
log
.
info
(
"注册涂鸦平台返回结果:{}"
,
result
);
if
(!
StringUtils
.
isEmpty
(
result
))
{
JSONObject
json
=
JSON
.
parseObject
(
result
);
if
(
json
.
getInteger
(
"code"
).
equals
(
200
))
{
return
json
.
getJSONObject
(
"message"
).
getString
(
"uid"
);
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"同步涂鸦平台失败:{}"
,
e
);
}
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