优化:提升小程序全链路性能
This commit is contained in:
+8
@@ -21,6 +21,7 @@ import com.xiaowang.jacyucloudsalon.core.modules.planning.dto.PlanningAppointmen
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.planning.service.PlanningService;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.planning.vo.PlanningAppointmentVO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.planning.vo.PlanningCalendarVO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.planning.vo.PlanningTodayOverviewVO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.product.service.ProductService;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.product.vo.ProductVO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.security.support.AdminScopeHelper;
|
||||
@@ -72,6 +73,13 @@ public class AdminManagerController {
|
||||
return Result.success(planningService.getCalendar(currentUser, start, end, artistId));
|
||||
}
|
||||
|
||||
@GetMapping("/planning/today-overview")
|
||||
@RequirePermission("schedule:view")
|
||||
public Result<PlanningTodayOverviewVO> todayOverview(HttpServletRequest request) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
return Result.success(planningService.getTodayOverview(currentUser));
|
||||
}
|
||||
|
||||
@PostMapping("/planning/appointments")
|
||||
@RequirePermission("order:process")
|
||||
@OperationGuard(action = "manager-planning-create-appointment", ttlSeconds = 10, message = "预约创建处理中,请勿重复提交")
|
||||
|
||||
+3
@@ -6,12 +6,15 @@ import com.xiaowang.jacyucloudsalon.core.modules.planning.dto.PlanningAppointmen
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.user.entity.UserDO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.planning.vo.PlanningAppointmentVO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.planning.vo.PlanningCalendarVO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.planning.vo.PlanningTodayOverviewVO;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
public interface PlanningService {
|
||||
PlanningCalendarVO getCalendar(UserDO currentUser, LocalDate startDate, LocalDate endDate, Long artistId);
|
||||
|
||||
PlanningTodayOverviewVO getTodayOverview(UserDO currentUser);
|
||||
|
||||
PlanningAppointmentVO createAppointment(UserDO currentUser, PlanningAppointmentCreateDTO dto);
|
||||
|
||||
PlanningAppointmentVO getAppointment(UserDO currentUser, Long orderItemId);
|
||||
|
||||
+34
-7
@@ -6,6 +6,7 @@ import com.xiaowang.jacyucloudsalon.core.modules.planning.dto.PlanningAppointmen
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.planning.dto.PlanningAppointmentStatusDTO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.planning.entity.AppointmentReservationDO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.artist.entity.ArtistScheduleDO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.artist.entity.ArtistScheduleExceptionDO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.artist.entity.NailArtistInfoDO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.order.entity.OrderDO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.order.entity.OrderItemDO;
|
||||
@@ -14,6 +15,7 @@ import com.xiaowang.jacyucloudsalon.core.modules.shop.entity.ShopDO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.user.entity.UserDO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.planning.mapper.AppointmentReservationMapper;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.artist.mapper.ArtistScheduleMapper;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.artist.mapper.ArtistScheduleExceptionMapper;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.artist.mapper.NailArtistInfoMapper;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.order.mapper.OrderItemMapper;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.order.mapper.OrderMapper;
|
||||
@@ -26,6 +28,7 @@ import com.xiaowang.jacyucloudsalon.core.modules.planning.service.PlanningServic
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.security.support.AdminScopeHelper;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.order.support.OrderStatus;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.planning.support.PlanningCalendarSupport;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.planning.support.PlanningTodayOverviewSupport;
|
||||
import com.xiaowang.jacyucloudsalon.core.support.id.TimeOrderedSnowflakeIdGenerator;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.planning.vo.PlanningAppointmentVO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.planning.vo.PlanningArtistCountVO;
|
||||
@@ -33,6 +36,7 @@ import com.xiaowang.jacyucloudsalon.core.modules.planning.vo.PlanningArtistVO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.planning.vo.PlanningCalendarVO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.planning.vo.PlanningDaySummaryVO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.planning.vo.PlanningScheduleVO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.planning.vo.PlanningTodayOverviewVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -75,6 +79,7 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
private final UserMapper userMapper;
|
||||
private final NailArtistInfoMapper nailArtistInfoMapper;
|
||||
private final ArtistScheduleMapper artistScheduleMapper;
|
||||
private final ArtistScheduleExceptionMapper artistScheduleExceptionMapper;
|
||||
private final AppointmentReservationMapper appointmentReservationMapper;
|
||||
private final OrderMapper orderMapper;
|
||||
private final OrderItemMapper orderItemMapper;
|
||||
@@ -103,8 +108,10 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
|
||||
List<PlanningArtistVO> artists = listArtists(shopId, artistId);
|
||||
List<ArtistScheduleDO> schedules = listSchedules(shopId, start, end, artistId);
|
||||
Map<Long, String> artistNames = artists.stream()
|
||||
.collect(Collectors.toMap(PlanningArtistVO::getId, PlanningArtistVO::getName, (a, b) -> a));
|
||||
List<PlanningScheduleVO> scheduleVos = schedules.stream()
|
||||
.map(schedule -> toScheduleVO(schedule, artists))
|
||||
.map(schedule -> toScheduleVO(schedule, artistNames))
|
||||
.sorted(Comparator.comparing(PlanningScheduleVO::getDate)
|
||||
.thenComparing(PlanningScheduleVO::getStartTime)
|
||||
.thenComparing(PlanningScheduleVO::getArtistName, Comparator.nullsLast(String::compareTo)))
|
||||
@@ -129,6 +136,27 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
return vo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlanningTodayOverviewVO getTodayOverview(UserDO currentUser) {
|
||||
LocalDate today = LocalDate.now();
|
||||
Long shopId = requirePlanningShopId(currentUser);
|
||||
PlanningCalendarVO calendar = getCalendar(currentUser, today, today, null);
|
||||
QueryWrapper<ArtistScheduleExceptionDO> exceptionWrapper = new QueryWrapper<>();
|
||||
exceptionWrapper.eq("shop_id", shopId)
|
||||
.eq("work_date", today)
|
||||
.eq("is_delete", 0);
|
||||
Long exceptionCount = artistScheduleExceptionMapper.selectCount(exceptionWrapper);
|
||||
ShopDO shop = shopMapper.selectById(shopId);
|
||||
boolean shopOpen = shop != null && !Integer.valueOf(0).equals(shop.getStatus());
|
||||
return PlanningTodayOverviewSupport.build(
|
||||
calendar,
|
||||
today,
|
||||
LocalTime.now(),
|
||||
exceptionCount == null ? 0L : exceptionCount,
|
||||
shopOpen
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public PlanningAppointmentVO createAppointment(UserDO currentUser, PlanningAppointmentCreateDTO dto) {
|
||||
@@ -340,9 +368,7 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
return artistScheduleMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
private PlanningScheduleVO toScheduleVO(ArtistScheduleDO schedule, List<PlanningArtistVO> artists) {
|
||||
Map<Long, String> artistNames = artists.stream()
|
||||
.collect(Collectors.toMap(PlanningArtistVO::getId, PlanningArtistVO::getName, (a, b) -> a));
|
||||
private PlanningScheduleVO toScheduleVO(ArtistScheduleDO schedule, Map<Long, String> artistNames) {
|
||||
PlanningScheduleVO vo = new PlanningScheduleVO();
|
||||
vo.setId(schedule.getId());
|
||||
vo.setArtistId(schedule.getArtistId());
|
||||
@@ -518,6 +544,9 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
Map<Long, Long> countByArtist = dayAppointments.stream()
|
||||
.filter(appointment -> appointment.getArtistId() != null)
|
||||
.collect(Collectors.groupingBy(PlanningAppointmentVO::getArtistId, Collectors.counting()));
|
||||
Map<Long, List<PlanningAppointmentVO>> appointmentsByArtist = dayAppointments.stream()
|
||||
.filter(appointment -> appointment.getArtistId() != null)
|
||||
.collect(Collectors.groupingBy(PlanningAppointmentVO::getArtistId));
|
||||
List<ArtistScheduleDO> daySchedules = schedulesByDate.getOrDefault(date, List.of());
|
||||
Map<Long, ArtistScheduleDO> scheduleByArtist = daySchedules.stream()
|
||||
.collect(Collectors.toMap(ArtistScheduleDO::getArtistId, Function.identity(), (a, b) -> a));
|
||||
@@ -528,9 +557,7 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
for (PlanningArtistVO artist : artists) {
|
||||
int count = countByArtist.getOrDefault(artist.getId(), 0L).intValue();
|
||||
ArtistScheduleDO schedule = scheduleByArtist.get(artist.getId());
|
||||
List<PlanningAppointmentVO> artistAppointments = dayAppointments.stream()
|
||||
.filter(appointment -> Objects.equals(appointment.getArtistId(), artist.getId()))
|
||||
.toList();
|
||||
List<PlanningAppointmentVO> artistAppointments = appointmentsByArtist.getOrDefault(artist.getId(), List.of());
|
||||
String artistStatus = resolveArtistDayStatus(artist, schedule, artistAppointments);
|
||||
if (!"rest".equals(artistStatus)) {
|
||||
workingArtistCount++;
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package com.xiaowang.jacyucloudsalon.core.modules.planning.support;
|
||||
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.planning.vo.PlanningAppointmentVO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.planning.vo.PlanningArtistVO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.planning.vo.PlanningCalendarVO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.planning.vo.PlanningTodayOverviewVO;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.util.List;
|
||||
|
||||
public final class PlanningTodayOverviewSupport {
|
||||
|
||||
private PlanningTodayOverviewSupport() {
|
||||
}
|
||||
|
||||
public static PlanningTodayOverviewVO build(PlanningCalendarVO calendar,
|
||||
LocalDate date,
|
||||
LocalTime now,
|
||||
long scheduleExceptions,
|
||||
boolean shopOpen) {
|
||||
List<PlanningAppointmentVO> appointments = calendar == null || calendar.getAppointments() == null
|
||||
? List.of() : calendar.getAppointments();
|
||||
List<PlanningArtistVO> artists = calendar == null || calendar.getArtists() == null
|
||||
? List.of() : calendar.getArtists();
|
||||
int currentMinute = now.getHour() * 60 + now.getMinute();
|
||||
|
||||
PlanningTodayOverviewVO overview = new PlanningTodayOverviewVO();
|
||||
overview.setDate(String.format("%02d月%02d日", date.getMonthValue(), date.getDayOfMonth()));
|
||||
overview.setTodayAppointments(appointments.size());
|
||||
overview.setPendingAppointments((int) appointments.stream()
|
||||
.filter(item -> Integer.valueOf(0).equals(item.getStatus()))
|
||||
.count());
|
||||
overview.setUpcomingAppointments((int) appointments.stream()
|
||||
.filter(item -> item.getStartMinute() != null && item.getStartMinute() >= currentMinute)
|
||||
.count());
|
||||
overview.setAvailableEmployees((int) artists.stream()
|
||||
.filter(item -> !Integer.valueOf(0).equals(item.getStatus()))
|
||||
.count());
|
||||
overview.setScheduleExceptions(Math.toIntExact(Math.max(0L, scheduleExceptions)));
|
||||
overview.setShopOpen(shopOpen);
|
||||
overview.setShopStatus(shopOpen ? "营业中" : "已暂停");
|
||||
return overview;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.xiaowang.jacyucloudsalon.core.modules.planning.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PlanningTodayOverviewVO {
|
||||
private String date;
|
||||
private Integer todayAppointments;
|
||||
private Integer pendingAppointments;
|
||||
private Integer upcomingAppointments;
|
||||
private Integer availableEmployees;
|
||||
private Integer scheduleExceptions;
|
||||
private Boolean shopOpen;
|
||||
private String shopStatus;
|
||||
}
|
||||
Reference in New Issue
Block a user