Kaynağa Gözat

成绩导入加入满分制转换

wangliang 8 ay önce
ebeveyn
işleme
1b39831097

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

@@ -1,5 +1,6 @@
 package com.qmth.distributed.print.business.bean.excel;
 
+import com.fasterxml.jackson.annotation.JsonInclude;
 import io.swagger.annotations.ApiModelProperty;
 
 import java.io.Serializable;
@@ -11,6 +12,7 @@ import java.io.Serializable;
  * @Author: wangliang
  * @Date: 2024/2/19
  */
+@JsonInclude(JsonInclude.Include.NON_NULL)
 public class ExcelField implements Serializable {
 
     @ApiModelProperty(value = "序号")
@@ -40,6 +42,13 @@ public class ExcelField implements Serializable {
         this.value = "测试" + name;
     }
 
+    public void setNull() {
+        this.index = null;
+        this.code = null;
+        this.value = null;
+        this.comment = null;
+    }
+
     public Integer getIndex() {
         return index;
     }

+ 8 - 0
distributed-print-business/src/main/resources/db/log/wl.sql

@@ -0,0 +1,8 @@
+-- 2024-10-09
+INSERT INTO sys_privilege
+(id, name, url, `type`, parent_id, `sequence`, property, related, enable, default_auth, front_display)
+VALUES(2111, '平时成绩-获取作业集合', '/api/admin/course/degree/usual_score/template_download/list', 'URL', 2006, 1, 'AUTH', NULL, 1, 1, 1);
+
+UPDATE sys_privilege
+SET name='管理成绩', url='Score', `type`='LINK', parent_id=2001, `sequence`=1, property='AUTH', related='2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2029,2030,2031,2032,2033,2034,3018,2111', enable=1, default_auth=0, front_display=1
+WHERE id=2006;

+ 46 - 24
distributed-print/src/main/java/com/qmth/distributed/print/api/obe/TCUsualScoreController.java

@@ -11,10 +11,7 @@ import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.SysUser;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.enums.log.OperationTypeEnum;
-import com.qmth.teachcloud.common.util.GsonUtil;
-import com.qmth.teachcloud.common.util.Result;
-import com.qmth.teachcloud.common.util.ResultUtil;
-import com.qmth.teachcloud.common.util.ServletUtil;
+import com.qmth.teachcloud.common.util.*;
 import com.qmth.teachcloud.obe.been.dto.CourseWeightDetailDto;
 import com.qmth.teachcloud.obe.been.dto.CourseWeightDto;
 import com.qmth.teachcloud.obe.been.dto.TCUsualScoreDto;
@@ -89,39 +86,35 @@ public class TCUsualScoreController {
     @ApiResponses({@ApiResponse(code = 200, message = "下载成功", response = Object.class)})
     public void usualScoreTemplateDownload(@ApiParam(value = "培养方案id", required = true) @RequestParam Long cultureProgramId,
                                            @ApiParam(value = "课程id", required = true) @RequestParam Long courseId) throws IOException {
-        ObeCourseOutline obeCourseOutline = obeCourseOutlineService.findByCultureProgramIdAndCourseId(
-                cultureProgramId, courseId);
-
-        ObeCourseWeightResult obeCourseWeightResult = trBasicInfoService.findCourseWeightResultRmi(obeCourseOutline.getId(), true);
-        List<CourseWeightDto> courseWeightDtoList = obeCourseWeightResult.getSubmitForm();
-
         List<ExcelField> excelFieldList = new ArrayList<>();
         excelFieldList.addAll(new ArrayList<>(Arrays.asList(new ExcelField("studentCode", "学号", true), new ExcelField("name", "姓名", true))));
-        courseWeightDtoList.stream().peek(e -> {
-            List<CourseWeightDetailDto> courseWeightDetailDtoList = e.getEvaluationList();
-            courseWeightDetailDtoList.stream().peek(s -> {
-                if (Objects.nonNull(s.getEnable()) && s.getEnable() && !Objects.equals(s.getEvaluationName(),
-                        SystemConstant.FINAL_SCORE_STR)) {
-                    excelFieldList.add(new ExcelField(s.getEvaluationName(), s.getEvaluationName(), true));
-                }
-            }).collect(Collectors.toList());
-        }).collect(Collectors.toList());
-        if (excelFieldList.size() == 2) {
-            throw ExceptionResultEnum.ERROR.exception("未设置评价方式,请在课程考核设置先设置评价方式再下载平时成绩导入模版");
-        }
+        excelFieldList = this.getUsualScoreList(cultureProgramId, courseId, excelFieldList);
         printCommonService.scoreDownLoadExaminationTemplate(
                 "1、所有字段均为必填字段;\n" + "2、平时成绩各项数据均需要填写;\n" + "3、请不要删除此行,也不要删除模板中的任何列。\n" + "4、使用前请先删除样例数据。", "sheet1",
                 "平时成绩导入模版", excelFieldList);
     }
 
+    @ApiOperation(value = "导入平时成绩-获取作业集合")
+    @RequestMapping(value = "/usual_score/template_download/list", method = RequestMethod.POST)
+    @OperationLogDetail(operationType = OperationTypeEnum.SELECT)
+    @ApiResponses({@ApiResponse(code = 200, message = "作业集合信息", response = Object.class)})
+    public Result usualScoreTemplateDownloadList(@ApiParam(value = "培养方案id", required = true) @RequestParam Long cultureProgramId,
+                                                 @ApiParam(value = "课程id", required = true) @RequestParam Long courseId) {
+        List<ExcelField> excelFieldList = new ArrayList<>();
+        excelFieldList = this.getUsualScoreList(cultureProgramId, courseId, excelFieldList);
+        excelFieldList.stream().peek(s -> s.setNull()).collect(Collectors.toList());
+        return ResultUtil.ok(JacksonUtil.parseJson(excelFieldList));
+    }
+
     @ApiOperation(value = "导入平时成绩")
     @RequestMapping(value = "/usual_score/import", method = RequestMethod.POST)
     @OperationLogDetail(operationType = OperationTypeEnum.IMPORT)
     @ApiResponses({@ApiResponse(code = 200, message = "导入成功", response = EditResult.class)})
     public Result usualScoreImport(@ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file,
                                    @ApiParam(value = "培养方案id", required = true) @RequestParam Long cultureProgramId,
-                                   @ApiParam(value = "课程id", required = true) @RequestParam Long courseId) throws IOException {
-        return ResultUtil.ok(tcUsualScoreService.usualScoreExcelImport(file, cultureProgramId, courseId));
+                                   @ApiParam(value = "课程id", required = true) @RequestParam Long courseId,
+                                   @ApiParam(value = "作业分数集合") @RequestParam(required = false) String usualScoreList) throws IOException {
+        return ResultUtil.ok(tcUsualScoreService.usualScoreExcelImport(file, cultureProgramId, courseId, usualScoreList));
     }
 
     @ApiOperation(value = "平时成绩列表")
@@ -202,4 +195,33 @@ public class TCUsualScoreController {
         }
         return ResultUtil.ok(true);
     }
+
+    /**
+     * 获取平时作业集合
+     *
+     * @param cultureProgramId
+     * @param courseId
+     * @param excelFieldList
+     * @return
+     */
+    protected List<ExcelField> getUsualScoreList(Long cultureProgramId, Long courseId, List<ExcelField> excelFieldList) {
+        ObeCourseOutline obeCourseOutline = obeCourseOutlineService.findByCultureProgramIdAndCourseId(
+                cultureProgramId, courseId);
+        ObeCourseWeightResult obeCourseWeightResult = trBasicInfoService.findCourseWeightResultRmi(obeCourseOutline.getId(), true);
+        List<CourseWeightDto> courseWeightDtoList = obeCourseWeightResult.getSubmitForm();
+
+        courseWeightDtoList.stream().peek(e -> {
+            List<CourseWeightDetailDto> courseWeightDetailDtoList = e.getEvaluationList();
+            courseWeightDetailDtoList.stream().peek(s -> {
+                if (Objects.nonNull(s.getEnable()) && s.getEnable() && !Objects.equals(s.getEvaluationName(),
+                        SystemConstant.FINAL_SCORE_STR)) {
+                    excelFieldList.add(new ExcelField(s.getEvaluationName(), s.getEvaluationName(), true));
+                }
+            }).collect(Collectors.toList());
+        }).collect(Collectors.toList());
+        if (excelFieldList.size() == 2) {
+            throw ExceptionResultEnum.ERROR.exception("未设置评价方式,请在课程考核设置先设置评价方式再下载平时成绩导入模版");
+        }
+        return excelFieldList;
+    }
 }

