refactor: 重命名 app 模块为 client 与 open 模块
- 将 app 包下的用户、文件相关类迁移到 client 包 - 将认证相关类迁移到 open 包,并更新安全配置放行路径 - 修复 ApkMetaParser 合并元数据时图标未保留的问题 - 调整 FilePath 上传路径逻辑
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -17,3 +17,4 @@ docker/*/data/
|
||||
docker/minio/config
|
||||
docker/xxljob/logs
|
||||
application-youlai.yml
|
||||
/uploadFile/
|
||||
|
||||
@@ -935,6 +935,10 @@ public class ApkMetaParser {
|
||||
if (!Objects.equals(target.getTargetSdk(), source.getTargetSdk())) {
|
||||
target.setTargetSdk(source.getTargetSdk());
|
||||
}
|
||||
if (target.getIconBytes() == null) {
|
||||
target.setIconBytes(source.getIconBytes());
|
||||
target.setIconPath(source.getIconPath());
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isNotEmpty(List<?> list) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.youlai.boot.app.controller;
|
||||
package com.youlai.boot.client.controller;
|
||||
|
||||
import com.youlai.boot.app.model.vo.AppFileInfo;
|
||||
import com.youlai.boot.app.service.AppFileService;
|
||||
import com.youlai.boot.client.model.vo.ClientFileInfo;
|
||||
import com.youlai.boot.client.service.ClientFileService;
|
||||
import com.youlai.boot.common.result.Result;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@@ -22,15 +22,15 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
*/
|
||||
@Tag(name = "10.文件接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/app/files")
|
||||
@RequestMapping("/api/v1/client/files")
|
||||
@RequiredArgsConstructor
|
||||
public class AppFileController {
|
||||
public class ClientFileController {
|
||||
|
||||
private final AppFileService fileService;
|
||||
private final ClientFileService fileService;
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "文件上传")
|
||||
public Result<AppFileInfo> uploadFile(
|
||||
public Result<ClientFileInfo> uploadFile(
|
||||
@Parameter(
|
||||
name = "file",
|
||||
description = "表单文件对象",
|
||||
@@ -41,7 +41,7 @@ public class AppFileController {
|
||||
@RequestPart(value = "file") MultipartFile file
|
||||
) {
|
||||
Assert.isTrue(!file.isEmpty(), "上传文件不能为空文件");
|
||||
AppFileInfo fileInfo = fileService.uploadFile(file);
|
||||
ClientFileInfo fileInfo = fileService.uploadFile(file);
|
||||
return Result.success(fileInfo);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.youlai.boot.app.model.entity;
|
||||
package com.youlai.boot.client.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.youlai.boot.common.base.BaseEntity;
|
||||
@@ -11,7 +11,7 @@ import lombok.Setter;
|
||||
@TableName("app_user")
|
||||
@Getter
|
||||
@Setter
|
||||
public class AppUser extends BaseEntity {
|
||||
public class ClientUser extends BaseEntity {
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.youlai.boot.app.model.form;
|
||||
package com.youlai.boot.client.model.form;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
@@ -17,7 +17,7 @@ import java.util.List;
|
||||
*/
|
||||
@Schema(description = "用户表单对象")
|
||||
@Data
|
||||
public class AppUserForm {
|
||||
public class ClientUserForm {
|
||||
|
||||
@Schema(description="用户ID")
|
||||
private Long id;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.youlai.boot.app.model.vo;
|
||||
package com.youlai.boot.client.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
@@ -12,7 +12,7 @@ import lombok.Data;
|
||||
*/
|
||||
@Schema(description = "文件对象")
|
||||
@Data
|
||||
public class AppFileInfo {
|
||||
public class ClientFileInfo {
|
||||
|
||||
@Schema(description = "文件名称")
|
||||
private String name;
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.youlai.boot.app.service;
|
||||
package com.youlai.boot.client.service;
|
||||
|
||||
import com.youlai.boot.app.model.vo.AppFileInfo;
|
||||
import com.youlai.boot.client.model.vo.ClientFileInfo;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
@@ -9,14 +9,14 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
* @author haoxr
|
||||
* @since 2022/11/19
|
||||
*/
|
||||
public interface AppFileService {
|
||||
public interface ClientFileService {
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
* @param file 表单文件对象
|
||||
* @return 文件信息
|
||||
*/
|
||||
AppFileInfo uploadFile(MultipartFile file);
|
||||
ClientFileInfo uploadFile(MultipartFile file);
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
@@ -1,12 +1,11 @@
|
||||
package com.youlai.boot.app.service;
|
||||
package com.youlai.boot.client.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.youlai.boot.app.model.entity.AppUser;
|
||||
import com.youlai.boot.app.model.form.AppUserForm;
|
||||
import com.youlai.boot.client.model.entity.ClientUser;
|
||||
import com.youlai.boot.client.model.form.ClientUserForm;
|
||||
import com.youlai.boot.common.model.Option;
|
||||
import com.youlai.boot.framework.security.model.SecurityUser;
|
||||
import com.youlai.boot.system.model.entity.SysUser;
|
||||
import com.youlai.boot.system.model.form.*;
|
||||
import com.youlai.boot.system.model.query.UserQuery;
|
||||
import com.youlai.boot.system.model.vo.CurrentUserVO;
|
||||
@@ -22,7 +21,7 @@ import java.util.List;
|
||||
* @author Ray.Hao
|
||||
* @since 2022/1/14
|
||||
*/
|
||||
public interface AppUserService extends IService<AppUser> {
|
||||
public interface ClientUserService extends IService<ClientUser> {
|
||||
|
||||
/**
|
||||
* 用户分页列表
|
||||
@@ -35,9 +34,9 @@ public interface AppUserService extends IService<AppUser> {
|
||||
* 获取用户表单数据
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return {@link AppUserForm} 用户表单数据
|
||||
* @return {@link ClientUserForm} 用户表单数据
|
||||
*/
|
||||
AppUserForm getUserFormData(Long userId);
|
||||
ClientUserForm getUserFormData(Long userId);
|
||||
|
||||
|
||||
/**
|
||||
@@ -46,7 +45,7 @@ public interface AppUserService extends IService<AppUser> {
|
||||
* @param userForm 用户表单对象
|
||||
* @return {@link Boolean} 是否新增成功
|
||||
*/
|
||||
boolean saveUser(AppUserForm userForm);
|
||||
boolean saveUser(ClientUserForm userForm);
|
||||
|
||||
/**
|
||||
* 修改用户
|
||||
@@ -55,7 +54,7 @@ public interface AppUserService extends IService<AppUser> {
|
||||
* @param userForm 用户表单对象
|
||||
* @return {@link Boolean} 是否修改成功
|
||||
*/
|
||||
boolean updateUser(Long userId, AppUserForm userForm);
|
||||
boolean updateUser(Long userId, ClientUserForm userForm);
|
||||
|
||||
|
||||
/**
|
||||
@@ -1,17 +1,15 @@
|
||||
package com.youlai.boot.app.service.impl;
|
||||
package com.youlai.boot.client.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.youlai.boot.app.model.vo.AppFileInfo;
|
||||
import com.youlai.boot.app.service.AppFileService;
|
||||
import com.youlai.boot.client.model.vo.ClientFileInfo;
|
||||
import com.youlai.boot.client.service.ClientFileService;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@@ -31,7 +29,7 @@ import java.time.LocalDateTime;
|
||||
//@ConditionalOnProperty(value = "oss.type", havingValue = "local")
|
||||
//@ConfigurationProperties(prefix = "oss.local")
|
||||
@RequiredArgsConstructor
|
||||
public class LocalAppFileService implements AppFileService {
|
||||
public class ClientClientFileService implements ClientFileService {
|
||||
|
||||
@Value("${file-storage.local.path}")
|
||||
private String storagePath;
|
||||
@@ -43,7 +41,7 @@ public class LocalAppFileService implements AppFileService {
|
||||
* @return 文件信息
|
||||
*/
|
||||
@Override
|
||||
public AppFileInfo uploadFile(MultipartFile file) {
|
||||
public ClientFileInfo uploadFile(MultipartFile file) {
|
||||
// 获取文件名
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
// 获取文件后缀
|
||||
@@ -63,7 +61,7 @@ public class LocalAppFileService implements AppFileService {
|
||||
}
|
||||
// 获取文件访问路径,因为这里是本地存储,所以直接返回文件的相对路径,需要前端自行处理访问前缀
|
||||
String fileUrl = File.separator + folder + File.separator + fileName;
|
||||
AppFileInfo fileInfo = new AppFileInfo();
|
||||
ClientFileInfo fileInfo = new ClientFileInfo();
|
||||
fileInfo.setName(originalFilename);
|
||||
fileInfo.setUrl(fileUrl);
|
||||
return fileInfo;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.youlai.boot.app.service.impl;
|
||||
package com.youlai.boot.client.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
@@ -8,11 +8,11 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.youlai.boot.app.converter.AppUserConverter;
|
||||
import com.youlai.boot.app.mapper.AppUserMapper;
|
||||
import com.youlai.boot.app.model.entity.AppUser;
|
||||
import com.youlai.boot.app.model.form.AppUserForm;
|
||||
import com.youlai.boot.app.service.AppUserService;
|
||||
import com.youlai.boot.open.converter.ClientUserConverter;
|
||||
import com.youlai.boot.open.mapper.ClientUserMapper;
|
||||
import com.youlai.boot.client.model.entity.ClientUser;
|
||||
import com.youlai.boot.client.model.form.ClientUserForm;
|
||||
import com.youlai.boot.client.service.ClientUserService;
|
||||
import com.youlai.boot.common.constant.RedisConstants;
|
||||
import com.youlai.boot.common.constant.SystemConstants;
|
||||
import com.youlai.boot.common.exception.BusinessException;
|
||||
@@ -24,10 +24,7 @@ import com.youlai.boot.framework.security.util.SecurityUtils;
|
||||
import com.youlai.boot.support.mail.EmailService;
|
||||
import com.youlai.boot.support.sms.SmsService;
|
||||
import com.youlai.boot.support.sms.SmsTypeEnum;
|
||||
import com.youlai.boot.system.converter.UserConverter;
|
||||
import com.youlai.boot.system.enums.DictCodeEnum;
|
||||
import com.youlai.boot.system.mapper.UserMapper;
|
||||
import com.youlai.boot.system.model.entity.Dept;
|
||||
import com.youlai.boot.system.model.entity.DictItem;
|
||||
import com.youlai.boot.system.model.entity.Role;
|
||||
import com.youlai.boot.system.model.form.*;
|
||||
@@ -55,7 +52,7 @@ import java.util.stream.Collectors;
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> implements AppUserService {
|
||||
public class ClientUserServiceImpl extends ServiceImpl<ClientUserMapper, ClientUser> implements ClientUserService {
|
||||
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
|
||||
@@ -77,7 +74,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
||||
|
||||
private final DictItemService dictItemService;
|
||||
|
||||
private final AppUserConverter userConverter;
|
||||
private final ClientUserConverter userConverter;
|
||||
|
||||
|
||||
/**
|
||||
@@ -105,10 +102,10 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
||||
* 获取用户表单数据
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return {@link AppUserForm} 用户表单数据
|
||||
* @return {@link ClientUserForm} 用户表单数据
|
||||
*/
|
||||
@Override
|
||||
public AppUserForm getUserFormData(Long userId) {
|
||||
public ClientUserForm getUserFormData(Long userId) {
|
||||
return this.baseMapper.getUserFormData(userId);
|
||||
}
|
||||
|
||||
@@ -120,16 +117,16 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean saveUser(AppUserForm userForm) {
|
||||
public boolean saveUser(ClientUserForm userForm) {
|
||||
|
||||
String username = userForm.getUsername();
|
||||
|
||||
// 实体转换 form->entity
|
||||
AppUser entity = userConverter.toEntity(userForm);
|
||||
ClientUser entity = userConverter.toEntity(userForm);
|
||||
|
||||
// 检查用户名是否已存在
|
||||
long count = this.count(new LambdaQueryWrapper<AppUser>()
|
||||
.eq(AppUser::getUsername, username));
|
||||
long count = this.count(new LambdaQueryWrapper<ClientUser>()
|
||||
.eq(ClientUser::getUsername, username));
|
||||
Assert.isTrue(count == 0, "用户名已存在");
|
||||
|
||||
// 设置默认加密密码
|
||||
@@ -156,23 +153,23 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean updateUser(Long userId, AppUserForm userForm) {
|
||||
public boolean updateUser(Long userId, ClientUserForm userForm) {
|
||||
|
||||
String username = userForm.getUsername();
|
||||
|
||||
// 获取原用户信息
|
||||
AppUser oldUser = this.getById(userId);
|
||||
ClientUser oldUser = this.getById(userId);
|
||||
Assert.notNull(oldUser, "用户不存在");
|
||||
|
||||
// 检查用户名是否已存在(排除当前用户)
|
||||
long count = this.count(new LambdaQueryWrapper<AppUser>()
|
||||
.eq(AppUser::getUsername, username)
|
||||
.ne(AppUser::getId, userId)
|
||||
long count = this.count(new LambdaQueryWrapper<ClientUser>()
|
||||
.eq(ClientUser::getUsername, username)
|
||||
.ne(ClientUser::getId, userId)
|
||||
);
|
||||
Assert.isTrue(count == 0, "用户名已存在");
|
||||
|
||||
// form -> entity
|
||||
AppUser entity = userConverter.toEntity(userForm);
|
||||
ClientUser entity = userConverter.toEntity(userForm);
|
||||
// entity.setUpdateBy(SecurityUtils.getUserId());
|
||||
|
||||
// 修改用户
|
||||
@@ -293,14 +290,14 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
||||
String username = SecurityUtils.getUsername();
|
||||
|
||||
// 获取登录用户基础信息
|
||||
AppUser user = this.getOne(new LambdaQueryWrapper<AppUser>()
|
||||
.eq(AppUser::getUsername, username)
|
||||
ClientUser user = this.getOne(new LambdaQueryWrapper<ClientUser>()
|
||||
.eq(ClientUser::getUsername, username)
|
||||
.select(
|
||||
AppUser::getId,
|
||||
AppUser::getUsername,
|
||||
AppUser::getNickname,
|
||||
AppUser::getAvatar,
|
||||
AppUser::getGender
|
||||
ClientUser::getId,
|
||||
ClientUser::getUsername,
|
||||
ClientUser::getNickname,
|
||||
ClientUser::getAvatar,
|
||||
ClientUser::getGender
|
||||
// AppUser::getDeptId
|
||||
)
|
||||
);
|
||||
@@ -367,11 +364,11 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
||||
throw new BusinessException("请修改至少一个字段");
|
||||
}
|
||||
|
||||
return this.update(new LambdaUpdateWrapper<AppUser>()
|
||||
.eq(AppUser::getId, userId)
|
||||
.set(formData.getNickname() != null, AppUser::getNickname, formData.getNickname())
|
||||
.set(formData.getAvatar() != null, AppUser::getAvatar, formData.getAvatar())
|
||||
.set(formData.getGender() != null, AppUser::getGender, formData.getGender())
|
||||
return this.update(new LambdaUpdateWrapper<ClientUser>()
|
||||
.eq(ClientUser::getId, userId)
|
||||
.set(formData.getNickname() != null, ClientUser::getNickname, formData.getNickname())
|
||||
.set(formData.getAvatar() != null, ClientUser::getAvatar, formData.getAvatar())
|
||||
.set(formData.getGender() != null, ClientUser::getGender, formData.getGender())
|
||||
);
|
||||
}
|
||||
|
||||
@@ -385,7 +382,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
||||
@Override
|
||||
public boolean changeUserPassword(Long userId, PasswordUpdateForm data) {
|
||||
|
||||
AppUser user = this.getById(userId);
|
||||
ClientUser user = this.getById(userId);
|
||||
if (user == null) {
|
||||
throw new BusinessException("用户不存在");
|
||||
}
|
||||
@@ -407,9 +404,9 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
||||
}
|
||||
|
||||
String newPassword = data.getNewPassword();
|
||||
boolean result = this.update(new LambdaUpdateWrapper<AppUser>()
|
||||
.eq(AppUser::getId, userId)
|
||||
.set(AppUser::getPassword, passwordEncoder.encode(newPassword))
|
||||
boolean result = this.update(new LambdaUpdateWrapper<ClientUser>()
|
||||
.eq(ClientUser::getId, userId)
|
||||
.set(ClientUser::getPassword, passwordEncoder.encode(newPassword))
|
||||
);
|
||||
|
||||
if (result) {
|
||||
@@ -428,9 +425,9 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
||||
*/
|
||||
@Override
|
||||
public boolean resetUserPassword(Long userId, String password) {
|
||||
boolean result = this.update(new LambdaUpdateWrapper<AppUser>()
|
||||
.eq(AppUser::getId, userId)
|
||||
.set(AppUser::getPassword, passwordEncoder.encode(password))
|
||||
boolean result = this.update(new LambdaUpdateWrapper<ClientUser>()
|
||||
.eq(ClientUser::getId, userId)
|
||||
.set(ClientUser::getPassword, passwordEncoder.encode(password))
|
||||
);
|
||||
if (result) {
|
||||
// 管理员重置用户密码后,使该用户的所有会话失效
|
||||
@@ -449,9 +446,9 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
||||
public boolean sendMobileCode(String mobile) {
|
||||
|
||||
Long currentUserId = SecurityUtils.getUserId();
|
||||
long mobileCount = this.count(new LambdaQueryWrapper<AppUser>()
|
||||
.eq(AppUser::getMobile, mobile)
|
||||
.ne(AppUser::getId, currentUserId)
|
||||
long mobileCount = this.count(new LambdaQueryWrapper<ClientUser>()
|
||||
.eq(ClientUser::getMobile, mobile)
|
||||
.ne(ClientUser::getId, currentUserId)
|
||||
);
|
||||
if (mobileCount > 0) {
|
||||
throw new BusinessException("手机号已被其他账号绑定");
|
||||
@@ -482,7 +479,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
||||
public boolean bindOrChangeMobile(MobileUpdateForm form) {
|
||||
|
||||
Long currentUserId = SecurityUtils.getUserId();
|
||||
AppUser currentUser = this.getById(currentUserId);
|
||||
ClientUser currentUser = this.getById(currentUserId);
|
||||
|
||||
if (currentUser == null) {
|
||||
throw new BusinessException("用户不存在");
|
||||
@@ -507,9 +504,9 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
||||
throw new BusinessException("验证码错误");
|
||||
}
|
||||
|
||||
long mobileCount = this.count(new LambdaQueryWrapper<AppUser>()
|
||||
.eq(AppUser::getMobile, mobile)
|
||||
.ne(AppUser::getId, currentUserId)
|
||||
long mobileCount = this.count(new LambdaQueryWrapper<ClientUser>()
|
||||
.eq(ClientUser::getMobile, mobile)
|
||||
.ne(ClientUser::getId, currentUserId)
|
||||
);
|
||||
if (mobileCount > 0) {
|
||||
throw new BusinessException("手机号已被其他账号绑定");
|
||||
@@ -519,9 +516,9 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
||||
|
||||
// 更新手机号码
|
||||
return this.update(
|
||||
new LambdaUpdateWrapper<AppUser>()
|
||||
.eq(AppUser::getId, currentUserId)
|
||||
.set(AppUser::getMobile, mobile)
|
||||
new LambdaUpdateWrapper<ClientUser>()
|
||||
.eq(ClientUser::getId, currentUserId)
|
||||
.set(ClientUser::getMobile, mobile)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -534,9 +531,9 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
||||
public void sendEmailCode(String email) {
|
||||
|
||||
Long currentUserId = SecurityUtils.getUserId();
|
||||
long emailCount = this.count(new LambdaQueryWrapper<AppUser>()
|
||||
.eq(AppUser::getEmail, email)
|
||||
.ne(AppUser::getId, currentUserId)
|
||||
long emailCount = this.count(new LambdaQueryWrapper<ClientUser>()
|
||||
.eq(ClientUser::getEmail, email)
|
||||
.ne(ClientUser::getId, currentUserId)
|
||||
);
|
||||
if (emailCount > 0) {
|
||||
throw new BusinessException("邮箱已被其他账号绑定");
|
||||
@@ -563,7 +560,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
||||
|
||||
Long currentUserId = SecurityUtils.getUserId();
|
||||
|
||||
AppUser currentUser = this.getById(currentUserId);
|
||||
ClientUser currentUser = this.getById(currentUserId);
|
||||
if (currentUser == null) {
|
||||
throw new BusinessException("用户不存在");
|
||||
}
|
||||
@@ -588,9 +585,9 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
||||
throw new BusinessException("验证码错误");
|
||||
}
|
||||
|
||||
long emailCount = this.count(new LambdaQueryWrapper<AppUser>()
|
||||
.eq(AppUser::getEmail, email)
|
||||
.ne(AppUser::getId, currentUserId)
|
||||
long emailCount = this.count(new LambdaQueryWrapper<ClientUser>()
|
||||
.eq(ClientUser::getEmail, email)
|
||||
.ne(ClientUser::getId, currentUserId)
|
||||
);
|
||||
if (emailCount > 0) {
|
||||
throw new BusinessException("邮箱已被其他账号绑定");
|
||||
@@ -600,9 +597,9 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
||||
|
||||
// 更新邮箱地址
|
||||
return this.update(
|
||||
new LambdaUpdateWrapper<AppUser>()
|
||||
.eq(AppUser::getId, currentUserId)
|
||||
.set(AppUser::getEmail, email)
|
||||
new LambdaUpdateWrapper<ClientUser>()
|
||||
.eq(ClientUser::getId, currentUserId)
|
||||
.set(ClientUser::getEmail, email)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -616,7 +613,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
||||
public boolean unbindMobile(PasswordVerifyForm form) {
|
||||
|
||||
Long currentUserId = SecurityUtils.getUserId();
|
||||
AppUser currentUser = this.getById(currentUserId);
|
||||
ClientUser currentUser = this.getById(currentUserId);
|
||||
|
||||
if (currentUser == null) {
|
||||
throw new BusinessException("用户不存在");
|
||||
@@ -630,9 +627,9 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
||||
throw new BusinessException("当前密码错误");
|
||||
}
|
||||
|
||||
return this.update(new LambdaUpdateWrapper<AppUser>()
|
||||
.eq(AppUser::getId, currentUserId)
|
||||
.set(AppUser::getMobile, null)
|
||||
return this.update(new LambdaUpdateWrapper<ClientUser>()
|
||||
.eq(ClientUser::getId, currentUserId)
|
||||
.set(ClientUser::getMobile, null)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -646,7 +643,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
||||
public boolean unbindEmail(PasswordVerifyForm form) {
|
||||
|
||||
Long currentUserId = SecurityUtils.getUserId();
|
||||
AppUser currentUser = this.getById(currentUserId);
|
||||
ClientUser currentUser = this.getById(currentUserId);
|
||||
|
||||
if (currentUser == null) {
|
||||
throw new BusinessException("用户不存在");
|
||||
@@ -660,9 +657,9 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
||||
throw new BusinessException("当前密码错误");
|
||||
}
|
||||
|
||||
return this.update(new LambdaUpdateWrapper<AppUser>()
|
||||
.eq(AppUser::getId, currentUserId)
|
||||
.set(AppUser::getEmail, null)
|
||||
return this.update(new LambdaUpdateWrapper<ClientUser>()
|
||||
.eq(ClientUser::getId, currentUserId)
|
||||
.set(ClientUser::getEmail, null)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,8 +6,12 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.File;
|
||||
|
||||
public class FilePath {
|
||||
|
||||
/**
|
||||
* 有可能部署在docker中,所以需要使用绝对路径
|
||||
*/
|
||||
// @Value("${file.upload-dir-unix}")
|
||||
private static final String unixUploadDir = "/tmp/ttstd/uploads" ;
|
||||
private static final String unixUploadDir = "/home/tt/ttstd/uploads" ;
|
||||
|
||||
// @Value("${file.upload-dir-windows}")
|
||||
private static final String windowsUploadDir = "uploadFile";
|
||||
@@ -25,12 +29,12 @@ public class FilePath {
|
||||
public static String getRootPath() {
|
||||
String osName = System.getProperty("os.name");
|
||||
logger.info("osName: {}", osName);
|
||||
String projectPath = System.getProperty("user.dir");
|
||||
logger.info("projectPath: {}", projectPath);
|
||||
if (osName.contains("Windows")) {
|
||||
String projectPath = System.getProperty("user.dir");
|
||||
logger.info("projectPath: {}", projectPath);
|
||||
return projectPath + File.separator + windowsUploadDir;
|
||||
} else {
|
||||
return unixUploadDir;
|
||||
return projectPath + File.separator + windowsUploadDir;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ public class SecurityConfig {
|
||||
|
||||
// 移动设备专用接口路径(需要设备签名验证,但不需要用户登录)
|
||||
requestMatcherRegistry.requestMatchers("/api/v1/sn/**").permitAll();
|
||||
requestMatcherRegistry.requestMatchers("/api/v1/app/**").permitAll();
|
||||
requestMatcherRegistry.requestMatchers("/api/v1/open/**").permitAll();
|
||||
// 其他所有请求需登录后访问
|
||||
requestMatcherRegistry.anyRequest().authenticated();
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.youlai.boot.app.controller;
|
||||
package com.youlai.boot.open.controller;
|
||||
|
||||
import com.youlai.boot.app.model.req.MobileLoginReq;
|
||||
import com.youlai.boot.app.model.req.MobileRegisterReq;
|
||||
import com.youlai.boot.app.service.AppAuthService;
|
||||
import com.youlai.boot.open.model.req.OpenLoginReq;
|
||||
import com.youlai.boot.open.model.req.OpenRegisterReq;
|
||||
import com.youlai.boot.open.service.OpenAuthService;
|
||||
import com.youlai.boot.common.annotation.Log;
|
||||
import com.youlai.boot.common.enums.ActionTypeEnum;
|
||||
import com.youlai.boot.common.enums.LogModuleEnum;
|
||||
@@ -22,19 +22,19 @@ import org.springframework.web.bind.annotation.*;
|
||||
*/
|
||||
@Tag(name = "01.认证中心")
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/app/auth/")
|
||||
@RequestMapping("/api/v1/open/auth/")
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class AppAuthController {
|
||||
public class OpenAuthController {
|
||||
|
||||
private final AppAuthService appAuthService;
|
||||
private final OpenAuthService openAuthService;
|
||||
|
||||
|
||||
@Operation(summary = "手机号注册")
|
||||
@PostMapping("/register/mobile")
|
||||
@Log(module = LogModuleEnum.LOGIN, value = ActionTypeEnum.REGISTER)
|
||||
public Result<AuthenticationToken> registerByMobile(@RequestBody @Valid MobileRegisterReq request) {
|
||||
AuthenticationToken authenticationToken = appAuthService.registerByMobile(
|
||||
public Result<AuthenticationToken> registerByMobile(@RequestBody @Valid OpenRegisterReq request) {
|
||||
AuthenticationToken authenticationToken = openAuthService.registerByMobile(
|
||||
request.getMobile(),
|
||||
request.getCode(),
|
||||
request.getPassword(),
|
||||
@@ -48,14 +48,14 @@ public class AppAuthController {
|
||||
public Result<Void> sendRegisterSmsCode(
|
||||
@Parameter(description = "手机号", example = "18888888888") @RequestParam String mobile
|
||||
) {
|
||||
return Result.judge(appAuthService.sendRegisterSmsCode(mobile));
|
||||
return Result.judge(openAuthService.sendRegisterSmsCode(mobile));
|
||||
}
|
||||
|
||||
@Operation(summary = "手机号验证码登录")
|
||||
@PostMapping("/login/mobile")
|
||||
@Log(module = LogModuleEnum.LOGIN, value = ActionTypeEnum.LOGIN)
|
||||
public Result<AuthenticationToken> loginByMobile(@RequestBody @Valid MobileLoginReq request) {
|
||||
AuthenticationToken authenticationToken = appAuthService.loginBySms(request.getMobile(), request.getCode());
|
||||
public Result<AuthenticationToken> loginByMobile(@RequestBody @Valid OpenLoginReq request) {
|
||||
AuthenticationToken authenticationToken = openAuthService.loginBySms(request.getMobile(), request.getCode());
|
||||
return Result.success(authenticationToken);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package com.youlai.boot.app.converter;
|
||||
package com.youlai.boot.open.converter;
|
||||
|
||||
import com.youlai.boot.app.model.entity.AppUser;
|
||||
import com.youlai.boot.app.model.form.AppUserForm;
|
||||
import com.youlai.boot.client.model.entity.ClientUser;
|
||||
import com.youlai.boot.client.model.form.ClientUserForm;
|
||||
import com.youlai.boot.common.model.Option;
|
||||
import com.youlai.boot.system.model.entity.SysUser;
|
||||
import com.youlai.boot.system.model.form.UserImportForm;
|
||||
import com.youlai.boot.system.model.form.UserProfileForm;
|
||||
import com.youlai.boot.system.model.vo.CurrentUserVO;
|
||||
@@ -21,27 +20,27 @@ import java.util.List;
|
||||
* @since 2022/6/8
|
||||
*/
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface AppUserConverter {
|
||||
public interface ClientUserConverter {
|
||||
|
||||
AppUserForm toForm(AppUser entity);
|
||||
ClientUserForm toForm(ClientUser entity);
|
||||
|
||||
@InheritInverseConfiguration(name = "toForm")
|
||||
AppUser toEntity(AppUserForm entity);
|
||||
ClientUser toEntity(ClientUserForm entity);
|
||||
|
||||
@Mappings({
|
||||
@Mapping(target = "userId", source = "id")
|
||||
})
|
||||
CurrentUserVO toCurrentUserVo(AppUser entity);
|
||||
CurrentUserVO toCurrentUserVo(ClientUser entity);
|
||||
|
||||
AppUser toEntity(UserImportForm vo);
|
||||
ClientUser toEntity(UserImportForm vo);
|
||||
|
||||
AppUser toEntity(UserProfileForm formData);
|
||||
ClientUser toEntity(UserProfileForm formData);
|
||||
|
||||
@Mappings({
|
||||
@Mapping(target = "label", source = "nickname"),
|
||||
@Mapping(target = "value", source = "id")
|
||||
})
|
||||
Option<String> toOption(AppUser entity);
|
||||
Option<String> toOption(ClientUser entity);
|
||||
|
||||
List<Option<String>> toOptions(List<AppUser> list);
|
||||
List<Option<String>> toOptions(List<ClientUser> list);
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.youlai.boot.app.mapper;
|
||||
package com.youlai.boot.open.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.youlai.boot.app.model.entity.AppUser;
|
||||
import com.youlai.boot.app.model.form.AppUserForm;
|
||||
import com.youlai.boot.client.model.entity.ClientUser;
|
||||
import com.youlai.boot.client.model.form.ClientUserForm;
|
||||
import com.youlai.boot.common.annotation.DataPermission;
|
||||
import com.youlai.boot.framework.security.model.SecurityUser;
|
||||
import com.youlai.boot.system.model.query.UserQuery;
|
||||
@@ -20,7 +20,7 @@ import java.util.List;
|
||||
*
|
||||
*/
|
||||
@Mapper
|
||||
public interface AppUserMapper extends BaseMapper<AppUser> {
|
||||
public interface ClientUserMapper extends BaseMapper<ClientUser> {
|
||||
|
||||
/**
|
||||
* 获取用户分页列表
|
||||
@@ -38,7 +38,7 @@ public interface AppUserMapper extends BaseMapper<AppUser> {
|
||||
* @param userId 用户ID
|
||||
* @return 用户表单详情
|
||||
*/
|
||||
AppUserForm getUserFormData(Long userId);
|
||||
ClientUserForm getUserFormData(Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户名获取认证信息
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.youlai.boot.app.model.req;
|
||||
package com.youlai.boot.open.model.req;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
@@ -11,7 +11,7 @@ import lombok.Data;
|
||||
*/
|
||||
@Schema(description = "手机号登录请求参数")
|
||||
@Data
|
||||
public class MobileLoginReq {
|
||||
public class OpenLoginReq {
|
||||
|
||||
@Schema(description = "手机号", requiredMode = Schema.RequiredMode.REQUIRED, example = "18888888888")
|
||||
@NotBlank(message = "手机号不能为空")
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.youlai.boot.app.model.req;
|
||||
package com.youlai.boot.open.model.req;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
@@ -12,7 +12,7 @@ import jakarta.validation.constraints.Pattern;
|
||||
*/
|
||||
@Schema(description = "手机号注册请求参数")
|
||||
@Data
|
||||
public class MobileRegisterReq {
|
||||
public class OpenRegisterReq {
|
||||
|
||||
@Schema(description = "手机号", requiredMode = Schema.RequiredMode.REQUIRED, example = "18888888888")
|
||||
@NotBlank(message = "手机号不能为空")
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.youlai.boot.app.service;
|
||||
package com.youlai.boot.open.service;
|
||||
|
||||
import com.youlai.boot.auth.model.resp.CaptchaInfo;
|
||||
import com.youlai.boot.framework.security.model.AuthenticationToken;
|
||||
|
||||
public interface AppAuthService {
|
||||
public interface OpenAuthService {
|
||||
|
||||
/**
|
||||
* 获取验证码
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.youlai.boot.app.service.impl;
|
||||
package com.youlai.boot.open.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.youlai.boot.app.model.entity.AppUser;
|
||||
import com.youlai.boot.app.service.AppAuthService;
|
||||
import com.youlai.boot.app.service.AppUserService;
|
||||
import com.youlai.boot.client.model.entity.ClientUser;
|
||||
import com.youlai.boot.open.service.OpenAuthService;
|
||||
import com.youlai.boot.client.service.ClientUserService;
|
||||
import com.youlai.boot.auth.model.resp.CaptchaInfo;
|
||||
import com.youlai.boot.auth.service.CaptchaService;
|
||||
import com.youlai.boot.common.constant.RedisConstants;
|
||||
@@ -15,7 +15,6 @@ import com.youlai.boot.support.sms.SmsService;
|
||||
import com.youlai.boot.support.sms.SmsTypeEnum;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
@@ -38,14 +37,14 @@ import java.util.concurrent.TimeUnit;
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class AppAuthServiceImpl implements AppAuthService {
|
||||
public class OpenAuthServiceImpl implements OpenAuthService {
|
||||
|
||||
private final AuthenticationManager authenticationManager;
|
||||
private final TokenManager tokenManager;
|
||||
private final SmsService smsService;
|
||||
private final RedisTemplate<String, Object> redisTemplate;
|
||||
private final CaptchaService captchaService;
|
||||
private final AppUserService userService;
|
||||
private final ClientUserService userService;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
|
||||
|
||||
@@ -62,8 +61,8 @@ public class AppAuthServiceImpl implements AppAuthService {
|
||||
@Override
|
||||
public boolean sendRegisterSmsCode(String mobile) {
|
||||
// 检查手机号是否已注册
|
||||
long count = userService.count(new LambdaQueryWrapper<AppUser>()
|
||||
.eq(AppUser::getMobile, mobile));
|
||||
long count = userService.count(new LambdaQueryWrapper<ClientUser>()
|
||||
.eq(ClientUser::getMobile, mobile));
|
||||
if (count > 0) {
|
||||
throw new BusinessException("该手机号已被注册");
|
||||
}
|
||||
@@ -109,12 +108,12 @@ public class AppAuthServiceImpl implements AppAuthService {
|
||||
}
|
||||
|
||||
// 2. 检查手机号是否已注册
|
||||
long count = userService.count(new LambdaQueryWrapper<AppUser>()
|
||||
.eq(AppUser::getMobile, mobile));
|
||||
long count = userService.count(new LambdaQueryWrapper<ClientUser>()
|
||||
.eq(ClientUser::getMobile, mobile));
|
||||
Assert.isTrue(count == 0, "该手机号已被注册");
|
||||
|
||||
// 3. 创建新用户
|
||||
AppUser user = new AppUser();
|
||||
ClientUser user = new ClientUser();
|
||||
user.setUsername(mobile); // 使用手机号作为用户名
|
||||
user.setMobile(mobile);
|
||||
user.setPassword(passwordEncoder.encode(password));
|
||||
@@ -41,7 +41,7 @@ public class MqttMessageHandler {
|
||||
* @param payload 消息内容(UTF-8 字符串)
|
||||
*/
|
||||
public void handleMessage(String topic, String payload) {
|
||||
log.info("收到 MQTT 消息, topic={}, payload={}", topic, payload);
|
||||
log.debug("收到 MQTT 消息, topic={}, payload={}", topic, payload);
|
||||
|
||||
// 根据业务需要,按主题分发处理
|
||||
String statusTopic = mqttProperties.getStatusTopic();
|
||||
@@ -59,7 +59,7 @@ public class MqttMessageHandler {
|
||||
* 其中 screenOn 为可选字段,表示设备亮屏(亮屏=屏幕点亮)状态。
|
||||
*/
|
||||
private void handleDeviceStatus(String payload) {
|
||||
log.info("处理设备状态上报: {}", payload);
|
||||
log.debug("处理设备状态上报: {}", payload);
|
||||
if (StrUtil.isBlank(payload)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user