PaperServiceImpl.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. package cn.com.qmth.mps.service.impl;
  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import java.util.ArrayList;
  5. import java.util.Arrays;
  6. import java.util.Comparator;
  7. import java.util.HashMap;
  8. import java.util.List;
  9. import java.util.Map;
  10. import java.util.stream.Collectors;
  11. import org.apache.commons.collections4.CollectionUtils;
  12. import org.apache.commons.lang3.StringUtils;
  13. import org.springframework.beans.BeanUtils;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.dao.DuplicateKeyException;
  16. import org.springframework.stereotype.Service;
  17. import org.springframework.transaction.annotation.Transactional;
  18. import org.springframework.transaction.interceptor.TransactionAspectSupport;
  19. import org.springframework.web.multipart.MultipartFile;
  20. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  21. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  22. import com.baomidou.mybatisplus.core.metadata.IPage;
  23. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  24. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  25. import com.qmth.boot.core.collection.PageResult;
  26. import com.qmth.boot.core.exception.StatusException;
  27. import com.qmth.boot.tools.excel.ExcelReader;
  28. import com.qmth.boot.tools.excel.enums.ExcelType;
  29. import com.qmth.boot.tools.excel.model.DataMap;
  30. import cn.com.qmth.mps.bean.PaperDetail;
  31. import cn.com.qmth.mps.bean.PaperDetailUnit;
  32. import cn.com.qmth.mps.bean.User;
  33. import cn.com.qmth.mps.dao.PaperDao;
  34. import cn.com.qmth.mps.entity.CourseEntity;
  35. import cn.com.qmth.mps.entity.ExamEntity;
  36. import cn.com.qmth.mps.entity.PaperEntity;
  37. import cn.com.qmth.mps.enums.ExamStatus;
  38. import cn.com.qmth.mps.enums.Role;
  39. import cn.com.qmth.mps.service.CourseService;
  40. import cn.com.qmth.mps.service.ExamService;
  41. import cn.com.qmth.mps.service.PaperDetailService;
  42. import cn.com.qmth.mps.service.PaperGroupService;
  43. import cn.com.qmth.mps.service.PaperService;
  44. import cn.com.qmth.mps.util.BatchSetDataUtil;
  45. import cn.com.qmth.mps.util.Calculator;
  46. import cn.com.qmth.mps.util.PageUtil;
  47. import cn.com.qmth.mps.vo.exam.ExamPaperCountVo;
  48. import cn.com.qmth.mps.vo.paper.GroupCountVo;
  49. import cn.com.qmth.mps.vo.paper.PaperInfoVo;
  50. import cn.com.qmth.mps.vo.paper.PaperQuery;
  51. import cn.com.qmth.mps.vo.paper.PaperStructInfoVo;
  52. import cn.com.qmth.mps.vo.paper.PaperVo;
  53. import cn.com.qmth.mps.vo.paper.StructDomain;
  54. @Service
  55. public class PaperServiceImpl extends ServiceImpl<PaperDao, PaperEntity> implements PaperService {
  56. private static final String[] SUBJECT_EXCEL_HEADER = new String[] {"科目代码", "科目名称"};
  57. private static final String[] SUBJECT_STRUCT_EXCEL_HEADER = new String[] {"科目代码*","科目名称","大题名称*","题目昵称","大题号(只能用小写数字)*","小题号(只能用小写数字)*","小题满分*","间隔分*","评卷分组(只能用小写数字)*","图片序号(用英文逗号分割)","双评比例(0~1)","仲裁阀值","合分策略(1-平均,2-最高,3-最低)","评卷模式(common-普通,track-轨迹)","试评数量(0-跳过试评)","选做题数量"};
  58. @Autowired
  59. private ExamService examService;
  60. @Autowired
  61. private CourseService courseService;
  62. @Autowired
  63. private PaperGroupService paperGroupService;
  64. @Autowired
  65. private PaperDetailService paperDetailService;
  66. @Transactional
  67. @Override
  68. public List<String> importPaper(Long examId, User user, MultipartFile file) {
  69. ExamEntity exam = examService.getById(examId);
  70. if (exam == null) {
  71. throw new StatusException("未找到考试批次");
  72. }
  73. if(!ExamStatus.EDIT.equals(exam.getExamStatus())) {
  74. throw new StatusException("考试未开放上报,不能设置结构信息或分组信息");
  75. }
  76. if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(exam.getSchoolId())) {
  77. throw new StatusException("没有权限");
  78. }
  79. InputStream inputStream = null;
  80. try {
  81. inputStream = file.getInputStream();
  82. ExcelReader reader=ExcelReader.create(ExcelType.XLSX, inputStream, 0);
  83. List<DataMap> lineList = reader.getDataMapList();
  84. if(!Arrays.equals(SUBJECT_EXCEL_HEADER,reader.getColumnNames())) {
  85. throw new StatusException("Excel表头错误");
  86. }
  87. if (CollectionUtils.isEmpty(lineList)) {
  88. throw new StatusException("Excel无内容");
  89. }
  90. if (1001 < lineList.size()) {
  91. throw new StatusException("数据行数不能超过1000");
  92. }
  93. List<String> failRecords = new ArrayList<>();
  94. List<PaperEntity> ret = new ArrayList<>();
  95. for (int i = 0; i < lineList.size(); i++) {
  96. DataMap line = lineList.get(i);
  97. StringBuilder msg = new StringBuilder();
  98. PaperEntity imp = new PaperEntity();
  99. imp.setTotalScore(0.0);
  100. imp.setObjectiveScore(0.0);
  101. imp.setSubjectiveScore(0.0);
  102. imp.setSchoolId(exam.getSchoolId());
  103. imp.setGroupFinish(false);
  104. imp.setStructFinish(false);
  105. imp.setExamId(examId);
  106. String code = trimAndNullIfBlank(line.get(SUBJECT_EXCEL_HEADER[0]));
  107. if (StringUtils.isBlank(code)) {
  108. msg.append(" 科目代码不能为空");
  109. } else if (code.length() > 50) {
  110. msg.append(" 科目代码不能超过50个字符");
  111. }
  112. String name = trimAndNullIfBlank(line.get(SUBJECT_EXCEL_HEADER[1]));
  113. if (StringUtils.isBlank(name)) {
  114. msg.append(" 科目名称不能为空");
  115. } else if (name.length() > 50) {
  116. msg.append(" 科目名称不能超过50个字符");
  117. }
  118. if (msg.length() == 0) {
  119. CourseEntity course = courseService.saveOrGet(exam.getSchoolId(), code, name);
  120. imp.setCourseId(course.getId());
  121. }
  122. if (msg.length() > 0) {
  123. failRecords.add(newError(i + 1, msg.toString()));
  124. } else {
  125. ret.add(imp);
  126. }
  127. }
  128. if (CollectionUtils.isNotEmpty(failRecords)) {
  129. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  130. return failRecords;
  131. }
  132. for (int i = 0; i < ret.size(); i++) {
  133. PaperEntity cur = ret.get(i);
  134. try {
  135. this.save(cur);
  136. } catch (DuplicateKeyException e) {
  137. // failRecords.add(newError(i + 1, "科目已存在"));
  138. } catch (Exception e) {
  139. failRecords.add(newError(i + 1, "系统异常"));
  140. log.error("科目导入系统异常", e);
  141. }
  142. }
  143. if (CollectionUtils.isNotEmpty(failRecords)) {
  144. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  145. }
  146. return failRecords;
  147. } catch (StatusException e) {
  148. throw e;
  149. } catch (Exception e) {
  150. throw new RuntimeException("系统错误", e);
  151. } finally {
  152. if (inputStream != null) {
  153. try {
  154. inputStream.close();
  155. } catch (IOException e) {
  156. }
  157. }
  158. }
  159. }
  160. private String trimAndNullIfBlank(String s) {
  161. if (StringUtils.isBlank(s)) {
  162. return null;
  163. }
  164. return s.trim();
  165. }
  166. private String newError(int lineNum, String msg) {
  167. return "第" + lineNum + "行" + msg;
  168. }
  169. @Override
  170. public List<ExamPaperCountVo> findPaperCount(List<Long> examIds) {
  171. return this.baseMapper.findPaperCount(examIds);
  172. }
  173. @Override
  174. public Integer findPaperCount(Long examId) {
  175. QueryWrapper<PaperEntity> wrapper = new QueryWrapper<>();
  176. LambdaQueryWrapper<PaperEntity> lw = wrapper.lambda();
  177. lw.eq(PaperEntity::getExamId, examId);
  178. return this.count(wrapper);
  179. }
  180. private PaperEntity findByExamAndCourse(Long examId, Long courseId) {
  181. QueryWrapper<PaperEntity> wrapper = new QueryWrapper<>();
  182. LambdaQueryWrapper<PaperEntity> lw = wrapper.lambda();
  183. lw.eq(PaperEntity::getExamId, examId);
  184. lw.eq(PaperEntity::getCourseId, courseId);
  185. return this.getOne(wrapper);
  186. }
  187. private PaperEntity saveOrGet(Long schoolId, Long examId, Long courseId) {
  188. PaperEntity ret = findByExamAndCourse(examId, courseId);
  189. if (ret != null) {
  190. return ret;
  191. }
  192. PaperEntity imp = new PaperEntity();
  193. imp.setTotalScore(0.0);
  194. imp.setObjectiveScore(0.0);
  195. imp.setSubjectiveScore(0.0);
  196. imp.setSchoolId(schoolId);
  197. imp.setGroupFinish(false);
  198. imp.setCourseId(courseId);
  199. imp.setExamId(examId);
  200. imp.setStructFinish(true);
  201. this.save(imp);
  202. return imp;
  203. }
  204. @Override
  205. public PageResult<PaperVo> page(PaperQuery query, User user) {
  206. if (query.getSchoolId() == null) {
  207. throw new StatusException("学校不能为空");
  208. }
  209. if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(query.getSchoolId())) {
  210. throw new StatusException("没有权限");
  211. }
  212. IPage<PaperVo> iPage = this.baseMapper.page(new Page<PaperVo>(query.getPageNumber(), query.getPageSize()),
  213. query);
  214. if (CollectionUtils.isNotEmpty(iPage.getRecords())) {
  215. new BatchSetDataUtil<PaperVo>() {
  216. @Override
  217. protected void setData(List<PaperVo> dataList) {
  218. List<Long> paperIds = dataList.stream().map(dto -> dto.getId()).distinct()
  219. .collect(Collectors.toList());
  220. List<GroupCountVo> ret = paperGroupService.findGroupCount(paperIds);
  221. if (ret != null && ret.size() > 0) {
  222. Map<Long, Integer> countMap = new HashMap<>();
  223. for (GroupCountVo item : ret) {
  224. countMap.put(item.getPaperId(), item.getGroupCount());
  225. }
  226. for (PaperVo vo : dataList) {
  227. vo.setGroupCount(countMap.get(vo.getId()));
  228. }
  229. }
  230. }
  231. }.setDataForBatch(iPage.getRecords(), 20);
  232. for (PaperVo vo : iPage.getRecords()) {
  233. if(vo.getGroupCount()==null) {
  234. vo.setGroupCount(0);
  235. }
  236. }
  237. }
  238. return PageUtil.of(iPage);
  239. }
  240. @Override
  241. public List<PaperVo> list(Long examId, User user) {
  242. ExamEntity exam = examService.getById(examId);
  243. if (exam == null) {
  244. throw new StatusException("未找到考试批次");
  245. }
  246. if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(exam.getSchoolId())) {
  247. throw new StatusException("没有权限");
  248. }
  249. List<PaperVo> ret=this.baseMapper.myPaperlist(examId,user.getId());
  250. if (CollectionUtils.isNotEmpty(ret)) {
  251. new BatchSetDataUtil<PaperVo>() {
  252. @Override
  253. protected void setData(List<PaperVo> dataList) {
  254. List<Long> paperIds = dataList.stream().map(dto -> dto.getId()).distinct()
  255. .collect(Collectors.toList());
  256. List<GroupCountVo> ret = paperGroupService.findGroupCount(paperIds);
  257. if (ret != null && ret.size() > 0) {
  258. Map<Long, Integer> countMap = new HashMap<>();
  259. for (GroupCountVo item : ret) {
  260. countMap.put(item.getPaperId(), item.getGroupCount());
  261. }
  262. for (PaperVo vo : dataList) {
  263. vo.setGroupCount(countMap.get(vo.getId()));
  264. }
  265. }
  266. }
  267. }.setDataForBatch(ret, 20);
  268. }
  269. return ret;
  270. }
  271. @Override
  272. public PaperInfoVo info(Long id, User user) {
  273. PaperEntity paper = this.getById(id);
  274. if (paper == null) {
  275. throw new StatusException("未找到试卷结构信息");
  276. }
  277. if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(paper.getSchoolId())) {
  278. throw new StatusException("没有权限");
  279. }
  280. PaperInfoVo vo = new PaperInfoVo();
  281. BeanUtils.copyProperties(paper, vo);
  282. CourseEntity course = courseService.getById(vo.getCourseId());
  283. vo.setCourseCode(course.getCode());
  284. vo.setCourseName(course.getName());
  285. vo.setStructInfo(paperDetailService.getStructInfo(vo.getId()));
  286. vo.setGroupInfo(paperGroupService.getGroupInfo(vo.getId()));
  287. return vo;
  288. }
  289. @Transactional
  290. @Override
  291. public List<String> importSubjectStruct(Long examId, User user, MultipartFile file) {
  292. ExamEntity exam = examService.getById(examId);
  293. if (exam == null) {
  294. throw new StatusException("未找到考试批次");
  295. }
  296. if(!ExamStatus.EDIT.equals(exam.getExamStatus())) {
  297. throw new StatusException("考试未开放上报,不能设置结构信息或分组信息");
  298. }
  299. if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(exam.getSchoolId())) {
  300. throw new StatusException("没有权限");
  301. }
  302. InputStream inputStream = null;
  303. try {
  304. inputStream = file.getInputStream();
  305. ExcelReader reader=ExcelReader.create(ExcelType.XLSX, inputStream, 1);
  306. List<DataMap> lineList = reader.getDataMapList();
  307. if(!Arrays.equals(SUBJECT_STRUCT_EXCEL_HEADER,reader.getColumnNames())) {
  308. throw new StatusException("Excel表头错误");
  309. }
  310. if (CollectionUtils.isEmpty(lineList)) {
  311. throw new StatusException("Excel无内容");
  312. }
  313. if (10001 < lineList.size()) {
  314. throw new StatusException("数据行数不能超过10000");
  315. }
  316. List<String> failRecords = new ArrayList<>();
  317. List<PaperStructInfoVo> ret = new ArrayList<>();
  318. for (int i = 0; i < lineList.size(); i++) {
  319. DataMap line = lineList.get(i);
  320. StringBuilder msg = new StringBuilder();
  321. PaperStructInfoVo imp = new PaperStructInfoVo();
  322. String code = trimAndNullIfBlank(line.get(SUBJECT_STRUCT_EXCEL_HEADER[0]));
  323. if (StringUtils.isBlank(code)) {
  324. msg.append(" 科目代码不能为空");
  325. } else if (code.length() > 50) {
  326. msg.append(" 科目代码不能超过50个字符");
  327. }
  328. imp.setCourseCode(code);
  329. String name = trimAndNullIfBlank(line.get(SUBJECT_STRUCT_EXCEL_HEADER[1]));
  330. if (StringUtils.isBlank(name)) {
  331. msg.append(" 科目名称不能为空");
  332. } else if (name.length() > 50) {
  333. msg.append(" 科目名称不能超过50个字符");
  334. }
  335. if (msg.length() == 0) {
  336. CourseEntity course = courseService.saveOrGet(exam.getSchoolId(), code, name);
  337. PaperEntity paper = saveOrGet(exam.getSchoolId(), examId, course.getId());
  338. imp.setPaperId(paper.getId());
  339. }
  340. String detailName = trimAndNullIfBlank(line.get(SUBJECT_STRUCT_EXCEL_HEADER[2]));
  341. if (StringUtils.isBlank(detailName)) {
  342. msg.append(" 大题名称不能为空");
  343. } else if (detailName.length() > 50) {
  344. msg.append(" 大题名称不能超过50个字符");
  345. }
  346. imp.setDetailName(detailName);
  347. //第4列不处理
  348. String detailNumber = trimAndNullIfBlank(line.get(SUBJECT_STRUCT_EXCEL_HEADER[4]));
  349. if (StringUtils.isBlank(detailNumber)) {
  350. msg.append(" 大题号不能为空");
  351. } else {
  352. try {
  353. int n = Integer.valueOf(detailNumber);
  354. if (n <= 0) {
  355. msg.append(" 大题号不能小于0");
  356. } else {
  357. imp.setDetailNumber(n);
  358. }
  359. } catch (Exception e) {
  360. msg.append(" 大题号只能是整数");
  361. }
  362. }
  363. String unitNumber = trimAndNullIfBlank(line.get(SUBJECT_STRUCT_EXCEL_HEADER[5]));
  364. if (StringUtils.isBlank(unitNumber)) {
  365. msg.append(" 小题号不能为空");
  366. } else {
  367. try {
  368. int n = Integer.valueOf(unitNumber);
  369. if (n <= 0) {
  370. msg.append(" 小题号不能小于0");
  371. } else {
  372. imp.setUnitNumber(n);
  373. }
  374. } catch (Exception e) {
  375. msg.append(" 小题号只能是整数");
  376. }
  377. }
  378. String score = trimAndNullIfBlank(line.get(SUBJECT_STRUCT_EXCEL_HEADER[6]));
  379. if (StringUtils.isBlank(score)) {
  380. msg.append(" 小题满分不能为空");
  381. } else {
  382. try {
  383. Double n = Double.valueOf(score);
  384. if (n <= 0) {
  385. msg.append(" 小题满分不能小于0");
  386. } else {
  387. if (score.indexOf(".")>=0&&score.indexOf(".") < score.length() - 2) {
  388. msg.append("小题满分只能有一位小数");
  389. } else {
  390. imp.setScore(n);
  391. }
  392. }
  393. } catch (Exception e) {
  394. msg.append(" 小题满分格式错误");
  395. }
  396. }
  397. String scoreStep = trimAndNullIfBlank(line.get(SUBJECT_STRUCT_EXCEL_HEADER[7]));
  398. if (StringUtils.isBlank(scoreStep)) {
  399. msg.append(" 间隔分不能为空");
  400. } else {
  401. try {
  402. Double n = Double.valueOf(scoreStep);
  403. if (n <= 0) {
  404. msg.append(" 间隔分不能小于0");
  405. } else {
  406. if (scoreStep.indexOf(".")>=0&&scoreStep.indexOf(".") < scoreStep.length() - 2) {
  407. msg.append("小间隔分只能有一位小数");
  408. } else {
  409. imp.setScoreStep(n);
  410. }
  411. }
  412. } catch (Exception e) {
  413. msg.append(" 间隔分格式错误");
  414. }
  415. }
  416. if (msg.length() > 0) {
  417. failRecords.add(newError(i + 3, msg.toString()));
  418. } else {
  419. ret.add(imp);
  420. }
  421. }
  422. if (CollectionUtils.isNotEmpty(failRecords)) {
  423. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  424. return failRecords;
  425. }
  426. this.saveStruct(ret, user, failRecords);
  427. if (CollectionUtils.isNotEmpty(failRecords)) {
  428. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  429. }
  430. return failRecords;
  431. } catch (StatusException e) {
  432. throw e;
  433. } catch (Exception e) {
  434. throw new RuntimeException("系统错误", e);
  435. } finally {
  436. if (inputStream != null) {
  437. try {
  438. inputStream.close();
  439. } catch (IOException e) {
  440. }
  441. }
  442. }
  443. }
  444. private void saveStruct(List<PaperStructInfoVo> cards, User user, List<String> failRecords) {
  445. Map<Long,String> map=new HashMap<>();
  446. for(PaperStructInfoVo vo:cards) {
  447. map.put(vo.getPaperId(), vo.getCourseCode());
  448. }
  449. List<StructDomain> ces = getBeans(cards);
  450. // checkStruct(ces, failRecords,map);
  451. if (CollectionUtils.isNotEmpty(failRecords)) {
  452. return;
  453. }
  454. for (StructDomain domain : ces) {
  455. try {
  456. paperDetailService.structImport(domain, user);
  457. } catch (StatusException e) {
  458. failRecords.add("科目:"+map.get(domain.getPaperId())+" "+e.getMessage());
  459. } catch (Exception e) {
  460. throw new RuntimeException("系统错误", e);
  461. }
  462. }
  463. }
  464. // private void checkStruct(List<StructDomain> ces, List<String> failRecords,Map<Long,String> courseMap) {
  465. // for (StructDomain card : ces) {
  466. // int lastDetailNum = 0;
  467. // for (PaperDetail detail : card.getStructInfo()) {
  468. // if (detail.getNumber() - lastDetailNum != 1) {
  469. // failRecords.add(
  470. // "科目:" + courseMap.get(card.getPaperId()) + ",大题号" + detail.getNumber() + "错误");
  471. // }
  472. // lastDetailNum = detail.getNumber();
  473. // int lastUnitNum = 0;
  474. // for (PaperDetailUnit unit : detail.getUnits()) {
  475. // if (unit.getNumber() - lastUnitNum != 1) {
  476. // failRecords.add("科目:" + courseMap.get(card.getPaperId()) + ",大题号:"
  477. // + detail.getNumber() + ",小题号" + unit.getNumber() + "错误");
  478. // }
  479. // lastUnitNum = unit.getNumber();
  480. // }
  481. // }
  482. // }
  483. // }
  484. private List<StructDomain> getBeans(List<PaperStructInfoVo> cards) {
  485. cards.sort(new Comparator<PaperStructInfoVo>() {
  486. @Override
  487. public int compare(PaperStructInfoVo o1, PaperStructInfoVo o2) {
  488. long c1 = o1.getPaperId();
  489. long c2 = o2.getPaperId();
  490. if (c1 < c2) {
  491. return -1;
  492. } else if (c1 > c2) {
  493. return 1;
  494. } else {
  495. int indx1 = o1.getDetailNumber();
  496. int indx2 = o2.getDetailNumber();
  497. if (indx1 < indx2) {
  498. return -1;
  499. } else if (indx1 > indx2) {
  500. return 1;
  501. } else {
  502. int u1 = o1.getUnitNumber();
  503. int u2 = o2.getUnitNumber();
  504. if (u1 < u2) {
  505. return -1;
  506. } else if (u1 > u2) {
  507. return 1;
  508. } else {
  509. return 0;
  510. }
  511. }
  512. }
  513. }
  514. });
  515. List<StructDomain> ces = new ArrayList<>();
  516. StructDomain curCard = null;
  517. PaperDetail curDetail = null;
  518. for (PaperStructInfoVo info : cards) {
  519. if (curCard == null || !info.getPaperId().equals(curCard.getPaperId())) {
  520. curCard = new StructDomain();
  521. curCard.setPaperId(info.getPaperId());
  522. curCard.setStructInfo(new ArrayList<>());
  523. ces.add(curCard);
  524. curDetail = null;
  525. }
  526. if (curDetail == null || !info.getDetailNumber().equals(curDetail.getNumber())) {
  527. curDetail = new PaperDetail();
  528. curDetail.setName(info.getDetailName());
  529. curDetail.setNumber(info.getDetailNumber());
  530. curDetail.setUnits(new ArrayList<>());
  531. curCard.getStructInfo().add(curDetail);
  532. }
  533. PaperDetailUnit unit = new PaperDetailUnit();
  534. curDetail.getUnits().add(unit);
  535. unit.setNumber(info.getUnitNumber());
  536. unit.setScore(info.getScore());
  537. unit.setScoreStep(info.getScoreStep());
  538. }
  539. for (StructDomain sd : ces) {
  540. setTotalScore(sd);
  541. }
  542. return ces;
  543. }
  544. private void setTotalScore(StructDomain domain) {
  545. double total = 0.0;
  546. for (PaperDetail detial : domain.getStructInfo()) {
  547. for (PaperDetailUnit unit : detial.getUnits()) {
  548. total = Calculator.add(total, unit.getScore(), 1);
  549. }
  550. }
  551. domain.setTotalScore(total);
  552. }
  553. @Override
  554. public List<PaperStructInfoVo> subjectiveList(PaperQuery query, User user) {
  555. if (query.getSchoolId() == null) {
  556. throw new StatusException("学校不能为空");
  557. }
  558. if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(query.getSchoolId())) {
  559. throw new StatusException("没有权限");
  560. }
  561. List<PaperStructInfoVo> ret = this.baseMapper.subjectiveList(query);
  562. if (CollectionUtils.isNotEmpty(ret)) {
  563. }
  564. return ret;
  565. }
  566. }