Search in sources :

Example 16 with AjaxResult

use of com.ruoyi.common.core.domain.AjaxResult in project RuoYi-Vue by yangzongzhuan.

the class SysProfileController method avatar.

/**
 * 头像上传
 */
@Log(title = "用户头像", businessType = BusinessType.UPDATE)
@PostMapping("/avatar")
public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws Exception {
    if (!file.isEmpty()) {
        LoginUser loginUser = getLoginUser();
        String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file, MimeTypeUtils.IMAGE_EXTENSION);
        if (userService.updateUserAvatar(loginUser.getUsername(), avatar)) {
            AjaxResult ajax = AjaxResult.success();
            ajax.put("imgUrl", avatar);
            // 更新缓存用户头像
            loginUser.getUser().setAvatar(avatar);
            tokenService.setLoginUser(loginUser);
            return ajax;
        }
    }
    return AjaxResult.error("上传图片异常,请联系管理员");
}
Also used : AjaxResult(com.ruoyi.common.core.domain.AjaxResult) LoginUser(com.ruoyi.common.core.domain.model.LoginUser) PostMapping(org.springframework.web.bind.annotation.PostMapping) Log(com.ruoyi.common.annotation.Log)

Example 17 with AjaxResult

use of com.ruoyi.common.core.domain.AjaxResult in project RuoYi-Vue by yangzongzhuan.

the class SysUserController method getInfo.

/**
 * 根据用户编号获取详细信息
 */
@PreAuthorize("@ss.hasPermi('system:user:query')")
@GetMapping(value = { "/", "/{userId}" })
public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) {
    userService.checkUserDataScope(userId);
    AjaxResult ajax = AjaxResult.success();
    List<SysRole> roles = roleService.selectRoleAll();
    ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
    ajax.put("posts", postService.selectPostAll());
    if (StringUtils.isNotNull(userId)) {
        SysUser sysUser = userService.selectUserById(userId);
        ajax.put(AjaxResult.DATA_TAG, sysUser);
        ajax.put("postIds", postService.selectPostListByUserId(userId));
        ajax.put("roleIds", sysUser.getRoles().stream().map(SysRole::getRoleId).collect(Collectors.toList()));
    }
    return ajax;
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) SysUser(com.ruoyi.common.core.domain.entity.SysUser) TableDataInfo(com.ruoyi.common.core.page.TableDataInfo) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ArrayUtils(org.apache.commons.lang3.ArrayUtils) AjaxResult(com.ruoyi.common.core.domain.AjaxResult) RequestBody(org.springframework.web.bind.annotation.RequestBody) StringUtils(com.ruoyi.common.utils.StringUtils) PutMapping(org.springframework.web.bind.annotation.PutMapping) SecurityUtils(com.ruoyi.common.utils.SecurityUtils) ISysRoleService(com.ruoyi.system.service.ISysRoleService) GetMapping(org.springframework.web.bind.annotation.GetMapping) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) BaseController(com.ruoyi.common.core.controller.BaseController) PostMapping(org.springframework.web.bind.annotation.PostMapping) Validated(org.springframework.validation.annotation.Validated) HttpServletResponse(javax.servlet.http.HttpServletResponse) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) BusinessType(com.ruoyi.common.enums.BusinessType) List(java.util.List) ISysUserService(com.ruoyi.system.service.ISysUserService) UserConstants(com.ruoyi.common.constant.UserConstants) Log(com.ruoyi.common.annotation.Log) ExcelUtil(com.ruoyi.common.utils.poi.ExcelUtil) MultipartFile(org.springframework.web.multipart.MultipartFile) SysRole(com.ruoyi.common.core.domain.entity.SysRole) ISysPostService(com.ruoyi.system.service.ISysPostService) AjaxResult(com.ruoyi.common.core.domain.AjaxResult) SysUser(com.ruoyi.common.core.domain.entity.SysUser) SysRole(com.ruoyi.common.core.domain.entity.SysRole) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 18 with AjaxResult

use of com.ruoyi.common.core.domain.AjaxResult in project RuoYi-Vue by yangzongzhuan.

the class SysLoginController method getInfo.

/**
 * 获取用户信息
 *
 * @return 用户信息
 */
