完善小程序登录排班与个人资料流程
This commit is contained in:
+28
-9
@@ -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);
|
||||
|
||||
+7
-3
@@ -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);
|
||||
|
||||
+2
@@ -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;
|
||||
|
||||
+27
-33
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置用户密码。
|
||||
*/
|
||||
|
||||
+3
@@ -48,6 +48,9 @@ public class UserDTO {
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
/** 当前用户本人上传的头像文件 ID。 */
|
||||
private Long avatarFileId;
|
||||
|
||||
/**
|
||||
* 用户签名
|
||||
*/
|
||||
|
||||
+61
-9
@@ -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);
|
||||
|
||||
+9
@@ -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;
|
||||
}
|
||||
+93
-3
@@ -23,6 +23,8 @@ import com.xiaowang.jayucloud.salon.core.modules.security.support.AdminScopeHelp
|
||||
import com.xiaowang.jayucloud.salon.core.modules.shop.mapper.ShopMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.shop.entity.ShopDO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.shop.service.ShopBusinessExpiryService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.shop.service.ShopBusinessScheduleService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.shop.vo.ShopBusinessHoursDayVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.entity.UserDO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.mapper.UserMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.service.UserService;
|
||||
@@ -39,6 +41,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -60,6 +63,7 @@ class PlanningServiceImplTest {
|
||||
@Mock private ProductMapper productMapper;
|
||||
@Mock private ShopMapper shopMapper;
|
||||
@Mock private ShopBusinessExpiryService shopBusinessExpiryService;
|
||||
@Mock private ShopBusinessScheduleService shopBusinessScheduleService;
|
||||
@Mock private AppointmentCapacityService appointmentCapacityService;
|
||||
@Mock private OrderService orderService;
|
||||
@Mock private WechatSubscribeMessageService wechatSubscribeMessageService;
|
||||
@@ -72,8 +76,14 @@ class PlanningServiceImplTest {
|
||||
void setUp() {
|
||||
service = new PlanningServiceImpl(adminScopeHelper, userMapper, userService, nailArtistInfoMapper, artistScheduleMapper,
|
||||
artistScheduleExceptionMapper, appointmentReservationMapper, orderMapper, orderItemMapper,
|
||||
productMapper, shopMapper, shopBusinessExpiryService, appointmentCapacityService, orderService, wechatSubscribeMessageService, snowflakeIdGenerator,
|
||||
productMapper, shopMapper, shopBusinessExpiryService, shopBusinessScheduleService, appointmentCapacityService, orderService, wechatSubscribeMessageService, snowflakeIdGenerator,
|
||||
objectStorageUrlSupport);
|
||||
ShopBusinessHoursDayVO defaultOpenDay = new ShopBusinessHoursDayVO();
|
||||
defaultOpenDay.setOpen(true);
|
||||
defaultOpenDay.setStartTime("10:00");
|
||||
defaultOpenDay.setEndTime("22:00");
|
||||
lenient().when(shopBusinessScheduleService.forDate(any(), any(), org.mockito.ArgumentMatchers.nullable(String.class)))
|
||||
.thenReturn(defaultOpenDay);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -139,6 +149,13 @@ class PlanningServiceImplTest {
|
||||
dto.setAppointmentDate(java.time.LocalDate.now().plusDays(2).toString());
|
||||
dto.setAppointmentTime("19:30");
|
||||
dto.setDurationMinutes(60);
|
||||
ShopBusinessHoursDayVO openDay = new ShopBusinessHoursDayVO();
|
||||
openDay.setOpen(true);
|
||||
openDay.setStartTime("10:00");
|
||||
openDay.setEndTime("20:00");
|
||||
when(shopBusinessScheduleService.forDate(org.mockito.ArgumentMatchers.eq(21L),
|
||||
org.mockito.ArgumentMatchers.eq(java.time.LocalDate.parse(dto.getAppointmentDate())),
|
||||
org.mockito.ArgumentMatchers.nullable(String.class))).thenReturn(openDay);
|
||||
|
||||
RuntimeException error = assertThrows(RuntimeException.class, () -> service.createAppointment(operator, dto));
|
||||
|
||||
@@ -147,7 +164,7 @@ class PlanningServiceImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsAppointmentWhenShopBusinessHoursAreMissing() {
|
||||
void rejectsAppointmentWhenShopIsClosedOnRequestedWeekday() {
|
||||
UserDO operator = new UserDO();
|
||||
operator.setType(2);
|
||||
ShopDO shop = new ShopDO();
|
||||
@@ -158,13 +175,68 @@ class PlanningServiceImplTest {
|
||||
dto.setAppointmentDate(java.time.LocalDate.now().plusDays(2).toString());
|
||||
dto.setAppointmentTime("14:00");
|
||||
dto.setDurationMinutes(60);
|
||||
ShopBusinessHoursDayVO closedDay = new ShopBusinessHoursDayVO();
|
||||
closedDay.setOpen(false);
|
||||
when(shopBusinessScheduleService.forDate(org.mockito.ArgumentMatchers.eq(21L),
|
||||
org.mockito.ArgumentMatchers.eq(java.time.LocalDate.parse(dto.getAppointmentDate())),
|
||||
org.mockito.ArgumentMatchers.nullable(String.class))).thenReturn(closedDay);
|
||||
|
||||
RuntimeException error = assertThrows(RuntimeException.class, () -> service.createAppointment(operator, dto));
|
||||
|
||||
assertEquals("门店营业时间未设置,请先完成设置", error.getMessage());
|
||||
assertEquals("预约日期门店休息,暂不可新建普通预约", error.getMessage());
|
||||
verify(orderMapper, never()).insert(any(OrderDO.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void calendarHasNoFallbackHoursWhenEveryShopDayIsClosed() {
|
||||
UserDO operator = new UserDO();
|
||||
operator.setType(2);
|
||||
ShopDO shop = new ShopDO();
|
||||
shop.setId(21L);
|
||||
shop.setBusinessHours("10:00-22:00");
|
||||
when(adminScopeHelper.resolveShopScope(operator, null)).thenReturn(21L);
|
||||
when(shopMapper.selectById(21L)).thenReturn(shop);
|
||||
when(shopBusinessScheduleService.mapByDay(21L, "10:00-22:00")).thenReturn(closedWeeklySchedule());
|
||||
mockEmptyCalendarRows();
|
||||
|
||||
com.xiaowang.jayucloud.salon.core.modules.planning.vo.PlanningCalendarVO calendar = service.getCalendar(
|
||||
operator, java.time.LocalDate.of(2026, 11, 2), java.time.LocalDate.of(2026, 11, 2), null);
|
||||
|
||||
assertNull(calendar.getBusinessStartTime());
|
||||
assertNull(calendar.getBusinessEndTime());
|
||||
assertEquals(false, calendar.getDaySummaries().get(0).getShopOpen());
|
||||
assertEquals("rest", calendar.getDaySummaries().get(0).getDayStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void calendarUsesWeeklyHoursInsteadOfLegacyHoursWhenAnyShopDayIsOpen() {
|
||||
UserDO operator = new UserDO();
|
||||
operator.setType(2);
|
||||
ShopDO shop = new ShopDO();
|
||||
shop.setId(21L);
|
||||
shop.setBusinessHours("10:00-22:00");
|
||||
java.util.Map<Integer, ShopBusinessHoursDayVO> weeklyHours = closedWeeklySchedule();
|
||||
ShopBusinessHoursDayVO monday = new ShopBusinessHoursDayVO();
|
||||
monday.setDayOfWeek(1);
|
||||
monday.setOpen(true);
|
||||
monday.setStartTime("12:00");
|
||||
monday.setEndTime("19:00");
|
||||
weeklyHours.put(1, monday);
|
||||
when(adminScopeHelper.resolveShopScope(operator, null)).thenReturn(21L);
|
||||
when(shopMapper.selectById(21L)).thenReturn(shop);
|
||||
when(shopBusinessScheduleService.mapByDay(21L, "10:00-22:00")).thenReturn(weeklyHours);
|
||||
mockEmptyCalendarRows();
|
||||
|
||||
com.xiaowang.jayucloud.salon.core.modules.planning.vo.PlanningCalendarVO calendar = service.getCalendar(
|
||||
operator, java.time.LocalDate.of(2026, 11, 2), java.time.LocalDate.of(2026, 11, 2), null);
|
||||
|
||||
assertEquals("12:00", calendar.getBusinessStartTime());
|
||||
assertEquals("19:00", calendar.getBusinessEndTime());
|
||||
assertEquals(true, calendar.getDaySummaries().get(0).getShopOpen());
|
||||
assertEquals("12:00", calendar.getDaySummaries().get(0).getShopStartTime());
|
||||
assertEquals("19:00", calendar.getDaySummaries().get(0).getShopEndTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
void usesShopDefaultDurationWhenRequestOmitsDuration() {
|
||||
UserDO operator = new UserDO();
|
||||
@@ -515,4 +587,22 @@ class PlanningServiceImplTest {
|
||||
order.setIsDelete(0);
|
||||
return order;
|
||||
}
|
||||
|
||||
private java.util.Map<Integer, ShopBusinessHoursDayVO> closedWeeklySchedule() {
|
||||
java.util.Map<Integer, ShopBusinessHoursDayVO> days = new java.util.HashMap<>();
|
||||
for (int dayOfWeek = 1; dayOfWeek <= 7; dayOfWeek++) {
|
||||
ShopBusinessHoursDayVO day = new ShopBusinessHoursDayVO();
|
||||
day.setDayOfWeek(dayOfWeek);
|
||||
day.setOpen(false);
|
||||
days.put(dayOfWeek, day);
|
||||
}
|
||||
return days;
|
||||
}
|
||||
|
||||
private void mockEmptyCalendarRows() {
|
||||
when(userMapper.selectList(any(Wrapper.class))).thenReturn(java.util.List.of());
|
||||
when(artistScheduleMapper.selectList(any(Wrapper.class))).thenReturn(java.util.List.of());
|
||||
when(appointmentReservationMapper.selectList(any(Wrapper.class))).thenReturn(java.util.List.of());
|
||||
when(orderItemMapper.selectList(any(Wrapper.class))).thenReturn(java.util.List.of());
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -19,6 +19,7 @@ import com.xiaowang.jayucloud.salon.core.modules.registration.vo.WorkbenchRegist
|
||||
import com.xiaowang.jayucloud.salon.core.modules.shop.mapper.ShopMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.shop.entity.ShopDO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.shop.service.ShopBusinessExpiryService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.shop.service.ShopBusinessScheduleService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.shop.mapper.UserShopBindingMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.shop.support.UserShopBindingSupport;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.service.SystemParameterConfigService;
|
||||
@@ -55,6 +56,7 @@ class WorkbenchRegistrationServiceImplTest {
|
||||
@Mock private ContentModerationService contentModerationService;
|
||||
@Mock private ContentModerationRecordMapper contentModerationRecordMapper;
|
||||
@Mock private ShopBusinessExpiryService shopBusinessExpiryService;
|
||||
@Mock private ShopBusinessScheduleService shopBusinessScheduleService;
|
||||
@Mock private PlatformTransactionManager transactionManager;
|
||||
@Mock private WechatMiniBindingMapper wechatMiniBindingMapper;
|
||||
@Mock private ObjectStorageFileService objectStorageFileService;
|
||||
@@ -66,7 +68,7 @@ class WorkbenchRegistrationServiceImplTest {
|
||||
void setUp() {
|
||||
service = new WorkbenchRegistrationServiceImpl(applicationMapper, userMapper, shopMapper, userService,
|
||||
userShopBindingSupport, userShopBindingMapper, wechatMiniAuthService, systemParameterConfigService,
|
||||
contentModerationService, contentModerationRecordMapper, shopBusinessExpiryService, transactionManager,
|
||||
contentModerationService, contentModerationRecordMapper, shopBusinessExpiryService, shopBusinessScheduleService, transactionManager,
|
||||
wechatMiniBindingMapper, objectStorageFileService, objectStorageUrlSupport);
|
||||
}
|
||||
|
||||
|
||||
+35
-1
@@ -21,6 +21,8 @@ import com.xiaowang.jayucloud.salon.core.modules.shop.dto.ShopAppointmentSetting
|
||||
import com.xiaowang.jayucloud.salon.core.modules.shop.entity.ShopDO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.shop.mapper.ShopMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.shop.service.ShopBusinessExpiryService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.shop.service.ShopBusinessScheduleService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.shop.vo.ShopBusinessHoursDayVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.shop.support.UserShopBindingSupport;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.shop.vo.ShopAppointmentSettingsVO;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -36,6 +38,7 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ShopAppointmentSettingsTest {
|
||||
@@ -43,6 +46,7 @@ class ShopAppointmentSettingsTest {
|
||||
@Mock private ShopMapper shopMapper;
|
||||
@Mock private ContentModerationRecordMapper contentModerationRecordMapper;
|
||||
@Mock private ShopBusinessExpiryService shopBusinessExpiryService;
|
||||
@Mock private ShopBusinessScheduleService shopBusinessScheduleService;
|
||||
@Mock private CouponService couponService;
|
||||
@Mock private CouponMapper couponMapper;
|
||||
@Mock private ProductMapper productMapper;
|
||||
@@ -71,8 +75,9 @@ class ShopAppointmentSettingsTest {
|
||||
when(shopMapper.selectById(21L)).thenReturn(shop);
|
||||
when(shopMapper.updateById(any(ShopDO.class))).thenReturn(1);
|
||||
ShopAppointmentSettingsDTO dto = new ShopAppointmentSettingsDTO();
|
||||
dto.setBusinessHours("09:30-21:00");
|
||||
dto.setWeeklyHours(weeklyHours("09:30", "21:00"));
|
||||
dto.setDefaultAppointmentDurationMinutes(75);
|
||||
when(shopBusinessScheduleService.list(21L, "10:00-22:00")).thenReturn(weeklyHoursVO("09:30", "21:00"));
|
||||
|
||||
assertTrue(shopService.updateAppointmentSettings(21L, dto));
|
||||
|
||||
@@ -80,6 +85,7 @@ class ShopAppointmentSettingsTest {
|
||||
verify(shopMapper).updateById(saved.capture());
|
||||
assertEquals("09:30-21:00", saved.getValue().getAppointmentBusinessHours());
|
||||
assertEquals(75, saved.getValue().getDefaultAppointmentDurationMinutes());
|
||||
verify(shopBusinessScheduleService).save(eq(21L), eq(dto.getWeeklyHours()), eq(null));
|
||||
verifyNoInteractions(contentModerationService);
|
||||
}
|
||||
|
||||
@@ -91,10 +97,38 @@ class ShopAppointmentSettingsTest {
|
||||
shop.setBusinessHours("09:00-21:00");
|
||||
when(shopMapper.selectById(21L)).thenReturn(shop);
|
||||
when(contentModerationRecordMapper.selectOne(any(Wrapper.class))).thenReturn(null);
|
||||
when(shopBusinessScheduleService.list(21L, "09:00-21:00")).thenReturn(weeklyHoursVO("09:00", "21:00"));
|
||||
|
||||
ShopAppointmentSettingsVO settings = shopService.getAppointmentSettings(21L);
|
||||
|
||||
assertEquals("09:00-21:00", settings.getBusinessHours());
|
||||
assertEquals(7, settings.getWeeklyHours().size());
|
||||
assertEquals(60, settings.getDefaultAppointmentDurationMinutes());
|
||||
}
|
||||
|
||||
private java.util.List<com.xiaowang.jayucloud.salon.core.modules.shop.dto.ShopBusinessHoursDayDTO> weeklyHours(String start, String end) {
|
||||
java.util.List<com.xiaowang.jayucloud.salon.core.modules.shop.dto.ShopBusinessHoursDayDTO> result = new java.util.ArrayList<>();
|
||||
for (int day = 1; day <= 7; day++) {
|
||||
com.xiaowang.jayucloud.salon.core.modules.shop.dto.ShopBusinessHoursDayDTO item = new com.xiaowang.jayucloud.salon.core.modules.shop.dto.ShopBusinessHoursDayDTO();
|
||||
item.setDayOfWeek(day);
|
||||
item.setOpen(true);
|
||||
item.setStartTime(start);
|
||||
item.setEndTime(end);
|
||||
result.add(item);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private java.util.List<ShopBusinessHoursDayVO> weeklyHoursVO(String start, String end) {
|
||||
java.util.List<ShopBusinessHoursDayVO> result = new java.util.ArrayList<>();
|
||||
for (int day = 1; day <= 7; day++) {
|
||||
ShopBusinessHoursDayVO item = new ShopBusinessHoursDayVO();
|
||||
item.setDayOfWeek(day);
|
||||
item.setOpen(true);
|
||||
item.setStartTime(start);
|
||||
item.setEndTime(end);
|
||||
result.add(item);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -4,6 +4,7 @@ import com.xiaowang.jayucloud.salon.core.common.Result;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.auth.service.VerificationCodeService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.file.service.ChunkUploadService;
|
||||
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.support.ObjectStorageUrlSupport;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.integration.service.WechatMiniAuthService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.privacy.service.AccountClosureService;
|
||||
@@ -39,7 +40,7 @@ class UserControllerPhonePrivacyTest {
|
||||
profile.setShopBusinessRemainingDays(66);
|
||||
when(userService.getCurrentUserInfo()).thenReturn(profile);
|
||||
UserController controller = new UserController(userService,
|
||||
mock(PrimaryObjectStorageService.class), mock(ChunkUploadService.class),
|
||||
mock(PrimaryObjectStorageService.class), mock(ObjectStorageDirectUploadService.class), mock(ChunkUploadService.class),
|
||||
mock(VerificationCodeService.class), mock(UserMapper.class), mock(AdminScopeHelper.class),
|
||||
mock(ShopRoleService.class), mock(TimeOrderedSnowflakeIdGenerator.class),
|
||||
mock(WechatMiniAuthService.class), mock(ObjectStorageUrlSupport.class),
|
||||
@@ -70,7 +71,7 @@ class UserControllerPhonePrivacyTest {
|
||||
AccountClosureService accountClosureService = mock(AccountClosureService.class);
|
||||
SecurityAuditLogService securityAuditLogService = mock(SecurityAuditLogService.class);
|
||||
UserController controller = new UserController(userService, primaryObjectStorageService,
|
||||
chunkUploadService, verificationCodeService, userMapper, adminScopeHelper, shopRoleService,
|
||||
mock(ObjectStorageDirectUploadService.class), chunkUploadService, verificationCodeService, userMapper, adminScopeHelper, shopRoleService,
|
||||
idGenerator, wechatMiniAuthService, objectStorageUrlSupport, requestThrottleService,
|
||||
legalAgreementService, accountClosureService, securityAuditLogService);
|
||||
|
||||
@@ -95,7 +96,7 @@ class UserControllerPhonePrivacyTest {
|
||||
@Test
|
||||
void rejectsPasswordCodeRequestWithoutAuthenticatedUser() {
|
||||
UserController controller = new UserController(mock(UserService.class),
|
||||
mock(PrimaryObjectStorageService.class), mock(ChunkUploadService.class),
|
||||
mock(PrimaryObjectStorageService.class), mock(ObjectStorageDirectUploadService.class), mock(ChunkUploadService.class),
|
||||
mock(VerificationCodeService.class), mock(UserMapper.class), mock(AdminScopeHelper.class),
|
||||
mock(ShopRoleService.class), mock(TimeOrderedSnowflakeIdGenerator.class),
|
||||
mock(WechatMiniAuthService.class), mock(ObjectStorageUrlSupport.class),
|
||||
|
||||
Reference in New Issue
Block a user