新增API接口

master
xiaoCJ 8 months ago
parent 6ec08da734
commit 4cd1cbaace

@ -193,12 +193,21 @@ public class TopicResourceController {
@RequestParam(required = false) String type,
@ApiParam("题干") @RequestParam(required = false) String content) {
PageHelper.startPage(index, size);
List<SysObjectiveQuestionsDto> list = sysObjectiveQuestionMapper.getTopicByConfig(oneID, twoID, threeID, type, content);
List<SysObjectiveQuestionsDto> list = sysObjectiveQuestionMapper.getTopicByConfig(oneID, twoID, threeID, type, null, content);
PageInfo<SysObjectiveQuestionsDto> pageInfo = new PageInfo(list);
return new ResultEntity<PageInfo<SysObjectiveQuestionsDto>>(pageInfo);
}
@AnonymousAccess
@ApiOperation("客观题单个详情查看")
@PostMapping("getById")
private ResultEntity<SysObjectiveQuestions> getById(@RequestParam String id) {
SysObjectiveQuestions sysObjectiveQuestions = sysObjectiveQuestionMapper.selectByPrimaryKey(id);
return new ResultEntity<>(sysObjectiveQuestions);
}
//老师新增的题目正在使用的话资源中心只能查看,不能编辑和删除,
// 如果老师自己删除了这个题目资源中心题库管理也可以编辑和删除。如果题目正在被使用则删除的时候提示题目被xx课程xx章节使用不能删除。
@ApiOperation("编辑")
@ -249,6 +258,15 @@ public class TopicResourceController {
}
@AnonymousAccess
@ApiOperation("批量删除题目绑定关系")
@PostMapping("deleteTopicBindingByList")
private ResultEntity<String> deleteTopicBindingByList(@RequestParam("传topicId和三级ID") @RequestBody List<SysTopicAndCourse> sysTopicAndCourses) {
sysTopicAndCourseMapper.batchDelete(sysTopicAndCourses);
return new ResultEntity<>(HttpStatus.OK, "成功删除绑定关系!");
}
//老师新增的题目正在使用的话资源中心只能查看,不能编辑和删除,
// 如果老师自己删除了这个题目资源中心题库管理也可以编辑和删除。如果题目正在被使用则删除的时候提示题目被xx课程xx章节使用不能删除。
@ApiOperation("删除")

