Commit 06a9c8fd by tangyi

调整开源协议为MIT、网关支持动态路由、优化其它功能

parent 3ea8a693
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
MIT License
Copyright (c) 2019 慕容若冰
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
......@@ -6,7 +6,7 @@
重写[spring-cloud-online-exam](https://gitee.com/wells2333/spring-cloud-online-exam)
采用前后端分离技术
采用前后端分离技术
前端采用`vue2.0`,通过`jwt`和后端交互
......@@ -59,6 +59,7 @@
- 角色管理:角色信息增删改查、分配权限
- 菜单管理:菜单信息增删改查、导入导出
- 终端管理:管理OAuth2.0的客户端,如client_id、client_secret、access_token有效时间等
- 路由管理:网关路由管理,包括路由的增删改查、刷新路由等
系统监控:监控服务、日志等
- 日志监控:查看系统日志
......@@ -111,8 +112,7 @@
## 后续
- [ ] 网关实现基于数据库、Redis的动态路由
- [ ] zipkin链路监控
- [ ] zipkin链路监控完善
- [ ] 容器化部署文档
- [ ] 业务功能完善
- [ ] 补充相关中间件的文档
......
......@@ -44,14 +44,24 @@ public class CommonConstant {
public static final String PAGE_NUM = "pageNum";
/**
* 默认页数
* 分页大小
*/
public static final String PAGE_NUM_DEFAULT = "1";
public static final String PAGE_SIZE = "pageSize";
/**
* 分页大小
* 排序
*/
public static final String PAGE_SIZE = "pageSize";
public static final String SORT = "sort";
/**
* 排序方向
*/
public static final String ORDER = "order";
/**
* 默认页数
*/
public static final String PAGE_NUM_DEFAULT = "1";
/**
* 默认分页大小
......@@ -127,5 +137,6 @@ public class CommonConstant {
* 保存code的前缀
*/
public static final String DEFAULT_CODE_KEY = "DEFAULT_CODE_KEY";
}
package com.github.tangyi.common.core.constant;
/**
* @author tangyi
* @date 2019/4/2 20:48
*/
public class MqConstant {
/**
* 修改路由
*/
public static final String EDIT_GATEWAY_ROUTE_QUEUE = "edit_gateway_route_queue";
/**
* 删除路由
*/
public static final String DEL_GATEWAY_ROUTE_QUEUE = "del_gateway_route_queue";
/**
* 刷新路由
*/
public static final String REFRESH_GATEWAY_ROUTE_QUEUE = "refresh_gateway_route_queue";
}
package com.github.tangyi.common.core.model;
import com.github.tangyi.common.core.persistence.BaseEntity;
/**
* 路由信息
*
* @author tangyi
* @date 2019/4/2 14:52
*/
public class Route extends BaseEntity<Route> {
/**
* 路由ID
*/
private String routeId;
/**
* 路由名称
*/
private String routeName;
/**
* 断言
*/
private String predicates;
/**
* 过滤器
*/
private String filters;
/**
* URI
*/
private String uri;
/**
* 排序
*/
private String sort;
/**
* 启用禁用
*/
private String status;
public String getRouteId() {
return routeId;
}
public void setRouteId(String routeId) {
this.routeId = routeId;
}
public String getRouteName() {
return routeName;
}
public void setRouteName(String routeName) {
this.routeName = routeName;
}
public String getPredicates() {
return predicates;
}
public void setPredicates(String predicates) {
this.predicates = predicates;
}
public String getFilters() {
return filters;
}
public void setFilters(String filters) {
this.filters = filters;
}
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public String getSort() {
return sort;
}
public void setSort(String sort) {
this.sort = sort;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}
package com.github.tangyi.common.core.utils;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
/**
* Created by tangyi on 2017/3/14.
*/
public class JsonMapper extends ObjectMapper {
private static final long serialVersionUID = 1L;
private static Logger logger = LoggerFactory.getLogger(JsonMapper.class);
private static JsonMapper mapper;
public static JsonMapper getInstance() {
if (mapper == null){
mapper = new JsonMapper().enableSimple();
}
return mapper;
}
public String toJson(Object object) {
try {
return this.writeValueAsString(object);
} catch (IOException e) {
logger.warn("将解析JSON为字符串失败:" + object, e);
return null;
}
}
public <T> T fromJson(String jsonString, Class<T> clazz) {
if (StringUtils.isEmpty(jsonString)) {
return null;
}
try {
return this.readValue(jsonString, clazz);
} catch (IOException e) {
logger.warn("将解析JSON为对象失败:" + jsonString, e);
return null;
}
}
public <T> T fromJson(String jsonString, JavaType javaType) {
if (StringUtils.isEmpty(jsonString)) {
return null;
}
try {
return (T) this.readValue(jsonString, javaType);
} catch (IOException e) {
logger.warn("将解析JSON为对象失败:" + jsonString, e);
return null;
}
}
public static Object fromJsonObject(String jsonString, JavaType javaType){
return JsonMapper.getInstance().fromJson(jsonString, javaType);
}
public JavaType createCollectionType(Class<?> collectionClass, Class<?>... elementClasses) {
return this.getTypeFactory().constructParametricType(collectionClass, elementClasses);
}
public JsonMapper enableSimple() {
this.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
this.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
return this;
}
public ObjectMapper getMapper() {
return this;
}
public static String toJsonString(Object object){
return JsonMapper.getInstance().toJson(object);
}
public static Object fromJsonString(String jsonString, Class<?> clazz){
return JsonMapper.getInstance().fromJson(jsonString, clazz);
}
}
package com.github.tangyi.gateway.module;
package com.github.tangyi.common.core.vo;
import java.util.LinkedHashMap;
import java.util.Map;
......@@ -9,7 +9,7 @@ import java.util.Map;
* @author tangyi
* @date 2019/3/27 11:07
*/
public class GatewayFilterDefinition {
public class RouteFilterVo {
/**
* Filter Name
......@@ -19,7 +19,7 @@ public class GatewayFilterDefinition {
/**
* 对应的路由规则
*/
private Map<String, String> args = new LinkedHashMap<String, String>();
private Map<String, String> args = new LinkedHashMap<>();
public String getName() {
return name;
......
package com.github.tangyi.gateway.module;
package com.github.tangyi.common.core.vo;
import java.util.LinkedHashMap;
import java.util.Map;
......@@ -9,7 +9,7 @@ import java.util.Map;
* @author tangyi
* @date 2019/3/27 11:08
*/
public class GatewayPredicateDefinition {
public class RoutePredicateVo {
/**
* 断言对应的Name
......@@ -19,7 +19,7 @@ public class GatewayPredicateDefinition {
/**
* 配置的断言规则
*/
private Map<String, String> args = new LinkedHashMap<String, String>();
private Map<String, String> args = new LinkedHashMap<>();
public String getName() {
return name;
......
package com.github.tangyi.gateway.module;
package com.github.tangyi.common.core.vo;
import java.util.ArrayList;
import java.util.List;
......@@ -9,22 +9,27 @@ import java.util.List;
* @author tangyi
* @date 2019/3/27 11:06
*/
public class GatewayRouteDefinition {
public class RouteVo {
/**
* 路由的Id
*/
private String id;
private String routeId;
/**
* 路由名称
*/
private String routeName;
/**
* 路由断言集合配置
*/
private List<GatewayPredicateDefinition> predicates = new ArrayList<>();
private List<RoutePredicateVo> predicates = new ArrayList<>();
/**
* 路由过滤器集合配置
*/
private List<GatewayFilterDefinition> filters = new ArrayList<>();
private List<RouteFilterVo> filters = new ArrayList<>();
/**
* 路由规则转发的目标uri
......@@ -36,27 +41,37 @@ public class GatewayRouteDefinition {
*/
private int order = 0;
public String getId() {
return id;
/**
* 排序
*/
private String sort;
/**
* 启用禁用
*/
private String status;
public String getRouteId() {
return routeId;
}
public void setId(String id) {
this.id = id;
public void setRouteId(String routeId) {
this.routeId = routeId;
}
public List<GatewayPredicateDefinition> getPredicates() {
public List<RoutePredicateVo> getPredicates() {
return predicates;
}
public void setPredicates(List<GatewayPredicateDefinition> predicates) {
public void setPredicates(List<RoutePredicateVo> predicates) {
this.predicates = predicates;
}
public List<GatewayFilterDefinition> getFilters() {
public List<RouteFilterVo> getFilters() {
return filters;
}
public void setFilters(List<GatewayFilterDefinition> filters) {
public void setFilters(List<RouteFilterVo> filters) {
this.filters = filters;
}
......@@ -75,4 +90,28 @@ public class GatewayRouteDefinition {
public void setOrder(int order) {
this.order = order;
}
public String getRouteName() {
return routeName;
}
public void setRouteName(String routeName) {
this.routeName = routeName;
}
public String getSort() {
return sort;
}
public void setSort(String sort) {
this.sort = sort;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}
......@@ -12,6 +12,16 @@ public class SecurityConstant {
public static final String BASE_ROLE = "ROLE_USER";
/**
* 管理员角色
*/
public static final String ROLE_ADMIN = "ROLE_ADMIN";
/**
* 老师角色
*/
public static final String ROLE_TEACHER = "ROLE_TEACHER";
/**
* token
*/
public static final String TOKEN_USER_DETAIL = "token-user-detail";
......
......@@ -75,7 +75,7 @@ ignore:
- /v2/api-docs
- /csrf
- /actuator/**
- /hystrix.stream
- /hystrix.sender
- /v1/user/findUserByUsername/**
- /v1/code/**
- /v1/attachment/download
......
......@@ -89,7 +89,7 @@ ignore:
- /v2/api-docs
- /csrf
- /actuator/**
- /hystrix.stream
- /hystrix.sender
- /v1/user/findUserByUsername/**
- /v1/code/**
- /v1/attachment/download
......
......@@ -4,6 +4,11 @@ spring:
redis:
host: ${REDIS_HOST:192.168.0.213}
port: ${REDIS_PORT:6379}
rabbitmq:
host: ${RABBIT_HOST:localhost}
port: ${RABBIT_PORT:5672}
username: guest
password: guest
boot:
admin:
client:
......@@ -22,30 +27,6 @@ spring:
# zipkin 配置
zipkin:
base-url: http://localhost:9411 # 指定了Zipkin服务器的地址
cloud:
gateway:
routes:
- id: auth-service
uri: lb://auth-service
predicates:
- Path=/api/auth/**
filters:
- StripPrefix=2
- RemoveRequestHeader=Cookie, Set-Cookie
- id: user-service
uri: lb://user-service
predicates:
- Path=/api/user/**
filters:
- StripPrefix=2
- RemoveRequestHeader=Cookie, Set-Cookie
- id: exam-service
uri: lb://exam-service
predicates:
- Path=/api/exam/**
filters:
- StripPrefix=2
- RemoveRequestHeader=Cookie, Set-Cookie
security:
encode:
......
......@@ -107,8 +107,9 @@ ignore:
- /v2/api-docs
- /csrf
- /actuator/**
- /hystrix.stream
- /hystrix.sender
- /v1/user/findUserByUsername/**
- /v1/user/register
- /v1/code/**
- /v1/attachment/download
- /v1/log/**
......
......@@ -11,7 +11,7 @@
Target Server Version : 50710
File Encoding : 65001
Date: 31/03/2019 15:16:50
Date: 07/04/2019 21:11:11
*/
SET NAMES utf8mb4;
......@@ -47,6 +47,6 @@ CREATE TABLE `oauth_client_details` (
-- ----------------------------
-- Records of oauth_client_details
-- ----------------------------
INSERT INTO `oauth_client_details` VALUES ('471037a0c1be4df99b40e3f84141cc56', 'web_app', NULL, 'spring-microservice-exam-secret', '$2a$10$S84wOzmAw4wqYBzAqNtmPOx1ZRWdDl9omm/W8T1hhW8S9EK2u57xG', 'read,write', 'password,authorization_code,refresh_token,implicit', NULL, NULL, '3600', '21600', NULL, NULL, 'admin', '2019-03-30 23:43:07', 'admin', '2019-03-31 15:06:55', '0', 'EXAM');
INSERT INTO `oauth_client_details` VALUES ('471037a0c1be4df99b40e3f84141cc56', 'web_app', NULL, 'spring-microservice-exam-secret', '$2a$10$eDZwlN8oMoExblOCDDLc2OIS1JFxYnn3iWScWOkvT9UommlXmBK.6', 'read,write', 'password,authorization_code,refresh_token,implicit', NULL, NULL, '3600', '21600', NULL, NULL, 'admin', '2019-03-30 23:43:07', 'admin', '2019-04-06 23:39:29', '0', 'EXAM');
SET FOREIGN_KEY_CHECKS = 1;
doc/images/image_ui_menu.png

70.7 KB | W: | H:

doc/images/image_ui_menu.png

53.2 KB | W: | H:

doc/images/image_ui_menu.png
doc/images/image_ui_menu.png
doc/images/image_ui_menu.png
doc/images/image_ui_menu.png
  • 2-up
  • Swipe
  • Onion skin
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
doc/产品设计/系统架构图.png

26.9 KB | W: | H:

doc/产品设计/系统架构图.png

67.8 KB | W: | H:

doc/产品设计/系统架构图.png
doc/产品设计/系统架构图.png
doc/产品设计/系统架构图.png
doc/产品设计/系统架构图.png
  • 2-up
  • Swipe
  • Onion skin
package com.github.tangyi.gateway.config;
import com.github.tangyi.common.core.constant.MqConstant;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* RabbitMq配置
*
* @author tangyi
* @date 2019/4/2 17:56
*/
@Configuration
public class RabbitConfig {
/**
* 修改路由
*
* @return Queue
*/
@Bean
public Queue editQueue() {
return new Queue(MqConstant.EDIT_GATEWAY_ROUTE_QUEUE);
}
/**
* 删除路由
*
* @return Queue
*/
@Bean
public Queue delQueue() {
return new Queue(MqConstant.DEL_GATEWAY_ROUTE_QUEUE);
}
/**
* 刷新路由
*
* @return Queue
*/
@Bean
public Queue refreshQueue() {
return new Queue(MqConstant.REFRESH_GATEWAY_ROUTE_QUEUE);
}
}
package com.github.tangyi.gateway.config;
import com.github.tangyi.common.core.constant.CommonConstant;
import com.github.tangyi.common.core.model.Route;
import com.github.tangyi.common.core.utils.JsonMapper;
import com.github.tangyi.gateway.receiver.GatewayRouteReceiver;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
/**
* 动态路由实现:修改数据库路由配置,用户服务发送路由更新消息,网关消费消息,更新路由配置
* 依赖Redis,如果Redis被清空,需要手动刷新加载路由列表
*
* @author tangyi
* @date 2019/4/2 14:40
*/
@Configuration
public class RouteInitConfig {
private static final Logger logger = LoggerFactory.getLogger(RouteInitConfig.class);
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private GatewayRouteReceiver gatewayRouteReceiver;
@PostConstruct
public void initRoute() {
// 重Redis加载路由列表
Object object = redisTemplate.opsForValue().get(CommonConstant.ROUTE_KEY);
if (object != null) {
List<Route> routes = JsonMapper.getInstance().fromJson(object.toString(), JsonMapper.getInstance().createCollectionType(ArrayList.class, Route.class));
if (CollectionUtils.isNotEmpty(routes)) {
logger.info("加载{}条路由记录", routes.size());
for (Route route : routes)
gatewayRouteReceiver.editRoute(route);
}
}
}
}
......@@ -15,4 +15,9 @@ public class GatewayConstant {
* 手机登录URL
*/
public static final String MOBILE_TOKEN_URL = "/mobile/token";
/**
* 注册
*/
public static final String REGISTER = "/user/register";
}
package com.github.tangyi.gateway.controller;
import com.github.tangyi.common.core.constant.MqConstant;
import com.github.tangyi.common.core.model.ResponseBean;
import com.github.tangyi.gateway.module.GatewayFilterDefinition;
import com.github.tangyi.gateway.module.GatewayPredicateDefinition;
import com.github.tangyi.gateway.module.GatewayRouteDefinition;
import com.github.tangyi.common.core.vo.RouteFilterVo;
import com.github.tangyi.common.core.vo.RoutePredicateVo;
import com.github.tangyi.common.core.vo.RouteVo;
import com.github.tangyi.gateway.service.DynamicRouteService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.filter.FilterDefinition;
import org.springframework.cloud.gateway.filter.GatewayFilter;
......@@ -32,10 +34,10 @@ import java.util.Map;
* @date 2019/3/27 10:59
*/
@RestController
@RequestMapping("/route")
public class RouteController {
@RequestMapping("/api/route")
public class GatewayRouteController {
private static final Logger logger = LoggerFactory.getLogger(RouteController.class);
private static final Logger logger = LoggerFactory.getLogger(GatewayRouteController.class);
private final RouteDefinitionLocator routeDefinitionLocator;
......@@ -43,11 +45,14 @@ public class RouteController {
private final DynamicRouteService dynamicRouteService;
private final AmqpTemplate amqpTemplate;
@Autowired
public RouteController(RouteDefinitionLocator routeDefinitionLocator, RouteLocator routeLocator, DynamicRouteService dynamicRouteService) {
public GatewayRouteController(RouteDefinitionLocator routeDefinitionLocator, RouteLocator routeLocator, DynamicRouteService dynamicRouteService, AmqpTemplate amqpTemplate) {
this.routeDefinitionLocator = routeDefinitionLocator;
this.routeLocator = routeLocator;
this.dynamicRouteService = dynamicRouteService;
this.amqpTemplate = amqpTemplate;
}
/**
......@@ -97,7 +102,7 @@ public class RouteController {
* @return ResponseBean
*/
@PostMapping
public ResponseBean<String> add(@RequestBody GatewayRouteDefinition gatewayRouteDefinition) {
public ResponseBean<String> add(@RequestBody RouteVo gatewayRouteDefinition) {
try {
RouteDefinition definition = assembleRouteDefinition(gatewayRouteDefinition);
logger.info("新增路由:{},{}", definition.getId(), definition);
......@@ -123,43 +128,56 @@ public class RouteController {
/**
* 更新路由
*
* @param gatewayRouteDefinition gatewayRouteDefinition
* @param routeVo routeVo
* @return ResponseBean
*/
@PutMapping
public ResponseBean<String> update(@RequestBody GatewayRouteDefinition gatewayRouteDefinition) {
RouteDefinition definition = assembleRouteDefinition(gatewayRouteDefinition);
public ResponseBean<String> update(@RequestBody RouteVo routeVo) {
RouteDefinition definition = assembleRouteDefinition(routeVo);
return new ResponseBean<>(this.dynamicRouteService.update(definition));
}
/**
* @param gatewayRouteDefinition gatewayRouteDefinition
* 刷新路由
*
* @return ResponseBean
* @author tangyi
* @date 2019/04/07 12:32
*/
@GetMapping("/refresh")
public ResponseBean<Boolean> refresh() {
amqpTemplate.convertAndSend(MqConstant.REFRESH_GATEWAY_ROUTE_QUEUE, "refresh");
return new ResponseBean<>(Boolean.TRUE);
}
/**
* @param routeVo routeVo
* @return RouteDefinition
*/
private RouteDefinition assembleRouteDefinition(GatewayRouteDefinition gatewayRouteDefinition) {
private RouteDefinition assembleRouteDefinition(RouteVo routeVo) {
RouteDefinition definition = new RouteDefinition();
// id
definition.setId(gatewayRouteDefinition.getId());
definition.setId(routeVo.getRouteId());
List<PredicateDefinition> predicateDefinitions = new ArrayList<>();
// predicates
for (GatewayPredicateDefinition gpDefinition : gatewayRouteDefinition.getPredicates()) {
for (RoutePredicateVo routePredicateVo : routeVo.getPredicates()) {
PredicateDefinition predicate = new PredicateDefinition();
predicate.setArgs(gpDefinition.getArgs());
predicate.setName(gpDefinition.getName());
predicate.setArgs(routePredicateVo.getArgs());
predicate.setName(routePredicateVo.getName());
predicateDefinitions.add(predicate);
}
definition.setPredicates(predicateDefinitions);
// filters
List<FilterDefinition> filterDefinitions = new ArrayList<>();
for (GatewayFilterDefinition gatewayFilterDefinition : gatewayRouteDefinition.getFilters()) {
for (RouteFilterVo routeFilterVo : routeVo.getFilters()) {
FilterDefinition filterDefinition = new FilterDefinition();
filterDefinition.setName(gatewayFilterDefinition.getName());
filterDefinition.setArgs(gatewayFilterDefinition.getArgs());
filterDefinition.setName(routeFilterVo.getName());
filterDefinition.setArgs(routeFilterVo.getArgs());
filterDefinitions.add(filterDefinition);
}
definition.setFilters(filterDefinitions);
// uri
definition.setUri(URI.create(gatewayRouteDefinition.getUri()));
definition.setUri(URI.create(routeVo.getUri()));
return definition;
}
}
......@@ -57,10 +57,11 @@ public class DecodePasswordFilter implements GlobalFilter, Ordered {
// 请求的URI
URI uri = request.getURI();
// 获取token的请求
if ("POST".equals(request.getMethodValue()) && StrUtil.containsAnyIgnoreCase(uri.getPath(), GatewayConstant.OAUTH_TOKEN_URL, GatewayConstant.MOBILE_TOKEN_URL)) {
if ("POST".equals(request.getMethodValue()) && StrUtil.containsAnyIgnoreCase(uri.getPath(), GatewayConstant.OAUTH_TOKEN_URL, GatewayConstant.REGISTER,
GatewayConstant.MOBILE_TOKEN_URL)) {
String grantType = request.getQueryParams().getFirst(GRANT_TYPE);
// 授权类型为密码模式则解密
if (PASSWORD.equals(grantType)) {
if (PASSWORD.equals(grantType) || StrUtil.containsAnyIgnoreCase(uri.getPath(), GatewayConstant.REGISTER)) {
String password = request.getQueryParams().getFirst(PASSWORD);
if (password == null || password.isEmpty()) {
logger.info("password is empty...");
......
......@@ -43,10 +43,10 @@ public class ValidateCodeFilter implements GlobalFilter, Ordered {
// 请求的URI
URI uri = request.getURI();
if ("POST".equals(request.getMethodValue())
&& StrUtil.containsAnyIgnoreCase(uri.getPath(), GatewayConstant.OAUTH_TOKEN_URL, GatewayConstant.MOBILE_TOKEN_URL)) {
&& StrUtil.containsAnyIgnoreCase(uri.getPath(), GatewayConstant.OAUTH_TOKEN_URL, GatewayConstant.REGISTER, GatewayConstant.MOBILE_TOKEN_URL)) {
String grantType = request.getQueryParams().getFirst(GRANT_TYPE);
// 授权类型为密码模式才校验验证码
if (PASSWORD.equals(grantType)) {
// 授权类型为密码模式、注册才校验验证码
if (PASSWORD.equals(grantType) || StrUtil.containsAnyIgnoreCase(uri.getPath(), GatewayConstant.REGISTER)) {
// 校验验证码
checkCode(request);
}
......
package com.github.tangyi.gateway.receiver;
import com.fasterxml.jackson.databind.JavaType;
import com.github.tangyi.common.core.constant.MqConstant;
import com.github.tangyi.common.core.model.Route;
import com.github.tangyi.common.core.utils.JsonMapper;
import com.github.tangyi.common.core.vo.RouteFilterVo;
import com.github.tangyi.common.core.vo.RoutePredicateVo;
import com.github.tangyi.gateway.service.DynamicRouteService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.filter.FilterDefinition;
import org.springframework.cloud.gateway.handler.predicate.PredicateDefinition;
import org.springframework.cloud.gateway.route.RouteDefinition;
import org.springframework.stereotype.Service;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
/**
* 动态路由
*
* @author tangyi
* @date 2019/4/2 18:07
*/
@Service
public class GatewayRouteReceiver {
private static final Logger logger = LoggerFactory.getLogger(GatewayRouteReceiver.class);
@Autowired
private DynamicRouteService dynamicRouteService;
/**
* 修改路由
*
* @param route route
* @author tangyi
* @date 2019/04/02 20:51
*/
@RabbitListener(queues = {MqConstant.EDIT_GATEWAY_ROUTE_QUEUE})
public void editRoute(Route route) {
if (route.getRouteId() == null)
throw new IllegalArgumentException("routeId不能为空!");
logger.info("更新{}路由", route.getRouteId());
dynamicRouteService.update(routeDefinition(route));
}
/**
* 删除路由
*
* @param routes routes
* @author tangyi
* @date 2019/04/02 20:51
*/
@RabbitListener(queues = {MqConstant.DEL_GATEWAY_ROUTE_QUEUE})
public void delRoute(List<Route> routes) {
if (routes == null || routes.isEmpty())
return;
for (Route route : routes) {
if (route.getRouteId() == null)
throw new IllegalArgumentException("routeId不能为空!");
logger.info("删除{}路由", route.getRouteId());
dynamicRouteService.delete(route.getRouteId());
}
}
/**
* 初始化RouteDefinition
*
* @param route route
* @return RouteDefinition
* @author tangyi
* @date 2019/04/02 18:50
*/
private RouteDefinition routeDefinition(Route route) {
RouteDefinition routeDefinition = new RouteDefinition();
// id
routeDefinition.setId(route.getRouteId());
// predicates
if (StringUtils.isNotBlank(route.getPredicates()))
routeDefinition.setPredicates(predicateDefinitions(route));
// filters
if (StringUtils.isNotBlank(route.getFilters())) {
routeDefinition.setFilters(filterDefinitions(route));
}
// uri
routeDefinition.setUri(URI.create(route.getUri()));
return routeDefinition;
}
/**
* @param route route
* @return List
* @author tangyi
* @date 2019/04/02 21:28
*/
private List<PredicateDefinition> predicateDefinitions(Route route) {
List<PredicateDefinition> predicateDefinitions = new ArrayList<>();
try {
List<RoutePredicateVo> routePredicateVoList = JsonMapper.getInstance().fromJson(route.getPredicates(),
JsonMapper.getInstance().createCollectionType(ArrayList.class, RoutePredicateVo.class));
if (CollectionUtils.isNotEmpty(routePredicateVoList)) {
for (RoutePredicateVo routePredicateVo : routePredicateVoList) {
PredicateDefinition predicate = new PredicateDefinition();
predicate.setArgs(routePredicateVo.getArgs());
predicate.setName(routePredicateVo.getName());
predicateDefinitions.add(predicate);
}
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
return predicateDefinitions;
}
/**
* @param route route
* @return List
* @author tangyi
* @date 2019/04/02 21:29
*/
private List<FilterDefinition> filterDefinitions(Route route) {
List<FilterDefinition> filterDefinitions = new ArrayList<>();
try {
JavaType javaType = JsonMapper.getInstance().createCollectionType(ArrayList.class, RouteFilterVo.class);
List<RouteFilterVo> gatewayFilterDefinitions = JsonMapper.getInstance().fromJson(route.getFilters(), javaType);
if (CollectionUtils.isNotEmpty(gatewayFilterDefinitions)) {
for (RouteFilterVo gatewayFilterDefinition : gatewayFilterDefinitions) {
FilterDefinition filterDefinition = new FilterDefinition();
filterDefinition.setName(gatewayFilterDefinition.getName());
filterDefinition.setArgs(gatewayFilterDefinition.getArgs());
filterDefinitions.add(filterDefinition);
}
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
return filterDefinitions;
}
}
......@@ -67,7 +67,7 @@ public class DynamicRouteService implements ApplicationEventPublisherAware {
* 删除路由
*
* @param id id
* @return ResponseEntity
* @return Mono
*/
public Mono<ResponseEntity<Object>> delete(String id) {
return this.routeDefinitionWriter.delete(Mono.just(id))
......
......@@ -31,7 +31,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
http.headers().frameOptions().disable();
http.authorizeRequests()
.antMatchers("/actuator/**", "/hystrix/**","/hystrix","*.stream").permitAll()
.antMatchers("/actuator/**", "/hystrix/**","/hystrix","*.sender").permitAll()
.antMatchers(adminContextPath + "/assets/**").permitAll()
.antMatchers(adminContextPath + "/login").permitAll()
.anyRequest().authenticated()
......
......@@ -9,6 +9,7 @@ import com.github.tangyi.common.core.utils.PageUtil;
import com.github.tangyi.common.core.utils.SysUtil;
import com.github.tangyi.common.core.web.BaseController;
import com.github.tangyi.common.log.annotation.Log;
import com.github.tangyi.common.security.constant.SecurityConstant;
import com.github.tangyi.common.security.utils.SecurityUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
......@@ -72,19 +73,18 @@ public class OauthClientDetailsController extends BaseController {
* @date 2019/03/30 16:54
*/
@RequestMapping("clientList")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取客户端列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "pageSize", value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "sort", value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "order", value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_NUM, value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_SIZE, value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.SORT, value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.ORDER, value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "attachment", value = "客户端信息", dataType = "OauthClient")
})
public PageInfo<OauthClientDetails> oauthClientList(@RequestParam(value = "pageNum", required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = "pageSize", required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = "sort", required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = "order", required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
public PageInfo<OauthClientDetails> oauthClientList(@RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = CommonConstant.SORT, required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = CommonConstant.ORDER, required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
OauthClientDetails oauthClientDetails) {
return oauthClientDetailsService.findPage(PageUtil.pageInfo(pageNum, pageSize, sort, order), oauthClientDetails);
}
......@@ -98,7 +98,6 @@ public class OauthClientDetailsController extends BaseController {
* @date 2019/03/30 23:17
*/
@RequestMapping("clients")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "查询客户端列表", notes = "查询客户端列表")
@ApiImplicitParam(name = "oauthClient", value = "客户端实体oauthClient", required = true, dataType = "OauthClientDetails")
public ResponseBean<List<OauthClientDetails>> findOauthClientList(@RequestBody OauthClientDetails oauthClientDetails) {
......@@ -114,7 +113,7 @@ public class OauthClientDetailsController extends BaseController {
* @date 2019/03/30 16:57
*/
@PostMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('sys:client:add') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "')")
@ApiOperation(value = "创建客户端", notes = "创建客户端")
@ApiImplicitParam(name = "oauthClientDetails", value = "客户端实体oauthClientDetails", required = true, dataType = "OauthClientDetails")
@Log("新增客户端")
......@@ -134,7 +133,7 @@ public class OauthClientDetailsController extends BaseController {
* @date 2019/03/30 16:56
*/
@PutMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('sys:client:edit') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "')")
@ApiOperation(value = "更新客户端信息", notes = "根据客户端id更新客户端的基本信息")
@ApiImplicitParam(name = "oauthClientDetails", value = "客户端实体oauthClientDetails", required = true, dataType = "OauthClientDetails")
@Log("修改客户端")
......@@ -154,7 +153,7 @@ public class OauthClientDetailsController extends BaseController {
* @date 2019/03/30 16:59
*/
@DeleteMapping("/{id}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('sys:client:del') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "')")
@ApiOperation(value = "删除客户端", notes = "根据ID删除客户端")
@ApiImplicitParam(name = "id", value = "客户端ID", required = true, paramType = "path")
@Log("删除客户端")
......@@ -175,7 +174,7 @@ public class OauthClientDetailsController extends BaseController {
* @date 2019/03/30 17:01
*/
@PostMapping("/deleteAll")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('sys:client:del') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "')")
@ApiOperation(value = "批量删除客户端", notes = "根据客户端id批量删除客户端")
@ApiImplicitParam(name = "oauthClientDetails", value = "客户端信息", dataType = "OauthClientDetails")
@Log("批量删除客户端")
......
......@@ -19,7 +19,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
/**
......@@ -35,6 +34,7 @@ public class AnswerController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(AnswerController.class);
@Autowired
private AnswerService answerService;
......@@ -47,7 +47,6 @@ public class AnswerController extends BaseController {
* @date 2018/11/10 21:23
*/
@GetMapping("/{id}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取答题信息", notes = "根据答题id获取答题详细信息")
@ApiImplicitParam(name = "id", value = "答题ID", required = true, dataType = "String", paramType = "path")
public ResponseBean<Answer> answer(@PathVariable String id) {
......@@ -72,19 +71,18 @@ public class AnswerController extends BaseController {
* @date 2018/11/10 21:25
*/
@RequestMapping("answerList")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取答题列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "pageSize", value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "sort", value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "order", value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_NUM, value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_SIZE, value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.SORT, value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.ORDER, value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "answer", value = "答题信息", dataType = "Answer")
})
public PageInfo<Answer> answerList(@RequestParam(value = "pageNum", required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = "pageSize", required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = "sort", required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = "order", required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
public PageInfo<Answer> answerList(@RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = CommonConstant.SORT, required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = CommonConstant.ORDER, required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
Answer answer) {
return answerService.findPage(PageUtil.pageInfo(pageNum, pageSize, sort, order), answer);
}
......@@ -98,7 +96,6 @@ public class AnswerController extends BaseController {
* @date 2018/11/10 21:26
*/
@PostMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "创建答题", notes = "创建答题")
@ApiImplicitParam(name = "answer", value = "答题实体answer", required = true, dataType = "Answer")
@Log("新增答题")
......@@ -116,7 +113,6 @@ public class AnswerController extends BaseController {
* @date 2018/11/10 21:27
*/
@PutMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "更新答题信息", notes = "根据答题id更新答题的基本信息")
@ApiImplicitParam(name = "answer", value = "答题实体answer", required = true, dataType = "Answer")
@Log("修改答题")
......@@ -134,7 +130,6 @@ public class AnswerController extends BaseController {
* @date 2018/11/10 21:28
*/
@DeleteMapping("{id}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "删除答题", notes = "根据ID删除答题")
@ApiImplicitParam(name = "id", value = "答题ID", required = true, paramType = "path")
@Log("删除答题")
......@@ -161,7 +156,6 @@ public class AnswerController extends BaseController {
* @date 2018/12/24 20:06
*/
@PostMapping("saveOrUpdate")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "保存答题", notes = "保存答题")
@ApiImplicitParam(name = "answer", value = "答题信息", dataType = "Answer")
@Log("保存答题")
......@@ -190,7 +184,6 @@ public class AnswerController extends BaseController {
* @date 2018/12/24 20:44
*/
@PostMapping("submit")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "提交答卷", notes = "提交答卷")
@ApiImplicitParam(name = "answer", value = "答卷信息", dataType = "Answer")
@Log("提交答题")
......
......@@ -7,6 +7,7 @@ import com.github.tangyi.common.core.utils.PageUtil;
import com.github.tangyi.common.core.utils.SysUtil;
import com.github.tangyi.common.core.web.BaseController;
import com.github.tangyi.common.log.annotation.Log;
import com.github.tangyi.common.security.constant.SecurityConstant;
import com.github.tangyi.common.security.utils.SecurityUtil;
import com.github.tangyi.exam.api.module.Course;
import com.github.tangyi.exam.service.CourseService;
......@@ -46,7 +47,6 @@ public class CourseController extends BaseController {
* @date 2018/11/10 21:28
*/
@GetMapping("/{id}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取课程信息", notes = "根据课程id获取课程详细信息")
@ApiImplicitParam(name = "id", value = "课程ID", required = true, dataType = "String", paramType = "path")
public ResponseBean<Course> course(@PathVariable String id) {
......@@ -71,19 +71,18 @@ public class CourseController extends BaseController {
* @date 2018/11/10 21:30
*/
@RequestMapping("courseList")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取课程列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "pageSize", value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "sort", value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "order", value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_NUM, value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_SIZE, value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.SORT, value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.ORDER, value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "course", value = "课程信息", dataType = "Course")
})
public PageInfo<Course> courseList(@RequestParam(value = "pageNum", required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = "pageSize", required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = "sort", required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = "order", required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
public PageInfo<Course> courseList(@RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = CommonConstant.SORT, required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = CommonConstant.ORDER, required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
Course course) {
return courseService.findPage(PageUtil.pageInfo(pageNum, pageSize, sort, order), course);
}
......@@ -97,7 +96,7 @@ public class CourseController extends BaseController {
* @date 2018/11/10 21:31
*/
@PostMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('exam:course:add') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "创建课程", notes = "创建课程")
@ApiImplicitParam(name = "course", value = "课程实体course", required = true, dataType = "Course")
@Log("新增课程")
......@@ -115,7 +114,7 @@ public class CourseController extends BaseController {
* @date 2018/11/10 21:31
*/
@PutMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('exam:course:edit') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "更新课程信息", notes = "根据课程id更新课程的基本信息")
@ApiImplicitParam(name = "course", value = "课程实体course", required = true, dataType = "Course")
@Log("更新课程")
......@@ -133,7 +132,7 @@ public class CourseController extends BaseController {
* @date 2018/11/10 21:32
*/
@DeleteMapping("{id}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('exam:course:del') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "删除课程", notes = "根据ID删除课程")
@ApiImplicitParam(name = "id", value = "课程ID", required = true, paramType = "path")
@Log("删除课程")
......@@ -162,7 +161,7 @@ public class CourseController extends BaseController {
* @date 2018/12/4 11:26
*/
@PostMapping("/deleteAll")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('exam:course:del') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "批量删除课程", notes = "根据课程id批量删除课程")
@ApiImplicitParam(name = "course", value = "课程信息", dataType = "Course")
@Log("批量删除课程")
......
......@@ -9,6 +9,7 @@ import com.github.tangyi.common.core.vo.DeptVo;
import com.github.tangyi.common.core.vo.UserVo;
import com.github.tangyi.common.core.web.BaseController;
import com.github.tangyi.common.log.annotation.Log;
import com.github.tangyi.common.security.constant.SecurityConstant;
import com.github.tangyi.common.security.utils.SecurityUtil;
import com.github.tangyi.exam.api.dto.ExamRecordDto;
import com.github.tangyi.exam.api.module.ExamRecord;
......@@ -67,10 +68,9 @@ public class ExamRecordController extends BaseController {
* @date 2018/11/10 21:33
*/
@GetMapping("/{id}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取考试记录信息", notes = "根据考试记录id获取考试记录详细信息")
@ApiImplicitParam(name = "id", value = "考试记录ID", required = true, dataType = "String", paramType = "path")
public ResponseBean<ExamRecord> examRecode(@PathVariable String id) {
public ResponseBean<ExamRecord> examRecord(@PathVariable String id) {
ExamRecord examRecord = new ExamRecord();
if (StringUtils.isNotBlank(id)) {
examRecord.setId(id);
......@@ -92,19 +92,18 @@ public class ExamRecordController extends BaseController {
* @date 2018/11/10 21:33
*/
@RequestMapping("examRecordList")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取考试记录列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "pageSize", value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "sort", value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "order", value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_NUM, value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_SIZE, value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.SORT, value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.ORDER, value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "examRecord", value = "考试记录信息", dataType = "ExamRecord")
})
public PageInfo<ExamRecordDto> examRecodeList(@RequestParam(value = "pageNum", required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = "pageSize", required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = "sort", required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = "order", required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
public PageInfo<ExamRecordDto> examRecordList(@RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = CommonConstant.SORT, required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = CommonConstant.ORDER, required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
ExamRecord examRecord) {
PageInfo<ExamRecordDto> examRecordDtoPageInfo = new PageInfo<>();
List<ExamRecordDto> examRecordDtoList = new ArrayList<>();
......@@ -183,11 +182,10 @@ public class ExamRecordController extends BaseController {
* @date 2018/11/10 21:33
*/
@PostMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "创建考试记录", notes = "创建考试记录")
@ApiImplicitParam(name = "examRecord", value = "考试记录实体examRecord", required = true, dataType = "ExamRecord")
@Log("新增考试记录")
public ResponseBean<ExamRecord> addExamRecode(@RequestBody ExamRecord examRecord) {
public ResponseBean<ExamRecord> addExamRecord(@RequestBody ExamRecord examRecord) {
if (StringUtils.isEmpty(examRecord.getExaminationId()))
throw new CommonException("参数校验失败,考试id为空!");
if (StringUtils.isEmpty(examRecord.getUserId()))
......@@ -215,11 +213,10 @@ public class ExamRecordController extends BaseController {
* @date 2018/11/10 21:34
*/
@PutMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "更新考试记录信息", notes = "根据考试记录id更新考试记录的基本信息")
@ApiImplicitParam(name = "examRecord", value = "考试记录实体examRecord", required = true, dataType = "ExamRecord")
@Log("更新考试记录")
public ResponseBean<Boolean> updateExamRecode(@RequestBody ExamRecord examRecord) {
public ResponseBean<Boolean> updateExamRecord(@RequestBody ExamRecord examRecord) {
examRecord.setCommonValue(SecurityUtil.getCurrentUsername(), SysUtil.getSysCode());
return new ResponseBean<>(examRecordService.update(examRecord) > 0);
}
......@@ -233,11 +230,10 @@ public class ExamRecordController extends BaseController {
* @date 2018/11/10 21:34
*/
@DeleteMapping("{id}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "删除考试记录", notes = "根据ID删除考试记录")
@ApiImplicitParam(name = "id", value = "考试记录ID", required = true, paramType = "path")
@Log("删除考试记录")
public ResponseBean<Boolean> deleteExamRecode(@PathVariable String id) {
public ResponseBean<Boolean> deleteExamRecord(@PathVariable String id) {
boolean success = false;
try {
ExamRecord examRecord = examRecordService.get(id);
......@@ -259,7 +255,7 @@ public class ExamRecordController extends BaseController {
* @date 2018/12/31 22:28
*/
@PostMapping("/export")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('exam:examRecord:export') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "导出考试成绩", notes = "根据成绩id导出成绩")
@ApiImplicitParam(name = "examRecordDto", value = "成绩信息", required = true, dataType = "ExamRecordDto")
@Log("导出考试记录")
......
......@@ -7,6 +7,7 @@ import com.github.tangyi.common.core.utils.PageUtil;
import com.github.tangyi.common.core.utils.SysUtil;
import com.github.tangyi.common.core.web.BaseController;
import com.github.tangyi.common.log.annotation.Log;
import com.github.tangyi.common.security.constant.SecurityConstant;
import com.github.tangyi.common.security.utils.SecurityUtil;
import com.github.tangyi.exam.api.dto.ExaminationDto;
import com.github.tangyi.exam.api.module.Course;
......@@ -57,7 +58,6 @@ public class ExaminationController extends BaseController {
* @date 2018/11/10 21:08
*/
@GetMapping("/{id}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取考试信息", notes = "根据考试id获取考试详细信息")
@ApiImplicitParam(name = "id", value = "考试ID", required = true, dataType = "String", paramType = "path")
public ResponseBean<Examination> examination(@PathVariable String id) {
......@@ -85,19 +85,18 @@ public class ExaminationController extends BaseController {
* @date 2018/11/10 21:10
*/
@RequestMapping("examinationList")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取考试列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "pageSize", value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "sort", value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "order", value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_NUM, value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_SIZE, value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.SORT, value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.ORDER, value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "examination", value = "考试信息", dataType = "Examination")
})
public PageInfo<ExaminationDto> examinationList(@RequestParam(value = "pageNum", required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = "pageSize", required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = "sort", required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = "order", required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
public PageInfo<ExaminationDto> examinationList(@RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = CommonConstant.SORT, required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = CommonConstant.ORDER, required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
Examination examination) {
PageInfo<Examination> page = examinationService.findPage(PageUtil.pageInfo(pageNum, pageSize, sort, order), examination);
PageInfo<ExaminationDto> examinationDtoPageInfo = new PageInfo<>();
......@@ -137,7 +136,7 @@ public class ExaminationController extends BaseController {
* @date 2018/11/10 21:14
*/
@PostMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('exam:exam:add') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "创建考试", notes = "创建考试")
@ApiImplicitParam(name = "examinationDto", value = "考试实体examinationDto", required = true, dataType = "ExaminationDto")
@Log("新增考试")
......@@ -158,7 +157,7 @@ public class ExaminationController extends BaseController {
* @date 2018/11/10 21:15
*/
@PutMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('exam:exam:edit') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "更新考试信息", notes = "根据考试id更新考试的基本信息")
@ApiImplicitParam(name = "examinationDto", value = "考试实体answer", required = true, dataType = "ExaminationDto")
@Log("更新考试")
......@@ -179,7 +178,7 @@ public class ExaminationController extends BaseController {
* @date 2018/11/10 21:20
*/
@DeleteMapping("{id}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('exam:exam:del') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "删除考试", notes = "根据ID删除考试")
@ApiImplicitParam(name = "id", value = "考试ID", required = true, paramType = "path")
@Log("删除考试")
......@@ -208,7 +207,7 @@ public class ExaminationController extends BaseController {
* @date 2018/12/03 22:03
*/
@PostMapping("/deleteAll")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('exam:exam:del') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "批量删除考试", notes = "根据考试id批量删除考试")
@ApiImplicitParam(name = "examinationDto", value = "考试信息", dataType = "ExaminationDto")
@Log("批量删除考试")
......@@ -231,7 +230,6 @@ public class ExaminationController extends BaseController {
* @date 2019/3/1 15:30
*/
@GetMapping("/examinationCount")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
public ResponseBean<Integer> findExaminationCount() {
Examination examination = new Examination();
examination.setCommonValue(SecurityUtil.getCurrentUsername(), SysUtil.getSysCode());
......
......@@ -23,7 +23,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
......@@ -59,10 +58,9 @@ public class IncorrectAnswerController extends BaseController {
* @date 2018/11/10 21:36
*/
@GetMapping("/{id}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取错题信息", notes = "根据错题id获取错题详细信息")
@ApiImplicitParam(name = "id", value = "错题ID", required = true, dataType = "String", paramType = "path")
public ResponseBean<IncorrectAnswer> examRecode(@PathVariable String id) {
public ResponseBean<IncorrectAnswer> examRecord(@PathVariable String id) {
IncorrectAnswer incorrectAnswer = new IncorrectAnswer();
if (StringUtils.isNotBlank(id)) {
incorrectAnswer.setId(id);
......@@ -84,19 +82,18 @@ public class IncorrectAnswerController extends BaseController {
* @date 2018/11/10 21:37
*/
@RequestMapping("incorrectAnswerList")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取错题列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "pageSize", value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "sort", value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "order", value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_NUM, value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_SIZE, value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.SORT, value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.ORDER, value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "incorrectAnswer", value = "错题信息", dataType = "IncorrectAnswer")
})
public PageInfo<IncorrectAnswerDto> incorrectAnswerList(@RequestParam(value = "pageNum", required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = "pageSize", required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = "sort", required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = "order", required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
public PageInfo<IncorrectAnswerDto> incorrectAnswerList(@RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = CommonConstant.SORT, required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = CommonConstant.ORDER, required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
IncorrectAnswer incorrectAnswer) {
// 查找错题
PageInfo<IncorrectAnswer> incorrectAnswerPageInfo = incorrectAnswerService.findPage(PageUtil.pageInfo(pageNum, pageSize, sort, order), incorrectAnswer);
......@@ -137,7 +134,6 @@ public class IncorrectAnswerController extends BaseController {
* @date 2018/11/10 21:38
*/
@PostMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "创建错题", notes = "创建错题")
@ApiImplicitParam(name = "incorrectAnswer", value = "错题实体incorrectAnswer", required = true, dataType = "IncorrectAnswer")
@Log("新增错题")
......@@ -155,7 +151,6 @@ public class IncorrectAnswerController extends BaseController {
* @date 2018/11/10 21:38
*/
@PutMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "更新错题信息", notes = "根据错题id更新错题的基本信息")
@ApiImplicitParam(name = "incorrectAnswer", value = "错题实体incorrectAnswer", required = true, dataType = "IncorrectAnswer")
@Log("更新错题")
......@@ -173,7 +168,6 @@ public class IncorrectAnswerController extends BaseController {
* @date 2018/11/10 21:39
*/
@DeleteMapping("{id}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "删除错题", notes = "根据ID删除错题")
@ApiImplicitParam(name = "id", value = "错题ID", required = true, paramType = "path")
@Log("删除错题")
......
......@@ -23,7 +23,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
......@@ -59,7 +58,6 @@ public class KnowledgeController extends BaseController {
* @date 2019/1/1 15:15
*/
@GetMapping("/{id}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取知识信息", notes = "根据知识id获取知识详细信息")
@ApiImplicitParam(name = "id", value = "知识ID", required = true, dataType = "String", paramType = "path")
public ResponseBean<Knowledge> knowledge(@PathVariable String id) {
......@@ -84,19 +82,18 @@ public class KnowledgeController extends BaseController {
* @date 2019/1/1 15:15
*/
@RequestMapping("knowledgeList")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取知识列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "pageSize", value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "sort", value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "order", value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_NUM, value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_SIZE, value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.SORT, value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.ORDER, value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "knowledge", value = "知识信息", dataType = "Knowledge")
})
public PageInfo<KnowledgeDto> knowledgeList(@RequestParam(value = "pageNum", required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = "pageSize", required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = "sort", required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = "order", required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
public PageInfo<KnowledgeDto> knowledgeList(@RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = CommonConstant.SORT, required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = CommonConstant.ORDER, required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
Knowledge knowledge) {
// 查询知识
PageInfo<Knowledge> knowledgePageInfo = knowledgeService.findPage(PageUtil.pageInfo(pageNum, pageSize, sort, order), knowledge);
......@@ -143,7 +140,6 @@ public class KnowledgeController extends BaseController {
* @date 2019/1/1 15:15
*/
@PostMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "创建知识", notes = "创建知识")
@ApiImplicitParam(name = "knowledge", value = "知识实体knowledge", required = true, dataType = "Knowledge")
@Log("新增知识")
......@@ -161,7 +157,6 @@ public class KnowledgeController extends BaseController {
* @date 2019/1/1 15:15
*/
@PutMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "更新知识信息", notes = "根据知识id更新知识的基本信息")
@ApiImplicitParam(name = "knowledge", value = "知识实体knowledge", required = true, dataType = "Knowledge")
@Log("更新知识")
......@@ -179,7 +174,6 @@ public class KnowledgeController extends BaseController {
* @date 2019/1/1 15:15
*/
@DeleteMapping("{id}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "删除知识", notes = "根据ID删除知识")
@ApiImplicitParam(name = "id", value = "知识ID", required = true, paramType = "path")
@Log("删除知识")
......@@ -211,7 +205,6 @@ public class KnowledgeController extends BaseController {
* @date 2019/1/1 15:15
*/
@PostMapping("/deleteAll")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "批量删除知识", notes = "根据知识id批量删除知识")
@ApiImplicitParam(name = "knowledge", value = "知识信息", dataType = "Knowledge")
@Log("批量删除知识")
......
......@@ -6,6 +6,7 @@ import com.github.tangyi.common.core.model.ResponseBean;
import com.github.tangyi.common.core.utils.*;
import com.github.tangyi.common.core.web.BaseController;
import com.github.tangyi.common.log.annotation.Log;
import com.github.tangyi.common.security.constant.SecurityConstant;
import com.github.tangyi.common.security.utils.SecurityUtil;
import com.github.tangyi.exam.api.dto.SubjectBankDto;
import com.github.tangyi.exam.api.module.SubjectBank;
......@@ -57,7 +58,6 @@ public class SubjectBankController extends BaseController {
* @date 2018/12/9 14:12
*/
@GetMapping("/{id}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取题库信息", notes = "根据题库id获取题库详细信息")
@ApiImplicitParam(name = "id", value = "题库ID", required = true, dataType = "String", paramType = "path")
public ResponseBean<SubjectBank> subjectBank(@PathVariable String id) {
......@@ -82,19 +82,18 @@ public class SubjectBankController extends BaseController {
* @date 2018/12/9 14:13
*/
@RequestMapping("subjectBankList")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取题库列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "pageSize", value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "sort", value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "order", value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_NUM, value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_SIZE, value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.SORT, value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.ORDER, value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "subjectBank", value = "题库信息", dataType = "SubjectBank")
})
public PageInfo<SubjectBank> subjectBankList(@RequestParam(value = "pageNum", required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = "pageSize", required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = "sort", required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = "order", required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
public PageInfo<SubjectBank> subjectBankList(@RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = CommonConstant.SORT, required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = CommonConstant.ORDER, required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
SubjectBank subjectBank) {
PageInfo<SubjectBank> page = subjectBankService.findPage(PageUtil.pageInfo(pageNum, pageSize, sort, order), subjectBank);
if (CollectionUtils.isNotEmpty(page.getList())) {
......@@ -128,7 +127,7 @@ public class SubjectBankController extends BaseController {
* @date 2018/12/9 14:14
*/
@PostMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('exam:subject:bank:add') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "创建题库", notes = "创建题库")
@ApiImplicitParam(name = "subjectBank", value = "题库实体subjectBank", required = true, dataType = "SubjectBank")
@Log("新增题库")
......@@ -146,7 +145,7 @@ public class SubjectBankController extends BaseController {
* @date 2018/12/9 14:15
*/
@PutMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('exam:subject:bank:edit') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "更新题库信息", notes = "根据题库id更新题库的基本信息")
@ApiImplicitParam(name = "subjectBank", value = "题库实体subjectBank", required = true, dataType = "SubjectBank")
@Log("更新题库")
......@@ -164,7 +163,7 @@ public class SubjectBankController extends BaseController {
* @date 2018/12/9 14:15
*/
@DeleteMapping("{id}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('exam:subject:bank:del') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "删除题库", notes = "根据ID删除题库")
@ApiImplicitParam(name = "id", value = "题库ID", required = true, paramType = "path")
@Log("删除题库")
......@@ -192,7 +191,7 @@ public class SubjectBankController extends BaseController {
* @date 2018/12/9 14:16
*/
@PostMapping("/export")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('exam:subject:bank:export') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "导出题目", notes = "根据分类id导出题目")
@ApiImplicitParam(name = "subjectBankDto", value = "分类信息", required = true, dataType = "SubjectBankDto")
@Log("导出题库题目")
......@@ -233,7 +232,7 @@ public class SubjectBankController extends BaseController {
* @date 2018/12/9 14:19
*/
@RequestMapping("/import")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('exam:subject:bank:import') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "导入题目", notes = "导入题目")
@ApiImplicitParam(name = "categoryId", value = "分类ID", required = true, dataType = "String")
@Log("导入题库题目")
......@@ -273,7 +272,7 @@ public class SubjectBankController extends BaseController {
* @date 2018/12/04 9:55
*/
@PostMapping("/deleteAll")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('exam:subject:bank:del') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "批量删除题目", notes = "根据题目id批量删除题目")
@ApiImplicitParam(name = "subjectBankDto", value = "题目信息", dataType = "SubjectBankDto")
@Log("批量删除题库题目")
......
......@@ -6,6 +6,7 @@ import com.github.tangyi.common.core.utils.SysUtil;
import com.github.tangyi.common.core.utils.TreeUtil;
import com.github.tangyi.common.core.web.BaseController;
import com.github.tangyi.common.log.annotation.Log;
import com.github.tangyi.common.security.constant.SecurityConstant;
import com.github.tangyi.common.security.utils.SecurityUtil;
import com.github.tangyi.exam.api.dto.SubjectCategoryDto;
import com.github.tangyi.exam.api.module.SubjectCategory;
......@@ -42,7 +43,6 @@ public class SubjectCategoryController extends BaseController {
* @date 2018/12/04 22:03
*/
@GetMapping(value = "/categories")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取分类列表")
public List<SubjectCategoryDto> menus() {
// 查询所有分类
......@@ -63,7 +63,6 @@ public class SubjectCategoryController extends BaseController {
* @date 2018/12/04 21:59
*/
@GetMapping("/{id}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取分类信息", notes = "根据分类id获取分类详细信息")
@ApiImplicitParam(name = "id", value = "分类ID", required = true, dataType = "String", paramType = "path")
public ResponseBean<SubjectCategory> subjectCategory(@PathVariable String id) {
......@@ -84,7 +83,7 @@ public class SubjectCategoryController extends BaseController {
* @date 2018/12/04 22:00
*/
@PostMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('exam:subject:category:add') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "创建分类", notes = "创建分类")
@ApiImplicitParam(name = "subjectCategory", value = "分类实体subjectCategory", required = true, dataType = "SubjectCategory")
@Log("新增题目分类")
......@@ -102,7 +101,7 @@ public class SubjectCategoryController extends BaseController {
* @date 2018/12/04 22:01
*/
@PutMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('exam:subject:category:edit') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "更新分类信息", notes = "根据分类id更新分类的基本信息")
@ApiImplicitParam(name = "subjectCategory", value = "分类实体subjectCategory", required = true, dataType = "SubjectCategory")
@Log("更新题目分类")
......@@ -120,7 +119,7 @@ public class SubjectCategoryController extends BaseController {
* @date 2018/12/04 22:02
*/
@DeleteMapping("/{id}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('exam:subject:category:del') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "删除分类", notes = "根据ID删除分类")
@ApiImplicitParam(name = "id", value = "分类ID", required = true, paramType = "path")
@Log("删除题目分类")
......
......@@ -6,6 +6,7 @@ import com.github.tangyi.common.core.model.ResponseBean;
import com.github.tangyi.common.core.utils.*;
import com.github.tangyi.common.core.web.BaseController;
import com.github.tangyi.common.log.annotation.Log;
import com.github.tangyi.common.security.constant.SecurityConstant;
import com.github.tangyi.common.security.utils.SecurityUtil;
import com.github.tangyi.exam.api.dto.SubjectDto;
import com.github.tangyi.exam.api.module.Answer;
......@@ -70,7 +71,6 @@ public class SubjectController extends BaseController {
* @date 2018/11/10 21:43
*/
@GetMapping("/{id}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取题目信息", notes = "根据题目id获取题目详细信息")
@ApiImplicitParam(name = "id", value = "题目ID", required = true, dataType = "String", paramType = "path")
public ResponseBean<Subject> subject(@PathVariable String id) {
......@@ -95,19 +95,18 @@ public class SubjectController extends BaseController {
* @date 2018/11/10 21:43
*/
@RequestMapping("subjectList")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取题目列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "pageSize", value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "sort", value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "order", value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_NUM, value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_SIZE, value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.SORT, value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.ORDER, value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "subject", value = "题目信息", dataType = "Subject")
})
public PageInfo<Subject> subjectList(@RequestParam(value = "pageNum", required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = "pageSize", required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = "sort", required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = "order", required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
public PageInfo<Subject> subjectList(@RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = CommonConstant.SORT, required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = CommonConstant.ORDER, required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
Subject subject) {
return subjectService.findPage(PageUtil.pageInfo(pageNum, pageSize, sort, order), subject);
}
......@@ -121,7 +120,7 @@ public class SubjectController extends BaseController {
* @date 2018/11/10 21:43
*/
@PostMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('exam:exam:subject:add') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "创建题目", notes = "创建题目")
@ApiImplicitParam(name = "subject", value = "题目实体subject", required = true, dataType = "Subject")
@Log("新增题目")
......@@ -149,7 +148,7 @@ public class SubjectController extends BaseController {
* @date 2018/11/10 21:43
*/
@PutMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('exam:exam:subject:edit') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "更新题目信息", notes = "根据题目id更新题目的基本信息")
@ApiImplicitParam(name = "subject", value = "角色实体subject", required = true, dataType = "Subject")
@Log("更新题目")
......@@ -167,7 +166,7 @@ public class SubjectController extends BaseController {
* @date 2018/11/10 21:43
*/
@DeleteMapping("{id}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('exam:exam:subject:del') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "删除题目", notes = "根据ID删除题目")
@ApiImplicitParam(name = "id", value = "题目ID", required = true, paramType = "path")
@Log("删除题目")
......@@ -202,7 +201,7 @@ public class SubjectController extends BaseController {
* @date 2018/11/28 12:53
*/
@PostMapping("/export")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('exam:exam:subject:export') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "导出题目", notes = "根据分类id导出题目")
@ApiImplicitParam(name = "subjectDto", value = "题目信息", required = true, dataType = "SubjectDto")
@Log("导出题目")
......@@ -243,7 +242,7 @@ public class SubjectController extends BaseController {
* @date 2018/11/28 12:59
*/
@RequestMapping("import")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('exam:exam:subject:import') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "导入题目", notes = "导入题目")
@ApiImplicitParam(name = "examinationId", value = "考试ID", required = true, dataType = "String")
@Log("导入题目")
......@@ -286,7 +285,7 @@ public class SubjectController extends BaseController {
* @date 2018/12/04 9:55
*/
@PostMapping("deleteAll")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('exam:exam:subject:del') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "批量删除题目", notes = "根据题目id批量删除题目")
@ApiImplicitParam(name = "subjectDto", value = "题目信息", dataType = "SubjectDto")
@Log("批量删除题目")
......@@ -326,7 +325,6 @@ public class SubjectController extends BaseController {
* @date 2019/01/16 22:25
*/
@GetMapping("subjectAnswer")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "查询题目和答题", notes = "根据题目id查询题目和答题")
@ApiImplicitParams({
@ApiImplicitParam(name = "serialNumber", value = "题目序号", required = true, dataType = "String"),
......
......@@ -36,7 +36,7 @@ public class AnswerService extends CrudService<AnswerMapper, Answer> {
private IncorrectAnswerService incorrectAnswerService;
@Autowired
private ExamRecordService examRecodeService;
private ExamRecordService examRecordService;
@Autowired
private ExaminationService examinationService;
......@@ -171,8 +171,7 @@ public class AnswerService extends CrudService<AnswerMapper, Answer> {
examRecord.setScore(totalScore.toString());
examRecord.setCorrectNumber(correctNumber.toString());
examRecord.setInCorrectNumber(incorrectNumber.toString());
examRecodeService.getByUserIdAndExaminationId(examRecord);
success = examRecodeService.update(examRecord) > 0;
success = examRecordService.update(examRecord) > 0;
// 保存错题
ExamRecord searchExamRecord = new ExamRecord();
searchExamRecord.setUserId(answer.getUserId());
......
......@@ -26,7 +26,7 @@ public class ExamRecordService extends CrudService<ExamRecordMapper, ExamRecord>
* @date 2019/1/3 14:10
*/
@Override
@Cacheable(value = "recode", key = "#examRecord.id")
@Cacheable(value = "record", key = "#examRecord.id")
public ExamRecord get(ExamRecord examRecord) {
return super.get(examRecord);
}
......@@ -64,13 +64,13 @@ public class ExamRecordService extends CrudService<ExamRecordMapper, ExamRecord>
/**
* 根据用户id、考试id查找
*
* @param examRecode examRecode
* @return ExamRecode
* @param examRecord examRecord
* @return ExamRecord
* @author tangyi
* @date 2018/12/26 13:58
*/
public ExamRecord getByUserIdAndExaminationId(ExamRecord examRecode) {
return this.dao.getByUserIdAndExaminationId(examRecode);
public ExamRecord getByUserIdAndExaminationId(ExamRecord examRecord) {
return this.dao.getByUserIdAndExaminationId(examRecord);
}
/**
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.github.tangyi.exam.mapper.ExamRecordMapper">
<resultMap id="examRecodeResultMap" type="com.github.tangyi.exam.api.module.ExamRecord">
<resultMap id="examRecordResultMap" type="com.github.tangyi.exam.api.module.ExamRecord">
<id column="id" property="id"/>
<result column="user_id" property="userId"/>
<result column="examination_id" property="examinationId"/>
......@@ -20,7 +20,7 @@
<result column="application_code" property="applicationCode"/>
</resultMap>
<sql id="examRecodeColumns">
<sql id="examRecordColumns">
a.id as "id",
a.user_id,
a.examination_id,
......@@ -55,32 +55,32 @@
</if>
</sql>
<select id="get" resultMap="examRecodeResultMap">
<select id="get" resultMap="examRecordResultMap">
SELECT
<include refid="examRecodeColumns"/>
FROM exam_recode a
<include refid="examRecordColumns"/>
FROM exam_record a
WHERE a.id = #{id} and a.del_flag = 0
</select>
<select id="getByUserIdAndExaminationId" resultMap="examRecodeResultMap">
<select id="getByUserIdAndExaminationId" resultMap="examRecordResultMap">
SELECT
<include refid="examRecodeColumns"/>
FROM exam_recode a
<include refid="examRecordColumns"/>
FROM exam_record a
WHERE a.user_id = #{userId} and examination_id = #{examinationId} and a.del_flag = 0
</select>
<select id="findList" resultMap="examRecodeResultMap">
<select id="findList" resultMap="examRecordResultMap">
SELECT
<include refid="examRecodeColumns"/>
FROM exam_recode a
<include refid="examRecordColumns"/>
FROM exam_record a
WHERE a.del_flag = 0
<include refid="whereColumnList"/>
</select>
<select id="findListById" resultMap="examRecodeResultMap">
<select id="findListById" resultMap="examRecordResultMap">
SELECT
<include refid="examRecodeColumns"/>
FROM exam_recode a
<include refid="examRecordColumns"/>
FROM exam_record a
WHERE a.id IN
<foreach collection="ids" index="index" item="item" open="(" separator="," close=")">
#{item}
......@@ -88,7 +88,7 @@
</select>
<insert id="insert">
insert into exam_recode (
insert into exam_record (
id,
user_id,
examination_id,
......@@ -126,7 +126,7 @@
</insert>
<update id="update">
UPDATE exam_recode SET
UPDATE exam_record SET
<if test="userId != null">
user_id = #{userId},
</if>
......@@ -163,7 +163,7 @@
</update>
<delete id="delete">
UPDATE exam_recode SET
UPDATE exam_record SET
del_flag = 1
WHERE id = #{id}
</delete>
......
......@@ -8,6 +8,7 @@
<version>2.0-SNAPSHOT</version>
</parent>
<artifactId>service-api-impl</artifactId>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
<description>api实现</description>
......
package com.github.tangyi.user.config;
import com.github.tangyi.common.core.constant.MqConstant;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* RabbitMq配置
*
* @author tangyi
* @date 2019/4/2 17:56
*/
@Configuration
public class RabbitConfig {
/**
* 修改路由
*
* @return Queue
*/
@Bean
public Queue editQueue() {
return new Queue(MqConstant.EDIT_GATEWAY_ROUTE_QUEUE);
}
/**
* 删除路由
*
* @return Queue
*/
@Bean
public Queue delQueue() {
return new Queue(MqConstant.DEL_GATEWAY_ROUTE_QUEUE);
}
}
package com.github.tangyi.user.config;
import com.github.tangyi.common.core.constant.CommonConstant;
import com.github.tangyi.common.core.constant.MqConstant;
import com.github.tangyi.common.core.model.Route;
import com.github.tangyi.common.core.utils.JsonMapper;
import com.github.tangyi.user.service.RouteService;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import javax.annotation.PostConstruct;
import java.util.List;
/**
* 初始化路由信息
*
* @author tangyi
* @date 2019/4/2 18:42
*/
@Configuration
public class RouteInitConfig {
private static final Logger logger = LoggerFactory.getLogger(RouteInitConfig.class);
@Autowired
private RouteService routeService;
@Autowired
private AmqpTemplate amqpTemplate;
@Autowired
private RedisTemplate redisTemplate;
@PostConstruct
public void initRoute() {
init();
}
/**
* 加载所有路由,发送到mq,存放到redis
*
* @author tangyi
* @date 2019/04/07 12:05
*/
public void init() {
try {
Route init = new Route();
init.setStatus(CommonConstant.DEL_FLAG_NORMAL.toString());
List<Route> routes = routeService.findList(init);
if (CollectionUtils.isNotEmpty(routes)) {
logger.info("加载{}条路由记录", routes.size());
for (Route route : routes) {
// 发送消息
amqpTemplate.convertAndSend(MqConstant.EDIT_GATEWAY_ROUTE_QUEUE, route);
}
// 存入Redis
redisTemplate.opsForValue().set(CommonConstant.ROUTE_KEY, JsonMapper.getInstance().toJson(routes));
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
}
......@@ -20,11 +20,8 @@ import io.swagger.annotations.*;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
......@@ -86,19 +83,18 @@ public class AttachmentController extends BaseController {
* @date 2018/10/30 21:05
*/
@RequestMapping("attachmentList")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取附件列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "pageSize", value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "sort", value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "order", value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_NUM, value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_SIZE, value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.SORT, value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.ORDER, value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "attachment", value = "附件信息", dataType = "Attachment")
})
public PageInfo<Attachment> userList(@RequestParam(value = "pageNum", required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = "pageSize", required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = "sort", required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = "order", required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
public PageInfo<Attachment> userList(@RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = CommonConstant.SORT, required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = CommonConstant.ORDER, required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
Attachment attachment) {
return attachmentService.findPage(PageUtil.pageInfo(pageNum, pageSize, sort, order), attachment);
}
......@@ -112,7 +108,6 @@ public class AttachmentController extends BaseController {
* @date 2018/10/30 21:54
*/
@RequestMapping("upload")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "上传文件", notes = "上传文件")
@ApiImplicitParams({
@ApiImplicitParam(name = "busiType", value = "业务分类", dataType = "String"),
......@@ -201,7 +196,6 @@ public class AttachmentController extends BaseController {
* @date 2018/10/30 22:44
*/
@DeleteMapping("/{id}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "删除附件", notes = "根据ID删除附件")
@ApiImplicitParam(name = "id", value = "附件ID", required = true, paramType = "path")
@Log("删除附件")
......@@ -228,7 +222,6 @@ public class AttachmentController extends BaseController {
* @date 2018/12/4 10:01
*/
@PostMapping("/deleteAll")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "批量删除附件", notes = "根据附件id批量删除附件")
@ApiImplicitParam(name = "attachment", value = "附件信息", dataType = "Attachment")
@Log("批量删除附件")
......@@ -252,7 +245,6 @@ public class AttachmentController extends BaseController {
* @date 2019/01/01 22:16
*/
@RequestMapping(value = "/findById", method = RequestMethod.POST)
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "批量查询附件信息", notes = "根据附件ID批量查询附件信息")
@ApiImplicitParam(name = "attachmentVo", value = "附件信息", dataType = "AttachmentVo")
public ResponseBean<List<AttachmentVo>> findById(@RequestBody AttachmentVo attachmentVo) {
......
......@@ -2,12 +2,11 @@ package com.github.tangyi.user.controller;
import com.github.tangyi.common.core.model.ResponseBean;
import com.github.tangyi.common.core.web.BaseController;
import com.github.tangyi.user.api.dto.DashboardDto;
import com.github.tangyi.exam.api.feign.ExaminationServiceClient;
import com.github.tangyi.user.api.dto.DashboardDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -35,7 +34,6 @@ public class DashboardController extends BaseController {
* @date 2019/3/1 13:55
*/
@GetMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "后台首页数据展示", notes = "后台首页数据展示")
@SuppressWarnings("unchecked")
public ResponseBean<DashboardDto> dashboard() {
......
......@@ -7,6 +7,7 @@ import com.github.tangyi.common.core.utils.TreeUtil;
import com.github.tangyi.common.core.vo.DeptVo;
import com.github.tangyi.common.core.web.BaseController;
import com.github.tangyi.common.log.annotation.Log;
import com.github.tangyi.common.security.constant.SecurityConstant;
import com.github.tangyi.common.security.utils.SecurityUtil;
import com.github.tangyi.user.api.dto.DeptDto;
import com.github.tangyi.user.api.module.Dept;
......@@ -44,7 +45,6 @@ public class DeptController extends BaseController {
* @date 2018/10/25 12:57
*/
@GetMapping(value = "/depts")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取部门列表")
public List<DeptDto> depts() {
// 查询所有部门
......@@ -65,7 +65,6 @@ public class DeptController extends BaseController {
* @date 2018/8/28 10:11
*/
@GetMapping("/{id}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取部门信息", notes = "根据部门id获取部门详细信息")
@ApiImplicitParam(name = "id", value = "部门ID", required = true, dataType = "String", paramType = "path")
public Dept get(@PathVariable String id) {
......@@ -83,7 +82,7 @@ public class DeptController extends BaseController {
* @date 2018/8/28 10:15
*/
@PostMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('sys:dept:add') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "创建部门", notes = "创建部门")
@ApiImplicitParam(name = "dept", value = "部门实体", required = true, dataType = "Dept")
@Log("新增部门")
......@@ -101,7 +100,7 @@ public class DeptController extends BaseController {
* @date 2018/8/28 10:16
*/
@DeleteMapping("/{id}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('sys:dept:del') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "删除部门", notes = "根据ID删除部门")
@ApiImplicitParam(name = "id", value = "部门ID", required = true, paramType = "path")
@Log("删除部门")
......@@ -121,7 +120,7 @@ public class DeptController extends BaseController {
* @date 2018/8/28 10:22
*/
@PutMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('sys:dept:edit') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "更新部门信息", notes = "根据部门id更新部门的基本信息")
@ApiImplicitParam(name = "dept", value = "部门实体", required = true, dataType = "Dept")
@Log("更新部门")
......@@ -139,7 +138,6 @@ public class DeptController extends BaseController {
* @date 2018/12/31 22:13
*/
@RequestMapping(value = "/findById", method = RequestMethod.POST)
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "批量查询部门信息", notes = "根据Ids批量查询信息")
@ApiImplicitParam(name = "deptVo", value = "部门实体", required = true, dataType = "DeptVo")
public ResponseBean<List<DeptVo>> findById(@RequestBody DeptVo deptVo) {
......
......@@ -7,6 +7,7 @@ import com.github.tangyi.common.core.model.ResponseBean;
import com.github.tangyi.common.core.utils.PageUtil;
import com.github.tangyi.common.core.utils.SysUtil;
import com.github.tangyi.common.core.web.BaseController;
import com.github.tangyi.common.security.constant.SecurityConstant;
import com.github.tangyi.common.security.utils.SecurityUtil;
import com.github.tangyi.user.service.LogService;
import io.swagger.annotations.Api;
......@@ -14,8 +15,6 @@ import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
......@@ -34,7 +33,6 @@ public class LogController extends BaseController {
@Autowired
private LogService logService;
/**
* 根据id获取日志
*
......@@ -44,7 +42,6 @@ public class LogController extends BaseController {
* @date 2018/9/14 18:20
*/
@GetMapping("/{id}")
@PreAuthorize("hasAnyRole('ROLE_ADMIN')")
@ApiOperation(value = "获取日志信息", notes = "根据日志id获取日志详细信息")
@ApiImplicitParam(name = "id", value = "日志ID", required = true, dataType = "String", paramType = "path")
public Log log(@PathVariable String id) {
......@@ -69,19 +66,18 @@ public class LogController extends BaseController {
* @date 2018/10/24 0024 下午 10:13
*/
@RequestMapping("logList")
@PreAuthorize("hasAnyRole('ROLE_ADMIN')")
@ApiOperation(value = "获取日志列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "pageSize", value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "sort", value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "order", value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_NUM, value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_SIZE, value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.SORT, value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.ORDER, value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "log", value = "日志信息", dataType = "Log")
})
public PageInfo<Log> userList(@RequestParam(value = "pageNum", required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = "pageSize", required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = "sort", required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = "order", required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
public PageInfo<Log> userList(@RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = CommonConstant.SORT, required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = CommonConstant.ORDER, required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
Log log) {
return logService.findPage(PageUtil.pageInfo(pageNum, pageSize, sort, order), log);
}
......@@ -113,7 +109,7 @@ public class LogController extends BaseController {
* @date 2018/10/31 21:27
*/
@DeleteMapping("/{id}")
@PreAuthorize("hasAnyRole('ROLE_ADMIN')")
@PreAuthorize("hasAuthority('monitor:log:del') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "删除日志", notes = "根据ID删除日志")
@ApiImplicitParam(name = "id", value = "日志ID", required = true, paramType = "path")
public ResponseBean<Boolean> delete(@PathVariable String id) {
......@@ -131,7 +127,7 @@ public class LogController extends BaseController {
* @date 2018/12/4 10:12
*/
@PostMapping("/deleteAll")
@PreAuthorize("hasAnyRole('ROLE_ADMIN')")
@PreAuthorize("hasAuthority('monitor:log:del') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "批量删除日志", notes = "根据日志ids批量删除日志")
@ApiImplicitParam(name = "log", value = "日志信息", dataType = "Log")
public ResponseBean<Boolean> deleteAllAttachments(@RequestBody Log log) {
......
......@@ -8,6 +8,7 @@ import com.github.tangyi.common.core.utils.*;
import com.github.tangyi.common.core.vo.MenuVo;
import com.github.tangyi.common.core.web.BaseController;
import com.github.tangyi.common.log.annotation.Log;
import com.github.tangyi.common.security.constant.SecurityConstant;
import com.github.tangyi.common.security.utils.SecurityUtil;
import com.github.tangyi.user.api.dto.MenuDto;
import com.github.tangyi.user.api.module.Menu;
......@@ -17,8 +18,6 @@ import com.google.common.net.HttpHeaders;
import io.swagger.annotations.*;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
......@@ -49,7 +48,6 @@ public class MenuController extends BaseController {
* @return 当前用户的树形菜单
*/
@GetMapping(value = "/userMenu")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取当前用户的菜单列表")
public List<MenuDto> userMenu() {
// 查询菜单
......@@ -88,7 +86,6 @@ public class MenuController extends BaseController {
* @return 树形菜单集合
*/
@GetMapping(value = "/menus")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取树形菜单列表")
public List<MenuDto> menus() {
// 查询所有菜单
......@@ -109,7 +106,7 @@ public class MenuController extends BaseController {
* @date 2018/8/27 16:12
*/
@PostMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('sys:menu:add') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "创建菜单", notes = "创建菜单")
@ApiImplicitParam(name = "menu", value = "角色实体menu", required = true, dataType = "Menu")
@Log("新增菜单")
......@@ -127,7 +124,7 @@ public class MenuController extends BaseController {
* @date 2018/10/24 16:34
*/
@PutMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('sys:menu:edit') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "更新菜单信息", notes = "根据菜单id更新菜单的基本信息")
@ApiImplicitParam(name = "menu", value = "角色实体menu", required = true, dataType = "Menu")
@Log("更新菜单")
......@@ -145,7 +142,7 @@ public class MenuController extends BaseController {
* @date 2018/8/27 16:19
*/
@DeleteMapping("/{id}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('sys:menu:del') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "删除菜单", notes = "根据ID删除菜单")
@ApiImplicitParam(name = "id", value = "菜单ID", required = true, paramType = "path")
@Log("删除菜单")
......@@ -164,7 +161,6 @@ public class MenuController extends BaseController {
* @date 2018/8/27 16:11
*/
@GetMapping("/{id}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取菜单信息", notes = "根据菜单id获取菜单详细信息")
@ApiImplicitParam(name = "id", value = "菜单ID", required = true, dataType = "String", paramType = "path")
public Menu menu(@PathVariable String id) {
......@@ -186,19 +182,18 @@ public class MenuController extends BaseController {
* @date 2018/8/26 23:17
*/
@RequestMapping("/menuList")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取菜单列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "pageSize", value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "sort", value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "order", value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_NUM, value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_SIZE, value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.SORT, value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.ORDER, value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "Menu", value = "菜单信息", dataType = "Menu")
})
public PageInfo<Menu> menuList(@RequestParam(value = "pageNum", required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = "pageSize", required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = "sort", required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = "order", required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
public PageInfo<Menu> menuList(@RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = CommonConstant.SORT, required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = CommonConstant.ORDER, required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
Menu menu) {
return menuService.findPage(PageUtil.pageInfo(pageNum, pageSize, sort, order), menu);
}
......@@ -212,7 +207,6 @@ public class MenuController extends BaseController {
* @date 2018/8/27 15:58
*/
@GetMapping("findMenuByRole/{role}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "根据角色查找菜单", notes = "根据角色id获取角色菜单")
@ApiImplicitParam(name = "role", value = "角色名称", required = true, dataType = "String", paramType = "path")
public List<Menu> findMenuByRole(@PathVariable String role) {
......@@ -226,7 +220,6 @@ public class MenuController extends BaseController {
* @return 属性集合
*/
@GetMapping("/roleTree/{roleCode}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "根据角色查找菜单", notes = "根据角色code获取角色菜单")
@ApiImplicitParam(name = "roleCode", value = "角色code", required = true, dataType = "String", paramType = "path")
public List<String> roleTree(@PathVariable String roleCode) {
......@@ -244,7 +237,7 @@ public class MenuController extends BaseController {
* @date 2018/11/28 12:46
*/
@PostMapping("/export")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('sys:menu:export') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "导出菜单", notes = "根据菜单id导出菜单")
@ApiImplicitParam(name = "menuVo", value = "菜单信息", required = true, dataType = "MenuVo")
@Log("导出菜单")
......@@ -284,7 +277,7 @@ public class MenuController extends BaseController {
* @date 2018/11/28 12:51
*/
@RequestMapping("import")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('sys:menu:import') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "导入菜单", notes = "导入菜单")
@Log("导入菜单")
public ResponseBean<Boolean> importMenu(@ApiParam(value = "要上传的文件", required = true) MultipartFile file, HttpServletRequest request) {
......
......@@ -7,6 +7,7 @@ import com.github.tangyi.common.core.utils.PageUtil;
import com.github.tangyi.common.core.utils.SysUtil;
import com.github.tangyi.common.core.web.BaseController;
import com.github.tangyi.common.log.annotation.Log;
import com.github.tangyi.common.security.constant.SecurityConstant;
import com.github.tangyi.common.security.utils.SecurityUtil;
import com.github.tangyi.user.api.module.Dept;
import com.github.tangyi.user.api.module.Role;
......@@ -21,8 +22,6 @@ import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
......@@ -35,7 +34,7 @@ import java.util.List;
* 角色controller
*
* @author tangyi
* @date 2018/8/26 0026 22:50
* @date 2018/8/26 22:50
*/
@Api("角色信息管理")
@RestController
......@@ -63,7 +62,6 @@ public class RoleController extends BaseController {
* @date 2018/9/14 18:20
*/
@GetMapping("/{id}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取角色信息", notes = "根据角色id获取角色详细信息")
@ApiImplicitParam(name = "id", value = "角色ID", required = true, dataType = "String", paramType = "path")
public Role role(@PathVariable String id) {
......@@ -88,19 +86,18 @@ public class RoleController extends BaseController {
* @date 2018/10/24 0024 下午 10:13
*/
@RequestMapping("roleList")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取角色列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "pageSize", value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "sort", value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "order", value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_NUM, value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_SIZE, value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.SORT, value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.ORDER, value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "role", value = "角色信息", dataType = "Role")
})
public PageInfo<Role> userList(@RequestParam(value = "pageNum", required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = "pageSize", required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = "sort", required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = "order", required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
public PageInfo<Role> userList(@RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = CommonConstant.SORT, required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = CommonConstant.ORDER, required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
Role role) {
// 查询所属部门
PageInfo<Role> pageInfo = roleService.findPage(PageUtil.pageInfo(pageNum, pageSize, sort, order), role);
......@@ -133,7 +130,6 @@ public class RoleController extends BaseController {
* @return List
*/
@GetMapping("/roleList/{deptId}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取角色信息", notes = "根据部门id获取角色详细信息")
@ApiImplicitParam(name = "deptId", value = "部门ID", required = true, dataType = "String", paramType = "path")
public List<Role> roleList(@PathVariable String deptId) {
......@@ -166,7 +162,7 @@ public class RoleController extends BaseController {
* @date 2018/9/14 18:22
*/
@PutMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('sys:role:edit') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "更新角色信息", notes = "根据角色id更新角色的基本信息")
@ApiImplicitParam(name = "role", value = "角色实体role", required = true, dataType = "Role")
@Log("修改角色")
......@@ -184,7 +180,6 @@ public class RoleController extends BaseController {
* @date 2018/10/28 下午 2:20
*/
@PutMapping("roleMenuUpdate")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "更新角色菜单信息", notes = "更新角色菜单信息")
@ApiImplicitParam(name = "role", value = "角色实体role", required = true, dataType = "Role")
@Log("更新角色菜单")
......@@ -209,7 +204,7 @@ public class RoleController extends BaseController {
* @date 2018/9/14 18:23
*/
@PostMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('sys:role:add') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "创建角色", notes = "创建角色")
@ApiImplicitParam(name = "role", value = "角色实体role", required = true, dataType = "Role")
@Log("新增角色")
......@@ -227,7 +222,7 @@ public class RoleController extends BaseController {
* @date 2018/9/14 18:24
*/
@DeleteMapping("/{id}")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('sys:role:del') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "删除角色", notes = "根据ID删除角色")
@ApiImplicitParam(name = "id", value = "角色ID", required = true, paramType = "path")
@Log("删除角色")
......@@ -248,7 +243,7 @@ public class RoleController extends BaseController {
* @date 2018/12/4 10:00
*/
@PostMapping("/deleteAll")
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@PreAuthorize("hasAuthority('sys:role:del') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "', '" + SecurityConstant.ROLE_TEACHER + "')")
@ApiOperation(value = "批量删除角色", notes = "根据角色id批量删除角色")
@ApiImplicitParam(name = "role", value = "角色信息", dataType = "Role")
@Log("批量删除角色")
......
package com.github.tangyi.user.controller;
import com.github.pagehelper.PageInfo;
import com.github.tangyi.common.core.constant.CommonConstant;
import com.github.tangyi.common.core.constant.MqConstant;
import com.github.tangyi.common.core.model.ResponseBean;
import com.github.tangyi.common.core.model.Route;
import com.github.tangyi.common.core.utils.PageUtil;
import com.github.tangyi.common.core.utils.SysUtil;
import com.github.tangyi.common.core.web.BaseController;
import com.github.tangyi.common.log.annotation.Log;
import com.github.tangyi.common.security.constant.SecurityConstant;
import com.github.tangyi.common.security.utils.SecurityUtil;
import com.github.tangyi.user.service.RouteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.Collections;
import java.util.List;
/**
* 路由controller
*
* @author tangyi
* @date 2019/4/2 15:03
*/
@Api("网关路由信息管理")
@RestController
@RequestMapping("/v1/route")
public class RouteController extends BaseController {
@Autowired
private RouteService routeService;
@Autowired
private AmqpTemplate amqpTemplate;
/**
* 根据id获取路由
*
* @param id id
* @return Route
* @author tangyi
* @date 2019/4/2 15:09
*/
@GetMapping("/{id}")
@ApiOperation(value = "获取路由信息", notes = "根据路由id获取路由详细信息")
@ApiImplicitParam(name = "id", value = "路由ID", required = true, dataType = "String", paramType = "path")
public Route get(@PathVariable String id) {
try {
return routeService.get(id);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
return new Route();
}
/**
* 路由分页查询
*
* @param pageNum pageNum
* @param pageSize pageSize
* @param sort sort
* @param order order
* @param route route
* @return PageInfo
* @author tangyi
* @date 2019/4/2 15:09
*/
@RequestMapping("routeList")
@ApiOperation(value = "获取路由列表")
@ApiImplicitParams({
@ApiImplicitParam(name = CommonConstant.PAGE_NUM, value = "分页页码", defaultValue = CommonConstant.PAGE_NUM_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.PAGE_SIZE, value = "分页大小", defaultValue = CommonConstant.PAGE_SIZE_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.SORT, value = "排序字段", defaultValue = CommonConstant.PAGE_SORT_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = CommonConstant.ORDER, value = "排序方向", defaultValue = CommonConstant.PAGE_ORDER_DEFAULT, dataType = "String"),
@ApiImplicitParam(name = "route", value = "路由信息", dataType = "Route")
})
public PageInfo<Route> userList(@RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) String pageNum,
@RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) String pageSize,
@RequestParam(value = CommonConstant.SORT, required = false, defaultValue = CommonConstant.PAGE_SORT_DEFAULT) String sort,
@RequestParam(value = CommonConstant.ORDER, required = false, defaultValue = CommonConstant.PAGE_ORDER_DEFAULT) String order,
Route route) {
return routeService.findPage(PageUtil.pageInfo(pageNum, pageSize, sort, order), route);
}
/**
* 修改路由
*
* @param route route
* @return ResponseBean
* @author tangyi
* @date 2019/4/2 15:09
*/
@PutMapping
@PreAuthorize("hasAuthority('sys:route:edit') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "')")
@ApiOperation(value = "更新路由信息", notes = "根据路由id更新路由的基本信息")
@ApiImplicitParam(name = "route", value = "路由实体route", required = true, dataType = "Route")
@Log("修改路由")
public ResponseBean<Boolean> updateRoute(@RequestBody Route route) {
route.setCommonValue(SecurityUtil.getCurrentUsername(), SysUtil.getSysCode());
// 更新路由
if (routeService.update(route) > 0) {
// 发送消息
if (Integer.parseInt(route.getStatus()) == CommonConstant.DEL_FLAG_DEL) {
amqpTemplate.convertAndSend(MqConstant.DEL_GATEWAY_ROUTE_QUEUE, route);
} else {
amqpTemplate.convertAndSend(MqConstant.EDIT_GATEWAY_ROUTE_QUEUE, route);
}
}
return new ResponseBean<>(Boolean.TRUE);
}
/**
* 创建路由
*
* @param route route
* @return ResponseBean
* @author tangyi
* @date 2019/4/2 15:09
*/
@PostMapping
@PreAuthorize("hasAuthority('sys:route:add') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "')")
@ApiOperation(value = "创建路由", notes = "创建路由")
@ApiImplicitParam(name = "route", value = "路由实体route", required = true, dataType = "Route")
@Log("新增路由")
public ResponseBean<Boolean> add(@RequestBody Route route) {
route.setCommonValue(SecurityUtil.getCurrentUsername(), SysUtil.getSysCode());
if (routeService.insert(route) > 0 && Integer.parseInt(route.getStatus()) == CommonConstant.DEL_FLAG_NORMAL) {
// 发送消息
amqpTemplate.convertAndSend(MqConstant.EDIT_GATEWAY_ROUTE_QUEUE, route);
}
return new ResponseBean<>(Boolean.TRUE);
}
/**
* 根据id删除路由
*
* @param id id
* @return ResponseBean
* @author tangyi
* @date 2019/4/2 15:09
*/
@DeleteMapping("/{id}")
@PreAuthorize("hasAuthority('sys:route:del') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "')")
@ApiOperation(value = "删除路由", notes = "根据ID删除路由")
@ApiImplicitParam(name = "id", value = "路由ID", required = true, paramType = "path")
@Log("删除路由")
public ResponseBean<Boolean> delete(@PathVariable String id) {
Route route = new Route();
route.setId(id);
route = routeService.get(route);
route.setNewRecord(false);
route.setCommonValue(SecurityUtil.getCurrentUsername(), SysUtil.getSysCode());
if (routeService.delete(route) > 0) {
// 发送消息
amqpTemplate.convertAndSend(MqConstant.DEL_GATEWAY_ROUTE_QUEUE, Collections.singletonList(route));
}
return new ResponseBean<>(Boolean.TRUE);
}
/**
* 批量删除
*
* @param route route
* @return ResponseBean
* @author tangyi
* @date 2019/4/2 15:09
*/
@PostMapping("/deleteAll")
@PreAuthorize("hasAuthority('sys:route:del') or hasAnyRole('" + SecurityConstant.ROLE_ADMIN + "')")
@ApiOperation(value = "批量删除路由", notes = "根据路由id批量删除路由")
@ApiImplicitParam(name = "route", value = "路由信息", dataType = "Route")
@Log("批量删除路由")
public ResponseBean<Boolean> deleteAll(@RequestBody Route route) {
boolean success = false;
try {
if (StringUtils.isNotEmpty(route.getIdString())) {
// 先获取路由列表
List<Route> routeList = routeService.findListById(route);
// 删除
success = routeService.deleteAll(route.getIdString().split(",")) > 0;
if (success && CollectionUtils.isNotEmpty(routeList)) {
// 发送消息
amqpTemplate.convertAndSend(MqConstant.DEL_GATEWAY_ROUTE_QUEUE, route);
}
}
} catch (Exception e) {
logger.error("删除路由失败!", e);
}
return new ResponseBean<>(success);
}
}
......@@ -6,7 +6,6 @@ import com.github.tangyi.user.config.SysConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -33,7 +32,6 @@ public class SysConfigController extends BaseController {
* @date 2019/2/28 17:31
*/
@GetMapping
@PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
@ApiOperation(value = "获取系统配置", notes = "获取系统配置")
public ResponseBean<SysConfig> getSysConfig() {
return new ResponseBean<>(sysConfig);
......
package com.github.tangyi.user.mapper;
import com.github.tangyi.common.core.persistence.CrudMapper;
import com.github.tangyi.common.core.model.Route;
import org.apache.ibatis.annotations.Mapper;
/**
* Route mapper
*
* @author tangyi
* @date 2019/4/2 15:00
*/
@Mapper
public interface RouteMapper extends CrudMapper<Route> {
}
package com.github.tangyi.user.receiver;
import com.github.tangyi.common.core.constant.MqConstant;
import com.github.tangyi.user.config.RouteInitConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author tangyi
* @date 2019/4/7 12:38
*/
@Service
public class RouteReceiver {
private static final Logger logger = LoggerFactory.getLogger(RouteReceiver.class);
@Autowired
private RouteInitConfig routeInitConfig;
/**
* 刷新路由
*
* @param msg msg
* @author tangyi
* @date 2019/04/07 12:39
*/
@RabbitListener(queues = {MqConstant.REFRESH_GATEWAY_ROUTE_QUEUE})
public void refreshRoute(String msg) {
logger.info("刷新路由{}", msg);
routeInitConfig.init();
}
}
package com.github.tangyi.user.service;
import com.github.tangyi.common.core.service.CrudService;
import com.github.tangyi.common.core.model.Route;
import com.github.tangyi.user.mapper.RouteMapper;
import org.springframework.stereotype.Service;
/**
* 路由service
*
* @author tangyi
* @date 2019/4/2 15:01
*/
@Service
public class RouteService extends CrudService<RouteMapper, Route> {
}
......@@ -18,8 +18,6 @@ import com.github.tangyi.user.mapper.UserMapper;
import com.github.tangyi.user.mapper.UserRoleMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
......@@ -43,8 +41,6 @@ import java.util.concurrent.TimeUnit;
@Service
public class UserService extends CrudService<UserMapper, User> {
private static final Logger logger = LoggerFactory.getLogger(UserService.class);
@Autowired
private UserMapper userMapper;
......@@ -88,7 +84,7 @@ public class UserService extends CrudService<UserMapper, User> {
* @param userVo userVo
* @return User
* @author tangyi
* @date 2018/9/11 下午 11:44
* @date 2018/9/11 23:44
*/
public UserInfoDto findUserInfo(UserVo userVo) {
// 根据用户名查询用户信息
......@@ -128,7 +124,7 @@ public class UserService extends CrudService<UserMapper, User> {
* @param userDto userDto
* @return int
* @author tangyi
* @date 2018/8/26 下午 3:15
* @date 2018/8/26 15:15
*/
@Transactional
@CacheEvict(value = "user", key = "#userDto.username")
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.github.tangyi.user.mapper.RouteMapper">
<resultMap id="routeResultMap" type="com.github.tangyi.common.core.model.Route">
<id column="id" property="id"/>
<result column="route_id" property="routeId" />
<result column="route_name" property="routeName" />
<result column="predicates" property="predicates" />
<result column="filters" property="filters" />
<result column="uri" property="uri" />
<result column="sort" property="sort" />
<result column="status" property="status" />
<result column="creator" property="creator" />
<result column="create_date" property="createDate" />
<result column="modifier" property="modifier" />
<result column="modify_date" property="modifyDate" />
<result column="del_flag" property="delFlag" />
<result column="application_code" property="applicationCode" />
</resultMap>
<sql id="routeColumns">
a.id as "id",
a.route_id,
a.route_name,
a.predicates,
a.filters,
a.uri,
a.sort,
a.status,
a.creator,
a.create_date,
a.modifier,
a.modify_date,
a.del_flag,
a.application_code
</sql>
<!-- where 条件 -->
<sql id="whereColumnList">
<if test="routeId != null and routeId != ''">
and a.route_id like CONCAT('%', #{routeId},'%')
</if>
<if test="routeName != null and routeName != ''">
and a.route_name like CONCAT('%', #{routeName},'%')
</if>
<if test="status != null and status != ''">
and a.status = #{status}
</if>
</sql>
<select id="get" resultMap="routeResultMap">
SELECT
<include refid="routeColumns"/>
FROM sys_route a
WHERE a.id = #{id} and a.del_flag = 0
</select>
<select id="findList" resultMap="routeResultMap">
SELECT
<include refid="routeColumns"/>
FROM sys_route a
WHERE a.del_flag = 0
<include refid="whereColumnList"/>
</select>
<select id="findListById" resultMap="routeResultMap">
SELECT
<include refid="routeColumns"/>
FROM sys_route a
WHERE a.id IN
<foreach collection="ids" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<insert id="insert">
INSERT INTO sys_route (
id,
route_id,
route_name,
predicates,
filters,
uri,
sort,
status,
creator,
create_date,
modifier,
modify_date,
del_flag,
application_code
) VALUES (
#{id},
#{routeId},
#{routeName},
#{predicates},
#{filters},
#{uri},
#{sort},
#{status},
#{creator},
#{createDate},
#{modifier},
#{modifyDate},
#{delFlag},
#{applicationCode}
)
</insert>
<update id="update">
UPDATE sys_route SET
<if test="routeId != null">
route_id = #{routeId},
</if>
<if test="routeName != null">
route_name = #{routeName},
</if>
<if test="predicates != null">
predicates = #{predicates},
</if>
<if test="filters != null">
filters = #{filters},
</if>
<if test="uri != null">
uri = #{uri},
</if>
<if test="sort != null">
sort = #{sort},
</if>
<if test="status != null">
status = #{status},
</if>
modifier = #{modifier},
modify_date = #{modifyDate}
WHERE
<if test="id != null">
id = #{id}
</if>
</update>
<delete id="delete">
UPDATE sys_route SET
del_flag = 1
WHERE id = #{id}
</delete>
<delete id="deleteAll">
UPDATE sys_route SET
del_flag = 1
WHERE id in
<foreach item="item" index="index" collection="array" open="("
separator="," close=")"> #{item}
</foreach>
</delete>
</mapper>
......@@ -8,6 +8,7 @@
<version>2.0-SNAPSHOT</version>
</parent>
<artifactId>zipkin-service</artifactId>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
<description>zipkin监控服务</description>
</project>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment