完成教师端题库管理:根据条件模糊搜索、新增题目、批量导入题目、编辑题目、分页展示、删除题目等接口
parent
0868f2e88e
commit
8d59c46fa8
@ -0,0 +1,24 @@
|
||||
package com.sztzjy.trade.entity.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author 17803
|
||||
* @date 2024-12-16 14:39
|
||||
*/
|
||||
@Data
|
||||
public class StuQuestionBankRemoveDTO {
|
||||
|
||||
@ApiModelProperty(notes = "题目ID")
|
||||
private String topicId;
|
||||
|
||||
// @ApiModelProperty(notes = "学校ID")
|
||||
// private String schoolId;
|
||||
//
|
||||
//
|
||||
// @ApiModelProperty(notes = "老师or管理员")
|
||||
// private String user;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package com.sztzjy.trade.service;
|
||||
|
||||
import com.sztzjy.trade.entity.StuLearningAssessment;
|
||||
import com.sztzjy.trade.entity.dto.StuQuestionBankDTO;
|
||||
import com.sztzjy.trade.entity.dto.StuQuestionBankRemoveDTO;
|
||||
import com.sztzjy.trade.util.ResultEntity;
|
||||
|
||||
/**
|
||||
* @author 17803
|
||||
* @date 2024-12-16 13:39
|
||||
*/
|
||||
public interface StuQuestionBankService {
|
||||
/**
|
||||
* 获取所有题目
|
||||
* @param schoolId
|
||||
* @return
|
||||
*/
|
||||
|
||||
ResultEntity getQuestionBankBySchoolId(String schoolId,Integer page,Integer size);
|
||||
|
||||
/**
|
||||
* 搜索功能
|
||||
* @param stuQuestionBankDTO
|
||||
* @return
|
||||
*/
|
||||
|
||||
ResultEntity searchFunction(StuQuestionBankDTO stuQuestionBankDTO);
|
||||
|
||||
/**
|
||||
* 新增题目功能
|
||||
* @param stuLearningAssessment
|
||||
* @return
|
||||
*/
|
||||
|
||||
ResultEntity addQuestionBank(StuLearningAssessment stuLearningAssessment);
|
||||
|
||||
/**
|
||||
* 编辑题目
|
||||
* @param stuLearningAssessment
|
||||
* @return
|
||||
*/
|
||||
|
||||
ResultEntity editQuestionBank(StuLearningAssessment stuLearningAssessment);
|
||||
|
||||
//下架题目
|
||||
ResultEntity removeQuestionBank(StuQuestionBankRemoveDTO questionBankRemoveDTO);
|
||||
|
||||
//删除题目
|
||||
ResultEntity delQuestionBank(String topicId);
|
||||
}
|
@ -0,0 +1,259 @@
|
||||
package com.sztzjy.trade.service.impl;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.sztzjy.trade.entity.StuLearningAssessment;
|
||||
import com.sztzjy.trade.entity.StuLearningAssessmentExample;
|
||||
import com.sztzjy.trade.entity.dto.StuQuestionBankDTO;
|
||||
import com.sztzjy.trade.entity.dto.StuQuestionBankRemoveDTO;
|
||||
import com.sztzjy.trade.mapper.StuLearningAssessmentMapper;
|
||||
import com.sztzjy.trade.service.StuQuestionBankService;
|
||||
import com.sztzjy.trade.util.ResultEntity;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 17803
|
||||
* @date 2024-12-16 13:39
|
||||
*/
|
||||
@Service
|
||||
public class StuQuestionBankServiceImpl implements StuQuestionBankService {
|
||||
|
||||
@Autowired
|
||||
private StuLearningAssessmentMapper stuLearningAssessmentMapper;
|
||||
|
||||
/**
|
||||
* 获取所有题目
|
||||
* @param schoolId
|
||||
* @return
|
||||
*/
|
||||
|
||||
@Override
|
||||
public ResultEntity getQuestionBankBySchoolId(String schoolId,Integer page,Integer size) {
|
||||
|
||||
if (!StringUtils.hasText(schoolId)){
|
||||
return new ResultEntity<>(HttpStatus.BAD_REQUEST,"schoolId不能为空");
|
||||
}
|
||||
|
||||
//开启分页
|
||||
PageHelper.startPage(page,size);
|
||||
|
||||
//查询当前学校所有题目按照导入时间排序
|
||||
StuLearningAssessmentExample learningAssessmentExample = new StuLearningAssessmentExample();
|
||||
//根据创建时间排序
|
||||
learningAssessmentExample.setOrderByClause("create_time asc");
|
||||
learningAssessmentExample
|
||||
.createCriteria()
|
||||
.andSchoolIdEqualTo(schoolId)
|
||||
.andLogicEqualTo(1);
|
||||
|
||||
List<StuLearningAssessment> stuLearningAssessmentList = stuLearningAssessmentMapper.selectByExample(learningAssessmentExample);
|
||||
|
||||
if (stuLearningAssessmentList == null || stuLearningAssessmentList.size() == 0){
|
||||
return new ResultEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
PageInfo<StuLearningAssessment> stuLearningAssessmentPageInfo = new PageInfo<>(stuLearningAssessmentList);
|
||||
return new ResultEntity<>(stuLearningAssessmentPageInfo);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索功能
|
||||
* @param stuQuestionBankDTO
|
||||
* @return
|
||||
*/
|
||||
|
||||
@Override
|
||||
public ResultEntity searchFunction(StuQuestionBankDTO stuQuestionBankDTO) {
|
||||
|
||||
if (!StringUtils.hasText(stuQuestionBankDTO.getSchoolId())){
|
||||
|
||||
return new ResultEntity<>(HttpStatus.BAD_REQUEST,"schoolId不能为空");
|
||||
}
|
||||
|
||||
//开启分页
|
||||
PageHelper.startPage(stuQuestionBankDTO.getPage(),stuQuestionBankDTO.getSize());
|
||||
|
||||
//查询当前学校所有题目按照导入时间排序
|
||||
StuLearningAssessmentExample learningAssessmentExample = new StuLearningAssessmentExample();
|
||||
//根据创建时间排序
|
||||
learningAssessmentExample.setOrderByClause("create_time asc");
|
||||
StuLearningAssessmentExample.Criteria criteria = learningAssessmentExample.createCriteria();
|
||||
//学校ID 和 没有被逻辑删除题目
|
||||
criteria.andSchoolIdEqualTo(stuQuestionBankDTO.getSchoolId()).andLogicEqualTo(1);
|
||||
//题干查询
|
||||
if (stuQuestionBankDTO.getTopicName()!=null)
|
||||
{
|
||||
criteria.andTopicNameLike("%"+stuQuestionBankDTO.getTopicName()+"%");
|
||||
|
||||
}
|
||||
//所属课程
|
||||
if (stuQuestionBankDTO.getAttributionCourses()!=null)
|
||||
{
|
||||
criteria.andTopicNameLike("%"+stuQuestionBankDTO.getAttributionCourses()+"%");
|
||||
|
||||
}
|
||||
|
||||
//归属章节
|
||||
if (stuQuestionBankDTO.getAttributionChapter()!=null)
|
||||
{
|
||||
criteria.andTopicNameLike("%"+stuQuestionBankDTO.getAttributionChapter()+"%");
|
||||
|
||||
}
|
||||
|
||||
|
||||
//上架状态
|
||||
if (stuQuestionBankDTO.getListingStatus()!=null)
|
||||
{
|
||||
criteria.andListingStatusEqualTo(stuQuestionBankDTO.getListingStatus());
|
||||
}
|
||||
|
||||
|
||||
List<StuLearningAssessment> stuLearningAssessmentList = stuLearningAssessmentMapper.selectByExample(learningAssessmentExample);
|
||||
|
||||
if (stuLearningAssessmentList == null || stuLearningAssessmentList.size() == 0){
|
||||
return new ResultEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
PageInfo<StuLearningAssessment> stuLearningAssessmentPageInfo = new PageInfo<>(stuLearningAssessmentList);
|
||||
|
||||
return new ResultEntity<>(stuLearningAssessmentPageInfo);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增题目功能
|
||||
*
|
||||
* @param stuLearningAssessment
|
||||
* @return
|
||||
*/
|
||||
|
||||
@Override
|
||||
public ResultEntity addQuestionBank(StuLearningAssessment stuLearningAssessment) {
|
||||
|
||||
if (!StringUtils.hasText(stuLearningAssessment.getSchoolId())){
|
||||
|
||||
return new ResultEntity<>(HttpStatus.BAD_REQUEST,"学校ID不能为空");
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(stuLearningAssessment.getTopicName())){
|
||||
|
||||
return new ResultEntity<>(HttpStatus.BAD_REQUEST,"题干不能为空");
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(stuLearningAssessment.getTopicType())){
|
||||
|
||||
return new ResultEntity<>(HttpStatus.BAD_REQUEST,"题目类型不能为空");
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(stuLearningAssessment.getAnswer())){
|
||||
|
||||
return new ResultEntity<>(HttpStatus.BAD_REQUEST,"正确答案不能为空");
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(stuLearningAssessment.getUploadUser())){
|
||||
|
||||
return new ResultEntity<>(HttpStatus.BAD_REQUEST,"上传用户不能为空");
|
||||
}
|
||||
|
||||
|
||||
|
||||
stuLearningAssessment.setTopicId(System.currentTimeMillis()+IdUtil.simpleUUID());
|
||||
|
||||
int i = stuLearningAssessmentMapper.insertSelective(stuLearningAssessment);
|
||||
if (i>0)
|
||||
return new ResultEntity<>(HttpStatus.OK);
|
||||
else
|
||||
return new ResultEntity<>(HttpStatus.BAD_REQUEST,"新增失败,请联系管理员!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑题目
|
||||
* @param stuLearningAssessment
|
||||
* @return
|
||||
*/
|
||||
|
||||
@Override
|
||||
public ResultEntity editQuestionBank(StuLearningAssessment stuLearningAssessment) {
|
||||
|
||||
if (!StringUtils.hasText(stuLearningAssessment.getTopicId())){
|
||||
return new ResultEntity<>(HttpStatus.BAD_REQUEST,"ID不能为空");
|
||||
}
|
||||
if (!StringUtils.hasText(stuLearningAssessment.getSchoolId())){
|
||||
|
||||
return new ResultEntity<>(HttpStatus.BAD_REQUEST,"学校ID不能为空");
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(stuLearningAssessment.getTopicName())){
|
||||
|
||||
return new ResultEntity<>(HttpStatus.BAD_REQUEST,"题干不能为空");
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(stuLearningAssessment.getTopicType())){
|
||||
|
||||
return new ResultEntity<>(HttpStatus.BAD_REQUEST,"题目类型不能为空");
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(stuLearningAssessment.getAnswer())){
|
||||
|
||||
return new ResultEntity<>(HttpStatus.BAD_REQUEST,"正确答案不能为空");
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(stuLearningAssessment.getUploadUser())){
|
||||
|
||||
return new ResultEntity<>(HttpStatus.BAD_REQUEST,"上传用户不能为空");
|
||||
}
|
||||
|
||||
int i = stuLearningAssessmentMapper.updateByPrimaryKeySelective(stuLearningAssessment);
|
||||
if (i>0)
|
||||
return new ResultEntity<>(HttpStatus.OK);
|
||||
else
|
||||
return new ResultEntity<>(HttpStatus.BAD_REQUEST,"编辑失败,请联系管理员!");
|
||||
|
||||
|
||||
}
|
||||
|
||||
//下架题目
|
||||
@Override
|
||||
public ResultEntity removeQuestionBank(StuQuestionBankRemoveDTO questionBankRemoveDTO) {
|
||||
|
||||
|
||||
|
||||
|
||||
//根据题目ID查询数据
|
||||
StuLearningAssessment learningAssessment = stuLearningAssessmentMapper.selectByPrimaryKey(questionBankRemoveDTO.getTopicId());
|
||||
|
||||
|
||||
learningAssessment.setListingStatus(0);
|
||||
stuLearningAssessmentMapper.updateByPrimaryKeySelective(learningAssessment);
|
||||
|
||||
return new ResultEntity<>(HttpStatus.OK,"下架成功");
|
||||
}
|
||||
|
||||
//删除题目
|
||||
@Override
|
||||
public ResultEntity delQuestionBank(String topicId) {
|
||||
|
||||
StuLearningAssessment learningAssessment = stuLearningAssessmentMapper.selectByPrimaryKey(topicId);
|
||||
|
||||
|
||||
learningAssessment.setLogic(0);
|
||||
stuLearningAssessmentMapper.updateByPrimaryKeySelective(learningAssessment);
|
||||
|
||||
return new ResultEntity<>(HttpStatus.OK,"删除成功");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue