mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-11 03:46:50 +08:00
feat: 资源学习情况导出-作业信息初版接口(缺少附件和zip导出)
This commit is contained in:
@@ -1388,6 +1388,136 @@ public class StudyCourseApi extends ApiBaseController{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 资源学习情况导出-作业信息
|
||||
* 导出单个作业信息
|
||||
*
|
||||
* @param courseId 课程id
|
||||
* @param contentId 内容id
|
||||
*/
|
||||
@RequestMapping(value = "/contents-homework-export", method = {RequestMethod.GET, RequestMethod.POST})
|
||||
public void findPageHomework(String courseId, String contentId, HttpServletResponse response) {
|
||||
if (StringUtils.isBlank(courseId)) {
|
||||
log.error("【资源学习情况导出-作业信息】课程id不能为空");
|
||||
return;
|
||||
}
|
||||
if (StringUtils.isBlank(contentId)) {
|
||||
log.error("【资源学习情况导出-作业信息】内容id不能为空");
|
||||
return;
|
||||
}
|
||||
OutputStream outputStream = null;
|
||||
try {
|
||||
outputStream = response.getOutputStream();
|
||||
LinkedHashMap<String, String> exportMap = new LinkedHashMap<>();
|
||||
// 1.拼接固定表头(课程名称、资源名称、姓名、工号、部门、作业状态、作业成绩、完成时间)
|
||||
exportMap.put("课程名称", "课程名称");
|
||||
exportMap.put("资源名称", "资源名称");
|
||||
exportMap.put("姓名", "姓名");
|
||||
exportMap.put("工号", "工号");
|
||||
exportMap.put("部门", "部门");
|
||||
exportMap.put("作业状态", "作业状态");
|
||||
exportMap.put("作业成绩", "作业成绩");
|
||||
exportMap.put("完成时间", "完成时间");
|
||||
// 查询课程名称
|
||||
StudyCourse studyCourse = new StudyCourse();
|
||||
studyCourse.setCourseId(courseId);
|
||||
List<StudyCourse> studyCourses = service.findList(studyCourse, null, null);
|
||||
String courseName;
|
||||
if (studyCourses != null && !studyCourses.isEmpty()) {
|
||||
courseName = studyCourses.get(0).getCourseName();
|
||||
} else {
|
||||
courseName = "";
|
||||
}
|
||||
// 查询资源名称
|
||||
List<CourseContent> courseContents = contentService.getByCourseId(courseId);
|
||||
String contentName = "";
|
||||
if (courseContents != null && !courseContents.isEmpty()) {
|
||||
for (CourseContent cc : courseContents) {
|
||||
if (contentId.equals(cc.getId())) {
|
||||
contentName = cc.getContentName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 查询特定作业信息
|
||||
List<StudyHomeWork> studyHomeWorks = studyHomeWorkService.getByCourseIdAndContentId(courseId, contentId);
|
||||
// 通过studyHomeWorks中的人员id集合(去重),调用用户中心接口获取人员信息,填充部门字段
|
||||
Set<String> userIds = studyHomeWorks.stream().map(StudyHomeWork::getStudentId).filter(Objects::nonNull).collect(Collectors.toSet());
|
||||
List<UserSimpleVo> userList = new ArrayList<>();
|
||||
if (!userIds.isEmpty()) {
|
||||
// 调用用户中心接口
|
||||
List<UserSimpleVo> userSimpleVos = outsideService.findByIds(new ArrayList<>(userIds));
|
||||
if (userSimpleVos != null && !userSimpleVos.isEmpty()) {
|
||||
userList.addAll(userSimpleVos);
|
||||
} else {
|
||||
log.error("【资源学习情况导出-作业信息】用户信息查询失败,查询boe人员表作为兜底方案");
|
||||
// 查询boe的人员表作为兜底方案
|
||||
for (String userId : userIds) {
|
||||
// 用户信息也是redis获取的
|
||||
User userInfo = userService.get(userId);
|
||||
if (userInfo != null) {
|
||||
UserSimpleVo userSimpleVo = new UserSimpleVo();
|
||||
userSimpleVo.setAid(userInfo.getId());
|
||||
userSimpleVo.setCode(userInfo.getUserNo());
|
||||
// 获取部门信息
|
||||
String departName = organizationService.getName(userInfo.getDepartId());
|
||||
userSimpleVo.setOrgInfo(StringUtils.isNotBlank(departName) ? departName : "");
|
||||
userList.add(userSimpleVo);
|
||||
log.info("【资源学习情况导出-作业信息】查询boe人员表,用户id:{}", userId);
|
||||
} else {
|
||||
log.error("【资源学习情况导出-作业信息】用户信息查询boe人员表失败,用户id:{}", userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 将作业信息与用户信息拼接为map
|
||||
String finalContentName = contentName;
|
||||
List<Map<String, Object>> dataList = studyHomeWorks.stream().map(hw -> {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
// 拼接基本信息
|
||||
map.put("课程名称", courseName);
|
||||
map.put("资源名称", finalContentName);
|
||||
map.put("姓名", hw.getStudentName());
|
||||
// 工号和部门信息需要从用户信息中获取
|
||||
String userNo = "";
|
||||
String orgInfo = "";
|
||||
for (UserSimpleVo user : userList) {
|
||||
if (hw.getStudentId().equals(user.getAid())) {
|
||||
userNo = user.getCode();
|
||||
orgInfo = user.getOrgInfo();
|
||||
break;
|
||||
}
|
||||
}
|
||||
map.put("工号", userNo);
|
||||
map.put("部门", orgInfo);
|
||||
// 作业状态(如果有成绩则为已完成,否则为未完成)
|
||||
String hwStatus = (hw.getScore() != null) ? "已完成" : "未完成";
|
||||
map.put("作业状态", hwStatus);
|
||||
// 作业成绩
|
||||
map.put("作业成绩", hw.getScore());
|
||||
// 完成时间
|
||||
map.put("完成时间", hw.getEndTime());
|
||||
return map;
|
||||
}).collect(Collectors.toList());
|
||||
// 设置响应头信息
|
||||
response.setContentType("application/octet-stream");
|
||||
response.setHeader("Content-disposition", "attachment;filename=HomeWorkRecord.xlsx");
|
||||
// 调用动态列excel导出接口
|
||||
ExportsExcelSenderUtil.exportDynamic(exportMap, dataList, outputStream, "yyyy-MM-dd HH:mm:ss");
|
||||
} catch (Exception e) {
|
||||
log.error("【资源学习情况导出-作业信息】导出资源学习情况错误:{}", e.getMessage());
|
||||
} finally {
|
||||
if (outputStream != null) {
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
log.error("关闭输出流失败:{}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value="/study-course-content",method = {RequestMethod.GET,RequestMethod.POST})
|
||||
public JsonResponse<StudyCourseItem> findStudyCourseItem(String studyId,String contentId){
|
||||
if(StringUtils.isBlank(studyId)){
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package com.xboe.school.study.service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.xboe.school.study.entity.StudyHomeWork;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IStudyHomeWorkService {
|
||||
|
||||
/**
|
||||
@@ -12,17 +11,17 @@ public interface IStudyHomeWorkService {
|
||||
* @param exam
|
||||
*/
|
||||
void save(StudyHomeWork homework,String token);
|
||||
|
||||
|
||||
|
||||
|
||||
StudyHomeWork get(String id);
|
||||
|
||||
|
||||
/**
|
||||
* 根据学习内容id得到答卷信息
|
||||
* @param studyItemId
|
||||
* @return
|
||||
*/
|
||||
List<StudyHomeWork> getByStudyItem(String studyItemId);
|
||||
|
||||
|
||||
/**
|
||||
* 根据学习id和内容id查出作业列表
|
||||
* @param studyId
|
||||
@@ -32,4 +31,15 @@ public interface IStudyHomeWorkService {
|
||||
List<StudyHomeWork> getByStudyIdAndContentId(String studyId,String contentId);
|
||||
|
||||
List<StudyHomeWork>getByStudnetNameAndContentId(List<String> studentName, String contentId);
|
||||
|
||||
/**
|
||||
* 根据课程id得到对应的作业记录
|
||||
* 25.11.20新增
|
||||
*
|
||||
* @param courseId 课程id
|
||||
* @param contentId 内容id
|
||||
* @return 作业记录集合
|
||||
*/
|
||||
List<StudyHomeWork> getByCourseIdAndContentId(String courseId, String contentId);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
package com.xboe.school.study.service.impl;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.xboe.common.OrderCondition;
|
||||
import com.xboe.core.orm.FieldFilters;
|
||||
import com.xboe.core.orm.IFieldFilter;
|
||||
import com.xboe.module.course.dao.CourseContentDao;
|
||||
import com.xboe.school.study.dao.StudyCourseDao;
|
||||
import com.xboe.school.study.dao.StudyCourseItemDao;
|
||||
@@ -17,6 +10,14 @@ import com.xboe.school.study.dao.StudyHomeWorkDao;
|
||||
import com.xboe.school.study.entity.StudyCourseItem;
|
||||
import com.xboe.school.study.entity.StudyHomeWork;
|
||||
import com.xboe.school.study.service.IStudyHomeWorkService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.transaction.Transactional;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class StudyHomeWorkServiceImpl implements IStudyHomeWorkService{
|
||||
@@ -95,4 +96,24 @@ public class StudyHomeWorkServiceImpl implements IStudyHomeWorkService{
|
||||
return dao.findList(FieldFilters.in("student_name", studentName),FieldFilters.eq("contentId", contentId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据课程id得到对应的作业记录
|
||||
* 25.11.20新增
|
||||
*
|
||||
* @param courseId 课程id
|
||||
* @param contentId 内容id
|
||||
* @return 作业记录集合
|
||||
*/
|
||||
@Override
|
||||
public List<StudyHomeWork> getByCourseIdAndContentId(String courseId, String contentId) {
|
||||
if (StringUtils.isEmpty(courseId)) {
|
||||
throw new IllegalArgumentException("课程id不能为空");
|
||||
}
|
||||
IFieldFilter filter = FieldFilters.eq("courseId", courseId);
|
||||
if (StringUtils.isNotEmpty(contentId)) {
|
||||
filter = FieldFilters.and(filter, FieldFilters.eq("contentId", contentId));
|
||||
}
|
||||
return dao.findList(OrderCondition.desc("id"), filter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user