linzhijie
2021-03-11 93af1c6ffb9ae0e894689ad3a37b548e57d54cff
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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
 *
 * @author ots
 * @date 2019-12-15
 */
@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);
        // 翻译一下 Item Template
        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));
    }
}