From 3a8e1524dcf0eeb610d38123d5f0a3ef838379cd Mon Sep 17 00:00:00 2001 From: linzhijie <19970921lzj> Date: 星期一, 12 四月 2021 15:44:53 +0800 Subject: [PATCH] Merge branch '20210406-maqv2' into 20210412-youhua --- src/main/java/com/ots/project/exam/restcontroller/ExamPaperAnswerController.java | 206 +++++++++++++++++---------------------------------- 1 files changed, 69 insertions(+), 137 deletions(-) diff --git a/src/main/java/com/ots/project/exam/restcontroller/ExamPaperAnswerController.java b/src/main/java/com/ots/project/exam/restcontroller/ExamPaperAnswerController.java index 5f5f453..293e36d 100644 --- a/src/main/java/com/ots/project/exam/restcontroller/ExamPaperAnswerController.java +++ b/src/main/java/com/ots/project/exam/restcontroller/ExamPaperAnswerController.java @@ -1,6 +1,4 @@ package com.ots.project.exam.restcontroller; - - import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.ots.common.enums.LangTypeEnum; @@ -28,20 +26,16 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; - import javax.validation.Valid; import java.util.*; import java.util.stream.Collectors; - import static com.ots.common.enums.ReportTypeEnum.Brief; import static com.ots.common.enums.SenderCode.noSend; import static com.ots.common.enums.SenderCode.send; - @RestController("StudentExamPaperAnswerController") @RequestMapping(value = "/api/exam/exampaper/answer") @AllArgsConstructor public class ExamPaperAnswerController extends BaseApiController { - @Autowired private ExamPaperAnswerService examPaperAnswerService; @Autowired @@ -57,53 +51,41 @@ @Autowired private TExamPaperServiceImpl examPaperService; private static final Logger logger = LoggerFactory.getLogger(Threads.class); - - // 绛旈鎻愪氦 + @RequestMapping(value = "/answerSubmit/{tokenId}", method = RequestMethod.POST) public RestResponse answerSubmit(@RequestBody @Valid ExamPaperSubmitVM examPaperSubmitVM, @PathVariable String tokenId) { logger.info("tokenId:" + tokenId); logger.info("itemOrder:" + examPaperSubmitVM.getItemOrder()); - try { - // 1銆佹煡璇㈠嚭鐢ㄦ埛鐨勪俊鎭� + ExamUser user = new ExamUser(); - // testId绛� + RelatedParty relatedParty = memberService.queryProdidByToken(tokenId); - //鍏ヤ汉鍙e鐨勯敭鍊� - // Map<String, String> examInfoMap = getDemographicReport(tokenId, user); - // dataReportList 瀵瑰簲鍩虹鏁版嵁瀵煎嚭content閭d釜瀛楁 + + + List<DataReport> dataReportList = getDemographicDataReport(examPaperSubmitVM, tokenId, user); - - // 3銆佹妸question鍙栧嚭鏉� + Map<Long, QuestionObject> questionObjectMap = getLongQuestionObjectMap(examPaperSubmitVM); - - // 4銆佹祴璇曞寘鍚嶇О銆佷骇鍝佸悕绉般�佹祴璇曞紑濮嬫椂闂淬�佹祴璇曞畬鎴愭椂闂寸殑 - // setReportInfo(examPaperSubmitVM, relatedParty, examInfoMap); + + setReportInfo(examPaperSubmitVM, relatedParty, dataReportList); - examPaperSubmitVM.setInterfaceContentList(new ArrayList<>()); TExamReport tExamReportQuery = new TExamReport(); tExamReportQuery.setTokenId(tokenId); setExamPaperSubTERList(examPaperSubmitVM, tExamReportQuery); - - // 5銆佷繚瀛樿皟鐢ㄦ嘲鍥藉洟闃熺殑鏁版嵁锛岀涓�娈电粨鏉熻皟鐢ㄦ嘲鍥藉洟闃� - // setRemoteCallReport(examPaperSubmitVM, tokenId, relatedParty, dataReportList); - - //6銆佸舰鎴愰鐩�佸洖绛旈�夐」,闇�瑕佹潈闄愮瓑绛� - // setQuestionAndAnswer(examPaperSubmitVM, tokenId, relatedParty, dataReportList, questionObjectMap); - - // 7銆佷笂涓�娆¢�変粈涔� + + + + + Map<String, String> lastContentMap = getLastChioce(examPaperSubmitVM); - - // 8銆佽繖娆¢�変粈涔� + Map<String, String> choiceMap = getThisChioce(examPaperSubmitVM); - - // 9銆佽缃姤琛ㄧ殑鍐呭 + setQuestionReport(examPaperSubmitVM); - - // 10銆侀鐩叆搴� + ExamPaperAnswerInfo examPaperAnswerInfo = answerSubmitResult(examPaperSubmitVM, tokenId, relatedParty, user, dataReportList, lastContentMap, choiceMap); - return RestResponse.ok(examPaperAnswerInfo.getSubmitReport()); } catch (Exception e) { logger.error("{}", e.getMessage(), e); @@ -116,25 +98,21 @@ throw e; } } - private void setExamPaperSubTERList(@RequestBody @Valid ExamPaperSubmitVM examPaperSubmitVM, TExamReport tExamReportQuery) { List<TExamReport> tExamReportList = examReportService.selectTExamReportList(tExamReportQuery); if (ExamUtil.isListEmpty(tExamReportList)) { tExamReportList = new ArrayList<>(); } - examPaperSubmitVM.setTExamReportList(tExamReportList); } - private void setRemoteCallReport(ExamPaperSubmitVM examPaperSubmitVM, @PathVariable String tokenId, RelatedParty relatedParty, List<DataReport> dataReportList) { List<InterfaceContent> interfaceContentList = examPaperSubmitVM.getInterfaceContentList(); if (!StringUtils.equals(examPaperSubmitVM.getIsCallTain(), "callTain")) { - // 瑕佸彇鍘熸潵鐨勬暟鎹� + setInterfaceContent(examPaperSubmitVM, interfaceContentList); return; } - - // 妯℃嫙璋冪敤 + Map<String, String> thaiCalculationMap = new HashMap<>(); MAQReport maqReport = new MAQReport(); maqReport.setQuestionnaireTaker(relatedParty.getMemberName()); @@ -151,7 +129,6 @@ thaiCalculationMap.put("P_Creat02", "80"); ReportResultData resultData = maqReport.getTemplateParameters(thaiCalculationMap, Brief, LangTypeEnum.English); Map<String, String> thaiDataMap = resultData.getTextMap(); - InterfaceContent interfaceContent = new InterfaceContent(); interfaceContent.setPartOrder(examPaperSubmitVM.getPartOrder()); interfaceContent.setDataReportList(new ArrayList<>()); @@ -159,13 +136,10 @@ thaiDataMap.forEach((key, value) -> { iterFDataReportList.add(new DataReport(key, value, UserTypeEnum.SYS_USER.getUserType(), examPaperSubmitVM.getLangType())); }); - - // 鎶婃棫鐨剅eport琛ㄦ暟鎹嬁鍑烘潵 + setInterfaceContent(examPaperSubmitVM, interfaceContentList); - interfaceContentList.add(interfaceContent); } - private void setInterfaceContent(ExamPaperSubmitVM examPaperSubmitVM, List<InterfaceContent> interfaceContentList) { if (ExamUtil.isListNotEmpty(examPaperSubmitVM.getTExamReportList())) { List<InterfaceContent> interfaceContentOldList = null; @@ -176,8 +150,7 @@ } } } - - // 娴嬭瘯鍖呭悕绉般�佷骇鍝佸悕绉般�佹祴璇曞紑濮嬫椂闂淬�佹祴璇曞畬鎴愭椂闂寸殑 + private void setReportInfo(@RequestBody @Valid ExamPaperSubmitVM examPaperSubmitVM, RelatedParty relatedParty, List<DataReport> dataReportList) { dataReportList.add(new DataReport("Test Package", relatedParty.getTestName(), "", examPaperSubmitVM.getLangType())); dataReportList.add(new DataReport("Test", relatedParty.getProdName(), "", examPaperSubmitVM.getLangType())); @@ -187,8 +160,7 @@ dataReportList.add(new DataReport("Begin Time", beginTime, "", examPaperSubmitVM.getLangType())); dataReportList.add(new DataReport("End Time", endTime, "", examPaperSubmitVM.getLangType())); } - - // 杩欐閫変粈涔� + private Map<String, String> getThisChioce(@RequestBody @Valid ExamPaperSubmitVM examPaperSubmitVM) { Map<String, String> choiceMap = new LinkedHashMap<String, String>(); examPaperSubmitVM.getAnswerItems().stream().forEach(it -> { @@ -196,8 +168,7 @@ }); return choiceMap; } - - // 涓婁竴娆¢�変粈涔� + private Map<String, String> getLastChioce(@RequestBody @Valid ExamPaperSubmitVM examPaperSubmitVM) { Map<String, String> lastContentMap = new LinkedHashMap<String, String>(); examPaperSubmitVM.getAnswerItems().stream().forEach(it -> { @@ -205,40 +176,34 @@ }); return lastContentMap; } - - // 4銆佸舰鎴愰鐩�佸洖绛旈�夐」 + private void setQuestionAndAnswer(@RequestBody @Valid ExamPaperSubmitVM examPaperSubmitVM, String tokenId, RelatedParty relatedParty, List<DataReport> dataReportList, Map<Long, QuestionObject> questionObjectMap) { - List<QuestionAnswer> questionAnswers = examPaperSubmitVM.getAnswerItems().stream().map(item -> { - - //棰樺共锛屽洖绛旈」 + QuestionAnswer questionAnswer = new QuestionAnswer(); QuestionObject questionObject = questionObjectMap.get(item.getQuestionId().longValue()); - try { - //1.鍙栭骞� + questionAnswer.setQuestionItem(item.getItemOrder() + "." + ExamUtil.html2Text(questionObject.getTitleContent())); - //2銆佸彇鍥炵瓟鐨勯�夐」 + questionObject.getQuestionItemObjects().stream().forEach(q -> { if (item.getContent().equals(q.getPrefix())) { questionAnswer.setAnswerItem(q.getContent()); } }); - // 3銆侀鐩案涔呯紪鍙� + questionAnswer.setPermanentId(item.getQuestionReport().getPermanentId()); - - // 4銆佹湰棰樼洰鍦ㄩ偅涓�娈� + questionAnswer.setPartOrder(item.getQuestionReport().getPartOrder()); } catch (Exception e) { } return questionAnswer; }).collect(Collectors.toList()); - for (int i = 0; i < questionAnswers.size(); i++) { if (StringUtils.isEmpty(questionAnswers.get(i).getAnswerItem())) { break; } - // 鎻掑叆娉板浗鍥㈤槦杩涙潵鐨勬暟鎹紝閫犳暟鎹紝濡傛灉璺冲埌浜嗕笅涓�娈碉紝閭e氨鎻掑叆娉板浗鍥㈤槦鐨勬暟鎹� + if (i == 0 || questionAnswers.get(i - 1).getPartOrder() != questionAnswers.get(i).getPartOrder()) { if (ExamUtil.isListNotEmpty(examPaperSubmitVM.getInterfaceContentList())) { InterfaceContent interfaceContent = examPaperSubmitVM.getInterfaceContentList().get(0); @@ -248,28 +213,26 @@ dataReportList.add(new DataReport(questionAnswers.get(i).getPermanentId(), questionAnswers.get(i).getAnswerItem(), UserTypeEnum.SYS_USER.getUserType(), examPaperSubmitVM.getLangType())); } } - - // 鎶妐uestion鍙栧嚭鏉� + private Map<Long, QuestionObject> getLongQuestionObjectMap(@RequestBody @Valid ExamPaperSubmitVM examPaperSubmitVM) { List<Long> questionIdList = examPaperSubmitVM.getAnswerItems().stream().map(i -> { return i.getQuestionId().longValue(); }).collect(Collectors.toList()); - //鎶妐uesitonId鍙栧嚭鏉� + List<TQuestion> tQuestionList = questionService.selectTQuestionByIds(questionIdList); - //棰樼洰id锛屾妸棰樺共锛岄�夐」涔嬬被鐨勫唴瀹瑰彇鍑烘潵 + Map<Long, QuestionObject> questionObjectMap = new HashMap<Long, QuestionObject>(); tQuestionList.stream().forEach(it -> { questionObjectMap.put(it.getId(), JSONObject.parseObject(it.getContent(), QuestionObject.class)); }); return questionObjectMap; } - - //鍏ヤ汉鍙e鐨勯敭鍊� + private Map<String, String> getDemographicReport(@PathVariable String tokenId, ExamUser user) { Map<String, String> examInfoMap = new LinkedHashMap<String, String>(); try { List<EntDemographyInfo> entDemographyInfoList = memberService.queryDemographyParamInfo(tokenId); - //2銆佽幏鍙栫敤鎴风殑鍊� + EntDemographyInfo entDemographyInfo = entDemographyInfoList.get(0); user.setId(entDemographyInfo.getMemberId().intValue()); entDemographyInfoList.stream().forEach(item -> examInfoMap.put(item.getParamName(), item.getParamValue())); @@ -279,13 +242,12 @@ } return examInfoMap; } - - //鍏ヤ汉鍙e鐨勯敭鍊� + private List<DataReport> getDemographicDataReport(ExamPaperSubmitVM examPaperSubmitVM, @PathVariable String tokenId, ExamUser user) { List<DataReport> dataReportList = new ArrayList<>(); try { List<EntDemographyInfo> entDemographyInfoList = memberService.queryDemographyParamInfo(tokenId); - //2銆佽幏鍙栫敤鎴风殑鍊� + EntDemographyInfo entDemographyInfo = entDemographyInfoList.get(0); user.setId(entDemographyInfo.getMemberId().intValue()); entDemographyInfoList.stream().forEach(item -> { @@ -297,11 +259,10 @@ } return dataReportList; } - private void setQuestionReport(@RequestBody @Valid ExamPaperSubmitVM examPaperSubmitVM) { List<ExamPaperTitleItemVM> titleItems = examPaperSubmitVM.getTitleItems(); List<ExamPaperSubmitItemVM> anserItems = examPaperSubmitVM.getAnswerItems(); - // 浜烘牸娴嬭瘯棰橈紝鍙湁涓�娈电殑 + if (Objects.isNull(titleItems)) { if (Objects.isNull(anserItems)) { return; @@ -311,23 +272,22 @@ questionReport.setId(questionReport.getQuestionOrder() + 1); questionReport.setTimeSpent(ExamUtil.timeSpent(DateTimeUtil.parseToOften(questionReport.getStartTime()), DateTimeUtil.parseToOften(questionReport.getEndTime()))); } - // else 宸ヤ綔闂嵎娴嬭瘯棰� + } else { for (ExamPaperTitleItemVM examPaperTitleItemVM : titleItems) { - // 璁板綍JAQ灏忛 + QuestionReport questionReport = examPaperTitleItemVM.getQuestionReport(); questionReport.setId(questionReport.getQuestionOrder() + 1); questionReport.setTimeSpent(ExamUtil.timeSpent(DateTimeUtil.parseToOften(questionReport.getStartTime()), DateTimeUtil.parseToOften(questionReport.getEndTime()))); } } } - private ExamPaperAnswerInfo answerSubmitResult(@RequestBody @Valid ExamPaperSubmitVM examPaperSubmitVM, @PathVariable String tokenId, RelatedParty relatedParty, ExamUser user, List<DataReport> dataReportList, Map<String, String> lastContentMap, Map<String, String> choiceMap) { TExamReport tExamReport = new TExamReport(); TExamReport tExamReportQuery = new TExamReport(); tExamReport.setContent(JSON.toJSON(dataReportList).toString()); tExamReport.setProductId(examPaperSubmitVM.getId().longValue()); - tExamReport.setQuestionReport(getQuestionReportsJson(examPaperSubmitVM));// 鎶ュ憡瀛楁 + tExamReport.setQuestionReport(getQuestionReportsJson(examPaperSubmitVM)); ExamPaperAnswerInfo examPaperAnswerInfo = examPaperAnswerService.calculateExamPaperAnswer(examPaperSubmitVM, user); TExamPaper examPaper = examPaperAnswerInfo.getExamPaper(); tExamReport.setProductName(examPaper.getName()); @@ -337,125 +297,100 @@ tExamReport.setChoice(JSON.toJSON(choiceMap).toString()); tExamReport.setDoTime(examPaperSubmitVM.getDoTime()); tExamReport.setLangType(examPaperSubmitVM.getLangType()); - // 鏄惁鑷姩鍙戦�佺姸鎬佹姤鍛� + setAutoSendReportStatus(relatedParty, tExamReport); BeanUtils.copyBeanProp(tExamReportQuery, tExamReport); - tExamReportQuery.setProductId(null); tExamReportQuery.setProductName(null); List<TExamReport> tExamReportList = examPaperSubmitVM.getTExamReportList(); - // ExamPaperAnswer examPaperAnswer = examPaperAnswerInfo.getExamPaperAnswer(); - // questionCount 鍋氶鏁扮洰 + + tExamReport.setQuestionCount(0); - //member_id + tExamReport.setMemberId(relatedParty.getMemberId().intValue()); - // user_id + tExamReport.setUserId(relatedParty.getUser_id()); - // parent_id + tExamReport.setParentId(relatedParty.getUser_parent_id()); - // test_id + tExamReport.setTestId(relatedParty.getTestId()); - // finish + tExamReport.setFinish(examPaperSubmitVM.getFinish()); //鏇存柊鐢ㄦ埛绛旈鐘舵�� setVerifyStatus(examPaperSubmitVM, tExamReport); - - // questionTemplateId + tExamReport.setQuestionTemplateId(relatedParty.getQuestionTemplateId()); - - // 闅忔満棰樼洰缂栧彿 + tExamReport.setQuestionOrder(JSON.toJSONString(examPaperSubmitVM.getQuestionOrder())); - - // 闅忔満鐨勯�夐」缂栧彿 + tExamReport.setOptionOrder(JSON.toJSONString(examPaperSubmitVM.getOptionOrder())); - - // 璁剧疆鎴愬憳鍚嶇О + tExamReport.setMemberName(relatedParty.getMemberName()); - - // 妯$増鍚嶇О + tExamReport.setReportTemplateId(relatedParty.getReportTemplateId()); - - // tExamReport - - // 鐢ㄦ埛绛旈鐨勬椂闂� + + setRemainPartTime(examPaperSubmitVM, tExamReport, tExamReportList); - - // 鏇存柊鎶ュ憡 + updateTExamReport(examPaperSubmitVM, tokenId, relatedParty, tExamReport, tExamReportList); - - // 璋冪敤娉板浗鍥㈤槦 + callThaiInteface(examPaperSubmitVM, tokenId, tExamReport, examPaperAnswerInfo); return examPaperAnswerInfo; } - private void updateTExamReport(@RequestBody @Valid ExamPaperSubmitVM examPaperSubmitVM, @PathVariable String tokenId, RelatedParty relatedParty, TExamReport tExamReport, List<TExamReport> tExamReportList) { - // 寮�濮嬫椂闂存病鏈夋洿鏂板氨鏇存柊涓�涓� + if (Objects.isNull(relatedParty.getStartTime())) { entTestMemberService.updateTestMemberStatus(TestMemberStatusEnum.answering, memberService.queryProdidByToken(tokenId).getMemberId()); } - if (tExamReportList.size() > 0) { - // 鏇存柊鏈鐨勭瓟棰樻椂闂达紝鍏堟妸鍘熸潵鐨勬璇诲嚭鏉� + examReportService.updateTExamReportByTokenId(tExamReport); } else { examReportService.insertTExamReport(tExamReport); } - - //鏇存柊娴嬭瘯鍖呯殑鐘舵�� + if (!Objects.isNull(examPaperSubmitVM.getFinish())) { - - // 鏍¢獙姣忎竴棰樻槸鍚﹂兘绛斾簡锛屾病鏈夋剰涔夛紝鍥犱负鏈夌殑浜轰細鎻愪氦绌虹殑绛旈璁板綍涓婃潵 + checkCaqQuestionItem(tExamReport); - - // MAQ 鏈夌瓟瀹屼笉鏀圭姸鎬佺殑鎯呭喌 + TestMemberStatusEnum testMemberStatusEnum = TestMemberStatusEnum.codeOf(examPaperSubmitVM.getFinish().toString()); if (Objects.equals(Integer.parseInt(TestMemberStatusEnum.completed.getCode()), tExamReport.getVerifyStatus())) { testMemberStatusEnum = TestMemberStatusEnum.completed; } - entTestMemberService.updateTestMemberStatus(testMemberStatusEnum, tExamReport.getMemberId()); } } - private void checkCaqQuestionItem(TExamReport tExamReport) { if (!Objects.equals(tExamReport.getQuestionTemplateId(), "job")) { return; } - List<QuestionReport> questionReportList = JsonUtil.parseArray(tExamReport.getQuestionReport(), QuestionReport.class); for (QuestionReport questionReport : questionReportList) { -// questionReport = null; // 娴嬭瘯鐢� + List<QuestionEditRequestVM> questionItems = questionReport.getQuestionItems(); } - } - private void setVerifyStatus(@RequestBody @Valid ExamPaperSubmitVM examPaperSubmitVM, TExamReport tExamReport) { if (Objects.equals(examPaperSubmitVM.getFinish(), 6)) { tExamReport.setVerifyStatus(Integer.parseInt(TestMemberStatusEnum.timeOut.getCode())); } else { - // 鏇存柊鐢ㄦ埛鐨勭瓟棰樼姸鎬� + tExamReport.setVerifyStatus(examPaperSubmitVM.getVerifyStatus()); } } - private void setRemainPartTime(@RequestBody @Valid ExamPaperSubmitVM examPaperSubmitVM, TExamReport tExamReport, List<TExamReport> tExamReportList) { if (Objects.isNull(examPaperSubmitVM.getRemainTime())) { return; } - Map<Integer, Integer> remainPartTimeMap = null; - if (tExamReportList.size() > 0) { remainPartTimeMap = JsonUtil.parseObject(tExamReportList.get(0).getRemainPartTime(), HashMap.class); } else { remainPartTimeMap = new HashMap<>(); } - remainPartTimeMap.put(examPaperSubmitVM.getPartOrder(), examPaperSubmitVM.getRemainTime()); tExamReport.setRemainPartTime(JsonUtil.toJSONString(remainPartTimeMap)); } - private void callThaiInteface(ExamPaperSubmitVM examPaperSubmitVM, @PathVariable String tokenId, TExamReport tExamReport, ExamPaperAnswerInfo examPaperAnswerInfo) { if (Objects.equals(examPaperSubmitVM.getIsCallTain(), "CallThai")) { SignalObject signalObject = examPaperService.callTaiData(tokenId, tExamReport.getLangType(), examPaperSubmitVM); @@ -463,10 +398,9 @@ submitReport.setSignalObject(signalObject); } } - - // 鑷姩鍙戦�佺姸鎬佹姤鍛婇渶瑕佸鐞嗙殑鍐呭 + private void setAutoSendReportStatus(RelatedParty relatedParty, TExamReport tExamReport) { - // 0锛氬緟鍙戦�侊紱1锛氬凡鍙戦�侊紱2锛氫笉鍙戦�� + if (relatedParty.isAutoSendReport()) { tExamReport.setSendHrStatus(send.getCode()); tExamReport.setSendTesterStatus(send.getCode()); @@ -476,8 +410,7 @@ tExamReport.setSendTesterStatus(noSend.getCode()); } } - - // 鑾峰緱QuestionReport鍒楄〃鐨凧son瀛楃涓插叆t_exam_roport琛� + private String getQuestionReportsJson(@RequestBody @Valid ExamPaperSubmitVM examPaperSubmitVM) { List<ExamPaperTitleItemVM> titleItems = examPaperSubmitVM.getTitleItems(); List<ExamPaperSubmitItemVM> answerItems = examPaperSubmitVM.getAnswerItems(); @@ -496,8 +429,7 @@ } return JsonUtil.toJsonStr(questionReportList); } - - // 鐐瑰嚮寮�濮嬬瓟棰樼殑鏃跺�欙紝鏀规垚绛旈涓紝浠呮墽琛屼竴娆� + @RequestMapping(value = "/updateTestMemberStatus/{tokenId}", method = RequestMethod.POST) public RestResponse updateTestMemberStatus(@PathVariable String tokenId) { entTestMemberService.updateTestMemberStatus(TestMemberStatusEnum.answering, memberService.queryProdidByToken(tokenId).getMemberId()); -- Gitblit v1.9.1