Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cacc8997ec | ||
|
|
593f6f13e7 | ||
|
|
8ee326b43a | ||
|
|
8fb4e714d8 | ||
|
|
a8e69e0850 | ||
|
|
f5b5724e92 | ||
|
|
1e41f31271 |
-43
@@ -194,47 +194,4 @@ public class CheckInHandler {
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.bodyValue(Map.of("code", 200, "message", "success", "data", stats)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员查询所有签到记录(支持排序)
|
||||
*
|
||||
* GET /api/checkIn/admin/records
|
||||
*/
|
||||
public Mono<ServerResponse> getAllSignInRecords(ServerRequest request) {
|
||||
String startDateStr = request.queryParam("startDate").orElse(null);
|
||||
String endDateStr = request.queryParam("endDate").orElse(null);
|
||||
String sortBy = request.queryParam("sortBy").orElse("signInTime");
|
||||
String sortOrder = request.queryParam("sortOrder").orElse("desc");
|
||||
|
||||
LocalDate startDate = startDateStr != null ? LocalDate.parse(startDateStr, DATE_FORMATTER) : LocalDate.now().minusDays(30);
|
||||
LocalDate endDate = endDateStr != null ? LocalDate.parse(endDateStr, DATE_FORMATTER) : LocalDate.now();
|
||||
|
||||
log.info("管理员查询所有签到记录, startDate: {}, endDate: {}, sortBy: {}, sortOrder: {}", startDate, endDate, sortBy, sortOrder);
|
||||
|
||||
return checkService.getAllSignInRecords(startDate, endDate, sortBy, sortOrder)
|
||||
.collectList()
|
||||
.flatMap(records -> ServerResponse.ok()
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.bodyValue(Map.of("code", 200, "message", "success", "data", records)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员查询签到统计(不限会员)
|
||||
*
|
||||
* GET /api/checkIn/admin/statistics
|
||||
*/
|
||||
public Mono<ServerResponse> getAllSignInStatistics(ServerRequest request) {
|
||||
String startDateStr = request.queryParam("startDate").orElse(null);
|
||||
String endDateStr = request.queryParam("endDate").orElse(null);
|
||||
|
||||
LocalDate startDate = startDateStr != null ? LocalDate.parse(startDateStr, DATE_FORMATTER) : LocalDate.now().minusDays(30);
|
||||
LocalDate endDate = endDateStr != null ? LocalDate.parse(endDateStr, DATE_FORMATTER) : LocalDate.now();
|
||||
|
||||
log.info("管理员查询签到统计, startDate: {}, endDate: {}", startDate, endDate);
|
||||
|
||||
return checkService.getAllSignInStats(startDate, endDate)
|
||||
.flatMap(stats -> ServerResponse.ok()
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.bodyValue(Map.of("code", 200, "message", "success", "data", stats)));
|
||||
}
|
||||
}
|
||||
|
||||
-6
@@ -57,12 +57,6 @@ public interface SignInRecordRepository extends R2dbcRepository<SignInRecord, Lo
|
||||
@Query("SELECT * FROM sign_in_record WHERE sign_in_time >= :startTime AND sign_in_time <= :endTime AND is_delete = false ORDER BY sign_in_time DESC")
|
||||
Flux<SignInRecord> findByTimeRange(LocalDateTime startTime, LocalDateTime endTime);
|
||||
|
||||
/**
|
||||
* 根据时间范围查询签到记录(支持动态排序)
|
||||
*/
|
||||
@Query("SELECT * FROM sign_in_record WHERE sign_in_time >= :startTime AND sign_in_time <= :endTime AND is_delete = false ORDER BY sign_in_time DESC")
|
||||
Flux<SignInRecord> findByTimeRangeSorted(LocalDateTime startTime, LocalDateTime endTime);
|
||||
|
||||
/**
|
||||
* 统计会员在时间范围内的签到次数
|
||||
*/
|
||||
|
||||
-16
@@ -78,20 +78,4 @@ public interface ICheckInService {
|
||||
* @return 签到统计VO
|
||||
*/
|
||||
Mono<SignInStatsVO> getDailySignInStats(LocalDate date);
|
||||
|
||||
/**
|
||||
* 管理员查询所有签到记录(支持排序)
|
||||
*
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @param sortBy 排序字段
|
||||
* @param sortOrder 排序方向
|
||||
* @return 签到记录列表(含会员姓名、卡类型)
|
||||
*/
|
||||
Flux<SignInRecordVO> getAllSignInRecords(LocalDate startTime, LocalDate endTime, String sortBy, String sortOrder);
|
||||
|
||||
/**
|
||||
* 管理员查询签到统计(不限会员)
|
||||
*/
|
||||
Mono<SignInStatsVO> getAllSignInStats(LocalDate startTime, LocalDate endTime);
|
||||
}
|
||||
|
||||
+36
-154
@@ -16,13 +16,11 @@ import cn.novalon.gym.manage.checkIn.websocket.MyWebSocketHandler;
|
||||
import cn.novalon.gym.manage.common.constant.RedisKeyConstants;
|
||||
import cn.novalon.gym.manage.common.util.RedisUtil;
|
||||
import cn.novalon.gym.manage.groupcourse.service.IGroupCourseBookingService;
|
||||
import cn.novalon.gym.manage.member.entity.Member;
|
||||
import cn.novalon.gym.manage.member.entity.MemberCard;
|
||||
import cn.novalon.gym.manage.member.entity.MemberCardRecord;
|
||||
import cn.novalon.gym.manage.member.enums.MemberCardType;
|
||||
import cn.novalon.gym.manage.member.repository.IMemberRepository;
|
||||
import cn.novalon.gym.manage.member.repository.MemberCardRepository;
|
||||
import cn.novalon.gym.manage.member.repository.MemberCardRecordRepository;
|
||||
import cn.novalon.gym.manage.member.repository.MemberCardRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -49,38 +47,29 @@ public class CheckServiceImpl implements ICheckInService {
|
||||
private final MemberCardRepository memberCardRepository;
|
||||
private final SignInRecordRepository signInRecordRepository;
|
||||
private final IGroupCourseBookingService groupCourseBookingService;
|
||||
private final IMemberRepository memberRepository;
|
||||
|
||||
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
@Override
|
||||
public Mono<QRCodeVo> getQRCode(Long memberId) {
|
||||
log.info("开始查询会员信息, memberId: {}", memberId);
|
||||
log.info("开始生成会员签到二维码, memberId: {}", memberId);
|
||||
|
||||
return findValidMemberCard(memberId)
|
||||
.flatMap(cardRecord -> {
|
||||
log.info("会员信息查询完成, memberCardRecordId: {}", cardRecord.getMemberCardRecordId());
|
||||
|
||||
log.info("开始生成二维码");
|
||||
String qrContent = QRRedisKey.generateQrcodeContent();
|
||||
Map<String, Object> redisMap = new HashMap<>();
|
||||
redisMap.put("qrContent", qrContent);
|
||||
redisMap.put("isUsed", false);
|
||||
redisMap.put("memberId", memberId);
|
||||
redisMap.put("memberCardRecordId", cardRecord.getMemberCardRecordId());
|
||||
String qrContent = QRRedisKey.generateQrcodeContent();
|
||||
Map<String, Object> redisMap = new HashMap<>();
|
||||
redisMap.put("qrContent", qrContent);
|
||||
redisMap.put("isUsed", false);
|
||||
redisMap.put("memberId", memberId);
|
||||
|
||||
return redisUtil.setWithExpire(
|
||||
RedisKeyConstants.QRCODE_USER_DAILY + memberId + LocalDate.now(),
|
||||
redisMap,
|
||||
getSecondsUntilEndOfDay()
|
||||
)
|
||||
.then(Mono.fromSupplier(() -> {
|
||||
String qrCodeBase64 = QrCodeUtil.generateAsBase64(qrContent,
|
||||
BeanUtil.copyProperties(qrCodeConfig, QrConfig.class), "png");
|
||||
return new QRCodeVo(qrCodeBase64, false, qrContent, qrCodeConfig.getWidth(), qrCodeConfig.getHeight(), LocalDate.now());
|
||||
}));
|
||||
})
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("该会员没有可用的会员卡")));
|
||||
return redisUtil.setWithExpire(
|
||||
RedisKeyConstants.QRCODE_USER_DAILY + memberId + LocalDate.now(),
|
||||
redisMap,
|
||||
getSecondsUntilEndOfDay()
|
||||
)
|
||||
.then(Mono.fromSupplier(() -> {
|
||||
String qrCodeBase64 = QrCodeUtil.generateAsBase64(qrContent,
|
||||
BeanUtil.copyProperties(qrCodeConfig, QrConfig.class), "png");
|
||||
return new QRCodeVo(qrCodeBase64, false, qrContent, qrCodeConfig.getWidth(), qrCodeConfig.getHeight(), LocalDate.now());
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -116,9 +105,10 @@ public class CheckServiceImpl implements ICheckInService {
|
||||
}
|
||||
log.info("二维码匹配成功,memberId: {}", memberId);
|
||||
|
||||
Long memberCardRecordId = ((Number) map.get("memberCardRecordId")).longValue();
|
||||
Long memberCardRecordId = map.get("memberCardRecordId") != null
|
||||
? ((Number) map.get("memberCardRecordId")).longValue() : null;
|
||||
|
||||
return processCheckIn(memberId, memberCardRecordId, map, qrContent);
|
||||
return processCheckIn(memberId, memberCardRecordId, map, qrContent);
|
||||
} else {
|
||||
MyWebSocketHandler.sendFailure(qrContent, "二维码无效");
|
||||
return Mono.error(new RuntimeException("二维码无效"));
|
||||
@@ -148,54 +138,23 @@ public class CheckServiceImpl implements ICheckInService {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
// 发送实时进度通知
|
||||
MyWebSocketHandler.sendProgress(qrContent, "VALIDATE_CARD", "正在验证会员卡...");
|
||||
|
||||
return memberCardRecordRepository.findById(memberCardRecordId)
|
||||
.switchIfEmpty(Mono.defer(() -> {
|
||||
MyWebSocketHandler.sendFailure(qrContent, "会员卡记录不存在");
|
||||
return Mono.error(new RuntimeException("会员卡记录不存在"));
|
||||
}))
|
||||
.flatMap(cardRecord -> {
|
||||
if (!"ACTIVE".equals(cardRecord.getStatus().name())) {
|
||||
MyWebSocketHandler.sendFailure(qrContent, "会员卡状态不正确");
|
||||
return Mono.error(new RuntimeException("会员卡状态不正确"));
|
||||
}
|
||||
MyWebSocketHandler.sendProgress(qrContent, "VALIDATE_BOOKING", "正在检查预约信息...");
|
||||
|
||||
// 检查是否有需要签到的团课预约
|
||||
return validateBooking(memberId, now)
|
||||
.then(Mono.defer(() -> {
|
||||
redisMap.put("isUsed", true);
|
||||
redisMap.put("checkInTime", now.format(DATE_FORMATTER));
|
||||
|
||||
if (cardRecord.getExpireTime() != null && cardRecord.getExpireTime().isBefore(now)) {
|
||||
MyWebSocketHandler.sendFailure(qrContent, "会员卡已过期");
|
||||
return Mono.error(new RuntimeException("会员卡已过期"));
|
||||
}
|
||||
|
||||
// 发送实时进度通知
|
||||
MyWebSocketHandler.sendProgress(qrContent, "VALIDATE_BOOKING", "会员卡验证通过,正在检查预约信息...");
|
||||
|
||||
// 检查是否有需要签到的团课预约
|
||||
return validateBooking(memberId, now)
|
||||
.then(memberCardRepository.findByMemberCardIdAndDeletedAtIsNull(cardRecord.getMemberCardId())
|
||||
.switchIfEmpty(Mono.defer(() -> {
|
||||
MyWebSocketHandler.sendFailure(qrContent, "会员卡类型不存在");
|
||||
return Mono.error(new RuntimeException("会员卡类型不存在"));
|
||||
}))
|
||||
.flatMap(card -> {
|
||||
// 发送实时进度通知
|
||||
MyWebSocketHandler.sendProgress(qrContent, "DEDUCT_USAGE", "正在扣减会员卡次数...");
|
||||
|
||||
return deductCardUsage(cardRecord, card)
|
||||
.flatMap(updatedRecord -> {
|
||||
redisMap.put("isUsed", true);
|
||||
redisMap.put("checkInTime", now.format(DATE_FORMATTER));
|
||||
|
||||
return saveSignInRecord(memberId, cardRecord.getMemberCardRecordId(), card.getMemberCardId())
|
||||
.then(redisUtil.set(RedisKeyConstants.QRCODE_USER_DAILY + memberId + LocalDate.now(), redisMap))
|
||||
.then(Mono.defer(() -> {
|
||||
String successMsg = buildSuccessResponse(now);
|
||||
MyWebSocketHandler.sendSuccess(qrContent, memberId, now.format(DATE_FORMATTER));
|
||||
log.info("签到成功, memberId: {}, cardRecordId: {}", memberId, memberCardRecordId);
|
||||
return Mono.just(successMsg);
|
||||
}));
|
||||
});
|
||||
}));
|
||||
});
|
||||
return saveSignInRecord(memberId, null, null)
|
||||
.then(redisUtil.set(RedisKeyConstants.QRCODE_USER_DAILY + memberId + LocalDate.now(), redisMap))
|
||||
.then(Mono.defer(() -> {
|
||||
String successMsg = buildSuccessResponse(now);
|
||||
MyWebSocketHandler.sendSuccess(qrContent, memberId, now.format(DATE_FORMATTER));
|
||||
log.info("签到成功, memberId: {}", memberId);
|
||||
return Mono.just(successMsg);
|
||||
}));
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -433,83 +392,6 @@ public class CheckServiceImpl implements ICheckInService {
|
||||
return vo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<SignInRecordVO> getAllSignInRecords(LocalDate startTime, LocalDate endTime, String sortBy, String sortOrder) {
|
||||
LocalDateTime start = startTime.atStartOfDay();
|
||||
LocalDateTime end = endTime.atTime(LocalTime.MAX);
|
||||
|
||||
Flux<SignInRecord> recordFlux = signInRecordRepository.findByTimeRangeSorted(start, end);
|
||||
|
||||
return recordFlux
|
||||
.flatMap(record -> {
|
||||
// fetch member name
|
||||
Mono<String> memberNameMono = memberRepository.findById(record.getMemberId())
|
||||
.map(Member::getNickname)
|
||||
.defaultIfEmpty("未知");
|
||||
// fetch card type name
|
||||
Mono<String> cardTypeMono = record.getMemberCardId() != null
|
||||
? memberCardRepository.findByMemberCardIdAndDeletedAtIsNull(record.getMemberCardId())
|
||||
.map(MemberCard::getMemberCardName)
|
||||
.defaultIfEmpty("未知")
|
||||
: Mono.just("-");
|
||||
return Mono.zip(memberNameMono, cardTypeMono)
|
||||
.map(tuple -> {
|
||||
SignInRecordVO vo = convertToVO(record);
|
||||
vo.setMemberName(tuple.getT1());
|
||||
vo.setMemberCardType(tuple.getT2());
|
||||
return vo;
|
||||
});
|
||||
})
|
||||
.collectList()
|
||||
.flatMapMany(list -> {
|
||||
// in-memory sort
|
||||
boolean asc = "asc".equalsIgnoreCase(sortOrder);
|
||||
java.util.Comparator<SignInRecordVO> comparator;
|
||||
switch (sortBy != null ? sortBy : "signInTime") {
|
||||
case "id":
|
||||
comparator = java.util.Comparator.comparing(SignInRecordVO::getId, java.util.Comparator.nullsLast(Long::compareTo));
|
||||
break;
|
||||
case "memberName":
|
||||
comparator = java.util.Comparator.comparing(SignInRecordVO::getMemberName, java.util.Comparator.nullsLast(String::compareTo));
|
||||
break;
|
||||
case "signInTime":
|
||||
default:
|
||||
comparator = java.util.Comparator.comparing(SignInRecordVO::getSignInTime, java.util.Comparator.nullsLast(java.time.LocalDateTime::compareTo));
|
||||
break;
|
||||
}
|
||||
if (!asc) {
|
||||
comparator = comparator.reversed();
|
||||
}
|
||||
list.sort(comparator);
|
||||
return Flux.fromIterable(list);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<SignInStatsVO> getAllSignInStats(LocalDate startTime, LocalDate endTime) {
|
||||
LocalDateTime start = startTime.atStartOfDay();
|
||||
LocalDateTime end = endTime.atTime(LocalTime.MAX);
|
||||
|
||||
return Mono.zip(
|
||||
(Object[] results) -> {
|
||||
Long total = (Long) results[0];
|
||||
Long success = (Long) results[1];
|
||||
Long members = (Long) results[2];
|
||||
SignInStatsVO stats = new SignInStatsVO();
|
||||
stats.setTotalCount(total);
|
||||
stats.setSuccessCount(success);
|
||||
stats.setStartDate(startTime);
|
||||
stats.setEndDate(endTime);
|
||||
stats.setUniqueMemberCount(members);
|
||||
stats.setSuccessRate(total > 0 ? (double) success / total * 100.0 : 0.0);
|
||||
return stats;
|
||||
},
|
||||
signInRecordRepository.countByTimeRange(start, end),
|
||||
signInRecordRepository.countSuccessByTimeRange(start, end),
|
||||
signInRecordRepository.countDistinctMembersByTimeRange(start, end)
|
||||
);
|
||||
}
|
||||
|
||||
private long getSecondsUntilEndOfDay() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalDateTime endOfDay = now.toLocalDate().atTime(23, 59, 59);
|
||||
|
||||
-10
@@ -59,16 +59,6 @@ public class SignInRecordVO {
|
||||
*/
|
||||
private String source;
|
||||
|
||||
/**
|
||||
* 会员姓名(关联查询)
|
||||
*/
|
||||
private String memberName;
|
||||
|
||||
/**
|
||||
* 会员卡类型名称(关联查询)
|
||||
*/
|
||||
private String memberCardType;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
|
||||
+1
-5
@@ -14,7 +14,6 @@ import cn.novalon.gym.manage.member.entity.MemberCard;
|
||||
import cn.novalon.gym.manage.member.entity.MemberCardRecord;
|
||||
import cn.novalon.gym.manage.member.repository.MemberCardRecordRepository;
|
||||
import cn.novalon.gym.manage.member.repository.MemberCardRepository;
|
||||
import cn.novalon.gym.manage.member.repository.IMemberRepository;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -58,9 +57,6 @@ class CheckInModuleTest {
|
||||
@Mock
|
||||
private IGroupCourseBookingService groupCourseBookingService;
|
||||
|
||||
@Mock
|
||||
private IMemberRepository memberRepository;
|
||||
|
||||
@Mock
|
||||
private MemberCard mockMemberCard;
|
||||
|
||||
@@ -76,7 +72,7 @@ class CheckInModuleTest {
|
||||
void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
checkService = new CheckServiceImpl(qrCodeConfig, redisUtil, memberCardRecordRepository,
|
||||
memberCardRepository, signInRecordRepository, groupCourseBookingService, memberRepository);
|
||||
memberCardRepository, signInRecordRepository, groupCourseBookingService);
|
||||
|
||||
when(mockMemberCard.getId()).thenReturn(1L);
|
||||
when(mockMemberCard.getMemberCardType()).thenReturn("TIME_CARD");
|
||||
|
||||
@@ -67,7 +67,12 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
<version>5.2.5</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Fix commons-compress version for POI compatibility -->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-compress</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Gym Modules -->
|
||||
|
||||
+2
-2
@@ -26,7 +26,7 @@ public class DataStatisticsDao {
|
||||
* 统计指定时间范围内新增会员数
|
||||
*/
|
||||
public Mono<Long> countNewMembers(LocalDateTime startTime, LocalDateTime endTime) {
|
||||
return databaseClient.sql("SELECT COUNT(*) FROM member_user WHERE created_at >= :startTime AND created_at < :endTime AND deleted_at IS NULL")
|
||||
return databaseClient.sql("SELECT COUNT(*) FROM member_user WHERE created_at >= :startTime AND created_at < :endTime AND is_deleted = false")
|
||||
.bind("startTime", startTime)
|
||||
.bind("endTime", endTime)
|
||||
.map(row -> row.get(0, Long.class))
|
||||
@@ -37,7 +37,7 @@ public class DataStatisticsDao {
|
||||
* 统计总会员数
|
||||
*/
|
||||
public Mono<Long> countTotalMembers() {
|
||||
return databaseClient.sql("SELECT COUNT(*) FROM member_user WHERE deleted_at IS NULL")
|
||||
return databaseClient.sql("SELECT COUNT(*) FROM member_user WHERE is_deleted = false")
|
||||
.map(row -> row.get(0, Long.class))
|
||||
.one();
|
||||
}
|
||||
|
||||
+6
@@ -59,6 +59,12 @@ public class DataStatistics {
|
||||
public static final String WEEK = "WEEK";
|
||||
/** 月统计 */
|
||||
public static final String MONTH = "MONTH";
|
||||
/** 近30天 */
|
||||
public static final String LAST_30_DAYS = "LAST_30_DAYS";
|
||||
/** 近90天 */
|
||||
public static final String LAST_90_DAYS = "LAST_90_DAYS";
|
||||
/** 今年 */
|
||||
public static final String YEAR = "YEAR";
|
||||
|
||||
private PeriodType() {}
|
||||
}
|
||||
|
||||
-5
@@ -4,8 +4,6 @@ import cn.novalon.gym.manage.datacount.domain.*;
|
||||
import cn.novalon.gym.manage.datacount.service.IDataStatisticsService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -27,8 +25,6 @@ import java.time.format.DateTimeFormatter;
|
||||
@Tag(name = "数据统计", description = "数据统计相关操作")
|
||||
public class DataStatisticsHandler {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(DataStatisticsHandler.class);
|
||||
|
||||
@Autowired
|
||||
private IDataStatisticsService dataStatisticsService;
|
||||
|
||||
@@ -39,7 +35,6 @@ public class DataStatisticsHandler {
|
||||
return dataStatisticsService.getStatisticsSummaryWithCache(query)
|
||||
.flatMap(summary -> ServerResponse.ok().bodyValue(summary))
|
||||
.onErrorResume(e -> {
|
||||
log.error("获取综合统计数据失败", e);
|
||||
StatisticsSummary errorSummary = StatisticsSummary.builder()
|
||||
.statDate(LocalDateTime.now().toLocalDate().toString())
|
||||
.generatedAt(LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME))
|
||||
|
||||
+28
-88
@@ -13,7 +13,6 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -23,9 +22,7 @@ import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -176,25 +173,9 @@ public class DataStatisticsServiceImpl implements IDataStatisticsService {
|
||||
|
||||
@Override
|
||||
public Mono<StatisticsSummary> getStatisticsSummary(StatisticsQuery query) {
|
||||
String statDate = query.getStartTime() != null
|
||||
? query.getStartTime().toLocalDate().toString()
|
||||
: LocalDateTime.now().toLocalDate().toString();
|
||||
|
||||
Mono<MemberStatistics> memberStatsMono = getMemberStatistics(query)
|
||||
.onErrorResume(e -> {
|
||||
log.error("获取会员统计数据失败", e);
|
||||
return Mono.just(MemberStatistics.builder().statDate(statDate).build());
|
||||
});
|
||||
Mono<BookingStatistics> bookingStatsMono = getBookingStatistics(query)
|
||||
.onErrorResume(e -> {
|
||||
log.error("获取预约统计数据失败", e);
|
||||
return Mono.just(BookingStatistics.builder().statDate(statDate).build());
|
||||
});
|
||||
Mono<SignInStatistics> signInStatsMono = getSignInStatistics(query)
|
||||
.onErrorResume(e -> {
|
||||
log.error("获取签到统计数据失败", e);
|
||||
return Mono.just(SignInStatistics.builder().statDate(statDate).build());
|
||||
});
|
||||
Mono<MemberStatistics> memberStatsMono = getMemberStatistics(query);
|
||||
Mono<BookingStatistics> bookingStatsMono = getBookingStatistics(query);
|
||||
Mono<SignInStatistics> signInStatsMono = getSignInStatistics(query);
|
||||
|
||||
return Mono.zip(memberStatsMono, bookingStatsMono, signInStatsMono)
|
||||
.map(tuple -> StatisticsSummary.builder()
|
||||
@@ -207,75 +188,21 @@ public class DataStatisticsServiceImpl implements IDataStatisticsService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<DataStatistics> queryHistoricalStatistics(StatisticsQuery query) {
|
||||
public reactor.core.publisher.Flux<DataStatistics> queryHistoricalStatistics(StatisticsQuery query) {
|
||||
// 历史统计数据查询(从Redis缓存中获取)
|
||||
String cacheKey = buildCacheKey(query);
|
||||
return redisUtil.get(cacheKey, String.class)
|
||||
.flatMapMany(json -> {
|
||||
try {
|
||||
List<DataStatistics> stats = objectMapper.readValue(json,
|
||||
objectMapper.getTypeFactory().constructCollectionType(List.class, DataStatistics.class));
|
||||
return Flux.fromIterable(stats);
|
||||
java.util.List<DataStatistics> stats = objectMapper.readValue(json,
|
||||
objectMapper.getTypeFactory().constructCollectionType(java.util.List.class, DataStatistics.class));
|
||||
return reactor.core.publisher.Flux.fromIterable(stats);
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to parse historical statistics from cache", e);
|
||||
return Flux.empty();
|
||||
return reactor.core.publisher.Flux.empty();
|
||||
}
|
||||
})
|
||||
.switchIfEmpty(buildLiveStatistics(query));
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存未命中时,从数据库实时构建统计数据
|
||||
*/
|
||||
private Flux<DataStatistics> buildLiveStatistics(StatisticsQuery query) {
|
||||
LocalDateTime startTime = getStartTime(query);
|
||||
LocalDateTime endTime = getEndTime(query);
|
||||
String periodType = query.getPeriodType() != null ? query.getPeriodType() : "DAY";
|
||||
LocalDateTime statDate = endTime;
|
||||
|
||||
Mono<Long> memberCountMono = dataStatisticsDao.countNewMembers(startTime, endTime);
|
||||
Mono<Long> totalMembersMono = dataStatisticsDao.countTotalMembers();
|
||||
Mono<Long> bookingCountMono = dataStatisticsDao.countBookings(startTime, endTime);
|
||||
Mono<Long> signInCountMono = dataStatisticsDao.countSignIns(startTime, endTime);
|
||||
|
||||
return Mono.zip(memberCountMono, totalMembersMono, bookingCountMono, signInCountMono)
|
||||
.flatMapMany(tuple -> {
|
||||
long newMembers = tuple.getT1() != null ? tuple.getT1() : 0L;
|
||||
long totalMembers = tuple.getT2() != null ? tuple.getT2() : 0L;
|
||||
long bookings = tuple.getT3() != null ? tuple.getT3() : 0L;
|
||||
long signIns = tuple.getT4() != null ? tuple.getT4() : 0L;
|
||||
|
||||
List<DataStatistics> list = new ArrayList<>();
|
||||
|
||||
DataStatistics memberStat = DataStatistics.builder()
|
||||
.statType(DataStatistics.StatType.MEMBER)
|
||||
.periodType(periodType)
|
||||
.statDate(statDate)
|
||||
.count(totalMembers)
|
||||
.extraData("新增" + newMembers + "人")
|
||||
.build();
|
||||
list.add(memberStat);
|
||||
|
||||
DataStatistics bookingStat = DataStatistics.builder()
|
||||
.statType(DataStatistics.StatType.BOOKING)
|
||||
.periodType(periodType)
|
||||
.statDate(statDate)
|
||||
.count(bookings)
|
||||
.extraData("新增" + bookings + "条预约")
|
||||
.build();
|
||||
list.add(bookingStat);
|
||||
|
||||
DataStatistics signInStat = DataStatistics.builder()
|
||||
.statType(DataStatistics.StatType.SIGN_IN)
|
||||
.periodType(periodType)
|
||||
.statDate(statDate)
|
||||
.count(signIns)
|
||||
.extraData("新增" + signIns + "次签到")
|
||||
.build();
|
||||
list.add(signInStat);
|
||||
|
||||
return Flux.fromIterable(list);
|
||||
});
|
||||
.switchIfEmpty(reactor.core.publisher.Flux.empty());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -531,13 +458,16 @@ public class DataStatisticsServiceImpl implements IDataStatisticsService {
|
||||
String periodType = query.getPeriodType();
|
||||
|
||||
if (DataStatistics.PeriodType.WEEK.equals(periodType)) {
|
||||
// 周统计:本周一
|
||||
return today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)).atStartOfDay();
|
||||
} else if (DataStatistics.PeriodType.MONTH.equals(periodType)) {
|
||||
// 月统计:本月第一天
|
||||
return today.withDayOfMonth(1).atStartOfDay();
|
||||
} else if (DataStatistics.PeriodType.LAST_30_DAYS.equals(periodType)) {
|
||||
return today.minusDays(29).atStartOfDay();
|
||||
} else if (DataStatistics.PeriodType.LAST_90_DAYS.equals(periodType)) {
|
||||
return today.minusDays(89).atStartOfDay();
|
||||
} else if (DataStatistics.PeriodType.YEAR.equals(periodType)) {
|
||||
return today.withDayOfYear(1).atStartOfDay();
|
||||
} else {
|
||||
// 日统计:当天零点
|
||||
return today.atStartOfDay();
|
||||
}
|
||||
}
|
||||
@@ -551,13 +481,14 @@ public class DataStatisticsServiceImpl implements IDataStatisticsService {
|
||||
String periodType = query.getPeriodType();
|
||||
|
||||
if (DataStatistics.PeriodType.WEEK.equals(periodType)) {
|
||||
// 周统计:本周日 23:59:59
|
||||
return today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY)).atTime(23, 59, 59);
|
||||
} else if (DataStatistics.PeriodType.MONTH.equals(periodType)) {
|
||||
// 月统计:本月最后一天 23:59:59
|
||||
return today.with(TemporalAdjusters.lastDayOfMonth()).atTime(23, 59, 59);
|
||||
} else if (DataStatistics.PeriodType.LAST_30_DAYS.equals(periodType)
|
||||
|| DataStatistics.PeriodType.LAST_90_DAYS.equals(periodType)
|
||||
|| DataStatistics.PeriodType.YEAR.equals(periodType)) {
|
||||
return LocalDateTime.now();
|
||||
} else {
|
||||
// 日统计:当前时间
|
||||
return LocalDateTime.now();
|
||||
}
|
||||
}
|
||||
@@ -576,6 +507,15 @@ public class DataStatisticsServiceImpl implements IDataStatisticsService {
|
||||
} else if (DataStatistics.PeriodType.MONTH.equals(periodType)) {
|
||||
startTime = date.withDayOfMonth(1).atStartOfDay();
|
||||
endTime = date.with(TemporalAdjusters.lastDayOfMonth()).atTime(23, 59, 59);
|
||||
} else if (DataStatistics.PeriodType.LAST_30_DAYS.equals(periodType)) {
|
||||
startTime = date.minusDays(29).atStartOfDay();
|
||||
endTime = date.atTime(23, 59, 59);
|
||||
} else if (DataStatistics.PeriodType.LAST_90_DAYS.equals(periodType)) {
|
||||
startTime = date.minusDays(89).atStartOfDay();
|
||||
endTime = date.atTime(23, 59, 59);
|
||||
} else if (DataStatistics.PeriodType.YEAR.equals(periodType)) {
|
||||
startTime = date.withDayOfYear(1).atStartOfDay();
|
||||
endTime = date.atTime(23, 59, 59);
|
||||
} else {
|
||||
startTime = date.atStartOfDay();
|
||||
endTime = date.plusDays(1).atStartOfDay();
|
||||
|
||||
@@ -94,11 +94,20 @@
|
||||
<version>3.5.3</version>
|
||||
</dependency>
|
||||
<!-- 阿里云OSS SDK -->
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>com.aliyun.oss</groupId>
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
<version>3.17.4</version>
|
||||
</dependency>
|
||||
-->
|
||||
|
||||
<!-- 文件管理模块(统一文件存储) -->
|
||||
<dependency>
|
||||
<groupId>cn.novalon.gym.manage</groupId>
|
||||
<artifactId>manage-file</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
package cn.novalon.gym.manage.groupcourse.dao;
|
||||
|
||||
import cn.novalon.gym.manage.groupcourse.entity.BannerEntity;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.r2dbc.repository.Modifying;
|
||||
import org.springframework.data.r2dbc.repository.Query;
|
||||
import org.springframework.data.r2dbc.repository.R2dbcRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Repository
|
||||
public interface BannerDao extends R2dbcRepository<BannerEntity, Long> {
|
||||
|
||||
Mono<BannerEntity> findByIdAndDeletedAtIsNull(Long id);
|
||||
|
||||
Flux<BannerEntity> findAllByDeletedAtIsNull();
|
||||
|
||||
Flux<BannerEntity> findAllByDeletedAtIsNull(Sort sort);
|
||||
|
||||
Flux<BannerEntity> findByIsActiveTrueAndDeletedAtIsNull();
|
||||
|
||||
Flux<BannerEntity> findByIsActiveTrueAndDeletedAtIsNull(Sort sort);
|
||||
|
||||
@Modifying
|
||||
@Query("UPDATE banner SET is_active = :isActive, updated_at = :updatedAt WHERE id = :id AND deleted_at IS NULL")
|
||||
Mono<Integer> updateActiveStatus(Long id, Boolean isActive, LocalDateTime updatedAt);
|
||||
|
||||
@Modifying
|
||||
@Query("UPDATE banner SET deleted_at = :deletedAt WHERE id = :id")
|
||||
Mono<Integer> softDelete(Long id, LocalDateTime deletedAt);
|
||||
}
|
||||
+96
-23
@@ -1,5 +1,6 @@
|
||||
package cn.novalon.gym.manage.groupcourse.dao;
|
||||
|
||||
import cn.novalon.gym.manage.common.dto.PageRequest;
|
||||
import cn.novalon.gym.manage.groupcourse.dto.GroupCourseQueryDto;
|
||||
import cn.novalon.gym.manage.groupcourse.entity.GroupCourseEntity;
|
||||
import org.springframework.data.domain.Sort;
|
||||
@@ -40,18 +41,10 @@ public interface GroupCourseDao extends R2dbcRepository<GroupCourseEntity, Long>
|
||||
@Query("UPDATE group_course SET deleted_at = :deletedAt WHERE id = :id")
|
||||
Mono<Integer> softDelete(Long id, LocalDateTime deletedAt);
|
||||
|
||||
@Modifying
|
||||
@Query("UPDATE group_course SET deleted_at = NULL, status = '1', updated_at = :updatedAt WHERE id = :id AND deleted_at IS NOT NULL")
|
||||
Mono<Integer> restoreCourse(Long id, LocalDateTime updatedAt);
|
||||
|
||||
@Modifying
|
||||
@Query("UPDATE group_course SET status = '2', updated_at = :updatedAt WHERE status = '0' AND end_time <= NOW() AND deleted_at IS NULL")
|
||||
Mono<Integer> completeExpiredCourses(LocalDateTime updatedAt);
|
||||
|
||||
@Modifying
|
||||
@Query("UPDATE group_course SET status = '0', current_members = 0, start_time = start_time + INTERVAL '7 days', end_time = end_time + INTERVAL '7 days', updated_at = :updatedAt WHERE is_recurring = TRUE AND status = '2' AND end_time <= NOW() AND deleted_at IS NULL")
|
||||
Mono<Integer> renewRecurringCourses(LocalDateTime updatedAt);
|
||||
|
||||
Flux<GroupCourseEntity> findByCourseTypeAndDeletedAtIsNull(Long courseType);
|
||||
|
||||
/**
|
||||
@@ -100,11 +93,6 @@ public interface GroupCourseDao extends R2dbcRepository<GroupCourseEntity, Long>
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 常态化团课筛选
|
||||
if (query.getIsRecurring() != null) {
|
||||
conditions.add("is_recurring = :isRecurring");
|
||||
}
|
||||
|
||||
sql.append(" AND ").append(String.join(" AND ", conditions));
|
||||
|
||||
// 5. 价格排序 / 6. 剩余名额最多排序
|
||||
@@ -154,9 +142,6 @@ public interface GroupCourseDao extends R2dbcRepository<GroupCourseEntity, Long>
|
||||
if (query.getEndDate() != null) {
|
||||
spec = spec.bind("endDate", query.getEndDate());
|
||||
}
|
||||
if (query.getIsRecurring() != null) {
|
||||
spec = spec.bind("isRecurring", query.getIsRecurring());
|
||||
}
|
||||
spec = spec.bind("limit", size);
|
||||
spec = spec.bind("offset", offset);
|
||||
|
||||
@@ -176,12 +161,12 @@ public interface GroupCourseDao extends R2dbcRepository<GroupCourseEntity, Long>
|
||||
entity.setCoverImage(row.get("cover_image", String.class));
|
||||
entity.setDescription(row.get("description", String.class));
|
||||
entity.setStoredValueAmount(row.get("stored_value_amount", java.math.BigDecimal.class));
|
||||
entity.setQrCodePath(row.get("qr_code_path", String.class));
|
||||
entity.setCreateBy(row.get("create_by", String.class));
|
||||
entity.setUpdateBy(row.get("update_by", String.class));
|
||||
entity.setCreatedAt(row.get("created_at", LocalDateTime.class));
|
||||
entity.setUpdatedAt(row.get("updated_at", LocalDateTime.class));
|
||||
entity.setDeletedAt(row.get("deleted_at", LocalDateTime.class));
|
||||
entity.setIsRecurring(row.get("is_recurring", Boolean.class));
|
||||
return entity;
|
||||
}).all();
|
||||
}
|
||||
@@ -224,10 +209,6 @@ public interface GroupCourseDao extends R2dbcRepository<GroupCourseEntity, Long>
|
||||
}
|
||||
}
|
||||
|
||||
if (query.getIsRecurring() != null) {
|
||||
conditions.add("is_recurring = :isRecurring");
|
||||
}
|
||||
|
||||
sql.append(" AND ").append(String.join(" AND ", conditions));
|
||||
|
||||
DatabaseClient.GenericExecuteSpec spec = databaseClient.sql(sql.toString());
|
||||
@@ -244,8 +225,100 @@ public interface GroupCourseDao extends R2dbcRepository<GroupCourseEntity, Long>
|
||||
if (query.getEndDate() != null) {
|
||||
spec = spec.bind("endDate", query.getEndDate());
|
||||
}
|
||||
if (query.getIsRecurring() != null) {
|
||||
spec = spec.bind("isRecurring", query.getIsRecurring());
|
||||
|
||||
return spec.map((row, meta) -> row.get(0, Long.class)).one();
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询团课(支持 keyword 和 status 过滤)
|
||||
*/
|
||||
default Flux<GroupCourseEntity> findByPageFiltered(DatabaseClient databaseClient, PageRequest pageRequest) {
|
||||
StringBuilder sql = new StringBuilder("SELECT * FROM group_course WHERE deleted_at IS NULL");
|
||||
List<String> conditions = new ArrayList<>();
|
||||
|
||||
if (pageRequest.getKeyword() != null && !pageRequest.getKeyword().isEmpty()) {
|
||||
conditions.add("course_name ILIKE :keyword");
|
||||
}
|
||||
if (pageRequest.getStatus() != null && !pageRequest.getStatus().isEmpty()) {
|
||||
conditions.add("status = :status");
|
||||
}
|
||||
|
||||
if (!conditions.isEmpty()) {
|
||||
sql.append(" AND ").append(String.join(" AND ", conditions));
|
||||
}
|
||||
|
||||
String sort = pageRequest.getSort() != null ? pageRequest.getSort() : "id";
|
||||
String order = "desc".equalsIgnoreCase(pageRequest.getOrder()) ? "DESC" : "ASC";
|
||||
sql.append(" ORDER BY ").append(sort).append(" ").append(order);
|
||||
|
||||
int size = pageRequest.getSize();
|
||||
if (size < 1) size = 10;
|
||||
if (size > 100) size = 100;
|
||||
int offset = pageRequest.getPage() * size;
|
||||
sql.append(" LIMIT :limit OFFSET :offset");
|
||||
|
||||
DatabaseClient.GenericExecuteSpec spec = databaseClient.sql(sql.toString());
|
||||
|
||||
if (pageRequest.getKeyword() != null && !pageRequest.getKeyword().isEmpty()) {
|
||||
spec = spec.bind("keyword", "%" + pageRequest.getKeyword() + "%");
|
||||
}
|
||||
if (pageRequest.getStatus() != null && !pageRequest.getStatus().isEmpty()) {
|
||||
spec = spec.bind("status", pageRequest.getStatus());
|
||||
}
|
||||
spec = spec.bind("limit", size);
|
||||
spec = spec.bind("offset", offset);
|
||||
|
||||
return spec.map((row, meta) -> {
|
||||
GroupCourseEntity entity = new GroupCourseEntity();
|
||||
entity.setId(row.get("id", Long.class));
|
||||
entity.setCourseName(row.get("course_name", String.class));
|
||||
entity.setCoachId(row.get("coach_id", Long.class));
|
||||
entity.setCourseType(row.get("course_type", Long.class));
|
||||
entity.setStartTime(row.get("start_time", LocalDateTime.class));
|
||||
entity.setEndTime(row.get("end_time", LocalDateTime.class));
|
||||
entity.setMaxMembers(row.get("max_members", Integer.class));
|
||||
entity.setCurrentMembers(row.get("current_members", Integer.class));
|
||||
String statusStr = row.get("status", String.class);
|
||||
entity.setStatus(statusStr != null ? Long.parseLong(statusStr) : null);
|
||||
entity.setLocation(row.get("location", String.class));
|
||||
entity.setCoverImage(row.get("cover_image", String.class));
|
||||
entity.setDescription(row.get("description", String.class));
|
||||
entity.setStoredValueAmount(row.get("stored_value_amount", java.math.BigDecimal.class));
|
||||
entity.setQrCodePath(row.get("qr_code_path", String.class));
|
||||
entity.setCreateBy(row.get("create_by", String.class));
|
||||
entity.setUpdateBy(row.get("update_by", String.class));
|
||||
entity.setCreatedAt(row.get("created_at", LocalDateTime.class));
|
||||
entity.setUpdatedAt(row.get("updated_at", LocalDateTime.class));
|
||||
entity.setDeletedAt(row.get("deleted_at", LocalDateTime.class));
|
||||
return entity;
|
||||
}).all();
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询团课总数(支持 keyword 和 status 过滤)
|
||||
*/
|
||||
default Mono<Long> countByPageFiltered(DatabaseClient databaseClient, PageRequest pageRequest) {
|
||||
StringBuilder sql = new StringBuilder("SELECT COUNT(*) FROM group_course WHERE deleted_at IS NULL");
|
||||
List<String> conditions = new ArrayList<>();
|
||||
|
||||
if (pageRequest.getKeyword() != null && !pageRequest.getKeyword().isEmpty()) {
|
||||
conditions.add("course_name ILIKE :keyword");
|
||||
}
|
||||
if (pageRequest.getStatus() != null && !pageRequest.getStatus().isEmpty()) {
|
||||
conditions.add("status = :status");
|
||||
}
|
||||
|
||||
if (!conditions.isEmpty()) {
|
||||
sql.append(" AND ").append(String.join(" AND ", conditions));
|
||||
}
|
||||
|
||||
DatabaseClient.GenericExecuteSpec spec = databaseClient.sql(sql.toString());
|
||||
|
||||
if (pageRequest.getKeyword() != null && !pageRequest.getKeyword().isEmpty()) {
|
||||
spec = spec.bind("keyword", "%" + pageRequest.getKeyword() + "%");
|
||||
}
|
||||
if (pageRequest.getStatus() != null && !pageRequest.getStatus().isEmpty()) {
|
||||
spec = spec.bind("status", pageRequest.getStatus());
|
||||
}
|
||||
|
||||
return spec.map((row, meta) -> row.get(0, Long.class)).one();
|
||||
|
||||
-4
@@ -29,8 +29,4 @@ public interface GroupCourseTypeDao extends R2dbcRepository<GroupCourseTypeEntit
|
||||
@Modifying
|
||||
@Query("UPDATE group_course_type SET deleted_at = :deletedAt WHERE id = :id")
|
||||
Mono<Integer> softDelete(Long id, LocalDateTime deletedAt);
|
||||
|
||||
@Modifying
|
||||
@Query("UPDATE group_course_type SET type_name = :typeName, base_difficulty = :baseDifficulty, description = :description, category = :category, updated_at = :updatedAt WHERE id = :id AND deleted_at IS NULL")
|
||||
Mono<Integer> updateFields(Long id, String typeName, Integer baseDifficulty, String description, String category, LocalDateTime updatedAt);
|
||||
}
|
||||
-43
@@ -1,43 +0,0 @@
|
||||
package cn.novalon.gym.manage.groupcourse.domain;
|
||||
|
||||
import cn.novalon.gym.manage.sys.core.domain.BaseDomain;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
public class Banner extends BaseDomain {
|
||||
|
||||
@Schema(description = "背景图URL", example = "https://example.com/banner.jpg")
|
||||
private String imageUrl;
|
||||
|
||||
@Schema(description = "主标题", example = "突破自我")
|
||||
private String title;
|
||||
|
||||
@Schema(description = "副标题", example = "超越极限")
|
||||
private String subtitle;
|
||||
|
||||
@Schema(description = "简介", example = "科学训练 · 遇见更好的自己")
|
||||
private String description;
|
||||
|
||||
@Schema(description = "排序(数值越大越靠前)", example = "10")
|
||||
private Integer sortOrder;
|
||||
|
||||
@Schema(description = "是否启用", example = "true")
|
||||
private Boolean isActive;
|
||||
|
||||
public String getImageUrl() { return imageUrl; }
|
||||
public void setImageUrl(String imageUrl) { this.imageUrl = imageUrl; }
|
||||
|
||||
public String getTitle() { return title; }
|
||||
public void setTitle(String title) { this.title = title; }
|
||||
|
||||
public String getSubtitle() { return subtitle; }
|
||||
public void setSubtitle(String subtitle) { this.subtitle = subtitle; }
|
||||
|
||||
public String getDescription() { return description; }
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
public Integer getSortOrder() { return sortOrder; }
|
||||
public void setSortOrder(Integer sortOrder) { this.sortOrder = sortOrder; }
|
||||
|
||||
public Boolean getIsActive() { return isActive; }
|
||||
public void setIsActive(Boolean isActive) { this.isActive = isActive; }
|
||||
}
|
||||
-12
@@ -60,10 +60,6 @@ public class GroupCourse extends BaseDomain{
|
||||
@Schema(description = "二维码路径", example = "D:\\Games\\exmp\\image\\abc123_20260618120000.png")
|
||||
private String qrCodePath;
|
||||
|
||||
//是否常态化团课
|
||||
@Schema(description = "是否常态化团课", example = "true")
|
||||
private Boolean isRecurring;
|
||||
|
||||
public String getCourseName() {
|
||||
return courseName;
|
||||
}
|
||||
@@ -167,12 +163,4 @@ public class GroupCourse extends BaseDomain{
|
||||
public void setQrCodePath(String qrCodePath) {
|
||||
this.qrCodePath = qrCodePath;
|
||||
}
|
||||
|
||||
public Boolean getIsRecurring() {
|
||||
return isRecurring;
|
||||
}
|
||||
|
||||
public void setIsRecurring(Boolean isRecurring) {
|
||||
this.isRecurring = isRecurring;
|
||||
}
|
||||
}
|
||||
|
||||
-12
@@ -53,10 +53,6 @@ public class GroupCourseBooking extends BaseDomain {
|
||||
@Schema(description = "上课地点", example = "健身房A区")
|
||||
private String location;
|
||||
|
||||
//封面图URL(非DB字段,由 Service 从 GroupCourse 填充)
|
||||
@Schema(description = "封面图URL", example = "https://example.com/cover.jpg")
|
||||
private String coverImage;
|
||||
|
||||
public Long getCourseId() {
|
||||
return courseId;
|
||||
}
|
||||
@@ -136,12 +132,4 @@ public class GroupCourseBooking extends BaseDomain {
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public String getCoverImage() {
|
||||
return coverImage;
|
||||
}
|
||||
|
||||
public void setCoverImage(String coverImage) {
|
||||
this.coverImage = coverImage;
|
||||
}
|
||||
}
|
||||
-11
@@ -40,9 +40,6 @@ public class GroupCourseQueryDto {
|
||||
@Schema(description = "每页大小", example = "10")
|
||||
private Integer size = 10;
|
||||
|
||||
@Schema(description = "是否常态化团课筛选:null-不过滤, true-仅常态化, false-仅非常态化", example = "true")
|
||||
private Boolean isRecurring;
|
||||
|
||||
// ===== Getters and Setters =====
|
||||
|
||||
public String getCourseName() {
|
||||
@@ -116,12 +113,4 @@ public class GroupCourseQueryDto {
|
||||
public void setSize(Integer size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public Boolean getIsRecurring() {
|
||||
return isRecurring;
|
||||
}
|
||||
|
||||
public void setIsRecurring(Boolean isRecurring) {
|
||||
this.isRecurring = isRecurring;
|
||||
}
|
||||
}
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
package cn.novalon.gym.manage.groupcourse.entity;
|
||||
|
||||
import cn.novalon.gym.manage.db.entity.BaseEntity;
|
||||
import org.springframework.data.relational.core.mapping.Column;
|
||||
import org.springframework.data.relational.core.mapping.Table;
|
||||
|
||||
@Table("banner")
|
||||
public class BannerEntity extends BaseEntity {
|
||||
|
||||
@Column("image_url")
|
||||
private String imageUrl;
|
||||
|
||||
@Column("title")
|
||||
private String title;
|
||||
|
||||
@Column("subtitle")
|
||||
private String subtitle;
|
||||
|
||||
@Column("description")
|
||||
private String description;
|
||||
|
||||
@Column("sort_order")
|
||||
private Integer sortOrder;
|
||||
|
||||
@Column("is_active")
|
||||
private Boolean isActive;
|
||||
|
||||
public String getImageUrl() { return imageUrl; }
|
||||
public void setImageUrl(String imageUrl) { this.imageUrl = imageUrl; }
|
||||
|
||||
public String getTitle() { return title; }
|
||||
public void setTitle(String title) { this.title = title; }
|
||||
|
||||
public String getSubtitle() { return subtitle; }
|
||||
public void setSubtitle(String subtitle) { this.subtitle = subtitle; }
|
||||
|
||||
public String getDescription() { return description; }
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
public Integer getSortOrder() { return sortOrder; }
|
||||
public void setSortOrder(Integer sortOrder) { this.sortOrder = sortOrder; }
|
||||
|
||||
public Boolean getIsActive() { return isActive; }
|
||||
public void setIsActive(Boolean isActive) { this.isActive = isActive; }
|
||||
}
|
||||
-12
@@ -62,10 +62,6 @@ public class GroupCourseEntity extends BaseEntity {
|
||||
@Column("qr_code_path")
|
||||
private String qrCodePath;
|
||||
|
||||
//是否常态化团课
|
||||
@Column("is_recurring")
|
||||
private Boolean isRecurring;
|
||||
|
||||
public String getCourseName() {
|
||||
return courseName;
|
||||
}
|
||||
@@ -169,12 +165,4 @@ public class GroupCourseEntity extends BaseEntity {
|
||||
public void setQrCodePath(String qrCodePath) {
|
||||
this.qrCodePath = qrCodePath;
|
||||
}
|
||||
|
||||
public Boolean getIsRecurring() {
|
||||
return isRecurring;
|
||||
}
|
||||
|
||||
public void setIsRecurring(Boolean isRecurring) {
|
||||
this.isRecurring = isRecurring;
|
||||
}
|
||||
}
|
||||
|
||||
-224
@@ -1,224 +0,0 @@
|
||||
package cn.novalon.gym.manage.groupcourse.handler;
|
||||
|
||||
import cn.novalon.gym.manage.groupcourse.domain.Banner;
|
||||
import cn.novalon.gym.manage.groupcourse.service.IBannerService;
|
||||
import cn.novalon.gym.manage.sys.core.service.ISysUserService;
|
||||
import cn.novalon.gym.manage.sys.util.AuthUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
@Tag(name = "轮播图管理", description = "轮播图相关操作")
|
||||
public class BannerHandler {
|
||||
|
||||
private final IBannerService bannerService;
|
||||
private final ISysUserService sysUserService;
|
||||
private final AuthUtil authUtil;
|
||||
|
||||
public BannerHandler(IBannerService bannerService,
|
||||
ISysUserService sysUserService,
|
||||
AuthUtil authUtil) {
|
||||
this.bannerService = bannerService;
|
||||
this.sysUserService = sysUserService;
|
||||
this.authUtil = authUtil;
|
||||
}
|
||||
|
||||
@Operation(summary = "获取所有轮播图", description = "获取系统中所有轮播图列表,支持按排序字段排序")
|
||||
public Mono<ServerResponse> getAllBanners(ServerRequest request) {
|
||||
String sortBy = request.queryParam("sortBy").orElse("sortOrder");
|
||||
String sortOrder = request.queryParam("sortOrder").orElse("desc");
|
||||
|
||||
return ServerResponse.ok()
|
||||
.body(bannerService.findAll(sortBy, sortOrder), Banner.class);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取所有启用的轮播图", description = "获取系统中所有已启用的轮播图列表")
|
||||
public Mono<ServerResponse> getAllActiveBanners(ServerRequest request) {
|
||||
return ServerResponse.ok()
|
||||
.body(bannerService.findAllActive(), Banner.class);
|
||||
}
|
||||
|
||||
@Operation(summary = "根据ID获取轮播图", description = "根据ID获取轮播图详情")
|
||||
public Mono<ServerResponse> getBannerById(ServerRequest request) {
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
return bannerService.findById(id)
|
||||
.flatMap(banner -> ServerResponse.ok().bodyValue(banner))
|
||||
.switchIfEmpty(ServerResponse.notFound().build());
|
||||
}
|
||||
|
||||
@Operation(summary = "创建轮播图", description = "创建新的轮播图记录")
|
||||
public Mono<ServerResponse> createBanner(ServerRequest request) {
|
||||
return request.bodyToMono(Banner.class)
|
||||
.flatMap(banner -> {
|
||||
if (banner.getImageUrl() == null || banner.getImageUrl().isBlank()) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "背景图不能为空");
|
||||
return ServerResponse.badRequest().bodyValue(error);
|
||||
}
|
||||
if (banner.getTitle() == null || banner.getTitle().isBlank()) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "主标题不能为空");
|
||||
return ServerResponse.badRequest().bodyValue(error);
|
||||
}
|
||||
|
||||
return bannerService.create(banner)
|
||||
.flatMap(r -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "轮播图创建成功");
|
||||
response.put("data", r);
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "更新轮播图", description = "更新指定轮播图信息,需验证管理员密码")
|
||||
public Mono<ServerResponse> updateBanner(ServerRequest request) {
|
||||
Long adminId = authUtil.getMemberIdOrThrow(request);
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
String adminPassword = request.queryParam("adminPassword").orElse(null);
|
||||
|
||||
if (adminPassword == null || adminPassword.isBlank()) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "管理员密码不能为空");
|
||||
return ServerResponse.badRequest().bodyValue(error);
|
||||
}
|
||||
|
||||
return sysUserService.verifyPassword(adminId, adminPassword)
|
||||
.flatMap(valid -> {
|
||||
if (!valid) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "管理员密码错误");
|
||||
return ServerResponse.status(HttpStatus.FORBIDDEN).bodyValue(error);
|
||||
}
|
||||
return request.bodyToMono(Banner.class)
|
||||
.flatMap(banner -> bannerService.update(id, banner)
|
||||
.flatMap(r -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "轮播图更新成功");
|
||||
response.put("data", r);
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "删除轮播图", description = "删除指定轮播图(软删除),需验证管理员密码")
|
||||
public Mono<ServerResponse> deleteBanner(ServerRequest request) {
|
||||
Long adminId = authUtil.getMemberIdOrThrow(request);
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
String adminPassword = request.queryParam("adminPassword").orElse(null);
|
||||
|
||||
if (adminPassword == null || adminPassword.isBlank()) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "管理员密码不能为空");
|
||||
return ServerResponse.badRequest().bodyValue(error);
|
||||
}
|
||||
|
||||
return sysUserService.verifyPassword(adminId, adminPassword)
|
||||
.flatMap(valid -> {
|
||||
if (!valid) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "管理员密码错误");
|
||||
return ServerResponse.status(HttpStatus.FORBIDDEN).bodyValue(error);
|
||||
}
|
||||
return bannerService.delete(id)
|
||||
.then(Mono.defer(() -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "轮播图删除成功");
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
}))
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "启用轮播图", description = "启用指定轮播图")
|
||||
public Mono<ServerResponse> enableBanner(ServerRequest request) {
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
|
||||
return bannerService.enable(id)
|
||||
.flatMap(r -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "轮播图启用成功");
|
||||
response.put("data", r);
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "禁用轮播图", description = "禁用指定轮播图,需验证管理员密码")
|
||||
public Mono<ServerResponse> disableBanner(ServerRequest request) {
|
||||
Long adminId = authUtil.getMemberIdOrThrow(request);
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
String adminPassword = request.queryParam("adminPassword").orElse(null);
|
||||
|
||||
if (adminPassword == null || adminPassword.isBlank()) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "管理员密码不能为空");
|
||||
return ServerResponse.badRequest().bodyValue(error);
|
||||
}
|
||||
|
||||
return sysUserService.verifyPassword(adminId, adminPassword)
|
||||
.flatMap(valid -> {
|
||||
if (!valid) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "管理员密码错误");
|
||||
return ServerResponse.status(HttpStatus.FORBIDDEN).bodyValue(error);
|
||||
}
|
||||
return bannerService.disable(id)
|
||||
.flatMap(r -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "轮播图禁用成功");
|
||||
response.put("data", r);
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
-120
@@ -1,120 +0,0 @@
|
||||
package cn.novalon.gym.manage.groupcourse.handler;
|
||||
|
||||
import cn.novalon.gym.manage.groupcourse.util.OSSUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.codec.multipart.FilePart;
|
||||
import org.springframework.http.codec.multipart.Part;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 通用文件上传处理器
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@Tag(name = "文件上传", description = "通用文件上传到阿里云OSS")
|
||||
public class CommonUploadHandler {
|
||||
|
||||
@Operation(summary = "上传图片文件", description = "上传图片到阿里云OSS,返回ossKey和预签名URL")
|
||||
public Mono<ServerResponse> uploadImage(ServerRequest request) {
|
||||
return request.multipartData()
|
||||
.flatMap(multiValueMap -> {
|
||||
List<Part> fileParts = multiValueMap.get("file");
|
||||
if (fileParts == null || fileParts.isEmpty()) {
|
||||
return ServerResponse.badRequest()
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.bodyValue(Map.of("code", 400, "message", "未选择文件"));
|
||||
}
|
||||
|
||||
Part part = fileParts.get(0);
|
||||
if (!(part instanceof FilePart filePart)) {
|
||||
return ServerResponse.badRequest()
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.bodyValue(Map.of("code", 400, "message", "文件格式不正确"));
|
||||
}
|
||||
|
||||
String originalFilename = filePart.filename();
|
||||
String ext = "";
|
||||
int dotIndex = originalFilename.lastIndexOf('.');
|
||||
if (dotIndex > 0) {
|
||||
ext = originalFilename.substring(dotIndex);
|
||||
}
|
||||
String newFileName = UUID.randomUUID().toString().replace("-", "") + ext;
|
||||
|
||||
Path tempFile = null;
|
||||
try {
|
||||
tempFile = Files.createTempFile("upload-", newFileName);
|
||||
} catch (Exception e) {
|
||||
return Mono.error(new RuntimeException("创建临时文件失败", e));
|
||||
}
|
||||
Path finalTempFile = tempFile;
|
||||
|
||||
return filePart.transferTo(finalTempFile)
|
||||
.then(Mono.defer(() -> {
|
||||
try {
|
||||
String ossKey;
|
||||
try (InputStream inputStream = Files.newInputStream(finalTempFile)) {
|
||||
ossKey = OSSUtil.uploadCoverToOSS(inputStream, newFileName);
|
||||
}
|
||||
String presignedUrl = OSSUtil.generatePresignedUrl(ossKey);
|
||||
return ServerResponse.ok()
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.bodyValue(Map.of(
|
||||
"code", 200,
|
||||
"message", "上传成功",
|
||||
"data", Map.of(
|
||||
"ossKey", ossKey,
|
||||
"presignedUrl", presignedUrl,
|
||||
"fileName", originalFilename
|
||||
)
|
||||
));
|
||||
} catch (Exception e) {
|
||||
return ServerResponse.status(500)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.bodyValue(Map.of("code", 500, "message", "上传失败: " + e.getMessage()));
|
||||
} finally {
|
||||
try {
|
||||
Files.deleteIfExists(finalTempFile);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "获取OSS预签名URL", description = "根据ossKey生成临时访问URL,有效期5分钟")
|
||||
public Mono<ServerResponse> presignUrl(ServerRequest request) {
|
||||
String ossKey = request.queryParam("key").orElse(null);
|
||||
if (ossKey == null || ossKey.isBlank()) {
|
||||
return ServerResponse.badRequest()
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.bodyValue(Map.of("code", 400, "message", "参数 key 不能为空"));
|
||||
}
|
||||
|
||||
try {
|
||||
String presignedUrl = OSSUtil.generatePresignedUrl(ossKey);
|
||||
return ServerResponse.ok()
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.bodyValue(Map.of(
|
||||
"code", 200,
|
||||
"data", Map.of("presignedUrl", presignedUrl)
|
||||
));
|
||||
} catch (Exception e) {
|
||||
return ServerResponse.status(500)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.bodyValue(Map.of("code", 500, "message", "生成预签名URL失败: " + e.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
-13
@@ -1,5 +1,6 @@
|
||||
package cn.novalon.gym.manage.groupcourse.handler;
|
||||
|
||||
import cn.novalon.gym.manage.common.dto.PageRequest;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.CourseLabel;
|
||||
import cn.novalon.gym.manage.groupcourse.service.ICourseLabelService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@@ -29,6 +30,13 @@ public class CourseLabelHandler {
|
||||
.body(courseLabelService.findAll(), CourseLabel.class);
|
||||
}
|
||||
|
||||
@Operation(summary = "分页查询标签", description = "支持按关键词筛选并分页查询标签")
|
||||
public Mono<ServerResponse> getLabelsByPage(ServerRequest request) {
|
||||
return request.bodyToMono(PageRequest.class)
|
||||
.flatMap(pageRequest -> courseLabelService.findByPage(pageRequest)
|
||||
.flatMap(response -> ServerResponse.ok().bodyValue(response)));
|
||||
}
|
||||
|
||||
@Operation(summary = "根据ID获取标签", description = "根据ID获取标签详情")
|
||||
public Mono<ServerResponse> getLabelById(ServerRequest request) {
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
@@ -146,24 +154,17 @@ public class CourseLabelHandler {
|
||||
|
||||
return request.bodyToMono(Map.class)
|
||||
.flatMap(body -> {
|
||||
Object labelIdsObj = body.get("labelIds");
|
||||
|
||||
if (!(labelIdsObj instanceof List)) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<?> rawIds = (List<?>) body.get("labelIds");
|
||||
|
||||
if (rawIds == null || rawIds.isEmpty()) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "labelIds不能为空");
|
||||
return ServerResponse.badRequest().bodyValue(error);
|
||||
}
|
||||
|
||||
List<?> rawList = (List<?>) labelIdsObj;
|
||||
if (rawList.isEmpty()) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "labelIds不能为空");
|
||||
return ServerResponse.badRequest().bodyValue(error);
|
||||
}
|
||||
|
||||
List<Long> labelIds = rawList.stream()
|
||||
|
||||
List<Long> labelIds = rawIds.stream()
|
||||
.map(id -> Long.valueOf(String.valueOf(id)))
|
||||
.collect(java.util.stream.Collectors.toList());
|
||||
|
||||
|
||||
+27
-84
@@ -2,7 +2,6 @@ package cn.novalon.gym.manage.groupcourse.handler;
|
||||
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourseBooking;
|
||||
import cn.novalon.gym.manage.groupcourse.service.IGroupCourseBookingService;
|
||||
import cn.novalon.gym.manage.member.service.IMemberStoredCardService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -24,12 +23,9 @@ import java.util.Map;
|
||||
public class GroupCourseBookingHandler {
|
||||
|
||||
private final IGroupCourseBookingService bookingService;
|
||||
private final IMemberStoredCardService memberStoredCardService;
|
||||
|
||||
public GroupCourseBookingHandler(IGroupCourseBookingService bookingService,
|
||||
IMemberStoredCardService memberStoredCardService) {
|
||||
public GroupCourseBookingHandler(IGroupCourseBookingService bookingService) {
|
||||
this.bookingService = bookingService;
|
||||
this.memberStoredCardService = memberStoredCardService;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,38 +42,23 @@ public class GroupCourseBookingHandler {
|
||||
if (body.get("memberId") == null) {
|
||||
return buildErrorResponse("请提供会员ID");
|
||||
}
|
||||
if (body.get("memberCardRecordId") == null) {
|
||||
return buildErrorResponse("请提供会员卡记录ID");
|
||||
}
|
||||
if (body.get("payPassword") == null || body.get("payPassword").toString().isEmpty()) {
|
||||
return buildErrorResponse("请输入支付密码");
|
||||
}
|
||||
|
||||
Long courseId = toLong(body.get("courseId"), "courseId");
|
||||
Long memberId = toLong(body.get("memberId"), "memberId");
|
||||
Long memberCardRecordId = toLong(body.get("memberCardRecordId"), "memberCardRecordId");
|
||||
String payPassword = body.get("payPassword").toString();
|
||||
|
||||
// 验证支付密码
|
||||
return memberStoredCardService.verifyPayPassword(memberId, payPassword)
|
||||
.flatMap(passwordValid -> {
|
||||
if (!passwordValid) {
|
||||
return buildErrorResponse("支付密码错误");
|
||||
}
|
||||
return bookingService.bookCourse(courseId, memberId, memberCardRecordId)
|
||||
.flatMap(booking -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "预约成功");
|
||||
response.put("data", booking);
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
});
|
||||
return bookingService.bookCourse(courseId, memberId)
|
||||
.flatMap(booking -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "预约成功");
|
||||
response.put("data", booking);
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -92,31 +73,20 @@ public class GroupCourseBookingHandler {
|
||||
return request.bodyToMono(Map.class)
|
||||
.flatMap(body -> {
|
||||
Long memberId = toLong(body.get("memberId"), "memberId");
|
||||
if (body.get("payPassword") == null || body.get("payPassword").toString().isEmpty()) {
|
||||
return buildErrorResponse("请输入支付密码");
|
||||
}
|
||||
String payPassword = body.get("payPassword").toString();
|
||||
|
||||
// 验证支付密码
|
||||
return memberStoredCardService.verifyPayPassword(memberId, payPassword)
|
||||
.flatMap(passwordValid -> {
|
||||
if (!passwordValid) {
|
||||
return buildErrorResponse("支付密码错误");
|
||||
}
|
||||
return bookingService.cancelBooking(bookingId, memberId)
|
||||
.flatMap(booking -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "取消成功");
|
||||
response.put("data", booking);
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
});
|
||||
return bookingService.cancelBooking(bookingId, memberId)
|
||||
.flatMap(booking -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "取消成功");
|
||||
response.put("data", booking);
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -177,31 +147,4 @@ public class GroupCourseBookingHandler {
|
||||
response.put("message", message);
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫码签到(二维码扫一扫签到)
|
||||
* 用户扫描团课签到二维码后,更新预约记录状态为 2(已出席)
|
||||
*/
|
||||
@Operation(summary = "扫码签到", description = "用户扫描团课二维码签到,更新预约状态为已出席")
|
||||
public Mono<ServerResponse> qrSignIn(ServerRequest request) {
|
||||
Long courseId = Long.valueOf(request.pathVariable("courseId"));
|
||||
|
||||
return request.bodyToMono(Map.class)
|
||||
.flatMap(body -> {
|
||||
if (body.get("memberId") == null) {
|
||||
return buildErrorResponse("请提供会员ID");
|
||||
}
|
||||
Long memberId = toLong(body.get("memberId"), "memberId");
|
||||
|
||||
return bookingService.qrSignIn(courseId, memberId)
|
||||
.flatMap(booking -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "签到成功");
|
||||
response.put("data", booking);
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
})
|
||||
.onErrorResume(error -> buildErrorResponse(error.getMessage()));
|
||||
});
|
||||
}
|
||||
}
|
||||
+32
-162
@@ -7,25 +7,15 @@ import cn.novalon.gym.manage.groupcourse.domain.GroupCourse;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourseDetail;
|
||||
import cn.novalon.gym.manage.groupcourse.dto.GroupCourseQueryDto;
|
||||
import cn.novalon.gym.manage.groupcourse.service.IGroupCourseService;
|
||||
import cn.novalon.gym.manage.sys.core.service.ISysUserService;
|
||||
import cn.novalon.gym.manage.sys.util.AuthUtil;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.client.j2se.MatrixToImageWriter;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.qrcode.QRCodeWriter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Validator;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -36,21 +26,15 @@ public class GroupCourseHandler {
|
||||
private final Validator validator;
|
||||
private final RedisUtil redisUtil;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final ISysUserService sysUserService;
|
||||
private final AuthUtil authUtil;
|
||||
|
||||
public GroupCourseHandler(IGroupCourseService groupCourseService,
|
||||
Validator validator,
|
||||
RedisUtil redisUtil,
|
||||
ObjectMapper objectMapper,
|
||||
ISysUserService sysUserService,
|
||||
AuthUtil authUtil){
|
||||
ObjectMapper objectMapper){
|
||||
this.groupCourseService = groupCourseService;
|
||||
this.validator = validator;
|
||||
this.redisUtil = redisUtil;
|
||||
this.objectMapper = objectMapper;
|
||||
this.sysUserService = sysUserService;
|
||||
this.authUtil = authUtil;
|
||||
}
|
||||
|
||||
@Operation(summary = "获取所有团课", description = "获取系统中所有团课列表")
|
||||
@@ -130,43 +114,25 @@ public class GroupCourseHandler {
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "更新团课", description = "更新指定团课信息,需验证管理员密码")
|
||||
@Operation(summary = "更新团课", description = "更新指定团课信息")
|
||||
public Mono<ServerResponse> updateGroupCourse(ServerRequest request) {
|
||||
Long adminId = authUtil.getMemberIdOrThrow(request);
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
String adminPassword = request.queryParam("adminPassword").orElse(null);
|
||||
|
||||
if (adminPassword == null || adminPassword.isBlank()) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "管理员密码不能为空");
|
||||
return ServerResponse.badRequest().bodyValue(error);
|
||||
}
|
||||
|
||||
return sysUserService.verifyPassword(adminId, adminPassword)
|
||||
.flatMap(valid -> {
|
||||
if (!valid) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "管理员密码错误");
|
||||
return ServerResponse.status(HttpStatus.FORBIDDEN).bodyValue(error);
|
||||
}
|
||||
return request.bodyToMono(GroupCourse.class)
|
||||
.flatMap(groupCourse -> {
|
||||
return groupCourseService.update(id, groupCourse)
|
||||
.flatMap(course -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "团课更新成功");
|
||||
response.put("data", course);
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
});
|
||||
|
||||
return request.bodyToMono(GroupCourse.class)
|
||||
.flatMap(groupCourse -> {
|
||||
return groupCourseService.update(id, groupCourse)
|
||||
.flatMap(course -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "团课更新成功");
|
||||
response.put("data", course);
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -231,78 +197,22 @@ public class GroupCourseHandler {
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "删除团课", description = "删除指定团课(软删除),需验证管理员密码")
|
||||
@Operation(summary = "删除团课", description = "删除指定团课(软删除)")
|
||||
public Mono<ServerResponse> deleteGroupCourse(ServerRequest request) {
|
||||
Long adminId = authUtil.getMemberIdOrThrow(request);
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
String adminPassword = request.queryParam("adminPassword").orElse(null);
|
||||
|
||||
if (adminPassword == null || adminPassword.isBlank()) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "管理员密码不能为空");
|
||||
return ServerResponse.badRequest().bodyValue(error);
|
||||
}
|
||||
|
||||
return sysUserService.verifyPassword(adminId, adminPassword)
|
||||
.flatMap(valid -> {
|
||||
if (!valid) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "管理员密码错误");
|
||||
return ServerResponse.status(HttpStatus.FORBIDDEN).bodyValue(error);
|
||||
}
|
||||
return groupCourseService.delete(id)
|
||||
.then(Mono.defer(() -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "团课删除成功");
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
}))
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "恢复已删除团课", description = "将已删除的团课恢复为已取消状态,需验证管理员密码")
|
||||
public Mono<ServerResponse> restoreGroupCourse(ServerRequest request) {
|
||||
Long adminId = authUtil.getMemberIdOrThrow(request);
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
String adminPassword = request.queryParam("adminPassword").orElse(null);
|
||||
|
||||
if (adminPassword == null || adminPassword.isBlank()) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "管理员密码不能为空");
|
||||
return ServerResponse.badRequest().bodyValue(error);
|
||||
}
|
||||
|
||||
return sysUserService.verifyPassword(adminId, adminPassword)
|
||||
.flatMap(valid -> {
|
||||
if (!valid) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "管理员密码错误");
|
||||
return ServerResponse.status(HttpStatus.FORBIDDEN).bodyValue(error);
|
||||
}
|
||||
return groupCourseService.restore(id)
|
||||
.flatMap(course -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "团课恢复成功");
|
||||
response.put("data", course);
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
});
|
||||
|
||||
return groupCourseService.delete(id)
|
||||
.then(Mono.defer(() -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "团课删除成功");
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
}))
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -379,44 +289,4 @@ public class GroupCourseHandler {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "获取团课签到二维码", description = "根据团课ID生成签到二维码(base64)")
|
||||
public Mono<ServerResponse> getCourseQRCode(ServerRequest request) {
|
||||
Long courseId = Long.valueOf(request.pathVariable("id"));
|
||||
|
||||
return groupCourseService.findById(courseId)
|
||||
.flatMap(course -> {
|
||||
return Mono.fromCallable(() -> {
|
||||
String qrContent = "{\"courseId\":" + course.getId()
|
||||
+ ",\"courseName\":\"" + escapeJson(course.getCourseName()) + "\"}";
|
||||
|
||||
QRCodeWriter qrCodeWriter = new QRCodeWriter();
|
||||
BitMatrix bitMatrix = qrCodeWriter.encode(qrContent, BarcodeFormat.QR_CODE, 300, 300);
|
||||
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
MatrixToImageWriter.writeToStream(bitMatrix, "PNG", outputStream);
|
||||
byte[] pngBytes = outputStream.toByteArray();
|
||||
String base64 = Base64.getEncoder().encodeToString(pngBytes);
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("base64", "data:image/png;base64," + base64);
|
||||
result.put("courseId", course.getId());
|
||||
result.put("courseName", course.getCourseName());
|
||||
result.put("width", 300);
|
||||
result.put("height", 300);
|
||||
return result;
|
||||
}).subscribeOn(reactor.core.scheduler.Schedulers.boundedElastic());
|
||||
})
|
||||
.flatMap(result -> ServerResponse.ok().bodyValue(result))
|
||||
.switchIfEmpty(ServerResponse.notFound().build());
|
||||
}
|
||||
|
||||
private String escapeJson(String s) {
|
||||
if (s == null) return "";
|
||||
return s.replace("\\", "\\\\")
|
||||
.replace("\"", "\\\"")
|
||||
.replace("\n", "\\n")
|
||||
.replace("\r", "\\r")
|
||||
.replace("\t", "\\t");
|
||||
}
|
||||
}
|
||||
|
||||
+42
-103
@@ -2,11 +2,8 @@ package cn.novalon.gym.manage.groupcourse.handler;
|
||||
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourseRecommend;
|
||||
import cn.novalon.gym.manage.groupcourse.service.IGroupCourseRecommendService;
|
||||
import cn.novalon.gym.manage.sys.core.service.ISysUserService;
|
||||
import cn.novalon.gym.manage.sys.util.AuthUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
@@ -20,15 +17,9 @@ import java.util.Map;
|
||||
public class GroupCourseRecommendHandler {
|
||||
|
||||
private final IGroupCourseRecommendService recommendService;
|
||||
private final ISysUserService sysUserService;
|
||||
private final AuthUtil authUtil;
|
||||
|
||||
public GroupCourseRecommendHandler(IGroupCourseRecommendService recommendService,
|
||||
ISysUserService sysUserService,
|
||||
AuthUtil authUtil) {
|
||||
public GroupCourseRecommendHandler(IGroupCourseRecommendService recommendService) {
|
||||
this.recommendService = recommendService;
|
||||
this.sysUserService = sysUserService;
|
||||
this.authUtil = authUtil;
|
||||
}
|
||||
|
||||
@Operation(summary = "获取所有团课推荐", description = "获取系统中所有团课推荐列表,支持按优先级排序")
|
||||
@@ -89,73 +80,20 @@ public class GroupCourseRecommendHandler {
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "更新团课推荐", description = "更新指定团课推荐信息,需验证管理员密码")
|
||||
@Operation(summary = "更新团课推荐", description = "更新指定团课推荐信息")
|
||||
public Mono<ServerResponse> updateRecommendation(ServerRequest request) {
|
||||
Long adminId = authUtil.getMemberIdOrThrow(request);
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
String adminPassword = request.queryParam("adminPassword").orElse(null);
|
||||
|
||||
if (adminPassword == null || adminPassword.isBlank()) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "管理员密码不能为空");
|
||||
return ServerResponse.badRequest().bodyValue(error);
|
||||
}
|
||||
|
||||
return sysUserService.verifyPassword(adminId, adminPassword)
|
||||
.flatMap(valid -> {
|
||||
if (!valid) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "管理员密码错误");
|
||||
return ServerResponse.status(HttpStatus.FORBIDDEN).bodyValue(error);
|
||||
}
|
||||
return request.bodyToMono(GroupCourseRecommend.class)
|
||||
.flatMap(recommend -> recommendService.update(id, recommend)
|
||||
.flatMap(r -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "团课推荐更新成功");
|
||||
response.put("data", r);
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "删除团课推荐", description = "删除指定团课推荐(软删除),需验证管理员密码")
|
||||
public Mono<ServerResponse> deleteRecommendation(ServerRequest request) {
|
||||
Long adminId = authUtil.getMemberIdOrThrow(request);
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
String adminPassword = request.queryParam("adminPassword").orElse(null);
|
||||
|
||||
if (adminPassword == null || adminPassword.isBlank()) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "管理员密码不能为空");
|
||||
return ServerResponse.badRequest().bodyValue(error);
|
||||
}
|
||||
|
||||
return sysUserService.verifyPassword(adminId, adminPassword)
|
||||
.flatMap(valid -> {
|
||||
if (!valid) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "管理员密码错误");
|
||||
return ServerResponse.status(HttpStatus.FORBIDDEN).bodyValue(error);
|
||||
}
|
||||
return recommendService.delete(id)
|
||||
.then(Mono.defer(() -> {
|
||||
return request.bodyToMono(GroupCourseRecommend.class)
|
||||
.flatMap(recommend -> {
|
||||
return recommendService.update(id, recommend)
|
||||
.flatMap(r -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "团课推荐删除成功");
|
||||
response.put("message", "团课推荐更新成功");
|
||||
response.put("data", r);
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
}))
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
@@ -165,6 +103,25 @@ public class GroupCourseRecommendHandler {
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "删除团课推荐", description = "删除指定团课推荐(软删除)")
|
||||
public Mono<ServerResponse> deleteRecommendation(ServerRequest request) {
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
|
||||
return recommendService.delete(id)
|
||||
.then(Mono.defer(() -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "团课推荐删除成功");
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
}))
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "启用团课推荐", description = "启用指定团课推荐")
|
||||
public Mono<ServerResponse> enableRecommendation(ServerRequest request) {
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
@@ -185,41 +142,23 @@ public class GroupCourseRecommendHandler {
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "禁用团课推荐", description = "禁用指定团课推荐,需验证管理员密码")
|
||||
@Operation(summary = "禁用团课推荐", description = "禁用指定团课推荐")
|
||||
public Mono<ServerResponse> disableRecommendation(ServerRequest request) {
|
||||
Long adminId = authUtil.getMemberIdOrThrow(request);
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
String adminPassword = request.queryParam("adminPassword").orElse(null);
|
||||
|
||||
if (adminPassword == null || adminPassword.isBlank()) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "管理员密码不能为空");
|
||||
return ServerResponse.badRequest().bodyValue(error);
|
||||
}
|
||||
|
||||
return sysUserService.verifyPassword(adminId, adminPassword)
|
||||
.flatMap(valid -> {
|
||||
if (!valid) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "管理员密码错误");
|
||||
return ServerResponse.status(HttpStatus.FORBIDDEN).bodyValue(error);
|
||||
}
|
||||
return recommendService.disable(id)
|
||||
.flatMap(r -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "团课推荐禁用成功");
|
||||
response.put("data", r);
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
});
|
||||
return recommendService.disable(id)
|
||||
.flatMap(r -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "团课推荐禁用成功");
|
||||
response.put("data", r);
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
});
|
||||
}
|
||||
}
|
||||
+40
-76
@@ -1,12 +1,10 @@
|
||||
package cn.novalon.gym.manage.groupcourse.handler;
|
||||
|
||||
import cn.novalon.gym.manage.common.dto.PageRequest;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourseType;
|
||||
import cn.novalon.gym.manage.groupcourse.service.IGroupCourseTypeService;
|
||||
import cn.novalon.gym.manage.sys.core.service.ISysUserService;
|
||||
import cn.novalon.gym.manage.sys.util.AuthUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
@@ -20,15 +18,9 @@ import java.util.Map;
|
||||
public class GroupCourseTypeHandler {
|
||||
|
||||
private final IGroupCourseTypeService groupCourseTypeService;
|
||||
private final ISysUserService sysUserService;
|
||||
private final AuthUtil authUtil;
|
||||
|
||||
public GroupCourseTypeHandler(IGroupCourseTypeService groupCourseTypeService,
|
||||
ISysUserService sysUserService,
|
||||
AuthUtil authUtil) {
|
||||
public GroupCourseTypeHandler(IGroupCourseTypeService groupCourseTypeService) {
|
||||
this.groupCourseTypeService = groupCourseTypeService;
|
||||
this.sysUserService = sysUserService;
|
||||
this.authUtil = authUtil;
|
||||
}
|
||||
|
||||
@Operation(summary = "获取所有团课类型", description = "获取系统中所有团课类型列表")
|
||||
@@ -101,76 +93,21 @@ public class GroupCourseTypeHandler {
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "更新团课类型", description = "更新指定团课类型信息,需验证管理员密码")
|
||||
@Operation(summary = "更新团课类型", description = "更新指定团课类型信息")
|
||||
public Mono<ServerResponse> updateGroupCourseType(ServerRequest request) {
|
||||
Long adminId = authUtil.getMemberIdOrThrow(request);
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
String adminPassword = request.queryParam("adminPassword").orElse(null);
|
||||
|
||||
if (adminPassword == null || adminPassword.isBlank()) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "管理员密码不能为空");
|
||||
return ServerResponse.badRequest().bodyValue(error);
|
||||
}
|
||||
|
||||
return sysUserService.verifyPassword(adminId, adminPassword)
|
||||
.flatMap(valid -> {
|
||||
if (!valid) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "管理员密码错误");
|
||||
return ServerResponse.status(HttpStatus.FORBIDDEN).bodyValue(error);
|
||||
}
|
||||
return request.bodyToMono(GroupCourseType.class)
|
||||
.flatMap(groupCourseType -> {
|
||||
groupCourseType.setId(id);
|
||||
return groupCourseTypeService.update(id, groupCourseType)
|
||||
.flatMap(type -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "团课类型更新成功");
|
||||
response.put("data", type);
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "删除团课类型", description = "删除指定团课类型(软删除),需验证管理员密码,且该类型不能被任何团课引用")
|
||||
public Mono<ServerResponse> deleteGroupCourseType(ServerRequest request) {
|
||||
Long adminId = authUtil.getMemberIdOrThrow(request);
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
String adminPassword = request.queryParam("adminPassword").orElse(null);
|
||||
|
||||
if (adminPassword == null || adminPassword.isBlank()) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "管理员密码不能为空");
|
||||
return ServerResponse.badRequest().bodyValue(error);
|
||||
}
|
||||
|
||||
return sysUserService.verifyPassword(adminId, adminPassword)
|
||||
.flatMap(valid -> {
|
||||
if (!valid) {
|
||||
Map<String, Object> error = new HashMap<>();
|
||||
error.put("success", false);
|
||||
error.put("message", "管理员密码错误");
|
||||
return ServerResponse.status(HttpStatus.FORBIDDEN).bodyValue(error);
|
||||
}
|
||||
return groupCourseTypeService.delete(id)
|
||||
.then(Mono.defer(() -> {
|
||||
|
||||
return request.bodyToMono(GroupCourseType.class)
|
||||
.flatMap(groupCourseType -> {
|
||||
groupCourseType.setId(id);
|
||||
return groupCourseTypeService.update(id, groupCourseType)
|
||||
.flatMap(type -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "团课类型删除成功");
|
||||
response.put("message", "团课类型更新成功");
|
||||
response.put("data", type);
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
}))
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
@@ -179,4 +116,31 @@ public class GroupCourseTypeHandler {
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "删除团课类型", description = "删除指定团课类型(软删除)")
|
||||
public Mono<ServerResponse> deleteGroupCourseType(ServerRequest request) {
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
|
||||
return groupCourseTypeService.delete(id)
|
||||
.then(Mono.defer(() -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", true);
|
||||
response.put("message", "团课类型删除成功");
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
}))
|
||||
.onErrorResume(error -> {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("success", false);
|
||||
response.put("message", error.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(response);
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "分页查询团课类型", description = "支持按关键词、分类筛选并分页查询团课类型")
|
||||
public Mono<ServerResponse> getGroupCourseTypesByPage(ServerRequest request) {
|
||||
return request.bodyToMono(PageRequest.class)
|
||||
.flatMap(pageRequest -> groupCourseTypeService.findByPage(pageRequest)
|
||||
.flatMap(response -> ServerResponse.ok().bodyValue(response))
|
||||
);
|
||||
}
|
||||
}
|
||||
+22
-19
@@ -1,5 +1,6 @@
|
||||
package cn.novalon.gym.manage.groupcourse.initializer;
|
||||
|
||||
import cn.novalon.gym.manage.file.core.service.ISysFileService;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourse;
|
||||
import cn.novalon.gym.manage.groupcourse.repository.IGroupCourseRepository;
|
||||
import cn.novalon.gym.manage.groupcourse.util.QRCodeUtil;
|
||||
@@ -10,15 +11,12 @@ import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 项目启动时补全缺失的团课二维码
|
||||
* 遍历所有未删除的团课,对qrCodePath为空的课程生成二维码并上传至阿里云OSS
|
||||
* 遍历所有未删除的团课,对qrCodePath为空的课程生成二维码并通过统一文件服务保存
|
||||
*/
|
||||
@Component
|
||||
public class QrCodeInitializer implements CommandLineRunner {
|
||||
@@ -27,11 +25,14 @@ public class QrCodeInitializer implements CommandLineRunner {
|
||||
|
||||
private final IGroupCourseRepository groupCourseRepository;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final ISysFileService fileService;
|
||||
|
||||
public QrCodeInitializer(IGroupCourseRepository groupCourseRepository,
|
||||
ObjectMapper objectMapper) {
|
||||
ObjectMapper objectMapper,
|
||||
ISysFileService fileService) {
|
||||
this.groupCourseRepository = groupCourseRepository;
|
||||
this.objectMapper = objectMapper;
|
||||
this.fileService = fileService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -58,20 +59,22 @@ public class QrCodeInitializer implements CommandLineRunner {
|
||||
|
||||
String jsonContent = objectMapper.writeValueAsString(qrCodeContent);
|
||||
|
||||
// 生成二维码并上传到阿里云OSS
|
||||
String uuid = UUID.randomUUID().toString().replace("-", "");
|
||||
String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
|
||||
String fileName = "qr_" + uuid + "_" + timestamp + ".png";
|
||||
String ossUrl = QRCodeUtil.generateQRCodeAndUploadToOSS(jsonContent, fileName);
|
||||
|
||||
course.setQrCodePath(ossUrl);
|
||||
|
||||
// 更新数据库
|
||||
return groupCourseRepository.update(course)
|
||||
.doOnSuccess(updated -> logger.info("团课二维码补全成功 - id={}, name={}, ossUrl={}",
|
||||
updated.getId(), updated.getCourseName(), ossUrl))
|
||||
.doOnError(error -> logger.error("团课二维码补全失败(更新DB) - id={}, name={}, error: {}",
|
||||
course.getId(), course.getCourseName(), error.getMessage()));
|
||||
// 生成二维码字节数组,通过统一文件服务保存
|
||||
return Mono.fromCallable(() -> QRCodeUtil.generateQrCodeBytes(jsonContent))
|
||||
.flatMap(qrCodeBytes -> {
|
||||
String fileName = "qrcode_" + course.getId() + ".png";
|
||||
return fileService.saveBytes(qrCodeBytes, fileName, "image/png", "system");
|
||||
})
|
||||
.flatMap(sysFile -> {
|
||||
String qrCodeUrl = "/api/files/" + sysFile.getId() + "/preview";
|
||||
course.setQrCodePath(qrCodeUrl);
|
||||
|
||||
return groupCourseRepository.update(course)
|
||||
.doOnSuccess(updated -> logger.info("团课二维码补全成功 - id={}, name={}, url={}",
|
||||
updated.getId(), updated.getCourseName(), qrCodeUrl))
|
||||
.doOnError(error -> logger.error("团课二维码补全失败(更新DB) - id={}, name={}, error: {}",
|
||||
course.getId(), course.getCourseName(), error.getMessage()));
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.error("团课二维码补全失败(生成) - id={}, name={}, error: {}",
|
||||
course.getId(), course.getCourseName(), e.getMessage(), e);
|
||||
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
package cn.novalon.gym.manage.groupcourse.repository;
|
||||
|
||||
import cn.novalon.gym.manage.groupcourse.domain.Banner;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public interface IBannerRepository {
|
||||
|
||||
Mono<Banner> findById(Long id);
|
||||
|
||||
Flux<Banner> findAll();
|
||||
|
||||
Flux<Banner> findAll(String sortBy, String sortOrder);
|
||||
|
||||
Flux<Banner> findAllActive();
|
||||
|
||||
Mono<Banner> save(Banner banner);
|
||||
|
||||
Mono<Banner> update(Banner banner);
|
||||
|
||||
Mono<Void> deleteById(Long id);
|
||||
|
||||
Mono<Banner> updateActiveStatus(Long id, Boolean isActive);
|
||||
}
|
||||
+4
@@ -1,5 +1,7 @@
|
||||
package cn.novalon.gym.manage.groupcourse.repository;
|
||||
|
||||
import cn.novalon.gym.manage.common.dto.PageRequest;
|
||||
import cn.novalon.gym.manage.common.dto.PageResponse;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.CourseLabel;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -29,4 +31,6 @@ public interface ICourseLabelRepository {
|
||||
Mono<Void> removeLabelFromType(Long typeId, Long labelId);
|
||||
|
||||
Mono<Void> clearLabelsFromType(Long typeId);
|
||||
|
||||
Mono<PageResponse<CourseLabel>> findByPage(PageRequest pageRequest);
|
||||
}
|
||||
-2
@@ -27,8 +27,6 @@ public interface IGroupCourseRepository {
|
||||
|
||||
Mono<Void> deleteById(Long id);
|
||||
|
||||
Mono<GroupCourse> restoreById(Long id);
|
||||
|
||||
Mono<GroupCourse> updateCurrentMembers(Long id, Integer delta);
|
||||
|
||||
Flux<GroupCourse> findByCourseType(Long courseType);
|
||||
|
||||
+4
@@ -1,5 +1,7 @@
|
||||
package cn.novalon.gym.manage.groupcourse.repository;
|
||||
|
||||
import cn.novalon.gym.manage.common.dto.PageRequest;
|
||||
import cn.novalon.gym.manage.common.dto.PageResponse;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourseType;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -25,4 +27,6 @@ public interface IGroupCourseTypeRepository {
|
||||
Mono<GroupCourseType> update(GroupCourseType groupCourseType);
|
||||
|
||||
Mono<Void> deleteById(Long id);
|
||||
|
||||
Mono<PageResponse<GroupCourseType>> findByPage(PageRequest pageRequest);
|
||||
}
|
||||
-113
@@ -1,113 +0,0 @@
|
||||
package cn.novalon.gym.manage.groupcourse.repository.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.novalon.gym.manage.groupcourse.dao.BannerDao;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.Banner;
|
||||
import cn.novalon.gym.manage.groupcourse.entity.BannerEntity;
|
||||
import cn.novalon.gym.manage.groupcourse.repository.IBannerRepository;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Repository
|
||||
public class BannerRepository implements IBannerRepository {
|
||||
|
||||
private final BannerDao bannerDao;
|
||||
private final R2dbcEntityTemplate r2dbcEntityTemplate;
|
||||
|
||||
public BannerRepository(BannerDao bannerDao, R2dbcEntityTemplate r2dbcEntityTemplate) {
|
||||
this.bannerDao = bannerDao;
|
||||
this.r2dbcEntityTemplate = r2dbcEntityTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Banner> findById(Long id) {
|
||||
return bannerDao.findByIdAndDeletedAtIsNull(id)
|
||||
.map(this::toDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Banner> findAll() {
|
||||
return bannerDao.findAllByDeletedAtIsNull()
|
||||
.map(this::toDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Banner> findAll(String sortBy, String sortOrder) {
|
||||
Sort.Direction direction = "asc".equalsIgnoreCase(sortOrder)
|
||||
? Sort.Direction.ASC
|
||||
: Sort.Direction.DESC;
|
||||
Sort sort = Sort.by(direction, sortBy);
|
||||
return bannerDao.findAllByDeletedAtIsNull(sort)
|
||||
.map(this::toDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Banner> findAllActive() {
|
||||
return bannerDao.findByIsActiveTrueAndDeletedAtIsNull(Sort.by(Sort.Direction.DESC, "sortOrder"))
|
||||
.map(this::toDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Banner> save(Banner banner) {
|
||||
BannerEntity entity = toEntity(banner);
|
||||
entity.setCreatedAt(LocalDateTime.now());
|
||||
entity.setUpdatedAt(LocalDateTime.now());
|
||||
if (entity.getSortOrder() == null) {
|
||||
entity.setSortOrder(0);
|
||||
}
|
||||
if (entity.getIsActive() == null) {
|
||||
entity.setIsActive(true);
|
||||
}
|
||||
|
||||
return bannerDao.save(entity)
|
||||
.map(this::toDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Banner> update(Banner banner) {
|
||||
BannerEntity entity = toEntity(banner);
|
||||
entity.setUpdatedAt(LocalDateTime.now());
|
||||
|
||||
return r2dbcEntityTemplate.update(entity)
|
||||
.then(findById(banner.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> deleteById(Long id) {
|
||||
return bannerDao.softDelete(id, LocalDateTime.now())
|
||||
.then();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Banner> updateActiveStatus(Long id, Boolean isActive) {
|
||||
return bannerDao.updateActiveStatus(id, isActive, LocalDateTime.now())
|
||||
.flatMap(updated -> {
|
||||
if (updated > 0) {
|
||||
return findById(id);
|
||||
}
|
||||
return Mono.empty();
|
||||
});
|
||||
}
|
||||
|
||||
private Banner toDomain(BannerEntity entity) {
|
||||
if (entity == null) return null;
|
||||
Banner banner = new Banner();
|
||||
BeanUtil.copyProperties(entity, banner);
|
||||
return banner;
|
||||
}
|
||||
|
||||
private BannerEntity toEntity(Banner domain) {
|
||||
if (domain == null) return null;
|
||||
BannerEntity entity = new BannerEntity();
|
||||
BeanUtil.copyProperties(domain, entity);
|
||||
if (domain.getId() != null) {
|
||||
entity.markNotNew();
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
+47
-1
@@ -1,5 +1,7 @@
|
||||
package cn.novalon.gym.manage.groupcourse.repository.impl;
|
||||
|
||||
import cn.novalon.gym.manage.common.dto.PageRequest;
|
||||
import cn.novalon.gym.manage.common.dto.PageResponse;
|
||||
import cn.novalon.gym.manage.groupcourse.converter.GroupCourseConverter;
|
||||
import cn.novalon.gym.manage.groupcourse.dao.CourseLabelDao;
|
||||
import cn.novalon.gym.manage.groupcourse.dao.CourseTypeLabelDao;
|
||||
@@ -9,12 +11,17 @@ import cn.novalon.gym.manage.groupcourse.entity.CourseTypeLabelEntity;
|
||||
import cn.novalon.gym.manage.groupcourse.repository.ICourseLabelRepository;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
||||
import org.springframework.data.relational.core.query.Criteria;
|
||||
import org.springframework.data.relational.core.query.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
@@ -26,12 +33,14 @@ public class CourseLabelRepository implements ICourseLabelRepository {
|
||||
private final CourseLabelDao courseLabelDao;
|
||||
private final CourseTypeLabelDao courseTypeLabelDao;
|
||||
private final GroupCourseConverter converter;
|
||||
private final R2dbcEntityTemplate r2dbcEntityTemplate;
|
||||
|
||||
public CourseLabelRepository(CourseLabelDao courseLabelDao, CourseTypeLabelDao courseTypeLabelDao,
|
||||
GroupCourseConverter converter) {
|
||||
GroupCourseConverter converter, R2dbcEntityTemplate r2dbcEntityTemplate) {
|
||||
this.courseLabelDao = courseLabelDao;
|
||||
this.courseTypeLabelDao = courseTypeLabelDao;
|
||||
this.converter = converter;
|
||||
this.r2dbcEntityTemplate = r2dbcEntityTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -158,4 +167,41 @@ public class CourseLabelRepository implements ICourseLabelRepository {
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<PageResponse<CourseLabel>> findByPage(PageRequest pageRequest) {
|
||||
int page = pageRequest.getPage();
|
||||
int size = pageRequest.getSize();
|
||||
String sort = pageRequest.getSort();
|
||||
String order = pageRequest.getOrder();
|
||||
String keyword = pageRequest.getKeyword();
|
||||
|
||||
Sort sortObj = Sort.unsorted();
|
||||
if (sort != null && !sort.isEmpty()) {
|
||||
sortObj = Sort.by(Sort.Direction.fromString(order), sort);
|
||||
}
|
||||
|
||||
List<Criteria> criteriaList = new ArrayList<>();
|
||||
criteriaList.add(Criteria.where("deleted_at").isNull());
|
||||
if (keyword != null && !keyword.isEmpty()) {
|
||||
criteriaList.add(Criteria.where("label_name").like("%" + keyword + "%").ignoreCase(true));
|
||||
}
|
||||
|
||||
Criteria criteria = criteriaList.isEmpty() ? Criteria.empty() : Criteria.from(criteriaList);
|
||||
Query query = Query.query(criteria).with(org.springframework.data.domain.PageRequest.of(page, size, sortObj));
|
||||
|
||||
return r2dbcEntityTemplate.select(CourseLabelEntity.class)
|
||||
.matching(query)
|
||||
.all()
|
||||
.collectList()
|
||||
.zipWith(r2dbcEntityTemplate.count(Query.query(criteria), CourseLabelEntity.class))
|
||||
.map(tuple -> {
|
||||
long total = tuple.getT2();
|
||||
int totalPages = (int) Math.ceil((double) total / size);
|
||||
List<CourseLabel> list = tuple.getT1().stream()
|
||||
.map(this::toCourseLabel)
|
||||
.toList();
|
||||
return new PageResponse<>(list, totalPages, total, page, size);
|
||||
});
|
||||
}
|
||||
}
|
||||
+11
-42
@@ -97,37 +97,19 @@ public class GroupCourseRepository implements IGroupCourseRepository {
|
||||
public Mono<PageResponse<GroupCourse>> findByPageAndNotDeleted(PageRequest pageRequest) {
|
||||
int page = pageRequest.getPage();
|
||||
int size = pageRequest.getSize();
|
||||
String sort = pageRequest.getSort();
|
||||
String order = pageRequest.getOrder();
|
||||
|
||||
Sort sortObj = Sort.unsorted();
|
||||
if (sort != null && !sort.isEmpty()) {
|
||||
sortObj = Sort.by(Sort.Direction.fromString(order), sort);
|
||||
}
|
||||
|
||||
org.springframework.data.domain.PageRequest pageable = org.springframework.data.domain.PageRequest.of(page, size, sortObj);
|
||||
|
||||
return groupCourseDao.findAllByDeletedAtIsNull(sortObj)
|
||||
.collectList()
|
||||
.zipWith(groupCourseDao.findAllByDeletedAtIsNull().count())
|
||||
.map(tuple -> {
|
||||
List<GroupCourseEntity> allEntities = tuple.getT1();
|
||||
long total = tuple.getT2();
|
||||
|
||||
int fromIndex = page * size;
|
||||
int toIndex = Math.min(fromIndex + size, allEntities.size());
|
||||
|
||||
List<GroupCourse> courseList;
|
||||
if (fromIndex < allEntities.size()) {
|
||||
courseList = allEntities.subList(fromIndex, toIndex).stream()
|
||||
.map(groupCourseConverter::toDomain)
|
||||
.toList();
|
||||
} else {
|
||||
courseList = List.of();
|
||||
return groupCourseDao.countByPageFiltered(r2dbcEntityTemplate.getDatabaseClient(), pageRequest)
|
||||
.flatMap(total -> {
|
||||
if (total == 0) {
|
||||
return Mono.just(new PageResponse<>(List.of(), 0, 0L, page, size));
|
||||
}
|
||||
|
||||
int totalPages = (int) Math.ceil((double) total / size);
|
||||
return new PageResponse<>(courseList, totalPages, total, page, size);
|
||||
return groupCourseDao.findByPageFiltered(r2dbcEntityTemplate.getDatabaseClient(), pageRequest)
|
||||
.map(groupCourseConverter::toDomain)
|
||||
.collectList()
|
||||
.map(courseList -> {
|
||||
int totalPages = (int) Math.ceil((double) total / size);
|
||||
return new PageResponse<>(courseList, totalPages, total, page, size);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -138,7 +120,6 @@ public class GroupCourseRepository implements IGroupCourseRepository {
|
||||
entity.setUpdatedAt(LocalDateTime.now());
|
||||
entity.setStatus(0L);
|
||||
entity.setCurrentMembers(0);
|
||||
entity.setIsRecurring(groupCourse.getIsRecurring() != null ? groupCourse.getIsRecurring() : false);
|
||||
|
||||
return groupCourseDao.save(entity)
|
||||
.map(groupCourseConverter::toDomain);
|
||||
@@ -148,7 +129,6 @@ public class GroupCourseRepository implements IGroupCourseRepository {
|
||||
public Mono<GroupCourse> update(GroupCourse groupCourse) {
|
||||
GroupCourseEntity entity = groupCourseConverter.toEntity(groupCourse);
|
||||
entity.setUpdatedAt(LocalDateTime.now());
|
||||
entity.setIsRecurring(groupCourse.getIsRecurring() != null ? groupCourse.getIsRecurring() : false);
|
||||
|
||||
return r2dbcEntityTemplate.update(entity)
|
||||
.then(findByIdAndDeletedAtIsNull(groupCourse.getId()));
|
||||
@@ -171,17 +151,6 @@ public class GroupCourseRepository implements IGroupCourseRepository {
|
||||
.then();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<GroupCourse> restoreById(Long id) {
|
||||
return groupCourseDao.restoreCourse(id, LocalDateTime.now())
|
||||
.flatMap(updated -> {
|
||||
if (updated > 0) {
|
||||
return findByIdAndDeletedAtIsNull(id);
|
||||
}
|
||||
return Mono.error(new RuntimeException("团课恢复失败,可能该课程未被删除"));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<GroupCourse> updateCurrentMembers(Long id, Integer delta) {
|
||||
return groupCourseDao.updateCurrentMembers(id, delta, LocalDateTime.now())
|
||||
|
||||
+69
-15
@@ -1,5 +1,7 @@
|
||||
package cn.novalon.gym.manage.groupcourse.repository.impl;
|
||||
|
||||
import cn.novalon.gym.manage.common.dto.PageRequest;
|
||||
import cn.novalon.gym.manage.common.dto.PageResponse;
|
||||
import cn.novalon.gym.manage.groupcourse.converter.GroupCourseConverter;
|
||||
import cn.novalon.gym.manage.groupcourse.dao.GroupCourseTypeDao;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourseType;
|
||||
@@ -7,12 +9,18 @@ import cn.novalon.gym.manage.groupcourse.entity.GroupCourseTypeEntity;
|
||||
import cn.novalon.gym.manage.groupcourse.repository.IGroupCourseTypeRepository;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
||||
import org.springframework.data.relational.core.query.Criteria;
|
||||
import org.springframework.data.relational.core.query.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
@Transactional
|
||||
@@ -22,10 +30,13 @@ public class GroupCourseTypeRepository implements IGroupCourseTypeRepository {
|
||||
|
||||
private final GroupCourseTypeDao groupCourseTypeDao;
|
||||
private final GroupCourseConverter converter;
|
||||
private final R2dbcEntityTemplate r2dbcEntityTemplate;
|
||||
|
||||
public GroupCourseTypeRepository(GroupCourseTypeDao groupCourseTypeDao, GroupCourseConverter converter) {
|
||||
public GroupCourseTypeRepository(GroupCourseTypeDao groupCourseTypeDao, GroupCourseConverter converter,
|
||||
R2dbcEntityTemplate r2dbcEntityTemplate) {
|
||||
this.groupCourseTypeDao = groupCourseTypeDao;
|
||||
this.converter = converter;
|
||||
this.r2dbcEntityTemplate = r2dbcEntityTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -105,20 +116,21 @@ public class GroupCourseTypeRepository implements IGroupCourseTypeRepository {
|
||||
return groupCourseTypeDao.findByIdIsAndDeletedAtIsNull(groupCourseType.getId())
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("团课类型不存在")))
|
||||
.flatMap(existing -> {
|
||||
String typeName = groupCourseType.getTypeName() != null
|
||||
? groupCourseType.getTypeName() : existing.getTypeName();
|
||||
Integer baseDifficulty = groupCourseType.getBaseDifficulty() != null
|
||||
? groupCourseType.getBaseDifficulty() : existing.getBaseDifficulty();
|
||||
String description = groupCourseType.getDescription() != null
|
||||
? groupCourseType.getDescription() : existing.getDescription();
|
||||
String category = groupCourseType.getCategory() != null
|
||||
? groupCourseType.getCategory() : existing.getCategory();
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
return groupCourseTypeDao.updateFields(
|
||||
groupCourseType.getId(), typeName, baseDifficulty,
|
||||
description, category, now)
|
||||
.then(groupCourseTypeDao.findByIdIsAndDeletedAtIsNull(groupCourseType.getId()));
|
||||
existing.markNotNew();
|
||||
if (groupCourseType.getTypeName() != null) {
|
||||
existing.setTypeName(groupCourseType.getTypeName());
|
||||
}
|
||||
if (groupCourseType.getBaseDifficulty() != null) {
|
||||
existing.setBaseDifficulty(groupCourseType.getBaseDifficulty());
|
||||
}
|
||||
if (groupCourseType.getDescription() != null) {
|
||||
existing.setDescription(groupCourseType.getDescription());
|
||||
}
|
||||
if (groupCourseType.getCategory() != null) {
|
||||
existing.setCategory(groupCourseType.getCategory());
|
||||
}
|
||||
existing.setUpdatedAt(LocalDateTime.now());
|
||||
return groupCourseTypeDao.save(existing);
|
||||
})
|
||||
.map(converter::toGroupCourseType);
|
||||
}
|
||||
@@ -128,4 +140,46 @@ public class GroupCourseTypeRepository implements IGroupCourseTypeRepository {
|
||||
return groupCourseTypeDao.softDelete(id, LocalDateTime.now())
|
||||
.then();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<PageResponse<GroupCourseType>> findByPage(PageRequest pageRequest) {
|
||||
int page = pageRequest.getPage();
|
||||
int size = pageRequest.getSize();
|
||||
String order = pageRequest.getOrder();
|
||||
String sort = pageRequest.getSort();
|
||||
String keyword = pageRequest.getKeyword();
|
||||
String category = pageRequest.getCategory();
|
||||
|
||||
Sort sortObj = Sort.unsorted();
|
||||
if (sort != null && !sort.isEmpty()) {
|
||||
sortObj = Sort.by(Sort.Direction.fromString(order), sort);
|
||||
}
|
||||
|
||||
// Build dynamic criteria
|
||||
List<Criteria> criteriaList = new ArrayList<>();
|
||||
criteriaList.add(Criteria.where("deleted_at").isNull());
|
||||
if (keyword != null && !keyword.isEmpty()) {
|
||||
criteriaList.add(Criteria.where("type_name").like("%" + keyword + "%").ignoreCase(true));
|
||||
}
|
||||
if (category != null && !category.isEmpty()) {
|
||||
criteriaList.add(Criteria.where("category").is(category));
|
||||
}
|
||||
|
||||
Criteria criteria = criteriaList.isEmpty() ? Criteria.empty() : Criteria.from(criteriaList);
|
||||
Query query = Query.query(criteria).with(org.springframework.data.domain.PageRequest.of(page, size, sortObj));
|
||||
|
||||
return r2dbcEntityTemplate.select(GroupCourseTypeEntity.class)
|
||||
.matching(query)
|
||||
.all()
|
||||
.collectList()
|
||||
.zipWith(r2dbcEntityTemplate.count(Query.query(criteria), GroupCourseTypeEntity.class))
|
||||
.map(tuple -> {
|
||||
long total = tuple.getT2();
|
||||
int totalPages = (int) Math.ceil((double) total / size);
|
||||
List<GroupCourseType> list = tuple.getT1().stream()
|
||||
.map(converter::toGroupCourseType)
|
||||
.toList();
|
||||
return new PageResponse<>(list, totalPages, total, page, size);
|
||||
});
|
||||
}
|
||||
}
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
package cn.novalon.gym.manage.groupcourse.scheduler;
|
||||
|
||||
import cn.novalon.gym.manage.groupcourse.dao.GroupCourseDao;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 常态化团课自动续期定时任务
|
||||
*
|
||||
* 功能:定期检查已结束的常态化团课(is_recurring = TRUE 且 status = '2'),
|
||||
* 自动重置状态为正常(status = '0'),并将课程时间推迟一周,重新开始。
|
||||
*
|
||||
* @date 2026-06-29
|
||||
*/
|
||||
@Component
|
||||
public class GroupCourseRecurringScheduler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GroupCourseRecurringScheduler.class);
|
||||
|
||||
private final GroupCourseDao groupCourseDao;
|
||||
|
||||
public GroupCourseRecurringScheduler(GroupCourseDao groupCourseDao) {
|
||||
this.groupCourseDao = groupCourseDao;
|
||||
}
|
||||
|
||||
/**
|
||||
* 每分钟检查一次,将已结束的常态化团课重置为正常状态,
|
||||
* 并将上课时间/下课时间各推迟一周
|
||||
*/
|
||||
@Scheduled(fixedRate = 60000)
|
||||
public void renewRecurringCourses() {
|
||||
logger.debug("定时任务开始检查常态化团课,续期已结束的课程");
|
||||
|
||||
groupCourseDao.renewRecurringCourses(LocalDateTime.now())
|
||||
.subscribe(
|
||||
count -> {
|
||||
if (count > 0) {
|
||||
logger.info("常态化团课续期完成,更新了 {} 条课程", count);
|
||||
}
|
||||
},
|
||||
error -> logger.error("常态化团课续期定时任务执行失败:{}", error.getMessage(), error)
|
||||
);
|
||||
}
|
||||
}
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
package cn.novalon.gym.manage.groupcourse.service;
|
||||
|
||||
import cn.novalon.gym.manage.groupcourse.domain.Banner;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public interface IBannerService {
|
||||
|
||||
Mono<Banner> findById(Long id);
|
||||
|
||||
Flux<Banner> findAll();
|
||||
|
||||
Flux<Banner> findAll(String sortBy, String sortOrder);
|
||||
|
||||
Flux<Banner> findAllActive();
|
||||
|
||||
Mono<Banner> create(Banner banner);
|
||||
|
||||
Mono<Banner> update(Long id, Banner banner);
|
||||
|
||||
Mono<Void> delete(Long id);
|
||||
|
||||
Mono<Banner> enable(Long id);
|
||||
|
||||
Mono<Banner> disable(Long id);
|
||||
}
|
||||
+4
@@ -1,5 +1,7 @@
|
||||
package cn.novalon.gym.manage.groupcourse.service;
|
||||
|
||||
import cn.novalon.gym.manage.common.dto.PageRequest;
|
||||
import cn.novalon.gym.manage.common.dto.PageResponse;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.CourseLabel;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -27,4 +29,6 @@ public interface ICourseLabelService {
|
||||
Mono<Void> removeLabelFromType(Long typeId, Long labelId);
|
||||
|
||||
Mono<Void> clearLabelsFromType(Long typeId);
|
||||
|
||||
Mono<PageResponse<CourseLabel>> findByPage(PageRequest pageRequest);
|
||||
}
|
||||
+1
-12
@@ -17,10 +17,9 @@ public interface IGroupCourseBookingService {
|
||||
*
|
||||
* @param courseId 团课ID
|
||||
* @param memberId 会员ID
|
||||
* @param memberCardRecordId 会员卡记录ID
|
||||
* @return 预约记录
|
||||
*/
|
||||
Mono<GroupCourseBooking> bookCourse(Long courseId, Long memberId, Long memberCardRecordId);
|
||||
Mono<GroupCourseBooking> bookCourse(Long courseId, Long memberId);
|
||||
|
||||
/**
|
||||
* 取消预约
|
||||
@@ -62,14 +61,4 @@ public interface IGroupCourseBookingService {
|
||||
* @return 处理的记录数
|
||||
*/
|
||||
Mono<Integer> processAbsentMembers();
|
||||
|
||||
/**
|
||||
* 扫码签到
|
||||
* 用户扫描团课二维码签到,将预约状态更新为已出席(2)
|
||||
*
|
||||
* @param courseId 团课ID
|
||||
* @param memberId 会员ID
|
||||
* @return 更新后的预约记录
|
||||
*/
|
||||
Mono<GroupCourseBooking> qrSignIn(Long courseId, Long memberId);
|
||||
}
|
||||
-2
@@ -26,8 +26,6 @@ public interface IGroupCourseService {
|
||||
Mono<GroupCourse> signIn(Long courseId, Long memberId);
|
||||
|
||||
Mono<Void> delete(Long id);
|
||||
|
||||
Mono<GroupCourse> restore(Long id);
|
||||
|
||||
Mono<PageResponse<GroupCourse>> searchGroupCourses(GroupCourseQueryDto query);
|
||||
}
|
||||
|
||||
+4
@@ -1,5 +1,7 @@
|
||||
package cn.novalon.gym.manage.groupcourse.service;
|
||||
|
||||
import cn.novalon.gym.manage.common.dto.PageRequest;
|
||||
import cn.novalon.gym.manage.common.dto.PageResponse;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourseType;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -29,4 +31,6 @@ public interface IGroupCourseTypeService {
|
||||
* @return 分类名称列表
|
||||
*/
|
||||
Flux<String> findCategories();
|
||||
|
||||
Mono<PageResponse<GroupCourseType>> findByPage(PageRequest pageRequest);
|
||||
}
|
||||
-99
@@ -1,99 +0,0 @@
|
||||
package cn.novalon.gym.manage.groupcourse.service.impl;
|
||||
|
||||
import cn.novalon.gym.manage.groupcourse.domain.Banner;
|
||||
import cn.novalon.gym.manage.groupcourse.repository.IBannerRepository;
|
||||
import cn.novalon.gym.manage.groupcourse.service.IBannerService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@Service
|
||||
public class BannerService implements IBannerService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(BannerService.class);
|
||||
|
||||
private final IBannerRepository bannerRepository;
|
||||
|
||||
public BannerService(IBannerRepository bannerRepository) {
|
||||
this.bannerRepository = bannerRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Banner> findById(Long id) {
|
||||
return bannerRepository.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Banner> findAll() {
|
||||
return bannerRepository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Banner> findAll(String sortBy, String sortOrder) {
|
||||
return bannerRepository.findAll(sortBy, sortOrder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Banner> findAllActive() {
|
||||
return bannerRepository.findAllActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Banner> create(Banner banner) {
|
||||
if (banner.getImageUrl() == null || banner.getImageUrl().isBlank()) {
|
||||
return Mono.error(new RuntimeException("背景图不能为空"));
|
||||
}
|
||||
if (banner.getTitle() == null || banner.getTitle().isBlank()) {
|
||||
return Mono.error(new RuntimeException("主标题不能为空"));
|
||||
}
|
||||
|
||||
return bannerRepository.save(banner)
|
||||
.doOnSuccess(r -> logger.info("轮播图创建成功 - id={}, title={}", r.getId(), r.getTitle()))
|
||||
.doOnError(error -> logger.error("轮播图创建失败 - error: {}", error.getMessage()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Banner> update(Long id, Banner banner) {
|
||||
return bannerRepository.findById(id)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("轮播图不存在")))
|
||||
.flatMap(existing -> {
|
||||
if (banner.getImageUrl() != null) existing.setImageUrl(banner.getImageUrl());
|
||||
if (banner.getTitle() != null) existing.setTitle(banner.getTitle());
|
||||
if (banner.getSubtitle() != null) existing.setSubtitle(banner.getSubtitle());
|
||||
if (banner.getDescription() != null) existing.setDescription(banner.getDescription());
|
||||
if (banner.getSortOrder() != null) existing.setSortOrder(banner.getSortOrder());
|
||||
if (banner.getIsActive() != null) existing.setIsActive(banner.getIsActive());
|
||||
|
||||
return bannerRepository.update(existing);
|
||||
})
|
||||
.doOnSuccess(r -> logger.info("轮播图更新成功 - id={}", id))
|
||||
.doOnError(error -> logger.error("轮播图更新失败 - id={}, error: {}", id, error.getMessage()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> delete(Long id) {
|
||||
return bannerRepository.findById(id)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("轮播图不存在")))
|
||||
.flatMap(banner -> bannerRepository.deleteById(id)
|
||||
.doOnSuccess(v -> logger.info("轮播图删除成功 - id={}", id))
|
||||
.doOnError(error -> logger.error("轮播图删除失败 - id={}, error: {}", id, error.getMessage())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Banner> enable(Long id) {
|
||||
return bannerRepository.updateActiveStatus(id, true)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("轮播图不存在")))
|
||||
.doOnSuccess(r -> logger.info("轮播图启用成功 - id={}", id))
|
||||
.doOnError(error -> logger.error("轮播图启用失败 - id={}, error: {}", id, error.getMessage()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Banner> disable(Long id) {
|
||||
return bannerRepository.updateActiveStatus(id, false)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("轮播图不存在")))
|
||||
.doOnSuccess(r -> logger.info("轮播图禁用成功 - id={}", id))
|
||||
.doOnError(error -> logger.error("轮播图禁用失败 - id={}, error: {}", id, error.getMessage()));
|
||||
}
|
||||
}
|
||||
+10
@@ -1,5 +1,7 @@
|
||||
package cn.novalon.gym.manage.groupcourse.service.impl;
|
||||
|
||||
import cn.novalon.gym.manage.common.dto.PageRequest;
|
||||
import cn.novalon.gym.manage.common.dto.PageResponse;
|
||||
import cn.novalon.gym.manage.common.util.RedisUtil;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.CourseLabel;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourse;
|
||||
@@ -109,4 +111,12 @@ public class CourseLabelService implements ICourseLabelService {
|
||||
.doOnSuccess(v -> logger.info("清空类型标签成功 - typeId={}", typeId))
|
||||
.doOnError(error -> logger.error("清空类型标签失败 - typeId={}, error: {}", typeId, error.getMessage()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<PageResponse<CourseLabel>> findByPage(PageRequest pageRequest) {
|
||||
return courseLabelRepository.findByPage(pageRequest)
|
||||
.doOnSuccess(result -> logger.info("分页查询标签成功 - page={}, size={}, total={}",
|
||||
pageRequest.getPage(), pageRequest.getSize(), result.getTotalElements()))
|
||||
.doOnError(error -> logger.error("分页查询标签失败 - error: {}", error.getMessage()));
|
||||
}
|
||||
}
|
||||
+91
-201
@@ -3,19 +3,15 @@ package cn.novalon.gym.manage.groupcourse.service.impl;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourse;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourseBooking;
|
||||
import cn.novalon.gym.manage.groupcourse.event.BookingReminderEventPublisher;
|
||||
import cn.novalon.gym.manage.groupcourse.handler.BookingSagaHandler;
|
||||
import cn.novalon.gym.manage.groupcourse.repository.IGroupCourseBookingRepository;
|
||||
import cn.novalon.gym.manage.groupcourse.repository.IGroupCourseRepository;
|
||||
import cn.novalon.gym.manage.groupcourse.service.IGroupCourseBookingService;
|
||||
import cn.novalon.gym.manage.groupcourse.util.OSSUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.r2dbc.core.DatabaseClient;
|
||||
import org.springframework.stereotype.Service;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.UUID;
|
||||
@@ -28,7 +24,6 @@ import java.util.UUID;
|
||||
* - 取消预约需在课程开始前至少2小时
|
||||
* - 每节课最多20人
|
||||
* - 预约成功后发送提醒
|
||||
* - 预约成功后扣减权益
|
||||
*
|
||||
* 技术要点:
|
||||
* - 使用Redis缓存团课信息
|
||||
@@ -47,8 +42,6 @@ public class GroupCourseBookingService implements IGroupCourseBookingService {
|
||||
private final IGroupCourseRepository courseRepository;
|
||||
private final GroupCourseRedisService redisService;
|
||||
private final BookingReminderEventPublisher bookingReminderEventPublisher;
|
||||
private final BookingSagaHandler bookingSagaHandler;
|
||||
private final DatabaseClient databaseClient;
|
||||
|
||||
// 预约提前时间限制(分钟)
|
||||
private static final long BOOKING_MIN_ADVANCE_MINUTES = 30;
|
||||
@@ -58,20 +51,16 @@ public class GroupCourseBookingService implements IGroupCourseBookingService {
|
||||
public GroupCourseBookingService(IGroupCourseBookingRepository bookingRepository,
|
||||
IGroupCourseRepository courseRepository,
|
||||
GroupCourseRedisService redisService,
|
||||
BookingReminderEventPublisher bookingReminderEventPublisher,
|
||||
BookingSagaHandler bookingSagaHandler,
|
||||
DatabaseClient databaseClient) {
|
||||
BookingReminderEventPublisher bookingReminderEventPublisher) {
|
||||
this.bookingRepository = bookingRepository;
|
||||
this.courseRepository = courseRepository;
|
||||
this.redisService = redisService;
|
||||
this.bookingReminderEventPublisher = bookingReminderEventPublisher;
|
||||
this.bookingSagaHandler = bookingSagaHandler;
|
||||
this.databaseClient = databaseClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<GroupCourseBooking> bookCourse(Long courseId, Long memberId, Long memberCardRecordId) {
|
||||
logger.info("开始预约团课:courseId={}, memberId={}, memberCardRecordId={}", courseId, memberId, memberCardRecordId);
|
||||
public Mono<GroupCourseBooking> bookCourse(Long courseId, Long memberId) {
|
||||
logger.info("开始预约团课:courseId={}, memberId={}", courseId, memberId);
|
||||
|
||||
// 生成唯一请求ID用于分布式锁
|
||||
String requestId = UUID.randomUUID().toString();
|
||||
@@ -87,14 +76,14 @@ public class GroupCourseBookingService implements IGroupCourseBookingService {
|
||||
return getCourseWithCache(courseId)
|
||||
.flatMap(course -> {
|
||||
// 3. 验证课程状态
|
||||
Long status = course.getStatus();
|
||||
if (status == null || status != 0L) {
|
||||
Long courseStatus = course.getStatus();
|
||||
if (courseStatus == null || courseStatus != 0L) {
|
||||
String errorMessage;
|
||||
if (status == null) {
|
||||
if (courseStatus == null) {
|
||||
errorMessage = "课程状态异常";
|
||||
} else if (status == 1L) {
|
||||
} else if (courseStatus == 1L) {
|
||||
errorMessage = "课程已取消,无法预约";
|
||||
} else if (status == 2L) {
|
||||
} else if (courseStatus == 2L) {
|
||||
errorMessage = "课程已结束,无法预约";
|
||||
} else {
|
||||
errorMessage = "课程状态不可预约";
|
||||
@@ -137,57 +126,61 @@ public class GroupCourseBookingService implements IGroupCourseBookingService {
|
||||
|
||||
// 7. 验证是否已预约
|
||||
return bookingRepository.findValidBooking(courseId, memberId)
|
||||
.flatMap(existingBooking -> {
|
||||
return releaseLockAndError(courseId, requestId, "您已预约该课程");
|
||||
})
|
||||
.flatMap(existingBooking ->
|
||||
releaseLockAndError(courseId, requestId, "您已预约该课程")
|
||||
)
|
||||
.switchIfEmpty(
|
||||
// 8. 使用Redis原子操作验证课程人数是否已满
|
||||
validateAndIncrementBookingCount(courseId, course.getMaxMembers())
|
||||
.flatMap(countValid -> {
|
||||
if (countValid > course.getMaxMembers()) {
|
||||
return releaseLockAndError(courseId, requestId, "课程已满");
|
||||
}
|
||||
// 8. 创建预约记录
|
||||
Mono.defer(() -> {
|
||||
GroupCourseBooking booking = new GroupCourseBooking();
|
||||
booking.setCourseId(courseId);
|
||||
booking.setMemberId(memberId);
|
||||
booking.setBookingTime(LocalDateTime.now());
|
||||
booking.setStatus("0"); // 0-已预约
|
||||
|
||||
// 9. 创建预约记录
|
||||
GroupCourseBooking booking = new GroupCourseBooking();
|
||||
booking.setCourseId(courseId);
|
||||
booking.setMemberId(memberId);
|
||||
booking.setMemberCardRecordId(memberCardRecordId);
|
||||
booking.setBookingTime(LocalDateTime.now());
|
||||
booking.setStatus("0"); // 0-已预约
|
||||
// 添加课程信息到预约记录
|
||||
booking.setCourseName(course.getCourseName());
|
||||
booking.setCourseStartTime(course.getStartTime());
|
||||
booking.setCourseEndTime(course.getEndTime());
|
||||
booking.setLocation(course.getLocation());
|
||||
|
||||
// 添加课程信息到预约记录
|
||||
booking.setCourseName(course.getCourseName());
|
||||
booking.setCourseStartTime(course.getStartTime());
|
||||
booking.setCourseEndTime(course.getEndTime());
|
||||
booking.setLocation(course.getLocation());
|
||||
|
||||
// 10. 使用Saga事务执行预约(包含权益扣减)
|
||||
BigDecimal courseAmount = course.getStoredValueAmount() != null ? course.getStoredValueAmount() : BigDecimal.ZERO;
|
||||
return bookingSagaHandler.executeBooking(booking, memberCardRecordId, courseAmount)
|
||||
.flatMap(savedBooking -> {
|
||||
// 11. 释放锁
|
||||
return redisService.releaseLock(courseId, requestId)
|
||||
.then(Mono.just(savedBooking));
|
||||
})
|
||||
.doOnSuccess(savedBooking -> {
|
||||
logger.info("预约成功:bookingId={}, courseId={}, memberId={}",
|
||||
savedBooking.getId(), courseId, memberId);
|
||||
// 发布预约成功事件
|
||||
bookingReminderEventPublisher.publishBookingSuccessEvent(
|
||||
savedBooking.getId(),
|
||||
savedBooking.getMemberId(),
|
||||
savedBooking.getCourseName(),
|
||||
savedBooking.getCourseStartTime().toString()
|
||||
);
|
||||
})
|
||||
.doOnError(error -> {
|
||||
// 回滚Redis计数
|
||||
redisService.decrementBookingCount(courseId).subscribe();
|
||||
logger.error("预约失败:courseId={}, memberId={}, error={}",
|
||||
courseId, memberId, error.getMessage());
|
||||
});
|
||||
})
|
||||
// 9. 保存预约记录
|
||||
return bookingRepository.save(booking)
|
||||
.flatMap(saved -> {
|
||||
if (saved.getId() == null) {
|
||||
return Mono.error(new RuntimeException("保存预约记录失败"));
|
||||
}
|
||||
// 10. 更新课程当前人数
|
||||
return courseRepository.updateCurrentMembers(courseId, 1)
|
||||
.flatMap(updatedCourse -> {
|
||||
// 11. 更新Redis预约计数
|
||||
return redisService.incrementBookingCount(courseId)
|
||||
.flatMap(count -> {
|
||||
// 12. 释放锁
|
||||
return redisService.releaseLock(courseId, requestId)
|
||||
.then(Mono.just(saved));
|
||||
});
|
||||
})
|
||||
.doOnSuccess(savedBooking -> {
|
||||
logger.info("预约成功:bookingId={}, courseId={}, memberId={}",
|
||||
saved.getId(), courseId, memberId);
|
||||
// 发布预约成功事件
|
||||
bookingReminderEventPublisher.publishBookingSuccessEvent(
|
||||
saved.getId(),
|
||||
saved.getMemberId(),
|
||||
saved.getCourseName(),
|
||||
saved.getCourseStartTime().toString()
|
||||
);
|
||||
})
|
||||
.doOnError(error -> {
|
||||
// 失败时回滚Redis计数和课程人数
|
||||
redisService.decrementBookingCount(courseId).subscribe();
|
||||
courseRepository.updateCurrentMembers(courseId, -1).subscribe();
|
||||
logger.error("预约失败:courseId={}, memberId={}, error={}",
|
||||
courseId, memberId, error.getMessage());
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
});
|
||||
})
|
||||
@@ -215,29 +208,6 @@ public class GroupCourseBookingService implements IGroupCourseBookingService {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证并增加预约人数(使用Redis原子操作)
|
||||
*/
|
||||
private Mono<Integer> validateAndIncrementBookingCount(Long courseId, Integer maxMembers) {
|
||||
// 先获取当前Redis中的预约计数
|
||||
return redisService.getBookingCount(courseId)
|
||||
.flatMap(currentCount -> {
|
||||
// 如果Redis中计数为0,可能是首次访问,需要从数据库同步
|
||||
if (currentCount == 0) {
|
||||
// 从数据库查询实际预约人数
|
||||
return bookingRepository.countValidBookings(courseId)
|
||||
.flatMap(dbCount -> {
|
||||
// 将数据库中的实际预约人数同步到Redis
|
||||
return redisService.setBookingCount(courseId, dbCount.intValue())
|
||||
.then(Mono.just(dbCount.intValue()));
|
||||
});
|
||||
}
|
||||
return Mono.just(currentCount);
|
||||
})
|
||||
// 递增预约计数
|
||||
.flatMap(count -> redisService.incrementBookingCount(courseId).map(Long::intValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* 释放锁并返回错误
|
||||
*/
|
||||
@@ -297,33 +267,37 @@ public class GroupCourseBookingService implements IGroupCourseBookingService {
|
||||
"需在课程开始前" + CANCEL_MIN_ADVANCE_HOURS + "小时取消");
|
||||
}
|
||||
|
||||
// 5. 查询课程金额和已取消次数,使用Saga事务执行取消预约
|
||||
return courseRepository.findByIdAndDeletedAtIsNull(booking.getCourseId())
|
||||
.flatMap(course -> {
|
||||
BigDecimal courseAmount = course.getStoredValueAmount() != null ? course.getStoredValueAmount() : BigDecimal.valueOf(50);
|
||||
return bookingRepository.countCancelledByMemberId(memberId)
|
||||
.flatMap(cancelCount -> {
|
||||
return bookingSagaHandler.executeCancelBooking(bookingId, booking.getCourseId(), booking.getMemberCardRecordId(), memberId, courseAmount, cancelCount);
|
||||
});
|
||||
})
|
||||
.flatMap(updatedBooking -> {
|
||||
// 6. 释放锁
|
||||
return redisService.releaseLock(bookingId, requestId)
|
||||
.then(Mono.just(updatedBooking));
|
||||
})
|
||||
.doOnSuccess(updatedBooking -> {
|
||||
logger.info("取消预约成功:bookingId={}, memberId={}", bookingId, memberId);
|
||||
// 发布预约取消事件
|
||||
bookingReminderEventPublisher.publishBookingCancelEvent(
|
||||
updatedBooking.getId(),
|
||||
updatedBooking.getMemberId(),
|
||||
updatedBooking.getCourseName()
|
||||
);
|
||||
})
|
||||
.doOnError(error -> {
|
||||
logger.error("取消预约失败:bookingId={}, memberId={}, error={}",
|
||||
bookingId, memberId, error.getMessage());
|
||||
});
|
||||
// 5. 更新预约状态为已取消
|
||||
return bookingRepository.updateStatus(bookingId, "1")
|
||||
.flatMap(rows -> {
|
||||
if (rows == 0) {
|
||||
return Mono.error(new RuntimeException("更新预约状态失败"));
|
||||
}
|
||||
// 6. 减少课程当前人数
|
||||
return courseRepository.updateCurrentMembers(booking.getCourseId(), -1)
|
||||
.flatMap(updatedCourse -> {
|
||||
// 7. 更新Redis预约计数
|
||||
return redisService.decrementBookingCount(booking.getCourseId())
|
||||
.flatMap(count -> {
|
||||
// 8. 释放锁
|
||||
return redisService.releaseLock(bookingId, requestId)
|
||||
.then(bookingRepository.findById(bookingId));
|
||||
});
|
||||
})
|
||||
.doOnSuccess(updatedBooking -> {
|
||||
logger.info("取消预约成功:bookingId={}, memberId={}", bookingId, memberId);
|
||||
// 发布预约取消事件
|
||||
bookingReminderEventPublisher.publishBookingCancelEvent(
|
||||
updatedBooking.getId(),
|
||||
updatedBooking.getMemberId(),
|
||||
updatedBooking.getCourseName()
|
||||
);
|
||||
})
|
||||
.doOnError(error -> {
|
||||
logger.error("取消预约失败:bookingId={}, memberId={}, error={}",
|
||||
bookingId, memberId, error.getMessage());
|
||||
});
|
||||
});
|
||||
})
|
||||
.onErrorResume(error -> {
|
||||
redisService.releaseLock(bookingId, requestId).subscribe();
|
||||
@@ -336,18 +310,6 @@ public class GroupCourseBookingService implements IGroupCourseBookingService {
|
||||
public Flux<GroupCourseBooking> getBookingsByMemberId(Long memberId) {
|
||||
logger.debug("查询会员预约记录:memberId={}", memberId);
|
||||
return bookingRepository.findByMemberId(memberId)
|
||||
.flatMap(booking -> {
|
||||
// 从关联的 GroupCourse 获取封面图并转为预签名URL
|
||||
if (booking.getCourseId() != null) {
|
||||
return courseRepository.findByIdAndDeletedAtIsNull(booking.getCourseId())
|
||||
.map(course -> {
|
||||
booking.setCoverImage(OSSUtil.toCoverPresignedUrl(course.getCoverImage()));
|
||||
return booking;
|
||||
})
|
||||
.defaultIfEmpty(booking);
|
||||
}
|
||||
return Mono.just(booking);
|
||||
})
|
||||
.doOnComplete(() -> logger.debug("查询完成:memberId={}", memberId));
|
||||
}
|
||||
|
||||
@@ -364,78 +326,6 @@ public class GroupCourseBookingService implements IGroupCourseBookingService {
|
||||
.doOnComplete(() -> logger.debug("查询完成:courseId={}", courseId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<GroupCourseBooking> qrSignIn(Long courseId, Long memberId) {
|
||||
logger.info("扫码签到:courseId={}, memberId={}", courseId, memberId);
|
||||
|
||||
return courseRepository.findByIdAndDeletedAtIsNull(courseId)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("团课不存在或已删除")))
|
||||
.flatMap(course -> {
|
||||
// 校验1:团课状态必须为 0(正常)
|
||||
Long status = course.getStatus();
|
||||
if (status == null || status != 0L) {
|
||||
String msg;
|
||||
if (status == null) msg = "课程状态异常";
|
||||
else if (status == 1L) msg = "课程已取消,无法签到";
|
||||
else if (status == 2L) msg = "课程已结束,无法签到";
|
||||
else msg = "课程状态不可签到";
|
||||
return Mono.error(new RuntimeException(msg));
|
||||
}
|
||||
|
||||
// 校验2:用户是否预约了该课程(状态为 0-已预约)
|
||||
return bookingRepository.findValidBooking(courseId, memberId)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("您未预约此课程,无法签到")))
|
||||
.flatMap(booking -> {
|
||||
// 校验3:预约状态必须为 0
|
||||
if (!"0".equals(booking.getStatus())) {
|
||||
String msg;
|
||||
if ("1".equals(booking.getStatus())) msg = "预约已取消";
|
||||
else if ("2".equals(booking.getStatus())) msg = "已签到,无需重复签到";
|
||||
else msg = "预约状态异常";
|
||||
return Mono.error(new RuntimeException(msg));
|
||||
}
|
||||
|
||||
// 更新预约状态为 2(已出席)
|
||||
return bookingRepository.updateStatus(booking.getId(), "2")
|
||||
.then(Mono.defer(() -> {
|
||||
// 同步写入签到记录,供仪表盘统计
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalDateTime todayStart = now.toLocalDate().atStartOfDay();
|
||||
LocalDateTime todayEnd = todayStart.plusDays(1);
|
||||
|
||||
// 先检查今天是否已有成功签到记录,避免重复
|
||||
return databaseClient.sql(
|
||||
"SELECT sign_in_status FROM sign_in_record WHERE member_id = :memberId AND sign_in_time >= :startTime AND sign_in_time < :endTime AND is_delete = false AND sign_in_status = 'SUCCESS' ORDER BY sign_in_time DESC LIMIT 1")
|
||||
.bind("memberId", memberId)
|
||||
.bind("startTime", todayStart)
|
||||
.bind("endTime", todayEnd)
|
||||
.map(row -> row.get("sign_in_status", String.class))
|
||||
.one()
|
||||
.flatMap(existing -> {
|
||||
// 已有签到记录,不重复插入
|
||||
return bookingRepository.findById(booking.getId());
|
||||
})
|
||||
.switchIfEmpty(
|
||||
// 无今日签到记录,插入一条
|
||||
databaseClient.sql(
|
||||
"INSERT INTO sign_in_record (member_id, member_card_id, sign_in_time, sign_in_type, sign_in_status, source, created_at, updated_at, is_delete) " +
|
||||
"VALUES (:memberId, :memberCardId, :signInTime, 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', NOW(), NOW(), false)")
|
||||
.bind("memberId", memberId)
|
||||
.bind("memberCardId", booking.getMemberCardRecordId())
|
||||
.bind("signInTime", now)
|
||||
.fetch()
|
||||
.rowsUpdated()
|
||||
.then(bookingRepository.findById(booking.getId()))
|
||||
);
|
||||
}));
|
||||
});
|
||||
})
|
||||
.doOnSuccess(booking -> logger.info("扫码签到成功:bookingId={}, courseId={}, memberId={}",
|
||||
booking.getId(), courseId, memberId))
|
||||
.doOnError(error -> logger.error("扫码签到失败:courseId={}, memberId={}, error={}",
|
||||
courseId, memberId, error.getMessage()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Integer> processAbsentMembers() {
|
||||
logger.info("开始处理已开始课程但未到场会员的预约记录");
|
||||
|
||||
-3
@@ -5,7 +5,6 @@ import cn.novalon.gym.manage.groupcourse.domain.GroupCourseRecommend;
|
||||
import cn.novalon.gym.manage.groupcourse.repository.IGroupCourseRecommendRepository;
|
||||
import cn.novalon.gym.manage.groupcourse.repository.IGroupCourseRepository;
|
||||
import cn.novalon.gym.manage.groupcourse.service.IGroupCourseRecommendService;
|
||||
import cn.novalon.gym.manage.groupcourse.util.OSSUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -135,8 +134,6 @@ public class GroupCourseRecommendService implements IGroupCourseRecommendService
|
||||
|
||||
return groupCourseRepository.findByIdAndDeletedAtIsNull(recommend.getCourseId())
|
||||
.map(course -> {
|
||||
// 将 OSS Key 转换为预签名URL,前端可直接加载
|
||||
course.setCoverImage(OSSUtil.toCoverPresignedUrl(course.getCoverImage()));
|
||||
recommend.setGroupCourse(course);
|
||||
return recommend;
|
||||
})
|
||||
|
||||
+39
-83
@@ -19,7 +19,7 @@ import cn.novalon.gym.manage.groupcourse.repository.IGroupCourseRepository;
|
||||
import cn.novalon.gym.manage.groupcourse.repository.IGroupCourseTypeRepository;
|
||||
import cn.novalon.gym.manage.groupcourse.service.IGroupCourseService;
|
||||
import cn.novalon.gym.manage.groupcourse.util.QRCodeUtil;
|
||||
import cn.novalon.gym.manage.groupcourse.util.OSSUtil;
|
||||
import cn.novalon.gym.manage.file.core.service.ISysFileService;
|
||||
import cn.novalon.gym.manage.member.entity.MemberCard;
|
||||
import cn.novalon.gym.manage.member.entity.MemberCardRecord;
|
||||
import cn.novalon.gym.manage.member.enums.MemberCardType;
|
||||
@@ -33,7 +33,6 @@ import org.springframework.r2dbc.core.DatabaseClient;
|
||||
import org.springframework.stereotype.Service;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
@@ -53,6 +52,7 @@ public class GroupCourseService implements IGroupCourseService {
|
||||
private final ObjectMapper objectMapper;
|
||||
private final GroupCourseStateMachine stateMachine;
|
||||
private final DatabaseClient databaseClient;
|
||||
private final ISysFileService fileService;
|
||||
|
||||
private static final String CACHE_KEY_PREFIX = "group_course:page:";
|
||||
private static final String CACHE_KEY_ID_PREFIX = "group_course:id:";
|
||||
@@ -70,7 +70,8 @@ public class GroupCourseService implements IGroupCourseService {
|
||||
RedisUtil redisUtil,
|
||||
ObjectMapper objectMapper,
|
||||
GroupCourseStateMachine stateMachine,
|
||||
DatabaseClient databaseClient){
|
||||
DatabaseClient databaseClient,
|
||||
ISysFileService fileService){
|
||||
this.groupCourseRepository = groupCourseRepository;
|
||||
this.bookingRepository = bookingRepository;
|
||||
this.groupCourseTypeRepository = groupCourseTypeRepository;
|
||||
@@ -81,6 +82,7 @@ public class GroupCourseService implements IGroupCourseService {
|
||||
this.objectMapper = objectMapper;
|
||||
this.stateMachine = stateMachine;
|
||||
this.databaseClient = databaseClient;
|
||||
this.fileService = fileService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -155,7 +157,7 @@ public class GroupCourseService implements IGroupCourseService {
|
||||
detail.setCurrentMembers(course.getCurrentMembers());
|
||||
detail.setStatus(course.getStatus());
|
||||
detail.setLocation(course.getLocation());
|
||||
detail.setCoverImage(OSSUtil.toCoverPresignedUrl(course.getCoverImage()));
|
||||
detail.setCoverImage(course.getCoverImage());
|
||||
detail.setDescription(course.getDescription());
|
||||
detail.setStoredValueAmount(course.getStoredValueAmount());
|
||||
detail.setQrCodePath(course.getQrCodePath());
|
||||
@@ -180,7 +182,7 @@ public class GroupCourseService implements IGroupCourseService {
|
||||
try {
|
||||
GroupCourse groupCourse = objectMapper.readValue(cachedJson, GroupCourse.class);
|
||||
logger.info("缓存命中 - findById: id={}", id);
|
||||
return Mono.just(fillCoverPresignedUrl(groupCourse));
|
||||
return Mono.just(groupCourse);
|
||||
} catch (JsonProcessingException e) {
|
||||
logger.warn("缓存解析失败,删除缓存 - id: {}, error: {}", id, e.getMessage());
|
||||
return redisUtil.delete(cacheKey).then(Mono.empty());
|
||||
@@ -190,7 +192,6 @@ public class GroupCourseService implements IGroupCourseService {
|
||||
})
|
||||
.switchIfEmpty(
|
||||
groupCourseRepository.findByIdAndDeletedAtIsNull(id)
|
||||
.map(this::fillCoverPresignedUrl)
|
||||
.flatMap(groupCourse -> {
|
||||
try {
|
||||
String jsonData = objectMapper.writeValueAsString(groupCourse);
|
||||
@@ -208,19 +209,16 @@ public class GroupCourseService implements IGroupCourseService {
|
||||
|
||||
@Override
|
||||
public Flux<GroupCourse> findAll() {
|
||||
return groupCourseRepository.findAll()
|
||||
.map(this::fillCoverPresignedUrl);
|
||||
return groupCourseRepository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<GroupCourse> findAll(boolean includeDeleted) {
|
||||
Flux<GroupCourse> flux;
|
||||
if(includeDeleted){
|
||||
flux = groupCourseRepository.findAll();
|
||||
return groupCourseRepository.findAll();
|
||||
}else{
|
||||
flux = groupCourseRepository.findByDeletedAtIsNull();
|
||||
return groupCourseRepository.findByDeletedAtIsNull();
|
||||
}
|
||||
return flux.map(this::fillCoverPresignedUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -230,8 +228,9 @@ public class GroupCourseService implements IGroupCourseService {
|
||||
String sort = pageRequest.getSort();
|
||||
String order = pageRequest.getOrder();
|
||||
String keyword = pageRequest.getKeyword() != null ? pageRequest.getKeyword() : "";
|
||||
String status = pageRequest.getStatus() != null ? pageRequest.getStatus() : "";
|
||||
|
||||
String cacheKey = CACHE_KEY_PREFIX + page + ":" + size + ":" + includeDeleted + ":" + sort + ":" + order + ":" + keyword;
|
||||
String cacheKey = CACHE_KEY_PREFIX + page + ":" + size + ":" + includeDeleted + ":" + sort + ":" + order + ":" + keyword + ":" + status;
|
||||
|
||||
return redisUtil.get(cacheKey, String.class)
|
||||
.flatMap(cachedJson -> {
|
||||
@@ -240,7 +239,6 @@ public class GroupCourseService implements IGroupCourseService {
|
||||
PageResponse<GroupCourse> pageResponse = objectMapper.readValue(cachedJson,
|
||||
objectMapper.getTypeFactory().constructParametricType(PageResponse.class, GroupCourse.class));
|
||||
logger.info("缓存命中 - findByPage: key={}", cacheKey);
|
||||
fillCoverPresignedUrl(pageResponse);
|
||||
return Mono.just(pageResponse);
|
||||
} catch (JsonProcessingException e) {
|
||||
logger.warn("缓存解析失败,删除缓存 - key: {}, error: {}", cacheKey, e.getMessage());
|
||||
@@ -261,7 +259,6 @@ public class GroupCourseService implements IGroupCourseService {
|
||||
|
||||
return resultMono.flatMap(pageResponse -> {
|
||||
try {
|
||||
fillCoverPresignedUrl(pageResponse);
|
||||
String jsonData = objectMapper.writeValueAsString(pageResponse);
|
||||
return redisUtil.setWithExpire(cacheKey, jsonData, CACHE_EXPIRE_SECONDS)
|
||||
.thenReturn(pageResponse)
|
||||
@@ -295,15 +292,21 @@ public class GroupCourseService implements IGroupCourseService {
|
||||
|
||||
String jsonContent = objectMapper.writeValueAsString(qrCodeContent);
|
||||
|
||||
// 生成二维码并上传到阿里云OSS
|
||||
String qrCodeUrl = QRCodeUtil.generateQRCodeAndUploadToOSS(jsonContent);
|
||||
course.setQrCodePath(qrCodeUrl);
|
||||
|
||||
logger.info("团课二维码上传到OSS成功 - id={}, qrCodeUrl={}", course.getId(), qrCodeUrl);
|
||||
|
||||
// 更新团课信息,保存二维码路径
|
||||
return groupCourseRepository.update(course)
|
||||
.doOnSuccess(updatedCourse -> logger.info("团课创建成功 - id={}, name={}", updatedCourse.getId(), updatedCourse.getCourseName()));
|
||||
// 生成二维码字节数组,通过统一文件服务保存
|
||||
return Mono.fromCallable(() -> QRCodeUtil.generateQrCodeBytes(jsonContent))
|
||||
.flatMap(qrCodeBytes -> {
|
||||
String fileName = "qrcode_" + course.getId() + ".png";
|
||||
return fileService.saveBytes(qrCodeBytes, fileName, "image/png", "system");
|
||||
})
|
||||
.flatMap(sysFile -> {
|
||||
String qrCodeUrl = "/api/files/" + sysFile.getId() + "/preview";
|
||||
course.setQrCodePath(qrCodeUrl);
|
||||
|
||||
logger.info("团课二维码已保存 - id={}, fileId={}, url={}", course.getId(), sysFile.getId(), qrCodeUrl);
|
||||
|
||||
return groupCourseRepository.update(course)
|
||||
.doOnSuccess(updatedCourse -> logger.info("团课创建成功 - id={}, name={}", updatedCourse.getId(), updatedCourse.getCourseName()));
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.error("团课二维码生成失败 - id={}, error: {}", course.getId(), e.getMessage(), e);
|
||||
// 即使二维码生成失败,也返回成功创建的团课
|
||||
@@ -355,9 +358,6 @@ public class GroupCourseService implements IGroupCourseService {
|
||||
if (groupCourse.getQrCodePath() != null) {
|
||||
existing.setQrCodePath(groupCourse.getQrCodePath());
|
||||
}
|
||||
if (groupCourse.getIsRecurring() != null) {
|
||||
existing.setIsRecurring(groupCourse.getIsRecurring());
|
||||
}
|
||||
return groupCourseRepository.update(existing);
|
||||
})
|
||||
.doOnSuccess(course -> logger.info("团课更新成功 - id={}", id))
|
||||
@@ -514,29 +514,14 @@ public class GroupCourseService implements IGroupCourseService {
|
||||
return Mono.error(new RuntimeException("课程已满员,无法签到"));
|
||||
}
|
||||
|
||||
// 校验5:用户今日是否已到店签到(直接查询sign_in_record表)
|
||||
LocalDateTime todayStart = LocalDateTime.now().toLocalDate().atStartOfDay();
|
||||
LocalDateTime todayEnd = todayStart.plusDays(1);
|
||||
return databaseClient.sql("SELECT sign_in_status FROM sign_in_record WHERE member_id = :memberId AND sign_in_time >= :startTime AND sign_in_time < :endTime AND is_delete = false ORDER BY sign_in_time DESC LIMIT 1")
|
||||
.bind("memberId", memberId)
|
||||
.bind("startTime", todayStart)
|
||||
.bind("endTime", todayEnd)
|
||||
.map(row -> row.get("sign_in_status", String.class))
|
||||
.one()
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("请先完成到店签到")))
|
||||
.flatMap(status -> {
|
||||
if (!"SUCCESS".equals(status)) {
|
||||
return Mono.error(new RuntimeException("到店签到未成功,请重新签到"));
|
||||
}
|
||||
// 校验6:用户已预约此课程(有效预约,状态为0-已预约)
|
||||
return bookingRepository.findValidBooking(courseId, memberId)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("您未预约此课程,无法签到")))
|
||||
.flatMap(booking -> {
|
||||
return groupCourseRepository.updateCurrentMembers(courseId, 1)
|
||||
.flatMap(updatedCourse -> {
|
||||
return bookingRepository.updateStatus(booking.getId(), "2")
|
||||
.thenReturn(updatedCourse);
|
||||
});
|
||||
// 校验5:用户已预约此课程(有效预约,状态为0-已预约)
|
||||
return bookingRepository.findValidBooking(courseId, memberId)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("您未预约此团课")))
|
||||
.flatMap(booking -> {
|
||||
return groupCourseRepository.updateCurrentMembers(courseId, 1)
|
||||
.flatMap(updatedCourse -> {
|
||||
return bookingRepository.updateStatus(booking.getId(), "2")
|
||||
.thenReturn(updatedCourse);
|
||||
});
|
||||
});
|
||||
})
|
||||
@@ -547,10 +532,11 @@ public class GroupCourseService implements IGroupCourseService {
|
||||
|
||||
@Override
|
||||
public Mono<Void> delete(Long id) {
|
||||
// 已取消或已结束的课程才能删除
|
||||
// 只有已取消或已结束的课程才能删除
|
||||
return groupCourseRepository.findByIdAndDeletedAtIsNull(id)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("团课不存在")))
|
||||
.flatMap(course -> {
|
||||
// 检查课程状态是否为已取消(状态码1)或已结束(状态码2)
|
||||
Long status = course.getStatus();
|
||||
if (status == null || (!status.equals(CourseStatus.CANCELLED.getValue()) && !status.equals(CourseStatus.ENDED.getValue()))) {
|
||||
return Mono.error(new RuntimeException("只有已取消或已结束的课程才能删除,当前状态: " +
|
||||
@@ -565,14 +551,6 @@ public class GroupCourseService implements IGroupCourseService {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<GroupCourse> restore(Long id) {
|
||||
return groupCourseRepository.restoreById(id)
|
||||
.doOnSuccess(course -> logger.info("团课恢复成功 - id={}", id))
|
||||
.flatMap(course -> clearCache().thenReturn(course))
|
||||
.doOnError(error -> logger.error("团课恢复失败 - id={}, error: {}", id, error.getMessage()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<PageResponse<GroupCourse>> searchGroupCourses(GroupCourseQueryDto query) {
|
||||
logger.info("多条件查询团课 - courseName={}, courseType={}, startDate={}, endDate={}, timePeriod={}, priceSort={}, remainingMost={}",
|
||||
@@ -580,11 +558,8 @@ public class GroupCourseService implements IGroupCourseService {
|
||||
query.getTimePeriod(), query.getPriceSort(), query.getRemainingMost());
|
||||
|
||||
return groupCourseRepository.searchGroupCourses(query)
|
||||
.doOnSuccess(result -> {
|
||||
fillCoverPresignedUrl(result);
|
||||
logger.info("多条件查询结果 - total={}, page={}, size={}",
|
||||
result.getTotalElements(), result.getCurrentPage(), result.getPageSize());
|
||||
})
|
||||
.doOnSuccess(result -> logger.info("多条件查询结果 - total={}, page={}, size={}",
|
||||
result.getTotalElements(), result.getCurrentPage(), result.getPageSize()))
|
||||
.doOnError(error -> logger.error("多条件查询失败 - error: {}", error.getMessage()));
|
||||
}
|
||||
|
||||
@@ -593,23 +568,4 @@ public class GroupCourseService implements IGroupCourseService {
|
||||
.then(redisUtil.deleteByPattern(CACHE_KEY_ID_PREFIX + "*"))
|
||||
.then(redisUtil.deleteByPattern(CACHE_KEY_DETAIL_PREFIX + "*")).then();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将单个 GroupCourse 的 coverImage 从 OSS Key 转换为预签名URL
|
||||
*/
|
||||
private GroupCourse fillCoverPresignedUrl(GroupCourse course) {
|
||||
if (course != null) {
|
||||
course.setCoverImage(OSSUtil.toCoverPresignedUrl(course.getCoverImage()));
|
||||
}
|
||||
return course;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将分页结果中所有 GroupCourse 的 coverImage 从 OSS Key 转换为预签名URL
|
||||
*/
|
||||
private void fillCoverPresignedUrl(PageResponse<GroupCourse> pageResponse) {
|
||||
if (pageResponse != null && pageResponse.getContent() != null) {
|
||||
pageResponse.getContent().forEach(this::fillCoverPresignedUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+19
-8
@@ -1,5 +1,7 @@
|
||||
package cn.novalon.gym.manage.groupcourse.service.impl;
|
||||
|
||||
import cn.novalon.gym.manage.common.dto.PageRequest;
|
||||
import cn.novalon.gym.manage.common.dto.PageResponse;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourseType;
|
||||
import cn.novalon.gym.manage.groupcourse.repository.IGroupCourseRepository;
|
||||
import cn.novalon.gym.manage.groupcourse.repository.IGroupCourseTypeRepository;
|
||||
@@ -19,7 +21,7 @@ public class GroupCourseTypeService implements IGroupCourseTypeService {
|
||||
private final IGroupCourseRepository groupCourseRepository;
|
||||
|
||||
public GroupCourseTypeService(IGroupCourseTypeRepository groupCourseTypeRepository,
|
||||
IGroupCourseRepository groupCourseRepository) {
|
||||
IGroupCourseRepository groupCourseRepository) {
|
||||
this.groupCourseTypeRepository = groupCourseTypeRepository;
|
||||
this.groupCourseRepository = groupCourseRepository;
|
||||
}
|
||||
@@ -72,16 +74,17 @@ public class GroupCourseTypeService implements IGroupCourseTypeService {
|
||||
|
||||
@Override
|
||||
public Mono<Void> delete(Long id) {
|
||||
// 检查是否有团课依赖该类型
|
||||
return groupCourseRepository.findByCourseType(id)
|
||||
.hasElements()
|
||||
.flatMap(hasCourses -> {
|
||||
if (hasCourses) {
|
||||
return Mono.<Void>error(new RuntimeException("该类型下存在关联团课,无法删除"));
|
||||
.flatMap(hasDependents -> {
|
||||
if (hasDependents) {
|
||||
return Mono.<Void>error(new RuntimeException("该类型下存在团课,无法删除"));
|
||||
}
|
||||
return groupCourseTypeRepository.deleteById(id);
|
||||
})
|
||||
.doOnSuccess(v -> logger.info("团课类型删除成功 - id={}", id))
|
||||
.doOnError(error -> logger.error("团课类型删除失败 - id={}, error: {}", id, error.getMessage()));
|
||||
return groupCourseTypeRepository.deleteById(id)
|
||||
.doOnSuccess(v -> logger.info("团课类型删除成功 - id={}", id))
|
||||
.doOnError(error -> logger.error("团课类型删除失败 - id={}, error: {}", id, error.getMessage()));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,4 +94,12 @@ public class GroupCourseTypeService implements IGroupCourseTypeService {
|
||||
.filter(category -> category != null && !category.isEmpty())
|
||||
.distinct();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<PageResponse<GroupCourseType>> findByPage(PageRequest pageRequest) {
|
||||
return groupCourseTypeRepository.findByPage(pageRequest)
|
||||
.doOnSuccess(result -> logger.info("分页查询团课类型成功 - page={}, size={}, total={}",
|
||||
pageRequest.getPage(), pageRequest.getSize(), result.getTotalElements()))
|
||||
.doOnError(error -> logger.error("分页查询团课类型失败 - error: {}", error.getMessage()));
|
||||
}
|
||||
}
|
||||
-193
@@ -1,193 +0,0 @@
|
||||
package cn.novalon.gym.manage.groupcourse.util;
|
||||
|
||||
import com.aliyun.oss.HttpMethod;
|
||||
import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.OSSClientBuilder;
|
||||
import com.aliyun.oss.model.GeneratePresignedUrlRequest;
|
||||
import com.aliyun.oss.model.PutObjectRequest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 阿里云OSS工具类
|
||||
*/
|
||||
public class OSSUtil {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(OSSUtil.class);
|
||||
|
||||
// OSS配置信息
|
||||
private static final String ENDPOINT = "https://oss-cn-beijing.aliyuncs.com";
|
||||
private static final String ACCESS_KEY_ID = "LTAI5t9wHCiH68Xjxg64Xx4Y";
|
||||
private static final String ACCESS_KEY_SECRET = "isAfz1IFGAnV13LOIrVg19aPhY8aRq";
|
||||
private static final String BUCKET_NAME = "ycc-filesaver";
|
||||
|
||||
// OSS访问地址前缀
|
||||
private static final String OSS_URL_PREFIX = "https://" + BUCKET_NAME + "." + ENDPOINT + "/";
|
||||
|
||||
// 文件存储目录
|
||||
private static final String QRCODE_DIR = "qrcode/";
|
||||
private static final String COVER_DIR = "cover/";
|
||||
|
||||
// 预签名URL有效期(秒)
|
||||
private static final long PRESIGN_EXPIRE_SECONDS = 300;
|
||||
// 封面图预签名URL有效期(秒)- 1小时,确保前端列表页足够展示
|
||||
private static final long COVER_PRESIGN_EXPIRE_SECONDS = 3600;
|
||||
|
||||
/**
|
||||
* 上传文件到阿里云OSS(文件默认继承Bucket权限,不设置ACL)
|
||||
*
|
||||
* @param localFilePath 本地文件路径
|
||||
* @param fileName 文件名(不含路径)
|
||||
* @return OSS object key(不含域名前缀)
|
||||
*/
|
||||
public static String uploadToOSS(String localFilePath, String fileName) {
|
||||
OSS ossClient = null;
|
||||
try {
|
||||
ossClient = new OSSClientBuilder().build(ENDPOINT, ACCESS_KEY_ID, ACCESS_KEY_SECRET);
|
||||
|
||||
String datePath = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd"));
|
||||
String ossFilePath = QRCODE_DIR + datePath + "/" + fileName;
|
||||
|
||||
PutObjectRequest putObjectRequest = new PutObjectRequest(BUCKET_NAME, ossFilePath, new File(localFilePath));
|
||||
ossClient.putObject(putObjectRequest);
|
||||
|
||||
logger.info("文件上传到OSS成功: localPath={}, ossKey={}", localFilePath, ossFilePath);
|
||||
return ossFilePath;
|
||||
} catch (Exception e) {
|
||||
logger.error("文件上传到OSS失败 - localPath: {}, error: {}", localFilePath, e.getMessage(), e);
|
||||
throw new RuntimeException("文件上传到OSS失败: " + e.getMessage(), e);
|
||||
} finally {
|
||||
if (ossClient != null) {
|
||||
ossClient.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件到阿里云OSS(自定义存储路径,文件默认继承Bucket权限)
|
||||
*
|
||||
* @param localFilePath 本地文件路径
|
||||
* @param ossDirectory OSS存储目录
|
||||
* @param fileName 文件名(不含路径)
|
||||
* @return OSS object key(不含域名前缀)
|
||||
*/
|
||||
public static String uploadToOSS(String localFilePath, String ossDirectory, String fileName) {
|
||||
OSS ossClient = null;
|
||||
try {
|
||||
ossClient = new OSSClientBuilder().build(ENDPOINT, ACCESS_KEY_ID, ACCESS_KEY_SECRET);
|
||||
|
||||
String ossFilePath = ossDirectory + fileName;
|
||||
|
||||
PutObjectRequest putObjectRequest = new PutObjectRequest(BUCKET_NAME, ossFilePath, new File(localFilePath));
|
||||
ossClient.putObject(putObjectRequest);
|
||||
|
||||
logger.info("文件上传到OSS成功: localPath={}, ossKey={}", localFilePath, ossFilePath);
|
||||
return ossFilePath;
|
||||
} catch (Exception e) {
|
||||
logger.error("文件上传到OSS失败 - localPath: {}, error: {}", localFilePath, e.getMessage(), e);
|
||||
throw new RuntimeException("文件上传到OSS失败: " + e.getMessage(), e);
|
||||
} finally {
|
||||
if (ossClient != null) {
|
||||
ossClient.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传封面图到阿里云OSS(使用InputStream,文件默认继承Bucket权限)
|
||||
*
|
||||
* @param inputStream 文件输入流
|
||||
* @param fileName 文件名(不含路径)
|
||||
* @return OSS object key(不含域名前缀)
|
||||
*/
|
||||
public static String uploadCoverToOSS(InputStream inputStream, String fileName) {
|
||||
OSS ossClient = null;
|
||||
try {
|
||||
ossClient = new OSSClientBuilder().build(ENDPOINT, ACCESS_KEY_ID, ACCESS_KEY_SECRET);
|
||||
|
||||
String datePath = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd"));
|
||||
String ossFilePath = COVER_DIR + datePath + "/" + fileName;
|
||||
|
||||
ossClient.putObject(BUCKET_NAME, ossFilePath, inputStream);
|
||||
|
||||
logger.info("封面上传到OSS成功: fileName={}, ossKey={}", fileName, ossFilePath);
|
||||
return ossFilePath;
|
||||
} catch (Exception e) {
|
||||
logger.error("封面上传到OSS失败 - fileName: {}, error: {}", fileName, e.getMessage(), e);
|
||||
throw new RuntimeException("封面上传到OSS失败: " + e.getMessage(), e);
|
||||
} finally {
|
||||
if (ossClient != null) {
|
||||
ossClient.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成OSS对象预签名URL(临时访问链接)
|
||||
*
|
||||
* @param ossKey OSS对象Key(不含域名前缀)
|
||||
* @return 预签名URL
|
||||
*/
|
||||
public static String generatePresignedUrl(String ossKey) {
|
||||
return generatePresignedUrl(ossKey, PRESIGN_EXPIRE_SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成OSS对象预签名URL(可指定有效期)
|
||||
*
|
||||
* @param ossKey OSS对象Key(不含域名前缀)
|
||||
* @param expireSeconds 有效期(秒)
|
||||
* @return 预签名URL
|
||||
*/
|
||||
public static String generatePresignedUrl(String ossKey, long expireSeconds) {
|
||||
OSS ossClient = null;
|
||||
try {
|
||||
ossClient = new OSSClientBuilder().build(ENDPOINT, ACCESS_KEY_ID, ACCESS_KEY_SECRET);
|
||||
|
||||
Date expiration = new Date(System.currentTimeMillis() + expireSeconds * 1000);
|
||||
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(BUCKET_NAME, ossKey, HttpMethod.GET);
|
||||
request.setExpiration(expiration);
|
||||
|
||||
URL signedUrl = ossClient.generatePresignedUrl(request);
|
||||
return signedUrl.toString();
|
||||
} catch (Exception e) {
|
||||
logger.error("生成预签名URL失败 - ossKey: {}, error: {}", ossKey, e.getMessage(), e);
|
||||
throw new RuntimeException("生成预签名URL失败: " + e.getMessage(), e);
|
||||
} finally {
|
||||
if (ossClient != null) {
|
||||
ossClient.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据OSS Key拼接公开访问URL(仅当Bucket为公共读时有效)
|
||||
*/
|
||||
public static String getPublicUrl(String ossKey) {
|
||||
return OSS_URL_PREFIX + ossKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将OSS Key(相对路径)转换为封面图预签名URL(1小时有效期)
|
||||
* 如果已经是HTTP(S)完整URL则直接返回
|
||||
*
|
||||
* @param ossKey OSS对象Key或完整URL
|
||||
* @return 可访问的预签名URL,ossKey为空时返回null
|
||||
*/
|
||||
public static String toCoverPresignedUrl(String ossKey) {
|
||||
if (ossKey == null || ossKey.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
if (ossKey.startsWith("http://") || ossKey.startsWith("https://")) {
|
||||
return ossKey;
|
||||
}
|
||||
return generatePresignedUrl(ossKey, COVER_PRESIGN_EXPIRE_SECONDS);
|
||||
}
|
||||
}
|
||||
+16
-107
@@ -10,46 +10,33 @@ import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 二维码生成工具类
|
||||
* 生成二维码的字节数组,由调用方统一通过文件服务保存
|
||||
*/
|
||||
public class QRCodeUtil {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(QRCodeUtil.class);
|
||||
|
||||
// 二维码默认保存路径(本地临时路径)
|
||||
private static final String DEFAULT_SAVE_PATH = "D:\\Games\\exmp\\image";
|
||||
|
||||
// 二维码尺寸
|
||||
private static final int QR_CODE_WIDTH = 300;
|
||||
private static final int QR_CODE_HEIGHT = 300;
|
||||
|
||||
/**
|
||||
* 生成二维码并保存到指定路径
|
||||
* 生成二维码图片的字节数组
|
||||
*
|
||||
* @param content 二维码内容
|
||||
* @param savePath 保存路径
|
||||
* @param fileName 文件名(不含扩展名)
|
||||
* @return 生成的二维码文件完整路径
|
||||
* @return PNG格式的二维码图片字节数组
|
||||
*/
|
||||
public static String generateQRCode(String content, String savePath, String fileName) {
|
||||
public static byte[] generateQrCodeBytes(String content) {
|
||||
try {
|
||||
Path directory = Paths.get(savePath);
|
||||
if (!Files.exists(directory)) {
|
||||
Files.createDirectories(directory);
|
||||
logger.info("创建二维码保存目录: {}", savePath);
|
||||
}
|
||||
|
||||
Map<EncodeHintType, Object> hints = new HashMap<>();
|
||||
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
|
||||
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
|
||||
@@ -58,99 +45,21 @@ public class QRCodeUtil {
|
||||
QRCodeWriter qrCodeWriter = new QRCodeWriter();
|
||||
BitMatrix bitMatrix = qrCodeWriter.encode(content, BarcodeFormat.QR_CODE, QR_CODE_WIDTH, QR_CODE_HEIGHT, hints);
|
||||
|
||||
String filePath = Paths.get(savePath, fileName + ".png").toString();
|
||||
Path path = Paths.get(filePath);
|
||||
BufferedImage image = MatrixToImageWriter.toBufferedImage(bitMatrix);
|
||||
|
||||
MatrixToImageWriter.writeToPath(bitMatrix, "PNG", path);
|
||||
logger.info("二维码生成成功: {}", filePath);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageIO.write(image, "PNG", baos);
|
||||
byte[] bytes = baos.toByteArray();
|
||||
baos.close();
|
||||
|
||||
return filePath;
|
||||
logger.info("二维码字节数组生成成功, size={} bytes", bytes.length);
|
||||
return bytes;
|
||||
} catch (WriterException e) {
|
||||
logger.error("二维码生成失败 - WriterException: {}", e.getMessage(), e);
|
||||
throw new RuntimeException("二维码生成失败: " + e.getMessage(), e);
|
||||
} catch (IOException e) {
|
||||
logger.error("二维码保存失败 - IOException: {}", e.getMessage(), e);
|
||||
throw new RuntimeException("二维码保存失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成二维码并保存到默认路径
|
||||
* 文件名格式: UUID + 创建时间
|
||||
*
|
||||
* @param content 二维码内容
|
||||
* @return 生成的二维码文件完整路径
|
||||
*/
|
||||
public static String generateQRCode(String content) {
|
||||
String uuid = UUID.randomUUID().toString().replace("-", "");
|
||||
String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
|
||||
String fileName = uuid + "_" + timestamp;
|
||||
|
||||
return generateQRCode(content, DEFAULT_SAVE_PATH, fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成二维码并保存到默认路径,使用自定义文件名
|
||||
*
|
||||
* @param content 二维码内容
|
||||
* @param fileName 文件名(不含扩展名)
|
||||
* @return 生成的二维码文件完整路径
|
||||
*/
|
||||
public static String generateQRCodeWithFileName(String content, String fileName) {
|
||||
return generateQRCode(content, DEFAULT_SAVE_PATH, fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成二维码并上传到阿里云OSS
|
||||
* 文件名格式: UUID + 创建时间
|
||||
*
|
||||
* @param content 二维码内容
|
||||
* @return 阿里云OSS访问地址
|
||||
*/
|
||||
public static String generateQRCodeAndUploadToOSS(String content) {
|
||||
String uuid = UUID.randomUUID().toString().replace("-", "");
|
||||
String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
|
||||
String fileName = uuid + "_" + timestamp + ".png";
|
||||
|
||||
return generateQRCodeAndUploadToOSS(content, fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成二维码并上传到阿里云OSS
|
||||
*
|
||||
* @param content 二维码内容
|
||||
* @param fileName 文件名(含扩展名)
|
||||
* @return 阿里云OSS访问地址
|
||||
*/
|
||||
public static String generateQRCodeAndUploadToOSS(String content, String fileName) {
|
||||
try {
|
||||
Path tempDir = Files.createTempDirectory("qrcode_temp");
|
||||
String tempFilePath = tempDir.resolve(fileName).toString();
|
||||
|
||||
Map<EncodeHintType, Object> hints = new HashMap<>();
|
||||
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
|
||||
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
|
||||
hints.put(EncodeHintType.MARGIN, 1);
|
||||
|
||||
QRCodeWriter qrCodeWriter = new QRCodeWriter();
|
||||
BitMatrix bitMatrix = qrCodeWriter.encode(content, BarcodeFormat.QR_CODE, QR_CODE_WIDTH, QR_CODE_HEIGHT, hints);
|
||||
|
||||
MatrixToImageWriter.writeToPath(bitMatrix, "PNG", Paths.get(tempFilePath));
|
||||
logger.info("二维码临时文件生成成功: {}", tempFilePath);
|
||||
|
||||
String ossUrl = OSSUtil.uploadToOSS(tempFilePath, fileName);
|
||||
|
||||
Files.deleteIfExists(Paths.get(tempFilePath));
|
||||
Files.deleteIfExists(tempDir);
|
||||
logger.info("临时文件已删除: {}", tempFilePath);
|
||||
|
||||
return ossUrl;
|
||||
} catch (WriterException e) {
|
||||
logger.error("二维码生成失败 - WriterException: {}", e.getMessage(), e);
|
||||
throw new RuntimeException("二维码生成失败: " + e.getMessage(), e);
|
||||
} catch (IOException e) {
|
||||
logger.error("二维码处理失败 - IOException: {}", e.getMessage(), e);
|
||||
throw new RuntimeException("二维码处理失败: " + e.getMessage(), e);
|
||||
logger.error("二维码输出失败 - IOException: {}", e.getMessage(), e);
|
||||
throw new RuntimeException("二维码输出失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
-41
@@ -1,9 +1,6 @@
|
||||
package cn.novalon.gym.manage.groupcourse.util;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@@ -12,58 +9,41 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
*/
|
||||
class QRCodeUtilTest {
|
||||
|
||||
@TempDir
|
||||
Path tempDir;
|
||||
|
||||
@Test
|
||||
void testGenerateQRCode() {
|
||||
void testGenerateQrCodeBytes() {
|
||||
String content = "测试二维码内容";
|
||||
String qrCodePath = QRCodeUtil.generateQRCode(content);
|
||||
byte[] bytes = QRCodeUtil.generateQrCodeBytes(content);
|
||||
|
||||
assertNotNull(qrCodePath, "二维码路径不应为空");
|
||||
assertTrue(qrCodePath.endsWith(".png"), "二维码文件应为PNG格式");
|
||||
assertTrue(qrCodePath.contains("D:\\Games\\exmp\\image"), "二维码应保存到指定路径");
|
||||
assertNotNull(bytes, "二维码字节数组不应为空");
|
||||
assertTrue(bytes.length > 0, "二维码字节数组应包含数据");
|
||||
|
||||
System.out.println("生成的二维码路径: " + qrCodePath);
|
||||
System.out.println("生成的二维码字节大小: " + bytes.length + " bytes");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenerateQRCodeWithCustomPath() {
|
||||
String content = "自定义路径测试";
|
||||
String customPath = tempDir.toString();
|
||||
String fileName = "test_qrcode";
|
||||
void testGenerateQrCodeBytesWithJsonContent() {
|
||||
String jsonContent = "{\"id\":1,\"courseName\":\"瑜伽课\",\"coachId\":100,\"startTime\":\"2026-07-14T10:00:00\"}";
|
||||
|
||||
String qrCodePath = QRCodeUtil.generateQRCode(content, customPath, fileName);
|
||||
byte[] bytes = QRCodeUtil.generateQrCodeBytes(jsonContent);
|
||||
|
||||
assertNotNull(qrCodePath, "二维码路径不应为空");
|
||||
assertTrue(qrCodePath.endsWith(".png"), "二维码文件应为PNG格式");
|
||||
assertTrue(qrCodePath.contains(fileName), "二维码文件名应包含指定名称");
|
||||
assertNotNull(bytes, "二维码字节数组不应为空");
|
||||
assertTrue(bytes.length > 0, "二维码字节数组应包含数据");
|
||||
|
||||
System.out.println("生成的二维码路径: " + qrCodePath);
|
||||
System.out.println("JSON内容二维码字节大小: " + bytes.length + " bytes");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenerateQRCodeWithJsonContent() {
|
||||
String jsonContent = "{\"id\":1,\"courseName\":\"瑜伽课\",\"coachId\":100,\"startTime\":\"2026-06-18T10:00:00\"}";
|
||||
void testGenerateQrCodeBytesWithLongContent() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
sb.append("这是第").append(i).append("行测试数据\n");
|
||||
}
|
||||
|
||||
String qrCodePath = QRCodeUtil.generateQRCode(jsonContent);
|
||||
byte[] bytes = QRCodeUtil.generateQrCodeBytes(sb.toString());
|
||||
|
||||
assertNotNull(qrCodePath, "二维码路径不应为空");
|
||||
assertTrue(qrCodePath.endsWith(".png"), "二维码文件应为PNG格式");
|
||||
assertNotNull(bytes, "二维码字节数组不应为空");
|
||||
assertTrue(bytes.length > 0, "长内容二维码应正常生成");
|
||||
|
||||
System.out.println("JSON内容二维码路径: " + qrCodePath);
|
||||
System.out.println("长内容二维码字节大小: " + bytes.length + " bytes");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenerateQRCodeAndUploadToOSS() {
|
||||
String jsonContent = "{\"id\":1,\"courseName\":\"瑜伽课\",\"coachId\":100,\"startTime\":\"2026-06-18T10:00:00\"}";
|
||||
|
||||
String ossUrl = QRCodeUtil.generateQRCodeAndUploadToOSS(jsonContent);
|
||||
|
||||
assertNotNull(ossUrl, "OSS访问地址不应为空");
|
||||
assertTrue(ossUrl.startsWith("qrcode/"), "OSS访问地址应以qrcode/开头");
|
||||
assertTrue(ossUrl.endsWith(".png"), "OSS访问地址应为PNG格式");
|
||||
|
||||
System.out.println("上传到OSS的二维码地址: " + ossUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -16,6 +16,9 @@ import org.springframework.stereotype.Component;
|
||||
@ConfigurationProperties(prefix = "wechat")
|
||||
public class WechatProperties {
|
||||
|
||||
// Mock模式:true=使用模拟数据,false=调用真实微信API
|
||||
private Boolean mockEnabled;
|
||||
|
||||
// 小程序配置
|
||||
private MiniApp miniapp = new MiniApp();
|
||||
|
||||
|
||||
-59
@@ -1,59 +0,0 @@
|
||||
package cn.novalon.gym.manage.member.dto;
|
||||
|
||||
import cn.novalon.gym.manage.member.enums.GenderEnum;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* 管理员编辑会员信息DTO(含密码验证)
|
||||
*
|
||||
* @author system
|
||||
* @date 2026-06-24
|
||||
*/
|
||||
@Data
|
||||
public class AdminEditMemberDto {
|
||||
|
||||
/**
|
||||
* 管理员密码(必填,用于验证身份)
|
||||
*/
|
||||
private String adminPassword;
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
private String nickname;
|
||||
|
||||
/**
|
||||
* 性别
|
||||
*/
|
||||
private GenderEnum gender;
|
||||
|
||||
/**
|
||||
* 生日
|
||||
*/
|
||||
private LocalDate birthday;
|
||||
|
||||
/**
|
||||
* 地址
|
||||
*/
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 转换为 UpdateMemberInfoDto
|
||||
*/
|
||||
public UpdateMemberInfoDto toUpdateMemberInfoDto() {
|
||||
UpdateMemberInfoDto dto = new UpdateMemberInfoDto();
|
||||
dto.setNickname(nickname);
|
||||
dto.setGender(gender);
|
||||
dto.setBirthday(birthday);
|
||||
dto.setAddress(address);
|
||||
dto.setAvatar(avatar);
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
+26
-69
@@ -2,21 +2,16 @@ package cn.novalon.gym.manage.member.handler;
|
||||
|
||||
import cn.novalon.gym.manage.member.entity.MemberCard;
|
||||
import cn.novalon.gym.manage.member.service.IMemberCardService;
|
||||
import cn.novalon.gym.manage.sys.core.service.ISysUserService;
|
||||
import cn.novalon.gym.manage.sys.util.AuthUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 会员卡管理处理器
|
||||
*
|
||||
@@ -29,13 +24,9 @@ import java.util.Map;
|
||||
public class MemberCardHandler {
|
||||
|
||||
private final IMemberCardService memberCardService;
|
||||
private final ISysUserService sysUserService;
|
||||
private final AuthUtil authUtil;
|
||||
|
||||
public MemberCardHandler(IMemberCardService memberCardService, ISysUserService sysUserService, AuthUtil authUtil) {
|
||||
public MemberCardHandler(IMemberCardService memberCardService) {
|
||||
this.memberCardService = memberCardService;
|
||||
this.sysUserService = sysUserService;
|
||||
this.authUtil = authUtil;
|
||||
}
|
||||
|
||||
@Operation(summary = "根据ID查询会员卡类型", description = "查询指定ID的会员卡类型详情")
|
||||
@@ -69,72 +60,38 @@ public class MemberCardHandler {
|
||||
.flatMap(card -> ServerResponse.status(HttpStatus.CREATED).bodyValue(card));
|
||||
}
|
||||
|
||||
@Operation(summary = "更新会员卡类型", description = "更新会员卡类型信息,需验证管理员密码")
|
||||
@Operation(summary = "更新会员卡类型", description = "更新会员卡类型信息")
|
||||
public Mono<ServerResponse> updateMemberCard(ServerRequest request) {
|
||||
Long adminId = authUtil.getMemberIdOrThrow(request);
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
String adminPassword = request.queryParam("adminPassword").orElse(null);
|
||||
|
||||
if (adminPassword == null || adminPassword.isBlank()) {
|
||||
return ServerResponse.badRequest()
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.bodyValue(Map.of("code", 400, "message", "管理员密码不能为空"))
|
||||
.flatMap(resp -> Mono.just(resp));
|
||||
}
|
||||
|
||||
return sysUserService.verifyPassword(adminId, adminPassword)
|
||||
.flatMap(valid -> {
|
||||
if (!valid) {
|
||||
return ServerResponse.status(HttpStatus.FORBIDDEN)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.bodyValue(Map.of("code", 403, "message", "管理员密码错误"))
|
||||
.flatMap(resp -> Mono.just(resp));
|
||||
}
|
||||
return request.bodyToMono(MemberCard.class)
|
||||
.flatMap(body -> memberCardService.findByMemberCardIdAndDeletedAtIsNull(id)
|
||||
.flatMap(existing -> {
|
||||
existing.setMemberCardName(body.getMemberCardName());
|
||||
existing.setMemberCardType(body.getMemberCardType());
|
||||
existing.setMemberCardPrice(body.getMemberCardPrice());
|
||||
existing.setMemberCardValidityDays(body.getMemberCardValidityDays());
|
||||
existing.setMemberCardTotalTimes(body.getMemberCardTotalTimes());
|
||||
existing.setMemberCardAmount(body.getMemberCardAmount());
|
||||
existing.setMemberCardStatus(body.getMemberCardStatus());
|
||||
return memberCardService.save(existing);
|
||||
})
|
||||
.flatMap(updated -> ServerResponse.ok().bodyValue(updated))
|
||||
.switchIfEmpty(ServerResponse.notFound().build()));
|
||||
});
|
||||
return memberCardService.findByMemberCardIdAndDeletedAtIsNull(id)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("会员卡不存在: " + id)))
|
||||
.zipWith(request.bodyToMono(MemberCard.class))
|
||||
.flatMap(tuple -> {
|
||||
MemberCard existing = tuple.getT1();
|
||||
MemberCard body = tuple.getT2();
|
||||
// 仅更新非 null 字段,避免 null 覆盖已有值
|
||||
if (body.getMemberCardName() != null) existing.setMemberCardName(body.getMemberCardName());
|
||||
if (body.getMemberCardType() != null) existing.setMemberCardType(body.getMemberCardType());
|
||||
if (body.getMemberCardPrice() != null) existing.setMemberCardPrice(body.getMemberCardPrice());
|
||||
if (body.getMemberCardValidityDays() != null) existing.setMemberCardValidityDays(body.getMemberCardValidityDays());
|
||||
if (body.getMemberCardTotalTimes() != null) existing.setMemberCardTotalTimes(body.getMemberCardTotalTimes());
|
||||
if (body.getMemberCardAmount() != null) existing.setMemberCardAmount(body.getMemberCardAmount());
|
||||
if (body.getMemberCardStatus() != null) existing.setMemberCardStatus(body.getMemberCardStatus());
|
||||
if (body.getExtraConfig() != null) existing.setExtraConfig(body.getExtraConfig());
|
||||
return memberCardService.save(existing);
|
||||
})
|
||||
.flatMap(updated -> ServerResponse.ok().bodyValue(updated));
|
||||
}
|
||||
|
||||
@Operation(summary = "删除会员卡类型", description = "逻辑删除会员卡类型,需验证管理员密码")
|
||||
@Operation(summary = "删除会员卡类型", description = "逻辑删除会员卡类型")
|
||||
public Mono<ServerResponse> deleteMemberCard(ServerRequest request) {
|
||||
Long adminId = authUtil.getMemberIdOrThrow(request);
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
String adminPassword = request.queryParam("adminPassword").orElse(null);
|
||||
|
||||
if (adminPassword == null || adminPassword.isBlank()) {
|
||||
return ServerResponse.badRequest()
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.bodyValue(Map.of("code", 400, "message", "管理员密码不能为空"))
|
||||
.flatMap(resp -> Mono.just(resp));
|
||||
}
|
||||
|
||||
return sysUserService.verifyPassword(adminId, adminPassword)
|
||||
.flatMap(valid -> {
|
||||
if (!valid) {
|
||||
return ServerResponse.status(HttpStatus.FORBIDDEN)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.bodyValue(Map.of("code", 403, "message", "管理员密码错误"))
|
||||
.flatMap(resp -> Mono.just(resp));
|
||||
return memberCardService.logicalDelete(id)
|
||||
.flatMap(rows -> {
|
||||
if (rows > 0) {
|
||||
return ServerResponse.noContent().build();
|
||||
}
|
||||
return memberCardService.logicalDelete(id)
|
||||
.flatMap(rows -> {
|
||||
if (rows > 0) {
|
||||
return ServerResponse.noContent().build();
|
||||
}
|
||||
return ServerResponse.notFound().build();
|
||||
});
|
||||
return ServerResponse.notFound().build();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+20
-37
@@ -1,7 +1,7 @@
|
||||
package cn.novalon.gym.manage.member.handler;
|
||||
|
||||
import cn.novalon.gym.manage.common.exception.NotFoundException;
|
||||
import cn.novalon.gym.manage.member.dto.AdminEditMemberDto;
|
||||
import cn.novalon.gym.manage.member.config.WechatProperties;
|
||||
import cn.novalon.gym.manage.member.dto.AdminUpdatePhoneDto;
|
||||
import cn.novalon.gym.manage.member.dto.SearchMemberDto;
|
||||
import cn.novalon.gym.manage.member.dto.UpdateMemberInfoDto;
|
||||
@@ -10,8 +10,8 @@ import cn.novalon.gym.manage.member.service.WechatAuthService;
|
||||
import cn.novalon.gym.manage.member.service.WechatOfficialService;
|
||||
import cn.novalon.gym.manage.member.util.AesUtil;
|
||||
import cn.novalon.gym.manage.member.util.WechatPhoneUtil;
|
||||
import cn.novalon.gym.manage.sys.core.service.ISysUserService;
|
||||
import cn.novalon.gym.manage.sys.util.AuthUtil;
|
||||
import cn.novalon.gym.manage.sys.security.JwtTokenProvider;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -24,8 +24,6 @@ import org.springframework.web.reactive.function.server.ServerRequest;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 会员信息处理器
|
||||
*
|
||||
@@ -43,7 +41,6 @@ public class MemberHandler {
|
||||
private final WechatAuthService wechatAuthService;
|
||||
private final WechatOfficialService wechatOfficialService;
|
||||
private final AuthUtil authUtil;
|
||||
private final ISysUserService sysUserService;
|
||||
|
||||
@Operation(summary = "获取会员信息", description = "根据当前登录用户获取会员基本信息")
|
||||
public Mono<ServerResponse> getMemberInfo(ServerRequest request) {
|
||||
@@ -158,8 +155,8 @@ public class MemberHandler {
|
||||
String decryptedPhone = AesUtil.decrypt(detail.getPhone());
|
||||
detail.setPhone(WechatPhoneUtil.maskPhone(decryptedPhone));
|
||||
} catch (Exception e) {
|
||||
log.error("手机号解密失败, memberId: {}", detail.getId(), e);
|
||||
detail.setPhone(null);
|
||||
log.warn("手机号解密失败(可能为明文存储), memberId: {}", detail.getId());
|
||||
detail.setPhone(WechatPhoneUtil.maskPhone(detail.getPhone()));
|
||||
}
|
||||
}
|
||||
return ServerResponse.ok()
|
||||
@@ -168,7 +165,7 @@ public class MemberHandler {
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "管理员编辑会员信息", description = "后台管理员编辑会员信息,需验证管理员密码")
|
||||
@Operation(summary = "管理员编辑会员信息", description = "后台管理员编辑会员信息")
|
||||
public Mono<ServerResponse> adminUpdateMemberInfo(ServerRequest request) {
|
||||
|
||||
Long adminId = authUtil.getMemberIdOrThrow(request);
|
||||
@@ -177,30 +174,14 @@ public class MemberHandler {
|
||||
long memberId = NumberUtils.toLong(memberIdStr, 0L);
|
||||
if(memberId <= 0L) throw new IllegalArgumentException("会员ID格式错误");
|
||||
|
||||
// TODO: 补充签到记录
|
||||
log.info("前台编辑会员信息, adminId: {}, memberId: {}", adminId, memberId);
|
||||
|
||||
return request.bodyToMono(AdminEditMemberDto.class)
|
||||
.flatMap(dto -> {
|
||||
if (dto.getAdminPassword() == null || dto.getAdminPassword().isBlank()) {
|
||||
return ServerResponse.badRequest()
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.bodyValue(Map.of("code", 400, "message", "管理员密码不能为空"))
|
||||
.flatMap(resp -> Mono.<ServerResponse>just(resp));
|
||||
}
|
||||
return sysUserService.verifyPassword(adminId, dto.getAdminPassword())
|
||||
.flatMap(valid -> {
|
||||
if (!valid) {
|
||||
return ServerResponse.status(HttpStatus.FORBIDDEN)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.bodyValue(Map.of("code", 403, "message", "管理员密码错误"))
|
||||
.flatMap(resp -> Mono.<ServerResponse>just(resp));
|
||||
}
|
||||
return memberService.adminUpdateMemberInfo(memberId, dto.toUpdateMemberInfoDto())
|
||||
.flatMap(result -> ServerResponse.ok()
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.bodyValue(result));
|
||||
});
|
||||
});
|
||||
return request.bodyToMono(UpdateMemberInfoDto.class)
|
||||
.flatMap(updateDto -> memberService.adminUpdateMemberInfo(memberId, updateDto))
|
||||
.flatMap(detail -> ServerResponse.ok()
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.bodyValue(detail));
|
||||
}
|
||||
|
||||
@Operation(summary = "搜索会员列表", description = "后台管理员按关键词搜索会员,支持性别筛选和分页")
|
||||
@@ -223,8 +204,8 @@ public class MemberHandler {
|
||||
String decryptedPhone = AesUtil.decrypt(member.getPhone());
|
||||
member.setPhone(WechatPhoneUtil.maskPhone(decryptedPhone));
|
||||
} catch (Exception e) {
|
||||
log.error("手机号解密失败, memberId: {}", member.getId(), e);
|
||||
member.setPhone(null);
|
||||
log.warn("手机号解密失败(可能为明文存储), memberId: {}", member.getId());
|
||||
member.setPhone(WechatPhoneUtil.maskPhone(member.getPhone()));
|
||||
}
|
||||
}
|
||||
return member;
|
||||
@@ -241,11 +222,13 @@ public class MemberHandler {
|
||||
|
||||
int pageNum = NumberUtils.toInt(request.queryParam("pageNum").orElse("1"), 1);
|
||||
int pageSize = NumberUtils.toInt(request.queryParam("pageSize").orElse("10"), 10);
|
||||
String sortField = request.queryParam("sortField").orElse(null);
|
||||
String sortOrder = request.queryParam("sortOrder").orElse(null);
|
||||
|
||||
log.info("前台查看会员列表, adminId: {}, pageNum: {}, pageSize: {}", adminId, pageNum, pageSize);
|
||||
// TODO: 补充签到记录
|
||||
log.info("前台查看会员列表, adminId: {}, pageNum: {}, pageSize: {}, sortField: {}, sortOrder: {}",
|
||||
adminId, pageNum, pageSize, sortField, sortOrder);
|
||||
|
||||
return memberService.findAll(pageNum, pageSize)
|
||||
return memberService.findAll(pageNum, pageSize, sortField, sortOrder)
|
||||
.map(member -> {
|
||||
// 解密手机号
|
||||
if (member.getPhone() != null && !member.getPhone().isEmpty()) {
|
||||
@@ -253,8 +236,8 @@ public class MemberHandler {
|
||||
String decryptedPhone = AesUtil.decrypt(member.getPhone());
|
||||
member.setPhone(WechatPhoneUtil.maskPhone(decryptedPhone));
|
||||
} catch (Exception e) {
|
||||
log.error("手机号解密失败, memberId: {}", member.getId(), e);
|
||||
member.setPhone(null);
|
||||
log.warn("手机号解密失败(可能为明文存储), memberId: {}", member.getId());
|
||||
member.setPhone(WechatPhoneUtil.maskPhone(member.getPhone()));
|
||||
}
|
||||
}
|
||||
return member;
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ public interface MemberCardRepository extends R2dbcRepository<MemberCard, Long>
|
||||
"AND (:type IS NULL OR member_card_type = :type) " +
|
||||
"AND (:minPrice IS NULL OR member_card_price >= :minPrice) " +
|
||||
"AND (:maxPrice IS NULL OR member_card_price <= :maxPrice) " +
|
||||
"ORDER BY created_at DESC LIMIT :#{#pageable.pageSize} OFFSET :#{#pageable.offset}")
|
||||
"ORDER BY id ASC LIMIT :#{#pageable.pageSize} OFFSET :#{#pageable.offset}")
|
||||
Flux<MemberCard> findWithConditions(Integer status, String name, String type,
|
||||
Double minPrice, Double maxPrice, Pageable pageable);
|
||||
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ public interface MemberService {
|
||||
* @param pageSize 页大小
|
||||
* @return 所有会员信息
|
||||
*/
|
||||
Flux<Member> findAll(Integer pageNum, Integer pageSize);
|
||||
Flux<Member> findAll(Integer pageNum, Integer pageSize, String sortField, String sortOrder);
|
||||
|
||||
/**
|
||||
* 前台管理端获取会员详情(含会员卡信息)
|
||||
|
||||
+63
-56
@@ -26,6 +26,7 @@ import jakarta.annotation.PostConstruct;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import reactor.core.publisher.Flux;
|
||||
@@ -230,13 +231,31 @@ public class MemberServiceImpl implements MemberService {
|
||||
);
|
||||
}
|
||||
|
||||
/** 合法的排序字段白名单,key=前端传值, value=数据库字段名 */
|
||||
private static final java.util.Map<String, String> ALLOWED_SORT_FIELDS = java.util.Map.of(
|
||||
"createdAt", "created_at",
|
||||
"memberNo", "member_no",
|
||||
"gender", "gender",
|
||||
"id", "id"
|
||||
);
|
||||
|
||||
@Override
|
||||
public Flux<Member> findAll(Integer pageNum, Integer pageSize) {
|
||||
log.info("查询所有会员列表, pageNum: {}, pageSize: {}", pageNum, pageSize);
|
||||
public Flux<Member> findAll(Integer pageNum, Integer pageSize, String sortField, String sortOrder) {
|
||||
log.info("查询所有会员列表, pageNum: {}, pageSize: {}, sortField: {}, sortOrder: {}",
|
||||
pageNum, pageSize, sortField, sortOrder);
|
||||
|
||||
// 排序方向:desc(默认) / asc
|
||||
Sort.Direction direction = "asc".equalsIgnoreCase(sortOrder)
|
||||
? Sort.Direction.ASC : Sort.Direction.DESC;
|
||||
|
||||
// 排序字段白名单校验,不在白名单中则使用默认排序
|
||||
String dbField = (sortField != null && ALLOWED_SORT_FIELDS.containsKey(sortField))
|
||||
? ALLOWED_SORT_FIELDS.get(sortField) : "created_at";
|
||||
|
||||
Pageable pageable = PageRequest.of(
|
||||
pageNum - 1,
|
||||
pageSize
|
||||
pageSize,
|
||||
Sort.by(direction, dbField)
|
||||
);
|
||||
|
||||
return memberRepository.findAllBy(pageable);
|
||||
@@ -249,63 +268,51 @@ public class MemberServiceImpl implements MemberService {
|
||||
String cacheKey = MEMBER_DETAIL_CACHE_PREFIX + memberId;
|
||||
|
||||
return redisUtil.get(cacheKey, MemberDetailVO.class)
|
||||
.flatMap(cached -> {
|
||||
if (cached != null) {
|
||||
log.debug("从缓存获取会员详情, memberId: {}", memberId);
|
||||
return Mono.just(cached);
|
||||
}
|
||||
// 缓存反序列化异常,查数据库
|
||||
return queryMemberDetailFromDb(memberId, cacheKey);
|
||||
})
|
||||
.switchIfEmpty(Mono.defer(() -> {
|
||||
// 缓存不存在,查数据库
|
||||
return queryMemberDetailFromDb(memberId, cacheKey);
|
||||
}));
|
||||
}
|
||||
.filter(cached -> cached != null)
|
||||
.switchIfEmpty(Mono.defer(() ->
|
||||
memberRepository.findById(memberId)
|
||||
.switchIfEmpty(Mono.error(() -> {
|
||||
log.error("会员不存在: memberId={}", memberId);
|
||||
throw new NotFoundException(ErrorCode.NOT_FOUND_USER, "会员不存在");
|
||||
}))
|
||||
.zipWith(
|
||||
memberRepository.findCardRecordsWithCardInfoByMemberId(memberId)
|
||||
.collectList(),
|
||||
(baseInfo, cardList) -> {
|
||||
MemberDetailVO memberDetailVO = BeanConvertUtil.toBean(baseInfo, MemberDetailVO.class);
|
||||
|
||||
private Mono<MemberDetailVO> queryMemberDetailFromDb(Long memberId, String cacheKey) {
|
||||
return memberRepository.findById(memberId)
|
||||
.zipWith(
|
||||
memberRepository.findCardRecordsWithCardInfoByMemberId(memberId)
|
||||
.collectList(),
|
||||
(baseInfo, cardList) -> {
|
||||
MemberDetailVO memberDetailVO = BeanConvertUtil.toBean(baseInfo, MemberDetailVO.class);
|
||||
GenderEnum genderEnum = GenderEnum.fromCode(baseInfo.getGender());
|
||||
memberDetailVO.setGenderDesc(genderEnum.getDesc());
|
||||
|
||||
GenderEnum genderEnum = GenderEnum.fromCode(baseInfo.getGender());
|
||||
memberDetailVO.setGenderDesc(genderEnum.getDesc());
|
||||
List<MemberCardInfoVO> enrichedCards = cardList.stream()
|
||||
.peek(vo -> {
|
||||
if (vo.getMemberCardType() != null) {
|
||||
try {
|
||||
MemberCardType cardType = MemberCardType.valueOf(vo.getMemberCardType());
|
||||
vo.setMemberCardTypeDesc(cardType.getDesc());
|
||||
} catch (IllegalArgumentException e) {
|
||||
vo.setMemberCardTypeDesc(vo.getMemberCardType());
|
||||
}
|
||||
}
|
||||
if (vo.getMemberCardStatus() != null) {
|
||||
vo.setMemberCardStatusDesc(vo.getMemberCardStatus() == 1 ? "上架" : "下架");
|
||||
}
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
memberDetailVO.setMemberCards(enrichedCards);
|
||||
|
||||
List<MemberCardInfoVO> enrichedCards = cardList.stream()
|
||||
.peek(vo -> {
|
||||
if (vo.getMemberCardType() != null) {
|
||||
try {
|
||||
MemberCardType cardType = MemberCardType.valueOf(vo.getMemberCardType());
|
||||
vo.setMemberCardTypeDesc(cardType.getDesc());
|
||||
} catch (IllegalArgumentException e) {
|
||||
vo.setMemberCardTypeDesc(vo.getMemberCardType());
|
||||
}
|
||||
long activeCount = enrichedCards.stream()
|
||||
.filter(card -> card.getMemberCardStatus() != null && card.getMemberCardStatus() == 1)
|
||||
.count();
|
||||
memberDetailVO.setActiveCardCount((int) activeCount);
|
||||
memberDetailVO.setInactiveCardCount(enrichedCards.size() - (int) activeCount);
|
||||
|
||||
return memberDetailVO;
|
||||
}
|
||||
if (vo.getMemberCardStatus() != null) {
|
||||
vo.setMemberCardStatusDesc(vo.getMemberCardStatus() == 1 ? "上架" : "下架");
|
||||
}
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
memberDetailVO.setMemberCards(enrichedCards);
|
||||
|
||||
long activeCount = enrichedCards.stream()
|
||||
.filter(card -> card.getMemberCardStatus() != null && card.getMemberCardStatus() == 1)
|
||||
.count();
|
||||
memberDetailVO.setActiveCardCount((int) activeCount);
|
||||
memberDetailVO.setInactiveCardCount(enrichedCards.size() - (int) activeCount);
|
||||
|
||||
return memberDetailVO;
|
||||
}
|
||||
)
|
||||
.flatMap(vo -> redisUtil.setWithExpire(cacheKey, vo, CACHE_EXPIRE_SECONDS)
|
||||
.then(Mono.just(vo)))
|
||||
.switchIfEmpty(Mono.error(() -> {
|
||||
log.error("会员不存在: memberId={}", memberId);
|
||||
return new NotFoundException(ErrorCode.NOT_FOUND_USER, "会员不存在");
|
||||
}));
|
||||
)
|
||||
.flatMap(vo -> redisUtil.setWithExpire(cacheKey, vo, CACHE_EXPIRE_SECONDS)
|
||||
.then(Mono.just(vo)))
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
|
||||
+22
-3
@@ -43,12 +43,25 @@ public class WechatApiServiceImpl implements WechatApiService {
|
||||
|
||||
@Override
|
||||
public Mono<Map<String, String>> jsCode2Session(String code) {
|
||||
log.info("微信jsCode2Session API");
|
||||
log.info("信息 - AppID: {}, AppSecret {}",
|
||||
log.info("微信jsCode2Session API, code: {}", code);
|
||||
|
||||
// Mock模式:返回模拟数据
|
||||
if (wechatProperties.getMockEnabled() != null && wechatProperties.getMockEnabled()) {
|
||||
log.info("Mock模式已启用,返回模拟微信登录数据");
|
||||
Map<String, String> mockResult = new HashMap<>();
|
||||
// 使用 code 的哈希生成唯一的 openid,确保每次登录创建不同用户
|
||||
String mockOpenId = "mock_openid_" + Math.abs(code.hashCode() % 1000000);
|
||||
mockResult.put("openid", mockOpenId);
|
||||
mockResult.put("session_key", "mock_session_key");
|
||||
mockResult.put("unionid", "mock_unionid_" + Math.abs(code.hashCode() % 1000000));
|
||||
log.info("Mock微信API响应成功, openid: {}, unionid: {}", mockOpenId, mockResult.get("unionid"));
|
||||
return Mono.just(mockResult);
|
||||
}
|
||||
|
||||
log.info("真实微信API调用 - AppID: {}, AppSecret {}",
|
||||
wechatProperties.getMiniapp().getAppId(),
|
||||
wechatProperties.getMiniapp().getAppSecret() != null ?
|
||||
wechatProperties.getMiniapp().getAppSecret().substring(0, Math.min(4, wechatProperties.getMiniapp().getAppSecret().length())) + "***" : "null");
|
||||
log.info(" - code: {}", code);
|
||||
|
||||
return webClient.get()
|
||||
.uri(uriBuilder -> uriBuilder
|
||||
@@ -152,6 +165,12 @@ public class WechatApiServiceImpl implements WechatApiService {
|
||||
public Mono<String> getAccessToken(String appType) {
|
||||
log.debug("获取access_token, appType: {}", appType);
|
||||
|
||||
// Mock模式:返回模拟access_token
|
||||
if (wechatProperties.getMockEnabled() != null && wechatProperties.getMockEnabled()) {
|
||||
log.debug("Mock模式已启用,返回模拟access_token");
|
||||
return Mono.just("mock_access_token");
|
||||
}
|
||||
|
||||
String cacheKey = ACCESS_TOKEN_CACHE_PREFIX + appType;
|
||||
|
||||
return redisUtil.get(cacheKey, String.class)
|
||||
|
||||
-54
@@ -1,54 +0,0 @@
|
||||
package cn.novalon.gym.manage.payment.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 支付记录响应DTO
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "支付记录")
|
||||
public class PaymentRecordResponse {
|
||||
|
||||
@Schema(description = "订单ID")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "订单号")
|
||||
private String orderNo;
|
||||
|
||||
@Schema(description = "用户编号(会员ID)")
|
||||
private Long memberId;
|
||||
|
||||
@Schema(description = "支付方式(ALIPAY/WECHAT)")
|
||||
private String tradeType;
|
||||
|
||||
@Schema(description = "购买内容(商品描述)")
|
||||
private String goodsDesc;
|
||||
|
||||
@Schema(description = "订单类型(MEMBER_CARD/GROUP_COURSE/GOODS)")
|
||||
private String orderType;
|
||||
|
||||
@Schema(description = "支付金额(元)")
|
||||
private BigDecimal transAmt;
|
||||
|
||||
@Schema(description = "支付状态(PENDING/SUCCESS/FAIL/CLOSED)")
|
||||
private String payStatus;
|
||||
|
||||
@Schema(description = "支付时间")
|
||||
private String payTime;
|
||||
|
||||
@Schema(description = "汇付流水号")
|
||||
private String hfSeqId;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private String createdAt;
|
||||
}
|
||||
-47
@@ -1,47 +0,0 @@
|
||||
package cn.novalon.gym.manage.payment.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 营业额统计数据
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "营业额统计数据")
|
||||
public class RevenueStatistics {
|
||||
|
||||
@Schema(description = "今日收入(元)")
|
||||
private BigDecimal todayIncome;
|
||||
|
||||
@Schema(description = "今日退款(元)")
|
||||
private BigDecimal todayRefund;
|
||||
|
||||
@Schema(description = "今日订单数")
|
||||
private Long todayOrderCount;
|
||||
|
||||
@Schema(description = "当月收入(元)")
|
||||
private BigDecimal monthIncome;
|
||||
|
||||
@Schema(description = "当月退款(元)")
|
||||
private BigDecimal monthRefund;
|
||||
|
||||
@Schema(description = "当月订单数")
|
||||
private Long monthOrderCount;
|
||||
|
||||
@Schema(description = "当年收入(元)")
|
||||
private BigDecimal yearIncome;
|
||||
|
||||
@Schema(description = "当年退款(元)")
|
||||
private BigDecimal yearRefund;
|
||||
|
||||
@Schema(description = "当年订单数")
|
||||
private Long yearOrderCount;
|
||||
}
|
||||
-74
@@ -1,74 +0,0 @@
|
||||
package cn.novalon.gym.manage.payment.handler;
|
||||
|
||||
import cn.novalon.gym.manage.payment.dto.ApiResponse;
|
||||
import cn.novalon.gym.manage.payment.service.PaymentService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* 支付营业数据 Handler
|
||||
*
|
||||
* @author system
|
||||
* @date 2026-06-29
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@Tag(name = "支付营业数据", description = "营业额统计与支付记录查询")
|
||||
public class PaymentRevenueHandler {
|
||||
|
||||
private final PaymentService paymentService;
|
||||
|
||||
public PaymentRevenueHandler(PaymentService paymentService) {
|
||||
this.paymentService = paymentService;
|
||||
}
|
||||
|
||||
@Operation(summary = "获取营业额统计", description = "获取今日、当月、当年的收入和退款情况")
|
||||
public Mono<ServerResponse> getRevenueStatistics(ServerRequest request) {
|
||||
log.info("[Revenue] 查询营业额统计");
|
||||
|
||||
return paymentService.getRevenueStatistics()
|
||||
.flatMap(stats -> ServerResponse.ok()
|
||||
.bodyValue(ApiResponse.success(stats)))
|
||||
.onErrorResume(e -> {
|
||||
log.error("[Revenue] 查询营业额统计失败", e);
|
||||
return ServerResponse.ok()
|
||||
.bodyValue(ApiResponse.error("查询营业额统计失败: " + e.getMessage()));
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "查询支付记录", description = "分页查询用户支付记录,支持按会员ID、支付状态、支付方式筛选")
|
||||
public Mono<ServerResponse> getPaymentRecords(ServerRequest request) {
|
||||
String memberIdStr = request.queryParam("memberId").orElse(null);
|
||||
Long memberId = null;
|
||||
if (memberIdStr != null && !memberIdStr.isEmpty()) {
|
||||
try {
|
||||
memberId = Long.parseLong(memberIdStr);
|
||||
} catch (NumberFormatException e) {
|
||||
return ServerResponse.ok()
|
||||
.bodyValue(ApiResponse.error("会员ID格式不正确"));
|
||||
}
|
||||
}
|
||||
|
||||
String payStatus = request.queryParam("payStatus").orElse(null);
|
||||
String tradeType = request.queryParam("tradeType").orElse(null);
|
||||
int page = Integer.parseInt(request.queryParam("page").orElse("1"));
|
||||
int pageSize = Integer.parseInt(request.queryParam("pageSize").orElse("20"));
|
||||
|
||||
log.info("[Revenue] 查询支付记录: memberId={}, payStatus={}, tradeType={}, page={}, pageSize={}",
|
||||
memberId, payStatus, tradeType, page, pageSize);
|
||||
|
||||
return paymentService.getPaymentRecords(memberId, payStatus, tradeType, page, pageSize)
|
||||
.flatMap(result -> ServerResponse.ok()
|
||||
.bodyValue(ApiResponse.success(result)))
|
||||
.onErrorResume(e -> {
|
||||
log.error("[Revenue] 查询支付记录失败", e);
|
||||
return ServerResponse.ok()
|
||||
.bodyValue(ApiResponse.error("查询支付记录失败: " + e.getMessage()));
|
||||
});
|
||||
}
|
||||
}
|
||||
-21
@@ -8,7 +8,6 @@ import org.springframework.stereotype.Repository;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Repository
|
||||
@@ -39,24 +38,4 @@ public interface PaymentOrderRepository extends R2dbcRepository<PaymentOrder, Lo
|
||||
Flux<PaymentOrder> findAllByDeletedAtIsNull();
|
||||
|
||||
Flux<PaymentOrder> findByMemberIdAndDeletedAtIsNull(Long memberId);
|
||||
|
||||
// ===== 营业额统计 =====
|
||||
|
||||
/** 统计指定时间范围内成功支付的金额总和 */
|
||||
@Query("SELECT COALESCE(SUM(trans_amt), 0) FROM payment_order WHERE pay_status = 'SUCCESS' AND pay_time >= :startTime AND pay_time < :endTime AND deleted_at IS NULL")
|
||||
Mono<BigDecimal> sumSuccessAmount(LocalDateTime startTime, LocalDateTime endTime);
|
||||
|
||||
/** 统计指定时间范围内的成功订单数 */
|
||||
@Query("SELECT COUNT(*) FROM payment_order WHERE pay_status = 'SUCCESS' AND pay_time >= :startTime AND pay_time < :endTime AND deleted_at IS NULL")
|
||||
Mono<Long> countSuccessOrders(LocalDateTime startTime, LocalDateTime endTime);
|
||||
|
||||
// ===== 支付记录分页查询 =====
|
||||
|
||||
/** 按条件分页查询支付记录 */
|
||||
@Query("SELECT * FROM payment_order WHERE (:memberId IS NULL OR member_id = :memberId) AND (:payStatus IS NULL OR pay_status = :payStatus) AND (:tradeType IS NULL OR trade_type = :tradeType) AND deleted_at IS NULL ORDER BY created_at DESC LIMIT :limit OFFSET :offset")
|
||||
Flux<PaymentOrder> findPaymentRecords(Long memberId, String payStatus, String tradeType, int limit, int offset);
|
||||
|
||||
/** 按条件统计支付记录总数 */
|
||||
@Query("SELECT COUNT(*) FROM payment_order WHERE (:memberId IS NULL OR member_id = :memberId) AND (:payStatus IS NULL OR pay_status = :payStatus) AND (:tradeType IS NULL OR trade_type = :tradeType) AND deleted_at IS NULL")
|
||||
Mono<Long> countPaymentRecords(Long memberId, String payStatus, String tradeType);
|
||||
}
|
||||
|
||||
-8
@@ -1,9 +1,7 @@
|
||||
package cn.novalon.gym.manage.payment.service;
|
||||
|
||||
import cn.novalon.gym.manage.payment.dto.CreatePaymentRequest;
|
||||
import cn.novalon.gym.manage.payment.dto.PaymentRecordResponse;
|
||||
import cn.novalon.gym.manage.payment.dto.PaymentResponse;
|
||||
import cn.novalon.gym.manage.payment.dto.RevenueStatistics;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -32,10 +30,4 @@ public interface PaymentService {
|
||||
Mono<PaymentResponse> getPendingOrder(Long memberId, String orderType);
|
||||
|
||||
Mono<Boolean> closeOrder(Long memberId, String orderId);
|
||||
|
||||
/** 获取营业额统计(今日/当月/当年) */
|
||||
Mono<RevenueStatistics> getRevenueStatistics();
|
||||
|
||||
/** 分页查询支付记录 */
|
||||
Mono<Map<String, Object>> getPaymentRecords(Long memberId, String payStatus, String tradeType, int page, int pageSize);
|
||||
}
|
||||
-74
@@ -3,9 +3,7 @@ package cn.novalon.gym.manage.payment.service.impl;
|
||||
import cn.novalon.gym.manage.common.util.RedisUtil;
|
||||
import cn.novalon.gym.manage.payment.config.HuifuProperties;
|
||||
import cn.novalon.gym.manage.payment.dto.CreatePaymentRequest;
|
||||
import cn.novalon.gym.manage.payment.dto.PaymentRecordResponse;
|
||||
import cn.novalon.gym.manage.payment.dto.PaymentResponse;
|
||||
import cn.novalon.gym.manage.payment.dto.RevenueStatistics;
|
||||
import cn.novalon.gym.manage.payment.entity.PaymentOrder;
|
||||
import cn.novalon.gym.manage.payment.repository.PaymentOrderRepository;
|
||||
import cn.novalon.gym.manage.payment.service.PaymentNotifyService;
|
||||
@@ -936,76 +934,4 @@ public class PaymentServiceImpl implements PaymentService {
|
||||
})
|
||||
.switchIfEmpty(Mono.just(false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<RevenueStatistics> getRevenueStatistics() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
// 今日
|
||||
LocalDateTime todayStart = now.toLocalDate().atStartOfDay();
|
||||
LocalDateTime todayEnd = todayStart.plusDays(1);
|
||||
// 当月
|
||||
LocalDateTime monthStart = now.toLocalDate().withDayOfMonth(1).atStartOfDay();
|
||||
LocalDateTime monthEnd = monthStart.plusMonths(1);
|
||||
// 当年
|
||||
LocalDateTime yearStart = now.toLocalDate().withDayOfYear(1).atStartOfDay();
|
||||
LocalDateTime yearEnd = yearStart.plusYears(1);
|
||||
|
||||
Mono<BigDecimal> todayIncomeMono = paymentOrderRepository.sumSuccessAmount(todayStart, todayEnd);
|
||||
Mono<Long> todayCountMono = paymentOrderRepository.countSuccessOrders(todayStart, todayEnd);
|
||||
Mono<BigDecimal> monthIncomeMono = paymentOrderRepository.sumSuccessAmount(monthStart, monthEnd);
|
||||
Mono<Long> monthCountMono = paymentOrderRepository.countSuccessOrders(monthStart, monthEnd);
|
||||
Mono<BigDecimal> yearIncomeMono = paymentOrderRepository.sumSuccessAmount(yearStart, yearEnd);
|
||||
Mono<Long> yearCountMono = paymentOrderRepository.countSuccessOrders(yearStart, yearEnd);
|
||||
|
||||
return Mono.zip(todayIncomeMono, todayCountMono, monthIncomeMono, monthCountMono, yearIncomeMono, yearCountMono)
|
||||
.map(tuple -> RevenueStatistics.builder()
|
||||
.todayIncome(tuple.getT1() != null ? tuple.getT1() : BigDecimal.ZERO)
|
||||
.todayRefund(BigDecimal.ZERO) // 退款功能暂未实现
|
||||
.todayOrderCount(tuple.getT2() != null ? tuple.getT2() : 0L)
|
||||
.monthIncome(tuple.getT3() != null ? tuple.getT3() : BigDecimal.ZERO)
|
||||
.monthRefund(BigDecimal.ZERO) // 退款功能暂未实现
|
||||
.monthOrderCount(tuple.getT4() != null ? tuple.getT4() : 0L)
|
||||
.yearIncome(tuple.getT5() != null ? tuple.getT5() : BigDecimal.ZERO)
|
||||
.yearRefund(BigDecimal.ZERO) // 退款功能暂未实现
|
||||
.yearOrderCount(tuple.getT6() != null ? tuple.getT6() : 0L)
|
||||
.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Map<String, Object>> getPaymentRecords(Long memberId, String payStatus, String tradeType, int page, int pageSize) {
|
||||
int offset = (page - 1) * pageSize;
|
||||
|
||||
Mono<List<PaymentRecordResponse>> recordsMono = paymentOrderRepository
|
||||
.findPaymentRecords(memberId, payStatus, tradeType, pageSize, offset)
|
||||
.map(order -> PaymentRecordResponse.builder()
|
||||
.id(order.getId())
|
||||
.orderNo(order.getOrderNo())
|
||||
.memberId(order.getMemberId())
|
||||
.tradeType(order.getTradeType())
|
||||
.goodsDesc(order.getGoodsDesc())
|
||||
.orderType(order.getOrderType())
|
||||
.transAmt(order.getTransAmt())
|
||||
.payStatus(order.getPayStatus())
|
||||
.payTime(order.getPayTime() != null
|
||||
? order.getPayTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
|
||||
: null)
|
||||
.hfSeqId(order.getHfSeqId())
|
||||
.createdAt(order.getCreatedAt() != null
|
||||
? order.getCreatedAt().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
|
||||
: null)
|
||||
.build())
|
||||
.collectList();
|
||||
|
||||
Mono<Long> totalMono = paymentOrderRepository.countPaymentRecords(memberId, payStatus, tradeType);
|
||||
|
||||
return Mono.zip(recordsMono, totalMono)
|
||||
.map(tuple -> {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("records", tuple.getT1());
|
||||
result.put("total", tuple.getT2());
|
||||
result.put("page", page);
|
||||
result.put("pageSize", pageSize);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
}
|
||||
+2915
-1991
File diff suppressed because it is too large
Load Diff
+6
-34
@@ -7,11 +7,9 @@ import cn.novalon.gym.manage.file.handler.SysFileHandler;
|
||||
import cn.novalon.gym.manage.auth.handler.PhoneAuthHandler;
|
||||
import cn.novalon.gym.manage.groupcourse.handler.GroupCourseBookingHandler;
|
||||
import cn.novalon.gym.manage.groupcourse.handler.GroupCourseHandler;
|
||||
import cn.novalon.gym.manage.groupcourse.handler.BannerHandler;
|
||||
import cn.novalon.gym.manage.groupcourse.handler.GroupCourseRecommendHandler;
|
||||
import cn.novalon.gym.manage.groupcourse.handler.GroupCourseTypeHandler;
|
||||
import cn.novalon.gym.manage.groupcourse.handler.CourseLabelHandler;
|
||||
import cn.novalon.gym.manage.groupcourse.handler.CommonUploadHandler;
|
||||
import cn.novalon.gym.manage.member.handler.MemberCardHandler;
|
||||
import cn.novalon.gym.manage.member.handler.MemberCardRecordHandler;
|
||||
import cn.novalon.gym.manage.member.handler.MemberCardTransactionHandler;
|
||||
@@ -21,7 +19,6 @@ import cn.novalon.gym.manage.member.handler.WechatAuthHandler;
|
||||
import cn.novalon.gym.manage.notify.handler.SysNoticeHandler;
|
||||
import cn.novalon.gym.manage.notify.handler.SysUserMessageHandler;
|
||||
import cn.novalon.gym.manage.payment.handler.PaymentHandler;
|
||||
import cn.novalon.gym.manage.payment.handler.PaymentRevenueHandler;
|
||||
import cn.novalon.gym.manage.sys.handler.auth.PasswordDiagnosticHandler;
|
||||
import cn.novalon.gym.manage.sys.handler.auth.SysAuthHandler;
|
||||
import cn.novalon.gym.manage.sys.handler.config.SysConfigHandler;
|
||||
@@ -82,13 +79,10 @@ public class SystemRouter {
|
||||
GroupCourseRecommendHandler groupCourseRecommendHandler,
|
||||
GroupCourseTypeHandler groupCourseTypeHandler,
|
||||
CourseLabelHandler courseLabelHandler,
|
||||
BannerHandler bannerHandler,
|
||||
CheckInHandler checkInHandler,
|
||||
DataStatisticsHandler dataStatisticsHandler,
|
||||
PhoneAuthHandler phoneAuthHandler,
|
||||
PaymentHandler paymentHandler,
|
||||
PaymentRevenueHandler paymentRevenueHandler,
|
||||
CommonUploadHandler commonUploadHandler) {
|
||||
PaymentHandler paymentHandler) {
|
||||
|
||||
return route()
|
||||
// ========== 诊断路由 ==========
|
||||
@@ -176,7 +170,6 @@ public class SystemRouter {
|
||||
.POST("/api/auth/login", authHandler::login)
|
||||
.POST("/api/auth/register", authHandler::register)
|
||||
.POST("/api/auth/logout", authHandler::logout)
|
||||
.GET("/api/auth/me", authHandler::me)
|
||||
|
||||
// ========== 统计路由 ==========
|
||||
.GET("/api/stats/overview", statsHandler::getOverview)
|
||||
@@ -224,10 +217,6 @@ public class SystemRouter {
|
||||
.GET("/api/files/preview/{fileName}", fileHandler::previewFileByName)
|
||||
.DELETE("/api/files/{id}", fileHandler::deleteFile)
|
||||
|
||||
// ===== 通用文件上传(OSS)=====
|
||||
.POST("/api/upload/image", commonUploadHandler::uploadImage)
|
||||
.GET("/api/upload/presign", commonUploadHandler::presignUrl)
|
||||
|
||||
// ========== 权限路由 ==========
|
||||
.GET("/api/permissions", permissionHandler::getAllPermissions)
|
||||
.GET("/api/permissions/{id}", permissionHandler::getPermissionById)
|
||||
@@ -319,6 +308,7 @@ public class SystemRouter {
|
||||
.GET("/api/groupCourse/types/category/{category}", groupCourseTypeHandler::getGroupCourseTypesByCategory)
|
||||
.GET("/api/groupCourse/types/{id}", groupCourseTypeHandler::getGroupCourseTypeById)
|
||||
.POST("/api/groupCourse/types", groupCourseTypeHandler::createGroupCourseType)
|
||||
.POST("/api/groupCourse/types/page", groupCourseTypeHandler::getGroupCourseTypesByPage)
|
||||
.PUT("/api/groupCourse/types/{id}", groupCourseTypeHandler::updateGroupCourseType)
|
||||
.DELETE("/api/groupCourse/types/{id}", groupCourseTypeHandler::deleteGroupCourseType)
|
||||
|
||||
@@ -327,6 +317,7 @@ public class SystemRouter {
|
||||
.GET("/api/groupCourse/labels/search", courseLabelHandler::searchLabels)
|
||||
.GET("/api/groupCourse/labels/{id}", courseLabelHandler::getLabelById)
|
||||
.GET("/api/groupCourse/types/{typeId}/labels", courseLabelHandler::getLabelsByTypeId)
|
||||
.POST("/api/groupCourse/labels/page", courseLabelHandler::getLabelsByPage)
|
||||
.POST("/api/groupCourse/labels", courseLabelHandler::createLabel)
|
||||
.PUT("/api/groupCourse/labels/{id}", courseLabelHandler::updateLabel)
|
||||
.DELETE("/api/groupCourse/labels/{id}", courseLabelHandler::deleteLabel)
|
||||
@@ -352,26 +343,13 @@ public class SystemRouter {
|
||||
.POST("/api/groupCourse/recommend/{id}/enable", groupCourseRecommendHandler::enableRecommendation)
|
||||
.POST("/api/groupCourse/recommend/{id}/disable", groupCourseRecommendHandler::disableRecommendation)
|
||||
|
||||
// ========== 轮播图路由 ==========
|
||||
.GET("/api/banner/list", bannerHandler::getAllBanners)
|
||||
.GET("/api/banner/active", bannerHandler::getAllActiveBanners)
|
||||
.GET("/api/banner/{id}", bannerHandler::getBannerById)
|
||||
.POST("/api/banner", bannerHandler::createBanner)
|
||||
.PUT("/api/banner/{id}", bannerHandler::updateBanner)
|
||||
.DELETE("/api/banner/{id}", bannerHandler::deleteBanner)
|
||||
.POST("/api/banner/{id}/enable", bannerHandler::enableBanner)
|
||||
.POST("/api/banner/{id}/disable", bannerHandler::disableBanner)
|
||||
|
||||
// ===== 团课课程管理(需要放在具体路由之后)=====
|
||||
.GET("/api/groupCourse/{id}/qrcode", groupCourseHandler::getCourseQRCode)
|
||||
.POST("/api/groupCourse/{courseId}/qrsignin", groupCourseBookingHandler::qrSignIn)
|
||||
.GET("/api/groupCourse/{id}", groupCourseHandler::getGroupCourseById)
|
||||
.GET("/api/groupCourse/{id}/detail", groupCourseHandler::getGroupCourseDetailById)
|
||||
.POST("/api/groupCourse", groupCourseHandler::createGroupCourse)
|
||||
.PUT("/api/groupCourse/{id}", groupCourseHandler::updateGroupCourse)
|
||||
.DELETE("/api/groupCourse/{id}", groupCourseHandler::deleteGroupCourse)
|
||||
.POST("/api/groupCourse/{id}/cancel", groupCourseHandler::cancelGroupCourse)
|
||||
.POST("/api/groupCourse/{id}/restore", groupCourseHandler::restoreGroupCourse)
|
||||
.POST("/api/groupCourse/signin/{memberId}", groupCourseHandler::signIn)
|
||||
.POST("/api/groupCourse/search", groupCourseHandler::searchGroupCourses)
|
||||
|
||||
@@ -381,17 +359,15 @@ public class SystemRouter {
|
||||
.GET("/api/checkIn/qrcode", checkInHandler::getQRCode)
|
||||
|
||||
// ===== 签到记录管理 =====
|
||||
.GET("/api/checkIn/records/export", checkInHandler::exportSignInRecords)
|
||||
.GET("/api/checkIn/records", checkInHandler::getSignInRecords)
|
||||
.GET("/api/checkIn/records/{id}", checkInHandler::getSignInRecordById)
|
||||
|
||||
// ===== 签到统计 =====
|
||||
.GET("/api/checkIn/statistics", checkInHandler::getSignInStatistics)
|
||||
.GET("/api/checkIn/daily-stats", checkInHandler::getDailySignInStats)
|
||||
|
||||
// ===== 管理员签到记录(全员) =====
|
||||
.GET("/api/checkIn/admin/records", checkInHandler::getAllSignInRecords)
|
||||
.GET("/api/checkIn/admin/statistics", checkInHandler::getAllSignInStatistics)
|
||||
|
||||
// ===== 签到数据导出 =====
|
||||
.GET("/api/checkIn/records/export", checkInHandler::exportSignInRecords)
|
||||
|
||||
// ========================================
|
||||
// ========== 数据统计模块路由 ============
|
||||
@@ -420,10 +396,6 @@ public class SystemRouter {
|
||||
.POST("/api/payment/{orderId}/refund", paymentHandler::refundPayment)
|
||||
.POST("/api/payment/{orderId}/close", paymentHandler::closeOrder)
|
||||
|
||||
// ===== 支付营业数据 =====
|
||||
.GET("/api/payment/revenue/statistics", paymentRevenueHandler::getRevenueStatistics)
|
||||
.GET("/api/payment/revenue/records", paymentRevenueHandler::getPaymentRecords)
|
||||
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
# 微信配置(测试环境使用模拟数据)
|
||||
wechat:
|
||||
# Mock模式:true=使用模拟数据(开发测试),false=调用真实微信API(生产环境)
|
||||
mock-enabled: false
|
||||
mock-enabled: true
|
||||
|
||||
miniapp:
|
||||
app-id: ${WECHAT_MINIAPP_APP_ID}
|
||||
app-secret: ${WECHAT_MINIAPP_SECRET}
|
||||
app-id: ${WECHAT_MINIAPP_APP_ID:}
|
||||
app-secret: ${WECHAT_MINIAPP_SECRET:}
|
||||
|
||||
mp:
|
||||
app-id: ${WECHAT_MP_APP_ID}
|
||||
app-secret: ${WECHAT_MP_SECRET}
|
||||
token: ${WECHAT_MP_TOKEN}
|
||||
aes-key: ${WECHAT_MP_AESKEY}
|
||||
callback-url: ${WECHAT_MP_CALLBACK_URL}
|
||||
app-id: ${WECHAT_MP_APP_ID:}
|
||||
app-secret: ${WECHAT_MP_SECRET:}
|
||||
token: ${WECHAT_MP_TOKEN:}
|
||||
aes-key: ${WECHAT_MP_AESKEY:}
|
||||
callback-url: ${WECHAT_MP_CALLBACK_URL:}
|
||||
|
||||
# 手机号加密配置(AES-128-CBC,16字节密钥和IV,Base64编码)
|
||||
phone-encryption:
|
||||
|
||||
@@ -60,10 +60,6 @@
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-redis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
+26
-11
@@ -3,6 +3,7 @@ package cn.novalon.gym.manage.common.config;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
|
||||
@@ -11,6 +12,9 @@ import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSeriali
|
||||
import org.springframework.data.redis.serializer.RedisSerializationContext;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* Redis 配置类(响应式版本)
|
||||
*
|
||||
@@ -20,30 +24,41 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
@Configuration
|
||||
public class RedisConfig {
|
||||
|
||||
/**
|
||||
* 创建支持 Java 8 时间类型与类型信息的 ObjectMapper,用于 Redis JSON 序列化
|
||||
*/
|
||||
private ObjectMapper createRedisObjectMapper() {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JavaTimeModule javaTimeModule = new JavaTimeModule();
|
||||
javaTimeModule.addSerializer(LocalDateTime.class,
|
||||
new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
mapper.registerModule(javaTimeModule);
|
||||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
// 启用默认类型信息,确保反序列化时能还原为原始 Java 类型
|
||||
mapper.activateDefaultTyping(
|
||||
mapper.getPolymorphicTypeValidator(),
|
||||
ObjectMapper.DefaultTyping.NON_FINAL
|
||||
);
|
||||
return mapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置 ReactiveRedisTemplate
|
||||
*/
|
||||
@Bean
|
||||
public ReactiveRedisTemplate<String, Object> reactiveRedisTemplate(
|
||||
ReactiveRedisConnectionFactory connectionFactory) {
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.registerModule(new JavaTimeModule());
|
||||
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
objectMapper.activateDefaultTyping(
|
||||
objectMapper.getPolymorphicTypeValidator(),
|
||||
ObjectMapper.DefaultTyping.NON_FINAL
|
||||
);
|
||||
|
||||
GenericJackson2JsonRedisSerializer serializer = new GenericJackson2JsonRedisSerializer(objectMapper);
|
||||
GenericJackson2JsonRedisSerializer jsonSerializer =
|
||||
new GenericJackson2JsonRedisSerializer(createRedisObjectMapper());
|
||||
|
||||
// 配置序列化上下文
|
||||
RedisSerializationContext<String, Object> serializationContext =
|
||||
RedisSerializationContext.<String, Object>newSerializationContext()
|
||||
.key(StringRedisSerializer.UTF_8)
|
||||
.value(serializer)
|
||||
.value(jsonSerializer)
|
||||
.hashKey(StringRedisSerializer.UTF_8)
|
||||
.hashValue(serializer)
|
||||
.hashValue(jsonSerializer)
|
||||
.build();
|
||||
|
||||
return new ReactiveRedisTemplate<>(connectionFactory, serializationContext);
|
||||
|
||||
+18
@@ -12,6 +12,8 @@ public class PageRequest {
|
||||
private String sort = "id";
|
||||
private String order = "asc";
|
||||
private String keyword;
|
||||
private String status;
|
||||
private String category;
|
||||
|
||||
public int getPage() {
|
||||
return page;
|
||||
@@ -52,4 +54,20 @@ public class PageRequest {
|
||||
public void setKeyword(String keyword) {
|
||||
this.keyword = keyword;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
public void setCategory(String category) {
|
||||
this.category = category;
|
||||
}
|
||||
}
|
||||
|
||||
+11
-2
@@ -1,5 +1,6 @@
|
||||
package cn.novalon.gym.manage.common.util;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.ReactiveRedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -13,6 +14,7 @@ import java.time.Duration;
|
||||
* @author liwentao
|
||||
* @date 2026/5/15
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class RedisUtil {
|
||||
|
||||
@@ -34,12 +36,19 @@ public class RedisUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取值
|
||||
* 获取值(带类型转换)
|
||||
* filter+cast 替代 map 避免 NPE,onErrorResume 兼容旧缓存格式反序列化失败
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> Mono<T> get(String key, Class<T> clazz) {
|
||||
return reactiveRedisTemplate.opsForValue().get(key)
|
||||
.map(obj -> clazz.isInstance(obj) ? (T) obj : null);
|
||||
.filter(clazz::isInstance)
|
||||
.cast(clazz)
|
||||
.onErrorResume(e -> {
|
||||
// 旧缓存数据格式不兼容时静默跳过,后续逻辑会 fallback 到 DB 查询
|
||||
log.warn("读取 Redis 缓存失败(可能为旧格式): key={}, error={}", key, e.getMessage());
|
||||
return Mono.empty();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+119
-119
@@ -1,7 +1,7 @@
|
||||
-- ============================================================
|
||||
-- V13: 整合所有测试数据(基于 2026-06-29 17:13)
|
||||
-- V13: 整合所有测试数据(基于 2026-07-14)
|
||||
-- 说明: 系统初始数据由 V2 处理,本文件仅包含业务测试数据
|
||||
-- 所有时间相关字段已更新为基于 2026-06-29
|
||||
-- 所有时间相关字段已更新为基于 2026-07-14
|
||||
-- ============================================================
|
||||
|
||||
-- ============================================================
|
||||
@@ -84,38 +84,38 @@ INSERT INTO member_card (member_card_name, member_card_type, member_card_price,
|
||||
|
||||
-- E1: 数据统计测试会员(V14,显式 ID 1001-1012)
|
||||
INSERT INTO member_user (id, member_no, nickname, phone, created_at, updated_at, is_deleted) VALUES
|
||||
(1001, 'M20260629001', '张三', '13800138001', '2026-06-29 08:00:00', '2026-06-29 08:00:00', false),
|
||||
(1002, 'M20260629002', '李四', '13800138002', '2026-06-29 09:00:00', '2026-06-29 09:00:00', false),
|
||||
(1003, 'M20260628003', '王五', '13800138003', '2026-06-28 10:00:00', '2026-06-28 10:00:00', false),
|
||||
(1004, 'M20260627004', '赵六', '13800138004', '2026-06-27 11:00:00', '2026-06-27 11:00:00', false),
|
||||
(1005, 'M20260629005', '钱七', '13800138005', '2026-06-29 08:00:00', '2026-06-29 08:00:00', false),
|
||||
(1006, 'M20260629006', '孙八', '13800138006', '2026-06-29 09:00:00', '2026-06-29 09:00:00', false),
|
||||
(1007, 'M20260629007', '周九', '13800138007', '2026-06-29 10:00:00', '2026-06-29 10:00:00', false),
|
||||
(1008, 'M20260626008', '吴十', '13800138008', '2026-06-26 14:00:00', '2026-06-26 14:00:00', false),
|
||||
(1009, 'M20260625009', '郑十一', '13800138009', '2026-06-25 15:00:00', '2026-06-25 15:00:00', false),
|
||||
(1010, 'M20260624010', '王十二', '13800138010', '2026-06-24 16:00:00', '2026-06-24 16:00:00', false),
|
||||
(1011, 'M20260623011', '陈十三', '13800138011', '2026-06-23 17:00:00', '2026-06-23 17:00:00', false),
|
||||
(1012, 'M20260622012', '刘十四', '13800138012', '2026-06-22 18:00:00', '2026-06-22 18:00:00', false);
|
||||
(1001, 'M20260714001', '张三', '13800138001', '2026-07-14 08:00:00', '2026-07-14 08:00:00', false),
|
||||
(1002, 'M20260714002', '李四', '13800138002', '2026-07-14 09:00:00', '2026-07-14 09:00:00', false),
|
||||
(1003, 'M20260713003', '王五', '13800138003', '2026-07-13 10:00:00', '2026-07-13 10:00:00', false),
|
||||
(1004, 'M20260712004', '赵六', '13800138004', '2026-07-12 11:00:00', '2026-07-12 11:00:00', false),
|
||||
(1005, 'M20260714005', '钱七', '13800138005', '2026-07-14 08:00:00', '2026-07-14 08:00:00', false),
|
||||
(1006, 'M20260714006', '孙八', '13800138006', '2026-07-14 09:00:00', '2026-07-14 09:00:00', false),
|
||||
(1007, 'M20260714007', '周九', '13800138007', '2026-07-14 10:00:00', '2026-07-14 10:00:00', false),
|
||||
(1008, 'M20260711008', '吴十', '13800138008', '2026-07-11 14:00:00', '2026-07-11 14:00:00', false),
|
||||
(1009, 'M20260710009', '郑十一', '13800138009', '2026-07-10 15:00:00', '2026-07-10 15:00:00', false),
|
||||
(1010, 'M20260709010', '王十二', '13800138010', '2026-07-09 16:00:00', '2026-07-09 16:00:00', false),
|
||||
(1011, 'M20260708011', '陈十三', '13800138011', '2026-07-08 17:00:00', '2026-07-08 17:00:00', false),
|
||||
(1012, 'M20260707012', '刘十四', '13800138012', '2026-07-07 18:00:00', '2026-07-07 18:00:00', false);
|
||||
|
||||
-- E2: 预约场景测试会员(V10: A-G)
|
||||
INSERT INTO member_user (member_no, nickname, phone, gender, is_deleted, created_at, updated_at) VALUES
|
||||
('MEM_TEST_A', '用户A_无卡新用户', '13800001001', 1, false, '2026-06-29 10:00:00', '2026-06-29 10:00:00'),
|
||||
('MEM_TEST_B', '用户B_过期时长卡', '13800001002', 1, false, '2026-06-28 10:00:00', '2026-06-28 10:00:00'),
|
||||
('MEM_TEST_C', '会员C_有效时长卡', '13800001003', 2, false, '2026-06-28 10:00:00', '2026-06-28 10:00:00'),
|
||||
('MEM_TEST_D', '会员D_次数用尽', '13800001004', 1, false, '2026-06-28 10:00:00', '2026-06-28 10:00:00'),
|
||||
('MEM_TEST_E', '会员E_次数充足', '13800001005', 2, false, '2026-06-28 10:00:00', '2026-06-28 10:00:00'),
|
||||
('MEM_TEST_F', '会员F_储值卡余额不足', '13800001006', 1, false, '2026-06-28 10:00:00', '2026-06-28 10:00:00'),
|
||||
('MEM_TEST_G', '会员G_储值卡余额充足', '13800001007', 2, false, '2026-06-28 10:00:00', '2026-06-28 10:00:00');
|
||||
('MEM_TEST_A', '用户A_无卡新用户', '13800001001', 1, false, '2026-07-14 10:00:00', '2026-07-14 10:00:00'),
|
||||
('MEM_TEST_B', '用户B_过期时长卡', '13800001002', 1, false, '2026-07-13 10:00:00', '2026-07-13 10:00:00'),
|
||||
('MEM_TEST_C', '会员C_有效时长卡', '13800001003', 2, false, '2026-07-13 10:00:00', '2026-07-13 10:00:00'),
|
||||
('MEM_TEST_D', '会员D_次数用尽', '13800001004', 1, false, '2026-07-13 10:00:00', '2026-07-13 10:00:00'),
|
||||
('MEM_TEST_E', '会员E_次数充足', '13800001005', 2, false, '2026-07-13 10:00:00', '2026-07-13 10:00:00'),
|
||||
('MEM_TEST_F', '会员F_储值卡余额不足', '13800001006', 1, false, '2026-07-13 10:00:00', '2026-07-13 10:00:00'),
|
||||
('MEM_TEST_G', '会员G_储值卡余额充足', '13800001007', 2, false, '2026-07-13 10:00:00', '2026-07-13 10:00:00');
|
||||
|
||||
-- E3: 取消预约测试会员(V11: 张三/李四/王五)
|
||||
INSERT INTO member_user (member_no, nickname, phone, gender, is_deleted, created_at, updated_at) VALUES
|
||||
('MEM_TEST_ZHANG', '张三_时长卡用户', '13800002001', 1, false, '2026-06-28 10:00:00', '2026-06-28 10:00:00'),
|
||||
('MEM_TEST_LI', '李四_次数卡用户', '13800002002', 1, false, '2026-06-28 10:00:00', '2026-06-28 10:00:00'),
|
||||
('MEM_TEST_WANG', '王五_储值卡用户', '13800002003', 2, false, '2026-06-28 10:00:00', '2026-06-28 10:00:00');
|
||||
('MEM_TEST_ZHANG', '张三_时长卡用户', '13800002001', 1, false, '2026-07-13 10:00:00', '2026-07-13 10:00:00'),
|
||||
('MEM_TEST_LI', '李四_次数卡用户', '13800002002', 1, false, '2026-07-13 10:00:00', '2026-07-13 10:00:00'),
|
||||
('MEM_TEST_WANG', '王五_储值卡用户', '13800002003', 2, false, '2026-07-13 10:00:00', '2026-07-13 10:00:00');
|
||||
|
||||
-- E4: 时间冲突测试会员(V12)
|
||||
INSERT INTO member_user (member_no, nickname, phone, gender, is_deleted, created_at, updated_at) VALUES
|
||||
('MEM_TIME_CONFLICT', '时间冲突测试会员', '13800009999', 1, false, '2026-06-28 10:00:00', '2026-06-28 10:00:00');
|
||||
('MEM_TIME_CONFLICT', '时间冲突测试会员', '13800009999', 1, false, '2026-07-13 10:00:00', '2026-07-13 10:00:00');
|
||||
|
||||
-- ============================================================
|
||||
-- Section F: 会员卡记录
|
||||
@@ -123,67 +123,67 @@ INSERT INTO member_user (member_no, nickname, phone, gender, is_deleted, created
|
||||
|
||||
-- F1: V10 预约场景 - 6条会员卡记录
|
||||
INSERT INTO member_card_record (member_id, member_card_id, status, remaining_times, remaining_amount, expire_time, purchase_time, version, card_composition, created_at, updated_at) VALUES
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_B'), (SELECT member_card_id FROM member_card WHERE member_card_name = '30天时长卡'), 'EXPIRED', 0, 0.00, '2026-06-28 23:59:59', '2026-05-29 10:00:00', 0, '{}', '2026-05-29 10:00:00', '2026-06-29 10:00:00');
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_B'), (SELECT member_card_id FROM member_card WHERE member_card_name = '30天时长卡'), 'EXPIRED', 0, 0.00, '2026-07-13 23:59:59', '2026-06-13 10:00:00', 0, '{}', '2026-06-13 10:00:00', '2026-07-14 10:00:00');
|
||||
|
||||
INSERT INTO member_card_record (member_id, member_card_id, status, remaining_times, remaining_amount, expire_time, purchase_time, version, card_composition, created_at, updated_at) VALUES
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_C'), (SELECT member_card_id FROM member_card WHERE member_card_name = '30天时长卡'), 'ACTIVE', 0, 0.00, '2026-07-29 23:59:59', '2026-06-29 10:00:00', 0, '{}', '2026-06-29 10:00:00', '2026-06-29 10:00:00');
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_C'), (SELECT member_card_id FROM member_card WHERE member_card_name = '30天时长卡'), 'ACTIVE', 0, 0.00, '2026-08-13 23:59:59', '2026-07-14 10:00:00', 0, '{}', '2026-07-14 10:00:00', '2026-07-14 10:00:00');
|
||||
|
||||
INSERT INTO member_card_record (member_id, member_card_id, status, remaining_times, remaining_amount, expire_time, purchase_time, version, card_composition, created_at, updated_at) VALUES
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_D'), (SELECT member_card_id FROM member_card WHERE member_card_name = '10次卡'), 'ACTIVE', 0, 0.00, '2026-12-31 23:59:59', '2026-05-29 10:00:00', 0, '{}', '2026-05-29 10:00:00', '2026-06-29 10:00:00');
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_D'), (SELECT member_card_id FROM member_card WHERE member_card_name = '10次卡'), 'ACTIVE', 0, 0.00, '2026-12-31 23:59:59', '2026-06-13 10:00:00', 0, '{}', '2026-06-13 10:00:00', '2026-07-14 10:00:00');
|
||||
|
||||
INSERT INTO member_card_record (member_id, member_card_id, status, remaining_times, remaining_amount, expire_time, purchase_time, version, card_composition, created_at, updated_at) VALUES
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_E'), (SELECT member_card_id FROM member_card WHERE member_card_name = '10次卡'), 'ACTIVE', 5, 0.00, '2026-12-31 23:59:59', '2026-05-29 10:00:00', 0, '{}', '2026-05-29 10:00:00', '2026-06-29 10:00:00');
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_E'), (SELECT member_card_id FROM member_card WHERE member_card_name = '10次卡'), 'ACTIVE', 5, 0.00, '2026-12-31 23:59:59', '2026-06-13 10:00:00', 0, '{}', '2026-06-13 10:00:00', '2026-07-14 10:00:00');
|
||||
|
||||
INSERT INTO member_card_record (member_id, member_card_id, status, remaining_times, remaining_amount, expire_time, purchase_time, version, card_composition, created_at, updated_at) VALUES
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_F'), (SELECT member_card_id FROM member_card WHERE member_card_name = '储值卡500'), 'ACTIVE', 0, 30.00, '2027-06-29 23:59:59', '2026-05-29 10:00:00', 0, '{}', '2026-05-29 10:00:00', '2026-06-29 10:00:00');
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_F'), (SELECT member_card_id FROM member_card WHERE member_card_name = '储值卡500'), 'ACTIVE', 0, 30.00, '2027-07-14 23:59:59', '2026-06-13 10:00:00', 0, '{}', '2026-06-13 10:00:00', '2026-07-14 10:00:00');
|
||||
|
||||
INSERT INTO member_card_record (member_id, member_card_id, status, remaining_times, remaining_amount, expire_time, purchase_time, version, card_composition, created_at, updated_at) VALUES
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_G'), (SELECT member_card_id FROM member_card WHERE member_card_name = '储值卡500'), 'ACTIVE', 0, 200.00, '2027-06-29 23:59:59', '2026-05-29 10:00:00', 0, '{}', '2026-05-29 10:00:00', '2026-06-29 10:00:00');
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_G'), (SELECT member_card_id FROM member_card WHERE member_card_name = '储值卡500'), 'ACTIVE', 0, 200.00, '2027-07-14 23:59:59', '2026-06-13 10:00:00', 0, '{}', '2026-06-13 10:00:00', '2026-07-14 10:00:00');
|
||||
|
||||
-- F2: V11 取消预约场景 - 3条
|
||||
INSERT INTO member_card_record (member_id, member_card_id, status, remaining_times, remaining_amount, expire_time, purchase_time, version, card_composition, created_at, updated_at) VALUES
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_ZHANG'), (SELECT member_card_id FROM member_card WHERE member_card_name = '30天时长卡'), 'ACTIVE', 0, 0.00, '2026-07-29 23:59:59', '2026-06-29 10:00:00', 0, '{}', '2026-06-29 10:00:00', '2026-06-29 10:00:00'),
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_LI'), (SELECT member_card_id FROM member_card WHERE member_card_name = '10次卡'), 'ACTIVE', 5, 0.00, '2026-12-31 23:59:59', '2026-05-29 10:00:00', 0, '{}', '2026-05-29 10:00:00', '2026-06-29 10:00:00'),
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_WANG'), (SELECT member_card_id FROM member_card WHERE member_card_name = '储值卡500'), 'ACTIVE', 0, 200.00, '2027-06-29 23:59:59', '2026-05-29 10:00:00', 0, '{}', '2026-05-29 10:00:00', '2026-06-29 10:00:00');
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_ZHANG'), (SELECT member_card_id FROM member_card WHERE member_card_name = '30天时长卡'), 'ACTIVE', 0, 0.00, '2026-08-13 23:59:59', '2026-07-14 10:00:00', 0, '{}', '2026-07-14 10:00:00', '2026-07-14 10:00:00'),
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_LI'), (SELECT member_card_id FROM member_card WHERE member_card_name = '10次卡'), 'ACTIVE', 5, 0.00, '2026-12-31 23:59:59', '2026-06-13 10:00:00', 0, '{}', '2026-06-13 10:00:00', '2026-07-14 10:00:00'),
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TEST_WANG'), (SELECT member_card_id FROM member_card WHERE member_card_name = '储值卡500'), 'ACTIVE', 0, 200.00, '2027-07-14 23:59:59', '2026-06-13 10:00:00', 0, '{}', '2026-06-13 10:00:00', '2026-07-14 10:00:00');
|
||||
|
||||
-- F3: V12 时间冲突场景 - 1条
|
||||
INSERT INTO member_card_record (member_id, member_card_id, status, remaining_times, remaining_amount, expire_time, purchase_time, version, card_composition, created_at, updated_at) VALUES
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TIME_CONFLICT'), (SELECT member_card_id FROM member_card WHERE member_card_name = '10次卡'), 'ACTIVE', 10, 0.00, '2026-12-31 23:59:59', '2026-06-29 10:00:00', 0, '{}', '2026-06-29 10:00:00', '2026-06-29 10:00:00');
|
||||
((SELECT id FROM member_user WHERE member_no = 'MEM_TIME_CONFLICT'), (SELECT member_card_id FROM member_card WHERE member_card_name = '10次卡'), 'ACTIVE', 10, 0.00, '2026-12-31 23:59:59', '2026-07-14 10:00:00', 0, '{}', '2026-07-14 10:00:00', '2026-07-14 10:00:00');
|
||||
|
||||
-- ============================================================
|
||||
-- Section G: 团课课程(来源 V7 / V10 / V11 / V12 / V14,基于 2026-06-29)
|
||||
-- Section G: 团课课程(来源 V7 / V10 / V11 / V12 / V14,基于 2026-07-14)
|
||||
-- ============================================================
|
||||
|
||||
-- G1: V7 - 7种场景团课
|
||||
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, create_by, created_at, updated_at) VALUES
|
||||
('极速燃脂单车', 104, 2, '2026-06-30 16:45:00', '2026-06-30 20:20:00', 25, 0, 0, '单车房', '/images/spinning.jpg', '跟随音乐节奏变换阻力和速度,体验爬坡与冲刺的快感。', 50.00, 'admin', '2026-06-29 10:00:00', '2026-06-29 10:00:00'),
|
||||
('清晨流瑜伽', 101, 1, '2026-07-03 09:00:00', '2026-07-03 10:30:00', 15, 5, 0, 'A座3楼瑜伽教室', '/images/yoga_flow.jpg', '适合有一定基础的学员,通过流畅的体式连接呼吸。', 50.00, 'admin', '2026-06-29 10:00:00', '2026-06-29 10:00:00'),
|
||||
('燃脂搏击', 102, 2, '2026-07-01 18:30:00', '2026-07-01 19:30:00', 20, 20, 0, '综合训练区', '/images/kickboxing.jpg', '高强度间歇训练,名额已满。', 50.00, 'coach_zhang', '2026-06-29 14:30:00', '2026-06-29 14:30:00'),
|
||||
('哈他瑜伽', 101, 1, '2026-06-29 17:45:00', '2026-06-29 18:50:00', 12, 3, 0, '瑜伽教室B', '/images/hatha_yoga.jpg', '基础哈他瑜伽,距开始不足30分钟,已停止预约。', 50.00, 'coach_li', '2026-06-29 08:00:00', '2026-06-29 08:00:00'),
|
||||
('周末冥想修复', 101, 1, '2026-07-11 15:00:00', '2026-07-11 16:00:00', 12, 3, 1, '冥想室', '/images/meditation.jpg', '通过呼吸和正念冥想,该课程已被取消。', 50.00, 'coach_wang', '2026-06-29 08:00:00', '2026-06-29 08:00:00'),
|
||||
('蜜桃臀塑造', 103, 3, '2026-06-23 19:00:00', '2026-06-23 20:00:00', 10, 8, 2, '私教专区', '/images/glute.jpg', '针对性训练臀部肌肉群,课程已结束。', 50.00, 'coach_li', '2026-06-23 09:15:00', '2026-06-23 09:15:00'),
|
||||
('午间冥想放松', 101, 1, '2026-06-25 12:00:00', '2026-06-25 13:00:00', 15, 6, 2, '冥想室', '/images/meditation_noon.jpg', '午间冥想课程,已结束。', 50.00, 'admin', '2026-06-25 09:00:00', '2026-06-25 09:00:00');
|
||||
('极速燃脂单车', 104, 2, '2026-07-15 16:45:00', '2026-07-15 20:20:00', 25, 0, 0, '单车房', '/images/spinning.jpg', '跟随音乐节奏变换阻力和速度,体验爬坡与冲刺的快感。', 50.00, 'admin', '2026-07-14 10:00:00', '2026-07-14 10:00:00'),
|
||||
('清晨流瑜伽', 101, 1, '2026-07-18 09:00:00', '2026-07-18 10:30:00', 15, 5, 0, 'A座3楼瑜伽教室', '/images/yoga_flow.jpg', '适合有一定基础的学员,通过流畅的体式连接呼吸。', 50.00, 'admin', '2026-07-14 10:00:00', '2026-07-14 10:00:00'),
|
||||
('燃脂搏击', 102, 2, '2026-07-16 18:30:00', '2026-07-16 19:30:00', 20, 20, 0, '综合训练区', '/images/kickboxing.jpg', '高强度间歇训练,名额已满。', 50.00, 'coach_zhang', '2026-07-14 14:30:00', '2026-07-14 14:30:00'),
|
||||
('哈他瑜伽', 101, 1, '2026-07-14 17:45:00', '2026-07-14 18:50:00', 12, 3, 0, '瑜伽教室B', '/images/hatha_yoga.jpg', '基础哈他瑜伽,距开始不足30分钟,已停止预约。', 50.00, 'coach_li', '2026-07-14 08:00:00', '2026-07-14 08:00:00'),
|
||||
('周末冥想修复', 101, 1, '2026-07-26 15:00:00', '2026-07-26 16:00:00', 12, 3, 1, '冥想室', '/images/meditation.jpg', '通过呼吸和正念冥想,该课程已被取消。', 50.00, 'coach_wang', '2026-07-14 08:00:00', '2026-07-14 08:00:00'),
|
||||
('蜜桃臀塑造', 103, 3, '2026-07-08 19:00:00', '2026-07-08 20:00:00', 10, 8, 2, '私教专区', '/images/glute.jpg', '针对性训练臀部肌肉群,课程已结束。', 50.00, 'coach_li', '2026-07-08 09:15:00', '2026-07-08 09:15:00'),
|
||||
('午间冥想放松', 101, 1, '2026-07-10 12:00:00', '2026-07-10 13:00:00', 15, 6, 2, '冥想室', '/images/meditation_noon.jpg', '午间冥想课程,已结束。', 50.00, 'admin', '2026-07-10 09:00:00', '2026-07-10 09:00:00');
|
||||
|
||||
-- G2: V10 预约场景(已取消次数卡支付,仅保留储值卡)
|
||||
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, description, stored_value_amount, create_by, created_at, updated_at) VALUES
|
||||
('燃脂搏击_储值测试', 102, 2, '2026-07-01 19:30:00', '2026-07-01 20:30:00', 20, 0, 0, '综合训练区', '消耗储值50元', 50.00, 'admin', '2026-06-29 10:00:00', '2026-06-29 10:00:00'),
|
||||
('高端普拉提_储值卡课程', 103, 1, '2026-07-02 19:00:00', '2026-07-02 20:00:00', 15, 0, 0, '普拉提教室', '消耗储值20元', 20.00, 'admin', '2026-06-29 10:00:00', '2026-06-29 10:00:00');
|
||||
('燃脂搏击_储值测试', 102, 2, '2026-07-16 19:30:00', '2026-07-16 20:30:00', 20, 0, 0, '综合训练区', '消耗储值50元', 50.00, 'admin', '2026-07-14 10:00:00', '2026-07-14 10:00:00'),
|
||||
('高端普拉提_储值卡课程', 103, 1, '2026-07-17 19:00:00', '2026-07-17 20:00:00', 15, 0, 0, '普拉提教室', '消耗储值20元', 20.00, 'admin', '2026-07-14 10:00:00', '2026-07-14 10:00:00');
|
||||
|
||||
-- G3: V11 取消预约场景
|
||||
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, description, stored_value_amount, create_by, created_at, updated_at) VALUES
|
||||
('晚间瑜伽_取消测试', 101, 1, '2026-07-02 19:00:00', '2026-07-02 20:00:00', 20, 0, 0, '瑜伽教室', '用于测试取消预约功能', 30.00, 'admin', '2026-06-29 10:00:00', '2026-06-29 10:00:00');
|
||||
('晚间瑜伽_取消测试', 101, 1, '2026-07-17 19:00:00', '2026-07-17 20:00:00', 20, 0, 0, '瑜伽教室', '用于测试取消预约功能', 30.00, 'admin', '2026-07-14 10:00:00', '2026-07-14 10:00:00');
|
||||
|
||||
-- G4: V12 时间冲突场景
|
||||
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, description, stored_value_amount, create_by, created_at, updated_at) VALUES
|
||||
('时间冲突测试_A_13点-15点', 102, 2, '2026-07-01 13:00:00', '2026-07-01 15:00:00', 20, 0, 0, '综合训练区', '测试用团课A', 50.00, 'admin', '2026-06-29 10:00:00', '2026-06-29 10:00:00'),
|
||||
('时间冲突测试_B_14点-16点', 103, 1, '2026-07-01 14:00:00', '2026-07-01 16:00:00', 15, 0, 0, '普拉提教室', '与团课A时间重叠', 50.00, 'admin', '2026-06-29 10:00:00', '2026-06-29 10:00:00'),
|
||||
('时间冲突测试_C_10点-12点', 101, 1, '2026-07-01 10:00:00', '2026-07-01 12:00:00', 15, 0, 0, '瑜伽教室', '与A/B不冲突', 50.00, 'admin', '2026-06-29 10:00:00', '2026-06-29 10:00:00');
|
||||
('时间冲突测试_A_13点-15点', 102, 2, '2026-07-16 13:00:00', '2026-07-16 15:00:00', 20, 0, 0, '综合训练区', '测试用团课A', 50.00, 'admin', '2026-07-14 10:00:00', '2026-07-14 10:00:00'),
|
||||
('时间冲突测试_B_14点-16点', 103, 1, '2026-07-16 14:00:00', '2026-07-16 16:00:00', 15, 0, 0, '普拉提教室', '与团课A时间重叠', 50.00, 'admin', '2026-07-14 10:00:00', '2026-07-14 10:00:00'),
|
||||
('时间冲突测试_C_10点-12点', 101, 1, '2026-07-16 10:00:00', '2026-07-16 12:00:00', 15, 0, 0, '瑜伽教室', '与A/B不冲突', 50.00, 'admin', '2026-07-14 10:00:00', '2026-07-14 10:00:00');
|
||||
|
||||
-- G5: V14 数据统计场景(今天 2026-06-29)
|
||||
-- G5: V14 数据统计场景(今天 2026-07-14)
|
||||
INSERT INTO group_course (id, course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, created_at, updated_at) VALUES
|
||||
(3001, '瑜伽入门', 1, 1, '2026-06-29 08:00:00', '2026-06-29 09:00:00', 20, 15, 0, '健身房A区', 'https://example.com/yoga.jpg', '适合初学者的瑜伽课程', 50.00, '2026-06-29 10:00:00', '2026-06-29 10:00:00'),
|
||||
(3002, '动感单车', 2, 2, '2026-06-29 09:30:00', '2026-06-29 10:30:00', 25, 20, 0, '健身房B区', 'https://example.com/spinning.jpg', '高强度有氧运动', 50.00, '2026-06-29 11:00:00', '2026-06-29 11:00:00'),
|
||||
(3003, '普拉提', 3, 1, '2026-06-29 14:00:00', '2026-06-29 15:00:00', 15, 10, 0, '健身房C区', 'https://example.com/pilates.jpg', '核心力量训练', 50.00, '2026-06-29 12:00:00', '2026-06-29 12:00:00');
|
||||
(3001, '瑜伽入门', 1, 1, '2026-07-14 08:00:00', '2026-07-14 09:00:00', 20, 15, 0, '健身房A区', 'https://example.com/yoga.jpg', '适合初学者的瑜伽课程', 50.00, '2026-07-14 10:00:00', '2026-07-14 10:00:00'),
|
||||
(3002, '动感单车', 2, 2, '2026-07-14 09:30:00', '2026-07-14 10:30:00', 25, 20, 0, '健身房B区', 'https://example.com/spinning.jpg', '高强度有氧运动', 50.00, '2026-07-14 11:00:00', '2026-07-14 11:00:00'),
|
||||
(3003, '普拉提', 3, 1, '2026-07-14 14:00:00', '2026-07-14 15:00:00', 15, 10, 0, '健身房C区', 'https://example.com/pilates.jpg', '核心力量训练', 50.00, '2026-07-14 12:00:00', '2026-07-14 12:00:00');
|
||||
|
||||
-- ============================================================
|
||||
-- Section H: 团课预约记录
|
||||
@@ -191,116 +191,116 @@ INSERT INTO group_course (id, course_name, coach_id, course_type, start_time, en
|
||||
|
||||
-- H1: V11 取消预约测试
|
||||
INSERT INTO group_course_booking (course_id, member_id, member_card_id, booking_time, status, course_name, course_start_time, course_end_time, location, created_at, updated_at) VALUES
|
||||
((SELECT id FROM group_course WHERE course_name = '晚间瑜伽_取消测试'), (SELECT id FROM member_user WHERE member_no = 'MEM_TEST_ZHANG'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_TEST_ZHANG')), '2026-06-29 11:00:00', '0', '晚间瑜伽_取消测试', '2026-07-02 19:00:00', '2026-07-02 20:00:00', '瑜伽教室', '2026-06-29 11:00:00', '2026-06-29 11:00:00'),
|
||||
((SELECT id FROM group_course WHERE course_name = '晚间瑜伽_取消测试'), (SELECT id FROM member_user WHERE member_no = 'MEM_TEST_LI'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_TEST_LI')), '2026-06-29 11:30:00', '0', '晚间瑜伽_取消测试', '2026-07-02 19:00:00', '2026-07-02 20:00:00', '瑜伽教室', '2026-06-29 11:30:00', '2026-06-29 11:30:00'),
|
||||
((SELECT id FROM group_course WHERE course_name = '晚间瑜伽_取消测试'), (SELECT id FROM member_user WHERE member_no = 'MEM_TEST_WANG'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_TEST_WANG')), '2026-06-29 12:00:00', '0', '晚间瑜伽_取消测试', '2026-07-02 19:00:00', '2026-07-02 20:00:00', '瑜伽教室', '2026-06-29 12:00:00', '2026-06-29 12:00:00');
|
||||
((SELECT id FROM group_course WHERE course_name = '晚间瑜伽_取消测试'), (SELECT id FROM member_user WHERE member_no = 'MEM_TEST_ZHANG'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_TEST_ZHANG')), '2026-07-14 11:00:00', '0', '晚间瑜伽_取消测试', '2026-07-17 19:00:00', '2026-07-17 20:00:00', '瑜伽教室', '2026-07-14 11:00:00', '2026-07-14 11:00:00'),
|
||||
((SELECT id FROM group_course WHERE course_name = '晚间瑜伽_取消测试'), (SELECT id FROM member_user WHERE member_no = 'MEM_TEST_LI'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_TEST_LI')), '2026-07-14 11:30:00', '0', '晚间瑜伽_取消测试', '2026-07-17 19:00:00', '2026-07-17 20:00:00', '瑜伽教室', '2026-07-14 11:30:00', '2026-07-14 11:30:00'),
|
||||
((SELECT id FROM group_course WHERE course_name = '晚间瑜伽_取消测试'), (SELECT id FROM member_user WHERE member_no = 'MEM_TEST_WANG'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_TEST_WANG')), '2026-07-14 12:00:00', '0', '晚间瑜伽_取消测试', '2026-07-17 19:00:00', '2026-07-17 20:00:00', '瑜伽教室', '2026-07-14 12:00:00', '2026-07-14 12:00:00');
|
||||
|
||||
UPDATE group_course SET current_members = current_members + 3 WHERE course_name = '晚间瑜伽_取消测试';
|
||||
|
||||
-- H2: V14 数据统计预约 - 今天(6月24日)
|
||||
-- H2: V14 数据统计预约 - 今天(7月14日)
|
||||
INSERT INTO group_course_booking (id, member_id, member_card_id, course_id, booking_time, status, created_at, updated_at) VALUES
|
||||
(4001, 1001, 1, 3001, '2026-06-29 08:00:00', '2', '2026-06-23 20:00:00', '2026-06-29 08:30:00'),
|
||||
(4002, 1002, 2, 3001, '2026-06-29 08:00:00', '2', '2026-06-23 21:00:00', '2026-06-29 08:30:00'),
|
||||
(4003, 1003, 3, 3001, '2026-06-29 08:00:00', '3', '2026-06-23 22:00:00', '2026-06-29 09:00:00'),
|
||||
(4004, 1004, 4, 3002, '2026-06-29 09:30:00', '2', '2026-06-23 19:00:00', '2026-06-29 09:30:00'),
|
||||
(4005, 1005, 5, 3002, '2026-06-29 09:30:00', '1', '2026-06-23 20:30:00', '2026-06-29 09:00:00'),
|
||||
(4006, 1006, 6, 3002, '2026-06-29 09:30:00', '2', '2026-06-23 21:30:00', '2026-06-29 09:30:00'),
|
||||
(4007, 1007, 7, 3003, '2026-06-29 14:00:00', '2', '2026-06-23 22:30:00', '2026-06-29 14:00:00'),
|
||||
(4008, 1008, 8, 3003, '2026-06-29 14:00:00', '3', '2026-06-29 08:00:00', '2026-06-29 14:00:00'),
|
||||
(4009, 1009, 9, 3003, '2026-06-29 14:00:00', '2', '2026-06-29 09:00:00', '2026-06-29 14:00:00'),
|
||||
(4010, 1010, 10, 3001, '2026-06-29 08:00:00', '2', '2026-06-29 07:00:00', '2026-06-29 08:00:00'),
|
||||
(4011, 1011, 11, 3002, '2026-06-29 09:30:00', '1', '2026-06-29 08:30:00', '2026-06-29 09:00:00'),
|
||||
(4012, 1012, 12, 3003, '2026-06-29 14:00:00', '2', '2026-06-29 10:00:00', '2026-06-29 14:00:00');
|
||||
(4001, 1001, 1, 3001, '2026-07-14 08:00:00', '2', '2026-07-08 20:00:00', '2026-07-14 08:30:00'),
|
||||
(4002, 1002, 2, 3001, '2026-07-14 08:00:00', '2', '2026-07-08 21:00:00', '2026-07-14 08:30:00'),
|
||||
(4003, 1003, 3, 3001, '2026-07-14 08:00:00', '3', '2026-07-08 22:00:00', '2026-07-14 09:00:00'),
|
||||
(4004, 1004, 4, 3002, '2026-07-14 09:30:00', '2', '2026-07-08 19:00:00', '2026-07-14 09:30:00'),
|
||||
(4005, 1005, 5, 3002, '2026-07-14 09:30:00', '1', '2026-07-08 20:30:00', '2026-07-14 09:00:00'),
|
||||
(4006, 1006, 6, 3002, '2026-07-14 09:30:00', '2', '2026-07-08 21:30:00', '2026-07-14 09:30:00'),
|
||||
(4007, 1007, 7, 3003, '2026-07-14 14:00:00', '2', '2026-07-08 22:30:00', '2026-07-14 14:00:00'),
|
||||
(4008, 1008, 8, 3003, '2026-07-14 14:00:00', '3', '2026-07-14 08:00:00', '2026-07-14 14:00:00'),
|
||||
(4009, 1009, 9, 3003, '2026-07-14 14:00:00', '2', '2026-07-14 09:00:00', '2026-07-14 14:00:00'),
|
||||
(4010, 1010, 10, 3001, '2026-07-14 08:00:00', '2', '2026-07-14 07:00:00', '2026-07-14 08:00:00'),
|
||||
(4011, 1011, 11, 3002, '2026-07-14 09:30:00', '1', '2026-07-14 08:30:00', '2026-07-14 09:00:00'),
|
||||
(4012, 1012, 12, 3003, '2026-07-14 14:00:00', '2', '2026-07-14 10:00:00', '2026-07-14 14:00:00');
|
||||
|
||||
-- H3: V14 数据统计预约 - 昨天(6月23日)
|
||||
-- H3: V14 数据统计预约 - 昨天(7月13日)
|
||||
INSERT INTO group_course_booking (id, member_id, member_card_id, course_id, booking_time, status, created_at, updated_at) VALUES
|
||||
(4013, 1001, 1, 3001, '2026-06-23 08:00:00', '2', '2026-06-22 20:00:00', '2026-06-23 08:30:00'),
|
||||
(4014, 1002, 2, 3001, '2026-06-23 08:00:00', '2', '2026-06-22 21:00:00', '2026-06-23 08:30:00'),
|
||||
(4015, 1003, 3, 3002, '2026-06-23 09:30:00', '3', '2026-06-22 22:00:00', '2026-06-23 09:30:00'),
|
||||
(4016, 1004, 4, 3002, '2026-06-23 09:30:00', '2', '2026-06-22 19:00:00', '2026-06-23 09:30:00'),
|
||||
(4017, 1005, 5, 3003, '2026-06-23 14:00:00', '1', '2026-06-22 20:30:00', '2026-06-23 13:00:00'),
|
||||
(4018, 1006, 6, 3003, '2026-06-23 14:00:00', '2', '2026-06-22 21:30:00', '2026-06-23 14:00:00');
|
||||
(4013, 1001, 1, 3001, '2026-07-08 08:00:00', '2', '2026-07-07 20:00:00', '2026-07-08 08:30:00'),
|
||||
(4014, 1002, 2, 3001, '2026-07-08 08:00:00', '2', '2026-07-07 21:00:00', '2026-07-08 08:30:00'),
|
||||
(4015, 1003, 3, 3002, '2026-07-08 09:30:00', '3', '2026-07-07 22:00:00', '2026-07-08 09:30:00'),
|
||||
(4016, 1004, 4, 3002, '2026-07-08 09:30:00', '2', '2026-07-07 19:00:00', '2026-07-08 09:30:00'),
|
||||
(4017, 1005, 5, 3003, '2026-07-08 14:00:00', '1', '2026-07-07 20:30:00', '2026-07-08 13:00:00'),
|
||||
(4018, 1006, 6, 3003, '2026-07-08 14:00:00', '2', '2026-07-07 21:30:00', '2026-07-08 14:00:00');
|
||||
|
||||
-- H4: V14 数据统计预约 - 前天(6月22日)
|
||||
-- H4: V14 数据统计预约 - 前天(7月12日)
|
||||
INSERT INTO group_course_booking (id, member_id, member_card_id, course_id, booking_time, status, created_at, updated_at) VALUES
|
||||
(4019, 1001, 1, 3002, '2026-06-22 09:30:00', '2', '2026-06-21 20:00:00', '2026-06-22 09:30:00'),
|
||||
(4020, 1002, 2, 3002, '2026-06-22 09:30:00', '2', '2026-06-21 21:00:00', '2026-06-22 09:30:00'),
|
||||
(4021, 1003, 3, 3003, '2026-06-22 14:00:00', '2', '2026-06-21 22:00:00', '2026-06-22 14:00:00'),
|
||||
(4022, 1004, 4, 3003, '2026-06-22 14:00:00', '3', '2026-06-21 19:00:00', '2026-06-22 14:00:00');
|
||||
(4019, 1001, 1, 3002, '2026-07-07 09:30:00', '2', '2026-07-06 20:00:00', '2026-07-07 09:30:00'),
|
||||
(4020, 1002, 2, 3002, '2026-07-07 09:30:00', '2', '2026-07-06 21:00:00', '2026-07-07 09:30:00'),
|
||||
(4021, 1003, 3, 3003, '2026-07-07 14:00:00', '2', '2026-07-06 22:00:00', '2026-07-07 14:00:00'),
|
||||
(4022, 1004, 4, 3003, '2026-07-07 14:00:00', '3', '2026-07-06 19:00:00', '2026-07-07 14:00:00');
|
||||
|
||||
-- ============================================================
|
||||
-- Section I: 签到记录(来源 V14,基于 2026-06-29)
|
||||
-- Section I: 签到记录(来源 V14,基于 2026-07-14)
|
||||
-- ============================================================
|
||||
|
||||
INSERT INTO sign_in_record (id, member_id, sign_in_time, sign_in_type, sign_in_status, source, is_delete) VALUES
|
||||
(2001, 1001, '2026-06-29 08:00:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2002, 1002, '2026-06-29 08:15:00', 'MANUAL', 'SUCCESS', 'PC_BACKEND', false),
|
||||
(2003, 1003, '2026-06-29 08:30:00', 'FACE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2004, 1004, '2026-06-29 09:00:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2005, 1005, '2026-06-29 09:15:00', 'MANUAL', 'SUCCESS', 'PC_BACKEND', false),
|
||||
(2006, 1006, '2026-06-29 09:30:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2007, 1007, '2026-06-29 10:00:00', 'FACE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2008, 1008, '2026-06-29 10:15:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2009, 1009, '2026-06-29 10:30:00', 'MANUAL', 'SUCCESS', 'PC_BACKEND', false),
|
||||
(2010, 1010, '2026-06-29 11:00:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2011, 1011, '2026-06-29 11:15:00', 'FACE', 'FAIL', 'MINI_PROGRAM', false),
|
||||
(2012, 1012, '2026-06-29 11:30:00', 'MANUAL', 'SUCCESS', 'PC_BACKEND', false);
|
||||
(2001, 1001, '2026-07-14 08:00:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2002, 1002, '2026-07-14 08:15:00', 'MANUAL', 'SUCCESS', 'PC_BACKEND', false),
|
||||
(2003, 1003, '2026-07-14 08:30:00', 'FACE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2004, 1004, '2026-07-14 09:00:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2005, 1005, '2026-07-14 09:15:00', 'MANUAL', 'SUCCESS', 'PC_BACKEND', false),
|
||||
(2006, 1006, '2026-07-14 09:30:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2007, 1007, '2026-07-14 10:00:00', 'FACE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2008, 1008, '2026-07-14 10:15:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2009, 1009, '2026-07-14 10:30:00', 'MANUAL', 'SUCCESS', 'PC_BACKEND', false),
|
||||
(2010, 1010, '2026-07-14 11:00:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2011, 1011, '2026-07-14 11:15:00', 'FACE', 'FAIL', 'MINI_PROGRAM', false),
|
||||
(2012, 1012, '2026-07-14 11:30:00', 'MANUAL', 'SUCCESS', 'PC_BACKEND', false);
|
||||
|
||||
INSERT INTO sign_in_record (id, member_id, sign_in_time, sign_in_type, sign_in_status, source, is_delete) VALUES
|
||||
(2013, 1001, '2026-06-23 07:30:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2014, 1002, '2026-06-23 08:00:00', 'MANUAL', 'SUCCESS', 'PC_BACKEND', false),
|
||||
(2015, 1003, '2026-06-23 08:30:00', 'FACE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2016, 1004, '2026-06-23 09:00:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2017, 1005, '2026-06-23 09:30:00', 'MANUAL', 'SUCCESS', 'PC_BACKEND', false),
|
||||
(2018, 1006, '2026-06-23 10:00:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2019, 1007, '2026-06-23 10:30:00', 'FACE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2020, 1008, '2026-06-23 11:00:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false);
|
||||
(2013, 1001, '2026-07-08 07:30:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2014, 1002, '2026-07-08 08:00:00', 'MANUAL', 'SUCCESS', 'PC_BACKEND', false),
|
||||
(2015, 1003, '2026-07-08 08:30:00', 'FACE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2016, 1004, '2026-07-08 09:00:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2017, 1005, '2026-07-08 09:30:00', 'MANUAL', 'SUCCESS', 'PC_BACKEND', false),
|
||||
(2018, 1006, '2026-07-08 10:00:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2019, 1007, '2026-07-08 10:30:00', 'FACE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2020, 1008, '2026-07-08 11:00:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false);
|
||||
|
||||
INSERT INTO sign_in_record (id, member_id, sign_in_time, sign_in_type, sign_in_status, source, is_delete) VALUES
|
||||
(2021, 1001, '2026-06-22 07:00:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2022, 1002, '2026-06-22 07:30:00', 'MANUAL', 'SUCCESS', 'PC_BACKEND', false),
|
||||
(2023, 1003, '2026-06-22 08:00:00', 'FACE', 'FAIL', 'MINI_PROGRAM', false),
|
||||
(2024, 1004, '2026-06-22 08:30:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2025, 1005, '2026-06-22 09:00:00', 'MANUAL', 'SUCCESS', 'PC_BACKEND', false);
|
||||
(2021, 1001, '2026-07-07 07:00:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2022, 1002, '2026-07-07 07:30:00', 'MANUAL', 'SUCCESS', 'PC_BACKEND', false),
|
||||
(2023, 1003, '2026-07-07 08:00:00', 'FACE', 'FAIL', 'MINI_PROGRAM', false),
|
||||
(2024, 1004, '2026-07-07 08:30:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||
(2025, 1005, '2026-07-07 09:00:00', 'MANUAL', 'SUCCESS', 'PC_BACKEND', false);
|
||||
|
||||
-- ============================================================
|
||||
-- Section J: 团课推荐测试数据(来源 V18,基于 2026-06-29)
|
||||
-- Section J: 团课推荐测试数据(来源 V18,基于 2026-07-14)
|
||||
-- ============================================================
|
||||
|
||||
INSERT INTO group_course_recommend (course_id, recommend_title, recommend_content, recommend_reason, priority, is_active, create_by, created_at, updated_at) VALUES
|
||||
((SELECT id FROM group_course WHERE course_name = '极速燃脂单车'), '本周热门推荐', '极速燃脂单车课程,跟随音乐节奏变换阻力和速度,体验爬坡与冲刺的快感,一节课消耗800大卡!', '教练专业,课程内容丰富,深受学员喜爱,燃脂效果显著', 20, true, 'admin', '2026-06-29 10:00:00', '2026-06-29 10:00:00');
|
||||
((SELECT id FROM group_course WHERE course_name = '极速燃脂单车'), '本周热门推荐', '极速燃脂单车课程,跟随音乐节奏变换阻力和速度,体验爬坡与冲刺的快感,一节课消耗800大卡!', '教练专业,课程内容丰富,深受学员喜爱,燃脂效果显著', 20, true, 'admin', '2026-07-14 10:00:00', '2026-07-14 10:00:00');
|
||||
|
||||
INSERT INTO group_course_recommend (course_id, recommend_title, recommend_content, recommend_reason, priority, is_active, create_by, created_at, updated_at) VALUES
|
||||
((SELECT id FROM group_course WHERE course_name = '清晨流瑜伽'), '新手友好推荐', '清晨流瑜伽课程,适合有一定基础的学员,通过流畅的体式连接呼吸,唤醒身体能量。', '适合新手入门,教练耐心指导,课程节奏适中', 15, true, 'admin', '2026-06-29 11:00:00', '2026-06-29 11:00:00');
|
||||
((SELECT id FROM group_course WHERE course_name = '清晨流瑜伽'), '新手友好推荐', '清晨流瑜伽课程,适合有一定基础的学员,通过流畅的体式连接呼吸,唤醒身体能量。', '适合新手入门,教练耐心指导,课程节奏适中', 15, true, 'admin', '2026-07-14 11:00:00', '2026-07-14 11:00:00');
|
||||
|
||||
INSERT INTO group_course_recommend (course_id, recommend_title, recommend_content, recommend_reason, priority, is_active, create_by, created_at, updated_at) VALUES
|
||||
((SELECT id FROM group_course WHERE course_name = '燃脂搏击'), '高强度燃脂', '燃脂搏击课程,高强度间歇训练,配合音乐快速燃脂,释放压力。', '高强度训练,适合进阶学员,快速燃脂塑形', 10, false, 'admin', '2026-06-29 12:00:00', '2026-06-29 12:00:00');
|
||||
((SELECT id FROM group_course WHERE course_name = '燃脂搏击'), '高强度燃脂', '燃脂搏击课程,高强度间歇训练,配合音乐快速燃脂,释放压力。', '高强度训练,适合进阶学员,快速燃脂塑形', 10, false, 'admin', '2026-07-14 12:00:00', '2026-07-14 12:00:00');
|
||||
|
||||
INSERT INTO group_course_recommend (course_id, recommend_title, recommend_content, recommend_reason, priority, is_active, create_by, created_at, updated_at) VALUES
|
||||
((SELECT id FROM group_course WHERE course_name = '哈他瑜伽'), '基础瑜伽推荐', '基础哈他瑜伽课程,适合所有级别学员,通过基础体式练习提升身体柔韧性和平衡能力。', '零基础友好,适合所有健身水平,放松身心', 12, true, 'coach_li', '2026-06-29 13:00:00', '2026-06-29 13:00:00');
|
||||
((SELECT id FROM group_course WHERE course_name = '哈他瑜伽'), '基础瑜伽推荐', '基础哈他瑜伽课程,适合所有级别学员,通过基础体式练习提升身体柔韧性和平衡能力。', '零基础友好,适合所有健身水平,放松身心', 12, true, 'coach_li', '2026-07-14 13:00:00', '2026-07-14 13:00:00');
|
||||
|
||||
INSERT INTO group_course_recommend (course_id, recommend_title, recommend_content, recommend_reason, priority, is_active, create_by, created_at, updated_at) VALUES
|
||||
((SELECT id FROM group_course WHERE course_name = '蜜桃臀塑造'), '塑形热门课程', '蜜桃臀塑造课程,针对性训练臀部肌肉群,打造完美曲线。', '专业私教指导,动作标准,效果显著,深受女性学员喜爱', 18, true, 'coach_li', '2026-06-29 09:15:00', '2026-06-29 09:15:00');
|
||||
((SELECT id FROM group_course WHERE course_name = '蜜桃臀塑造'), '塑形热门课程', '蜜桃臀塑造课程,针对性训练臀部肌肉群,打造完美曲线。', '专业私教指导,动作标准,效果显著,深受女性学员喜爱', 18, true, 'coach_li', '2026-07-14 09:15:00', '2026-07-14 09:15:00');
|
||||
|
||||
INSERT INTO group_course_recommend (course_id, recommend_title, recommend_content, recommend_reason, priority, is_active, create_by, created_at, updated_at) VALUES
|
||||
((SELECT id FROM group_course WHERE course_name = '午间冥想放松'), '午间放松推荐', '午间冥想放松课程,通过呼吸和正念冥想,深度放松身心,缓解工作压力。', '适合上班族,午间放松充电,提升下午工作效率', 8, true, 'admin', '2026-06-29 09:00:00', '2026-06-29 09:00:00');
|
||||
((SELECT id FROM group_course WHERE course_name = '午间冥想放松'), '午间放松推荐', '午间冥想放松课程,通过呼吸和正念冥想,深度放松身心,缓解工作压力。', '适合上班族,午间放松充电,提升下午工作效率', 8, true, 'admin', '2026-07-14 09:00:00', '2026-07-14 09:00:00');
|
||||
|
||||
INSERT INTO group_course_recommend (course_id, recommend_title, recommend_content, recommend_reason, priority, is_active, create_by, created_at, updated_at) VALUES
|
||||
((SELECT id FROM group_course WHERE course_name = '极速燃脂单车'), '减脂首选课程', '想要快速减脂?极速燃脂单车是你的最佳选择!专业教练带领,科学训练计划。', '减脂效果最佳,课程强度适中,适合想要快速瘦身的学员', 16, true, 'coach_zhang', '2026-06-29 14:00:00', '2026-06-29 14:00:00');
|
||||
((SELECT id FROM group_course WHERE course_name = '极速燃脂单车'), '减脂首选课程', '想要快速减脂?极速燃脂单车是你的最佳选择!专业教练带领,科学训练计划。', '减脂效果最佳,课程强度适中,适合想要快速瘦身的学员', 16, true, 'coach_zhang', '2026-07-14 14:00:00', '2026-07-14 14:00:00');
|
||||
|
||||
INSERT INTO group_course_recommend (course_id, recommend_title, recommend_content, recommend_reason, priority, is_active, create_by, created_at, updated_at) VALUES
|
||||
((SELECT id FROM group_course WHERE course_name = '清晨流瑜伽'), '晨练优选', '清晨流瑜伽,唤醒身体能量,开启活力一天!适合晨练爱好者。', '晨练最佳选择,提升身体活力,改善精神状态', 14, true, 'coach_wang', '2026-06-29 15:00:00', '2026-06-29 15:00:00');
|
||||
((SELECT id FROM group_course WHERE course_name = '清晨流瑜伽'), '晨练优选', '清晨流瑜伽,唤醒身体能量,开启活力一天!适合晨练爱好者。', '晨练最佳选择,提升身体活力,改善精神状态', 14, true, 'coach_wang', '2026-07-14 15:00:00', '2026-07-14 15:00:00');
|
||||
|
||||
INSERT INTO group_course_recommend (course_id, recommend_title, recommend_content, recommend_reason, priority, is_active, create_by, created_at, updated_at) VALUES
|
||||
((SELECT id FROM group_course WHERE course_name = '哈他瑜伽'), '身心平衡推荐', '哈他瑜伽课程,通过体式练习和呼吸控制,达到身心平衡,提升整体健康水平。', '改善身体柔韧性,增强核心力量,提升身体协调性', 11, true, 'coach_li', '2026-06-29 16:00:00', '2026-06-29 16:00:00');
|
||||
((SELECT id FROM group_course WHERE course_name = '哈他瑜伽'), '身心平衡推荐', '哈他瑜伽课程,通过体式练习和呼吸控制,达到身心平衡,提升整体健康水平。', '改善身体柔韧性,增强核心力量,提升身体协调性', 11, true, 'coach_li', '2026-07-14 16:00:00', '2026-07-14 16:00:00');
|
||||
|
||||
INSERT INTO group_course_recommend (course_id, recommend_title, recommend_content, recommend_reason, priority, is_active, create_by, created_at, updated_at) VALUES
|
||||
((SELECT id FROM group_course WHERE course_name = '午间冥想放松'), '职场减压课程', '午间冥想放松,专为职场人士设计,快速缓解工作压力,提升工作状态。', '职场减压首选,课程时间短,效果显著', 9, false, 'admin', '2026-06-29 10:00:00', '2026-06-29 10:00:00');
|
||||
((SELECT id FROM group_course WHERE course_name = '午间冥想放松'), '职场减压课程', '午间冥想放松,专为职场人士设计,快速缓解工作压力,提升工作状态。', '职场减压首选,课程时间短,效果显著', 9, false, 'admin', '2026-07-14 10:00:00', '2026-07-14 10:00:00');
|
||||
|
||||
-- ============================================================
|
||||
-- Section K: 统计说明
|
||||
-- ============================================================
|
||||
-- 今日(2026-06-29)统计预期:
|
||||
-- 今日(2026-07-14)统计预期:
|
||||
-- 新增会员: 3 (1005, 1006, 1007)
|
||||
-- 签到会员: 12
|
||||
-- 预约总数: 12 (4001-4012),取消: 2,出席: 8,缺席: 2
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
-- ============================================================
|
||||
-- V23: 教练账号测试数据
|
||||
-- 描述: 创建教练角色、教练用户及相关团课测试数据
|
||||
-- 日期: 2026-06-22
|
||||
-- 日期: 2026-07-14
|
||||
-- ============================================================
|
||||
|
||||
-- ============================================================
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
-- 1. 新增测试教练用户 coachli(李教练)
|
||||
-- 2. 为李教练分配教练角色(继承教练的有限权限)
|
||||
-- 3. 为李教练分配未来一周的测试团课
|
||||
-- 日期: 2026-06-22
|
||||
-- 日期: 2026-07-14
|
||||
-- ============================================================
|
||||
|
||||
-- ============================================================
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
-- ============================================
|
||||
-- V28: 新增业务模块菜单
|
||||
-- 描述: 为团课管理、团课类型、团课标签、团课推荐创建菜单项
|
||||
-- ============================================
|
||||
|
||||
-- 团课管理一级菜单(目录)
|
||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||
(400, '团课管理', 0, 4, 'M', NULL, NULL, 1, NOW(), NOW());
|
||||
|
||||
-- 团课管理子菜单(页面)
|
||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||
(401, '团课管理', 400, 1, 'C', 'business:groupCourse:list', 'gymCourse/course/index', 1, NOW(), NOW()),
|
||||
(402, '团课类型', 400, 2, 'C', 'business:groupCourseType:list', 'gymCourse/type/index', 1, NOW(), NOW()),
|
||||
(403, '类型标签', 400, 3, 'C', 'business:groupCourseLabel:list', 'gymCourse/label/index', 1, NOW(), NOW()),
|
||||
(404, '团课推荐', 400, 4, 'C', 'business:groupCourseRecommend:list', 'gymCourse/recommend/index', 1, NOW(), NOW());
|
||||
|
||||
-- 团课管理按钮权限
|
||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||
(4011, '团课查询', 401, 1, 'F', 'business:groupCourse:query', NULL, 1, NOW(), NOW()),
|
||||
(4012, '团课新增', 401, 2, 'F', 'business:groupCourse:add', NULL, 1, NOW(), NOW()),
|
||||
(4013, '团课修改', 401, 3, 'F', 'business:groupCourse:edit', NULL, 1, NOW(), NOW()),
|
||||
(4014, '团课删除', 401, 4, 'F', 'business:groupCourse:remove', NULL, 1, NOW(), NOW()),
|
||||
(4015, '团课取消', 401, 5, 'F', 'business:groupCourse:cancel', NULL, 1, NOW(), NOW());
|
||||
|
||||
-- 团课类型按钮权限
|
||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||
(4021, '类型查询', 402, 1, 'F', 'business:groupCourseType:query', NULL, 1, NOW(), NOW()),
|
||||
(4022, '类型新增', 402, 2, 'F', 'business:groupCourseType:add', NULL, 1, NOW(), NOW()),
|
||||
(4023, '类型修改', 402, 3, 'F', 'business:groupCourseType:edit', NULL, 1, NOW(), NOW()),
|
||||
(4024, '类型删除', 402, 4, 'F', 'business:groupCourseType:remove', NULL, 1, NOW(), NOW());
|
||||
|
||||
-- 团课标签按钮权限
|
||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||
(4031, '标签查询', 403, 1, 'F', 'business:groupCourseLabel:query', NULL, 1, NOW(), NOW()),
|
||||
(4032, '标签新增', 403, 2, 'F', 'business:groupCourseLabel:add', NULL, 1, NOW(), NOW()),
|
||||
(4033, '标签修改', 403, 3, 'F', 'business:groupCourseLabel:edit', NULL, 1, NOW(), NOW()),
|
||||
(4034, '标签删除', 403, 4, 'F', 'business:groupCourseLabel:remove', NULL, 1, NOW(), NOW());
|
||||
|
||||
-- 团课推荐按钮权限
|
||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||
(4041, '推荐查询', 404, 1, 'F', 'business:groupCourseRecommend:query', NULL, 1, NOW(), NOW()),
|
||||
(4042, '推荐新增', 404, 2, 'F', 'business:groupCourseRecommend:add', NULL, 1, NOW(), NOW()),
|
||||
(4043, '推荐修改', 404, 3, 'F', 'business:groupCourseRecommend:edit', NULL, 1, NOW(), NOW()),
|
||||
(4044, '推荐删除', 404, 4, 'F', 'business:groupCourseRecommend:remove', NULL, 1, NOW(), NOW());
|
||||
|
||||
-- 重置菜单序列
|
||||
SELECT setval('sys_menu_id_seq', (SELECT COALESCE(MAX(id), 1) FROM sys_menu));
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
-- ============================================
|
||||
-- 团课新增常态化标记
|
||||
-- ============================================
|
||||
|
||||
ALTER TABLE group_course ADD COLUMN IF NOT EXISTS is_recurring BOOLEAN DEFAULT FALSE;
|
||||
|
||||
COMMENT ON COLUMN group_course.is_recurring IS '是否常态化团课:TRUE-是,FALSE-否(默认)';
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
-- ============================================
|
||||
-- V29: 新增会员管理菜单
|
||||
-- 描述: 为会员管理功能创建菜单项
|
||||
-- ============================================
|
||||
|
||||
-- 会员管理一级菜单(目录)
|
||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||
(500, '会员管理', 0, 5, 'M', NULL, NULL, 1, NOW(), NOW());
|
||||
|
||||
-- 会员管理子菜单(页面)
|
||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||
(501, '会员管理', 500, 1, 'C', 'business:member:list', 'member/member/index', 1, NOW(), NOW());
|
||||
|
||||
-- 会员管理按钮权限
|
||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||
(5011, '会员查询', 501, 1, 'F', 'business:member:query', NULL, 1, NOW(), NOW()),
|
||||
(5012, '会员新增', 501, 2, 'F', 'business:member:add', NULL, 1, NOW(), NOW()),
|
||||
(5013, '会员修改', 501, 3, 'F', 'business:member:edit', NULL, 1, NOW(), NOW()),
|
||||
(5014, '会员删除', 501, 4, 'F', 'business:member:remove', NULL, 1, NOW(), NOW()),
|
||||
(5015, '会员详情', 501, 5, 'F', 'business:member:detail', NULL, 1, NOW(), NOW());
|
||||
|
||||
-- 重置菜单序列
|
||||
SELECT setval('sys_menu_id_seq', (SELECT COALESCE(MAX(id), 1) FROM sys_menu));
|
||||
@@ -1,36 +0,0 @@
|
||||
-- ============================================
|
||||
-- 轮播图表
|
||||
-- ============================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS banner (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
image_url TEXT NOT NULL,
|
||||
title VARCHAR(100) NOT NULL,
|
||||
subtitle VARCHAR(100),
|
||||
description TEXT,
|
||||
sort_order INTEGER DEFAULT 0,
|
||||
is_active BOOLEAN DEFAULT TRUE,
|
||||
create_by VARCHAR(50),
|
||||
update_by VARCHAR(50),
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
deleted_at TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_banner_sort_order ON banner(sort_order);
|
||||
CREATE INDEX IF NOT EXISTS idx_banner_is_active ON banner(is_active);
|
||||
CREATE INDEX IF NOT EXISTS idx_banner_deleted_at ON banner(deleted_at);
|
||||
|
||||
COMMENT ON TABLE banner IS '轮播图表';
|
||||
COMMENT ON COLUMN banner.id IS '主键ID';
|
||||
COMMENT ON COLUMN banner.image_url IS '背景图URL';
|
||||
COMMENT ON COLUMN banner.title IS '主标题';
|
||||
COMMENT ON COLUMN banner.subtitle IS '副标题';
|
||||
COMMENT ON COLUMN banner.description IS '简介';
|
||||
COMMENT ON COLUMN banner.sort_order IS '排序(数值越大越靠前)';
|
||||
COMMENT ON COLUMN banner.is_active IS '是否启用';
|
||||
COMMENT ON COLUMN banner.create_by IS '创建人';
|
||||
COMMENT ON COLUMN banner.update_by IS '更新人';
|
||||
COMMENT ON COLUMN banner.created_at IS '创建时间';
|
||||
COMMENT ON COLUMN banner.updated_at IS '更新时间';
|
||||
COMMENT ON COLUMN banner.deleted_at IS '删除时间(软删除)';
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
-- ============================================
|
||||
-- V30: 新增会员卡管理菜单
|
||||
-- 描述: 为会员卡管理功能创建菜单项
|
||||
-- ============================================
|
||||
|
||||
-- 会员卡管理一级菜单(目录)
|
||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||
(502, '会员卡管理', 0, 6, 'M', NULL, NULL, 1, NOW(), NOW());
|
||||
|
||||
-- 会员卡管理子菜单(页面)
|
||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||
(503, '会员卡管理', 502, 1, 'C', 'business:memberCard:list', 'member/card/index', 1, NOW(), NOW());
|
||||
|
||||
-- 会员卡管理按钮权限
|
||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||
(5031, '会员卡查询', 503, 1, 'F', 'business:memberCard:query', NULL, 1, NOW(), NOW()),
|
||||
(5032, '会员卡新增', 503, 2, 'F', 'business:memberCard:add', NULL, 1, NOW(), NOW()),
|
||||
(5033, '会员卡修改', 503, 3, 'F', 'business:memberCard:edit', NULL, 1, NOW(), NOW()),
|
||||
(5034, '会员卡删除', 503, 4, 'F', 'business:memberCard:remove', NULL, 1, NOW(), NOW());
|
||||
|
||||
-- 重置菜单序列
|
||||
SELECT setval('sys_menu_id_seq', (SELECT COALESCE(MAX(id), 1) FROM sys_menu));
|
||||
@@ -0,0 +1,19 @@
|
||||
-- ============================================
|
||||
-- V31: 新增数据统计菜单
|
||||
-- 描述: 为数据统计看板功能创建菜单项
|
||||
-- ============================================
|
||||
|
||||
-- 数据统计一级菜单(目录)
|
||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||
(504, '数据统计', 0, 7, 'M', NULL, NULL, 1, NOW(), NOW());
|
||||
|
||||
-- 数据统计子菜单(页面)
|
||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||
(505, '数据统计看板', 504, 1, 'C', 'business:statistics:view', 'statistics/dashboard/index', 1, NOW(), NOW());
|
||||
|
||||
-- 数据统计按钮权限
|
||||
INSERT INTO sys_menu (id, menu_name, parent_id, order_num, menu_type, perms, component, status, created_at, updated_at) VALUES
|
||||
(5051, '数据统计导出', 505, 1, 'F', 'business:statistics:export', NULL, 1, NOW(), NOW());
|
||||
|
||||
-- 重置菜单序列
|
||||
SELECT setval('sys_menu_id_seq', (SELECT COALESCE(MAX(id), 1) FROM sys_menu));
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
-- ============================================================
|
||||
-- V32: 将 group_course_booking 表的 member_card_id 改为可空
|
||||
-- 说明: 预约团课不再需要会员卡,member_card_id 允许为空
|
||||
-- 日期: 2026-07-14
|
||||
-- ============================================================
|
||||
|
||||
ALTER TABLE group_course_booking
|
||||
ALTER COLUMN member_card_id DROP NOT NULL;
|
||||
+11
@@ -15,6 +15,17 @@ public interface ISysFileService {
|
||||
|
||||
Mono<SysFile> uploadFile(FilePart filePart, String username);
|
||||
|
||||
/**
|
||||
* 保存字节数组为文件(用于服务端生成的文件,如二维码)
|
||||
*
|
||||
* @param content 文件字节内容
|
||||
* @param filename 原始文件名
|
||||
* @param contentType MIME类型
|
||||
* @param username 操作用户名
|
||||
* @return 保存后的文件信息
|
||||
*/
|
||||
Mono<SysFile> saveBytes(byte[] content, String filename, String contentType, String username);
|
||||
|
||||
Mono<Void> downloadFile(Long id);
|
||||
|
||||
Mono<Void> deleteFile(Long id);
|
||||
|
||||
+37
@@ -29,6 +29,43 @@ public class SysFileServiceImpl implements ISysFileService {
|
||||
this.uploadDir = uploadDir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<SysFile> saveBytes(byte[] content, String filename, String contentType, String username) {
|
||||
String fileExtension = filename.contains(".")
|
||||
? filename.substring(filename.lastIndexOf("."))
|
||||
: ".png";
|
||||
String newFileName = UUID.randomUUID().toString() + fileExtension;
|
||||
|
||||
Path uploadPath = Paths.get(uploadDir);
|
||||
return Mono.fromCallable(() -> {
|
||||
if (!Files.exists(uploadPath)) {
|
||||
Files.createDirectories(uploadPath);
|
||||
}
|
||||
return uploadPath;
|
||||
})
|
||||
.flatMap(path -> {
|
||||
Path filePath = path.resolve(newFileName);
|
||||
return Mono.fromCallable(() -> {
|
||||
Files.write(filePath, content);
|
||||
return filePath;
|
||||
});
|
||||
})
|
||||
.flatMap(filePath -> Mono.fromCallable(() -> {
|
||||
long fileSize = Files.size(filePath);
|
||||
|
||||
SysFile sysFile = new SysFile();
|
||||
sysFile.setFileName(filename);
|
||||
sysFile.setFilePath(filePath.toString());
|
||||
sysFile.setFileSize(fileSize);
|
||||
sysFile.setFileType(contentType != null ? contentType : "image/png");
|
||||
sysFile.setStorageType("LOCAL");
|
||||
sysFile.setCreateBy(username);
|
||||
sysFile.setCreatedAt(LocalDateTime.now());
|
||||
|
||||
return sysFile;
|
||||
}).flatMap(fileRepository::save));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<SysFile> getAllFiles() {
|
||||
return fileRepository.findByDeletedAtIsNullOrderByCreatedAtDesc();
|
||||
|
||||
@@ -106,6 +106,12 @@
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Fix commons-compress version for POI compatibility -->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-compress</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
+101
-181
@@ -9,17 +9,24 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.core.io.buffer.DataBufferUtils;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.security.core.context.ReactiveSecurityContextHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.function.server.HandlerStrategies;
|
||||
import org.springframework.web.reactive.function.server.RouterFunction;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.WebFilter;
|
||||
import org.springframework.web.server.WebFilterChain;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Component
|
||||
@Order(Ordered.LOWEST_PRECEDENCE)
|
||||
@@ -30,76 +37,19 @@ public class OperationLogWebFilter implements WebFilter {
|
||||
private final IOperationLogService operationLogService;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
/** 精确匹配的操作映射(method:path → module, operation) */
|
||||
private static final Map<String, OperationInfo> PRECISE_MAPPING = new LinkedHashMap<>();
|
||||
|
||||
/** 前缀匹配的操作映射(按声明顺序) */
|
||||
private static final Map<String, OperationInfo> PREFIX_MAPPING = new LinkedHashMap<>();
|
||||
|
||||
/** URL模块名称映射 */
|
||||
private static final Map<String, String> MODULE_NAMES = new LinkedHashMap<>();
|
||||
private static final Map<String, OperationInfo> OPERATION_MAPPING = new ConcurrentHashMap<>();
|
||||
|
||||
static {
|
||||
// ===== 精确路径匹配 =====
|
||||
PRECISE_MAPPING.put("POST:/api/roles", new OperationInfo("角色管理", "创建角色"));
|
||||
PRECISE_MAPPING.put("POST:/api/users", new OperationInfo("用户管理", "创建用户"));
|
||||
PRECISE_MAPPING.put("POST:/api/menus", new OperationInfo("菜单管理", "创建菜单"));
|
||||
PRECISE_MAPPING.put("POST:/api/auth/login", new OperationInfo("认证", "用户登录"));
|
||||
PRECISE_MAPPING.put("GET:/api/groupCourse/types/categories", new OperationInfo("团课类型", "查询分类"));
|
||||
PRECISE_MAPPING.put("POST:/api/groupCourse/types", new OperationInfo("团课类型", "创建类型"));
|
||||
PRECISE_MAPPING.put("POST:/api/groupCourse", new OperationInfo("团课管理", "创建团课"));
|
||||
PRECISE_MAPPING.put("POST:/api/member", new OperationInfo("会员管理", "创建会员"));
|
||||
PRECISE_MAPPING.put("POST:/api/member-cards", new OperationInfo("会员卡管理", "创建会员卡"));
|
||||
PRECISE_MAPPING.put("POST:/api/groupCourse/recommend", new OperationInfo("推荐管理", "创建推荐"));
|
||||
PRECISE_MAPPING.put("POST:/api/checkIn", new OperationInfo("签到管理", "签到"));
|
||||
PRECISE_MAPPING.put("POST:/api/payment/create", new OperationInfo("支付管理", "创建支付"));
|
||||
PRECISE_MAPPING.put("POST:/api/upload/image", new OperationInfo("文件管理", "上传图片"));
|
||||
|
||||
// ===== 前缀匹配 =====
|
||||
PREFIX_MAPPING.put("PUT:/api/roles/", new OperationInfo("角色管理", "更新角色"));
|
||||
PREFIX_MAPPING.put("DELETE:/api/roles/", new OperationInfo("角色管理", "删除角色"));
|
||||
PREFIX_MAPPING.put("PUT:/api/users/", new OperationInfo("用户管理", "更新用户"));
|
||||
PREFIX_MAPPING.put("DELETE:/api/users/", new OperationInfo("用户管理", "删除用户"));
|
||||
PREFIX_MAPPING.put("PUT:/api/menus/", new OperationInfo("菜单管理", "更新菜单"));
|
||||
PREFIX_MAPPING.put("DELETE:/api/menus/", new OperationInfo("菜单管理", "删除菜单"));
|
||||
PREFIX_MAPPING.put("PUT:/api/groupCourse/types/", new OperationInfo("团课类型", "更新类型"));
|
||||
PREFIX_MAPPING.put("DELETE:/api/groupCourse/types/", new OperationInfo("团课类型", "删除类型"));
|
||||
PREFIX_MAPPING.put("PUT:/api/groupCourse/", new OperationInfo("团课管理", "更新团课"));
|
||||
PREFIX_MAPPING.put("DELETE:/api/groupCourse/", new OperationInfo("团课管理", "删除团课"));
|
||||
PREFIX_MAPPING.put("POST:/api/groupCourse/", new OperationInfo("团课管理", "操作团课"));
|
||||
PREFIX_MAPPING.put("PUT:/api/member/", new OperationInfo("会员管理", "编辑会员"));
|
||||
PREFIX_MAPPING.put("DELETE:/api/member/", new OperationInfo("会员管理", "删除会员"));
|
||||
PREFIX_MAPPING.put("PUT:/api/member-cards/", new OperationInfo("会员卡管理", "编辑会员卡"));
|
||||
PREFIX_MAPPING.put("DELETE:/api/member-cards/", new OperationInfo("会员卡管理", "删除会员卡"));
|
||||
PREFIX_MAPPING.put("PUT:/api/groupCourse/recommend/", new OperationInfo("推荐管理", "更新推荐"));
|
||||
PREFIX_MAPPING.put("DELETE:/api/groupCourse/recommend/", new OperationInfo("推荐管理", "删除推荐"));
|
||||
PREFIX_MAPPING.put("POST:/api/groupCourse/recommend/", new OperationInfo("推荐管理", "操作推荐"));
|
||||
PREFIX_MAPPING.put("POST:/api/member-card-transactions/", new OperationInfo("会员卡", "交易操作"));
|
||||
PREFIX_MAPPING.put("PUT:/api/payment/", new OperationInfo("支付管理", "更新支付"));
|
||||
PREFIX_MAPPING.put("POST:/api/payment/", new OperationInfo("支付管理", "支付操作"));
|
||||
PREFIX_MAPPING.put("PUT:/api/admin/member/", new OperationInfo("会员管理", "管理员编辑会员"));
|
||||
PREFIX_MAPPING.put("DELETE:/api/admin/member/", new OperationInfo("会员管理", "管理员删除会员"));
|
||||
PREFIX_MAPPING.put("DELETE:/api/groupCourse/labels/", new OperationInfo("标签管理", "删除标签"));
|
||||
|
||||
// ===== URL模块名映射(用于未匹配写操作自动生成) =====
|
||||
MODULE_NAMES.put("roles", "角色管理");
|
||||
MODULE_NAMES.put("users", "用户管理");
|
||||
MODULE_NAMES.put("menus", "菜单管理");
|
||||
MODULE_NAMES.put("auth", "认证");
|
||||
MODULE_NAMES.put("groupCourse", "团课管理");
|
||||
MODULE_NAMES.put("member", "会员管理");
|
||||
MODULE_NAMES.put("member-cards", "会员卡管理");
|
||||
MODULE_NAMES.put("member-card-records", "会员卡记录");
|
||||
MODULE_NAMES.put("member-card-transactions", "会员卡交易");
|
||||
MODULE_NAMES.put("checkIn", "签到管理");
|
||||
MODULE_NAMES.put("payment", "支付管理");
|
||||
MODULE_NAMES.put("dictionaries", "字典管理");
|
||||
MODULE_NAMES.put("config", "系统配置");
|
||||
MODULE_NAMES.put("upload", "文件管理");
|
||||
MODULE_NAMES.put("logs", "日志管理");
|
||||
MODULE_NAMES.put("datacount", "数据统计");
|
||||
MODULE_NAMES.put("diagnostic", "诊断");
|
||||
MODULE_NAMES.put("stats", "统计");
|
||||
OPERATION_MAPPING.put("POST:/api/roles", new OperationInfo("角色管理", "创建角色"));
|
||||
OPERATION_MAPPING.put("PUT:/api/roles/", new OperationInfo("角色管理", "更新角色"));
|
||||
OPERATION_MAPPING.put("DELETE:/api/roles/", new OperationInfo("角色管理", "删除角色"));
|
||||
OPERATION_MAPPING.put("POST:/api/users", new OperationInfo("用户管理", "创建用户"));
|
||||
OPERATION_MAPPING.put("PUT:/api/users/", new OperationInfo("用户管理", "更新用户"));
|
||||
OPERATION_MAPPING.put("DELETE:/api/users/", new OperationInfo("用户管理", "删除用户"));
|
||||
OPERATION_MAPPING.put("POST:/api/users/", new OperationInfo("用户管理", "用户操作"));
|
||||
OPERATION_MAPPING.put("POST:/api/menus", new OperationInfo("菜单管理", "创建菜单"));
|
||||
OPERATION_MAPPING.put("PUT:/api/menus/", new OperationInfo("菜单管理", "更新菜单"));
|
||||
OPERATION_MAPPING.put("DELETE:/api/menus/", new OperationInfo("菜单管理", "删除菜单"));
|
||||
}
|
||||
|
||||
public OperationLogWebFilter(IOperationLogService operationLogService, ObjectMapper objectMapper) {
|
||||
@@ -111,8 +61,10 @@ public class OperationLogWebFilter implements WebFilter {
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
logger.info("=== OperationLogWebFilter 初始化 ===");
|
||||
logger.info("精确匹配配置数量: {}, 前缀匹配配置数量: {}, 模块映射数量: {}",
|
||||
PRECISE_MAPPING.size(), PREFIX_MAPPING.size(), MODULE_NAMES.size());
|
||||
logger.info("操作日志映射配置数量: {}", OPERATION_MAPPING.size());
|
||||
OPERATION_MAPPING.forEach((key, value) -> {
|
||||
logger.info(" {} -> {}:{}", key, value.module, value.operation);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -120,135 +72,103 @@ public class OperationLogWebFilter implements WebFilter {
|
||||
ServerHttpRequest request = exchange.getRequest();
|
||||
String method = request.getMethod().name();
|
||||
String path = request.getPath().value();
|
||||
String key = method + ":" + path;
|
||||
|
||||
// 先尝试精确匹配
|
||||
OperationInfo operationInfo = PRECISE_MAPPING.get(key);
|
||||
logger.info("WebFilter 拦截请求: {} {}", method, path);
|
||||
|
||||
if (operationInfo == null) {
|
||||
// 尝试前缀匹配
|
||||
operationInfo = findPrefixMatch(key);
|
||||
}
|
||||
|
||||
if (operationInfo == null) {
|
||||
// 未匹配:如果是写操作(POST/PUT/DELETE),自动生成记录
|
||||
if (isWriteOperation(method)) {
|
||||
operationInfo = buildAutoOperationInfo(method, path);
|
||||
logger.info("自动生成操作日志: {} {} -> {}:{}", method, path, operationInfo.module, operationInfo.operation);
|
||||
}
|
||||
} else {
|
||||
logger.info("匹配到操作日志配置: {} {} -> {}:{}", method, path, operationInfo.module, operationInfo.operation);
|
||||
}
|
||||
OperationInfo operationInfo = findOperationInfo(method, path);
|
||||
|
||||
if (operationInfo == null) {
|
||||
logger.info("未匹配到操作日志配置,跳过: {} {}", method, path);
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
|
||||
logger.info("匹配到操作日志配置: {} {} -> {}:{}", method, path, operationInfo.module, operationInfo.operation);
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
String ip = IpUtils.getClientIp(request);
|
||||
final OperationInfo finalInfo = operationInfo;
|
||||
|
||||
return chain.filter(exchange)
|
||||
.then(Mono.defer(() -> {
|
||||
long duration = System.currentTimeMillis() - startTime;
|
||||
return getCurrentUsername()
|
||||
.flatMap(username -> saveOperationLog(username, method, path, ip, duration, "0", null, finalInfo));
|
||||
}))
|
||||
.onErrorResume(error -> {
|
||||
long duration = System.currentTimeMillis() - startTime;
|
||||
logger.error("请求处理失败: {} {}, 错误: {}", method, path, error.getMessage());
|
||||
return getCurrentUsername()
|
||||
.flatMap(username -> saveOperationLog(username, method, path, ip, duration, "1",
|
||||
error.getMessage().substring(0, Math.min(error.getMessage().length(), 500)), finalInfo))
|
||||
.then(Mono.error(error));
|
||||
});
|
||||
return Mono.deferContextual(contextView -> {
|
||||
return chain.filter(exchange)
|
||||
.then(Mono.defer(() -> {
|
||||
long duration = System.currentTimeMillis() - startTime;
|
||||
logger.info("请求处理完成,准备保存操作日志: {} {}, 耗时: {}ms", method, path, duration);
|
||||
|
||||
return ReactiveSecurityContextHolder.getContext()
|
||||
.flatMap(securityContext -> {
|
||||
Object principal = securityContext.getAuthentication().getPrincipal();
|
||||
String username = principal instanceof String ? (String) principal : "system";
|
||||
logger.info("获取到用户名: {}", username);
|
||||
return Mono.just(username);
|
||||
})
|
||||
.defaultIfEmpty("system")
|
||||
.flatMap(username -> {
|
||||
logger.info("开始保存操作日志: 用户={}, 操作={}", username,
|
||||
operationInfo.module + " - " + operationInfo.operation);
|
||||
|
||||
OperationLog log = new OperationLog();
|
||||
log.setUsername(username);
|
||||
log.setOperation(operationInfo.module + " - " + operationInfo.operation);
|
||||
log.setMethod(method + " " + path);
|
||||
log.setParams(null);
|
||||
log.setIp(ip);
|
||||
log.setDuration(duration);
|
||||
log.setStatus("0");
|
||||
|
||||
return operationLogService.save(log)
|
||||
.doOnSuccess(saved -> logger.info("操作日志保存成功: {} - {}",
|
||||
operationInfo.module, operationInfo.operation))
|
||||
.doOnError(e -> logger.error("操作日志保存失败: {}", e.getMessage(), e))
|
||||
.onErrorResume(e -> Mono.empty());
|
||||
})
|
||||
.then();
|
||||
}))
|
||||
.onErrorResume(error -> {
|
||||
long duration = System.currentTimeMillis() - startTime;
|
||||
logger.error("请求处理失败: {} {}, 错误: {}", method, path, error.getMessage());
|
||||
|
||||
return ReactiveSecurityContextHolder.getContext()
|
||||
.flatMap(securityContext -> {
|
||||
Object principal = securityContext.getAuthentication().getPrincipal();
|
||||
String username = principal instanceof String ? (String) principal : "system";
|
||||
return Mono.just(username);
|
||||
})
|
||||
.defaultIfEmpty("system")
|
||||
.flatMap(username -> {
|
||||
OperationLog log = new OperationLog();
|
||||
log.setUsername(username);
|
||||
log.setOperation(operationInfo.module + " - " + operationInfo.operation);
|
||||
log.setMethod(method + " " + path);
|
||||
log.setParams(null);
|
||||
log.setIp(ip);
|
||||
log.setDuration(duration);
|
||||
log.setStatus("1");
|
||||
log.setErrorMsg(error.getMessage());
|
||||
|
||||
return operationLogService.save(log)
|
||||
.doOnError(e -> logger.error("错误日志保存失败: {}", e.getMessage()))
|
||||
.onErrorResume(e -> Mono.empty());
|
||||
})
|
||||
.then(Mono.error(error));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private boolean isWriteOperation(String method) {
|
||||
return HttpMethod.POST.name().equals(method) ||
|
||||
HttpMethod.PUT.name().equals(method) ||
|
||||
HttpMethod.DELETE.name().equals(method) ||
|
||||
HttpMethod.PATCH.name().equals(method);
|
||||
}
|
||||
private OperationInfo findOperationInfo(String method, String path) {
|
||||
String key = method + ":" + path;
|
||||
if (OPERATION_MAPPING.containsKey(key)) {
|
||||
return OPERATION_MAPPING.get(key);
|
||||
}
|
||||
|
||||
private OperationInfo findPrefixMatch(String key) {
|
||||
for (Map.Entry<String, OperationInfo> entry : PREFIX_MAPPING.entrySet()) {
|
||||
if (key.startsWith(entry.getKey())) {
|
||||
for (Map.Entry<String, OperationInfo> entry : OPERATION_MAPPING.entrySet()) {
|
||||
String mappingKey = entry.getKey();
|
||||
if (key.startsWith(mappingKey)) {
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据URL路径自动生成操作信息
|
||||
* 例如: DELETE:/api/groupCourse/types/5 → 团课管理 - 删除操作
|
||||
*/
|
||||
private OperationInfo buildAutoOperationInfo(String method, String path) {
|
||||
String module = extractModuleFromPath(path);
|
||||
String operation = methodToOperationName(method);
|
||||
return new OperationInfo(module, operation);
|
||||
}
|
||||
|
||||
private String extractModuleFromPath(String path) {
|
||||
// 去掉 /api/ 前缀,取第一段作为模块名
|
||||
if (path.startsWith("/api/")) {
|
||||
String subPath = path.substring(5); // remove "/api/"
|
||||
int slashIdx = subPath.indexOf('/');
|
||||
String moduleKey = slashIdx > 0 ? subPath.substring(0, slashIdx) : subPath;
|
||||
|
||||
// 尝试复合模块名 (如 member-cards)
|
||||
if (slashIdx > 0) {
|
||||
String rest = subPath.substring(slashIdx + 1);
|
||||
int nextSlash = rest.indexOf('/');
|
||||
String secondPart = nextSlash > 0 ? rest.substring(0, nextSlash) : rest;
|
||||
String compositeKey = moduleKey + "/" + secondPart;
|
||||
if (MODULE_NAMES.containsKey(compositeKey)) {
|
||||
return MODULE_NAMES.get(compositeKey);
|
||||
}
|
||||
}
|
||||
|
||||
return MODULE_NAMES.getOrDefault(moduleKey, moduleKey);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
private String methodToOperationName(String method) {
|
||||
switch (method.toUpperCase()) {
|
||||
case "POST": return "创建/新增操作";
|
||||
case "PUT": return "编辑/更新操作";
|
||||
case "DELETE": return "删除操作";
|
||||
case "PATCH": return "修改操作";
|
||||
default: return "操作";
|
||||
}
|
||||
}
|
||||
|
||||
private Mono<String> getCurrentUsername() {
|
||||
return ReactiveSecurityContextHolder.getContext()
|
||||
.map(ctx -> ctx.getAuthentication().getPrincipal())
|
||||
.map(principal -> principal instanceof String ? (String) principal : "system")
|
||||
.defaultIfEmpty("system")
|
||||
.onErrorReturn("system");
|
||||
}
|
||||
|
||||
private Mono<Void> saveOperationLog(String username, String method, String path, String ip,
|
||||
long duration, String status, String errorMsg, OperationInfo info) {
|
||||
OperationLog log = new OperationLog();
|
||||
log.setUsername(username);
|
||||
log.setOperation(info.module + " - " + info.operation);
|
||||
log.setMethod(method + " " + path);
|
||||
log.setIp(ip);
|
||||
log.setDuration(duration);
|
||||
log.setStatus(status);
|
||||
log.setErrorMsg(errorMsg);
|
||||
|
||||
return operationLogService.save(log)
|
||||
.doOnSuccess(saved -> logger.debug("操作日志保存成功: {} - {}", info.module, info.operation))
|
||||
.doOnError(e -> logger.error("操作日志保存失败: {}", e.getMessage(), e))
|
||||
.onErrorResume(e -> Mono.empty())
|
||||
.then();
|
||||
}
|
||||
|
||||
private static class OperationInfo {
|
||||
final String module;
|
||||
final String operation;
|
||||
|
||||
-20
@@ -11,11 +11,6 @@ import org.springframework.security.config.annotation.web.reactive.EnableWebFlux
|
||||
import org.springframework.security.config.web.server.SecurityWebFiltersOrder;
|
||||
import org.springframework.security.config.web.server.ServerHttpSecurity;
|
||||
import org.springframework.security.web.server.SecurityWebFilterChain;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.reactive.CorsConfigurationSource;
|
||||
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Configuration
|
||||
@EnableWebFluxSecurity
|
||||
@@ -34,20 +29,6 @@ public class SecurityConfig {
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CorsConfigurationSource corsConfigurationSource() {
|
||||
CorsConfiguration configuration = new CorsConfiguration();
|
||||
configuration.setAllowedOriginPatterns(Arrays.asList("*"));
|
||||
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"));
|
||||
configuration.setAllowedHeaders(Arrays.asList("*"));
|
||||
configuration.setAllowCredentials(true);
|
||||
configuration.setMaxAge(3600L);
|
||||
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
source.registerCorsConfiguration("/**", configuration);
|
||||
return source;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
|
||||
String[] activeProfiles = environment.getActiveProfiles();
|
||||
@@ -60,7 +41,6 @@ public class SecurityConfig {
|
||||
activeProfiles.length > 0 ? String.join(",", activeProfiles) : "default", isDevOrTest);
|
||||
|
||||
http
|
||||
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
|
||||
.csrf(ServerHttpSecurity.CsrfSpec::disable)
|
||||
.httpBasic(ServerHttpSecurity.HttpBasicSpec::disable)
|
||||
.formLogin(ServerHttpSecurity.FormLoginSpec::disable)
|
||||
|
||||
-2
@@ -53,8 +53,6 @@ public interface ISysUserService {
|
||||
|
||||
Mono<SysUser> changePassword(Long userId, String oldPassword, String newPassword);
|
||||
|
||||
Mono<Boolean> verifyPassword(Long userId, String password);
|
||||
|
||||
Mono<Void> updateRoleIdToNullByRoleId(Long roleId);
|
||||
|
||||
Mono<Void> assignRolesToUser(Long userId, java.util.List<Long> roleIds);
|
||||
|
||||
-3
@@ -120,9 +120,6 @@ public class SysPermissionService implements ISysPermissionService {
|
||||
|
||||
@Override
|
||||
public Flux<SysPermission> findByRoleIds(List<Long> roleIds) {
|
||||
if (roleIds == null || roleIds.isEmpty()) {
|
||||
return Flux.empty();
|
||||
}
|
||||
return permissionRepository.findByRoleIds(roleIds);
|
||||
}
|
||||
|
||||
|
||||
+1
@@ -83,6 +83,7 @@ public class SysRoleService implements ISysRoleService {
|
||||
@Override
|
||||
public Mono<SysRole> createRole(CreateRoleCommand command) {
|
||||
SysRole role = new SysRole();
|
||||
role.generateId();
|
||||
role.setRoleName(command.roleName());
|
||||
role.setRoleKey(command.roleKey());
|
||||
role.setRoleSort(command.roleSort());
|
||||
|
||||
+2
-7
@@ -97,6 +97,7 @@ public class SysUserService implements ISysUserService {
|
||||
logger.info("SysUserService.createUser - 用户名: {}, 密码前缀: {}",
|
||||
user.getUsername(),
|
||||
user.getPassword() != null ? user.getPassword().substring(0, 7) : "null");
|
||||
user.generateId();
|
||||
if (user.getPassword() != null && !user.getPassword().startsWith("$2a$")
|
||||
&& !user.getPassword().startsWith("$2b$")) {
|
||||
logger.info("密码不以$2a$或$2b$开头,重新编码");
|
||||
@@ -116,6 +117,7 @@ public class SysUserService implements ISysUserService {
|
||||
@Override
|
||||
public Mono<SysUser> createUser(CreateUserCommand command) {
|
||||
SysUser user = new SysUser();
|
||||
user.generateId();
|
||||
user.setUsername(command.username().getValue());
|
||||
user.setPassword(passwordEncoder.encode(command.password().getValue()));
|
||||
user.setEmail(command.email().getValue());
|
||||
@@ -202,13 +204,6 @@ public class SysUserService implements ISysUserService {
|
||||
return userRepository.updateRoleIdToNullByRoleId(roleId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Boolean> verifyPassword(Long userId, String password) {
|
||||
return userRepository.findById(userId)
|
||||
.map(user -> passwordEncoder.matches(password, user.getPassword()))
|
||||
.defaultIfEmpty(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<SysUser> changePassword(Long userId, String oldPassword, String newPassword) {
|
||||
return userRepository.findById(userId)
|
||||
|
||||
+1
-27
@@ -2,8 +2,6 @@ package cn.novalon.gym.manage.sys.dto.response;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 认证响应DTO
|
||||
*
|
||||
@@ -22,21 +20,13 @@ public class AuthResponse {
|
||||
@Schema(description = "用户名", example = "admin")
|
||||
private String username;
|
||||
|
||||
@Schema(description = "角色标识列表", example = "[\"admin\"]")
|
||||
private List<String> roles;
|
||||
|
||||
@Schema(description = "权限码列表", example = "[\"system:user:view\", \"system:user:create\"]")
|
||||
private List<String> permissions;
|
||||
|
||||
public AuthResponse() {
|
||||
}
|
||||
|
||||
public AuthResponse(String token, Long userId, String username, List<String> roles, List<String> permissions) {
|
||||
public AuthResponse(String token, Long userId, String username) {
|
||||
this.token = token;
|
||||
this.userId = userId;
|
||||
this.username = username;
|
||||
this.roles = roles;
|
||||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
@@ -62,20 +52,4 @@ public class AuthResponse {
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public List<String> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
public void setRoles(List<String> roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
public List<String> getPermissions() {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public void setPermissions(List<String> permissions) {
|
||||
this.permissions = permissions;
|
||||
}
|
||||
}
|
||||
|
||||
+19
-88
@@ -8,7 +8,6 @@ import cn.novalon.gym.manage.sys.core.domain.SysUser;
|
||||
import cn.novalon.gym.manage.sys.core.domain.SysLoginLog;
|
||||
import cn.novalon.gym.manage.sys.core.service.ISysUserService;
|
||||
import cn.novalon.gym.manage.sys.core.service.ISysLoginLogService;
|
||||
import cn.novalon.gym.manage.sys.core.service.ISysPermissionService;
|
||||
import cn.novalon.gym.manage.sys.util.UserAgentParser;
|
||||
import cn.novalon.gym.manage.sys.util.IpLocationParser;
|
||||
import cn.novalon.gym.manage.common.util.StatusConstants;
|
||||
@@ -29,7 +28,6 @@ import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -52,7 +50,6 @@ public class SysAuthHandler {
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
private final JwtTokenProvider jwtTokenProvider;
|
||||
private final ISysLoginLogService loginLogService;
|
||||
private final ISysPermissionService permissionService;
|
||||
private final UserAgentParser userAgentParser;
|
||||
private final IpLocationParser ipLocationParser;
|
||||
|
||||
@@ -63,13 +60,11 @@ public class SysAuthHandler {
|
||||
public SysAuthHandler(ISysUserService userService,
|
||||
@Qualifier("passwordEncoder") PasswordEncoder passwordEncoder,
|
||||
JwtTokenProvider jwtTokenProvider, ISysLoginLogService loginLogService,
|
||||
ISysPermissionService permissionService,
|
||||
UserAgentParser userAgentParser, IpLocationParser ipLocationParser) {
|
||||
this.userService = userService;
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
this.jwtTokenProvider = jwtTokenProvider;
|
||||
this.loginLogService = loginLogService;
|
||||
this.permissionService = permissionService;
|
||||
this.userAgentParser = userAgentParser;
|
||||
this.ipLocationParser = ipLocationParser;
|
||||
|
||||
@@ -131,49 +126,29 @@ public class SysAuthHandler {
|
||||
}
|
||||
|
||||
return userService.getUserRoles(user.getId())
|
||||
.map(role -> role.getRoleKey())
|
||||
.collectList()
|
||||
.flatMap(roles -> {
|
||||
List<String> roleKeys = roles.stream()
|
||||
.map(r -> r.getRoleKey())
|
||||
.collect(Collectors.toList());
|
||||
List<Long> roleIds = roles.stream()
|
||||
.map(r -> r.getId())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Mono<List<String>> permCodesMono;
|
||||
if (roleIds.isEmpty()) {
|
||||
permCodesMono = Mono.just(java.util.Collections.<String>emptyList());
|
||||
} else {
|
||||
permCodesMono = permissionService.findByRoleIds(roleIds)
|
||||
.map(p -> p.getPermissionCode())
|
||||
.collectList();
|
||||
}
|
||||
|
||||
return permCodesMono
|
||||
.flatMap(permCodes -> {
|
||||
String token = jwtTokenProvider
|
||||
.generateToken(
|
||||
.flatMap(roleKeys -> {
|
||||
String token = jwtTokenProvider
|
||||
.generateToken(
|
||||
user.getUsername(),
|
||||
user.getId(),
|
||||
roleKeys);
|
||||
logger.info("用户登录成功: username={}, userId={}, roles={}, permissions={}",
|
||||
user.getUsername(),
|
||||
user.getId(),
|
||||
roleKeys,
|
||||
permCodes.size());
|
||||
recordLoginLog(loginRequest.getUsername(),
|
||||
clientIp,
|
||||
"0", "登录成功",
|
||||
userAgent);
|
||||
AuthResponse response = new AuthResponse(
|
||||
token,
|
||||
user.getId(),
|
||||
user.getUsername(),
|
||||
roleKeys,
|
||||
permCodes);
|
||||
return ServerResponse.ok()
|
||||
.bodyValue(response);
|
||||
});
|
||||
logger.info("用户登录成功: username={}, userId={}, roles={}",
|
||||
user.getUsername(),
|
||||
user.getId(),
|
||||
roleKeys);
|
||||
recordLoginLog(loginRequest
|
||||
.getUsername(),
|
||||
clientIp,
|
||||
"0", "登录成功",
|
||||
userAgent);
|
||||
AuthResponse response = new AuthResponse(
|
||||
token,
|
||||
user.getId(),
|
||||
user.getUsername());
|
||||
return ServerResponse.ok()
|
||||
.bodyValue(response);
|
||||
});
|
||||
})
|
||||
.switchIfEmpty(Mono.defer(() -> {
|
||||
@@ -215,50 +190,6 @@ public class SysAuthHandler {
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "获取当前用户信息", description = "根据Token获取当前登录用户的详细信息和权限")
|
||||
public Mono<ServerResponse> me(ServerRequest request) {
|
||||
String authHeader = request.headers().firstHeader("Authorization");
|
||||
if (authHeader == null || !authHeader.startsWith("Bearer ")) {
|
||||
return ServerResponse.status(HttpStatus.UNAUTHORIZED).build();
|
||||
}
|
||||
String token = authHeader.substring(7);
|
||||
if (!jwtTokenProvider.validateToken(token)) {
|
||||
return ServerResponse.status(HttpStatus.UNAUTHORIZED).build();
|
||||
}
|
||||
Long userId = jwtTokenProvider.getUserIdFromToken(token);
|
||||
return userService.findById(userId)
|
||||
.flatMap(user -> userService.getUserRoles(user.getId())
|
||||
.collectList()
|
||||
.flatMap(roles -> {
|
||||
List<String> roleKeys = roles.stream()
|
||||
.map(r -> r.getRoleKey())
|
||||
.collect(Collectors.toList());
|
||||
List<Long> roleIds = roles.stream()
|
||||
.map(r -> r.getId())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Mono<List<String>> permCodesMono;
|
||||
if (roleIds.isEmpty()) {
|
||||
permCodesMono = Mono.just(java.util.Collections.<String>emptyList());
|
||||
} else {
|
||||
permCodesMono = permissionService.findByRoleIds(roleIds)
|
||||
.map(p -> p.getPermissionCode())
|
||||
.collectList();
|
||||
}
|
||||
|
||||
return permCodesMono
|
||||
.flatMap(permCodes -> {
|
||||
AuthResponse response = new AuthResponse(
|
||||
token,
|
||||
user.getId(),
|
||||
user.getUsername(),
|
||||
roleKeys,
|
||||
permCodes);
|
||||
return ServerResponse.ok().bodyValue(response);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
private void recordLoginLog(String username, String ip, String status, String message, String userAgent) {
|
||||
try {
|
||||
SysLoginLog loginLog = new SysLoginLog();
|
||||
|
||||
+5
-33
@@ -1,11 +1,7 @@
|
||||
package cn.novalon.gym.manage.sys.handler.permission;
|
||||
|
||||
import cn.novalon.gym.manage.sys.core.domain.SysPermission;
|
||||
import cn.novalon.gym.manage.sys.core.domain.SysRole;
|
||||
import cn.novalon.gym.manage.sys.core.service.ISysPermissionService;
|
||||
import cn.novalon.gym.manage.sys.core.service.ISysRoleService;
|
||||
import cn.novalon.gym.manage.sys.core.service.ISysUserService;
|
||||
import cn.novalon.gym.manage.sys.util.AuthUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -26,19 +22,10 @@ import java.util.List;
|
||||
@Tag(name = "权限管理", description = "权限相关操作")
|
||||
public class SysPermissionHandler {
|
||||
|
||||
private static final Long BUILTIN_ROLE_ID = 1L;
|
||||
|
||||
private final ISysPermissionService permissionService;
|
||||
private final ISysRoleService roleService;
|
||||
private final ISysUserService userService;
|
||||
private final AuthUtil authUtil;
|
||||
|
||||
public SysPermissionHandler(ISysPermissionService permissionService, ISysRoleService roleService,
|
||||
ISysUserService userService, AuthUtil authUtil) {
|
||||
public SysPermissionHandler(ISysPermissionService permissionService) {
|
||||
this.permissionService = permissionService;
|
||||
this.roleService = roleService;
|
||||
this.userService = userService;
|
||||
this.authUtil = authUtil;
|
||||
}
|
||||
|
||||
@Operation(summary = "获取所有权限", description = "获取系统中所有权限列表")
|
||||
@@ -110,27 +97,12 @@ public class SysPermissionHandler {
|
||||
.body(permissionService.getPermissionsByRoleId(roleId), SysPermission.class);
|
||||
}
|
||||
|
||||
@Operation(summary = "为角色分配权限", description = "为指定角色分配权限列表,需验证管理员密码,超级管理员角色不可被分配")
|
||||
@Operation(summary = "为角色分配权限", description = "为指定角色分配权限列表")
|
||||
public Mono<ServerResponse> assignPermissionsToRole(ServerRequest request) {
|
||||
Long roleId = Long.valueOf(request.pathVariable("id"));
|
||||
|
||||
return verifyAdminPassword(request)
|
||||
.flatMap(valid -> {
|
||||
if (!valid) return ServerResponse.badRequest().bodyValue("管理员密码不能为空或错误");
|
||||
if (BUILTIN_ROLE_ID.equals(roleId)) return ServerResponse.badRequest().bodyValue("超级管理员角色权限不可被修改");
|
||||
return request.bodyToMono(AssignPermissionsRequest.class)
|
||||
.flatMap(req -> permissionService.assignPermissionsToRole(roleId, req.permissionIds()))
|
||||
.then(ServerResponse.ok().build());
|
||||
});
|
||||
}
|
||||
|
||||
private Mono<Boolean> verifyAdminPassword(ServerRequest request) {
|
||||
String adminPassword = request.queryParam("adminPassword").orElse(null);
|
||||
if (adminPassword == null || adminPassword.isBlank()) {
|
||||
return Mono.just(false);
|
||||
}
|
||||
Long adminId = authUtil.getMemberIdOrThrow(request);
|
||||
return userService.verifyPassword(adminId, adminPassword);
|
||||
return request.bodyToMono(AssignPermissionsRequest.class)
|
||||
.flatMap(req -> permissionService.assignPermissionsToRole(roleId, req.permissionIds()))
|
||||
.then(ServerResponse.ok().build());
|
||||
}
|
||||
|
||||
private record AssignPermissionsRequest(List<Long> permissionIds) {}
|
||||
|
||||
+17
-43
@@ -2,8 +2,6 @@ package cn.novalon.gym.manage.sys.handler.role;
|
||||
|
||||
import cn.novalon.gym.manage.sys.core.domain.SysRole;
|
||||
import cn.novalon.gym.manage.sys.core.service.ISysRoleService;
|
||||
import cn.novalon.gym.manage.sys.core.service.ISysUserService;
|
||||
import cn.novalon.gym.manage.sys.util.AuthUtil;
|
||||
import cn.novalon.gym.manage.common.dto.PageRequest;
|
||||
import cn.novalon.gym.manage.sys.dto.request.RoleCreateRequest;
|
||||
import cn.novalon.gym.manage.sys.dto.request.RoleUpdateRequest;
|
||||
@@ -32,18 +30,12 @@ import java.util.Map;
|
||||
@Tag(name = "角色管理", description = "角色相关操作")
|
||||
public class SysRoleHandler {
|
||||
|
||||
private static final Long BUILTIN_ROLE_ID = 1L;
|
||||
|
||||
private final ISysRoleService roleService;
|
||||
private final Validator validator;
|
||||
private final AuthUtil authUtil;
|
||||
private final ISysUserService userService;
|
||||
|
||||
public SysRoleHandler(ISysRoleService roleService, Validator validator, AuthUtil authUtil, ISysUserService userService) {
|
||||
public SysRoleHandler(ISysRoleService roleService, Validator validator) {
|
||||
this.roleService = roleService;
|
||||
this.validator = validator;
|
||||
this.authUtil = authUtil;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@Operation(summary = "获取所有角色", description = "获取系统中所有角色列表")
|
||||
@@ -123,39 +115,30 @@ public class SysRoleHandler {
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "更新角色", description = "更新角色信息,需验证管理员密码,超级管理员角色不可被编辑")
|
||||
@Operation(summary = "更新角色", description = "更新角色信息")
|
||||
@OperationLog(operation = "更新角色", module = "角色管理")
|
||||
public Mono<ServerResponse> updateRole(ServerRequest request) {
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
|
||||
return verifyAdminPassword(request)
|
||||
.flatMap(valid -> {
|
||||
if (!valid) return ServerResponse.badRequest().bodyValue("管理员密码不能为空或错误");
|
||||
if (BUILTIN_ROLE_ID.equals(id)) return ServerResponse.badRequest().bodyValue("超级管理员角色不可编辑");
|
||||
return request.bodyToMono(RoleUpdateRequest.class)
|
||||
.map(req -> UpdateRoleCommand.of(
|
||||
id, req.getRoleName(), req.getRoleKey(),
|
||||
req.getRoleSort(), req.getStatus()
|
||||
))
|
||||
.flatMap(roleService::updateRole)
|
||||
.flatMap(updatedRole -> ServerResponse.ok().bodyValue(updatedRole))
|
||||
.switchIfEmpty(ServerResponse.notFound().build());
|
||||
});
|
||||
return request.bodyToMono(RoleUpdateRequest.class)
|
||||
.map(req -> UpdateRoleCommand.of(
|
||||
id,
|
||||
req.getRoleName(),
|
||||
req.getRoleKey(),
|
||||
req.getRoleSort(),
|
||||
req.getStatus()
|
||||
))
|
||||
.flatMap(roleService::updateRole)
|
||||
.flatMap(updatedRole -> ServerResponse.ok().bodyValue(updatedRole))
|
||||
.switchIfEmpty(ServerResponse.notFound().build());
|
||||
}
|
||||
|
||||
@Operation(summary = "删除角色", description = "逻辑删除角色,需验证管理员密码,超级管理员角色不可被删除")
|
||||
@Operation(summary = "删除角色", description = "逻辑删除角色")
|
||||
@OperationLog(operation = "删除角色", module = "角色管理")
|
||||
public Mono<ServerResponse> deleteRole(ServerRequest request) {
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
|
||||
return verifyAdminPassword(request)
|
||||
.flatMap(valid -> {
|
||||
if (!valid) return ServerResponse.badRequest().bodyValue("管理员密码不能为空或错误");
|
||||
if (BUILTIN_ROLE_ID.equals(id)) return ServerResponse.badRequest().bodyValue("超级管理员角色不可删除");
|
||||
return roleService.logicalDeleteRole(id)
|
||||
.flatMap(role -> ServerResponse.ok().bodyValue(role))
|
||||
.switchIfEmpty(ServerResponse.notFound().build());
|
||||
});
|
||||
return roleService.logicalDeleteRole(id)
|
||||
.flatMap(role -> ServerResponse.ok().bodyValue(role))
|
||||
.switchIfEmpty(ServerResponse.notFound().build());
|
||||
}
|
||||
|
||||
@Operation(summary = "恢复角色", description = "恢复被逻辑删除的角色")
|
||||
@@ -165,13 +148,4 @@ public class SysRoleHandler {
|
||||
.flatMap(role -> ServerResponse.ok().bodyValue(role))
|
||||
.switchIfEmpty(ServerResponse.notFound().build());
|
||||
}
|
||||
|
||||
private Mono<Boolean> verifyAdminPassword(ServerRequest request) {
|
||||
String adminPassword = request.queryParam("adminPassword").orElse(null);
|
||||
if (adminPassword == null || adminPassword.isBlank()) {
|
||||
return Mono.just(false);
|
||||
}
|
||||
Long adminId = authUtil.getMemberIdOrThrow(request);
|
||||
return userService.verifyPassword(adminId, adminPassword);
|
||||
}
|
||||
}
|
||||
|
||||
+32
-92
@@ -2,7 +2,6 @@ package cn.novalon.gym.manage.sys.handler.user;
|
||||
|
||||
import cn.novalon.gym.manage.sys.core.domain.SysUser;
|
||||
import cn.novalon.gym.manage.sys.core.service.ISysUserService;
|
||||
import cn.novalon.gym.manage.sys.util.AuthUtil;
|
||||
import cn.novalon.gym.manage.common.dto.PageRequest;
|
||||
import cn.novalon.gym.manage.sys.dto.request.AssignRolesRequest;
|
||||
import cn.novalon.gym.manage.sys.dto.request.PasswordChangeRequest;
|
||||
@@ -43,12 +42,10 @@ public class SysUserHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(SysUserHandler.class);
|
||||
private final ISysUserService userService;
|
||||
private final Validator validator;
|
||||
private final AuthUtil authUtil;
|
||||
|
||||
public SysUserHandler(ISysUserService userService, Validator validator, AuthUtil authUtil) {
|
||||
public SysUserHandler(ISysUserService userService, Validator validator) {
|
||||
this.userService = userService;
|
||||
this.validator = validator;
|
||||
this.authUtil = authUtil;
|
||||
}
|
||||
|
||||
@Operation(summary = "获取所有用户", description = "获取系统中所有用户列表")
|
||||
@@ -155,63 +152,39 @@ public class SysUserHandler {
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "更新用户", description = "更新用户信息,需验证管理员密码,超级管理员不可编辑")
|
||||
@Operation(summary = "更新用户", description = "更新用户信息")
|
||||
@OperationLog(operation = "更新用户", module = "用户管理")
|
||||
public Mono<ServerResponse> updateUser(ServerRequest request) {
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
|
||||
return verifyAdminPassword(request)
|
||||
.flatMap(valid -> {
|
||||
if (!valid) {
|
||||
return ServerResponse.badRequest().bodyValue("管理员密码不能为空或错误");
|
||||
}
|
||||
return userService.findById(id)
|
||||
.flatMap(user -> {
|
||||
if ("admin".equals(user.getUsername())) {
|
||||
return Mono.<ServerResponse>error(new RuntimeException("超级管理员不可编辑"));
|
||||
}
|
||||
return request.bodyToMono(UserUpdateRequest.class)
|
||||
.map(req -> {
|
||||
boolean clearRole = Boolean.TRUE.equals(req.getClearRole()) ||
|
||||
(req.getRoleId() == null && req.getClearRole() != null);
|
||||
return UpdateUserCommand.of(
|
||||
id, null, null, req.getEmail(),
|
||||
req.getRoleId(), req.getStatus(), clearRole
|
||||
);
|
||||
})
|
||||
.flatMap(userService::updateUser)
|
||||
.flatMap(updated -> ServerResponse.ok().bodyValue(updated));
|
||||
})
|
||||
.switchIfEmpty(ServerResponse.notFound().build());
|
||||
});
|
||||
return request.bodyToMono(UserUpdateRequest.class)
|
||||
.map(req -> {
|
||||
boolean clearRole = Boolean.TRUE.equals(req.getClearRole()) ||
|
||||
(req.getRoleId() == null && req.getClearRole() != null);
|
||||
return UpdateUserCommand.of(
|
||||
id,
|
||||
null,
|
||||
null,
|
||||
req.getEmail(),
|
||||
req.getRoleId(),
|
||||
req.getStatus(),
|
||||
clearRole
|
||||
);
|
||||
})
|
||||
.flatMap(userService::updateUser)
|
||||
.flatMap(user -> ServerResponse.ok().bodyValue(user))
|
||||
.switchIfEmpty(ServerResponse.notFound().build());
|
||||
}
|
||||
|
||||
@Operation(summary = "删除用户", description = "物理删除用户,需验证管理员密码,超级管理员不可删除")
|
||||
@Operation(summary = "删除用户", description = "物理删除用户")
|
||||
@OperationLog(operation = "删除用户", module = "用户管理")
|
||||
public Mono<ServerResponse> deleteUser(ServerRequest request) {
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
|
||||
return verifyAdminPassword(request)
|
||||
.flatMap(valid -> {
|
||||
if (!valid) {
|
||||
return ServerResponse.badRequest().bodyValue("管理员密码不能为空或错误");
|
||||
}
|
||||
return userService.findById(id)
|
||||
.flatMap(user -> {
|
||||
if ("admin".equals(user.getUsername())) {
|
||||
return Mono.<ServerResponse>error(new RuntimeException("超级管理员不可删除"));
|
||||
}
|
||||
return userService.deleteUser(id)
|
||||
.then(ServerResponse.noContent().build());
|
||||
})
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("User not found")));
|
||||
})
|
||||
return userService.findById(id)
|
||||
.flatMap(user -> userService.deleteUser(id)
|
||||
.then(ServerResponse.noContent().build()))
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("User not found")))
|
||||
.onErrorResume(RuntimeException.class, ex -> {
|
||||
String msg = ex.getMessage();
|
||||
if ("超级管理员不可删除".equals(msg) || "超级管理员不可编辑".equals(msg)) {
|
||||
return ServerResponse.badRequest().bodyValue(msg);
|
||||
}
|
||||
if ("User not found".equals(msg)) {
|
||||
if (ex.getMessage().contains("not found")) {
|
||||
return ServerResponse.notFound().build();
|
||||
}
|
||||
return Mono.error(ex);
|
||||
@@ -285,37 +258,16 @@ public class SysUserHandler {
|
||||
.flatMap(exists -> ServerResponse.ok().bodyValue(exists));
|
||||
}
|
||||
|
||||
@Operation(summary = "为用户分配角色", description = "为指定用户分配角色列表,需验证管理员密码,超级管理员不可分配")
|
||||
@Operation(summary = "为用户分配角色", description = "为指定用户分配角色列表")
|
||||
@OperationLog(operation = "分配角色", module = "用户管理")
|
||||
public Mono<ServerResponse> assignRoles(ServerRequest request) {
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
|
||||
return verifyAdminPassword(request)
|
||||
.flatMap(valid -> {
|
||||
if (!valid) {
|
||||
return ServerResponse.badRequest().bodyValue("管理员密码不能为空或错误");
|
||||
}
|
||||
return userService.findById(id)
|
||||
.flatMap(user -> {
|
||||
if ("admin".equals(user.getUsername())) {
|
||||
return Mono.<ServerResponse>error(new RuntimeException("超级管理员不可被分配角色"));
|
||||
}
|
||||
return request.bodyToMono(AssignRolesRequest.class)
|
||||
.flatMap(req -> userService.assignRolesToUser(id, req.getRoleIdsAsLong()))
|
||||
.then(ServerResponse.ok().build());
|
||||
})
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("User not found")));
|
||||
})
|
||||
.onErrorResume(RuntimeException.class, ex -> {
|
||||
String msg = ex.getMessage();
|
||||
if ("超级管理员不可被分配角色".equals(msg)) {
|
||||
return ServerResponse.badRequest().bodyValue(msg);
|
||||
}
|
||||
if ("User not found".equals(msg)) {
|
||||
return ServerResponse.notFound().build();
|
||||
}
|
||||
logger.error("分配角色失败", ex);
|
||||
return ServerResponse.status(500).bodyValue("分配角色失败: " + msg);
|
||||
return request.bodyToMono(AssignRolesRequest.class)
|
||||
.flatMap(req -> userService.assignRolesToUser(id, req.getRoleIdsAsLong()))
|
||||
.then(ServerResponse.ok().build())
|
||||
.onErrorResume(error -> {
|
||||
logger.error("分配角色失败", error);
|
||||
return ServerResponse.status(500).bodyValue("分配角色失败: " + error.getMessage());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -325,16 +277,4 @@ public class SysUserHandler {
|
||||
return ServerResponse.ok()
|
||||
.body(userService.getUserRoles(id), cn.novalon.gym.manage.sys.core.domain.SysRole.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证管理员密码
|
||||
*/
|
||||
private Mono<Boolean> verifyAdminPassword(ServerRequest request) {
|
||||
String adminPassword = request.queryParam("adminPassword").orElse(null);
|
||||
if (adminPassword == null || adminPassword.isBlank()) {
|
||||
return Mono.just(false);
|
||||
}
|
||||
Long adminId = authUtil.getMemberIdOrThrow(request);
|
||||
return userService.verifyPassword(adminId, adminPassword);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -8,7 +8,7 @@ class AuthResponseTest {
|
||||
|
||||
@Test
|
||||
void testConstructorWithParameters() {
|
||||
AuthResponse response = new AuthResponse("test-token", 1L, "testuser", null, null);
|
||||
AuthResponse response = new AuthResponse("test-token", 1L, "testuser");
|
||||
|
||||
assertEquals("test-token", response.getToken());
|
||||
assertEquals(1L, response.getUserId());
|
||||
@@ -63,7 +63,7 @@ class AuthResponseTest {
|
||||
|
||||
@Test
|
||||
void testConstructorWithNullValues() {
|
||||
AuthResponse response = new AuthResponse(null, null, null, null, null);
|
||||
AuthResponse response = new AuthResponse(null, null, null);
|
||||
|
||||
assertNull(response.getToken());
|
||||
assertNull(response.getUserId());
|
||||
@@ -72,7 +72,7 @@ class AuthResponseTest {
|
||||
|
||||
@Test
|
||||
void testConstructorWithEmptyStrings() {
|
||||
AuthResponse response = new AuthResponse("", 1L, "", null, null);
|
||||
AuthResponse response = new AuthResponse("", 1L, "");
|
||||
|
||||
assertEquals("", response.getToken());
|
||||
assertEquals(1L, response.getUserId());
|
||||
@@ -164,7 +164,7 @@ class AuthResponseTest {
|
||||
|
||||
@Test
|
||||
void testConstructorWithZeroUserId() {
|
||||
AuthResponse response = new AuthResponse("token", 0L, "user", null, null);
|
||||
AuthResponse response = new AuthResponse("token", 0L, "user");
|
||||
|
||||
assertEquals("token", response.getToken());
|
||||
assertEquals(0L, response.getUserId());
|
||||
|
||||
+1
-10
@@ -6,11 +6,9 @@ import cn.novalon.gym.manage.sys.security.JwtTokenProvider;
|
||||
import cn.novalon.gym.manage.sys.core.domain.SysUser;
|
||||
import cn.novalon.gym.manage.sys.core.domain.SysRole;
|
||||
import cn.novalon.gym.manage.sys.core.domain.SysLoginLog;
|
||||
import cn.novalon.gym.manage.sys.core.domain.SysPermission;
|
||||
import cn.novalon.gym.manage.sys.util.TestDataFactory;
|
||||
import cn.novalon.gym.manage.sys.core.service.ISysUserService;
|
||||
import cn.novalon.gym.manage.sys.core.service.ISysLoginLogService;
|
||||
import cn.novalon.gym.manage.sys.core.service.ISysPermissionService;
|
||||
import cn.novalon.gym.manage.sys.util.UserAgentParser;
|
||||
import cn.novalon.gym.manage.sys.util.IpLocationParser;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -49,9 +47,6 @@ class SysAuthHandlerTest {
|
||||
@Mock
|
||||
private ISysLoginLogService loginLogService;
|
||||
|
||||
@Mock
|
||||
private ISysPermissionService permissionService;
|
||||
|
||||
@Mock
|
||||
private UserAgentParser userAgentParser;
|
||||
|
||||
@@ -64,7 +59,7 @@ class SysAuthHandlerTest {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
authHandler = new SysAuthHandler(userService, passwordEncoder, jwtTokenProvider, loginLogService,
|
||||
permissionService, userAgentParser, ipLocationParser);
|
||||
userAgentParser, ipLocationParser);
|
||||
|
||||
testUser = TestDataFactory.createTestUser();
|
||||
}
|
||||
@@ -93,10 +88,6 @@ class SysAuthHandlerTest {
|
||||
when(userService.getUserRoles(1L)).thenReturn(Flux.just(mockRole));
|
||||
when(loginLogService.save(any())).thenReturn(Mono.just(new SysLoginLog()));
|
||||
|
||||
SysPermission mockPermission = new SysPermission();
|
||||
mockPermission.setPermissionCode("system:user:view");
|
||||
when(permissionService.findByRoleIds(anyList())).thenReturn(Flux.just(mockPermission));
|
||||
|
||||
ServerRequest request = MockServerRequest.builder()
|
||||
.body(Mono.just(loginRequest));
|
||||
Mono<ServerResponse> response = authHandler.login(request);
|
||||
|
||||
+5
-25
@@ -2,8 +2,6 @@ package cn.novalon.gym.manage.sys.handler.role;
|
||||
|
||||
import cn.novalon.gym.manage.sys.core.domain.SysRole;
|
||||
import cn.novalon.gym.manage.sys.core.service.ISysRoleService;
|
||||
import cn.novalon.gym.manage.sys.core.service.ISysUserService;
|
||||
import cn.novalon.gym.manage.sys.util.AuthUtil;
|
||||
import cn.novalon.gym.manage.sys.dto.request.RoleCreateRequest;
|
||||
import cn.novalon.gym.manage.sys.dto.request.RoleUpdateRequest;
|
||||
import cn.novalon.gym.manage.sys.core.command.CreateRoleCommand;
|
||||
@@ -37,18 +35,12 @@ class SysRoleHandlerTest {
|
||||
@Mock
|
||||
private Validator validator;
|
||||
|
||||
@Mock
|
||||
private AuthUtil authUtil;
|
||||
|
||||
@Mock
|
||||
private ISysUserService userService;
|
||||
|
||||
private SysRoleHandler roleHandler;
|
||||
private SysRole testRole;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
roleHandler = new SysRoleHandler(roleService, validator, authUtil, userService);
|
||||
roleHandler = new SysRoleHandler(roleService, validator);
|
||||
|
||||
testRole = new SysRole();
|
||||
testRole.setId(1L);
|
||||
@@ -259,13 +251,10 @@ class SysRoleHandlerTest {
|
||||
updateRequest.setRoleSort(3);
|
||||
updateRequest.setStatus(0);
|
||||
|
||||
when(authUtil.getMemberIdOrThrow(any())).thenReturn(1L);
|
||||
when(userService.verifyPassword(1L, "password123")).thenReturn(Mono.just(true));
|
||||
when(roleService.updateRole(any(UpdateRoleCommand.class))).thenReturn(Mono.just(testRole));
|
||||
|
||||
ServerRequest request = MockServerRequest.builder()
|
||||
.pathVariable("id", "2")
|
||||
.queryParam("adminPassword", "password123")
|
||||
.pathVariable("id", "1")
|
||||
.body(Mono.just(updateRequest));
|
||||
Mono<ServerResponse> response = roleHandler.updateRole(request);
|
||||
|
||||
@@ -282,13 +271,10 @@ class SysRoleHandlerTest {
|
||||
RoleUpdateRequest updateRequest = new RoleUpdateRequest();
|
||||
updateRequest.setRoleName("UPDATED_ROLE");
|
||||
|
||||
when(authUtil.getMemberIdOrThrow(any())).thenReturn(1L);
|
||||
when(userService.verifyPassword(1L, "password123")).thenReturn(Mono.just(true));
|
||||
when(roleService.updateRole(any(UpdateRoleCommand.class))).thenReturn(Mono.empty());
|
||||
|
||||
ServerRequest request = MockServerRequest.builder()
|
||||
.pathVariable("id", "999")
|
||||
.queryParam("adminPassword", "password123")
|
||||
.body(Mono.just(updateRequest));
|
||||
Mono<ServerResponse> response = roleHandler.updateRole(request);
|
||||
|
||||
@@ -302,13 +288,10 @@ class SysRoleHandlerTest {
|
||||
|
||||
@Test
|
||||
void testDeleteRole() {
|
||||
when(authUtil.getMemberIdOrThrow(any())).thenReturn(1L);
|
||||
when(userService.verifyPassword(1L, "password123")).thenReturn(Mono.just(true));
|
||||
when(roleService.logicalDeleteRole(2L)).thenReturn(Mono.just(testRole));
|
||||
when(roleService.logicalDeleteRole(1L)).thenReturn(Mono.just(testRole));
|
||||
|
||||
ServerRequest request = MockServerRequest.builder()
|
||||
.pathVariable("id", "2")
|
||||
.queryParam("adminPassword", "password123")
|
||||
.pathVariable("id", "1")
|
||||
.build();
|
||||
Mono<ServerResponse> response = roleHandler.deleteRole(request);
|
||||
|
||||
@@ -317,18 +300,15 @@ class SysRoleHandlerTest {
|
||||
serverResponse.statusCode() == HttpStatus.OK)
|
||||
.verifyComplete();
|
||||
|
||||
verify(roleService).logicalDeleteRole(2L);
|
||||
verify(roleService).logicalDeleteRole(1L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeleteRole_NotFound() {
|
||||
when(authUtil.getMemberIdOrThrow(any())).thenReturn(1L);
|
||||
when(userService.verifyPassword(1L, "password123")).thenReturn(Mono.just(true));
|
||||
when(roleService.logicalDeleteRole(999L)).thenReturn(Mono.empty());
|
||||
|
||||
ServerRequest request = MockServerRequest.builder()
|
||||
.pathVariable("id", "999")
|
||||
.queryParam("adminPassword", "password123")
|
||||
.build();
|
||||
Mono<ServerResponse> response = roleHandler.deleteRole(request);
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user