角色管理添加并且添加接口 使用vo来在前台取出

/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.winchampion.credit.platform.modules.planset.web;


import java.util.ArrayList;
import java.util.List;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;


import com.winchampion.credit.platform.common.config.Global;
import com.winchampion.credit.platform.common.persistence.Page;
import com.winchampion.credit.platform.common.web.BaseController;
import com.winchampion.credit.platform.common.utils.StringUtils;
import com.winchampion.credit.platform.modules.planset.entity.InterfaceSelectedVo;
import com.winchampion.credit.platform.modules.planset.entity.PermInterfaceInfo;
import com.winchampion.credit.platform.modules.planset.entity.PermInterfaceRoleRef;
import com.winchampion.credit.platform.modules.planset.entity.PermRole;
import com.winchampion.credit.platform.modules.planset.service.PermInterfaceInfoService;
import com.winchampion.credit.platform.modules.planset.service.PermInterfaceRoleRefService;
import com.winchampion.credit.platform.modules.planset.service.PermRoleService;


/**
 * 设置角色和其关联用户关联接口Controller
 * @author daisylee
 * @version 2016-07-07
 */
@Controller
@RequestMapping(value = "${adminPath}/planset/permRole")
public class PermRoleController extends BaseController {


@Autowired
private PermRoleService permRoleService;
@Autowired 
private PermInterfaceRoleRefService permInterfaceRoleRefService;
@Autowired 
PermInterfaceInfoService permInterfaceInfoService;

@ModelAttribute
public PermRole get(@RequestParam(required=false) String id) {
PermRole entity = null;
if (StringUtils.isNotBlank(id)){
entity = permRoleService.get(id);
}
if (entity == null){
entity = new PermRole();
}
return entity;
}

@RequiresPermissions("planset:permRole:view")
@RequestMapping(value = {"list", ""})
public String list(PermRole permRole, HttpServletRequest request, HttpServletResponse response, Model model) {
Page<PermRole> page = permRoleService.findPage(new Page<PermRole>(request, response), permRole); 
model.addAttribute("page", page);
return "modules/planset/permRoleList";
}

@RequiresPermissions("planset:permRole:view")
@RequestMapping(value = "form")
public String form(PermRole permRole, Model model) {
model.addAttribute("permRole", permRole);
String type=permRole.getRoleType();
PermInterfaceInfo permInterfaceInfo=new PermInterfaceInfo();
permInterfaceInfo.setInterfaceNature(type);
List<PermInterfaceInfo> permInterfaceInfolist=permInterfaceInfoService.findList(permInterfaceInfo);//获取类型为对内或者对外的所有接口信息
//model.addAttribute("permInterfaceInfolist",permInterfaceInfolist);

List<InterfaceSelectedVo> volists=new ArrayList<InterfaceSelectedVo>();
if(StringUtils.isNotBlank(permRole.getId())){//如果是修改而不是新增
PermInterfaceRoleRef permInterfaceRoleRef=new PermInterfaceRoleRef();
permInterfaceRoleRef.setRoleId(permRole.getId());
List<PermInterfaceRoleRef> permInterfaceRoleRefLists=permInterfaceRoleRefService.findList(permInterfaceRoleRef);//所有应该被选中的集合
// model.addAttribute("permInterfaceInfolist",permInterfaceInfolist);
// model.addAttribute("permInterfaceRoleRefLists",permInterfaceRoleRefLists);

if(permInterfaceRoleRefLists.size()>0){
List<String> interfacesSelectedList=new ArrayList<String>();
for(PermInterfaceRoleRef p:permInterfaceRoleRefLists){
interfacesSelectedList.add(p.getInterfaceId());
}
for(PermInterfaceInfo pi:permInterfaceInfolist){
InterfaceSelectedVo interfaceSelectedVo=new InterfaceSelectedVo();
interfaceSelectedVo.setPermInterfaceInfo(pi);
if(interfacesSelectedList.contains(pi.getId()) ){
interfaceSelectedVo.setIsSelected(true);
}
else{
interfaceSelectedVo.setIsSelected(false);
}
volists.add(interfaceSelectedVo);
}
model.addAttribute("volists",volists);
}
}
else{
for(PermInterfaceInfo pio:permInterfaceInfolist){
InterfaceSelectedVo interfaceSelectedVo=new InterfaceSelectedVo();
//interfaceSelectedVo.
interfaceSelectedVo.setPermInterfaceInfo(pio);
interfaceSelectedVo.setIsSelected(false);
volists.add(interfaceSelectedVo);
}
model.addAttribute("volists",volists);
}
return "modules/planset/permRoleForm";//?roleType="+type
}


@RequiresPermissions("planset:permRole:edit")
@RequestMapping(value = "save")
public String save(PermRole permRole, Model model, RedirectAttributes redirectAttributes, HttpServletRequest request) {
if (!beanValidator(model, permRole)){
return form(permRole, model);
}
if(StringUtils.isNotBlank(permRole.getId())){//有用户,不是新增是更新
String permRoleid=permRole.getId();
PermInterfaceRoleRef permInterfaceRoleRef=new PermInterfaceRoleRef();
permInterfaceRoleRef.setRoleId(permRoleid);
permInterfaceRoleRefService.deleteByRole(permRoleid);
//发现只删除了该角色的角色接口表,没有保存新的联系
}
String[] lists=request.getParameterValues("interface");//或者用list new Arraylist
if(lists!=null){
for(String s:lists){
System.err.println(s);
PermInterfaceRoleRef permInterfaceRoleRef=new PermInterfaceRoleRef();
permInterfaceRoleRef.setRoleId(permRole.getId());
permInterfaceRoleRef.setInterfaceId(s);
permInterfaceRoleRefService.save(permInterfaceRoleRef);
}
}
// step 2 保存角色
permRoleService.save(permRole);
addMessage(redirectAttributes, "保存角色设置管理生产成功成功");
return "redirect:"+Global.getAdminPath()+"/planset/permRole/list?repage&roleType="+permRole.getRoleType();
//return "redirect:"+Global.getAdminPath()+"/planset/permInterfaceRoleRef/?repage";
}

@RequiresPermissions("planset:permRole:edit")
@RequestMapping(value = "delete")
public String delete(PermRole permRole, RedirectAttributes redirectAttributes) {
permRoleService.delete(permRole);
addMessage(redirectAttributes, "删除角色设置管理生产成功成功");
return "redirect:"+Global.getAdminPath()+"/planset/permRole/list?repage&roleType="+permRole.getRoleType();
}

}


