UserPaperService.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. package com.qxgmat.service;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.github.pagehelper.Page;
  4. import com.nuliji.tools.AbstractService;
  5. import com.nuliji.tools.PageResult;
  6. import com.nuliji.tools.exception.ParameterException;
  7. import com.nuliji.tools.exception.SystemException;
  8. import com.nuliji.tools.mybatis.Example;
  9. import com.qxgmat.data.constants.enums.QuestionType;
  10. import com.qxgmat.data.constants.enums.module.PaperModule;
  11. import com.qxgmat.data.constants.enums.status.DirectionStatus;
  12. import com.qxgmat.data.dao.UserPaperMapper;
  13. import com.qxgmat.data.dao.entity.UserPaper;
  14. import com.qxgmat.data.dao.entity.UserReport;
  15. import com.qxgmat.data.relation.UserPaperRelationMapper;
  16. import com.qxgmat.service.annotation.InitPaper;
  17. import com.qxgmat.service.inline.UserReportService;
  18. import com.qxgmat.util.annotation.Callback;
  19. import org.slf4j.Logger;
  20. import org.slf4j.LoggerFactory;
  21. import org.springframework.stereotype.Service;
  22. import org.springframework.transaction.annotation.Transactional;
  23. import javax.annotation.Resource;
  24. import java.util.Collection;
  25. import java.util.HashMap;
  26. import java.util.List;
  27. import java.util.Map;
  28. @Service
  29. public class UserPaperService extends AbstractService {
  30. private static final Logger logger = LoggerFactory.getLogger(UserPaperService.class);
  31. protected boolean SOFT_FLAG = true;
  32. @Resource
  33. private UserPaperMapper userPaperMapper;
  34. @Resource
  35. private UserPaperRelationMapper userPaperRelationMapper;
  36. @Resource
  37. private UserReportService userReportService;
  38. /**
  39. * 获取报告列表:以paper进行分组
  40. * @param page
  41. * @param size
  42. * @param userId
  43. * @param module
  44. * @param type
  45. * @param startTime
  46. * @param endTime
  47. * @param order
  48. * @param direction
  49. * @return
  50. */
  51. public PageResult<UserPaper> list(int page, int size, Integer userId, PaperModule module, QuestionType type, String startTime, String endTime, String order, DirectionStatus direction){
  52. return new PageResult<>(null, 0);
  53. }
  54. public UserPaper getByPaper(Integer userId, PaperModule module, Integer paperId, InitPaper IInitPaper){
  55. // 查找对应的paper是否有,没有则添加
  56. Example example = new Example(UserPaper.class);
  57. example.and(
  58. example.createCriteria()
  59. .andEqualTo("userId", userId)
  60. .andEqualTo("module", module.key)
  61. .andEqualTo("module_id", paperId)
  62. );
  63. UserPaper paper = one(userPaperMapper, example);
  64. if (paper == null){
  65. paper = UserPaper.builder().userId(userId).module(module.key).moduleId(paperId).build();
  66. // 回调,根据模块更新设置
  67. IInitPaper.callback(paper, paperId);
  68. paper = add(paper);
  69. }
  70. return paper;
  71. }
  72. /**
  73. * 重置做题信息:不自动关联最后次做题记录
  74. * @param id
  75. * @return
  76. */
  77. public Boolean reset(Integer id, Integer userId){
  78. Example example = new Example(UserPaper.class);
  79. example.and(
  80. example.createCriteria()
  81. .andEqualTo("id", id)
  82. .andEqualTo("userId", userId)
  83. );
  84. return update(userPaperMapper, example, UserPaper.builder().isReset(1).build()) > 0;
  85. }
  86. /**
  87. * 累加做题记录到paper
  88. * @param report
  89. */
  90. public void accumulation(UserReport report){
  91. userPaperRelationMapper.accumulation(report.getPaperId(), report.getUserNumber(), report.getUserTime(), report.getCorrectNumber(), 1);
  92. }
  93. /**
  94. * 批量删除用户记录:homework切换可用学生
  95. * @param userIds
  96. * @param module
  97. * @param paperId
  98. * @return
  99. */
  100. public Boolean removeByUsersAndPaper(Collection<Integer> userIds, PaperModule module, Integer paperId){
  101. if(userIds.size() == 0) return false;
  102. Example example = new Example(UserPaper.class);
  103. example.and(
  104. example.createCriteria()
  105. .andIn("userId", userIds)
  106. .andEqualTo("module", module.key)
  107. .andEqualTo("moduleId", paperId)
  108. );
  109. return delete(userPaperMapper, example, SOFT_FLAG) > 0;
  110. }
  111. /**
  112. * 批量修改用户记录:homework更新内容
  113. * @param userIds
  114. * @param module
  115. * @param paperId
  116. * @return
  117. */
  118. public Boolean editByUsersAndPaper(UserPaper userPaper, Collection<Integer> userIds, PaperModule module, Integer paperId){
  119. if(userIds.size() == 0) return false;
  120. Example example = new Example(UserPaper.class);
  121. example.and(
  122. example.createCriteria()
  123. .andIn("userId", userIds)
  124. .andEqualTo("module", module.key)
  125. .andEqualTo("moduleId", paperId)
  126. );
  127. return update(userPaperMapper, example, userPaper) > 0;
  128. }
  129. public UserPaper add(UserPaper paper){
  130. int result = insert(userPaperMapper, paper);
  131. paper = one(userPaperMapper, paper.getId());
  132. if(paper == null){
  133. throw new SystemException("组卷添加失败");
  134. }
  135. return paper;
  136. }
  137. public UserPaper edit(UserPaper paper){
  138. UserPaper in = one(userPaperMapper, paper.getId());
  139. if(in == null){
  140. throw new ParameterException("组卷不存在");
  141. }
  142. int result = update(userPaperMapper, paper);
  143. return paper;
  144. }
  145. public boolean delete(Number id){
  146. UserPaper in = one(userPaperMapper, id);
  147. if(in == null){
  148. throw new ParameterException("组卷不存在");
  149. }
  150. int result = delete(userPaperMapper, id);
  151. return result > 0;
  152. }
  153. public UserPaper get(Number id){
  154. UserPaper in = one(userPaperMapper, id);
  155. if(in == null){
  156. throw new ParameterException("组卷不存在");
  157. }
  158. return in;
  159. }
  160. public Page<UserPaper> select(int page, int pageSize){
  161. return select(userPaperMapper, page, pageSize);
  162. }
  163. public List<UserPaper> select(Collection ids){
  164. return select(userPaperMapper, ids);
  165. }
  166. }