@Log(message="修改了{0}角色的信息。")
@RequiresPermissions("Role:edit")
@RequestMapping(value="/update", method=RequestMethod.POST)
public @ResponseBody String update(@Valid Role role) {
Role oldRole = roleService.get(role.getId());
oldRole.setName(role.getName());
oldRole.setDescription(role.getDescription());
List<RolePermission> newRList = new ArrayList<RolePermission>();
List<RolePermission> delRList = new ArrayList<RolePermission>();
List<RolePermission> hasRolePermissions = rolePermissionService.findByRoleId(role.getId());
for (RolePermission rolePermission : role.getRolePermissions()) {
if (rolePermission.getId() == null && rolePermission.getPermission() != null) {
rolePermission.setRole(oldRole);
newRList.add(rolePermission);
} else if (rolePermission.getId() != null && rolePermission.getPermission() == null) {
for (RolePermission rp : hasRolePermissions) {
if (rp.getId().equals(rolePermission.getId())) {
delRList.add(rp);
break;
}
}
}
}
rolePermissionService.save(newRList);
rolePermissionService.delete(delRList);
roleService.saveOrUpdate(oldRole);
LogUitls.putArgs(LogMessageObject.newWrite().setObjects(new Object[]{oldRole.getName()}));
return AjaxObject.newOk("修改角色成功!").toString();
}