feat(新增): 用户修改头像
This commit is contained in:
parent
0bbc0b5cd2
commit
149b44640e
|
@ -17,6 +17,27 @@
|
||||||
const formRef = ref();
|
const formRef = ref();
|
||||||
const ${lowercaseName}Store = use${originalName}Store();
|
const ${lowercaseName}Store = use${originalName}Store();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 当前页改变时
|
||||||
|
*/
|
||||||
|
const onCurrentPageChange = async (value: number) => {
|
||||||
|
${lowercaseName}Store.pagination.currentPage = value;
|
||||||
|
await onSearch();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 当分页发生变化
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
const onPageSizeChange = async (value: number) => {
|
||||||
|
${lowercaseName}Store.pagination.pageSize = value;
|
||||||
|
await onSearch();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重置表单
|
||||||
|
* @param formEl
|
||||||
|
*/
|
||||||
const resetForm = async formEl => {
|
const resetForm = async formEl => {
|
||||||
if (!formEl) return;
|
if (!formEl) return;
|
||||||
formEl.resetFields();
|
formEl.resetFields();
|
||||||
|
@ -63,6 +84,9 @@
|
||||||
row-key="id"
|
row-key="id"
|
||||||
showOverflowTooltip
|
showOverflowTooltip
|
||||||
table-layout="auto"
|
table-layout="auto"
|
||||||
|
:pagination="${lowercaseName}Store.pagination"
|
||||||
|
@page-size-change="onPageSizeChange"
|
||||||
|
@page-current-change="onCurrentPageChange"
|
||||||
>
|
>
|
||||||
|
|
||||||
<template #createUser="{ row }">
|
<template #createUser="{ row }">
|
||||||
|
|
|
@ -76,7 +76,9 @@ public class GlobalExceptionHandler {
|
||||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||||
public Result<String> handleValidationExceptions(MethodArgumentNotValidException ex) {
|
public Result<String> handleValidationExceptions(MethodArgumentNotValidException ex) {
|
||||||
log.error("表单验证失败:{}", ex.getMessage());
|
log.error("表单验证失败:{}", ex.getMessage());
|
||||||
String errorMessage = ex.getBindingResult().getFieldErrors().stream().map(DefaultMessageSourceResolvable::getDefaultMessage).collect(Collectors.joining(", "));
|
String errorMessage = ex.getBindingResult().getFieldErrors().stream()
|
||||||
|
.map(DefaultMessageSourceResolvable::getDefaultMessage)
|
||||||
|
.collect(Collectors.joining(", "));
|
||||||
return Result.error(null, 201, errorMessage);
|
return Result.error(null, 201, errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package cn.bunny.dao.dto.system.files;
|
package cn.bunny.dao.dto.system.files;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
@ -15,9 +17,11 @@ import org.springframework.web.multipart.MultipartFile;
|
||||||
public class FileUploadDto {
|
public class FileUploadDto {
|
||||||
|
|
||||||
@Schema(name = "file", title = "文件")
|
@Schema(name = "file", title = "文件")
|
||||||
|
@NotNull(message = "文件不能为空")
|
||||||
MultipartFile file;
|
MultipartFile file;
|
||||||
|
|
||||||
@Schema(name = "type", title = "文件类型")
|
@Schema(name = "type", title = "文件类型")
|
||||||
|
@NotBlank(message = "文件类型不能为空")
|
||||||
String type;
|
String type;
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package cn.bunny.dao.dto.system.user;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@Schema(name = "UserUpdateWithAvatarDto对象", title = "管理员用户修改头像", description = "管理员用户修改头像")
|
||||||
|
public class UserUpdateWithAvatarDto {
|
||||||
|
|
||||||
|
@Schema(name = "userId", title = "用户ID")
|
||||||
|
@NotNull(message = "用户ID不能为空")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
@Schema(name = "avatar", title = "用户头像")
|
||||||
|
@NotBlank(message = "用户头像不能为空")
|
||||||
|
@NotEmpty
|
||||||
|
private String avatar;
|
||||||
|
|
||||||
|
}
|
|
@ -26,3 +26,4 @@ public class UserUpdateWithPasswordDto {
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package cn.bunny.services.Bunny;
|
package cn.bunny.dao.entity.system;
|
||||||
|
|
||||||
import cn.bunny.dao.entity.BaseEntity;
|
import cn.bunny.dao.entity.BaseEntity;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
|
@ -70,6 +70,14 @@ public class UserController {
|
||||||
return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
|
return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "管理员上传用户头像", description = "管理员上传用户头像")
|
||||||
|
@PutMapping("uploadAvatarByAdmin")
|
||||||
|
public Result<String> uploadAvatarByAdmin(@Valid UserUpdateWithAvatarDto dto) {
|
||||||
|
userService.uploadAvatarByAdmin(dto);
|
||||||
|
return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Operation(summary = "登录发送邮件验证码", description = "登录发送邮件验证码")
|
@Operation(summary = "登录发送邮件验证码", description = "登录发送邮件验证码")
|
||||||
@PostMapping("noAuth/sendLoginEmail")
|
@PostMapping("noAuth/sendLoginEmail")
|
||||||
public Result<String> sendLoginEmail(String email) {
|
public Result<String> sendLoginEmail(String email) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package cn.bunny.services.mapper;
|
package cn.bunny.services.mapper;
|
||||||
|
|
||||||
import cn.bunny.services.Bunny.Files;
|
import cn.bunny.dao.entity.system.Files;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package cn.bunny.services.service;
|
package cn.bunny.services.service;
|
||||||
|
|
||||||
import cn.bunny.dao.dto.system.files.FileUploadDto;
|
import cn.bunny.dao.dto.system.files.FileUploadDto;
|
||||||
|
import cn.bunny.dao.entity.system.Files;
|
||||||
import cn.bunny.dao.vo.system.files.FileInfoVo;
|
import cn.bunny.dao.vo.system.files.FileInfoVo;
|
||||||
import cn.bunny.services.Bunny.Files;
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -86,4 +86,11 @@ public interface UserService extends IService<AdminUser> {
|
||||||
* @param dto 管理员用户修改密码
|
* @param dto 管理员用户修改密码
|
||||||
*/
|
*/
|
||||||
void updateUserPasswordByAdmin(UserUpdateWithPasswordDto dto);
|
void updateUserPasswordByAdmin(UserUpdateWithPasswordDto dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 管理员上传用户头像
|
||||||
|
*
|
||||||
|
* @param dto 管理员用户修改头像
|
||||||
|
*/
|
||||||
|
void uploadAvatarByAdmin(UserUpdateWithAvatarDto dto);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,10 @@ import cn.bunny.common.service.exception.BunnyException;
|
||||||
import cn.bunny.common.service.utils.FileUtil;
|
import cn.bunny.common.service.utils.FileUtil;
|
||||||
import cn.bunny.common.service.utils.minio.MinioUtil;
|
import cn.bunny.common.service.utils.minio.MinioUtil;
|
||||||
import cn.bunny.dao.dto.system.files.FileUploadDto;
|
import cn.bunny.dao.dto.system.files.FileUploadDto;
|
||||||
|
import cn.bunny.dao.entity.system.Files;
|
||||||
import cn.bunny.dao.pojo.common.MinioFIlePath;
|
import cn.bunny.dao.pojo.common.MinioFIlePath;
|
||||||
import cn.bunny.dao.pojo.result.ResultCodeEnum;
|
import cn.bunny.dao.pojo.result.ResultCodeEnum;
|
||||||
import cn.bunny.dao.vo.system.files.FileInfoVo;
|
import cn.bunny.dao.vo.system.files.FileInfoVo;
|
||||||
import cn.bunny.services.Bunny.Files;
|
|
||||||
import cn.bunny.services.mapper.FilesMapper;
|
import cn.bunny.services.mapper.FilesMapper;
|
||||||
import cn.bunny.services.service.FilesService;
|
import cn.bunny.services.service.FilesService;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
|
|
@ -165,6 +165,27 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, AdminUser> implemen
|
||||||
updateById(adminUser);
|
updateById(adminUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 管理员上传用户头像
|
||||||
|
*
|
||||||
|
* @param dto 管理员用户修改头像
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void uploadAvatarByAdmin(UserUpdateWithAvatarDto dto) {
|
||||||
|
String avatar = dto.getAvatar();
|
||||||
|
Long userId = dto.getUserId();
|
||||||
|
|
||||||
|
// 判断是否存在这个用户
|
||||||
|
AdminUser adminUser = getOne(Wrappers.<AdminUser>lambdaQuery().eq(AdminUser::getId, userId));
|
||||||
|
if (adminUser == null) throw new BunnyException(ResultCodeEnum.USER_IS_EMPTY);
|
||||||
|
|
||||||
|
// 更新用户
|
||||||
|
adminUser = new AdminUser();
|
||||||
|
adminUser.setId(userId);
|
||||||
|
adminUser.setAvatar(avatar);
|
||||||
|
updateById(adminUser);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* * 用户信息 服务实现类
|
* * 用户信息 服务实现类
|
||||||
*
|
*
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<mapper namespace="cn.bunny.services.mapper.FilesMapper">
|
<mapper namespace="cn.bunny.services.mapper.FilesMapper">
|
||||||
|
|
||||||
<!-- 通用查询映射结果 -->
|
<!-- 通用查询映射结果 -->
|
||||||
<resultMap id="BaseResultMap" type="cn.bunny.services.Bunny.Files">
|
<resultMap id="BaseResultMap" type="cn.bunny.dao.entity.system.Files">
|
||||||
<id column="id" property="id"/>
|
<id column="id" property="id"/>
|
||||||
<result column="filename" property="filename"/>
|
<result column="filename" property="filename"/>
|
||||||
<result column="filepath" property="filepath"/>
|
<result column="filepath" property="filepath"/>
|
||||||
|
|
Loading…
Reference in New Issue