/**
* FileName: AdminController
*
* Date: 2020/10/6 17:59
* Description: 管理员控制类
*/
package com.qst.goldenarches.controller;
import com.github.pagehelper.PageHelper;
import com.qst.goldenarches.pojo.*;
import com.qst.goldenarches.service.AdminService;
import com.qst.goldenarches.service.PermissionService;
import com.qst.goldenarches.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.*;
@Controller
@RequestMapping("admin")
public class AdminController {
@Autowired
private AdminService adminService;
@Autowired
private RoleService roleService;
@Autowired
private PermissionService permissionService;
/**
* 跳转到错误页面(权限不足)
* @return
*/
@RequestMapping("error")
public String error() {
return "admin/error";
}
/**
* 删除管理员的角色
* @param adminId
* @param assignRoleIds
* @return
*/
@ResponseBody
@RequestMapping("doUnAssign")
public Object dounAssign( Integer adminId, Integer[] assignRoleIds ) {
try {
// 删除关系表数据
Map<String, Object> map = new HashMap<String, Object>();
map.put("adminId", adminId);
map.put("roleIds", assignRoleIds);
adminService.removeAdminRoles(map);
return Msg.success();
} catch ( Exception e ) {
e.printStackTrace();
return Msg.fail();
}
}
/**
* 为管理员分配角色
* @param adminId
* @param unassignRoleIds
* @return
*/
@ResponseBody
@RequestMapping("doAssign")
public Object doAssign( Integer adminId, Integer[] unassignRoleIds ) {
try {
// 增加admin_role关系表数据
Map<String, Object> map = new HashMap<String, Object>();
map.put("adminId", adminId);
map.put("roleIds", unassignRoleIds);
adminService.addAdminRoles(map);
return Msg.success();
} catch ( Exception e ) {
e.printStackTrace();
return Msg.fail();
}
}
/**
* 页面跳转:
* 跳转到管理员角色分配页面
* 数据回显,显示已经分配的角色
* 和没有分配的角色
* @param id
* @param model
* @return
*/
@RequestMapping("/assign")
public String assign( Integer id, Model model ) {
Admin admin = adminService.getAdminById(id);
model.addAttribute("admin", admin);
List<Role> roles = roleService.getAllRoles(null);
List<Role> assingedRoles = new ArrayList<Role>();
List<Role> unassignRoles = new ArrayList<Role>();
// 获取关系表的数据
List<Integer> roleids = adminService.getRoleIdsByAdminId(id);
for ( Role role : roles ) {
if ( roleids.contains(role.getId()) ) {
assingedRoles.add(role);
} else {
unassignRoles.add(role);
}
}
model.addAttribute("assingedRoles", assingedRoles);
model.addAttribute("unassignRoles", unassignRoles);
return "admin/assign";
}
/**
* 根据id删除管理员
* @param adminid
* @return
*/
@ResponseBody
@RequestMapping("/deletes")
public Msg deletes( Integer[] adminid ) {
try {
if (adminid.length>0){
Map<String, Object> map = new HashMap<String, Object>();
map.put("adminids", adminid);
adminService.removeAdmins(map);
return Msg.success();
}
return Msg.fail();
} catch ( Exception e ) {
e.printStackTrace();
return Msg.fail();
}
}
/**
* 实现用户修改业务逻辑
* @param admin
* @return
*/
@ResponseBody
@RequestMapping("/doEdit")
public Msg update(HttpSession session, Admin admin ) {
try {
Admin sessionAdmin =(Admin) session.getAttribute("loginAdmin");
if(sessionAdmin.getId()==admin.getId()){
adminService.editAdmin(admin);
session.setAttribute("loginAdmin",admin);
return Msg.success();
}
return Msg.fail();
} catch ( Exception e ) {
e.printStackTrace();
return Msg.fail();
}
}
/**
* 跳转到修改个人信息(admin)界面
* @param model
* @return
*/
@RequestMapping("/edit")
public String edit(HttpSession session,Model model ) {
Admin admin =(Admin) session.getAttribute("loginAdmin");
model.addAttribute("admin",admin);
return "admin/edit";
}
/**
* 新增界面实现新增业务
* @param admin
* @return
*/
@ResponseBody
@RequestMapping("doAdd")
public Msg doAdd( Admin admin ) {
try {
if (adminService.validateAccountUnique(admin.getAccount())){
admin.setPassword("1234");//默认密码
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
admin.setCreateTime(sdf.format(new Date()));
adminService.addAdmin(admin);
return Msg.success();
}
return Msg.fail();
} catch ( Exception e ) {
e.printStackTrace();
return Msg.fail();
}
}
/**
* 检验用户账户唯一性
* @param account
* @return
*/
@RequestMapping("uniqueAcct")
@ResponseBody
public Msg validateAccountUnique(String account,HttpSession session){
try {
if(account!=null) {
boolean flag = adminService.validateAccountUnique(account);
if (flag){
return Msg.success();
}
}
return Msg.fail().add("va_msg","账户已存在");
}catch (Exception e){
e.printStackTrace();
return Msg.fail().add("va_mag","服务异常,稍后重试");
}
}
/**
* 跳转到新增界面
* @return
*/
@RequestMapping("add")
public String toAdd(){
return "admin/add";
}
/**
*
* @param pn
* @param pagesize
* @param queryText
* @return
*/
@ResponseBody
@RequestMapping("/pageQuery")
public Msg pageQuery( @RequestParam(value = "pageno",defaultValue = "1") Integer pn,
@RequestParam(value = "pagesize",defaultValue = "10")Integer pagesize , String queryText) {
try {
PageHelper.startPage(pn,pagesize);
List<Admin> admins =adminService.getAllAdmin(queryText);
com.github.pagehelper.PageInfo<Admin> adminPageInfo =
new com.github.pagehelper.PageInfo<Admin>(admins,5);
return Msg.success().add("pageInfo",adminPageInfo);
} catch ( Exception e ) {
e.printStackTrace();
return Msg.fail();
}
}
/**
* 页面跳转
* 管理员列表主界面
* @return
*/
@RequestMapping("/index")
public String index(){
return "admin/index";
}
/***
* 管理员退出
* @param session
* @return
*/
@RequestMapping
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Java毕业设计项目-麦当劳在线点餐(ssm框架项目) (543个子文件)
0b2ef6a8132a452b857e597148d94f00e6f6f2 247B
1de75ad0d2878e1332599601c2d46494d1ed31 239B
6aa80ab0ae2c2ce3f8d1ff795572768bd4155d 216B
78f6a00b7f3dc3ab5539e673f64c3b15b21842 248B
a24fcbd76bf46eac981dc76abe14dd2f666be1 205B
AdminController.class 10KB
AdminController.class 10KB
ProductController.class 7KB
ProductController.class 7KB
RoleController.class 7KB
RoleController.class 7KB
OrderServiceImpl.class 6KB
OrderServiceImpl.class 6KB
OrderController.class 5KB
OrderController.class 5KB
CategoryController.class 5KB
CategoryController.class 5KB
ChartServiceImpl.class 4KB
ChartServiceImpl.class 4KB
ProductServiceImpl.class 4KB
ProductServiceImpl.class 4KB
MemberController.class 3KB
MemberController.class 3KB
RoleServiceImpl.class 3KB
RoleServiceImpl.class 3KB
AdminServiceImpl.class 3KB
AdminServiceImpl.class 3KB
ImageUtil.class 3KB
ImageUtil.class 3KB
AuthInterceptor.class 3KB
AuthInterceptor.class 3KB
Product.class 3KB
Product.class 3KB
PermissionController.class 2KB
PermissionController.class 2KB
OrderByEnumUtil.class 2KB
OrderByEnumUtil.class 2KB
LoginInterceptor.class 2KB
LoginInterceptor.class 2KB
Permission.class 2KB
Permission.class 2KB
CategoryServiceImpl.class 2KB
CategoryServiceImpl.class 2KB
VIPController.class 2KB
VIPController.class 2KB
VIPServiceImpl.class 2KB
VIPServiceImpl.class 2KB
Detail.class 2KB
Detail.class 2KB
Order.class 2KB
Order.class 2KB
Msg.class 2KB
Msg.class 2KB
VIP.class 2KB
VIP.class 2KB
Admin.class 2KB
Admin.class 2KB
ChartController.class 2KB
ChartController.class 2KB
PageInfo.class 2KB
PageInfo.class 2KB
OrderMapper.class 2KB
OrderMapper.class 2KB
AdminMapper.class 2KB
AdminMapper.class 2KB
ProductMapper.class 2KB
ProductMapper.class 2KB
PermissionServiceImpl.class 1KB
PermissionServiceImpl.class 1KB
TimeUtil.class 1KB
TimeUtil.class 1KB
DetailController.class 1KB
DetailController.class 1KB
MemberServiceImpl.class 1KB
MemberServiceImpl.class 1KB
OrderService.class 1KB
OrderService.class 1KB
RoleMapper.class 1KB
RoleMapper.class 1KB
Category.class 1KB
Category.class 1KB
ServerStartupListener.class 1KB
ServerStartupListener.class 1KB
DetailServiceImpl.class 955B
DetailServiceImpl.class 955B
ProductService.class 909B
ProductService.class 909B
AdminService.class 907B
AdminService.class 907B
VIPMapper.class 880B
VIPMapper.class 880B
CategoryMapper.class 856B
CategoryMapper.class 856B
DigitalUtil.class 853B
DigitalUtil.class 853B
PermissionMapper.class 817B
PermissionMapper.class 817B
Role.class 786B
Role.class 786B
CategoryService.class 734B
共 543 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
qwsrfss
- 粉丝: 1
- 资源: 32
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 离线安装包 Adobe Flash Player 32.0.0.156 for Linux 32-bit PPAPI
- javaweb作业jsp内置对象作业:简单购物车功能
- 【java毕业设计】野生动物公益保护系统源码(ssm+mysql+说明文档+LW).zip
- 离线安装包 Adobe Flash Player 32.0.0.156 for Linux 64-bit NPAPI
- 单片机测频率DSN
- 【java毕业设计】学习交流平台源码(ssm+mysql+说明文档+LW).zip
- Jsp内置对象作业:Session、Cookie实现登录功能,记住用户密码功能等
- 【java毕业设计】融资租赁管理系统源码(ssm+mysql+说明文档+LW).zip
- 离线安装包 Adobe Flash Player 32.0.0.156 for Linux 64-bit PPAPI
- 黑客与渗透测试编程之道.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功