mirror of
https://gitee.com/jamen/slife.git
synced 2026-10-24 11:03:39 +00:00
角色编辑
This commit is contained in:
@@ -32,8 +32,7 @@ import java.util.Map;
|
||||
@RequestMapping(value = "/sys/menu")
|
||||
public class SysMenuController extends BaseController{
|
||||
|
||||
@Autowired
|
||||
private SysRoleService sysRoleService;
|
||||
|
||||
@Autowired
|
||||
private ISysMenuService sysMenuService;
|
||||
|
||||
@@ -93,6 +92,12 @@ public class SysMenuController extends BaseController{
|
||||
return "redirect:/sys/menu";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置为不可用
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value="disable/{id}")
|
||||
@ResponseBody
|
||||
public ReturnDTO disable(@PathVariable("id") Long id){
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
package com.slife.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.slife.annotation.SLog;
|
||||
import com.slife.base.controller.BaseController;
|
||||
import com.slife.base.entity.ReturnDTO;
|
||||
import com.slife.base.vo.DataTable;
|
||||
import com.slife.entity.SysRole;
|
||||
import com.slife.entity.SysUser;
|
||||
import com.slife.service.ISysMenuService;
|
||||
import com.slife.service.impl.SysRoleService;
|
||||
import com.slife.util.ReturnDTOUtil;
|
||||
import com.slife.util.ServletUtils;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
@@ -15,6 +20,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -29,6 +35,8 @@ import java.util.Map;
|
||||
public class SysRoleController extends BaseController {
|
||||
@Autowired
|
||||
private SysRoleService sysRoleService;
|
||||
@Autowired
|
||||
private ISysMenuService sysMenuService;
|
||||
|
||||
/**
|
||||
* 进入系统角色列表
|
||||
@@ -38,12 +46,11 @@ public class SysRoleController extends BaseController {
|
||||
*/
|
||||
@GetMapping(value = "")
|
||||
public String list(Model model, HttpServletRequest request) {
|
||||
model.addAttribute("url", request.getContextPath()+"/sys/role/");
|
||||
model.addAttribute("url", request.getContextPath() + "/sys/role/");
|
||||
return "role/list";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@SLog("获角色列表")
|
||||
@ApiOperation(value = "获角色列表", notes = "获角色列表:使用约定的DataTable")
|
||||
@PostMapping(value = "/list")
|
||||
@@ -51,4 +58,96 @@ public class SysRoleController extends BaseController {
|
||||
public DataTable<SysRole> list(@RequestBody DataTable dt, ServletRequest request) {
|
||||
return sysRoleService.pageSearch(dt);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 进入创建角色界面
|
||||
*
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/insert")
|
||||
public String create(Model model, HttpServletRequest request) {
|
||||
SysRole sysRole = new SysRole();
|
||||
sysRole.setId(0L);
|
||||
model.addAttribute("action", "insert");
|
||||
model.addAttribute("role", sysRole);
|
||||
model.addAttribute("url", request.getContextPath() + "/sys/role/");
|
||||
model.addAttribute("menuTree", JSON.toJSONString(sysMenuService.getMenuTree()));
|
||||
return "role/detail";
|
||||
}
|
||||
|
||||
@ApiOperation(value = "创建角色操作", notes = "创建角色操作")
|
||||
@PostMapping(value = "/insert")
|
||||
@ResponseBody
|
||||
public ReturnDTO create(@Valid SysRole sysRole, @RequestParam(value = "ids", defaultValue = "") Long[] menuIds) {
|
||||
sysRole.setId(null);
|
||||
sysRoleService.insertSysRole(sysRole, menuIds);
|
||||
return ReturnDTOUtil.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测角色编码是否存在
|
||||
*
|
||||
* @param id
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "check/{id}")
|
||||
@ResponseBody
|
||||
public Boolean check(@PathVariable("id") Long id, @RequestParam("code") String code) {
|
||||
return sysRoleService.checkRoleCode(code, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看用户详情界面
|
||||
*
|
||||
* @param id
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/detail/{id}")
|
||||
public String detail(@PathVariable("id") Long id, Model model, HttpServletRequest request) {
|
||||
model.addAttribute("action", "detail");
|
||||
SysRole sysRole = sysRoleService.selectById(id);
|
||||
model.addAttribute("role", sysRole);
|
||||
model.addAttribute("menuTree", JSON.toJSONString(sysRoleService.selectMenuTreeHasSelectDis(id,true)));
|
||||
model.addAttribute("url", request.getContextPath() + "/sys/role/");
|
||||
return "role/detail";
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新角色界面
|
||||
*
|
||||
* @param id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
@GetMapping(value="update/{id}")
|
||||
public String updateForm(@PathVariable("id") Long id,Model model, HttpServletRequest request){
|
||||
model.addAttribute("action","update");
|
||||
SysRole sysRole = sysRoleService.selectById(id);
|
||||
model.addAttribute("role",sysRole);
|
||||
model.addAttribute("url", request.getContextPath() + "/sys/role/");
|
||||
model.addAttribute("menuTree", JSON.toJSONString(sysRoleService.selectMenuTreeHasSelectDis(id,false)));
|
||||
return "role/detail";
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "修改角色操作", notes = "修改角色操作")
|
||||
@PostMapping(value = "/update")
|
||||
@ResponseBody
|
||||
public ReturnDTO update(@Valid SysRole sysRole, @RequestParam(value = "ids", defaultValue = "") Long[] menuIds) {
|
||||
sysRoleService.insertSysRole(sysRole, menuIds);
|
||||
return ReturnDTOUtil.success();
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/tf")
|
||||
@ResponseBody
|
||||
public ReturnDTO tf() {
|
||||
sysRoleService.tf();
|
||||
return ReturnDTOUtil.success();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ public class SysUserController extends BaseController {
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "update/{id}")
|
||||
@GetMapping(value = "update/{id}")
|
||||
public String update(@PathVariable("id") Long id, Model model,HttpServletRequest request) {
|
||||
model.addAttribute("action", "update");
|
||||
model.addAttribute("url", request.getContextPath() + "/sys/user/");
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.slife.dao;
|
||||
|
||||
import com.slife.base.dao.CrudDao;
|
||||
import com.slife.entity.SysRoleMenu;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chen
|
||||
* @date 2017/10/26
|
||||
* <p>
|
||||
* Email 122741482@qq.com
|
||||
* <p>
|
||||
* Describe:
|
||||
*/
|
||||
@Component
|
||||
public interface SysRoleMenuDao extends CrudDao<SysRoleMenu> {
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.slife.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotations.TableField;
|
||||
import com.baomidou.mybatisplus.annotations.TableName;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author chen
|
||||
* @date 2017/10/26
|
||||
* <p>
|
||||
* Email 122741482@qq.com
|
||||
* <p>
|
||||
* Describe: 角色 菜单 表
|
||||
*/
|
||||
@TableName("sys_role_sys_menu")
|
||||
public class SysRoleMenu implements Serializable {
|
||||
private static final long serialVersionUID = -3876781931176875589L;
|
||||
|
||||
public SysRoleMenu() {
|
||||
|
||||
}
|
||||
|
||||
public SysRoleMenu(Long sysMenuId, Long sysRoleId) {
|
||||
this.sysMenuId = sysMenuId;
|
||||
this.sysRoleId = sysRoleId;
|
||||
}
|
||||
|
||||
@TableField(value = "sys_menu_id")
|
||||
private Long sysMenuId;
|
||||
|
||||
@TableField(value = "sys_role_id")
|
||||
private Long sysRoleId;
|
||||
|
||||
public Long getSysRoleId() {
|
||||
return sysRoleId;
|
||||
}
|
||||
|
||||
public void setSysRoleId(Long sysRoleId) {
|
||||
this.sysRoleId = sysRoleId;
|
||||
}
|
||||
|
||||
public Long getSysMenuId() {
|
||||
return sysMenuId;
|
||||
}
|
||||
|
||||
public void setSysMenuId(Long sysMenuId) {
|
||||
this.sysMenuId = sysMenuId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.slife.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
||||
import com.slife.dao.SysRoleMenuDao;
|
||||
import com.slife.entity.SysRoleMenu;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chen
|
||||
* @date 2017/10/26
|
||||
* <p>
|
||||
* Email 122741482@qq.com
|
||||
* <p>
|
||||
* Describe:
|
||||
*/
|
||||
@Service
|
||||
@Transactional(readOnly = true, rollbackFor = Exception.class)
|
||||
public class SysRoleMenuService extends ServiceImpl<SysRoleMenuDao, SysRoleMenu> {
|
||||
}
|
||||
@@ -2,35 +2,91 @@ package com.slife.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.mapper.Condition;
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.baomidou.mybatisplus.toolkit.ArrayUtils;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.slife.base.service.impl.BaseService;
|
||||
import com.slife.base.vo.DataTable;
|
||||
import com.slife.base.vo.JsTree;
|
||||
import com.slife.base.vo.JsTreeState;
|
||||
import com.slife.constant.Global;
|
||||
import com.slife.dao.SysRoleDao;
|
||||
import com.slife.entity.SysMenu;
|
||||
import com.slife.entity.SysRole;
|
||||
import com.slife.entity.SysRoleMenu;
|
||||
import com.slife.entity.SysUserRole;
|
||||
import com.slife.vo.SysRoleVO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Created by chen on 2017/4/24.
|
||||
* @author chen
|
||||
* @date 2017/4/24
|
||||
* <p>
|
||||
* Email 122741482@qq.com
|
||||
* <p>
|
||||
* Describe: sys 角色 服务
|
||||
*/
|
||||
@Service
|
||||
@Transactional(readOnly = true)
|
||||
@Transactional(readOnly = true, rollbackFor = Exception.class)
|
||||
public class SysRoleService extends BaseService<SysRoleDao, SysRole> {
|
||||
|
||||
@Autowired
|
||||
private SysUserRoleService sysUserRoleService;
|
||||
@Autowired
|
||||
private SysRoleMenuService sysRoleMenuService;
|
||||
@Autowired
|
||||
private SysMenuService sysMenuService;
|
||||
|
||||
@Autowired
|
||||
private SysRoleDao sysRoleDao;
|
||||
|
||||
/**
|
||||
* 获取角色选中的菜单树
|
||||
*
|
||||
* @param roleId
|
||||
* @return
|
||||
*/
|
||||
public List<JsTree> selectMenuTreeHasSelectDis(Long roleId,Boolean disable) {
|
||||
|
||||
List<SysRoleMenu> sysRoleMenus = sysRoleMenuService.selectList(Condition.create().eq("sys_role_id", roleId));
|
||||
|
||||
Map<Long, Long> map = Maps.newHashMap();
|
||||
sysRoleMenus.stream().parallel().forEach(sysRoleMenu -> map.put(sysRoleMenu.getSysMenuId(), sysRoleMenu.getSysMenuId()));
|
||||
|
||||
List<SysMenu> list = sysMenuService.selectList(null);
|
||||
|
||||
List<JsTree> jts = list.stream().parallel().map(sysMenu -> {
|
||||
JsTree jt = new JsTree();
|
||||
jt.setId(sysMenu.getId().toString());
|
||||
jt.setParent(sysMenu.getParentId() == null ? "#" : (sysMenu.getParentId().compareTo(0L) > 0 ? sysMenu.getParentId()
|
||||
.toString() : "#"));
|
||||
jt.setText(sysMenu.getName());
|
||||
JsTreeState jtState = new JsTreeState();
|
||||
if (disable){
|
||||
jtState.setDisabled(disable);
|
||||
}
|
||||
|
||||
//一级节点除了主页,都是未选中状态
|
||||
if ((sysMenu.getParentId() == null || 0L == sysMenu.getParentId()) && !"/index".equalsIgnoreCase(sysMenu.getHref())) {
|
||||
jtState.setSelected(false);
|
||||
} else {
|
||||
jtState.setSelected(map.get(sysMenu.getId()) != null);
|
||||
}
|
||||
jt.setState(jtState);
|
||||
return jt;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
return jts;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户的角色和菜单
|
||||
@@ -95,25 +151,62 @@ public class SysRoleService extends BaseService<SysRoleDao, SysRole> {
|
||||
* @param userId
|
||||
* @param ids
|
||||
*/
|
||||
@Transactional(readOnly = false)
|
||||
@Transactional(readOnly = false, rollbackFor = Exception.class)
|
||||
public void insertSysRole(Long userId, Long[] ids) {
|
||||
|
||||
//删除现有的用户角色
|
||||
sysUserRoleService.delete(Condition.create().eq("sys_user_id", userId));
|
||||
if (null != ids && ids.length > 0) {
|
||||
|
||||
/* List<SysUserRole> sysUserRoles = new ArrayList<SysUserRole>();
|
||||
for (Long roleId : ids) {
|
||||
sysUserRoles.add(new SysUserRole(userId, roleId));
|
||||
}*/
|
||||
|
||||
List<SysUserRole> sysUserRoles =Arrays.stream(ids).parallel().map(roleId->{
|
||||
return new SysUserRole(userId, roleId);
|
||||
List<SysUserRole> sysUserRoles = Arrays.stream(ids).parallel().map(roleId -> {
|
||||
return new SysUserRole(userId, roleId);
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
|
||||
//保存用户角色
|
||||
sysUserRoleService.insertBatch(sysUserRoles);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(readOnly = false, rollbackFor = Exception.class)
|
||||
public void tf() {
|
||||
SysRole s=new SysRole();
|
||||
s.setName("ddddd");
|
||||
this.baseMapper.insert(s);
|
||||
double d=1/0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存角色和对应的菜单
|
||||
*
|
||||
* @param sysRole
|
||||
* @param menuIds
|
||||
*/
|
||||
@Transactional(readOnly = false, rollbackFor = Exception.class)
|
||||
public void insertSysRole(SysRole sysRole, Long[] menuIds) {
|
||||
|
||||
insertOrUpdate(sysRole);
|
||||
Long roleId = sysRole.getId();
|
||||
//删除现有的 角色 菜单
|
||||
sysRoleMenuService.delete(Condition.create().eq("sys_role_id", roleId));
|
||||
if (null != menuIds && menuIds.length > 0) {
|
||||
List<SysRoleMenu> sysRoleMenu = Arrays.stream(menuIds).parallel().map(menuId -> {
|
||||
return new SysRoleMenu(menuId, roleId);
|
||||
}).collect(Collectors.toList());
|
||||
//角色关联的菜单
|
||||
sysRoleMenuService.insertBatch(sysRoleMenu);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测角色编码是否存在
|
||||
*
|
||||
* @param code
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public Boolean checkRoleCode(String code, Long id) {
|
||||
SysRole sysRole = selectOne(Condition.create().eq("code", code));
|
||||
return sysRole == null || !id.equals(0L) && sysRole.getId().equals(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,13 +7,15 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Created by chen on 2017/9/1.
|
||||
*
|
||||
* @author chen
|
||||
* @date 2017/9/1
|
||||
* <p>
|
||||
* Email 122741482@qq.com
|
||||
* <p>
|
||||
* Describe: 系统用户角色中间表
|
||||
*/
|
||||
@Service
|
||||
@Transactional(readOnly = true)
|
||||
@Transactional(readOnly = true, rollbackFor = Exception.class)
|
||||
public class SysUserRoleService extends ServiceImpl<SysUserRoleDao, SysUserRole> {
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
|
||||
</div>
|
||||
<div class="portlet-body form" id="menu_edit_table">
|
||||
<form id="resourceForm" action="${base}/sys/menu/insert" class="form-horizontal form-bordered"
|
||||
<form id="menuForm" action="${base}/sys/menu/insert" class="form-horizontal form-bordered"
|
||||
method="POST">
|
||||
<input type="hidden" name="id"/>
|
||||
<input type="hidden" name="parentId" value="0"/>
|
||||
@@ -271,7 +271,7 @@
|
||||
<script type="text/javascript">
|
||||
|
||||
|
||||
var form = $('#resourceForm'), rid, text;
|
||||
var form = $('#menuForm'), menuid, text;
|
||||
$("#resTree").jstree({
|
||||
"core": {
|
||||
"animation": 0,
|
||||
@@ -317,7 +317,7 @@
|
||||
$("select[name=showFlag] option[value='" + data.showFlag + "']").attr("selected", "selected");
|
||||
$("select[name=showFlag] option[value!='" + data.showFlag + "']").attr("selected", false);
|
||||
|
||||
$('#resourceForm :input').each(function (a) {
|
||||
$('#menuForm :input').each(function (a) {
|
||||
$(this).attr('disabled', "disabled");
|
||||
$(this).attr("readonly", "true");
|
||||
});
|
||||
@@ -325,6 +325,8 @@
|
||||
$('.btn-children').enable();
|
||||
$('.btn-edit').enable();
|
||||
$('.btn-delete').enable();
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -370,7 +372,7 @@
|
||||
form.resetForm();
|
||||
$('input[name=id]').val("");
|
||||
$('input[name=parentId]').val(0);
|
||||
$('#resourceForm :input').each(function (a) {
|
||||
$('#menuForm :input').each(function (a) {
|
||||
$(this).enable();
|
||||
$(this).attr("readonly", false);
|
||||
});
|
||||
@@ -382,7 +384,7 @@
|
||||
form.resetForm();
|
||||
$('input[name=id]').val("");
|
||||
$('input[name=parentId]').val(menuid);
|
||||
$('#resourceForm :input').each(function (a) {
|
||||
$('#menuForm :input').each(function (a) {
|
||||
$(this).enable();
|
||||
$(this).attr("readonly", false);
|
||||
});
|
||||
@@ -390,14 +392,14 @@
|
||||
$('.btn-delete').attr('disabled', "disabled");
|
||||
});
|
||||
$('.btn-edit').click(function () {
|
||||
$('#resourceForm :input').each(function (a) {
|
||||
$('#menuForm :input').each(function (a) {
|
||||
$(this).enable();
|
||||
$(this).attr("readonly", false);
|
||||
|
||||
});
|
||||
});
|
||||
$('.btn-cancel').click(function () {
|
||||
$('#resourceForm :input').each(function (a) {
|
||||
$('#menuForm :input').each(function (a) {
|
||||
$(this).attr('disabled', "disabled");
|
||||
$(this).attr("readonly", "true");
|
||||
});
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>系统用户编辑</title>
|
||||
|
||||
<link href="${base}/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
|
||||
<link href="${base}/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
|
||||
<link href="${base}/css/animate.css" rel="stylesheet">
|
||||
<link href="${base}/css/style.css?v=4.1.0" rel="stylesheet">
|
||||
<link href="${base}/css/slife.css" rel="stylesheet">
|
||||
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="${base}/css/plugins/jsTree/style.min.css"/>
|
||||
<!-- 全局js -->
|
||||
<script src="${base}/js/jquery.min.js?v=2.1.4"></script>
|
||||
<script src="${base}/js/bootstrap.min.js?v=3.3.6"></script>
|
||||
<script src="${base}/js/plugins/validate/jquery.validate.min.js"></script>
|
||||
<script src="${base}/js/plugins/validate/messages_zh.min.js"></script>
|
||||
<script src="${base}/js/plugins/layer/layer.min.js"></script>
|
||||
<script src="${base}/js/jquery.form.js"></script>
|
||||
|
||||
|
||||
<script>
|
||||
var url = "${url}", action = "${action}";
|
||||
|
||||
</script>
|
||||
<script src="${base}/js/slife/slife.js"></script>
|
||||
<script src="${base}/js/slife/slifeform.js"></script>
|
||||
</head>
|
||||
|
||||
<body class="gray-bg">
|
||||
<div class="wrapper wrapper-content animated fadeInRight">
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<div class="ibox float-e-margins">
|
||||
<div class="ibox-content">
|
||||
|
||||
<form class="form-horizontal form-bordered" id="slifeForm">
|
||||
|
||||
<input type="hidden" name="id" value="${role.id}"/>
|
||||
<input type="hidden" name="ids"/>
|
||||
|
||||
<div class="form-body">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">名称<span class="required">*</span></label>
|
||||
|
||||
<div class="col-sm-8">
|
||||
<input type="text" class="form-control" placeholder="录入权限名称" name="name"
|
||||
value="${role.name}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">编码<span class="required">*</span></label>
|
||||
|
||||
<div class="col-sm-8">
|
||||
<input type="text" class="form-control" placeholder="录入角色编码" name="code"
|
||||
value="${role.code}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">状态<span class="required">*</span></label>
|
||||
|
||||
<div class="col-sm-8">
|
||||
<select name="useable" class="form-control">
|
||||
<option value="Y">启用</option>
|
||||
<option value="N">禁用</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">描述</label>
|
||||
|
||||
<div class="col-sm-8">
|
||||
<textarea name="remark" type="text" class="form-control"
|
||||
placeholder="请输入角色描述">${role.remark}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">菜单树</label>
|
||||
|
||||
<div class="col-sm-8">
|
||||
<div id="menuTree"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<#if action !='detail'>
|
||||
<div class="form-actions fluid">
|
||||
<div class="col-md-offset-3 col-md-9">
|
||||
<button type="submit" class="btn green">保存</button>
|
||||
</div>
|
||||
</div>
|
||||
</#if>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="${base}/js/plugins/jsTree/jstree.js" type="text/javascript"></script>
|
||||
<script type="text/javascript">
|
||||
var tree = $("#menuTree").jstree({
|
||||
"checkbox": {"keep_selected_style": false},
|
||||
"core": {
|
||||
"multiple": true,
|
||||
"animation": 0,
|
||||
"themes": {
|
||||
theme: "classic",
|
||||
"dots": true,
|
||||
"icons": true
|
||||
},
|
||||
"check_callback": true,
|
||||
'data':${menuTree}
|
||||
},
|
||||
"plugins": ["wholerow", "checkbox"],
|
||||
});
|
||||
|
||||
|
||||
$("select[name=useable] option[value='${role.useable}']").attr("selected", "selected");
|
||||
|
||||
|
||||
/**
|
||||
* 标志选择了的菜单
|
||||
*/
|
||||
function selectMenuId() {
|
||||
var array = $.jstree.reference('#menuTree').get_selected(true);
|
||||
var ar = new Array();
|
||||
if (array) {
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
var a = array[i]
|
||||
ar.push(a.id);
|
||||
if (a.parent != "#") {
|
||||
ar.push(a.parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
$('input[name=ids]').val(ar.join(","));
|
||||
}
|
||||
|
||||
function cusFunction() {
|
||||
selectMenuId();
|
||||
}
|
||||
|
||||
var form = $('#slifeForm');
|
||||
var error = $('.alert-danger', form);
|
||||
form.validate({
|
||||
errorElement: 'span',
|
||||
errorClass: 'error',
|
||||
focusInvalid: true,
|
||||
messages: {
|
||||
code: {remote: "角色编码已存在"}
|
||||
},
|
||||
rules: {
|
||||
code: {
|
||||
maxlength: 64,
|
||||
required: true,
|
||||
remote: '${base}/sys/role/check/${role.id}'
|
||||
},
|
||||
name: {
|
||||
maxlength: 64,
|
||||
required: true
|
||||
},
|
||||
active: {
|
||||
required: true
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -24,7 +24,7 @@
|
||||
<input type="text" class="form-filter input-sm _search" name="search_like_name">
|
||||
</label>
|
||||
<label style="margin-left: 10px;">
|
||||
角色代码:
|
||||
角色编码:
|
||||
<input type="text" class="form-filter input-sm _search" name="search_like_code">
|
||||
</label>
|
||||
<label style="margin-left: 10px;">
|
||||
@@ -43,7 +43,7 @@
|
||||
<button type="button" class="btn btn-danger" onclick="batch_remove()">
|
||||
<i class="fa fa-trash" aria-hidden="true"></i>删除
|
||||
</button>
|
||||
<button type="button" class="btn btn-info" onclick="add()">
|
||||
<button type="button" class="btn btn-info" onclick="dt_insert()">
|
||||
<i class="fa fa-plus-square" aria-hidden="true"></i>添加
|
||||
</button>
|
||||
</label>
|
||||
@@ -87,7 +87,7 @@
|
||||
},
|
||||
{
|
||||
field: 'code',
|
||||
title: '代码'
|
||||
title: '编码'
|
||||
},
|
||||
|
||||
{
|
||||
|
||||
@@ -176,6 +176,9 @@
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
function cusFunction() {
|
||||
console.info("提交之前,最后执行自定义的函数");
|
||||
}
|
||||
|
||||
/**
|
||||
* 错误图片的默认处理
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.slife;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@MapperScan(value = {"com.slife.dao"}) //@Mapper 在mapper 接口上加入也行
|
||||
@SpringBootApplication
|
||||
|
||||
@@ -24,7 +24,8 @@ public class DataSourceAop {
|
||||
logger.info("dataSource切换到:Read");
|
||||
}
|
||||
|
||||
@Before("execution(* com.slife.dao..*.insert*(..)) || execution(* com.slife.dao..*.update*(..))")
|
||||
@Before("execution(* com.slife.dao..*.insert**(..)) || execution(* com.slife.dao..*.update*(..)) || execution(* " +
|
||||
"com.slife.dao..*.delete*(..))")
|
||||
public void setWriteDataSourceType() {
|
||||
DataSourceContextHolder.write();
|
||||
logger.info("dataSource切换到:write");
|
||||
|
||||
@@ -79,15 +79,7 @@ public class DruidAutoConfiguration {
|
||||
}
|
||||
|
||||
|
||||
@Bean(name = "writeDataSource1")
|
||||
@Primary
|
||||
// @ConfigurationProperties(prefix = "writedatasource")
|
||||
public DataSource writeDataSource() {
|
||||
logger.info("-------------------- writeDataSource init ---------------------");
|
||||
// return DataSourceBuilder.create().type(dataSourceType).build();
|
||||
|
||||
return dataSource(writeProperties);
|
||||
}
|
||||
|
||||
/**
|
||||
* 有多少个从库就要配置多少个
|
||||
@@ -98,7 +90,6 @@ public class DruidAutoConfiguration {
|
||||
// @ConfigurationProperties(prefix = "readdatasource01")
|
||||
public DataSource readDataSourceOne() {
|
||||
logger.info("-------------------- readDataSourceOne init ---------------------");
|
||||
// DataSource dataSource= DataSourceBuilder.create().type(dataSourceType).build();
|
||||
return dataSource(readProperties1);
|
||||
}
|
||||
|
||||
@@ -106,7 +97,6 @@ public class DruidAutoConfiguration {
|
||||
// @ConfigurationProperties(prefix = "readdatasource02")
|
||||
public DataSource readDataSourceTwo() {
|
||||
logger.info("-------------------- readDataSourceTwo init ---------------------");
|
||||
// return DataSourceBuilder.create().type(dataSourceType).build();
|
||||
return dataSource(readProperties2);
|
||||
}
|
||||
|
||||
@@ -117,4 +107,11 @@ public class DruidAutoConfiguration {
|
||||
dataSources.add(readDataSourceTwo());
|
||||
return dataSources;
|
||||
}
|
||||
|
||||
@Bean(name = "writeDataSource1")
|
||||
@Primary
|
||||
public DataSource writeDataSource() {
|
||||
logger.info("-------------------- writeDataSource init ---------------------");
|
||||
return dataSource(writeProperties);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,12 +90,10 @@ public class MybatisPlusConfig {
|
||||
@Bean
|
||||
public MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean() {
|
||||
MybatisSqlSessionFactoryBean mybatisPlus = new MybatisSqlSessionFactoryBean();
|
||||
//mybatisPlus.setDataSource(dataSource);
|
||||
|
||||
mybatisPlus.setDataSource(roundRobinDataSouceProxy());
|
||||
|
||||
|
||||
mybatisPlus.setVfs(SpringBootVFS.class);
|
||||
|
||||
if (StringUtils.hasText(this.properties.getConfigLocation())) {
|
||||
mybatisPlus.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation()));
|
||||
}
|
||||
@@ -140,10 +138,10 @@ public class MybatisPlusConfig {
|
||||
|
||||
BlifeAbstractRoutingDataSource proxy = new BlifeAbstractRoutingDataSource(size);
|
||||
Map<Object, Object> targetDataSources = new HashMap<Object, Object>();
|
||||
// DataSource writeDataSource = SpringContextHolder.getBean("writeDataSource");
|
||||
|
||||
// 写
|
||||
targetDataSources.put(DataSourceType.write.getType(),writeDataSource);
|
||||
// targetDataSources.put(DataSourceType.read.getType(),readDataSource);
|
||||
|
||||
//多个读数据库时
|
||||
for (int i = 0; i < size; i++) {
|
||||
targetDataSources.put(i, readDataSources.get(i));
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -7,7 +7,7 @@ $.validator.setDefaults({
|
||||
* 提交表单
|
||||
*/
|
||||
function saveForm() {
|
||||
|
||||
cusFunction();
|
||||
$.ajax({
|
||||
cache: true,
|
||||
type: "POST",
|
||||
|
||||
Reference in New Issue
Block a user