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);
|
}
|
}
|