Blame view

src/main/java/com/huaheng/pc/system/user/controller/UserController.java 8.45 KB
tangying authored
1
2
package com.huaheng.pc.system.user.controller;
mahuandong authored
3
4
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
5
6
7
import com.huaheng.common.constant.Constants;
import com.huaheng.common.utils.MessageUtils;
import com.huaheng.common.utils.SystemLogUtils;
tangying authored
8
import com.huaheng.common.utils.security.ShiroUtils;
9
import com.huaheng.framework.shiro.web.filter.LogoutFilter;
tangying authored
10
import com.huaheng.pc.general.company.domain.Company;
mahuandong authored
11
import com.huaheng.pc.general.company.service.CompanyService;
12
13
14
15
import com.huaheng.pc.general.warehouse.domain.Warehouse;
import com.huaheng.pc.general.warehouse.mapper.WarehouseMapper;
import com.huaheng.pc.general.warehouse.service.WarehouseService;
import com.huaheng.pc.system.user.domain.SysUserWarehouse;
tangying authored
16
import org.apache.shiro.authz.annotation.RequiresPermissions;
17
18
import org.apache.shiro.session.SessionException;
import org.apache.shiro.subject.Subject;
tangying authored
19
import org.springframework.beans.factory.annotation.Autowired;
20
import org.springframework.boot.web.servlet.server.Session;
tangying authored
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
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 com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.poi.ExcelUtil;
import com.huaheng.framework.aspectj.lang.annotation.Log;
import com.huaheng.framework.aspectj.lang.constant.BusinessType;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.page.TableDataInfo;
import com.huaheng.pc.system.role.service.IRoleService;
import com.huaheng.pc.system.user.domain.User;
import com.huaheng.pc.system.user.service.IUserService;
39
40
41
42

import javax.annotation.Resource;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
tangying authored
43
import java.util.List;
44
45
46
import java.util.Map;

import static javax.security.auth.Subject.getSubject;
tangying authored
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

/**
 * 用户信息
 * 
 * @author huaheng
 */
@Controller
@RequestMapping("/system/user")
public class UserController extends BaseController
{
    private String prefix = "system/user";

    @Autowired
    private IUserService userService;

    @Autowired
    private IRoleService roleService;

    @Autowired
mahuandong authored
66
    private CompanyService companyService;
tangying authored
67
68
69
70
71
72
73
    @Autowired
    private WarehouseService warehouseService;

    @Resource
    private WarehouseMapper warehouseMapper;
tangying authored
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
    @RequiresPermissions("system:user:view")
    @GetMapping()
    public String user()
    {
        return prefix + "/user";
    }

    @RequiresPermissions("system:user:list")
    @Log(title = "系统管理-用户管理", operating = "查看用户列表", action = BusinessType.GRANT)
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(User user)
    {
        startPage();
        List<User> list = userService.selectUserList(user);
        return getDataTable(list);
    }

