整体测试和细节调整

hehai msdw_tms-v1.0.1
shijie 4 years ago
parent 9fa87e11d6
commit 4dce5e1a29
  1. 17
      src/main/java/com/msdw/tms/common/utils/Constant.java
  2. 6
      src/main/java/com/msdw/tms/controller/QuestionsController.java
  3. 4
      src/main/java/com/msdw/tms/entity/QuestionsEntity.java
  4. 5
      src/main/java/com/msdw/tms/entity/request/QuestionsUpdateRequest.java
  5. 1
      src/main/java/com/msdw/tms/entity/response/CommonCode.java
  6. 48
      src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java
  7. BIN
      src/main/resources/excel-template/试题导出模板.xlsx
  8. 1
      src/main/resources/mapper/tms/QuestionsDao.xml
  9. 81
      src/main/resources/sql/data.sql
  10. 9
      src/test/java/com/msdw/tms/TmsApplicationTests.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, "删除"),
/**
* 不删除
*/

@ -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<String> list = questionsService.importQuestion(file);
//return b ? R.ok() : R.error();
return null;
return R.ok().put("data", list);
}
/**

@ -86,8 +86,4 @@ public class QuestionsEntity implements Serializable {
* 修改时间用于排序创建时修改时间等于创建时间
*/
private Date modifyTime;
/**
* 试题科目
*/
private String subjects;
}

@ -67,9 +67,4 @@ public class QuestionsUpdateRequest {
*/
@ApiModelProperty(value = "答案解析", name = "answerAnalysis", example = "鲸鱼是最大的哺乳动物")
private String answerAnalysis;
/**
* 试题科目
*/
@ApiModelProperty(value = "试题科目", name = "subjects", example = "基础通识")
private String subjects;
}

@ -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, "抱歉,系统繁忙,请稍后重试!");
//操作是否成功

@ -323,9 +323,15 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
@Override
@Transactional
public List<String> 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<QuestionsImportRequest> 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<QuestionsDao, QuestionsEnt
@Override
@Transactional
public FilesResult uploadFiles(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);
}
FilesResult filesResult = ossService.uploadFiles(file);
XlsxTemplateEntity xlsxTemplateEntity = new XlsxTemplateEntity();
@ -410,34 +423,7 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
BeanUtils.copyProperties(evaluationRules, evaluation);
// //时长转成秒来计算
// //先查询该用户有没有开始考试,既redis中有没有跟该用户id相关联的key
// //如果没有,表示是开始测评,向redis中插入一条数据,key是前缀加用户id,value是当前时间,过期时间是测评时长加三十秒
// //如果有,则得到value,既开始测评的时间,用当前时间和开始测评时间做差,测评时长减去该差值
// //TODO 提交测评时删除redis中的该条数据
// //得到总时长,单位:分
// Integer duration = evaluation.getDuration();
// ValueOperations<String, String> 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<QuestionsVO> set = new HashSet<>();
@ -501,11 +487,11 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
}).collect(Collectors.toList());
//2.加载模板流数据
org.springframework.core.io.Resource resource = new ClassPathResource("excel-template/试题导模板.xlsx");
org.springframework.core.io.Resource resource = new ClassPathResource("excel-template/试题导模板.xlsx");
FileInputStream fis = new FileInputStream(resource.getFile());
//3、通过工具类下载文件
new ExcelExportUtil(QuestionsImportRequest.class, Constant.STARTING_ROW, Constant.STARTING_CELL).
new ExcelExportUtil(QuestionsImportRequest.class, Constant.ROW_INDEX, Constant.STYLE_INDEX).
export(response, fis, list, "试题表.xlsx");
}

@ -22,6 +22,5 @@
<result property="createTime" column="create_time"/>
<result property="modifyUser" column="modify_user"/>
<result property="modifyTime" column="modify_time"/>
<result property="subjects" column="subjects"/>
</resultMap>
</mapper>

@ -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);

@ -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(".")));
}
}

Loading…
Cancel
Save