huang
2025-05-20 e5b578d2c586ca9f664e31d3759952752255fdd3
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
package com.mes.md.controller;
import com.mes.md.entity.Account;
import com.mes.md.service.AccountService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mes.utils.Result;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
import java.util.Map;
 
/**
 * <p>
 * 账户表 前端控制器
 * </p>
 *
 * @author wu
 * @since 2024-08-28
 */
@Api(tags = "账户")
@RestController
@RequestMapping("/account")
public class AccountController {
 
    @Autowired
    AccountService accountService;
 
 
    @ApiOperation("登录验证 成功则返回账户权限 参数(account,password)")
    @PostMapping("/selectAccount")
    @ResponseBody
    public Result selectAccount (@RequestBody Map<String, Object> arguments) {
        String account=arguments.get("account").toString();
        String password=arguments.get("password").toString();
        if(account.isEmpty()||password.isEmpty()){
            return Result.build(300,"账户或密码为空!",arguments);
        }
        Map<String, Object> roleAccount=accountService.selectAccount(account,password);
        if(roleAccount.isEmpty()){
            return Result.build(201,"登录失败",roleAccount);
        }
        return Result.build(200,"登录成功",roleAccount);
    }
 
    @ApiOperation("账户绑定角色")
    @PostMapping("/bindAccountRole")
    @ResponseBody
    public Result bindAccountRole (@RequestBody Account account) {
        int count=accountService.updateAccount(account);
        String message=count>0?"账户绑定角色成功:"+count:"账户绑定角色失败!";
        return Result.build(200,message,count);
    }
 
    @ApiOperation("查询所有账户")
    @PostMapping("/findAccounts")
    @ResponseBody
    public Result findAccounts () {
        List<Map<String, Object>> Accounts=accountService.findAccounts();
        return Result.build(200,"成功:"+Accounts.size(),Accounts);
    }
    @ApiOperation("添加账户")
    @PostMapping("/addAccount")
    @ResponseBody
    public Result addAccount (@RequestBody Account account) {
        int count=accountService.addAccount(account);
        String message=count>0?"账户添加成功:"+count:"账户添加失败!";
        return Result.build(200,message,count);
    }
 
    @ApiOperation("修改账户")
    @PostMapping("/updateAccount")
    @ResponseBody
    public Result updateAccount (@RequestBody Account account) {
        int count=accountService.updateAccount(account);
        String message=count>0?"账户修改成功:"+count:"账户修改失败!";
        return Result.build(200,message,count);
    }
 
    @ApiOperation("删除账户")
    @PostMapping("/deleteAccount")
    @ResponseBody
    public Result deleteAccount (@RequestBody Account account) {
        if(account.getId()==1){
            return Result.build(200,"账户删除失败!(原始账户不可删除)",-1);
        }
        int count=accountService.deleteAccount(account);
        String message=count>0?"账户删除成功:"+count:"账户删除失败!";
        return Result.build(200,message,count);
    }
}