Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/test/java/com/msdw/tms/TmsApplicationTests.java
hehai
pd 4 years ago
commit 2c93c58370
  1. 10
      pom.xml
  2. 2
      src/main/java/com/msdw/tms/api/QuestionsControllerApi.java
  3. 46
      src/main/java/com/msdw/tms/common/utils/poi/ExcelExportUtil.java
  4. 5
      src/main/java/com/msdw/tms/common/utils/poi/ExcelImportUtil.java
  5. 15
      src/main/java/com/msdw/tms/controller/QuestionsController.java
  6. 3
      src/main/java/com/msdw/tms/dao/QuestionsDao.java
  7. 9
      src/main/java/com/msdw/tms/entity/QuestionsEntity.java
  8. 13
      src/main/java/com/msdw/tms/entity/request/QuestionsAddRequest.java
  9. 6
      src/main/java/com/msdw/tms/entity/request/QuestionsImportRequest.java
  10. 6
      src/main/java/com/msdw/tms/entity/request/QuestionsQueryRequest.java
  11. 6
      src/main/java/com/msdw/tms/entity/request/QuestionsUpdateRequest.java
  12. 6
      src/main/java/com/msdw/tms/entity/response/CommonCode.java
  13. 4
      src/main/java/com/msdw/tms/entity/vo/EvaluationVO.java
  14. 35
      src/main/java/com/msdw/tms/entity/vo/QuestionsDetailVO.java
  15. 46
      src/main/java/com/msdw/tms/entity/vo/QuestionsListVO.java
  16. 43
      src/main/java/com/msdw/tms/entity/vo/QuestionsVO.java
  17. 6
      src/main/java/com/msdw/tms/service/QuestionsService.java
  18. 348
      src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java
  19. 5
      src/main/resources/application.yml
  20. 5
      src/main/resources/mapper/tms/QuestionsDao.xml
  21. 92
      src/test/java/com/msdw/tms/TmsApplicationTests.java
  22. 8
      src/test/java/com/msdw/tms/service/QuestionsServiceTest.java

@ -118,6 +118,16 @@
<version>1.4</version> <version>1.4</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!--JSR303校验-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<!-- springboot整合redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>

