Commit 67e2c9e8 authored by YangZhaoJun1's avatar YangZhaoJun1

简化代码

parent 2b37d575
...@@ -174,59 +174,39 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -174,59 +174,39 @@ public class BChapterServiceImpl implements BChapterService {
throw new ServiceException(ResultServiceEnums.UPDATE_ERROR); throw new ServiceException(ResultServiceEnums.UPDATE_ERROR);
} }
@Transactional(propagation = Propagation.REQUIRED,readOnly = false)
@Override @Override
public int addBslFormLesson(String bLseeonId, String lessonCode, String slId) { public int addBslFormLesson(String bLseeonId, String lessonCode, String slId) {
//获取课程的章节列表 //获取课程的章节列表
List<BChapter> lessonList = bChapterRepository.queryChapterByLessonId(bLseeonId); List<BChapter> lessonList = bChapterRepository.queryChapterByLessonId(bLseeonId);
//new一个章的list
List<BChapter> chapterList = new ArrayList<>(); List<BChapter> chapterList = new ArrayList<>();
//map存放章的ID(key:章名称 value:新的章ID) //map存放章的ID(key:章名称 value:新的章ID)
Map map = new HashMap(); Map map = new HashMap();
for (int i=0;i<lessonList.size();i++){ for (int i=0;i<lessonList.size();i++){
BChapter sl_chapter = new BChapter(); BChapter sl_chapter = new BChapter();
sl_chapter.setSlId(slId);
sl_chapter.setChapterName(lessonList.get(i).getChapterName());
sl_chapter.setChapterLevel(lessonList.get(i).getChapterLevel());
sl_chapter.setChapterUrl(lessonList.get(i).getChapterUrl());
sl_chapter.setMdFile(lessonList.get(i).getMdFile());
sl_chapter.setIsTest(lessonList.get(i).getIsTest());
sl_chapter.setLessonOrSl("0");
UserUtil.setCurrentPersistOperation(sl_chapter);
if(lessonList.get(i).getPid().equals("-1")){ if(lessonList.get(i).getPid().equals("-1")){
sl_chapter.setPid(lessonList.get(i).getPid()); sl_chapter.setPid(lessonList.get(i).getPid());
sl_chapter.setSlId(slId);
sl_chapter.setChapterName(lessonList.get(i).getChapterName());
sl_chapter.setChapterLevel(lessonList.get(i).getChapterLevel());
sl_chapter.setChapterUrl(lessonList.get(i).getChapterUrl());
sl_chapter.setMdFile(lessonList.get(i).getMdFile());
sl_chapter.setIsTest(lessonList.get(i).getIsTest());
sl_chapter.setLessonOrSl("0");
UserUtil.setCurrentPersistOperation(sl_chapter);
chapterList.add(sl_chapter);
map.put(sl_chapter.getChapterName(),sl_chapter.getBusinessId()); map.put(sl_chapter.getChapterName(),sl_chapter.getBusinessId());
} }
chapterList.add(sl_chapter);
} }
//先把章插入 for (int i=0;i<chapterList.size();i++){
int chapter = bChapterRepository.insertChapterList(chapterList);
//new一个节的list
List<BChapter> sectionList = new ArrayList<>();
for (int i=0;i<lessonList.size();i++){
BChapter sl_chapter = new BChapter(); BChapter sl_chapter = new BChapter();
if(!lessonList.get(i).getPid().equals("-1")){ if(!chapterList.get(i).getPid().equals("-1")){
//根据父ID获取父节点章节名称 //根据父ID获取父节点章节名称
String chapterName = bChapterRepository.selectChapterNameByPid(lessonList.get(i).getPid()); String chapterName = bChapterRepository.selectChapterNameByPid(lessonList.get(i).getPid());
//取出map中存放的新的章ID作为父节点ID //取出map中存放的新的章ID作为父节点ID
sl_chapter.setPid(String.valueOf(map.get(chapterName))); chapterList.get(i).setPid(String.valueOf(map.get(chapterName)));
sl_chapter.setSlId(slId);
sl_chapter.setChapterName(lessonList.get(i).getChapterName());
sl_chapter.setChapterLevel(lessonList.get(i).getChapterLevel());
sl_chapter.setChapterUrl(lessonList.get(i).getChapterUrl());
sl_chapter.setMdFile(lessonList.get(i).getMdFile());
sl_chapter.setIsTest(lessonList.get(i).getIsTest());
sl_chapter.setLessonOrSl("0");
UserUtil.setCurrentPersistOperation(sl_chapter);
sectionList.add(sl_chapter);
} }
} }
//执行插入节操作 return bChapterRepository.insertChapterList(chapterList);
int section = bChapterRepository.insertChapterList(sectionList);
if(chapter!=0&&section!=0){
return 1;
}else{
return 0;
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment