Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
beyond-clouds
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
段启岩
beyond-clouds
Commits
49a8fc46
Commit
49a8fc46
authored
Jan 31, 2020
by
张晋雄
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
用户基本信息
parent
c5372948
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
147 additions
and
8 deletions
+147
-8
src/main/java/cn/meteor/beyondclouds/modules/user/api/UserApi.java
+53
-6
src/main/java/cn/meteor/beyondclouds/modules/user/form/UserBaseinfoFrom.java
+29
-0
src/main/java/cn/meteor/beyondclouds/modules/user/service/IUserService.java
+10
-0
src/main/java/cn/meteor/beyondclouds/modules/user/service/impl/UserServiceImpl.java
+53
-0
src/main/resources/application.yml
+2
-2
No files found.
src/main/java/cn/meteor/beyondclouds/modules/user/api/UserApi.java
View file @
49a8fc46
package
cn
.
meteor
.
beyondclouds
.
modules
.
user
.
api
;
package
cn
.
meteor
.
beyondclouds
.
modules
.
user
.
api
;
import
cn.meteor.beyondclouds.core.annotation.Anonymous
;
import
cn.meteor.beyondclouds.core.annotation.Anonymous
;
import
cn.meteor.beyondclouds.core.annotation.CurrentSubject
;
import
cn.meteor.beyondclouds.core.api.Response
;
import
cn.meteor.beyondclouds.core.api.Response
;
import
cn.meteor.beyondclouds.core.bean.Subject
;
import
cn.meteor.beyondclouds.modules.user.entity.User
;
import
cn.meteor.beyondclouds.modules.user.exception.UserServiceException
;
import
cn.meteor.beyondclouds.modules.user.exception.UserServiceException
;
import
cn.meteor.beyondclouds.modules.user.form.UserBaseinfoFrom
;
import
cn.meteor.beyondclouds.modules.user.form.UserRegisterFrom
;
import
cn.meteor.beyondclouds.modules.user.form.UserRegisterFrom
;
import
cn.meteor.beyondclouds.modules.user.service.IUserService
;
import
cn.meteor.beyondclouds.modules.user.service.IUserService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.validation.Valid
;
import
javax.validation.Valid
;
...
@@ -22,7 +23,7 @@ import javax.validation.Valid;
...
@@ -22,7 +23,7 @@ import javax.validation.Valid;
@Api
(
tags
=
"用户Api"
)
@Api
(
tags
=
"用户Api"
)
@RestController
@RestController
@RequestMapping
(
"/api
/user
"
)
@RequestMapping
(
"/api"
)
public
class
UserApi
{
public
class
UserApi
{
private
IUserService
userService
;
private
IUserService
userService
;
...
@@ -34,7 +35,7 @@ public class UserApi {
...
@@ -34,7 +35,7 @@ public class UserApi {
@Anonymous
@Anonymous
@ApiOperation
(
"用户注册"
)
@ApiOperation
(
"用户注册"
)
@PostMapping
(
"/register/mobile"
)
@PostMapping
(
"/
user/
register/mobile"
)
public
Response
register
(
@RequestBody
@Valid
UserRegisterFrom
registerFrom
,
BindingResult
result
)
{
public
Response
register
(
@RequestBody
@Valid
UserRegisterFrom
registerFrom
,
BindingResult
result
)
{
if
(
result
.
hasErrors
())
{
if
(
result
.
hasErrors
())
{
...
@@ -50,5 +51,51 @@ public class UserApi {
...
@@ -50,5 +51,51 @@ public class UserApi {
}
}
}
}
@ApiOperation
(
"修改我的基本信息"
)
@PutMapping
(
"/my/baseinfo"
)
public
Response
alterBaseinfo
(
@RequestBody
@Valid
UserBaseinfoFrom
userBaseinfoFrom
,
BindingResult
result
,
@CurrentSubject
Subject
subject
){
if
(
result
.
hasErrors
())
{
return
Response
.
fieldError
(
result
.
getFieldError
());
}
userService
.
alterBaseinfo
(
userBaseinfoFrom
.
getNickName
(),
userBaseinfoFrom
.
getUserAvatar
(),
userBaseinfoFrom
.
getGender
(),
userBaseinfoFrom
.
getMobile
(),
userBaseinfoFrom
.
getSignature
(),
userBaseinfoFrom
.
getQqNumber
(),
userBaseinfoFrom
.
getWxNumber
(),
String
.
valueOf
(
subject
.
getId
()));
return
Response
.
success
();
}
@Anonymous
@ApiOperation
(
"修改密码"
)
@PutMapping
(
"/my/password"
)
public
Response
alterPassword
(
@RequestBody
@Valid
UserRegisterFrom
registerFrom
,
BindingResult
result
){
if
(
result
.
hasErrors
())
{
return
Response
.
fieldError
(
result
.
getFieldError
());
}
try
{
userService
.
alterPassword
(
registerFrom
.
getMobile
(),
registerFrom
.
getPassword
(),
registerFrom
.
getVerifyCode
());
return
Response
.
success
();
}
catch
(
UserServiceException
e
)
{
e
.
printStackTrace
();
return
Response
.
error
(
e
);
}
}
@ApiOperation
((
"获取我的基本信息"
))
@GetMapping
(
"/my/baseinfo"
)
public
Response
myBaseinfo
(
@CurrentSubject
Subject
subject
){
return
Response
.
success
(
userService
.
myBaseinfo
(
String
.
valueOf
(
subject
.
getId
())));
}
@ApiOperation
((
"获取他人基本信息"
))
@GetMapping
(
"/user/{userId}/baseinfo"
)
public
Response
otherBaseinfo
(
@PathVariable
(
name
=
"userId"
)
String
userId
){
return
Response
.
success
(
userService
.
otherBaseinfo
(
userId
));
}
}
}
src/main/java/cn/meteor/beyondclouds/modules/user/form/UserBaseinfoFrom.java
0 → 100644
View file @
49a8fc46
package
cn
.
meteor
.
beyondclouds
.
modules
.
user
.
form
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
/**
* @program: beyond-clouds
* @description: 用户信息表
* @author: Mr.Zhang
* @create: 2020-01-31 11:41
**/
@Data
@ApiModel
(
"用户信息表"
)
public
class
UserBaseinfoFrom
{
private
String
nickName
;
private
String
userAvatar
;
private
Integer
gender
;
private
String
signature
;
private
String
mobile
;
private
String
wxNumber
;
private
String
qqNumber
;
}
src/main/java/cn/meteor/beyondclouds/modules/user/service/IUserService.java
View file @
49a8fc46
...
@@ -4,6 +4,8 @@ import cn.meteor.beyondclouds.modules.user.entity.User;
...
@@ -4,6 +4,8 @@ import cn.meteor.beyondclouds.modules.user.entity.User;
import
cn.meteor.beyondclouds.modules.user.exception.UserServiceException
;
import
cn.meteor.beyondclouds.modules.user.exception.UserServiceException
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
java.io.Serializable
;
/**
/**
* @author meteor
* @author meteor
*/
*/
...
@@ -32,4 +34,12 @@ public interface IUserService extends IService<User> {
...
@@ -32,4 +34,12 @@ public interface IUserService extends IService<User> {
* @param nickName
* @param nickName
*/
*/
void
updateNickName
(
String
userId
,
String
nickName
);
void
updateNickName
(
String
userId
,
String
nickName
);
void
alterBaseinfo
(
String
nickName
,
String
userAvatar
,
Integer
gender
,
String
mobile
,
String
signature
,
String
qqNumber
,
String
wxNumber
,
String
id
);
void
alterPassword
(
String
mobile
,
String
password
,
String
verifyCode
)
throws
UserServiceException
;
User
myBaseinfo
(
String
id
);
User
otherBaseinfo
(
String
nickName
);
}
}
src/main/java/cn/meteor/beyondclouds/modules/user/service/impl/UserServiceImpl.java
View file @
49a8fc46
...
@@ -17,6 +17,8 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -17,6 +17,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
import
java.io.Serializable
;
/**
/**
* @author meteor
* @author meteor
*/
*/
...
@@ -85,4 +87,55 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I
...
@@ -85,4 +87,55 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I
updateWrapper
.
set
(
"nick_name"
,
nickName
);
updateWrapper
.
set
(
"nick_name"
,
nickName
);
update
(
updateWrapper
);
update
(
updateWrapper
);
}
}
@Override
public
void
alterBaseinfo
(
String
nickName
,
String
userAvatar
,
Integer
gender
,
String
mobile
,
String
signature
,
String
qqNumber
,
String
wxNumber
,
String
id
)
{
UpdateWrapper
updateWrapper
=
new
UpdateWrapper
();
updateWrapper
.
eq
(
"user_id"
,
id
);
updateWrapper
.
set
(
"nick_name"
,
nickName
);
updateWrapper
.
set
(
"user_avatar"
,
userAvatar
);
updateWrapper
.
set
(
"gender"
,
gender
);
updateWrapper
.
set
(
"signature"
,
signature
);
updateWrapper
.
set
(
"mobile"
,
mobile
);
updateWrapper
.
set
(
"wx_number"
,
wxNumber
);
updateWrapper
.
set
(
"qq_number"
,
qqNumber
);
update
(
updateWrapper
);
}
@Override
public
void
alterPassword
(
String
mobile
,
String
password
,
String
verifyCode
)
throws
UserServiceException
{
//1.检查验证码是否正确
String
realVerifyCode
=
redisHelper
.
get
(
RedisKey
.
VERIFY_CODE_KEY
(
mobile
));
if
(
StringUtils
.
isEmpty
(
realVerifyCode
)
||
!
realVerifyCode
.
equals
(
verifyCode
))
{
throw
new
UserServiceException
(
UserErrorCode
.
REG_VERIFY_CODE_ERROR
);
}
// 删除验证码
redisHelper
.
del
(
RedisKey
.
VERIFY_CODE_KEY
(
mobile
));
UpdateWrapper
updateWrapper
=
new
UpdateWrapper
();
updateWrapper
.
set
(
"password"
,
Md5Utils
.
encode
(
password
));
updateWrapper
.
eq
(
"mobile"
,
mobile
);
userAuthLocalService
.
update
(
updateWrapper
);
}
@Override
public
User
myBaseinfo
(
String
userId
)
{
QueryWrapper
<
User
>
queryWrapper
=
new
QueryWrapper
<>();
queryWrapper
.
eq
(
"user_id"
,
userId
);
System
.
out
.
println
(
userId
);
return
getOne
(
queryWrapper
);
}
@Override
public
User
otherBaseinfo
(
String
userId
)
{
QueryWrapper
queryWrapper
=
new
QueryWrapper
<>();
queryWrapper
.
eq
(
"user_id"
,
userId
);
return
getOne
(
queryWrapper
);
}
}
}
src/main/resources/application.yml
View file @
49a8fc46
spring
:
spring
:
datasource
:
datasource
:
driver-class-name
:
com.mysql.cj.jdbc.Driver
driver-class-name
:
com.mysql.cj.jdbc.Driver
url
:
jdbc:mysql://127.0.0.1:3306/beyond_clouds?useUnicode=true&characterEncoding=UTF-8&useSSL=false
url
:
jdbc:mysql://127.0.0.1:3306/beyond_clouds?useUnicode=true&characterEncoding=UTF-8&useSSL=false
&allowPublicKeyRetrieval=true
username
:
root
username
:
root
password
:
100Centa30821%mysql
password
:
2018006709
swagger
:
swagger
:
enable
:
true
enable
:
true
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment