分页展示bug修改,代码优化

hehai
shijie 4 years ago
parent e321bec332
commit ad02c4ad50
  1. 12
      pom.xml
  2. 6
      src/main/java/com/msdw/tms/api/EvaluationRulesControllerApi.java
  3. 10
      src/main/java/com/msdw/tms/api/QuestionsControllerApi.java
  4. 36
      src/main/java/com/msdw/tms/common/utils/FilesResult.java
  5. 18
      src/main/java/com/msdw/tms/config/MybatisPlusConfig.java
  6. 9
      src/main/java/com/msdw/tms/controller/EvaluationRulesController.java
  7. 20
      src/main/java/com/msdw/tms/controller/QuestionsController.java
  8. 5
      src/main/java/com/msdw/tms/entity/EvaluationRulesEntity.java
  9. 4
      src/main/java/com/msdw/tms/entity/QuestionsEntity.java
  10. 5
      src/main/java/com/msdw/tms/entity/XlsxTemplateEntity.java
  11. 18
      src/main/java/com/msdw/tms/entity/request/QuestionsAddRequest.java
  12. 2
      src/main/java/com/msdw/tms/entity/request/QuestionsImportRequest.java
  13. 4
      src/main/java/com/msdw/tms/entity/request/QuestionsQueryRequest.java
  14. 18
      src/main/java/com/msdw/tms/entity/request/QuestionsUpdateRequest.java
  15. 10
      src/main/java/com/msdw/tms/entity/response/CommonCode.java
  16. 4
      src/main/java/com/msdw/tms/entity/response/Response.java
  17. 6
      src/main/java/com/msdw/tms/entity/response/ResponseResult.java
  18. 4
      src/main/java/com/msdw/tms/entity/vo/EvaluationRulesVO.java
  19. 2
      src/main/java/com/msdw/tms/entity/vo/EvaluationVO.java
  20. 3
      src/main/java/com/msdw/tms/entity/vo/QuestionsDetailVO.java
  21. 2
      src/main/java/com/msdw/tms/entity/vo/QuestionsVO.java
  22. 3
      src/main/java/com/msdw/tms/service/AliyunOssService.java
  23. 2
      src/main/java/com/msdw/tms/service/EvaluationRulesService.java
  24. 2
      src/main/java/com/msdw/tms/service/XlsxTemplateService.java
  25. 12
      src/main/java/com/msdw/tms/service/impl/AliyunOssServiceImpl.java
  26. 24
      src/main/java/com/msdw/tms/service/impl/EvaluationRulesServiceImpl.java
  27. 177
      src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java
  28. 56
      src/test/java/com/msdw/tms/TmsApplicationTests.java
  29. 62
      src/test/java/com/msdw/tms/service/AliyunOssServiceTest.java
  30. 33
      src/test/java/com/msdw/tms/service/EvaluationRulesServiceTest.java
  31. 122
      src/test/java/com/msdw/tms/service/QuestionsServiceTest.java

@ -98,6 +98,18 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.4</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

