From 5e873863bc7324894c89b0a0fc77a6202c91cd64 Mon Sep 17 00:00:00 2001 From: wzp <516075396@qq.com> Date: 星期二, 06 四月 2021 10:35:42 +0800 Subject: [PATCH] 20210406 --- src/main/java/com/ots/project/exam/controller/TQuestionController.java | 110 ++++++++++++------------------------------------------- 1 files changed, 24 insertions(+), 86 deletions(-) diff --git a/src/main/java/com/ots/project/exam/controller/TQuestionController.java b/src/main/java/com/ots/project/exam/controller/TQuestionController.java index e0f66aa..871d918 100644 --- a/src/main/java/com/ots/project/exam/controller/TQuestionController.java +++ b/src/main/java/com/ots/project/exam/controller/TQuestionController.java @@ -1,5 +1,4 @@ package com.ots.project.exam.controller; - import com.alibaba.fastjson.JSONObject; import com.ots.common.utils.MessageUtils; import com.ots.common.utils.StringUtils; @@ -34,53 +33,35 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; - import static com.ots.common.enums.ExamPaperQuestion.permanentIdDuplicate; -/** - * 棰樼洰鍒楄〃Controller - * - * @author Shawn - * @date 2019-11-20 - */ @Controller @RequestMapping("/exam/question") public class TQuestionController extends BaseController { private static final Logger log = LoggerFactory.getLogger(TQuestionController.class); private String prefix = "exam/question"; - @Autowired private ITQuestionService tQuestionService; - @Autowired private ITSubjectService subjectService; - @Autowired private ITExamLevelService itExamLevelService; - @Autowired private IDictDataService dictDataService; - @Autowired private DictService dictService; - - @RequiresPermissions("exam:question:view") @GetMapping() public String question() { return prefix + "/question"; } - - /** - * 鏌ヨ棰樼洰鍒楄〃鍒楄〃 - */ + @RequiresPermissions("exam:question:list") @PostMapping("/list") @ResponseBody @@ -89,11 +70,7 @@ List<TQuestion> list = tQuestionService.selectTQuestionList(tQuestion); return getDataTable(list); } - - - /** - * 涓撻棬涓簆roduct鐨刟dd_question.html 椤甸潰鎻愪緵鏌ヨ - */ + @RequiresPermissions("exam:question:list") @PostMapping("/listForProductAddQuestion") @ResponseBody @@ -105,30 +82,20 @@ List<TQuestion> list = tQuestionService.selectTQuestionsForProductAddQuestion(tQuestion); return getDataTable(list); } - - /** - * 鏂板棰樼洰鍒楄〃 - * 鍙傛暟 id鏄� t_subject 琛ㄧ殑id - */ + @GetMapping("/add/{id}") public String add(@PathVariable("id") Long id, ModelMap mmap) { - // 杩欏彞浠g爜涓轰簡鎻愮ず浼犺繃鏉ョ殑id鏄痩evelid - /* - * 鍘绘帀棰樼洰缁村害t_subject鍚庡彧鏌ヨt_exam_level 琛紝寰楀埌瀛楀吀閲岄潰鐨�3绫婚棶鍗锋ā鏉匡紝鍒嗗埆璺宠浆鍒�3涓笉鍚岀殑妯℃澘椤甸潰锛屽垎鍒槸 - * add-job.html,add-personality.html,add-intelligence.html - */ - // 杩欏彞浠g爜涓轰簡鎻愮ず浼犺繃鏉ョ殑id鏄痩evelId + + + Long levelId = id; TExamLevel tExamLevel = itExamLevelService.selectTExamLevelById(levelId); - // 璇█閫夐」鏄剧ず褰撳墠鍥介檯鍖栫殑閭g + mmap.put("tExamLevel", tExamLevel); mmap.put("langType", dictService.getLangType(LocaleContextHolder.getLocale().toString())); return prefix + "/add-" + tExamLevel.getQuestionTemplateId(); } - - /** - * 鏂板淇濆瓨棰樼洰鍒楄〃 - */ + @RequiresPermissions("exam:question:add") @Log(title = "棰樼洰鍒楄〃", businessType = BusinessType.INSERT) @PostMapping("/add") @@ -140,10 +107,7 @@ } return toAjax(resultNum); } - - /** - * 淇敼棰樼洰鍒楄〃 - */ + @GetMapping("/edit/{id}") public String edit(@PathVariable("id") Long id, ModelMap mmap) { TQuestion tQuestion = tQuestionService.selectTQuestionById(id); @@ -153,45 +117,35 @@ tQuestion.setLangName(lanTypeMap.get(tQuestion.getLangType())); return prefix + "/edit-" + tExamLevel.getQuestionTemplateId(); } - private TExamLevel getEditQuestion(ModelMap mmap, TQuestion tQuestion) { QuestionObject questionObject = JSONObject.parseObject(tQuestion.getContent(), QuestionObject.class); - if (ExamUtil.isListNotEmpty(questionObject.getQuestionItemObjects())) { setChioceAndSelectInput(tQuestion, questionObject); } - tQuestion.setAnalyze(questionObject.getAnalyze()); - // 澶氳瑷�鐗堟湰 + Map<String, String> titleMap = JsonUtil.toJsonObject(questionObject.getTitleContent(), HashMap.class); tQuestion.setTitle(titleMap.get(tQuestion.getLangType())); - TExamLevel tExamLevel = itExamLevelService.selectTExamLevelById(tQuestion.getLevelId()); mmap.put("tExamLevel", tExamLevel); mmap.put("tQuestion", tQuestion); return tExamLevel; } - private void setChioceAndSelectInput(TQuestion tQuestion, QuestionObject questionObject) { - //閫夐」鐨勭涓�涓緭鍏ユ鐨勫唴瀹� + List<String> choiceInputList = questionObject.getQuestionItemObjects().stream().map(i -> { return i.getPrefix(); }).collect(Collectors.toList()); - - //閫夐」鐨勭浜屼釜杈撳叆妗嗙殑鍐呭 + List<String> selectInput = questionObject.getQuestionItemObjects().stream().map(i -> { - // 澶氳瑷�鐗堟湰灞曠ず + Map<String, String> content = JsonUtil.toJsonObject(i.getContent(), HashMap.class); return content.get(tQuestion.getLangType()); }).collect(Collectors.toList()); - tQuestion.setChoiceInput(choiceInputList); tQuestion.setSelectInput(selectInput); } - - /** - * 淇敼淇濆瓨棰樼洰鍒楄〃 - */ + @RequiresPermissions("exam:question:edit") @Log(title = "棰樼洰鍒楄〃", businessType = BusinessType.UPDATE) @PostMapping("/edit") @@ -199,10 +153,7 @@ public AjaxResult editSave(TQuestion tQuestion) { return toAjax(tQuestionService.updateTQuestion(tQuestion)); } - - /** - * 鍒犻櫎棰樼洰鍒楄〃 - */ + @RequiresPermissions("exam:question:remove") @Log(title = "棰樼洰鍒楄〃", businessType = BusinessType.DELETE) @PostMapping("/remove") @@ -210,10 +161,7 @@ public AjaxResult remove(String ids) { return toAjax(tQuestionService.deleteTQuestionByIds(ids)); } - - /** - * 鎵归噺瀵煎叆娴嬭瘯浜哄憳鍚嶅崟 - */ + @RequiresPermissions("enterprise:question:import") @PostMapping("/importData") @ResponseBody @@ -226,11 +174,7 @@ String message = tQuestionService.insertImportQuestion(excelList); return AjaxResult.success(message); } - - - /** - * 鎵归噺瀵煎叆娴嬭瘯浜哄憳鍚嶅崟妯℃澘涓嬭浇 - */ + @RequiresPermissions("enterprise:question:view") @GetMapping("/importTemplate") @ResponseBody @@ -238,18 +182,16 @@ ExcelUtil<QuestionJobImport> util = new ExcelUtil<QuestionJobImport>(QuestionJobImport.class); return util.importTemplateExcel("棰樼洰妯$増"); } - @GetMapping("/addLang/{uuid}") public String addLang(@PathVariable("uuid") Long uuid, ModelMap mmap) { - // 澶氳瑷�鐨勬椂鍊檜uid灏辨槸id + TQuestion tQuestion = tQuestionService.selectTQuestionById(uuid); tQuestion.setUuid(uuid); TExamLevel tExamLevel = getEditQuestion(mmap, tQuestion); - - // 璋冪敤鐨勬槸淇敼椤甸潰杩涜淇敼锛屾墍浠ヤ笉闇�瑕佸~鍐欎富瑕佺殑閫夐」 + tQuestion.setTitle(""); List<String> selectInputList = tQuestion.getSelectInput(); - // job宸ヤ綔鍒嗘瀽闂嵎娌℃湁input + if (ExamUtil.isListNotEmpty(selectInputList)) { List<String> selectInputs = new ArrayList<>(); for (String selectInput : selectInputList) { @@ -259,15 +201,12 @@ } return prefix + "/edit-" + tExamLevel.getQuestionTemplateId(); } - - /** - * 鏍规嵁璇█淇敼棰樼洰, 椤甸潰涓婄殑鏂板璇█璋冪敤 - */ + @GetMapping("/editLang/{uuid}/{langType}") public String editLang(@PathVariable("uuid") Long uuid, @PathVariable("langType") String langType,ModelMap mmap) { - // 澶氳瑷�鐨勬椂鍊檜uid灏辨槸id + TQuestion tQuestion = tQuestionService.selectTQuestionById(uuid); - // 澶氳瑷�鐗堟湰 + tQuestion.setUuid(uuid); tQuestion.setLangType(langType); TExamLevel tExamLevel = getEditQuestion(mmap, tQuestion); @@ -276,11 +215,10 @@ tQuestion.setLangName(lanTypeMap.get(langType)); return prefix + "/edit-" + tExamLevel.getQuestionTemplateId(); } - @GetMapping("/deleteLang/{uuid}/{langType}") @ResponseBody public AjaxResult deleteLang(@PathVariable("uuid") Long uuid, @PathVariable("langType") String langType) { - // 澶氳瑷�鐨勬椂鍊檜uid灏辨槸id + TQuestion tQuestion = tQuestionService.selectTQuestionById(uuid); tQuestion.setLangType(langType); return toAjax(tQuestionService.deleteQuestionContent(tQuestion)); -- Gitblit v1.9.1