UserReportService.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package com.qxgmat.service.inline;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.github.pagehelper.Page;
  4. import com.nuliji.tools.AbstractService;
  5. import com.nuliji.tools.Transform;
  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.dao.UserQuestionMapper;
  10. import com.qxgmat.data.dao.UserReportMapper;
  11. import com.qxgmat.data.dao.entity.UserPaper;
  12. import com.qxgmat.data.dao.entity.UserQuestion;
  13. import com.qxgmat.data.dao.entity.UserReport;
  14. import com.qxgmat.data.relation.UserReportRelationMapper;
  15. import com.qxgmat.data.relation.entity.UserHomeworkPreviewRelation;
  16. import com.qxgmat.service.annotation.InitPaper;
  17. import com.qxgmat.service.annotation.InitReport;
  18. import com.qxgmat.util.shiro.UserRealm;
  19. import org.slf4j.Logger;
  20. import org.slf4j.LoggerFactory;
  21. import org.springframework.stereotype.Service;
  22. import javax.annotation.Resource;
  23. import java.util.*;
  24. @Service
  25. public class UserReportService extends AbstractService {
  26. private static final Logger logger = LoggerFactory.getLogger(UserReportService.class);
  27. @Resource
  28. private UserReportMapper userReportMapper;
  29. @Resource
  30. private UserReportRelationMapper userReportRelationMapper;
  31. /**
  32. * 获取所属组卷的所有报告
  33. * @param paperIds
  34. * @return
  35. */
  36. public Map<Object, Collection<UserReport>> mapByPaper(Collection paperIds){
  37. Map<Object, Collection<UserReport>> relationMap = new HashMap<>();
  38. if(paperIds.size() == 0) return relationMap;
  39. Example example = new Example(UserReport.class);
  40. example.and(
  41. example.createCriteria()
  42. .andIn("paperId", paperIds)
  43. );
  44. List<UserReport> userClassList = select(userReportMapper, example);
  45. if(userClassList.size() == 0) return relationMap;
  46. for(UserReport row: userClassList){
  47. List<UserReport> l;
  48. Number paperId = row.getPaperId();
  49. if(!relationMap.containsKey(paperId)){
  50. l = new ArrayList<>();
  51. relationMap.put(paperId, l);
  52. }else{
  53. l = (List<UserReport>)relationMap.get(paperId);
  54. }
  55. l.add(row);
  56. }
  57. return relationMap;
  58. }
  59. /**
  60. * 根据用户paper生成一份新的report记录
  61. * @param paper
  62. * @param setting
  63. * @param IInitReport
  64. * @return
  65. */
  66. public UserReport addByPaper(UserPaper paper, JSONObject setting, InitReport IInitReport){
  67. UserReport report = UserReport.builder()
  68. .module(paper.getModule())
  69. .moduleId(paper.getModuleId())
  70. .setting(setting)
  71. .userId(paper.getUserId())
  72. .paperId(paper.getId())
  73. .questionNoIds(paper.getQuestionNoIds())
  74. .build();
  75. // 回调,根据模块更新设置
  76. IInitReport.callback(report, paper);
  77. return add(report);
  78. }
  79. public UserReport add(UserReport report){
  80. int result = insert(userReportMapper, report);
  81. report = one(userReportMapper, report.getId());
  82. if(report == null){
  83. throw new SystemException("用户报告添加失败");
  84. }
  85. return report;
  86. }
  87. public UserReport edit(UserReport report){
  88. UserReport in = one(userReportMapper, report.getId());
  89. if(in == null){
  90. throw new ParameterException("用户报告不存在");
  91. }
  92. int result = update(userReportMapper, report);
  93. return report;
  94. }
  95. public boolean delete(Number id){
  96. UserReport in = one(userReportMapper, id);
  97. if(in == null){
  98. throw new ParameterException("用户报告不存在");
  99. }
  100. int result = delete(userReportMapper, id);
  101. return result > 0;
  102. }
  103. public UserReport get(Number id){
  104. UserReport in = one(userReportMapper, id);
  105. if(in == null){
  106. throw new ParameterException("用户报告不存在");
  107. }
  108. return in;
  109. }
  110. public Page<UserReport> select(int page, int pageSize){
  111. return select(userReportMapper, page, pageSize);
  112. }
  113. public List<UserReport> select(Collection ids){
  114. return select(userReportMapper, ids);
  115. }
  116. }