考试导出

beetlsql3-dev
Mlxa0324 2 years ago
parent 7140f20ec3
commit 8602db7513

@ -8,14 +8,15 @@ import cn.hutool.core.util.ReflectUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelProperty;
import com.ibeetl.admin.core.entity.BaseEntity; import com.ibeetl.admin.core.entity.BaseEntity;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.util.MultiValueMapAdapter; import org.springframework.util.MultiValueMapAdapter;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
/** /**
* <p> * <p>
@ -104,23 +105,29 @@ public class BeanUtil extends cn.hutool.core.bean.BeanUtil {
* value * value
* value index * value index
* *
* @param object * @param clazz
* @return
*/ */
public static <T extends BaseEntity> void processExcelAnnotation(@NotNull Class<T> object) { public static <T extends BaseEntity> Map<String, String> processExcelAnnotationToMap(@NotNull Class<T> clazz) {
Map<String, String> result = new TreeMap<>(); Map<String, String> result = new ConcurrentHashMap<>(16);
for (Field declaredField : object.getDeclaredFields()) { // 过滤有指定注解的属性
Annotation[] declaredAnnotations = declaredField.getDeclaredAnnotations(); Set<Field> filterFields = Arrays.stream(clazz.getDeclaredFields())
for (Annotation declaredAnnotation : declaredAnnotations) { .filter(declaredField -> ObjectUtil.isNotNull(AnnotationUtils.findAnnotation(declaredField, ExcelProperty.class)))
// 判断是否是easyExcel 的注解 .collect(Collectors.toSet());
if (declaredAnnotation instanceof ExcelProperty) {
ExcelProperty excelProperty = (ExcelProperty) declaredAnnotation; // 根据index属性排序,并放置到Map的返回值中
String title = excelProperty.value()[0]; filterFields.stream().sorted(Comparator.comparingInt(o -> AnnotationUtils.findAnnotation(o, ExcelProperty.class).index()))
int index = excelProperty.index(); .forEachOrdered(field -> {
result.put(declaredField.getName(), title); ExcelProperty annotation = AnnotationUtils.findAnnotation(field, ExcelProperty.class);
; String title = annotation.value()[0];
} String name = field.getName();
} // 防止覆盖
} if (!result.containsKey(name)) {
result.put(name, title);
}
});
return result;
} }
} }

@ -146,7 +146,6 @@ public class ResourcesQuestionSnapshotController extends BaseController {
Map<String, String> header = new LinkedHashMap<>(11); Map<String, String> header = new LinkedHashMap<>(11);
header.put("studentName", "学生姓名"); header.put("studentName", "学生姓名");
header.put("studentSn", "学号"); header.put("studentSn", "学号");
header.put("teacherOpenCourseIdText", "开课名称");
header.put("className", "班级名称"); header.put("className", "班级名称");
header.put("finishTime", "完成时间"); header.put("finishTime", "完成时间");
header.put("correctCount", "答对数量"); header.put("correctCount", "答对数量");
@ -154,6 +153,8 @@ public class ResourcesQuestionSnapshotController extends BaseController {
header.put("correctRate", "正确率 (100)%"); header.put("correctRate", "正确率 (100)%");
header.put("totalScore", "总得分"); header.put("totalScore", "总得分");
// Map<String, String> header = processExcelAnnotationToMap(TeacherOpenCourseQuestionTestDetailVO.class);
PageQuery<TeacherOpenCourseQuestionTestDetailVO> data = resourcesQuestionSnapshotService.questionTestResults(condition.getPageQuery()); PageQuery<TeacherOpenCourseQuestionTestDetailVO> data = resourcesQuestionSnapshotService.questionTestResults(condition.getPageQuery());
List<Map<String, Object>> maps = baseEntity2MapWithParallel(data.getList()); List<Map<String, Object>> maps = baseEntity2MapWithParallel(data.getList());

Loading…
Cancel
Save