123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380 |
- package com.qxgmat.service;
- import com.alibaba.fastjson.JSONObject;
- 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.QuestionType;
- import com.qxgmat.data.constants.enums.module.PaperModule;
- import com.qxgmat.data.constants.enums.module.PaperOrigin;
- import com.qxgmat.data.constants.enums.module.QuestionOrigin;
- import com.qxgmat.data.constants.enums.status.DirectionStatus;
- import com.qxgmat.data.dao.UserPaperMapper;
- import com.qxgmat.data.dao.entity.UserPaper;
- import com.qxgmat.data.dao.entity.UserReport;
- import com.qxgmat.data.relation.UserPaperRelationMapper;
- import com.qxgmat.service.annotation.InitPaper;
- import com.qxgmat.service.extend.ToolsService;
- import com.qxgmat.service.inline.UserPaperQuestionService;
- import com.qxgmat.service.inline.UserReportService;
- import com.qxgmat.util.annotation.Callback;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import javax.annotation.Resource;
- import java.util.*;
- @Service
- public class UserPaperService extends AbstractService {
- private static final Logger logger = LoggerFactory.getLogger(UserPaperService.class);
- protected boolean SOFT_FLAG = true;
- @Resource
- private UserPaperMapper userPaperMapper;
- @Resource
- private UserPaperRelationMapper userPaperRelationMapper;
- @Resource
- private UserReportService userReportService;
- @Resource
- private UserPaperQuestionService userPaperQuestionService;
- @Resource
- private ToolsService toolsService;
- /**
- * 获取报告列表:以paper进行分组
- * @param page
- * @param size
- * @param userId
- * @param origin
- * @param startTime
- * @param endTime
- * @param order
- * @return
- */
- public Page<UserPaper> list(int page, int size, Integer userId, String keyword, PaperOrigin origin, String startTime, String endTime, String order){
- Page<UserPaper> p = page(()->{
- userPaperRelationMapper.list(userId, keyword, origin != null ? origin.key : null, startTime, endTime, order);
- }, page, size);
- Collection ids = Transform.getIds(p, UserPaper.class, "id");
- // 获取详细数据
- List<UserPaper> list = select(ids);
- Transform.replace(p, list, UserPaper.class, "id");
- return p;
- }
- /**
- * 获取报告列表:以paper进行分组
- * @param page
- * @param size
- * @param userId
- * @param startTime
- * @param endTime
- * @param order
- * @return
- */
- public Page<UserPaper> listExercise(int page, int size, Integer userId, String keyword, String[] questionTypes, Integer[] structIds, String[] courseModules, String startTime, String endTime, String order){
- Page<UserPaper> p = page(()->{
- userPaperRelationMapper.listExercise(userId, keyword, questionTypes, structIds, courseModules, startTime, endTime, order);
- }, page, size);
- Collection ids = Transform.getIds(p, UserPaper.class, "id");
- // 获取详细数据
- List<UserPaper> list = select(ids);
- Transform.replace(p, list, UserPaper.class, "id");
- return p;
- }
- /**
- * 获取报告列表:以paper进行分组
- * @param page
- * @param size
- * @param userId
- * @param startTime
- * @param endTime
- * @param order
- * @return
- */
- public Page<UserPaper> listExamination(int page, int size, Integer userId, String keyword, Integer[] structIds, Integer libraryId, String year, String startTime, String endTime, String order){
- Page<UserPaper> p = page(()->{
- userPaperRelationMapper.listExamination(userId, keyword, structIds, libraryId, year, startTime, endTime, order);
- }, page, size);
- Collection ids = Transform.getIds(p, UserPaper.class, "id");
- // 获取详细数据
- List<UserPaper> list = select(ids);
- Transform.replace(p, list, UserPaper.class, "id");
- return p;
- }
- /**
- * 获取用户做题记录
- * @param userId
- * @param origin
- * @param ids
- * @param recordId
- * @return
- */
- public List<UserPaper> listWithOrigin(Integer userId, PaperOrigin origin, Collection ids, Integer recordId){
- if (ids == null || ids.size() == 0) return new ArrayList<>();
- Example example = new Example(UserPaper.class);
- example.and(
- example.createCriteria()
- .andEqualTo("userId", userId)
- .andEqualTo("paperOrigin", origin.key)
- .andIn("originId", ids)
- );
- if (recordId != null){
- example.and(
- example.createCriteria()
- .andEqualTo("recordId", recordId)
- );
- }
- return select(userPaperMapper, example);
- }
- /**
- * 获取用户预约预习作业记录
- * @param ids
- * @return
- */
- public List<UserPaper> listWithAppointment(Collection ids){
- if(ids == null || ids.size() == 0) return new ArrayList<>();
- Example example = new Example(UserPaper.class);
- example.and(
- example.createCriteria()
- .andEqualTo("paperOrigin", PaperOrigin.PREVIEW.key)
- .andIn("originId", ids)
- );
- return select(userPaperMapper, example);
- }
- /**
- * 获取用户预约预习作业记录
- * @param ids
- * @return
- */
- public List<UserPaper> listWithCourse(Integer userId, Collection ids, Integer recordId){
- if (ids == null || ids.size() == 0) return new ArrayList<>();
- Example example = new Example(UserPaper.class);
- example.and(
- example.createCriteria()
- .andEqualTo("userId", userId)
- .andEqualTo("recordId", recordId)
- .andEqualTo("paperOrigin", PaperOrigin.PREVIEW.key)
- .andIn("originId", ids)
- );
- return select(userPaperMapper, example);
- }
- /**
- * 获取用户cat做题记录
- * @param userId
- * @param ids
- * @param no
- * @return
- */
- public List<UserPaper> listWithCat(Integer userId, Collection ids, Integer no){
- if (ids == null || ids.size() == 0) return new ArrayList<>();
- Example example = new Example(UserPaper.class);
- example.and(
- example.createCriteria()
- .andEqualTo("userId", userId)
- .andEqualTo("paperOrigin", PaperOrigin.EXAMINATION.key)
- .andIn("originId", ids)
- .andEqualTo("qxCatNo", no)
- );
- return select(userPaperMapper, example);
- }
- /**
- * 获取用户做题组卷
- * @param userId
- * @param origin
- * @param originId
- * @return
- */
- public UserPaper getByPaper(Integer userId, PaperOrigin origin, Integer originId){
- // 查找对应的paper是否有,没有则添加
- Example example = new Example(UserPaper.class);
- UserPaper paper;
- if (origin.equals(PaperOrigin.ERROR) || origin.equals(PaperOrigin.COLLECT)){
- // 错题和收藏组卷,originId即为userPaper的id
- example.and(
- example.createCriteria()
- .andEqualTo("userId", userId)
- .andEqualTo("paperOrigin", origin.key)
- .andEqualTo("id", originId)
- );
- paper = one(userPaperMapper, example);
- if (paper == null){
- throw new ParameterException("试卷不存在");
- }
- }else{
- example.and(
- example.createCriteria()
- .andEqualTo("userId", userId)
- .andEqualTo("paperOrigin", origin.key)
- .andEqualTo("originId", originId)
- );
- paper = one(userPaperMapper, example);
- }
- return paper;
- }
- /**
- * 生成用户做题组卷
- * @param userId
- * @param origin
- * @param module
- * @param originId
- * @return
- */
- public UserPaper newByPaper(Integer userId, PaperOrigin origin, PaperModule module, Integer originId){
- return UserPaper.builder()
- .userId(userId)
- .paperOrigin(origin.key)
- .paperModule(module.key)
- .originId(originId)
- .build();
- }
- /**
- * 重置做题信息:不自动关联最后次做题记录
- * @param id
- * @return
- */
- public Boolean reset(Integer id, Integer userId){
- Example example = new Example(UserPaper.class);
- example.and(
- example.createCriteria()
- .andEqualTo("id", id)
- .andEqualTo("userId", userId)
- );
- return update(userPaperMapper, example, UserPaper.builder().isReset(1).build()) > 0;
- }
- /**
- * 重置做题信息:不自动关联最后次做题记录
- * @param ids
- * @return
- */
- public Boolean reset(Collection ids, Integer userId){
- if (ids == null || ids.size() == 0) return true;
- Example example = new Example(UserPaper.class);
- example.and(
- example.createCriteria()
- .andIn("id", ids)
- .andEqualTo("userId", userId)
- );
- return update(userPaperMapper, example, UserPaper.builder().isReset(1).build()) > 0;
- }
- /**
- * 累加做题记录到paper
- * @param report
- */
- public void accumulation(UserReport report){
- userPaperRelationMapper.accumulation(report.getPaperId(), report.getUserNumber(), report.getUserTime(), report.getUserCorrect(), 1, report.getFinishTime(), report.getId());
- }
- /**
- * 批量删除用户记录:preview切换可用学生
- * @param userIds
- * @param origin
- * @param originId
- * @return
- */
- public Boolean removeByUsersAndPaper(Collection<Integer> userIds, PaperOrigin origin, Integer originId){
- if(userIds == null || userIds.size() == 0) return false;
- Example example = new Example(UserPaper.class);
- example.and(
- example.createCriteria()
- .andIn("userId", userIds)
- .andEqualTo("paperOrigin", origin.key)
- .andEqualTo("originId", originId)
- );
- return delete(userPaperMapper, example, SOFT_FLAG) > 0;
- }
- /**
- * 批量修改用户记录:preview更新内容
- * @param userIds
- * @param origin
- * @param originId
- * @return
- */
- public Boolean editByUsersAndPaper(UserPaper userPaper, Collection<Integer> userIds, PaperOrigin origin, Integer originId){
- if(userIds == null || userIds.size() == 0) return false;
- Example example = new Example(UserPaper.class);
- example.and(
- example.createCriteria()
- .andIn("userId", userIds)
- .andEqualTo("paperOrigin", origin.key)
- .andEqualTo("originId", originId)
- );
- return update(userPaperMapper, example, userPaper) > 0;
- }
- public UserPaper add(UserPaper paper){
- int result = insert(userPaperMapper, paper);
- paper = one(userPaperMapper, paper.getId());
- if(paper == null){
- throw new SystemException("组卷添加失败");
- }
- return paper;
- }
- public UserPaper edit(UserPaper paper){
- UserPaper in = one(userPaperMapper, paper.getId());
- if(in == null){
- throw new ParameterException("组卷不存在");
- }
- int result = update(userPaperMapper, paper);
- return paper;
- }
- public boolean delete(Number id){
- UserPaper in = one(userPaperMapper, id);
- if(in == null){
- throw new ParameterException("组卷不存在");
- }
- int result = delete(userPaperMapper, id);
- return result > 0;
- }
- public UserPaper get(Number id){
- UserPaper in = one(userPaperMapper, id);
- if(in == null){
- throw new ParameterException("组卷不存在");
- }
- return in;
- }
- public Page<UserPaper> select(int page, int pageSize){
- return select(userPaperMapper, page, pageSize);
- }
- public Page<UserPaper> select(Integer[] ids){
- return page(()->select(userPaperMapper, ids), 1, ids.length);
- }
- public List<UserPaper> select(Collection ids){
- return select(userPaperMapper, ids);
- }
- }
|