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
4a5971c6
Commit
4a5971c6
authored
Apr 11, 2019
by
tangyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
配置、权限等优化
parent
8a2ca63e
Show whitespace changes
Inline
Side-by-side
Showing
58 changed files
with
501 additions
and
571 deletions
+501
-571
CrudMapper.java
...com/github/tangyi/common/core/persistence/CrudMapper.java
+8
-0
CrudService.java
...va/com/github/tangyi/common/core/service/CrudService.java
+10
-0
SecurityConstant.java
...hub/tangyi/common/security/constant/SecurityConstant.java
+13
-3
UserDetailsImpl.java
...m/github/tangyi/common/security/core/UserDetailsImpl.java
+20
-2
auth-service.yml
config-service/src/main/resources/config/auth-service.yml
+9
-3
exam-service.yml
config-service/src/main/resources/config/exam-service.yml
+9
-3
user-service.yml
config-service/src/main/resources/config/user-service.yml
+15
-3
GatewayServiceApplication.java
.../com/github/tangyi/gateway/GatewayServiceApplication.java
+0
-4
GatewayExceptionHandler.java
...ithub/tangyi/gateway/handler/GatewayExceptionHandler.java
+1
-1
pom.xml
pom.xml
+2
-10
pom.xml
service-api-impl/auth-service/pom.xml
+0
-6
MybatisConfig.java
...ain/java/com/github/tangyi/auth/config/MybatisConfig.java
+0
-31
UserDetailsServiceImpl.java
...om/github/tangyi/auth/service/UserDetailsServiceImpl.java
+12
-13
bootstrap.yml
...ce-api-impl/auth-service/src/main/resources/bootstrap.yml
+0
-0
OauthClientMapper.xml
...h-service/src/main/resources/mapper/OauthClientMapper.xml
+1
-1
mybatis-config.xml
...i-impl/auth-service/src/main/resources/mybatis-config.xml
+0
-16
pom.xml
service-api-impl/exam-service/pom.xml
+0
-6
MybatisConfig.java
...ain/java/com/github/tangyi/exam/config/MybatisConfig.java
+0
-33
ExamRecordController.java
...m/github/tangyi/exam/controller/ExamRecordController.java
+58
-55
ExaminationController.java
.../github/tangyi/exam/controller/ExaminationController.java
+15
-16
IncorrectAnswerController.java
...hub/tangyi/exam/controller/IncorrectAnswerController.java
+5
-10
KnowledgeController.java
...om/github/tangyi/exam/controller/KnowledgeController.java
+19
-12
SubjectBankController.java
.../github/tangyi/exam/controller/SubjectBankController.java
+16
-13
SubjectCategoryController.java
...hub/tangyi/exam/controller/SubjectCategoryController.java
+13
-7
SubjectController.java
.../com/github/tangyi/exam/controller/SubjectController.java
+18
-16
AnswerService.java
...in/java/com/github/tangyi/exam/service/AnswerService.java
+33
-32
AnswerMapper.xml
...l/exam-service/src/main/resources/mapper/AnswerMapper.xml
+1
-1
CourseMapper.xml
...l/exam-service/src/main/resources/mapper/CourseMapper.xml
+1
-1
ExamRecodeMapper.xml
...am-service/src/main/resources/mapper/ExamRecodeMapper.xml
+1
-1
ExaminationMapper.xml
...m-service/src/main/resources/mapper/ExaminationMapper.xml
+1
-1
IncorrectAnswerMapper.xml
...rvice/src/main/resources/mapper/IncorrectAnswerMapper.xml
+1
-1
KnowledgeMapper.xml
...xam-service/src/main/resources/mapper/KnowledgeMapper.xml
+1
-1
SubjectBankMapper.xml
...m-service/src/main/resources/mapper/SubjectBankMapper.xml
+1
-1
SubjectCategoryMapper.xml
...rvice/src/main/resources/mapper/SubjectCategoryMapper.xml
+1
-1
SubjectMapper.xml
.../exam-service/src/main/resources/mapper/SubjectMapper.xml
+1
-1
mybatis-config.xml
...i-impl/exam-service/src/main/resources/mybatis-config.xml
+0
-16
pom.xml
service-api-impl/user-service/pom.xml
+0
-6
MybatisConfig.java
...ain/java/com/github/tangyi/user/config/MybatisConfig.java
+0
-33
RabbitConfig.java
...main/java/com/github/tangyi/user/config/RabbitConfig.java
+11
-0
AttachmentController.java
...m/github/tangyi/user/controller/AttachmentController.java
+5
-5
DeptController.java
...ava/com/github/tangyi/user/controller/DeptController.java
+23
-15
MenuController.java
...ava/com/github/tangyi/user/controller/MenuController.java
+47
-48
RoleController.java
...ava/com/github/tangyi/user/controller/RoleController.java
+13
-15
UserController.java
...ava/com/github/tangyi/user/controller/UserController.java
+52
-62
AttachmentService.java
...ava/com/github/tangyi/user/service/AttachmentService.java
+0
-2
MenuService.java
...main/java/com/github/tangyi/user/service/MenuService.java
+15
-6
UserService.java
...main/java/com/github/tangyi/user/service/UserService.java
+25
-26
AttachmentMapper.xml
...er-service/src/main/resources/mapper/AttachmentMapper.xml
+1
-1
DeptMapper.xml
...mpl/user-service/src/main/resources/mapper/DeptMapper.xml
+1
-1
LogMapper.xml
...impl/user-service/src/main/resources/mapper/LogMapper.xml
+1
-1
MenuMapper.xml
...mpl/user-service/src/main/resources/mapper/MenuMapper.xml
+9
-1
RoleDeptMapper.xml
...user-service/src/main/resources/mapper/RoleDeptMapper.xml
+3
-3
RoleMapper.xml
...mpl/user-service/src/main/resources/mapper/RoleMapper.xml
+1
-1
RoleMenuMapper.xml
...user-service/src/main/resources/mapper/RoleMenuMapper.xml
+3
-3
RouteMapper.xml
...pl/user-service/src/main/resources/mapper/RouteMapper.xml
+1
-1
UserMapper.xml
...mpl/user-service/src/main/resources/mapper/UserMapper.xml
+1
-1
UserRoleMapper.xml
...user-service/src/main/resources/mapper/UserRoleMapper.xml
+3
-3
mybatis-config.xml
...i-impl/user-service/src/main/resources/mybatis-config.xml
+0
-16
No files found.
common/common-core/src/main/java/com/github/tangyi/common/core/persistence/CrudMapper.java
View file @
4a5971c6
...
@@ -27,6 +27,14 @@ public interface CrudMapper<T> extends BaseMapper {
...
@@ -27,6 +27,14 @@ public interface CrudMapper<T> extends BaseMapper {
List
<
T
>
findList
(
T
entity
);
List
<
T
>
findList
(
T
entity
);
/**
/**
* 获取全部列表数据
*
* @param entity entity
* @return List
*/
List
<
T
>
findAllList
(
T
entity
);
/**
* 根据id获取列表数据
* 根据id获取列表数据
*
*
* @param entity entity
* @param entity entity
...
...
common/common-core/src/main/java/com/github/tangyi/common/core/service/CrudService.java
View file @
4a5971c6
...
@@ -60,6 +60,16 @@ public abstract class CrudService<D extends CrudMapper<T>, T extends BaseEntity<
...
@@ -60,6 +60,16 @@ public abstract class CrudService<D extends CrudMapper<T>, T extends BaseEntity<
* @param entity entity
* @param entity entity
* @return List
* @return List
*/
*/
public
List
<
T
>
findAllList
(
T
entity
)
{
return
dao
.
findList
(
entity
);
}
/**
* 查询列表
*
* @param entity entity
* @return List
*/
public
List
<
T
>
findListById
(
T
entity
)
{
public
List
<
T
>
findListById
(
T
entity
)
{
return
dao
.
findListById
(
entity
);
return
dao
.
findListById
(
entity
);
}
}
...
...
common/common-security/src/main/java/com/github/tangyi/common/security/constant/SecurityConstant.java
View file @
4a5971c6
...
@@ -9,17 +9,17 @@ public class SecurityConstant {
...
@@ -9,17 +9,17 @@ public class SecurityConstant {
/**
/**
* 基础角色
* 基础角色
*/
*/
public
static
final
String
BASE_ROLE
=
"
ROLE_USER
"
;
public
static
final
String
BASE_ROLE
=
"
role_user
"
;
/**
/**
* 管理员角色
* 管理员角色
*/
*/
public
static
final
String
ROLE_ADMIN
=
"
ROLE_ADMIN
"
;
public
static
final
String
ROLE_ADMIN
=
"
role_admin
"
;
/**
/**
* 老师角色
* 老师角色
*/
*/
public
static
final
String
ROLE_TEACHER
=
"
ROLE_TEACHER
"
;
public
static
final
String
ROLE_TEACHER
=
"
role_teacher
"
;
/**
/**
* token
* token
...
@@ -35,4 +35,14 @@ public class SecurityConstant {
...
@@ -35,4 +35,14 @@ public class SecurityConstant {
* oauth 客户端信息
* oauth 客户端信息
*/
*/
public
static
final
String
CLIENT_DETAILS_KEY
=
"exam_oauth:client:details"
;
public
static
final
String
CLIENT_DETAILS_KEY
=
"exam_oauth:client:details"
;
/**
* 正常状态
*/
public
static
final
String
NORMAL
=
"0"
;
/**
* 异常状态
*/
public
static
final
String
ABNORMAL
=
"1"
;
}
}
common/common-security/src/main/java/com/github/tangyi/common/security/core/UserDetailsImpl.java
View file @
4a5971c6
package
com
.
github
.
tangyi
.
common
.
security
.
core
;
package
com
.
github
.
tangyi
.
common
.
security
.
core
;
import
com.github.tangyi.common.security.constant.SecurityConstant
;
import
org.springframework.security.core.GrantedAuthority
;
import
org.springframework.security.core.GrantedAuthority
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetails
;
...
@@ -15,14 +16,31 @@ public class UserDetailsImpl implements UserDetails {
...
@@ -15,14 +16,31 @@ public class UserDetailsImpl implements UserDetails {
private
static
final
long
serialVersionUID
=
-
6509897037222767090L
;
private
static
final
long
serialVersionUID
=
-
6509897037222767090L
;
/**
* 权限
*/
private
Set
<
GrantedAuthority
>
authorities
;
private
Set
<
GrantedAuthority
>
authorities
;
/**
* 密码
*/
private
String
password
;
private
String
password
;
/**
* 用户名
*/
private
String
username
;
private
String
username
;
public
UserDetailsImpl
(
String
username
,
String
password
,
Set
<
GrantedAuthority
>
authorities
)
{
/**
* 启用禁用状态
*/
private
String
status
;
public
UserDetailsImpl
(
String
username
,
String
password
,
String
status
,
Set
<
GrantedAuthority
>
authorities
)
{
this
.
authorities
=
authorities
;
this
.
authorities
=
authorities
;
this
.
username
=
username
;
this
.
username
=
username
;
this
.
password
=
password
;
this
.
password
=
password
;
this
.
status
=
status
;
}
}
@Override
@Override
...
@@ -57,6 +75,6 @@ public class UserDetailsImpl implements UserDetails {
...
@@ -57,6 +75,6 @@ public class UserDetailsImpl implements UserDetails {
@Override
@Override
public
boolean
isEnabled
()
{
public
boolean
isEnabled
()
{
return
true
;
return
SecurityConstant
.
NORMAL
.
equals
(
this
.
status
)
;
}
}
}
}
config-service/src/main/resources/config/auth-service.yml
View file @
4a5971c6
...
@@ -5,7 +5,7 @@ spring:
...
@@ -5,7 +5,7 @@ spring:
url
:
jdbc:mysql://${MYSQL_HOST:192.168.0.144}:${MYSQL_PORT:3306}/microservice-auth?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
url
:
jdbc:mysql://${MYSQL_HOST:192.168.0.144}:${MYSQL_PORT:3306}/microservice-auth?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
username
:
${MYSQL_USERNAME:platform}
username
:
${MYSQL_USERNAME:platform}
password
:
${MYSQL_PASSWORD:11}
password
:
${MYSQL_PASSWORD:11}
type
:
com.
alibaba.druid.pool.Druid
DataSource
type
:
com.
zaxxer.hikari.Hikari
DataSource
driver-class-name
:
com.mysql.jdbc.Driver
driver-class-name
:
com.mysql.jdbc.Driver
redis
:
redis
:
host
:
${REDIS_HOST:192.168.0.213}
host
:
${REDIS_HOST:192.168.0.213}
...
@@ -57,9 +57,15 @@ management:
...
@@ -57,9 +57,15 @@ management:
health
:
health
:
show-details
:
ALWAYS
show-details
:
ALWAYS
# mybatis配置
mybatis
:
mybatis
:
mapperLocations
:
classpath:mapper/*.xml
type-aliases-package
:
com.github.tangyi.auth.api.module
configLocation
:
classpath:/mybatis-config.xml
configuration
:
# 驼峰转换
map-underscore-to-camel-case
:
true
# 延迟加载
lazy-loading-enabled
:
true
mapper-locations
:
classpath:mapper/*.xml
pagehelper
:
pagehelper
:
helperDialect
:
mysql
helperDialect
:
mysql
reasonable
:
true
reasonable
:
true
...
...
config-service/src/main/resources/config/exam-service.yml
View file @
4a5971c6
...
@@ -5,7 +5,7 @@ spring:
...
@@ -5,7 +5,7 @@ spring:
url
:
jdbc:mysql://${MYSQL_HOST:192.168.0.144}:${MYSQL_PORT:3306}/microservice-exam?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
url
:
jdbc:mysql://${MYSQL_HOST:192.168.0.144}:${MYSQL_PORT:3306}/microservice-exam?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
username
:
${MYSQL_USERNAME:platform}
username
:
${MYSQL_USERNAME:platform}
password
:
${MYSQL_PASSWORD:11}
password
:
${MYSQL_PASSWORD:11}
type
:
com.
alibaba.druid.pool.Druid
DataSource
type
:
com.
zaxxer.hikari.Hikari
DataSource
driver-class-name
:
com.mysql.jdbc.Driver
driver-class-name
:
com.mysql.jdbc.Driver
redis
:
redis
:
host
:
${REDIS_HOST:192.168.0.213}
host
:
${REDIS_HOST:192.168.0.213}
...
@@ -48,9 +48,15 @@ security:
...
@@ -48,9 +48,15 @@ security:
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAimUKhvBhsoeSM3HkIOP/Y3RXjvonBlZnLj8oO92TyAKG53lmAoK0wZ5MTZPsfrOz2Z7CeAp6mPhUANX2RUoFwVzG7rJmgWyqGmGFNBmtYL+uVqQ80TzWi5zyzXTxgVMWiCqqw/u4AeE1qhN8chnGwhUBnpgPAPd8v57mIwg0n5JxjdYe7pgHlpvt8ZXTXd1KBxB5K7WjNlCfMf75ZEeBaplxsSfJUwKbnHQKWcY3NnpjkVR8y4jviAbkOHmGMaliM7fcsLzbosBUPDQuNlvYdjPBRfH6MMPeXRW6On3u0Um9wIYmkQS+AEgHCq4UuLOnTTqqxnGkwFYeMAAXmRyMtQIDAQAB
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAimUKhvBhsoeSM3HkIOP/Y3RXjvonBlZnLj8oO92TyAKG53lmAoK0wZ5MTZPsfrOz2Z7CeAp6mPhUANX2RUoFwVzG7rJmgWyqGmGFNBmtYL+uVqQ80TzWi5zyzXTxgVMWiCqqw/u4AeE1qhN8chnGwhUBnpgPAPd8v57mIwg0n5JxjdYe7pgHlpvt8ZXTXd1KBxB5K7WjNlCfMf75ZEeBaplxsSfJUwKbnHQKWcY3NnpjkVR8y4jviAbkOHmGMaliM7fcsLzbosBUPDQuNlvYdjPBRfH6MMPeXRW6On3u0Um9wIYmkQS+AEgHCq4UuLOnTTqqxnGkwFYeMAAXmRyMtQIDAQAB
-----END PUBLIC KEY-----
-----END PUBLIC KEY-----
# mybatis配置
mybatis
:
mybatis
:
mapperLocations
:
classpath:mapper/*.xml
type-aliases-package
:
com.github.tangyi.exam.api.module
configLocation
:
classpath:/mybatis-config.xml
configuration
:
# 驼峰转换
map-underscore-to-camel-case
:
true
# 延迟加载
lazy-loading-enabled
:
true
mapper-locations
:
classpath:mapper/*.xml
pagehelper
:
pagehelper
:
helperDialect
:
mysql
helperDialect
:
mysql
reasonable
:
true
reasonable
:
true
...
...
config-service/src/main/resources/config/user-service.yml
View file @
4a5971c6
server
:
server
:
port
:
8082
port
:
8082
spring
:
spring
:
servlet
:
multipart
:
# 单个文件的大小
max-file-size
:
10MB
# 单次请求的文件的总大小
max-request-size
:
100MB
datasource
:
datasource
:
url
:
jdbc:mysql://${MYSQL_HOST:192.168.0.144}:${MYSQL_PORT:3306}/microservice-user?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
url
:
jdbc:mysql://${MYSQL_HOST:192.168.0.144}:${MYSQL_PORT:3306}/microservice-user?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
username
:
${MYSQL_USERNAME:platform}
username
:
${MYSQL_USERNAME:platform}
password
:
${MYSQL_PASSWORD:11}
password
:
${MYSQL_PASSWORD:11}
type
:
com.
alibaba.druid.pool.Druid
DataSource
type
:
com.
zaxxer.hikari.Hikari
DataSource
driver-class-name
:
com.mysql.jdbc.Driver
driver-class-name
:
com.mysql.jdbc.Driver
redis
:
redis
:
host
:
${REDIS_HOST:192.168.0.213}
host
:
${REDIS_HOST:192.168.0.213}
...
@@ -48,9 +54,15 @@ security:
...
@@ -48,9 +54,15 @@ security:
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAimUKhvBhsoeSM3HkIOP/Y3RXjvonBlZnLj8oO92TyAKG53lmAoK0wZ5MTZPsfrOz2Z7CeAp6mPhUANX2RUoFwVzG7rJmgWyqGmGFNBmtYL+uVqQ80TzWi5zyzXTxgVMWiCqqw/u4AeE1qhN8chnGwhUBnpgPAPd8v57mIwg0n5JxjdYe7pgHlpvt8ZXTXd1KBxB5K7WjNlCfMf75ZEeBaplxsSfJUwKbnHQKWcY3NnpjkVR8y4jviAbkOHmGMaliM7fcsLzbosBUPDQuNlvYdjPBRfH6MMPeXRW6On3u0Um9wIYmkQS+AEgHCq4UuLOnTTqqxnGkwFYeMAAXmRyMtQIDAQAB
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAimUKhvBhsoeSM3HkIOP/Y3RXjvonBlZnLj8oO92TyAKG53lmAoK0wZ5MTZPsfrOz2Z7CeAp6mPhUANX2RUoFwVzG7rJmgWyqGmGFNBmtYL+uVqQ80TzWi5zyzXTxgVMWiCqqw/u4AeE1qhN8chnGwhUBnpgPAPd8v57mIwg0n5JxjdYe7pgHlpvt8ZXTXd1KBxB5K7WjNlCfMf75ZEeBaplxsSfJUwKbnHQKWcY3NnpjkVR8y4jviAbkOHmGMaliM7fcsLzbosBUPDQuNlvYdjPBRfH6MMPeXRW6On3u0Um9wIYmkQS+AEgHCq4UuLOnTTqqxnGkwFYeMAAXmRyMtQIDAQAB
-----END PUBLIC KEY-----
-----END PUBLIC KEY-----
# mybatis配置
mybatis
:
mybatis
:
mapperLocations
:
classpath:mapper/*.xml
type-aliases-package
:
com.github.tangyi.user.api.module
configLocation
:
classpath:/mybatis-config.xml
configuration
:
# 驼峰转换
map-underscore-to-camel-case
:
true
# 延迟加载
lazy-loading-enabled
:
true
mapper-locations
:
classpath:mapper/*.xml
pagehelper
:
pagehelper
:
helperDialect
:
mysql
helperDialect
:
mysql
reasonable
:
true
reasonable
:
true
...
...
gateway-service/src/main/java/com/github/tangyi/gateway/GatewayServiceApplication.java
View file @
4a5971c6
...
@@ -5,16 +5,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
...
@@ -5,16 +5,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker
;
import
org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker
;
import
org.springframework.cloud.client.discovery.EnableDiscoveryClient
;
import
org.springframework.cloud.client.discovery.EnableDiscoveryClient
;
import
org.springframework.cloud.context.config.annotation.RefreshScope
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.ComponentScan
;
@EnableDiscoveryClient
@EnableDiscoveryClient
@SpringBootApplication
(
exclude
=
{
DataSourceAutoConfiguration
.
class
})
@SpringBootApplication
(
exclude
=
{
DataSourceAutoConfiguration
.
class
})
// 配置包扫描,排查Swagger配置
@ComponentScan
(
basePackages
=
{
"com.github.tangyi"
})
@ComponentScan
(
basePackages
=
{
"com.github.tangyi"
})
@EnableCircuitBreaker
@EnableCircuitBreaker
// 动态刷新
@RefreshScope
public
class
GatewayServiceApplication
{
public
class
GatewayServiceApplication
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
...
...
gateway-service/src/main/java/com/github/tangyi/gateway/handler/GatewayExceptionHandler.java
View file @
4a5971c6
...
@@ -123,7 +123,7 @@ public class GatewayExceptionHandler implements ErrorWebExceptionHandler {
...
@@ -123,7 +123,7 @@ public class GatewayExceptionHandler implements ErrorWebExceptionHandler {
}
}
pr
otected
Mono
<
ServerResponse
>
renderErrorResponse
(
ServerRequest
request
)
{
pr
ivate
Mono
<
ServerResponse
>
renderErrorResponse
(
ServerRequest
request
)
{
ResponseBean
<?>
responseBean
=
exceptionHandlerResult
.
get
();
ResponseBean
<?>
responseBean
=
exceptionHandlerResult
.
get
();
return
ServerResponse
.
status
(
responseBean
.
getStatus
())
return
ServerResponse
.
status
(
responseBean
.
getStatus
())
.
contentType
(
MediaType
.
APPLICATION_JSON_UTF8
)
.
contentType
(
MediaType
.
APPLICATION_JSON_UTF8
)
...
...
pom.xml
View file @
4a5971c6
...
@@ -54,7 +54,6 @@
...
@@ -54,7 +54,6 @@
<!--<spring-boot-devtools.version>2.0.4.RELEASE</spring-boot-devtools.version>-->
<!--<spring-boot-devtools.version>2.0.4.RELEASE</spring-boot-devtools.version>-->
<zipkin.version>
2.11.3
</zipkin.version>
<zipkin.version>
2.11.3
</zipkin.version>
<swagger.version>
2.9.2
</swagger.version>
<swagger.version>
2.9.2
</swagger.version>
<driud.version>
1.1.4
</driud.version>
<fastdfs-client.version>
1.26.5
</fastdfs-client.version>
<fastdfs-client.version>
1.26.5
</fastdfs-client.version>
<mysql.connector.version>
8.0.13
</mysql.connector.version>
<mysql.connector.version>
8.0.13
</mysql.connector.version>
<!-- common-->
<!-- common-->
...
@@ -65,8 +64,8 @@
...
@@ -65,8 +64,8 @@
<!-- 其它依赖 -->
<!-- 其它依赖 -->
<hibernate-validator.version>
6.0.14.Final
</hibernate-validator.version>
<hibernate-validator.version>
6.0.14.Final
</hibernate-validator.version>
<mybatis.version>
1.1
.1
</mybatis.version>
<mybatis.version>
2.0
.1
</mybatis.version>
<pagehelper.version>
1.2.
3
</pagehelper.version>
<pagehelper.version>
1.2.
10
</pagehelper.version>
<poi.version>
3.9
</poi.version>
<poi.version>
3.9
</poi.version>
<xmlbeans.version>
2.3.0
</xmlbeans.version>
<xmlbeans.version>
2.3.0
</xmlbeans.version>
<hutool.version>
4.5.0
</hutool.version>
<hutool.version>
4.5.0
</hutool.version>
...
@@ -226,13 +225,6 @@
...
@@ -226,13 +225,6 @@
<version>
${mysql.connector.version}
</version>
<version>
${mysql.connector.version}
</version>
</dependency>
</dependency>
<!-- druid阿里巴巴数据库连接池 -->
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid
</artifactId>
<version>
${driud.version}
</version>
</dependency>
<!-- mybatis -->
<!-- mybatis -->
<dependency>
<dependency>
<groupId>
org.mybatis.spring.boot
</groupId>
<groupId>
org.mybatis.spring.boot
</groupId>
...
...
service-api-impl/auth-service/pom.xml
View file @
4a5971c6
...
@@ -77,12 +77,6 @@
...
@@ -77,12 +77,6 @@
<artifactId>
mysql-connector-java
</artifactId>
<artifactId>
mysql-connector-java
</artifactId>
</dependency>
</dependency>
<!-- druid阿里巴巴数据库连接池 -->
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid
</artifactId>
</dependency>
<!-- mybatis -->
<!-- mybatis -->
<dependency>
<dependency>
<groupId>
org.mybatis.spring.boot
</groupId>
<groupId>
org.mybatis.spring.boot
</groupId>
...
...
service-api-impl/auth-service/src/main/java/com/github/tangyi/auth/config/MybatisConfig.java
deleted
100644 → 0
View file @
8a2ca63e
package
com
.
github
.
tangyi
.
auth
.
config
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.jdbc.datasource.DataSourceTransactionManager
;
import
org.springframework.transaction.PlatformTransactionManager
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
import
org.springframework.transaction.annotation.TransactionManagementConfigurer
;
import
javax.sql.DataSource
;
/**
* @author tangyi
* @date 2019/3/30 23:48
*/
@Configuration
@EnableTransactionManagement
public
class
MybatisConfig
implements
TransactionManagementConfigurer
{
private
final
DataSource
dataSource
;
@Autowired
public
MybatisConfig
(
DataSource
dataSource
)
{
this
.
dataSource
=
dataSource
;
}
@Override
public
PlatformTransactionManager
annotationDrivenTransactionManager
()
{
return
new
DataSourceTransactionManager
(
dataSource
);
}
}
service-api-impl/auth-service/src/main/java/com/github/tangyi/auth/service/UserDetailsServiceImpl.java
View file @
4a5971c6
...
@@ -4,11 +4,10 @@ import com.github.tangyi.common.core.vo.Role;
...
@@ -4,11 +4,10 @@ import com.github.tangyi.common.core.vo.Role;
import
com.github.tangyi.common.core.vo.UserVo
;
import
com.github.tangyi.common.core.vo.UserVo
;
import
com.github.tangyi.common.security.core.GrantedAuthorityImpl
;
import
com.github.tangyi.common.security.core.GrantedAuthorityImpl
;
import
com.github.tangyi.common.security.core.UserDetailsImpl
;
import
com.github.tangyi.common.security.core.UserDetailsImpl
;
import
com.github.tangyi.user.api.constant.MenuConstant
;
import
com.github.tangyi.user.api.feign.UserServiceClient
;
import
com.github.tangyi.user.api.feign.UserServiceClient
;
import
com.github.tangyi.user.api.module.Menu
;
import
com.github.tangyi.user.api.module.Menu
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.GrantedAuthority
;
import
org.springframework.security.core.GrantedAuthority
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetails
;
...
@@ -18,7 +17,9 @@ import org.springframework.stereotype.Service;
...
@@ -18,7 +17,9 @@ import org.springframework.stereotype.Service;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.stream.Stream
;
/**
/**
* 模拟从数据库获取用户信息
* 模拟从数据库获取用户信息
...
@@ -29,8 +30,6 @@ import java.util.Set;
...
@@ -29,8 +30,6 @@ import java.util.Set;
@Service
@Service
public
class
UserDetailsServiceImpl
implements
UserDetailsService
{
public
class
UserDetailsServiceImpl
implements
UserDetailsService
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
UserDetailsServiceImpl
.
class
);
@Autowired
@Autowired
private
UserServiceClient
userServiceClient
;
private
UserServiceClient
userServiceClient
;
...
@@ -48,7 +47,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
...
@@ -48,7 +47,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
UserVo
userVo
=
userServiceClient
.
findUserByUsername
(
username
);
UserVo
userVo
=
userServiceClient
.
findUserByUsername
(
username
);
if
(
userVo
==
null
)
if
(
userVo
==
null
)
throw
new
UsernameNotFoundException
(
"User name not found."
);
throw
new
UsernameNotFoundException
(
"User name not found."
);
userDetails
=
new
UserDetailsImpl
(
username
,
userVo
.
getPassword
(),
getAuthority
(
userVo
));
userDetails
=
new
UserDetailsImpl
(
username
,
userVo
.
getPassword
(),
userVo
.
getStatus
(),
getAuthority
(
userVo
));
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
UsernameNotFoundException
(
"Exception occurred wile reading user info."
);
throw
new
UsernameNotFoundException
(
"Exception occurred wile reading user info."
);
}
}
...
@@ -69,18 +68,18 @@ public class UserDetailsServiceImpl implements UserDetailsService {
...
@@ -69,18 +68,18 @@ public class UserDetailsServiceImpl implements UserDetailsService {
// 角色
// 角色
List
<
Role
>
roleList
=
userVo
.
getRoleList
();
List
<
Role
>
roleList
=
userVo
.
getRoleList
();
if
(
CollectionUtils
.
isNotEmpty
(
roleList
))
{
if
(
CollectionUtils
.
isNotEmpty
(
roleList
))
{
for
(
Role
role
:
roleList
)
{
roleList
.
forEach
(
role
->
{
// 权限如果前缀是ROLE_,security就会认为这是个角色信息,而不是权限,例如ROLE_ADMIN就是ADMIN角色,MENU:ADD就是MENU:ADD权限
// 权限如果前缀是ROLE_,security就会认为这是个角色信息,而不是权限,例如ROLE_ADMIN就是ADMIN角色,MENU:ADD就是MENU:ADD权限
authorities
.
add
(
new
GrantedAuthorityImpl
(
role
.
getRoleCode
()
.
toUpperCase
()
));
authorities
.
add
(
new
GrantedAuthorityImpl
(
role
.
getRoleCode
()));
// 根据角色查找菜单权限
// 根据角色查找菜单权限
List
<
Menu
>
menuList
=
userServiceClient
.
findMenuByRole
(
role
.
getRoleCode
()
);
Stream
<
Menu
>
menuStream
=
userServiceClient
.
findMenuByRole
(
role
.
getRoleCode
()).
stream
(
);
if
(
CollectionUtils
.
isNotEmpty
(
menuList
))
{
if
(
Optional
.
ofNullable
(
menuStream
).
isPresent
(
))
{
for
(
Menu
menu
:
menuList
)
{
menuStream
// 菜单权限
// 菜单权限
authorities
.
add
(
new
GrantedAuthorityImpl
(
menu
.
getPermission
()));
.
filter
(
menu
->
MenuConstant
.
MENU_TYPE_PERMISSION
.
equals
(
menu
.
getType
()))
}
.
forEach
(
menu
->
authorities
.
add
(
new
GrantedAuthorityImpl
(
menu
.
getPermission
())));
}
}
}
});
}
}
return
authorities
;
return
authorities
;
}
}
...
...
service-api-impl/auth-service/src/main/resources/bootstrap.yml
View file @
4a5971c6
service-api-impl/auth-service/src/main/resources/mapper/OauthClientMapper.xml
View file @
4a5971c6
...
@@ -23,7 +23,7 @@
...
@@ -23,7 +23,7 @@
</resultMap>
</resultMap>
<sql
id=
"oauthClientColumns"
>
<sql
id=
"oauthClientColumns"
>
a.id
as "id"
,
a.id,
a.client_id,
a.client_id,
a.resource_ids,
a.resource_ids,
a.client_secret_plain_text,
a.client_secret_plain_text,
...
...
service-api-impl/auth-service/src/main/resources/mybatis-config.xml
deleted
100644 → 0
View file @
8a2ca63e
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<!-- 驼峰转换 -->
<setting
name=
"mapUnderscoreToCamelCase"
value=
"true"
/>
<!-- 延迟加载 -->
<setting
name=
"lazyLoadingEnabled"
value=
"true"
/>
</settings>
<typeAliases>
<package
name=
"com.tangyi.module"
/>
</typeAliases>
</configuration>
\ No newline at end of file
service-api-impl/exam-service/pom.xml
View file @
4a5971c6
...
@@ -72,12 +72,6 @@
...
@@ -72,12 +72,6 @@
<artifactId>
mysql-connector-java
</artifactId>
<artifactId>
mysql-connector-java
</artifactId>
</dependency>
</dependency>
<!-- druid阿里巴巴数据库连接池 -->
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid
</artifactId>
</dependency>
<!-- mybatis -->
<!-- mybatis -->
<dependency>
<dependency>
<groupId>
org.mybatis.spring.boot
</groupId>
<groupId>
org.mybatis.spring.boot
</groupId>
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/config/MybatisConfig.java
deleted
100644 → 0
View file @
8a2ca63e
package
com
.
github
.
tangyi
.
exam
.
config
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.jdbc.datasource.DataSourceTransactionManager
;
import
org.springframework.transaction.PlatformTransactionManager
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
import
org.springframework.transaction.annotation.TransactionManagementConfigurer
;
import
javax.sql.DataSource
;
/**
* mybatis 配置
*
* @author tangyi
* @date 2019/3/16 21:03
*/
@Configuration
@EnableTransactionManagement
public
class
MybatisConfig
implements
TransactionManagementConfigurer
{
private
final
DataSource
dataSource
;
@Autowired
public
MybatisConfig
(
DataSource
dataSource
)
{
this
.
dataSource
=
dataSource
;
}
@Override
public
PlatformTransactionManager
annotationDrivenTransactionManager
()
{
return
new
DataSourceTransactionManager
(
dataSource
);
}
}
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/controller/ExamRecordController.java
View file @
4a5971c6
...
@@ -36,6 +36,7 @@ import javax.servlet.http.HttpServletRequest;
...
@@ -36,6 +36,7 @@ import javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.*
;
import
java.util.stream.Stream
;
/**
/**
* 考试记录controller
* 考试记录controller
...
@@ -110,26 +111,26 @@ public class ExamRecordController extends BaseController {
...
@@ -110,26 +111,26 @@ public class ExamRecordController extends BaseController {
// 查询考试记录
// 查询考试记录
PageInfo
<
ExamRecord
>
examRecordPageInfo
=
examRecordService
.
findPage
(
PageUtil
.
pageInfo
(
pageNum
,
pageSize
,
sort
,
order
),
examRecord
);
PageInfo
<
ExamRecord
>
examRecordPageInfo
=
examRecordService
.
findPage
(
PageUtil
.
pageInfo
(
pageNum
,
pageSize
,
sort
,
order
),
examRecord
);
if
(
CollectionUtils
.
isNotEmpty
(
examRecordPageInfo
.
getList
()))
{
if
(
CollectionUtils
.
isNotEmpty
(
examRecordPageInfo
.
getList
()))
{
// 考试id、用户id
Set
<
String
>
examIdSet
=
new
HashSet
<>(),
userIdSet
=
new
HashSet
<>();
examRecordPageInfo
.
getList
().
forEach
(
tempExamRecord
->
{
examIdSet
.
add
(
tempExamRecord
.
getExaminationId
());
userIdSet
.
add
(
tempExamRecord
.
getUserId
());
});
Examination
examination
=
new
Examination
();
Examination
examination
=
new
Examination
();
examination
.
setIds
(
examIdSet
.
toArray
(
new
String
[
examIdSet
.
size
()]));
// 获取考试ID集合,转成字符串数组
examination
.
setIds
(
examRecordPageInfo
.
getList
().
stream
().
map
(
ExamRecord:
:
getExaminationId
).
distinct
().
toArray
(
String
[]::
new
));
// 查询考试信息
// 查询考试信息
List
<
Examination
>
examinations
=
examinationService
.
findListById
(
examination
);
List
<
Examination
>
examinations
=
examinationService
.
findListById
(
examination
);
// 查询用户信息
// 查询用户信息
UserVo
userVo
=
new
UserVo
();
UserVo
userVo
=
new
UserVo
();
userVo
.
setIds
(
userIdSet
.
toArray
(
new
String
[
userIdSet
.
size
()]));
// 获取用户ID集合,转成字符串数组
userVo
.
setIds
(
examRecordPageInfo
.
getList
().
stream
().
map
(
ExamRecord:
:
getUserId
).
distinct
().
toArray
(
String
[]::
new
));
ResponseBean
<
List
<
UserVo
>>
returnT
=
userServiceClient
.
findUserById
(
userVo
);
ResponseBean
<
List
<
UserVo
>>
returnT
=
userServiceClient
.
findUserById
(
userVo
);
if
(
returnT
!=
null
&&
CollectionUtils
.
isNotEmpty
(
returnT
.
getData
()))
{
if
(
returnT
!=
null
&&
CollectionUtils
.
isNotEmpty
(
returnT
.
getData
()))
{
examRecordPageInfo
.
getList
().
forEach
(
tempExamRecord
->
{
examRecordPageInfo
.
getList
().
forEach
(
tempExamRecord
->
{
examinations
.
forEach
(
tempExamination
->
{
// 找到考试记录所属的考试信息
if
(
tempExamRecord
.
getExaminationId
().
equals
(
tempExamination
.
getId
()))
{
Examination
examinationRecordExamination
=
examinations
.
stream
()
.
filter
(
tempExamination
->
tempExamRecord
.
getExaminationId
().
equals
(
tempExamination
.
getId
()))
.
findFirst
().
orElse
(
null
);
// 转换成ExamRecordDto
if
(
examinationRecordExamination
!=
null
)
{
ExamRecordDto
examRecordDto
=
new
ExamRecordDto
();
ExamRecordDto
examRecordDto
=
new
ExamRecordDto
();
BeanUtils
.
copyProperties
(
temp
Examination
,
examRecordDto
);
BeanUtils
.
copyProperties
(
examinationRecord
Examination
,
examRecordDto
);
examRecordDto
.
setId
(
tempExamRecord
.
getId
());
examRecordDto
.
setId
(
tempExamRecord
.
getId
());
examRecordDto
.
setStartTime
(
tempExamRecord
.
getStartTime
());
examRecordDto
.
setStartTime
(
tempExamRecord
.
getStartTime
());
examRecordDto
.
setEndTime
(
tempExamRecord
.
getEndTime
());
examRecordDto
.
setEndTime
(
tempExamRecord
.
getEndTime
());
...
@@ -138,31 +139,31 @@ public class ExamRecordController extends BaseController {
...
@@ -138,31 +139,31 @@ public class ExamRecordController extends BaseController {
examRecordDtoList
.
add
(
examRecordDto
);
examRecordDtoList
.
add
(
examRecordDto
);
}
}
});
});
});
// 查询部门信息
// 查询部门信息
Set
<
String
>
deptIdSet
=
new
HashSet
<>();
returnT
.
getData
().
forEach
(
tempUserVo
->
deptIdSet
.
add
(
tempUserVo
.
getDeptId
()));
DeptVo
deptVo
=
new
DeptVo
();
DeptVo
deptVo
=
new
DeptVo
();
deptVo
.
setIds
(
deptIdSet
.
toArray
(
new
String
[
deptIdSet
.
size
()]));
// 获取部门ID集合,转成字符串数组
deptVo
.
setIds
(
returnT
.
getData
().
stream
().
map
(
UserVo:
:
getDeptId
).
distinct
().
toArray
(
String
[]::
new
));
ResponseBean
<
List
<
DeptVo
>>
deptResponseBean
=
userServiceClient
.
findDeptById
(
deptVo
);
ResponseBean
<
List
<
DeptVo
>>
deptResponseBean
=
userServiceClient
.
findDeptById
(
deptVo
);
for
(
ExamRecordDto
tempExamRecordDto
:
examRecordDtoList
)
{
examRecordDtoList
.
forEach
(
tempExamRecordDto
->
{
for
(
UserVo
tempUserVo
:
returnT
.
getData
())
{
// 查询、设置用户信息
if
(
tempExamRecordDto
.
getUserId
().
equals
(
tempUserVo
.
getId
()))
{
UserVo
examRecordDtoUserVo
=
returnT
.
getData
().
stream
()
tempExamRecordDto
.
setUserName
(
tempUserVo
.
getName
());
.
filter
(
tempUserVo
->
tempExamRecordDto
.
getUserId
().
equals
(
tempUserVo
.
getId
()))
// 查询部门信息
.
findFirst
().
orElse
(
null
);
if
(
examRecordDtoUserVo
!=
null
)
{
// 设置用户名
tempExamRecordDto
.
setUserName
(
examRecordDtoUserVo
.
getName
());
// 查询、设置部门信息
if
(
deptResponseBean
!=
null
&&
CollectionUtils
.
isNotEmpty
(
deptResponseBean
.
getData
()))
{
if
(
deptResponseBean
!=
null
&&
CollectionUtils
.
isNotEmpty
(
deptResponseBean
.
getData
()))
{
for
(
DeptVo
tempDept
:
deptResponseBean
.
getData
())
{
DeptVo
examRecordDtoDeptVo
=
deptResponseBean
.
getData
().
stream
()
// 设置所属部门名称
// 根据部门ID过滤
if
(
tempDept
.
getId
().
equals
(
tempUserVo
.
getDeptId
()))
{
.
filter
(
tempDept
->
tempDept
.
getId
().
equals
(
examRecordDtoUserVo
.
getDeptId
()))
tempExamRecordDto
.
setDeptName
(
tempDept
.
getDeptName
());
.
findFirst
().
orElse
(
null
);
break
;
// 设置部门名称
}
if
(
examRecordDtoDeptVo
!=
null
)
}
tempExamRecordDto
.
setDeptName
(
examRecordDtoDeptVo
.
getDeptName
());
}
break
;
}
}
}
}
}
});
}
}
}
}
examRecordDtoPageInfo
.
setTotal
(
examRecordPageInfo
.
getTotal
());
examRecordDtoPageInfo
.
setTotal
(
examRecordPageInfo
.
getTotal
());
...
@@ -267,13 +268,9 @@ public class ExamRecordController extends BaseController {
...
@@ -267,13 +268,9 @@ public class ExamRecordController extends BaseController {
response
.
setHeader
(
HttpHeaders
.
CONTENT_DISPOSITION
,
Servlets
.
getDownName
(
request
,
"考试成绩"
+
new
SimpleDateFormat
(
"yyyyMMddhhmmssSSS"
).
format
(
new
Date
())
+
".xlsx"
));
response
.
setHeader
(
HttpHeaders
.
CONTENT_DISPOSITION
,
Servlets
.
getDownName
(
request
,
"考试成绩"
+
new
SimpleDateFormat
(
"yyyyMMddhhmmssSSS"
).
format
(
new
Date
())
+
".xlsx"
));
List
<
ExamRecord
>
examRecordList
;
List
<
ExamRecord
>
examRecordList
;
if
(
StringUtils
.
isNotEmpty
(
examRecordDto
.
getIdString
()))
{
if
(
StringUtils
.
isNotEmpty
(
examRecordDto
.
getIdString
()))
{
Set
<
String
>
examRecordIdSet
=
new
HashSet
<>();
for
(
String
id
:
examRecordDto
.
getIdString
().
split
(
","
))
{
if
(
StringUtils
.
isNotEmpty
(
id
))
examRecordIdSet
.
add
(
id
);
}
ExamRecord
examRecord
=
new
ExamRecord
();
ExamRecord
examRecord
=
new
ExamRecord
();
examRecord
.
setIds
(
examRecordIdSet
.
toArray
(
new
String
[
examRecordIdSet
.
size
()]));
// 按逗号切割ID,流处理获取ID集合,去重,转成字符串数组
examRecord
.
setIds
(
Stream
.
of
(
examRecordDto
.
getIdString
().
split
(
","
)).
filter
(
StringUtils:
:
isNotEmpty
).
distinct
().
toArray
(
String
[]::
new
));
examRecordList
=
examRecordService
.
findListById
(
examRecord
);
examRecordList
=
examRecordService
.
findListById
(
examRecord
);
}
else
{
}
else
{
// 导出全部
// 导出全部
...
@@ -283,19 +280,21 @@ public class ExamRecordController extends BaseController {
...
@@ -283,19 +280,21 @@ public class ExamRecordController extends BaseController {
if
(
CollectionUtils
.
isNotEmpty
(
examRecordList
))
{
if
(
CollectionUtils
.
isNotEmpty
(
examRecordList
))
{
List
<
ExamRecordDto
>
examRecordDtoList
=
new
ArrayList
<>();
List
<
ExamRecordDto
>
examRecordDtoList
=
new
ArrayList
<>();
// 查询考试信息
// 查询考试信息
Set
<
String
>
examIdSet
=
new
HashSet
<>();
examRecordList
.
forEach
(
tempExamRecord
->
examIdSet
.
add
(
tempExamRecord
.
getExaminationId
()));
Examination
examination
=
new
Examination
();
Examination
examination
=
new
Examination
();
examination
.
setIds
(
examIdSet
.
toArray
(
new
String
[
examIdSet
.
size
()]));
// 流处理获取考试ID集合,去重,转成字符串数组
examination
.
setIds
(
examRecordList
.
stream
().
map
(
ExamRecord:
:
getExaminationId
).
distinct
().
toArray
(
String
[]::
new
));
List
<
Examination
>
examinations
=
examinationService
.
findListById
(
examination
);
List
<
Examination
>
examinations
=
examinationService
.
findListById
(
examination
);
// 用户id
// 用户id
Set
<
String
>
userIdSet
=
new
HashSet
<>();
Set
<
String
>
userIdSet
=
new
HashSet
<>();
examRecordList
.
forEach
(
tempExamRecord
->
{
examRecordList
.
forEach
(
tempExamRecord
->
{
examinations
.
forEach
(
tempExamination
->
{
// 查找考试记录所属的考试信息
if
(
tempExamRecord
.
getExaminationId
().
equals
(
tempExamination
.
getId
()))
{
Examination
examRecordExamination
=
examinations
.
stream
()
.
filter
(
tempExamination
->
tempExamRecord
.
getExaminationId
().
equals
(
tempExamination
.
getId
()))
.
findFirst
().
orElse
(
null
);
if
(
examRecordExamination
!=
null
)
{
ExamRecordDto
recordDto
=
new
ExamRecordDto
();
ExamRecordDto
recordDto
=
new
ExamRecordDto
();
recordDto
.
setId
(
tempExamRecord
.
getId
());
recordDto
.
setId
(
tempExamRecord
.
getId
());
recordDto
.
setExaminationName
(
temp
Examination
.
getExaminationName
());
recordDto
.
setExaminationName
(
examRecord
Examination
.
getExaminationName
());
recordDto
.
setExamTime
(
tempExamRecord
.
getCreateDate
());
recordDto
.
setExamTime
(
tempExamRecord
.
getCreateDate
());
recordDto
.
setScore
(
tempExamRecord
.
getScore
());
recordDto
.
setScore
(
tempExamRecord
.
getScore
());
recordDto
.
setUserId
(
tempExamRecord
.
getUserId
());
recordDto
.
setUserId
(
tempExamRecord
.
getUserId
());
...
@@ -303,31 +302,35 @@ public class ExamRecordController extends BaseController {
...
@@ -303,31 +302,35 @@ public class ExamRecordController extends BaseController {
examRecordDtoList
.
add
(
recordDto
);
examRecordDtoList
.
add
(
recordDto
);
}
}
});
});
});
// 查询用户信息
// 查询用户信息
UserVo
userVo
=
new
UserVo
();
UserVo
userVo
=
new
UserVo
();
userVo
.
setIds
(
userIdSet
.
toArray
(
new
String
[
userIdSet
.
size
()
]));
userVo
.
setIds
(
userIdSet
.
toArray
(
new
String
[
0
]));
ResponseBean
<
List
<
UserVo
>>
returnT
=
userServiceClient
.
findUserById
(
userVo
);
ResponseBean
<
List
<
UserVo
>>
returnT
=
userServiceClient
.
findUserById
(
userVo
);
if
(
returnT
!=
null
&&
CollectionUtils
.
isNotEmpty
(
returnT
.
getData
()))
{
if
(
returnT
!=
null
&&
CollectionUtils
.
isNotEmpty
(
returnT
.
getData
()))
{
// 查询部门信息
// 查询部门信息
Set
<
String
>
deptIdSet
=
new
HashSet
<>();
returnT
.
getData
().
forEach
(
tempUserVo
->
deptIdSet
.
add
(
tempUserVo
.
getDeptId
()));
DeptVo
deptVo
=
new
DeptVo
();
DeptVo
deptVo
=
new
DeptVo
();
deptVo
.
setIds
(
deptIdSet
.
toArray
(
new
String
[
deptIdSet
.
size
()]));
// 流处理获取部门ID集合,去重,转成字符串数组
deptVo
.
setIds
(
returnT
.
getData
().
stream
().
map
(
UserVo:
:
getDeptId
).
distinct
().
toArray
(
String
[]::
new
));
// 获取部门信息
ResponseBean
<
List
<
DeptVo
>>
deptResponseBean
=
userServiceClient
.
findDeptById
(
deptVo
);
ResponseBean
<
List
<
DeptVo
>>
deptResponseBean
=
userServiceClient
.
findDeptById
(
deptVo
);
examRecordDtoList
.
forEach
(
tempExamRecordDto
->
returnT
.
getData
().
forEach
(
tempUserVo
->
{
examRecordDtoList
.
forEach
(
tempExamRecordDto
->
{
if
(
tempExamRecordDto
.
getUserId
().
equals
(
tempUserVo
.
getId
()))
{
// 查询用户信息
tempExamRecordDto
.
setUserName
(
tempUserVo
.
getName
());
UserVo
examRecordDtoUserVo
=
returnT
.
getData
().
stream
().
filter
(
tempUserVo
->
tempExamRecordDto
.
getUserId
().
equals
(
tempUserVo
.
getId
()))
.
findFirst
().
orElse
(
null
);
if
(
examRecordDtoUserVo
!=
null
)
{
tempExamRecordDto
.
setUserName
(
examRecordDtoUserVo
.
getName
());
// 查询部门信息
// 查询部门信息
if
(
deptResponseBean
!=
null
&&
CollectionUtils
.
isNotEmpty
(
deptResponseBean
.
getData
()))
{
if
(
deptResponseBean
!=
null
&&
CollectionUtils
.
isNotEmpty
(
deptResponseBean
.
getData
()))
{
deptResponseBean
.
getData
().
forEach
(
tempDept
->
{
// 查找用户所属部门
DeptVo
examRecordDtoDeptVo
=
deptResponseBean
.
getData
().
stream
()
.
filter
(
tempDept
->
tempDept
.
getId
().
equals
(
examRecordDtoUserVo
.
getDeptId
()))
.
findFirst
().
orElse
(
null
);
// 设置所属部门名称
// 设置所属部门名称
if
(
tempDept
.
getId
().
equals
(
tempUserVo
.
getDeptId
()))
if
(
examRecordDtoDeptVo
!=
null
)
tempExamRecordDto
.
setDeptName
(
tempDept
.
getDeptName
());
tempExamRecordDto
.
setDeptName
(
examRecordDtoDeptVo
.
getDeptName
());
});
}
}
}
}
})
)
;
});
}
}
// 导出
// 导出
ExcelToolUtil
.
exportExcel
(
request
.
getInputStream
(),
response
.
getOutputStream
(),
MapUtil
.
java2Map
(
examRecordDtoList
),
ExamRecordUtil
.
getExamRecordDtoMap
());
ExcelToolUtil
.
exportExcel
(
request
.
getInputStream
(),
response
.
getOutputStream
(),
MapUtil
.
java2Map
(
examRecordDtoList
),
ExamRecordUtil
.
getExamRecordDtoMap
());
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/controller/ExaminationController.java
View file @
4a5971c6
...
@@ -28,7 +28,9 @@ import org.springframework.security.access.prepost.PreAuthorize;
...
@@ -28,7 +28,9 @@ import org.springframework.security.access.prepost.PreAuthorize;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
/**
* 考试controller
* 考试controller
...
@@ -101,29 +103,26 @@ public class ExaminationController extends BaseController {
...
@@ -101,29 +103,26 @@ public class ExaminationController extends BaseController {
PageInfo
<
Examination
>
page
=
examinationService
.
findPage
(
PageUtil
.
pageInfo
(
pageNum
,
pageSize
,
sort
,
order
),
examination
);
PageInfo
<
Examination
>
page
=
examinationService
.
findPage
(
PageUtil
.
pageInfo
(
pageNum
,
pageSize
,
sort
,
order
),
examination
);
PageInfo
<
ExaminationDto
>
examinationDtoPageInfo
=
new
PageInfo
<>();
PageInfo
<
ExaminationDto
>
examinationDtoPageInfo
=
new
PageInfo
<>();
BeanUtils
.
copyProperties
(
page
,
examinationDtoPageInfo
);
BeanUtils
.
copyProperties
(
page
,
examinationDtoPageInfo
);
List
<
ExaminationDto
>
examinationDtos
=
new
ArrayList
<>();
if
(
CollectionUtils
.
isNotEmpty
(
page
.
getList
()))
{
if
(
CollectionUtils
.
isNotEmpty
(
page
.
getList
()))
{
Set
<
String
>
courseIdSet
=
new
HashSet
<>();
page
.
getList
().
forEach
(
exam
->
{
courseIdSet
.
add
(
exam
.
getCourseId
());
});
Course
course
=
new
Course
();
Course
course
=
new
Course
();
course
.
setIds
(
courseIdSet
.
toArray
(
new
String
[
courseIdSet
.
size
()]));
// 流处理获取课程ID集合,转成字符串数组
course
.
setIds
(
page
.
getList
().
stream
().
map
(
Examination:
:
getCourseId
).
distinct
().
toArray
(
String
[]::
new
));
List
<
Course
>
courses
=
courseService
.
findListById
(
course
);
List
<
Course
>
courses
=
courseService
.
findListById
(
course
);
// 当前时间
String
currentTime
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
format
(
new
Date
());
String
currentTime
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
format
(
new
Date
());
page
.
getList
().
forEach
(
exam
->
{
// 流处理转成Dto集合
List
<
ExaminationDto
>
examinationDtos
=
page
.
getList
().
stream
().
map
(
exam
->
{
ExaminationDto
examinationDto
=
new
ExaminationDto
();
ExaminationDto
examinationDto
=
new
ExaminationDto
();
BeanUtils
.
copyProperties
(
exam
,
examinationDto
);
BeanUtils
.
copyProperties
(
exam
,
examinationDto
);
examinationDto
.
setCurrentTime
(
currentTime
);
examinationDto
.
setCurrentTime
(
currentTime
);
courses
.
forEach
(
tempCourse
->
{
// 设置考试所属课程
if
(
tempCourse
.
getId
().
equals
(
exam
.
getCourseId
()))
{
Course
examinationCourse
=
courses
.
stream
().
filter
(
tempCourse
->
tempCourse
.
getId
().
equals
(
exam
.
getCourseId
())).
findFirst
().
orElse
(
null
);
examinationDto
.
setCourse
(
tempCourse
);
if
(
examinationCourse
!=
null
)
}
examinationDto
.
setCourse
(
examinationCourse
);
});
return
examinationDto
;
examinationDtos
.
add
(
examinationDto
);
}).
collect
(
Collectors
.
toList
());
});
}
examinationDtoPageInfo
.
setList
(
examinationDtos
);
examinationDtoPageInfo
.
setList
(
examinationDtos
);
}
return
examinationDtoPageInfo
;
return
examinationDtoPageInfo
;
}
}
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/controller/IncorrectAnswerController.java
View file @
4a5971c6
...
@@ -26,9 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -26,9 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Set
;
/**
/**
* 错题controller
* 错题controller
...
@@ -100,23 +98,20 @@ public class IncorrectAnswerController extends BaseController {
...
@@ -100,23 +98,20 @@ public class IncorrectAnswerController extends BaseController {
PageInfo
<
IncorrectAnswerDto
>
pageInfo
=
new
PageInfo
<>();
PageInfo
<
IncorrectAnswerDto
>
pageInfo
=
new
PageInfo
<>();
List
<
IncorrectAnswerDto
>
incorrectAnswerDtoList
=
new
ArrayList
<>();
List
<
IncorrectAnswerDto
>
incorrectAnswerDtoList
=
new
ArrayList
<>();
if
(
CollectionUtils
.
isNotEmpty
(
incorrectAnswerPageInfo
.
getList
()))
{
if
(
CollectionUtils
.
isNotEmpty
(
incorrectAnswerPageInfo
.
getList
()))
{
Set
<
String
>
subjectIds
=
new
HashSet
<>();
incorrectAnswerPageInfo
.
getList
().
forEach
(
incorrect
->
{
subjectIds
.
add
(
incorrect
.
getSubjectId
());
});
Subject
subject
=
new
Subject
();
Subject
subject
=
new
Subject
();
subject
.
setIds
(
subjectIds
.
toArray
(
new
String
[
subjectIds
.
size
()]));
// 获取题目ID
subject
.
setIds
(
incorrectAnswerPageInfo
.
getList
().
stream
().
map
(
IncorrectAnswer:
:
getSubjectId
).
distinct
().
toArray
(
String
[]::
new
));
// 查找题目
// 查找题目
List
<
Subject
>
subjects
=
subjectService
.
findListById
(
subject
);
List
<
Subject
>
subjects
=
subjectService
.
findListById
(
subject
);
if
(
CollectionUtils
.
isNotEmpty
(
subjects
))
{
if
(
CollectionUtils
.
isNotEmpty
(
subjects
))
{
subjects
.
forEach
(
tempSubject
->
{
subjects
.
forEach
(
tempSubject
->
{
incorrectAnswerPageInfo
.
getList
().
forEach
(
tempIncorrectAnswer
->
{
incorrectAnswerPageInfo
.
getList
().
stream
()
if
(
tempSubject
.
getId
().
equalsIgnoreCase
(
tempIncorrectAnswer
.
getSubjectId
()))
{
.
filter
(
tempIncorrectAnswer
->
tempSubject
.
getId
().
equalsIgnoreCase
(
tempIncorrectAnswer
.
getSubjectId
()))
.
forEach
(
tempIncorrectAnswer
->
{
IncorrectAnswerDto
incorrectAnswerDto
=
new
IncorrectAnswerDto
();
IncorrectAnswerDto
incorrectAnswerDto
=
new
IncorrectAnswerDto
();
BeanUtils
.
copyProperties
(
tempSubject
,
incorrectAnswerDto
);
BeanUtils
.
copyProperties
(
tempSubject
,
incorrectAnswerDto
);
incorrectAnswerDto
.
setIncorrectAnswer
(
tempIncorrectAnswer
.
getIncorrectAnswer
());
incorrectAnswerDto
.
setIncorrectAnswer
(
tempIncorrectAnswer
.
getIncorrectAnswer
());
incorrectAnswerDtoList
.
add
(
incorrectAnswerDto
);
incorrectAnswerDtoList
.
add
(
incorrectAnswerDto
);
}
});
});
});
});
}
}
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/controller/KnowledgeController.java
View file @
4a5971c6
...
@@ -99,31 +99,38 @@ public class KnowledgeController extends BaseController {
...
@@ -99,31 +99,38 @@ public class KnowledgeController extends BaseController {
PageInfo
<
Knowledge
>
knowledgePageInfo
=
knowledgeService
.
findPage
(
PageUtil
.
pageInfo
(
pageNum
,
pageSize
,
sort
,
order
),
knowledge
);
PageInfo
<
Knowledge
>
knowledgePageInfo
=
knowledgeService
.
findPage
(
PageUtil
.
pageInfo
(
pageNum
,
pageSize
,
sort
,
order
),
knowledge
);
PageInfo
<
KnowledgeDto
>
knowledgeDtoPageInfo
=
new
PageInfo
<>();
PageInfo
<
KnowledgeDto
>
knowledgeDtoPageInfo
=
new
PageInfo
<>();
List
<
KnowledgeDto
>
knowledgeDtoList
=
new
ArrayList
<>();
List
<
KnowledgeDto
>
knowledgeDtoList
=
new
ArrayList
<>();
// 查询附件
// 查询附件
Set
<
String
>
attachmentIdSet
=
new
HashSet
<>();
Set
<
String
>
attachmentIdSet
=
new
HashSet
<>();
knowledgePageInfo
.
getList
().
forEach
(
tempKnowledge
->
{
knowledgePageInfo
.
getList
().
forEach
(
tempKnowledge
->
{
attachmentIdSet
.
add
(
tempKnowledge
.
getAttachmentId
());
attachmentIdSet
.
add
(
tempKnowledge
.
getAttachmentId
());
});
});
AttachmentVo
attachmentVo
=
new
AttachmentVo
();
AttachmentVo
attachmentVo
=
new
AttachmentVo
();
attachmentVo
.
setIds
(
attachmentIdSet
.
toArray
(
new
String
[
attachmentIdSet
.
size
()
]));
attachmentVo
.
setIds
(
attachmentIdSet
.
toArray
(
new
String
[
0
]));
// 根据附件ID查询附件
// 根据附件ID查询附件
ResponseBean
<
List
<
AttachmentVo
>>
returnT
=
userServiceClient
.
findAttachmentById
(
attachmentVo
);
ResponseBean
<
List
<
AttachmentVo
>>
returnT
=
userServiceClient
.
findAttachmentById
(
attachmentVo
);
for
(
Knowledge
tempKnowledge
:
knowledgePageInfo
.
getList
())
{
knowledgePageInfo
.
getList
().
stream
()
// 转成Dto
.
map
(
tempKnowledge
->
{
KnowledgeDto
knowledgeDto
=
new
KnowledgeDto
();
KnowledgeDto
knowledgeDto
=
new
KnowledgeDto
();
BeanUtils
.
copyProperties
(
tempKnowledge
,
knowledgeDto
);
BeanUtils
.
copyProperties
(
tempKnowledge
,
knowledgeDto
);
return
knowledgeDto
;
})
// 遍历
.
forEach
(
tempKnowledgeDto
->
{
if
(
returnT
!=
null
&&
CollectionUtils
.
isNotEmpty
(
returnT
.
getData
()))
{
if
(
returnT
!=
null
&&
CollectionUtils
.
isNotEmpty
(
returnT
.
getData
()))
{
for
(
AttachmentVo
tempAttachmentVo
:
returnT
.
getData
())
{
AttachmentVo
tempKnowledgeDtoAttachmentVo
=
returnT
.
getData
().
stream
()
// 设置附件名称和大小
// 根据ID过滤
if
(
tempAttachmentVo
.
getId
().
equals
(
tempKnowledge
.
getAttachmentId
()))
{
.
filter
(
tempAttachmentVo
->
tempAttachmentVo
.
getId
().
equals
(
tempKnowledgeDto
.
getAttachmentId
()))
knowledgeDto
.
setAttachName
(
tempAttachmentVo
.
getAttachName
());
// 匹配第一个
knowledgeDto
.
setAttachSize
(
tempAttachmentVo
.
getAttachSize
());
.
findFirst
().
orElse
(
null
);
break
;
// 设置附件名称、附件大小
}
if
(
tempKnowledgeDtoAttachmentVo
!=
null
)
{
tempKnowledgeDto
.
setAttachName
(
tempKnowledgeDtoAttachmentVo
.
getAttachName
());
tempKnowledgeDto
.
setAttachSize
(
tempKnowledgeDtoAttachmentVo
.
getAttachSize
());
}
}
}
}
knowledgeDtoList
.
add
(
k
nowledgeDto
);
knowledgeDtoList
.
add
(
tempK
nowledgeDto
);
}
});
knowledgeDtoPageInfo
.
setList
(
knowledgeDtoList
);
knowledgeDtoPageInfo
.
setList
(
knowledgeDtoList
);
knowledgeDtoPageInfo
.
setTotal
(
knowledgePageInfo
.
getTotal
());
knowledgeDtoPageInfo
.
setTotal
(
knowledgePageInfo
.
getTotal
());
knowledgeDtoPageInfo
.
setPageNum
(
knowledgePageInfo
.
getPageNum
());
knowledgeDtoPageInfo
.
setPageNum
(
knowledgePageInfo
.
getPageNum
());
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/controller/SubjectBankController.java
View file @
4a5971c6
...
@@ -28,7 +28,11 @@ import org.springframework.web.multipart.MultipartFile;
...
@@ -28,7 +28,11 @@ import org.springframework.web.multipart.MultipartFile;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.stream.Stream
;
/**
/**
* 题库controller
* 题库controller
...
@@ -98,23 +102,22 @@ public class SubjectBankController extends BaseController {
...
@@ -98,23 +102,22 @@ public class SubjectBankController extends BaseController {
PageInfo
<
SubjectBank
>
page
=
subjectBankService
.
findPage
(
PageUtil
.
pageInfo
(
pageNum
,
pageSize
,
sort
,
order
),
subjectBank
);
PageInfo
<
SubjectBank
>
page
=
subjectBankService
.
findPage
(
PageUtil
.
pageInfo
(
pageNum
,
pageSize
,
sort
,
order
),
subjectBank
);
if
(
CollectionUtils
.
isNotEmpty
(
page
.
getList
()))
{
if
(
CollectionUtils
.
isNotEmpty
(
page
.
getList
()))
{
// 查询分类信息
// 查询分类信息
Set
<
String
>
categoryIdSet
=
new
HashSet
<>();
page
.
getList
().
forEach
(
tempSubjectBank
->
{
categoryIdSet
.
add
(
tempSubjectBank
.
getCategoryId
());
});
SubjectCategory
subjectCategory
=
new
SubjectCategory
();
SubjectCategory
subjectCategory
=
new
SubjectCategory
();
subjectCategory
.
setIds
(
categoryIdSet
.
toArray
(
new
String
[
categoryIdSet
.
size
()]));
// 流处理获取分类ID,去重,转成字符串数组
List
<
SubjectCategory
>
subjectCategoryList
=
subjectCategoryService
.
findListById
(
subjectCategory
);
subjectCategory
.
setIds
(
page
.
getList
().
stream
().
map
(
SubjectBank:
:
getCategoryId
).
distinct
().
toArray
(
String
[]::
new
));
Stream
<
SubjectCategory
>
subjectCategoryStream
=
subjectCategoryService
.
findListById
(
subjectCategory
).
stream
();
if
(
Optional
.
ofNullable
(
subjectCategoryStream
).
isPresent
())
{
page
.
getList
().
forEach
(
tempSubjectBank
->
{
page
.
getList
().
forEach
(
tempSubjectBank
->
{
for
(
SubjectCategory
tempSubjectCategory
:
subjectCategoryList
)
{
SubjectCategory
category
=
subjectCategoryStream
if
(
tempSubjectCategory
.
getId
().
equals
(
tempSubjectBank
.
getCategoryId
()))
{
.
filter
(
tempSubjectCategory
->
tempSubjectCategory
.
getId
().
equals
(
tempSubjectBank
.
getCategoryId
()))
.
findFirst
()
.
orElse
(
null
);
// 设置分类名称
// 设置分类名称
tempSubjectBank
.
setCategoryName
(
tempSubjectCategory
.
getCategoryName
());
if
(
category
!=
null
)
break
;
tempSubjectBank
.
setCategoryName
(
category
.
getCategoryName
());
}
}
});
});
}
}
}
return
page
;
return
page
;
}
}
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/controller/SubjectCategoryController.java
View file @
4a5971c6
...
@@ -14,12 +14,16 @@ import com.github.tangyi.exam.service.SubjectCategoryService;
...
@@ -14,12 +14,16 @@ import com.github.tangyi.exam.service.SubjectCategoryService;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.*
;
import
java.util.ArrayList
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
/**
* 题目分类controller
* 题目分类controller
...
@@ -46,12 +50,14 @@ public class SubjectCategoryController extends BaseController {
...
@@ -46,12 +50,14 @@ public class SubjectCategoryController extends BaseController {
@ApiOperation
(
value
=
"获取分类列表"
)
@ApiOperation
(
value
=
"获取分类列表"
)
public
List
<
SubjectCategoryDto
>
menus
()
{
public
List
<
SubjectCategoryDto
>
menus
()
{
// 查询所有分类
// 查询所有分类
Set
<
SubjectCategory
>
subjectCategorySet
=
new
HashSet
<
SubjectCategory
>(
categoryService
.
findList
(
new
SubjectCategory
()));
List
<
SubjectCategory
>
subjectCategoryList
=
categoryService
.
findList
(
new
SubjectCategory
());
List
<
SubjectCategoryDto
>
subjectCategorySetTreeList
=
new
ArrayList
<
SubjectCategoryDto
>();
if
(
CollectionUtils
.
isNotEmpty
(
subjectCategoryList
))
{
subjectCategorySet
.
forEach
(
subjectCategory
->
subjectCategorySetTreeList
.
add
(
new
SubjectCategoryDto
(
subjectCategory
)));
// 转成dto
// 排序
List
<
SubjectCategoryDto
>
subjectCategorySetTreeList
=
subjectCategoryList
.
stream
().
map
(
SubjectCategoryDto:
:
new
).
distinct
().
collect
(
Collectors
.
toList
());
CollUtil
.
sort
(
subjectCategorySetTreeList
,
Comparator
.
comparingInt
(
SubjectCategoryDto:
:
getSort
));
// 排序、组装树形结构
return
TreeUtil
.
buildTree
(
subjectCategorySetTreeList
,
"-1"
);
return
TreeUtil
.
buildTree
(
CollUtil
.
sort
(
subjectCategorySetTreeList
,
Comparator
.
comparingInt
(
SubjectCategoryDto:
:
getSort
)),
"-1"
);
}
return
new
ArrayList
<>();
}
}
/**
/**
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/controller/SubjectController.java
View file @
4a5971c6
...
@@ -33,9 +33,9 @@ import org.springframework.web.multipart.MultipartFile;
...
@@ -33,9 +33,9 @@ import org.springframework.web.multipart.MultipartFile;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.
ArrayList
;
import
java.util.
*
;
import
java.util.
Date
;
import
java.util.
stream.Collectors
;
import
java.util.
List
;
import
java.util.
stream.Stream
;
/**
/**
* 题目controller
* 题目controller
...
@@ -214,13 +214,15 @@ public class SubjectController extends BaseController {
...
@@ -214,13 +214,15 @@ public class SubjectController extends BaseController {
List
<
Subject
>
subjects
=
new
ArrayList
<>();
List
<
Subject
>
subjects
=
new
ArrayList
<>();
// 根据题目id导出
// 根据题目id导出
if
(
StringUtils
.
isNotEmpty
(
subjectDto
.
getIdString
()))
{
if
(
StringUtils
.
isNotEmpty
(
subjectDto
.
getIdString
()))
{
for
(
String
id
:
subjectDto
.
getIdString
().
split
(
","
))
{
subjects
=
Stream
.
of
(
subjectDto
.
getIdString
().
split
(
","
))
// 根据ID查找题目信息
.
map
(
id
->
{
Subject
subject
=
new
Subject
();
Subject
subject
=
new
Subject
();
subject
.
setId
(
id
);
subject
.
setId
(
id
);
subject
=
subjectService
.
get
(
subject
);
return
subjectService
.
get
(
subject
);
if
(
subject
!=
null
)
}
)
subjects
.
add
(
subject
);
// 过滤收集
}
.
filter
(
Objects:
:
nonNull
).
collect
(
Collectors
.
toList
());
}
else
if
(
StringUtils
.
isNotEmpty
(
subjectDto
.
getExaminationId
()))
{
// 根据考试id导出
}
else
if
(
StringUtils
.
isNotEmpty
(
subjectDto
.
getExaminationId
()))
{
// 根据考试id导出
Subject
subject
=
new
Subject
();
Subject
subject
=
new
Subject
();
subject
.
setExaminationId
(
subjectDto
.
getExaminationId
());
subject
.
setExaminationId
(
subjectDto
.
getExaminationId
());
...
@@ -251,17 +253,17 @@ public class SubjectController extends BaseController {
...
@@ -251,17 +253,17 @@ public class SubjectController extends BaseController {
Assert
.
notNull
(
examinationId
,
CommonConstant
.
IllEGAL_ARGUMENT
);
Assert
.
notNull
(
examinationId
,
CommonConstant
.
IllEGAL_ARGUMENT
);
try
{
try
{
logger
.
debug
(
"开始导入题目数据,分类ID:{}"
,
examinationId
);
logger
.
debug
(
"开始导入题目数据,分类ID:{}"
,
examinationId
);
List
<
Subject
>
subjects
=
MapUtil
.
map2Java
(
Subject
.
class
,
Stream
<
Subject
>
subjectStream
=
MapUtil
.
map2Java
(
Subject
.
class
,
ExcelToolUtil
.
importExcel
(
file
.
getInputStream
(),
SubjectUtil
.
getSubjectMap
()));
ExcelToolUtil
.
importExcel
(
file
.
getInputStream
(),
SubjectUtil
.
getSubjectMap
()))
.
stream
()
;
if
(
CollectionUtils
.
isNotEmpty
(
subjects
))
{
if
(
Optional
.
ofNullable
(
subjectStream
).
isPresent
(
))
{
for
(
Subject
subject
:
subjects
)
{
subjectStream
.
forEach
(
subject
->
{
// 初始化考试ID
// 初始化考试ID
if
(
StringUtils
.
isBlank
(
subject
.
getId
()))
{
if
(
StringUtils
.
isBlank
(
subject
.
getId
()))
{
subject
.
setCommonValue
(
SecurityUtil
.
getCurrentUsername
(),
SysUtil
.
getSysCode
());
subject
.
setCommonValue
(
SecurityUtil
.
getCurrentUsername
(),
SysUtil
.
getSysCode
());
subject
.
setExaminationId
(
examinationId
);
subject
.
setExaminationId
(
examinationId
);
subjectService
.
insert
(
subject
);
subjectService
.
insert
(
subject
);
}
}
}
}
);
// 更新考试的题目数
// 更新考试的题目数
Examination
examination
=
new
Examination
();
Examination
examination
=
new
Examination
();
examination
.
setId
(
examinationId
);
examination
.
setId
(
examinationId
);
...
@@ -297,9 +299,9 @@ public class SubjectController extends BaseController {
...
@@ -297,9 +299,9 @@ public class SubjectController extends BaseController {
success
=
subjectService
.
deleteAll
(
subjectIds
)
>
0
;
success
=
subjectService
.
deleteAll
(
subjectIds
)
>
0
;
Subject
subject
=
new
Subject
();
Subject
subject
=
new
Subject
();
subject
.
setIds
(
subjectIds
);
subject
.
setIds
(
subjectIds
);
List
<
Subject
>
subjectList
=
subjectService
.
findListById
(
subject
);
Stream
<
Subject
>
subjectStream
=
subjectService
.
findListById
(
subject
).
stream
(
);
if
(
CollectionUtils
.
isNotEmpty
(
subjectList
))
{
if
(
Optional
.
ofNullable
(
subjectStream
).
isPresent
(
))
{
subject
List
.
forEach
(
tempSubject
->
{
subject
Stream
.
forEach
(
tempSubject
->
{
// 更新考试的题目数
// 更新考试的题目数
Examination
examination
=
new
Examination
();
Examination
examination
=
new
Examination
();
examination
.
setId
(
tempSubject
.
getExaminationId
());
examination
.
setId
(
tempSubject
.
getExaminationId
());
...
...
service-api-impl/exam-service/src/main/java/com/github/tangyi/exam/service/AnswerService.java
View file @
4a5971c6
...
@@ -3,11 +3,11 @@ package com.github.tangyi.exam.service;
...
@@ -3,11 +3,11 @@ package com.github.tangyi.exam.service;
import
com.github.tangyi.common.core.service.CrudService
;
import
com.github.tangyi.common.core.service.CrudService
;
import
com.github.tangyi.common.core.utils.SysUtil
;
import
com.github.tangyi.common.core.utils.SysUtil
;
import
com.github.tangyi.common.security.utils.SecurityUtil
;
import
com.github.tangyi.common.security.utils.SecurityUtil
;
import
com.github.tangyi.exam.mapper.AnswerMapper
;
import
com.github.tangyi.exam.api.module.Answer
;
import
com.github.tangyi.exam.api.module.Answer
;
import
com.github.tangyi.exam.api.module.ExamRecord
;
import
com.github.tangyi.exam.api.module.ExamRecord
;
import
com.github.tangyi.exam.api.module.IncorrectAnswer
;
import
com.github.tangyi.exam.api.module.IncorrectAnswer
;
import
com.github.tangyi.exam.api.module.Subject
;
import
com.github.tangyi.exam.api.module.Subject
;
import
com.github.tangyi.exam.mapper.AnswerMapper
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.CacheEvict
;
...
@@ -16,9 +16,7 @@ import org.springframework.stereotype.Service;
...
@@ -16,9 +16,7 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Set
;
/**
/**
* 答题service
* 答题service
...
@@ -38,9 +36,6 @@ public class AnswerService extends CrudService<AnswerMapper, Answer> {
...
@@ -38,9 +36,6 @@ public class AnswerService extends CrudService<AnswerMapper, Answer> {
@Autowired
@Autowired
private
ExamRecordService
examRecordService
;
private
ExamRecordService
examRecordService
;
@Autowired
private
ExaminationService
examinationService
;
/**
/**
* 查找答题
* 查找答题
*
*
...
@@ -57,6 +52,7 @@ public class AnswerService extends CrudService<AnswerMapper, Answer> {
...
@@ -57,6 +52,7 @@ public class AnswerService extends CrudService<AnswerMapper, Answer> {
/**
/**
* 根据用户ID、考试ID、考试记录ID、题目ID查找答题
* 根据用户ID、考试ID、考试记录ID、题目ID查找答题
*
* @param answer answer
* @param answer answer
* @return Answer
* @return Answer
* @author tangyi
* @author tangyi
...
@@ -121,37 +117,43 @@ public class AnswerService extends CrudService<AnswerMapper, Answer> {
...
@@ -121,37 +117,43 @@ public class AnswerService extends CrudService<AnswerMapper, Answer> {
*/
*/
@Transactional
@Transactional
public
boolean
submit
(
Answer
answer
)
{
public
boolean
submit
(
Answer
answer
)
{
long
start
=
System
.
currentTimeMillis
();
boolean
success
=
false
;
boolean
success
=
false
;
logger
.
debug
(
"提交答卷:{}, {}"
,
answer
.
getExaminationId
(),
answer
.
getUserId
());
String
currentUsername
=
SecurityUtil
.
getCurrentUsername
();
// 总分
Integer
totalScore
=
0
,
correctNumber
=
0
,
incorrectNumber
=
0
;
// 查找已提交的题目
// 查找已提交的题目
List
<
Answer
>
answerList
=
findList
(
answer
);
List
<
Answer
>
answerList
=
findList
(
answer
);
if
(
CollectionUtils
.
isNotEmpty
(
answerList
))
{
if
(
CollectionUtils
.
isNotEmpty
(
answerList
))
{
// 收集题目id
Set
<
String
>
subjectIdSet
=
new
HashSet
<>();
answerList
.
forEach
(
tempAnswer
->
{
subjectIdSet
.
add
(
tempAnswer
.
getSubjectId
());
});
Subject
subject
=
new
Subject
();
Subject
subject
=
new
Subject
();
subject
.
setIds
(
subjectIdSet
.
toArray
(
new
String
[
subjectIdSet
.
size
()]));
// 获取题目ID,去重,转成字符串数组
subject
.
setIds
(
answerList
.
stream
().
map
(
Answer:
:
getSubjectId
).
distinct
().
toArray
(
String
[]::
new
));
// 查找题目列表
// 查找题目列表
List
<
Subject
>
subjects
=
subjectService
.
findListById
(
subject
);
List
<
Subject
>
subjects
=
subjectService
.
findListById
(
subject
);
if
(
CollectionUtils
.
isNotEmpty
(
subjects
))
{
if
(
CollectionUtils
.
isNotEmpty
(
subjects
))
{
// 保存答题正确的题目分数
List
<
String
>
rightScore
=
new
ArrayList
<>();
answerList
.
forEach
(
tempAnswer
->
{
// 题目集合
subjects
.
stream
()
// 题目ID、题目答案匹配
.
filter
(
tempSubject
->
tempSubject
.
getId
().
equals
(
tempAnswer
.
getSubjectId
())
&&
tempSubject
.
getAnswer
().
equalsIgnoreCase
(
tempAnswer
.
getAnswer
()))
// 记录答题正确的成绩
.
findFirst
().
ifPresent
(
right
->
rightScore
.
add
(
right
.
getScore
()));
});
// 求和计算总分
int
totalScore
=
rightScore
.
stream
().
mapToInt
(
Integer:
:
parseInt
).
sum
();
// 错题列表
// 错题列表
List
<
IncorrectAnswer
>
incorrectAnswers
=
new
ArrayList
<>();
List
<
IncorrectAnswer
>
incorrectAnswers
=
new
ArrayList
<>();
for
(
Subject
tempSubject
:
subjects
)
{
answerList
.
forEach
(
tempAnswer
->
{
for
(
Answer
tempAnswer
:
answerList
)
{
// 题目集合
if
(
tempAnswer
.
getSubjectId
().
equals
(
tempSubject
.
getId
()))
{
subjects
.
stream
()
// 答题正确
// 题目ID、题目答案匹配
if
(
tempSubject
.
getAnswer
().
toUpperCase
().
equalsIgnoreCase
(
tempAnswer
.
getAnswer
()))
{
.
filter
(
tempSubject
->
tempSubject
.
getId
().
equals
(
tempAnswer
.
getSubjectId
())
&&
!
tempSubject
.
getAnswer
().
equalsIgnoreCase
(
tempAnswer
.
getAnswer
()))
totalScore
+=
Integer
.
parseInt
(
tempSubject
.
getScore
());
// 错题
correctNumber
++;
.
findFirst
()
}
else
{
.
ifPresent
(
tempSubject
->
{
incorrectNumber
++;
// 记录错题
// 记录错题
IncorrectAnswer
incorrectAnswer
=
new
IncorrectAnswer
();
IncorrectAnswer
incorrectAnswer
=
new
IncorrectAnswer
();
incorrectAnswer
.
setCommonValue
(
SecurityUtil
.
getCurrentUsername
()
,
SysUtil
.
getSysCode
());
incorrectAnswer
.
setCommonValue
(
currentUsername
,
SysUtil
.
getSysCode
());
incorrectAnswer
.
setExaminationId
(
tempAnswer
.
getExaminationId
());
incorrectAnswer
.
setExaminationId
(
tempAnswer
.
getExaminationId
());
incorrectAnswer
.
setExamRecordId
(
answer
.
getExamRecordId
());
incorrectAnswer
.
setExamRecordId
(
answer
.
getExamRecordId
());
incorrectAnswer
.
setSubjectId
(
tempAnswer
.
getSubjectId
());
incorrectAnswer
.
setSubjectId
(
tempAnswer
.
getSubjectId
());
...
@@ -159,18 +161,16 @@ public class AnswerService extends CrudService<AnswerMapper, Answer> {
...
@@ -159,18 +161,16 @@ public class AnswerService extends CrudService<AnswerMapper, Answer> {
incorrectAnswer
.
setUserId
(
tempAnswer
.
getUserId
());
incorrectAnswer
.
setUserId
(
tempAnswer
.
getUserId
());
incorrectAnswer
.
setIncorrectAnswer
(
tempAnswer
.
getAnswer
());
incorrectAnswer
.
setIncorrectAnswer
(
tempAnswer
.
getAnswer
());
incorrectAnswers
.
add
(
incorrectAnswer
);
incorrectAnswers
.
add
(
incorrectAnswer
);
}
});
}
});
}
}
// 保存成绩
// 保存成绩
ExamRecord
examRecord
=
new
ExamRecord
();
ExamRecord
examRecord
=
new
ExamRecord
();
examRecord
.
setCommonValue
(
SecurityUtil
.
getCurrentUsername
(),
SysUtil
.
getSysCode
());
examRecord
.
setCommonValue
(
SecurityUtil
.
getCurrentUsername
(),
SysUtil
.
getSysCode
());
examRecord
.
setId
(
answer
.
getExamRecordId
());
examRecord
.
setId
(
answer
.
getExamRecordId
());
examRecord
.
setEndTime
(
examRecord
.
getCreateDate
());
examRecord
.
setEndTime
(
examRecord
.
getCreateDate
());
examRecord
.
setScore
(
totalScore
.
toString
(
));
examRecord
.
setScore
(
Integer
.
toString
(
totalScore
));
examRecord
.
setCorrectNumber
(
correctNumber
.
toString
(
));
examRecord
.
setCorrectNumber
(
String
.
valueOf
(
rightScore
.
size
()
));
examRecord
.
setInCorrectNumber
(
incorrectNumber
.
toString
(
));
examRecord
.
setInCorrectNumber
(
String
.
valueOf
(
incorrectAnswers
.
size
()
));
success
=
examRecordService
.
update
(
examRecord
)
>
0
;
success
=
examRecordService
.
update
(
examRecord
)
>
0
;
// 保存错题
// 保存错题
ExamRecord
searchExamRecord
=
new
ExamRecord
();
ExamRecord
searchExamRecord
=
new
ExamRecord
();
...
@@ -185,6 +185,7 @@ public class AnswerService extends CrudService<AnswerMapper, Answer> {
...
@@ -185,6 +185,7 @@ public class AnswerService extends CrudService<AnswerMapper, Answer> {
}
}
}
}
}
}
logger
.
debug
(
"提交答卷,用户名:{},考试ID:{},耗时:{}ms"
,
currentUsername
,
answer
.
getExaminationId
(),
System
.
currentTimeMillis
()
-
start
);
return
success
;
return
success
;
}
}
}
}
service-api-impl/exam-service/src/main/resources/mapper/AnswerMapper.xml
View file @
4a5971c6
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
</resultMap>
</resultMap>
<sql
id=
"answerColumns"
>
<sql
id=
"answerColumns"
>
a.id
as "id"
,
a.id,
a.user_id,
a.user_id,
a.examination_id,
a.examination_id,
a.exam_record_id,
a.exam_record_id,
...
...
service-api-impl/exam-service/src/main/resources/mapper/CourseMapper.xml
View file @
4a5971c6
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
</resultMap>
</resultMap>
<sql
id=
"courseColumns"
>
<sql
id=
"courseColumns"
>
a.id
as "id"
,
a.id,
a.course_name,
a.course_name,
a.college,
a.college,
a.major,
a.major,
...
...
service-api-impl/exam-service/src/main/resources/mapper/ExamRecodeMapper.xml
View file @
4a5971c6
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
</resultMap>
</resultMap>
<sql
id=
"examRecordColumns"
>
<sql
id=
"examRecordColumns"
>
a.id
as "id"
,
a.id,
a.user_id,
a.user_id,
a.examination_id,
a.examination_id,
a.examination_name,
a.examination_name,
...
...
service-api-impl/exam-service/src/main/resources/mapper/ExaminationMapper.xml
View file @
4a5971c6
...
@@ -27,7 +27,7 @@
...
@@ -27,7 +27,7 @@
</resultMap>
</resultMap>
<sql
id=
"examinationColumns"
>
<sql
id=
"examinationColumns"
>
a.id
as "id"
,
a.id,
a.examination_name,
a.examination_name,
a.type,
a.type,
a.attention,
a.attention,
...
...
service-api-impl/exam-service/src/main/resources/mapper/IncorrectAnswerMapper.xml
View file @
4a5971c6
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
</resultMap>
</resultMap>
<sql
id=
"incorrectAnswerColumns"
>
<sql
id=
"incorrectAnswerColumns"
>
a.id
as "id"
,
a.id,
a.user_id,
a.user_id,
a.examination_id,
a.examination_id,
a.exam_record_id,
a.exam_record_id,
...
...
service-api-impl/exam-service/src/main/resources/mapper/KnowledgeMapper.xml
View file @
4a5971c6
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
</resultMap>
</resultMap>
<sql
id=
"knowledgeColumns"
>
<sql
id=
"knowledgeColumns"
>
a.id
as "id"
,
a.id,
a.knowledge_name,
a.knowledge_name,
a.knowledge_desc,
a.knowledge_desc,
a.attachment_id,
a.attachment_id,
...
...
service-api-impl/exam-service/src/main/resources/mapper/SubjectBankMapper.xml
View file @
4a5971c6
...
@@ -27,7 +27,7 @@
...
@@ -27,7 +27,7 @@
</resultMap>
</resultMap>
<sql
id=
"subjectBankColumns"
>
<sql
id=
"subjectBankColumns"
>
a.id
as "id"
,
a.id,
a.category_id,
a.category_id,
a.serial_number,
a.serial_number,
a.subject_name,
a.subject_name,
...
...
service-api-impl/exam-service/src/main/resources/mapper/SubjectCategoryMapper.xml
View file @
4a5971c6
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
</resultMap>
</resultMap>
<sql
id=
"subjectCategoryColumns"
>
<sql
id=
"subjectCategoryColumns"
>
a.id
as "id"
,
a.id,
a.category_name,
a.category_name,
a.category_desc,
a.category_desc,
a.parent_id,
a.parent_id,
...
...
service-api-impl/exam-service/src/main/resources/mapper/SubjectMapper.xml
View file @
4a5971c6
...
@@ -27,7 +27,7 @@
...
@@ -27,7 +27,7 @@
</resultMap>
</resultMap>
<sql
id=
"subjectColumns"
>
<sql
id=
"subjectColumns"
>
a.id
as "id"
,
a.id,
a.examination_id,
a.examination_id,
a.serial_number,
a.serial_number,
a.subject_name,
a.subject_name,
...
...
service-api-impl/exam-service/src/main/resources/mybatis-config.xml
deleted
100644 → 0
View file @
8a2ca63e
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<!-- 驼峰转换 -->
<setting
name=
"mapUnderscoreToCamelCase"
value=
"true"
/>
<!-- 延迟加载 -->
<setting
name=
"lazyLoadingEnabled"
value=
"true"
/>
</settings>
<typeAliases>
<package
name=
"com.tangyi.module"
/>
</typeAliases>
</configuration>
\ No newline at end of file
service-api-impl/user-service/pom.xml
View file @
4a5971c6
...
@@ -60,12 +60,6 @@
...
@@ -60,12 +60,6 @@
<artifactId>
mysql-connector-java
</artifactId>
<artifactId>
mysql-connector-java
</artifactId>
</dependency>
</dependency>
<!-- druid阿里巴巴数据库连接池 -->
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid
</artifactId>
</dependency>
<!-- mybatis -->
<!-- mybatis -->
<dependency>
<dependency>
<groupId>
org.mybatis.spring.boot
</groupId>
<groupId>
org.mybatis.spring.boot
</groupId>
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/config/MybatisConfig.java
deleted
100644 → 0
View file @
8a2ca63e
package
com
.
github
.
tangyi
.
user
.
config
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.jdbc.datasource.DataSourceTransactionManager
;
import
org.springframework.transaction.PlatformTransactionManager
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
import
org.springframework.transaction.annotation.TransactionManagementConfigurer
;
import
javax.sql.DataSource
;
/**
* mybatis 配置
*
* @author tangyi
* @date 2019/3/16 21:03
*/
@Configuration
@EnableTransactionManagement
public
class
MybatisConfig
implements
TransactionManagementConfigurer
{
private
final
DataSource
dataSource
;
@Autowired
public
MybatisConfig
(
DataSource
dataSource
)
{
this
.
dataSource
=
dataSource
;
}
@Override
public
PlatformTransactionManager
annotationDrivenTransactionManager
()
{
return
new
DataSourceTransactionManager
(
dataSource
);
}
}
service-api-impl/user-service/src/main/java/com/github/tangyi/user/config/RabbitConfig.java
View file @
4a5971c6
...
@@ -33,4 +33,15 @@ public class RabbitConfig {
...
@@ -33,4 +33,15 @@ public class RabbitConfig {
public
Queue
delQueue
()
{
public
Queue
delQueue
()
{
return
new
Queue
(
MqConstant
.
DEL_GATEWAY_ROUTE_QUEUE
);
return
new
Queue
(
MqConstant
.
DEL_GATEWAY_ROUTE_QUEUE
);
}
}
/**
* 刷新路由
*
* @return Queue
*/
@Bean
public
Queue
refreshQueue
()
{
return
new
Queue
(
MqConstant
.
REFRESH_GATEWAY_ROUTE_QUEUE
);
}
}
}
service-api-impl/user-service/src/main/java/com/github/tangyi/user/controller/AttachmentController.java
View file @
4a5971c6
...
@@ -30,8 +30,8 @@ import javax.servlet.http.HttpServletRequest;
...
@@ -30,8 +30,8 @@ import javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.io.OutputStream
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
/**
* 附件信息管理
* 附件信息管理
...
@@ -253,12 +253,12 @@ public class AttachmentController extends BaseController {
...
@@ -253,12 +253,12 @@ public class AttachmentController extends BaseController {
attachment
.
setIds
(
attachmentVo
.
getIds
());
attachment
.
setIds
(
attachmentVo
.
getIds
());
List
<
Attachment
>
attachmentList
=
attachmentService
.
findListById
(
attachment
);
List
<
Attachment
>
attachmentList
=
attachmentService
.
findListById
(
attachment
);
if
(
CollectionUtils
.
isNotEmpty
(
attachmentList
))
{
if
(
CollectionUtils
.
isNotEmpty
(
attachmentList
))
{
List
<
AttachmentVo
>
attachmentVoList
=
new
ArrayList
<>();
// 流处理转换成AttachmentVo
attachmentList
.
forEach
(
tempAttachment
->
{
List
<
AttachmentVo
>
attachmentVoList
=
attachmentList
.
stream
().
map
(
tempAttachment
->
{
AttachmentVo
tempAttachmentVo
=
new
AttachmentVo
();
AttachmentVo
tempAttachmentVo
=
new
AttachmentVo
();
BeanUtils
.
copyProperties
(
tempAttachment
,
tempAttachmentVo
);
BeanUtils
.
copyProperties
(
tempAttachment
,
tempAttachmentVo
);
attachmentVoList
.
add
(
tempAttachmentVo
)
;
return
tempAttachmentVo
;
});
})
.
collect
(
Collectors
.
toList
())
;
returnT
=
new
ResponseBean
<>(
attachmentVoList
);
returnT
=
new
ResponseBean
<>(
attachmentVoList
);
}
}
return
returnT
;
return
returnT
;
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/controller/DeptController.java
View file @
4a5971c6
...
@@ -15,13 +15,17 @@ import com.github.tangyi.user.service.DeptService;
...
@@ -15,13 +15,17 @@ import com.github.tangyi.user.service.DeptService;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.*
;
import
java.util.ArrayList
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
/**
/**
* 部门controller
* 部门controller
...
@@ -47,13 +51,17 @@ public class DeptController extends BaseController {
...
@@ -47,13 +51,17 @@ public class DeptController extends BaseController {
@GetMapping
(
value
=
"/depts"
)
@GetMapping
(
value
=
"/depts"
)
@ApiOperation
(
value
=
"获取部门列表"
)
@ApiOperation
(
value
=
"获取部门列表"
)
public
List
<
DeptDto
>
depts
()
{
public
List
<
DeptDto
>
depts
()
{
// 查询所有部门
Dept
dept
=
new
Dept
();
Set
<
Dept
>
deptSet
=
new
HashSet
<
Dept
>(
deptService
.
findList
(
new
Dept
()));
dept
.
setApplicationCode
(
SysUtil
.
getSysCode
());
List
<
DeptDto
>
deptTreeList
=
new
ArrayList
<
DeptDto
>();
// 查询部门集合
deptSet
.
forEach
(
dept
->
deptTreeList
.
add
(
new
DeptDto
(
dept
)));
Stream
<
Dept
>
deptStream
=
deptService
.
findList
(
dept
).
stream
();
// 排序
if
(
Optional
.
ofNullable
(
deptStream
).
isPresent
())
{
CollUtil
.
sort
(
deptTreeList
,
Comparator
.
comparingInt
(
DeptDto:
:
getSort
));
// 流处理转成DeptDto
return
TreeUtil
.
buildTree
(
deptTreeList
,
"-1"
);
List
<
DeptDto
>
deptTreeList
=
deptStream
.
map
(
DeptDto:
:
new
).
collect
(
Collectors
.
toList
());
// 排序、构建树形结构
return
TreeUtil
.
buildTree
(
CollUtil
.
sort
(
deptTreeList
,
Comparator
.
comparingInt
(
DeptDto:
:
getSort
)),
"-1"
);
}
return
new
ArrayList
<>();
}
}
/**
/**
...
@@ -144,14 +152,14 @@ public class DeptController extends BaseController {
...
@@ -144,14 +152,14 @@ public class DeptController extends BaseController {
ResponseBean
<
List
<
DeptVo
>>
returnT
=
null
;
ResponseBean
<
List
<
DeptVo
>>
returnT
=
null
;
Dept
dept
=
new
Dept
();
Dept
dept
=
new
Dept
();
dept
.
setIds
(
deptVo
.
getIds
());
dept
.
setIds
(
deptVo
.
getIds
());
List
<
Dept
>
depts
=
deptService
.
findListById
(
dept
);
Stream
<
Dept
>
deptStream
=
deptService
.
findListById
(
dept
).
stream
(
);
if
(
CollectionUtils
.
isNotEmpty
(
depts
))
{
if
(
Optional
.
ofNullable
(
deptStream
).
isPresent
(
))
{
List
<
DeptVo
>
deptVoList
=
new
ArrayList
<>();
// 流处理转换成DeptVo
depts
.
forEach
(
tempDept
->
{
List
<
DeptVo
>
deptVoList
=
deptStream
.
map
(
tempDept
->
{
DeptVo
tempDeptVo
=
new
DeptVo
();
DeptVo
tempDeptVo
=
new
DeptVo
();
BeanUtils
.
copyProperties
(
tempDept
,
tempDeptVo
);
BeanUtils
.
copyProperties
(
tempDept
,
tempDeptVo
);
deptVoList
.
add
(
tempDeptVo
)
;
return
tempDeptVo
;
});
})
.
collect
(
Collectors
.
toList
())
;
returnT
=
new
ResponseBean
<>(
deptVoList
);
returnT
=
new
ResponseBean
<>(
deptVoList
);
}
}
return
returnT
;
return
returnT
;
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/controller/MenuController.java
View file @
4a5971c6
...
@@ -10,13 +10,13 @@ import com.github.tangyi.common.core.web.BaseController;
...
@@ -10,13 +10,13 @@ import com.github.tangyi.common.core.web.BaseController;
import
com.github.tangyi.common.log.annotation.Log
;
import
com.github.tangyi.common.log.annotation.Log
;
import
com.github.tangyi.common.security.constant.SecurityConstant
;
import
com.github.tangyi.common.security.constant.SecurityConstant
;
import
com.github.tangyi.common.security.utils.SecurityUtil
;
import
com.github.tangyi.common.security.utils.SecurityUtil
;
import
com.github.tangyi.user.api.constant.MenuConstant
;
import
com.github.tangyi.user.api.dto.MenuDto
;
import
com.github.tangyi.user.api.dto.MenuDto
;
import
com.github.tangyi.user.api.module.Menu
;
import
com.github.tangyi.user.api.module.Menu
;
import
com.github.tangyi.user.service.MenuService
;
import
com.github.tangyi.user.service.MenuService
;
import
com.github.tangyi.user.utils.MenuUtil
;
import
com.github.tangyi.user.utils.MenuUtil
;
import
com.google.common.net.HttpHeaders
;
import
com.google.common.net.HttpHeaders
;
import
io.swagger.annotations.*
;
import
io.swagger.annotations.*
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.access.prepost.PreAuthorize
;
...
@@ -27,6 +27,8 @@ import javax.servlet.http.HttpServletRequest;
...
@@ -27,6 +27,8 @@ import javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
/**
/**
* 菜单controller
* 菜单controller
...
@@ -50,34 +52,29 @@ public class MenuController extends BaseController {
...
@@ -50,34 +52,29 @@ public class MenuController extends BaseController {
@GetMapping
(
value
=
"/userMenu"
)
@GetMapping
(
value
=
"/userMenu"
)
@ApiOperation
(
value
=
"获取当前用户的菜单列表"
)
@ApiOperation
(
value
=
"获取当前用户的菜单列表"
)
public
List
<
MenuDto
>
userMenu
()
{
public
List
<
MenuDto
>
userMenu
()
{
// 查询菜单
List
<
MenuDto
>
menuDtoList
=
new
ArrayList
<>();
Set
<
Menu
>
menuSet
=
new
HashSet
<>();
// 根据角色code查找菜单
SecurityUtil
.
getCurrentAuthentication
().
getAuthorities
().
forEach
(
roleName
->
{
SecurityUtil
.
getCurrentAuthentication
().
getAuthorities
().
stream
()
// 按角色过滤
.
filter
(
authority
->
authority
.
getAuthority
()
!=
null
&&
authority
.
getAuthority
().
startsWith
(
"role_"
))
// 查找菜单
.
forEach
(
roleName
->
{
// 获取角色的菜单
// 获取角色的菜单
List
<
Menu
>
menus
=
menuService
.
findMenuByRole
(
roleName
.
getAuthority
());
Stream
<
Menu
>
menuStream
=
menuService
.
findMenuByRole
(
roleName
.
getAuthority
()).
stream
();
if
(
CollectionUtils
.
isNotEmpty
(
menus
))
{
if
(
Optional
.
ofNullable
(
menuStream
).
isPresent
())
{
menus
.
forEach
(
menu
->
{
// 筛选出类型为菜单的菜单,放进menuMap,防止重复,用菜单的ID作为key
// 检查是否已经存在
menuStream
boolean
exist
=
false
;
// 菜单类型
for
(
Menu
existMenu
:
menuSet
)
{
.
filter
(
menu
->
MenuConstant
.
MENU_TYPE_MENU
.
equals
(
menu
.
getType
()))
if
(
existMenu
.
getId
().
equals
(
menu
.
getId
())
&&
!
exist
)
// dto封装
exist
=
true
;
.
map
(
MenuDto:
:
new
)
}
// 去重
// 不存在
.
distinct
()
if
(!
exist
)
.
forEach
(
menuDtoList:
:
add
);
menuSet
.
add
(
menu
);
});
}
});
List
<
MenuDto
>
menuTreeList
=
new
ArrayList
<
MenuDto
>();
menuSet
.
forEach
(
menuVo
->
{
if
(
CommonConstant
.
MENU
.
equals
(
menuVo
.
getType
()))
{
menuTreeList
.
add
(
new
MenuDto
(
menuVo
));
}
}
});
});
CollUtil
.
sort
(
menuTreeList
,
Comparator
.
comparingInt
(
MenuDto:
:
getSort
));
// 排序、构建树形关系
return
TreeUtil
.
buildTree
(
menuTreeList
,
"-1"
);
return
TreeUtil
.
buildTree
(
CollUtil
.
sort
(
menuDtoList
,
Comparator
.
comparingInt
(
MenuDto:
:
getSort
))
,
"-1"
);
}
}
/**
/**
...
@@ -89,12 +86,16 @@ public class MenuController extends BaseController {
...
@@ -89,12 +86,16 @@ public class MenuController extends BaseController {
@ApiOperation
(
value
=
"获取树形菜单列表"
)
@ApiOperation
(
value
=
"获取树形菜单列表"
)
public
List
<
MenuDto
>
menus
()
{
public
List
<
MenuDto
>
menus
()
{
// 查询所有菜单
// 查询所有菜单
Set
<
Menu
>
menuSet
=
new
HashSet
<
Menu
>(
menuService
.
findList
(
new
Menu
()));
Menu
condition
=
new
Menu
();
List
<
MenuDto
>
menuTreeList
=
new
ArrayList
<
MenuDto
>();
condition
.
setApplicationCode
(
SysUtil
.
getSysCode
());
menuSet
.
forEach
(
menuVo
->
menuTreeList
.
add
(
new
MenuDto
(
menuVo
)));
Stream
<
Menu
>
menuStream
=
menuService
.
findAllList
(
condition
).
stream
();
// 排序
if
(
Optional
.
ofNullable
(
menuStream
).
isPresent
())
{
CollUtil
.
sort
(
menuTreeList
,
Comparator
.
comparingInt
(
MenuDto:
:
getSort
));
// 转成MenuDto
return
TreeUtil
.
buildTree
(
menuTreeList
,
"-1"
);
List
<
MenuDto
>
menuDtoList
=
menuStream
.
map
(
MenuDto:
:
new
).
collect
(
Collectors
.
toList
());
// 排序、构建树形关系
return
TreeUtil
.
buildTree
(
CollUtil
.
sort
(
menuDtoList
,
Comparator
.
comparingInt
(
MenuDto:
:
getSort
)),
"-1"
);
}
return
new
ArrayList
<>();
}
}
/**
/**
...
@@ -223,10 +224,12 @@ public class MenuController extends BaseController {
...
@@ -223,10 +224,12 @@ public class MenuController extends BaseController {
@ApiOperation
(
value
=
"根据角色查找菜单"
,
notes
=
"根据角色code获取角色菜单"
)
@ApiOperation
(
value
=
"根据角色查找菜单"
,
notes
=
"根据角色code获取角色菜单"
)
@ApiImplicitParam
(
name
=
"roleCode"
,
value
=
"角色code"
,
required
=
true
,
dataType
=
"String"
,
paramType
=
"path"
)
@ApiImplicitParam
(
name
=
"roleCode"
,
value
=
"角色code"
,
required
=
true
,
dataType
=
"String"
,
paramType
=
"path"
)
public
List
<
String
>
roleTree
(
@PathVariable
String
roleCode
)
{
public
List
<
String
>
roleTree
(
@PathVariable
String
roleCode
)
{
List
<
Menu
>
menus
=
menuService
.
findMenuByRole
(
roleCode
);
// 根据角色查找菜单
List
<
String
>
menuList
=
new
ArrayList
<>();
Stream
<
Menu
>
menuStream
=
menuService
.
findMenuByRole
(
roleCode
).
stream
();
menus
.
forEach
(
menu
->
menuList
.
add
(
menu
.
getId
()));
// 获取菜单ID
return
menuList
;
if
(
Optional
.
ofNullable
(
menuStream
).
isPresent
())
return
menuStream
.
map
(
Menu:
:
getId
).
collect
(
Collectors
.
toList
());
return
new
ArrayList
<>();
}
}
/**
/**
...
@@ -247,19 +250,15 @@ public class MenuController extends BaseController {
...
@@ -247,19 +250,15 @@ public class MenuController extends BaseController {
response
.
setCharacterEncoding
(
"utf-8"
);
response
.
setCharacterEncoding
(
"utf-8"
);
response
.
setContentType
(
"multipart/form-data"
);
response
.
setContentType
(
"multipart/form-data"
);
response
.
setHeader
(
HttpHeaders
.
CONTENT_DISPOSITION
,
Servlets
.
getDownName
(
request
,
"菜单信息"
+
new
SimpleDateFormat
(
"yyyyMMddhhmmssSSS"
).
format
(
new
Date
())
+
".xlsx"
));
response
.
setHeader
(
HttpHeaders
.
CONTENT_DISPOSITION
,
Servlets
.
getDownName
(
request
,
"菜单信息"
+
new
SimpleDateFormat
(
"yyyyMMddhhmmssSSS"
).
format
(
new
Date
())
+
".xlsx"
));
List
<
Menu
>
menus
=
new
ArrayList
<>()
;
List
<
Menu
>
menus
;
// 导出所有
// 导出所有
if
(
StringUtils
.
isEmpty
(
menuVo
.
getIdString
()))
{
if
(
StringUtils
.
isEmpty
(
menuVo
.
getIdString
()))
{
Menu
menu
=
new
Menu
();
Menu
menu
=
new
Menu
();
menus
=
menuService
.
findList
(
menu
);
menus
=
menuService
.
findList
(
menu
);
}
else
{
// 导出选中
}
else
{
// 导出选中
Set
<
String
>
menuIdSet
=
new
HashSet
<>();
for
(
String
id
:
menuVo
.
getIdString
().
split
(
","
))
{
if
(
StringUtils
.
isNotBlank
(
id
))
menuIdSet
.
add
(
id
);
}
Menu
menu
=
new
Menu
();
Menu
menu
=
new
Menu
();
menu
.
setIds
(
menuIdSet
.
toArray
(
new
String
[
menuIdSet
.
size
()]));
// 按逗号切割ID,流处理获取ID集合,去重,转成字符串数组
menu
.
setIds
(
Stream
.
of
(
menuVo
.
getIdString
().
split
(
","
)).
filter
(
StringUtils:
:
isNotBlank
).
distinct
().
toArray
(
String
[]::
new
));
menus
=
menuService
.
findListById
(
menu
);
menus
=
menuService
.
findListById
(
menu
);
}
}
ExcelToolUtil
.
exportExcel
(
request
.
getInputStream
(),
response
.
getOutputStream
(),
MapUtil
.
java2Map
(
menus
),
MenuUtil
.
getMenuMap
());
ExcelToolUtil
.
exportExcel
(
request
.
getInputStream
(),
response
.
getOutputStream
(),
MapUtil
.
java2Map
(
menus
),
MenuUtil
.
getMenuMap
());
...
@@ -283,13 +282,13 @@ public class MenuController extends BaseController {
...
@@ -283,13 +282,13 @@ public class MenuController extends BaseController {
public
ResponseBean
<
Boolean
>
importMenu
(
@ApiParam
(
value
=
"要上传的文件"
,
required
=
true
)
MultipartFile
file
,
HttpServletRequest
request
)
{
public
ResponseBean
<
Boolean
>
importMenu
(
@ApiParam
(
value
=
"要上传的文件"
,
required
=
true
)
MultipartFile
file
,
HttpServletRequest
request
)
{
try
{
try
{
logger
.
debug
(
"开始导入菜单数据"
);
logger
.
debug
(
"开始导入菜单数据"
);
List
<
Menu
>
menus
=
MapUtil
.
map2Java
(
Menu
.
class
,
Stream
<
Menu
>
menuStream
=
MapUtil
.
map2Java
(
Menu
.
class
,
ExcelToolUtil
.
importExcel
(
file
.
getInputStream
(),
MenuUtil
.
getMenuMap
()));
ExcelToolUtil
.
importExcel
(
file
.
getInputStream
(),
MenuUtil
.
getMenuMap
()))
.
stream
()
;
if
(
CollectionUtils
.
isNotEmpty
(
menus
))
{
if
(
Optional
.
ofNullable
(
menuStream
).
isPresent
(
))
{
for
(
Menu
menu
:
menus
)
{
menuStream
.
forEach
(
menu
->
{
if
(
menuService
.
update
(
menu
)
<
1
)
if
(
menuService
.
update
(
menu
)
<
1
)
menuService
.
insert
(
menu
);
menuService
.
insert
(
menu
);
}
}
);
}
}
return
new
ResponseBean
<>(
Boolean
.
TRUE
);
return
new
ResponseBean
<>(
Boolean
.
TRUE
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/controller/RoleController.java
View file @
4a5971c6
...
@@ -20,15 +20,16 @@ import io.swagger.annotations.Api;
...
@@ -20,15 +20,16 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
/**
/**
* 角色controller
* 角色controller
...
@@ -101,8 +102,9 @@ public class RoleController extends BaseController {
...
@@ -101,8 +102,9 @@ public class RoleController extends BaseController {
Role
role
)
{
Role
role
)
{
// 查询所属部门
// 查询所属部门
PageInfo
<
Role
>
pageInfo
=
roleService
.
findPage
(
PageUtil
.
pageInfo
(
pageNum
,
pageSize
,
sort
,
order
),
role
);
PageInfo
<
Role
>
pageInfo
=
roleService
.
findPage
(
PageUtil
.
pageInfo
(
pageNum
,
pageSize
,
sort
,
order
),
role
);
if
(
CollectionUtils
.
isNotEmpty
(
pageInfo
.
getList
()))
{
Stream
<
Role
>
roleStream
=
pageInfo
.
getList
().
stream
();
pageInfo
.
getList
().
forEach
(
tempRole
->
{
if
(
Optional
.
ofNullable
(
roleStream
).
isPresent
())
{
roleStream
.
forEach
(
tempRole
->
{
RoleDept
roleDept
=
new
RoleDept
();
RoleDept
roleDept
=
new
RoleDept
();
roleDept
.
setRoleId
(
tempRole
.
getId
());
roleDept
.
setRoleId
(
tempRole
.
getId
());
// 查询角色部门关系
// 查询角色部门关系
...
@@ -136,17 +138,13 @@ public class RoleController extends BaseController {
...
@@ -136,17 +138,13 @@ public class RoleController extends BaseController {
List
<
Role
>
roles
=
new
ArrayList
<>();
List
<
Role
>
roles
=
new
ArrayList
<>();
if
(
StringUtils
.
isNotBlank
(
deptId
))
{
if
(
StringUtils
.
isNotBlank
(
deptId
))
{
// 获取角色部门关系
// 获取角色部门关系
List
<
RoleDept
>
roleDepts
=
roleDeptService
.
getRoleByDeptId
(
deptId
);
Stream
<
RoleDept
>
roleDeptStream
=
roleDeptService
.
getRoleByDeptId
(
deptId
).
stream
();
// 遍历
// 获取角色列表
if
(
CollectionUtils
.
isNotEmpty
(
roleDepts
))
{
if
(
Optional
.
ofNullable
(
roleDeptStream
).
isPresent
())
{
roleDepts
.
forEach
(
roleDept
->
{
Role
role
=
new
Role
();
Role
role
=
new
Role
();
role
.
setId
(
roleDept
.
getRoleId
());
// 流处理获取角色ID集合,去重,转成字符串数组
// 查询部门信息
role
.
setIds
(
roleDeptStream
.
map
(
RoleDept:
:
getRoleId
).
distinct
().
toArray
(
String
[]::
new
));
role
=
roleService
.
get
(
role
);
roles
=
roleService
.
findListById
(
role
);
if
(
role
!=
null
)
roles
.
add
(
role
);
});
}
}
}
}
return
roles
;
return
roles
;
...
@@ -190,7 +188,7 @@ public class RoleController extends BaseController {
...
@@ -190,7 +188,7 @@ public class RoleController extends BaseController {
role
=
roleService
.
get
(
role
);
role
=
roleService
.
get
(
role
);
// 保存角色菜单关系
// 保存角色菜单关系
if
(
role
!=
null
&&
StringUtils
.
isNotBlank
(
deptId
))
if
(
role
!=
null
&&
StringUtils
.
isNotBlank
(
deptId
))
success
=
roleMenuService
.
saveRoleMenus
(
role
.
getId
(),
Arrays
.
asList
(
deptId
.
split
(
","
)))
>
0
;
success
=
roleMenuService
.
saveRoleMenus
(
role
.
getId
(),
Stream
.
of
(
deptId
.
split
(
","
)).
collect
(
Collectors
.
toList
(
)))
>
0
;
}
}
return
new
ResponseBean
<>(
success
);
return
new
ResponseBean
<>(
success
);
}
}
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/controller/UserController.java
View file @
4a5971c6
...
@@ -37,7 +37,12 @@ import javax.servlet.http.HttpServletRequest;
...
@@ -37,7 +37,12 @@ import javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.security.Principal
;
import
java.security.Principal
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
/**
/**
* @author tangyi
* @author tangyi
...
@@ -140,58 +145,48 @@ public class UserController extends BaseController {
...
@@ -140,58 +145,48 @@ public class UserController extends BaseController {
PageInfo
<
User
>
page
=
userService
.
findPage
(
PageUtil
.
pageInfo
(
pageNum
,
pageSize
,
sort
,
order
),
user
);
PageInfo
<
User
>
page
=
userService
.
findPage
(
PageUtil
.
pageInfo
(
pageNum
,
pageSize
,
sort
,
order
),
user
);
List
<
User
>
users
=
page
.
getList
();
List
<
User
>
users
=
page
.
getList
();
if
(
CollectionUtils
.
isNotEmpty
(
users
))
{
if
(
CollectionUtils
.
isNotEmpty
(
users
))
{
// 收集用户、部门id
Set
<
String
>
deptIdSet
=
new
HashSet
<>(),
userIdSet
=
new
HashSet
<>();
users
.
forEach
(
tempUser
->
{
if
(
tempUser
.
getDeptId
()
!=
null
)
deptIdSet
.
add
(
tempUser
.
getDeptId
());
userIdSet
.
add
(
tempUser
.
getId
());
});
// 批量查找部门
List
<
Dept
>
deptList
=
null
;
if
(!
deptIdSet
.
isEmpty
())
{
Dept
dept
=
new
Dept
();
Dept
dept
=
new
Dept
();
dept
.
setIds
(
deptIdSet
.
toArray
(
new
String
[
deptIdSet
.
size
()]));
// 流处理获取部门ID集合,转成字符串数组
deptList
=
deptService
.
findListById
(
dept
);
dept
.
setIds
(
users
.
stream
().
filter
(
tempUser
->
tempUser
.
getDeptId
()
!=
null
).
map
(
User:
:
getDeptId
).
distinct
().
toArray
(
String
[]::
new
)
);
}
// 批量查找部门
List
<
Dept
>
deptList
=
deptService
.
findListById
(
dept
);
// 批量查找角色
//
流处理获取用户ID集合,根据用户ID
批量查找角色
List
<
UserRole
>
userRoles
=
userRoleService
.
getByUserIds
(
new
ArrayList
<>(
userIdSet
));
List
<
UserRole
>
userRoles
=
userRoleService
.
getByUserIds
(
users
.
stream
().
map
(
User:
:
getId
).
collect
(
Collectors
.
toList
()
));
List
<
Role
>
roleList
=
new
ArrayList
<>();
List
<
Role
>
roleList
=
new
ArrayList
<>();
if
(
CollectionUtils
.
isNotEmpty
(
userRoles
))
{
if
(
CollectionUtils
.
isNotEmpty
(
userRoles
))
{
Set
<
String
>
roleIdSet
=
new
HashSet
<>();
userRoles
.
forEach
(
tempUserRole
->
{
roleIdSet
.
add
(
tempUserRole
.
getRoleId
());
});
Role
role
=
new
Role
();
Role
role
=
new
Role
();
role
.
setIds
(
roleIdSet
.
toArray
(
new
String
[
roleIdSet
.
size
()]));
// 获取角色ID集合,转成字节数组
// 查询所有角色
role
.
setIds
(
userRoles
.
stream
().
map
(
UserRole:
:
getRoleId
).
distinct
().
toArray
(
String
[]::
new
));
// 批量查找角色
roleList
=
roleService
.
findListById
(
role
);
roleList
=
roleService
.
findListById
(
role
);
}
}
//
设置部门、角色信息
//
遍历用户集合,设置部门、角色
for
(
User
tempUser
:
users
)
{
List
<
Role
>
finalRoleList
=
roleList
;
List
<
Role
>
userRoleList
=
new
ArrayList
<>();
users
.
forEach
(
tempUser
->
{
// 设置部门信息
// 设置部门信息
if
(
deptList
!=
null
)
{
if
(
CollectionUtils
.
isNotEmpty
(
deptList
))
{
for
(
Dept
tempDept
:
deptList
)
{
// 用户所属部门
if
(
tempDept
.
getId
().
equals
(
tempUser
.
getDeptId
()))
{
Dept
userDept
=
deptList
.
stream
()
tempUser
.
setDeptName
(
tempDept
.
getDeptName
());
// 按部门ID找到部门信息
tempUser
.
setDeptId
(
tempDept
.
getId
());
.
filter
(
tempDept
->
tempDept
.
getId
().
equals
(
tempUser
.
getDeptId
()))
break
;
.
findFirst
().
orElse
(
null
);
}
if
(
userDept
!=
null
)
{
}
tempUser
.
setDeptName
(
userDept
.
getDeptName
());
}
tempUser
.
setDeptId
(
userDept
.
getId
());
for
(
UserRole
tempUserRole
:
userRoles
)
{
}
if
(
tempUser
.
getId
().
equals
(
tempUserRole
.
getUserId
()))
{
}
for
(
Role
role
:
roleList
)
{
// 设置角色信息
if
(
role
.
getId
().
equals
(
tempUserRole
.
getRoleId
()))
{
if
(
CollectionUtils
.
isNotEmpty
(
userRoles
))
{
userRoleList
.
add
(
role
);
List
<
Role
>
userRoleList
=
new
ArrayList
<>();
}
userRoles
.
stream
()
}
// 过滤
}
.
filter
(
tempUserRole
->
tempUser
.
getId
().
equals
(
tempUserRole
.
getUserId
()))
}
.
forEach
(
tempUserRole
->
finalRoleList
.
stream
()
.
filter
(
role
->
role
.
getId
().
equals
(
tempUserRole
.
getRoleId
()))
.
forEach
(
userRoleList:
:
add
));
tempUser
.
setRoleList
(
userRoleList
);
tempUser
.
setRoleList
(
userRoleList
);
}
}
});
}
}
return
page
;
return
page
;
}
}
...
@@ -259,9 +254,7 @@ public class UserController extends BaseController {
...
@@ -259,9 +254,7 @@ public class UserController extends BaseController {
// 新密码不为空
// 新密码不为空
if
(
StringUtils
.
isNotEmpty
(
userDto
.
getNewPassword
()))
{
if
(
StringUtils
.
isNotEmpty
(
userDto
.
getNewPassword
()))
{
if
(!
encoder
.
matches
(
userDto
.
getOldPassword
(),
userDto
.
getPassword
()))
{
if
(!
encoder
.
matches
(
userDto
.
getOldPassword
(),
userDto
.
getPassword
()))
{
ResponseBean
<
Boolean
>
returnT
=
new
ResponseBean
<>(
Boolean
.
FALSE
);
return
new
ResponseBean
<>(
Boolean
.
FALSE
,
"新旧密码不匹配"
);
returnT
.
setMsg
(
"新旧密码不匹配"
);
return
returnT
;
}
else
{
}
else
{
// 新旧密码一致,修改密码
// 新旧密码一致,修改密码
userDto
.
setPassword
(
encoder
.
encode
(
userDto
.
getNewPassword
()));
userDto
.
setPassword
(
encoder
.
encode
(
userDto
.
getNewPassword
()));
...
@@ -314,13 +307,9 @@ public class UserController extends BaseController {
...
@@ -314,13 +307,9 @@ public class UserController extends BaseController {
response
.
setHeader
(
HttpHeaders
.
CONTENT_DISPOSITION
,
Servlets
.
getDownName
(
request
,
"用户信息"
+
new
SimpleDateFormat
(
"yyyyMMddhhmmssSSS"
).
format
(
new
Date
())
+
".xlsx"
));
response
.
setHeader
(
HttpHeaders
.
CONTENT_DISPOSITION
,
Servlets
.
getDownName
(
request
,
"用户信息"
+
new
SimpleDateFormat
(
"yyyyMMddhhmmssSSS"
).
format
(
new
Date
())
+
".xlsx"
));
List
<
User
>
users
;
List
<
User
>
users
;
if
(
StringUtils
.
isNotEmpty
(
userVo
.
getIdString
()))
{
if
(
StringUtils
.
isNotEmpty
(
userVo
.
getIdString
()))
{
List
<
String
>
userIdList
=
new
ArrayList
<>();
for
(
String
id
:
userVo
.
getIdString
().
split
(
","
))
{
if
(
StringUtils
.
isNotEmpty
(
id
))
userIdList
.
add
(
id
);
}
User
user
=
new
User
();
User
user
=
new
User
();
user
.
setIds
(
userIdList
.
toArray
(
new
String
[
userIdList
.
size
()]));
// 按逗号切割ID,流处理获取ID集合,去重,转成字符串数组
user
.
setIds
(
Stream
.
of
(
userVo
.
getIdString
().
split
(
","
)).
filter
(
StringUtils:
:
isNotBlank
).
distinct
().
toArray
(
String
[]::
new
));
users
=
userService
.
findListById
(
user
);
users
=
userService
.
findListById
(
user
);
}
else
{
// 导出全部用户
}
else
{
// 导出全部用户
users
=
userService
.
findList
(
new
User
());
users
=
userService
.
findList
(
new
User
());
...
@@ -400,14 +389,13 @@ public class UserController extends BaseController {
...
@@ -400,14 +389,13 @@ public class UserController extends BaseController {
ResponseBean
<
List
<
UserVo
>>
returnT
=
null
;
ResponseBean
<
List
<
UserVo
>>
returnT
=
null
;
User
user
=
new
User
();
User
user
=
new
User
();
user
.
setIds
(
userVo
.
getIds
());
user
.
setIds
(
userVo
.
getIds
());
List
<
User
>
users
=
userService
.
findListById
(
user
);
Stream
<
User
>
userStream
=
userService
.
findListById
(
user
).
stream
();
if
(
CollectionUtils
.
isNotEmpty
(
users
))
{
if
(
Optional
.
ofNullable
(
userStream
).
isPresent
())
{
List
<
UserVo
>
userVoList
=
new
ArrayList
<>();
List
<
UserVo
>
userVoList
=
userStream
.
map
(
tempUser
->
{
users
.
forEach
(
tempUser
->
{
UserVo
tempUserVo
=
new
UserVo
();
UserVo
tempUserVo
=
new
UserVo
();
BeanUtils
.
copyProperties
(
tempUser
,
tempUserVo
);
BeanUtils
.
copyProperties
(
tempUser
,
tempUserVo
);
userVoList
.
add
(
tempUserVo
)
;
return
tempUserVo
;
});
})
.
collect
(
Collectors
.
toList
())
;
returnT
=
new
ResponseBean
<>(
userVoList
);
returnT
=
new
ResponseBean
<>(
userVoList
);
}
}
return
returnT
;
return
returnT
;
...
@@ -441,9 +429,10 @@ public class UserController extends BaseController {
...
@@ -441,9 +429,10 @@ public class UserController extends BaseController {
Role
role
=
new
Role
();
Role
role
=
new
Role
();
role
.
setIsDefault
(
RoleConstant
.
IS_DEFAULT_ROLE
);
role
.
setIsDefault
(
RoleConstant
.
IS_DEFAULT_ROLE
);
// 查询默认角色
// 查询默认角色
List
<
Role
>
roleList
=
roleService
.
findList
(
role
);
Stream
<
Role
>
roleStream
=
roleService
.
findList
(
role
).
stream
();
if
(
CollectionUtils
.
isNotEmpty
(
roleList
))
{
if
(
Optional
.
ofNullable
(
roleStream
).
isPresent
())
{
Role
defaultRole
=
roleList
.
get
(
0
);
Role
defaultRole
=
roleStream
.
findFirst
().
orElse
(
null
);
if
(
defaultRole
!=
null
)
{
UserRole
userRole
=
new
UserRole
();
UserRole
userRole
=
new
UserRole
();
userRole
.
setCommonValue
(
SecurityUtil
.
getCurrentUsername
(),
SysUtil
.
getSysCode
());
userRole
.
setCommonValue
(
SecurityUtil
.
getCurrentUsername
(),
SysUtil
.
getSysCode
());
userRole
.
setUserId
(
user
.
getId
());
userRole
.
setUserId
(
user
.
getId
());
...
@@ -452,6 +441,7 @@ public class UserController extends BaseController {
...
@@ -452,6 +441,7 @@ public class UserController extends BaseController {
success
=
userRoleService
.
insert
(
userRole
)
>
0
;
success
=
userRoleService
.
insert
(
userRole
)
>
0
;
}
}
}
}
}
return
new
ResponseBean
<>(
success
);
return
new
ResponseBean
<>(
success
);
}
}
}
}
service-api-impl/user-service/src/main/java/com/github/tangyi/user/service/AttachmentService.java
View file @
4a5971c6
...
@@ -11,6 +11,4 @@ import org.springframework.stereotype.Service;
...
@@ -11,6 +11,4 @@ import org.springframework.stereotype.Service;
*/
*/
@Service
@Service
public
class
AttachmentService
extends
CrudService
<
AttachmentMapper
,
Attachment
>
{
public
class
AttachmentService
extends
CrudService
<
AttachmentMapper
,
Attachment
>
{
}
}
service-api-impl/user-service/src/main/java/com/github/tangyi/user/service/MenuService.java
View file @
4a5971c6
...
@@ -34,12 +34,26 @@ public class MenuService extends CrudService<MenuMapper, Menu> {
...
@@ -34,12 +34,26 @@ public class MenuService extends CrudService<MenuMapper, Menu> {
* @author tangyi
* @author tangyi
* @date 2018/8/27 16:00
* @date 2018/8/27 16:00
*/
*/
@Cacheable
(
value
=
"menu"
,
key
=
"#role
+ '_menu'
"
)
@Cacheable
(
value
=
"menu"
,
key
=
"#role"
)
public
List
<
Menu
>
findMenuByRole
(
String
role
)
{
public
List
<
Menu
>
findMenuByRole
(
String
role
)
{
return
menuMapper
.
findByRole
(
role
);
return
menuMapper
.
findByRole
(
role
);
}
}
/**
/**
* 查询全部菜单
*
* @param menu menu
* @return List
* @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
);
}
/**
* 新增菜单
* 新增菜单
*
*
* @param menu menu
* @param menu menu
...
@@ -50,11 +64,6 @@ public class MenuService extends CrudService<MenuMapper, Menu> {
...
@@ -50,11 +64,6 @@ public class MenuService extends CrudService<MenuMapper, Menu> {
@Transactional
@Transactional
@Override
@Override
public
int
insert
(
Menu
menu
)
{
public
int
insert
(
Menu
menu
)
{
// 初始化权限
/*if (MenuConstant.MENU_TYPE_MENU.equals(menu.getType())) {
List<Menu> menus = MenuUtil.initMenuPermission(menu);
menus.forEach(super::insert);
}*/
return
super
.
insert
(
menu
);
return
super
.
insert
(
menu
);
}
}
...
...
service-api-impl/user-service/src/main/java/com/github/tangyi/user/service/UserService.java
View file @
4a5971c6
...
@@ -4,20 +4,18 @@ import com.github.tangyi.common.core.constant.CommonConstant;
...
@@ -4,20 +4,18 @@ import com.github.tangyi.common.core.constant.CommonConstant;
import
com.github.tangyi.common.core.service.CrudService
;
import
com.github.tangyi.common.core.service.CrudService
;
import
com.github.tangyi.common.core.utils.IdGen
;
import
com.github.tangyi.common.core.utils.IdGen
;
import
com.github.tangyi.common.core.utils.SysUtil
;
import
com.github.tangyi.common.core.utils.SysUtil
;
import
com.github.tangyi.common.core.vo.Role
;
import
com.github.tangyi.common.core.vo.UserVo
;
import
com.github.tangyi.common.core.vo.UserVo
;
import
com.github.tangyi.common.security.constant.SecurityConstant
;
import
com.github.tangyi.common.security.constant.SecurityConstant
;
import
com.github.tangyi.common.security.utils.SecurityUtil
;
import
com.github.tangyi.common.security.utils.SecurityUtil
;
import
com.github.tangyi.user.api.constant.MenuConstant
;
import
com.github.tangyi.user.api.dto.UserDto
;
import
com.github.tangyi.user.api.dto.UserDto
;
import
com.github.tangyi.user.api.dto.UserInfoDto
;
import
com.github.tangyi.user.api.dto.UserInfoDto
;
import
com.github.tangyi.user.api.module.Menu
;
import
com.github.tangyi.user.api.module.Menu
;
import
com.github.tangyi.user.api.module.User
;
import
com.github.tangyi.user.api.module.User
;
import
com.github.tangyi.user.api.module.UserRole
;
import
com.github.tangyi.user.api.module.UserRole
;
import
com.github.tangyi.user.mapper.MenuMapper
;
import
com.github.tangyi.user.mapper.UserMapper
;
import
com.github.tangyi.user.mapper.UserMapper
;
import
com.github.tangyi.user.mapper.UserRoleMapper
;
import
com.github.tangyi.user.mapper.UserRoleMapper
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.CacheEvict
;
...
@@ -27,9 +25,7 @@ import org.springframework.stereotype.Service;
...
@@ -27,9 +25,7 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
/**
/**
...
@@ -48,7 +44,7 @@ public class UserService extends CrudService<UserMapper, User> {
...
@@ -48,7 +44,7 @@ public class UserService extends CrudService<UserMapper, User> {
private
UserRoleMapper
userRoleMapper
;
private
UserRoleMapper
userRoleMapper
;
@Autowired
@Autowired
private
Menu
Mapper
menuMapper
;
private
Menu
Service
menuService
;
@Autowired
@Autowired
private
RedisTemplate
redisTemplate
;
private
RedisTemplate
redisTemplate
;
...
@@ -92,28 +88,31 @@ public class UserService extends CrudService<UserMapper, User> {
...
@@ -92,28 +88,31 @@ public class UserService extends CrudService<UserMapper, User> {
UserInfoDto
user
=
new
UserInfoDto
();
UserInfoDto
user
=
new
UserInfoDto
();
if
(
userVo
!=
null
)
{
if
(
userVo
!=
null
)
{
user
.
setUser
(
userVo
);
user
.
setUser
(
userVo
);
// 用户角色列表
// 用户角色
List
<
Role
>
roleList
=
userVo
.
getRoleList
();
List
<
String
>
roles
=
new
ArrayList
<>();
List
<
String
>
roleCodes
=
new
ArrayList
<>();
// 用户权限
if
(
CollectionUtils
.
isNotEmpty
(
roleList
))
{
List
<
String
>
permissions
=
new
ArrayList
<>();
roleList
.
forEach
(
role
->
{
// 根据角色获取权限
if
(!
SecurityConstant
.
BASE_ROLE
.
equals
(
role
.
getRoleName
()))
if
(
CollectionUtils
.
isNotEmpty
(
userVo
.
getRoleList
()))
{
roleCodes
.
add
(
role
.
getRoleCode
());
userVo
.
getRoleList
().
stream
()
});
// 过滤普通用户角色
.
filter
(
role
->
!
SecurityConstant
.
BASE_ROLE
.
equals
(
role
.
getRoleName
()))
.
forEach
(
role
->
{
// 根据角色查找菜单
List
<
Menu
>
menuList
=
menuService
.
findMenuByRole
(
role
.
getRoleCode
());
if
(
CollectionUtils
.
isNotEmpty
(
menuList
))
{
menuList
.
stream
()
// 获取权限菜单
.
filter
(
menu
->
MenuConstant
.
MENU_TYPE_PERMISSION
.
equals
(
menu
.
getType
()))
// 获取权限
.
forEach
(
menu
->
permissions
.
add
(
menu
.
getPermission
()));
}
}
String
[]
roleCodeArray
=
roleCodes
.
toArray
(
new
String
[
roleCodes
.
size
()]);
// 保存角色code
user
.
setRoles
(
roleCodeArray
);
roles
.
add
(
role
.
getRoleCode
());
// 菜单列表
Set
<
Menu
>
menuSet
=
new
HashSet
<>();
for
(
String
role
:
roleCodeArray
)
menuSet
.
addAll
(
menuMapper
.
findByRole
(
role
));
// 权限列表
Set
<
String
>
permissions
=
new
HashSet
<>();
menuSet
.
forEach
(
menu
->
{
if
(
StringUtils
.
isNotEmpty
(
menu
.
getPermission
()))
permissions
.
add
(
menu
.
getPermission
());
});
});
user
.
setPermissions
(
permissions
.
toArray
(
new
String
[
permissions
.
size
()]));
}
user
.
setRoles
(
roles
.
toArray
(
new
String
[
0
]));
user
.
setPermissions
(
permissions
.
toArray
(
new
String
[
0
]));
}
}
return
user
;
return
user
;
}
}
...
...
service-api-impl/user-service/src/main/resources/mapper/AttachmentMapper.xml
View file @
4a5971c6
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
</resultMap>
</resultMap>
<sql
id=
"attachmentColumns"
>
<sql
id=
"attachmentColumns"
>
a.id
as "id"
,
a.id,
a.attach_name,
a.attach_name,
a.attach_size,
a.attach_size,
a.group_name,
a.group_name,
...
...
service-api-impl/user-service/src/main/resources/mapper/DeptMapper.xml
View file @
4a5971c6
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
</resultMap>
</resultMap>
<sql
id=
"deptColumns"
>
<sql
id=
"deptColumns"
>
a.id
as "id"
,
a.id,
a.dept_name,
a.dept_name,
a.dept_desc,
a.dept_desc,
a.dept_leader,
a.dept_leader,
...
...
service-api-impl/user-service/src/main/resources/mapper/LogMapper.xml
View file @
4a5971c6
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
</resultMap>
</resultMap>
<sql
id=
"logColumns"
>
<sql
id=
"logColumns"
>
a.id
as "id"
,
a.id,
a.type,
a.type,
a.title,
a.title,
a.ip,
a.ip,
...
...
service-api-impl/user-service/src/main/resources/mapper/MenuMapper.xml
View file @
4a5971c6
...
@@ -23,7 +23,7 @@
...
@@ -23,7 +23,7 @@
</resultMap>
</resultMap>
<sql
id=
"menuColumns"
>
<sql
id=
"menuColumns"
>
a.id
as "id"
,
a.id,
a.name,
a.name,
a.permission,
a.permission,
a.url,
a.url,
...
@@ -113,6 +113,14 @@
...
@@ -113,6 +113,14 @@
<include
refid=
"whereColumnList"
/>
<include
refid=
"whereColumnList"
/>
</select>
</select>
<select
id=
"findAllList"
resultMap=
"menuResultMap"
>
SELECT
<include
refid=
"menuColumns"
/>
FROM sys_menu a
WHERE a.del_flag = 0
<include
refid=
"whereColumnList"
/>
</select>
<select
id=
"findListById"
resultMap=
"menuResultMap"
>
<select
id=
"findListById"
resultMap=
"menuResultMap"
>
SELECT
SELECT
<include
refid=
"menuColumns"
/>
<include
refid=
"menuColumns"
/>
...
...
service-api-impl/user-service/src/main/resources/mapper/RoleDeptMapper.xml
View file @
4a5971c6
...
@@ -8,9 +8,9 @@
...
@@ -8,9 +8,9 @@
</resultMap>
</resultMap>
<sql
id=
"roleDeptColumns"
>
<sql
id=
"roleDeptColumns"
>
a.id
as "id"
,
a.id,
a.role_id
as "role_id"
,
a.role_id,
a.dept_id
as "dept_id"
a.dept_id
</sql>
</sql>
<select
id=
"get"
resultMap=
"roleDeptResultMap"
>
<select
id=
"get"
resultMap=
"roleDeptResultMap"
>
...
...
service-api-impl/user-service/src/main/resources/mapper/RoleMapper.xml
View file @
4a5971c6
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
</resultMap>
</resultMap>
<sql
id=
"roleColumns"
>
<sql
id=
"roleColumns"
>
a.id
as "id"
,
a.id,
a.role_name,
a.role_name,
a.role_code,
a.role_code,
a.role_desc,
a.role_desc,
...
...
service-api-impl/user-service/src/main/resources/mapper/RoleMenuMapper.xml
View file @
4a5971c6
...
@@ -8,9 +8,9 @@
...
@@ -8,9 +8,9 @@
</resultMap>
</resultMap>
<sql
id=
"roleMenuColumns"
>
<sql
id=
"roleMenuColumns"
>
a.id
as "id"
,
a.id,
a.role_id
as "role_id"
,
a.role_id,
a.menu_id
as "menu_id"
a.menu_id
</sql>
</sql>
<insert
id=
"insert"
>
<insert
id=
"insert"
>
...
...
service-api-impl/user-service/src/main/resources/mapper/RouteMapper.xml
View file @
4a5971c6
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
</resultMap>
</resultMap>
<sql
id=
"routeColumns"
>
<sql
id=
"routeColumns"
>
a.id
as "id"
,
a.id,
a.route_id,
a.route_id,
a.route_name,
a.route_name,
a.predicates,
a.predicates,
...
...
service-api-impl/user-service/src/main/resources/mapper/UserMapper.xml
View file @
4a5971c6
...
@@ -60,7 +60,7 @@
...
@@ -60,7 +60,7 @@
</resultMap>
</resultMap>
<sql
id=
"userColumns"
>
<sql
id=
"userColumns"
>
a.id
as "id"
,
a.id,
a.name,
a.name,
a.username,
a.username,
a.password,
a.password,
...
...
service-api-impl/user-service/src/main/resources/mapper/UserRoleMapper.xml
View file @
4a5971c6
...
@@ -8,9 +8,9 @@
...
@@ -8,9 +8,9 @@
</resultMap>
</resultMap>
<sql
id=
"userRoleColumns"
>
<sql
id=
"userRoleColumns"
>
a.id
as "id"
,
a.id,
a.user_id
as "userId"
,
a.user_id,
a.role_id
as "roleId"
a.role_id
</sql>
</sql>
<select
id=
"getByUserId"
resultMap=
"userResultMap"
>
<select
id=
"getByUserId"
resultMap=
"userResultMap"
>
...
...
service-api-impl/user-service/src/main/resources/mybatis-config.xml
deleted
100644 → 0
View file @
8a2ca63e
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<!-- 驼峰转换 -->
<setting
name=
"mapUnderscoreToCamelCase"
value=
"true"
/>
<!-- 延迟加载 -->
<setting
name=
"lazyLoadingEnabled"
value=
"true"
/>
</settings>
<typeAliases>
<package
name=
"com.tangyi.module"
/>
</typeAliases>
</configuration>
\ No newline at end of file
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