liujie
5 天以前 3b64bcc08e7103006599278f7fe3d8cdeebf30b5
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.ruoyi.user.controller;
 
import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
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.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.user.domain.AccountUser;
import com.ruoyi.user.service.IAccountUserService;
 
/**
 * 会员用户 信息操作处理
 *
 * 网关前缀 /account 由 StripPrefix=1 剥掉,故此处映射为 /user,
 * 外部实际路径是 /account/user/**。
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/user")
public class AccountUserController extends BaseController
{
    @Autowired
    private IAccountUserService accountUserService;
 
    /**
     * 查询会员列表
     */
    @RequiresPermissions("account:user:list")
    @GetMapping("/list")
    public TableDataInfo list(AccountUser accountUser)
    {
        startPage();
        List<AccountUser> list = accountUserService.selectAccountUserList(accountUser);
        return getDataTable(list);
    }
 
    /**
     * 导出会员列表
     */
    @RequiresPermissions("account:user:export")
    @Log(title = "会员管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AccountUser accountUser)
    {
        List<AccountUser> list = accountUserService.selectAccountUserList(accountUser);
        ExcelUtil<AccountUser> util = new ExcelUtil<AccountUser>(AccountUser.class);
        util.exportExcel(response, list, "会员数据");
    }
 
    /**
     * 获取会员详细信息
     */
    @RequiresPermissions("account:user:query")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable Long userId)
    {
        return success(accountUserService.selectAccountUserById(userId));
    }
 
    /**
     * 新增会员
     */
    @RequiresPermissions("account:user:add")
    @Log(title = "会员管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody AccountUser accountUser)
    {
        if (!accountUserService.checkUsernameUnique(accountUser))
        {
            return error("新增会员'" + accountUser.getUserName() + "'失败,用户名已存在");
        }
        if (!accountUserService.checkPhoneUnique(accountUser))
        {
            return error("新增会员'" + accountUser.getUserName() + "'失败,手机号已存在");
        }
        if (StringUtils.isEmpty(accountUser.getPassword()))
        {
            return error("密码不能为空");
        }
        accountUser.setCreateBy(SecurityUtils.getUsername());
        return toAjax(accountUserService.insertAccountUser(accountUser));
    }
 
    /**
     * 修改会员
     */
    @RequiresPermissions("account:user:edit")
    @Log(title = "会员管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody AccountUser accountUser)
    {
        if (!accountUserService.checkUsernameUnique(accountUser))
        {
            return error("修改会员'" + accountUser.getUserName() + "'失败,用户名已存在");
        }
        if (!accountUserService.checkPhoneUnique(accountUser))
        {
            return error("修改会员'" + accountUser.getUserName() + "'失败,手机号已存在");
        }
        accountUser.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(accountUserService.updateAccountUser(accountUser));
    }
 
    /**
     * 删除会员
     */
    @RequiresPermissions("account:user:remove")
    @Log(title = "会员管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(accountUserService.deleteAccountUserByIds(userIds));
    }
}