@GetMapping("getInfo")
public AjaxResult getInfo() {
    SysUser user = SecurityUtils.getLoginUser().getUser();
    // 角色集合
    Set<String> roles = permissionService.getRolePermission(user);
    // 权限集合
    Set<String> permissions = permissionService.getMenuPermission(user);
    AjaxResult ajax = AjaxResult.success();
    ajax.put("user", user);
    ajax.put("roles", roles);
    ajax.put("permissions", permissions);
    return ajax;
}
Also used : AjaxResult(com.ruoyi.common.core.domain.AjaxResult) SysUser(com.ruoyi.common.core.domain.entity.SysUser) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 19 with AjaxResult

use of com.ruoyi.common.core.domain.AjaxResult in project RuoYi-Vue by yangzongzhuan.

the class CommonController method uploadFiles.

/**
 * 通用上传请求(多个)
 */
@PostMapping("/uploads")
public AjaxResult uploadFiles(List<MultipartFile> files) throws Exception {
    try {
        // 上传文件路径
        String filePath = RuoYiConfig.getUploadPath();
        List<String> urls = new ArrayList<String>();
        List<String> fileNames = new ArrayList<String>();
        List<String> newFileNames = new ArrayList<String>();
        List<String> originalFilenames = new ArrayList<String>();
        for (MultipartFile file : files) {
            // 上传并返回新文件名称
            String fileName = FileUploadUtils.upload(filePath, file);
            String url = serverConfig.getUrl() + fileName;
            urls.add(url);
            fileNames.add(fileName);
            newFileNames.add(FileUtils.getName(fileName));
            originalFilenames.add(file.getOriginalFilename());
        }
        AjaxResult ajax = AjaxResult.success();
        ajax.put("urls", StringUtils.join(urls, FILE_DELIMETER));
        ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER));
        ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER));
        ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER));
        return ajax;
    } catch (Exception e) {
        return AjaxResult.error(e.getMessage());
    }
}
Also used : AjaxResult(com.ruoyi.common.core.domain.AjaxResult) MultipartFile(org.springframework.web.multipart.MultipartFile) ArrayList(java.util.ArrayList) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 20 with AjaxResult

use of com.ruoyi.common.core.domain.AjaxResult in project RuoYi-Vue by yangzongzhuan.

the class CommonController method uploadFile.

/**
 * 通用上传请求(单个)
 */
@PostMapping("/upload")
public AjaxResult uploadFile(MultipartFile file) throws Exception {
    try {
        // 上传文件路径
        String filePath = RuoYiConfig.getUploadPath();
        // 上传并返回新文件名称
        String fileName = FileUploadUtils.upload(filePath, file);
        String url = serverConfig.getUrl() + fileName;
        AjaxResult ajax = AjaxResult.success();
        ajax.put("url", url);
        ajax.put("fileName", fileName);
        ajax.put("newFileName", FileUtils.getName(fileName));
        ajax.put("originalFilename", file.getOriginalFilename());
        return ajax;
    } catch (Exception e) {
        return AjaxResult.error(e.getMessage());
    }
}
Also used : AjaxResult(com.ruoyi.common.core.domain.AjaxResult) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

AjaxResult (com.ruoyi.common.core.domain.AjaxResult)55 GetMapping (org.springframework.web.bind.annotation.GetMapping)25 PostMapping (org.springframework.web.bind.annotation.PostMapping)16 SysUser (com.ruoyi.common.core.domain.entity.SysUser)12 LoginUser (com.ruoyi.common.core.domain.model.LoginUser)10 Log (com.ruoyi.common.annotation.Log)8 StringUtils (com.ruoyi.common.utils.StringUtils)7 List (java.util.List)7 Autowired (org.springframework.beans.factory.annotation.Autowired)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 RestController (org.springframework.web.bind.annotation.RestController)7 MultipartFile (org.springframework.web.multipart.MultipartFile)7 SysUser (com.ruoyi.system.domain.SysUser)6 UserConstants (com.ruoyi.common.constant.UserConstants)5 BaseController (com.ruoyi.common.core.controller.BaseController)5 SysRole (com.ruoyi.common.core.domain.entity.SysRole)5 TableDataInfo (com.ruoyi.common.core.page.TableDataInfo)5 BusinessType (com.ruoyi.common.enums.BusinessType)5 SecurityUtils (com.ruoyi.common.utils.SecurityUtils)5