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());
}
}
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("上传图片异常,请联系管理员");
}
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;
}
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;
}
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;
}
Aggregations