mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-11 20:06:51 +08:00
作业导出bug
This commit is contained in:
@@ -29,6 +29,8 @@ import com.xboe.module.course.dao.CourseSectionDao;
|
|||||||
import com.xboe.module.course.entity.*;
|
import com.xboe.module.course.entity.*;
|
||||||
import com.xboe.module.course.vo.TeacherVo;
|
import com.xboe.module.course.vo.TeacherVo;
|
||||||
import com.xboe.module.usergroup.entity.UserGroupItem;
|
import com.xboe.module.usergroup.entity.UserGroupItem;
|
||||||
|
import com.xboe.school.study.entity.StudyHomeWork;
|
||||||
|
import com.xboe.school.study.service.IStudyHomeWorkService;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
@@ -97,17 +99,8 @@ public class CoursePortalApi extends ApiBaseController{
|
|||||||
@Resource
|
@Resource
|
||||||
private ThirdApi thirdApi;
|
private ThirdApi thirdApi;
|
||||||
|
|
||||||
@Resource
|
@Autowired
|
||||||
private CourseHomeWorkDao homeworkDao;
|
IStudyHomeWorkService shomeworkService;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private CourseContentDao ccDao;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private CourseSectionDao courseSectionDao;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private CourseDao courseDao;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
StringRedisTemplate redisTemplate;
|
StringRedisTemplate redisTemplate;
|
||||||
@@ -369,35 +362,43 @@ public class CoursePortalApi extends ApiBaseController{
|
|||||||
}
|
}
|
||||||
//作业导出
|
//作业导出
|
||||||
@GetMapping("/export")
|
@GetMapping("/export")
|
||||||
public void export(String contentId, String courseName,HttpServletResponse response) throws IOException {
|
public void export(String contentId, String courseName,String studentName,HttpServletResponse response) throws IOException {
|
||||||
//将courseId以逗号分割转换为list
|
// 将courseId以逗号分割转换为list
|
||||||
List<String> contentIds = Arrays.asList(contentId.split(","));
|
List<String> studentNames = Arrays.asList(studentName.split(","));
|
||||||
Map<String, String>map=new HashMap<>();
|
Map<String, String>map=new HashMap<>();
|
||||||
try {
|
try {
|
||||||
homeworkDao.findList(FieldFilters.in("content_id", contentIds)).stream().filter(Objects::nonNull).forEach(e -> {
|
// homeworkDao.findList(FieldFilters.in("content_id", contentIds)).stream().filter(Objects::nonNull).forEach(e -> {
|
||||||
//查询内容名称
|
// //查询内容名称
|
||||||
CourseContent courseContent=contentService.getById(e.getContentId());
|
// CourseContent courseContent=contentService.getById(e.getContentId());
|
||||||
if(courseContent!=null &&courseContent.getContentName()==null){
|
// if(courseContent!=null &&courseContent.getContentName()==null){
|
||||||
courseContent.setContentName("作业");
|
// courseContent.setContentName("作业");
|
||||||
}
|
// }
|
||||||
//查询目录
|
// //查询目录
|
||||||
List<CourseSection> courseSections = sectionService.getByCourseId(e.getCourseId());
|
// List<CourseSection> courseSections = sectionService.getByCourseId(e.getCourseId());
|
||||||
|
// //取作业后缀名
|
||||||
|
// int dotIndex = e.getFile().lastIndexOf('.'); // 查找最后一个'.'的位置
|
||||||
|
// String extension = e.getFile().substring(dotIndex);
|
||||||
|
// //判断是否有目录
|
||||||
|
// if(!courseSections.isEmpty()){
|
||||||
|
// map.put(courseSections.get(0).getName()+"--"+courseContent.getContentName()+extension, "/home/www/elearning/upload"+e.getFile());
|
||||||
|
// }else {
|
||||||
|
// Course course=courseDao.get(e.getCourseId());
|
||||||
|
// if(course==null || course.getDeleted()){
|
||||||
|
// throw new RuntimeException("课程不存在或已被删除");
|
||||||
|
// }
|
||||||
|
// map.put(course.getName()+"--"+courseContent.getContentName()+extension, "/home/www/elearning/upload"+e.getFile());
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
shomeworkService.getByStudnetNameAndContentId(studentNames,contentId).stream().filter(Objects::nonNull).filter(e->e.getFilePath()!=null).forEach(e->{
|
||||||
//取作业后缀名
|
//取作业后缀名
|
||||||
int dotIndex = e.getFile().lastIndexOf('.'); // 查找最后一个'.'的位置
|
int dotIndex = e.getFilePath().lastIndexOf('/'); // 查找最后一个'.'的位置
|
||||||
String extension = e.getFile().substring(dotIndex);
|
String extension = e.getFilePath().substring(dotIndex+1);
|
||||||
//判断是否有目录
|
map.put(extension,e.getFilePath());
|
||||||
if(!courseSections.isEmpty()){
|
|
||||||
map.put(courseSections.get(0).getName()+"--"+courseContent.getContentName()+extension, "/home/www/elearning/upload"+e.getFile());
|
|
||||||
}else {
|
|
||||||
Course course=courseDao.get(e.getCourseId());
|
|
||||||
if(course==null || course.getDeleted()){
|
|
||||||
throw new RuntimeException("课程不存在或已被删除");
|
|
||||||
}
|
|
||||||
map.put(course.getName()+"--"+courseContent.getContentName()+extension, "/home/www/elearning/upload"+e.getFile());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("导出异常");
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException("导出异常"+e.getMessage());
|
||||||
}
|
}
|
||||||
String encodedFilename = URLEncoder.encode(courseName+"【作业】.zip")
|
String encodedFilename = URLEncoder.encode(courseName+"【作业】.zip")
|
||||||
.replace("+", "%20") // 空格替换为"%20"
|
.replace("+", "%20") // 空格替换为"%20"
|
||||||
|
|||||||
@@ -83,5 +83,4 @@ public interface ICourseContentService{
|
|||||||
*/
|
*/
|
||||||
CourseAssess getAssess(String ccid);
|
CourseAssess getAssess(String ccid);
|
||||||
|
|
||||||
CourseContent getById(String contentId);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,12 +141,6 @@ public class CourseContentServiceImpl implements ICourseContentService {
|
|||||||
return assess;
|
return assess;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public CourseContent getById(String contentId) {
|
|
||||||
CourseContent courseContent = ccDao.findOne(FieldFilters.eq("id", contentId));
|
|
||||||
return courseContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void updateName(String id, String name) {
|
public void updateName(String id, String name) {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class StudyHomeWorkApi extends ApiBaseController{
|
|||||||
IStudyHomeWorkService shomeworkService;
|
IStudyHomeWorkService shomeworkService;
|
||||||
@Resource
|
@Resource
|
||||||
private ThirdApi thirdApi;
|
private ThirdApi thirdApi;
|
||||||
@PostMapping("/save")
|
@PostMapping("/`save`")
|
||||||
public JsonResponse<StudyHomeWork> save(@RequestBody StudyHomeWork shw, HttpServletRequest request){
|
public JsonResponse<StudyHomeWork> save(@RequestBody StudyHomeWork shw, HttpServletRequest request){
|
||||||
if(StringUtils.isBlank(shw.getCourseId())) {
|
if(StringUtils.isBlank(shw.getCourseId())) {
|
||||||
return badRequest("无课程信息");
|
return badRequest("无课程信息");
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.xboe.school.study.service;
|
package com.xboe.school.study.service;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.xboe.school.study.entity.StudyHomeWork;
|
import com.xboe.school.study.entity.StudyHomeWork;
|
||||||
@@ -29,4 +30,6 @@ public interface IStudyHomeWorkService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<StudyHomeWork> getByStudyIdAndContentId(String studyId,String contentId);
|
List<StudyHomeWork> getByStudyIdAndContentId(String studyId,String contentId);
|
||||||
|
|
||||||
|
List<StudyHomeWork>getByStudnetNameAndContentId(List<String> studentName, String contentId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,4 +89,9 @@ public class StudyHomeWorkServiceImpl implements IStudyHomeWorkService{
|
|||||||
return dao.findList(FieldFilters.eq("studyId", studyId),FieldFilters.eq("contentId", contentId));
|
return dao.findList(FieldFilters.eq("studyId", studyId),FieldFilters.eq("contentId", contentId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<StudyHomeWork> getByStudnetNameAndContentId(List<String> studentName, String contentId) {
|
||||||
|
return dao.findList(FieldFilters.in("student_name", studentName),FieldFilters.eq("contentId", contentId));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user