Bladeren bron

1.0.4 赋分成绩导出

xiaofei 2 jaren geleden
bovenliggende
commit
0799240c30

+ 22 - 0
src/main/java/com/qmth/eds/api/ExamAssignController.java

@@ -20,6 +20,7 @@ import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
 import javax.validation.constraints.Max;
 import javax.validation.constraints.Min;
 import java.math.BigDecimal;
@@ -156,4 +157,25 @@ public class ExamAssignController {
         }
         return ResultUtil.ok(Objects.isNull(assignContrastResult) ? new AssignContrastResult() : assignContrastResult);
     }
+
+    /**
+     * 下载
+     *
+     * @param semesterId  学期
+     * @param examTypeId  考试类型
+     * @param collegeId   学院ID
+     * @param courseCode  课程代码
+     * @param openCollege 开课学院
+     * @param response    response
+     */
+    @ApiOperation(value = "下载赋分成绩")
+    @PostMapping("/download")
+    public void page(@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);
+    }
 }

+ 9 - 0
src/main/java/com/qmth/eds/bean/dto/CloudMarkingScoreDto.java

@@ -34,6 +34,7 @@ public class CloudMarkingScoreDto implements Serializable {
     private String status;
 
     private String totalScore;
+    private String assignScore;
 
     private String objectiveScore;
 
@@ -143,6 +144,14 @@ public class CloudMarkingScoreDto implements Serializable {
         this.totalScore = totalScore;
     }
 
+    public String getAssignScore() {
+        return assignScore;
+    }
+
+    public void setAssignScore(String assignScore) {
+        this.assignScore = assignScore;
+    }
+
     public String getObjectiveScore() {
         return objectiveScore;
     }

+ 129 - 0
src/main/java/com/qmth/eds/bean/dto/ScoreDownloadDto.java

@@ -0,0 +1,129 @@
+package com.qmth.eds.bean.dto;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.qmth.eds.common.enums.FormulaEnum;
+
+public class ScoreDownloadDto {
+
+    @ExcelProperty("学期名称(系统)")
+    private String semesterName;
+
+    @ExcelProperty("考试类型(系统)")
+    private String examTypeName;
+    @ExcelProperty("学年")
+    private String xnm;
+    @ExcelProperty("学期")
+    private String xqm;
+    @ExcelProperty("课程号")
+    private String kch;
+    @ExcelProperty("课程名称")
+    private String kcmc;
+    @ExcelProperty("开课学院")
+    private String kkbm;
+    @ExcelProperty("学号")
+    private String xh;
+    @ExcelProperty("学生姓名")
+    private String xsxm;
+    @ExcelProperty("学院")
+    private String jgmc;
+    @ExcelProperty("原始成绩")
+    private String totalScore;
+    @ExcelProperty("赋分成绩")
+    private String assignScore;
+
+    public String getSemesterName() {
+        return semesterName;
+    }
+
+    public void setSemesterName(String semesterName) {
+        this.semesterName = semesterName;
+    }
+
+    public String getExamTypeName() {
+        return examTypeName;
+    }
+
+    public void setExamTypeName(String examTypeName) {
+        this.examTypeName = examTypeName;
+    }
+
+    public String getXnm() {
+        return xnm;
+    }
+
+    public void setXnm(String xnm) {
+        this.xnm = xnm;
+    }
+
+    public String getXqm() {
+        return xqm;
+    }
+
+    public void setXqm(String xqm) {
+        this.xqm = xqm;
+    }
+
+    public String getKch() {
+        return kch;
+    }
+
+    public void setKch(String kch) {
+        this.kch = kch;
+    }
+
+    public String getKcmc() {
+        return kcmc;
+    }
+
+    public void setKcmc(String kcmc) {
+        this.kcmc = kcmc;
+    }
+
+    public String getKkbm() {
+        return kkbm;
+    }
+
+    public void setKkbm(String kkbm) {
+        this.kkbm = kkbm;
+    }
+
+    public String getXh() {
+        return xh;
+    }
+
+    public void setXh(String xh) {
+        this.xh = xh;
+    }
+
+    public String getXsxm() {
+        return xsxm;
+    }
+
+    public void setXsxm(String xsxm) {
+        this.xsxm = xsxm;
+    }
+
+    public String getJgmc() {
+        return jgmc;
+    }
+
+    public void setJgmc(String jgmc) {
+        this.jgmc = jgmc;
+    }
+
+    public String getTotalScore() {
+        return totalScore;
+    }
+
+    public void setTotalScore(String totalScore) {
+        this.totalScore = totalScore;
+    }
+
+    public String getAssignScore() {
+        return assignScore;
+    }
+
+    public void setAssignScore(String assignScore) {
+        this.assignScore = assignScore;
+    }
+}

+ 3 - 0
src/main/java/com/qmth/eds/mapper/CloudMarkingScoreMapper.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.qmth.eds.bean.dto.CloudMarkingScoreDto;
 import com.qmth.eds.bean.dto.ExamSyncStudentDto;
+import com.qmth.eds.bean.dto.ScoreDownloadDto;
 import com.qmth.eds.bean.result.StudentMarkResult;
 import com.qmth.eds.common.entity.CloudMarkingScore;
 import org.apache.ibatis.annotations.Param;
@@ -37,4 +38,6 @@ public interface CloudMarkingScoreMapper extends BaseMapper<CloudMarkingScore> {
                                              @Param("examTypeId") Long examTypeId,
                                              @Param("openCollege") String openCollege,
                                              @Param("courseCode") String courseCode);
+
+    List<ScoreDownloadDto> listScoreBySemesterIdAndExamTypeIdAndCollegeIdAndCourseCodeAndOpenCollege(@Param("semesterId") Long semesterId, @Param("examTypeId") Long examTypeId, @Param("collegeId") Long collegeId, @Param("courseCode") String courseCode, @Param("openCollege") String openCollege);
 }

