Ver Fonte

加入平时成绩列表和平时成绩模版下载

wangliang há 1 ano atrás
pai
commit
ee57e6070e

+ 82 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/excel/ExcelField.java

@@ -0,0 +1,82 @@
+package com.qmth.distributed.print.business.bean.excel;
+
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+
+/**
+ * @Description: excel 动态字段
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2024/2/19
+ */
+public class ExcelField implements Serializable {
+
+    @ApiModelProperty(value = "序号")
+    Integer index = 0;
+
+    @ApiModelProperty(value = "编码")
+    String code;
+
+    @ApiModelProperty(value = "名称")
+    String name;
+
+    @ApiModelProperty(value = "值")
+    String value;
+
+    @ApiModelProperty(value = "批注")
+    Boolean comment;
+
+    public ExcelField() {
+
+    }
+
+    public ExcelField(String code, String name, Boolean comment) {
+        this.index = getIndex() + 1;
+        this.code = code;
+        this.name = name;
+        this.comment = comment;
+        this.value = "测试" + name;
+    }
+
+    public Integer getIndex() {
+        return index;
+    }
+
+    public void setIndex(Integer index) {
+        this.index = index;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    public Boolean getComment() {
+        return comment;
+    }
+
+    public void setComment(Boolean comment) {
+        this.comment = comment;
+    }
+}

+ 97 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/result/ScoreNormalResult.java

@@ -0,0 +1,97 @@
+package com.qmth.distributed.print.business.bean.result;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+
+/**
+ * @Description: 平常作业result
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2024/2/19
+ */
+public class ScoreNormalResult implements Serializable {
+
+    @JsonSerialize(using = ToStringSerializer.class)
+    @ApiModelProperty(value = "id")
+    private Long id;
+
+    @JsonSerialize(using = ToStringSerializer.class)
+    @ApiModelProperty(value = "学期id")
+    private Long semesterId;
+
+    @JsonSerialize(using = ToStringSerializer.class)
+    @ApiModelProperty(value = "考试id")
+    private Long examId;
+
+    @ApiModelProperty(value = "课程编码")
+    private String courseCode;
+
+    @ApiModelProperty(value = "课程名称")
+    private String courseName;
+
+    @ApiModelProperty(value = "试卷编号")
+    private String paperNumber;
+
+    @ApiModelProperty(value = "试卷类型")
+    private String paperType;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getSemesterId() {
+        return semesterId;
+    }
+
+    public void setSemesterId(Long semesterId) {
+        this.semesterId = semesterId;
+    }
+
+    public Long getExamId() {
+        return examId;
+    }
+
+    public void setExamId(Long examId) {
+        this.examId = examId;
+    }
+
+    public String getCourseCode() {
+        return courseCode;
+    }
+
+    public void setCourseCode(String courseCode) {
+        this.courseCode = courseCode;
+    }
+
+    public String getCourseName() {
+        return courseName;
+    }
+
+    public void setCourseName(String courseName) {
+        this.courseName = courseName;
+    }
+
+    public String getPaperNumber() {
+        return paperNumber;
+    }
+
+    public void setPaperNumber(String paperNumber) {
+        this.paperNumber = paperNumber;
+    }
+
+    public String getPaperType() {
+        return paperType;
+    }
+
+    public void setPaperType(String paperType) {
+        this.paperType = paperType;
+    }
+}

+ 3 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/mapper/TCScoreNormalMapper.java

@@ -2,6 +2,7 @@ package com.qmth.distributed.print.business.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.qmth.distributed.print.business.bean.result.ScoreNormalResult;
 import com.qmth.distributed.print.business.entity.TCScoreNormal;
 import org.apache.ibatis.annotations.Param;
 
@@ -23,7 +24,8 @@ public interface TCScoreNormalMapper extends BaseMapper<TCScoreNormal> {
      * @param iPage
      * @param semesterId
      * @param examId
+     * @param courseCode
      * @return
      */
-    public IPage<Map> scoreList(IPage<Map> iPage, @Param("semesterId") Long semesterId, @Param("examId") Long examId);
+    public IPage<ScoreNormalResult> scoreList(IPage<Map> iPage, @Param("semesterId") Long semesterId, @Param("examId") Long examId, @Param("courseCode") String courseCode);
 }

+ 18 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/TCScoreNormalService.java

@@ -2,8 +2,13 @@ package com.qmth.distributed.print.business.service;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.distributed.print.business.bean.examRule.FieldsDto;
+import com.qmth.distributed.print.business.bean.excel.ExcelField;
+import com.qmth.distributed.print.business.bean.result.ScoreNormalResult;
 import com.qmth.distributed.print.business.entity.TCScoreNormal;
 
+import java.io.IOException;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -22,7 +27,19 @@ public interface TCScoreNormalService extends IService<TCScoreNormal> {
      * @param iPage
      * @param semesterId
      * @param examId
+     * @param courseCode
      * @return
      */
-    public IPage<Map> scoreList(IPage<Map> iPage, Long semesterId, Long examId);
+    public IPage<ScoreNormalResult> scoreList(IPage<Map> iPage, Long semesterId, Long examId, String courseCode);
+
+    /**
+     * 动态生成excel
+     *
+     * @param describe
+     * @param sheetName
+     * @param fileName
+     * @param excelFieldList
+     * @throws IOException
+     */
+    void downLoadExaminationTemplate(String describe, String sheetName, String fileName, List<ExcelField> excelFieldList) throws IOException;
 }

+ 106 - 2
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/TCScoreNormalServiceImpl.java

@@ -2,11 +2,27 @@ package com.qmth.distributed.print.business.service.impl;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.distributed.print.business.bean.excel.ExcelField;
+import com.qmth.distributed.print.business.bean.result.ScoreNormalResult;
 import com.qmth.distributed.print.business.entity.TCScoreNormal;
 import com.qmth.distributed.print.business.mapper.TCScoreNormalMapper;
 import com.qmth.distributed.print.business.service.TCScoreNormalService;
+import com.qmth.teachcloud.common.contant.SystemConstant;
+import com.qmth.teachcloud.common.util.ExcelUtil;
+import com.qmth.teachcloud.common.util.ServletUtil;
+import org.apache.poi.ss.usermodel.FillPatternType;
+import org.apache.poi.ss.usermodel.Font;
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
+import org.apache.poi.ss.usermodel.IndexedColors;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.usermodel.*;
 import org.springframework.stereotype.Service;
 
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -26,10 +42,98 @@ public class TCScoreNormalServiceImpl extends ServiceImpl<TCScoreNormalMapper, T
      * @param iPage
      * @param semesterId
      * @param examId
+     * @param courseCode
      * @return
      */
     @Override
-    public IPage<Map> scoreList(IPage<Map> iPage, Long semesterId, Long examId) {
-        return this.baseMapper.scoreList(iPage, semesterId, examId);
+    public IPage<ScoreNormalResult> scoreList(IPage<Map> iPage, Long semesterId, Long examId, String courseCode) {
+        return this.baseMapper.scoreList(iPage, semesterId, examId, courseCode);
+    }
+
+    /**
+     * 动态生成excel
+     *
+     * @param describe
+     * @param sheetName
+     * @param fileName
+     * @param excelFieldList
+     * @throws IOException
+     */
+    @Override
+    public void downLoadExaminationTemplate(String describe, String sheetName, String fileName, List<ExcelField> excelFieldList) throws IOException {
+        HttpServletResponse response = ServletUtil.getResponse();
+        log.debug("导出Excel开始...");
+        XSSFWorkbook wb = new XSSFWorkbook();
+        response.setHeader("Content-Disposition", "inline;filename=" + URLEncoder.encode(fileName, SystemConstant.CHARSET_NAME) + ExcelUtil.DEFALUT_EXT);
+        response.setContentType(ExcelUtil.DEFALUT_CONTENT_TYPE);
+        XSSFSheet sheet = wb.createSheet(sheetName);
+
+        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());
+        describeStyle.setFont(describeFont);
+        describe = describe.trim();
+        XSSFRow rowDescribe = sheet.createRow(0);
+        rowDescribe.setHeightInPoints(195); //行高设置成195px
+        for (int i = 0; i < cellCount; i++) {
+            XSSFCell cell = rowDescribe.createCell(i);
+            if (i == 0) {
+                cell.setCellValue(describe);
+                cell.setCellStyle(describeStyle);
+            }
+        }
+        CellRangeAddress region = new CellRangeAddress(0, 0, 0, cellCount - 1);
+        sheet.addMergedRegion(region);
+
+        // 表头行
+        XSSFCellStyle headerStyle = wb.createCellStyle();
+        headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+        headerStyle.setAlignment(HorizontalAlignment.CENTER);
+        headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
+        headerStyle.setFont(defaultFont);
+        XSSFRow rowHead = sheet.createRow(1);
+        for (int i = 0; i < excelFieldList.size(); i++) {
+            XSSFCell cell = rowHead.createCell(i);
+            cell.setCellValue(excelFieldList.get(i).getName());
+            cell.setCellStyle(headerStyle);
+            if (excelFieldList.get(i).getComment()) {
+                // 前四个参数是坐标点,后四个参数是编辑和显示批注时的大小.
+                XSSFDrawing p = sheet.createDrawingPatriarch();
+                XSSFComment comment = p.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 3, 3, (short) 5, 6));
+                // 输入批注信息
+                comment.setString(new XSSFRichTextString("必填"));
+                cell.setCellComment(comment);
+            }
+        }
+
+        // 样例行
+        XSSFCellStyle exampleStyle = wb.createCellStyle();
+        exampleStyle.setAlignment(HorizontalAlignment.LEFT);
+        exampleStyle.setFont(defaultFont);
+        XSSFRow rowExample = sheet.createRow(2);
+        for (int i = 0; i < excelFieldList.size(); i++) {
+            XSSFCell cell = rowExample.createCell(i);
+            cell.setCellValue(excelFieldList.get(i).getValue());
+            cell.setCellStyle(exampleStyle);
+        }
+
+        for (int i = 0; i < cellCount; i++) {
+            sheet.autoSizeColumn(i);
+            sheet.setColumnWidth(i, sheet.getColumnWidth(i) * 17 / 10);
+        }
+        ServletOutputStream outputStream = response.getOutputStream();
+        wb.write(outputStream);
+        outputStream.flush();
+        outputStream.close();
+        log.debug("导出Excel结束...");
     }
 }

