首页>代码>spring3+spring mvc3+hibernate4开发通用网站后台管理系统>/my-forestry/src/com/forestry/controller/sys/AuthorityController.java
001 | package com.forestry.controller.sys; |
002 |
003 | import java.io.IOException; |
004 | import java.util.ArrayList; |
005 | import java.util.HashMap; |
006 | import java.util.LinkedHashMap; |
007 | import java.util.List; |
008 | import java.util.Map; |
009 |
010 | import javax.annotation.Resource; |
011 | import javax.servlet.http.HttpServletRequest; |
012 | import javax.servlet.http.HttpServletResponse; |
013 |
014 | import net.sf.json.JSONArray; |
015 | import net.sf.json.JSONObject; |
016 |
017 | import org.apache.commons.lang.StringUtils; |
018 | import org.springframework.stereotype.Controller; |
019 | import org.springframework.web.bind.annotation.RequestMapping; |
020 | import org.springframework.web.bind.annotation.RequestMethod; |
021 | import org.springframework.web.bind.annotation.RequestParam; |
022 |
023 | import com.forestry.core.ForestryBaseController; |
024 | import com.forestry.model.sys.Authority; |
025 | import com.forestry.model.sys.RoleAuthority; |
026 | import com.forestry.service.sys.AuthorityService; |
027 | import com.forestry.service.sys.RoleAuthorityService; |
028 |
029 | import core.extjs.ExtJSBaseParameter; |
030 | import core.extjs.ListView; |
031 | import core.support.QueryResult; |
032 |
033 | /** |
034 | * @author Yang Tian |
035 | * @email 1298588579@qq.com |
036 | */ |
037 | @Controller |
038 | @RequestMapping ( "/sys/authority" ) |
039 | public class AuthorityController extends ForestryBaseController<Authority> { |
040 |
041 | @Resource |
042 | private AuthorityService authorityService; |
043 | @Resource |
044 | private RoleAuthorityService roleAuthorityService; |
045 |
046 | @RequestMapping ( "/getAuthority" ) |
047 | public void getAuthority(HttpServletRequest request, HttpServletResponse response) throws Exception { |
048 | Short role = Short.valueOf(request.getParameter( "globalRoleId" )); |
049 | List<Authority> mainMenuList = authorityService.queryByParentIdAndRole(role); |
050 | List resultList = new ArrayList(); |
051 | for ( int i = 0 ; i < mainMenuList.size(); i++) { |
052 | JSONObject jsonObject = new JSONObject(); |
053 | jsonObject.element( "id" , mainMenuList.get(i).getId()); |
054 | jsonObject.element( "sortOrder" , mainMenuList.get(i).getSortOrder()); |
055 | jsonObject.element( "menuCode" , mainMenuList.get(i).getMenuCode()); |
056 | jsonObject.element( "text" , mainMenuList.get(i).getMenuName()); |
057 | jsonObject.element( "menuConfig" , mainMenuList.get(i).getMenuConfig()); |
058 | jsonObject.element( "buttons" , mainMenuList.get(i).getButtons()); |
059 | jsonObject.element( "expanded" , mainMenuList.get(i).getExpanded()); |
060 | jsonObject.element( "checked" , mainMenuList.get(i).getChecked()); |
061 | jsonObject.element( "leaf" , mainMenuList.get(i).getLeaf()); |
062 | jsonObject.element( "url" , mainMenuList.get(i).getUrl()); |
063 | jsonObject.element( "iconCls" , mainMenuList.get(i).getIconCls()); |
064 |
065 | JSONArray jsonArray = new JSONArray(); |
066 | List<Authority> childrenMenuList = authorityService.queryChildrenByParentIdAndRole(mainMenuList.get(i).getId(), role); |
067 | for ( int j = 0 ; j < childrenMenuList.size(); j++) { |
068 | JSONObject childrenJsonObject = new JSONObject(); |
069 |
070 | String buttons = authorityService.querySurfaceAuthorityList(roleAuthorityService.queryByProerties( "role" , role), childrenMenuList.get(j).getId(), childrenMenuList.get(j).getButtons()); |
071 |
072 | childrenJsonObject.element( "id" , childrenMenuList.get(j).getId()); |
073 | childrenJsonObject.element( "sortOrder" , childrenMenuList.get(j).getSortOrder()); |
074 | childrenJsonObject.element( "menuCode" , childrenMenuList.get(j).getMenuCode()); |
075 | childrenJsonObject.element( "text" , childrenMenuList.get(j).getMenuName()); |
076 | childrenJsonObject.element( "menuConfig" , childrenMenuList.get(j).getMenuConfig()); |
077 | childrenJsonObject.element( "buttons" , buttons); |
078 | childrenJsonObject.element( "expanded" , childrenMenuList.get(j).getExpanded()); |
079 | childrenJsonObject.element( "checked" , childrenMenuList.get(j).getChecked()); |
080 | childrenJsonObject.element( "leaf" , childrenMenuList.get(j).getLeaf()); |
081 | childrenJsonObject.element( "url" , childrenMenuList.get(j).getUrl()); |
082 | childrenJsonObject.element( "iconCls" , childrenMenuList.get(j).getIconCls()); |
083 | jsonArray.add(childrenJsonObject); |
084 | } |
085 | jsonObject.element( "children" , jsonArray); |
086 | resultList.add(jsonObject); |
087 | } |
088 | writeJSON(response, resultList); |
089 | } |
090 |
091 | @RequestMapping ( "/getAuthorizationList" ) |
092 | public void getAuthorizationList(HttpServletRequest request, HttpServletResponse response) throws Exception { |
093 | String roleParam = request.getParameter( "role" ); |
094 | List<String> authorityIdList = new ArrayList<String>(); |
095 | if (roleParam != null ) { |
096 | List<RoleAuthority> roleAuthorityList = roleAuthorityService.queryByProerties( "role" , Short.valueOf(roleParam)); |
097 | for (RoleAuthority roleAuthority : roleAuthorityList) { |
098 | authorityIdList.add(roleAuthority.getAuthorityId()); |
099 | } |
100 | } |
101 |
102 | List<Authority> mainMenuList = authorityService.queryByProerties( "parentId" , null ); |
103 | List resultList = new ArrayList(); |
104 | for ( int i = 0 ; i < mainMenuList.size(); i++) { |
105 | JSONObject jsonObject = new JSONObject(); |
106 | jsonObject.element( "id" , mainMenuList.get(i).getId()); |
107 | jsonObject.element( "text" , mainMenuList.get(i).getMenuName()); |
108 | jsonObject.element( "expanded" , mainMenuList.get(i).getExpanded()); |
109 |
110 | if (authorityIdList.contains(mainMenuList.get(i).getId().toString())) { |
111 | jsonObject.element( "checked" , true ); |
112 | } else { |
113 | jsonObject.element( "checked" , false ); |
114 | } |
115 |
116 | jsonObject.element( "leaf" , mainMenuList.get(i).getLeaf()); |
117 |
118 | JSONArray jsonArray = new JSONArray(); |
119 | List<Authority> childrenMenuList = authorityService.queryByProerties( "parentId" , mainMenuList.get(i).getId()); |
120 | for ( int j = 0 ; j < childrenMenuList.size(); j++) { |
121 | JSONObject childrenJsonObject = new JSONObject(); |
122 | childrenJsonObject.element( "id" , childrenMenuList.get(j).getId()); |
123 | childrenJsonObject.element( "text" , childrenMenuList.get(j).getMenuName()); |
124 | childrenJsonObject.element( "expanded" , childrenMenuList.get(j).getExpanded()); |
125 | if (authorityIdList.contains(childrenMenuList.get(j).getId().toString())) { |
126 | childrenJsonObject.element( "checked" , true ); |
127 | } else { |
128 | childrenJsonObject.element( "checked" , false ); |
129 | } |
130 |
131 | if (childrenMenuList.get(j).getButtons().length() == 0 ) { |
132 | childrenJsonObject.element( "leaf" , true ); |
133 | } else { |
134 | childrenJsonObject.element( "leaf" , false ); |
135 | } |
136 |
137 | JSONArray buttonJSONArray = new JSONArray(); |
138 | String[] buttons = childrenMenuList.get(j).getButtons().split( "," ); |
139 | for ( int z = 0 ; z < buttons.length; z++) { |
140 | if (StringUtils.isBlank(buttons[z])) { |
141 | continue ; |
142 | } |
143 | JSONObject buttonChildrenJSONObject = new JSONObject(); |
144 | buttonChildrenJSONObject.element( "id" , childrenMenuList.get(j).getId() + buttons[z]); |
145 | String buttonText = null ; |
146 | if (buttons[z].equalsIgnoreCase( "Add" )) { |
147 | buttonText = "添加" ; |
148 | } else if (buttons[z].equalsIgnoreCase( "Edit" )) { |
149 | buttonText = "修改" ; |
150 | } else if (buttons[z].equalsIgnoreCase( "Delete" )) { |
151 | buttonText = "删除" ; |
152 | } else if (buttons[z].equalsIgnoreCase( "View" )) { |
153 | buttonText = "查看" ; |
154 | } else if (buttons[z].equalsIgnoreCase( "Import" )) { |
155 | buttonText = "导入" ; |
156 | } else if (buttons[z].equalsIgnoreCase( "Query" )) { |
157 | buttonText = "查询" ; |
158 | } else if (buttons[z].equalsIgnoreCase( "Disarm" )) { |
159 | buttonText = "解除" ; |
160 | } else if (buttons[z].equalsIgnoreCase( "Export" )) { |
161 | buttonText = "导出" ; |
162 | } |
163 | buttonChildrenJSONObject.element( "text" , buttonText); |
164 | buttonChildrenJSONObject.element( "expanded" , true ); |
165 |
166 | if (authorityIdList.contains(childrenMenuList.get(j).getId() + buttons[z])) { |
167 | buttonChildrenJSONObject.element( "checked" , true ); |
168 | } else { |
169 | buttonChildrenJSONObject.element( "checked" , false ); |
170 | } |
171 |
172 | buttonChildrenJSONObject.element( "leaf" , true ); |
173 | buttonJSONArray.add(buttonChildrenJSONObject); |
174 | } |
175 | childrenJsonObject.element( "children" , buttonJSONArray); |
176 |
177 | jsonArray.add(childrenJsonObject); |
178 |
179 | } |
180 | jsonObject.element( "children" , jsonArray); |
181 | resultList.add(jsonObject); |
182 | } |
183 | writeJSON(response, resultList); |
184 | } |
185 |
186 | @RequestMapping ( "/getAuthorityTreePicker" ) |
187 | public void getAuthorityTreePicker(HttpServletRequest request, HttpServletResponse response) throws Exception { |
188 | Short role = Short.valueOf(request.getParameter( "roleId" )); |
189 | List<Authority> mainMenuList = authorityService.queryByParentIdAndRole(role); |
190 | List resultList = new ArrayList(); |
191 | for ( int i = 0 ; i < mainMenuList.size(); i++) { |
192 | JSONObject jsonObject = new JSONObject(); |
193 | jsonObject.element( "id" , mainMenuList.get(i).getId()); |
194 | jsonObject.element( "sortOrder" , mainMenuList.get(i).getSortOrder()); |
195 | jsonObject.element( "menuCode" , mainMenuList.get(i).getMenuCode()); |
196 | jsonObject.element( "text" , mainMenuList.get(i).getMenuName()); |
197 | jsonObject.element( "menuConfig" , mainMenuList.get(i).getMenuConfig()); |
198 | jsonObject.element( "buttons" , mainMenuList.get(i).getButtons()); |
199 | jsonObject.element( "expanded" , true ); |
200 | jsonObject.element( "checked" , mainMenuList.get(i).getChecked()); |
201 | jsonObject.element( "leaf" , mainMenuList.get(i).getLeaf()); |
202 | jsonObject.element( "url" , mainMenuList.get(i).getUrl()); |
203 | jsonObject.element( "iconCls" , mainMenuList.get(i).getIconCls()); |
204 |
205 | JSONArray jsonArray = new JSONArray(); |
206 | List<Authority> childrenMenuList = authorityService.queryChildrenByParentIdAndRole(mainMenuList.get(i).getId(), role); |
207 | for ( int j = 0 ; j < childrenMenuList.size(); j++) { |
208 | JSONObject childrenJsonObject = new JSONObject(); |
209 |
210 | String buttons = authorityService.querySurfaceAuthorityList(roleAuthorityService.queryByProerties( "role" , role), childrenMenuList.get(j).getId(), childrenMenuList.get(j).getButtons()); |
211 |
212 | childrenJsonObject.element( "id" , childrenMenuList.get(j).getId()); |
213 | childrenJsonObject.element( "sortOrder" , childrenMenuList.get(j).getSortOrder()); |
214 | childrenJsonObject.element( "menuCode" , childrenMenuList.get(j).getMenuCode()); |
215 | childrenJsonObject.element( "text" , childrenMenuList.get(j).getMenuName()); |
216 | childrenJsonObject.element( "menuConfig" , childrenMenuList.get(j).getMenuConfig()); |
217 | childrenJsonObject.element( "buttons" , buttons); |
218 | childrenJsonObject.element( "expanded" , true ); |
219 | childrenJsonObject.element( "checked" , childrenMenuList.get(j).getChecked()); |
220 | childrenJsonObject.element( "leaf" , childrenMenuList.get(j).getLeaf()); |
221 | childrenJsonObject.element( "url" , childrenMenuList.get(j).getUrl()); |
222 | childrenJsonObject.element( "iconCls" , childrenMenuList.get(j).getIconCls()); |
223 | jsonArray.add(childrenJsonObject); |
224 | } |
225 | jsonObject.element( "children" , jsonArray); |
226 | resultList.add(jsonObject); |
227 | } |
228 | writeJSON(response, resultList); |
229 | } |
230 |
231 | @Override |
232 | @RequestMapping (value = "/saveAuthority" , method = { RequestMethod.POST, RequestMethod.GET }) |
233 | public void doSave(Authority entity, HttpServletRequest request, HttpServletResponse response) throws IOException { |
234 | ExtJSBaseParameter parameter = ((ExtJSBaseParameter) entity); |
235 | Authority checkMenuCode = authorityService.getByProerties( "menuCode" , entity.getMenuCode()); |
236 | if ( null != checkMenuCode && null == entity.getId()) { |
237 | parameter.setSuccess( false ); |
238 | } else { |
239 | if (entity.getChecked() == false ) { |
240 | entity.setChecked( null ); |
241 | } |
242 | if (CMD_EDIT.equals(parameter.getCmd())) { |
243 | authorityService.update(entity); |
244 | } else if (CMD_NEW.equals(parameter.getCmd())) { |
245 | authorityService.persist(entity); |
246 | } |
247 | parameter.setCmd(CMD_EDIT); |
248 | parameter.setSuccess( true ); |
249 | } |
250 | writeJSON(response, parameter); |
251 | } |
252 |
253 | @RequestMapping (value = "/getAuthorityPagination" , method = { RequestMethod.POST, RequestMethod.GET }) |
254 | public void getAuthorityPagination(HttpServletRequest request, HttpServletResponse response) throws Exception { |
255 | Integer firstResult = Integer.valueOf(request.getParameter( "start" )); |
256 | Integer maxResults = Integer.valueOf(request.getParameter( "limit" )); |
257 | String sortedObject = null ; |
258 | String sortedValue = null ; |
259 | List<LinkedHashMap<String, Object>> sortedList = mapper.readValue(request.getParameter( "sort" ), List. class ); |
260 | for ( int i = 0 ; i < sortedList.size(); i++) { |
261 | Map<String, Object> map = sortedList.get(i); |
262 | sortedObject = (String) map.get( "property" ); |
263 | sortedValue = (String) map.get( "direction" ); |
264 | } |
265 | Authority authority = new Authority(); |
266 | authority.setFirstResult(firstResult); |
267 | authority.setMaxResults(maxResults); |
268 | Map<String, String> sortedCondition = new HashMap<String, String>(); |
269 | sortedCondition.put(sortedObject, sortedValue); |
270 | authority.setSortedConditions(sortedCondition); |
271 | QueryResult<Authority> queryResult = authorityService.doPaginationQuery(authority); |
272 | ListView<Authority> authorityListView = new ListView<Authority>(); |
273 | authorityListView.setData(queryResult.getResultList()); |
274 | authorityListView.setTotalRecord(queryResult.getTotalCount()); |
275 | writeJSON(response, authorityListView); |
276 | } |
277 |
278 | @RequestMapping ( "/deleteAuthority" ) |
279 | public void deleteAuthority(HttpServletRequest request, HttpServletResponse response, @RequestParam ( "ids" ) Long[] ids) throws IOException { |
280 | boolean flag = authorityService.deleteByPK(ids); |
281 | if (flag) { |
282 | writeJSON(response, "{success:true}" ); |
283 | } else { |
284 | writeJSON(response, "{success:false}" ); |
285 | } |
286 | } |
287 |
288 | } |

AAA孚盟软件售前刘美鲸 LV3
2021年10月20日
love8309287 LV4
2021年5月9日
有法说可能 LV4
2020年6月5日
ssy552 LV10
2020年5月7日
labelA LV5
2020年2月12日
garin_lau LV9
2019年7月29日
huasir2018 LV14
2019年7月22日
yyyyyyyyyyyyyyyyyyy LV16
2019年7月4日
xk9587 LV16
2019年4月30日
17614099410 LV2
2019年4月26日

lyq6666666 LV5
2023年10月25日
45436683 LV8
2023年9月20日
what_the_fo LV5
2023年4月6日
xxx520520 LV6
2023年1月31日
微信网友_6123092784238592
2022年12月2日
暂无贡献等级
adnawda
2022年11月27日
暂无贡献等级
cdjiangyang
2022年8月23日
暂无贡献等级
zhaoyangwfd LV17
2022年6月24日
无名氏111 LV33
2022年1月30日
不会写代码的小姚 LV3
2021年11月20日