Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-microservice-exam
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
汪想
spring-microservice-exam
Commits
9ca661d9
Commit
9ca661d9
authored
Jul 14, 2019
by
tangyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加学生模块,优化缓存失效时间
parent
e9194a2d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
41 changed files
with
965 additions
and
62 deletions
+965
-62
CHANGELOG.md
CHANGELOG.md
+6
-0
MultitenantCacheManager.java
...hub/tangyi/common/core/cache/MultitenantCacheManager.java
+8
-4
AppStartupRunner.java
...om/github/tangyi/common/core/config/AppStartupRunner.java
+30
-0
RedisConfig.java
...ava/com/github/tangyi/common/core/config/RedisConfig.java
+13
-27
CommonConstant.java
...om/github/tangyi/common/core/constant/CommonConstant.java
+6
-1
SysProperties.java
...m/github/tangyi/common/core/properties/SysProperties.java
+7
-1
auth-service.yml
config-service/src/main/resources/config/auth-service.yml
+1
-0
exam-service.yml
config-service/src/main/resources/config/exam-service.yml
+4
-0
gateway-service.yml
config-service/src/main/resources/config/gateway-service.yml
+1
-0
user-service.yml
config-service/src/main/resources/config/user-service.yml
+1
-0
microservice-user.sql
docs/deploy/mysql/init/microservice-user.sql
+0
-0
在线考试.pdb
docs/产品设计/数据库设计/在线考试.pdb
+0
-0
在线考试.pdm
docs/产品设计/数据库设计/在线考试.pdm
+0
-0
README.md
service-api-impl/auth-service/README.md
+29
-0
AnswerService.java
...in/java/com/github/tangyi/exam/service/AnswerService.java
+1
-1
CourseService.java
...in/java/com/github/tangyi/exam/service/CourseService.java
+2
-1
ExamRecordService.java
...ava/com/github/tangyi/exam/service/ExamRecordService.java
+2
-1
ExaminationService.java
...va/com/github/tangyi/exam/service/ExaminationService.java
+2
-1
KnowledgeService.java
...java/com/github/tangyi/exam/service/KnowledgeService.java
+2
-1
SubjectCategoryService.java
...om/github/tangyi/exam/service/SubjectCategoryService.java
+2
-1
SubjectChoicesService.java
...com/github/tangyi/exam/service/SubjectChoicesService.java
+2
-1
SubjectShortAnswerService.java
...github/tangyi/exam/service/SubjectShortAnswerService.java
+2
-1
SwaggerConfig.java
...ain/java/com/github/tangyi/user/config/SwaggerConfig.java
+2
-0
StudentController.java
.../com/github/tangyi/user/controller/StudentController.java
+195
-0
UserController.java
...ava/com/github/tangyi/user/controller/UserController.java
+13
-5
StudentMapper.java
...ain/java/com/github/tangyi/user/mapper/StudentMapper.java
+15
-0
UserStudentMapper.java
...java/com/github/tangyi/user/mapper/UserStudentMapper.java
+49
-0
AttachmentService.java
...ava/com/github/tangyi/user/service/AttachmentService.java
+2
-1
MenuService.java
...main/java/com/github/tangyi/user/service/MenuService.java
+4
-5
RoleService.java
...main/java/com/github/tangyi/user/service/RoleService.java
+2
-1
StudentService.java
...n/java/com/github/tangyi/user/service/StudentService.java
+63
-0
TenantService.java
...in/java/com/github/tangyi/user/service/TenantService.java
+2
-1
UserService.java
...main/java/com/github/tangyi/user/service/UserService.java
+23
-5
UserStudentService.java
...va/com/github/tangyi/user/service/UserStudentService.java
+70
-0
StudentMapper.xml
.../user-service/src/main/resources/mapper/StudentMapper.xml
+146
-0
UserStudentMapper.xml
...r-service/src/main/resources/mapper/UserStudentMapper.xml
+87
-0
StudentDto.java
.../main/java/com/github/tangyi/user/api/dto/StudentDto.java
+85
-0
UserDto.java
...src/main/java/com/github/tangyi/user/api/dto/UserDto.java
+0
-1
Student.java
.../main/java/com/github/tangyi/user/api/module/Student.java
+56
-0
UserAuths.java
...ain/java/com/github/tangyi/user/api/module/UserAuths.java
+1
-2
UserStudent.java
...n/java/com/github/tangyi/user/api/module/UserStudent.java
+29
-0
No files found.
CHANGELOG.md
View file @
9ca661d9
Version v3.0.0 (2019-7-6)
--------------------------
改进:
*
优化缓存失效时间
Version v3.0.0 (2019-7-6)
--------------------------
新功能:
...
...
common/common-core/src/main/java/com/github/tangyi/common/core/cache/MultitenantCacheManager.java
View file @
9ca661d9
package
com
.
github
.
tangyi
.
common
.
core
.
cache
;
import
com.github.tangyi.common.security.tenant.TenantContextHolder
;
import
com.github.tangyi.common.core.utils.SysUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
...
...
@@ -40,17 +39,22 @@ public class MultitenantCacheManager extends RedisCacheManager {
*/
@Override
protected
RedisCache
createRedisCache
(
String
name
,
RedisCacheConfiguration
cacheConfig
)
{
if
(
StringUtils
.
isNotBlank
(
name
)
||
!
name
.
contains
(
SPLIT_FLAG
))
if
(
StringUtils
.
isBlank
(
name
)
||
!
name
.
contains
(
SPLIT_FLAG
))
{
log
.
debug
(
"create cache name[{}]"
,
name
);
return
super
.
createRedisCache
(
name
,
cacheConfig
);
}
String
[]
cacheArray
=
name
.
split
(
SPLIT_FLAG
);
if
(
cacheArray
.
length
<
CACHE_LENGTH
)
{
log
.
debug
(
"create cache name[{}]"
,
name
);
return
super
.
createRedisCache
(
name
,
cacheConfig
);
}
String
cacheName
=
cacheArray
[
0
]
+
":"
+
TenantContextHolder
.
getTenantCode
()
;
String
cacheName
=
cacheArray
[
0
];
if
(
cacheConfig
!=
null
)
{
// 从系统属性里读取超时时间
long
cacheAge
=
Long
.
getLong
(
cacheArray
[
1
],
-
1
);
cacheConfig
=
cacheConfig
.
entryTtl
(
Duration
.
ofSeconds
(
cacheAge
));
}
log
.
debug
(
"create cache[{}]"
,
cacheName
);
return
super
.
createRedisCache
(
cacheName
,
cacheConfig
);
}
...
...
@@ -63,7 +67,7 @@ public class MultitenantCacheManager extends RedisCacheManager {
@Override
public
Cache
getCache
(
String
name
)
{
name
=
SysUtil
.
getTenantCode
()
+
":"
+
name
;
log
.
info
(
"
cache name: {}
"
,
name
);
log
.
info
(
"
get cache[{}]
"
,
name
);
return
super
.
getCache
(
name
);
}
}
common/common-core/src/main/java/com/github/tangyi/common/core/config/AppStartupRunner.java
0 → 100644
View file @
9ca661d9
package
com
.
github
.
tangyi
.
common
.
core
.
config
;
import
com.github.tangyi.common.core.constant.CommonConstant
;
import
com.github.tangyi.common.core.properties.SysProperties
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.boot.CommandLineRunner
;
import
org.springframework.stereotype.Component
;
/**
* 系统启动时的一些处理
*
* @author tangyi
* @date 2019/07/14 16:09
*/
@Slf4j
@AllArgsConstructor
@Component
public
class
AppStartupRunner
implements
CommandLineRunner
{
private
final
SysProperties
sysProperties
;
@Override
public
void
run
(
String
...
args
)
throws
Exception
{
log
.
info
(
"start command line..."
);
log
.
info
(
"set system properties..."
);
// 设置系统属性
System
.
setProperty
(
CommonConstant
.
CACHE_EXPIRE
,
sysProperties
.
getCacheExpire
());
}
}
common/common-core/src/main/java/com/github/tangyi/common/core/config/RedisConfig.java
View file @
9ca661d9
...
...
@@ -2,6 +2,9 @@ package com.github.tangyi.common.core.config;
import
com.github.tangyi.common.core.cache.CustomRedisCacheWriter
;
import
com.github.tangyi.common.core.cache.MultitenantCacheManager
;
import
org.springframework.beans.factory.ObjectProvider
;
import
org.springframework.boot.autoconfigure.cache.CacheManagerCustomizer
;
import
org.springframework.boot.autoconfigure.cache.CacheManagerCustomizers
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -9,11 +12,12 @@ import org.springframework.data.redis.cache.RedisCacheConfiguration;
import
org.springframework.data.redis.cache.RedisCacheManager
;
import
org.springframework.data.redis.cache.RedisCacheWriter
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.core.
*
;
import
org.springframework.data.redis.core.
RedisTemplate
;
import
org.springframework.data.redis.serializer.JdkSerializationRedisSerializer
;
import
org.springframework.data.redis.serializer.StringRedisSerializer
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
...
...
@@ -34,8 +38,6 @@ public class RedisConfig {
redisTemplate
.
setHashKeySerializer
(
new
StringRedisSerializer
());
redisTemplate
.
setValueSerializer
(
new
JdkSerializationRedisSerializer
());
redisTemplate
.
setHashValueSerializer
(
new
JdkSerializationRedisSerializer
());
// 开启事务
redisTemplate
.
setEnableTransactionSupport
(
true
);
redisTemplate
.
setConnectionFactory
(
redisConnectionFactory
);
return
redisTemplate
;
}
...
...
@@ -46,35 +48,19 @@ public class RedisConfig {
* @return RedisCacheManager
*/
@Bean
public
RedisCacheManager
cacheManager
(
RedisConnectionFactory
connectionFactory
)
{
public
RedisCacheManager
cacheManager
(
RedisConnectionFactory
connectionFactory
,
CacheManagerCustomizers
customizerInvoker
)
{
RedisCacheWriter
redisCacheWriter
=
new
CustomRedisCacheWriter
(
connectionFactory
);
RedisCacheConfiguration
redisCacheConfiguration
=
RedisCacheConfiguration
.
defaultCacheConfig
();
Map
<
String
,
RedisCacheConfiguration
>
initialCacheConfigurations
=
new
LinkedHashMap
<>();
return
new
MultitenantCacheManager
(
redisCacheWriter
,
redisCacheConfiguration
,
initialCacheConfigurations
,
true
);
// 多租户cacheManager
RedisCacheManager
cacheManager
=
new
MultitenantCacheManager
(
redisCacheWriter
,
redisCacheConfiguration
,
initialCacheConfigurations
,
true
);
cacheManager
.
setTransactionAware
(
false
);
return
customizerInvoker
.
customize
(
cacheManager
);
}
@Bean
public
HashOperations
<
String
,
String
,
Object
>
hashOperations
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
return
redisTemplate
.
opsForHash
();
}
@Bean
public
ValueOperations
<
String
,
String
>
valueOperations
(
RedisTemplate
<
String
,
String
>
redisTemplate
)
{
return
redisTemplate
.
opsForValue
();
}
@Bean
public
ListOperations
<
String
,
Object
>
listOperations
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
return
redisTemplate
.
opsForList
();
}
@Bean
public
SetOperations
<
String
,
Object
>
setOperations
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
return
redisTemplate
.
opsForSet
();
}
@Bean
public
ZSetOperations
<
String
,
Object
>
zSetOperations
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
return
redisTemplate
.
opsForZSet
();
public
CacheManagerCustomizers
cacheManagerCustomizers
(
ObjectProvider
<
List
<
CacheManagerCustomizer
<?>>>
customizers
)
{
return
new
CacheManagerCustomizers
(
customizers
.
getIfAvailable
());
}
}
common/common-core/src/main/java/com/github/tangyi/common/core/constant/CommonConstant.java
View file @
9ca661d9
...
...
@@ -131,7 +131,7 @@ public class CommonConstant {
/**
* 验证码长度
*/
public
static
final
String
CODE_SIZE
=
"
4
"
;
public
static
final
String
CODE_SIZE
=
"
6
"
;
/**
* Bearer
...
...
@@ -158,5 +158,10 @@ public class CommonConstant {
*/
public
static
final
String
TENANT_CODE_HEADER
=
"Tenant-Code"
;
/**
* 默认超时时间
*/
public
static
final
String
CACHE_EXPIRE
=
"CACHE_EXPIRE"
;
}
common/common-core/src/main/java/com/github/tangyi/common/core/properties/SysProperties.java
View file @
9ca661d9
package
com
.
github
.
tangyi
.
common
.
core
.
properties
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
lombok.Data
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.annotation.Configuration
;
import
javax.annotation.PostConstruct
;
/**
* @author tangyi
* @date 2019/4/26 11:54
...
...
@@ -38,4 +39,9 @@ public class SysProperties {
* 密码加密解密的key
*/
private
String
key
;
/**
* 缓存超时时间
*/
private
String
cacheExpire
;
}
config-service/src/main/resources/config/auth-service.yml
View file @
9ca661d9
...
...
@@ -121,6 +121,7 @@ sys:
uploadUrl
:
api/user/v1/attachment/upload
defaultAvatar
:
https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif?imageView2/1/w/80/h/80
key
:
'
1234567887654321'
cacheExpire
:
86400
# 缓存失效时间,单位秒,默认一天
# 微信配置
wx
:
...
...
config-service/src/main/resources/config/exam-service.yml
View file @
9ca661d9
...
...
@@ -73,6 +73,10 @@ pagehelper:
supportMethodsArguments
:
true
params
:
count=countSql
# 系统配置
sys
:
cacheExpire
:
86400
# 缓存失效时间,单位秒,默认一天
# feign相关配置
feign
:
httpclient
:
...
...
config-service/src/main/resources/config/gateway-service.yml
View file @
9ca661d9
...
...
@@ -35,6 +35,7 @@ sys:
uploadUrl
:
api/user/v1/attachment/upload
defaultAvatar
:
https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif?imageView2/1/w/80/h/80
key
:
'
1234567887654321'
cacheExpire
:
86400
# 缓存失效时间,单位秒,默认一天
# feign相关配置
feign
:
...
...
config-service/src/main/resources/config/user-service.yml
View file @
9ca661d9
...
...
@@ -98,6 +98,7 @@ sys:
uploadUrl
:
api/user/v1/attachment/upload
defaultAvatar
:
https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif?imageView2/1/w/80/h/80
key
:
'
1234567887654321'
cacheExpire
:
86400
# 缓存失效时间,单位秒,默认一天
# feign相关配置
feign
:
...
...
docs/deploy/mysql/init/microservice-user.sql
View file @
9ca661d9
This diff is collapsed.
Click to expand it.
docs/产品设计/数据库设计/在线考试.pdb
View file @
9ca661d9
This diff is collapsed.
Click to expand it.
docs/产品设计/数据库设计/在线考试.pdm
View file @
9ca661d9
This diff is collapsed.
Click to expand it.
service-api-impl/auth-service/README.md
View file @
9ca661d9
...
...
@@ -194,4 +194,32 @@ export const encryption = (params) => {
}
return result
}
```
#### 刷新token
用于token失效后(token有效期默认为一个小时),根据refresh_token重新获取token
1.
token失效:token失效后,请求的api接口会统一返回403,可以定义http请求的拦截器,判断后端返回的状态码是否为403,是则尝试刷新token
2.
根据不同的认证方式,
`POST`
到对应的认证URL,设置参数
`grant_type=refresh_token、scope、refresh_token`
,如账号密码登录方式下的刷新token:
```
/**
* 刷新token
*/
export function refreshToken () {
// grant_type为refresh_token
const grantType = 'refresh_token'
const scope = 'read'
// refresh_token的具体值在登录获取token的时候返回的
const refreshToken = {refresh_token}
return request({
url: '/api/auth/oauth/token',
headers: {
'Authorization': 'Basic ' + btoa('web_app:spring-microservice-exam-secret')
},
method: 'post',
params: { grant_type: grantType, scope, refresh_token: refreshToken }
})
}
```
\ No newline at end of file
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/service/AnswerService.java
View file @
9ca661d9
...
...
@@ -66,7 +66,7 @@ public class AnswerService extends CrudService<AnswerMapper, Answer> {
* @date 2019/1/3 14:27
*/
@Override
@Cacheable
(
value
=
"answer
"
,
key
=
"#answer.id"
)
@Cacheable
(
value
=
"answer
#"
+
CommonConstant
.
CACHE_EXPIRE
,
key
=
"#answer.id"
)
public
Answer
get
(
Answer
answer
)
{
return
super
.
get
(
answer
);
}
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/service/CourseService.java
View file @
9ca661d9
package
com
.
github
.
tangyi
.
exam
.
service
;
import
com.github.tangyi.common.core.constant.CommonConstant
;
import
com.github.tangyi.common.core.service.CrudService
;
import
com.github.tangyi.exam.api.module.Course
;
import
com.github.tangyi.exam.mapper.CourseMapper
;
...
...
@@ -26,7 +27,7 @@ public class CourseService extends CrudService<CourseMapper, Course> {
* @date 2018/12/03 21:30
*/
@Override
@Cacheable
(
value
=
"course
"
,
key
=
"#course.id"
)
@Cacheable
(
value
=
"course
#"
+
CommonConstant
.
CACHE_EXPIRE
,
key
=
"#course.id"
)
public
Course
get
(
Course
course
)
{
return
super
.
get
(
course
);
}
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/service/ExamRecordService.java
View file @
9ca661d9
package
com
.
github
.
tangyi
.
exam
.
service
;
import
com.github.tangyi.common.core.constant.CommonConstant
;
import
com.github.tangyi.common.core.service.CrudService
;
import
com.github.tangyi.exam.api.module.ExaminationRecord
;
import
com.github.tangyi.exam.mapper.ExamRecordMapper
;
...
...
@@ -28,7 +29,7 @@ public class ExamRecordService extends CrudService<ExamRecordMapper, Examination
* @date 2019/1/3 14:10
*/
@Override
@Cacheable
(
value
=
"record
"
,
key
=
"#examRecord.id"
)
@Cacheable
(
value
=
"record
#"
+
CommonConstant
.
CACHE_EXPIRE
,
key
=
"#examRecord.id"
)
public
ExaminationRecord
get
(
ExaminationRecord
examRecord
)
{
return
super
.
get
(
examRecord
);
}
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/service/ExaminationService.java
View file @
9ca661d9
package
com
.
github
.
tangyi
.
exam
.
service
;
import
com.github.pagehelper.PageInfo
;
import
com.github.tangyi.common.core.constant.CommonConstant
;
import
com.github.tangyi.common.core.service.CrudService
;
import
com.github.tangyi.common.core.utils.PageUtil
;
import
com.github.tangyi.common.core.utils.SysUtil
;
...
...
@@ -46,7 +47,7 @@ public class ExaminationService extends CrudService<ExaminationMapper, Examinati
* @date 2019/1/3 14:06
*/
@Override
@Cacheable
(
value
=
"examination
"
,
key
=
"#examination.id"
)
@Cacheable
(
value
=
"examination
#"
+
CommonConstant
.
CACHE_EXPIRE
,
key
=
"#examination.id"
)
public
Examination
get
(
Examination
examination
)
{
return
super
.
get
(
examination
);
}
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/service/KnowledgeService.java
View file @
9ca661d9
package
com
.
github
.
tangyi
.
exam
.
service
;
import
com.github.tangyi.common.core.constant.CommonConstant
;
import
com.github.tangyi.common.core.service.CrudService
;
import
com.github.tangyi.exam.api.module.Knowledge
;
import
com.github.tangyi.exam.mapper.KnowledgeMapper
;
...
...
@@ -26,7 +27,7 @@ public class KnowledgeService extends CrudService<KnowledgeMapper, Knowledge> {
* @date 2019/1/1 15:09
*/
@Override
@Cacheable
(
value
=
"knowledge
"
,
key
=
"#knowledge.id"
)
@Cacheable
(
value
=
"knowledge
#"
+
CommonConstant
.
CACHE_EXPIRE
,
key
=
"#knowledge.id"
)
public
Knowledge
get
(
Knowledge
knowledge
)
{
return
super
.
get
(
knowledge
);
}
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/service/SubjectCategoryService.java
View file @
9ca661d9
package
com
.
github
.
tangyi
.
exam
.
service
;
import
com.github.tangyi.common.core.constant.CommonConstant
;
import
com.github.tangyi.common.core.service.CrudService
;
import
com.github.tangyi.exam.api.module.SubjectCategory
;
import
com.github.tangyi.exam.mapper.SubjectCategoryMapper
;
...
...
@@ -26,7 +27,7 @@ public class SubjectCategoryService extends CrudService<SubjectCategoryMapper, S
* @date 2019/1/3 14:21
*/
@Override
@Cacheable
(
value
=
"category
"
,
key
=
"#subjectCategory.id"
)
@Cacheable
(
value
=
"category
#"
+
CommonConstant
.
CACHE_EXPIRE
,
key
=
"#subjectCategory.id"
)
public
SubjectCategory
get
(
SubjectCategory
subjectCategory
)
{
return
super
.
get
(
subjectCategory
);
}
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/service/SubjectChoicesService.java
View file @
9ca661d9
package
com
.
github
.
tangyi
.
exam
.
service
;
import
com.github.pagehelper.PageInfo
;
import
com.github.tangyi.common.core.constant.CommonConstant
;
import
com.github.tangyi.common.core.service.CrudService
;
import
com.github.tangyi.exam.api.dto.SubjectDto
;
import
com.github.tangyi.exam.api.module.ExaminationSubject
;
...
...
@@ -41,7 +42,7 @@ public class SubjectChoicesService extends CrudService<SubjectChoicesMapper, Sub
* @date 2019/1/3 14:24
*/
@Override
@Cacheable
(
value
=
"subjectChoices
"
,
key
=
"#subjectChoices.id"
)
@Cacheable
(
value
=
"subjectChoices
#"
+
CommonConstant
.
CACHE_EXPIRE
,
key
=
"#subjectChoices.id"
)
public
SubjectChoices
get
(
SubjectChoices
subjectChoices
)
{
SubjectChoices
subject
=
super
.
get
(
subjectChoices
);
// 查找选项信息
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/service/SubjectShortAnswerService.java
View file @
9ca661d9
package
com
.
github
.
tangyi
.
exam
.
service
;
import
com.github.pagehelper.PageInfo
;
import
com.github.tangyi.common.core.constant.CommonConstant
;
import
com.github.tangyi.common.core.service.CrudService
;
import
com.github.tangyi.exam.api.dto.SubjectDto
;
import
com.github.tangyi.exam.api.module.SubjectShortAnswer
;
...
...
@@ -32,7 +33,7 @@ public class SubjectShortAnswerService extends CrudService<SubjectShortAnswerMap
* @date 2019/6/16 14:58
*/
@Override
@Cacheable
(
value
=
"subjectShortAnswer
"
,
key
=
"#subjectShortAnswer.id"
)
@Cacheable
(
value
=
"subjectShortAnswer
#"
+
CommonConstant
.
CACHE_EXPIRE
,
key
=
"#subjectShortAnswer.id"
)
public
SubjectShortAnswer
get
(
SubjectShortAnswer
subjectShortAnswer
)
{
return
super
.
get
(
subjectShortAnswer
);
}
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/config/SwaggerConfig.java
View file @
9ca661d9
...
...
@@ -4,6 +4,7 @@ import com.github.tangyi.common.security.constant.SecurityConstant;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.security.oauth2.provider.OAuth2Authentication
;
import
org.springframework.web.servlet.config.annotation.EnableWebMvc
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
...
...
@@ -40,6 +41,7 @@ public class SwaggerConfig implements WebMvcConfigurer {
parameterList
.
add
(
tenantCodeParameter
());
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
.
apiInfo
(
apiInfo
())
.
ignoredParameterTypes
(
OAuth2Authentication
.
class
)
.
select
()
.
apis
(
RequestHandlerSelectors
.
withMethodAnnotation
(
ApiOperation
.
class
))
.
paths
(
PathSelectors
.
any
())
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/controller/StudentController.java
0 → 100644
View file @
9ca661d9
package
com
.
github
.
tangyi
.
user
.
controller
;
import
com.github.pagehelper.PageInfo
;
import
com.github.tangyi.common.core.constant.CommonConstant
;
import
com.github.tangyi.common.core.model.ResponseBean
;
import
com.github.tangyi.common.core.utils.PageUtil
;
import
com.github.tangyi.common.core.utils.SysUtil
;
import
com.github.tangyi.common.core.web.BaseController
;
import
com.github.tangyi.common.log.annotation.Log
;
import
com.github.tangyi.user.api.dto.StudentDto
;
import
com.github.tangyi.user.api.module.Student
;
import
com.github.tangyi.user.service.StudentService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.web.bind.annotation.*
;
import
javax.validation.Valid
;
import
java.util.List
;
import
java.util.Optional
;
/**
* 学生管理Controller
*
* @author tangyi
* @date 2019/07/09 15:29
*/
@Slf4j
@AllArgsConstructor
@Api
(
"学生管理"
)
@RestController
@RequestMapping
(
"/v1/students"
)
public
class
StudentController
extends
BaseController
{
private
final
StudentService
studentService
;
/**
* 根据ID获取
*
* @param id id
* @return ResponseBean
* @author tangyi
* @date 2019/07/09 15:30
*/
@ApiOperation
(
value
=
"获取学生信息"
,
notes
=
"根据学生id获取学生详细信息"
)
@ApiImplicitParam
(
name
=
"id"
,
value
=
"学生ID"
,
required
=
true
,
dataType
=
"String"
,
paramType
=
"path"
)
@GetMapping
(
"/{id}"
)
public
ResponseBean
<
Student
>
student
(
@PathVariable
String
id
)
{
Student
student
=
new
Student
();
student
.
setId
(
id
);
return
new
ResponseBean
<>(
studentService
.
get
(
student
));
}
/**
* 分页查询
*
* @param pageNum pageNum
* @param pageSize pageSize
* @param sort sort
* @param order order
* @param studentDto studentDto
* @return PageInfo
* @author tangyi
* @date 2019/07/09 15:31
*/
@GetMapping
(
"studentList"
)
@ApiOperation
(
value
=
"获取学生列表"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
CommonConstant
.
PAGE_NUM
,
value
=
"分页页码"
,
defaultValue
=
CommonConstant
.
PAGE_NUM_DEFAULT
,
dataType
=
"String"
),
@ApiImplicitParam
(
name
=
CommonConstant
.
PAGE_SIZE
,
value
=
"分页大小"
,
defaultValue
=
CommonConstant
.
PAGE_SIZE_DEFAULT
,
dataType
=
"String"
),
@ApiImplicitParam
(
name
=
CommonConstant
.
SORT
,
value
=
"排序字段"
,
defaultValue
=
CommonConstant
.
PAGE_SORT_DEFAULT
,
dataType
=
"String"
),
@ApiImplicitParam
(
name
=
CommonConstant
.
ORDER
,
value
=
"排序方向"
,
defaultValue
=
CommonConstant
.
PAGE_ORDER_DEFAULT
,
dataType
=
"String"
),
@ApiImplicitParam
(
name
=
"studentDto"
,
value
=
"学生信息"
,
dataType
=
"StudentDto"
)
})
public
PageInfo
<
Student
>
userList
(
@RequestParam
(
value
=
CommonConstant
.
PAGE_NUM
,
required
=
false
,
defaultValue
=
CommonConstant
.
PAGE_NUM_DEFAULT
)
String
pageNum
,
@RequestParam
(
value
=
CommonConstant
.
PAGE_SIZE
,
required
=
false
,
defaultValue
=
CommonConstant
.
PAGE_SIZE_DEFAULT
)
String
pageSize
,
@RequestParam
(
value
=
CommonConstant
.
SORT
,
required
=
false
,
defaultValue
=
CommonConstant
.
PAGE_SORT_DEFAULT
)
String
sort
,
@RequestParam
(
value
=
CommonConstant
.
ORDER
,
required
=
false
,
defaultValue
=
CommonConstant
.
PAGE_ORDER_DEFAULT
)
String
order
,
StudentDto
studentDto
)
{
Student
student
=
new
Student
();
BeanUtils
.
copyProperties
(
studentDto
,
student
);
student
.
setTenantCode
(
SysUtil
.
getTenantCode
());
return
studentService
.
findPage
(
PageUtil
.
pageInfo
(
pageNum
,
pageSize
,
sort
,
order
),
student
);
}
/**
* 创建学生
*
* @param studentDto studentDto
* @return ResponseBean
* @author tangyi
* @date 2019/07/09 15:31
*/
@PostMapping
@ApiOperation
(
value
=
"新增学生"
,
notes
=
"新增学生"
)
@ApiImplicitParam
(
name
=
"studentDto"
,
value
=
"学生实体student"
,
required
=
true
,
dataType
=
"StudentDto"
)
@Log
(
"新增学生"
)
public
ResponseBean
<
Boolean
>
add
(
@RequestBody
@Valid
StudentDto
studentDto
)
{
return
new
ResponseBean
<>(
studentService
.
add
(
studentDto
)
>
0
);
}
/**
* 更新学生
*
* @param studentDto studentDto
* @return ResponseBean
* @author tangyi
* @date 2019/07/09 15:32
*/
@PutMapping
@ApiOperation
(
value
=
"更新学生信息"
,
notes
=
"根据学生id更新学生的基本信息"
)
@ApiImplicitParam
(
name
=
"studentDto"
,
value
=
"学生实体student"
,
required
=
true
,
dataType
=
"StudentDto"
)
@Log
(
"修改学生"
)
public
ResponseBean
<
Boolean
>
update
(
@RequestBody
@Valid
StudentDto
studentDto
)
{
try
{
Student
student
=
new
Student
();
BeanUtils
.
copyProperties
(
studentDto
,
student
);
return
new
ResponseBean
<>(
studentService
.
update
(
student
)
>
0
);
}
catch
(
Exception
e
)
{
log
.
error
(
"更新学生信息失败!"
,
e
);
}
return
new
ResponseBean
<>(
Boolean
.
FALSE
);
}
/**
* 删除学生
*
* @param id id
* @return ResponseBean
* @author tangyi
* @date 2019/07/09 15:33
*/
@DeleteMapping
(
"/{id}"
)
@ApiOperation
(
value
=
"删除学生"
,
notes
=
"根据ID删除学生"
)
@ApiImplicitParam
(
name
=
"id"
,
value
=
"学生ID"
,
required
=
true
,
paramType
=
"path"
)
@Log
(
"删除学生"
)
public
ResponseBean
<
Boolean
>
delete
(
@PathVariable
String
id
)
{
try
{
Student
student
=
new
Student
();
student
.
setId
(
id
);
student
=
studentService
.
get
(
student
);
student
.
setCommonValue
(
SysUtil
.
getUser
(),
SysUtil
.
getSysCode
());
studentService
.
delete
(
student
);
}
catch
(
Exception
e
)
{
log
.
error
(
"删除学生信息失败!"
,
e
);
}
return
new
ResponseBean
<>(
Boolean
.
FALSE
);
}
/**
* 批量删除
*
* @param student student
* @return ResponseBean
* @author tangyi
* @date 2019/07/09 15:34
*/
@PostMapping
(
"deleteAll"
)
@ApiOperation
(
value
=
"批量删除学生"
,
notes
=
"根据学生id批量删除学生"
)
@ApiImplicitParam
(
name
=
"student"
,
value
=
"学生信息"
,
dataType
=
"Student"
)
@Log
(
"批量删除学生"
)
public
ResponseBean
<
Boolean
>
deleteAll
(
@RequestBody
Student
student
)
{
boolean
success
=
false
;
try
{
if
(
StringUtils
.
isNotEmpty
(
student
.
getIdString
()))
success
=
studentService
.
deleteAll
(
student
.
getIdString
().
split
(
","
))
>
0
;
}
catch
(
Exception
e
)
{
log
.
error
(
"删除学生失败!"
,
e
);
}
return
new
ResponseBean
<>(
success
);
}
/**
* 根据ID查询
*
* @param studentDto studentDto
* @return ResponseBean
* @author tangyi
* @date 2019/07/09 15:34
*/
@RequestMapping
(
value
=
"findById"
,
method
=
RequestMethod
.
POST
)
@ApiOperation
(
value
=
"根据ID查询学生"
,
notes
=
"根据ID查询学生"
)
@ApiImplicitParam
(
name
=
"studentDto"
,
value
=
"学生信息"
,
required
=
true
,
paramType
=
"StudentDto"
)
public
ResponseBean
<
List
<
Student
>>
findById
(
@RequestBody
StudentDto
studentDto
)
{
Student
student
=
new
Student
();
BeanUtils
.
copyProperties
(
studentDto
,
student
);
List
<
Student
>
studentList
=
studentService
.
findListById
(
student
);
return
Optional
.
ofNullable
(
studentList
).
isPresent
()
?
new
ResponseBean
<>(
studentList
)
:
null
;
}
}
service-api-impl/user-service/src/main/java/com/github/tangyi/user/controller/UserController.java
View file @
9ca661d9
...
...
@@ -80,11 +80,19 @@ public class UserController extends BaseController {
*/
@GetMapping
(
"info"
)
@ApiOperation
(
value
=
"获取用户信息"
,
notes
=
"获取当前登录用户详细信息"
)
public
ResponseBean
<
UserInfoDto
>
userInfo
(
OAuth2Authentication
authentication
)
{
UserVo
userVo
=
new
UserVo
();
userVo
.
setIdentifier
(
authentication
.
getName
());
userVo
.
setTenantCode
(
SysUtil
.
getTenantCode
());
return
new
ResponseBean
<>(
userService
.
findUserInfo
(
userVo
));
@ApiImplicitParam
(
name
=
"identityType"
,
value
=
"账号类型"
,
required
=
true
,
dataType
=
"String"
)
public
ResponseBean
<
UserInfoDto
>
userInfo
(
@RequestParam
(
required
=
false
)
String
identityType
,
OAuth2Authentication
authentication
)
{
try
{
UserVo
userVo
=
new
UserVo
();
if
(
StringUtils
.
isNotEmpty
(
identityType
))
userVo
.
setIdentityType
(
Integer
.
valueOf
(
identityType
));
userVo
.
setIdentifier
(
authentication
.
getName
());
userVo
.
setTenantCode
(
SysUtil
.
getTenantCode
());
return
new
ResponseBean
<>(
userService
.
findUserInfo
(
userVo
));
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
throw
new
CommonException
(
"获取当前登录用户详细信息"
);
}
}
/**
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/mapper/StudentMapper.java
0 → 100644
View file @
9ca661d9
package
com
.
github
.
tangyi
.
user
.
mapper
;
import
com.github.tangyi.common.core.persistence.CrudMapper
;
import
com.github.tangyi.user.api.module.Student
;
import
org.apache.ibatis.annotations.Mapper
;
/**
* 学生Mapper
*
* @author tangyi
* @date 2019/07/09 15:27
*/
@Mapper
public
interface
StudentMapper
extends
CrudMapper
<
Student
>
{
}
service-api-impl/user-service/src/main/java/com/github/tangyi/user/mapper/UserStudentMapper.java
0 → 100644
View file @
9ca661d9
package
com
.
github
.
tangyi
.
user
.
mapper
;
import
com.github.tangyi.common.core.persistence.CrudMapper
;
import
com.github.tangyi.user.api.module.UserStudent
;
import
org.apache.ibatis.annotations.Mapper
;
import
java.util.List
;
/**
* 用户学生Mapper
*
* @author tangyi
* @date 2019/07/09 15:57
*/
@Mapper
public
interface
UserStudentMapper
extends
CrudMapper
<
UserStudent
>
{
/**
* 根据userId查询
*
* @param userId userId
* @return List
*/
List
<
UserStudent
>
getByUserId
(
String
userId
);
/**
* 根据studentId查询
*
* @param studentId studentId
* @return UserStudent
*/
UserStudent
getByStudentId
(
String
studentId
);
/**
* 根据用户id删除
*
* @param userId userId
* @return int
*/
int
deleteByUserId
(
String
userId
);
/**
* 根据学生id删除
*
* @param studentId studentId
* @return int
*/
int
deleteByStudentId
(
String
studentId
);
}
service-api-impl/user-service/src/main/java/com/github/tangyi/user/service/AttachmentService.java
View file @
9ca661d9
package
com
.
github
.
tangyi
.
user
.
service
;
import
com.github.tangyi.common.core.constant.CommonConstant
;
import
com.github.tangyi.common.core.exceptions.CommonException
;
import
com.github.tangyi.common.core.properties.SysProperties
;
import
com.github.tangyi.common.core.service.CrudService
;
...
...
@@ -39,7 +40,7 @@ public class AttachmentService extends CrudService<AttachmentMapper, Attachment>
* @param attachment attachment
* @return Attachment
*/
@Cacheable
(
value
=
"attachment
"
,
key
=
"#attachment.id"
)
@Cacheable
(
value
=
"attachment
#"
+
CommonConstant
.
CACHE_EXPIRE
,
key
=
"#attachment.id"
)
@Override
public
Attachment
get
(
Attachment
attachment
)
{
return
super
.
get
(
attachment
);
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/service/MenuService.java
View file @
9ca661d9
...
...
@@ -37,7 +37,7 @@ public class MenuService extends CrudService<MenuMapper, Menu> {
* @author tangyi
* @date 2018/8/27 16:00
*/
@Cacheable
(
value
=
"menu
"
,
key
=
"#role"
)
@Cacheable
(
value
=
"menu
#"
+
CommonConstant
.
CACHE_EXPIRE
,
key
=
"#role"
)
public
List
<
Menu
>
findMenuByRole
(
String
role
,
String
tenantCode
)
{
return
menuMapper
.
findByRole
(
role
,
tenantCode
);
}
...
...
@@ -54,9 +54,9 @@ public class MenuService extends CrudService<MenuMapper, Menu> {
public
List
<
Menu
>
finMenuByRoleList
(
List
<
Role
>
roleList
,
String
tenantCode
)
{
List
<
Menu
>
menus
=
Lists
.
newArrayList
();
for
(
Role
role
:
roleList
)
{
List
<
Menu
>
roleMenus
=
this
.
findMenuByRole
(
role
.
getRoleCode
(),
tenantCode
);
if
(
CollectionUtils
.
isNotEmpty
(
roleMenus
))
menus
.
addAll
(
roleMenus
);
List
<
Menu
>
roleMenus
=
this
.
findMenuByRole
(
role
.
getRoleCode
(),
tenantCode
);
if
(
CollectionUtils
.
isNotEmpty
(
roleMenus
))
menus
.
addAll
(
roleMenus
);
}
return
menus
;
}
...
...
@@ -69,7 +69,6 @@ public class MenuService extends CrudService<MenuMapper, Menu> {
* @author tangyi
* @date 2019/04/10 17:58
*/
@Cacheable
(
value
=
"menu"
,
key
=
"#menu.applicationCode"
)
@Override
public
List
<
Menu
>
findAllList
(
Menu
menu
)
{
return
menuMapper
.
findAllList
(
menu
);
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/service/RoleService.java
View file @
9ca661d9
package
com
.
github
.
tangyi
.
user
.
service
;
import
com.github.tangyi.common.core.constant.CommonConstant
;
import
com.github.tangyi.common.core.service.CrudService
;
import
com.github.tangyi.user.api.module.Role
;
import
com.github.tangyi.user.mapper.RoleMapper
;
...
...
@@ -35,7 +36,7 @@ public class RoleService extends CrudService<RoleMapper, Role> {
* @date 2019/05/15 23:32
*/
@Override
@Cacheable
(
value
=
"role
"
,
key
=
"#role.applicationCode"
)
@Cacheable
(
value
=
"role
#"
+
CommonConstant
.
CACHE_EXPIRE
,
key
=
"#role.applicationCode"
)
public
List
<
Role
>
findAllList
(
Role
role
)
{
return
super
.
findAllList
(
role
);
}
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/service/StudentService.java
0 → 100644
View file @
9ca661d9
package
com
.
github
.
tangyi
.
user
.
service
;
import
com.github.tangyi.common.core.exceptions.CommonException
;
import
com.github.tangyi.common.core.service.CrudService
;
import
com.github.tangyi.common.core.utils.SysUtil
;
import
com.github.tangyi.common.core.vo.UserVo
;
import
com.github.tangyi.user.api.dto.StudentDto
;
import
com.github.tangyi.user.api.module.Student
;
import
com.github.tangyi.user.api.module.UserStudent
;
import
com.github.tangyi.user.mapper.StudentMapper
;
import
lombok.AllArgsConstructor
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
/**
* 学生Service
*
* @author tangyi
* @date 2019/07/09 15:28
*/
@AllArgsConstructor
@Service
public
class
StudentService
extends
CrudService
<
StudentMapper
,
Student
>
{
private
final
UserService
userService
;
private
final
UserStudentService
userStudentService
;
/**
* 新增学生
*
* @param studentDto studentDto
* @return int
* @author tangyi
* @date 2019/07/10 18:18:04
*/
@Transactional
public
int
add
(
StudentDto
studentDto
)
{
String
currentUser
=
SysUtil
.
getUser
(),
tenantCode
=
SysUtil
.
getTenantCode
(),
userId
=
studentDto
.
getUserId
();
if
(
StringUtils
.
isBlank
(
userId
))
{
// 查询当前用户
UserVo
userVo
=
userService
.
findUserByIdentifier
(
currentUser
,
tenantCode
);
if
(
userVo
==
null
)
throw
new
CommonException
(
"获取当前用户详细信息失败"
);
userId
=
userVo
.
getId
();
}
Student
student
=
new
Student
();
student
.
setCommonValue
(
currentUser
,
SysUtil
.
getSysCode
(),
tenantCode
);
BeanUtils
.
copyProperties
(
studentDto
,
student
);
// 新增用户学生关系
UserStudent
userStudent
=
new
UserStudent
();
userStudent
.
setCommonValue
(
currentUser
,
SysUtil
.
getSysCode
(),
tenantCode
);
userStudent
.
setUserId
(
userId
);
userStudent
.
setStudentId
(
student
.
getId
());
// TODO
userStudent
.
setRelationshipType
(
0
);
userStudentService
.
insert
(
userStudent
);
// 保存学生
return
this
.
insert
(
student
);
}
}
service-api-impl/user-service/src/main/java/com/github/tangyi/user/service/TenantService.java
View file @
9ca661d9
package
com
.
github
.
tangyi
.
user
.
service
;
import
com.github.tangyi.common.core.constant.CommonConstant
;
import
com.github.tangyi.common.core.service.CrudService
;
import
com.github.tangyi.user.api.module.Tenant
;
import
com.github.tangyi.user.mapper.TenantMapper
;
...
...
@@ -27,7 +28,7 @@ public class TenantService extends CrudService<TenantMapper, Tenant> {
* @author tangyi
* @date 2019/05/26 10:28
*/
@Cacheable
(
value
=
"tenant
"
,
key
=
"#tenantCode"
)
@Cacheable
(
value
=
"tenant
#"
+
CommonConstant
.
CACHE_EXPIRE
,
key
=
"#tenantCode"
)
public
Tenant
getByTenantCode
(
String
tenantCode
)
{
return
this
.
dao
.
getByTenantCode
(
tenantCode
);
}
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/service/UserService.java
View file @
9ca661d9
...
...
@@ -144,6 +144,8 @@ public class UserService extends CrudService<UserMapper, User> {
String
tenantCode
=
userVo
.
getTenantCode
(),
identifier
=
userVo
.
getIdentifier
();
// 根据唯一标识查询账号信息
UserAuths
userAuths
=
new
UserAuths
();
if
(
userVo
.
getIdentityType
()
!=
null
)
userAuths
.
setIdentityType
(
userVo
.
getIdentityType
());
userAuths
.
setIdentifier
(
userVo
.
getIdentifier
());
userAuths
=
userAuthsService
.
getByIdentifier
(
userAuths
);
if
(
userAuths
==
null
)
...
...
@@ -191,8 +193,8 @@ public class UserService extends CrudService<UserMapper, User> {
*/
public
List
<
String
>
getUserPermissions
(
User
user
,
String
identifier
,
List
<
Role
>
roles
)
{
// 用户权限
List
<
String
>
permissions
=
Lists
.
newArrayList
();
List
<
Menu
>
menuList
=
Lists
.
newArrayList
();
List
<
String
>
permissions
=
new
ArrayList
<>
();
List
<
Menu
>
menuList
=
new
ArrayList
<>
();
// 管理员
if
(
UserUtils
.
isAdmin
(
identifier
))
{
Menu
menu
=
new
Menu
();
...
...
@@ -209,11 +211,12 @@ public class UserService extends CrudService<UserMapper, User> {
}
}
if
(
CollectionUtils
.
isNotEmpty
(
menuList
))
{
menuList
.
stream
()
permissions
=
menuList
.
stream
()
// 获取权限菜单
.
filter
(
menu
->
MenuConstant
.
MENU_TYPE_PERMISSION
.
equals
(
menu
.
getType
()))
// 获取权限
.
forEach
(
menu
->
permissions
.
add
(
menu
.
getPermission
()));
.
map
(
Menu:
:
getPermission
).
collect
(
Collectors
.
toList
());
}
return
permissions
;
}
...
...
@@ -375,7 +378,7 @@ public class UserService extends CrudService<UserMapper, User> {
* @author tangyi
* @date 2019/07/03 13:00:39
*/
@Cacheable
(
value
=
"user
"
,
key
=
"#identifier"
)
@Cacheable
(
value
=
"user
#"
+
CommonConstant
.
CACHE_EXPIRE
,
key
=
"#identifier"
)
public
UserVo
findUserByIdentifier
(
Integer
identityType
,
String
identifier
,
String
tenantCode
)
{
UserAuths
userAuths
=
new
UserAuths
();
userAuths
.
setIdentifier
(
identifier
);
...
...
@@ -401,6 +404,19 @@ public class UserService extends CrudService<UserMapper, User> {
}
/**
* 根据用户唯一标识获取用户详细信息
*
* @param identifier identifier
* @param tenantCode tenantCode
* @return UserVo
* @author tangyi
* @date 2019/07/10 18:04:15
*/
public
UserVo
findUserByIdentifier
(
String
identifier
,
String
tenantCode
)
{
return
this
.
findUserByIdentifier
(
null
,
identifier
,
tenantCode
);
}
/**
* 查询账号是否存在
*
* @param identityType identityType
...
...
@@ -544,6 +560,8 @@ public class UserService extends CrudService<UserMapper, User> {
@CacheEvict
(
value
=
"user"
,
key
=
"#userDto.identifier"
)
public
boolean
register
(
UserDto
userDto
)
{
boolean
success
=
false
;
if
(
userDto
.
getIdentityType
()
==
null
)
userDto
.
setIdentityType
(
IdentityType
.
PASSWORD
.
getValue
());
// 解密
String
password
=
this
.
decryptCredential
(
userDto
.
getCredential
(),
userDto
.
getIdentityType
());
User
user
=
new
User
();
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/service/UserStudentService.java
0 → 100644
View file @
9ca661d9
package
com
.
github
.
tangyi
.
user
.
service
;
import
com.github.tangyi.common.core.service.CrudService
;
import
com.github.tangyi.user.api.module.UserStudent
;
import
com.github.tangyi.user.mapper.UserStudentMapper
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.validation.constraints.NotBlank
;
import
java.util.List
;
/**
* 用户学生Service
*
* @author tangyi
* @date 2019/07/09 15:58
*/
@Service
public
class
UserStudentService
extends
CrudService
<
UserStudentMapper
,
UserStudent
>
{
/**
* 根据用户ID查询
*
* @param userId userId
* @return List
* @author tangyi
* @date 2019/07/09 17:01:13
*/
public
List
<
UserStudent
>
getByUserId
(
@NotBlank
String
userId
)
{
return
this
.
dao
.
getByUserId
(
userId
);
}
/**
* 根据学生ID查询
*
* @param studentId studentId
* @return UserStudent
* @author tangyi
* @date 2019/07/09 17:02:19
*/
public
UserStudent
getByStudentId
(
@NotBlank
String
studentId
)
{
return
this
.
dao
.
getByStudentId
(
studentId
);
}
/**
* 根据用户id删除
*
* @param userId userId
* @return int
* @author tangyi
* @date 2019/07/09 17:04:13
*/
@Transactional
public
int
deleteByUserId
(
@NotBlank
String
userId
)
{
return
this
.
dao
.
deleteByUserId
(
userId
);
}
/**
* 根据学生id删除
*
* @param studentId studentId
* @return int
* @author tangyi
* @date 2019/07/09 17:04:59
*/
@Transactional
public
int
deleteByStudentId
(
@NotBlank
String
studentId
)
{
return
this
.
dao
.
deleteByStudentId
(
studentId
);
}
}
service-api-impl/user-service/src/main/resources/mapper/StudentMapper.xml
0 → 100644
View file @
9ca661d9
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.github.tangyi.user.mapper.StudentMapper"
>
<resultMap
id=
"studentResultMap"
type=
"com.github.tangyi.user.api.module.Student"
>
<id
column=
"id"
property=
"id"
/>
<result
column=
"student_name"
property=
"studentName"
/>
<result
column=
"phone"
property=
"phone"
/>
<result
column=
"born"
property=
"born"
jdbcType=
"DATE"
javaType=
"java.util.Date"
/>
<result
column=
"sex"
property=
"sex"
/>
<result
column=
"address"
property=
"address"
/>
<result
column=
"grade"
property=
"grade"
/>
<result
column=
"school"
property=
"school"
/>
<result
column=
"wechat"
property=
"wechat"
/>
<result
column=
"creator"
property=
"creator"
/>
<result
column=
"create_date"
property=
"createDate"
javaType=
"java.util.Date"
jdbcType=
"TIMESTAMP"
/>
<result
column=
"modifier"
property=
"modifier"
/>
<result
column=
"modify_date"
property=
"modifyDate"
javaType=
"java.util.Date"
jdbcType=
"TIMESTAMP"
/>
<result
column=
"del_flag"
property=
"delFlag"
/>
</resultMap>
<sql
id=
"studentColumns"
>
a.id,
a.student_name,
a.phone,
a.born,
a.sex,
a.address,
a.grade,
a.school,
a.wechat,
a.creator,
a.create_date,
a.modifier,
a.modify_date,
a.del_flag
</sql>
<select
id=
"get"
resultMap=
"studentResultMap"
>
SELECT
<include
refid=
"studentColumns"
/>
FROM sys_student a
WHERE a.id = #{id} and a.del_flag = 0
</select>
<select
id=
"findList"
resultMap=
"studentResultMap"
>
SELECT
<include
refid=
"studentColumns"
/>
FROM sys_student a
WHERE a.del_flag = 0
</select>
<select
id=
"findListById"
resultMap=
"studentResultMap"
>
SELECT
<include
refid=
"studentColumns"
/>
FROM sys_student a
WHERE a.id IN
<foreach
collection=
"ids"
index=
"index"
item=
"item"
open=
"("
separator=
","
close=
")"
>
#{item}
</foreach>
</select>
<insert
id=
"insert"
>
INSERT INTO sys_student (
id,
student_name,
phone,
born,
sex,
address,
grade,
school,
wechat,
creator,
create_date,
modifier,
modify_date,
del_flag
) VALUES (
#{id},
#{studentName},
#{phone},
#{born, jdbcType=DATE, javaType=java.util.Date},
#{sex},
#{address},
#{grade},
#{school},
#{wechat},
#{creator},
#{createDate, jdbcType=TIMESTAMP, javaType=java.util.Date},
#{modifier},
#{modifyDate, jdbcType=TIMESTAMP, javaType=java.util.Date},
#{delFlag}
)
</insert>
<update
id=
"update"
>
UPDATE sys_student SET
<if
test=
"studentName != null"
>
student_name = #{studentName},
</if>
<if
test=
"phone != null"
>
phone = #{phone},
</if>
<if
test=
"born != null"
>
born = #{born, jdbcType=TIMESTAMP, javaType=java.util.Date},
</if>
<if
test=
"sex != null"
>
sex = #{sex},
</if>
<if
test=
"address != null"
>
address = #{address},
</if>
<if
test=
"grade != null"
>
grade = #{grade},
</if>
<if
test=
"school != null"
>
school = #{school},
</if>
<if
test=
"wechat != null"
>
wechat = #{wechat},
</if>
<if
test=
"delFlag != null"
>
del_flag = #{delFlag},
</if>
modifier = #{modifier},
modify_date = #{modifyDate, jdbcType=TIMESTAMP, javaType=java.util.Date}
WHERE id = #{id}
</update>
<delete
id=
"delete"
>
UPDATE sys_student SET
del_flag = 1,
modifier = #{modifier} ,
modify_date = #{modifyDate, jdbcType=TIMESTAMP, javaType=java.util.Date}
WHERE ID = #{id}
</delete>
<delete
id=
"deleteAll"
>
update sys_student SET
del_flag = 1
where id in
<foreach
item=
"item"
index=
"index"
collection=
"array"
open=
"("
separator=
","
close=
")"
>
#{item}
</foreach>
</delete>
</mapper>
service-api-impl/user-service/src/main/resources/mapper/UserStudentMapper.xml
0 → 100644
View file @
9ca661d9
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.github.tangyi.user.mapper.UserStudentMapper"
>
<resultMap
id=
"userStudentResultMap"
type=
"com.github.tangyi.user.api.module.UserStudent"
>
<id
column=
"id"
property=
"id"
/>
<result
column=
"user_id"
property=
"userId"
/>
<result
column=
"student_id"
property=
"studentId"
/>
<result
column=
"relationship_type"
property=
"relationshipType"
/>
</resultMap>
<sql
id=
"userStudentColumns"
>
a.id,
a.user_id,
a.student_id,
a.relationship_type
</sql>
<select
id=
"get"
resultMap=
"userStudentResultMap"
>
SELECT
<include
refid=
"userStudentColumns"
/>
FROM sys_user_student a
WHERE a.id = #{id} and a.del_flag = 0
</select>
<select
id=
"getByUserId"
resultMap=
"userStudentResultMap"
>
SELECT
<include
refid=
"userStudentColumns"
/>
FROM sys_user_student a
WHERE a.user_id = #{userId}
</select>
<select
id=
"getByStudentId"
resultMap=
"userStudentResultMap"
>
SELECT
<include
refid=
"userStudentColumns"
/>
FROM sys_user_student a
WHERE a.student_id = #{studentId}
</select>
<select
id=
"findList"
resultMap=
"userStudentResultMap"
>
SELECT
<include
refid=
"userStudentColumns"
/>
FROM sys_user_student a
</select>
<select
id=
"findListById"
resultMap=
"userStudentResultMap"
>
SELECT
<include
refid=
"userStudentColumns"
/>
FROM sys_user_student a
WHERE a.id IN
<foreach
collection=
"ids"
index=
"index"
item=
"item"
open=
"("
separator=
","
close=
")"
>
#{item}
</foreach>
</select>
<insert
id=
"insert"
>
INSERT INTO sys_user_student (
id,
user_id,
student_id,
relationship_type
) VALUES (
#{id},
#{userId},
#{studentId},
#{relationshipType}
)
</insert>
<delete
id=
"delete"
>
DELETE FROM sys_user_student WHERE ID = #{id}
</delete>
<delete
id=
"deleteByUserId"
>
DELETE FROM sys_user_student WHERE user_id = #{userId}
</delete>
<delete
id=
"deleteByStudentId"
>
DELETE FROM sys_user_student WHERE student_id = #{studentId}
</delete>
<delete
id=
"deleteAll"
>
DELETE FROM sys_user_student ID in
<foreach
item=
"item"
index=
"index"
collection=
"array"
open=
"("
separator=
","
close=
")"
>
#{item}
</foreach>
</delete>
</mapper>
service-api/user-api/src/main/java/com/github/tangyi/user/api/dto/StudentDto.java
0 → 100644
View file @
9ca661d9
package
com
.
github
.
tangyi
.
user
.
api
.
dto
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
* @author tangyi
* @date 2019/07/10 18:07
*/
@Data
public
class
StudentDto
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
id
;
/**
* 用户id
*/
@ApiModelProperty
(
value
=
"用户id"
)
private
String
userId
;
/**
* 学生id
*/
@ApiModelProperty
(
value
=
"学生id"
)
private
String
studentId
;
/**
* 关系类型
*/
@ApiModelProperty
(
value
=
"关系类型"
)
private
Integer
relationshipType
;
/**
* 学生姓名
*/
@ApiModelProperty
(
value
=
"学生姓名"
)
private
String
studentName
;
/**
* 出生日期
*/
@ApiModelProperty
(
value
=
"出生日期"
,
dataType
=
"Date"
)
private
Date
born
;
/**
* 电话号码
*/
@ApiModelProperty
(
value
=
"电话"
,
example
=
"15521089184"
)
private
String
phone
;
/**
* 微信
*/
@ApiModelProperty
(
value
=
"微信"
)
private
String
wechat
;
/**
* 性别
*/
@ApiModelProperty
(
value
=
"性别,0:男,1:女"
,
dataType
=
"Integer"
,
example
=
"0"
)
private
Integer
sex
;
/**
* 家庭住址
*/
@ApiModelProperty
(
value
=
"家庭住址"
)
private
String
address
;
/**
* 就读年级
*/
@ApiModelProperty
(
value
=
"就读年级"
)
private
String
grade
;
/**
* 就读学校
*/
@ApiModelProperty
(
value
=
"就读学校"
)
private
String
school
;
}
service-api/user-api/src/main/java/com/github/tangyi/user/api/dto/UserDto.java
View file @
9ca661d9
package
com
.
github
.
tangyi
.
user
.
api
.
dto
;
import
com.github.tangyi.common.core.constant.CommonConstant
;
import
com.github.tangyi.user.api.module.Role
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
...
...
service-api/user-api/src/main/java/com/github/tangyi/user/api/module/Student.java
0 → 100644
View file @
9ca661d9
package
com
.
github
.
tangyi
.
user
.
api
.
module
;
import
com.github.tangyi.common.core.persistence.BaseEntity
;
import
lombok.Data
;
import
java.util.Date
;
/**
* 学生
*
* @author tangyi
* @date 2019/07/09 15:08
*/
@Data
public
class
Student
extends
BaseEntity
<
Student
>
{
/**
* 学生姓名
*/
private
String
studentName
;
/**
* 出生日期
*/
private
Date
born
;
/**
* 电话号码
*/
private
String
phone
;
/**
* 微信
*/
private
String
wechat
;
/**
* 性别
*/
private
Integer
sex
;
/**
* 家庭住址
*/
private
String
address
;
/**
* 就读年级
*/
private
String
grade
;
/**
* 就读学校
*/
private
String
school
;
}
service-api/user-api/src/main/java/com/github/tangyi/user/api/module/UserAuths.java
View file @
9ca661d9
package
com
.
github
.
tangyi
.
user
.
api
.
module
;
import
com.github.tangyi.common.core.persistence.BaseEntity
;
import
com.github.tangyi.user.api.enums.IdentityType
;
import
lombok.Data
;
/**
...
...
@@ -21,7 +20,7 @@ public class UserAuths extends BaseEntity<UserAuths> {
/**
* 授权类型,1:用户名密码,2:手机号,3:邮箱,4:微信,5:QQ
*/
private
Integer
identityType
=
IdentityType
.
PASSWORD
.
getValue
()
;
private
Integer
identityType
;
/**
* 唯一标识,如用户名、手机号
...
...
service-api/user-api/src/main/java/com/github/tangyi/user/api/module/UserStudent.java
0 → 100644
View file @
9ca661d9
package
com
.
github
.
tangyi
.
user
.
api
.
module
;
import
com.github.tangyi.common.core.persistence.BaseEntity
;
import
lombok.Data
;
/**
* 用户学生关联关系,一个用户可以绑定多个学生
*
* @author tangyi
* @date 2019/07/09 15:23
*/
@Data
public
class
UserStudent
extends
BaseEntity
<
UserStudent
>
{
/**
* 用户id
*/
private
String
userId
;
/**
* 学生id
*/
private
String
studentId
;
/**
* 关系类型
*/
private
Integer
relationshipType
;
}
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