Exemplo n.º 1
10
 @RequestMapping(value = "role/update")
 public ModelAndView updateRole(@ModelAttribute @Valid SysRole sysRole, BindingResult result)
     throws Exception {
   Map<String, Object> map = new HashMap<String, Object>();
   SysRole checkByName = this.sysRoleUserService.selectByRoleName(sysRole.getRoleName());
   if (checkByName != null
       && checkByName.getRoleId().intValue() != sysRole.getRoleId().intValue()) {
     FieldError error = new FieldError("sysRole", "roleName", "角色名已存在!");
     result.addError(error);
   }
   SysRole checkById = this.sysRoleUserService.selectOneRole(sysRole.getRoleId());
   if (checkById == null) {
     FieldError error = new FieldError("sysRole", "roleName", "更新的角色不存在!");
     result.addError(error);
   }
   if (result.hasErrors()) {
     List<SysRight> allRights = this.sysRoleUserService.findRights();
     RightModuleBuilder builder = RightModuleBuilder.initModules(allRights);
     map.put("builder", builder);
     map.put("sysRole", sysRole);
     return new ModelAndView("sys/sys_role_edit", map);
   }
   // update SysRole
   checkById.setRoleName(sysRole.getRoleName());
   checkById.setRoleRightCodes(sysRole.getRoleRightCodes());
   this.sysRoleUserService.updateRole(checkById);
   //
   map.put("success_msg", "角色修改成功!");
   map.put("action", "update");
   return new ModelAndView("sys/sys_role_success", map);
 }
 @RequestMapping(value = "role/save")
 public ModelAndView saveRole(@ModelAttribute @Valid SysRole sysRole, BindingResult result)
     throws Exception {
   Map<String, Object> map = new HashMap<String, Object>();
   SysRole checkOne = this.sysRoleUserService.selectByRoleName(sysRole.getRoleName());
   if (checkOne != null) {
     FieldError error = new FieldError("sysRole", "roleName", "角色名已存在!");
     result.addError(error);
   }
   if (result.hasErrors()) {
     List<SysRight> allRights = this.sysRoleUserService.findRights();
     RightModuleBuilder builder = RightModuleBuilder.initModules(allRights);
     map.put("builder", builder);
     return new ModelAndView("sys/sys_role_new", map);
   }
   // create SysRole
   sysRole.setAuditStatus(EntityConstants.IS_VALILD_0);
   sysRole.setIsValid(EntityConstants.IS_VALILD_1);
   this.sysRoleUserService.createRole(sysRole);
   //
   map.put("success_msg", "角色创建成功!");
   map.put("action", "new");
   return new ModelAndView("sys/sys_role_success", map);
 }