@ -4,18 +4,12 @@ import com.msdw.tms.common.utils.R;
import com.msdw.tms.entity.EvaluationRulesEntity; import com.msdw.tms.entity.EvaluationRulesEntity;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.Map;
/** /**
* 测评规则信息记录只记录一条信息 * 测评规则信息记录只记录一条信息
* *
* @author gongsj * @author gongsj
* @email gongsj@gmail.com
* @date 2020-08-19 09:28:06
*/ */
@Api(value = "测评规则管理", tags = "测评规则的查询和修改") @Api(value = "测评规则管理", tags = "测评规则的查询和修改")
public interface EvaluationRulesControllerApi { public interface EvaluationRulesControllerApi {

@ -7,7 +7,6 @@ import com.msdw.tms.entity.request.QuestionsUpdateRequest;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -18,8 +17,6 @@ import java.io.IOException;
* 记录试题信息 * 记录试题信息
* *
* @author gongsj * @author gongsj
* @email gongsj@gmail.com
* @date 2020-08-19 09:28:06
*/ */
@Api(value = "试题信息管理", tags = "提供试题信息的增删改查及导入等功能") @Api(value = "试题信息管理", tags = "提供试题信息的增删改查及导入等功能")
public interface QuestionsControllerApi { public interface QuestionsControllerApi {
@ -54,7 +51,7 @@ public interface QuestionsControllerApi {
* 是否禁用试题 * 是否禁用试题
*/ */
@ApiOperation(value = "是否禁用试题", notes = "是否禁用试题") @ApiOperation(value = "是否禁用试题", notes = "是否禁用试题")
R isnable(@ApiParam(name = "id", value = "试题主键", required = true) Integer id); R isNable(@ApiParam(name = "id", value = "试题主键", required = true) Integer id);
/** /**
* 删除 * 删除
@ -70,17 +67,12 @@ public interface QuestionsControllerApi {
/** /**
* excel模板文件上传 * excel模板文件上传
*
* @param file
* @return
*/ */
@ApiOperation(value = "excel模板文件上传", notes = "excel模板文件上传") @ApiOperation(value = "excel模板文件上传", notes = "excel模板文件上传")
R uploadFiles(@ApiParam(name = "file", value = "excel文件", required = true) MultipartFile file) throws IOException; R uploadFiles(@ApiParam(name = "file", value = "excel文件", required = true) MultipartFile file) throws IOException;
/** /**
* excel模板文件下载 * excel模板文件下载
*
* @return
*/ */
@ApiOperation(value = "excel模板文件下载", notes = "excel模板文件下载") @ApiOperation(value = "excel模板文件下载", notes = "excel模板文件下载")
R downloadFiles(HttpServletResponse response) throws IOException; R downloadFiles(HttpServletResponse response) throws IOException;

@ -1,41 +1,15 @@
package com.msdw.tms.common.utils; package com.msdw.tms.common.utils;
public class FilesResult { import lombok.Data;
import lombok.ToString;
@Data
@ToString
public class FilesResult {
// 文件名 // 文件名
private String fileName; private String fileName;
// 文件在储存空间的路径 // 文件在储存空间的路径
private String fileUrl; private String fileUrl;
// 上传状态 // 上传状态
private String status; private String status;
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getFileUrl() {
return fileUrl;
}
public void setFileUrl(String fileUrl) {
this.fileUrl = fileUrl;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
@Override
public String toString() {
return "UploadFilesResult [fileName=" + fileName + ", fileUrl=" + fileUrl + ", status=" + status + "]";
}
} }

@ -0,0 +1,18 @@
package com.msdw.tms.config;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MybatisPlusConfig {
/**
* mybatis-plus分页插件
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
PaginationInterceptor page = new PaginationInterceptor();
page.setDialectType("mysql");
return page;
}
}

@ -5,22 +5,21 @@ import com.msdw.tms.common.utils.R;
import com.msdw.tms.entity.EvaluationRulesEntity; import com.msdw.tms.entity.EvaluationRulesEntity;
import com.msdw.tms.entity.vo.EvaluationRulesVO; import com.msdw.tms.entity.vo.EvaluationRulesVO;
import com.msdw.tms.service.EvaluationRulesService; import com.msdw.tms.service.EvaluationRulesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/** /**
* 测评规则信息记录只记录一条信息 * 测评规则信息记录只记录一条信息
* *
* @author gongsj * @author gongsj
* @email gongsj@gmail.com
* @date 2020-08-19 09:28:06
*/ */
@RestController @RestController
@RequestMapping("tms/evaluationrules") @RequestMapping("tms/evaluationrules")
public class EvaluationRulesController implements EvaluationRulesControllerApi { public class EvaluationRulesController implements EvaluationRulesControllerApi {
@Autowired @Resource
private EvaluationRulesService evaluationRulesService; EvaluationRulesService evaluationRulesService;
/** /**
* 测评规则信息的展示 * 测评规则信息的展示

@ -9,12 +9,12 @@ 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.vo.EvaluationVO; import com.msdw.tms.entity.vo.EvaluationVO;
import com.msdw.tms.entity.vo.QuestionsDetailVO; import com.msdw.tms.entity.vo.QuestionsDetailVO;
import com.msdw.tms.service.AliyunOssService;
import com.msdw.tms.service.QuestionsService; import com.msdw.tms.service.QuestionsService;
import org.springframework.beans.factory.annotation.Autowired; import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
@ -24,17 +24,13 @@ import java.util.Arrays;
* 记录试题信息 * 记录试题信息
* *
* @author gongsj * @author gongsj
* @email gongsj@gmail.com
* @date 2020-08-19 09:28:06
*/ */
@RestController @RestController
@RequestMapping("tms/questions") @RequestMapping("tms/questions")
public class QuestionsController implements QuestionsControllerApi { public class QuestionsController implements QuestionsControllerApi {
@Autowired
private QuestionsService questionsService;
@Autowired @Resource
private AliyunOssService ossService; QuestionsService questionsService;
/** /**
* 列表 * 列表
@ -66,6 +62,7 @@ public class QuestionsController implements QuestionsControllerApi {
/** /**
* 保存 * 保存
*/ */
@ApiOperation(value = "新增一道试题", notes = "传入新增试题所需相关参数")
@Override @Override
@PostMapping("/save") @PostMapping("/save")
//@RequiresPermissions("qms:questions:save") //@RequiresPermissions("qms:questions:save")
@ -93,7 +90,7 @@ public class QuestionsController implements QuestionsControllerApi {
@Override @Override
@PutMapping("/isnable") @PutMapping("/isnable")
//@RequiresPermissions("qms:questions:isnable") //@RequiresPermissions("qms:questions:isnable")
public R isnable(Integer id) { public R isNable(Integer id) {
boolean b = questionsService.isnable(id); boolean b = questionsService.isnable(id);
return b ? R.ok() : R.error(); return b ? R.ok() : R.error();
@ -125,9 +122,6 @@ public class QuestionsController implements QuestionsControllerApi {
/** /**
* excel模板文件上传 * excel模板文件上传
*
* @param file
* @return
*/ */
@Override @Override
@PostMapping("/upload") @PostMapping("/upload")
@ -139,8 +133,6 @@ public class QuestionsController implements QuestionsControllerApi {
/** /**
* excel模板文件下载 * excel模板文件下载
*
* @return
*/ */
@Override @Override
@GetMapping("/download") @GetMapping("/download")

@ -2,17 +2,14 @@ package com.msdw.tms.entity;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date;
import lombok.Data;
/** /**
* 测评规则信息记录只记录一条信息 * 测评规则信息记录只记录一条信息
* *
* @author gongsj * @author gongsj
* @email gongsj@gmail.com
* @date 2020-08-19 09:28:06
*/ */
@Data @Data
@TableName("tms_evaluation_rules") @TableName("tms_evaluation_rules")

@ -2,17 +2,15 @@ package com.msdw.tms.entity;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import lombok.Data;
/** /**
* 记录试题信息 * 记录试题信息
* *
* @author gongsj * @author gongsj
* @email gongsj@gmail.com
* @date 2020-08-19 09:28:06
*/ */
@Data @Data
@TableName("tms_questions") @TableName("tms_questions")

@ -2,17 +2,14 @@ package com.msdw.tms.entity;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date;
import lombok.Data;
/** /**
* 模板文件信息记录 * 模板文件信息记录
* *
* @author gongsj * @author gongsj
* @email gongsj@gmail.com
* @date 2020-08-19 09:28:06
*/ */
@Data @Data
@TableName("tms_xlsx_template") @TableName("tms_xlsx_template")

@ -8,8 +8,6 @@ import lombok.Data;
* 试题的基本信息表 * 试题的基本信息表
* *
* @author gongsj * @author gongsj
* @email gongsj@gmail.com
* @date 2020-08-14 16:05:06
*/ */
@Data @Data
@ApiModel(value = "QuestionsAddRequest", description = "添加试题请求体对象") @ApiModel(value = "QuestionsAddRequest", description = "添加试题请求体对象")
@ -27,32 +25,32 @@ public class QuestionsAddRequest {
/** /**
* A选项内容 * A选项内容
*/ */
@ApiModelProperty(value = "A选项内容", name = "optionA", example = "鲸鱼", required = false) @ApiModelProperty(value = "A选项内容", name = "optionA", example = "鲸鱼")
private String optionA; private String optionA;
/** /**
* B选项内容 * B选项内容
*/ */
@ApiModelProperty(value = "B选项内容", name = "optionB", example = "鲨鱼", required = false) @ApiModelProperty(value = "B选项内容", name = "optionB", example = "鲨鱼")
private String optionB; private String optionB;
/** /**
* C选项内容 * C选项内容
*/ */
@ApiModelProperty(value = "C选项内容", name = "optionC", example = "河马", required = false) @ApiModelProperty(value = "C选项内容", name = "optionC", example = "河马")
private String optionC; private String optionC;
/** /**
* D选项内容 * D选项内容
*/ */
@ApiModelProperty(value = "D选项内容", name = "optionD", example = "豹子", required = false) @ApiModelProperty(value = "D选项内容", name = "optionD", example = "豹子")
private String optionD; private String optionD;
/** /**
* E选项内容 * E选项内容
*/ */
@ApiModelProperty(value = "E选项内容", name = "optionE", example = "大象", required = false) @ApiModelProperty(value = "E选项内容", name = "optionE", example = "大象")
private String optionE; private String optionE;
/** /**
* F选项内容 * F选项内容
*/ */
@ApiModelProperty(value = "F选项内容", name = "optionF", example = "老虎", required = false) @ApiModelProperty(value = "F选项内容", name = "optionF", example = "老虎")
private String optionF; private String optionF;
/** /**
* 正确答案 * 正确答案
@ -62,11 +60,11 @@ public class QuestionsAddRequest {
/** /**
* 答案解析 * 答案解析
*/ */
@ApiModelProperty(value = "答案解析", name = "answerAnalysis", example = "鲸鱼是最大的哺乳动物", required = false) @ApiModelProperty(value = "答案解析", name = "answerAnalysis", example = "鲸鱼是最大的哺乳动物")
private String answerAnalysis; private String answerAnalysis;
/** /**
* 试题科目 * 试题科目
*/ */
@ApiModelProperty(value = "试题科目", name = "subjects", example = "基础通识", required = false) @ApiModelProperty(value = "试题科目", name = "subjects", example = "基础通识")
private String subjects; private String subjects;
} }

@ -7,8 +7,6 @@ import lombok.Data;
* 试题的基本信息表 * 试题的基本信息表
* *
* @author gongsj * @author gongsj
* @email gongsj@gmail.com
* @date 2020-08-14 16:05:06
*/ */
@Data @Data
public class QuestionsImportRequest { public class QuestionsImportRequest {

@ -8,8 +8,6 @@ import lombok.Data;
* 试题的基本信息表 * 试题的基本信息表
* *
* @author gongsj * @author gongsj
* @email gongsj@gmail.com
* @date 2020-08-14 16:05:06
*/ */
@Data @Data
@ApiModel(value = "QuestionsQueryRequest", description = "条件查询请求对象") @ApiModel(value = "QuestionsQueryRequest", description = "条件查询请求对象")
@ -18,7 +16,7 @@ public class QuestionsQueryRequest {
/** /**
* 题干问题描述 * 题干问题描述
*/ */
@ApiModelProperty(value = "题干,问题描述", name = "questionStem", example = "世界上最大的哺乳动物是什么?", required = false) @ApiModelProperty(value = "题干,问题描述", name = "questionStem", example = "世界上最大的哺乳动物是什么?")
private String questionStem; private String questionStem;
// /** // /**

@ -8,8 +8,6 @@ import lombok.Data;
* 试题的基本信息表 * 试题的基本信息表
* *
* @author gongsj * @author gongsj
* @email gongsj@gmail.com
* @date 2020-08-14 16:05:06
*/ */
@Data @Data
@ApiModel(value = "QuestionsUpdateRequest", description = "修改试题请求体对象") @ApiModel(value = "QuestionsUpdateRequest", description = "修改试题请求体对象")
@ -32,32 +30,32 @@ public class QuestionsUpdateRequest {
/** /**
* A选项内容 * A选项内容
*/ */
@ApiModelProperty(value = "A选项内容", name = "optionA", example = "鲸鱼", required = false) @ApiModelProperty(value = "A选项内容", name = "optionA", example = "鲸鱼")
private String optionA; private String optionA;
/** /**
* B选项内容 * B选项内容
*/ */
@ApiModelProperty(value = "B选项内容", name = "optionB", example = "鲨鱼", required = false) @ApiModelProperty(value = "B选项内容", name = "optionB", example = "鲨鱼")
private String optionB; private String optionB;
/** /**
* C选项内容 * C选项内容
*/ */
@ApiModelProperty(value = "C选项内容", name = "optionC", example = "河马", required = false) @ApiModelProperty(value = "C选项内容", name = "optionC", example = "河马")
private String optionC; private String optionC;
/** /**
* D选项内容 * D选项内容
*/ */
@ApiModelProperty(value = "D选项内容", name = "optionD", example = "豹子", required = false) @ApiModelProperty(value = "D选项内容", name = "optionD", example = "豹子")
private String optionD; private String optionD;
/** /**
* E选项内容 * E选项内容
*/ */
@ApiModelProperty(value = "E选项内容", name = "optionE", example = "大象", required = false) @ApiModelProperty(value = "E选项内容", name = "optionE", example = "大象")
private String optionE; private String optionE;
/** /**
* F选项内容 * F选项内容
*/ */
@ApiModelProperty(value = "F选项内容", name = "optionF", example = "老虎", required = false) @ApiModelProperty(value = "F选项内容", name = "optionF", example = "老虎")
private String optionF; private String optionF;
/** /**
* 正确答案 * 正确答案
@ -67,11 +65,11 @@ public class QuestionsUpdateRequest {
/** /**
* 答案解析 * 答案解析
*/ */
@ApiModelProperty(value = "答案解析", name = "answerAnalysis", example = "鲸鱼是最大的哺乳动物", required = false) @ApiModelProperty(value = "答案解析", name = "answerAnalysis", example = "鲸鱼是最大的哺乳动物")
private String answerAnalysis; private String answerAnalysis;
/** /**
* 试题科目 * 试题科目
*/ */
@ApiModelProperty(value = "试题科目", name = "subjects", example = "基础通识", required = false) @ApiModelProperty(value = "试题科目", name = "subjects", example = "基础通识")
private String subjects; private String subjects;
} }

@ -2,13 +2,6 @@ package com.msdw.tms.entity.response;
import lombok.ToString; import lombok.ToString;
/**
* @Author: mrt.
* @Description:
* @Date:Created in 2018/1/24 18:33.
* @Modified By:
*/
@ToString @ToString
public enum CommonCode implements ResultCode { public enum CommonCode implements ResultCode {
@ -21,7 +14,6 @@ public enum CommonCode implements ResultCode {
QUESTIONTYPE_INVALID(false, 10005, "题型错误!"), QUESTIONTYPE_INVALID(false, 10005, "题型错误!"),
FAIL(false, 11111, "操作失败!"), FAIL(false, 11111, "操作失败!"),
SERVER_ERROR(false, 99999, "抱歉,系统繁忙,请稍后重试!"); SERVER_ERROR(false, 99999, "抱歉,系统繁忙,请稍后重试!");
// private static ImmutableMap<Integer, CommonCode> codes ;
//操作是否成功 //操作是否成功
boolean success; boolean success;
//操作代码 //操作代码
@ -29,7 +21,7 @@ public enum CommonCode implements ResultCode {
//提示信息 //提示信息
String message; String message;
private CommonCode(boolean success, int code, String message) { CommonCode(boolean success, int code, String message) {
this.success = success; this.success = success;
this.code = code; this.code = code;
this.message = message; this.message = message;

@ -4,6 +4,6 @@ package com.msdw.tms.entity.response;
* Created by admin on 2018/3/5. * Created by admin on 2018/3/5.
*/ */
public interface Response { public interface Response {
public static final boolean SUCCESS = true; boolean SUCCESS = true;
public static final int SUCCESS_CODE = 10000; int SUCCESS_CODE = 10000;
} }

@ -4,12 +4,6 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.ToString; import lombok.ToString;
/**
* @Author: mrt.
* @Description:
* @Date:Created in 2018/1/24 18:33.
* @Modified By:
*/
@Data @Data
@ToString @ToString
@NoArgsConstructor @NoArgsConstructor

@ -1,7 +1,5 @@
package com.msdw.tms.entity.vo; package com.msdw.tms.entity.vo;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
@ -10,8 +8,6 @@ import java.io.Serializable;
* 测评规则信息记录只记录一条信息 * 测评规则信息记录只记录一条信息
* *
* @author gongsj * @author gongsj
* @email gongsj@gmail.com
* @date 2020-08-19 09:28:06
*/ */
@Data @Data
public class EvaluationRulesVO implements Serializable { public class EvaluationRulesVO implements Serializable {

@ -10,8 +10,6 @@ import java.util.Set;
* 测评规则信息记录只记录一条信息 * 测评规则信息记录只记录一条信息
* *
* @author gongsj * @author gongsj
* @email gongsj@gmail.com
* @date 2020-08-19 09:28:06
*/ */
@Data @Data
@TableName("tms_evaluation_rules") @TableName("tms_evaluation_rules")

@ -3,14 +3,11 @@ package com.msdw.tms.entity.vo;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date;
/** /**
* 记录试题信息 * 记录试题信息
* *
* @author gongsj * @author gongsj
* @email gongsj@gmail.com
* @date 2020-08-19 09:28:06
*/ */
@Data @Data
public class QuestionsDetailVO implements Serializable { public class QuestionsDetailVO implements Serializable {

@ -9,8 +9,6 @@ import java.io.Serializable;
* 试题列表展示信息 * 试题列表展示信息
* *
* @author gongsj * @author gongsj
* @email gongsj@gmail.com
* @date 2020-08-19 09:28:06
*/ */
@Data @Data
@ToString @ToString

@ -18,15 +18,12 @@ public interface AliyunOssService {
/** /**
* 下载文件 * 下载文件
* *
* @param response
* @param objectName 本地路径 * @param objectName 本地路径
*/ */
void downloadFiles(HttpServletResponse response, String objectName) throws IOException; void downloadFiles(HttpServletResponse response, String objectName) throws IOException;
/** /**
* 根据文件路径+文件名称删除该文件 * 根据文件路径+文件名称删除该文件
*
* @param filename
*/ */
void deleteFile(String filename); void deleteFile(String filename);
} }

@ -8,8 +8,6 @@ import com.msdw.tms.entity.vo.EvaluationRulesVO;
* 测评规则信息记录只记录一条信息 * 测评规则信息记录只记录一条信息
* *
* @author gongsj * @author gongsj
* @email gongsj@gmail.com
* @date 2020-08-19 09:28:06
*/ */
public interface EvaluationRulesService extends IService<EvaluationRulesEntity> { public interface EvaluationRulesService extends IService<EvaluationRulesEntity> {
EvaluationRulesVO getEvaluationRules(); EvaluationRulesVO getEvaluationRules();

@ -7,8 +7,6 @@ import com.msdw.tms.entity.XlsxTemplateEntity;
* 模板文件信息记录 * 模板文件信息记录
* *
* @author gongsj * @author gongsj
* @email gongsj@gmail.com
* @date 2020-08-19 09:28:06
*/ */
public interface XlsxTemplateService extends IService<XlsxTemplateEntity> { public interface XlsxTemplateService extends IService<XlsxTemplateEntity> {
} }

@ -6,10 +6,10 @@ import com.msdw.tms.common.utils.FilesResult;
import com.msdw.tms.config.AliyunOssConfig; import com.msdw.tms.config.AliyunOssConfig;
import com.msdw.tms.service.AliyunOssService; import com.msdw.tms.service.AliyunOssService;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
@ -19,11 +19,11 @@ import java.io.IOException;
@Service @Service
public class AliyunOssServiceImpl implements AliyunOssService { public class AliyunOssServiceImpl implements AliyunOssService {
@Autowired @Resource
private AliyunOssConfig config; AliyunOssConfig config;
@Autowired @Resource
private BeanFactory beanFactory; BeanFactory beanFactory;
/** /**
* 上传文件 * 上传文件
@ -38,7 +38,6 @@ public class AliyunOssServiceImpl implements AliyunOssService {
/** /**
* 下载文件 * 下载文件
* *
* @param response
* @param objectName 本地路径 * @param objectName 本地路径
*/ */
public void downloadFiles(HttpServletResponse response, String objectName) throws IOException { public void downloadFiles(HttpServletResponse response, String objectName) throws IOException {
@ -49,7 +48,6 @@ public class AliyunOssServiceImpl implements AliyunOssService {
/** /**
* 根据文件路径+文件名称删除该文件 * 根据文件路径+文件名称删除该文件
* *
* @param filename
*/ */
public void deleteFile(String filename) { public void deleteFile(String filename) {
OSSClient client = beanFactory.getBean(OSSClient.class); OSSClient client = beanFactory.getBean(OSSClient.class);

@ -12,32 +12,34 @@ import com.msdw.tms.entity.vo.EvaluationRulesVO;
import com.msdw.tms.service.EvaluationRulesService; import com.msdw.tms.service.EvaluationRulesService;
import com.msdw.tms.service.QuestionsService; import com.msdw.tms.service.QuestionsService;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service("evaluationRulesService") @Service("evaluationRulesService")
public class EvaluationRulesServiceImpl extends ServiceImpl<EvaluationRulesDao, EvaluationRulesEntity> implements EvaluationRulesService { public class EvaluationRulesServiceImpl extends ServiceImpl<EvaluationRulesDao, EvaluationRulesEntity> implements EvaluationRulesService {
@Autowired @Resource
QuestionsService questionsService; QuestionsService questionsService;
//TODO 此表数据可存在redis中,提高系统性能
@Override @Override
public EvaluationRulesVO getEvaluationRules() { public EvaluationRulesVO getEvaluationRules() {
EvaluationRulesVO evaluationRulesVO = new EvaluationRulesVO(); EvaluationRulesVO evaluationRulesVO = new EvaluationRulesVO();
EvaluationRulesEntity evaluationRules = this.getById(Constant.EVALUATION_RULES_ID); EvaluationRulesEntity evaluationRules = this.getById(Constant.EVALUATION_RULES_ID);
if (evaluationRules.getEvaluationType() == Constant.RulesType.CUSTOMIZE.getType()) {//自定义 if (evaluationRules.getEvaluationType().equals(Constant.RulesType.CUSTOMIZE.getType())) {//自定义
int totalNum = 0; int totalNum = 0;
if (evaluationRules.getIsSingleEnable() == Constant.IsEnable.ENABLE.getType()) {//启用 if (evaluationRules.getIsSingleEnable().equals(Constant.IsEnable.ENABLE.getType())) {//启用
totalNum += evaluationRules.getSingleNum(); totalNum += evaluationRules.getSingleNum();
} }
if (evaluationRules.getIsMultipleEnable() == Constant.IsEnable.ENABLE.getType()) {//启用 if (evaluationRules.getIsMultipleEnable().equals(Constant.IsEnable.ENABLE.getType())) {//启用
totalNum += evaluationRules.getMultipleNum(); totalNum += evaluationRules.getMultipleNum();
} }
if (evaluationRules.getIsJudgmentEnable() == Constant.IsEnable.ENABLE.getType()) {//启用 if (evaluationRules.getIsJudgmentEnable().equals(Constant.IsEnable.ENABLE.getType())) {//启用
totalNum += evaluationRules.getJudgmentNum(); totalNum += evaluationRules.getJudgmentNum();
} }
@ -76,27 +78,27 @@ public class EvaluationRulesServiceImpl extends ServiceImpl<EvaluationRulesDao,
//判断题目是否超出范围 //判断题目是否超出范围
//判断类型 //判断类型
Integer evaluationType = evaluationRules.getEvaluationType(); Integer evaluationType = evaluationRules.getEvaluationType();
if (evaluationType == Constant.RulesType.RANDOM.getType()) {//随机 if (evaluationType.equals(Constant.RulesType.RANDOM.getType())) {//随机
Integer questionNum = evaluationRules.getQuestionNum(); Integer questionNum = evaluationRules.getQuestionNum();
//查询总题数 //查询总题数
int count = questionsService.count(queryWrapper);//总题数 int count = questionsService.count(queryWrapper);//总题数
numIncalid(questionNum, count); numIncalid(questionNum, count);
} else if (evaluationType == Constant.RulesType.CUSTOMIZE.getType()) {//自定义 } else if (evaluationType.equals(Constant.RulesType.CUSTOMIZE.getType())) {//自定义
if (evaluationRules.getIsSingleEnable() == Constant.IsEnable.ENABLE.getType()) {//启用 if (evaluationRules.getIsSingleEnable().equals(Constant.IsEnable.ENABLE.getType())) {//启用
int singleNum = evaluationRules.getSingleNum(); int singleNum = evaluationRules.getSingleNum();
int totalSingleNum = questionsService.count(queryWrapper.eq("question_type_no", int totalSingleNum = questionsService.count(queryWrapper.eq("question_type_no",
Constant.QuestionType.SINGLE_CHOICE.getType()));//单选题总数 Constant.QuestionType.SINGLE_CHOICE.getType()));//单选题总数
numIncalid(singleNum, totalSingleNum); numIncalid(singleNum, totalSingleNum);
} }
if (evaluationRules.getIsMultipleEnable() == Constant.IsEnable.ENABLE.getType()) {//启用 if (evaluationRules.getIsMultipleEnable().equals(Constant.IsEnable.ENABLE.getType())) {//启用
int multipleNum = evaluationRules.getMultipleNum(); int multipleNum = evaluationRules.getMultipleNum();
int totalMultipleNum = questionsService.count(queryWrapper.eq("question_type_no", int totalMultipleNum = questionsService.count(queryWrapper.eq("question_type_no",
Constant.QuestionType.MULTIPLE_CHOICE.getType()));//多选题总数 Constant.QuestionType.MULTIPLE_CHOICE.getType()));//多选题总数
numIncalid(multipleNum, totalMultipleNum); numIncalid(multipleNum, totalMultipleNum);
} }
if (evaluationRules.getIsJudgmentEnable() == Constant.IsEnable.ENABLE.getType()) {//启用 if (evaluationRules.getIsJudgmentEnable().equals(Constant.IsEnable.ENABLE.getType())) {//启用
int judgmentNum = evaluationRules.getJudgmentNum(); int judgmentNum = evaluationRules.getJudgmentNum();
int totalJudgmentNum = questionsService.count(queryWrapper.eq("question_type_no", int totalJudgmentNum = questionsService.count(queryWrapper.eq("question_type_no",
Constant.QuestionType.TRUE_OR_FALSE.getType()));//判断题总数 Constant.QuestionType.TRUE_OR_FALSE.getType()));//判断题总数

@ -27,11 +27,11 @@ import com.msdw.tms.service.QuestionsService;
import com.msdw.tms.service.XlsxTemplateService; 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.beans.factory.annotation.Autowired;
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;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.time.Instant; import java.time.Instant;
@ -41,74 +41,70 @@ import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service("questionsService") @Service("questionsService")
public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEntity> implements QuestionsService { public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEntity> implements QuestionsService {
@Autowired @Resource
private AliyunOssService ossService; AliyunOssService ossService;
@Autowired @Resource
XlsxTemplateService xlsxTemplateService; XlsxTemplateService xlsxTemplateService;
@Autowired @Resource
EvaluationRulesService evaluationRulesService; EvaluationRulesService evaluationRulesService;
/** /**
* 条件加分页查询题干模糊查询未删除修改时间降序 * 条件加分页查询题干模糊查询未删除修改时间降序
*
* @param page
* @param size
* @param request
* @return
*/ */
@Override @Override
public PageUtils queryQuestionsPage(Integer page, Integer size, QuestionsQueryRequest request) { public PageUtils queryQuestionsPage(Integer page, Integer size, QuestionsQueryRequest request) {
//请求包装类 // 请求包装类
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());
//判断请求体是否为空 // 判断请求体是否为空
if (request != null) { if (request != null) {
// 题干:判断题干是否为空,不为空则加入搜索条件 // 题干:判断题干是否为空,不为空则加入搜索条件
if (request.getQuestionStem() != null) { if (request.getQuestionStem() != null) {
queryWrapper.like("question_stem", request.getQuestionStem()); queryWrapper.like("question_stem", request.getQuestionStem());
} }
// 题型:判断题型是否为空,不为空则加入搜索条件 //TODO 扩展搜索条件
// if (questionsRequest.getQuestionType() != null) { // 题型:判断题型是否为空,不为空则加入搜索条件
// queryWrapper.eq("question_type", questionsRequest.getQuestionType()); // if (questionsRequest.getQuestionType() != null) {
// } // queryWrapper.eq("question_type", questionsRequest.getQuestionType());
// 修改时间:判断修改时间是否为空,不为空则加入搜索条件 // }
// if (questionsRequest.getModifyTime() != null) { // 修改时间:判断修改时间是否为空,不为空则加入搜索条件
// queryWrapper.eq("modify_time", questionsRequest.getModifyTime()); // if (questionsRequest.getModifyTime() != null) {
// } // queryWrapper.eq("modify_time", questionsRequest.getModifyTime());
// }
} }
//修改时间降序 // 修改时间降序
queryWrapper.orderByDesc("modify_time"); queryWrapper.orderByDesc("modify_time");
IPage<QuestionsEntity> questionsEntityIPage = this.page( IPage<QuestionsEntity> questionsIPage = this.page(
new Query<QuestionsEntity>().getPage(page, size), new Query<QuestionsEntity>().getPage(page, size),
queryWrapper queryWrapper
); );
PageUtils questionsPage = new PageUtils(questionsEntityIPage); List<QuestionsEntity> records = questionsIPage.getRecords();
List<QuestionsEntity> list = (List<QuestionsEntity>) questionsPage.getList();
List<QuestionsVO> collect = list.stream().map(item -> { List<QuestionsVO> questions = records.stream().map(question -> {
QuestionsVO questionsVO = new QuestionsVO(); QuestionsVO questionsVO = new QuestionsVO();
BeanUtils.copyProperties(item, questionsVO); BeanUtils.copyProperties(question, questionsVO);
//处理时间格式 //处理时间格式
questionsVO.setCreateTime(handleTime(item.getCreateTime())); questionsVO.setCreateTime(handleTime(question.getCreateTime()));
questionsVO.setModifyTime(handleTime(item.getModifyTime())); questionsVO.setModifyTime(handleTime(question.getModifyTime()));
return questionsVO; return questionsVO;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
questionsPage.setList(collect); PageUtils questionsPage = new PageUtils(questionsIPage);
new PageUtils(questionsIPage).setList(questions);
return questionsPage; return questionsPage;
} }
@ -161,9 +157,6 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
/** /**
* 保存试题根据题型名称得到题型号设置创建时间和修改时间 * 保存试题根据题型名称得到题型号设置创建时间和修改时间
*
* @param questions
* @return
*/ */
@Override @Override
@Transactional @Transactional
@ -172,28 +165,19 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
ExceptionCast.cast(CommonCode.INVALID_PARAM); ExceptionCast.cast(CommonCode.INVALID_PARAM);
} }
// 判断是否题干重复。。。 // 判断是否题干重复,
isStemRepeat(questions.getQuestionStem()); QueryWrapper<QuestionsEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("is_del", Constant.IsDel.NOT_DEL.getType())
QuestionsEntity questionsEntity = new QuestionsEntity(); .eq("question_stem", questions.getQuestionStem());
BeanUtils.copyProperties(questions, questionsEntity); int count = this.count(queryWrapper);
if (count > 0) {//说明已存在
String questionType = questions.getQuestionType(); //抛出题目已存在异常
//根据题型名称得到题型号 ExceptionCast.cast(CommonCode.QUESTION_EXISTS);
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);
} }
// 将传入的对象内容拷贝到QuestionsEntity并返回
QuestionsEntity questionsEntity = getQuestionsEntity(questions);
questionsEntity.setCreateTime(new Date()); questionsEntity.setCreateTime(new Date());
questionsEntity.setModifyTime(new Date()); questionsEntity.setModifyTime(new Date());
//TODO 创建者和修改者。。。 //TODO 创建者和修改者。。。
@ -208,18 +192,38 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
ExceptionCast.cast(CommonCode.INVALID_PARAM); ExceptionCast.cast(CommonCode.INVALID_PARAM);
} }
// 判断是否题干重复 // 判断是否题干重复,除了自己之外还有没有重复的题干,因为自己的题干可以不做修改
isStemRepeat(questions.getQuestionStem()); 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);
questionsEntity.setModifyTime(new Date());
//TODO 设置修改者。。。
return this.updateById(questionsEntity);
}
// 将传入的对象内容拷贝到QuestionsEntity并返回
private <T> QuestionsEntity getQuestionsEntity(T questions) {
QuestionsEntity questionsEntity = new QuestionsEntity(); QuestionsEntity questionsEntity = new QuestionsEntity();
BeanUtils.copyProperties(questions, questionsEntity); BeanUtils.copyProperties(questions, questionsEntity);
String questionType = questions.getQuestionType(); String questionType = questionsEntity.getQuestionType();
//根据题型名称得到题型号 //根据题型名称得到题型号
if (questionType.equals(Constant.QuestionType.SINGLE_CHOICE.getDesc())) { if (questionType.equals(Constant.QuestionType.SINGLE_CHOICE.getDesc())) {
//单选题 //单选题
@ -230,23 +234,11 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
} else if (questionType.equals(Constant.QuestionType.TRUE_OR_FALSE.getDesc())) { } else if (questionType.equals(Constant.QuestionType.TRUE_OR_FALSE.getDesc())) {
//判断题 //判断题
questionsEntity.setQuestionTypeNo(Constant.QuestionType.TRUE_OR_FALSE.getType()); questionsEntity.setQuestionTypeNo(Constant.QuestionType.TRUE_OR_FALSE.getType());
} else { } else {// 判断题型是否不存在。。。
//说明题型不正确 //说明题型不正确
ExceptionCast.cast(CommonCode.QUESTIONTYPE_INVALID); ExceptionCast.cast(CommonCode.QUESTIONTYPE_INVALID);
} }
return questionsEntity;
questionsEntity.setModifyTime(new Date());
//TODO 设置修改者。。。
return this.updateById(questionsEntity);
}
private void isStemRepeat(String stem) {
int count = this.count(new QueryWrapper<QuestionsEntity>().eq("question_stem", stem));
if (count > 0) {//说明已存在
//抛出题目已存在异常
ExceptionCast.cast(CommonCode.QUESTION_EXISTS);
}
} }
@Override @Override
@ -255,11 +247,11 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
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() == 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());
} }
if (byId.getIsEnable() == 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());
} }
@ -281,27 +273,18 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
/** /**
* 校验题干重复和题型不对的从列表中将该题剔除名称相同的要去重 * 校验题干重复和题型不对的从列表中将该题剔除名称相同的要去重
*
* @param file
* @return
* @throws IOException
*/ */
@Override @Override
@Transactional @Transactional
public boolean importQuestion(MultipartFile file) throws IOException { public boolean importQuestion(MultipartFile file) throws IOException {
List<QuestionsImportRequest> list = new ExcelImportUtil(QuestionsImportRequest.class) // 使用excel导入工具类获取试题数据列表
.readExcel(file.getInputStream(), Constant.STARTING_ROW, Constant.STARTING_CELL); List<QuestionsImportRequest> list = new ExcelImportUtil(QuestionsImportRequest.class).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.INVALID_PARAM);
} }
//List<Person> unique = persons.stream().collect(
// Collectors.collectingAndThen(
// Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(Person::getName))), ArrayList::new)
//);
List<QuestionsEntity> collect = list.stream().map(item -> { List<QuestionsEntity> collect = list.stream().map(item -> {
int count = this.count(new QueryWrapper<QuestionsEntity>().eq("question_stem", item.getQuestionStem())); int count = this.count(new QueryWrapper<QuestionsEntity>().eq("question_stem", item.getQuestionStem()));
if (count > 0) {//说明已存在 if (count > 0) {//说明已存在
return null; return null;
@ -327,19 +310,18 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
questionsEntity.setModifyTime(new Date()); questionsEntity.setModifyTime(new Date());
//TODO 创建者和修改者。。。 //TODO 创建者和修改者。。。
return questionsEntity; return questionsEntity;
}).filter(question -> question != null).collect(Collectors.collectingAndThen( }).filter(Objects::nonNull)// 过滤掉为null的对象
.collect(Collectors.collectingAndThen(// 去重收集
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(QuestionsEntity::getQuestionStem))), Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(QuestionsEntity::getQuestionStem))),
ArrayList::new ArrayList::new
)); ));
// 批量新增
return this.saveBatch(collect); return this.saveBatch(collect);
} }
/** /**
* 上传模板文件修改模板信息表数据 * 上传模板文件修改模板信息表数据
*
* @param file
* @return
*/ */
@Override @Override
@Transactional @Transactional
@ -360,7 +342,6 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
ossService.downloadFiles(response, xlsxTemplate.getFileName()); ossService.downloadFiles(response, xlsxTemplate.getFileName());
} }
// TODO 处理时间格式
@Override @Override
public EvaluationVO evaluation() { public EvaluationVO evaluation() {
@ -378,7 +359,7 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
BeanUtils.copyProperties(evaluationRules, evaluation); BeanUtils.copyProperties(evaluationRules, evaluation);
Integer evaluationType = evaluationRules.getEvaluationType(); Integer evaluationType = evaluationRules.getEvaluationType();
if (evaluationType == Constant.RulesType.RANDOM.getType()) {//随机 if (evaluationType.equals(Constant.RulesType.RANDOM.getType())) {//随机
// 类型为随机,直接用题目数量 // 类型为随机,直接用题目数量
Integer questionNum = evaluationRules.getQuestionNum(); Integer questionNum = evaluationRules.getQuestionNum();
// 查询题库所有未删除,未禁用的题目id // 查询题库所有未删除,未禁用的题目id
@ -386,34 +367,38 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
set = getRandomList(questionNum, questions); set = getRandomList(questionNum, questions);
} else if (evaluationType == Constant.RulesType.CUSTOMIZE.getType()) {//自定义 } else if (evaluationType.equals(Constant.RulesType.CUSTOMIZE.getType())) {//自定义
// 单选题数量
int singleNum = 0; int singleNum = 0;
// 多选题数量
int multipleNum = 0; int multipleNum = 0;
// 判断题数量
int judgmentNum = 0; int judgmentNum = 0;
//判断各条目的题型是否启用 //判断各条目的题型是否启用
if (evaluationRules.getIsSingleEnable() == Constant.IsEnable.ENABLE.getType()) { if (evaluationRules.getIsSingleEnable().equals(Constant.IsEnable.ENABLE.getType())) {
singleNum = evaluationRules.getSingleNum(); singleNum = evaluationRules.getSingleNum();
List<QuestionsEntity> singleChoice = this.list(queryWrapper.eq("question_type_no", List<QuestionsEntity> singleChoice = this.list(queryWrapper.eq("question_type_no",
Constant.QuestionType.SINGLE_CHOICE.getType())); Constant.QuestionType.SINGLE_CHOICE.getType()));
set.addAll(getRandomList(singleNum, singleChoice)); set.addAll(getRandomList(singleNum, singleChoice));
} }
if (evaluationRules.getIsMultipleEnable() == Constant.IsEnable.ENABLE.getType()) { if (evaluationRules.getIsMultipleEnable().equals(Constant.IsEnable.ENABLE.getType())) {
multipleNum = evaluationRules.getMultipleNum(); multipleNum = evaluationRules.getMultipleNum();
List<QuestionsEntity> multipleChoice = this.list(queryWrapper.eq("question_type_no", List<QuestionsEntity> multipleChoice = this.list(queryWrapper.eq("question_type_no",
Constant.QuestionType.MULTIPLE_CHOICE.getType())); Constant.QuestionType.MULTIPLE_CHOICE.getType()));
set.addAll(getRandomList(multipleNum, multipleChoice)); set.addAll(getRandomList(multipleNum, multipleChoice));
} }
if (evaluationRules.getIsJudgmentEnable() == Constant.IsEnable.ENABLE.getType()) { if (evaluationRules.getIsJudgmentEnable().equals(Constant.IsEnable.ENABLE.getType())) {
judgmentNum = evaluationRules.getJudgmentNum(); judgmentNum = evaluationRules.getJudgmentNum();
List<QuestionsEntity> judgments = this.list(queryWrapper.eq("question_type_no", List<QuestionsEntity> judgments = this.list(queryWrapper.eq("question_type_no",
Constant.QuestionType.TRUE_OR_FALSE.getType())); Constant.QuestionType.TRUE_OR_FALSE.getType()));
set.addAll(getRandomList(judgmentNum, judgments)); set.addAll(getRandomList(judgmentNum, judgments));
} }
// 总题数等于各类题目数量之和
evaluation.setQuestionNum(singleNum + multipleNum + judgmentNum); evaluation.setQuestionNum(singleNum + multipleNum + judgmentNum);
} }
Set<QuestionsVO> collect = set.stream().map(item -> { Set<QuestionsVO> collect = set.stream().map(item -> {
@ -431,7 +416,7 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
private Set<QuestionsEntity> getRandomList(int len, List<QuestionsEntity> list) { private Set<QuestionsEntity> getRandomList(int len, List<QuestionsEntity> list) {
Set<QuestionsEntity> set = new HashSet<>(); Set<QuestionsEntity> set = new HashSet<>();
Random random = new Random(); Random random = new Random();
int i = 0; int i;
while (true) { while (true) {
i = random.nextInt(list.size()); i = random.nextInt(list.size());
set.add(list.get(i)); set.add(list.get(i));

@ -3,18 +3,15 @@ package com.msdw.tms;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
@SpringBootTest @SpringBootTest
class TmsApplicationTests { class TmsApplicationTests {
@Test @Test
void contextLoads() { void contextLoads() {
printMsg(1, 2, 3, "哈哈哈");
// ------------------------------------------------------------------------------------------
// QuestionsVO questionsVO = new QuestionsVO(); // QuestionsVO questionsVO = new QuestionsVO();
// //
// QuestionsEntity questionsEntity = new QuestionsEntity(); // QuestionsEntity questionsEntity = new QuestionsEntity();
@ -43,16 +40,45 @@ class TmsApplicationTests {
// //
// System.out.println(questionsVO.toString()); // System.out.println(questionsVO.toString());
Date date = new Date(); // ------------------------------------------------------------------------------------------
Instant instant = date.toInstant();
ZoneId zoneId = ZoneId.systemDefault(); // Date date = new Date();
// Instant instant = date.toInstant();
// ZoneId zoneId = ZoneId.systemDefault();
//
// LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
// System.out.println("Date = " + date);
// System.out.println("LocalDateTime = " + localDateTime);
// String DateNow = localDateTime.format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss")); // 当前日期和时间
// // String DateNow = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss")); // 当前日期和时间
// System.out.println(DateNow);
}
<T> void printMsg(T... args) {
for (T t : args) {
System.out.println("t is " + t);
}
}
/**
* 泛型方法的基本介绍
*
* @param tClass 传入的泛型实参
* @return T 返回值为T类型
* 说明
* 1public 返回值中间<T>非常重要可以理解为声明此方法为泛型方法
* 2只有声明了<T>的方法才是泛型方法泛型类中的使用了泛型的成员方法并不是泛型方法
* 3<T>表明该方法将使用泛型类型T此时才可以在方法中使用泛型类型T
* 4与泛型类的定义一样此处T可以随便写为任意标识常见的如TEKV等形式的参数常用于表示泛型
*/
public <T> T genericMethod(Class<T> tClass) throws InstantiationException,
IllegalAccessException {
T instance = tClass.newInstance();
return instance;
}
LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime(); public <T> T TestG(T t){
System.out.println("Date = " + date); return t;
System.out.println("LocalDateTime = " + localDateTime);
String DateNow = localDateTime.format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss")); // 当前日期和时间
// String DateNow = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss")); // 当前日期和时间
System.out.println(DateNow);
} }
} }

@ -0,0 +1,62 @@
package com.msdw.tms.service;
import com.msdw.tms.common.utils.FilesResult;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItem;
import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
@SpringBootTest
class AliyunOssServiceTest {
@Autowired
AliyunOssService aliyunOssService;
/**
* 测试上传文件
*/
@Test
void testUploadFiles() throws IOException {
File file = new File("D:\\pic\\1.jpg");
FileItem fileItem = new DiskFileItem("file",
Files.probeContentType(file.toPath()),
false,
file.getName(),
(int) file.length(),
file.getParentFile());
IOUtils.copy(new FileInputStream(file), fileItem.getOutputStream());
MultipartFile multipartFile = new CommonsMultipartFile(fileItem);
FilesResult filesResult = aliyunOssService.uploadFiles(multipartFile);
System.out.println(filesResult.toString());
}
/**
* 测试下载文件
*/
@Test
void testDownloadFiles() throws IOException {
HttpServletResponse response = new MockHttpServletResponse();
AliyunOssService aliyunOssService = this.aliyunOssService;
aliyunOssService.downloadFiles(response,
"http://liuwanr.oss-cn-shenzhen.aliyuncs.com/jpg/20200807/1596787474773.jpg");
}
/**
* 测试根据文件路径+文件名称删除该文件
*/
@Test
void testDeleteFile() {
aliyunOssService.deleteFile("http://liuwanr.oss-cn-shenzhen.aliyuncs.com/jpg/20200807/1596787474773.jpg");
}
}

@ -0,0 +1,33 @@
package com.msdw.tms.service;
import com.msdw.tms.entity.EvaluationRulesEntity;
import com.msdw.tms.entity.vo.EvaluationRulesVO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
/**
* 测评规则信息记录只记录一条信息
*
* @author gongsj
*/
@SpringBootTest
class EvaluationRulesServiceTest {
@Autowired
EvaluationRulesService evaluationRulesService;
@Test
void getEvaluationRules() {
EvaluationRulesVO evaluationRules = evaluationRulesService.getEvaluationRules();
System.out.println(evaluationRules.toString());
}
@Test
void updateEvaluationRulesById() {
EvaluationRulesEntity evaluationRules = new EvaluationRulesEntity();
boolean b = evaluationRulesService.updateEvaluationRulesById(evaluationRules);
System.out.println(b);
}
}

@ -0,0 +1,122 @@
package com.msdw.tms.service;
import com.msdw.tms.common.utils.FilesResult;
import com.msdw.tms.common.utils.PageUtils;
import com.msdw.tms.entity.request.QuestionsAddRequest;
import com.msdw.tms.entity.request.QuestionsQueryRequest;
import com.msdw.tms.entity.request.QuestionsUpdateRequest;
import com.msdw.tms.entity.vo.EvaluationVO;
import com.msdw.tms.entity.vo.QuestionsDetailVO;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItem;
import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
/**
* 记录试题信息
*
* @author gongsj
*/
@SpringBootTest
class QuestionsServiceTest {
@Autowired
QuestionsService questionsService;
@Test
void queryQuestionsPage() {
Integer page = 1;
Integer size = 10;
QuestionsQueryRequest request = new QuestionsQueryRequest();
PageUtils pageUtils = questionsService.queryQuestionsPage(page, size, request);
System.out.println(pageUtils.toString());
}
@Test
void getQuestionDetailById() {
Integer id = 1;
QuestionsDetailVO detail = questionsService.getQuestionDetailById(id);
System.out.println(detail.toString());
}
@Test
void saveQuestion() {
QuestionsAddRequest questions = new QuestionsAddRequest();
System.out.println(questionsService.saveQuestion(questions));
}
@Test
void updateQuestionById() {
QuestionsUpdateRequest questions = new QuestionsUpdateRequest();
System.out.println(questionsService.updateQuestionById(questions));
}
@Test
void isnable() {
Integer id = 1;
System.out.println(questionsService.isnable(id));
}
@Test
void deleteByIds() {
List<Integer> asList = new ArrayList<>();
System.out.println(questionsService.deleteByIds(asList));
}
@Test
void importQuestion() throws IOException {
File file = new File("D:\\pic\\1.jpg");
FileItem fileItem = new DiskFileItem("file",
Files.probeContentType(file.toPath()),
false,
file.getName(),
(int) file.length(),
file.getParentFile());
IOUtils.copy(new FileInputStream(file), fileItem.getOutputStream());
MultipartFile multipartFile = new CommonsMultipartFile(fileItem);
boolean b = questionsService.importQuestion(multipartFile);
System.out.println(b);
}
@Test
void uploadFiles() throws IOException {
File file = new File("D:\\pic\\1.jpg");
FileItem fileItem = new DiskFileItem("file",
Files.probeContentType(file.toPath()),
false,
file.getName(),
(int) file.length(),
file.getParentFile());
IOUtils.copy(new FileInputStream(file), fileItem.getOutputStream());
MultipartFile multipartFile = new CommonsMultipartFile(fileItem);
FilesResult filesResult = questionsService.uploadFiles(multipartFile);
System.out.println(filesResult.toString());
}
@Test
void downloadFiles() throws IOException {
HttpServletResponse response = null;
questionsService.downloadFiles(response);
}
@Test
void evaluation() {
EvaluationVO evaluation = questionsService.evaluation();
System.out.println(evaluation.toString());
}
}
Loading…
Cancel
Save