Browse Source

加入期末成绩模版下载

wangliang 1 year ago
parent
commit
c7c9ba3a8e

+ 21 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/TCScoreEndExam.java

@@ -2,6 +2,7 @@ package com.qmth.distributed.print.business.entity;
 
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.qmth.teachcloud.common.contant.SystemConstant;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
@@ -69,6 +70,26 @@ public class TCScoreEndExam implements Serializable {
     @ApiModelProperty(value = "更新时间")
     private Long updateTime;
 
+    public TCScoreEndExam() {
+
+    }
+
+    public TCScoreEndExam(Long examId, String courseCode, String courseName, String paperNumber, String paperType, String name, String examNumber, Double score, String scoreDetail, Long userId) {
+        this.id = SystemConstant.getDbUuid();
+        this.examId = examId;
+        this.courseCode = courseCode;
+        this.courseName = courseName;
+        this.paperNumber = paperNumber;
+        this.paperType = paperType;
+        this.name = name;
+        this.examNumber = examNumber;
+        this.score = score;
+        this.scoreDetail = scoreDetail;
+        this.enable = true;
+        this.createId = userId;
+        this.createTime = System.currentTimeMillis();
+    }
+
     public Long getId() {
         return id;
     }

+ 20 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/TCScoreNormal.java

@@ -2,6 +2,7 @@ package com.qmth.distributed.print.business.entity;
 
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.qmth.teachcloud.common.contant.SystemConstant;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
@@ -66,6 +67,25 @@ public class TCScoreNormal implements Serializable {
     @ApiModelProperty(value = "更新时间")
     private Long updateTime;
 
+    public TCScoreNormal() {
+
+    }
+
+    public TCScoreNormal(Long examId, String courseCode, String courseName, String paperNumber, String paperType, String name, String examNumber, String scoreNormal, Long userId) {
+        this.id = SystemConstant.getDbUuid();
+        this.examId = examId;
+        this.courseCode = courseCode;
+        this.courseName = courseName;
+        this.paperNumber = paperNumber;
+        this.paperType = paperType;
+        this.name = name;
+        this.examNumber = examNumber;
+        this.scoreNormal = scoreNormal;
+        this.enable = true;
+        this.createId = userId;
+        this.createTime = System.currentTimeMillis();
+    }
+
     public Long getId() {
         return id;
     }

+ 12 - 7
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/TCScoreNormalServiceImpl.java

@@ -24,7 +24,6 @@ import java.io.IOException;
 import java.net.URLEncoder;
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
 import java.util.Random;
 
 /**
@@ -70,18 +69,24 @@ public class TCScoreNormalServiceImpl extends ServiceImpl<TCScoreNormalMapper, T
         response.setContentType(ExcelUtil.DEFALUT_CONTENT_TYPE);
         XSSFSheet sheet = wb.createSheet(sheetName);
 
+        Font headFont = wb.createFont();
+        headFont.setFontHeightInPoints((short) 12);
+        headFont.setFontName("宋体");
+        headFont.setBold(true);
+
         Font defaultFont = wb.createFont();
         defaultFont.setFontHeightInPoints((short) 12);
         defaultFont.setFontName("宋体");
 
-        int cellCount = excelFieldList.size();
-        // 说明
-        XSSFCellStyle describeStyle = wb.createCellStyle();
-        describeStyle.setAlignment(HorizontalAlignment.LEFT);
         Font describeFont = wb.createFont();
         describeFont.setFontHeightInPoints((short) 12);
         describeFont.setFontName("宋体");
         describeFont.setColor(IndexedColors.RED.getIndex());
+
+        int cellCount = excelFieldList.size();
+        // 说明
+        XSSFCellStyle describeStyle = wb.createCellStyle();
+        describeStyle.setAlignment(HorizontalAlignment.LEFT);
         describeStyle.setFont(describeFont);
         describe = describe.trim();
         XSSFRow rowDescribe = sheet.createRow(0);
@@ -101,7 +106,7 @@ public class TCScoreNormalServiceImpl extends ServiceImpl<TCScoreNormalMapper, T
         headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
         headerStyle.setAlignment(HorizontalAlignment.CENTER);
         headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
-        headerStyle.setFont(defaultFont);
+        headerStyle.setFont(headFont);
         XSSFRow rowHead = sheet.createRow(1);
         for (int i = 0; i < excelFieldList.size(); i++) {
             XSSFCell cell = rowHead.createCell(i);
@@ -124,7 +129,7 @@ public class TCScoreNormalServiceImpl extends ServiceImpl<TCScoreNormalMapper, T
         XSSFRow rowExample = sheet.createRow(2);
         for (int i = 0; i < excelFieldList.size(); i++) {
             XSSFCell cell = rowExample.createCell(i);
-            if (Objects.equals("score", excelFieldList.get(i).getCode())) {
+            if (excelFieldList.get(i).getCode().startsWith("score")) {
                 cell.setCellValue(new Random().nextInt(100) + 1);
             } else if (excelFieldList.get(i).getCode().startsWith("key")) {
                 cell.setCellValue(new Random().nextInt(10) + 1);

+ 3 - 4
distributed-print-business/src/main/resources/mapper/TCScoreNormalMapper.xml

@@ -9,12 +9,11 @@
                  t.course_code as courseCode,
                  t.course_name as courseName,
                  t.paper_number as paperNumber,
-                 mq.paper_type as paperType
+                 t.paper_type as paperType
         FROM
-            mark_paper t join mark_question mq on mq.exam_id = t.exam_id and mq.paper_number = t.paper_number
+            mark_paper t
             left join basic_exam be on be.id = t.exam_id
             left join basic_semester bs on bs.id = be.semester_id
-            left join sys_user su on t.user_id = su.id
         <where>
             <if test="semesterId != null and semesterId != ''">
                 and bs.id = #{semesterId}
@@ -27,6 +26,6 @@
             </if>
             AND t.status = 'FINISH'
         </where>
-        ORDER BY t.id desc
+        ORDER BY t.course_code,t.paper_type
     </select>
 </mapper>

+ 7 - 7
distributed-print/install/mysql/upgrade/3.3.1.sql

@@ -124,7 +124,7 @@ CREATE TABLE `t_c_paper_positive` (
                                       `course_name` varchar(100) COLLATE utf8mb4_general_ci NOT NULL COMMENT '课程名称',
                                       `paper_number` varchar(100) COLLATE utf8mb4_general_ci NOT NULL COMMENT '试卷编码',
                                       `paper_type` varchar(50) COLLATE utf8mb4_general_ci NOT NULL COMMENT '试卷类型',
-                                      `paper_struct` json NOT NULL COMMENT '试卷结构',
+                                      `paper_struct` mediumtext NOT NULL COMMENT '试卷结构',
                                       `enable` tinyint NOT NULL DEFAULT '1' COMMENT '是否启用,0:停用,1:启用',
                                       `create_id` bigint DEFAULT NULL COMMENT '创建人id',
                                       `create_time` bigint DEFAULT NULL COMMENT '创建时间',
@@ -144,7 +144,7 @@ CREATE TABLE `t_c_score_end_exam` (
                                       `name` varchar(100) COLLATE utf8mb4_general_ci NOT NULL COMMENT '考生姓名',
                                       `exam_number` varchar(100) COLLATE utf8mb4_general_ci NOT NULL COMMENT '学号',
                                       `score` double NOT NULL COMMENT '分数',
-                                      `score_detail` json NOT NULL COMMENT '成绩明细',
+                                      `score_detail` mediumtext NOT NULL COMMENT '成绩明细',
                                       `enable` tinyint NOT NULL DEFAULT '1' COMMENT '是否启用,0:停用,1:启用',
                                       `create_id` bigint DEFAULT NULL COMMENT '创建人id',
                                       `create_time` bigint DEFAULT NULL COMMENT '创建时间',
@@ -163,7 +163,7 @@ CREATE TABLE `t_c_score_normal` (
                                     `paper_type` varchar(50) COLLATE utf8mb4_general_ci NOT NULL COMMENT '试卷类型',
                                     `name` varchar(100) COLLATE utf8mb4_general_ci NOT NULL COMMENT '考生姓名',
                                     `exam_number` varchar(100) COLLATE utf8mb4_general_ci NOT NULL COMMENT '学号',
-                                    `score_normal` json NOT NULL COMMENT '平常作业分数',
+                                    `score_normal` mediumtext NOT NULL COMMENT '平常作业分数',
                                     `enable` tinyint NOT NULL DEFAULT '1' COMMENT '是否启用,0:停用,1:启用',
                                     `create_id` bigint DEFAULT NULL COMMENT '创建人id',
                                     `create_time` bigint DEFAULT NULL COMMENT '创建时间',
@@ -195,9 +195,9 @@ CREATE TABLE `t_r_basic_info` (
                                   `create_time` bigint DEFAULT NULL COMMENT '创建时间',
                                   `update_id` bigint DEFAULT NULL COMMENT '更新人id',
                                   `update_time` bigint DEFAULT NULL COMMENT '更新时间',
-                                  `course_evaluation_spread` json DEFAULT NULL COMMENT '课程目标考核分布',
-                                  `course_evaluation_result` json DEFAULT NULL COMMENT '课程考核成绩评价结果',
-                                  `course_evaluation_result_detail` json DEFAULT NULL COMMENT '课程考核成绩评价明细结果',
+                                  `course_evaluation_spread` mediumtext DEFAULT NULL COMMENT '课程目标考核分布',
+                                  `course_evaluation_result` mediumtext DEFAULT NULL COMMENT '课程考核成绩评价结果',
+                                  `course_evaluation_result_detail` mediumtext DEFAULT NULL COMMENT '课程考核成绩评价明细结果',
                                   PRIMARY KEY (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='报告基本情况表';
 
@@ -209,6 +209,6 @@ CREATE TABLE `t_r_exam_student` (
                                     `name` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '考生姓名',
                                     `exam_number` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '学号',
                                     `clazz` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '行政班级',
-                                    `result_detail` json DEFAULT NULL COMMENT '考生课程考核成绩评价明细结果',
+                                    `result_detail` mediumtext DEFAULT NULL COMMENT '考生课程考核成绩评价明细结果',
                                     PRIMARY KEY (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='报告考生表';

+ 8 - 1
distributed-print/src/main/java/com/qmth/distributed/print/api/TCScoreEndExamController.java

@@ -9,6 +9,8 @@ import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.enums.log.CustomizedOperationTypeEnum;
 import com.qmth.teachcloud.common.util.ResultUtil;
 import io.swagger.annotations.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -31,6 +33,7 @@ import java.util.List;
 @RestController
 @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_COURSE_DEGREE)
 public class TCScoreEndExamController {
+    private final static Logger log = LoggerFactory.getLogger(TCScoreEndExamController.class);
 
     @Resource
     TCScoreNormalService tcScoreNormalService;
@@ -59,7 +62,11 @@ public class TCScoreEndExamController {
     @RequestMapping(value = "/score/end_exam/import", method = RequestMethod.POST)
     @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.IMPORT)
     @ApiResponses({@ApiResponse(code = 200, message = "导入成功", response = EditResult.class)})
-    public Object scoreEndExamImport(@ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file) throws IOException {
+    public Object scoreEndExamImport(@ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file,
+                                     @ApiParam(value = "考试id", required = true) @RequestParam Long examId,
+                                     @ApiParam(value = "科目编码", required = true) @RequestParam String courseCode,
+                                     @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber,
+                                     @ApiParam(value = "试卷类型", required = true) @RequestParam String paperType) throws IOException {
         return ResultUtil.ok(true);
     }
 

+ 56 - 4
distributed-print/src/main/java/com/qmth/distributed/print/api/TCScoreNormalController.java

@@ -1,15 +1,26 @@
 package com.qmth.distributed.print.api;
 
+import com.alibaba.excel.EasyExcel;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.distributed.print.business.bean.excel.ExcelField;
 import com.qmth.distributed.print.business.bean.result.EditResult;
+import com.qmth.distributed.print.business.entity.TCScoreNormal;
 import com.qmth.distributed.print.business.service.TCScoreNormalService;
 import com.qmth.teachcloud.common.annotation.OperationLogDetail;
 import com.qmth.teachcloud.common.contant.SystemConstant;
+import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.enums.log.CustomizedOperationTypeEnum;
+import com.qmth.teachcloud.common.util.JacksonUtil;
 import com.qmth.teachcloud.common.util.ResultUtil;
+import com.qmth.teachcloud.common.util.ServletUtil;
+import com.qmth.teachcloud.mark.entity.MarkPaper;
+import com.qmth.teachcloud.mark.service.MarkPaperService;
 import io.swagger.annotations.*;
+import org.apache.commons.codec.digest.DigestUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
@@ -20,8 +31,7 @@ import javax.annotation.Resource;
 import javax.validation.constraints.Max;
 import javax.validation.constraints.Min;
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
 
 /**
  * <p>
@@ -35,10 +45,14 @@ import java.util.List;
 @RestController
 @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_COURSE_DEGREE)
 public class TCScoreNormalController {
+    private final static Logger log = LoggerFactory.getLogger(TCScoreNormalController.class);
 
     @Resource
     TCScoreNormalService tcScoreNormalService;
 
+    @Resource
+    MarkPaperService markPaperService;
+
     @ApiOperation(value = "成绩管理列表")
     @RequestMapping(value = "/score/list", method = RequestMethod.POST)
     @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.SEARCH)
@@ -75,8 +89,46 @@ public class TCScoreNormalController {
     @RequestMapping(value = "/score/import", method = RequestMethod.POST)
     @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.IMPORT)
     @ApiResponses({@ApiResponse(code = 200, message = "导入成功", response = EditResult.class)})
-    public Object scoreImport(@ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file) throws IOException {
-        return ResultUtil.ok(true);
+    @Transactional
+    public Object scoreImport(@ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file,
+                              @ApiParam(value = "考试id", required = true) @RequestParam Long examId,
+                              @ApiParam(value = "科目编码", required = true) @RequestParam String courseCode,
+                              @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber,
+                              @ApiParam(value = "试卷类型", required = true) @RequestParam String paperType) throws IOException {
+        log.debug("导入Excel开始...");
+        long start = System.currentTimeMillis();
+        String reqFileMd5 = ServletUtil.getRequestMd5();
+        String fileMd5 = DigestUtils.md5Hex(file.getBytes());
+        if (!Objects.equals(fileMd5, reqFileMd5)) {
+            throw ExceptionResultEnum.MD5_EQUALS_FALSE.exception();
+        }
+        MarkPaper markPaper = markPaperService.getByExamIdAndPaperNumberAndPaperType(examId, paperNumber, paperType);
+        Objects.requireNonNull(markPaper, "未找到科目信息");
+
+        List<Map<String, String>> list = null;
+        try {
+            StringJoiner errorData = new StringJoiner("");
+            list = EasyExcel.read(file.getInputStream()).headRowNumber(1).sheet(0).doReadSync();
+            List<TCScoreNormal> tcScoreNormalList = new ArrayList<>(list.size());
+            log.info("list:{}", JacksonUtil.parseJson(list));
+            Map<String, String> headMap = list.get(0);
+            log.info("headMap:{}", JacksonUtil.parseJson(headMap));
+            for (int i = 1; i < list.size(); i++) {
+                Map<String, String> objectMap = list.get(i);
+                for (Map.Entry<String, String> entry : objectMap.entrySet()) {
+                    if (Objects.isNull(entry) || Objects.equals(entry, "")) {
+                        errorData.add("第" + i + "行").add(headMap.get(entry.getKey()) + "为空\n");
+                    }
+                }
+                log.info("objectMap:{}", JacksonUtil.parseJson(objectMap));
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        log.debug("导入Excel结束...");
+        long end = System.currentTimeMillis();
+        log.info("============耗时{}秒============:", (end - start) / 1000);
+        return ResultUtil.ok(list);
     }
 
     @ApiOperation(value = "平时成绩列表")

+ 11 - 5
pom.xml

@@ -55,6 +55,7 @@
         <zip4j.version>1.3.3</zip4j.version>
         <nanoid.version>2.0.0</nanoid.version>
 <!--        <jasypt.version>3.0.3</jasypt.version>-->
+        <easyexcel.version>3.0.5</easyexcel.version>
     </properties>
 
     <dependencyManagement>
@@ -164,11 +165,11 @@
                 <artifactId>core-sms</artifactId>
                 <version>${qmth.boot.version}</version>
             </dependency>
-            <dependency>
-                <groupId>com.qmth.boot</groupId>
-                <artifactId>tools-poi</artifactId>
-                <version>${qmth.boot.version}</version>
-            </dependency>
+<!--            <dependency>-->
+<!--                <groupId>com.qmth.boot</groupId>-->
+<!--                <artifactId>tools-poi</artifactId>-->
+<!--                <version>${qmth.boot.version}</version>-->
+<!--            </dependency>-->
 <!--            <dependency>-->
 <!--                <groupId>io.springfox</groupId>-->
 <!--                <artifactId>springfox-swagger-ui</artifactId>-->
@@ -378,6 +379,11 @@
                 <artifactId>mybatisplus-plus</artifactId>
                 <version>1.5.1-RELEASE</version>
             </dependency>
+            <dependency>
+                <groupId>com.alibaba</groupId>
+                <artifactId>easyexcel</artifactId>
+                <version>${easyexcel.version}</version>
+            </dependency>
         </dependencies>
     </dependencyManagement>
 

+ 8 - 4
teachcloud-common/pom.xml

@@ -54,10 +54,10 @@
             <groupId>com.qmth.boot</groupId>
             <artifactId>core-sms</artifactId>
         </dependency>
-        <dependency>
-            <groupId>com.qmth.boot</groupId>
-            <artifactId>tools-poi</artifactId>
-        </dependency>
+<!--        <dependency>-->
+<!--            <groupId>com.qmth.boot</groupId>-->
+<!--            <artifactId>tools-poi</artifactId>-->
+<!--        </dependency>-->
         <dependency>
             <groupId>io.netty</groupId>
             <artifactId>netty-all</artifactId>
@@ -181,5 +181,9 @@
             <groupId>com.github.jeffreyning</groupId>
             <artifactId>mybatisplus-plus</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>easyexcel</artifactId>
+        </dependency>
     </dependencies>
 </project>