diff --git a/src/main/java/com/msdw/tms/common/utils/Constant.java b/src/main/java/com/msdw/tms/common/utils/Constant.java index 14962fa..4588be9 100644 --- a/src/main/java/com/msdw/tms/common/utils/Constant.java +++ b/src/main/java/com/msdw/tms/common/utils/Constant.java @@ -41,11 +41,15 @@ public class Constant { /** * 通过excel批量导入试题数据时起始行 */ - public static final int STARTING_ROW = 2; + public static final int ROW_INDEX = 2; /** - * 通过excel批量导入试题数据时起始列 + * 通过excel批量导入试题数据时起始行 + */ + public static final int CELL_INDEX = 0; + /** + * 需要提取的样式所在的行号 */ - public static final int STARTING_CELL = 0; + public static final int STYLE_INDEX = 2; /** * 试题选项A */ @@ -77,7 +81,10 @@ public class Constant { /** * 测评规则表id */ - public static final int EVALUATION_RULES_ID = 1; + public static final int EVALUATION_RULES_ID = 1;/** + * 测评规则表id + */ + public static final String EXCEL_SUFFIX = ".xlsx"; /** * 菜单类型 * @@ -211,7 +218,7 @@ public class Constant { /** * 删除 */ - DEL(1, "删除"), + DEL(1, "已删除"), /** * 不删除 */ diff --git a/src/main/java/com/msdw/tms/controller/QuestionsController.java b/src/main/java/com/msdw/tms/controller/QuestionsController.java index 7431a2d..cbb1eb7 100644 --- a/src/main/java/com/msdw/tms/controller/QuestionsController.java +++ b/src/main/java/com/msdw/tms/controller/QuestionsController.java @@ -18,6 +18,7 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.Arrays; +import java.util.List; /** @@ -115,10 +116,9 @@ public class QuestionsController implements QuestionsControllerApi { @PostMapping("/import") //@RequiresPermissions("qms:questions:import") public R importQuestion(@RequestParam(name = "file") MultipartFile file) throws IOException { - //TODO boolean b = questionsService.importQuestion(file); + List list = questionsService.importQuestion(file); - //return b ? R.ok() : R.error(); - return null; + return R.ok().put("data", list); } /** diff --git a/src/main/java/com/msdw/tms/entity/QuestionsEntity.java b/src/main/java/com/msdw/tms/entity/QuestionsEntity.java index a536930..1a47701 100644 --- a/src/main/java/com/msdw/tms/entity/QuestionsEntity.java +++ b/src/main/java/com/msdw/tms/entity/QuestionsEntity.java @@ -86,8 +86,4 @@ public class QuestionsEntity implements Serializable { * 修改时间,用于排序,创建时,修改时间等于创建时间 */ private Date modifyTime; - /** - * 试题科目 - */ - private String subjects; } diff --git a/src/main/java/com/msdw/tms/entity/request/QuestionsUpdateRequest.java b/src/main/java/com/msdw/tms/entity/request/QuestionsUpdateRequest.java index c84895a..f44f6fa 100644 --- a/src/main/java/com/msdw/tms/entity/request/QuestionsUpdateRequest.java +++ b/src/main/java/com/msdw/tms/entity/request/QuestionsUpdateRequest.java @@ -67,9 +67,4 @@ public class QuestionsUpdateRequest { */ @ApiModelProperty(value = "答案解析", name = "answerAnalysis", example = "鲸鱼是最大的哺乳动物") private String answerAnalysis; - /** - * 试题科目 - */ - @ApiModelProperty(value = "试题科目", name = "subjects", example = "基础通识") - private String subjects; } diff --git a/src/main/java/com/msdw/tms/entity/response/CommonCode.java b/src/main/java/com/msdw/tms/entity/response/CommonCode.java index 23b65c5..542b19e 100644 --- a/src/main/java/com/msdw/tms/entity/response/CommonCode.java +++ b/src/main/java/com/msdw/tms/entity/response/CommonCode.java @@ -14,6 +14,7 @@ public enum CommonCode implements ResultCode { QUESTIONTYPE_INVALID(false, 10006, "题型错误!"), EXCEL_INVALID(false, 10007, "excel表内容错误!"), EVALUATION_TIME_INVALID(false, 10008, "测评时间错误!"), + EXCEL_FILE_INVALID(false, 10009, "上传excel文件错误!"), FAIL(false, 11111, "操作失败!"), SERVER_ERROR(false, 99999, "抱歉,系统繁忙,请稍后重试!"); //操作是否成功 diff --git a/src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java index 55cdf06..2a97bc2 100644 --- a/src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java +++ b/src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java @@ -323,9 +323,15 @@ public class QuestionsServiceImpl extends ServiceImpl importQuestion(MultipartFile file) throws IOException { + // 参数合法性校验,只能上传.xlsx后缀的文件 + if (StringUtils.isBlank(file.getOriginalFilename()) + || !file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")).equals(Constant.EXCEL_SUFFIX)) { + ExceptionCast.cast(CommonCode.EXCEL_FILE_INVALID); + } + // 使用excel导入工具类获取试题数据列表 List list = new ExcelImportUtil(QuestionsImportRequest.class) - .readExcel(file.getInputStream(), Constant.STARTING_ROW, Constant.STARTING_CELL); + .readExcel(file.getInputStream(), Constant.ROW_INDEX, Constant.CELL_INDEX); if (list == null || list.size() == 0) { ExceptionCast.cast(CommonCode.EXCEL_INVALID); @@ -380,6 +386,13 @@ public class QuestionsServiceImpl extends ServiceImpl ops = stringRedisTemplate.opsForValue(); -// String key = REMAINING_TINE_KEY + userId; -// String startTime = ops.get(key); -// // 剩余时间,单位:秒 -// int remainingTime = duration * 60; -// if (StringUtils.isEmpty(startTime)) { -// //如果没有,表示是开始测评,向redis中插入一条数据,key是前缀加用户id,value是当前时间,过期时间是测评时长加十秒 -// ops.set(key, String.valueOf(System.currentTimeMillis()), duration * 60 + 10, TimeUnit.SECONDS); -// } else { -// // 当前时间与开始时间得时间差,单位:毫秒 -// long difference = System.currentTimeMillis() - Long.parseLong(startTime); -// remainingTime = (duration * 60) - (new Long(difference).intValue() / 1000); -// if (remainingTime < 0) { -// ExceptionCast.cast(CommonCode.EVALUATION_TIME_INVALID); -// } -// } -// evaluation.setRemainingDuration(DateUtil.secondToTime(remainingTime)); - - + //TODO 提交测评时删除redis中的该条数据 //搜集随机抽取的试题 Set set = new HashSet<>(); @@ -501,11 +487,11 @@ public class QuestionsServiceImpl extends ServiceImpl - \ No newline at end of file diff --git a/src/main/resources/sql/data.sql b/src/main/resources/sql/data.sql new file mode 100644 index 0000000..f40c053 --- /dev/null +++ b/src/main/resources/sql/data.sql @@ -0,0 +1,81 @@ +/* +Navicat MySQL Data Transfer + +Source Server : localhost +Source Server Version : 80020 +Source Host : localhost:3306 +Source Database : msdw_tms + +Target Server Type : MYSQL +Target Server Version : 80020 +File Encoding : 65001 + +Date: 2020-08-26 18:02:57 +*/ + +SET FOREIGN_KEY_CHECKS=0; + +-- ---------------------------- +-- Table structure for tms_evaluation_rules +-- ---------------------------- +DROP TABLE IF EXISTS `tms_evaluation_rules`; +CREATE TABLE `tms_evaluation_rules` ( + `id` int NOT NULL AUTO_INCREMENT COMMENT '主键', + `evaluation_type` int DEFAULT NULL COMMENT '测评类型:1:随机类型,0:自定义类型', + `duration` int DEFAULT NULL COMMENT '测评时长,单位:分钟', + `question_num` int DEFAULT NULL COMMENT '测评总题数', + `single_num` int DEFAULT NULL COMMENT '单选题数', + `is_single_enable` int DEFAULT '1' COMMENT '只在类型为自定义类型时才启用:1:启用,0:不启用,默认1启用', + `multiple_num` int DEFAULT NULL COMMENT '多选题数', + `is_multiple_enable` int DEFAULT '1' COMMENT '只在类型为自定义类型时才启用:1:启用,0:不启用,默认1启用', + `judgment_num` int DEFAULT NULL COMMENT '判断题数', + `is_judgment_enable` int DEFAULT '1' COMMENT '只在类型为自定义类型时才启用:1:启用,0:不启用,默认1启用', + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='测评规则信息记录,只记录一条信息'; + +-- ---------------------------- +-- Records of tms_evaluation_rules +-- ---------------------------- +INSERT INTO `tms_evaluation_rules` VALUES ('1', '1', '10', '0', '0', '1', '0', '1', '0', '1'); + +-- ---------------------------- +-- Table structure for tms_questions +-- ---------------------------- +DROP TABLE IF EXISTS `tms_questions`; +CREATE TABLE `tms_questions` ( + `id` int NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `question_type` int DEFAULT NULL COMMENT '题型:1、单选题,2、多选题,3、判断题', + `question_stem` text COMMENT '题干信息', + `option_a` text COMMENT 'A选项内容', + `option_b` text COMMENT 'B选项内容', + `option_c` text COMMENT 'C选项内容', + `option_d` text COMMENT 'D选项内容', + `option_e` text COMMENT 'E选项内容', + `option_f` text COMMENT 'F选项内容', + `answer` varchar(32) DEFAULT NULL COMMENT '正确答案', + `answer_analysis` text COMMENT '答案解析', + `is_enable` int DEFAULT '1' COMMENT '是否禁用:1:启用,0:禁用,默认是1启用', + `is_del` int DEFAULT '0' COMMENT '是否删除:0未删除,1删除,默认0未删除', + `create_user` varchar(32) DEFAULT NULL COMMENT '创建人', + `create_time` datetime DEFAULT NULL COMMENT '创建时间', + `modify_user` varchar(32) DEFAULT NULL COMMENT '修改人', + `modify_time` datetime DEFAULT NULL COMMENT '修改时间,用于排序,创建时,修改时间等于创建时间', + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=53 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='记录试题信息'; + +-- ---------------------------- +-- Table structure for tms_xlsx_template +-- ---------------------------- +DROP TABLE IF EXISTS `tms_xlsx_template`; +CREATE TABLE `tms_xlsx_template` ( + `id` int NOT NULL AUTO_INCREMENT COMMENT '主键', + `file_name` varchar(300) DEFAULT NULL COMMENT '文件名', + `file_url` varchar(500) DEFAULT NULL COMMENT '文件全路径', + `status` int DEFAULT NULL COMMENT '状态', + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='模板文件信息记录'; + +-- ---------------------------- +-- Records of tms_xlsx_template +-- ---------------------------- +INSERT INTO `tms_xlsx_template` VALUES ('1', 'xlsx/20200826/1598430904075.xlsx', 'http://liuwanr.oss-cn-shenzhen.aliyuncs.com/xlsx/20200826/1598430904075.xlsx', null); \ No newline at end of file diff --git a/src/test/java/com/msdw/tms/TmsApplicationTests.java b/src/test/java/com/msdw/tms/TmsApplicationTests.java index f91b814..9876fca 100644 --- a/src/test/java/com/msdw/tms/TmsApplicationTests.java +++ b/src/test/java/com/msdw/tms/TmsApplicationTests.java @@ -278,4 +278,13 @@ class TmsApplicationTests { System.out.println(s); } + @Test + void t7() throws ParseException { + + String f = "hahdhfasdf.xlsx"; + + System.out.println(f.substring(f.lastIndexOf("."))); + + } + }