123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- package com.qxgmat.service.inline;
- import com.github.pagehelper.Page;
- import com.nuliji.tools.AbstractService;
- import com.nuliji.tools.PageResult;
- import com.nuliji.tools.Transform;
- import com.nuliji.tools.exception.ParameterException;
- import com.nuliji.tools.exception.SystemException;
- import com.nuliji.tools.mybatis.Example;
- import com.qxgmat.data.constants.enums.logic.TextbookLogic;
- import com.qxgmat.data.dao.TextbookPaperMapper;
- import com.qxgmat.data.dao.entity.*;
- import com.qxgmat.data.relation.TextbookPaperRelationMapper;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.stereotype.Service;
- import javax.annotation.Resource;
- import java.util.*;
- @Service
- public class TextbookPaperService extends AbstractService {
- private static final Logger logger = LoggerFactory.getLogger(TextbookPaperService.class);
- @Resource
- private TextbookPaperMapper textbookPaperMapper;
- @Resource
- private TextbookPaperRelationMapper textbookPaperRelationMapper;
- /**
- * 查找组卷
- * @param page
- * @param size
- * @param libraryId
- * @param userId
- * @param logic
- * @param times
- * @return
- */
- public Page<TextbookPaper> list(int page, int size, Number libraryId, Number userId, TextbookLogic logic, String year, Integer times){
- String logicKey = logic != null ? logic.key : "";
- Page<TextbookPaper> p = page(()->{
- textbookPaperRelationMapper.listWithUser(libraryId, userId, logicKey, year, times);
- },page, size);
- Collection ids = Transform.getIds(p, TextbookPaper.class, "id");
- // 获取详细数据
- List<TextbookPaper> list = select(ids);
- Transform.replace(p, list, TextbookPaper.class, "id");
- return p;
- }
- /**
- * 更新所有组卷title
- * @param libraryId
- * @param prefixTitle
- */
- public void updateTitle(Integer libraryId, String prefixTitle, Integer length){
- Example example = new Example(TextbookLibrary.class);
- example.and(
- example.createCriteria()
- .andEqualTo("libraryId", libraryId)
- );
- List<TextbookPaper> paperList = select(textbookPaperMapper, example);
- for(TextbookPaper paper : paperList){
- paper.setTitle(generateTitle(prefixTitle, length, paper.getNo(), paper.getQuestionNumber()));
- edit(paper);
- }
- }
- /**
- * 生成试卷名称
- * @param prefixTitle
- * @param no
- * @param questionNumber
- * @return
- */
- public String generateTitle(String prefixTitle, Integer length, Integer no, Integer questionNumber){
- return String.format("%s#%d~%d", prefixTitle, (no - 1) * length + 1, (no - 1) * length + questionNumber);
- }
- /**
- * 管理后台查询列表
- * @param page
- * @param keyword
- * @return
- */
- public Page<TextbookPaper> listAdmin(int page, int size, String keyword){
- Example example = new Example(TextbookLibrary.class);
- if(keyword != null)
- example.and(
- example.createCriteria()
- .orLike("title", "%"+keyword+"%")
- );
- example.orderBy("id").desc();
- return page(()->select(textbookPaperMapper, example), page, size);
- }
- public List<TextbookPaper> listByQuestion(TextbookQuestion question){
- Example example = new Example(SentencePaper.class);
- example.and(
- example.createCriteria()
- .andCondition(String.format(formatSet, question.getId(), "question_no_ids"))
- );
- return select(textbookPaperMapper, example);
- }
- public TextbookPaper getLastByLibrary(TextbookLogic logic, Integer libraryId){
- Example example = new Example(TextbookPaper.class);
- example.and(
- example.createCriteria()
- .andEqualTo("logic", logic.key)
- .andEqualTo("libraryId", libraryId)
- );
- example.orderBy("createTime").desc();
- return one(textbookPaperMapper, example);
- }
- public TextbookPaper add(TextbookPaper paper){
- int result = insert(textbookPaperMapper, paper);
- paper = one(textbookPaperMapper, paper.getId());
- if(paper == null){
- throw new SystemException("题目添加失败");
- }
- return paper;
- }
- public TextbookPaper edit(TextbookPaper paper){
- TextbookPaper in = one(textbookPaperMapper, paper.getId());
- if(in == null){
- throw new ParameterException("题目不存在");
- }
- int result = update(textbookPaperMapper, paper);
- return paper;
- }
- public boolean delete(Number id){
- TextbookPaper in = one(textbookPaperMapper, id);
- if(in == null){
- throw new ParameterException("题目不存在");
- }
- int result = delete(textbookPaperMapper, id);
- return result > 0;
- }
- public TextbookPaper get(Number id){
- TextbookPaper in = one(textbookPaperMapper, id);
- if(in == null){
- throw new ParameterException("题目不存在");
- }
- return in;
- }
- public Page<TextbookPaper> select(int page, int pageSize){
- return select(textbookPaperMapper, page, pageSize);
- }
- public Page<TextbookPaper> select(int page, int pageSize, String keyword){
- Example example = new Example(TextbookPaper.class);
- example.and(
- example.createCriteria()
- .andEqualTo("status", 1)
- );
- if (keyword != null)
- example.and(
- example.createCriteria()
- .andLike("title", "%"+keyword+"%")
- );
- return select(textbookPaperMapper, example, page, pageSize);
- }
- public Page<TextbookPaper> select(Integer[] ids){
- return page(()-> select(textbookPaperMapper, ids), 1, ids.length);
- }
- public List<TextbookPaper> select(Collection ids){
- return select(textbookPaperMapper, ids);
- }
- }
|