|
|
|
@ -4,22 +4,20 @@ import com.tz.platform.common.core.base.Result;
|
|
|
|
|
import com.tz.platform.entity.Question;
|
|
|
|
|
import com.tz.platform.feign.user.IFeignUser;
|
|
|
|
|
import com.tz.platform.feign.user.vo.UserVo;
|
|
|
|
|
import com.tz.platform.pc.dto.ListQuestionDTO;
|
|
|
|
|
import com.tz.platform.pc.dto.PageQuestionDTO;
|
|
|
|
|
import com.tz.platform.pc.dto.QuestionDTO;
|
|
|
|
|
import com.tz.platform.pc.vo.BatchQuestionVO;
|
|
|
|
|
import com.tz.platform.pc.vo.PageQuestionVO;
|
|
|
|
|
import com.tz.platform.pc.vo.QuestionUpdateVO;
|
|
|
|
|
import com.tz.platform.pc.vo.QuestionVO;
|
|
|
|
|
import com.tz.platform.pc.vo.*;
|
|
|
|
|
import com.tz.platform.repository.QuestionDao;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
|
|
import org.springframework.data.domain.*;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@Component
|
|
|
|
|
public class PCQuestionBiz {
|
|
|
|
@ -32,17 +30,34 @@ public class PCQuestionBiz {
|
|
|
|
|
|
|
|
|
|
public Result<PageQuestionDTO> list(PageQuestionVO questionVO){
|
|
|
|
|
PageQuestionDTO questionDTO = new PageQuestionDTO();
|
|
|
|
|
Pageable pageable = PageRequest.of(questionVO.getPageNo(),20);
|
|
|
|
|
Integer pageNo = questionVO.getPageNo()-1;
|
|
|
|
|
if(pageNo< 0){
|
|
|
|
|
pageNo = 0;
|
|
|
|
|
}
|
|
|
|
|
if(questionVO.getPageSize()==null){
|
|
|
|
|
questionVO.setPageSize(20);
|
|
|
|
|
}
|
|
|
|
|
Pageable pageable = PageRequest.of(pageNo,questionVO.getPageSize());
|
|
|
|
|
Page<Question> questions =null;
|
|
|
|
|
if((questionVO.getCourseId() == null|| questionVO.getCourseId() == 0) && StringUtils.isEmpty(questionVO.getStem())){
|
|
|
|
|
questions = questionDao.findAllByType(questionVO.getType(),pageable);
|
|
|
|
|
}else if(questionVO.getCourseId()>0&&StringUtils.hasText(questionVO.getStem())){
|
|
|
|
|
questions = questionDao.findAllByCourseIdAndStemAndType(questionVO.getCourseId(),questionVO.getStem(),questionVO.getType(),pageable);
|
|
|
|
|
}else if(questionVO.getCourseId()>0){
|
|
|
|
|
questions = questionDao.findAllByCourseIdAndType(questionVO.getCourseId(),questionVO.getType(),pageable);
|
|
|
|
|
}else {
|
|
|
|
|
questions = questionDao.findAllByStemAndType(questionVO.getStem(), questionVO.getType(),pageable);
|
|
|
|
|
Long questionId = 0L;
|
|
|
|
|
if(StringUtils.hasText(questionVO.getStem())){
|
|
|
|
|
String regex = "\\d+";
|
|
|
|
|
if(questionVO.getStem().matches(regex)){
|
|
|
|
|
questionId = Long.parseLong(questionVO.getStem());
|
|
|
|
|
List<Long> ids = new ArrayList<>();
|
|
|
|
|
ids.add(questionId);
|
|
|
|
|
questions = questionDao.findAllByIdIn(ids,pageable);
|
|
|
|
|
return Result.success(questionDTO.setPage(questions));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Question question = new Question();
|
|
|
|
|
BeanUtils.copyProperties(questionVO,question);
|
|
|
|
|
ExampleMatcher exampleMatcher = ExampleMatcher.matching().withIgnoreNullValues();
|
|
|
|
|
if(StringUtils.isEmpty(questionVO.getStem())){
|
|
|
|
|
exampleMatcher = exampleMatcher.withIgnorePaths("stem");
|
|
|
|
|
}
|
|
|
|
|
Example example = Example.of(question,exampleMatcher);
|
|
|
|
|
questions = questionDao.findAll( example ,pageable);
|
|
|
|
|
return Result.success(questionDTO.setPage(questions));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -135,4 +150,11 @@ public class PCQuestionBiz {
|
|
|
|
|
questionDao.batchUpdate(vo.getStatus(),vo.getIds());
|
|
|
|
|
return Result.success("success");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Result<ListQuestionDTO> listByIds(ListQuestionVO vo){
|
|
|
|
|
List<Question> list = questionDao.findAllByIdIn(vo.getQuestionIds());
|
|
|
|
|
ListQuestionDTO dto = new ListQuestionDTO();
|
|
|
|
|
dto.setList(list);
|
|
|
|
|
return Result.success(dto);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|