@ -81,7 +81,7 @@ public interface QuestionsControllerApi {
* 抽题测评 * 抽题测评
*/ */
@ApiOperation(value = "抽题测评", notes = "抽题测评") @ApiOperation(value = "抽题测评", notes = "抽题测评")
R evaluation (); R evaluation (Integer userId);
/** /**
* 通过excel批量导出 * 通过excel批量导出

@ -74,52 +74,6 @@ public class ExcelExportUtil<T> {
workbook.write(response.getOutputStream()); workbook.write(response.getOutputStream());
} }
/**
* 基于注解导出
* 参数
* response
* objs数据
* fileName生成的文件名
*/
// public void export(HttpServletResponse response, List<T> objs, String fileName) throws Exception {
//
// //1.根据模板创建工作簿
// Workbook workbook = new XSSFWorkbook(); //2007版本
//
// fileName = URLEncoder.encode(fileName, "UTF-8");
//
// Sheet sheet = workbook.createSheet(fileName);
//
// //3.提取公共的样式
// // CellStyle[] styles = getTemplateStyles(sheet.getRow(styleIndex));
// //4.根据数据创建每一行和每一个单元格的数据2
// AtomicInteger datasAi = new AtomicInteger(rowIndex); //数字
// for (T t : objs) {
// //datasAi.getAndIncrement() :获取数字,并++ i++
// Row row = sheet.createRow(datasAi.getAndIncrement());
// for (int i = 0; i < styles.length; i++) {
// Cell cell = row.createCell(i);
// cell.setCellStyle(styles[i]);
// for (Field field : fields) {
// if (field.isAnnotationPresent(ExcelAttribute.class)) {
// field.setAccessible(true);
// ExcelAttribute ea = field.getAnnotation(ExcelAttribute.class);
// if (i == ea.sort()) {
// if (field.get(t) != null) {
// cell.setCellValue(field.get(t).toString());
// }
// }
// }
// }
// }
// }
//
// response.setContentType("application/octet-stream");
// response.setHeader("content-disposition", "attachment;filename=" + new String(fileName.getBytes("ISO8859-1")));
// response.setHeader("filename", fileName);
// workbook.write(response.getOutputStream());
// }
CellStyle[] getTemplateStyles(Row row) { CellStyle[] getTemplateStyles(Row row) {
CellStyle[] styles = new CellStyle[row.getLastCellNum()]; CellStyle[] styles = new CellStyle[row.getLastCellNum()];
for (int i = 0; i < row.getLastCellNum(); i++) { for (int i = 0; i < row.getLastCellNum(); i++) {

@ -29,7 +29,7 @@ public class ExcelImportUtil<T> {
* 基于注解读取excel * 基于注解读取excel
*/ */
public List<T> readExcel(InputStream is, int rowIndex, int cellIndex) { public List<T> readExcel(InputStream is, int rowIndex, int cellIndex) {
List<T> list = new ArrayList<T>(); List<T> list = new ArrayList<>();
T entity = null; T entity = null;
try { try {
XSSFWorkbook workbook = new XSSFWorkbook(is); XSSFWorkbook workbook = new XSSFWorkbook(is);
@ -53,6 +53,9 @@ public class ExcelImportUtil<T> {
} }
} }
} }
Field field = entity.getClass().getDeclaredField("index");
field.setAccessible(true);
field.set(entity, rowNum);
list.add(entity); list.add(entity);
} }
} catch (Exception e) { } catch (Exception e) {

@ -88,10 +88,10 @@ public class QuestionsController implements QuestionsControllerApi {
* 是否禁用试题 * 是否禁用试题
*/ */
@Override @Override
@PutMapping("/isnable") @PutMapping("/isenable")
//@RequiresPermissions("qms:questions:isnable") //@RequiresPermissions("qms:questions:isenable")
public R isNable(Integer id) { public R isNable(Integer id) {
boolean b = questionsService.isnable(id); boolean b = questionsService.isEnable(id);
return b ? R.ok() : R.error(); return b ? R.ok() : R.error();
} }
@ -115,9 +115,10 @@ public class QuestionsController implements QuestionsControllerApi {
@PostMapping("/import") @PostMapping("/import")
//@RequiresPermissions("qms:questions:import") //@RequiresPermissions("qms:questions:import")
public R importQuestion(@RequestParam(name = "file") MultipartFile file) throws IOException { public R importQuestion(@RequestParam(name = "file") MultipartFile file) throws IOException {
boolean b = questionsService.importQuestion(file); //TODO boolean b = questionsService.importQuestion(file);
return b ? R.ok() : R.error(); //return b ? R.ok() : R.error();
return null;
} }
/** /**
@ -144,8 +145,8 @@ public class QuestionsController implements QuestionsControllerApi {
@Override @Override
@GetMapping("/evaluation") @GetMapping("/evaluation")
public R evaluation() { public R evaluation(Integer userId) {
EvaluationVO evaluation = questionsService.evaluation(); EvaluationVO evaluation = questionsService.evaluation(userId);
return R.ok().put("data", evaluation); return R.ok().put("data", evaluation);
} }

@ -1,7 +1,7 @@
package com.msdw.tms.dao; package com.msdw.tms.dao;
import com.msdw.tms.entity.QuestionsEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.msdw.tms.entity.QuestionsEntity;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
/** /**
@ -13,5 +13,4 @@ import org.apache.ibatis.annotations.Mapper;
*/ */
@Mapper @Mapper
public interface QuestionsDao extends BaseMapper<QuestionsEntity> { public interface QuestionsDao extends BaseMapper<QuestionsEntity> {
} }

@ -23,13 +23,9 @@ public class QuestionsEntity implements Serializable {
@TableId @TableId
private Integer id; private Integer id;
/** /**
* 题型1单选题2多选题3判断题 * 题型1单选题2多选题3判断题
*/ */
private Integer questionTypeNo; private Integer questionType;
/**
* 题型名称
*/
private String questionType;
/** /**
* 题干信息 * 题干信息
*/ */
@ -94,5 +90,4 @@ public class QuestionsEntity implements Serializable {
* 试题科目 * 试题科目
*/ */
private String subjects; private String subjects;
} }

@ -4,6 +4,8 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotNull;
/** /**
* 试题的基本信息表 * 试题的基本信息表
* *
@ -13,10 +15,10 @@ import lombok.Data;
@ApiModel(value = "QuestionsAddRequest", description = "添加试题请求体对象") @ApiModel(value = "QuestionsAddRequest", description = "添加试题请求体对象")
public class QuestionsAddRequest { public class QuestionsAddRequest {
/** /**
* 题型名称 * 题型1单选题2多选题3判断题
*/ */
@ApiModelProperty(value = "题型名称", name = "questionType", example = "单选题", required = true) @ApiModelProperty(value = "题型:1、单选题,2、多选题,3、判断题", name = "questionType", example = "1", required = true)
private String questionType; private Integer questionType;
/** /**
* 题干信息 * 题干信息
*/ */
@ -62,9 +64,4 @@ public class QuestionsAddRequest {
*/ */
@ApiModelProperty(value = "答案解析", name = "answerAnalysis", example = "鲸鱼是最大的哺乳动物") @ApiModelProperty(value = "答案解析", name = "answerAnalysis", example = "鲸鱼是最大的哺乳动物")
private String answerAnalysis; private String answerAnalysis;
/**
* 试题科目
*/
@ApiModelProperty(value = "试题科目", name = "subjects", example = "基础通识")
private String subjects;
} }

@ -10,6 +10,10 @@ import lombok.Data;
*/ */
@Data @Data
public class QuestionsImportRequest { public class QuestionsImportRequest {
/**
* 第几行
*/
private Integer index;
/** /**
* 题干问题描述 * 题干问题描述
@ -20,7 +24,7 @@ public class QuestionsImportRequest {
* 题型 * 题型
*/ */
@ExcelAttribute(sort = 1) @ExcelAttribute(sort = 1)
private String questionType; private String questionTypeName;
/** /**
* 选项A * 选项A
*/ */

@ -20,10 +20,10 @@ public class QuestionsQueryRequest {
private String questionStem; private String questionStem;
/** /**
* 题型id * 题型
*/ */
@ApiModelProperty(value = "题型:1、单选题,2、多选题,3、判断题", name = "questionTypeNo", example = "1") @ApiModelProperty(value = "题型:1、单选题,2、多选题,3、判断题", name = "questionType", example = "1")
private Integer questionTypeNo; private Integer questionType;
// /** // /**
// * 参考答案 // * 参考答案
// */ // */

@ -18,10 +18,10 @@ public class QuestionsUpdateRequest {
@ApiModelProperty(value = "主键", name = "id", example = "1", required = true) @ApiModelProperty(value = "主键", name = "id", example = "1", required = true)
private Integer id; private Integer id;
/** /**
* 题型名称 * 题型1单选题2多选题3判断题
*/ */
@ApiModelProperty(value = "题型名称", name = "questionType", example = "单选题", required = true) @ApiModelProperty(value = "题型:1、单选题,2、多选题,3、判断题", name = "questionType", example = "1", required = true)
private String questionType; private Integer questionType;
/** /**
* 题干信息 * 题干信息
*/ */

@ -10,8 +10,10 @@ public enum CommonCode implements ResultCode {
UNAUTHORISE(false, 10002, "权限不足,无权操作!"), UNAUTHORISE(false, 10002, "权限不足,无权操作!"),
INVALID_PARAM(false, 10003, "非法参数!"), INVALID_PARAM(false, 10003, "非法参数!"),
QUESTION_NUM_INVALID(false, 10004, "测评题目数量设置超出范围!"), QUESTION_NUM_INVALID(false, 10004, "测评题目数量设置超出范围!"),
QUESTION_EXISTS(false, 10005, "此题目已存在!"), QUESTION_EXISTS(false, 10005, "此题已存在!"),
QUESTIONTYPE_INVALID(false, 10005, "题型错误!"), QUESTIONTYPE_INVALID(false, 10006, "题型错误!"),
EXCEL_INVALID(false, 10007, "excel表内容错误!"),
EVALUATION_TIME_INVALID(false, 10008, "测评时间错误!"),
FAIL(false, 11111, "操作失败!"), FAIL(false, 11111, "操作失败!"),
SERVER_ERROR(false, 99999, "抱歉,系统繁忙,请稍后重试!"); SERVER_ERROR(false, 99999, "抱歉,系统繁忙,请稍后重试!");
//操作是否成功 //操作是否成功

@ -27,6 +27,10 @@ public class EvaluationVO implements Serializable {
* 测评时长单位分钟 * 测评时长单位分钟
*/ */
private Integer duration; private Integer duration;
/**
* 当前用户的剩余时长格式 HH:ss
*/
private String remainingDuration;
/** /**
* 测评总题数 * 测评总题数
*/ */

@ -17,13 +17,13 @@ public class QuestionsDetailVO implements Serializable {
*/ */
private Integer id; private Integer id;
/** /**
* 题型用于区分是什么题型1单选2多选3判断 * 题型用于区分是什么题型1单选2多选3判断
*/ */
private Integer questionTypeNo; private Integer questionType;
/** /**
* 题型名称 * 题型名称
*/ */
private String questionType; private String questionTypeName;
/** /**
* 题干信息 * 题干信息
*/ */
@ -84,33 +84,4 @@ public class QuestionsDetailVO implements Serializable {
* 答案解析 * 答案解析
*/ */
private String answerAnalysis; private String answerAnalysis;
/**
* 是否禁用1启用0禁用默认是1启用
*/
private Integer isEnable;
/**
* 是否删除0使用1删除默认0使用
*/
private Integer isDel;
/**
* 创建人
*/
private String createUser;
/**
* 创建时间
*/
private String createTime;
/**
* 修改人
*/
private String modifyUser;
/**
* 修改时间用于排序创建时修改时间等于创建时间
*/
private String modifyTime;
/**
* 试题科目
*/
private String subjects;
} }

@ -0,0 +1,46 @@
package com.msdw.tms.entity.vo;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
/**
* 试题列表展示信息
*
* @author gongsj
*/
@Data
@ToString
public class QuestionsListVO implements Serializable {
/**
* 主键
*/
private Integer id;
/**
* 题型1单选题2多选题3判断题
*/
private String questionTypeName;
/**
* 题干信息
*/
private String questionStem;
/**
* 正确答案
*/
private String answer;
/**
* 答案解析
*/
private String answerAnalysis;
/**
* 是否禁用1启用0禁用默认是1启用
*/
private Integer isEnable;
/**
* 修改时间用于排序创建时修改时间等于创建时间
*/
private String modifyTime;
}

@ -18,14 +18,10 @@ public class QuestionsVO implements Serializable {
* 主键 * 主键
*/ */
private Integer id; private Integer id;
/**
* 题型号用于区分是什么题型
*/
private Integer questionTypeNo;
/** /**
* 题型名称 * 题型名称
*/ */
private String questionType; private String questionTypeName;
/** /**
* 题干信息 * 题干信息
*/ */
@ -54,41 +50,4 @@ public class QuestionsVO implements Serializable {
* F选项内容 * F选项内容
*/ */
private String optionF; private String optionF;
/**
* 正确答案
*/
private String answer;
/**
* 答案解析
*/
private String answerAnalysis;
/**
* 是否禁用1启用0禁用默认是1启用
*/
private Integer isEnable;
/**
* 是否删除0使用1删除默认0使用
*/
private Integer isDel;
/**
* 创建人
*/
private String createUser;
/**
* 创建时间
*/
private String createTime;
/**
* 修改人
*/
private String modifyUser;
/**
* 修改时间用于排序创建时修改时间等于创建时间
*/
private String modifyTime;
/**
* 试题科目
*/
private String subjects;
} }

@ -34,17 +34,17 @@ public interface QuestionsService extends IService<QuestionsEntity> {
boolean updateQuestionById(QuestionsUpdateRequest questions); boolean updateQuestionById(QuestionsUpdateRequest questions);
boolean isnable(Integer id); boolean isEnable(Integer id);
boolean deleteByIds(List<Integer> asList); boolean deleteByIds(List<Integer> asList);
boolean importQuestion(MultipartFile file) throws IOException; List<String> importQuestion(MultipartFile file) throws IOException;
FilesResult uploadFiles(MultipartFile file) throws IOException; FilesResult uploadFiles(MultipartFile file) throws IOException;
void downloadFiles(HttpServletResponse response) throws IOException; void downloadFiles(HttpServletResponse response) throws IOException;
EvaluationVO evaluation(); EvaluationVO evaluation(Integer userId);
void exportQuestion(HttpServletResponse response) throws Exception; void exportQuestion(HttpServletResponse response) throws Exception;
} }

@ -18,10 +18,7 @@ import com.msdw.tms.entity.request.QuestionsImportRequest;
import com.msdw.tms.entity.request.QuestionsQueryRequest; import com.msdw.tms.entity.request.QuestionsQueryRequest;
import com.msdw.tms.entity.request.QuestionsUpdateRequest; import com.msdw.tms.entity.request.QuestionsUpdateRequest;
import com.msdw.tms.entity.response.CommonCode; import com.msdw.tms.entity.response.CommonCode;
import com.msdw.tms.entity.vo.EvaluationRulesVO; import com.msdw.tms.entity.vo.*;
import com.msdw.tms.entity.vo.EvaluationVO;
import com.msdw.tms.entity.vo.QuestionsDetailVO;
import com.msdw.tms.entity.vo.QuestionsVO;
import com.msdw.tms.service.AliyunOssService; import com.msdw.tms.service.AliyunOssService;
import com.msdw.tms.service.EvaluationRulesService; import com.msdw.tms.service.EvaluationRulesService;
import com.msdw.tms.service.QuestionsService; import com.msdw.tms.service.QuestionsService;
@ -29,6 +26,8 @@ import com.msdw.tms.service.XlsxTemplateService;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@ -42,6 +41,7 @@ import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service("questionsService") @Service("questionsService")
@ -56,6 +56,11 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
@Resource @Resource
EvaluationRulesService evaluationRulesService; EvaluationRulesService evaluationRulesService;
@Resource
StringRedisTemplate stringRedisTemplate;
private String REMAINING_TINE_KEY = "REMAINING_TINE";
/** /**
* 条件加分页查询题干模糊查询未删除修改时间降序 * 条件加分页查询题干模糊查询未删除修改时间降序
*/ */
@ -74,14 +79,10 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
queryWrapper.like("question_stem", request.getQuestionStem()); queryWrapper.like("question_stem", request.getQuestionStem());
} }
// 题型:判断题型是否为空,不为空则加入搜索条件 // 题型:判断题型是否为空,不为空则加入搜索条件
if (request.getQuestionTypeNo() != null) { if (request.getQuestionType() != null) {
queryWrapper.eq("question_type_no", request.getQuestionTypeNo()); queryWrapper.eq("question_type", request.getQuestionType());
} }
//TODO 扩展搜索条件 //扩展其他搜索条件...
// 修改时间:判断修改时间是否为空,不为空则加入搜索条件
// if (request.getModifyTime() != null) {
// queryWrapper.eq("modify_time", request.getModifyTime());
// }
} }
// 修改时间降序 // 修改时间降序
@ -91,24 +92,20 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
new Query<QuestionsEntity>().getPage(page, size), new Query<QuestionsEntity>().getPage(page, size),
queryWrapper queryWrapper
); );
List<QuestionsEntity> records = questionsIPage.getRecords(); List<QuestionsEntity> records = questionsIPage.getRecords();
List<QuestionsVO> questions = records.stream().map(question -> { List<QuestionsListVO> questions = records.stream().map(question -> {
QuestionsVO questionsVO = new QuestionsVO(); QuestionsListVO questionsListVO = new QuestionsListVO();
BeanUtils.copyProperties(question, questionsVO); BeanUtils.copyProperties(question, questionsListVO);
//处理试题类型
String questionTypeName = getQuestionTypeName(question.getQuestionType());
questionsListVO.setQuestionTypeName(questionTypeName);
//处理时间格式 //处理时间格式
questionsVO.setCreateTime(handleTime(question.getCreateTime())); questionsListVO.setModifyTime(handleTime(question.getModifyTime()));
questionsVO.setModifyTime(handleTime(question.getModifyTime())); return questionsListVO;
return questionsVO;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
PageUtils questionsPage = new PageUtils(questionsIPage); PageUtils questionsPage = new PageUtils(questionsIPage);
questionsPage.setList(questions); questionsPage.setList(questions);
return questionsPage; return questionsPage;
} }
@ -127,11 +124,9 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
//查询试题信息 //查询试题信息
QuestionsEntity questionsEntity = this.getById(id); QuestionsEntity questionsEntity = this.getById(id);
BeanUtils.copyProperties(questionsEntity, questionsDetailVO); BeanUtils.copyProperties(questionsEntity, questionsDetailVO);
//处理试题类型
//处理时间 String questionTypeName = getQuestionTypeName(questionsEntity.getQuestionType());
//处理时间格式 questionsDetailVO.setQuestionTypeName(questionTypeName);
questionsDetailVO.setCreateTime(handleTime(questionsEntity.getCreateTime()));
questionsDetailVO.setModifyTime(handleTime(questionsEntity.getModifyTime()));
//处理每个选项是否为被设置为答案 //处理每个选项是否为被设置为答案
String answer = questionsEntity.getAnswer(); String answer = questionsEntity.getAnswer();
@ -158,29 +153,56 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
} }
} }
private String getQuestionTypeName(Integer questionType) {
String questionTypeName = "";
//处理试题类型
if (questionType.equals(Constant.QuestionType.SINGLE_CHOICE.getType())) {
//单选题
questionTypeName = Constant.QuestionType.SINGLE_CHOICE.getDesc();
} else if (questionType.equals(Constant.QuestionType.MULTIPLE_CHOICE.getType())) {
//多选题
questionTypeName = Constant.QuestionType.MULTIPLE_CHOICE.getDesc();
} else if (questionType.equals(Constant.QuestionType.TRUE_OR_FALSE.getType())) {
//判断题
questionTypeName = Constant.QuestionType.TRUE_OR_FALSE.getDesc();
} else {
ExceptionCast.cast(CommonCode.QUESTIONTYPE_INVALID);
}
return questionTypeName;
}
/** /**
* 保存试题根据题型名称得到题型号设置创建时间和修改时间 * 保存试题
* 1检验题型是否正确
* 2检验题干和选项是否有重复
* 3设置创建时间和修改时间
*/ */
@Override @Override
@Transactional @Transactional
public boolean saveQuestion(QuestionsAddRequest questions) { public boolean saveQuestion(QuestionsAddRequest questions) {
if (questions == null || StringUtils.isEmpty(questions.getQuestionStem())) { //试题对象为空或题干内容为空,抛出参数不合法异常
if (questions == null
|| StringUtils.isEmpty(questions.getQuestionStem())
|| questions.getQuestionType() == null) {
ExceptionCast.cast(CommonCode.INVALID_PARAM); ExceptionCast.cast(CommonCode.INVALID_PARAM);
} }
// 判断是否题干重复, //校验题型是否正确
QueryWrapper<QuestionsEntity> queryWrapper = new QueryWrapper<>(); checkType(questions.getQuestionType());
queryWrapper.eq("is_del", Constant.IsDel.NOT_DEL.getType())
.eq("question_stem", questions.getQuestionStem()); // 校验重复,不仅要校验题干,还要校验选项
QuestionsEntity questionsEntity = new QuestionsEntity();
BeanUtils.copyProperties(questions, questionsEntity);
//构造根据内容查询试题数量的Wrapper
QueryWrapper<QuestionsEntity> queryWrapper = constructDistinctWrapper(questionsEntity);
int count = this.count(queryWrapper); int count = this.count(queryWrapper);
if (count > 0) {//说明已存在 if (count > 0) {//说明已存在
//抛出题目已存在异常 //抛出题目已存在异常
ExceptionCast.cast(CommonCode.QUESTION_EXISTS); ExceptionCast.cast(CommonCode.QUESTION_EXISTS);
} }
// 将传入的对象内容拷贝到QuestionsEntity并返回 // 将传入的对象内容拷贝到QuestionsEntity并返回
QuestionsEntity questionsEntity = getQuestionsEntity(questions);
questionsEntity.setCreateTime(new Date()); questionsEntity.setCreateTime(new Date());
questionsEntity.setModifyTime(new Date()); questionsEntity.setModifyTime(new Date());
//TODO 创建者和修改者。。。 //TODO 创建者和修改者。。。
@ -191,28 +213,33 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
@Override @Override
@Transactional @Transactional
public boolean updateQuestionById(QuestionsUpdateRequest questions) { public boolean updateQuestionById(QuestionsUpdateRequest questions) {
if (questions == null || questions.getId() == null || StringUtils.isEmpty(questions.getQuestionStem())) { if (questions == null
|| questions.getId() == null
|| StringUtils.isEmpty(questions.getQuestionStem())) {
ExceptionCast.cast(CommonCode.INVALID_PARAM); ExceptionCast.cast(CommonCode.INVALID_PARAM);
} }
// 判断是否题干重复,除了自己之外还有没有重复的题干,因为自己的题干可以不做修改
QueryWrapper<QuestionsEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("id", questions.getId())
.eq("question_stem", questions.getQuestionStem())
.eq("is_del", Constant.IsDel.NOT_DEL.getType());
int count = this.count(queryWrapper);
if (count > 0) {//说明除了本题之外题干已存在
//抛出题目已存在异常
ExceptionCast.cast(CommonCode.QUESTION_EXISTS);
}
// 判断id是否存在 // 判断id是否存在
if (this.getById(questions.getId()) == null) { if (this.getById(questions.getId()) == null) {
ExceptionCast.cast(CommonCode.INVALID_PARAM); ExceptionCast.cast(CommonCode.INVALID_PARAM);
} }
// 将传入的对象内容拷贝到QuestionsEntity并返回 //校验题型是否正确
QuestionsEntity questionsEntity = getQuestionsEntity(questions); checkType(questions.getQuestionType());
//校验题干和内容重复
QuestionsEntity questionsEntity = new QuestionsEntity();
BeanUtils.copyProperties(questions, questionsEntity);
//构造根据内容查询试题数量的Wrapper
QueryWrapper<QuestionsEntity> queryWrapper = constructDistinctWrapper(questionsEntity);
queryWrapper.notIn("id", questions.getId());
int count = this.count(queryWrapper);
if (count > 0) {//说明除了本题之外题干已存在
//抛出题目已存在异常
ExceptionCast.cast(CommonCode.QUESTION_EXISTS);
}
questionsEntity.setModifyTime(new Date()); questionsEntity.setModifyTime(new Date());
//TODO 设置修改者。。。 //TODO 设置修改者。。。
@ -220,42 +247,55 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
return this.updateById(questionsEntity); return this.updateById(questionsEntity);
} }
// 将传入的对象内容拷贝到QuestionsEntity并返回 private void checkType(int type) {
private <T> QuestionsEntity getQuestionsEntity(T questions) { boolean include = false;
QuestionsEntity questionsEntity = new QuestionsEntity(); for (Constant.QuestionType value : Constant.QuestionType.values()) {
if (value.getType().equals(type)) {
BeanUtils.copyProperties(questions, questionsEntity); include = true;
}
String questionType = questionsEntity.getQuestionType(); }
//根据题型名称得到题型号 if (!include) {//题型不在枚举类中,不正确
if (questionType.equals(Constant.QuestionType.SINGLE_CHOICE.getDesc())) {
//单选题
questionsEntity.setQuestionTypeNo(Constant.QuestionType.SINGLE_CHOICE.getType());
} else if (questionType.equals(Constant.QuestionType.MULTIPLE_CHOICE.getDesc())) {
//多选题
questionsEntity.setQuestionTypeNo(Constant.QuestionType.MULTIPLE_CHOICE.getType());
} else if (questionType.equals(Constant.QuestionType.TRUE_OR_FALSE.getDesc())) {
//判断题
questionsEntity.setQuestionTypeNo(Constant.QuestionType.TRUE_OR_FALSE.getType());
} else {// 判断题型是否不存在
//说明题型不正确
ExceptionCast.cast(CommonCode.QUESTIONTYPE_INVALID); ExceptionCast.cast(CommonCode.QUESTIONTYPE_INVALID);
} }
return questionsEntity; }
private QueryWrapper<QuestionsEntity> constructDistinctWrapper(QuestionsEntity questions) {
QueryWrapper<QuestionsEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("is_del", Constant.IsDel.NOT_DEL.getType())
.eq("question_stem", questions.getQuestionStem());
if (StringUtils.isNotEmpty(questions.getOptionA())) {
queryWrapper.eq("option_a", questions.getOptionA());
}
if (StringUtils.isNotEmpty(questions.getOptionB())) {
queryWrapper.eq("option_b", questions.getOptionB());
}
if (StringUtils.isNotEmpty(questions.getOptionC())) {
queryWrapper.eq("option_c", questions.getOptionC());
}
if (StringUtils.isNotEmpty(questions.getOptionD())) {
queryWrapper.eq("option_d", questions.getOptionD());
}
if (StringUtils.isNotEmpty(questions.getOptionE())) {
queryWrapper.eq("option_e", questions.getOptionE());
}
if (StringUtils.isNotEmpty(questions.getOptionF())) {
queryWrapper.eq("option_f", questions.getOptionF());
}
return queryWrapper;
} }
@Override @Override
@Transactional @Transactional
public boolean isnable(Integer id) { public boolean isEnable(Integer id) {
QuestionsEntity questionsEntity = new QuestionsEntity(); QuestionsEntity questionsEntity = new QuestionsEntity();
questionsEntity.setId(id); questionsEntity.setId(id);
QuestionsEntity byId = this.getById(id); QuestionsEntity byId = this.getById(id);
if (byId.getIsEnable().equals(Constant.IsEnable.ENABLE.getType())) { if (byId.getIsEnable().equals(Constant.IsEnable.ENABLE.getType())) {
questionsEntity.setIsEnable(Constant.IsEnable.NOT_ENABLE.getType()); questionsEntity.setIsEnable(Constant.IsEnable.NOT_ENABLE.getType());
} } else if (byId.getIsEnable().equals(Constant.IsEnable.NOT_ENABLE.getType())) {
if (byId.getIsEnable().equals(Constant.IsEnable.NOT_ENABLE.getType())) {
questionsEntity.setIsEnable(Constant.IsEnable.ENABLE.getType()); questionsEntity.setIsEnable(Constant.IsEnable.ENABLE.getType());
} else {
ExceptionCast.cast(CommonCode.INVALID_PARAM);
} }
return this.updateById(questionsEntity); return this.updateById(questionsEntity);
@ -275,53 +315,62 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
} }
/** /**
* 校验题干重复和题型不对的从列表中将该题剔除名称相同的要去重 * 1校验题干重复和题型不对的
* 2从列表中将该题剔除并记录index和导入失败的原因
* 3名称和选项内容都相同的要去重
*/ */
@Override @Override
@Transactional @Transactional
public boolean importQuestion(MultipartFile file) throws IOException { public List<String> importQuestion(MultipartFile file) throws IOException {
// 使用excel导入工具类获取试题数据列表 // 使用excel导入工具类获取试题数据列表
List<QuestionsImportRequest> list = new ExcelImportUtil(QuestionsImportRequest.class) List<QuestionsImportRequest> list = new ExcelImportUtil(QuestionsImportRequest.class)
.readExcel(file.getInputStream(), Constant.STARTING_ROW, Constant.STARTING_CELL); .readExcel(file.getInputStream(), Constant.STARTING_ROW, Constant.STARTING_CELL);
if (list == null || list.size() == 0) { if (list == null || list.size() == 0) {
ExceptionCast.cast(CommonCode.INVALID_PARAM); ExceptionCast.cast(CommonCode.EXCEL_INVALID);
} }
List<QuestionsEntity> collect = list.stream().map(item -> { List<String> failureRecord = new ArrayList<>();
int count = this.count(new QueryWrapper<QuestionsEntity>().eq("question_stem", item.getQuestionStem()));
if (count > 0) {//说明已存在 for (int i = 0; i < list.size(); i++) {
return null; QuestionsImportRequest question = list.get(i);
} //校验题干和内容重复
QuestionsEntity questionsEntity = new QuestionsEntity(); QuestionsEntity questionsEntity = new QuestionsEntity();
BeanUtils.copyProperties(item, questionsEntity); BeanUtils.copyProperties(question, questionsEntity);
String questionType = item.getQuestionType(); String questionTypeName = question.getQuestionTypeName();
//根据题型名称得到题型号 //根据题型名称得到题型号
if (questionType.equals(Constant.QuestionType.SINGLE_CHOICE.getDesc())) { if (questionTypeName.equals(Constant.QuestionType.SINGLE_CHOICE.getDesc())) {
//单选题 //单选题
questionsEntity.setQuestionTypeNo(Constant.QuestionType.SINGLE_CHOICE.getType()); questionsEntity.setQuestionType(Constant.QuestionType.SINGLE_CHOICE.getType());
} else if (questionType.equals(Constant.QuestionType.MULTIPLE_CHOICE.getDesc())) { } else if (questionTypeName.equals(Constant.QuestionType.MULTIPLE_CHOICE.getDesc())) {
//多选题 //多选题
questionsEntity.setQuestionTypeNo(Constant.QuestionType.MULTIPLE_CHOICE.getType()); questionsEntity.setQuestionType(Constant.QuestionType.MULTIPLE_CHOICE.getType());
} else if (questionType.equals(Constant.QuestionType.TRUE_OR_FALSE.getDesc())) { } else if (questionTypeName.equals(Constant.QuestionType.TRUE_OR_FALSE.getDesc())) {
//判断题 //判断题
questionsEntity.setQuestionTypeNo(Constant.QuestionType.TRUE_OR_FALSE.getType()); questionsEntity.setQuestionType(Constant.QuestionType.TRUE_OR_FALSE.getType());
} else { } else {
// 题型不正确 // 题型不正确
return null; failureRecord.add("第 " + question.getIndex() + " 行导入失败," + "题干:" + question.getQuestionStem() + ",失败信息:" + CommonCode.QUESTIONTYPE_INVALID.message());
continue;
} }
//构造根据内容查询试题数量的Wrapper
QueryWrapper<QuestionsEntity> queryWrapper = constructDistinctWrapper(questionsEntity);
int count = this.count(queryWrapper);
if (count > 0) {//说明已存在
failureRecord.add("第 " + question.getIndex() + " 行导入失败," + "题干:" + question.getQuestionStem() + ",失败信息:" + CommonCode.QUESTION_EXISTS.message());
continue;
}
questionsEntity.setCreateTime(new Date()); questionsEntity.setCreateTime(new Date());
questionsEntity.setModifyTime(new Date()); questionsEntity.setModifyTime(new Date());
//TODO 创建者和修改者。。。
return questionsEntity; this.save(questionsEntity);
}).filter(Objects::nonNull)// 过滤掉为null的对象 }
.collect(Collectors.collectingAndThen(// 去重收集
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(QuestionsEntity::getQuestionStem))), return failureRecord;
ArrayList::new
));
// 批量新增
return this.saveBatch(collect);
} }
/** /**
@ -347,14 +396,12 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
} }
@Override @Override
public EvaluationVO evaluation() { public EvaluationVO evaluation(Integer userId) {
QueryWrapper<QuestionsEntity> queryWrapper = new QueryWrapper<>(); QueryWrapper<QuestionsEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("is_del", Constant.IsDel.NOT_DEL.getType()) //未删除 queryWrapper.eq("is_del", Constant.IsDel.NOT_DEL.getType()) //未删除
.eq("is_enable", Constant.IsEnable.ENABLE.getType()); //启用 .eq("is_enable", Constant.IsEnable.ENABLE.getType()); //启用
Set<QuestionsEntity> set = new HashSet<>();
// 查询测评规则类型 // 查询测评规则类型
EvaluationRulesVO evaluationRules = evaluationRulesService.getEvaluationRules(); EvaluationRulesVO evaluationRules = evaluationRulesService.getEvaluationRules();
@ -362,17 +409,46 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
BeanUtils.copyProperties(evaluationRules, evaluation); BeanUtils.copyProperties(evaluationRules, evaluation);
//TODO 处理时长,获取当前登录用户id,将用户剩余的时长实时计算,存在Redis中
//时长转成秒来计算
//先查询该用户有没有开始考试,既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;
if (StringUtils.isEmpty(startTime)) {
//如果没有,表示是开始测评,向redis中插入一条数据,key是前缀加用户id,value是当前时间,过期时间是测评时长加十秒
ops.set(key, getSecondTimestamp(new Date()) + "", duration * 60 + 10, TimeUnit.SECONDS);
} else {
int difference = getSecondTimestamp(new Date()) - Integer.valueOf(startTime);
remainingTime = duration - difference;
if (remainingTime < 0) {
ExceptionCast.cast(CommonCode.EVALUATION_TIME_INVALID);
}
}
evaluation.setRemainingDuration(formatDateTime(remainingTime));
//搜集随机抽取的试题
Set<QuestionsVO> set = new HashSet<>();
//根据测评规则的类型不同
Integer evaluationType = evaluationRules.getEvaluationType(); Integer evaluationType = evaluationRules.getEvaluationType();
if (evaluationType.equals(Constant.RulesType.RANDOM.getType())) {//随机 if (evaluationType.equals(Constant.RulesType.RANDOM.getType())) {//随机
// 类型为随机,直接用题目数量 // 类型为随机,直接用题目数量
Integer questionNum = evaluationRules.getQuestionNum(); Integer questionNum = evaluationRules.getQuestionNum();
// 查询题库所有未删除,未禁用的题目id // 查询题库所有未删除,未禁用的题目id
List<QuestionsEntity> questions = this.list(queryWrapper); List<QuestionsEntity> questions = this.list(queryWrapper);
set = getRandomList(questionNum, questions); set = getRandomList(questionNum, questions);
} else if (evaluationType.equals(Constant.RulesType.CUSTOMIZE.getType())) {//自定义 } else if (evaluationType.equals(Constant.RulesType.CUSTOMIZE.getType())) {//自定义
// 单选题数量 // 单选题数量
int singleNum = 0; int singleNum = 0;
// 多选题数量 // 多选题数量
@ -405,22 +481,51 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
// 总题数等于各类题目数量之和 // 总题数等于各类题目数量之和
evaluation.setQuestionNum(singleNum + multipleNum + judgmentNum); evaluation.setQuestionNum(singleNum + multipleNum + judgmentNum);
} }
Set<QuestionsVO> collect = set.stream().map(item -> { // Set<QuestionsVO> collect = set.stream().map(item -> {
QuestionsVO questionsVO = new QuestionsVO(); // QuestionsVO questionsVO = new QuestionsVO();
BeanUtils.copyProperties(item, questionsVO); // BeanUtils.copyProperties(item, questionsVO);
questionsVO.setCreateTime(handleTime(item.getCreateTime())); // return questionsVO;
questionsVO.setModifyTime(handleTime(item.getModifyTime())); // }).collect(Collectors.toSet());
return questionsVO; evaluation.setQuestions(set);
}).collect(Collectors.toSet());
evaluation.setQuestions(collect);
return evaluation; return evaluation;
} }
private int getSecondTimestamp(Date date) {
if (null == date) {
return 0;
}
String timestamp = String.valueOf(date.getTime() / 1000 / 60);
return Integer.valueOf(timestamp);
}
private String formatDateTime(long mss) {
String DateTimes;
long hours = (mss % (60 * 24)) / (60);
long minutes = (mss % (60));
//long seconds = mss % 60;
if (hours > 0) {
if (hours < 10) {
DateTimes = "0" + hours + ":" + minutes;
} else {
DateTimes = hours + ":" + minutes;
}
} else {
DateTimes = "00:" + minutes;
}
return DateTimes;
}
@Override @Override
public void exportQuestion(HttpServletResponse response) throws Exception { public void exportQuestion(HttpServletResponse response) throws Exception {
// 请求包装类
QueryWrapper<QuestionsEntity> queryWrapper = new QueryWrapper<>();
// 只查询未被删除且启用的试题
queryWrapper.eq("is_del", Constant.IsDel.NOT_DEL.getType())
.eq("is_enable", Constant.IsEnable.ENABLE.getType()); //启用
//1.构造数据 //1.构造数据
List<QuestionsImportRequest> list = this.list().stream().map(item -> { List<QuestionsImportRequest> list = this.list(queryWrapper).stream().map(item -> {
QuestionsImportRequest importRequest = new QuestionsImportRequest(); QuestionsImportRequest importRequest = new QuestionsImportRequest();
BeanUtils.copyProperties(item, importRequest); BeanUtils.copyProperties(item, importRequest);
return importRequest; return importRequest;
@ -436,13 +541,16 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
} }
private Set<QuestionsEntity> getRandomList(int len, List<QuestionsEntity> list) { private Set<QuestionsVO> getRandomList(int len, List<QuestionsEntity> list) {
Set<QuestionsEntity> set = new HashSet<>(); Set<QuestionsVO> set = new HashSet<>();
Random random = new Random(); Random random = new Random();
int i; int i;
while (true) { while (true) {
i = random.nextInt(list.size()); i = random.nextInt(list.size());
set.add(list.get(i)); QuestionsVO questionsVO = new QuestionsVO();
BeanUtils.copyProperties(list.get(i), questionsVO);
questionsVO.setQuestionTypeName(getQuestionTypeName(list.get(i).getQuestionType()));
set.add(questionsVO);
if (set.size() >= len) { if (set.size() >= len) {
break; break;
} }

@ -4,6 +4,10 @@ spring:
username: super username: super
password: huoran888 password: huoran888
driver-class-name: com.mysql.jdbc.Driver driver-class-name: com.mysql.jdbc.Driver
redis:
host: www.liuwanr.cn
port: 6379
password: huoran
mybatis-plus: mybatis-plus:
configuration: configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用 log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用
@ -13,3 +17,4 @@ mybatis-plus:
id-type: auto id-type: auto
server: server:
port: 7000 port: 7000

@ -3,10 +3,9 @@
<mapper namespace="com.msdw.tms.dao.QuestionsDao"> <mapper namespace="com.msdw.tms.dao.QuestionsDao">
<!-- 可根据自己的需求,是否要使用 --> <!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.msdw.tms.entity.QuestionsEntity" id="questionsMap"> <resultMap type="com.msdw.tms.entity.QuestionsEntity" id="questionsMap">
<result property="id" column="id"/> <result property="id" column="id"/>
<result property="questionTypeNo" column="question_type_no"/>
<result property="questionType" column="question_type"/> <result property="questionType" column="question_type"/>
<result property="questionStem" column="question_stem"/> <result property="questionStem" column="question_stem"/>
<result property="optionA" column="option_a"/> <result property="optionA" column="option_a"/>
@ -25,6 +24,4 @@
<result property="modifyTime" column="modify_time"/> <result property="modifyTime" column="modify_time"/>
<result property="subjects" column="subjects"/> <result property="subjects" column="subjects"/>
</resultMap> </resultMap>
</mapper> </mapper>

@ -1,10 +1,21 @@
package com.msdw.tms; package com.msdw.tms;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.concurrent.TimeUnit;
@SpringBootTest @SpringBootTest
class TmsApplicationTests { class TmsApplicationTests {
@ -82,7 +93,84 @@ class TmsApplicationTests {
return instance; return instance;
} }
public <T> T TestG(T t){ public <T, K> K t2(T t, K k) {
return t; k = (K) "haha";
return k;
} }
private String formatDateTime(long mss) {
String DateTimes = null;
long days = mss / (60 * 60 * 24);
long hours = (mss % (60 * 60 * 24)) / (60 * 60);
long minutes = (mss % (60 * 60)) / 60;
long seconds = mss % 60;
if (days > 0) {
DateTimes = days + "天" + hours + "小时" + minutes + "分钟"
+ seconds + "秒";
} else if (hours > 0) {
DateTimes = hours + "小时" + minutes + "分钟"
+ seconds + "秒";
} else if (minutes > 0) {
DateTimes = minutes + "分钟"
+ seconds + "秒";
} else {
DateTimes = seconds + "秒";
}
return DateTimes;
}
private String formatDateTime2(long mss) {
String DateTimes;
long hours = (mss % (60 * 24)) / (60);
long minutes = (mss % (60));
//long seconds = mss % 60;
if (hours > 0) {
if (hours < 10) {
DateTimes = "0" + hours + ":" + minutes;
} else {
DateTimes = hours + ":" + minutes;
}
} else {
DateTimes = "00:" + minutes;
}
return DateTimes;
}
@Test
void t2() {
long mss = 150;
String ss = formatDateTime2(mss);
System.out.println(ss);
}
/**
* 获取精确到秒的时间戳
*
* @param date
* @return
*/
private int getSecondTimestampTwo(Date date) {
if (null == date) {
return 0;
}
String timestamp = String.valueOf(date.getTime() / 1000 / 60);
return Integer.valueOf(timestamp);
}
@Test
void t3() {
String s = handleTime(new Date());
System.out.println("ssss" + s);
int secondTimestampTwo = getSecondTimestampTwo(new Date());
System.out.println(secondTimestampTwo);
long l = System.currentTimeMillis();
System.out.println("----" + new Date().getTime());
System.out.println("====" + System.currentTimeMillis());
// System.currentTimeMillis() / (long)1000 / (long)60;
}
} }

@ -70,7 +70,7 @@ class QuestionsServiceTest {
@Transactional @Transactional
void isnable() { void isnable() {
Integer id = 1; Integer id = 1;
System.out.println(questionsService.isnable(id)); System.out.println(questionsService.isEnable(id));
} }
@Test @Test
@ -93,9 +93,9 @@ class QuestionsServiceTest {
IOUtils.copy(new FileInputStream(file), fileItem.getOutputStream()); IOUtils.copy(new FileInputStream(file), fileItem.getOutputStream());
MultipartFile multipartFile = new CommonsMultipartFile(fileItem); MultipartFile multipartFile = new CommonsMultipartFile(fileItem);
boolean b = questionsService.importQuestion(multipartFile); List<String> strings = questionsService.importQuestion(multipartFile);
System.out.println(b); System.out.println(strings.toString());
} }
@Test @Test
@ -121,7 +121,7 @@ class QuestionsServiceTest {
@Test @Test
void evaluation() { void evaluation() {
EvaluationVO evaluation = questionsService.evaluation(); EvaluationVO evaluation = questionsService.evaluation(1);
System.out.println(evaluation.toString()); System.out.println(evaluation.toString());
} }
} }

Loading…
Cancel
Save