package com.controller;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.xml.ws.RespectBinding;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.beans.Admin;
import com.beans.AdminCustom;
import com.beans.PrivilegeCustom;
import com.beans.Query;
import com.beans.RoleCustom;
import com.beans.RolePrivilegeCustom;
import com.beans.Users;
import com.beans.UsersCustom;
import com.beans.UsersRoleCustom;
import com.service.IAdminService;
import com.service.IPrivilegeService;
import com.service.IRolePrivilegeService;
import com.service.IRoleService;
import com.service.IUsersRoleService;
import com.service.IUsersService;
@Controller
@RequestMapping("controller1")
public class Controller1 {
@Resource(name="rolePrivilegeServiceImpl")
private IRolePrivilegeService rolePrivilegeService;
@Resource(name="roleServiceImpl")
private IRoleService roleService;
@Resource(name="usersRoleServiceImpl")
private IUsersRoleService usersRoleService;
@Resource(name="privilegeServiceImpl")
private IPrivilegeService privilegeService;
@Resource(name="usersServiceImpl")
private IUsersService usersService;
@Resource(name="adminServiceImpl")
private IAdminService adminService;
@RequestMapping("/queryMoney.action")
public String queryMoney(){
return "error";
}
//未完成
@RequestMapping("/login.action")
public String login(UsersCustom usersCustom,HttpSession session){
usersCustom = usersService.login(usersCustom);
if(usersCustom==null){
return "login";
}
ArrayList<PrivilegeCustom> pricilegeByUid = privilegeService.getPricilegeByUid(usersCustom.getId());
usersCustom.setOnePrivilegeCustom(pricilegeByUid);
session.setAttribute("user", usersCustom);
return "main";
}
//"用户登录以后" 操作 ,查询出所有父菜单(去重)
@RequestMapping("/parentSon.action")
public @ResponseBody Query parentSon2(HttpSession session){
try {
System.out.println(0);
Users user1 = (Users) session.getAttribute("user");
System.out.println(1);
ArrayList<PrivilegeCustom> distinctParent = privilegeService.getParent(user1.getId());
System.out.println(2);
ArrayList<PrivilegeCustom> allPricilege2 = privilegeService.getPricilegeByUid(user1.getId());
System.out.println(3);
Query qlist = new Query();
qlist.setSlist(allPricilege2);
qlist.setPlist(distinctParent);
return qlist;
} catch (Exception e) {
System.out.println("我的天,出错了,请修改。辛苦了");
e.printStackTrace();
}
return null;
}
//超级管理员登录并用session保存超级管理员信息
@RequestMapping("/adminLogin.action")
public String adminLogin(Admin admin,HttpSession session){
AdminCustom adminLogin = adminService.adminLogin(admin);
session.setAttribute("adminLogin", adminLogin);
session.setAttribute("user", adminLogin);
return "redirect:../controller1/queryAllPricilege.action";
}
//用于生成左侧菜单
@RequestMapping("/queryAllPricilege.action")
public String queryAllPricilege(HttpSession session){
ArrayList<PrivilegeCustom> allPricilege = privilegeService.queryAllPricilege();
session.setAttribute("allPricilege", allPricilege);
return "main";
}
//"为用户赋予角色" 操作 ,查询出所有的用户
@RequestMapping("/queryAllUsers.action")
public String queryAllUsers(HttpSession session){
Collection<UsersCustom> allUsers = usersService.queryAllUsers();
session.setAttribute("allUsers", allUsers);
return "redirect:../controller1/queryAllRole.action";
}
//"为用户赋予角色" 操作 ,查询出所有的角色
@RequestMapping("/queryAllRole.action")
public String queryAllRole(HttpSession session){
ArrayList<RoleCustom> allRole = (ArrayList<RoleCustom>) roleService.queryAllRole();
session.setAttribute("allRole", allRole);
return "usersRole";
}
//"为用户赋予角色" 操作 ,查询出单个角色的所有用户
@RequestMapping("/queryOneRoleUsers.action")
public @ResponseBody ArrayList<UsersRoleCustom> queryOneRoleUsers(@RequestParam(required=true,defaultValue="1") int rid){
ArrayList<UsersRoleCustom> queryOneRoleUsers = (ArrayList<UsersRoleCustom>) usersRoleService.queryOneRoleUsers(rid);
return queryOneRoleUsers;
}
//修改用户角色
@RequestMapping("/updateRoleUsers.action")
public void updateRoleUsers(int rid,String uids){
UsersRoleCustom usersRoleCustom = new UsersRoleCustom();
usersRoleCustom.setRid(rid);
if(uids.trim().equals("")){
usersRoleService.truncateTable(usersRoleCustom);
}else{
usersRoleService.truncateTable(usersRoleCustom);
String[] str = uids.trim().split(",");
System.out.println(str.length);
for (String uid : str) {
usersRoleService.add(new UsersRoleCustom(Integer.parseInt(uid),rid));
}
}
}
//"为角色赋予权限" 操作 ,查询出所有的角色和权限
@RequestMapping("/queryAllPrivilegeAndRole.action")
public String queryAllPrivilegeAndRole(HttpSession session){
ArrayList<RoleCustom> allRole2 = (ArrayList<RoleCustom>) roleService.queryAllRole();
session.setAttribute("allRole2", allRole2);
return "rolePrivilege";
}
//"为角色赋予权限" 操作 ,查询出所有父菜单(去重)
@RequestMapping("/distinctParent.action")
public @ResponseBody Query distinctParent(){
ArrayList<PrivilegeCustom> distinctParent = privilegeService.distinctParent();
ArrayList<PrivilegeCustom> allPricilege2 = privilegeService.queryAllPricilege();
Query qlist = new Query();
qlist.setSlist(allPricilege2);
qlist.setPlist(distinctParent);
return qlist;
}
//"为角色赋予权限" 操作 ,查询出单个角色的所有权限
@RequestMapping("/queryOneRolePrivileges.action")
public @ResponseBody ArrayList<RolePrivilegeCustom> queryOneRolePrivilege(int rid){
ArrayList<RolePrivilegeCustom> queryOneRoleP = (ArrayList<RolePrivilegeCustom>) rolePrivilegeService.queryOneRolePrivileges(rid);
return queryOneRoleP;
}
//"为角色赋予权限" 操作 ,为角色赋予新的权限
@RequestMapping("/updateRolePrivilege.action")
public void updateRolePrivilege(int rid,String pids){
RolePrivilegeCustom rolePrivilegeCustom = new RolePrivilegeCustom();
rolePrivilegeCustom.setRid(rid);
if(pids.trim().equals("")){
rolePrivilegeService.deleteTable(rolePrivilegeCustom);
}else{
rolePrivilegeService.deleteTable(rolePrivilegeCustom);
String[] str = pids.trim().split(",");
System.out.println(str.length);
for (String pid : str) {
rolePrivilegeService.add(new RolePrivilegeCustom(rid,Integer.parseInt(pid)));
}
}
}
}
评论1
最新资源