mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
[update]更新代码规范
This commit is contained in:
parent
c06d6e53f6
commit
79da36ac04
@ -1,12 +1,12 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.file;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.service.file.InfFileService;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.controller.file.vo.InfFilePageReqVO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.controller.file.vo.InfFileRespVO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFilePageReqVO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFileRespVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.convert.file.InfFileConvert;
|
||||
import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
@ -35,7 +35,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
public class InfFileController {
|
||||
|
||||
@Resource
|
||||
private InfFileCoreService fileService;
|
||||
private InfFileService fileService;
|
||||
|
||||
@PostMapping("/upload")
|
||||
@ApiOperation("上传文件")
|
||||
|
@ -1,8 +1,8 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.convert.file;
|
||||
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.controller.file.vo.InfFileRespVO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFileRespVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
|
@ -0,0 +1,46 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.service.file;
|
||||
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.controller.file.vo.InfFilePageReqVO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
/**
|
||||
* 文件 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface InfFileService {
|
||||
|
||||
/**
|
||||
* 保存文件,并返回文件的访问路径
|
||||
*
|
||||
* @param path 文件路径
|
||||
* @param content 文件内容
|
||||
* @return 文件路径
|
||||
*/
|
||||
String createFile(String path, byte[] content);
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteFile(String id);
|
||||
|
||||
/**
|
||||
* 获得文件
|
||||
*
|
||||
* @param path 文件路径
|
||||
* @return 文件
|
||||
*/
|
||||
InfFileDO getFile(String path);
|
||||
|
||||
/**
|
||||
* 获得文件分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 文件分页
|
||||
*/
|
||||
PageResult<InfFileDO> getFilePage(InfFilePageReqVO pageReqVO);
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.service.file.impl;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.service.file.InfFileService;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.controller.file.vo.InfFilePageReqVO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.file.InfFileCoreMapper;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 文件 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
public class InfFileServiceImpl implements InfFileService {
|
||||
@Resource
|
||||
private InfFileCoreMapper fileCoreMapper;
|
||||
|
||||
@Resource
|
||||
private InfFileCoreService fileCoreService;
|
||||
|
||||
@Override
|
||||
public String createFile(String path, byte[] content) {
|
||||
return fileCoreService.createFile(path,content);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFile(String id) {
|
||||
fileCoreService.deleteFile(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InfFileDO getFile(String path) {
|
||||
return fileCoreService.getFile(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<InfFileDO> getFilePage(InfFilePageReqVO pageReqVO) {
|
||||
return fileCoreMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
}
|
@ -2,12 +2,12 @@ package cn.iocoder.yudao.adminserver.modules.infra.service.file;
|
||||
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.iocoder.yudao.adminserver.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.controller.file.vo.InfFilePageReqVO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.file.InfFileCoreMapper;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.service.file.impl.InfFileCoreServiceImpl;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.framework.file.config.FileProperties;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFilePageReqVO;
|
||||
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
@ -28,7 +28,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
public class InfFileServiceTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private InfFileCoreServiceImpl fileService;
|
||||
private InfFileService fileService;
|
||||
|
||||
@MockBean
|
||||
private FileProperties fileProperties;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cn.iocoder.yudao.coreservice.modules.infra.file.vo;
|
||||
package cn.iocoder.yudao.coreservice.modules.infra.controller.file.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.annotations.ApiModel;
|
@ -1,4 +1,4 @@
|
||||
package cn.iocoder.yudao.coreservice.modules.infra.file.vo;
|
||||
package cn.iocoder.yudao.coreservice.modules.infra.controller.file.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
@ -1,6 +1,6 @@
|
||||
package cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.file;
|
||||
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFilePageReqVO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.controller.file.vo.InfFilePageReqVO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO;
|
||||
|
@ -1,14 +1,11 @@
|
||||
package cn.iocoder.yudao.coreservice.modules.infra.service.file;
|
||||
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFilePageReqVO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
/**
|
||||
* @Class:ruoyi-vue-pro.cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService
|
||||
* @Descript: 文件 core Service 接口
|
||||
* @Author:宋天
|
||||
* @Date:2021/10/19
|
||||
* core service 文件接口
|
||||
*
|
||||
* @author 宋天
|
||||
*/
|
||||
public interface InfFileCoreService {
|
||||
|
||||
@ -36,12 +33,4 @@ public interface InfFileCoreService {
|
||||
* @return 文件
|
||||
*/
|
||||
InfFileDO getFile(String path);
|
||||
|
||||
/**
|
||||
* 获得文件分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 文件分页
|
||||
*/
|
||||
PageResult<InfFileDO> getFilePage(InfFilePageReqVO pageReqVO);
|
||||
}
|
||||
|
@ -3,24 +3,20 @@ package cn.iocoder.yudao.coreservice.modules.infra.service.file.impl;
|
||||
import cn.hutool.core.io.FileTypeUtil;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.file.InfFileCoreMapper;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.file.vo.InfFilePageReqVO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.framework.file.config.FileProperties;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
import static cn.iocoder.yudao.coreservice.modules.system.enums.SysErrorCodeConstants.FILE_NOT_EXISTS;
|
||||
import static cn.iocoder.yudao.coreservice.modules.system.enums.SysErrorCodeConstants.FILE_PATH_EXISTS;
|
||||
import static cn.iocoder.yudao.coreservice.modules.system.enums.SysErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
|
||||
/**
|
||||
* @Class:ruoyi-vue-pro.cn.iocoder.yudao.coreservice.modules.infra.service.file.impl.InfFileCoreServiceImpl
|
||||
* @Descript: core service 文件实现类
|
||||
* @Author:宋天
|
||||
* @Date:2021/10/19
|
||||
* core service 文件实现类
|
||||
*
|
||||
* @author 宋天
|
||||
*/
|
||||
@Service
|
||||
public class InfFileCoreServiceImpl implements InfFileCoreService {
|
||||
@ -65,9 +61,4 @@ public class InfFileCoreServiceImpl implements InfFileCoreService {
|
||||
return fileMapper.selectById(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<InfFileDO> getFilePage(InfFilePageReqVO pageReqVO) {
|
||||
return fileMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ GET {{userServerUrl}}/system/user/profile/get
|
||||
Authorization: Bearer test245
|
||||
|
||||
### 请求 /system/user/profile/revise-nickname 接口 成功
|
||||
PUT http://localhost:28080/api/system/user/profile/revise-nickname?nickName=yunai111
|
||||
PUT http://localhost:28080/api/system/user/profile/update-nickname?nickName=yunai222
|
||||
Authorization: Bearer test245
|
||||
|
||||
### 请求 /system/user/profile/get-user-info 接口 成功
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.iocoder.yudao.userserver.modules.member.controller.user;
|
||||
|
||||
import cn.iocoder.yudao.coreservice.modules.system.controller.user.vo.SysUserCoreProfileRespVo;
|
||||
import cn.iocoder.yudao.userserver.modules.member.controller.user.vo.SysUserInfoRespVO;
|
||||
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
|
||||
@ -37,15 +37,17 @@ public class SysUserProfileController {
|
||||
return null;
|
||||
}
|
||||
|
||||
@PutMapping("/revise-nickname")
|
||||
@PutMapping("/update-nickname")
|
||||
@ApiOperation("修改用户昵称")
|
||||
public CommonResult<Boolean> reviseNickname(@RequestParam("nickName") String nickName) {
|
||||
userService.reviseNickname(getLoginUserId(), nickName);
|
||||
@PreAuthenticated
|
||||
public CommonResult<Boolean> updateNickname(@RequestParam("nickName") String nickName) {
|
||||
userService.updateNickname(getLoginUserId(), nickName);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PutMapping("/revise-avatar")
|
||||
@ApiOperation("修改用户头像")
|
||||
@PreAuthenticated
|
||||
public CommonResult<String> reviseAvatar(@RequestParam("avatarFile") MultipartFile file) throws IOException {
|
||||
if (file.isEmpty()) {
|
||||
throw ServiceExceptionUtil.exception(FILE_IS_EMPTY);
|
||||
@ -56,8 +58,9 @@ public class SysUserProfileController {
|
||||
|
||||
@GetMapping("/get-user-info")
|
||||
@ApiOperation("获取用户头像与昵称")
|
||||
public CommonResult<SysUserCoreProfileRespVo> getUserInfo(@RequestParam("id") Long id) {
|
||||
return success(userService.getUserInfo(id));
|
||||
@PreAuthenticated
|
||||
public CommonResult<SysUserInfoRespVO> getUserInfo() {
|
||||
return success(userService.getUserInfo(getLoginUserId()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cn.iocoder.yudao.coreservice.modules.system.controller.user.vo;
|
||||
package cn.iocoder.yudao.userserver.modules.member.controller.user.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
@ -6,11 +6,11 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@ApiModel("用户个人信息 Response VO")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@ApiModel("用户个人中心信息 Response VO")
|
||||
public class SysUserCoreProfileRespVo {
|
||||
public class SysUserInfoRespVO {
|
||||
|
||||
@ApiModelProperty(value = "用户昵称", required = true, example = "芋艿")
|
||||
private String nickName;
|
@ -9,9 +9,9 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode;
|
||||
*/
|
||||
public interface MbrErrorCodeConstants {
|
||||
|
||||
// 用户相关
|
||||
ErrorCode USER_NOT_EXISTS = new ErrorCode(1004000000, "用户不存在");
|
||||
// ==========用户相关============
|
||||
ErrorCode USER_NOT_EXISTS = new ErrorCode(1004001000, "用户不存在");
|
||||
|
||||
// 文件相关
|
||||
ErrorCode FILE_IS_EMPTY = new ErrorCode(1004000000, "用户不存在");
|
||||
// ==========文件相关 ===========
|
||||
ErrorCode FILE_IS_EMPTY = new ErrorCode(1004002000, "文件不存在");
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package cn.iocoder.yudao.userserver.modules.member.service.user;
|
||||
|
||||
import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO;
|
||||
import cn.iocoder.yudao.coreservice.modules.system.controller.user.vo.SysUserCoreProfileRespVo;
|
||||
import cn.iocoder.yudao.userserver.modules.member.controller.user.vo.SysUserInfoRespVO;
|
||||
import cn.iocoder.yudao.framework.common.validation.Mobile;
|
||||
|
||||
import java.io.InputStream;
|
||||
@ -49,24 +49,24 @@ public interface MbrUserService {
|
||||
|
||||
/**
|
||||
* 修改用户昵称
|
||||
* @param loginUserId 登录用户id
|
||||
* @param userId 用户id
|
||||
* @param nickName 用户新昵称
|
||||
*/
|
||||
void reviseNickname(Long loginUserId, String nickName);
|
||||
void updateNickname(Long userId, String nickName);
|
||||
|
||||
/**
|
||||
* 修改用户头像
|
||||
* @param loginUserId 登录用户id
|
||||
* @param userId 用户id
|
||||
* @param inputStream 头像文件
|
||||
* @return 头像url
|
||||
*/
|
||||
String reviseAvatar(Long loginUserId, InputStream inputStream);
|
||||
String reviseAvatar(Long userId, InputStream inputStream);
|
||||
|
||||
/**
|
||||
* 根据用户id,获取用户头像与昵称
|
||||
* @param loginUserId 登录用户id
|
||||
* @param userId 用户id
|
||||
* @return 用户响应实体类
|
||||
*/
|
||||
SysUserCoreProfileRespVo getUserInfo(Long loginUserId);
|
||||
SysUserInfoRespVO getUserInfo(Long userId);
|
||||
|
||||
}
|
||||
|
@ -4,8 +4,7 @@ import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService;
|
||||
import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO;
|
||||
import cn.iocoder.yudao.coreservice.modules.system.controller.user.vo.SysUserCoreProfileRespVo;
|
||||
import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO;
|
||||
import cn.iocoder.yudao.userserver.modules.member.controller.user.vo.SysUserInfoRespVO;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.userserver.modules.member.dal.mysql.user.MbrUserMapper;
|
||||
import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService;
|
||||
@ -81,52 +80,51 @@ public class MbrUserServiceImpl implements MbrUserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reviseNickname(Long loginUserId, String nickName) {
|
||||
MbrUserDO mbrUserDO = userMapper.selectById(loginUserId);
|
||||
public void updateNickname(Long userId, String nickName) {
|
||||
MbrUserDO user = this.checkUserExists(userId);
|
||||
// 仅当新昵称不等于旧昵称时进行修改
|
||||
if (!nickName.equals(mbrUserDO.getNickname())){
|
||||
MbrUserDO user = new MbrUserDO();
|
||||
user.setId(mbrUserDO.getId());
|
||||
user.setNickname(nickName);
|
||||
userMapper.updateById(user);
|
||||
if (nickName.equals(user.getNickname())){
|
||||
return;
|
||||
}
|
||||
MbrUserDO userDO = new MbrUserDO();
|
||||
userDO.setId(user.getId());
|
||||
userDO.setNickname(nickName);
|
||||
userMapper.updateById(userDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String reviseAvatar(Long loginUserId, InputStream avatarFile) {
|
||||
this.checkUserExists(loginUserId);
|
||||
public String reviseAvatar(Long userId, InputStream avatarFile) {
|
||||
this.checkUserExists(userId);
|
||||
// 创建文件
|
||||
String avatar = fileCoreService.createFile(IdUtil.fastUUID(), IoUtil.readBytes(avatarFile));
|
||||
// 更新头像路径
|
||||
MbrUserDO userDO = new MbrUserDO();
|
||||
userDO.setId(loginUserId);
|
||||
userDO.setAvatar(avatar);
|
||||
MbrUserDO userDO = MbrUserDO.builder()
|
||||
.id(userId)
|
||||
.avatar(avatar)
|
||||
.build();
|
||||
userMapper.updateById(userDO);
|
||||
return avatar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUserCoreProfileRespVo getUserInfo(Long loginUserId) {
|
||||
MbrUserDO mbrUserDO = userMapper.selectById(loginUserId);
|
||||
if (mbrUserDO == null){
|
||||
log.error("用户不存在:{}",loginUserId);
|
||||
throw exception(USER_NOT_EXISTS);
|
||||
}
|
||||
|
||||
SysUserCoreProfileRespVo userRes = new SysUserCoreProfileRespVo();
|
||||
userRes.setNickName(mbrUserDO.getNickname());
|
||||
userRes.setAvatar(mbrUserDO.getAvatar());
|
||||
return userRes;
|
||||
public SysUserInfoRespVO getUserInfo(Long userId) {
|
||||
MbrUserDO user = this.checkUserExists(userId);
|
||||
SysUserInfoRespVO userResp = new SysUserInfoRespVO();
|
||||
userResp.setNickName(user.getNickname());
|
||||
userResp.setAvatar(user.getAvatar());
|
||||
return userResp;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void checkUserExists(Long id) {
|
||||
public MbrUserDO checkUserExists(Long id) {
|
||||
if (id == null) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
MbrUserDO user = userMapper.selectById(id);
|
||||
if (user == null) {
|
||||
throw exception(USER_NOT_EXISTS);
|
||||
}else{
|
||||
return user;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user