    @Log(title = "系统管理-用户管理", operating = "导出用户", action = BusinessType.EXPORT)
    @RequiresPermissions("system:user:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(User user)
    {
        try
        {
            List<User> list = userService.selectUserList(user);
            ExcelUtil<User> util = new ExcelUtil<User>(User.class);
            return util.exportExcel(list, "user");
        }
        catch (Exception e)
        {
            return error("导出Excel失败,请联系网站管理员!");
        }
    }

    /**
     * 新增用户
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        Company company = new Company();
mahuandong authored
117
        company.setWarehouseCode(ShiroUtils.getWarehouseCode());
tangying authored
118
        mmap.put("roles", roleService.selectRoleAll());
mahuandong authored
119
120
        LambdaQueryWrapper<Company> lambdaQueryWrapper = Wrappers.lambdaQuery(company);
        mmap.put("companys", companyService.list(lambdaQueryWrapper));
121
122
123
124
125
126
127
        LambdaQueryWrapper<Warehouse> warehouse = Wrappers.lambdaQuery();
        warehouse.select(Warehouse::getCode,Warehouse::getName,Warehouse::getEnable);
        List<Map<String, Object>> warehouseList = warehouseService.listMaps(warehouse);
        for (Map<String, Object> item : warehouseList){
            item.put("value",item.get("code").toString());
        }
        mmap.put("warehouseList",warehouseList);
tangying authored
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
153
154
155
156
        return prefix + "/add";
    }

    /**
     * 新增保存用户
     */
    @RequiresPermissions("system:user:add")
    @Log(title = "系统管理-用户管理", operating = "新增用户", action = BusinessType.INSERT)
    @PostMapping("/add")
    @Transactional(rollbackFor = Exception.class)
    @ResponseBody
    public AjaxResult addSave(User user)
    {
        if (StringUtils.isNotNull(user.getId()) && User.isAdmin(user.getId()))
        {
            return error("不允许修改超级管理员用户");
        }
        AjaxResult ajaxResult = toAjax(userService.insertUser(user));
        return  ajaxResult;
    }

    /**
     * 修改用户
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        mmap.put("user", userService.selectUserById(id));
        mmap.put("roles", roleService.selectRolesByUserId(id));
wangyanxiong authored
157
        mmap.put("companys", companyService.selectCompanyByUserId(id));
158
        mmap.put("warehouses", warehouseService.selectWarehouseByUserId(id));
tangying authored
159
160
161
162
163
164
165
166
167
168
169
170
171
        return prefix + "/edit";
    }

    /**
     * 修改保存用户
     */
    @RequiresPermissions("system:user:edit")
    @Log(title = "系统管理-用户管理", operating = "修改用户", action = BusinessType.UPDATE)
    @PostMapping("/edit")
    @Transactional(rollbackFor = Exception.class)
    @ResponseBody
    public AjaxResult editSave(User user)
    {
172
tangying authored
173
174
175
176
177
        if (StringUtils.isNotNull(user.getId()) && User.isAdmin(user.getId()))
        {
            return error("不允许修改超级管理员用户");
        }
        AjaxResult ajaxResult = toAjax(userService.updateUser(user));
178
179
180
181

        if (ShiroUtils.getLoginName().equals(user.getUserName()))
            ShiroUtils.logout();
tangying authored
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
        return ajaxResult;
    }

    @RequiresPermissions("system:user:resetPwd")
    @Log(title = "系统管理-用户管理", operating = "重置密码", action = BusinessType.UPDATE)
    @GetMapping("/resetPwd/{id}")
    public String resetPwd(@PathVariable("id") Integer userId, ModelMap mmap)
    {
        mmap.put("user", userService.selectUserById(userId));
        return prefix + "/resetPwd";
    }

    @RequiresPermissions("system:user:resetPwd")
    @Log(title = "系统管理-用户管理", operating = "重置密码", action = BusinessType.UPDATE)
    @PostMapping("/resetPwd")
    @ResponseBody
    public AjaxResult resetPwd(User user)
    {
        return toAjax(userService.resetUserPwd(user));
    }

    @RequiresPermissions("system:user:remove")
    @Log(title = "系统管理-用户管理", operating = "删除用户", action = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        try
        {
            return toAjax(userService.deleteUserByIds(ids));
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
    }

    /**
     * 校验用户名
     */
    @PostMapping("/checkLoginNameUnique")
    @ResponseBody
    public String checkLoginNameUnique(User user)
    {
        String uniqueFlag = "0";
        if (StringUtils.isNotNull(user))
        {
            uniqueFlag = userService.checkLoginNameUnique(user.getLoginName());
        }
        return uniqueFlag;
    }

    /**
     * 校验手机号码
     */
    @PostMapping("/checkPhoneUnique")
    @ResponseBody
    public String checkPhoneUnique(User user)
    {
        String uniqueFlag = "0";
        if (StringUtils.isNotNull(user))
        {
            uniqueFlag = userService.checkPhoneUnique(user);
        }
        return uniqueFlag;
    }

    /**
     * 校验email邮箱
     */
    @PostMapping("/checkEmailUnique")
    @ResponseBody
    public String checkEmailUnique(User user)
    {
        String uniqueFlag = "0";
        if (StringUtils.isNotNull(user))
        {
            uniqueFlag = userService.checkEmailUnique(user);
        }
        return uniqueFlag;
    }


}