+ 3 - 0
src/main/java/com/qmth/eds/service/CloudMarkingScoreService.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.eds.bean.dto.CloudMarkingScoreDto;
 import com.qmth.eds.bean.dto.ExamSyncStudentDto;
+import com.qmth.eds.bean.dto.ScoreDownloadDto;
 import com.qmth.eds.bean.result.StudentMarkResult;
 import com.qmth.eds.common.entity.CloudMarkingScore;
 
@@ -34,4 +35,6 @@ public interface CloudMarkingScoreService extends IService<CloudMarkingScore> {
                                              Long collegeId,
                                              String openCollege,
                                              String courseCode);
+
+    List<ScoreDownloadDto> listScoreBySemesterIdAndExamTypeIdAndCollegeIdAndCourseCodeAndOpenCollege(Long semesterId, Long examTypeId, Long collegeId, String courseCode, String openCollege);
 }

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

@@ -6,6 +6,7 @@ import com.qmth.eds.bean.dto.ExamAssignDto;
 import com.qmth.eds.bean.result.AssignResultPreviewResult;
 import com.qmth.eds.common.entity.ExamAssign;
 
+import javax.servlet.http.HttpServletResponse;
 import java.util.Map;
 
 /**
@@ -46,4 +47,6 @@ public interface ExamAssignService extends IService<ExamAssign> {
     ExamAssignDto toCalc(Long semesterId, Long examTypeId, Long collegeId, String courseCode, String courseName, String openCollege);
 
     boolean publish(Long id, Long semesterId, Long examTypeId, Long collegeId, String courseCode, String courseName, String openCollege);
+
+    void download(Long semesterId, Long examTypeId, Long collegeId, String courseCode, String openCollege, HttpServletResponse response);
 }

+ 6 - 1
src/main/java/com/qmth/eds/service/impl/CloudMarkingScoreServiceImpl.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.eds.bean.dto.CloudMarkingScoreDto;
 import com.qmth.eds.bean.dto.ExamSyncStudentDto;
+import com.qmth.eds.bean.dto.ScoreDownloadDto;
 import com.qmth.eds.bean.result.StudentMarkResult;
 import com.qmth.eds.common.entity.CloudMarkingScore;
 import com.qmth.eds.common.entity.SysUser;
@@ -36,7 +37,6 @@ public class CloudMarkingScoreServiceImpl extends ServiceImpl<CloudMarkingScoreM
 
     @Override
     public IPage<CloudMarkingScoreDto> pageData(Long collegeId, Long semesterId, Long examTypeId, String examId, Integer pageNumber, Integer pageSize) {
-        Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
         Page<CloudMarkingScoreDto> page = new Page<>(pageNumber, pageSize);
         return this.baseMapper.pageData(page, collegeId, semesterId, examTypeId, examId);
     }
@@ -60,4 +60,9 @@ public class CloudMarkingScoreServiceImpl extends ServiceImpl<CloudMarkingScoreM
         Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
         return cloudMarkingScoreMapper.queryStudentMark(schoolId, collegeId, semesterId, examTypeId, openCollege, courseCode);
     }
+
+    @Override
+    public List<ScoreDownloadDto> listScoreBySemesterIdAndExamTypeIdAndCollegeIdAndCourseCodeAndOpenCollege(Long semesterId, Long examTypeId, Long collegeId, String courseCode, String openCollege) {
+        return this.baseMapper.listScoreBySemesterIdAndExamTypeIdAndCollegeIdAndCourseCodeAndOpenCollege(semesterId, examTypeId, collegeId, courseCode, openCollege);
+    }
 }

+ 29 - 1
src/main/java/com/qmth/eds/service/impl/ExamAssignServiceImpl.java

@@ -1,5 +1,8 @@
 package com.qmth.eds.service.impl;
 
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.ExcelWriter;
+import com.alibaba.excel.write.metadata.WriteSheet;
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@@ -7,11 +10,13 @@ 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.eds.bean.dto.ExamAssignDto;
+import com.qmth.eds.bean.dto.ScoreDownloadDto;
 import com.qmth.eds.bean.result.AssignResultPreviewResult;
 import com.qmth.eds.common.contant.SystemConstant;
 import com.qmth.eds.common.entity.*;
 import com.qmth.eds.common.enums.ExamAssignStatusEnum;
 import com.qmth.eds.common.enums.ExceptionResultEnum;
+import com.qmth.eds.common.util.FileUtil;
 import com.qmth.eds.common.util.ServletUtil;
 import com.qmth.eds.mapper.ExamAssignMapper;
 import com.qmth.eds.service.*;
@@ -22,6 +27,8 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -189,7 +196,7 @@ public class ExamAssignServiceImpl extends ServiceImpl<ExamAssignMapper, ExamAss
             this.save(examAssign);
         } else {
             examAssign = this.getById(id);
-            if(examAssign.getFormula() != null && !ExamAssignStatusEnum.FINISH.equals(examAssign.getStatus())){
+            if (examAssign.getFormula() != null && !ExamAssignStatusEnum.FINISH.equals(examAssign.getStatus())) {
                 throw ExceptionResultEnum.ERROR.exception("赋分计算未完成,暂无法发布成绩");
             }
         }
@@ -257,4 +264,25 @@ public class ExamAssignServiceImpl extends ServiceImpl<ExamAssignMapper, ExamAss
                 .eq(ExamAssign::getId, examAssign.getId());
         return this.update(examAssignUpdateWrapper);
     }
+
+    @Override
+    public void download(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();
+            }
+        }
+
+    }
 }

+ 3 - 0
src/main/resources/db/log/log-1.0.4.sql

@@ -32,6 +32,7 @@ INSERT INTO `sys_privilege` (`id`, `name`, `url`, `type`, `parent_id`, `sequence
 INSERT INTO `sys_privilege` (`id`, `name`, `url`, `type`, `parent_id`, `sequence`, `property`, `enable`, `default_auth`, `front_display`) VALUES ('63', '发布赋分数据', '/api/assign/publish', 'URL', '45', '7', 'AUTH', '1', '1', '1');
 INSERT INTO `sys_privilege` (`id`, `name`, `url`, `type`, `parent_id`, `sequence`, `property`, `enable`, `default_auth`, `front_display`) VALUES ('64', '学期管理-启用/禁用', '/api/exam_semester/enable', 'URL', '17', '5', 'AUTH', '1', '1', '1');
 INSERT INTO `sys_privilege` (`id`, `name`, `url`, `type`, `parent_id`, `sequence`, `property`, `enable`, `default_auth`, `front_display`) VALUES ('65', '考试类型管理-启用/禁用', '/api/exam_type/enable', 'URL', '21', '5', 'AUTH', '1', '1', '1');
+INSERT INTO `sys_privilege` (`id`, `name`, `url`, `type`, `parent_id`, `sequence`, `property`, `enable`, `default_auth`, `front_display`) VALUES ('66', '导出赋分数据', '/api/assign/download', 'URL', '45', '8', 'AUTH', '1', '1', '1');
 
 
 INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`) VALUES ('45', '3', '45', '1');
@@ -45,6 +46,8 @@ INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`) VAL
 INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`) VALUES ('53', '2', '57', '1');
 INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`) VALUES ('54', '3', '63', '1');
 INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`) VALUES ('55', '3', '41', '1');
+INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`) VALUES ('56', '3', '63', '1');
+INSERT INTO `sys_role_privilege` (`id`, `role_id`, `privilege_id`, `enable`) VALUES ('57', '3', '66', '1');
 
 
 

+ 42 - 0
src/main/resources/mapper/CloudMarkingScoreMapper.xml

@@ -21,6 +21,7 @@
                 WHEN 3 THEN '违纪'
                 END status,
             cms.total_score totalScore,
+            cms.assign_score assignScore,
             cms.objective_score objectiveScore,
             cms.subjective_score subjectiveScore
         FROM
@@ -116,4 +117,45 @@
             </if>
         </where>
     </select>
+    <select id="listScoreBySemesterIdAndExamTypeIdAndCollegeIdAndCourseCodeAndOpenCollege"
+            resultType="com.qmth.eds.bean.dto.ScoreDownloadDto">
+        SELECT
+            es.name semesterName,
+            et.name examTypeName,
+            ess.xnm,
+            ess.xqm,
+            ess.kch,
+            ess.kcmc,
+            ess.kkbm,
+            ess.xh,
+            ess.xsxm,
+            ess.jgmc,
+            cms.total_score totalScore,
+            cms.assign_score assignScore
+        FROM
+            cloud_marking_score cms
+                LEFT JOIN
+            exam_sync_student ess ON cms.exam_sync_student_id = ess.id
+                LEFT JOIN
+            exam_semester es ON cms.semester_id = es.id
+                LEFT JOIN
+            exam_type et ON cms.exam_type_id = et.id
+        <where>
+            <if test="semesterId != null">
+                and cms.semester_id = #{semesterId}
+            </if>
+            <if test="examTypeId != null">
+                and cms.exam_type_id = #{examTypeId}
+            </if>
+            <if test="collegeId != null">
+                and cms.school_id = #{collegeId}
+            </if>
+            <if test="courseCode != null">
+                and cms.subject_code = #{courseCode}
+            </if>
+            <if test="openCollege != null and openCollege != ''">
+                and ess.kkbm = #{openCollege}
+            </if>
+        </where>
+    </select>
 </mapper>

+ 10 - 0
src/test/java/com/qmth/eds/WhuTest.java

@@ -1,8 +1,10 @@
 package com.qmth.eds;
 
+import com.qmth.eds.common.entity.ExamAssign;
 import com.qmth.eds.common.entity.ExamSyncStudentTemp;
 import com.qmth.eds.job.service.JobService;
 import com.qmth.eds.common.tools.WhuUtils;
+import com.qmth.eds.service.ExamAssignService;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.boot.test.context.SpringBootTest;
@@ -24,6 +26,9 @@ public class WhuTest {
     @Resource
     JobService jobService;
 
+    @Resource
+    ExamAssignService examAssignService;
+
     @Test
     public void test() {
         String token = whuUtils.getAccessToken(1l);
@@ -38,4 +43,9 @@ public class WhuTest {
         jobService.getExamData(false);
     }
 
+    @Test
+    public void download(){
+        examAssignService.download(323866074581827584l, 323866121386065920l, 7l, "100830011001", null, null);
+    }
+
 }