<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>角色设置管理生产成功管理</title>
<meta name="decorator" content="default"/>
<script type="text/javascript">
$(document).ready(function() {
//$("#name").focus();
$("#inputForm").validate({
submitHandler: function(form){
loading('正在提交,请稍等...');
form.submit();
},
errorContainer: "#messageBox",
errorPlacement: function(error, element) {
$("#messageBox").text("输入有误,请先更正。");
if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
error.appendTo(element.parent().parent());
} else {
error.insertAfter(element);
}
}
});
});


//接口全选
function selectAll(){
$("input[name='interface']:checkbox").each(function(){ 
                $(this).attr("checked",true);
            })
}


//保存关系
function relateFun(){
var interfaces="";
var accessCounts = "";
$("input[name='interface']:checkbox").each(function(){ 
                if($(this).attr("checked")){
                interfaces += $(this).val()+",";
                var checkedId = $(this).attr("id");
                alert(checkedId);
                //accessCounts += checkedId+":"+$('#'+checkedId+'_count').val()+",";
                }
            })
            alert(interfaces);
        
}
</script>
</head>
<body>
<ul class="nav nav-tabs">
<c:choose>
<c:when test="${permRole.roleType=='1'}">
<li><a href="${ctx}/planset/permRole/list?roleType=${permRole.roleType}">Zealot角色设置</a></li>
<li class="active"><a href="${ctx}/planset/permRole/form?roleType=${permRole.roleType}">Zealot角色管理添加</a></li>
</c:when>
<c:otherwise>
<li><a href="${ctx}/planset/permRole/list?roleType=${permRole.roleType}">Zither角色设置</a></li>
<shiro:hasPermission name="planset:permRole:edit"><li  class="active"><a href="${ctx}/planset/permRole/form?roleType=${PermRole.roleType}">Zither角色管理添加</a></li></shiro:hasPermission>
</c:otherwise>
</c:choose>
</ul><br/>
<form:form id="inputForm" modelAttribute="permRole" action="${ctx}/planset/permRole/save" method="post" class="form-horizontal">
<form:hidden path="id"/>
<sys:message content="${message}"/>

