diff --git a/pom.xml b/pom.xml index 26abadc..5d3a89c 100644 --- a/pom.xml +++ b/pom.xml @@ -14,6 +14,7 @@ tms 测评管理系统 + war 1.8 @@ -39,6 +40,13 @@ org.springframework.boot spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-tomcat + + provided + com.baomidou @@ -98,6 +106,18 @@ + + commons-io + commons-io + 2.6 + test + + + commons-fileupload + commons-fileupload + 1.4 + test + @@ -106,6 +126,14 @@ org.springframework.boot spring-boot-maven-plugin + + org.apache.maven.plugins + maven-surefire-plugin + 2.20.1 + + true + + diff --git a/src/main/java/com/msdw/tms/TmsApplication.java b/src/main/java/com/msdw/tms/TmsApplication.java index 33869c2..4bf070b 100644 --- a/src/main/java/com/msdw/tms/TmsApplication.java +++ b/src/main/java/com/msdw/tms/TmsApplication.java @@ -2,12 +2,18 @@ package com.msdw.tms; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; @SpringBootApplication -public class TmsApplication { +public class TmsApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(TmsApplication.class, args); } + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { + return builder.sources(TmsApplication.class); + } } diff --git a/src/main/java/com/msdw/tms/api/EvaluationRulesControllerApi.java b/src/main/java/com/msdw/tms/api/EvaluationRulesControllerApi.java index ebafe18..dda9144 100644 --- a/src/main/java/com/msdw/tms/api/EvaluationRulesControllerApi.java +++ b/src/main/java/com/msdw/tms/api/EvaluationRulesControllerApi.java @@ -4,18 +4,12 @@ import com.msdw.tms.common.utils.R; import com.msdw.tms.entity.EvaluationRulesEntity; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.*; - -import java.util.Arrays; -import java.util.Map; /** * 测评规则信息记录,只记录一条信息 * * @author gongsj - * @email gongsj@gmail.com - * @date 2020-08-19 09:28:06 */ @Api(value = "测评规则管理", tags = "测评规则的查询和修改") public interface EvaluationRulesControllerApi { diff --git a/src/main/java/com/msdw/tms/api/QuestionsControllerApi.java b/src/main/java/com/msdw/tms/api/QuestionsControllerApi.java index ce25d72..bf4d9e7 100644 --- a/src/main/java/com/msdw/tms/api/QuestionsControllerApi.java +++ b/src/main/java/com/msdw/tms/api/QuestionsControllerApi.java @@ -7,7 +7,6 @@ import com.msdw.tms.entity.request.QuestionsUpdateRequest; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; @@ -18,8 +17,6 @@ import java.io.IOException; * 记录试题信息 * * @author gongsj - * @email gongsj@gmail.com - * @date 2020-08-19 09:28:06 */ @Api(value = "试题信息管理", tags = "提供试题信息的增删改查及导入等功能") public interface QuestionsControllerApi { @@ -54,7 +51,7 @@ public interface QuestionsControllerApi { * 是否禁用试题 */ @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模板文件上传 - * - * @param file - * @return */ @ApiOperation(value = "excel模板文件上传", notes = "excel模板文件上传") R uploadFiles(@ApiParam(name = "file", value = "excel文件", required = true) MultipartFile file) throws IOException; /** * excel模板文件下载 - * - * @return */ @ApiOperation(value = "excel模板文件下载", notes = "excel模板文件下载") R downloadFiles(HttpServletResponse response) throws IOException; diff --git a/src/main/java/com/msdw/tms/common/utils/FilesResult.java b/src/main/java/com/msdw/tms/common/utils/FilesResult.java index 103ac4b..aa36a77 100644 --- a/src/main/java/com/msdw/tms/common/utils/FilesResult.java +++ b/src/main/java/com/msdw/tms/common/utils/FilesResult.java @@ -1,41 +1,15 @@ 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 fileUrl; // 上传状态 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 + "]"; - } - } diff --git a/src/main/java/com/msdw/tms/config/MybatisPlusConfig.java b/src/main/java/com/msdw/tms/config/MybatisPlusConfig.java new file mode 100644 index 0000000..e206ea3 --- /dev/null +++ b/src/main/java/com/msdw/tms/config/MybatisPlusConfig.java @@ -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; + } +} \ No newline at end of file diff --git a/src/main/java/com/msdw/tms/controller/EvaluationRulesController.java b/src/main/java/com/msdw/tms/controller/EvaluationRulesController.java index 0efa731..99f70bd 100644 --- a/src/main/java/com/msdw/tms/controller/EvaluationRulesController.java +++ b/src/main/java/com/msdw/tms/controller/EvaluationRulesController.java @@ -5,22 +5,21 @@ import com.msdw.tms.common.utils.R; import com.msdw.tms.entity.EvaluationRulesEntity; import com.msdw.tms.entity.vo.EvaluationRulesVO; import com.msdw.tms.service.EvaluationRulesService; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; + /** * 测评规则信息记录,只记录一条信息 * * @author gongsj - * @email gongsj@gmail.com - * @date 2020-08-19 09:28:06 */ @RestController @RequestMapping("tms/evaluationrules") public class EvaluationRulesController implements EvaluationRulesControllerApi { - @Autowired - private EvaluationRulesService evaluationRulesService; + @Resource + EvaluationRulesService evaluationRulesService; /** * 测评规则信息的展示 diff --git a/src/main/java/com/msdw/tms/controller/QuestionsController.java b/src/main/java/com/msdw/tms/controller/QuestionsController.java index bce1ca3..036b0de 100644 --- a/src/main/java/com/msdw/tms/controller/QuestionsController.java +++ b/src/main/java/com/msdw/tms/controller/QuestionsController.java @@ -9,12 +9,12 @@ 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 com.msdw.tms.service.AliyunOssService; 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.multipart.MultipartFile; +import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.Arrays; @@ -24,17 +24,13 @@ import java.util.Arrays; * 记录试题信息 * * @author gongsj - * @email gongsj@gmail.com - * @date 2020-08-19 09:28:06 */ @RestController @RequestMapping("tms/questions") public class QuestionsController implements QuestionsControllerApi { - @Autowired - private QuestionsService questionsService; - @Autowired - private AliyunOssService ossService; + @Resource + QuestionsService questionsService; /** * 列表 @@ -66,6 +62,7 @@ public class QuestionsController implements QuestionsControllerApi { /** * 保存 */ + @ApiOperation(value = "新增一道试题", notes = "传入新增试题所需相关参数") @Override @PostMapping("/save") //@RequiresPermissions("qms:questions:save") @@ -93,7 +90,7 @@ public class QuestionsController implements QuestionsControllerApi { @Override @PutMapping("/isnable") //@RequiresPermissions("qms:questions:isnable") - public R isnable(Integer id) { + public R isNable(Integer id) { boolean b = questionsService.isnable(id); return b ? R.ok() : R.error(); @@ -125,9 +122,6 @@ public class QuestionsController implements QuestionsControllerApi { /** * excel模板文件上传 - * - * @param file - * @return */ @Override @PostMapping("/upload") @@ -139,8 +133,6 @@ public class QuestionsController implements QuestionsControllerApi { /** * excel模板文件下载 - * - * @return */ @Override @GetMapping("/download") diff --git a/src/main/java/com/msdw/tms/entity/EvaluationRulesEntity.java b/src/main/java/com/msdw/tms/entity/EvaluationRulesEntity.java index 88f776e..9f25968 100644 --- a/src/main/java/com/msdw/tms/entity/EvaluationRulesEntity.java +++ b/src/main/java/com/msdw/tms/entity/EvaluationRulesEntity.java @@ -2,17 +2,14 @@ package com.msdw.tms.entity; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; import java.io.Serializable; -import java.util.Date; -import lombok.Data; /** * 测评规则信息记录,只记录一条信息 * * @author gongsj - * @email gongsj@gmail.com - * @date 2020-08-19 09:28:06 */ @Data @TableName("tms_evaluation_rules") diff --git a/src/main/java/com/msdw/tms/entity/QuestionsEntity.java b/src/main/java/com/msdw/tms/entity/QuestionsEntity.java index f6ea702..03600ef 100644 --- a/src/main/java/com/msdw/tms/entity/QuestionsEntity.java +++ b/src/main/java/com/msdw/tms/entity/QuestionsEntity.java @@ -2,17 +2,15 @@ package com.msdw.tms.entity; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; import java.io.Serializable; import java.util.Date; -import lombok.Data; /** * 记录试题信息 * * @author gongsj - * @email gongsj@gmail.com - * @date 2020-08-19 09:28:06 */ @Data @TableName("tms_questions") @@ -25,7 +23,7 @@ public class QuestionsEntity implements Serializable { @TableId private Integer id; /** - * 题型号:用于区分是什么题型 + * 题型号:1、单选题,2、多选题,3、判断题 */ private Integer questionTypeNo; /** diff --git a/src/main/java/com/msdw/tms/entity/XlsxTemplateEntity.java b/src/main/java/com/msdw/tms/entity/XlsxTemplateEntity.java index cb3757a..163a0de 100644 --- a/src/main/java/com/msdw/tms/entity/XlsxTemplateEntity.java +++ b/src/main/java/com/msdw/tms/entity/XlsxTemplateEntity.java @@ -2,17 +2,14 @@ package com.msdw.tms.entity; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; import java.io.Serializable; -import java.util.Date; -import lombok.Data; /** * 模板文件信息记录 * * @author gongsj - * @email gongsj@gmail.com - * @date 2020-08-19 09:28:06 */ @Data @TableName("tms_xlsx_template") diff --git a/src/main/java/com/msdw/tms/entity/request/QuestionsAddRequest.java b/src/main/java/com/msdw/tms/entity/request/QuestionsAddRequest.java index 5d3da9e..8c52299 100644 --- a/src/main/java/com/msdw/tms/entity/request/QuestionsAddRequest.java +++ b/src/main/java/com/msdw/tms/entity/request/QuestionsAddRequest.java @@ -8,8 +8,6 @@ import lombok.Data; * 试题的基本信息表 * * @author gongsj - * @email gongsj@gmail.com - * @date 2020-08-14 16:05:06 */ @Data @ApiModel(value = "QuestionsAddRequest", description = "添加试题请求体对象") @@ -27,32 +25,32 @@ public class QuestionsAddRequest { /** * A选项内容 */ - @ApiModelProperty(value = "A选项内容", name = "optionA", example = "鲸鱼", required = false) + @ApiModelProperty(value = "A选项内容", name = "optionA", example = "鲸鱼") private String optionA; /** * B选项内容 */ - @ApiModelProperty(value = "B选项内容", name = "optionB", example = "鲨鱼", required = false) + @ApiModelProperty(value = "B选项内容", name = "optionB", example = "鲨鱼") private String optionB; /** * C选项内容 */ - @ApiModelProperty(value = "C选项内容", name = "optionC", example = "河马", required = false) + @ApiModelProperty(value = "C选项内容", name = "optionC", example = "河马") private String optionC; /** * D选项内容 */ - @ApiModelProperty(value = "D选项内容", name = "optionD", example = "豹子", required = false) + @ApiModelProperty(value = "D选项内容", name = "optionD", example = "豹子") private String optionD; /** * E选项内容 */ - @ApiModelProperty(value = "E选项内容", name = "optionE", example = "大象", required = false) + @ApiModelProperty(value = "E选项内容", name = "optionE", example = "大象") private String optionE; /** * F选项内容 */ - @ApiModelProperty(value = "F选项内容", name = "optionF", example = "老虎", required = false) + @ApiModelProperty(value = "F选项内容", name = "optionF", example = "老虎") 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; /** * 试题科目 */ - @ApiModelProperty(value = "试题科目", name = "subjects", example = "基础通识", required = false) + @ApiModelProperty(value = "试题科目", name = "subjects", example = "基础通识") private String subjects; } diff --git a/src/main/java/com/msdw/tms/entity/request/QuestionsImportRequest.java b/src/main/java/com/msdw/tms/entity/request/QuestionsImportRequest.java index 6ae49e1..e671e12 100644 --- a/src/main/java/com/msdw/tms/entity/request/QuestionsImportRequest.java +++ b/src/main/java/com/msdw/tms/entity/request/QuestionsImportRequest.java @@ -7,64 +7,58 @@ import lombok.Data; * 试题的基本信息表 * * @author gongsj - * @email gongsj@gmail.com - * @date 2020-08-14 16:05:06 */ @Data public class QuestionsImportRequest { - /** - * 试题科目 - */ - @ExcelAttribute(sort = 0) - private String subjects; + /** * 题干,问题描述 */ - @ExcelAttribute(sort = 1) + @ExcelAttribute(sort = 0) private String questionStem; /** * 题型 */ - @ExcelAttribute(sort = 2) + @ExcelAttribute(sort = 1) private String questionType; /** * 选项A */ - @ExcelAttribute(sort = 3) + @ExcelAttribute(sort = 2) private String optionA; /** * 选项B */ - @ExcelAttribute(sort = 4) + @ExcelAttribute(sort = 3) private String optionB; /** * 选项C */ - @ExcelAttribute(sort = 5) + @ExcelAttribute(sort = 4) private String optionC; /** * 选项D */ - @ExcelAttribute(sort = 6) + @ExcelAttribute(sort = 5) private String optionD; /** * 选项E */ - @ExcelAttribute(sort = 7) + @ExcelAttribute(sort = 6) private String optionE; /** * 选项F */ - @ExcelAttribute(sort = 8) + @ExcelAttribute(sort = 7) private String optionF; /** * 正确答案 */ - @ExcelAttribute(sort = 9) + @ExcelAttribute(sort = 8) private String answer; /** * 答案解析 */ - @ExcelAttribute(sort = 10) + @ExcelAttribute(sort = 9) private String answerAnalysis; } diff --git a/src/main/java/com/msdw/tms/entity/request/QuestionsQueryRequest.java b/src/main/java/com/msdw/tms/entity/request/QuestionsQueryRequest.java index 635285d..f73f4a3 100644 --- a/src/main/java/com/msdw/tms/entity/request/QuestionsQueryRequest.java +++ b/src/main/java/com/msdw/tms/entity/request/QuestionsQueryRequest.java @@ -8,8 +8,6 @@ import lombok.Data; * 试题的基本信息表 * * @author gongsj - * @email gongsj@gmail.com - * @date 2020-08-14 16:05:06 */ @Data @ApiModel(value = "QuestionsQueryRequest", description = "条件查询请求对象") @@ -18,13 +16,14 @@ public class QuestionsQueryRequest { /** * 题干,问题描述 */ - @ApiModelProperty(value = "题干,问题描述", name = "questionStem", example = "世界上最大的哺乳动物是什么?", required = false) + @ApiModelProperty(value = "题干,问题描述", name = "questionStem", example = "世界上最大的哺乳动物是什么?") private String questionStem; - // /** - // * 题型id - // */ - // private Integer questionType; + /** + * 题型id + */ + @ApiModelProperty(value = "题型号:1、单选题,2、多选题,3、判断题", name = "questionTypeNo", example = "1") + private Integer questionTypeNo; // /** // * 参考答案 // */ diff --git a/src/main/java/com/msdw/tms/entity/request/QuestionsUpdateRequest.java b/src/main/java/com/msdw/tms/entity/request/QuestionsUpdateRequest.java index defadbb..494a20c 100644 --- a/src/main/java/com/msdw/tms/entity/request/QuestionsUpdateRequest.java +++ b/src/main/java/com/msdw/tms/entity/request/QuestionsUpdateRequest.java @@ -8,8 +8,6 @@ import lombok.Data; * 试题的基本信息表 * * @author gongsj - * @email gongsj@gmail.com - * @date 2020-08-14 16:05:06 */ @Data @ApiModel(value = "QuestionsUpdateRequest", description = "修改试题请求体对象") @@ -32,32 +30,32 @@ public class QuestionsUpdateRequest { /** * A选项内容 */ - @ApiModelProperty(value = "A选项内容", name = "optionA", example = "鲸鱼", required = false) + @ApiModelProperty(value = "A选项内容", name = "optionA", example = "鲸鱼") private String optionA; /** * B选项内容 */ - @ApiModelProperty(value = "B选项内容", name = "optionB", example = "鲨鱼", required = false) + @ApiModelProperty(value = "B选项内容", name = "optionB", example = "鲨鱼") private String optionB; /** * C选项内容 */ - @ApiModelProperty(value = "C选项内容", name = "optionC", example = "河马", required = false) + @ApiModelProperty(value = "C选项内容", name = "optionC", example = "河马") private String optionC; /** * D选项内容 */ - @ApiModelProperty(value = "D选项内容", name = "optionD", example = "豹子", required = false) + @ApiModelProperty(value = "D选项内容", name = "optionD", example = "豹子") private String optionD; /** * E选项内容 */ - @ApiModelProperty(value = "E选项内容", name = "optionE", example = "大象", required = false) + @ApiModelProperty(value = "E选项内容", name = "optionE", example = "大象") private String optionE; /** * F选项内容 */ - @ApiModelProperty(value = "F选项内容", name = "optionF", example = "老虎", required = false) + @ApiModelProperty(value = "F选项内容", name = "optionF", example = "老虎") 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; /** * 试题科目 */ - @ApiModelProperty(value = "试题科目", name = "subjects", example = "基础通识", required = false) + @ApiModelProperty(value = "试题科目", name = "subjects", example = "基础通识") private String subjects; } diff --git a/src/main/java/com/msdw/tms/entity/response/CommonCode.java b/src/main/java/com/msdw/tms/entity/response/CommonCode.java index 5f33b78..19b0501 100644 --- a/src/main/java/com/msdw/tms/entity/response/CommonCode.java +++ b/src/main/java/com/msdw/tms/entity/response/CommonCode.java @@ -2,13 +2,6 @@ package com.msdw.tms.entity.response; import lombok.ToString; -/** - * @Author: mrt. - * @Description: - * @Date:Created in 2018/1/24 18:33. - * @Modified By: - */ - @ToString public enum CommonCode implements ResultCode { @@ -21,7 +14,6 @@ public enum CommonCode implements ResultCode { QUESTIONTYPE_INVALID(false, 10005, "题型错误!"), FAIL(false, 11111, "操作失败!"), SERVER_ERROR(false, 99999, "抱歉,系统繁忙,请稍后重试!"); - // private static ImmutableMap codes ; //操作是否成功 boolean success; //操作代码 @@ -29,7 +21,7 @@ public enum CommonCode implements ResultCode { //提示信息 String message; - private CommonCode(boolean success, int code, String message) { + CommonCode(boolean success, int code, String message) { this.success = success; this.code = code; this.message = message; diff --git a/src/main/java/com/msdw/tms/entity/response/Response.java b/src/main/java/com/msdw/tms/entity/response/Response.java index 9c159ea..35b841e 100644 --- a/src/main/java/com/msdw/tms/entity/response/Response.java +++ b/src/main/java/com/msdw/tms/entity/response/Response.java @@ -4,6 +4,6 @@ package com.msdw.tms.entity.response; * Created by admin on 2018/3/5. */ public interface Response { - public static final boolean SUCCESS = true; - public static final int SUCCESS_CODE = 10000; + boolean SUCCESS = true; + int SUCCESS_CODE = 10000; } diff --git a/src/main/java/com/msdw/tms/entity/response/ResponseResult.java b/src/main/java/com/msdw/tms/entity/response/ResponseResult.java index 0897404..c05f8ed 100644 --- a/src/main/java/com/msdw/tms/entity/response/ResponseResult.java +++ b/src/main/java/com/msdw/tms/entity/response/ResponseResult.java @@ -4,12 +4,6 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.ToString; -/** - * @Author: mrt. - * @Description: - * @Date:Created in 2018/1/24 18:33. - * @Modified By: - */ @Data @ToString @NoArgsConstructor diff --git a/src/main/java/com/msdw/tms/entity/vo/EvaluationRulesVO.java b/src/main/java/com/msdw/tms/entity/vo/EvaluationRulesVO.java index d8e375e..c331a09 100644 --- a/src/main/java/com/msdw/tms/entity/vo/EvaluationRulesVO.java +++ b/src/main/java/com/msdw/tms/entity/vo/EvaluationRulesVO.java @@ -1,7 +1,5 @@ package com.msdw.tms.entity.vo; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import java.io.Serializable; @@ -10,8 +8,6 @@ import java.io.Serializable; * 测评规则信息记录,只记录一条信息 * * @author gongsj - * @email gongsj@gmail.com - * @date 2020-08-19 09:28:06 */ @Data public class EvaluationRulesVO implements Serializable { diff --git a/src/main/java/com/msdw/tms/entity/vo/EvaluationVO.java b/src/main/java/com/msdw/tms/entity/vo/EvaluationVO.java index c4ce69e..68a8172 100644 --- a/src/main/java/com/msdw/tms/entity/vo/EvaluationVO.java +++ b/src/main/java/com/msdw/tms/entity/vo/EvaluationVO.java @@ -10,8 +10,6 @@ import java.util.Set; * 测评规则信息记录,只记录一条信息 * * @author gongsj - * @email gongsj@gmail.com - * @date 2020-08-19 09:28:06 */ @Data @TableName("tms_evaluation_rules") diff --git a/src/main/java/com/msdw/tms/entity/vo/QuestionsDetailVO.java b/src/main/java/com/msdw/tms/entity/vo/QuestionsDetailVO.java index 43dbb70..9d32676 100644 --- a/src/main/java/com/msdw/tms/entity/vo/QuestionsDetailVO.java +++ b/src/main/java/com/msdw/tms/entity/vo/QuestionsDetailVO.java @@ -3,14 +3,11 @@ package com.msdw.tms.entity.vo; import lombok.Data; import java.io.Serializable; -import java.util.Date; /** * 记录试题信息 * * @author gongsj - * @email gongsj@gmail.com - * @date 2020-08-19 09:28:06 */ @Data public class QuestionsDetailVO implements Serializable { diff --git a/src/main/java/com/msdw/tms/entity/vo/QuestionsVO.java b/src/main/java/com/msdw/tms/entity/vo/QuestionsVO.java index f1342ce..64a5c14 100644 --- a/src/main/java/com/msdw/tms/entity/vo/QuestionsVO.java +++ b/src/main/java/com/msdw/tms/entity/vo/QuestionsVO.java @@ -9,8 +9,6 @@ import java.io.Serializable; * 试题列表展示信息 * * @author gongsj - * @email gongsj@gmail.com - * @date 2020-08-19 09:28:06 */ @Data @ToString diff --git a/src/main/java/com/msdw/tms/service/AliyunOssService.java b/src/main/java/com/msdw/tms/service/AliyunOssService.java index 5c12e80..9833ba4 100644 --- a/src/main/java/com/msdw/tms/service/AliyunOssService.java +++ b/src/main/java/com/msdw/tms/service/AliyunOssService.java @@ -18,15 +18,12 @@ public interface AliyunOssService { /** * 下载文件 * - * @param response * @param objectName 本地路径 */ void downloadFiles(HttpServletResponse response, String objectName) throws IOException; /** * 根据文件路径+文件名称,删除该文件 - * - * @param filename */ void deleteFile(String filename); } diff --git a/src/main/java/com/msdw/tms/service/EvaluationRulesService.java b/src/main/java/com/msdw/tms/service/EvaluationRulesService.java index a9578a3..48f31b9 100644 --- a/src/main/java/com/msdw/tms/service/EvaluationRulesService.java +++ b/src/main/java/com/msdw/tms/service/EvaluationRulesService.java @@ -8,8 +8,6 @@ import com.msdw.tms.entity.vo.EvaluationRulesVO; * 测评规则信息记录,只记录一条信息 * * @author gongsj - * @email gongsj@gmail.com - * @date 2020-08-19 09:28:06 */ public interface EvaluationRulesService extends IService { EvaluationRulesVO getEvaluationRules(); diff --git a/src/main/java/com/msdw/tms/service/XlsxTemplateService.java b/src/main/java/com/msdw/tms/service/XlsxTemplateService.java index 9f36b79..d478256 100644 --- a/src/main/java/com/msdw/tms/service/XlsxTemplateService.java +++ b/src/main/java/com/msdw/tms/service/XlsxTemplateService.java @@ -7,8 +7,6 @@ import com.msdw.tms.entity.XlsxTemplateEntity; * 模板文件信息记录 * * @author gongsj - * @email gongsj@gmail.com - * @date 2020-08-19 09:28:06 */ public interface XlsxTemplateService extends IService { } diff --git a/src/main/java/com/msdw/tms/service/impl/AliyunOssServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/AliyunOssServiceImpl.java index e5acfc7..5a687f4 100644 --- a/src/main/java/com/msdw/tms/service/impl/AliyunOssServiceImpl.java +++ b/src/main/java/com/msdw/tms/service/impl/AliyunOssServiceImpl.java @@ -6,10 +6,10 @@ import com.msdw.tms.common.utils.FilesResult; import com.msdw.tms.config.AliyunOssConfig; import com.msdw.tms.service.AliyunOssService; import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; +import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @@ -19,11 +19,11 @@ import java.io.IOException; @Service public class AliyunOssServiceImpl implements AliyunOssService { - @Autowired - private AliyunOssConfig config; + @Resource + AliyunOssConfig config; - @Autowired - private BeanFactory beanFactory; + @Resource + BeanFactory beanFactory; /** * 上传文件 @@ -38,7 +38,6 @@ public class AliyunOssServiceImpl implements AliyunOssService { /** * 下载文件 * - * @param response * @param objectName 本地路径 */ 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) { OSSClient client = beanFactory.getBean(OSSClient.class); diff --git a/src/main/java/com/msdw/tms/service/impl/EvaluationRulesServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/EvaluationRulesServiceImpl.java index 66afb7d..3977fd4 100644 --- a/src/main/java/com/msdw/tms/service/impl/EvaluationRulesServiceImpl.java +++ b/src/main/java/com/msdw/tms/service/impl/EvaluationRulesServiceImpl.java @@ -12,32 +12,34 @@ import com.msdw.tms.entity.vo.EvaluationRulesVO; import com.msdw.tms.service.EvaluationRulesService; import com.msdw.tms.service.QuestionsService; import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import javax.annotation.Resource; + @Service("evaluationRulesService") public class EvaluationRulesServiceImpl extends ServiceImpl implements EvaluationRulesService { - @Autowired + @Resource QuestionsService questionsService; + //TODO 此表数据可存在redis中,提高系统性能 @Override public EvaluationRulesVO getEvaluationRules() { EvaluationRulesVO evaluationRulesVO = new EvaluationRulesVO(); 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; - if (evaluationRules.getIsSingleEnable() == Constant.IsEnable.ENABLE.getType()) {//启用 + if (evaluationRules.getIsSingleEnable().equals(Constant.IsEnable.ENABLE.getType())) {//启用 totalNum += evaluationRules.getSingleNum(); } - if (evaluationRules.getIsMultipleEnable() == Constant.IsEnable.ENABLE.getType()) {//启用 + if (evaluationRules.getIsMultipleEnable().equals(Constant.IsEnable.ENABLE.getType())) {//启用 totalNum += evaluationRules.getMultipleNum(); } - if (evaluationRules.getIsJudgmentEnable() == Constant.IsEnable.ENABLE.getType()) {//启用 + if (evaluationRules.getIsJudgmentEnable().equals(Constant.IsEnable.ENABLE.getType())) {//启用 totalNum += evaluationRules.getJudgmentNum(); } @@ -76,27 +78,27 @@ public class EvaluationRulesServiceImpl extends ServiceImpl implements QuestionsService { - @Autowired - private AliyunOssService ossService; + @Resource + AliyunOssService ossService; - @Autowired + @Resource XlsxTemplateService xlsxTemplateService; - @Autowired + @Resource EvaluationRulesService evaluationRulesService; /** * 条件加分页查询,题干模糊查询,未删除,修改时间降序 - * - * @param page - * @param size - * @param request - * @return */ @Override public PageUtils queryQuestionsPage(Integer page, Integer size, QuestionsQueryRequest request) { - //请求包装类 + // 请求包装类 QueryWrapper queryWrapper = new QueryWrapper<>(); - //只查询未被删除的试题 + // 只查询未被删除的试题 queryWrapper.eq("is_del", Constant.IsDel.NOT_DEL.getType()); - //判断请求体是否为空 + // 判断请求体是否为空 if (request != null) { // 题干:判断题干是否为空,不为空则加入搜索条件 if (request.getQuestionStem() != null) { queryWrapper.like("question_stem", request.getQuestionStem()); } -// 题型:判断题型是否为空,不为空则加入搜索条件 -// if (questionsRequest.getQuestionType() != null) { -// queryWrapper.eq("question_type", questionsRequest.getQuestionType()); -// } -// 修改时间:判断修改时间是否为空,不为空则加入搜索条件 -// if (questionsRequest.getModifyTime() != null) { -// queryWrapper.eq("modify_time", questionsRequest.getModifyTime()); -// } + // 题型:判断题型是否为空,不为空则加入搜索条件 + if (request.getQuestionTypeNo() != null) { + queryWrapper.eq("question_type_no", request.getQuestionTypeNo()); + } + //TODO 扩展搜索条件 + // 修改时间:判断修改时间是否为空,不为空则加入搜索条件 + // if (request.getModifyTime() != null) { + // queryWrapper.eq("modify_time", request.getModifyTime()); + // } } - //修改时间降序 + // 修改时间降序 queryWrapper.orderByDesc("modify_time"); - IPage questionsEntityIPage = this.page( + IPage questionsIPage = this.page( new Query().getPage(page, size), queryWrapper ); - PageUtils questionsPage = new PageUtils(questionsEntityIPage); - List list = (List) questionsPage.getList(); + List records = questionsIPage.getRecords(); - List collect = list.stream().map(item -> { + List questions = records.stream().map(question -> { QuestionsVO questionsVO = new QuestionsVO(); - BeanUtils.copyProperties(item, questionsVO); + BeanUtils.copyProperties(question, questionsVO); //处理时间格式 - questionsVO.setCreateTime(handleTime(item.getCreateTime())); - questionsVO.setModifyTime(handleTime(item.getModifyTime())); + questionsVO.setCreateTime(handleTime(question.getCreateTime())); + questionsVO.setModifyTime(handleTime(question.getModifyTime())); return questionsVO; }).collect(Collectors.toList()); - questionsPage.setList(collect); + PageUtils questionsPage = new PageUtils(questionsIPage); + + questionsPage.setList(questions); return questionsPage; } @@ -161,9 +157,6 @@ public class QuestionsServiceImpl extends ServiceImpl queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("is_del", Constant.IsDel.NOT_DEL.getType()) + .eq("question_stem", questions.getQuestionStem()); + int count = this.count(queryWrapper); + if (count > 0) {//说明已存在 + //抛出题目已存在异常 + ExceptionCast.cast(CommonCode.QUESTION_EXISTS); } + // 将传入的对象内容拷贝到QuestionsEntity并返回 + QuestionsEntity questionsEntity = getQuestionsEntity(questions); + questionsEntity.setCreateTime(new Date()); questionsEntity.setModifyTime(new Date()); //TODO 创建者和修改者。。。 @@ -208,18 +192,38 @@ public class QuestionsServiceImpl extends ServiceImpl 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是否存在 if (this.getById(questions.getId()) == null) { ExceptionCast.cast(CommonCode.INVALID_PARAM); } + // 将传入的对象内容拷贝到QuestionsEntity并返回 + QuestionsEntity questionsEntity = getQuestionsEntity(questions); + + questionsEntity.setModifyTime(new Date()); + //TODO 设置修改者。。。 + + return this.updateById(questionsEntity); + } + + // 将传入的对象内容拷贝到QuestionsEntity并返回 + private QuestionsEntity getQuestionsEntity(T questions) { QuestionsEntity questionsEntity = new QuestionsEntity(); + BeanUtils.copyProperties(questions, questionsEntity); - String questionType = questions.getQuestionType(); + String questionType = questionsEntity.getQuestionType(); //根据题型名称得到题型号 if (questionType.equals(Constant.QuestionType.SINGLE_CHOICE.getDesc())) { //单选题 @@ -230,23 +234,11 @@ public class QuestionsServiceImpl extends ServiceImpl().eq("question_stem", stem)); - if (count > 0) {//说明已存在 - //抛出题目已存在异常 - ExceptionCast.cast(CommonCode.QUESTION_EXISTS); - } + return questionsEntity; } @Override @@ -255,11 +247,11 @@ public class QuestionsServiceImpl extends ServiceImpl list = new ExcelImportUtil(QuestionsImportRequest.class) - .readExcel(file.getInputStream(), Constant.STARTING_ROW, Constant.STARTING_CELL); + // 使用excel导入工具类获取试题数据列表 + List list = new ExcelImportUtil(QuestionsImportRequest.class).readExcel(file.getInputStream(), Constant.STARTING_ROW, Constant.STARTING_CELL); if (list == null || list.size() == 0) { ExceptionCast.cast(CommonCode.INVALID_PARAM); } - //List unique = persons.stream().collect( - // Collectors.collectingAndThen( - // Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(Person::getName))), ArrayList::new) - //); List collect = list.stream().map(item -> { - int count = this.count(new QueryWrapper().eq("question_stem", item.getQuestionStem())); if (count > 0) {//说明已存在 return null; @@ -323,19 +310,18 @@ public class QuestionsServiceImpl extends ServiceImpl question != null).collect(Collectors.collectingAndThen( + }).filter(Objects::nonNull)// 过滤掉为null的对象 + .collect(Collectors.collectingAndThen(// 去重收集 Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(QuestionsEntity::getQuestionStem))), ArrayList::new )); + // 批量新增 return this.saveBatch(collect); } /** * 上传模板文件,修改模板信息表数据 - * - * @param file - * @return */ @Override @Transactional @@ -356,7 +342,6 @@ public class QuestionsServiceImpl extends ServiceImpl singleChoice = this.list(queryWrapper.eq("question_type_no", Constant.QuestionType.SINGLE_CHOICE.getType())); set.addAll(getRandomList(singleNum, singleChoice)); } - if (evaluationRules.getIsMultipleEnable() == Constant.IsEnable.ENABLE.getType()) { + if (evaluationRules.getIsMultipleEnable().equals(Constant.IsEnable.ENABLE.getType())) { multipleNum = evaluationRules.getMultipleNum(); List multipleChoice = this.list(queryWrapper.eq("question_type_no", Constant.QuestionType.MULTIPLE_CHOICE.getType())); - set.addAll(getRandomList(multipleNum, multipleChoice)); } - if (evaluationRules.getIsJudgmentEnable() == Constant.IsEnable.ENABLE.getType()) { + if (evaluationRules.getIsJudgmentEnable().equals(Constant.IsEnable.ENABLE.getType())) { judgmentNum = evaluationRules.getJudgmentNum(); + List judgments = this.list(queryWrapper.eq("question_type_no", Constant.QuestionType.TRUE_OR_FALSE.getType())); set.addAll(getRandomList(judgmentNum, judgments)); } + // 总题数等于各类题目数量之和 evaluation.setQuestionNum(singleNum + multipleNum + judgmentNum); } Set collect = set.stream().map(item -> { @@ -427,7 +416,7 @@ public class QuestionsServiceImpl extends ServiceImpl getRandomList(int len, List list) { Set set = new HashSet<>(); Random random = new Random(); - int i = 0; + int i; while (true) { i = random.nextInt(list.size()); set.add(list.get(i)); diff --git a/src/main/resources/excel-template/试题导入模板.xlsx b/src/main/resources/excel-template/试题导入模板.xlsx index 4c064f0..30c5e14 100644 Binary files a/src/main/resources/excel-template/试题导入模板.xlsx and b/src/main/resources/excel-template/试题导入模板.xlsx differ diff --git a/src/test/java/com/msdw/tms/TmsApplicationTests.java b/src/test/java/com/msdw/tms/TmsApplicationTests.java index f8576e2..b6f6ef6 100644 --- a/src/test/java/com/msdw/tms/TmsApplicationTests.java +++ b/src/test/java/com/msdw/tms/TmsApplicationTests.java @@ -3,18 +3,15 @@ package com.msdw.tms; import org.junit.jupiter.api.Test; 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 class TmsApplicationTests { @Test void contextLoads() { + printMsg(1, 2, 3, "哈哈哈"); +// ------------------------------------------------------------------------------------------ + // QuestionsVO questionsVO = new QuestionsVO(); // // QuestionsEntity questionsEntity = new QuestionsEntity(); @@ -43,15 +40,44 @@ class TmsApplicationTests { // // 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); + } + + void printMsg(T... args) { + for (T t : args) { + System.out.println("t is " + t); + } + } + + /** + * 泛型方法的基本介绍 + * + * @param tClass 传入的泛型实参 + * @return T 返回值为T类型 + * 说明: + * 1)public 与 返回值中间非常重要,可以理解为声明此方法为泛型方法。 + * 2)只有声明了的方法才是泛型方法,泛型类中的使用了泛型的成员方法并不是泛型方法。 + * 3)表明该方法将使用泛型类型T,此时才可以在方法中使用泛型类型T。 + * 4)与泛型类的定义一样,此处T可以随便写为任意标识,常见的如T、E、K、V等形式的参数常用于表示泛型。 + */ + public T genericMethod(Class tClass) throws InstantiationException, + IllegalAccessException { + T instance = tClass.newInstance(); + return instance; + } - 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); + public T TestG(T t){ + return t; } } diff --git a/src/test/java/com/msdw/tms/service/AliyunOssServiceTest.java b/src/test/java/com/msdw/tms/service/AliyunOssServiceTest.java new file mode 100644 index 0000000..c9583fd --- /dev/null +++ b/src/test/java/com/msdw/tms/service/AliyunOssServiceTest.java @@ -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"); + } +} diff --git a/src/test/java/com/msdw/tms/service/EvaluationRulesServiceTest.java b/src/test/java/com/msdw/tms/service/EvaluationRulesServiceTest.java new file mode 100644 index 0000000..2a9d364 --- /dev/null +++ b/src/test/java/com/msdw/tms/service/EvaluationRulesServiceTest.java @@ -0,0 +1,35 @@ +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; +import org.springframework.transaction.annotation.Transactional; + +/** + * 测评规则信息记录,只记录一条信息 + * + * @author gongsj + */ +@SpringBootTest +class EvaluationRulesServiceTest { + + @Autowired + EvaluationRulesService evaluationRulesService; + + @Test + void getEvaluationRules() { + EvaluationRulesVO evaluationRules = evaluationRulesService.getEvaluationRules(); + System.out.println(evaluationRules.toString()); + } + + @Test + @Transactional + void updateEvaluationRulesById() { + EvaluationRulesEntity evaluationRules = new EvaluationRulesEntity(); + boolean b = evaluationRulesService.updateEvaluationRulesById(evaluationRules); + System.out.println(b); + } +} + diff --git a/src/test/java/com/msdw/tms/service/QuestionsServiceTest.java b/src/test/java/com/msdw/tms/service/QuestionsServiceTest.java new file mode 100644 index 0000000..cf15c5f --- /dev/null +++ b/src/test/java/com/msdw/tms/service/QuestionsServiceTest.java @@ -0,0 +1,128 @@ +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.transaction.annotation.Transactional; +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 + @Transactional + void saveQuestion() { + QuestionsAddRequest questions = new QuestionsAddRequest(); + System.out.println(questionsService.saveQuestion(questions)); + } + + @Test + @Transactional + void updateQuestionById() { + QuestionsUpdateRequest questions = new QuestionsUpdateRequest(); + System.out.println(questionsService.updateQuestionById(questions)); + } + + @Test + @Transactional + void isnable() { + Integer id = 1; + System.out.println(questionsService.isnable(id)); + } + + @Test + @Transactional + void deleteByIds() { + List asList = new ArrayList<>(); + System.out.println(questionsService.deleteByIds(asList)); + } + + @Test + @Transactional + 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()); + } +} +