Procházet zdrojové kódy

1.1.0 update-20250101导出重命名

xiaofei před 6 měsíci
rodič
revize
9bd8a59e59

+ 40 - 2
pom.xml

@@ -11,7 +11,7 @@
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <maven.compiler.source>1.8</maven.compiler.source>
         <maven.compiler.target>1.8</maven.compiler.target>
-        <qmth.boot.version>1.0.4</qmth.boot.version>
+        <qmth.boot.version>1.0.5</qmth.boot.version>
         <java.version>1.8</java.version>
         <swagger2.version>2.9.2</swagger2.version>
         <fastjson.version>1.2.68</fastjson.version>
@@ -23,7 +23,7 @@
         <gson.version>2.8.6</gson.version>
         <commons.version>3.10</commons.version>
         <commons.codec.version>1.15</commons.codec.version>
-        <commons-io.version>2.6</commons-io.version>
+        <commons-io.version>2.11.0</commons-io.version>
         <jackson.version>2.11.0</jackson.version>
         <swagger2-bootstrap.version>1.9.6</swagger2-bootstrap.version>
         <version-plugin.version>2.8.1</version-plugin.version>
@@ -37,6 +37,8 @@
         <bcprov.version>1.52</bcprov.version>
         <googlecode.aviator.version>5.0.1</googlecode.aviator.version>
         <dysmsapi.version>1.1.0</dysmsapi.version>
+        <poi.version>5.2.2</poi.version>
+        <poi-ooxml-schemas.version>4.1.2</poi-ooxml-schemas.version>
     </properties>
 
     <dependencyManagement>
@@ -76,6 +78,11 @@
                 <artifactId>core-solar</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.github.xiaoymin</groupId>
                 <artifactId>knife4j-spring-boot-starter</artifactId>
@@ -204,6 +211,21 @@
                 <artifactId>aviator</artifactId>
                 <version>${googlecode.aviator.version}</version>
             </dependency>
