Search in sources :

Example 36 with AjaxResult

use of com.ruoyi.common.core.domain.AjaxResult in project wumei-smart by kerwincui.

the class ToolController method uploadFile.

/**
 * 文件上传
 */
@PostMapping("/upload")
@ApiOperation("文件上传")
public AjaxResult uploadFile(MultipartFile file) throws Exception {
    try {
        String filePath = RuoYiConfig.getProfile();
        // 文件名长度限制
        int fileNamelength = file.getOriginalFilename().length();
        if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH) {
            throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
        }
        // 文件类型限制
        // assertAllowed(file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
        // 获取文件名和文件类型
        String fileName = file.getOriginalFilename();
        String extension = getExtension(file);
        // 设置日期格式
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MMdd-HHmmss");
        fileName = "/iot/" + getLoginUser().getUserId().toString() + "/" + df.format(new Date()) + "." + extension;
        // 创建目录
        File desc = new File(filePath + File.separator + fileName);
        if (!desc.exists()) {
            if (!desc.getParentFile().exists()) {
                desc.getParentFile().mkdirs();
            }
        }
        // 存储文件
        file.transferTo(desc);
        String url = "/profile" + fileName;
        AjaxResult ajax = AjaxResult.success();
        ajax.put("fileName", url);
        ajax.put("url", url);
        return ajax;
    } catch (Exception e) {
        return AjaxResult.error(e.getMessage());
    }
}
Also used : AjaxResult(com.ruoyi.common.core.domain.AjaxResult) FileNameLengthLimitExceededException(com.ruoyi.common.exception.file.FileNameLengthLimitExceededException) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) Date(java.util.Date) FileNameLengthLimitExceededException(com.ruoyi.common.exception.file.FileNameLengthLimitExceededException) IOException(java.io.IOException) ApiOperation(io.swagger.annotations.ApiOperation)

Example 37 with AjaxResult

use of com.ruoyi.common.core.domain.AjaxResult in project wumei-smart by kerwincui.

the class SysProfileController method avatar.

/**
 * 头像上传
 */
@Log(title = "用户头像", businessType = BusinessType.UPDATE)
@PostMapping("/avatar")
public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws IOException {
    if (!file.isEmpty()) {
        LoginUser loginUser = getLoginUser();
        String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file);
        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) Log(com.ruoyi.common.annotation.Log)

Example 38 with AjaxResult

use of com.ruoyi.common.core.domain.AjaxResult in project wumei-smart by kerwincui.

the class SysProfileController method profile.

/**
 * 个人信息
 */
@GetMapping
public AjaxResult profile() {
    LoginUser loginUser = getLoginUser();
    SysUser user = loginUser.getUser();
    AjaxResult ajax = AjaxResult.success(user);
    ajax.put("roleGroup", userService.selectUserRoleGroup(loginUser.getUsername()));
    ajax.put("postGroup", userService.selectUserPostGroup(loginUser.getUsername()));
    ajax.put("socialGroup", iUserSocialProfileService.selectUserSocialProfile(loginUser.getUserId()));
    return ajax;
}
Also used : AjaxResult(com.ruoyi.common.core.domain.AjaxResult) SysUser(com.ruoyi.common.core.domain.entity.SysUser) LoginUser(com.ruoyi.common.core.domain.model.LoginUser)

Example 39 with AjaxResult

use of com.ruoyi.common.core.domain.AjaxResult in project wumei-smart by kerwincui.

the class SysLoginController method login.

/**
 * 登录方法
 *
 * @param loginBody 登录信息
 * @return 结果
 */
@PostMapping("/login")
public AjaxResult login(@RequestBody LoginBody loginBody) {
    AjaxResult ajax = AjaxResult.success();
    // 生成令牌
    String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(), loginBody.getUuid());
    ajax.put(Constants.TOKEN, token);
    return ajax;
}
Also used : AjaxResult(com.ruoyi.common.core.domain.AjaxResult) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 40 with AjaxResult

use of com.ruoyi.common.core.domain.AjaxResult in project wumei-smart by kerwincui.

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)

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