Quellcode durchsuchen

考试成绩统计导出

yangfeng vor 1 Jahr
Ursprung
Commit
a99f71cbdc

+ 7 - 0
web/src/main/java/com/ynfy/buss/exam/examstatistics/service/impl/ExamStatisticsServiceImpl.java

@@ -134,12 +134,19 @@ public class ExamStatisticsServiceImpl extends ServiceImpl<ExamStatisticsMapper,
         Map<String, List<UserExamQuestion>> ueqMap = userExamQuestionList.stream().collect(Collectors
                 .groupingBy(UserExamQuestion::getUserExamId, Collectors.toList()));
         int rank = 1;
+
+        //查询用户所属机构
+        List<String> userIdList = userExamList.stream().map(ExamStatisticsDTO::getUserId).collect(Collectors.toList());
+        Map<String, String> userMap = sysUserService.getDepNamesByUserIds(userIdList);
+
         for (ExamStatisticsDTO dto : userExamList) {
             ExamUserStatistics examUserStatistics = new ExamUserStatistics();
             BeanUtils.copyProperties(dto, examUserStatistics);
             examUserStatistics.setAccuracy(calcUserAccuracy(ueqMap, dto));
             examUserStatistics.setScoreRate(calcScoreRate(ueqMap, dto));
+            examUserStatistics.setOrgName(!Objects.isNull(userMap) ? userMap.get(dto.getUserId()) : null);
             examUserStatistics.setRank(rank);
+            examUserStatistics.setPassedText(dto.getPassed() == 1 ? "通过" : "未通过");
             examUserStatistics.setId(null);
             examUserStatisticsList.add(examUserStatistics);
             rank++;

+ 123 - 116
web/src/main/java/com/ynfy/buss/exam/examuserstatistics/controller/ExamUserStatisticsController.java

@@ -3,6 +3,8 @@ package com.ynfy.buss.exam.examuserstatistics.controller;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ynfy.buss.exam.exam.entity.Exam;
+import com.ynfy.buss.exam.exam.service.IExamService;
 import com.ynfy.buss.exam.examuserstatistics.entity.ExamUserStatistics;
 import com.ynfy.buss.exam.examuserstatistics.service.IExamUserStatisticsService;
 import io.swagger.annotations.Api;
@@ -21,138 +23,143 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.util.Arrays;
 
- /**
+/**
  * @Description: 考试用户统计
  * @Author: jeecg-boot
- * @Date:   2023-03-20
+ * @Date: 2023-03-20
  * @Version: V1.0
  */
-@Api(tags="考试用户统计")
+@Api(tags = "考试用户统计")
 @RestController
 @RequestMapping("/examUserStatistics")
 @Slf4j
 public class ExamUserStatisticsController extends JeecgController<ExamUserStatistics, IExamUserStatisticsService> {
-	@Autowired
-	private IExamUserStatisticsService examUserStatisticsService;
-	
-	/**
-	 * 分页列表查询
-	 *
-	 * @param examUserStatistics
-	 * @param pageNo
-	 * @param pageSize
-	 * @param req
-	 * @return
-	 */
-	@ApiOperation(value="考试用户统计-分页列表查询", notes="考试用户统计-分页列表查询")
-	@RequiresPermissions("examUserStatistics:list")
-	@GetMapping(value = "/list")
-	public Result<IPage<ExamUserStatistics>> queryPageList(ExamUserStatistics examUserStatistics,
-								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
-								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
-								   HttpServletRequest req) {
-		QueryWrapper<ExamUserStatistics> queryWrapper = QueryGenerator.initQueryWrapper(examUserStatistics, req.getParameterMap());
-		Page<ExamUserStatistics> page = new Page<ExamUserStatistics>(pageNo, pageSize);
-		IPage<ExamUserStatistics> pageList = examUserStatisticsService.page(page, queryWrapper);
-		return Result.OK(pageList);
-	}
-	
-	/**
-	 *   添加
-	 *
-	 * @param examUserStatistics
-	 * @return
-	 */
-	@AutoLog(value = "考试用户统计-添加")
-	@ApiOperation(value="考试用户统计-添加", notes="考试用户统计-添加")
-	//@RequiresPermissions("examUserStatistics:add")
-	@PostMapping(value = "/add")
-	public Result<String> add(@RequestBody ExamUserStatistics examUserStatistics) {
-		examUserStatisticsService.save(examUserStatistics);
-		return Result.OK("添加成功!");
-	}
-	
-	/**
-	 *  编辑
-	 *
-	 * @param examUserStatistics
-	 * @return
-	 */
-	@AutoLog(value = "考试用户统计-编辑")
-	@ApiOperation(value="考试用户统计-编辑", notes="考试用户统计-编辑")
-	//@RequiresPermissions("examUserStatistics:edit")
-	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
-	public Result<String> edit(@RequestBody ExamUserStatistics examUserStatistics) {
-		examUserStatisticsService.updateById(examUserStatistics);
-		return Result.OK("编辑成功!");
-	}
-	
-	/**
-	 *   通过id删除
-	 *
-	 * @param id
-	 * @return
-	 */
-	@AutoLog(value = "考试用户统计-通过id删除")
-	@ApiOperation(value="考试用户统计-通过id删除", notes="考试用户统计-通过id删除")
-	//@RequiresPermissions("examUserStatistics:delete")
-	@DeleteMapping(value = "/delete")
-	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
-		examUserStatisticsService.removeById(id);
-		return Result.OK("删除成功!");
-	}
-	
-	/**
-	 *  批量删除
-	 *
-	 * @param ids
-	 * @return
-	 */
-	@AutoLog(value = "考试用户统计-批量删除")
-	@ApiOperation(value="考试用户统计-批量删除", notes="考试用户统计-批量删除")
-	//@RequiresPermissions("examUserStatistics:deleteBatch")
-	@DeleteMapping(value = "/deleteBatch")
-	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
-		this.examUserStatisticsService.removeByIds(Arrays.asList(ids.split(",")));
-		return Result.OK("批量删除成功!");
-	}
-	
-	/**
-	 * 通过id查询
-	 *
-	 * @param id
-	 * @return
-	 */
-	//@AutoLog(value = "考试用户统计-通过id查询")
-	@ApiOperation(value="考试用户统计-通过id查询", notes="考试用户统计-通过id查询")
-	@GetMapping(value = "/queryById")
-	public Result<ExamUserStatistics> queryById(@RequestParam(name="id",required=true) String id) {
-		ExamUserStatistics examUserStatistics = examUserStatisticsService.getById(id);
-		if(examUserStatistics==null) {
-			return Result.error("未找到对应数据");
-		}
-		return Result.OK(examUserStatistics);
-	}
+    @Autowired
+    private IExamUserStatisticsService examUserStatisticsService;
+
+    @Autowired
+    private IExamService examService;
+
+    /**
+     * 分页列表查询
+     *
+     * @param examUserStatistics
+     * @param pageNo
+     * @param pageSize
+     * @param req
+     * @return
+     */
+    @ApiOperation(value = "考试用户统计-分页列表查询", notes = "考试用户统计-分页列表查询")
+    @RequiresPermissions("examUserStatistics:list")
+    @GetMapping(value = "/list")
+    public Result<IPage<ExamUserStatistics>> queryPageList(ExamUserStatistics examUserStatistics,
+                                                           @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                                           @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
+                                                           HttpServletRequest req) {
+        QueryWrapper<ExamUserStatistics> queryWrapper = QueryGenerator.initQueryWrapper(examUserStatistics, req.getParameterMap());
+        Page<ExamUserStatistics> page = new Page<ExamUserStatistics>(pageNo, pageSize);
+        IPage<ExamUserStatistics> pageList = examUserStatisticsService.page(page, queryWrapper);
+        return Result.OK(pageList);
+    }
+
+    /**
+     * 添加
+     *
+     * @param examUserStatistics
+     * @return
+     */
+    @AutoLog(value = "考试用户统计-添加")
+    @ApiOperation(value = "考试用户统计-添加", notes = "考试用户统计-添加")
+    //@RequiresPermissions("examUserStatistics:add")
+    @PostMapping(value = "/add")
+    public Result<String> add(@RequestBody ExamUserStatistics examUserStatistics) {
+        examUserStatisticsService.save(examUserStatistics);
+        return Result.OK("添加成功!");
+    }
+
+    /**
+     * 编辑
+     *
+     * @param examUserStatistics
+     * @return
+     */
+    @AutoLog(value = "考试用户统计-编辑")
+    @ApiOperation(value = "考试用户统计-编辑", notes = "考试用户统计-编辑")
+    //@RequiresPermissions("examUserStatistics:edit")
+    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
+    public Result<String> edit(@RequestBody ExamUserStatistics examUserStatistics) {
+        examUserStatisticsService.updateById(examUserStatistics);
+        return Result.OK("编辑成功!");
+    }
+
+    /**
+     * 通过id删除
+     *
+     * @param id
+     * @return
+     */
+    @AutoLog(value = "考试用户统计-通过id删除")
+    @ApiOperation(value = "考试用户统计-通过id删除", notes = "考试用户统计-通过id删除")
+    //@RequiresPermissions("examUserStatistics:delete")
+    @RequestMapping(value = "/delete", method = RequestMethod.POST)
+    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
+        examUserStatisticsService.removeById(id);
+        return Result.OK("删除成功!");
+    }
+
+    /**
+     * 批量删除
+     *
+     * @param ids
+     * @return
+     */
+    @AutoLog(value = "考试用户统计-批量删除")
+    @ApiOperation(value = "考试用户统计-批量删除", notes = "考试用户统计-批量删除")
+    //@RequiresPermissions("examUserStatistics:deleteBatch")
+    @RequestMapping(value = "/deleteBatch", method = RequestMethod.POST)
+    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
+        this.examUserStatisticsService.removeByIds(Arrays.asList(ids.split(",")));
+        return Result.OK("批量删除成功!");
+    }
+
+    /**
+     * 通过id查询
+     *
+     * @param id
+     * @return
+     */
+    //@AutoLog(value = "考试用户统计-通过id查询")
+    @ApiOperation(value = "考试用户统计-通过id查询", notes = "考试用户统计-通过id查询")
+    @GetMapping(value = "/queryById")
+    public Result<ExamUserStatistics> queryById(@RequestParam(name = "id", required = true) String id) {
+        ExamUserStatistics examUserStatistics = examUserStatisticsService.getById(id);
+        if (examUserStatistics == null) {
+            return Result.error("未找到对应数据");
+        }
+        return Result.OK(examUserStatistics);
+    }
 
     /**
-    * 导出excel
-    *
-    * @param request
-    * @param examUserStatistics
-    */
+     * 导出excel
+     *
+     * @param request
+     * @param examUserStatistics
+     */
     //@RequiresPermissions("examUserStatistics:exportXls")
     @RequestMapping(value = "/exportXls")
     public ModelAndView exportXls(HttpServletRequest request, ExamUserStatistics examUserStatistics) {
-        return super.exportXls(request, examUserStatistics, ExamUserStatistics.class, "考试用户统计");
+        String examId = request.getParameter("examId");
+        Exam exam = examService.getById(examId);
+        return super.exportXls(request, examUserStatistics, ExamUserStatistics.class, exam.getTitle() + "考试用户成绩统计");
     }
 
     /**
-      * 通过excel导入数据
-    *
-    * @param request
-    * @param response
-    * @return
-    */
+     * 通过excel导入数据
+     *
+     * @param request
+     * @param response
+     * @return
+     */
     //@RequiresPermissions("examUserStatistics:importExcel")
     @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
     public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {

+ 18 - 19
web/src/main/java/com/ynfy/buss/exam/examuserstatistics/entity/ExamUserStatistics.java

@@ -62,43 +62,38 @@ public class ExamUserStatistics implements Serializable {
     /**
      * 考试id
      */
-    @Excel(name = "考试id", width = 15)
     @ApiModelProperty(value = "考试id")
     private String examId;
     /**
-     * 所属部门
+     * 用户id
      */
-    @Excel(name = "所属部门", width = 15)
-    @ApiModelProperty(value = "所属部门")
+    @ApiModelProperty(value = "用户id")
     private String userId;
     /**
      * 用户名
      */
-    @Excel(name = "用户名", width = 15)
     @ApiModelProperty(value = "用户名")
     private String username;
     /**
      * 真实姓名
      */
-    @Excel(name = "真实姓名", width = 15)
+    @Excel(name = "姓名", width = 15)
     @ApiModelProperty(value = "真实姓名")
     private String realname;
     /**
      * 组织机构编码
      */
-    @Excel(name = "组织机构编码", width = 15)
     @ApiModelProperty(value = "组织机构编码")
     private String orgCode;
     /**
      * 组织机构名称
      */
-    @Excel(name = "组织机构名称", width = 15)
+    @Excel(name = "所属部门", width = 32)
     @ApiModelProperty(value = "组织机构名称")
     private String orgName;
     /**
      * 开始考试时间
      */
-    @Excel(name = "开始考试时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
     @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @ApiModelProperty(value = "开始考试时间")
@@ -106,7 +101,6 @@ public class ExamUserStatistics implements Serializable {
     /**
      * 交卷时间
      */
-    @Excel(name = "交卷时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
     @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @ApiModelProperty(value = "交卷时间")
@@ -132,15 +126,17 @@ public class ExamUserStatistics implements Serializable {
     /**
      * 正确率
      */
-    @Excel(name = "正确率", width = 15)
+    @Excel(name = "正确率", width = 15, suffix = "%")
     @ApiModelProperty(value = "正确率")
     private Double accuracy;
+
     /**
-     * 是否通过
+     * 得分率
      */
-    @Excel(name = "是否通过", width = 15)
-    @ApiModelProperty(value = "是否通过")
-    private Integer passed;
+    @Excel(name = "得分率", width = 15, suffix = "%")
+    @ApiModelProperty(value = "得分率")
+    private Double scoreRate;
+
     /**
      * 排名
      */
@@ -149,9 +145,12 @@ public class ExamUserStatistics implements Serializable {
     private Integer rank;
 
     /**
-     * 得分率
+     * 是否通过
      */
-    @Excel(name = "得分率", width = 15)
-    @ApiModelProperty(value = "得分率")
-    private Double scoreRate;
+    @ApiModelProperty(value = "是否通过")
+    private Integer passed;
+
+    @Excel(name = "是否通过", width = 15)
+    private String passedText;
+
 }