package com.ots.project.exam.controller;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.ots.common.utils.MessageUtils;
|
import com.ots.common.utils.StringUtils;
|
import com.ots.common.utils.poi.ExcelUtil;
|
import com.ots.framework.aspectj.lang.annotation.Log;
|
import com.ots.framework.aspectj.lang.enums.BusinessType;
|
import com.ots.framework.web.controller.BaseController;
|
import com.ots.framework.web.domain.AjaxResult;
|
import com.ots.framework.web.page.TableDataInfo;
|
import com.ots.framework.web.service.DictService;
|
import com.ots.project.exam.domain.TExamLevel;
|
import com.ots.project.exam.domain.TQuestion;
|
import com.ots.project.exam.dto.QuestionJobImport;
|
import com.ots.project.exam.dto.QuestionObject;
|
import com.ots.project.exam.service.ITExamLevelService;
|
import com.ots.project.exam.service.ITQuestionService;
|
import com.ots.project.exam.service.ITSubjectService;
|
import com.ots.project.system.dict.domain.DictData;
|
import com.ots.project.system.dict.service.IDictDataService;
|
import com.ots.project.tool.exam.ExamUtil;
|
import com.ots.project.tool.exam.JsonUtil;
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.ui.ModelMap;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PostMapping;
|
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
|
public TableDataInfo list(TQuestion tQuestion) {
|
startPage();
|
List<TQuestion> list = tQuestionService.selectTQuestionList(tQuestion);
|
return getDataTable(list);
|
}
|
|
|
/**
|
* 专门为product的add_question.html 页面提供查询
|
*/
|
@RequiresPermissions("exam:question:list")
|
@PostMapping("/listForProductAddQuestion")
|
@ResponseBody
|
public TableDataInfo listForProductAddQuestion(TQuestion tQuestion) {
|
startPage();
|
if (StringUtils.equals(tQuestion.getLangType(), "ALL")) {
|
tQuestion.setLangType(dictService.getLangType(LocaleContextHolder.getLocale().toString()));
|
}
|
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) {
|
// 这句代码为了提示传过来的id是levelid
|
/*
|
* 去掉题目维度t_subject后只查询t_exam_level 表,得到字典里面的3类问卷模板,分别跳转到3个不同的模板页面,分别是
|
* add-job.html,add-personality.html,add-intelligence.html
|
*/
|
// 这句代码为了提示传过来的id是levelId
|
Long levelId = id;
|
TExamLevel tExamLevel = itExamLevelService.selectTExamLevelById(levelId);
|
// 语言选项显示当前国际化的那种
|
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")
|
@ResponseBody
|
public AjaxResult addSave(TQuestion tQuestion) {
|
int resultNum = tQuestionService.insertTQuestion(tQuestion);
|
if (permanentIdDuplicate.ordinal() == resultNum) {
|
return AjaxResult.error(MessageUtils.message("jsp.exam.quesiton.permanentidDuplicate"));
|
}
|
return toAjax(resultNum);
|
}
|
|
/**
|
* 修改题目列表
|
*/
|
@GetMapping("/edit/{id}")
|
public String edit(@PathVariable("id") Long id, ModelMap mmap) {
|
TQuestion tQuestion = tQuestionService.selectTQuestionById(id);
|
TExamLevel tExamLevel = getEditQuestion(mmap, tQuestion);
|
List<DictData> langTypeList = dictDataService.selectDictDataByType("lang_type");
|
Map<String, String> lanTypeMap = langTypeList.stream().collect(Collectors.toMap(DictData::getDictValue,DictData::getDictLabel));
|
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")
|
@ResponseBody
|
public AjaxResult editSave(TQuestion tQuestion) {
|
return toAjax(tQuestionService.updateTQuestion(tQuestion));
|
}
|
|
/**
|
* 删除题目列表
|
*/
|
@RequiresPermissions("exam:question:remove")
|
@Log(title = "题目列表", businessType = BusinessType.DELETE)
|
@PostMapping("/remove")
|
@ResponseBody
|
public AjaxResult remove(String ids) {
|
return toAjax(tQuestionService.deleteTQuestionByIds(ids));
|
}
|
|
/**
|
* 批量导入测试人员名单
|
*/
|
@RequiresPermissions("enterprise:question:import")
|
@PostMapping("/importData")
|
@ResponseBody
|
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
|
ExcelUtil<QuestionJobImport> util = new ExcelUtil<>(QuestionJobImport.class);
|
List<Map<Integer,String >> excelList = util.importDynamicExcel(file.getInputStream());
|
if (excelList.size() <= 0 && Objects.isNull(excelList)) {
|
return AjaxResult.success("导入失败,模版格式不正确。");
|
}
|
String message = tQuestionService.insertImportQuestion(excelList);
|
return AjaxResult.success(message);
|
}
|
|
|
/**
|
* 批量导入测试人员名单模板下载
|
*/
|
@RequiresPermissions("enterprise:question:view")
|
@GetMapping("/importTemplate")
|
@ResponseBody
|
public AjaxResult importTemplate() {
|
ExcelUtil<QuestionJobImport> util = new ExcelUtil<QuestionJobImport>(QuestionJobImport.class);
|
return util.importTemplateExcel("题目模版");
|
}
|
|
@GetMapping("/addLang/{uuid}")
|
public String addLang(@PathVariable("uuid") Long uuid, ModelMap mmap) {
|
// 多语言的时候uuid就是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) {
|
selectInputs.add("");
|
}
|
tQuestion.setSelectInput(selectInputs);
|
}
|
return prefix + "/edit-" + tExamLevel.getQuestionTemplateId();
|
}
|
|
/**
|
* 根据语言修改题目, 页面上的新增语言调用
|
*/
|
@GetMapping("/editLang/{uuid}/{langType}")
|
public String editLang(@PathVariable("uuid") Long uuid, @PathVariable("langType") String langType,ModelMap mmap) {
|
// 多语言的时候uuid就是id
|
TQuestion tQuestion = tQuestionService.selectTQuestionById(uuid);
|
// 多语言版本
|
tQuestion.setUuid(uuid);
|
tQuestion.setLangType(langType);
|
TExamLevel tExamLevel = getEditQuestion(mmap, tQuestion);
|
List<DictData> langTypeList = dictDataService.selectDictDataByType("lang_type");
|
Map<String, String> lanTypeMap = langTypeList.stream().collect(Collectors.toMap(DictData::getDictValue,DictData::getDictLabel));
|
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) {
|
// 多语言的时候uuid就是id
|
TQuestion tQuestion = tQuestionService.selectTQuestionById(uuid);
|
tQuestion.setLangType(langType);
|
return toAjax(tQuestionService.deleteQuestionContent(tQuestion));
|
}
|
}
|