diff --git a/src/main/java/com/sztzjy/resource_center/controller/TopicResourceController.java b/src/main/java/com/sztzjy/resource_center/controller/TopicResourceController.java index 6dd2dcd..13dcf01 100644 --- a/src/main/java/com/sztzjy/resource_center/controller/TopicResourceController.java +++ b/src/main/java/com/sztzjy/resource_center/controller/TopicResourceController.java @@ -326,37 +326,54 @@ public class TopicResourceController { Cell cell12 = row.getCell(12); //判断题的BCDE选项和解析可能为空 - if (cell0 == null || cell1 == null || cell2 == null || cell6 == null || cell7 == null || cell9 == null) { + if (cell0 == null || cell2 == null || cell3 == null || cell7 == null || cell8 == null || cell10 == null || cell11 == null || cell12 == null) { return new ResultEntity<>(HttpStatus.BAD_REQUEST, "必填项不能为空"); } - String content = this.getCellValue(cell0);//题干 - String a = this.getCellValue(cell1); //选项A - String b = this.getCellValue(cell2);//选项B - String type = this.getCellValue(cell6);//题型 + String type = this.getCellValue(cell0);//题型 + String content = this.getCellValue(cell1);//题干 + String a = this.getCellValue(cell2); //选项A + String b = this.getCellValue(cell3);//选项B String answer = this.getCellValue(cell7);//答案 - String score = this.getCellValue(cell9);//分值 + String score = this.getCellValue(cell8);//分值 String oneName = this.getCellValue(cell10);//一级目录名称 String twoName = this.getCellValue(cell11);//二级目录名称 String threeName = this.getCellValue(cell12);//三级目录名称 - String c = cell3 != null ? this.getCellValue(cell3) : null; - String d = cell4 != null ? this.getCellValue(cell4) : null; - String e = cell5 != null ? this.getCellValue(cell5) : null; - String analyze = cell8 != null ? this.getCellValue(cell8) : null; + String c = cell4 != null ? this.getCellValue(cell4) : null; + String d = cell5 != null ? this.getCellValue(cell5) : null; + String e = cell6 != null ? this.getCellValue(cell6) : null; + String analyze = cell9 != null ? this.getCellValue(cell9) : null; //答案解析 SysObjectiveQuestions obj = new SysObjectiveQuestions(); String topicId = IdUtil.randomUUID(); obj.setObjectiveId(topicId); obj.setContent(content); - obj.setType(type); + obj.setAnswer(answer); + + if (type.equals("单选题") || type.equals("单选")) { + obj.setType("0"); + } + if (type.equals("多选题") || type.equals("多选")) { + obj.setType("1"); + } + if (type.equals("判断题") || type.equals("判断")) { + obj.setType("2"); + + if (answer.equals("A")) { + obj.setAnswer("对"); + } + if (answer.equals("B")) { + obj.setAnswer("错"); + } + } + obj.setSource(source); obj.setQuestionA(a); obj.setQuestionB(b); obj.setQuestionC(c); obj.setQuestionD(d); obj.setQuestionE(e); - obj.setAnswer(answer); obj.setAnalysis(analyze); obj.setScore(BigDecimal.valueOf(Integer.parseInt(score))); obj.setCreateTime(new Date()); @@ -385,7 +402,7 @@ public class TopicResourceController { String threeId = threeIdMap.get(threeName); if (threeId == null) { - threeId = sysThreeCatalogMapper.getIdByName(twoName, threeName); + threeId = sysThreeCatalogMapper.getIdByName(oneId, twoId, threeName); if (threeId == null) { return new ResultEntity(HttpStatus.INTERNAL_SERVER_ERROR, "导入关联的章节不存在,请在添加后重新导入"); } diff --git a/src/main/java/com/sztzjy/resource_center/controller/api/ObjectiveApi.java b/src/main/java/com/sztzjy/resource_center/controller/api/ObjectiveApi.java index 27dd146..0ae3662 100644 --- a/src/main/java/com/sztzjy/resource_center/controller/api/ObjectiveApi.java +++ b/src/main/java/com/sztzjy/resource_center/controller/api/ObjectiveApi.java @@ -7,6 +7,7 @@ import com.sztzjy.resource_center.entity.*; import com.sztzjy.resource_center.entity.dto.SysObjectiveQuestionsDto; import com.sztzjy.resource_center.mapper.*; import com.sztzjy.resource_center.util.PageUtil; +import com.sztzjy.resource_center.util.ResultEntity; import com.sztzjy.resource_center.util.file.IFileUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -17,6 +18,7 @@ import org.apache.poi.ss.usermodel.*; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -298,60 +300,97 @@ public class ObjectiveApi { Cell cell10 = row.getCell(10); Cell cell11 = row.getCell(11); Cell cell12 = row.getCell(12); + if (cell0 == null) { + return false; + } + + String type = this.getCellValue(cell0);//题型 + if (type.equals("0") || type.equals("1")) { + if (cell1 == null || cell2 == null) { + return false; + } + } + //判断题的BCDE选项和解析可能为空 - if (cell0 == null || cell1 == null || cell2 == null || cell6 == null || cell7 == null || cell9 == null) { + if (cell7 == null || cell8 == null || cell10 == null || cell11 == null || cell12 == null) { return false; } - String content = this.getCellValue(cell0);//题干 - String a = this.getCellValue(cell1); //选项A - String b = this.getCellValue(cell2);//选项B - String type = this.getCellValue(cell6);//题型 + String content = this.getCellValue(cell1);//题干 + String a = cell2 != null ? this.getCellValue(cell2) : null; //选项A + String b = cell3 != null ? this.getCellValue(cell3) : null;//选项B String answer = this.getCellValue(cell7);//答案 - String score = this.getCellValue(cell9);//分值 + String score = this.getCellValue(cell8);//分值 String oneName = this.getCellValue(cell10);//一级目录名称 String twoName = this.getCellValue(cell11);//二级目录名称 String threeName = this.getCellValue(cell12);//三级目录名称 - String c = cell3 != null ? this.getCellValue(cell3) : null; - String d = cell4 != null ? this.getCellValue(cell4) : null; - String e = cell5 != null ? this.getCellValue(cell5) : null; - String analyze = cell8 != null ? this.getCellValue(cell8) : null; + String c = cell4 != null ? this.getCellValue(cell4) : null; + String d = cell5 != null ? this.getCellValue(cell5) : null; + String e = cell6 != null ? this.getCellValue(cell6) : null; + String analyze = cell9 != null ? this.getCellValue(cell9) : null; //答案解析 SysObjectiveQuestions obj = new SysObjectiveQuestions(); String topicId = IdUtil.randomUUID(); obj.setObjectiveId(topicId); obj.setContent(content); - obj.setType(type); + if (type.equals("单选题") || type.equals("单选")) { + obj.setType("0"); + } + if (type.equals("多选题") || type.equals("多选")) { + obj.setType("1"); + } + obj.setSource(schoolId); obj.setQuestionA(a); obj.setQuestionB(b); obj.setQuestionC(c); obj.setQuestionD(d); obj.setQuestionE(e); + obj.setAnswer(answer); + if (type.equals("判断题") || type.equals("判断")) { + obj.setType("2"); + + if (answer.equals("A")){ + obj.setAnswer("对"); + } + if (answer.equals("B")){ + obj.setAnswer("错"); + } + } obj.setAnalysis(analyze); obj.setScore(BigDecimal.valueOf(Integer.parseInt(score))); obj.setCreateTime(new Date()); obj.setIsDelete(false); objectiveQuestionList.add(obj); + //判断名称是否被查出来过 String oneId = oneIdMap.get(oneName); if (oneId == null) { oneId = oneCatalogMapper.getIdByName(oneName); + if (oneId == null) { + return false; + } oneIdMap.put(oneName, oneId); } String twoId = twoIdMap.get(twoName); if (twoId == null) { twoId = sysTwoCatalogMapper.getIdByName(twoName); + if (twoId == null) { + return false; + } twoIdMap.put(twoName, twoId); } String threeId = threeIdMap.get(threeName); if (threeId == null) { - threeId = sysThreeCatalogMapper.getIdByName(threeName,twoName); + threeId = sysThreeCatalogMapper.getIdByName(oneId, twoId, threeName); + if (threeId == null) { + return false; + } threeIdMap.put(threeName, threeId); } diff --git a/src/main/java/com/sztzjy/resource_center/mapper/SysThreeCatalogMapper.java b/src/main/java/com/sztzjy/resource_center/mapper/SysThreeCatalogMapper.java index 980419c..b43a92b 100644 --- a/src/main/java/com/sztzjy/resource_center/mapper/SysThreeCatalogMapper.java +++ b/src/main/java/com/sztzjy/resource_center/mapper/SysThreeCatalogMapper.java @@ -49,7 +49,9 @@ public interface SysThreeCatalogMapper { List selectNameByCourseID(@Param("oneId") String oneId, @Param("source") String source); - @Select("select three_id from sys_three_catalog where three_name =#{threeName} and two_name =#{twoName}") - String getIdByName(@Param("threeName") String threeName, - @Param("twoName") String twoName); + @Select("select three_id from sys_three_catalog where three_name =#{threeName} and two_id =#{twoId} and ont_id = #{oneID}") + String getIdByName(@Param("oneID") String oneID, + @Param("twoId") String twoId, + @Param("threeName") String threeName + ); } \ No newline at end of file