| | |
| | | package com.ots.project.exam.controller; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.ots.common.utils.StringUtils; |
| | | import com.ots.common.utils.bean.BeanUtils; |
| | |
| | | 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.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 产品包列表Controller |
| | | * |
| | | * @author ots |
| | | * @date 2019-11-20 |
| | | */ |
| | | @Controller |
| | | @RequestMapping("/exam/product") |
| | | public class TExamPaperController extends BaseController { |
| | | private String prefix = "exam/product"; |
| | | |
| | | @Autowired |
| | | private ITExamPaperService tExamPaperService; |
| | | |
| | | @Autowired |
| | | private ITTextContentService tTextContentService; |
| | | |
| | | @Autowired |
| | | private ITExamLevelService itExamLevelService; |
| | | |
| | | @Autowired |
| | | private IDictDataService dictDataService; |
| | | |
| | | @Autowired |
| | | private IExamUtilService examUtilService; |
| | | |
| | | @Autowired |
| | | private ITReportTemplateService reportTemplateService; |
| | | |
| | | protected final static ModelMapper modelMapper = ModelMapperSingle.Instance(); |
| | | |
| | | @RequiresPermissions("exam:product:view") |
| | | @GetMapping() |
| | | public String product() { |
| | | return prefix + "/product"; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 查询产品包列表列表 |
| | | */ |
| | | @RequiresPermissions("exam:product:list") |
| | | @PostMapping("/list") |
| | | @ResponseBody |
| | |
| | | List<TExamPaper> list = tExamPaperService.selectTExamPaperList(tExamPaper); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 导出产品包列表列表 |
| | | */ |
| | | @RequiresPermissions("exam:product:export") |
| | | @PostMapping("/export") |
| | | @ResponseBody |
| | |
| | | ExcelUtil<TExamPaper> util = new ExcelUtil<TExamPaper>(TExamPaper.class); |
| | | return util.exportExcel(list, "product"); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 新增产品包列表 |
| | | */ |
| | | @GetMapping("/add/{id}") |
| | | public String add(@PathVariable("id") Long id, ModelMap mmap) { |
| | | |
| | | // 这句代码为了提示传过来的id是levelId |
| | | Long levelId = id; |
| | | TExamLevel tExamLevel = itExamLevelService.selectTExamLevelById(levelId); |
| | | mmap.put("tExamLevel", tExamLevel); |
| | | mmap.put("templateList", reportTemplateService.getReportTemplates(ShiroUtils.getSysUser())); |
| | | return prefix + "/add-" + tExamLevel.getQuestionTemplateId(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 新增保存产品包列表 |
| | | */ |
| | | @RequiresPermissions("exam:product:add") |
| | | @Log(title = "产品包列表", businessType = BusinessType.INSERT) |
| | | @PostMapping("/add") |
| | |
| | | public AjaxResult addSave(TExamPaper tExamPaper) { |
| | | return toAjax(tExamPaperService.insertTExamPaper(tExamPaper)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 修改产品包列表 |
| | | */ |
| | | @GetMapping("/edit/{id}") |
| | | public String edit(@PathVariable("id") Long id, ModelMap mmap) { |
| | | TExamPaper tExamPaper = tExamPaperService.selectTExamPaperById(id); |
| | | |
| | | //获取题目的内容展示 |
| | | List<ExamPaperTitleItem> examPaperTitleItemList = tExamPaperService.getExamPaperTitleContent(tExamPaper); |
| | | mmap.put("examPaperTitleItemList", examPaperTitleItemList); |
| | | mmap.put("templateList", reportTemplateService.getReportTemplates(ShiroUtils.getSysUser())); |
| | | mmap.put("tExamPaper", tExamPaper); |
| | | |
| | | // 跳到具体的页面 |
| | | TExamLevel tExamLevel = itExamLevelService.selectTExamLevelById(tExamPaper.getLevelId()); |
| | | mmap.put("tExamLevel", tExamLevel); |
| | | return prefix + "/edit-" + tExamLevel.getQuestionTemplateId(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 修改保存产品包列表 |
| | | */ |
| | | @RequiresPermissions("exam:product:edit") |
| | | @Log(title = "产品包列表", businessType = BusinessType.UPDATE) |
| | | @PostMapping("/edit") |
| | |
| | | public AjaxResult editSave(TExamPaper tExamPaper) { |
| | | return toAjax(tExamPaperService.updateTExamPaper(tExamPaper)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 删除产品包列表 |
| | | */ |
| | | @RequiresPermissions("exam:product:remove") |
| | | @Log(title = "产品包列表", businessType = BusinessType.DELETE) |
| | | @PostMapping("/remove") |
| | |
| | | public AjaxResult remove(String ids) { |
| | | return toAjax(tExamPaperService.deleteTExamPaperByIds(ids)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 选题目,ABCD的题目 |
| | | */ |
| | | @GetMapping("/addQuestion/{levelId}/{langType}") |
| | | public String addQuestion(@PathVariable("levelId") Long levelId, @PathVariable("langType") String langType, ModelMap mmap) { |
| | | mmap.put("level", levelId); |
| | | mmap.put("langType", langType); |
| | | return prefix + "/add_question"; |
| | | } |
| | | |
| | | @GetMapping("/addIntelligenceTitleQuestion/{levelId}/{langType}") |
| | | public String addIntelligenceTitleQuestion(@PathVariable("levelId") Long levelId, @PathVariable("langType") String langType, ModelMap mmap) { |
| | | mmap.put("level", levelId); |
| | |
| | | mmap.put("template", "intelligence_title"); |
| | | return prefix + "/add_question"; |
| | | } |
| | | |
| | | @GetMapping("/addIntelligenceQuestion/{levelId}/{langType}") |
| | | public String addIntelligenceQuestion(@PathVariable("levelId") Long levelId, @PathVariable("langType") String langType, ModelMap mmap) { |
| | | mmap.put("level", levelId); |
| | |
| | | mmap.put("template", "intelligence"); |
| | | return prefix + "/add_question"; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 选题目,ABCD的题目 |
| | | */ |
| | | @GetMapping("/addTitle/{questionTemplateId}/{langType}") |
| | | public String addTitle(@PathVariable("questionTemplateId") String questionTemplateId, @PathVariable("langType") String langType, ModelMap mmap) { |
| | | mmap.put("questionTemplateId", questionTemplateId); |
| | | mmap.put("langType", langType); |
| | | return prefix + "/add_title"; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 新增测试包管理 |
| | | */ |
| | | @GetMapping("/getProdList") |
| | | public String getProdList(String langType,String testType,ModelMap mmap) { |
| | | mmap.put("langType", langType); |
| | | mmap.put("testType", testType); |
| | | return prefix + "/prodtree"; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 加载字典列表树 |
| | | */ |
| | | @GetMapping("/treeData/{langType}/{testType}") |
| | | @ResponseBody |
| | | public List<Ztree> treeData(@PathVariable("langType") String langType,@PathVariable("testType") String testType) { |
| | | System.out.println(langType); |
| | | List<Ztree> ztrees = tExamPaperService.selectProdTree(testType); |
| | | |
| | | // 多语言翻译 |
| | | ztrees.stream().forEach(ztree -> { |
| | | ztree.setName(ExamUtil.getLangString(langType, ztree.getName())); |
| | | }); |
| | | return ztrees; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 批量导入测试人员名单 |
| | | */ |
| | | @RequiresPermissions("exam:product:import") |
| | | @PostMapping("/importJobData/{langType}/{levelId}/{levelName}") |
| | | @ResponseBody |
| | | public AjaxResult importJobData(MultipartFile file, @PathVariable("langType") String langType, @PathVariable("levelId") Long levelId, @PathVariable("levelName") String leveltName, boolean updateSupport) throws Exception { |
| | | ExcelUtil<QuestionJobImport> util = new ExcelUtil<>(QuestionJobImport.class); |
| | | QuestionJobImport questionJobImport = util.importJobExcel(file.getInputStream(),levelId, leveltName, langType); |
| | | |
| | | List<TQuestion> questionList = questionJobImport.getQuestionList(); |
| | | |
| | | |
| | | // 大题目要job_title |
| | | for (TQuestion tQuestion : questionList) { |
| | | tQuestion.setTemplate("job_title"); |
| | | } |
| | | |
| | | |
| | | // 翻译多语言 |
| | | // 更新、入库逻辑, 多语言 |
| | | updateBatchImportData(langType, JsonUtil.toJsonStr(questionJobImport.getMultilingualList()), questionList); |
| | | |
| | | if (StringUtils.isEmpty(questionJobImport.getLangType())) { |
| | | return AjaxResult.success(questionJobImport); |
| | | } |
| | | |
| | | if (Objects.isNull(questionJobImport) || Objects.isNull(questionJobImport.getQuestionList()) || questionJobImport.getQuestionList().isEmpty()) { |
| | | return AjaxResult.error("导入失败"); |
| | | } |
| | | |
| | | |
| | | // 翻译多语言 |
| | | return AjaxResult.success(questionJobImport); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 批量导入测试人员名单模板下载 |
| | | */ |
| | | @RequiresPermissions("exam:product:view") |
| | | @GetMapping("/importTemplate") |
| | | @ResponseBody |
| | |
| | | ExcelUtil<QuestionJobImport> util = new ExcelUtil<>(QuestionJobImport.class); |
| | | return util.importTemplateQuestionExcel("JAQ题目模板.xlsx"); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 批量导入测试人员名单模板下载 |
| | | */ |
| | | @RequiresPermissions("exam:product:view") |
| | | @GetMapping("/importMAQTemplate") |
| | | @ResponseBody |
| | |
| | | ExcelUtil<QuestionPersonalityImport> util = new ExcelUtil<>(QuestionPersonalityImport.class); |
| | | return util.importTemplateQuestionExcel("MAQ题目模板.xlsx"); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 批量导入测试人员名单 |
| | | */ |
| | | @RequiresPermissions("exam:product:import") |
| | | @PostMapping("/importMAQData/{langType}") |
| | | @ResponseBody |
| | |
| | | if (StringUtils.isEmpty(questionPersonalityImport.getLangType())) { |
| | | return AjaxResult.success(questionPersonalityImport); |
| | | } |
| | | |
| | | List<TQuestion> questionList = questionPersonalityImport.getQuestionList(); |
| | | |
| | | |
| | | // 校验有效性 |
| | | if (Objects.isNull(questionPersonalityImport) || Objects.isNull(questionList) || questionList.isEmpty()) { |
| | | return AjaxResult.error("导入失败"); |
| | | } |
| | | |
| | | // 更新、入库逻辑, 多语言 |
| | | updateBatchImportData(langType, JsonUtil.toJsonStr(questionPersonalityImport.getMultilingualList()), questionList); |
| | | |
| | | return AjaxResult.success(questionPersonalityImport); |
| | | } |
| | | |
| | | |
| | | // 更新、入库逻辑, 多语言 |
| | | private void updateBatchImportData(@PathVariable String langType, String multilinguag, List<TQuestion> questionList) { |
| | | tExamPaperService.updateInsertQuestion(questionList, multilinguag); |
| | | |
| | | for (TQuestion tQuestion : questionList) { |
| | | tQuestion.setTitle(examUtilService.getLangOrLocalLangString(langType, tQuestion.getTitle())); |
| | | List<String> selectInput = tQuestion.getSelectInput(); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 批量导入测试人员名单模板下载 |
| | | */ |
| | | @RequiresPermissions("exam:product:changeDeleted") |
| | | @PostMapping("/changeDeleted") |
| | | @ResponseBody |
| | | public AjaxResult changeDeleted(TExamPaper tExamPaper) { |
| | | return toAjax(tExamPaperService.updateDeleted(tExamPaper)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 产品包新增语言入口,产品包多语言添加入口 |
| | | * @param uuid |
| | | * @param mmap |
| | | * @return |
| | | */ |
| | | @GetMapping("/addLang/{uuid}/{langType}") |
| | | public String addLang(@PathVariable("uuid") Long uuid, @PathVariable("langType") String langType, ModelMap mmap) { |
| | | TExamPaper tExamPaper = tExamPaperService.selectTExamPaperById(uuid); |
| | |
| | | tExamPaper.setLangName(getDitcByType("lang_type", langType)); |
| | | tExamPaper.setUuid(uuid); |
| | | tExamPaper.setOperatingLanguage("addLang"); |
| | | |
| | | |
| | | //获取题目的内容展示 |
| | | List<ExamPaperTitleItem> examPaperTitleItemList = getExamPaperTitleItems(mmap, tExamPaper); |
| | | |
| | | mmap.put("templateList", reportTemplateService.getReportTemplates(ShiroUtils.getSysUser())); |
| | | mmap.put("tExamPaper", tExamPaper); |
| | | |
| | | // 跳到具体的页面 |
| | | TExamLevel tExamLevel = itExamLevelService.selectTExamLevelById(tExamPaper.getLevelId()); |
| | | mmap.put("tExamLevel", tExamLevel); |
| | | |
| | | // 批量导入的时候展示题目的维度,Job才需要,维度都是一样的 |
| | | nmapPutQuestionItem(mmap, examPaperTitleItemList); |
| | | |
| | | // 多语言清理数据 |
| | | tExamPaper.setName(""); |
| | | tExamPaper.setGuide(""); |
| | | |
| | | return prefix + "/edit-" + tExamLevel.getQuestionTemplateId(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据语言修改题目, 页面上的新增语言调用,产品包修改多语言题目入口 |
| | | */ |
| | | @GetMapping("/editLang/{uuid}/{langType}") |
| | | public String editLang(@PathVariable("uuid") Long uuid, @PathVariable("langType") String langType, ModelMap mmap) { |
| | | TExamPaper tExamPaper = tExamPaperService.selectTExamPaperById(uuid); |
| | |
| | | tExamPaper.setId(uuid); |
| | | tExamPaper.setLangType(langType); |
| | | tExamPaper.setOperatingLanguage("editLang"); |
| | | |
| | | |
| | | // 多语言 |
| | | tExamPaper.setName(ExamUtil.getStringByLang(tExamPaper.getLangType(), tExamPaper.getName())); |
| | | |
| | | tExamPaper.setGuide(ExamUtil.getStringByLang(tExamPaper.getLangType(), tExamPaper.getGuide())); |
| | | |
| | | tExamPaper.setLangName(getDitcByType("lang_type", langType)); |
| | | List<ExamPaperTitleItem> examPaperTitleItemList = getExamPaperTitleItems(mmap, tExamPaper); |
| | | |
| | | |
| | | // 批量导入的时候展示题目的维度,Job才需要,维度都是一样的 |
| | | nmapPutQuestionItem(mmap, examPaperTitleItemList); |
| | | |
| | | |
| | | // 多语言 |
| | | mmap.put("tExamPaper", tExamPaper); |
| | | mmap.put("templateList", reportTemplateService.getReportTemplates(ShiroUtils.getSysUser())); |
| | | |
| | | // 跳到具体的页面 |
| | | TExamLevel tExamLevel = itExamLevelService.selectTExamLevelById(tExamPaper.getLevelId()); |
| | | mmap.put("tExamLevel", tExamLevel); |
| | | |
| | | return prefix + "/edit-" + tExamLevel.getQuestionTemplateId(); |
| | | } |
| | | |
| | | private List<ExamPaperTitleItem> getExamPaperTitleItems(ModelMap mmap, TExamPaper tExamPaper) { |
| | | |
| | | //获取题目的内容展示 |
| | | List<ExamPaperTitleItem> examPaperTitleItemList = tExamPaperService.getExamPaperTitleContent(tExamPaper); |
| | | |
| | | // begin 重复题目 |
| | | List<ExamPaperTitleItem> contentOriginalList = getExamDuplicateTitleItems(tExamPaper, examPaperTitleItemList); |
| | | |
| | | // end 重复题目 |
| | | mmap.put("examPaperTitleItemList", contentOriginalList); |
| | | |
| | | nmapPutQuestionItem(mmap, examPaperTitleItemList); |
| | | |
| | | return examPaperTitleItemList; |
| | | } |
| | | |
| | | private List<ExamPaperTitleItem> getExamDuplicateTitleItems(TExamPaper tExamPaper, List<ExamPaperTitleItem> examPaperTitleItemList) { |
| | | List<ExamPaperTitleItem> contentOriginalList = JSONArray.parseArray(tExamPaper.getContent(), ExamPaperTitleItem.class); |
| | | |
| | | Map<Integer, QuestionItem> questionItemMap = new HashMap<>(); |
| | | for (ExamPaperTitleItem examPaperTitleItem : examPaperTitleItemList) { |
| | | List<QuestionItem> questionItems = examPaperTitleItem.getQuestionItems(); |
| | |
| | | questionItemMap.put(questionItem.getQuestionId(), questionItem); |
| | | } |
| | | } |
| | | |
| | | for (ExamPaperTitleItem examPaperTitleItem : contentOriginalList) { |
| | | List<QuestionItem> questionItems = examPaperTitleItem.getQuestionItems(); |
| | | for (QuestionItem questionItem : questionItems) { |
| | | Integer partOrder = questionItem.getPartOrder(); |
| | | |
| | | // 复制题目里面不存在的属性后再复制 |
| | | QuestionItem questionItemSource = questionItemMap.get(questionItem.getId()); |
| | | questionItemSource.setTemplate(questionItem.getTemplate()); |
| | | questionItemSource.setParentQuestionId(questionItem.getParentQuestionId()); |
| | |
| | | } |
| | | return contentOriginalList; |
| | | } |
| | | |
| | | private void nmapPutQuestionItem(ModelMap mmap, List<ExamPaperTitleItem> examPaperTitleItemList) { |
| | | |
| | | // 批量导入的时候展示题目的维度,Job才需要,维度都是一样的 |
| | | List<QuestionItem> questionItems = examPaperTitleItemList.get(0).getQuestionItems(); |
| | | mmap.put("questionItems", questionItems); |
| | | mmap.put("parts", JsonUtil.toJsonStr(examPaperTitleItemList.get(0).getParts())); |
| | | } |
| | | |
| | | @GetMapping("/deleteLang/{uuid}/{langType}") |
| | | @ResponseBody |
| | | public AjaxResult deleteLang(@PathVariable("uuid") Long uuid, @PathVariable("langType") String langType) { |
| | | |
| | | // 多语言的时候uuid就是id |
| | | TExamPaper tExamPaper = tExamPaperService.selectTExamPaperById(uuid); |
| | | tExamPaper.setLangType(langType); |
| | | return toAjax(tExamPaperService.deleteProductContent(tExamPaper)); |
| | | } |
| | | |
| | | private String getDitcByType(String type, String dictType) { |
| | | List<DictData> langTypeList = dictDataService.selectDictDataByType(type); |
| | | Map<String, String> lanTypeMap = langTypeList.stream().collect(Collectors.toMap(DictData::getDictValue, DictData::getDictLabel)); |
| | | return lanTypeMap.get(dictType); |
| | | } |
| | | |
| | | |
| | | // 弹出语言 |
| | | @GetMapping("/langType/{id}") |
| | | public String getLangType(@PathVariable("id") Long id, ModelMap mmap) { |
| | | List<DictData> dictDataList = tExamPaperService.getType(id); |