完善小程序登录排班与个人资料流程

This commit is contained in:
2026-11-03 15:33:03 +08:00
parent 6aafbd4eac
commit 19e2cd2594
37 changed files with 779 additions and 195 deletions
@@ -10,6 +10,8 @@ import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.InputStream;
@Service
@RequiredArgsConstructor
public class ObjectStorageDirectUploadService {
@@ -22,26 +24,43 @@ public class ObjectStorageDirectUploadService {
public ObjectStorageFileVO upload(MultipartFile file) throws Exception {
uploadSecurityValidator.validate(file);
String originalFilename = file.getOriginalFilename();
String fileExtension = originalFilename.substring(originalFilename.lastIndexOf("."));
String objectName = snowflakeIdGenerator.nextIdString() + fileExtension;
return upload(file.getOriginalFilename(), file.getInputStream(), file.getSize(), file.getContentType(), "");
}
public ObjectStorageFileVO uploadUserProfileImage(MultipartFile file, Long userId) throws Exception {
uploadSecurityValidator.validate(file);
return upload(file.getOriginalFilename(), file.getInputStream(), file.getSize(), file.getContentType(), "profile/" + userId + "/");
}
public ObjectStorageFileVO uploadUserProfileImage(String fileName, InputStream inputStream, long fileSize,
String contentType, Long userId) throws Exception {
uploadSecurityValidator.validateMetadata(fileName, contentType, fileSize);
return upload(fileName, inputStream, fileSize, contentType, "profile/" + userId + "/");
}
private ObjectStorageFileVO upload(String fileName, InputStream inputStream, long fileSize,
String contentType, String objectNamePrefix) throws Exception {
String extension = "";
if (fileName != null && fileName.lastIndexOf('.') >= 0) {
extension = fileName.substring(fileName.lastIndexOf('.'));
}
String objectName = objectNamePrefix + snowflakeIdGenerator.nextIdString() + extension;
ObjectStorageUploadOutcome uploadOutcome = objectStorageOrchestrationService.uploadPrimary(
file.getInputStream(),
file.getSize(),
file.getContentType(),
inputStream,
fileSize,
contentType,
objectName
);
ObjectStorageFileDTO dto = new ObjectStorageFileDTO();
dto.setFileName(originalFilename);
dto.setFileName(fileName);
dto.setFileUrl(uploadOutcome.getPrimaryUrl());
dto.setObjectName(objectName);
dto.setPrimaryProvider(uploadOutcome.getPrimaryProvider());
dto.setPrimaryUrl(uploadOutcome.getPrimaryUrl());
dto.setBackupProvider(String.join(",", objectStorageProperties.getReplicaRequiredProviders()));
dto.setContentType(file.getContentType());
dto.setFileSize(file.getSize());
dto.setContentType(contentType);
dto.setFileSize(fileSize);
dto.setPrimaryUploadStatus(1);
dto.setBackupUploadStatus(0);
dto.setBackupRetryCount(0);
@@ -117,12 +117,16 @@ public class PlanningServiceImpl implements PlanningService {
Long shopId = requirePlanningShopId(currentUser);
ShopDO shop = shopMapper.selectById(shopId);
PlanningCalendarSupport.BusinessHours businessHours = parseConfiguredBusinessHours(
shop == null ? null : (StringUtils.hasText(shop.getAppointmentBusinessHours())
? shop.getAppointmentBusinessHours() : shop.getBusinessHours()));
Map<Integer, ShopBusinessHoursDayVO> weeklyHours = shopBusinessScheduleService.mapByDay(
shopId, shop == null ? null : (StringUtils.hasText(shop.getAppointmentBusinessHours())
? shop.getAppointmentBusinessHours() : shop.getBusinessHours()));
PlanningCalendarSupport.BusinessHours businessHours = null;
for (int dayOfWeek = 1; dayOfWeek <= 7 && businessHours == null; dayOfWeek++) {
ShopBusinessHoursDayVO day = weeklyHours.get(dayOfWeek);
if (day != null && Boolean.TRUE.equals(day.getOpen())) {
businessHours = parseConfiguredBusinessHours(day.getStartTime() + "-" + day.getEndTime());
}
}
List<PlanningArtistVO> artists = listArtists(shopId, artistId);
List<ArtistScheduleDO> schedules = listSchedules(shopId, start, end, artistId);
@@ -81,6 +81,7 @@ public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationSe
ContentModerationService contentModerationService,
ContentModerationRecordMapper contentModerationRecordMapper,
ShopBusinessExpiryService shopBusinessExpiryService,
ShopBusinessScheduleService shopBusinessScheduleService,
PlatformTransactionManager transactionManager,
WechatMiniBindingMapper wechatMiniBindingMapper,
ObjectStorageFileService objectStorageFileService,
@@ -97,6 +98,7 @@ public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationSe
this.contentModerationService = contentModerationService;
this.contentModerationRecordMapper = contentModerationRecordMapper;
this.shopBusinessExpiryService = shopBusinessExpiryService;
this.shopBusinessScheduleService = shopBusinessScheduleService;
this.transactionTemplate = new TransactionTemplate(transactionManager);
this.wechatMiniBindingMapper = wechatMiniBindingMapper;
this.objectStorageFileService = objectStorageFileService;
@@ -15,6 +15,8 @@ import com.xiaowang.jayucloud.salon.core.modules.user.vo.UserVO;
import com.xiaowang.jayucloud.salon.core.modules.user.vo.InviteCodeVO;
import com.xiaowang.jayucloud.salon.core.modules.integration.vo.WechatMiniLoginResultVO;
import com.xiaowang.jayucloud.salon.core.modules.file.service.PrimaryObjectStorageService;
import com.xiaowang.jayucloud.salon.core.modules.file.service.ObjectStorageDirectUploadService;
import com.xiaowang.jayucloud.salon.core.modules.file.vo.ObjectStorageFileVO;
import com.xiaowang.jayucloud.salon.core.modules.user.service.UserService;
import com.xiaowang.jayucloud.salon.core.modules.security.service.ShopRoleService;
import com.xiaowang.jayucloud.salon.core.modules.auth.service.VerificationCodeService;
@@ -59,6 +61,7 @@ import com.xiaowang.jayucloud.salon.core.modules.integration.dto.WechatMiniQuick
import com.xiaowang.jayucloud.salon.core.modules.integration.dto.WechatMiniBindPhoneRequestDTO;
import com.xiaowang.jayucloud.salon.core.modules.user.dto.UserDTO;
import com.xiaowang.jayucloud.salon.core.modules.user.vo.UserAgreementConsentVO;
import com.xiaowang.jayucloud.salon.core.modules.user.vo.ProfileImageUploadVO;
/**
* 系统用户信息表 Controller
* 对应数据库表 t_user
@@ -78,6 +81,7 @@ public class UserController {
* Variable `primaryObjectStorageService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
*/
private final PrimaryObjectStorageService primaryObjectStorageService;
private final ObjectStorageDirectUploadService objectStorageDirectUploadService;
/**
* Variable `chunkUploadService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
*/
@@ -780,14 +784,12 @@ public class UserController {
try (ChunkUploadService.PreparedUploadFile preparedUploadFile =
chunkUploadService.prepareUserAvatarFile(userId, requestDTO.getUploadId());
FileInputStream inputStream = new FileInputStream(preparedUploadFile.getFile())) {
String originalFilename = preparedUploadFile.getFileName();
String fileExtension = originalFilename.substring(originalFilename.lastIndexOf("."));
String objectName = "avatar/" + userId + "/" + snowflakeIdGenerator.nextIdString() + fileExtension;
String avatarUrl = primaryObjectStorageService.uploadStream(inputStream, preparedUploadFile.getFileSize(), preparedUploadFile.getContentType(), objectName);
userService.updateUserAvatar(userId, avatarUrl);
ObjectStorageFileVO file = objectStorageDirectUploadService.uploadUserProfileImage(
preparedUploadFile.getFileName(), inputStream, preparedUploadFile.getFileSize(),
preparedUploadFile.getContentType(), userId);
userService.updateUserAvatar(userId, file.getObjectName());
chunkUploadService.clearUserAvatarUpload(userId, requestDTO.getUploadId());
return Result.success(objectStorageUrlSupport.toAccessibleUrl(avatarUrl));
return Result.success(objectStorageUrlSupport.getSignedUrlOrThrow(file, 60));
} catch (Exception e) {
e.printStackTrace();
return Result.error("头像上传失败: " + e.getMessage());
@@ -818,14 +820,9 @@ public class UserController {
public Result<String> uploadAvatar(HttpServletRequest request, @RequestParam("file") MultipartFile file) {
try {
Long userId = (Long) request.getAttribute("userId");
String originalFilename = file.getOriginalFilename();
String fileExtension = originalFilename.substring(originalFilename.lastIndexOf("."));
String objectName = "avatar/" + userId + "/" + snowflakeIdGenerator.nextIdString() + fileExtension;
String avatarUrl = primaryObjectStorageService.uploadFile(file, objectName);
userService.updateUserAvatar(userId, avatarUrl);
return Result.success(objectStorageUrlSupport.toAccessibleUrl(avatarUrl));
ObjectStorageFileVO uploaded = objectStorageDirectUploadService.uploadUserProfileImage(file, userId);
userService.updateUserAvatar(userId, uploaded.getObjectName());
return Result.success(objectStorageUrlSupport.getSignedUrlOrThrow(uploaded, 60));
} catch (Exception e) {
e.printStackTrace();
return Result.error("头像上传失败: " + e.getMessage());
@@ -862,20 +859,16 @@ public class UserController {
@PostMapping("/upload-profile-image/complete")
@OperationGuard(action = "user-profile-image-upload-complete", ttlSeconds = 30, message = "上传处理中,请勿重复操作")
public Result<String> completeProfileImageUpload(HttpServletRequest request, @Valid @RequestBody ChunkUploadCompleteRequestDTO requestDTO) {
public Result<ProfileImageUploadVO> completeProfileImageUpload(HttpServletRequest request, @Valid @RequestBody ChunkUploadCompleteRequestDTO requestDTO) {
Long userId = (Long) request.getAttribute("userId");
try (ChunkUploadService.PreparedUploadFile preparedUploadFile =
chunkUploadService.prepareUserProfileImageFile(userId, requestDTO.getUploadId());
FileInputStream inputStream = new FileInputStream(preparedUploadFile.getFile())) {
String originalFilename = preparedUploadFile.getFileName();
String fileExtension = "";
if (originalFilename != null && originalFilename.lastIndexOf(".") >= 0) {
fileExtension = originalFilename.substring(originalFilename.lastIndexOf("."));
}
String objectName = "profile/" + userId + "/" + snowflakeIdGenerator.nextIdString() + fileExtension;
String imageUrl = primaryObjectStorageService.uploadStream(inputStream, preparedUploadFile.getFileSize(), preparedUploadFile.getContentType(), objectName);
ObjectStorageFileVO file = objectStorageDirectUploadService.uploadUserProfileImage(
preparedUploadFile.getFileName(), inputStream, preparedUploadFile.getFileSize(),
preparedUploadFile.getContentType(), userId);
chunkUploadService.clearUserProfileImageUpload(userId, requestDTO.getUploadId());
return Result.success(objectStorageUrlSupport.toAccessibleUrl(imageUrl));
return Result.success(toProfileImageUploadVO(file));
} catch (Exception e) {
e.printStackTrace();
return Result.error("资料图片上传失败: " + e.getMessage());
@@ -892,26 +885,27 @@ public class UserController {
@PostMapping("/upload-profile-image")
@OperationGuard(action = "user-profile-image-upload", ttlSeconds = 30, message = "上传处理中,请勿重复操作")
public Result<String> uploadProfileImage(HttpServletRequest request, @RequestParam("file") MultipartFile file) {
public Result<ProfileImageUploadVO> uploadProfileImage(HttpServletRequest request, @RequestParam("file") MultipartFile file) {
try {
if (file == null || file.isEmpty()) {
return Result.error("请选择要上传的图片");
}
Long userId = (Long) request.getAttribute("userId");
String originalFilename = file.getOriginalFilename();
String fileExtension = "";
if (originalFilename != null && originalFilename.lastIndexOf(".") >= 0) {
fileExtension = originalFilename.substring(originalFilename.lastIndexOf("."));
}
String objectName = "profile/" + userId + "/" + snowflakeIdGenerator.nextIdString() + fileExtension;
String imageUrl = primaryObjectStorageService.uploadFile(file, objectName);
return Result.success(objectStorageUrlSupport.toAccessibleUrl(imageUrl));
ObjectStorageFileVO uploaded = objectStorageDirectUploadService.uploadUserProfileImage(file, userId);
return Result.success(toProfileImageUploadVO(uploaded));
} catch (Exception e) {
e.printStackTrace();
return Result.error("资料图片上传失败: " + e.getMessage());
}
}
private ProfileImageUploadVO toProfileImageUploadVO(ObjectStorageFileVO file) {
ProfileImageUploadVO result = new ProfileImageUploadVO();
result.setFileId(file.getId());
result.setFileUrl(objectStorageUrlSupport.getSignedUrlOrThrow(file, 60));
return result;
}
/**
* 重置用户密码。
*/
@@ -48,6 +48,9 @@ public class UserDTO {
*/
private String avatar;
/** 当前用户本人上传的头像文件 ID。 */
private Long avatarFileId;
/**
* 用户签名
*/
@@ -39,6 +39,7 @@ import com.xiaowang.jayucloud.salon.core.modules.registration.mapper.WorkbenchRe
import com.xiaowang.jayucloud.salon.core.modules.system.support.AdminDefaultPasswordSupport;
import com.xiaowang.jayucloud.salon.core.modules.file.support.ObjectStorageUrlSupport;
import com.xiaowang.jayucloud.salon.core.modules.file.service.ObjectStorageFileService;
import com.xiaowang.jayucloud.salon.core.modules.file.vo.ObjectStorageFileVO;
import com.xiaowang.jayucloud.salon.core.modules.security.support.PermissionCatalog;
import com.xiaowang.jayucloud.salon.core.support.security.UserSessionService;
import com.xiaowang.jayucloud.salon.core.support.id.TimeOrderedSnowflakeIdGenerator;
@@ -1950,17 +1951,29 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
*/
assertUserAvailable(userDO);
String avatarForUpdate = userDTO.getAvatarFileId() == null
? userDTO.getAvatar()
: resolveOwnedProfileFileReference(userId, userDTO.getAvatarFileId());
if (avatarForUpdate != null && !avatarForUpdate.isEmpty()) {
avatarForUpdate = normalizeOwnedProfileImage(userId, avatarForUpdate, userDO.getAvatar());
}
String qrForUpdate = userDTO.getWechatQrCode();
if (qrForUpdate != null && !qrForUpdate.isEmpty()) {
qrForUpdate = normalizeOwnedProfileImage(userId, qrForUpdate, userDO.getWechatQrCode());
}
boolean profileApproved = true;
if (userDTO.getNickname() != null || userDTO.getSignature() != null
|| (userDTO.getAvatar() != null && !userDTO.getAvatar().isEmpty()) || userDTO.getWechatQrCode() != null) {
|| (userDTO.getAvatar() != null && !userDTO.getAvatar().isEmpty()) || userDTO.getAvatarFileId() != null
|| userDTO.getWechatQrCode() != null) {
Map<String, String> content = new java.util.LinkedHashMap<>();
content.put("nickname", userDTO.getNickname() == null ? userDO.getNickname() : userDTO.getNickname());
content.put("signature", userDTO.getSignature() == null ? userDO.getSignature() : userDTO.getSignature());
content.put("avatar", userDTO.getAvatar() == null
content.put("avatar", avatarForUpdate == null
? userDO.getAvatar()
: (userDTO.getAvatar().isEmpty() ? null : normalizeStoredAvatar(userDTO.getAvatar())));
: (avatarForUpdate.isEmpty() ? null : avatarForUpdate));
content.put("wechatQrCode", userDTO.getWechatQrCode() == null
? userDO.getWechatQrCode() : normalizeStoredProfileImage(userDTO.getWechatQrCode()));
? userDO.getWechatQrCode() : (qrForUpdate.isEmpty() ? null : qrForUpdate));
String serialized = serializeModerationPayload(content);
List<Long> profileImages = new ArrayList<>();
addImageFileId(profileImages, content.get("avatar"));
@@ -1974,11 +1987,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
if (profileApproved && userDTO.getNickname() != null) {
userDO.setNickname(userDTO.getNickname());
}
if (profileApproved && userDTO.getAvatar() != null) {
if (userDTO.getAvatar().isEmpty()) {
if (profileApproved && (userDTO.getAvatar() != null || userDTO.getAvatarFileId() != null)) {
if (avatarForUpdate == null || avatarForUpdate.isEmpty()) {
userDO.setAvatar(null);
} else {
userDO.setAvatar(normalizeStoredAvatar(userDTO.getAvatar()));
userDO.setAvatar(avatarForUpdate);
}
}
if (profileApproved && userDTO.getSignature() != null) {
@@ -1994,7 +2007,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
userDO.setWechatId(UserProfileFieldSupport.normalizeOptionalText(userDTO.getWechatId()));
}
if (profileApproved && userDTO.getWechatQrCode() != null) {
userDO.setWechatQrCode(normalizeStoredProfileImage(userDTO.getWechatQrCode()));
userDO.setWechatQrCode(qrForUpdate.isEmpty() ? null : qrForUpdate);
}
UserProfileFieldSupport.requireWechatIdForServiceUser(userDO.getType(), userDO.getWechatId());
@@ -2448,7 +2461,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
* @return result consumed by the caller or returned to the frontend
*/
assertUserAvailable(userDO);
String storedAvatar = normalizeStoredAvatar(avatarUrl);
String storedAvatar = normalizeOwnedProfileImage(userId, avatarUrl, userDO.getAvatar());
List<Long> imageIds = new ArrayList<>();
addImageFileId(imageIds, storedAvatar);
ContentModerationResultVO moderation = contentModerationService.assessVersion("USER_AVATAR", userId, userId,
@@ -2466,6 +2479,45 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
if (!imageIds.contains(fileId)) imageIds.add(fileId);
}
private String resolveOwnedProfileFileReference(Long userId, Long fileId) {
if (fileId == null || fileId <= 0) {
throw new IllegalArgumentException("个人资料图片文件无效");
}
ObjectStorageFileVO file = objectStorageFileService.getObjectStorageFileById(fileId);
String objectName = file == null ? null : file.getObjectName();
String prefix = "profile/" + userId + "/";
if (file == null || !Integer.valueOf(1).equals(file.getStatus()) || !StringUtils.hasText(objectName)
|| !objectName.startsWith(prefix)) {
throw new IllegalArgumentException("个人资料图片必须引用本人上传的文件");
}
return objectName;
}
private String normalizeOwnedProfileImage(Long userId, String reference, String existingReference) {
if (!StringUtils.hasText(reference) || DEFAULT_AVATAR_URL.equals(reference)) return reference;
Long fileId;
if (reference.trim().matches("\\d+")) {
try {
fileId = Long.parseLong(reference.trim());
} catch (NumberFormatException exception) {
throw new IllegalArgumentException("个人资料图片文件无效");
}
} else {
fileId = objectStorageFileService.findFileIdByReference(reference);
}
if (fileId == null || fileId <= 0) throw new IllegalArgumentException("个人资料图片必须引用已上传文件");
ObjectStorageFileVO file = objectStorageFileService.getObjectStorageFileById(fileId);
if (file == null || !Integer.valueOf(1).equals(file.getStatus()) || !StringUtils.hasText(file.getObjectName())) {
throw new IllegalArgumentException("个人资料图片不存在或不可用");
}
String normalized = normalizeStoredProfileImage(file.getObjectName());
boolean unchanged = Objects.equals(reference, existingReference) || Objects.equals(normalized, existingReference);
if (!unchanged && !file.getObjectName().startsWith("profile/" + userId + "/")) {
throw new IllegalArgumentException("个人资料图片必须引用本人上传的文件");
}
return normalized;
}
private String serializeModerationPayload(Object payload) {
try {
return objectMapper.writeValueAsString(payload);
@@ -0,0 +1,9 @@
package com.xiaowang.jayucloud.salon.core.modules.user.vo;
import lombok.Data;
@Data
public class ProfileImageUploadVO {
private Long fileId;
private String fileUrl;
}