<div class="control-group">
<label class="control-label">角色名称:</label>
<div class="controls">
<form:input path="roleName" htmlEscape="false" maxlength="50" class="input-xlarge "/>
</div>
</div>
<div class="control-group">
<label class="control-label">描述:</label>
<div class="controls">
<form:input path="roleDesc" htmlEscape="false" maxlength="100" class="input-xlarge "/>
<form:hidden path="roleType" value="${roleType}"/>
</div>
</div>

<!-- 搜索接口 -->
<%-- 
<form:form id="searchForm" modelAttribute="permRole" action="${ctx}/planset/permRole/" method="post" class="breadcrumb form-search">
<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
<ul class="ul-form">
<li><label>接口编码:</label>
<form:input path="switchName" htmlEscape="false" maxlength="50" class="input-medium"/>
</li>
<li><label>接口URL:</label>
<form:input path="switchCode" htmlEscape="false" maxlength="50" class="input-medium"/>
</li>
<li><label>接口名称</label> 
<form:select path="onOrOff" class="input-medium" maxlength="30">
     <form:option value="" label="请选择"/>
 <form:option value="1"label="开启"></form:option>
     <form:option value="0"label="关闭"></form:option>
</form:select>
</li>
<li><label>开关类型</label>
<form:select path="switchType" class="input-medium" maxlength="30">
     <form:option value="" label="请选择"/>
     <form:option value="1"label="本地接口开关"></form:option>
 <form:option value="3"label="第三方接口开关"></form:option>
</form:select>
</li>
<li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/></li>
<li class="btns"><input id="btnClearCache" class="btn btn-primary" type="button"  value="清空缓存" onclick="clearCache()"></li>
</ul>
</form:form>
--%>

<div class="control-group">
<table id="contentTable" class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>选项</th>
<th>接口编码</th>
<th>接口序号</th>
<th>接口名称</th>
<th>接口URL</th>
<th>接口描述</th>
<th>接口状态</th>
<th>接口性质</th>
<th>接口类型</th>
<th>接口来源</th>
<!--<th>接口业务类型</th>-->
</tr>
</thead>
<tbody>

<c:forEach items="${volists}" var="vo">
<tr>
<td>
<c:choose>
<c:when test="${vo.isSelected==true}">
<input type="checkbox"  checked="checked" value="${vo.permInterfaceInfo.id}" name="interface" >
</c:when>
<c:otherwise>
<input type="checkbox" value="${vo.permInterfaceInfo.id}" name="interface" >
</c:otherwise>
</c:choose> 
</td>
<td style="text-align: center">
${vo.permInterfaceInfo.interfaceCode}
</td>
<td style="text-align: center">
${vo.permInterfaceInfo.interfaceSort}
</td>
<td style="text-align: center">
${vo.permInterfaceInfo.interfaceName}
</td>
<td style="text-align: center">
${vo.permInterfaceInfo.interfaceUrlCode}
</td>
<td style="text-align: center">
${vo.permInterfaceInfo.interfaceDesc}
</td>
<td style="text-align: center">
${vo.permInterfaceInfo.interfaceStatus}
</td>
<td style="text-align: center">
${vo.permInterfaceInfo.interfaceNature}
</td>
<td style="text-align: center">
${vo.permInterfaceInfo.interfaceType}
</td>
<td style="text-align: center">
${vo.permInterfaceInfo.interfaceSource}
</td>
<%--<td>
<input type="text" id="${vo.permInterfaceInfo.id}_count" value="0" style="width:50px">
</td> --%>
</tr>
</c:forEach>
</tbody>
</table>
</div>
<div class="form-actions">
<input id="selectAllBtn" class="btn"type="button" value="全选" onclick="selectAll()"/>&nbsp;&nbsp;&nbsp;&nbsp;
<shiro:hasPermission name="planset:permRole:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>

<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
</div>
</form:form>
</body>
</html>


你可能感兴趣的:(角色管理添加并且添加接口 使用vo来在前台取出)