|
@@ -4,11 +4,9 @@ import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
-import org.springframework.ui.Model;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
@@ -25,11 +23,9 @@ import cn.com.qmth.stmms.biz.basic.model.Privilege;
|
|
|
import cn.com.qmth.stmms.biz.basic.service.PrivilegeService;
|
|
|
import cn.com.qmth.stmms.biz.basic.service.RoleInfoService;
|
|
|
import cn.com.qmth.stmms.biz.basic.service.RolePrivilegeService;
|
|
|
+import cn.com.qmth.stmms.biz.exception.StatusException;
|
|
|
import cn.com.qmth.stmms.biz.utils.PageUtil;
|
|
|
import cn.com.qmth.stmms.common.domain.WebUser;
|
|
|
-import cn.com.qmth.stmms.common.enums.Role;
|
|
|
-import cn.com.qmth.stmms.common.utils.RequestUtils;
|
|
|
-import net.sf.json.JSONArray;
|
|
|
|
|
|
@Controller
|
|
|
@RequestMapping("/api/admin/role")
|
|
@@ -47,6 +43,9 @@ public class RoleController extends BaseApiController {
|
|
|
@ResponseBody
|
|
|
@RequestMapping(value = "page", method = RequestMethod.POST)
|
|
|
public PageResult<RoleInfoVo> getPage(RoleInfoQuery query) {
|
|
|
+ if (query.getSchoolId() == null) {
|
|
|
+ throw new StatusException("SchoolId不能为空");
|
|
|
+ }
|
|
|
Integer totalCount = roleInfoService.countByQuery(query);
|
|
|
query.setTotalCount(totalCount);
|
|
|
if (totalCount > 0) {
|
|
@@ -64,27 +63,51 @@ public class RoleController extends BaseApiController {
|
|
|
}
|
|
|
|
|
|
@ResponseBody
|
|
|
- @RequestMapping(value = "privilege")
|
|
|
- public String privilege(Model model, HttpServletRequest request, RoleInfoQuery query) {
|
|
|
- List<RolePrivilegeVo> ps = rolePrivilegeService.findByQuery(query);
|
|
|
- if (ps != null) {
|
|
|
- model.addAttribute("privilegeList", JSONArray.fromObject(ps).toString());
|
|
|
- } else {
|
|
|
- model.addAttribute("privilegeList", "[]");
|
|
|
+ @RequestMapping(value = "privilege/codes", method = RequestMethod.POST)
|
|
|
+ public Set<String> privilegeCodes() {
|
|
|
+ WebUser wu = getWebUser();
|
|
|
+ return rolePrivilegeService.getRoleCodes(wu.getUser().getSchoolId(), wu.getRole());
|
|
|
+ }
|
|
|
+
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping(value = "privilege/all", method = RequestMethod.POST)
|
|
|
+ public List<RolePrivilegeVo> privilegeAll(RoleInfoQuery query) {
|
|
|
+ if (StringUtils.isBlank(query.getRole())) {
|
|
|
+ throw new StatusException("role不能为空");
|
|
|
+ }
|
|
|
+ if (query.getSchoolId() == null) {
|
|
|
+ throw new StatusException("SchoolId不能为空");
|
|
|
}
|
|
|
- model.addAttribute("schoolId", query.getSchoolId());
|
|
|
- model.addAttribute("roleCode", query.getRole());
|
|
|
- model.addAttribute("roleName", Role.valueOf(query.getRole()).getName());
|
|
|
- return "modules/basic/rolePrivilege";
|
|
|
+ return rolePrivilegeService.findByQuery(query);
|
|
|
}
|
|
|
|
|
|
@ResponseBody
|
|
|
- @RequestMapping(value = "privilege/save")
|
|
|
- public String privilegeSave(RolePrivilegeDomain domain) {
|
|
|
+ @RequestMapping(value = "privilege/menu", method = RequestMethod.POST)
|
|
|
+ public List<Privilege> privilegeMenu() {
|
|
|
+ WebUser wu = getWebUser();
|
|
|
+ List<Privilege> ps = privilegeService.getMenuPrivileges();
|
|
|
+ Set<String> codes = rolePrivilegeService.getRoleCodes(wu.getUser().getSchoolId(), wu.getRole());
|
|
|
+ List<Privilege> ret = new ArrayList<>();
|
|
|
+ for (Privilege p : ps) {
|
|
|
+ if (codes.contains(p.getCode())) {
|
|
|
+ ret.add(p);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping(value = "privilege/save", method = RequestMethod.POST)
|
|
|
+ public void privilegeSave(RolePrivilegeDomain domain) {
|
|
|
+ if (StringUtils.isBlank(domain.getRole())) {
|
|
|
+ throw new StatusException("role不能为空");
|
|
|
+ }
|
|
|
+ if (domain.getSchoolId() == null) {
|
|
|
+ throw new StatusException("SchoolId不能为空");
|
|
|
+ }
|
|
|
WebUser wu = getWebUser();
|
|
|
domain.setUserId(wu.getId());
|
|
|
rolePrivilegeService.save(domain);
|
|
|
- return "redirect:/admin/basic/role/info/list?schoolId=" + domain.getSchoolId();
|
|
|
}
|
|
|
|
|
|
}
|