+ 26 - 2
distributed-print-business/src/main/resources/mapper/TCScoreNormalMapper.xml

@@ -2,7 +2,31 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.qmth.distributed.print.business.mapper.TCScoreNormalMapper">
 
-    <select id="scoreList" resultType="java.util.Map">
-
+    <select id="scoreList" resultType="com.qmth.distributed.print.business.bean.result.ScoreNormalResult">
+        SELECT distinct t.id,
+                 bs.id as semesterId,
+                 t.exam_id as examId,
+                 t.course_code as courseCode,
+                 t.course_name as courseName,
+                 t.paper_number as paperNumber,
+                 mq.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
+            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}
+            </if>
+            <if test="examId != null and examId != ''">
+                and t.exam_id = #{examId}
+            </if>
+            <if test="courseCode != null and courseCode != ''">
+                and t.course_code = #{courseCode}
+            </if>
+            AND t.status = 'FINISH'
+        </where>
+        ORDER BY t.id desc
     </select>
 </mapper>

+ 18 - 3
distributed-print/src/main/java/com/qmth/distributed/print/api/TCScoreNormalController.java

@@ -2,6 +2,7 @@ package com.qmth.distributed.print.api;
 
 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.service.TCScoreNormalService;
 import com.qmth.teachcloud.common.annotation.OperationLogDetail;
