GroupPrivilegesController.java 4.8 KB
Newer Older
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 

M
authn  
MaxKey 已提交
18
package org.maxkey.web.access.contorller;
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
19 20

import org.apache.mybatis.jpa.persistence.JpaPageResults;
M
v 3.3.0  
MaxKey 已提交
21
import org.maxkey.constants.ConstsOperateMessage;
M
MaxKey 已提交
22 23
import org.maxkey.entity.GroupPrivileges;
import org.maxkey.entity.apps.Apps;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
24
import org.maxkey.persistence.service.GroupPrivilegesService;
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
import org.maxkey.web.WebContext;
import org.maxkey.web.message.Message;
import org.maxkey.web.message.MessageType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;


@Controller
M
authn  
MaxKey 已提交
41
@RequestMapping(value={"/access/privileges"})
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
42 43 44 45
public class GroupPrivilegesController {
	final static Logger _logger = LoggerFactory.getLogger(GroupPrivilegesController.class);
	
	@Autowired
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
46 47
	@Qualifier("groupPrivilegesService")
	GroupPrivilegesService groupPrivilegesService;
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
48 49 50 51 52 53 54

	
	@RequestMapping(value={"/list"})
	public ModelAndView groupsList(){
		return new ModelAndView("groupapp/groupAppsList");
	}
	
MaxKey单点登录官方's avatar
mgt fix  
MaxKey单点登录官方 已提交
55
	@RequestMapping(value = { "/queryAppsInGroup" })
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
56
	@ResponseBody
MaxKey单点登录官方's avatar
mgt fix  
MaxKey单点登录官方 已提交
57
	public JpaPageResults<GroupPrivileges> queryAppsInGroup(@ModelAttribute("groupApp") GroupPrivileges groupApp) {
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
58
		
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
59
		JpaPageResults<GroupPrivileges> groupPrivileges;
M
MaxKey 已提交
60
		groupApp.setInstId(WebContext.getUserInfo().getInstId());
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
61
		groupPrivileges= groupPrivilegesService.queryPageResults("appsInGroup",groupApp);
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
62

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
63 64
		if(groupPrivileges!=null&&groupPrivileges.getRows()!=null){
			for (Apps app : groupPrivileges.getRows()){
M
MaxKey 已提交
65
				app.transIconBase64();
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
66 67
			}
		}
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
68
		return groupPrivileges;
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
69 70 71 72 73 74 75 76 77 78 79

	}
	
	@RequestMapping(value={"/addGroupAppsList/{groupId}"})
	public ModelAndView appsNotInGroupList(@PathVariable("groupId") String groupId){
		ModelAndView modelAndView=new ModelAndView("groupapp/addGroupAppsList");
		modelAndView.addObject("groupId", groupId);
		return modelAndView;
	}
	
	
MaxKey单点登录官方's avatar
mgt fix  
MaxKey单点登录官方 已提交
80
	@RequestMapping(value = { "/queryAppsNotInGroup" })
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
81
	@ResponseBody
MaxKey单点登录官方's avatar
mgt fix  
MaxKey单点登录官方 已提交
82
	public JpaPageResults<GroupPrivileges> queryAppsNotInGroup(@ModelAttribute("groupApp") GroupPrivileges groupApp) {
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
83
		JpaPageResults<GroupPrivileges> groupPrivileges;
M
MaxKey 已提交
84
		groupApp.setInstId(WebContext.getUserInfo().getInstId());
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
85
		groupPrivileges= groupPrivilegesService.queryPageResults("appsNotInGroup",groupApp);
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
86

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
87 88
		if(groupPrivileges!=null&&groupPrivileges.getRows()!=null){
			for (Apps app : groupPrivileges.getRows()){
M
MaxKey 已提交
89
				app.transIconBase64();
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
90 91
			}
		}
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
92
		return groupPrivileges;
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111

	}

	
	@RequestMapping(value = {"/insert"})
	@ResponseBody
	public Message insertGroupApp(@ModelAttribute("groupApp") GroupPrivileges groupApp) {
		if (groupApp == null || groupApp.getGroupId() == null) {
			return  new Message("传入参数为空",MessageType.error);
		}
		String groupId = groupApp.getGroupId();
		
		
		boolean result = true;
		String appIds = groupApp.getAppId();
		if (appIds != null) {
			String[] arrAppIds = appIds.split(",");
			
			for (int i = 0; i < arrAppIds.length; i++) {
M
v 3.2.0  
MaxKey 已提交
112 113
				GroupPrivileges newGroupApp = 
						new GroupPrivileges(groupId, arrAppIds[i],WebContext.getUserInfo().getInstId());
M
MaxKey 已提交
114
				newGroupApp.setId(WebContext.genId());
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
115
				result = groupPrivilegesService.insert(newGroupApp);
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
116 117
			}
			if(!result) {
M
v 3.3.0  
MaxKey 已提交
118
				return  new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_ERROR),MessageType.error);
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
119 120 121
			}
			
		}
M
v 3.3.0  
MaxKey 已提交
122
		return  new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS),MessageType.info);
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
123 124 125 126 127
	}
	
	@RequestMapping(value = {"/delete"})
	@ResponseBody
	public Message deleteGroupApp(@ModelAttribute("groupApp") GroupPrivileges groupApp) {
MaxKey单点登录官方's avatar
mgt fix  
MaxKey单点登录官方 已提交
128
		if (groupApp == null || groupApp.getId() == null) {
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
129 130
			return  new Message("传入参数为空",MessageType.error);
		}
131
	
M
MaxKey 已提交
132
		if(groupPrivilegesService.deleteBatch(groupApp.getId())) {
M
v 3.3.0  
MaxKey 已提交
133
		    return  new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS),MessageType.info);
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
134
		}
135
		
M
v 3.3.0  
MaxKey 已提交
136
		return  new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_ERROR),MessageType.error);
MaxKey单点登录官方's avatar
init  
MaxKey单点登录官方 已提交
137 138 139 140 141 142
	}
	
	


}