xiangpei
2024-07-09 53dea0ef5fc8b035397b73b10f7a819ebf381b1c
src/main/java/com/mindskip/xzs/controller/admin/ExamPaperAnswerController.java
@@ -8,6 +8,8 @@
import com.mindskip.xzs.domain.ExamPaperSubject;
import com.mindskip.xzs.domain.Subject;
import com.mindskip.xzs.domain.exam.ExamPaperAnswerObject;
import com.mindskip.xzs.domain.vo.ExamPaperDataExportVO;
import com.mindskip.xzs.domain.vo.ExamPaperDataVO;
import com.mindskip.xzs.domain.vo.ExamPaperStatisticVO;
import com.mindskip.xzs.service.ExamPaperAnswerService;
import com.mindskip.xzs.service.ExamPaperSubjectService;
@@ -16,16 +18,20 @@
import com.mindskip.xzs.utility.DateTimeUtil;
import com.mindskip.xzs.utility.ExamUtil;
import com.mindskip.xzs.utility.PageInfoHelper;
import com.mindskip.xzs.utility.excel.ExcelUtils;
import com.mindskip.xzs.viewmodel.admin.paper.ExamPaperAnswerPageRequestVM;
import com.mindskip.xzs.viewmodel.student.exampaper.ExamPaperAnswerPageResponseVM;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@@ -74,12 +80,13 @@
            vm.setSubjectName(name);
            vm.setCreateTime(DateTimeUtil.dateFormat(e.getCreateTime()));
//            vm.setUserName(user.getRealName());
            return vm;
        });
//        page.setList(page.getList().stream().filter(e -> e != null).collect(Collectors.toList()));
        if (page.getList().size() > 0) {
            Double avg = page.getList().stream().mapToInt(ExamPaperAnswerPageResponseVM -> Integer.parseInt(ExamPaperAnswerPageResponseVM.getUserScore())).average().getAsDouble();
            BigDecimal sum = page.getList().stream()
                    .map(ExamPaperAnswerPageResponseVM -> new BigDecimal(ExamPaperAnswerPageResponseVM.getUserScore()))
                    .reduce(BigDecimal.ZERO, BigDecimal::add); // 计算总和
            Double avg = sum.divide(BigDecimal.valueOf(page.getList().size()), 2, RoundingMode.HALF_UP).doubleValue();
            page.getList().get(0).setAvgSource(avg);
        }
        return RestResponse.ok(page);
@@ -122,7 +129,19 @@
    @RequestMapping(value = "/statistic", method = RequestMethod.POST)
    public RestResponse<Map<String, Object>> statistic(@RequestBody ExamPaperStatisticVO examPaperStatisticVO) {
        examPaperStatisticVO.setDepartmentId(isDeptAdmin() ? getAdminDeptIds() : null);
        examPaperStatisticVO.setDepartmentId(ObjectUtils.isNotEmpty(examPaperStatisticVO.getDepartmentId()) ? examPaperStatisticVO.getDepartmentId() : getAdminDeptIds());
        return RestResponse.ok(examPaperAnswerService.statistic(examPaperStatisticVO));
    }
    @RequestMapping(value = "/data", method = RequestMethod.POST)
    public RestResponse<Map<String, Object>> data(@RequestBody ExamPaperDataVO examPaperDataVO) {
        return RestResponse.ok(examPaperAnswerService.data(examPaperDataVO));
    }
    @RequestMapping(value = "/export", method = RequestMethod.GET)
    public void export(Integer id, Integer type, HttpServletResponse response) {
        List<ExamPaperDataExportVO> list =  examPaperAnswerService.dataExport(new ExamPaperDataVO().setId(id).setType(type));
        ExcelUtils.export(response, "分数统计", list, ExamPaperDataExportVO.class);
    }
}