@@ -19,6 +20,8 @@ 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;
 
 /**
  * <p>
@@ -36,15 +39,19 @@ public class TCScoreNormalController {
     @Resource
     TCScoreNormalService tcScoreNormalService;
 
+//    @Resource
+//    ExamDetailService examDetailService;
+
     @ApiOperation(value = "成绩管理列表")
     @RequestMapping(value = "/score/list", method = RequestMethod.POST)
     @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.SEARCH)
     @ApiResponses({@ApiResponse(code = 200, message = "分页查询", response = Object.class)})
     public Object scoreList(@ApiParam(value = "学期ID", required = true) @RequestParam Long semesterId,
                             @ApiParam(value = "考试ID", required = true) @RequestParam Long examId,
+                            @ApiParam(value = "课程编码") @RequestParam(required = false) String courseCode,
                             @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
                             @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
-        return ResultUtil.ok(tcScoreNormalService.scoreList(new Page<>(pageNumber, pageSize), semesterId, examId));
+        return ResultUtil.ok(tcScoreNormalService.scoreList(new Page<>(pageNumber, pageSize), semesterId, examId, courseCode));
     }
 
     @ApiOperation(value = "导入平时成绩-模板下载")
@@ -55,8 +62,16 @@ public class TCScoreNormalController {
                                  @ApiParam(value = "科目编码", required = true) @RequestParam String courseCode,
                                  @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber,
                                  @ApiParam(value = "试卷类型", required = true) @RequestParam String paperType) throws IOException {
-//        Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
-//        examDetailService.downLoadExaminationTemplate(schoolId, ServletUtil.getResponse());
+        List<ExcelField> excelFieldList = new ArrayList<>();
+        excelFieldList.add(new ExcelField("examNumber", "学号", true));
+        excelFieldList.add(new ExcelField("name", "姓名", true));
+        excelFieldList.add(new ExcelField("score1", "作业1", true));
+        excelFieldList.add(new ExcelField("score2", "作业2", true));
+        excelFieldList.add(new ExcelField("score3", "作业3", false));
+        tcScoreNormalService.downLoadExaminationTemplate("1、所有字段均为必填字段;\n" +
+                "2、平时成绩各项数据均需要填写;\n" +
+                "3、请不要删除此行,也不要删除模板中的任何列。\n" +
+                "4、使用前请先删除样例数据。", "sheet1", "平时成绩导入模版", excelFieldList);
     }
 
     @ApiOperation(value = "导入平时成绩")

+ 2 - 1
distributed-print/src/main/java/com/qmth/distributed/print/api/TRBasicInfoController.java

@@ -37,9 +37,10 @@ public class TRBasicInfoController {
     @ApiResponses({@ApiResponse(code = 200, message = "分页查询", response = Object.class)})
     public Object reportList(@ApiParam(value = "学期ID", required = true) @RequestParam Long semesterId,
                              @ApiParam(value = "考试ID", required = true) @RequestParam Long examId,
+                             @ApiParam(value = "课程编码") @RequestParam(required = false) String courseCode,
                              @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
                              @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
-        return ResultUtil.ok(tcScoreNormalService.scoreList(new Page<>(pageNumber, pageSize), semesterId, examId));
+        return ResultUtil.ok(tcScoreNormalService.scoreList(new Page<>(pageNumber, pageSize), semesterId, examId, courseCode));
     }
 
     @ApiOperation(value = "查看报告")

+ 2 - 2
teachcloud-common/src/main/java/com/qmth/teachcloud/common/util/ExcelUtil.java

@@ -38,8 +38,8 @@ import java.util.*;
  */
 public class ExcelUtil {
     private final static Logger log = LoggerFactory.getLogger(ExcelUtil.class);
-    private static final String DEFALUT_CONTENT_TYPE = "application/vnd.ms-excel";
-    private static final String DEFALUT_EXT = ".xlsx";
+    public static final String DEFALUT_CONTENT_TYPE = "application/vnd.ms-excel";
+    public static final String DEFALUT_EXT = ".xlsx";
 
     /**
      * excel多sheet