@ -1,19 +1,127 @@
package com.sztzjy.resource_center.controller.api;
import cn.hutool.core.util.IdUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sztzjy.resource_center.annotation.AnonymousAccess;
import com.sztzjy.resource_center.entity.*;
import com.sztzjy.resource_center.entity.dto.SysObjectiveQuestionsDto;
import com.sztzjy.resource_center.mapper.SysObjectiveQuestionsMapper;
import com.sztzjy.resource_center.mapper.SysOneCatalogMapper;
import com.sztzjy.resource_center.mapper.SysTopicAndCourseMapper;
import com.sztzjy.resource_center.util.ResultEntity;
import com.sztzjy.resource_center.util.file.IFileUtil;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;
@RestController
@Api(tags = "课程方面API")
@RequestMapping("api/sys/ObjectiveApi")
public class ObjectiveApi {
@Autowired
private SysObjectiveQuestionsMapper sysObjectiveQuestionMapper;
@Autowired
private SysTopicAndCourseMapper sysTopicAndCourseMapper;
@Autowired
SysOneCatalogMapper oneCatalogMapper;
@Autowired
IFileUtil fileUtil;
@Value("${file.path}")
private String filePath;
private SysOneCatalog getSysOneCatalogs(String systemOwner) {
SysOneCatalogExample example = new SysOneCatalogExample();
example.createCriteria().andOneNameEqualTo(systemOwner);
List<SysOneCatalog> sysOneCatalogs = oneCatalogMapper.selectByExample(example);
return sysOneCatalogs.get(0);
}
/**
*
* insertObjective
* SysObjectiveQuestions systemOwner schoolId
* SysObjectiveQuestions systemOwner
* return: boolean
*/
@AnonymousAccess
@ApiOperation("新增单个试题") //新增 题干不允许重复
@PostMapping("addTopic")
private Boolean addTopic(@RequestBody SysObjectiveQuestionsDto objectiveQuestion) {
if (StringUtils.isBlank(objectiveQuestion.getContent())) {
return false;
}
if (StringUtils.isBlank(objectiveQuestion.getAnswer())) {
return false;
}
if (objectiveQuestion.getScore() == null) {
return false;
}
if (StringUtils.isBlank(objectiveQuestion.getType())) {
return false;
}
if (StringUtils.isBlank(objectiveQuestion.getObjectiveId())) { //子系统的oneName放在这个字段传过来
return false;
}
if (objectiveQuestion.getType().equals("1") || objectiveQuestion.getType().equals("0")) {
if (StringUtils.isBlank(objectiveQuestion.getQuestionA()) || StringUtils.isBlank(objectiveQuestion.getQuestionB())
|| StringUtils.isBlank(objectiveQuestion.getQuestionC()) || StringUtils.isBlank(objectiveQuestion.getQuestionD()))
return false;
}
if (objectiveQuestion.getType().equals("2")) {
if (StringUtils.isBlank(objectiveQuestion.getQuestionA()) || StringUtils.isBlank(objectiveQuestion.getQuestionB()))
return false;
}
SysOneCatalog sysOneCatalogs = getSysOneCatalogs(objectiveQuestion.getObjectiveId());
String oneId = sysOneCatalogs.getOneId();
SysObjectiveQuestionsExample example = new SysObjectiveQuestionsExample();
example.createCriteria().andContentEqualTo(objectiveQuestion.getContent());
List<SysObjectiveQuestions> sysObjectiveQuestions = sysObjectiveQuestionMapper.selectByExample(example);
if (!sysObjectiveQuestions.isEmpty()) {
return false;
}
//新增题库表
String uuid = IdUtil.randomUUID();
objectiveQuestion.setObjectiveId(uuid);
objectiveQuestion.setCreateTime(new Date());
objectiveQuestion.setIsDelete(false);
objectiveQuestion.setOneID(oneId);
sysObjectiveQuestionMapper.insert(objectiveQuestion);
//新增题库关系表
SysTopicAndCourse sysTopicAndCourse = new SysTopicAndCourse();
sysTopicAndCourse.setId(IdUtil.randomUUID());
sysTopicAndCourse.setTopicId(uuid);
sysTopicAndCourse.setTopicType(objectiveQuestion.getType());
sysTopicAndCourse.setOneId(oneId);
sysTopicAndCourse.setOneName(objectiveQuestion.getObjectiveId()); //子系统的oneName放在这个字段传过来
if (StringUtils.isNotBlank(objectiveQuestion.getTwoID())) {
sysTopicAndCourse.setTwoId(objectiveQuestion.getTwoID());
sysTopicAndCourse.setTwoName(objectiveQuestion.getTwoName());
}
if (StringUtils.isNotBlank(objectiveQuestion.getThreeID())) {
sysTopicAndCourse.setThreeId(objectiveQuestion.getThreeID());
sysTopicAndCourse.setThreeName(objectiveQuestion.getThreeName());
}
sysTopicAndCourseMapper.insert(sysTopicAndCourse);
return true;
}
/**
*
@ -21,6 +129,30 @@ public class ObjectiveApi {
* List<String> objIdList schoolId
* return: boolean
*/
@AnonymousAccess
@ApiOperation("客观题批量删除")
@PostMapping("batchDeleteObjective")
private Boolean batchDeleteObjective(@RequestBody List<String> objIdList,
@RequestParam String schoolId) {
SysObjectiveQuestionsExample example = new SysObjectiveQuestionsExample();
example.createCriteria().andObjectiveIdIn(objIdList);
List<SysObjectiveQuestions> sysObjectiveQuestions = sysObjectiveQuestionMapper.selectByExample(example);
List<String> ids = new ArrayList<>();
for (SysObjectiveQuestions sysObjectiveQuestion : sysObjectiveQuestions) {
if (sysObjectiveQuestion.getSource().equals(schoolId)) {
continue;
} else {
ids.add(sysObjectiveQuestion.getObjectiveId());
}
}
try {
sysObjectiveQuestionMapper.batchDelete(ids);
return true;
} catch (Exception e) {
return false;
}
}
/**
*
@ -28,6 +160,21 @@ public class ObjectiveApi {
* schoolId courseId type content index size
* return:PageInfo<SysObjectiveQuestions>
*/
@AnonymousAccess
@ApiOperation("课程配置/题目条件查询")
@PostMapping("getTopicByConfig") //todo 关于老师删除的题库如何查询
private PageInfo<SysObjectiveQuestionsDto> getTopicByConfig(@RequestParam Integer index,
@RequestParam Integer size,
@RequestParam(required = false) String courseId,
@RequestParam(required = false) String threeID,
@RequestParam(required = false) String type,
@RequestParam String schoolId,
@ApiParam("题干") @RequestParam(required = false) String content) {
PageHelper.startPage(index, size);
List<SysObjectiveQuestionsDto> list = sysObjectiveQuestionMapper.getTopicByConfig(null, courseId, threeID, type, schoolId, content);
PageInfo<SysObjectiveQuestionsDto> pageInfo = new PageInfo(list);
return (pageInfo);
}
/**
*
@ -35,6 +182,13 @@ public class ObjectiveApi {
* objectiveId
* return:SysObjectiveQuestions
*/
@AnonymousAccess
@ApiOperation("客观题单个详情查看")
@PostMapping("selectObjectiveDetails")
private SysObjectiveQuestions getById(@RequestParam String objectiveId) {
SysObjectiveQuestions sysObjectiveQuestions = sysObjectiveQuestionMapper.selectByPrimaryKey(objectiveId);
return sysObjectiveQuestions;
}
/**
*
@ -42,11 +196,104 @@ public class ObjectiveApi {
* response
* return:void
*/
@GetMapping("downloadResource")
@ApiOperation("客观题导入模板下载")
@AnonymousAccess
public void downloadResource(HttpServletResponse response) {
fileUtil.download(response, "客观题导入模板.xlsx", filePath);
}
/**
*
* insertObjectiveByExcel
* MultipartFile schoolId
* return:void
* return:Boolean
*/
@AnonymousAccess
@ApiOperation("本地excel导入试题")
@PostMapping("importTopicByLocal")
private Boolean importTopicByLocal(@RequestParam MultipartFile file,
@RequestParam String schoolId) throws IOException, InvalidFormatException {
if (file == null) {
return false;
}
return insertObjectiveByExcel(file, schoolId);
}
//如果是内置增加 则需要提供课程和章节信息
//如果是老师增加 则只需要提供课程信息
public Boolean insertObjectiveByExcel(MultipartFile file, String schoolId) throws IOException, InvalidFormatException {
List<SysObjectiveQuestions> objectiveQuestionList = new ArrayList<>();
Workbook workbook = WorkbookFactory.create(file.getInputStream());
Sheet sheet = workbook.getSheetAt(0);
// 迭代每一行
Iterator<Row> iterator = sheet.iterator();
iterator.next();
while (iterator.hasNext()) {
Row row = iterator.next();
/*解析列下标从0开始*/
Cell cell0 = row.getCell(0);
Cell cell1 = row.getCell(1);
Cell cell2 = row.getCell(2);
Cell cell3 = row.getCell(3);
Cell cell4 = row.getCell(4);
Cell cell5 = row.getCell(5);
Cell cell6 = row.getCell(6);
Cell cell7 = row.getCell(7);
Cell cell8 = row.getCell(8);
Cell cell9 = row.getCell(9);
//判断题的BCDE选项和解析可能为空
if (cell0 == null || cell1 == null || cell2 == null || cell6 == null || cell7 == null || cell9 == 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 answer = this.getCellValue(cell7);//答案
String score = this.getCellValue(cell9);//分值
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;
SysObjectiveQuestions obj = new SysObjectiveQuestions();
obj.setObjectiveId(String.valueOf(UUID.randomUUID()));
obj.setContent(content);
obj.setType(type);
obj.setSource(schoolId);
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());
obj.setIsDelete(false);
objectiveQuestionList.add(obj);
}
int result = sysObjectiveQuestionMapper.insertBatch(objectiveQuestionList);
if (result > 0) {
return true;
} else {
return false;
}
}
public String getCellValue(Cell cell) {
if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
return String.valueOf(cell.getBooleanCellValue());
} else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
Double d = cell.getNumericCellValue();
return String.valueOf(d.intValue());
}
return String.valueOf(cell.getStringCellValue());
}
}

