main
parent
95f5396e8a
commit
dda8c4877f
@ -0,0 +1,11 @@
|
||||
package com.tamguo.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.tamguo.model.ChapterEntity;
|
||||
|
||||
public interface ICourseService {
|
||||
|
||||
// 获取科目章节
|
||||
public List<ChapterEntity> findCourseChapter(String courseId);
|
||||
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package com.tamguo.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.tamguo.dao.CourseMapper;
|
||||
import com.tamguo.model.ChapterEntity;
|
||||
import com.tamguo.service.ICourseService;
|
||||
|
||||
@Service
|
||||
public class CourseService implements ICourseService{
|
||||
|
||||
@Autowired
|
||||
private CourseMapper courseMapper;
|
||||
|
||||
@Override
|
||||
public List<ChapterEntity> findCourseChapter(String courseId) {
|
||||
List<ChapterEntity> chapterList = courseMapper.findByCourseId(courseId);
|
||||
|
||||
// 获取根chapter UID
|
||||
String rootUid = StringUtils.EMPTY;
|
||||
for(int i=0 ; i<chapterList.size() ; i++){
|
||||
ChapterEntity chapter = chapterList.get(i);
|
||||
if(chapter.getParentId().equals("-1")){
|
||||
rootUid = chapter.getUid();
|
||||
}
|
||||
}
|
||||
// 获取第一层结构
|
||||
List<ChapterEntity> entitys = new ArrayList<>();
|
||||
for(int i=0 ; i<chapterList.size() ; i++){
|
||||
ChapterEntity chapter = chapterList.get(i);
|
||||
if(rootUid.equals(chapter.getParentId())){
|
||||
entitys.add(chapter);
|
||||
}
|
||||
}
|
||||
for(int i=0 ; i<entitys.size() ; i++){
|
||||
ChapterEntity entity = entitys.get(i);
|
||||
List<ChapterEntity> childs = new ArrayList<>();
|
||||
for(int k=0 ; k<chapterList.size() ; k++){
|
||||
ChapterEntity chapter = chapterList.get(k);
|
||||
if(entity.getUid().equals(chapter.getParentId())){
|
||||
childs.add(chapter);
|
||||
}
|
||||
}
|
||||
entity.setChildChapterList(childs);
|
||||
}
|
||||
for(int i=0 ; i<entitys.size() ; i++){
|
||||
List<ChapterEntity> childs = entitys.get(i).getChildChapterList();
|
||||
for(int k=0 ; k<childs.size() ; k++){
|
||||
ChapterEntity child = childs.get(k);
|
||||
List<ChapterEntity> tmpChilds = new ArrayList<>();
|
||||
for(int n=0 ; n<chapterList.size() ; n++){
|
||||
ChapterEntity chapter = chapterList.get(n);
|
||||
if(child.getUid().equals(chapter.getParentId())){
|
||||
tmpChilds.add(chapter);
|
||||
}
|
||||
}
|
||||
child.setChildChapterList(tmpChilds);
|
||||
}
|
||||
}
|
||||
return entitys;
|
||||
}
|
||||
}
|
@ -1,23 +1,58 @@
|
||||
package com.tamguo.web;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.tamguo.model.ChapterEntity;
|
||||
import com.tamguo.model.CourseEntity;
|
||||
import com.tamguo.service.ICourseService;
|
||||
import com.tamguo.service.ISubjectService;
|
||||
import com.tamguo.util.ExceptionSupport;
|
||||
import com.tamguo.util.Result;
|
||||
|
||||
@Controller
|
||||
public class ChapterController {
|
||||
|
||||
@Autowired
|
||||
private ISubjectService iSubjectService;
|
||||
@Autowired
|
||||
private ICourseService iCourseService;
|
||||
|
||||
@RequestMapping(path= {"chapter/{subjectId}/{courseId}"})
|
||||
public String chapter(@PathVariable String subjectId , @PathVariable String courseId , ModelAndView model) {
|
||||
model.addObject("courseList", iSubjectService.findCourseList(subjectId));
|
||||
model.addObject("subjectId", subjectId);
|
||||
model.addObject("courseId", courseId);
|
||||
return "chapter";
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(path="chapter/findCourseList",method=RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Result findAllMenus(String subjectId) {
|
||||
try {
|
||||
List<CourseEntity> courseList = iSubjectService.findCourseList(subjectId);
|
||||
return Result.successResult(courseList);
|
||||
} catch (Exception e) {
|
||||
return ExceptionSupport.resolverResult("查询科目", this.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(path="chapter/findChapterList",method=RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Result findChapterList(String courseId) {
|
||||
try {
|
||||
List<ChapterEntity> chapterList = iCourseService.findCourseChapter(courseId);
|
||||
return Result.successResult(chapterList);
|
||||
} catch (Exception e) {
|
||||
return ExceptionSupport.resolverResult("查询章节", this.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
var vm = new Vue({
|
||||
el:'#app',
|
||||
data : {
|
||||
courseList:[],
|
||||
chapterList:[],
|
||||
docked: false,
|
||||
open: true,
|
||||
position: 'left',
|
||||
panel: ''
|
||||
},
|
||||
methods:{
|
||||
findCourseList(subjectId){
|
||||
axios({method: 'post',url: mainHttp + 'chapter/findCourseList.html?subjectId='+subjectId}).then(function(response){
|
||||
if(response.data.code == 0){
|
||||
vm.courseList = response.data.result;
|
||||
}
|
||||
});
|
||||
},
|
||||
findChapterList(courseId){
|
||||
axios({method: 'post',url: mainHttp + 'chapter/findChapterList.html?courseId='+courseId}).then(function(response){
|
||||
if(response.data.code == 0){
|
||||
vm.courseList = response.data.result;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
vm.findCourseList(subjectId);
|
||||
vm.findChapterList(courseId);
|
Loading…
Reference in new issue