Search in sources :

Example 1 with Role

use of com.codingmore.model.Role in project coding-more by itwanger.

the class RoleController method create.

@ApiOperation("添加角色")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public ResultObject<String> create(@Valid RoleParam roleParam) {
    if (roleParam.getCreateTime() == null) {
        roleParam.setCreateTime(new Date());
    }
    if (roleParam.getStatus() != 0 && roleParam.getStatus() != 1) {
        return ResultObject.failed("状态不合法");
    }
    Role role = new Role();
    BeanUtils.copyProperties(roleParam, role);
    return ResultObject.success(roleService.save(role) ? "添加成功" : "添加失败");
}
Also used : Role(com.codingmore.model.Role) Date(java.util.Date) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with Role

use of com.codingmore.model.Role in project coding-more by itwanger.

the class RoleController method update.

@ApiOperation("修改角色")
@RequestMapping(value = "/update", method = RequestMethod.POST)
@ResponseBody
public ResultObject<String> update(@Valid RoleParam roleParam) {
    if (roleParam.getStatus() != 0 && roleParam.getStatus() != 1) {
        return ResultObject.failed("状态不合法");
    }
    if (roleParam.getRoleId() == null) {
        return ResultObject.failed("角色id不能为空");
    }
    Role role = roleService.getById(roleParam.getRoleId());
    BeanUtils.copyProperties(roleParam, role);
    return ResultObject.success(roleService.updateById(role) ? "修改成功" : "修改失败");
}
Also used : Role(com.codingmore.model.Role) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with Role

use of com.codingmore.model.Role in project coding-more by itwanger.

the class RoleController method updateStatus.

@ApiOperation("修改角色状态")
@RequestMapping(value = "/updateStatus", method = RequestMethod.POST)
@ResponseBody
public ResultObject updateStatus(@RequestParam(value = "id") Long id, @RequestParam(value = "status") Integer status) {
    if (status != 0 && status != 1) {
        return ResultObject.failed("状态不合法");
    }
    Role role = roleService.getById(id);
    if (role == null) {
        return ResultObject.failed("角色不存在");
    }
    role.setStatus(status);
    return ResultObject.success(roleService.updateById(role) ? "修改成功" : "修改失败");
}
Also used : Role(com.codingmore.model.Role) ApiOperation(io.swagger.annotations.ApiOperation)

Example 4 with Role

use of com.codingmore.model.Role in project coding-more by itwanger.

the class UsersController method getAdminInfo.

@ApiOperation(value = "获取当前登录用户信息")
@RequestMapping(value = "/info", method = RequestMethod.GET)
@ResponseBody
public ResultObject getAdminInfo(Principal principal) {
    if (principal == null) {
        return ResultObject.unauthorized(null);
    }
    AdminUserDetails adminUserDetails = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    Users user = adminUserDetails.getUsers();
    // ?
    user.setUserPass(null);
    Map<String, Object> data = new HashMap<>();
    data.put("userDetail", adminUserDetails.getUsers());
    data.put("username", user.getUserLogin());
    data.put("menus", roleService.getMenuList(user.getUsersId()));
    data.put("icon", user.getDisplayName());
    List<Role> roleList = usersService.getRoleList(user.getUsersId());
    if (CollUtil.isNotEmpty(roleList)) {
        List<String> roles = roleList.stream().map(Role::getName).collect(Collectors.toList());
        data.put("roles", roles);
    }
    return ResultObject.success(data);
}
Also used : Role(com.codingmore.model.Role) HashMap(java.util.HashMap) ResultObject(com.codingmore.webapi.ResultObject) Users(com.codingmore.model.Users) AdminUserDetails(com.codingmore.model.AdminUserDetails) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Role (com.codingmore.model.Role)4 ApiOperation (io.swagger.annotations.ApiOperation)4 AdminUserDetails (com.codingmore.model.AdminUserDetails)1 Users (com.codingmore.model.Users)1 ResultObject (com.codingmore.webapi.ResultObject)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1