mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-19 01:48:47 +08:00
用户信息接口迁移及其他修改
This commit is contained in:
parent
d3cbd62e44
commit
3ce20cae9f
@ -6,6 +6,10 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.dromara.common.core.domain.R;
|
import org.dromara.common.core.domain.R;
|
||||||
import org.dromara.common.core.exception.ServiceException;
|
import org.dromara.common.core.exception.ServiceException;
|
||||||
import org.dromara.common.core.validate.AddGroup;
|
import org.dromara.common.core.validate.AddGroup;
|
||||||
|
import org.dromara.common.core.validate.EditGroup;
|
||||||
|
import org.dromara.common.idempotent.annotation.RepeatSubmit;
|
||||||
|
import org.dromara.common.log.annotation.Log;
|
||||||
|
import org.dromara.common.log.enums.BusinessType;
|
||||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||||
import org.dromara.common.satoken.utils.LoginHelper;
|
import org.dromara.common.satoken.utils.LoginHelper;
|
||||||
@ -50,6 +54,17 @@ public class EqHomeController extends BaseController {
|
|||||||
return R.ok(eqUserConfigService.userConfig());
|
return R.ok(eqUserConfigService.userConfig());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改用户配置
|
||||||
|
* @param bo
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Log(title = "用户配置", businessType = BusinessType.UPDATE)
|
||||||
|
@RepeatSubmit()
|
||||||
|
@PutMapping("/editUserConfig")
|
||||||
|
public R<Void> editUserConfig(@Validated(EditGroup.class) @RequestBody EqUserConfigBo bo) {
|
||||||
|
return toAjax(eqUserConfigService.updateByBo(bo));
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 首页切换 查询家庭主体
|
* 首页切换 查询家庭主体
|
||||||
*/
|
*/
|
||||||
@ -134,6 +149,18 @@ public class EqHomeController extends BaseController {
|
|||||||
return R.ok(eqAreaService.queryList(bo));
|
return R.ok(eqAreaService.queryList(bo));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增分布
|
||||||
|
* @param bo
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Log(title = "分布管理", businessType = BusinessType.INSERT)
|
||||||
|
@RepeatSubmit()
|
||||||
|
@PostMapping("areaAdd")
|
||||||
|
public R<Void> areaAdd(@Validated(AddGroup.class) @RequestBody EqAreaBo bo) {
|
||||||
|
return toAjax(eqAreaService.insertByBo(bo));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 首页查看设备列表
|
* 首页查看设备列表
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -0,0 +1,228 @@
|
|||||||
|
package org.dromara.web.controller.app;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import cn.dev33.satoken.secure.BCrypt;
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.dromara.common.core.domain.R;
|
||||||
|
import org.dromara.common.core.domain.model.LoginUser;
|
||||||
|
import org.dromara.common.core.exception.ServiceException;
|
||||||
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
|
import org.dromara.common.core.utils.file.MimeTypeUtils;
|
||||||
|
import org.dromara.common.idempotent.annotation.RepeatSubmit;
|
||||||
|
import org.dromara.common.log.annotation.Log;
|
||||||
|
import org.dromara.common.log.enums.BusinessType;
|
||||||
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||||
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||||
|
import org.dromara.common.satoken.utils.LoginHelper;
|
||||||
|
import org.dromara.common.tenant.helper.TenantHelper;
|
||||||
|
import org.dromara.common.web.core.BaseController;
|
||||||
|
import org.dromara.system.domain.bo.SysUserBo;
|
||||||
|
import org.dromara.system.domain.bo.SysUserPasswordBo;
|
||||||
|
import org.dromara.system.domain.bo.SysUserProfileBo;
|
||||||
|
import org.dromara.system.domain.vo.AvatarVo;
|
||||||
|
import org.dromara.system.domain.vo.SysOssVo;
|
||||||
|
import org.dromara.system.domain.vo.SysUserVo;
|
||||||
|
import org.dromara.system.domain.vo.UserInfoVo;
|
||||||
|
import org.dromara.system.service.*;
|
||||||
|
import org.dromara.web.domain.bo.EqAppHomeBo;
|
||||||
|
import org.dromara.web.domain.bo.EqAreaBo;
|
||||||
|
import org.dromara.web.domain.bo.EqEquipmentBo;
|
||||||
|
import org.dromara.web.domain.bo.EqShareBo;
|
||||||
|
import org.dromara.web.domain.vo.EqAreaVo;
|
||||||
|
import org.dromara.web.domain.vo.EqEquipmentVo;
|
||||||
|
import org.dromara.web.domain.vo.EqShareVo;
|
||||||
|
import org.dromara.web.domain.vo.EqUserConfigVo;
|
||||||
|
import org.dromara.web.service.IEqAreaService;
|
||||||
|
import org.dromara.web.service.IEqEquipmentService;
|
||||||
|
import org.dromara.web.service.IEqShareService;
|
||||||
|
import org.dromara.web.service.IEqUserConfigService;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* app用户相关
|
||||||
|
*
|
||||||
|
* @author zzc
|
||||||
|
* @date 2024-07-14
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/app/user")
|
||||||
|
public class EqUserController extends BaseController {
|
||||||
|
|
||||||
|
private final ISysUserService userService;
|
||||||
|
private final ISysRoleService roleService;
|
||||||
|
private final ISysPostService postService;
|
||||||
|
private final ISysDeptService deptService;
|
||||||
|
private final ISysTenantService tenantService;
|
||||||
|
private final ISysOssService ossService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户信息
|
||||||
|
*
|
||||||
|
* @return 用户信息
|
||||||
|
*/
|
||||||
|
@GetMapping("/getInfo")
|
||||||
|
public R<UserInfoVo> getInfo() {
|
||||||
|
UserInfoVo userInfoVo = new UserInfoVo();
|
||||||
|
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||||
|
if (TenantHelper.isEnable() && LoginHelper.isSuperAdmin()) {
|
||||||
|
// 超级管理员 如果重新加载用户信息需清除动态租户
|
||||||
|
TenantHelper.clearDynamic();
|
||||||
|
}
|
||||||
|
SysUserVo user = userService.selectUserById(loginUser.getUserId());
|
||||||
|
if (ObjectUtil.isNull(user)) {
|
||||||
|
return R.fail("没有权限访问用户数据!");
|
||||||
|
}
|
||||||
|
userInfoVo.setUser(user);
|
||||||
|
userInfoVo.setPermissions(loginUser.getMenuPermission());
|
||||||
|
userInfoVo.setRoles(loginUser.getRolePermission());
|
||||||
|
return R.ok(userInfoVo);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* *//**
|
||||||
|
* 修改用户
|
||||||
|
*//*
|
||||||
|
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping
|
||||||
|
public R<Void> edit(@Validated @RequestBody SysUserBo user) {
|
||||||
|
userService.checkUserAllowed(user.getUserId());
|
||||||
|
userService.checkUserDataScope(user.getUserId());
|
||||||
|
deptService.checkDeptDataScope(user.getDeptId());
|
||||||
|
if (!userService.checkUserNameUnique(user)) {
|
||||||
|
return R.fail("修改用户'" + user.getUserName() + "'失败,登录账号已存在");
|
||||||
|
} else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
|
||||||
|
return R.fail("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
|
||||||
|
} else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
|
||||||
|
return R.fail("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
||||||
|
}
|
||||||
|
return toAjax(userService.updateUser(user));
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除用户
|
||||||
|
* 删除当前登录用户
|
||||||
|
* @param
|
||||||
|
*/
|
||||||
|
@Log(title = "用户管理", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("")
|
||||||
|
public R<Void> remove() {
|
||||||
|
Long[] userIds = {LoginHelper.getUserId()};
|
||||||
|
return toAjax(userService.deleteUserByIds(userIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改用户信息
|
||||||
|
*/
|
||||||
|
@RepeatSubmit
|
||||||
|
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping
|
||||||
|
public R<Void> updateProfile(@Validated @RequestBody SysUserProfileBo profile) {
|
||||||
|
SysUserBo user = BeanUtil.toBean(profile, SysUserBo.class);
|
||||||
|
user.setUserId(LoginHelper.getUserId());
|
||||||
|
String username = LoginHelper.getUsername();
|
||||||
|
if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
|
||||||
|
return R.fail("修改用户'" + username + "'失败,手机号码已存在");
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
|
||||||
|
return R.fail("修改用户'" + username + "'失败,邮箱账号已存在");
|
||||||
|
}
|
||||||
|
if (userService.updateUserProfile(user) > 0) {
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
return R.fail("修改个人信息异常,请联系管理员");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重置密码
|
||||||
|
*
|
||||||
|
* @param bo 新旧密码
|
||||||
|
*/
|
||||||
|
@RepeatSubmit
|
||||||
|
//@ApiEncrypt
|
||||||
|
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping("/updatePwd")
|
||||||
|
public R<Void> updatePwd(@Validated @RequestBody SysUserPasswordBo bo) {
|
||||||
|
SysUserVo user = userService.selectUserById(LoginHelper.getUserId());
|
||||||
|
String password = user.getPassword();
|
||||||
|
if (!BCrypt.checkpw(bo.getOldPassword(), password)) {
|
||||||
|
return R.fail("修改密码失败,旧密码错误");
|
||||||
|
}
|
||||||
|
if (BCrypt.checkpw(bo.getNewPassword(), password)) {
|
||||||
|
return R.fail("新密码不能与旧密码相同");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userService.resetUserPwd(user.getUserId(), BCrypt.hashpw(bo.getNewPassword())) > 0) {
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
return R.fail("修改密码异常,请联系管理员");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 头像上传
|
||||||
|
*
|
||||||
|
* @param avatarfile 用户头像
|
||||||
|
*/
|
||||||
|
@RepeatSubmit
|
||||||
|
@Log(title = "用户头像", businessType = BusinessType.UPDATE)
|
||||||
|
@PostMapping(value = "/avatar", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
|
public R<AvatarVo> avatar(@RequestPart("avatarfile") MultipartFile avatarfile) {
|
||||||
|
if (!avatarfile.isEmpty()) {
|
||||||
|
String extension = FileUtil.extName(avatarfile.getOriginalFilename());
|
||||||
|
if (!StringUtils.equalsAnyIgnoreCase(extension, MimeTypeUtils.IMAGE_EXTENSION)) {
|
||||||
|
return R.fail("文件格式不正确,请上传" + Arrays.toString(MimeTypeUtils.IMAGE_EXTENSION) + "格式");
|
||||||
|
}
|
||||||
|
SysOssVo oss = ossService.upload(avatarfile);
|
||||||
|
String avatar = oss.getUrl();
|
||||||
|
if (userService.updateUserAvatar(LoginHelper.getUserId(), oss.getOssId())) {
|
||||||
|
AvatarVo avatarVo = new AvatarVo();
|
||||||
|
avatarVo.setImgUrl(avatar);
|
||||||
|
return R.ok(avatarVo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return R.fail("上传图片异常,请联系管理员");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码验证
|
||||||
|
* @param bo
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/checkPassword")
|
||||||
|
public R<Boolean> checkPassword(EqAppHomeBo bo){
|
||||||
|
//密码验证
|
||||||
|
if (bo.getUserId()==null||bo.getPassword()== null) throw new ServiceException("用户ID或密码不能为空");
|
||||||
|
SysUserVo sysUserVo = userService.selectUserById(bo.getUserId());
|
||||||
|
if (sysUserVo == null) throw new ServiceException("用户不存在");
|
||||||
|
return R.ok(BCrypt.checkpw(bo.getPassword(), sysUserVo.getPassword()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private final IEqShareService eqShareService;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ public class EqUserConfigBo extends BaseEntity {
|
|||||||
/**
|
/**
|
||||||
* 时间格式
|
* 时间格式
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "时间格式不能为空", groups = { AddGroup.class, EditGroup.class })
|
// @NotNull(message = "时间格式不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||||
private String timeFormat;
|
private String timeFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user