linzhijie
2021-04-12 c632636e2f5b4188b430f5efc9d9f68c8dbe3d6d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package com.ots.project.exam.controller;
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.service.ITExamLevelService;
import com.ots.project.system.dict.domain.DictData;
import org.apache.shiro.authz.annotation.RequiresPermissions;
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 java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
@Controller
@RequestMapping("/exam/level")
public class TExamLevelController extends BaseController {
    private String prefix = "exam/level";
    @Autowired
    private ITExamLevelService tExamLevelService;
    @Autowired
    private DictService dictService;
    @RequiresPermissions("exam:level:view")
    @GetMapping()
    public String level() {
        return prefix + "/level";
    }
    
    @RequiresPermissions("exam:level:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TExamLevel tExamLevel) {
        startPage();
        List<TExamLevel> list = tExamLevelService.selectTExamLevelList(tExamLevel);
        
        List<DictData> questionnaireTemplate = dictService.getType("questionnaire_template");
        Map<String, String> dictMap = questionnaireTemplate.stream().collect(Collectors.toMap(DictData::getDictValue, DictData::getDictLabel));
        list.stream().forEach(t -> {
            t.setQuestionTemplateName(dictMap.get(t.getQuestionTemplateId()));
        });
        return getDataTable(list);
    }
    
    @RequiresPermissions("exam:level:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TExamLevel tExamLevel) {
        List<TExamLevel> list = tExamLevelService.selectTExamLevelList(tExamLevel);
        ExcelUtil<TExamLevel> util = new ExcelUtil<TExamLevel>(TExamLevel.class);
        return util.exportExcel(list, "level");
    }
    
    @GetMapping("/add")
    public String add(String uuid,ModelMap mmap) {
        if(StringUtils.isNotBlank(uuid)){
            List<TExamLevel> tExamLevels = tExamLevelService.selectTExamLevelByUuid(uuid);
            mmap.put("tExamLevel", tExamLevels.get(0));
            return prefix + "/add-lan";
        }
        return prefix + "/add";
    }
    
    @RequiresPermissions("exam:level:add")
    @Log(title = "问卷类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TExamLevel tExamLevel) {
        TExamLevel tExamLevel1 = this.tExamLevelService.selectTExamLevelByUuidLan(tExamLevel.getUuid(), tExamLevel.getLangType());
        if (tExamLevel1 != null) {
            return AjaxResult.error("语言已经存在");
        }
        return toAjax(tExamLevelService.insertTExamLevel(tExamLevel));
    }
    
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        TExamLevel tExamLevel = tExamLevelService.selectTExamLevelById(id);
        mmap.put("tExamLevel", tExamLevel);
        return prefix + "/edit";
    }
    
    @RequiresPermissions("exam:level:edit")
    @Log(title = "问卷类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TExamLevel tExamLevel) {
        return toAjax(tExamLevelService.updateTExamLevel(tExamLevel));
    }
    
    @RequiresPermissions("exam:level:remove")
    @Log(title = "问卷类型", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(tExamLevelService.deleteTExamLevelByIds(ids));
    }
}