Commit 9f6d0ba5 by tangyi

修复bug、增加演示环境相关内容

parent 4fa72a58
......@@ -12,9 +12,9 @@
- 后端基于`spring boot``spring cloud``MySQL`等技术实现权限管理、考试管理等功能。
- [在线体验-前台](http://www.it99.club)
- 在线体验-前台:[http://www.it99.club](http://www.it99.club)
- [在线体验-后台](http://www.it99.club:81)
- 在线体验-后台:[http://www.it99.club:81](http://www.it99.club:81)
## 技术选型
......
......@@ -83,6 +83,7 @@ ignore:
- /actuator/**
- /hystrix.sender
- /v1/user/findUserByUsername/**
- /v1/user/checkExist/**
- /v1/menu/findMenuByRole/**
- /v1/code/**
- /v1/attachment/download
......
......@@ -98,6 +98,7 @@ ignore:
- /hystrix.sender
- /v1/user/findUserByUsername/**
- /v1/menu/findMenuByRole/**
- /v1/user/checkExist/**
- /v1/code/**
- /v1/attachment/download
- /v1/log/**
......
......@@ -63,6 +63,19 @@ swagger:
- exam-service
- auth-service
# 演示环境
preview:
enabled: ${PREVIEW_ENABLED:false}
ignoreUrls:
- token
- examRecord
- saveOrUpdate
- register
- submit
- checkExist
- updateInfo
- attachment
logging:
level:
root: info
......
......@@ -123,6 +123,7 @@ ignore:
- /v1/user/findUserByUsername/**
- /v1/menu/findMenuByRole/**
- /v1/user/register
- /v1/user/checkExist/**
- /v1/code/**
- /v1/attachment/download
- /v1/log/**
......
......@@ -11,7 +11,7 @@
Target Server Version : 50710
File Encoding : 65001
Date: 21/04/2019 13:46:49
Date: 23/04/2019 20:03:29
*/
SET NAMES utf8mb4;
......
......@@ -11,7 +11,7 @@
Target Server Version : 50710
File Encoding : 65001
Date: 21/04/2019 13:47:02
Date: 23/04/2019 20:03:38
*/
SET NAMES utf8mb4;
......@@ -63,6 +63,7 @@ CREATE TABLE `course` (
-- Records of course
-- ----------------------------
INSERT INTO `course` VALUES ('6dcccd4639bc49b88810be1d30a77f92', '测试课程', '测试学院', '测试专业', '陈老师', '测试课程', 'admin', '2018-11-12 22:31:28', 'admin', '2019-04-11 16:51:15', '0', 'EXAM');
INSERT INTO `course` VALUES ('b2321aa045d64448a3ad710aae6efbbf', '高等数学', '测试', '测试', '测试', '测试', 'admin', '2019-04-23 19:40:05', 'admin', '2019-04-23 19:40:05', '0', 'EXAM');
-- ----------------------------
-- Table structure for exam_record
......@@ -121,10 +122,10 @@ CREATE TABLE `examination` (
-- ----------------------------
-- Records of examination
-- ----------------------------
INSERT INTO `examination` VALUES ('4f9ced28ffe64fcea57a7367e9fd4c0c', '离散数学', '2', '离散数学', '2019-01-03 00:00', '2019-01-11 00:00', '', '100', '0', '1', 'group1/M00/00/00/wKgAX1x3gGqABz6cAAZyO2yzEwA450.jpg', 'da4b5623e9754abbb07320d8def18fe7', '信息学院', '软件工程', '6dcccd4639bc49b88810be1d30a77f92', '离散数学练习', 'admin', '2019-01-13 20:16:36', 'admin', '2019-04-11 10:56:03', '0', 'EXAM');
INSERT INTO `examination` VALUES ('4f9ced28ffe64fcea57a7367e9fd4c0c', '离散数学', '2', '离散数学', '2019-01-03 00:00', '2019-01-11 00:00', '', '100', '0', '1', 'group1/M00/00/00/wKgAX1x3gGqABz6cAAZyO2yzEwA450.jpg', 'da4b5623e9754abbb07320d8def18fe7', '信息学院', '软件工程', 'b2321aa045d64448a3ad710aae6efbbf', '离散数学练习', 'admin', '2019-01-13 20:16:36', 'admin', '2019-04-23 19:40:15', '0', 'EXAM');
INSERT INTO `examination` VALUES ('b5990bc1c48d49fcb0023de51772c309', '数学期末考试', '0', '期末考试', '2019-01-22 17:00', '2019-01-22 23:00', '', '150', '2', '1', 'group1/M00/00/00/wKgAX1x3gHWAa82wAAArtzxOXJ4599.jpg', '60df2d550bd9453a943122033a27fe72', '应用数学', '应用数学', '6dcccd4639bc49b88810be1d30a77f92', '期末考试', 'admin', '2018-11-20 22:48:40', NULL, '2019-03-18 14:09:49', '0', 'EXAM');
INSERT INTO `examination` VALUES ('f051f54621fc4812b929a7777a701712', '语文考试', '0', '语文考试', '2019-01-22 17:00', '2019-01-22 23:00', '', '150', '2', '1', 'group1/M00/00/00/wKgAX1x3gIOAIVzXAABrb92CxLk678.jpg', '45d2ac58eb21436692e8cdbdd64291dd', '中文', '中文', '6dcccd4639bc49b88810be1d30a77f92', '语文考试', 'admin', '2018-11-20 22:50:55', 'admin', '2019-02-28 14:33:27', '0', 'EXAM');
INSERT INTO `examination` VALUES ('fad663ea371f4250a81332bd3a346739', '四川省2016年普通高考适应性测试文综历史试题', '0', '文综历史试题', '2019-04-11 00:00', '2019-04-11 20:30', '', '100', '3', '0', 'group1/M00/00/00/wKgAX1x3f52AIE4IAADGq28ys0g361.jpg', 'a178c7b221524a89b44e884d8e3172cf', '文综历史试题', '文综历史试题', '6dcccd4639bc49b88810be1d30a77f92', '文综历史试题', 'admin', '2018-11-12 20:25:38', 'admin', '2019-03-06 13:57:13', '0', 'EXAM');
INSERT INTO `examination` VALUES ('fad663ea371f4250a81332bd3a346739', '四川省2016年普通高考适应性测试文综历史试题', '0', '文综历史试题', '2019-04-23 12:00', '2019-04-23 20:30', '', '100', '3', '0', 'group1/M00/00/00/wKgAX1x3f52AIE4IAADGq28ys0g361.jpg', 'a178c7b221524a89b44e884d8e3172cf', '文综历史试题', '文综历史试题', '6dcccd4639bc49b88810be1d30a77f92', '文综历史试题', 'admin', '2018-11-12 20:25:38', 'admin', '2019-03-06 13:57:13', '0', 'EXAM');
-- ----------------------------
-- Table structure for incorrect_answer
......@@ -234,6 +235,14 @@ CREATE TABLE `subject_bank` (
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '题库表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of subject_bank
-- ----------------------------
INSERT INTO `subject_bank` VALUES ('2f4d39409f164955b26941202e8f6d86', '700556b5becd4091821644a5288d489c', '323', '323', '0', '', '32', '323', '2323', '2323', '', '', 'B', '323', '32323', '2', 'admin', '2019-04-23 19:37:02', 'admin', '2019-04-23 19:37:02', '0', 'EXAM');
INSERT INTO `subject_bank` VALUES ('50f5ca89942e4b468fc9d9fd1323231b', 'c664646337c345ac8a91e3b024ded8bb', '1', '1', '0', '', '1', '1', '1', '1', '', '', 'B', '1', '1', '2', 'admin', '2019-04-23 19:40:34', 'admin', '2019-04-23 19:40:34', '0', 'EXAM');
INSERT INTO `subject_bank` VALUES ('a66c85dc98a243bdbb576ca699ed4a78', '700556b5becd4091821644a5288d489c', '1', '1', '0', '', '1', '1', '1', '1', '', '', 'B', '1', '1', '2', 'admin', '2019-04-23 19:36:54', 'admin', '2019-04-23 19:36:54', '0', 'EXAM');
INSERT INTO `subject_bank` VALUES ('bc030f9138964031bca3de7ef1621ca6', 'c664646337c345ac8a91e3b024ded8bb', '32', '32', '0', '', '323', '32', '332', '3323', '', '', 'B', '32', '323', '2', 'admin', '2019-04-23 19:40:42', 'admin', '2019-04-23 19:40:42', '0', 'EXAM');
-- ----------------------------
-- Table structure for subject_category
-- ----------------------------
DROP TABLE IF EXISTS `subject_category`;
......
......@@ -59,7 +59,8 @@ services:
# Redis
# ---------------------------
redis:
image: redis:alpine
image: redis:latest
container_name: redis
ports:
- "6379:6379"
networks:
......
......@@ -45,4 +45,7 @@ ADMIN_PASSWORD=11
// zipkin配置
ZIPKIN_HOST=localhost
ZIPKIN_PORT=9411
\ No newline at end of file
ZIPKIN_PORT=9411
// 演示环境
PREVIEW_ENABLED=false
\ No newline at end of file
package com.github.tangyi.gateway.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;
import java.util.ArrayList;
import java.util.List;
/**
* 演示环境配置
* @author tangyi
* @date 2019/4/23 13:38
*/
@Configuration
@RefreshScope
@ConditionalOnExpression("!'${preview}'.isEmpty()")
@ConfigurationProperties(prefix = "preview")
public class PreviewConfig {
private List<String> ignoreUrls = new ArrayList<>();
public List<String> getIgnoreUrls() {
return ignoreUrls;
}
public void setIgnoreUrls(List<String> ignoreUrls) {
this.ignoreUrls = ignoreUrls;
}
}
package com.github.tangyi.gateway.filters;
import cn.hutool.core.util.StrUtil;
import com.github.tangyi.gateway.config.PreviewConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
import java.util.List;
/**
* 演示环境过滤器
* 如果配置了preview.enabled为true则过滤器生效
*
* @author tangyi
* @date 2019/4/23 10:54
*/
@Configuration
@ConditionalOnProperty(prefix = "preview", name = "enabled", havingValue = "true", matchIfMissing = true)
public class PreviewFilter implements GlobalFilter, Ordered {
private static final Logger logger = LoggerFactory.getLogger(PreviewFilter.class);
@Autowired
private PreviewConfig previewConfig;
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
// 当前请求
ServerHttpRequest request = exchange.getRequest();
// GET或者忽略的URL,直接向下执行
if (StrUtil.equalsIgnoreCase(request.getMethodValue(), HttpMethod.GET.name()) || isIgnore(request.getURI().getPath()))
return chain.filter(exchange);
logger.warn("演示环境不能操作,{},{}", request.getMethodValue(), request.getURI().getPath());
ServerHttpResponse response = exchange.getResponse();
response.setStatusCode(HttpStatus.LOCKED);
return response.setComplete();
}
/**
* 是否忽略URI
*
* @param uri uri
* @return boolean
* @author tangyi
* @date 2019/04/23 13:44
*/
private boolean isIgnore(String uri) {
List<String> ignoreUrls = previewConfig.getIgnoreUrls();
if (ignoreUrls != null && !ignoreUrls.isEmpty()) {
for (String ignoreUrl : ignoreUrls) {
if (StrUtil.containsIgnoreCase(uri, ignoreUrl))
return true;
}
}
return false;
}
@Override
public int getOrder() {
return -100;
}
}
......@@ -31,8 +31,6 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
/**
* 题库controller
......@@ -105,10 +103,10 @@ public class SubjectBankController extends BaseController {
SubjectCategory subjectCategory = new SubjectCategory();
// 流处理获取分类ID,去重,转成字符串数组
subjectCategory.setIds(page.getList().stream().map(SubjectBank::getCategoryId).distinct().toArray(String[]::new));
Stream<SubjectCategory> subjectCategoryStream = subjectCategoryService.findListById(subjectCategory).stream();
if (Optional.ofNullable(subjectCategoryStream).isPresent()) {
List<SubjectCategory> subjectCategoryList = subjectCategoryService.findListById(subjectCategory);
if (CollectionUtils.isNotEmpty(subjectCategoryList)) {
page.getList().forEach(tempSubjectBank -> {
SubjectCategory category = subjectCategoryStream
SubjectCategory category = subjectCategoryList.stream()
.filter(tempSubjectCategory -> tempSubjectCategory.getId().equals(tempSubjectBank.getCategoryId()))
.findFirst()
.orElse(null);
......
......@@ -444,4 +444,22 @@ public class UserController extends BaseController {
}
return new ResponseBean<>(success);
}
/**
* 检查用户是否存在
*
* @param username username
* @return ResponseBean
* @author tangyi
* @date 2019/04/23 15:35
*/
@ApiOperation(value = "检查用户是否存在", notes = "检查用户名是否存在")
@ApiImplicitParam(name = "username", value = "用户name", required = true, dataType = "String", paramType = "path")
@GetMapping("/checkExist/{username}")
public ResponseBean<Boolean> checkUsernameIsExist(@PathVariable("username") String username) {
boolean exist = Boolean.FALSE;
if (StringUtils.isNotEmpty(username))
exist = userService.selectUserVoByUsername(username) != null;
return new ResponseBean<>(exist);
}
}
......@@ -59,6 +59,7 @@ public class UserService extends CrudService<UserMapper, User> {
*/
@Override
@Transactional
@CacheEvict(value = "user", key = "#user.username")
public int insert(User user) {
// 保存角色
if (CollectionUtils.isNotEmpty(user.getRole())) {
......
......@@ -144,7 +144,7 @@
<select id="selectUserVoByUsername" resultMap="userVoResultMap">
<include refid="selectUserVo"/>
WHERE `user`.username = #{username}
WHERE `user`.username = #{username} and `user`.del_flag = 0
</select>
<select id="get" resultMap="userResultMap">
......
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