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 com.ots.common.utils.poi.ExcelUtil;
|
import com.ots.common.utils.security.ShiroUtils;
|
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.domain.Ztree;
|
import com.ots.framework.web.page.TableDataInfo;
|
import com.ots.project.exam.domain.TExamLevel;
|
import com.ots.project.exam.domain.TExamPaper;
|
import com.ots.project.exam.domain.TQuestion;
|
import com.ots.project.exam.dto.ExamPaperTitleItem;
|
import com.ots.project.exam.dto.QuestionItem;
|
import com.ots.project.exam.dto.QuestionJobImport;
|
import com.ots.project.exam.dto.QuestionPersonalityImport;
|
import com.ots.project.exam.service.ITExamLevelService;
|
import com.ots.project.exam.service.ITExamPaperService;
|
import com.ots.project.exam.service.ITReportTemplateService;
|
import com.ots.project.exam.service.ITTextContentService;
|
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 com.ots.project.tool.exam.ModelMapperSingle;
|
import com.ots.project.tool.gen.service.IExamUtilService;
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
import org.modelmapper.ModelMapper;
|
import org.springframework.beans.factory.annotation.Autowired;
|
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;
|
|
@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
|
public TableDataInfo list(TExamPaper tExamPaper) {
|
startPage();
|
List<TExamPaper> list = tExamPaperService.selectTExamPaperList(tExamPaper);
|
return getDataTable(list);
|
}
|
|
@RequiresPermissions("exam:product:export")
|
@PostMapping("/export")
|
@ResponseBody
|
public AjaxResult export(TExamPaper tExamPaper) {
|
List<TExamPaper> list = tExamPaperService.selectTExamPaperList(tExamPaper);
|
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) {
|
|
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")
|
@ResponseBody
|
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")
|
@ResponseBody
|
public AjaxResult editSave(TExamPaper tExamPaper) {
|
return toAjax(tExamPaperService.updateTExamPaper(tExamPaper));
|
}
|
|
@RequiresPermissions("exam:product:remove")
|
@Log(title = "产品包列表", businessType = BusinessType.DELETE)
|
@PostMapping("/remove")
|
@ResponseBody
|
public AjaxResult remove(String ids) {
|
return toAjax(tExamPaperService.deleteTExamPaperByIds(ids));
|
}
|
|
@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("langType", langType);
|
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("langType", langType);
|
mmap.put("template", "intelligence");
|
return prefix + "/add_question";
|
}
|
|
@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();
|
|
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
|
public AjaxResult importTemplate() {
|
ExcelUtil<QuestionJobImport> util = new ExcelUtil<>(QuestionJobImport.class);
|
return util.importTemplateQuestionExcel("JAQ题目模板.xlsx");
|
}
|
|
@RequiresPermissions("exam:product:view")
|
@GetMapping("/importMAQTemplate")
|
@ResponseBody
|
public AjaxResult importMQATemplate() {
|
ExcelUtil<QuestionPersonalityImport> util = new ExcelUtil<>(QuestionPersonalityImport.class);
|
return util.importTemplateQuestionExcel("MAQ题目模板.xlsx");
|
}
|
|
@RequiresPermissions("exam:product:import")
|
@PostMapping("/importMAQData/{langType}")
|
@ResponseBody
|
public AjaxResult importMAQData(MultipartFile file, boolean updateSupport, Long levelId, String leveltName, @PathVariable String langType) throws Exception {
|
ExcelUtil<QuestionPersonalityImport> util = new ExcelUtil<>(QuestionPersonalityImport.class);
|
QuestionPersonalityImport questionPersonalityImport = util.importPersonalityExcel(file.getInputStream(), levelId, leveltName, langType);
|
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();
|
if (ExamUtil.isListNotEmpty(selectInput)) {
|
List<String> selectInputResult = new ArrayList<>();
|
for (String value : selectInput) {
|
selectInputResult.add(examUtilService.getLangOrLocalLangString(langType, value));
|
}
|
tQuestion.setSelectInput(selectInputResult);
|
}
|
}
|
}
|
|
@RequiresPermissions("exam:product:changeDeleted")
|
@PostMapping("/changeDeleted")
|
@ResponseBody
|
public AjaxResult changeDeleted(TExamPaper tExamPaper) {
|
return toAjax(tExamPaperService.updateDeleted(tExamPaper));
|
}
|
|
@GetMapping("/addLang/{uuid}/{langType}")
|
public String addLang(@PathVariable("uuid") Long uuid, @PathVariable("langType") String langType, ModelMap mmap) {
|
TExamPaper tExamPaper = tExamPaperService.selectTExamPaperById(uuid);
|
tExamPaper.setLangType(langType);
|
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);
|
|
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.setUuid(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);
|
|
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);
|
|
List<ExamPaperTitleItem> contentOriginalList = getExamDuplicateTitleItems(tExamPaper, examPaperTitleItemList);
|
|
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();
|
for (QuestionItem questionItem : questionItems) {
|
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());
|
BeanUtils.copyProperties(questionItemSource, questionItem);
|
questionItem.setPartOrder(partOrder);
|
}
|
}
|
return contentOriginalList;
|
}
|
private void nmapPutQuestionItem(ModelMap mmap, List<ExamPaperTitleItem> examPaperTitleItemList) {
|
|
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) {
|
|
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);
|
mmap.put("dictDatas", dictDataList);
|
return prefix + "/product::langTypeDiv";
|
}
|
}
|