From ec4bd7c526c2c7f91ce970729ddd8303db966f00 Mon Sep 17 00:00:00 2001 From: xiaoCJ <406612557@qq.com> Date: Fri, 17 May 2024 12:15:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=80=81=E5=B8=88=E7=AB=AF?= =?UTF-8?q?=E5=8D=95=E7=82=B9=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/SysCourseChapterMapper.java | 2 + .../common/impl/CourseServiceImpl.java | 6 +- .../tea/impl/TeaObjectiveServiceImpl.java | 77 ++-- .../mapper/SysCourseChapterMapper.xml | 388 +++++++++--------- 4 files changed, 254 insertions(+), 219 deletions(-) diff --git a/src/main/java/com/sztzjy/financial_bigdata/mapper/SysCourseChapterMapper.java b/src/main/java/com/sztzjy/financial_bigdata/mapper/SysCourseChapterMapper.java index ac77e98..7bcbd0f 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/mapper/SysCourseChapterMapper.java +++ b/src/main/java/com/sztzjy/financial_bigdata/mapper/SysCourseChapterMapper.java @@ -36,4 +36,6 @@ public interface SysCourseChapterMapper { @Select("SELECT COUNT(chapter_id) FROM sys_course JOIN sys_course_chapter WHERE sys_course.course_id = sys_course_chapter.course_id AND school_Id in(999999999,#{schoolId})") BigDecimal selectChapterBySchoolId(@Param("schoolId")String schoolId); + + List selectChapterDataBySchoolId(@Param("schoolId")String schoolId); } \ No newline at end of file diff --git a/src/main/java/com/sztzjy/financial_bigdata/service/common/impl/CourseServiceImpl.java b/src/main/java/com/sztzjy/financial_bigdata/service/common/impl/CourseServiceImpl.java index 1531694..75c04bc 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/service/common/impl/CourseServiceImpl.java +++ b/src/main/java/com/sztzjy/financial_bigdata/service/common/impl/CourseServiceImpl.java @@ -10,6 +10,7 @@ import com.sztzjy.financial_bigdata.service.common.ICourseService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -72,7 +73,10 @@ public class CourseServiceImpl implements ICourseService { public List selectAllBySchoolId(String schoolId) { SysCourseExample example=new SysCourseExample(); SysCourseExample.Criteria criteria = example.createCriteria(); - criteria.andSchoolIdEqualTo(schoolId); + List list =new ArrayList(); + list.add("999999999"); + list.add(schoolId); + criteria.andSchoolIdIn(list); List courseList = courseMapper.selectByExample(example); return courseList; } diff --git a/src/main/java/com/sztzjy/financial_bigdata/service/tea/impl/TeaObjectiveServiceImpl.java b/src/main/java/com/sztzjy/financial_bigdata/service/tea/impl/TeaObjectiveServiceImpl.java index 4a4a966..aad0c67 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/service/tea/impl/TeaObjectiveServiceImpl.java +++ b/src/main/java/com/sztzjy/financial_bigdata/service/tea/impl/TeaObjectiveServiceImpl.java @@ -7,11 +7,11 @@ import com.sztzjy.financial_bigdata.entity.SysCourse; import com.sztzjy.financial_bigdata.entity.SysCourseChapter; import com.sztzjy.financial_bigdata.entity.SysObjectiveQuestion; import com.sztzjy.financial_bigdata.entity.SysObjectiveQuestionExample; +import com.sztzjy.financial_bigdata.mapper.SysCourseChapterMapper; import com.sztzjy.financial_bigdata.mapper.SysObjectiveQuestionMapper; import com.sztzjy.financial_bigdata.service.common.ICourseChapterService; import com.sztzjy.financial_bigdata.service.common.ICourseService; import com.sztzjy.financial_bigdata.service.tea.ITeaObjectiveService; -import io.swagger.models.auth.In; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.ss.usermodel.*; import org.springframework.beans.factory.annotation.Autowired; @@ -30,6 +30,9 @@ public class TeaObjectiveServiceImpl implements ITeaObjectiveService { ICourseService courseService; @Autowired ICourseChapterService chapterService; + @Autowired + SysCourseChapterMapper sysCourseChapterMapper; + @Override public Boolean insertObjective(SysObjectiveQuestion objectiveQuestion) { @@ -112,13 +115,13 @@ public class TeaObjectiveServiceImpl implements ITeaObjectiveService { iterator.next(); while (iterator.hasNext()) { Row currentRow = iterator.next(); - String courseName = currentRow.getCell(0).getStringCellValue(); //课程名称 - String chapterName = currentRow.getCell(1).getStringCellValue(); //章节名称 - String type = String.valueOf(currentRow.getCell(2).getNumericCellValue()); //题目类型 - String score = String.valueOf(currentRow.getCell(3).getNumericCellValue()); //分数 + String courseName = currentRow.getCell(0).getStringCellValue().trim(); //课程名称 + String chapterName = currentRow.getCell(1).getStringCellValue().trim(); //章节名称 + String type = String.valueOf(currentRow.getCell(2).getNumericCellValue()).trim(); //题目类型 + String score = String.valueOf(currentRow.getCell(3).getNumericCellValue()).trim(); //分数 String content = currentRow.getCell(4).getStringCellValue(); //题目内容 System.out.println(chapterName); - System.out.println("!!!"+content); + System.out.println("!!!" + content); String question_a = ""; String question_b = ""; String question_c = ""; @@ -145,12 +148,12 @@ public class TeaObjectiveServiceImpl implements ITeaObjectiveService { obj.setChapterId(chapterMap.get(chapterName)); obj.setChapterName(chapterName); obj.setInputType(Constant.INPUT_TYPE_BUILT_IN); - if(type.equals("0.0")){ - type="0"; - }else if(type.equals("1.0")){ - type="1"; - }else { - type="2"; + if (type.equals("0.0")) { + type = "0"; + } else if (type.equals("1.0")) { + type = "1"; + } else { + type = "2"; } obj.setType(type); obj.setScore(new BigDecimal(score)); @@ -166,57 +169,69 @@ public class TeaObjectiveServiceImpl implements ITeaObjectiveService { } } else { //老师批量新增题目 List courseList = courseService.selectAllBySchoolId(schoolId); - List builtInList = courseService.selectAllBuiltIn(); - courseList.addAll(builtInList); Map courseMap = new HashMap<>(); + Map courseChapterMap = new HashMap<>(); for (int i = 0; i < courseList.size(); i++) { courseMap.put(courseList.get(i).getCourseName(), courseList.get(i).getCourseId()); } + List chapterList = sysCourseChapterMapper.selectChapterDataBySchoolId(schoolId); + for (int i = 0; i < chapterList.size(); i++) { + courseChapterMap.put(chapterList.get(i).getChapterName(), chapterList.get(i).getChapterId()); + } + Workbook workbook = WorkbookFactory.create(file.getInputStream()); Sheet sheet = workbook.getSheetAt(0); // 迭代每一行 Iterator iterator = sheet.iterator(); + iterator.next(); while (iterator.hasNext()) { Row currentRow = iterator.next(); String courseName = currentRow.getCell(0).getStringCellValue(); //课程名称 - String type = String.valueOf(currentRow.getCell(1).getNumericCellValue()); //题目类型 - String score = String.valueOf(currentRow.getCell(2).getNumericCellValue()); //分数 - String content = currentRow.getCell(3).getStringCellValue(); //题目内容 + String chapterName = currentRow.getCell(1).getStringCellValue(); //章节名称 + String type = String.valueOf(currentRow.getCell(2).getNumericCellValue()); //题目类型 + String score = String.valueOf(currentRow.getCell(3).getNumericCellValue()); //分数 + String content = currentRow.getCell(4).getStringCellValue(); //题目内容 String question_a = ""; String question_b = ""; String question_c = ""; String question_d = ""; + if (type.equals("2.0") || type.equals("2")) { question_a = "正确"; question_b = "错误"; } else { - question_a = currentRow.getCell(4).getStringCellValue(); - question_b = currentRow.getCell(5).getStringCellValue(); - question_c = currentRow.getCell(6).getStringCellValue(); - question_d = currentRow.getCell(7).getStringCellValue(); + question_a = currentRow.getCell(5).getStringCellValue(); + question_b = currentRow.getCell(6).getStringCellValue(); + question_c = currentRow.getCell(7).getStringCellValue(); + question_d = currentRow.getCell(8).getStringCellValue(); } - String answer = currentRow.getCell(8).getStringCellValue(); - Cell cell = currentRow.getCell(9); + String answer = currentRow.getCell(9).getStringCellValue(); + Cell cell = currentRow.getCell(10); String analyze = (cell != null) ? cell.getStringCellValue() : ""; SysObjectiveQuestion obj = new SysObjectiveQuestion(); obj.setObjectiveId(String.valueOf(UUID.randomUUID())); obj.setCourseId(courseMap.get(courseName)); + String s = courseMap.get(courseName); + System.out.println(s); + obj.setScore(new BigDecimal(score)); obj.setCourseName(courseName); + obj.setChapterName(chapterName); + obj.setChapterId(courseChapterMap.get(chapterName)); obj.setInputType(Constant.INPUT_TYPE_TEACHER); - if(type.equals("0.0")){ - type="0"; - }else if(type.equals("1.0")){ - type="1"; - }else { - type="2"; + if (type.equals("0.0")) { + type = "0"; + } else if (type.equals("1.0")) { + type = "1"; + } else { + type = "2"; } - obj.setType(String.valueOf(type)); - obj.setScore(new BigDecimal(score)); + + obj.setType(type); obj.setContent(content); obj.setQuestionA(question_a); obj.setQuestionB(question_b); diff --git a/src/main/resources/mapper/SysCourseChapterMapper.xml b/src/main/resources/mapper/SysCourseChapterMapper.xml index 7b657b7..0aa35bb 100644 --- a/src/main/resources/mapper/SysCourseChapterMapper.xml +++ b/src/main/resources/mapper/SysCourseChapterMapper.xml @@ -1,196 +1,210 @@ - - - - - - - - - - - - - - - and ${criterion.condition} - - - and ${criterion.condition} #{criterion.value} - - - and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} - - - and ${criterion.condition} - - #{listItem} - - - + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + - - - - - - - - - - - - - - and ${criterion.condition} - - - and ${criterion.condition} #{criterion.value} - - - and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} - - - and ${criterion.condition} - - #{listItem} - - - + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + - + + + + chapter_id + , chapter_name, course_id, sequence + + + + + delete + from sys_course_chapter + where chapter_id = #{chapterId,jdbcType=VARCHAR} + + + delete from sys_course_chapter + + - - - - - chapter_id, chapter_name, course_id, sequence - - - - - delete from sys_course_chapter - where chapter_id = #{chapterId,jdbcType=VARCHAR} - - - delete from sys_course_chapter - - - - - - insert into sys_course_chapter (chapter_id, chapter_name, course_id, - sequence) - values (#{chapterId,jdbcType=VARCHAR}, #{chapterName,jdbcType=VARCHAR}, #{courseId,jdbcType=VARCHAR}, - #{sequence,jdbcType=INTEGER}) - - - insert into sys_course_chapter - - - chapter_id, - - - chapter_name, - - - course_id, - - - sequence, - - - - - #{chapterId,jdbcType=VARCHAR}, - - - #{chapterName,jdbcType=VARCHAR}, - - - #{courseId,jdbcType=VARCHAR}, - - - #{sequence,jdbcType=INTEGER}, - - - - - - update sys_course_chapter - - - chapter_id = #{record.chapterId,jdbcType=VARCHAR}, - - + + + insert into sys_course_chapter (chapter_id, chapter_name, course_id, + sequence) + values (#{chapterId,jdbcType=VARCHAR}, #{chapterName,jdbcType=VARCHAR}, #{courseId,jdbcType=VARCHAR}, + #{sequence,jdbcType=INTEGER}) + + + insert into sys_course_chapter + + + chapter_id, + + + chapter_name, + + + course_id, + + + sequence, + + + + + #{chapterId,jdbcType=VARCHAR}, + + + #{chapterName,jdbcType=VARCHAR}, + + + #{courseId,jdbcType=VARCHAR}, + + + #{sequence,jdbcType=INTEGER}, + + + + + + update sys_course_chapter + + + chapter_id = #{record.chapterId,jdbcType=VARCHAR}, + + + chapter_name = #{record.chapterName,jdbcType=VARCHAR}, + + + course_id = #{record.courseId,jdbcType=VARCHAR}, + + + sequence = #{record.sequence,jdbcType=INTEGER}, + + + + + + + + update sys_course_chapter + set chapter_id = #{record.chapterId,jdbcType=VARCHAR}, chapter_name = #{record.chapterName,jdbcType=VARCHAR}, - - course_id = #{record.courseId,jdbcType=VARCHAR}, - - - sequence = #{record.sequence,jdbcType=INTEGER}, - - - - - - - - update sys_course_chapter - set chapter_id = #{record.chapterId,jdbcType=VARCHAR}, - chapter_name = #{record.chapterName,jdbcType=VARCHAR}, - course_id = #{record.courseId,jdbcType=VARCHAR}, - sequence = #{record.sequence,jdbcType=INTEGER} - - - - - - update sys_course_chapter - - - chapter_name = #{chapterName,jdbcType=VARCHAR}, - - - course_id = #{courseId,jdbcType=VARCHAR}, - - - sequence = #{sequence,jdbcType=INTEGER}, - - - where chapter_id = #{chapterId,jdbcType=VARCHAR} - - - update sys_course_chapter - set chapter_name = #{chapterName,jdbcType=VARCHAR}, - course_id = #{courseId,jdbcType=VARCHAR}, - sequence = #{sequence,jdbcType=INTEGER} - where chapter_id = #{chapterId,jdbcType=VARCHAR} - + sequence = #{record.sequence,jdbcType=INTEGER} + + + + + + update sys_course_chapter + + + chapter_name = #{chapterName,jdbcType=VARCHAR}, + + + course_id = #{courseId,jdbcType=VARCHAR}, + + + sequence = #{sequence,jdbcType=INTEGER}, + + + where chapter_id = #{chapterId,jdbcType=VARCHAR} + + + update sys_course_chapter + set chapter_name = #{chapterName,jdbcType=VARCHAR}, + course_id = #{courseId,jdbcType=VARCHAR}, + sequence = #{sequence,jdbcType=INTEGER} + where chapter_id = #{chapterId,jdbcType=VARCHAR} + + + \ No newline at end of file