给店铺增加排班规则
This commit is contained in:
+24
@@ -25,7 +25,9 @@ import com.xiaowang.jayucloud.core.modules.product.service.ProductService;
|
||||
import com.xiaowang.jayucloud.core.modules.product.vo.ProductVO;
|
||||
import com.xiaowang.jayucloud.core.modules.security.support.AdminScopeHelper;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.dto.ShopDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.dto.ShopScheduleExceptionDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.service.ShopService;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.vo.ShopScheduleExceptionVO;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.vo.ShopVO;
|
||||
import com.xiaowang.jayucloud.core.modules.user.dto.UserDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.user.entity.UserDO;
|
||||
@@ -294,4 +296,26 @@ public class AdminManagerController {
|
||||
}
|
||||
return Result.success(shopService.updateShop(shopId, dto));
|
||||
}
|
||||
|
||||
@GetMapping("/shop/schedule-exceptions")
|
||||
@RequirePermission("shop:view")
|
||||
public Result<List<ShopScheduleExceptionVO>> shopScheduleExceptions(HttpServletRequest request,
|
||||
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
|
||||
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
Long shopId = adminScopeHelper.resolveShopScope(currentUser, null);
|
||||
adminScopeHelper.requireShopContext(currentUser);
|
||||
return Result.success(shopService.listScheduleExceptions(shopId, startDate, endDate));
|
||||
}
|
||||
|
||||
@PostMapping("/shop/schedule-exceptions")
|
||||
@RequirePermission("shop:edit")
|
||||
@OperationGuard(action = "manager-shop-schedule-exception-save", ttlSeconds = 10, message = "店铺特殊日期保存处理中,请勿重复提交")
|
||||
public Result<ShopScheduleExceptionVO> saveShopScheduleException(HttpServletRequest request,
|
||||
@RequestBody ShopScheduleExceptionDTO dto) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
dto.setShopId(adminScopeHelper.resolveShopScope(currentUser, dto.getShopId()));
|
||||
adminScopeHelper.requireShopContext(currentUser);
|
||||
return Result.success(shopService.saveScheduleException(dto));
|
||||
}
|
||||
}
|
||||
|
||||
+37
-5
@@ -11,6 +11,7 @@ import com.xiaowang.jayucloud.core.modules.order.entity.OrderDO;
|
||||
import com.xiaowang.jayucloud.core.modules.order.entity.OrderItemDO;
|
||||
import com.xiaowang.jayucloud.core.modules.product.entity.ProductDO;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.entity.ShopDO;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.entity.ShopScheduleExceptionDO;
|
||||
import com.xiaowang.jayucloud.core.modules.user.entity.UserDO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.mapper.AppointmentReservationMapper;
|
||||
import com.xiaowang.jayucloud.core.modules.artist.mapper.ArtistScheduleMapper;
|
||||
@@ -19,6 +20,7 @@ import com.xiaowang.jayucloud.core.modules.order.mapper.OrderItemMapper;
|
||||
import com.xiaowang.jayucloud.core.modules.order.mapper.OrderMapper;
|
||||
import com.xiaowang.jayucloud.core.modules.product.mapper.ProductMapper;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.mapper.ShopMapper;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.mapper.ShopScheduleExceptionMapper;
|
||||
import com.xiaowang.jayucloud.core.modules.user.mapper.UserMapper;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.service.AppointmentCapacityService;
|
||||
import com.xiaowang.jayucloud.core.modules.order.service.OrderService;
|
||||
@@ -26,6 +28,7 @@ import com.xiaowang.jayucloud.core.modules.planning.service.PlanningService;
|
||||
import com.xiaowang.jayucloud.core.modules.security.support.AdminScopeHelper;
|
||||
import com.xiaowang.jayucloud.core.modules.order.support.OrderStatus;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.support.PlanningCalendarSupport;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.support.ShopScheduleSupport;
|
||||
import com.xiaowang.jayucloud.core.support.id.TimeOrderedSnowflakeIdGenerator;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.vo.PlanningAppointmentVO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.vo.PlanningArtistCountVO;
|
||||
@@ -83,6 +86,7 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
private final OrderItemMapper orderItemMapper;
|
||||
private final ProductMapper productMapper;
|
||||
private final ShopMapper shopMapper;
|
||||
private final ShopScheduleExceptionMapper shopScheduleExceptionMapper;
|
||||
private final AppointmentCapacityService appointmentCapacityService;
|
||||
private final OrderService orderService;
|
||||
private final TimeOrderedSnowflakeIdGenerator snowflakeIdGenerator;
|
||||
@@ -103,6 +107,7 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
PlanningCalendarSupport.BusinessHours businessHours = PlanningCalendarSupport.parseBusinessHours(
|
||||
shop == null ? null : shop.getBusinessHours()
|
||||
);
|
||||
Map<LocalDate, ShopScheduleExceptionDO> shopExceptionByDate = listShopScheduleExceptions(shopId, start, end);
|
||||
|
||||
List<PlanningArtistVO> artists = listArtists(shopId, artistId);
|
||||
List<ArtistScheduleDO> schedules = listSchedules(shopId, start, end, artistId);
|
||||
@@ -128,7 +133,7 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
vo.setArtists(artists);
|
||||
vo.setSchedules(scheduleVos);
|
||||
vo.setAppointments(appointments);
|
||||
vo.setDaySummaries(buildDaySummaries(start, end, artists, schedules, appointments));
|
||||
vo.setDaySummaries(buildDaySummaries(start, end, artists, schedules, appointments, shop, shopExceptionByDate));
|
||||
return vo;
|
||||
}
|
||||
|
||||
@@ -505,7 +510,8 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
}
|
||||
|
||||
private List<PlanningDaySummaryVO> buildDaySummaries(LocalDate start, LocalDate end, List<PlanningArtistVO> artists,
|
||||
List<ArtistScheduleDO> schedules, List<PlanningAppointmentVO> appointments) {
|
||||
List<ArtistScheduleDO> schedules, List<PlanningAppointmentVO> appointments,
|
||||
ShopDO shop, Map<LocalDate, ShopScheduleExceptionDO> shopExceptionByDate) {
|
||||
Map<String, List<PlanningAppointmentVO>> appointmentsByDate = appointments.stream()
|
||||
.filter(appointment -> appointment.getDate() != null)
|
||||
.collect(Collectors.groupingBy(PlanningAppointmentVO::getDate));
|
||||
@@ -558,13 +564,27 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
summary.setDate(date);
|
||||
summary.setTotalCount(total);
|
||||
summary.setArtistCounts(artistCounts);
|
||||
summary.setDayStatus(PlanningCalendarSupport.resolveDayStatus(total, hasWorkingSchedule, allFull));
|
||||
ShopScheduleSupport.LocalTimeRange openRange = ShopScheduleSupport.resolveOpenRange(shop, shopExceptionByDate.get(cursor), cursor);
|
||||
summary.setBusinessStartTime(openRange.startTime() == null ? null : openRange.startTime().toString());
|
||||
summary.setBusinessEndTime(openRange.endTime() == null ? null : openRange.endTime().toString());
|
||||
summary.setDayStatus(openRange.open()
|
||||
? PlanningCalendarSupport.resolveDayStatus(total, hasWorkingSchedule, allFull)
|
||||
: "rest");
|
||||
summaries.add(summary);
|
||||
cursor = cursor.plusDays(1);
|
||||
}
|
||||
return summaries;
|
||||
}
|
||||
|
||||
private Map<LocalDate, ShopScheduleExceptionDO> listShopScheduleExceptions(Long shopId, LocalDate start, LocalDate end) {
|
||||
return shopScheduleExceptionMapper.selectList(new QueryWrapper<ShopScheduleExceptionDO>()
|
||||
.eq("shop_id", shopId)
|
||||
.eq("is_delete", 0)
|
||||
.between("work_date", start, end))
|
||||
.stream()
|
||||
.collect(Collectors.toMap(ShopScheduleExceptionDO::getWorkDate, Function.identity(), (a, b) -> a));
|
||||
}
|
||||
|
||||
private String resolveArtistDayStatus(PlanningArtistVO artist, ArtistScheduleDO schedule, List<PlanningAppointmentVO> appointments) {
|
||||
if (schedule != null && !Integer.valueOf(1).equals(schedule.getStatus())) {
|
||||
return "rest";
|
||||
@@ -740,14 +760,26 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
|
||||
private void ensureWithinBusinessHours(Long shopId, LocalDateTime startTime, LocalDateTime endTime) {
|
||||
ShopDO shop = shopMapper.selectById(shopId);
|
||||
PlanningCalendarSupport.BusinessHours hours = PlanningCalendarSupport.parseBusinessHours(shop == null ? null : shop.getBusinessHours());
|
||||
LocalDate workDate = startTime.toLocalDate();
|
||||
ShopScheduleSupport.LocalTimeRange hours = ShopScheduleSupport.resolveOpenRange(shop, selectShopScheduleException(shopId, workDate), workDate);
|
||||
if (!hours.open()) {
|
||||
throw new RuntimeException("当前日期为店铺休息日,不能预约:" + workDate);
|
||||
}
|
||||
LocalTime start = startTime.toLocalTime();
|
||||
LocalTime end = endTime.toLocalTime();
|
||||
if (start.isBefore(hours.start()) || end.isAfter(hours.end()) || !startTime.toLocalDate().equals(endTime.toLocalDate())) {
|
||||
if (start.isBefore(hours.startTime()) || end.isAfter(hours.endTime()) || !startTime.toLocalDate().equals(endTime.toLocalDate())) {
|
||||
throw new RuntimeException("预约时间超出店铺营业时间");
|
||||
}
|
||||
}
|
||||
|
||||
private ShopScheduleExceptionDO selectShopScheduleException(Long shopId, LocalDate workDate) {
|
||||
return shopScheduleExceptionMapper.selectOne(new QueryWrapper<ShopScheduleExceptionDO>()
|
||||
.eq("shop_id", shopId)
|
||||
.eq("work_date", workDate)
|
||||
.eq("is_delete", 0)
|
||||
.last("LIMIT 1"));
|
||||
}
|
||||
|
||||
private LocalDateTime parseAppointmentStart(String appointmentStartTime, String appointmentDate, String appointmentTime) {
|
||||
if (hasText(appointmentStartTime)) {
|
||||
String normalized = appointmentStartTime.trim().replace('T', ' ');
|
||||
|
||||
+2
@@ -10,4 +10,6 @@ public class PlanningDaySummaryVO {
|
||||
private Integer totalCount;
|
||||
private List<PlanningArtistCountVO> artistCounts;
|
||||
private String dayStatus;
|
||||
private String businessStartTime;
|
||||
private String businessEndTime;
|
||||
}
|
||||
|
||||
@@ -54,6 +54,12 @@ public class ShopDTO {
|
||||
*/
|
||||
private String businessHours;
|
||||
|
||||
private String schedulePresetType;
|
||||
|
||||
private String scheduleWorkDays;
|
||||
|
||||
private String scheduleRemark;
|
||||
|
||||
/**
|
||||
* 店铺封面图文件ID集合(Banner图),多个ID以逗号分隔
|
||||
*/
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.xiaowang.jayucloud.core.modules.shop.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
|
||||
@Data
|
||||
public class ShopScheduleExceptionDTO {
|
||||
private Long shopId;
|
||||
private LocalDate workDate;
|
||||
private String exceptionType;
|
||||
private LocalTime startTime;
|
||||
private LocalTime endTime;
|
||||
private String remark;
|
||||
}
|
||||
@@ -76,6 +76,15 @@ public class ShopDO extends BaseEntity {
|
||||
@TableField("business_hours")
|
||||
private String businessHours;
|
||||
|
||||
@TableField("schedule_preset_type")
|
||||
private String schedulePresetType;
|
||||
|
||||
@TableField("schedule_work_days")
|
||||
private String scheduleWorkDays;
|
||||
|
||||
@TableField("schedule_remark")
|
||||
private String scheduleRemark;
|
||||
|
||||
/**
|
||||
* 店铺封面图文件ID集合(Banner图),多个ID以逗号分隔
|
||||
*/
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.xiaowang.jayucloud.core.modules.shop.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.xiaowang.jayucloud.core.common.entity.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("t_shop_schedule_exception")
|
||||
public class ShopScheduleExceptionDO extends BaseEntity {
|
||||
@TableField("shop_id")
|
||||
private Long shopId;
|
||||
@TableField("work_date")
|
||||
private LocalDate workDate;
|
||||
@TableField("exception_type")
|
||||
private String exceptionType;
|
||||
@TableField("start_time")
|
||||
private LocalTime startTime;
|
||||
@TableField("end_time")
|
||||
private LocalTime endTime;
|
||||
@TableField("remark")
|
||||
private String remark;
|
||||
@TableField("is_delete")
|
||||
@TableLogic
|
||||
private Integer isDelete;
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.xiaowang.jayucloud.core.modules.shop.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.entity.ShopScheduleExceptionDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface ShopScheduleExceptionMapper extends BaseMapper<ShopScheduleExceptionDO> {
|
||||
}
|
||||
+7
@@ -3,10 +3,13 @@ package com.xiaowang.jayucloud.core.modules.shop.service;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.entity.ShopDO;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.dto.ShopDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.dto.ShopScheduleExceptionDTO;
|
||||
import com.xiaowang.jayucloud.core.common.vo.PageResultVO;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.vo.ShopScheduleExceptionVO;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.vo.ShopTrustProfileVO;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.vo.ShopVO;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -110,4 +113,8 @@ public interface ShopService extends IService<ShopDO> {
|
||||
* 前台可用:未删除、启用、且授权未到期。
|
||||
*/
|
||||
boolean isFrontendAvailable(Long shopId);
|
||||
|
||||
List<ShopScheduleExceptionVO> listScheduleExceptions(Long shopId, LocalDate startDate, LocalDate endDate);
|
||||
|
||||
ShopScheduleExceptionVO saveScheduleException(ShopScheduleExceptionDTO dto);
|
||||
}
|
||||
|
||||
+94
@@ -7,11 +7,13 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.xiaowang.jayucloud.core.config.AppCacheProperties;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.dto.ShopDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.dto.ShopScheduleExceptionDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.marketing.entity.CouponDO;
|
||||
import com.xiaowang.jayucloud.core.modules.content.entity.CommentDO;
|
||||
import com.xiaowang.jayucloud.core.modules.order.entity.OrderArtistReviewDO;
|
||||
import com.xiaowang.jayucloud.core.modules.product.entity.ProductDO;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.entity.ShopDO;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.entity.ShopScheduleExceptionDO;
|
||||
import com.xiaowang.jayucloud.core.modules.product.entity.TagDO;
|
||||
import com.xiaowang.jayucloud.core.modules.marketing.entity.UserCouponDO;
|
||||
import com.xiaowang.jayucloud.core.modules.content.mapper.CommentMapper;
|
||||
@@ -19,6 +21,7 @@ import com.xiaowang.jayucloud.core.modules.marketing.mapper.CouponMapper;
|
||||
import com.xiaowang.jayucloud.core.modules.order.mapper.OrderArtistReviewMapper;
|
||||
import com.xiaowang.jayucloud.core.modules.product.mapper.ProductMapper;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.mapper.ShopMapper;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.mapper.ShopScheduleExceptionMapper;
|
||||
import com.xiaowang.jayucloud.core.modules.product.mapper.TagMapper;
|
||||
import com.xiaowang.jayucloud.core.modules.marketing.mapper.UserCouponMapper;
|
||||
import com.xiaowang.jayucloud.core.modules.marketing.service.CouponService;
|
||||
@@ -27,11 +30,13 @@ import com.xiaowang.jayucloud.core.modules.artist.service.NailArtistInfoService;
|
||||
import com.xiaowang.jayucloud.core.modules.file.service.ObjectStorageFileService;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.service.ShopService;
|
||||
import com.xiaowang.jayucloud.core.modules.file.support.ObjectStorageUrlSupport;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.support.ShopScheduleSupport;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.support.ShopThemeSupport;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.support.UserShopBindingSupport;
|
||||
import com.xiaowang.jayucloud.core.support.cache.MultiLevelCacheService;
|
||||
import com.xiaowang.jayucloud.core.modules.file.vo.ObjectStorageFileVO;
|
||||
import com.xiaowang.jayucloud.core.common.vo.PageResultVO;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.vo.ShopScheduleExceptionVO;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.vo.ShopTrustProfileVO;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.vo.ShopVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -89,6 +94,7 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopDO> implements
|
||||
* Variable `shopMapper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
*/
|
||||
private final ShopMapper shopMapper;
|
||||
private final ShopScheduleExceptionMapper shopScheduleExceptionMapper;
|
||||
/**
|
||||
* Variable `couponService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
*/
|
||||
@@ -161,6 +167,7 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopDO> implements
|
||||
shopDO.setLongitude(shopDTO.getLongitude());
|
||||
shopDO.setLatitude(shopDTO.getLatitude());
|
||||
shopDO.setBusinessHours(shopDTO.getBusinessHours());
|
||||
applyScheduleRule(shopDO, shopDTO);
|
||||
shopDO.setCoverImageFileId(shopDTO.getCoverImageFileId());
|
||||
shopDO.setImageFileIds(shopDTO.getImageFileIds());
|
||||
applyTheme(shopDO, shopDTO);
|
||||
@@ -196,6 +203,7 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopDO> implements
|
||||
shopDO.setLongitude(shopDTO.getLongitude());
|
||||
shopDO.setLatitude(shopDTO.getLatitude());
|
||||
shopDO.setBusinessHours(shopDTO.getBusinessHours());
|
||||
applyScheduleRule(shopDO, shopDTO);
|
||||
shopDO.setCoverImageFileId(shopDTO.getCoverImageFileId());
|
||||
shopDO.setImageFileIds(shopDTO.getImageFileIds());
|
||||
applyTheme(shopDO, shopDTO);
|
||||
@@ -453,6 +461,45 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopDO> implements
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ShopScheduleExceptionVO> listScheduleExceptions(Long shopId, LocalDate startDate, LocalDate endDate) {
|
||||
if (shopId == null) {
|
||||
throw new RuntimeException("店铺ID不能为空");
|
||||
}
|
||||
LocalDate start = startDate == null ? LocalDate.now() : startDate;
|
||||
LocalDate end = endDate == null ? start.plusDays(60L) : endDate;
|
||||
if (end.isBefore(start)) {
|
||||
end = start;
|
||||
}
|
||||
return shopScheduleExceptionMapper.selectList(Wrappers.lambdaQuery(ShopScheduleExceptionDO.class)
|
||||
.eq(ShopScheduleExceptionDO::getShopId, shopId)
|
||||
.eq(ShopScheduleExceptionDO::getIsDelete, 0)
|
||||
.between(ShopScheduleExceptionDO::getWorkDate, start, end)
|
||||
.orderByAsc(ShopScheduleExceptionDO::getWorkDate))
|
||||
.stream()
|
||||
.map(this::toScheduleExceptionVO)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ShopScheduleExceptionVO saveScheduleException(ShopScheduleExceptionDTO dto) {
|
||||
ShopScheduleExceptionDO normalized = normalizeScheduleException(dto);
|
||||
ShopScheduleExceptionDO existing = shopScheduleExceptionMapper.selectOne(Wrappers.lambdaQuery(ShopScheduleExceptionDO.class)
|
||||
.eq(ShopScheduleExceptionDO::getShopId, normalized.getShopId())
|
||||
.eq(ShopScheduleExceptionDO::getWorkDate, normalized.getWorkDate())
|
||||
.eq(ShopScheduleExceptionDO::getIsDelete, 0)
|
||||
.last("LIMIT 1"));
|
||||
if (existing == null) {
|
||||
shopScheduleExceptionMapper.insert(normalized);
|
||||
} else {
|
||||
normalized.setId(existing.getId());
|
||||
shopScheduleExceptionMapper.updateById(normalized);
|
||||
}
|
||||
evictShopCaches(normalized.getShopId());
|
||||
return toScheduleExceptionVO(normalized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: countActiveProducts counts products that can contribute to a public shop trust profile.
|
||||
* Usage: call it with a valid shop id before rendering product trust metrics.
|
||||
@@ -768,6 +815,9 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopDO> implements
|
||||
shopVO.setLatitude(shopDO.getLatitude());
|
||||
shopVO.setNavigationUrls(mapService.buildNavigationUrls(shopDO.getShopName(), shopDO.getAddress(), shopDO.getLongitude(), shopDO.getLatitude()));
|
||||
shopVO.setBusinessHours(shopDO.getBusinessHours());
|
||||
shopVO.setSchedulePresetType(ShopScheduleSupport.normalizePresetType(shopDO.getSchedulePresetType()));
|
||||
shopVO.setScheduleWorkDays(ShopScheduleSupport.normalizeWorkDays(shopDO.getScheduleWorkDays(), shopDO.getSchedulePresetType()));
|
||||
shopVO.setScheduleRemark(shopDO.getScheduleRemark());
|
||||
shopVO.setCoverImageFileId(shopDO.getCoverImageFileId());
|
||||
shopVO.setCoverImageUrls(new java.util.ArrayList<>());
|
||||
shopVO.setImageFileIds(shopDO.getImageFileIds());
|
||||
@@ -870,6 +920,50 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopDO> implements
|
||||
shopDO.setAuthorizationExpireTime(shopDTO.getAuthorizationExpireTime());
|
||||
}
|
||||
|
||||
private void applyScheduleRule(ShopDO shopDO, ShopDTO shopDTO) {
|
||||
if (shopDO.getId() != null && !StringUtils.hasText(shopDTO.getSchedulePresetType())
|
||||
&& !StringUtils.hasText(shopDTO.getScheduleWorkDays()) && !StringUtils.hasText(shopDTO.getScheduleRemark())) {
|
||||
return;
|
||||
}
|
||||
String presetType = ShopScheduleSupport.normalizePresetType(shopDTO.getSchedulePresetType());
|
||||
shopDO.setSchedulePresetType(presetType);
|
||||
shopDO.setScheduleWorkDays(ShopScheduleSupport.normalizeWorkDays(shopDTO.getScheduleWorkDays(), presetType));
|
||||
shopDO.setScheduleRemark(StringUtils.hasText(shopDTO.getScheduleRemark()) ? shopDTO.getScheduleRemark().trim() : null);
|
||||
}
|
||||
|
||||
private ShopScheduleExceptionDO normalizeScheduleException(ShopScheduleExceptionDTO dto) {
|
||||
if (dto == null || dto.getShopId() == null || dto.getWorkDate() == null) {
|
||||
throw new RuntimeException("店铺特殊日期信息不完整");
|
||||
}
|
||||
String exceptionType = ShopScheduleSupport.normalizeExceptionType(dto.getExceptionType());
|
||||
if (!ShopScheduleSupport.EXCEPTION_REST.equals(exceptionType)
|
||||
&& (dto.getStartTime() == null || dto.getEndTime() == null || !dto.getStartTime().isBefore(dto.getEndTime()))) {
|
||||
throw new RuntimeException("临时营业或改班必须填写正确的开始和结束时间");
|
||||
}
|
||||
ShopScheduleExceptionDO exception = new ShopScheduleExceptionDO();
|
||||
exception.setShopId(dto.getShopId());
|
||||
exception.setWorkDate(dto.getWorkDate());
|
||||
exception.setExceptionType(exceptionType);
|
||||
exception.setStartTime(ShopScheduleSupport.EXCEPTION_REST.equals(exceptionType) ? null : dto.getStartTime());
|
||||
exception.setEndTime(ShopScheduleSupport.EXCEPTION_REST.equals(exceptionType) ? null : dto.getEndTime());
|
||||
exception.setRemark(StringUtils.hasText(dto.getRemark()) ? dto.getRemark().trim() : null);
|
||||
exception.setIsDelete(0);
|
||||
return exception;
|
||||
}
|
||||
|
||||
private ShopScheduleExceptionVO toScheduleExceptionVO(ShopScheduleExceptionDO exception) {
|
||||
ShopScheduleExceptionVO vo = new ShopScheduleExceptionVO();
|
||||
vo.setId(exception.getId());
|
||||
vo.setShopId(exception.getShopId());
|
||||
vo.setWorkDate(exception.getWorkDate());
|
||||
vo.setExceptionType(exception.getExceptionType());
|
||||
vo.setStartTime(exception.getStartTime());
|
||||
vo.setEndTime(exception.getEndTime());
|
||||
vo.setRemark(exception.getRemark());
|
||||
vo.setCreateTime(exception.getCreateTime());
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: applyTheme supports ShopServiceImpl.java by holding or executing the apply theme business role.
|
||||
* Usage: reference this method from the owning layer and pass validated inputs before reading or updating related state.
|
||||
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
package com.xiaowang.jayucloud.core.modules.shop.support;
|
||||
|
||||
import com.xiaowang.jayucloud.core.modules.planning.support.PlanningCalendarSupport;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.entity.ShopDO;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.entity.ShopScheduleExceptionDO;
|
||||
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class ShopScheduleSupport {
|
||||
public static final String PRESET_EVERYDAY = "EVERYDAY";
|
||||
public static final String PRESET_DOUBLE_REST = "DOUBLE_REST";
|
||||
public static final String PRESET_SINGLE_REST = "SINGLE_REST";
|
||||
public static final String PRESET_CUSTOM = "CUSTOM";
|
||||
public static final String EXCEPTION_REST = "REST";
|
||||
public static final String EXCEPTION_EXTRA_WORK = "EXTRA_WORK";
|
||||
public static final String EXCEPTION_CHANGE_SHIFT = "CHANGE_SHIFT";
|
||||
private static final List<Integer> EVERYDAY_WORK_DAYS = List.of(1, 2, 3, 4, 5, 6, 7);
|
||||
|
||||
private ShopScheduleSupport() {
|
||||
}
|
||||
|
||||
public static String normalizePresetType(String presetType) {
|
||||
if (presetType == null || presetType.trim().isEmpty()) {
|
||||
return PRESET_EVERYDAY;
|
||||
}
|
||||
String value = presetType.trim();
|
||||
if (PRESET_EVERYDAY.equals(value) || PRESET_DOUBLE_REST.equals(value)
|
||||
|| PRESET_SINGLE_REST.equals(value) || PRESET_CUSTOM.equals(value)) {
|
||||
return value;
|
||||
}
|
||||
throw new RuntimeException("不支持的店铺排班预设:" + value);
|
||||
}
|
||||
|
||||
public static List<Integer> resolveWorkDays(String workDays, String presetType) {
|
||||
String normalizedPreset = normalizePresetType(presetType);
|
||||
List<Integer> presetDays = switch (normalizedPreset) {
|
||||
case PRESET_DOUBLE_REST -> List.of(1, 2, 3, 4, 5);
|
||||
case PRESET_SINGLE_REST -> List.of(1, 2, 3, 4, 5, 6);
|
||||
case PRESET_EVERYDAY -> EVERYDAY_WORK_DAYS;
|
||||
default -> workDays == null ? List.of() : decodeWorkDays(workDays);
|
||||
};
|
||||
List<Integer> normalized = normalizeWorkDays(presetDays);
|
||||
if (normalized.isEmpty()) {
|
||||
throw new RuntimeException("请至少选择一个店铺营业日");
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
public static String normalizeWorkDays(String workDays, String presetType) {
|
||||
return encodeWorkDays(resolveWorkDays(workDays, presetType));
|
||||
}
|
||||
|
||||
public static List<Integer> decodeWorkDays(String workDays) {
|
||||
if (workDays == null) {
|
||||
return EVERYDAY_WORK_DAYS;
|
||||
}
|
||||
if (workDays.trim().isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
return List.of(workDays.split(",")).stream()
|
||||
.map(String::trim)
|
||||
.filter(value -> !value.isEmpty())
|
||||
.map(Integer::valueOf)
|
||||
.toList();
|
||||
}
|
||||
|
||||
public static String encodeWorkDays(List<Integer> workDays) {
|
||||
return normalizeWorkDays(workDays).stream()
|
||||
.map(String::valueOf)
|
||||
.collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
public static String normalizeExceptionType(String exceptionType) {
|
||||
if (exceptionType == null || exceptionType.trim().isEmpty()) {
|
||||
throw new RuntimeException("特殊日期类型不能为空");
|
||||
}
|
||||
String value = exceptionType.trim();
|
||||
if (EXCEPTION_REST.equals(value) || EXCEPTION_EXTRA_WORK.equals(value) || EXCEPTION_CHANGE_SHIFT.equals(value)) {
|
||||
return value;
|
||||
}
|
||||
throw new RuntimeException("不支持的店铺特殊日期类型:" + value);
|
||||
}
|
||||
|
||||
public static LocalTimeRange resolveOpenRange(ShopDO shop, ShopScheduleExceptionDO exception, LocalDate workDate) {
|
||||
PlanningCalendarSupport.BusinessHours businessHours = PlanningCalendarSupport.parseBusinessHours(shop == null ? null : shop.getBusinessHours());
|
||||
if (exception != null) {
|
||||
if (EXCEPTION_REST.equals(exception.getExceptionType())) {
|
||||
return new LocalTimeRange(false, businessHours.start(), businessHours.end(), exceptionRemark(exception));
|
||||
}
|
||||
if (EXCEPTION_EXTRA_WORK.equals(exception.getExceptionType()) || EXCEPTION_CHANGE_SHIFT.equals(exception.getExceptionType())) {
|
||||
if (exception.getStartTime() == null || exception.getEndTime() == null) {
|
||||
throw new RuntimeException("店铺特殊日期营业时间不完整:" + exception.getWorkDate());
|
||||
}
|
||||
return new LocalTimeRange(true, exception.getStartTime(), exception.getEndTime(), exceptionRemark(exception));
|
||||
}
|
||||
}
|
||||
List<Integer> workDays = resolveWorkDays(shop == null ? null : shop.getScheduleWorkDays(), shop == null ? null : shop.getSchedulePresetType());
|
||||
boolean open = workDays.contains(workDate.getDayOfWeek().getValue());
|
||||
return new LocalTimeRange(open, businessHours.start(), businessHours.end(), "店铺常规营业");
|
||||
}
|
||||
|
||||
private static List<Integer> normalizeWorkDays(List<Integer> workDays) {
|
||||
Set<Integer> normalized = new LinkedHashSet<>();
|
||||
for (Integer day : workDays == null ? List.<Integer>of() : workDays) {
|
||||
if (day != null && day >= DayOfWeek.MONDAY.getValue() && day <= DayOfWeek.SUNDAY.getValue()) {
|
||||
normalized.add(day);
|
||||
}
|
||||
}
|
||||
return normalized.stream().sorted().toList();
|
||||
}
|
||||
|
||||
private static String exceptionRemark(ShopScheduleExceptionDO exception) {
|
||||
if (exception.getRemark() != null && !exception.getRemark().isBlank()) {
|
||||
return exception.getRemark();
|
||||
}
|
||||
return "店铺特殊日期:" + exception.getExceptionType();
|
||||
}
|
||||
|
||||
public record LocalTimeRange(boolean open, LocalTime startTime, LocalTime endTime, String remark) {
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.xiaowang.jayucloud.core.modules.shop.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
|
||||
@Data
|
||||
public class ShopScheduleExceptionVO {
|
||||
private Long id;
|
||||
private Long shopId;
|
||||
private LocalDate workDate;
|
||||
private String exceptionType;
|
||||
private LocalTime startTime;
|
||||
private LocalTime endTime;
|
||||
private String remark;
|
||||
private LocalDateTime createTime;
|
||||
}
|
||||
@@ -70,6 +70,12 @@ public class ShopVO {
|
||||
*/
|
||||
private String businessHours;
|
||||
|
||||
private String schedulePresetType;
|
||||
|
||||
private String scheduleWorkDays;
|
||||
|
||||
private String scheduleRemark;
|
||||
|
||||
/**
|
||||
* 店铺封面图文件ID集合(Banner图),多个ID以逗号分隔
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user