+ 2 - 1
teachcloud-obe/src/main/java/com/qmth/teachcloud/obe/service/TCUsualScoreService.java

@@ -25,9 +25,10 @@ public interface TCUsualScoreService extends IService<TCUsualScore> {
      * @param file
      * @param cultureProgramId
      * @param courseId
+     * @param usualScoreList
      * @return 结果
      */
-    public Map<String, String> usualScoreExcelImport(MultipartFile file, Long cultureProgramId, Long courseId) throws IOException;
+    public Map<String, String> usualScoreExcelImport(MultipartFile file, Long cultureProgramId, Long courseId, String usualScoreList) throws IOException;
 
     /**
      * 平时成绩列表(分页)

+ 28 - 3
teachcloud-obe/src/main/java/com/qmth/teachcloud/obe/service/impl/TCUsualScoreServiceImpl.java

@@ -3,10 +3,11 @@ package com.qmth.teachcloud.obe.service.impl;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.google.gson.reflect.TypeToken;
 import com.qmth.boot.api.exception.ApiException;
 import com.qmth.boot.tools.excel.ExcelReader;
 import com.qmth.boot.tools.excel.enums.ExcelType;
-import com.qmth.distributed.print.business.service.PrintCommonService;
+import com.qmth.distributed.print.business.bean.excel.ExcelField;
 import com.qmth.teachcloud.common.base.BaseEntity;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.BasicCourse;
@@ -14,6 +15,7 @@ import com.qmth.teachcloud.common.entity.SysUser;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.enums.FieldUniqueEnum;
 import com.qmth.teachcloud.common.service.BasicCourseService;
+import com.qmth.teachcloud.common.util.GsonUtil;
 import com.qmth.teachcloud.common.util.JacksonUtil;
 import com.qmth.teachcloud.common.util.ResultUtil;
 import com.qmth.teachcloud.common.util.ServletUtil;
@@ -31,7 +33,9 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
 import java.util.*;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 /**
@@ -61,11 +65,12 @@ public class TCUsualScoreServiceImpl extends ServiceImpl<TCUsualScoreMapper, TCU
      * @param file             excel
      * @param cultureProgramId 培养方案id
      * @param courseId         课程id
+     * @param usualScoreList
      * @return
      */
     @Override
     @Transactional
-    public Map<String, String> usualScoreExcelImport(MultipartFile file, Long cultureProgramId, Long courseId) {
+    public Map<String, String> usualScoreExcelImport(MultipartFile file, Long cultureProgramId, Long courseId, String usualScoreList) {
         log.debug("导入Excel开始...");
         long start = System.currentTimeMillis();
         Map<String, String> messageMap = new LinkedHashMap<>();
@@ -75,7 +80,6 @@ public class TCUsualScoreServiceImpl extends ServiceImpl<TCUsualScoreMapper, TCU
 
         try {
             Double totalScore = 100d;
-
             StringJoiner errorData = new StringJoiner("");
             StringJoiner successData = new StringJoiner("");
 
@@ -94,6 +98,13 @@ public class TCUsualScoreServiceImpl extends ServiceImpl<TCUsualScoreMapper, TCU
                     }
                 }
 
+                Map<String, ExcelField> excelFieldMap = new HashMap<>();
+                if (Objects.nonNull(usualScoreList)) {
+                    List<ExcelField> excelFieldList = GsonUtil.fromJson(usualScoreList, new TypeToken<List<ExcelField>>() {
+                    }.getType());
+                    excelFieldMap = excelFieldList.stream().collect(Collectors.toMap(k -> k.getName(), Function.identity(), (dto1, dto2) -> dto1));
+                }
+
                 for (int i = 0; i < arrayList.size(); i++) {
                     String[] strs = arrayList.get(i);
                     if (Objects.nonNull(strs) && strs.length > 0) {
@@ -119,6 +130,20 @@ public class TCUsualScoreServiceImpl extends ServiceImpl<TCUsualScoreMapper, TCU
                                             errorData.add("excel第").add((i + 1) + "").add("行[").add(columnNames[j]).add("]总分大于试卷总分").add("\r\n");
                                             error = true;
                                         } else {
+                                            if (excelFieldMap.containsKey(columnNames[j])) {
+                                                ExcelField excelField = excelFieldMap.get(columnNames[j]);
+                                                if (Objects.nonNull(excelField.getValue()) && !Objects.equals(excelField.getValue().trim(), "")) {
+                                                    BigDecimal scoreFull = new BigDecimal(excelField.getValue());
+                                                    BigDecimal scoreBd = new BigDecimal(score);
+                                                    if (scoreBd.compareTo(scoreFull) == 1) {
+                                                        errorData.add("excel第").add((i + 1) + "").add("行[").add(columnNames[j]).add("]总分大于评价方式满分").add("\r\n");
+                                                        error = true;
+                                                    } else {
+                                                        scoreBd = scoreBd.divide(scoreFull, 2, BigDecimal.ROUND_HALF_UP).multiply(SystemConstant.PERCENT).setScale(2, BigDecimal.ROUND_HALF_UP);
+                                                        strs[j] = scoreBd.toString();
+                                                    }
+                                                }
+                                            }
                                             tcUsualScoreDtoList.add(new TCUsualScoreDto(strs[j], columnNames[j]));
                                         }
                                     } else {