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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package com.ots.project.exam.controller;
import com.ots.common.enums.UserTypeEnum;
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.page.TableDataInfo;
import com.ots.project.exam.domain.EntDemographyParam;
import com.ots.project.exam.dto.DemographyDto;
import com.ots.project.exam.service.IEntDemographyParamService;
import com.ots.project.system.user.domain.User;
import com.ots.project.tool.exam.JsonUtil;
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.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
 
@Controller
@RequestMapping("/exam/demographyParam")
public class EntDemographyParamController extends BaseController {
    private String prefix = "exam/demographyParam";
    @Autowired
    private IEntDemographyParamService entDemographyParamService;
    @RequiresPermissions("exam:demographyParam:view")
    @GetMapping()
    public String demographyParam() {
        return prefix + "/demographyParam";
    }
    
    @RequiresPermissions("exam:demographyParam:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EntDemographyParam entDemographyParam) {
        startPage();
        User sysUser = ShiroUtils.getSysUser();
        if (Objects.isNull(entDemographyParam.getUserId()) && !Objects.equals(UserTypeEnum.SYS_USER.getUserType(), sysUser.getUserType())) {
            entDemographyParam.setUserId(sysUser.getUserId());
        }
        
        
        
        entDemographyParam.setUserId(null);
        List<EntDemographyParam> list = entDemographyParamService.selectEntDemographyParamList(entDemographyParam);
        return getDataTable(list);
    }
    
    @RequiresPermissions("exam:demographyParam:list")
    @PostMapping("/listCodes")
    @ResponseBody
    public TableDataInfo listCodes(EntDemographyParam entDemographyParam) {
        startPage();
        User sysUser = ShiroUtils.getSysUser();
        if (Objects.isNull(entDemographyParam.getUserId()) && !Objects.equals(UserTypeEnum.SYS_USER.getUserType(), sysUser.getUserType())) {
            entDemographyParam.setUserId(sysUser.getUserId());
        }
        EntDemographyParam param = entDemographyParamService.selectEntDemographyParamById(entDemographyParam.getParamId());
        String langCodes = param.getLangCodes();
        List<DemographyDto> list = JsonUtil.toJsonListObject(langCodes, DemographyDto.class);
        return getDataTable(list);
    }
    
    @RequiresPermissions("exam:demographyParam:list")
    @PostMapping("/addListCodes")
    @ResponseBody
    public TableDataInfo addListCodes(EntDemographyParam entDemographyParam) {
        return getDataTable(new ArrayList<EntDemographyParam>());
    }
    
    @RequiresPermissions("exam:demographyParam:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EntDemographyParam entDemographyParam) {
        List<EntDemographyParam> list = entDemographyParamService.selectEntDemographyParamList(entDemographyParam);
        ExcelUtil<EntDemographyParam> util = new ExcelUtil<EntDemographyParam>(EntDemographyParam.class);
        return util.exportExcel(list, "demographyParam");
    }
    
    @GetMapping("/add")
    public String add(ModelMap mmap) {
        User sysUser = ShiroUtils.getSysUser();
        mmap.put("sysUser", sysUser);
        return prefix + "/add";
    }
    
    @RequiresPermissions("exam:demographyParam:add")
    @Log(title = "人口学变量定义", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EntDemographyParam entDemographyParam) {
        User sysUser = ShiroUtils.getSysUser();
        if (!Objects.equals(UserTypeEnum.SYS_USER.getUserType(), sysUser.getUserType())) {
            return error("只有系统用户才允许添加人口学变量!");
        }
        EntDemographyParam param = new EntDemographyParam();
        param.setParamCode(entDemographyParam.getParamCode());
        List<EntDemographyParam> entDemographyParams = entDemographyParamService.selectEntDemographyParamList(param);
        if (entDemographyParams.size()>0) {
            return error("新增参数'" + entDemographyParam.getParamCode() + "'失败,已存在!");
        }
        return toAjax(entDemographyParamService.insertEntDemographyParam(entDemographyParam));
    }
    
    @GetMapping("/edit/{paramId}")
    public String edit(@PathVariable("paramId") Long paramId, ModelMap mmap) {
        EntDemographyParam entDemographyParam = entDemographyParamService.selectEntDemographyParamById(paramId);
        mmap.put("entDemographyParam", entDemographyParam);
        return prefix + "/edit";
    }
    
    @RequiresPermissions("exam:demographyParam:edit")
    @Log(title = "人口学变量定义", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EntDemographyParam entDemographyParam) {
        return toAjax(entDemographyParamService.updateEntDemographyParam(entDemographyParam));
    }
    
    @RequiresPermissions("exam:demographyParam:remove")
    @Log(title = "人口学变量定义", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(entDemographyParamService.deleteEntDemographyParamByIds(ids));
    }
}