Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
邬吉朋
practical_train
Commits
cd112ea9
Commit
cd112ea9
authored
Aug 03, 2026
by
wujipeng
Browse files
init
parents
Pipeline
#346
canceled with stages
Changes
327
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
practical-api/practical-business-api/src/main/java/com/platform/business/model/vo/UserTeacherVO.java
0 → 100644
View file @
cd112ea9
package
com.platform.business.model.vo
;
import
com.platform.business.model.entity.TeacherWorkRecordEntity
;
import
com.platform.business.model.entity.UserTeacherEntity
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
java.util.List
;
@Data
@EqualsAndHashCode
(
callSuper
=
true
)
public
class
UserTeacherVO
extends
UserTeacherEntity
{
private
List
<
TeacherWorkRecordEntity
>
teacherWorkRecord
;
private
List
<
ClassSubjectVO
>
classSubjectList
;
}
practical-api/practical-business-api/src/main/java/com/platform/business/model/vo/UserVO.java
0 → 100644
View file @
cd112ea9
package
com.platform.business.model.vo
;
import
com.google.common.collect.Lists
;
import
com.platform.business.model.entity.*
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
java.util.List
;
@EqualsAndHashCode
(
callSuper
=
true
)
@Data
public
class
UserVO
extends
UserEntity
{
// private UserTeacherVO userTeacherExtend;
private
List
<
StudentLevelCertEntity
>
studentLevelCertList
;
@ApiModelProperty
(
"从业经历"
)
List
<
TeacherWorkRecordEntity
>
teacherWorkRecordList
;
@ApiModelProperty
(
"任教经历"
)
List
<
TeacherTeachRecordEntity
>
teacherTeachRecordList
;
private
Integer
roleId
;
private
String
roleName
;
private
List
<
SysRoleAndMenuVO
>
sysMenuEntities
;
//菜单权限列表
private
List
<
SysPhoneRoleEntity
>
sysPhoneRoleEntities
;
//用户角色列表
}
practical-auth/pom.xml
0 → 100644
View file @
cd112ea9
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
practical-auth
</artifactId>
<version>
1.0.0
</version>
<parent>
<groupId>
com.platform
</groupId>
<artifactId>
practical-train
</artifactId>
<version>
1.0.0
</version>
</parent>
<dependencies>
<dependency>
<groupId>
com.alibaba.cloud
</groupId>
<artifactId>
spring-cloud-starter-alibaba-nacos-discovery
</artifactId>
<version>
2.2.6.RELEASE
</version>
</dependency>
<!--配置中心客户端-->
<dependency>
<groupId>
com.alibaba.cloud
</groupId>
<artifactId>
spring-cloud-starter-alibaba-nacos-config
</artifactId>
<version>
2.2.6.RELEASE
</version>
</dependency>
<dependency>
<groupId>
com.platform
</groupId>
<artifactId>
practical-auth-api
</artifactId>
<version>
1.0.0
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-security
</artifactId>
</dependency>
<dependency>
<groupId>
io.jsonwebtoken
</groupId>
<artifactId>
jjwt-api
</artifactId>
<version>
0.11.5
</version>
</dependency>
<dependency>
<groupId>
io.jsonwebtoken
</groupId>
<artifactId>
jjwt-impl
</artifactId>
<version>
0.11.5
</version>
<scope>
runtime
</scope>
</dependency>
<dependency>
<groupId>
io.jsonwebtoken
</groupId>
<artifactId>
jjwt-jackson
</artifactId>
<version>
0.11.5
</version>
<scope>
runtime
</scope>
</dependency>
<!-- logstash -->
<!-- <dependency>-->
<!-- <groupId>net.logstash.logback</groupId>-->
<!-- <artifactId>logstash-logback-encoder</artifactId>-->
<!-- <version>7.1.1</version>-->
<!-- </dependency>-->
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-dependencies
</artifactId>
<version>
${spring.boot.version}
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<version>
${spring.boot.version}
</version>
<configuration>
<mainClass>
com.platform.auth.PracticalAuthApplication
</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>
repackage
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
practical-auth/src/main/java/com/platform/auth/PracticalAuthApplication.java
0 → 100644
View file @
cd112ea9
package
com.platform.auth
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
@SpringBootApplication
public
class
PracticalAuthApplication
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
PracticalAuthApplication
.
class
,
args
);
}
}
practical-auth/src/main/java/com/platform/auth/config/SecurityConfig.java
0 → 100644
View file @
cd112ea9
package
com.platform.auth.config
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
import
org.springframework.security.config.http.SessionCreationPolicy
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.security.crypto.password.PasswordEncoder
;
@Configuration
public
class
SecurityConfig
extends
WebSecurityConfigurerAdapter
{
@Override
protected
void
configure
(
HttpSecurity
http
)
throws
Exception
{
http
.
csrf
().
disable
()
.
authorizeRequests
()
.
antMatchers
(
"/login/**"
).
permitAll
()
.
anyRequest
().
authenticated
()
.
and
()
.
sessionManagement
().
sessionCreationPolicy
(
SessionCreationPolicy
.
STATELESS
);
}
@Bean
public
PasswordEncoder
passwordEncoder
()
{
return
new
BCryptPasswordEncoder
();
}
}
\ No newline at end of file
practical-auth/src/main/java/com/platform/auth/controller/UserController.java
0 → 100644
View file @
cd112ea9
package
com.platform.auth.controller
;
import
com.platform.auth.model.dto.UserDTO
;
import
com.platform.auth.model.vo.UserVO
;
import
com.platform.auth.service.UserService
;
import
com.platform.model.resp.Result
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
@RestController
@RequestMapping
(
"/login"
)
public
class
UserController
{
@Resource
private
UserService
userService
;
@PostMapping
(
"/in"
)
public
Result
<
UserVO
>
login
(
@RequestBody
UserDTO
userDTO
)
{
return
userService
.
login
(
userDTO
);
}
}
\ No newline at end of file
practical-auth/src/main/java/com/platform/auth/exception/GlobalExceptionHandler.java
0 → 100644
View file @
cd112ea9
package
com.platform.auth.exception
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
@RestControllerAdvice
public
class
GlobalExceptionHandler
{
@ExceptionHandler
(
RuntimeException
.
class
)
public
ResponseEntity
<
String
>
handleRuntimeException
(
RuntimeException
e
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
UNAUTHORIZED
).
body
(
e
.
getMessage
());
}
}
\ No newline at end of file
practical-auth/src/main/java/com/platform/auth/mapper/RoleMapper.java
0 → 100644
View file @
cd112ea9
package
com.platform.auth.mapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.platform.auth.model.entity.RoleEntity
;
import
org.apache.ibatis.annotations.Mapper
;
@Mapper
public
interface
RoleMapper
extends
BaseMapper
<
RoleEntity
>
{
}
practical-auth/src/main/java/com/platform/auth/mapper/USerMapper.java
0 → 100644
View file @
cd112ea9
package
com.platform.auth.mapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.platform.auth.model.entity.User
;
import
org.apache.ibatis.annotations.Mapper
;
/**
* @author : wujipeng
* @date : 2025/7/31 14:42
* @Version: 1.0
* @Desc : 描述信息
*/
@Mapper
public
interface
USerMapper
extends
BaseMapper
<
User
>
{
}
practical-auth/src/main/java/com/platform/auth/mapper/UserRoleMapper.java
0 → 100644
View file @
cd112ea9
package
com.platform.auth.mapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.platform.auth.model.entity.UserRoleEntity
;
import
com.platform.auth.model.vo.UserRoleVO
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
@Mapper
public
interface
UserRoleMapper
extends
BaseMapper
<
UserRoleEntity
>
{
/**
* 查看用户角色信息
*
* @param id id
* @return List<RoleEntity>
*/
List
<
UserRoleVO
>
queryUserRoleList
(
String
id
);
/**
* 查看用户考试类型
*
* @param id id
* @return String
*/
String
queryExamType
(
@Param
(
"id"
)
String
id
);
/**
* 查看用户考试id
*
* @param id id
* @return String
*/
Integer
queryExamId
(
@Param
(
"id"
)
String
id
);
}
practical-auth/src/main/java/com/platform/auth/service/RoleService.java
0 → 100644
View file @
cd112ea9
package
com.platform.auth.service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.platform.auth.model.entity.RoleEntity
;
public
interface
RoleService
extends
IService
<
RoleEntity
>
{
}
practical-auth/src/main/java/com/platform/auth/service/UserRoleService.java
0 → 100644
View file @
cd112ea9
package
com.platform.auth.service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.platform.auth.model.entity.RoleEntity
;
import
com.platform.auth.model.entity.UserRoleEntity
;
import
com.platform.auth.model.vo.UserRoleVO
;
import
java.util.List
;
public
interface
UserRoleService
extends
IService
<
UserRoleEntity
>
{
/**
* 查看用户角色
*
* @param id 用户Id
* @return List<RoleEntity>
*/
List
<
UserRoleVO
>
queryUserRoleList
(
String
id
);
/**
* 查看用户考试类型
*
* @param id 用户Id
* @return String
*/
String
queryExamType
(
String
id
);
/**
* 查看用户考试id
*
* @param id 用户Id
* @return String
*/
Integer
queryExamId
(
String
id
);
}
practical-auth/src/main/java/com/platform/auth/service/UserService.java
0 → 100644
View file @
cd112ea9
package
com.platform.auth.service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.platform.auth.model.dto.UserDTO
;
import
com.platform.auth.model.entity.User
;
import
com.platform.auth.model.vo.UserVO
;
import
com.platform.model.resp.Result
;
/**
* @author : wujipeng
* @date : 2025/7/31 14:45
* @Version: 1.0
* @Desc : 描述信息
*/
public
interface
UserService
extends
IService
<
User
>
{
Result
<
UserVO
>
login
(
UserDTO
userDTO
);
}
practical-auth/src/main/java/com/platform/auth/service/impl/RoleServiceImpl.java
0 → 100644
View file @
cd112ea9
package
com.platform.auth.service.impl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.platform.auth.mapper.RoleMapper
;
import
com.platform.auth.model.entity.RoleEntity
;
import
com.platform.auth.service.RoleService
;
import
org.springframework.stereotype.Service
;
@Service
public
class
RoleServiceImpl
extends
ServiceImpl
<
RoleMapper
,
RoleEntity
>
implements
RoleService
{
}
practical-auth/src/main/java/com/platform/auth/service/impl/UserRoleServiceImpl.java
0 → 100644
View file @
cd112ea9
package
com.platform.auth.service.impl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.platform.auth.mapper.UserRoleMapper
;
import
com.platform.auth.model.entity.UserRoleEntity
;
import
com.platform.auth.model.vo.UserRoleVO
;
import
com.platform.auth.service.UserRoleService
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
@Service
public
class
UserRoleServiceImpl
extends
ServiceImpl
<
UserRoleMapper
,
UserRoleEntity
>
implements
UserRoleService
{
@Override
public
List
<
UserRoleVO
>
queryUserRoleList
(
String
id
)
{
return
baseMapper
.
queryUserRoleList
(
id
);
}
@Override
public
String
queryExamType
(
String
id
)
{
return
baseMapper
.
queryExamType
(
id
);
}
@Override
public
Integer
queryExamId
(
String
id
)
{
return
baseMapper
.
queryExamId
(
id
);
}
}
practical-auth/src/main/java/com/platform/auth/service/impl/UserServiceImpl.java
0 → 100644
View file @
cd112ea9
package
com.platform.auth.service.impl
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.platform.auth.mapper.USerMapper
;
import
com.platform.auth.model.dto.UserDTO
;
import
com.platform.auth.model.entity.User
;
import
com.platform.auth.model.vo.UserRoleVO
;
import
com.platform.auth.model.vo.UserVO
;
import
com.platform.auth.service.UserRoleService
;
import
com.platform.auth.service.UserService
;
import
com.platform.auth.utils.JwtTokenUtil
;
import
com.platform.auth.utils.PasswordUtil
;
import
com.platform.model.resp.Result
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.Date
;
import
java.util.List
;
@Service
public
class
UserServiceImpl
extends
ServiceImpl
<
USerMapper
,
User
>
implements
UserService
{
@Resource
private
JwtTokenUtil
jwtTokenUtil
;
@Resource
private
PasswordUtil
passwordUtil
;
@Resource
private
UserRoleService
userRoleService
;
@Override
public
Result
<
UserVO
>
login
(
UserDTO
loginRequest
)
{
User
user
=
baseMapper
.
selectOne
(
new
LambdaQueryWrapper
<
User
>()
.
eq
(
User:
:
getPhoneNumber
,
loginRequest
.
getPhoneNumber
()));
if
(
user
==
null
)
{
return
Result
.
fail
(
"用户不存在"
);
}
//判断是否禁用
if
(
user
.
getDelFlag
())
{
return
Result
.
fail
(
"用户已禁用"
);
}
if
(!
passwordUtil
.
matches
(
loginRequest
.
getPassword
(),
user
.
getPassword
()))
{
// 更新登录失败次数
user
.
setLoginFailNum
(
user
.
getLoginFailNum
()
+
1
);
updateById
(
user
);
return
Result
.
fail
(
"密码错误"
);
}
// 重置登录失败次数
user
.
setLoginFailNum
(
0
);
user
.
setLoginDate
(
new
Date
());
user
.
setFirstLoginFlag
(
false
);
updateById
(
user
);
// 生成token
String
token
=
jwtTokenUtil
.
generateToken
(
user
.
getPhoneNumber
());
//查看用户角色
List
<
UserRoleVO
>
userRoleVOList
=
userRoleService
.
queryUserRoleList
(
user
.
getId
());
//查询是否有考试
// String type = userRoleService.queryExamType(user.getId());
//查询考试id
Integer
examId
=
userRoleService
.
queryExamId
(
user
.
getId
());
UserVO
response
=
new
UserVO
();
if
(
examId
==
null
){
response
.
setType
(
"演示"
);
}
else
{
response
.
setExamId
(
examId
);
response
.
setType
(
"考试"
);
}
response
.
setToken
(
token
);
response
.
setId
(
user
.
getId
());
response
.
setIdType
(
user
.
getIdType
());
response
.
setUserRoleList
(
userRoleVOList
);
response
.
setUsername
(
user
.
getUsername
());
response
.
setNickName
(
user
.
getNickName
());
response
.
setPhoneNumber
(
user
.
getPhoneNumber
());
response
.
setFirstLogin
(
user
.
getFirstLoginFlag
());
response
.
setLevel
(
user
.
getLevel
());
response
.
setExamFlag
(
user
.
getExamFlag
());
response
.
setExamOneselfId
(
user
.
getExamOneselfId
());
return
Result
.
data
(
response
);
}
}
\ No newline at end of file
practical-auth/src/main/java/com/platform/auth/utils/JwtTokenUtil.java
0 → 100644
View file @
cd112ea9
package
com.platform.auth.utils
;
import
io.jsonwebtoken.Claims
;
import
io.jsonwebtoken.Jwts
;
import
io.jsonwebtoken.SignatureAlgorithm
;
import
io.jsonwebtoken.security.Keys
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
javax.crypto.SecretKey
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.function.Function
;
@Component
public
class
JwtTokenUtil
{
@Value
(
"${jwt.secret}"
)
private
String
secret
;
@Value
(
"${jwt.expiration}"
)
private
Long
expiration
;
// 生成密钥
private
SecretKey
getSigningKey
()
{
return
Keys
.
hmacShaKeyFor
(
secret
.
getBytes
());
}
// 生成token
public
String
generateToken
(
String
username
)
{
Map
<
String
,
Object
>
claims
=
new
HashMap
<>();
return
createToken
(
claims
,
username
);
}
private
String
createToken
(
Map
<
String
,
Object
>
claims
,
String
subject
)
{
return
Jwts
.
builder
()
.
setClaims
(
claims
)
.
setSubject
(
subject
)
.
setIssuedAt
(
new
Date
(
System
.
currentTimeMillis
()))
.
setExpiration
(
new
Date
(
System
.
currentTimeMillis
()
+
expiration
*
1000
))
.
signWith
(
getSigningKey
(),
SignatureAlgorithm
.
HS256
)
.
compact
();
}
// 从token中获取用户名
public
String
getUsernameFromToken
(
String
token
)
{
return
getClaimFromToken
(
token
,
Claims:
:
getSubject
);
}
// 从token中获取过期时间
public
Date
getExpirationDateFromToken
(
String
token
)
{
return
getClaimFromToken
(
token
,
Claims:
:
getExpiration
);
}
public
<
T
>
T
getClaimFromToken
(
String
token
,
Function
<
Claims
,
T
>
claimsResolver
)
{
final
Claims
claims
=
getAllClaimsFromToken
(
token
);
return
claimsResolver
.
apply
(
claims
);
}
private
Claims
getAllClaimsFromToken
(
String
token
)
{
return
Jwts
.
parserBuilder
()
.
setSigningKey
(
getSigningKey
())
.
build
()
.
parseClaimsJws
(
token
)
.
getBody
();
}
// 验证token是否过期
private
Boolean
isTokenExpired
(
String
token
)
{
final
Date
expiration
=
getExpirationDateFromToken
(
token
);
return
expiration
.
before
(
new
Date
());
}
// 验证token
public
Boolean
validateToken
(
String
token
,
String
username
)
{
final
String
tokenUsername
=
getUsernameFromToken
(
token
);
return
(
tokenUsername
.
equals
(
username
)
&&
!
isTokenExpired
(
token
));
}
}
\ No newline at end of file
practical-auth/src/main/java/com/platform/auth/utils/PasswordUtil.java
0 → 100644
View file @
cd112ea9
package
com.platform.auth.utils
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.stereotype.Component
;
@Component
public
class
PasswordUtil
{
private
final
BCryptPasswordEncoder
passwordEncoder
=
new
BCryptPasswordEncoder
();
public
String
encodePassword
(
String
rawPassword
)
{
return
passwordEncoder
.
encode
(
rawPassword
);
}
public
boolean
matches
(
String
rawPassword
,
String
encodedPassword
)
{
return
passwordEncoder
.
matches
(
rawPassword
,
encodedPassword
);
}
}
\ No newline at end of file
practical-auth/src/main/resources/bootstrap-dev.yml
0 → 100644
View file @
cd112ea9
spring
:
application
:
name
:
practical-train-auth
# 配置中心
cloud
:
nacos
:
discovery
:
server-addr
:
${NACOS-HOST:192.168.10.3}:${NACOS-PORT:6001}
namespace
:
272b9958-7a2d-41f8-ba0b-fdcb7ee8ead0
config
:
server-addr
:
${spring.cloud.nacos.discovery.server-addr}
file-extension
:
yml
namespace
:
272b9958-7a2d-41f8-ba0b-fdcb7ee8ead0
shared-configs
:
-
application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
practical-auth/src/main/resources/bootstrap-prd.yml
0 → 100644
View file @
cd112ea9
spring
:
application
:
name
:
practical-train-auth
# 配置中心
cloud
:
nacos
:
discovery
:
server-addr
:
${NACOS-HOST:47.111.94.26}:${NACOS-PORT:8848}
namespace
:
272b9958-7a2d-41f8-ba0b-fdcb7ee8ead0
config
:
server-addr
:
${spring.cloud.nacos.discovery.server-addr}
file-extension
:
yml
namespace
:
272b9958-7a2d-41f8-ba0b-fdcb7ee8ead0
shared-configs
:
-
application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
\ No newline at end of file
Prev
1
2
3
4
5
6
7
8
9
10
…
17
Next
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