+            <dependency>
+                <groupId>org.apache.poi</groupId>
+                <artifactId>poi-ooxml</artifactId>
+                <version>${poi.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.poi</groupId>
+                <artifactId>poi-ooxml-schemas</artifactId>
+                <version>${poi-ooxml-schemas.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.poi</groupId>
+                <artifactId>poi</artifactId>
+                <version>${poi.version}</version>
+            </dependency>
         </dependencies>
     </dependencyManagement>
 
@@ -248,6 +270,10 @@
             <groupId>com.qmth.boot</groupId>
             <artifactId>core-solar</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.qmth.boot</groupId>
+            <artifactId>tools-poi</artifactId>
+        </dependency>
         <dependency>
             <groupId>com.github.xiaoymin</groupId>
             <artifactId>knife4j-spring-boot-starter</artifactId>
@@ -350,6 +376,18 @@
             <groupId>com.googlecode.aviator</groupId>
             <artifactId>aviator</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi-ooxml</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi-ooxml-schemas</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi</artifactId>
+        </dependency>
     </dependencies>
 
     <build>

+ 5 - 4
src/main/java/com/qmth/eds/api/ExamAssignController.java

@@ -163,7 +163,7 @@ public class ExamAssignController {
     }
 
     /**
-     * 下载
+     * 导出
      *
      * @param semesterId  学期
      * @param examTypeId  考试类型
@@ -172,14 +172,15 @@ public class ExamAssignController {
      * @param openCollege 开课学院
      * @param response    response
      */
-    @ApiOperation(value = "下载赋分成绩")
+    @ApiOperation(value = "导出赋分成绩")
     @PostMapping("/download")
-    public void page(@RequestParam(value = "semesterId", required = false) Long semesterId,
+    public void page(@RequestParam(value = "id", required = false) Long id,
+                     @RequestParam(value = "semesterId", required = false) Long semesterId,
                      @RequestParam(value = "examTypeId", required = false) Long examTypeId,
                      @RequestParam(value = "collegeId", required = false) Long collegeId,
                      @RequestParam(value = "courseCode", required = false) String courseCode,
                      @RequestParam(value = "openCollege", required = false) String openCollege,
                      HttpServletResponse response) {
-        examAssignService.download(semesterId, examTypeId, collegeId, courseCode, openCollege, response);
+        examAssignService.download(id, semesterId, examTypeId, collegeId, courseCode, openCollege, response);
     }
 }

+ 14 - 13
src/main/java/com/qmth/eds/bean/dto/ScoreDownloadDto.java

@@ -1,36 +1,37 @@
 package com.qmth.eds.bean.dto;
 
 import com.alibaba.excel.annotation.ExcelProperty;
+import com.qmth.boot.tools.excel.annotation.ExcelColumn;
 import com.qmth.eds.common.enums.FormulaEnum;
 
 public class ScoreDownloadDto {
 
-    @ExcelProperty("学期名称(系统)")
+    @ExcelColumn(name = "学期名称(系统)", index = 0)
     private String semesterName;
 
-    @ExcelProperty("考试类型(系统)")
+    @ExcelColumn(name = "考试类型(系统)", index = 1)
     private String examTypeName;
-    @ExcelProperty("学年")
+    @ExcelColumn(name = "学年", index = 2)
     private String xnm;
-    @ExcelProperty("学期")
+    @ExcelColumn(name = "学期", index = 3)
     private String xqm;
-    @ExcelProperty("课程号")
+    @ExcelColumn(name = "课程号", index = 4)
     private String kch;
-    @ExcelProperty("课程名称")
+    @ExcelColumn(name = "课程名称", index = 5)
     private String kcmc;
-    @ExcelProperty("开课学院")
+    @ExcelColumn(name = "开课学院", index = 6)
     private String kkbm;
-    @ExcelProperty("学号")
+    @ExcelColumn(name = "学号", index = 7)
     private String xh;
-    @ExcelProperty("学生姓名")
+    @ExcelColumn(name = "学生姓名", index = 8)
     private String xsxm;
-    @ExcelProperty("学院")
+    @ExcelColumn(name = "学院", index = 9)
     private String jgmc;
-    @ExcelProperty("原始成绩")
+    @ExcelColumn(name = "原始成绩", index = 10)
     private String totalScore;
-    @ExcelProperty("赋分成绩")
+    @ExcelColumn(name = "赋分成绩", index = 11)
     private String assignScore;
-    @ExcelProperty("是否关联考务数据")
+    @ExcelColumn(name = "是否关联考务数据", index = 12)
     private String relateExamData;
 
     public String getSemesterName() {

+ 1 - 1
src/main/java/com/qmth/eds/service/ExamAssignService.java

@@ -50,5 +50,5 @@ public interface ExamAssignService extends IService<ExamAssign> {
 
     boolean publish(Long id, Long semesterId, Long examTypeId, Long collegeId, String syncCourseCode, String courseCode, String courseName, String openCollege);
 
-    void download(Long semesterId, Long examTypeId, Long collegeId, String courseCode, String openCollege, HttpServletResponse response);
+    void download(Long id, Long semesterId, Long examTypeId, Long collegeId, String courseCode, String openCollege, HttpServletResponse response);
 }

+ 35 - 14
src/main/java/com/qmth/eds/service/impl/ExamAssignServiceImpl.java

@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.boot.tools.excel.ExcelWriter;
+import com.qmth.boot.tools.excel.enums.ExcelType;
 import com.qmth.eds.bean.dto.ExamAssignDto;
 import com.qmth.eds.bean.dto.ScoreDownloadDto;
 import com.qmth.eds.bean.result.AssignResultPreviewResult;
@@ -20,6 +22,9 @@ import com.qmth.eds.mapper.ExamAssignMapper;
 import com.qmth.eds.service.*;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.FillPatternType;
+import org.apache.poi.ss.usermodel.IndexedColors;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -27,6 +32,8 @@ import org.springframework.transaction.annotation.Transactional;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 import java.io.File;
+import java.io.IOException;
+import java.net.URLEncoder;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -245,23 +252,37 @@ public class ExamAssignServiceImpl extends ServiceImpl<ExamAssignMapper, ExamAss
     }
 
     @Override
-    public void download(Long semesterId, Long examTypeId, Long collegeId, String courseCode, String openCollege, HttpServletResponse response) {
+    public void download(Long id, Long semesterId, Long examTypeId, Long collegeId, String courseCode, String openCollege, HttpServletResponse response) {
         Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
-        File file = null;
         try {
-            List<ScoreDownloadDto> scoreDownloadDtoList = cloudMarkingScoreService.listScoreBySemesterIdAndExamTypeIdAndCollegeIdAndCourseCodeAndOpenCollege(semesterId, examTypeId, collegeId, courseCode, openCollege);
-            String fileName = "file-folder" + File.separator + schoolId + File.separator + System.currentTimeMillis() + ".xlsx";
-            file = new File(fileName);
-            if (!file.exists()) {
-                file.getParentFile().mkdirs();
-            }
-            EasyExcel.write(fileName, ScoreDownloadDto.class).sheet("赋分成绩数据").doWrite(scoreDownloadDtoList);
-            FileUtil.outputFile(response, file, file.getName());
-        } finally {
-            if (file != null && file.exists()) {
-                file.delete();
+            String fileNamePrefix = "批量导出" + System.currentTimeMillis();
+            if (id != null) {
+                ExamAssign examAssign = this.getById(id);
+                if (examAssign != null) {
+                    fileNamePrefix = examAssign.getCourseName() + "(" + examAssign.getCourseCode() + ")";
+                }
             }
-        }
+            List<ScoreDownloadDto> scoreDownloadDtoList = cloudMarkingScoreService.listScoreBySemesterIdAndExamTypeIdAndCollegeIdAndCourseCodeAndOpenCollege(semesterId, examTypeId, collegeId, courseCode, openCollege);
+            response.setHeader("Content-Disposition",
+                    "inline;filename=" + URLEncoder.encode(fileNamePrefix, SystemConstant.CHARSET_NAME) + ".xlsx");
+            response.setContentType("application/vnd.ms-excel");
+            ExcelWriter writer = ExcelWriter.create(ExcelType.XLSX);
+
+            String sheetName = "赋分成绩数据";
+            // 设置样式
+            CellStyle cellStyle1 = writer.createCellStyle();
+            org.apache.poi.ss.usermodel.Font font1 = writer.createFont();
+            font1.setBold(true);
+            font1.setFontHeightInPoints((short) 18);
+            cellStyle1.setFont(font1);
+            cellStyle1.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
+//            cellStyle1.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+            writer.setCellStyle(sheetName, cellStyle1, 0, new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
 
+            writer.writeObjects(sheetName, null, ScoreDownloadDto.class, scoreDownloadDtoList.listIterator());
+            writer.output(response.getOutputStream());
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
     }
 }

+ 2 - 2
src/main/java/com/qmth/eds/service/impl/WhuDataSyncServiceImpl.java

@@ -564,7 +564,7 @@ public class WhuDataSyncServiceImpl implements WhuDataSyncService {
         }
         // 赋分后如果小于54.5的取原始分值
         else if (open54d5 && intValue < 54.5) {
-            return String.valueOf(studentScore);
+            return new BigDecimal(studentScore).stripTrailingZeros().toPlainString();
         } else {
             return assignScore;
         }
@@ -575,7 +575,7 @@ public class WhuDataSyncServiceImpl implements WhuDataSyncService {
         double doubleValue = new BigDecimal(assignScore).setScale(0, RoundingMode.FLOOR).doubleValue();
         // 赋分后小于原始分值取原始分值
         if (openFetchOriginScore && doubleValue < studentScore) {
-            return String.valueOf(studentScore);
+            return new BigDecimal(studentScore).stripTrailingZeros().toPlainString();
         } else {
             return assignScore;
         }

+ 1 - 1
src/test/java/com/qmth/eds/WhuTest.java

@@ -45,7 +45,7 @@ public class WhuTest {
 
     @Test
     public void download(){
-        examAssignService.download(323866074581827584l, 323866121386065920l, 7l, "100830011001", null, null);
+        examAssignService.download(null,323866074581827584l, 323866121386065920l, 7l, "100830011001", null, null);
     }
 
 }