@ -2,11 +2,12 @@ package com.sztzjy.resource_center.mapper;
import com.sztzjy.resource_center.entity.SysObjectiveQuestions;
import com.sztzjy.resource_center.entity.SysObjectiveQuestionsExample;
import java.util.List;
import com.sztzjy.resource_center.entity.dto.SysObjectiveQuestionsDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface SysObjectiveQuestionsMapper {
long countByExample(SysObjectiveQuestionsExample example);
@ -31,17 +32,21 @@ public interface SysObjectiveQuestionsMapper {
int updateByPrimaryKey(SysObjectiveQuestions record);
List<SysObjectiveQuestionsDto> selectTopicByConditions(@Param("oneID")String oneID,
List<SysObjectiveQuestionsDto> selectTopicByConditions(@Param("oneID") String oneID,
@Param("twoID") String twoID,
@Param("threeID") String threeID,
@Param("type")String type,
@Param("type") String type,
@Param("content") String content);
int insertBatch(@Param("objectiveQuestionList") List<SysObjectiveQuestions> objectiveQuestionList);
List<SysObjectiveQuestionsDto> getTopicByConfig(@Param("oneID")String oneID,
List<SysObjectiveQuestionsDto> getTopicByConfig(@Param("oneID") String oneID,
@Param("twoID") String twoID,
@Param("threeID") String threeID,
@Param("type")String type,
@Param("content") String content);
@Param("type") String type,
@Param("schoolId") String schoolId,
@Param("content") String content
);
void batchDelete(@Param("list") List<String> ids);
}

@ -2,10 +2,11 @@ package com.sztzjy.resource_center.mapper;
import com.sztzjy.resource_center.entity.SysTopicAndCourse;
import com.sztzjy.resource_center.entity.SysTopicAndCourseExample;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface SysTopicAndCourseMapper {
long countByExample(SysTopicAndCourseExample example);
@ -31,4 +32,6 @@ public interface SysTopicAndCourseMapper {
int updateByPrimaryKey(SysTopicAndCourse record);
void batchInsert(@Param("list") List<SysTopicAndCourse> list);
void batchDelete(@Param("list") List<SysTopicAndCourse> sysTopicAndCourses);
}

@ -401,7 +401,7 @@
SELECT/* sb.*,st.one_id,st.two_id,st.three_id,st.id,st.one_name,st.two_name,st.three_name*/
sb.*, st.*
FROM sys_objective_questions sb
left JOIN sys_topic_and_course st
left JOIN sys_topic_and_course st
on sb.objective_id = st.topic_id
<where>
<if test="oneID != null and oneID != ''">
@ -427,7 +427,7 @@
<!-- 条件查询-->
<select id="getTopicByConfig" parameterType="java.lang.String" resultMap="DtoMap">
SELECT sb.*,st.one_id,st.two_id,st.three_id,st.id,st.one_name,st.two_name,st.three_name
FROM sys_objective_questions sb
FROM sys_objective_questions sb
LEFT JOIN sys_topic_and_course st
on sb.objective_id = st.topic_id
<where>
@ -446,6 +446,9 @@
<if test="content != null and content != ''">
and sb.content = #{content}
</if>
<if test="schoolId != null and schoolId != ''">
and sb.source in (#{schoolId},'管理员')
</if>
</where>
order by sb.create_time
</select>
@ -464,4 +467,12 @@
)
</foreach>
</insert>
<delete id="batchDelete" parameterType="java.util.List">
DELETE FROM sys_objective_questions
WHERE objective_id IN
<foreach collection="list" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>

@ -295,4 +295,16 @@
)
</foreach>
</insert>
<!-- 批量删除 -->
<delete id="batchDelete" parameterType="java.util.List">
DELETE FROM sys_topic_and_course
WHERE topic_id IN
<foreach collection="list" item="item" open="(" separator="," close=")">
#{item.id}
AND one_id = #{item.oneId}
AND two_id = #{item.twoId}
AND three_id = #{item.threeId}
</foreach>
</delete>
</mapper>
Loading…
Cancel
Save