package com.zjt.web;
import com.github.pagehelper.PageHelper;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.zjt.entity.Tmenu;
import com.zjt.entity.Trole;
import com.zjt.entity.Trolemenu;
import com.zjt.entity.Tuserrole;
import com.zjt.model.JqgridBean;
import com.zjt.model.PageRusult;
import com.zjt.service.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
import java.util.*;
/**
* 后台管理用户Controller
*
* @author zjt
*/
@Controller
@RequestMapping("/admin/role")
public class RoleAdminController {
@Resource
private TuserService userService;
@Resource
private TroleService roleService;
@Resource
private TuserroleService userRoleService;
@Resource
private TmenuService tmenuService;
@Resource
private TrolemenuService trolemenuService;
@RequestMapping("/torolemanage")
@RequiresPermissions(value = {"角色管理"})
public String tousermanage() {
return "power/role";
}
/**
* 分页查询角色信息
*/
@ResponseBody
@RequestMapping(value = "/list")
@RequiresPermissions(value = {"角色管理"})
public Map<String, Object> list(JqgridBean jqgridbean
/*String userName,@RequestParam(value="page",required=false)Integer page*/
) throws Exception {
LinkedHashMap<String, Object> resultmap = new LinkedHashMap<String, Object>();
LinkedHashMap<String, Object> datamap = new LinkedHashMap<String, Object>();
Example troleExample = new Example(Trole.class);
//tuserExample.or().andIdNotEqualTo(1L);
Example.Criteria criteria = troleExample.or();
if (StringUtils.isNotEmpty(jqgridbean.getSearchField())) {
if ("name".equalsIgnoreCase(jqgridbean.getSearchField())) {
if ("eq".contentEquals(jqgridbean.getSearchOper())) {
criteria.andEqualTo("name",jqgridbean.getSearchString());
}
}
}
PageHelper.startPage(jqgridbean.getPage(), jqgridbean.getLength());
List<Trole> roleList = roleService.selectByExample(troleExample);
PageRusult<Trole> pageRusult =new PageRusult<Trole>(roleList);
/*Integer totalrecords = roleService.countByExample(troleExample);//总记录数
Page pagebean = new Page(jqgridbean.getLength() * ((jqgridbean.getPage() > 0 ? jqgridbean.getPage() : 1) - 1), jqgridbean.getLength(), totalrecords);
troleExample.setPage(pagebean);
troleExample.setOrderByClause(jqgridbean.getSidx() + " " + jqgridbean.getSord());
List<Trole> roleList = roleService.selectByExample(troleExample);*/
resultmap.put("currpage", String.valueOf(pageRusult.getPageNum()));
resultmap.put("totalpages", String.valueOf(pageRusult.getPages()));
resultmap.put("totalrecords", String.valueOf(pageRusult.getTotal()));
resultmap.put("datamap", roleList);
return resultmap;
}
@ResponseBody
@RequestMapping(value = "/addupdaterole")
@RequiresPermissions(value = {"角色管理"})
public Map<String, Object> addupdaterole(Trole trole) {
LinkedHashMap<String, Object> resultmap = new LinkedHashMap<String, Object>();
try {
if (trole.getId() == null) {//新建
//首先判断用户名是否可用
Example troleExample = new Example(Trole.class);
troleExample.or().andEqualTo("name",trole.getName());
List<Trole> rolelist = roleService.selectByExample(troleExample);
if (rolelist != null && rolelist.size() > 0) {
resultmap.put("state", "fail");
resultmap.put("mesg", "当前角色名已存在");
return resultmap;
}
roleService.saveNotNull(trole);
} else {//编辑
Trole oldObject = roleService.selectByKey(trole.getId());
if (oldObject == null) {
resultmap.put("state", "fail");
resultmap.put("mesg", "当前角色名不存在");
return resultmap;
} else {
roleService.updateNotNull(trole);
}
}
resultmap.put("state", "success");
resultmap.put("mesg", "操作成功");
return resultmap;
} catch (Exception e) {
e.printStackTrace();
resultmap.put("state", "fail");
resultmap.put("mesg", "操作失败,系统异常");
return resultmap;
}
}
@ResponseBody
@RequestMapping(value = "/deleterole")
@RequiresPermissions(value = {"角色管理"})
public Map<String, Object> deleteuser(Trole trole) {
LinkedHashMap<String, Object> resultmap = new LinkedHashMap<String, Object>();
try {
if (trole.getId() != null && !trole.getId().equals(0)) {
Trole role = roleService.selectByKey(trole.getId());
if (role == null) {
resultmap.put("state", "fail");
resultmap.put("mesg", "删除失败,无法找到该记录");
return resultmap;
} else {
//还需删除用户角色中间表
Example tuserroleexample = new Example(Tuserrole.class);
tuserroleexample.or().andEqualTo("roleId",trole.getId());
userRoleService.deleteByExample(tuserroleexample);
Example trolemenuexample = new Example(Trolemenu.class);
trolemenuexample.or().andEqualTo("roleId",trole.getId());
trolemenuService.deleteByExample(trolemenuexample);
roleService.delete(trole.getId());
}
} else {
resultmap.put("state", "fail");
resultmap.put("mesg", "删除失败");
}
resultmap.put("state", "success");
resultmap.put("mesg", "删除成功");
return resultmap;
} catch (Exception e) {
e.printStackTrace();
resultmap.put("state", "fail");
resultmap.put("mesg", "删除失败,系统异常");
return resultmap;
}
}
@ResponseBody
@RequestMapping(value = "/selectRoleById")
@RequiresPermissions(value = {"角色管理"})
public Map<String, Object> selectRoleById(Trole trole) {
LinkedHashMap<String, Object> resultmap = new LinkedHashMap<String, Object>();
try {
if (trole.getId() != null && !trole.getId().equals(0)) {
trole = roleService.selectByKey(trole.getId());
if (trole == null) {
resultmap.put("state", "fail");
resultmap.put("mesg", "无法找到该记录");
return resultmap;
}
} else {
resultmap.put("state", "fail");
resultmap.put("mesg", "无法找到该记录的id");
return resultmap;
}
resultmap.put("trole", trole);
resultmap.put("state", "success");
resultmap.put("mesg", "获取成功");
return resultmap;
} catch (Exception e) {
e.printStackTrace();
resultmap.put("state", "fail");
resultmap.put("mesg", "获取失败,系统异常");
return resultmap;
}
}
/**
* 根据父节点获取所有复选框权限�
没有合适的资源?快使用搜索试试~ 我知道了~
管理系统系列--通用的java后台管理系统(权限管理+用户管理+菜单管理).zip
共460个文件
png:114个
js:103个
gif:81个
需积分: 5 0 下载量 172 浏览量
2024-02-24
22:38:30
上传
评论
收藏 2.72MB ZIP 举报
温馨提示
管理系统系列--通用的java后台管理系统(权限管理+用户管理+菜单管理)
资源推荐
资源详情
资源评论
收起资源包目录
管理系统系列--通用的java后台管理系统(权限管理+用户管理+菜单管理).zip (460个子文件)
mvnw.cmd 5KB
bootstrap.min.css 118KB
layui.css 59KB
font-awesome.css 37KB
jquery-ui.css 36KB
jquery-ui-1.8.16.custom.css 33KB
jquery-ui-1.8.16.custom.css 33KB
jquery-ui-1.8.16.custom.css 33KB
jquery-ui-1.8.16.custom.css 33KB
jquery-ui-1.8.20.custom.css 33KB
font-awesome.min.css 30KB
layuiGlobalForIcon.css 23KB
global.css 19KB
jquery-ui-1.8.16.custom.css 19KB
jquery-ui.theme.css 18KB
layer.css 14KB
ui.jqgrid.css 13KB
public.css 12KB
index.css 10KB
layui.mobile.css 10KB
awesome.css 8KB
laydate.css 7KB
metroStyle.css 6KB
zTreeStyle.css 6KB
demo.css 2KB
ui.multiselect.css 2KB
code.css 1KB
searchFilter.css 393B
fontawesome-webfont.eot 162KB
iconfont.eot 38KB
glyphicons-halflings-regular.eot 20KB
role.ftl 28KB
user.ftl 25KB
welcome.ftl 16KB
menu.ftl 15KB
login.ftl 7KB
updatePassword.ftl 3KB
common.ftl 1KB
main.ftl 960B
unauthorized.ftl 31B
errordeal.ftl 31B
59.gif 10KB
22.gif 10KB
24.gif 8KB
13.gif 7KB
16.gif 7KB
39.gif 6KB
64.gif 6KB
63.gif 6KB
50.gif 6KB
loading-0.gif 6KB
4.gif 6KB
zTreeStandard.gif 5KB
1.gif 5KB
42.gif 5KB
71.gif 5KB
21.gif 5KB
20.gif 5KB
29.gif 5KB
metro.gif 5KB
70.gif 4KB
5.gif 4KB
17.gif 4KB
27.gif 4KB
9.gif 4KB
44.gif 4KB
11.gif 4KB
8.gif 4KB
3.gif 4KB
23.gif 4KB
34.gif 4KB
41.gif 4KB
38.gif 4KB
65.gif 3KB
32.gif 3KB
45.gif 3KB
7.gif 3KB
12.gif 3KB
26.gif 3KB
60.gif 3KB
2.gif 3KB
40.gif 3KB
25.gif 3KB
19.gif 3KB
66.gif 3KB
18.gif 3KB
46.gif 3KB
10.gif 3KB
28.gif 3KB
51.gif 3KB
57.gif 3KB
67.gif 3KB
0.gif 3KB
48.gif 3KB
43.gif 3KB
30.gif 2KB
61.gif 2KB
33.gif 2KB
69.gif 2KB
14.gif 2KB
共 460 条
- 1
- 2
- 3
- 4
- 5
资源评论
Kwan的解忧杂货铺
- 粉丝: 1w+
- 资源: 3651
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功