1
vince
2024-03-28 07c751ae483138d1754bd35a5325ad0d61463a36
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
141
142
143
144
145
146
147
148
149
150
151
152
package com.ruoyi.web.controller.system;
 
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysCompany;
import com.ruoyi.system.service.ISysCompanyService;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
/**
 * 组织管理
 *
 * @author andy
 */
@Controller
@RequestMapping("/system/company")
public class SysCompanyController extends BaseController {
 
    private String prefix = "system/company";
 
    @Autowired
    private ISysCompanyService companyService;
 
    @RequiresPermissions("system:company:view")
    @GetMapping()
    public String config() {
        return prefix + "/company";
    }
 
    /**
     * 查询参数配置列表
     */
    @RequiresPermissions("system:company:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysCompany company) {
 
        if (null == company.getCompanyId()) {
            company.setCompanyId(ShiroUtils.getLoginUserCompanyId());
        }
 
        startPage();
        List<SysCompany> list = companyService.selectAll();
 
        return getDataTable(list);
    }
 
    @Log(title = "参数管理", businessType = BusinessType.EXPORT)
    @RequiresPermissions("system:company:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysCompany config) {
 
        List<SysCompany> list = companyService.selectAll();
 
        ExcelUtil<SysCompany> util = new ExcelUtil<SysCompany>(SysCompany.class);
 
        return util.exportExcel(list, "参数数据");
    }
 
    /**
     * 新增参数配置
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }
 
    /**
     * 新增保存参数配置
     */
    @RequiresPermissions("system:company:add")
    @Log(title = "参数管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@Validated SysCompany company) {
        if (!companyService.checkCompanyIdUnique(company)) {
            return error("新增参数'" + company.getName() + "'失败,参数键名已存在");
        }
        company.setCreateBy(getLoginName());
        return toAjax(companyService.insertCompany(company));
    }
 
    /**
     * 修改参数配置
     */
    @RequiresPermissions("system:company:edit")
    @GetMapping("/edit/{companyId}")
    public String edit(@PathVariable("companyId") String companyId, ModelMap mmap) {
        mmap.put("company", companyService.selectCompanyById(companyId));
        return prefix + "/edit";
    }
 
    /**
     * 修改保存参数配置
     */
    @RequiresPermissions("system:company:edit")
    @Log(title = "参数管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated SysCompany company) {
        if (!companyService.checkCompanyIdUnique(company)) {
            return error("修改参数'" + company.getName() + "'失败,参数键名已存在");
        }
        company.setUpdateBy(getLoginName());
        return toAjax(companyService.updateCompany(company));
    }
 
    /**
     * 删除参数配置
     */
    @RequiresPermissions("system:company:remove")
    @Log(title = "参数管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        companyService.deleteCompanyByIds(ids);
        return success();
    }
 
    /**
     * 刷新参数缓存
     */
    @RequiresPermissions("system:company:remove")
    @Log(title = "参数管理", businessType = BusinessType.CLEAN)
    @GetMapping("/refreshCache")
    @ResponseBody
    public AjaxResult refreshCache() {
        companyService.resetCompanyCache();
        return success();
    }
 
    /**
     * 校验参数键名
     */
    @PostMapping("/checkCompanyIdUnique")
    @ResponseBody
    public boolean checkCompanyIdUnique(SysCompany config) {
        return companyService.checkCompanyIdUnique(config);
    }
}