main
tamguo 7 years ago
parent 95f5396e8a
commit dda8c4877f

@ -2,11 +2,16 @@ package com.tamguo.dao;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.tamguo.config.dao.SuperMapper;
import com.tamguo.model.ChapterEntity;
import com.tamguo.model.CourseEntity;
public interface CourseMapper extends SuperMapper<CourseEntity>{
List<CourseEntity> findBySubjectId(String uid);
List<ChapterEntity> findByCourseId(@Param(value="courseId") String courseId);
}

@ -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);
}
}
}

@ -17,4 +17,13 @@
ORDER BY orders ASC
</select>
<select id="findByCourseId" resultType="ChapterEntity">
SELECT
c.uid,c.course_id , c.parent_id , c.`name` , c.question_num , c.point_num , c.orders
FROM
tiku_chapter c
WHERE c.course_id = #{courseId}
ORDER BY c.uid asc
</select>
</mapper>

@ -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);

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="Zh-hans" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<meta charset="utf-8">
@ -29,7 +29,6 @@
<mu-icon value="chevron_right" slot="divider"></mu-icon>
<mu-breadcrumbs-item :disabled="true">当前位置</mu-breadcrumbs-item>
<mu-breadcrumbs-item :disabled="true">理科数学</mu-breadcrumbs-item>
<mu-breadcrumbs-item :disabled="true">第一章 社会工作概述</mu-breadcrumbs-item>
</mu-breadcrumbs>
</mu-container>
<mu-list textline="three-line">
@ -90,18 +89,10 @@
<mu-drawer :open.sync="open" :docked="docked" :right="position === 'right'">
<mu-list>
<mu-list-item button>
<mu-list-item-title>理科数学</mu-list-item-title>
</mu-list-item>
<mu-list-item button>
<mu-list-item-title>文科数学</mu-list-item-title>
</mu-list-item>
<mu-list-item button>
<mu-list-item-title>物理</mu-list-item-title>
</mu-list-item>
<mu-list-item button>
<mu-list-item-title>英语</mu-list-item-title>
<mu-list-item button v-for="course in courseList" @click="open = false">
<mu-list-item-title>{{course.name}}</mu-list-item-title>
</mu-list-item>
<mu-list-item @click="open = false" button>
<mu-list-item-title>关闭</mu-list-item-title>
</mu-list-item>
@ -113,16 +104,11 @@
<!-- 引入 Vue -->
<script type="text/javascript" th:inline="javascript">
var mainHttp = [[${setting.domain}]];
var subjectId = [[${subjectId}]];
var courseId = [[${courseId}]];
</script>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.16"></script>
<script src="https://cdn.jsdelivr.net/npm/muse-ui@3.0.0-rc.5/dist/muse-ui.min.js"></script>
<script type="text/javascript">
new Vue({data:{docked: false,
open: true,
position: 'left',panel: ''},methods: {
toggle (panel) {
this.panel = panel === this.panel ? '' : panel;
}
}}).$mount('#app')
</script>
<script src="https://cdn.jsdelivr.net/npm/axios@0.18.0/dist/axios.min.js"></script>
<script th:src="${setting.domain + 'js/chapter/main.js'}"></script>
</html>
Loading…
Cancel
Save