package com.example.demo.controller;
import com.example.demo.entity.Admin;
import com.example.demo.entity.AdminDevice;
import com.example.demo.result.Result;
import com.example.demo.service.AdminDeviceService;
import com.example.demo.service.AdminService;
import com.example.demo.service.DeviceService;
import com.example.demo.utils.ResultUtil;
import com.example.demo.view.AdminView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.websocket.server.PathParam;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping("/api/admin")
@CrossOrigin
public class AdminControl {
@Autowired
private AdminService adminService;
@Autowired
private AdminDeviceService adminDeviceService;
@Autowired
private DeviceService deviceService;
/**
* @Description: 登录功能
* @Param: [admin]
* @return: com.example.demo.result.Result
* @Author: Zjh
* @Date: 5/19/21
*/
@RequestMapping("/login")
@ResponseBody
public Result login(@RequestBody Admin admin) {
Admin admin1 = adminService.Login(admin);
if (null != admin1) {
List<Integer> devices;
if (admin.getUsername().equals("admin")) {
devices = deviceService.getAllDeviceId();
} else {
devices = adminDeviceService.getDidByUsername(admin1.getUsername());
}
return ResultUtil.buildSuccessResult("登录成功", devices);
} else {
return ResultUtil.buildFailResult("用户名或密码错误", null);
}
}
@GetMapping("/getAllAdmin")
public List<AdminView> getAllAdmins() {
List<AdminView> list = new ArrayList<>();
List<Admin> admins = adminService.getAllAdmin();
for (Admin admin : admins) {
List<Integer> devices = adminDeviceService.getDidByUsername(admin.getUsername());
AdminView userView = new AdminView(admin.getUsername(), admin.getPassword(), devices);
list.add(userView);
}
return list;
}
@GetMapping("/findByKeyword")
public List<AdminView> findByKeyWord(@PathParam("keyword") String keyword) {
keyword = "%" + keyword + "%";
List<AdminView> list = new ArrayList<>();
List<Admin> admins = adminService.findByKeyWord(keyword);
for (Admin admin : admins) {
List<Integer> devices = adminDeviceService.getDidByUsername(admin.getUsername());
AdminView userView = new AdminView(admin.getUsername(), admin.getPassword(), devices);
list.add(userView);
}
return list;
}
@RequestMapping("/addAdmin")
@ResponseBody
public Result addUser(@RequestBody AdminView adminView) {
Admin admin = new Admin(adminView.getUsername(), "123456");
//判断用户名是否已存在
Admin admin1 = adminService.findByUsername(admin);
if (null == admin1) {
//1.新增一个admin,成功则返回1
int ret = adminService.insertAdmin(admin);
if (ret == 1) {
//2.新增权限
for (int i : adminView.getDevices()) {
AdminDevice adminDevice = new AdminDevice(0, adminView.getUsername(), i);
int flag = adminDeviceService.insertAdminDevice(adminDevice);
if (flag == 0) {
return ResultUtil.buildFailResult("增加管理员权限失败", null);
}
}
return ResultUtil.buildSuccessResult("新增管理员成功,默认密码为123456", null);
} else {
return ResultUtil.buildFailResult("增加管理员失败", null);
}
} else {
return ResultUtil.buildFailResult("昵称已存在", null);
}
}
@RequestMapping("/deleteAdmin")
@ResponseBody
public Result deleteUser(@RequestBody Admin admin) {
int flag = adminDeviceService.deleteAllAdminDevice(admin.getUsername());
if (flag == 0) {
return ResultUtil.buildFailResult("删除权限失败", null);
}
flag = adminService.deleteAdmin(admin);
if (flag == 0) {
return ResultUtil.buildFailResult("删除管理员失败", null);
}
return ResultUtil.buildSuccessResult("删除管理员成功!", null);
}
/**
* @Description: 修改某个管理员的权限,括号内为新的权限
* @Param: [username, devices]
* @return: com.example.demo.result.Result
* @Author: Zjh
* @Date: 5/19/21
*/
@RequestMapping("/changeAuthority")
@ResponseBody
public Result changeAuthority(@RequestBody AdminView adminView) {
String username = adminView.getUsername();
List<Integer> devices = adminView.getDevices();
Admin admin = new Admin(username, "");
if (null != adminService.findByUsername(admin)) {
if (devices == null) {
// 清空
adminDeviceService.deleteAllAdminDevice(username);
} else {
// 求差集,删除一些权限
List<Integer> old_devices = adminDeviceService.getDidByUsername(username);
old_devices.removeAll(devices);
for (int i : old_devices) {
AdminDevice adminDevice = new AdminDevice(0, username, i);
adminDeviceService.deleteOneAdminDevice(adminDevice);
}
//求差集,增加一些权限
old_devices = adminDeviceService.getDidByUsername(username);
devices.removeAll(old_devices);
for (int i : devices) {
AdminDevice adminDevice = new AdminDevice(0, username, i);
adminDeviceService.insertAdminDevice(adminDevice);
}
}
return ResultUtil.buildSuccessResult("修改权限成功", null);
} else {
return ResultUtil.buildFailResult("用户不存在", null);
}
}
@RequestMapping("/changePassword")
@ResponseBody
public Result changePassword(@RequestParam String username,@RequestParam String oldPassword, @RequestParam String newPassword) {
System.out.println(username);
Admin admin = new Admin(username, oldPassword);
if (null != adminService.Login(admin)){
admin.setPassword(newPassword);
int ret = adminService.updatePassword(admin);
if (ret == 1){
return ResultUtil.buildSuccessResult("修改密码成功!",null);
} else {
return ResultUtil.buildFailResult("修改密码失败!",null);
}
}
return ResultUtil.buildFailResult("旧密码错误!",null);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于SpringBoot+MyBatis+Vue+Element的门禁管理系统源码+项目说明.zip

共88个文件
java:31个
js:14个
vue:12个

1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉

温馨提示
基于SpringBoot+MyBatis+Vue+Element的门禁管理系统源码+项目说明.zip 【功能实现】 系统用户分为超级管理员和普通管理员 系统功能包括门禁记录管理、门禁设备管理和人员管理 系统是人脸识别门禁闸机系统之上的管理系统 基于Atlas200DK的人脸识别智能门禁系统:https://download.csdn.net/download/DeepLearning_/87351419 【备注】 主要针对计算机相关专业的正在做毕设的学生和需要项目实战的Java学习者。 也可作为课程设计、期末大作业。包含:项目源码、项目说明等,该项目可以直接作为毕设、课程设计使用。 也可以用来学习参考借鉴!
资源推荐
资源详情
资源评论

















收起资源包目录































































































































共 88 条
- 1
资源评论

- m0_623025372023-04-21资源内容详实,描述详尽,解决了我的问题,受益匪浅,学到了。onnx2023-11-08感谢认可~~

onnx
- 粉丝: 1w+
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 基于大数据的水利水电项目质量控制(1).docx
- 对提升中职学校教师信息化教学能力的思考与建议(1).docx
- 中职学校档案信息化建设探究(1).docx
- 电子商务各岗位职责及任职要求(1)(1).doc
- 企业级软件订阅协议(标准版)(1)(1).docx
- 人工智能技术研发的思考和发展(1).docx
- 基于人工智能下农商平台的新型发展道路的分析(1).docx
- 互联网+地方特产营销建议(1).docx
- 自动化年度工作计划(1).doc
- 用例和用例图(1).pptx
- 暑假计算机专职管理人员维护培训班班级管理规定(1).docx
- 基于PLC的点胶机控制系统设计(1)(1).doc
- 嘉兴市企业信息化项目管理办法.doc
- 电子商务网站报告.doc
- 计算机网络谢希仁第五版课后题答案(1).pptx
- 大数据对人民生活影响分析(1).docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
