功能:重建指尖管理师规划系统
This commit is contained in:
@@ -214,6 +214,7 @@ public class AuthInterceptor implements HandlerInterceptor {
|
||||
|| path.equals("/admin/user/info")
|
||||
|| path.equals("/permission/list/user/current")
|
||||
|| path.equals("/api/permission/list/user/current")
|
||||
|| path.startsWith("/admin/planning/")
|
||||
|| path.startsWith("/admin/shops/");
|
||||
}
|
||||
|
||||
|
||||
+7
@@ -3,6 +3,7 @@ package com.xiaowang.yuminailcore.controller;
|
||||
import com.xiaowang.yuminailcore.annotation.OperationGuard;
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.dto.LoginRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.PlanningManagerRegisterDTO;
|
||||
import com.xiaowang.yuminailcore.dto.RefreshTokenRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.SwitchShopRequestDTO;
|
||||
import com.xiaowang.yuminailcore.service.UserService;
|
||||
@@ -63,6 +64,12 @@ public class AdminAuthController {
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/register")
|
||||
@OperationGuard(action = "admin-planning-register", ttlSeconds = 10, message = "注册处理中,请勿重复提交")
|
||||
public Result<LoginResponseVO> register(@RequestBody PlanningManagerRegisterDTO registerDTO) {
|
||||
return Result.success(userService.registerPlanningManager(registerDTO));
|
||||
}
|
||||
|
||||
@GetMapping("/login-shops/{account}")
|
||||
/**
|
||||
* Load data by the supplied parameter.
|
||||
|
||||
+19
@@ -3,6 +3,7 @@ package com.xiaowang.yuminailcore.controller;
|
||||
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||
import com.xiaowang.yuminailcore.annotation.OperationGuard;
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.dto.OrderQuoteSubmitDTO;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.service.OrderService;
|
||||
import com.xiaowang.yuminailcore.support.AdminScopeHelper;
|
||||
@@ -141,4 +142,22 @@ public class AdminOrderController {
|
||||
orderService.processOrder(id, status);
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/quote")
|
||||
@RequirePermission("order:process")
|
||||
@OperationGuard(action = "admin-order-quote-submit", ttlSeconds = 10, message = "报价处理中,请勿重复提交")
|
||||
public Result<OrderVO> submitQuote(HttpServletRequest request,
|
||||
@PathVariable Long id,
|
||||
@RequestBody OrderQuoteSubmitDTO dto) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
return Result.success(orderService.submitShopQuote(id, currentUser.getId(), currentUser.getType(), dto));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}/quote/confirm")
|
||||
@RequirePermission("order:process")
|
||||
@OperationGuard(action = "admin-order-quote-confirm", ttlSeconds = 10, message = "确认处理中,请勿重复提交")
|
||||
public Result<OrderVO> confirmQuote(HttpServletRequest request, @PathVariable Long id) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
return Result.success(orderService.confirmShopQuote(id, currentUser.getId(), currentUser.getType()));
|
||||
}
|
||||
}
|
||||
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package com.xiaowang.yuminailcore.controller;
|
||||
|
||||
import com.xiaowang.yuminailcore.annotation.OperationGuard;
|
||||
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.dto.PlanningAppointmentCreateDTO;
|
||||
import com.xiaowang.yuminailcore.dto.PlanningAppointmentMoveDTO;
|
||||
import com.xiaowang.yuminailcore.dto.PlanningAppointmentStatusDTO;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.service.PlanningService;
|
||||
import com.xiaowang.yuminailcore.support.AdminScopeHelper;
|
||||
import com.xiaowang.yuminailcore.vo.PlanningAppointmentVO;
|
||||
import com.xiaowang.yuminailcore.vo.PlanningCalendarVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.time.LocalDate;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/planning")
|
||||
@RequiredArgsConstructor
|
||||
public class AdminPlanningController {
|
||||
|
||||
private final PlanningService planningService;
|
||||
private final AdminScopeHelper adminScopeHelper;
|
||||
|
||||
@GetMapping("/calendar")
|
||||
@RequirePermission("schedule:view")
|
||||
public Result<PlanningCalendarVO> calendar(HttpServletRequest request,
|
||||
@RequestParam(required = false) String startDate,
|
||||
@RequestParam(required = false) String endDate,
|
||||
@RequestParam(required = false) Long artistId) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
LocalDate start = startDate == null || startDate.isBlank() ? LocalDate.now() : LocalDate.parse(startDate);
|
||||
LocalDate end = endDate == null || endDate.isBlank() ? start : LocalDate.parse(endDate);
|
||||
return Result.success(planningService.getCalendar(currentUser, start, end, artistId));
|
||||
}
|
||||
|
||||
@PostMapping("/appointments")
|
||||
@RequirePermission("order:process")
|
||||
@OperationGuard(action = "admin-planning-create-appointment", ttlSeconds = 10, message = "预约创建处理中,请勿重复提交")
|
||||
public Result<PlanningAppointmentVO> createAppointment(HttpServletRequest request,
|
||||
@RequestBody PlanningAppointmentCreateDTO dto) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
return Result.success(planningService.createAppointment(currentUser, dto));
|
||||
}
|
||||
|
||||
@GetMapping("/appointments/{orderItemId}")
|
||||
@RequirePermission("order:view")
|
||||
public Result<PlanningAppointmentVO> appointment(HttpServletRequest request,
|
||||
@PathVariable Long orderItemId) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
return Result.success(planningService.getAppointment(currentUser, orderItemId));
|
||||
}
|
||||
|
||||
@PutMapping("/appointments/{orderItemId}/time-artist")
|
||||
@RequirePermission("order:process")
|
||||
@OperationGuard(action = "admin-planning-move-appointment", ttlSeconds = 10, message = "预约调整处理中,请勿重复提交")
|
||||
public Result<PlanningAppointmentVO> moveAppointment(HttpServletRequest request,
|
||||
@PathVariable Long orderItemId,
|
||||
@RequestBody PlanningAppointmentMoveDTO dto) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
return Result.success(planningService.moveAppointment(currentUser, orderItemId, dto));
|
||||
}
|
||||
|
||||
@PutMapping("/appointments/{orderId}/status")
|
||||
@RequirePermission("order:process")
|
||||
@OperationGuard(action = "admin-planning-update-appointment-status", ttlSeconds = 10, message = "预约状态处理中,请勿重复提交")
|
||||
public Result<Boolean> updateStatus(HttpServletRequest request,
|
||||
@PathVariable Long orderId,
|
||||
@RequestBody PlanningAppointmentStatusDTO dto) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
return Result.success(planningService.updateStatus(currentUser, orderId, dto));
|
||||
}
|
||||
}
|
||||
+5
-2
@@ -18,6 +18,7 @@ import com.xiaowang.yuminailcore.mapper.ShopMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.UserMapper;
|
||||
import com.xiaowang.yuminailcore.service.OperationsAnalyticsService;
|
||||
import com.xiaowang.yuminailcore.support.AdminScopeHelper;
|
||||
import com.xiaowang.yuminailcore.support.OrderStatus;
|
||||
import com.xiaowang.yuminailcore.support.UserShopBindingSupport;
|
||||
import com.xiaowang.yuminailcore.support.cache.MultiLevelCacheService;
|
||||
import com.xiaowang.yuminailcore.vo.DashboardStatsVO;
|
||||
@@ -183,8 +184,10 @@ public class DashboardController {
|
||||
stats.setNewCustomersToday(countUsers(shopIdScope, 0, todayStart, null));
|
||||
stats.setNewCustomers7Days(countUsers(shopIdScope, 0, weekStart, null));
|
||||
stats.setNewOrders7Days(countOrders(shopIdScope, artistScope, null, weekStart, null));
|
||||
stats.setPendingOrders(countOrders(shopIdScope, artistScope, 1, null, null));
|
||||
stats.setCompletedOrders(countOrders(shopIdScope, artistScope, 3, null, null));
|
||||
long priceConfirmingOrders = countOrders(shopIdScope, artistScope, OrderStatus.PRICE_CONFIRMING.getCode(), null, null);
|
||||
long pendingServiceOrders = countOrders(shopIdScope, artistScope, OrderStatus.PENDING_SERVICE.getCode(), null, null);
|
||||
stats.setPendingOrders(priceConfirmingOrders + pendingServiceOrders);
|
||||
stats.setCompletedOrders(countOrders(shopIdScope, artistScope, OrderStatus.COMPLETED.getCode(), null, null));
|
||||
|
||||
stats.setHotProducts(getHotProducts(shopIdScope));
|
||||
stats.setRecentActivities(getRecentActivities(shopIdScope));
|
||||
|
||||
+56
-1
@@ -8,6 +8,8 @@ import com.xiaowang.yuminailcore.dto.OrderDTO;
|
||||
import com.xiaowang.yuminailcore.dto.OrderArtistChangeRejectDTO;
|
||||
import com.xiaowang.yuminailcore.dto.OrderArtistChangeRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.OrderArtistReviewSubmitDTO;
|
||||
import com.xiaowang.yuminailcore.dto.OrderQuoteReplyDTO;
|
||||
import com.xiaowang.yuminailcore.dto.OrderQuoteSubmitDTO;
|
||||
import com.xiaowang.yuminailcore.service.OrderService;
|
||||
import com.xiaowang.yuminailcore.service.UserService;
|
||||
import com.xiaowang.yuminailcore.support.SecurityAuditActions;
|
||||
@@ -24,6 +26,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@@ -119,6 +122,42 @@ public class OrderController {
|
||||
}
|
||||
|
||||
// 后台管理接口
|
||||
@PostMapping("/{orderId}/quote/reply")
|
||||
@OperationGuard(action = "order-quote-reply", ttlSeconds = 10, message = "回复处理中,请勿重复提交")
|
||||
public Result<OrderVO> replyQuote(@PathVariable Long orderId,
|
||||
@RequestBody(required = false) OrderQuoteReplyDTO dto,
|
||||
HttpServletRequest request) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
return Result.success(orderService.replyQuote(orderId, userId, dto));
|
||||
}
|
||||
|
||||
@PutMapping("/{orderId}/quote/confirm")
|
||||
@OperationGuard(action = "order-quote-user-confirm", ttlSeconds = 10, message = "确认处理中,请勿重复提交")
|
||||
public Result<OrderVO> confirmUserQuote(@PathVariable Long orderId, HttpServletRequest request) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
return Result.success(orderService.confirmUserQuote(orderId, userId));
|
||||
}
|
||||
|
||||
@RequirePermission("order:process")
|
||||
@PostMapping("/{orderId}/quote/shop")
|
||||
@OperationGuard(action = "order-shop-quote-submit", ttlSeconds = 10, message = "报价处理中,请勿重复提交")
|
||||
public Result<OrderVO> submitShopQuote(@PathVariable Long orderId,
|
||||
@RequestBody OrderQuoteSubmitDTO dto,
|
||||
HttpServletRequest request) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
Integer userType = (Integer) request.getAttribute("userType");
|
||||
return Result.success(orderService.submitShopQuote(orderId, userId, userType, dto));
|
||||
}
|
||||
|
||||
@RequirePermission("order:process")
|
||||
@PutMapping("/{orderId}/quote/shop/confirm")
|
||||
@OperationGuard(action = "order-shop-quote-confirm", ttlSeconds = 10, message = "确认处理中,请勿重复提交")
|
||||
public Result<OrderVO> confirmShopQuote(@PathVariable Long orderId, HttpServletRequest request) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
Integer userType = (Integer) request.getAttribute("userType");
|
||||
return Result.success(orderService.confirmShopQuote(orderId, userId, userType));
|
||||
}
|
||||
|
||||
@RequirePermission("order:view")
|
||||
@GetMapping("/admin/list")
|
||||
/**
|
||||
@@ -238,7 +277,23 @@ public class OrderController {
|
||||
*/
|
||||
throw new RuntimeException("仅美甲师可查看自己的订单");
|
||||
}
|
||||
List<OrderVO> orderList = orderService.getArtistWorkbenchOrders(userId);
|
||||
List<OrderVO> orderList;
|
||||
if (Integer.valueOf(2).equals(userType)) {
|
||||
UserVO currentUser = userService.getUserById(userId);
|
||||
if (currentUser == null || currentUser.getShopId() == null) {
|
||||
throw new RuntimeException("当前账号未绑定店铺");
|
||||
}
|
||||
orderList = orderService.getAllOrders().stream()
|
||||
.filter(order -> currentUser.getShopId().equals(order.getShopId()))
|
||||
.peek(order -> {
|
||||
order.setArtistOrderSource("SHOP");
|
||||
order.setArtistOrderSourceText("本店美甲师订单");
|
||||
})
|
||||
.sorted(Comparator.comparing(OrderVO::getCreateTime, Comparator.nullsLast(Comparator.reverseOrder())))
|
||||
.toList();
|
||||
} else {
|
||||
orderList = orderService.getArtistWorkbenchOrders(userId);
|
||||
}
|
||||
return Result.success(orderList);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ public class CheckoutPreviewDTO {
|
||||
* 优惠来源:USER_COUPON、SYSTEM_VIP、NONE。
|
||||
*/
|
||||
private String couponSourceType;
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 本次预览的商品列表。
|
||||
|
||||
@@ -22,6 +22,7 @@ public class OrderDTO {
|
||||
* Field `couponSourceType` (String): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled.
|
||||
*/
|
||||
private String couponSourceType;
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 订单商品列表
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class OrderQuoteItemDTO {
|
||||
private Long orderItemId;
|
||||
private BigDecimal quotedPrice;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class OrderQuoteReplyDTO {
|
||||
private String remark;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class OrderQuoteSubmitDTO {
|
||||
private String remark;
|
||||
private List<OrderQuoteItemDTO> items;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PlanningAppointmentCreateDTO {
|
||||
private Long customerUserId;
|
||||
private String customerName;
|
||||
private String phone;
|
||||
private Long productId;
|
||||
private Integer quantity;
|
||||
private Long artistId;
|
||||
private String appointmentDate;
|
||||
private String appointmentTime;
|
||||
private String appointmentStartTime;
|
||||
private Integer durationMinutes;
|
||||
private String remark;
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PlanningAppointmentMoveDTO {
|
||||
private Long artistId;
|
||||
private String appointmentDate;
|
||||
private String appointmentTime;
|
||||
private String appointmentStartTime;
|
||||
private Integer durationMinutes;
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PlanningAppointmentStatusDTO {
|
||||
private Integer status;
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class PlanningManagerRegisterDTO {
|
||||
|
||||
private String phone;
|
||||
|
||||
private String code;
|
||||
|
||||
private String password;
|
||||
|
||||
private String confirmPassword;
|
||||
|
||||
private String shopName;
|
||||
}
|
||||
@@ -52,6 +52,12 @@ public class OrderDO extends BaseEntity {
|
||||
private String paymentMethod;
|
||||
private String paymentOrderNo;
|
||||
private String refundStatus;
|
||||
private String customerRemark;
|
||||
private String quoteStatus;
|
||||
private Integer quoteUserConfirmed;
|
||||
private Integer quoteShopConfirmed;
|
||||
private LocalDateTime quoteExpireTime;
|
||||
private LocalDateTime quoteConfirmedTime;
|
||||
/**
|
||||
* Field `status` (Integer): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled.
|
||||
*/
|
||||
|
||||
@@ -30,6 +30,9 @@ public class OrderItemDO extends BaseEntity {
|
||||
* Field `price` (BigDecimal): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled.
|
||||
*/
|
||||
private BigDecimal price;
|
||||
private BigDecimal referencePrice;
|
||||
private BigDecimal quotedPrice;
|
||||
private BigDecimal confirmedPrice;
|
||||
/**
|
||||
* Field `artistId` (Long): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.xiaowang.yuminailcore.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("t_order_quote_message")
|
||||
public class OrderQuoteMessageDO extends BaseEntity {
|
||||
|
||||
@TableField("order_id")
|
||||
private Long orderId;
|
||||
|
||||
@TableField("actor_id")
|
||||
private Long actorId;
|
||||
|
||||
@TableField("actor_type")
|
||||
private String actorType;
|
||||
|
||||
@TableField("action")
|
||||
private String action;
|
||||
|
||||
@TableField("remark")
|
||||
private String remark;
|
||||
|
||||
@TableField("items_snapshot")
|
||||
private String itemsSnapshot;
|
||||
|
||||
@TableField("is_delete")
|
||||
private Integer isDelete;
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public interface OrderItemMapper extends BaseMapper<OrderItemDO> {
|
||||
"WHERE oi.artist_id = #{artistId} " +
|
||||
"AND oi.is_delete = 0 " +
|
||||
"AND o.is_delete = 0 " +
|
||||
"AND o.status <> 3 " +
|
||||
"AND o.status = 1 " +
|
||||
"AND oi.appointment_time IS NOT NULL")
|
||||
List<OrderItemDO> selectActiveAppointmentItemsByArtistId(@Param("artistId") Long artistId);
|
||||
|
||||
@@ -35,7 +35,7 @@ public interface OrderItemMapper extends BaseMapper<OrderItemDO> {
|
||||
"WHERE oi.artist_id = #{artistId} " +
|
||||
"AND oi.is_delete = 0 " +
|
||||
"AND o.is_delete = 0 " +
|
||||
"AND o.status <> 3 " +
|
||||
"AND o.status = 1 " +
|
||||
"AND oi.appointment_time >= #{startTime} " +
|
||||
"AND oi.appointment_time < #{endTime} " +
|
||||
"ORDER BY oi.appointment_time ASC, oi.id ASC")
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.xiaowang.yuminailcore.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xiaowang.yuminailcore.entity.OrderQuoteMessageDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface OrderQuoteMessageMapper extends BaseMapper<OrderQuoteMessageDO> {
|
||||
|
||||
@Select("SELECT * FROM t_order_quote_message WHERE order_id = #{orderId} AND is_delete = 0 ORDER BY create_time ASC, id ASC")
|
||||
List<OrderQuoteMessageDO> selectByOrderId(@Param("orderId") Long orderId);
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import com.xiaowang.yuminailcore.dto.CheckoutPreviewDTO;
|
||||
import com.xiaowang.yuminailcore.dto.OrderArtistChangeRejectDTO;
|
||||
import com.xiaowang.yuminailcore.dto.OrderArtistChangeRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.OrderArtistReviewSubmitDTO;
|
||||
import com.xiaowang.yuminailcore.dto.OrderQuoteReplyDTO;
|
||||
import com.xiaowang.yuminailcore.dto.OrderQuoteSubmitDTO;
|
||||
import com.xiaowang.yuminailcore.vo.ArtistCalendarAppointmentVO;
|
||||
import com.xiaowang.yuminailcore.vo.CheckoutPreviewVO;
|
||||
import com.xiaowang.yuminailcore.vo.OrderArtistChangeOptionsVO;
|
||||
@@ -125,4 +127,14 @@ public interface OrderService {
|
||||
OrderArtistChangeRequestVO approveArtistChange(Long requestId, Long userId, Integer userType);
|
||||
|
||||
OrderArtistChangeRequestVO rejectArtistChange(Long requestId, Long userId, Integer userType, OrderArtistChangeRejectDTO dto);
|
||||
|
||||
OrderVO submitShopQuote(Long orderId, Long operatorId, Integer operatorType, OrderQuoteSubmitDTO dto);
|
||||
|
||||
OrderVO confirmShopQuote(Long orderId, Long operatorId, Integer operatorType);
|
||||
|
||||
OrderVO replyQuote(Long orderId, Long userId, OrderQuoteReplyDTO dto);
|
||||
|
||||
OrderVO confirmUserQuote(Long orderId, Long userId);
|
||||
|
||||
int expirePendingQuoteOrders();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.xiaowang.yuminailcore.service;
|
||||
|
||||
import com.xiaowang.yuminailcore.dto.PlanningAppointmentCreateDTO;
|
||||
import com.xiaowang.yuminailcore.dto.PlanningAppointmentMoveDTO;
|
||||
import com.xiaowang.yuminailcore.dto.PlanningAppointmentStatusDTO;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.vo.PlanningAppointmentVO;
|
||||
import com.xiaowang.yuminailcore.vo.PlanningCalendarVO;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
public interface PlanningService {
|
||||
PlanningCalendarVO getCalendar(UserDO currentUser, LocalDate startDate, LocalDate endDate, Long artistId);
|
||||
|
||||
PlanningAppointmentVO createAppointment(UserDO currentUser, PlanningAppointmentCreateDTO dto);
|
||||
|
||||
PlanningAppointmentVO getAppointment(UserDO currentUser, Long orderItemId);
|
||||
|
||||
PlanningAppointmentVO moveAppointment(UserDO currentUser, Long orderItemId, PlanningAppointmentMoveDTO dto);
|
||||
|
||||
Boolean updateStatus(UserDO currentUser, Long orderId, PlanningAppointmentStatusDTO dto);
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.xiaowang.yuminailcore.dto.BindEmailRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.BindPhoneRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.LoginRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.PhoneLoginRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.PlanningManagerRegisterDTO;
|
||||
import com.xiaowang.yuminailcore.dto.RegisterRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.ResetPasswordRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.UpdatePhoneRequestDTO;
|
||||
@@ -189,6 +190,8 @@ public interface UserService extends IService<UserDO> {
|
||||
*/
|
||||
boolean register(RegisterRequestDTO registerRequestDTO);
|
||||
|
||||
LoginResponseVO registerPlanningManager(PlanningManagerRegisterDTO registerDTO);
|
||||
|
||||
/**
|
||||
* Run business method `refreshToken`.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
|
||||
+3
@@ -49,6 +49,9 @@ public class AfterSaleServiceImpl implements AfterSaleService {
|
||||
if (!order.getUserId().equals(userId)) {
|
||||
throw new RuntimeException("无权申请该订单售后");
|
||||
}
|
||||
if (Integer.valueOf(0).equals(order.getStatus())) {
|
||||
throw new RuntimeException("询价预约确认价格前暂不能申请售后");
|
||||
}
|
||||
AfterSaleDO afterSale = new AfterSaleDO();
|
||||
afterSale.setAfterSaleNo("AS" + System.currentTimeMillis() + dto.getOrderId());
|
||||
afterSale.setOrderId(order.getId());
|
||||
|
||||
+941
-84
File diff suppressed because it is too large
Load Diff
+3
@@ -131,6 +131,9 @@ public class PaymentServiceImpl implements PaymentService {
|
||||
if (userId != null && !userId.equals(order.getUserId())) {
|
||||
throw new RuntimeException("无权支付该订单");
|
||||
}
|
||||
if (Integer.valueOf(0).equals(order.getStatus())) {
|
||||
throw new RuntimeException("询价预约确认价格前暂不能支付");
|
||||
}
|
||||
if (STATUS_PAID.equals(order.getPaymentStatus())) {
|
||||
throw new RuntimeException("订单已支付");
|
||||
}
|
||||
|
||||
+760
@@ -0,0 +1,760 @@
|
||||
package com.xiaowang.yuminailcore.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.xiaowang.yuminailcore.dto.PlanningAppointmentCreateDTO;
|
||||
import com.xiaowang.yuminailcore.dto.PlanningAppointmentMoveDTO;
|
||||
import com.xiaowang.yuminailcore.dto.PlanningAppointmentStatusDTO;
|
||||
import com.xiaowang.yuminailcore.entity.AppointmentReservationDO;
|
||||
import com.xiaowang.yuminailcore.entity.ArtistScheduleDO;
|
||||
import com.xiaowang.yuminailcore.entity.NailArtistInfoDO;
|
||||
import com.xiaowang.yuminailcore.entity.OrderDO;
|
||||
import com.xiaowang.yuminailcore.entity.OrderItemDO;
|
||||
import com.xiaowang.yuminailcore.entity.ProductDO;
|
||||
import com.xiaowang.yuminailcore.entity.ShopDO;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.mapper.AppointmentReservationMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.ArtistScheduleMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.NailArtistInfoMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.OrderItemMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.OrderMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.ProductMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.ShopMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.UserMapper;
|
||||
import com.xiaowang.yuminailcore.service.AppointmentCapacityService;
|
||||
import com.xiaowang.yuminailcore.service.OrderService;
|
||||
import com.xiaowang.yuminailcore.service.PlanningService;
|
||||
import com.xiaowang.yuminailcore.support.AdminScopeHelper;
|
||||
import com.xiaowang.yuminailcore.support.OrderStatus;
|
||||
import com.xiaowang.yuminailcore.support.PlanningCalendarSupport;
|
||||
import com.xiaowang.yuminailcore.support.id.TimeOrderedSnowflakeIdGenerator;
|
||||
import com.xiaowang.yuminailcore.vo.PlanningAppointmentVO;
|
||||
import com.xiaowang.yuminailcore.vo.PlanningArtistCountVO;
|
||||
import com.xiaowang.yuminailcore.vo.PlanningArtistVO;
|
||||
import com.xiaowang.yuminailcore.vo.PlanningCalendarVO;
|
||||
import com.xiaowang.yuminailcore.vo.PlanningDaySummaryVO;
|
||||
import com.xiaowang.yuminailcore.vo.PlanningScheduleVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PlanningServiceImpl implements PlanningService {
|
||||
|
||||
private static final int DEFAULT_SLOT_MINUTES = 30;
|
||||
private static final int DEFAULT_DURATION_MINUTES = 60;
|
||||
private static final String RESERVATION_CONFIRMED = "CONFIRMED";
|
||||
private static final List<String> ACTIVE_RESERVATION_STATUS = List.of("LOCKED", RESERVATION_CONFIRMED);
|
||||
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
private static final List<String> ARTIST_COLORS = List.of(
|
||||
"#7BA7C7", "#8FB89A", "#A894C7", "#D7A86E", "#D98DA5", "#79A6A3", "#B9A16B", "#9BA9C8"
|
||||
);
|
||||
|
||||
private final AdminScopeHelper adminScopeHelper;
|
||||
private final UserMapper userMapper;
|
||||
private final NailArtistInfoMapper nailArtistInfoMapper;
|
||||
private final ArtistScheduleMapper artistScheduleMapper;
|
||||
private final AppointmentReservationMapper appointmentReservationMapper;
|
||||
private final OrderMapper orderMapper;
|
||||
private final OrderItemMapper orderItemMapper;
|
||||
private final ProductMapper productMapper;
|
||||
private final ShopMapper shopMapper;
|
||||
private final AppointmentCapacityService appointmentCapacityService;
|
||||
private final OrderService orderService;
|
||||
private final TimeOrderedSnowflakeIdGenerator snowflakeIdGenerator;
|
||||
|
||||
@Override
|
||||
public PlanningCalendarVO getCalendar(UserDO currentUser, LocalDate startDate, LocalDate endDate, Long artistId) {
|
||||
LocalDate start = startDate == null ? LocalDate.now() : startDate;
|
||||
LocalDate end = endDate == null ? start : endDate;
|
||||
if (end.isBefore(start)) {
|
||||
end = start;
|
||||
}
|
||||
if (start.plusDays(61).isBefore(end)) {
|
||||
end = start.plusDays(61);
|
||||
}
|
||||
|
||||
Long shopId = requirePlanningShopId(currentUser);
|
||||
ShopDO shop = shopMapper.selectById(shopId);
|
||||
PlanningCalendarSupport.BusinessHours businessHours = PlanningCalendarSupport.parseBusinessHours(
|
||||
shop == null ? null : shop.getBusinessHours()
|
||||
);
|
||||
|
||||
List<PlanningArtistVO> artists = listArtists(shopId, artistId);
|
||||
List<ArtistScheduleDO> schedules = listSchedules(shopId, start, end, artistId);
|
||||
List<PlanningScheduleVO> scheduleVos = schedules.stream()
|
||||
.map(schedule -> toScheduleVO(schedule, artists))
|
||||
.sorted(Comparator.comparing(PlanningScheduleVO::getDate)
|
||||
.thenComparing(PlanningScheduleVO::getStartTime)
|
||||
.thenComparing(PlanningScheduleVO::getArtistName, Comparator.nullsLast(String::compareTo)))
|
||||
.toList();
|
||||
|
||||
LocalDateTime rangeStart = start.atStartOfDay();
|
||||
LocalDateTime rangeEnd = end.plusDays(1).atStartOfDay();
|
||||
List<PlanningAppointmentVO> appointments = listAppointments(shopId, rangeStart, rangeEnd, artistId, artists);
|
||||
Map<Long, Long> countByArtist = appointments.stream()
|
||||
.filter(appointment -> appointment.getArtistId() != null)
|
||||
.collect(Collectors.groupingBy(PlanningAppointmentVO::getArtistId, Collectors.counting()));
|
||||
artists.forEach(artist -> artist.setRangeCount(countByArtist.getOrDefault(artist.getId(), 0L).intValue()));
|
||||
|
||||
PlanningCalendarVO vo = new PlanningCalendarVO();
|
||||
vo.setBusinessStartTime(businessHours.start().toString());
|
||||
vo.setBusinessEndTime(businessHours.end().toString());
|
||||
vo.setSlotMinutes(DEFAULT_SLOT_MINUTES);
|
||||
vo.setArtists(artists);
|
||||
vo.setSchedules(scheduleVos);
|
||||
vo.setAppointments(appointments);
|
||||
vo.setDaySummaries(buildDaySummaries(start, end, artists, schedules, appointments));
|
||||
return vo;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public PlanningAppointmentVO createAppointment(UserDO currentUser, PlanningAppointmentCreateDTO dto) {
|
||||
if (dto == null) {
|
||||
throw new RuntimeException("预约信息不能为空");
|
||||
}
|
||||
Long shopId = requirePlanningShopId(currentUser);
|
||||
ProductDO product = requireActiveProduct(dto.getProductId(), shopId);
|
||||
UserDO artist = requireActiveArtist(dto.getArtistId(), shopId);
|
||||
UserDO customer = resolveCustomer(shopId, dto);
|
||||
|
||||
int quantity = dto.getQuantity() == null || dto.getQuantity() <= 0 ? 1 : dto.getQuantity();
|
||||
int durationMinutes = resolveDurationMinutes(product, dto.getDurationMinutes()) * quantity;
|
||||
LocalDateTime startTime = parseAppointmentStart(dto.getAppointmentStartTime(), dto.getAppointmentDate(), dto.getAppointmentTime());
|
||||
LocalDateTime endTime = startTime.plusMinutes(durationMinutes);
|
||||
ensureWithinBusinessHours(shopId, startTime, endTime);
|
||||
|
||||
BigDecimal unitPrice = product.getPrice() == null ? BigDecimal.ZERO : product.getPrice();
|
||||
BigDecimal amount = unitPrice.multiply(BigDecimal.valueOf(quantity));
|
||||
|
||||
OrderDO order = new OrderDO();
|
||||
order.setOrderNo("ORD" + snowflakeIdGenerator.nextIdString());
|
||||
order.setUserId(customer.getId());
|
||||
order.setShopId(shopId);
|
||||
order.setTotalAmount(amount);
|
||||
order.setActualAmount(amount);
|
||||
order.setCustomerRemark(trimToNull(dto.getRemark()));
|
||||
order.setQuoteStatus("CONFIRMED");
|
||||
order.setQuoteUserConfirmed(1);
|
||||
order.setQuoteShopConfirmed(1);
|
||||
order.setQuoteConfirmedTime(LocalDateTime.now());
|
||||
order.setPaymentStatus("UNPAID");
|
||||
order.setPayAmount(amount);
|
||||
order.setPaidAmount(BigDecimal.ZERO);
|
||||
order.setStatus(OrderStatus.PENDING_SERVICE.getCode());
|
||||
order.setIsDelete(0);
|
||||
orderMapper.insert(order);
|
||||
|
||||
OrderItemDO item = new OrderItemDO();
|
||||
item.setOrderId(order.getId());
|
||||
item.setProductId(product.getId());
|
||||
item.setQuantity(quantity);
|
||||
item.setPrice(unitPrice);
|
||||
item.setArtistId(artist.getId());
|
||||
item.setAppointmentTime(startTime);
|
||||
item.setIsDelete(0);
|
||||
orderItemMapper.insert(item);
|
||||
|
||||
appointmentCapacityService.reserveOrThrow(
|
||||
order.getId(),
|
||||
item.getId(),
|
||||
shopId,
|
||||
artist.getId(),
|
||||
product.getTitle(),
|
||||
startTime,
|
||||
endTime
|
||||
);
|
||||
|
||||
return getAppointment(currentUser, item.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlanningAppointmentVO getAppointment(UserDO currentUser, Long orderItemId) {
|
||||
if (orderItemId == null) {
|
||||
throw new RuntimeException("预约ID不能为空");
|
||||
}
|
||||
OrderItemDO item = orderItemMapper.selectById(orderItemId);
|
||||
if (item == null || Integer.valueOf(1).equals(item.getIsDelete())) {
|
||||
throw new RuntimeException("预约不存在");
|
||||
}
|
||||
OrderDO order = requireAccessibleOrder(currentUser, item.getOrderId());
|
||||
ProductDO product = item.getProductId() == null ? null : productMapper.selectById(item.getProductId());
|
||||
AppointmentReservationDO reservation = findActiveReservation(orderItemId);
|
||||
Map<Long, PlanningArtistVO> artistMap = listArtists(order.getShopId(), item.getArtistId()).stream()
|
||||
.collect(Collectors.toMap(PlanningArtistVO::getId, Function.identity(), (a, b) -> a));
|
||||
Map<Long, UserDO> customerMap = loadUsers(Set.of(order.getUserId()));
|
||||
return toAppointmentVO(reservation, item, order, product, customerMap.get(order.getUserId()), artistMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public PlanningAppointmentVO moveAppointment(UserDO currentUser, Long orderItemId, PlanningAppointmentMoveDTO dto) {
|
||||
if (orderItemId == null || dto == null) {
|
||||
throw new RuntimeException("改派信息不能为空");
|
||||
}
|
||||
OrderItemDO item = orderItemMapper.selectByIdForUpdate(orderItemId);
|
||||
if (item == null || Integer.valueOf(1).equals(item.getIsDelete())) {
|
||||
throw new RuntimeException("预约不存在");
|
||||
}
|
||||
OrderDO order = requireAccessibleOrder(currentUser, item.getOrderId());
|
||||
ProductDO product = requireActiveProduct(item.getProductId(), order.getShopId());
|
||||
Long targetArtistId = dto.getArtistId() == null ? item.getArtistId() : dto.getArtistId();
|
||||
UserDO artist = requireActiveArtist(targetArtistId, order.getShopId());
|
||||
int durationMinutes = resolveDurationMinutes(product, dto.getDurationMinutes()) *
|
||||
Math.max(1, item.getQuantity() == null ? 1 : item.getQuantity());
|
||||
LocalDateTime startTime = hasText(dto.getAppointmentStartTime()) || hasText(dto.getAppointmentDate()) || hasText(dto.getAppointmentTime())
|
||||
? parseAppointmentStart(dto.getAppointmentStartTime(), dto.getAppointmentDate(), dto.getAppointmentTime())
|
||||
: item.getAppointmentTime();
|
||||
if (startTime == null) {
|
||||
throw new RuntimeException("预约时间不能为空");
|
||||
}
|
||||
LocalDateTime endTime = startTime.plusMinutes(durationMinutes);
|
||||
ensureWithinBusinessHours(order.getShopId(), startTime, endTime);
|
||||
|
||||
appointmentCapacityService.moveReservationForArtistChange(
|
||||
order.getId(),
|
||||
item.getId(),
|
||||
order.getShopId(),
|
||||
item.getArtistId(),
|
||||
artist.getId(),
|
||||
product.getTitle(),
|
||||
startTime,
|
||||
endTime
|
||||
);
|
||||
|
||||
item.setArtistId(artist.getId());
|
||||
item.setAppointmentTime(startTime);
|
||||
orderItemMapper.updateById(item);
|
||||
return getAppointment(currentUser, item.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Boolean updateStatus(UserDO currentUser, Long orderId, PlanningAppointmentStatusDTO dto) {
|
||||
if (orderId == null || dto == null || dto.getStatus() == null) {
|
||||
throw new RuntimeException("预约状态不能为空");
|
||||
}
|
||||
OrderDO order = requireAccessibleOrder(currentUser, orderId);
|
||||
int targetStatus = dto.getStatus();
|
||||
if (targetStatus == OrderStatus.PENDING_SERVICE.getCode()) {
|
||||
if (!Integer.valueOf(OrderStatus.PENDING_SERVICE.getCode()).equals(order.getStatus())) {
|
||||
orderMapper.updateStatusIfCurrent(order.getId(), order.getStatus(), OrderStatus.PENDING_SERVICE.getCode());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
orderService.processOrder(orderId, targetStatus);
|
||||
return true;
|
||||
}
|
||||
|
||||
private Long requirePlanningShopId(UserDO currentUser) {
|
||||
Long shopId = adminScopeHelper.resolveShopScope(currentUser, null);
|
||||
if (shopId == null || shopId <= 0) {
|
||||
throw new RuntimeException("请先选择店铺后再查看规划");
|
||||
}
|
||||
return shopId;
|
||||
}
|
||||
|
||||
private List<PlanningArtistVO> listArtists(Long shopId, Long artistId) {
|
||||
QueryWrapper<UserDO> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("shop_id", shopId)
|
||||
.eq("type", 3)
|
||||
.eq("is_delete", 0)
|
||||
.orderByAsc("id");
|
||||
if (artistId != null && artistId > 0) {
|
||||
wrapper.eq("id", artistId);
|
||||
}
|
||||
List<UserDO> artists = userMapper.selectList(wrapper);
|
||||
if (artists == null || artists.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
Set<Long> artistIds = artists.stream().map(UserDO::getId).collect(Collectors.toCollection(HashSet::new));
|
||||
Map<Long, NailArtistInfoDO> infoMap = loadArtistInfo(artistIds);
|
||||
List<PlanningArtistVO> result = new ArrayList<>();
|
||||
for (int i = 0; i < artists.size(); i++) {
|
||||
UserDO user = artists.get(i);
|
||||
NailArtistInfoDO info = infoMap.get(user.getId());
|
||||
PlanningArtistVO vo = new PlanningArtistVO();
|
||||
vo.setId(user.getId());
|
||||
vo.setName(firstNonBlank(user.getNickname(), user.getAccount(), "美甲师" + (i + 1)));
|
||||
vo.setShortName(PlanningCalendarSupport.shortName(vo.getName()));
|
||||
vo.setPhone(firstNonBlank(user.getContactPhone(), user.getPhone(), ""));
|
||||
vo.setAvatar(user.getAvatar());
|
||||
vo.setColor(colorForArtist(user.getId(), i));
|
||||
vo.setStatus(info == null || info.getStatus() == null ? user.getStatus() : info.getStatus());
|
||||
vo.setStatusText(Integer.valueOf(0).equals(vo.getStatus()) ? "休息" : "可预约");
|
||||
vo.setWorkStartTime(info == null || info.getWorkStartTime() == null ? null : info.getWorkStartTime().toString());
|
||||
vo.setWorkEndTime(info == null || info.getWorkEndTime() == null ? null : info.getWorkEndTime().toString());
|
||||
vo.setRangeCount(0);
|
||||
result.add(vo);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Map<Long, NailArtistInfoDO> loadArtistInfo(Set<Long> artistIds) {
|
||||
if (artistIds == null || artistIds.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
QueryWrapper<NailArtistInfoDO> wrapper = new QueryWrapper<>();
|
||||
wrapper.in("user_id", artistIds).eq("is_delete", 0);
|
||||
return nailArtistInfoMapper.selectList(wrapper).stream()
|
||||
.collect(Collectors.toMap(NailArtistInfoDO::getUserId, Function.identity(), (a, b) -> a));
|
||||
}
|
||||
|
||||
private List<ArtistScheduleDO> listSchedules(Long shopId, LocalDate start, LocalDate end, Long artistId) {
|
||||
QueryWrapper<ArtistScheduleDO> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("shop_id", shopId)
|
||||
.between("work_date", start, end)
|
||||
.eq("is_delete", 0)
|
||||
.orderByAsc("work_date")
|
||||
.orderByAsc("start_time");
|
||||
if (artistId != null && artistId > 0) {
|
||||
wrapper.eq("artist_id", artistId);
|
||||
}
|
||||
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));
|
||||
PlanningScheduleVO vo = new PlanningScheduleVO();
|
||||
vo.setId(schedule.getId());
|
||||
vo.setArtistId(schedule.getArtistId());
|
||||
vo.setArtistName(artistNames.get(schedule.getArtistId()));
|
||||
vo.setDate(schedule.getWorkDate() == null ? null : schedule.getWorkDate().toString());
|
||||
vo.setStartTime(schedule.getStartTime() == null ? null : schedule.getStartTime().toString());
|
||||
vo.setEndTime(schedule.getEndTime() == null ? null : schedule.getEndTime().toString());
|
||||
vo.setCapacity(schedule.getCapacity());
|
||||
vo.setStatus(schedule.getStatus());
|
||||
vo.setStatusText(Integer.valueOf(1).equals(schedule.getStatus()) ? "可预约" : "请假");
|
||||
vo.setRemark(schedule.getRemark());
|
||||
return vo;
|
||||
}
|
||||
|
||||
private List<PlanningAppointmentVO> listAppointments(Long shopId, LocalDateTime rangeStart, LocalDateTime rangeEnd,
|
||||
Long artistId, List<PlanningArtistVO> artists) {
|
||||
QueryWrapper<AppointmentReservationDO> reservationWrapper = new QueryWrapper<>();
|
||||
reservationWrapper.eq("shop_id", shopId)
|
||||
.eq("is_delete", 0)
|
||||
.in("status", ACTIVE_RESERVATION_STATUS)
|
||||
.lt("appointment_start_time", rangeEnd)
|
||||
.gt("appointment_end_time", rangeStart)
|
||||
.orderByAsc("appointment_start_time");
|
||||
if (artistId != null && artistId > 0) {
|
||||
reservationWrapper.eq("artist_id", artistId);
|
||||
}
|
||||
List<AppointmentReservationDO> reservations = appointmentReservationMapper.selectList(reservationWrapper);
|
||||
|
||||
QueryWrapper<OrderItemDO> itemWrapper = new QueryWrapper<>();
|
||||
itemWrapper.eq("is_delete", 0)
|
||||
.isNotNull("appointment_time")
|
||||
.ge("appointment_time", rangeStart)
|
||||
.lt("appointment_time", rangeEnd)
|
||||
.orderByAsc("appointment_time");
|
||||
if (artistId != null && artistId > 0) {
|
||||
itemWrapper.eq("artist_id", artistId);
|
||||
}
|
||||
List<OrderItemDO> fallbackItems = orderItemMapper.selectList(itemWrapper);
|
||||
|
||||
return buildAppointmentList(shopId, reservations, fallbackItems, artists);
|
||||
}
|
||||
|
||||
private List<PlanningAppointmentVO> buildAppointmentList(Long shopId, List<AppointmentReservationDO> reservations,
|
||||
List<OrderItemDO> fallbackItems, List<PlanningArtistVO> artists) {
|
||||
Set<Long> itemIds = new HashSet<>();
|
||||
Set<Long> orderIds = new HashSet<>();
|
||||
for (AppointmentReservationDO reservation : safeList(reservations)) {
|
||||
if (reservation.getOrderItemId() != null) {
|
||||
itemIds.add(reservation.getOrderItemId());
|
||||
}
|
||||
if (reservation.getOrderId() != null) {
|
||||
orderIds.add(reservation.getOrderId());
|
||||
}
|
||||
}
|
||||
for (OrderItemDO item : safeList(fallbackItems)) {
|
||||
if (item.getId() != null) {
|
||||
itemIds.add(item.getId());
|
||||
}
|
||||
if (item.getOrderId() != null) {
|
||||
orderIds.add(item.getOrderId());
|
||||
}
|
||||
}
|
||||
|
||||
Map<Long, OrderItemDO> itemMap = loadOrderItems(itemIds);
|
||||
Map<Long, OrderDO> orderMap = loadOrders(orderIds);
|
||||
Set<Long> productIds = itemMap.values().stream()
|
||||
.map(OrderItemDO::getProductId)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
Set<Long> customerIds = orderMap.values().stream()
|
||||
.map(OrderDO::getUserId)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
Map<Long, ProductDO> productMap = loadProducts(productIds);
|
||||
Map<Long, UserDO> customerMap = loadUsers(customerIds);
|
||||
Map<Long, PlanningArtistVO> artistMap = artists.stream()
|
||||
.collect(Collectors.toMap(PlanningArtistVO::getId, Function.identity(), (a, b) -> a));
|
||||
|
||||
List<PlanningAppointmentVO> result = new ArrayList<>();
|
||||
Set<Long> reservationItemIds = new HashSet<>();
|
||||
for (AppointmentReservationDO reservation : safeList(reservations)) {
|
||||
OrderItemDO item = itemMap.get(reservation.getOrderItemId());
|
||||
OrderDO order = orderMap.get(reservation.getOrderId());
|
||||
if (!isVisibleOrder(order, shopId)) {
|
||||
continue;
|
||||
}
|
||||
ProductDO product = item == null ? null : productMap.get(item.getProductId());
|
||||
UserDO customer = customerMap.get(order.getUserId());
|
||||
result.add(toAppointmentVO(reservation, item, order, product, customer, artistMap));
|
||||
if (reservation.getOrderItemId() != null) {
|
||||
reservationItemIds.add(reservation.getOrderItemId());
|
||||
}
|
||||
}
|
||||
for (OrderItemDO item : safeList(fallbackItems)) {
|
||||
if (item.getId() != null && reservationItemIds.contains(item.getId())) {
|
||||
continue;
|
||||
}
|
||||
OrderDO order = orderMap.get(item.getOrderId());
|
||||
if (!isVisibleOrder(order, shopId)) {
|
||||
continue;
|
||||
}
|
||||
ProductDO product = productMap.get(item.getProductId());
|
||||
UserDO customer = customerMap.get(order.getUserId());
|
||||
result.add(toAppointmentVO(null, item, order, product, customer, artistMap));
|
||||
}
|
||||
result.sort(Comparator.comparing(PlanningAppointmentVO::getStartTime, Comparator.nullsLast(String::compareTo))
|
||||
.thenComparing(PlanningAppointmentVO::getArtistName, Comparator.nullsLast(String::compareTo)));
|
||||
return result;
|
||||
}
|
||||
|
||||
private PlanningAppointmentVO toAppointmentVO(AppointmentReservationDO reservation, OrderItemDO item, OrderDO order,
|
||||
ProductDO product, UserDO customer, Map<Long, PlanningArtistVO> artistMap) {
|
||||
LocalDateTime start = reservation == null ? null : reservation.getAppointmentStartTime();
|
||||
if (start == null && item != null) {
|
||||
start = item.getAppointmentTime();
|
||||
}
|
||||
int durationMinutes = resolveDurationMinutes(product, null) * Math.max(1, item == null || item.getQuantity() == null ? 1 : item.getQuantity());
|
||||
LocalDateTime end = reservation == null ? null : reservation.getAppointmentEndTime();
|
||||
if (end == null && start != null) {
|
||||
end = start.plusMinutes(durationMinutes);
|
||||
}
|
||||
|
||||
Long artistId = reservation != null && reservation.getArtistId() != null
|
||||
? reservation.getArtistId()
|
||||
: item == null ? null : item.getArtistId();
|
||||
PlanningArtistVO artist = artistId == null ? null : artistMap.get(artistId);
|
||||
|
||||
PlanningAppointmentVO vo = new PlanningAppointmentVO();
|
||||
vo.setOrderId(order == null ? null : order.getId());
|
||||
vo.setOrderNo(order == null ? null : order.getOrderNo());
|
||||
vo.setOrderItemId(item == null ? reservation == null ? null : reservation.getOrderItemId() : item.getId());
|
||||
vo.setCustomerId(customer == null ? order == null ? null : order.getUserId() : customer.getId());
|
||||
vo.setCustomerName(customer == null ? "到店客户" : firstNonBlank(customer.getNickname(), customer.getAccount(), "到店客户"));
|
||||
vo.setCustomerPhone(customer == null ? null : firstNonBlank(customer.getContactPhone(), customer.getPhone(), ""));
|
||||
vo.setProductId(product == null ? item == null ? null : item.getProductId() : product.getId());
|
||||
vo.setProductTitle(reservation != null && hasText(reservation.getProductTitle())
|
||||
? reservation.getProductTitle()
|
||||
: product == null ? "预约项目" : product.getTitle());
|
||||
vo.setArtistId(artistId);
|
||||
vo.setArtistName(artist == null ? "未分配" : artist.getName());
|
||||
vo.setArtistColor(artist == null ? ARTIST_COLORS.get(0) : artist.getColor());
|
||||
vo.setDate(start == null ? null : start.toLocalDate().toString());
|
||||
vo.setStartTime(start == null ? null : DATE_TIME_FORMATTER.format(start));
|
||||
vo.setEndTime(end == null ? null : DATE_TIME_FORMATTER.format(end));
|
||||
vo.setStartMinute(start == null ? null : start.toLocalTime().toSecondOfDay() / 60);
|
||||
vo.setDurationMinutes(start == null || end == null ? durationMinutes : Math.toIntExact(Duration.between(start, end).toMinutes()));
|
||||
vo.setStatus(order == null ? null : order.getStatus());
|
||||
vo.setStatusText(statusText(order == null ? null : order.getStatus()));
|
||||
vo.setAmount(order == null ? null : order.getActualAmount());
|
||||
vo.setRemark(order == null ? null : order.getCustomerRemark());
|
||||
return vo;
|
||||
}
|
||||
|
||||
private List<PlanningDaySummaryVO> buildDaySummaries(LocalDate start, LocalDate end, List<PlanningArtistVO> artists,
|
||||
List<ArtistScheduleDO> schedules, List<PlanningAppointmentVO> appointments) {
|
||||
Map<String, List<PlanningAppointmentVO>> appointmentsByDate = appointments.stream()
|
||||
.filter(appointment -> appointment.getDate() != null)
|
||||
.collect(Collectors.groupingBy(PlanningAppointmentVO::getDate));
|
||||
Map<String, List<ArtistScheduleDO>> schedulesByDate = schedules.stream()
|
||||
.filter(schedule -> schedule.getWorkDate() != null)
|
||||
.collect(Collectors.groupingBy(schedule -> schedule.getWorkDate().toString()));
|
||||
|
||||
List<PlanningDaySummaryVO> summaries = new ArrayList<>();
|
||||
LocalDate cursor = start;
|
||||
while (!cursor.isAfter(end)) {
|
||||
String date = cursor.toString();
|
||||
List<PlanningAppointmentVO> dayAppointments = appointmentsByDate.getOrDefault(date, List.of());
|
||||
Map<Long, Long> countByArtist = dayAppointments.stream()
|
||||
.filter(appointment -> appointment.getArtistId() != null)
|
||||
.collect(Collectors.groupingBy(PlanningAppointmentVO::getArtistId, Collectors.counting()));
|
||||
List<ArtistScheduleDO> daySchedules = schedulesByDate.getOrDefault(date, List.of());
|
||||
Map<Long, ArtistScheduleDO> scheduleByArtist = daySchedules.stream()
|
||||
.collect(Collectors.toMap(ArtistScheduleDO::getArtistId, Function.identity(), (a, b) -> a));
|
||||
|
||||
List<PlanningArtistCountVO> artistCounts = new ArrayList<>();
|
||||
int workingArtistCount = 0;
|
||||
int busyWorkingArtistCount = 0;
|
||||
for (PlanningArtistVO artist : artists) {
|
||||
int count = countByArtist.getOrDefault(artist.getId(), 0L).intValue();
|
||||
ArtistScheduleDO schedule = scheduleByArtist.get(artist.getId());
|
||||
String artistStatus = resolveArtistDayStatus(artist, schedule, count);
|
||||
if (!"rest".equals(artistStatus)) {
|
||||
workingArtistCount++;
|
||||
if (count > 0) {
|
||||
busyWorkingArtistCount++;
|
||||
}
|
||||
}
|
||||
PlanningArtistCountVO countVO = new PlanningArtistCountVO();
|
||||
countVO.setArtistId(artist.getId());
|
||||
countVO.setArtistName(artist.getName());
|
||||
countVO.setShortName(artist.getShortName());
|
||||
countVO.setColor(artist.getColor());
|
||||
countVO.setCount(count);
|
||||
countVO.setStatus(artistStatus);
|
||||
artistCounts.add(countVO);
|
||||
}
|
||||
int total = dayAppointments.size();
|
||||
boolean hasWorkingSchedule = workingArtistCount > 0;
|
||||
boolean allBusy = workingArtistCount > 0 && busyWorkingArtistCount == workingArtistCount;
|
||||
|
||||
PlanningDaySummaryVO summary = new PlanningDaySummaryVO();
|
||||
summary.setDate(date);
|
||||
summary.setTotalCount(total);
|
||||
summary.setArtistCounts(artistCounts);
|
||||
summary.setDayStatus(PlanningCalendarSupport.resolveDayStatus(total, hasWorkingSchedule, allBusy));
|
||||
summaries.add(summary);
|
||||
cursor = cursor.plusDays(1);
|
||||
}
|
||||
return summaries;
|
||||
}
|
||||
|
||||
private String resolveArtistDayStatus(PlanningArtistVO artist, ArtistScheduleDO schedule, int count) {
|
||||
if (schedule != null && !Integer.valueOf(1).equals(schedule.getStatus())) {
|
||||
return "rest";
|
||||
}
|
||||
if (schedule == null && Integer.valueOf(0).equals(artist.getStatus())) {
|
||||
return "rest";
|
||||
}
|
||||
if (count <= 0) {
|
||||
return "free";
|
||||
}
|
||||
if (schedule != null && schedule.getCapacity() != null && schedule.getCapacity() > 0 && count >= schedule.getCapacity() * 4) {
|
||||
return "full";
|
||||
}
|
||||
return "working";
|
||||
}
|
||||
|
||||
private ProductDO requireActiveProduct(Long productId, Long shopId) {
|
||||
if (productId == null) {
|
||||
throw new RuntimeException("请选择预约项目");
|
||||
}
|
||||
ProductDO product = productMapper.selectById(productId);
|
||||
if (product == null || Integer.valueOf(1).equals(product.getIsDelete()) || !shopId.equals(product.getShopId())) {
|
||||
throw new RuntimeException("预约项目不存在或不属于当前店铺");
|
||||
}
|
||||
return product;
|
||||
}
|
||||
|
||||
private UserDO requireActiveArtist(Long artistId, Long shopId) {
|
||||
if (artistId == null) {
|
||||
throw new RuntimeException("请选择美甲师");
|
||||
}
|
||||
UserDO artist = userMapper.selectById(artistId);
|
||||
if (artist == null || Integer.valueOf(1).equals(artist.getIsDelete())
|
||||
|| !Integer.valueOf(3).equals(artist.getType()) || !shopId.equals(artist.getShopId())) {
|
||||
throw new RuntimeException("美甲师不存在或不属于当前店铺");
|
||||
}
|
||||
return artist;
|
||||
}
|
||||
|
||||
private UserDO resolveCustomer(Long shopId, PlanningAppointmentCreateDTO dto) {
|
||||
if (dto.getCustomerUserId() != null) {
|
||||
UserDO customer = userMapper.selectById(dto.getCustomerUserId());
|
||||
if (customer == null || Integer.valueOf(1).equals(customer.getIsDelete())) {
|
||||
throw new RuntimeException("客户不存在");
|
||||
}
|
||||
return customer;
|
||||
}
|
||||
if (!hasText(dto.getPhone())) {
|
||||
throw new RuntimeException("客户手机号不能为空");
|
||||
}
|
||||
QueryWrapper<UserDO> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("is_delete", 0)
|
||||
.and(query -> query.eq("phone", dto.getPhone()).or().eq("contact_phone", dto.getPhone()))
|
||||
.last("LIMIT 1");
|
||||
UserDO existing = userMapper.selectOne(wrapper);
|
||||
if (existing != null) {
|
||||
return existing;
|
||||
}
|
||||
UserDO customer = new UserDO();
|
||||
customer.setShopId(shopId);
|
||||
customer.setNickname(firstNonBlank(dto.getCustomerName(), dto.getPhone()));
|
||||
customer.setPhone(dto.getPhone());
|
||||
customer.setContactPhone(dto.getPhone());
|
||||
customer.setAccount(dto.getPhone());
|
||||
customer.setType(0);
|
||||
customer.setStatus(1);
|
||||
customer.setIsDelete(0);
|
||||
userMapper.insert(customer);
|
||||
return customer;
|
||||
}
|
||||
|
||||
private OrderDO requireAccessibleOrder(UserDO currentUser, Long orderId) {
|
||||
OrderDO order = orderMapper.selectById(orderId);
|
||||
if (order == null || Integer.valueOf(1).equals(order.getIsDelete())) {
|
||||
throw new RuntimeException("订单不存在");
|
||||
}
|
||||
adminScopeHelper.ensureShopAccessible(currentUser, order.getShopId(), "无权访问其他店铺预约");
|
||||
return order;
|
||||
}
|
||||
|
||||
private AppointmentReservationDO findActiveReservation(Long orderItemId) {
|
||||
QueryWrapper<AppointmentReservationDO> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("order_item_id", orderItemId)
|
||||
.eq("is_delete", 0)
|
||||
.in("status", ACTIVE_RESERVATION_STATUS)
|
||||
.orderByDesc("id")
|
||||
.last("LIMIT 1");
|
||||
return appointmentReservationMapper.selectOne(wrapper);
|
||||
}
|
||||
|
||||
private void ensureWithinBusinessHours(Long shopId, LocalDateTime startTime, LocalDateTime endTime) {
|
||||
ShopDO shop = shopMapper.selectById(shopId);
|
||||
PlanningCalendarSupport.BusinessHours hours = PlanningCalendarSupport.parseBusinessHours(shop == null ? null : shop.getBusinessHours());
|
||||
LocalTime start = startTime.toLocalTime();
|
||||
LocalTime end = endTime.toLocalTime();
|
||||
if (start.isBefore(hours.start()) || end.isAfter(hours.end()) || !startTime.toLocalDate().equals(endTime.toLocalDate())) {
|
||||
throw new RuntimeException("预约时间超出店铺营业时间");
|
||||
}
|
||||
}
|
||||
|
||||
private LocalDateTime parseAppointmentStart(String appointmentStartTime, String appointmentDate, String appointmentTime) {
|
||||
if (hasText(appointmentStartTime)) {
|
||||
String normalized = appointmentStartTime.trim().replace('T', ' ');
|
||||
if (normalized.length() == 16) {
|
||||
normalized = normalized + ":00";
|
||||
}
|
||||
try {
|
||||
return LocalDateTime.parse(normalized, DATE_TIME_FORMATTER);
|
||||
} catch (DateTimeParseException ignored) {
|
||||
return LocalDateTime.parse(appointmentStartTime.trim());
|
||||
}
|
||||
}
|
||||
if (!hasText(appointmentDate) || !hasText(appointmentTime)) {
|
||||
throw new RuntimeException("请选择预约日期和时间");
|
||||
}
|
||||
LocalDate date = LocalDate.parse(appointmentDate.trim());
|
||||
LocalTime time = LocalTime.parse(appointmentTime.trim().length() == 5 ? appointmentTime.trim() + ":00" : appointmentTime.trim());
|
||||
return LocalDateTime.of(date, time);
|
||||
}
|
||||
|
||||
private int resolveDurationMinutes(ProductDO product, Integer overrideMinutes) {
|
||||
if (overrideMinutes != null && overrideMinutes > 0) {
|
||||
return overrideMinutes;
|
||||
}
|
||||
return PlanningCalendarSupport.parseDurationMinutes(product == null ? null : product.getApproximateDuration(), DEFAULT_DURATION_MINUTES);
|
||||
}
|
||||
|
||||
private boolean isVisibleOrder(OrderDO order, Long shopId) {
|
||||
return order != null
|
||||
&& !Integer.valueOf(1).equals(order.getIsDelete())
|
||||
&& shopId.equals(order.getShopId())
|
||||
&& !Integer.valueOf(OrderStatus.CANCELLED.getCode()).equals(order.getStatus());
|
||||
}
|
||||
|
||||
private Map<Long, OrderItemDO> loadOrderItems(Set<Long> itemIds) {
|
||||
if (itemIds == null || itemIds.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
return orderItemMapper.selectBatchIds(itemIds).stream()
|
||||
.collect(Collectors.toMap(OrderItemDO::getId, Function.identity(), (a, b) -> a));
|
||||
}
|
||||
|
||||
private Map<Long, OrderDO> loadOrders(Set<Long> orderIds) {
|
||||
if (orderIds == null || orderIds.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
return orderMapper.selectBatchIds(orderIds).stream()
|
||||
.collect(Collectors.toMap(OrderDO::getId, Function.identity(), (a, b) -> a));
|
||||
}
|
||||
|
||||
private Map<Long, ProductDO> loadProducts(Set<Long> productIds) {
|
||||
if (productIds == null || productIds.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
return productMapper.selectBatchIds(productIds).stream()
|
||||
.collect(Collectors.toMap(ProductDO::getId, Function.identity(), (a, b) -> a));
|
||||
}
|
||||
|
||||
private Map<Long, UserDO> loadUsers(Set<Long> userIds) {
|
||||
if (userIds == null || userIds.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
return userMapper.selectBatchIds(userIds).stream()
|
||||
.collect(Collectors.toMap(UserDO::getId, Function.identity(), (a, b) -> a));
|
||||
}
|
||||
|
||||
private String colorForArtist(Long artistId, int index) {
|
||||
if (artistId == null) {
|
||||
return ARTIST_COLORS.get(index % ARTIST_COLORS.size());
|
||||
}
|
||||
int colorIndex = Math.abs(artistId.hashCode()) % ARTIST_COLORS.size();
|
||||
return ARTIST_COLORS.get(colorIndex);
|
||||
}
|
||||
|
||||
private String statusText(Integer status) {
|
||||
if (Integer.valueOf(OrderStatus.PENDING_SERVICE.getCode()).equals(status)) {
|
||||
return "已确认";
|
||||
}
|
||||
if (Integer.valueOf(OrderStatus.COMPLETED.getCode()).equals(status)) {
|
||||
return "已完成";
|
||||
}
|
||||
if (Integer.valueOf(OrderStatus.CANCELLED.getCode()).equals(status)) {
|
||||
return "已取消";
|
||||
}
|
||||
if (Integer.valueOf(OrderStatus.PRICE_CONFIRMING.getCode()).equals(status)) {
|
||||
return "待确认";
|
||||
}
|
||||
return "未知";
|
||||
}
|
||||
|
||||
private <T> List<T> safeList(List<T> list) {
|
||||
return list == null ? List.of() : list;
|
||||
}
|
||||
|
||||
private String firstNonBlank(String... values) {
|
||||
for (String value : values) {
|
||||
if (hasText(value)) {
|
||||
return value.trim();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private String trimToNull(String value) {
|
||||
return hasText(value) ? value.trim() : null;
|
||||
}
|
||||
|
||||
private boolean hasText(String value) {
|
||||
return value != null && !value.trim().isEmpty();
|
||||
}
|
||||
}
|
||||
+69
@@ -10,11 +10,13 @@ import com.xiaowang.yuminailcore.dto.NailArtistInfoDTO;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.entity.UserPermissionDO;
|
||||
import com.xiaowang.yuminailcore.entity.PermissionDO;
|
||||
import com.xiaowang.yuminailcore.entity.ShopDO;
|
||||
import com.xiaowang.yuminailcore.entity.UserRelationDO;
|
||||
import com.xiaowang.yuminailcore.entity.UserInviteCodeDO;
|
||||
import com.xiaowang.yuminailcore.entity.UserShopRoleDO;
|
||||
import com.xiaowang.yuminailcore.entity.WechatMiniBindingDO;
|
||||
import com.xiaowang.yuminailcore.mapper.UserMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.ShopMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.UserPermissionMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.PermissionMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.UserRelationMapper;
|
||||
@@ -117,6 +119,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
* Variable `userMapper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
*/
|
||||
private final UserMapper userMapper;
|
||||
private final ShopMapper shopMapper;
|
||||
/**
|
||||
* Variable `jwtUtil`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
*/
|
||||
@@ -1484,6 +1487,72 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public LoginResponseVO registerPlanningManager(PlanningManagerRegisterDTO registerDTO) {
|
||||
if (registerDTO == null) {
|
||||
throw new RuntimeException("注册信息不能为空");
|
||||
}
|
||||
String phone = validateUserPhone(registerDTO.getPhone(), null, true);
|
||||
if (!verificationCodeService.verifyCode(phone, registerDTO.getCode())) {
|
||||
throw new RuntimeException("验证码错误或已过期");
|
||||
}
|
||||
String password = registerDTO.getPassword();
|
||||
if (!StringUtils.hasText(password)) {
|
||||
throw new RuntimeException("密码不能为空");
|
||||
}
|
||||
if (!Objects.equals(password, registerDTO.getConfirmPassword())) {
|
||||
throw new RuntimeException("两次密码不一致");
|
||||
}
|
||||
validatePasswordStrength(password);
|
||||
String shopName = registerDTO.getShopName() == null ? null : registerDTO.getShopName().trim();
|
||||
if (!StringUtils.hasText(shopName)) {
|
||||
throw new RuntimeException("店铺名称不能为空");
|
||||
}
|
||||
|
||||
UserDO existingUser = userMapper.selectOne(
|
||||
Wrappers.lambdaQuery(UserDO.class)
|
||||
.eq(UserDO::getAccount, phone)
|
||||
.eq(UserDO::getIsDelete, 0)
|
||||
.last("limit 1")
|
||||
);
|
||||
if (existingUser != null) {
|
||||
throw new RuntimeException("该手机号已注册");
|
||||
}
|
||||
|
||||
ShopDO shop = new ShopDO();
|
||||
shop.setShopName(shopName);
|
||||
shop.setDescription("指尖管理师注册店铺");
|
||||
shop.setBusinessHours("10:00-22:00");
|
||||
shop.setStatus(1);
|
||||
shop.setAuthorizationStartDate(LocalDateTime.now().minusDays(1).toLocalDate());
|
||||
shop.setAuthorizationDays(0);
|
||||
shop.setAuthorizationExpireTime(LocalDateTime.now().minusSeconds(1));
|
||||
shop.setIsDelete(0);
|
||||
shopMapper.insert(shop);
|
||||
|
||||
UserDO manager = new UserDO();
|
||||
manager.setShopId(shop.getId());
|
||||
manager.setNickname(shopName + "店长");
|
||||
manager.setAccount(phone);
|
||||
manager.setPassword(passwordEncoder.encode(password));
|
||||
manager.setPhone(phone);
|
||||
manager.setContactPhone(phone);
|
||||
manager.setPhoneVerified(1);
|
||||
manager.setEmailVerified(0);
|
||||
manager.setType(2);
|
||||
manager.setStatus(1);
|
||||
manager.setIsDelete(0);
|
||||
manager.setAvatar(DEFAULT_AVATAR_URL);
|
||||
userMapper.insert(manager);
|
||||
|
||||
syncDefaultPermissions(manager.getId(), manager.getType());
|
||||
userShopBindingSupport.syncUserShopBindings(manager.getId(), List.of(shop.getId()));
|
||||
createRelationForRegister(manager.getId(), shop.getId(), null);
|
||||
clearLoginFailureCount(manager.getAccount());
|
||||
return buildLoginResponse(manager, shop.getId(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Run business method `refreshToken`.
|
||||
|
||||
+10
-1
@@ -16,6 +16,7 @@ import com.xiaowang.yuminailcore.mapper.OrderArtistReviewMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.OrderItemMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.OrderMapper;
|
||||
import com.xiaowang.yuminailcore.service.WorkbenchService;
|
||||
import com.xiaowang.yuminailcore.support.OrderStatus;
|
||||
import com.xiaowang.yuminailcore.vo.StoreWorkbenchVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -47,7 +48,7 @@ public class WorkbenchServiceImpl implements WorkbenchService {
|
||||
List<OrderDO> orders = scopedOrders(shopId, artistId);
|
||||
StoreWorkbenchVO vo = new StoreWorkbenchVO();
|
||||
vo.setTodayOrderCount(orders.stream().filter(order -> between(order.getCreateTime(), todayStart, tomorrowStart)).count());
|
||||
vo.setPendingOrderCount(orders.stream().filter(order -> Integer.valueOf(1).equals(order.getStatus())).count());
|
||||
vo.setPendingOrderCount(orders.stream().filter(this::isActionableOrder).count());
|
||||
vo.setPendingAfterSaleCount(countAfterSales(shopId));
|
||||
vo.setPendingArtistChangeCount(countArtistChanges(shopId, artistId));
|
||||
vo.setLowStockItemCount(countLowStock(shopId));
|
||||
@@ -61,6 +62,14 @@ public class WorkbenchServiceImpl implements WorkbenchService {
|
||||
return vo;
|
||||
}
|
||||
|
||||
private boolean isActionableOrder(OrderDO order) {
|
||||
if (order == null || order.getStatus() == null) {
|
||||
return false;
|
||||
}
|
||||
return Integer.valueOf(OrderStatus.PRICE_CONFIRMING.getCode()).equals(order.getStatus())
|
||||
|| Integer.valueOf(OrderStatus.PENDING_SERVICE.getCode()).equals(order.getStatus());
|
||||
}
|
||||
|
||||
private List<OrderDO> scopedOrders(Long shopId, Long artistId) {
|
||||
List<OrderDO> orders = orderMapper.selectList(new LambdaQueryWrapper<OrderDO>()
|
||||
.eq(shopId != null, OrderDO::getShopId, shopId)
|
||||
|
||||
@@ -16,6 +16,9 @@ public final class OrderStateMachine {
|
||||
public static boolean isAllowedTransition(Integer fromStatus, Integer toStatus) {
|
||||
OrderStatus from = OrderStatus.requireKnown(fromStatus);
|
||||
OrderStatus to = OrderStatus.requireKnown(toStatus);
|
||||
if (from == OrderStatus.PRICE_CONFIRMING) {
|
||||
return to == OrderStatus.PENDING_SERVICE || to == OrderStatus.CANCELLED;
|
||||
}
|
||||
return from == OrderStatus.PENDING_SERVICE
|
||||
&& (to == OrderStatus.COMPLETED || to == OrderStatus.CANCELLED);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.util.Arrays;
|
||||
* Usage: reference this enum from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
public enum OrderStatus {
|
||||
PRICE_CONFIRMING(0),
|
||||
PENDING_SERVICE(1),
|
||||
COMPLETED(2),
|
||||
CANCELLED(3);
|
||||
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package com.xiaowang.yuminailcore.support;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalTime;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class PlanningCalendarSupport {
|
||||
|
||||
private static final LocalTime DEFAULT_START = LocalTime.of(10, 0);
|
||||
private static final LocalTime DEFAULT_END = LocalTime.of(22, 0);
|
||||
private static final Pattern NUMBER_PATTERN = Pattern.compile("(\\d+(?:\\.\\d+)?)");
|
||||
|
||||
private PlanningCalendarSupport() {
|
||||
}
|
||||
|
||||
public static String shortName(String name) {
|
||||
if (name == null || name.trim().isEmpty()) {
|
||||
return "?";
|
||||
}
|
||||
String normalized = name.trim();
|
||||
if (normalized.startsWith("小") && normalized.length() > 1) {
|
||||
return normalized.substring(1, 2);
|
||||
}
|
||||
if (normalized.endsWith("老师") && normalized.length() > 2) {
|
||||
return normalized.substring(0, 1);
|
||||
}
|
||||
return normalized.substring(0, 1).toUpperCase();
|
||||
}
|
||||
|
||||
public static BusinessHours parseBusinessHours(String businessHours) {
|
||||
if (businessHours == null || businessHours.trim().isEmpty()) {
|
||||
return new BusinessHours(DEFAULT_START, DEFAULT_END);
|
||||
}
|
||||
String[] parts = businessHours.trim().split("-");
|
||||
if (parts.length != 2) {
|
||||
return new BusinessHours(DEFAULT_START, DEFAULT_END);
|
||||
}
|
||||
try {
|
||||
LocalTime start = LocalTime.parse(parts[0].trim());
|
||||
LocalTime end = LocalTime.parse(parts[1].trim());
|
||||
if (!start.isBefore(end)) {
|
||||
return new BusinessHours(DEFAULT_START, DEFAULT_END);
|
||||
}
|
||||
return new BusinessHours(start, end);
|
||||
} catch (RuntimeException ignored) {
|
||||
return new BusinessHours(DEFAULT_START, DEFAULT_END);
|
||||
}
|
||||
}
|
||||
|
||||
public static int parseDurationMinutes(String durationText, int defaultMinutes) {
|
||||
if (durationText == null || durationText.trim().isEmpty()) {
|
||||
return defaultMinutes;
|
||||
}
|
||||
Matcher matcher = NUMBER_PATTERN.matcher(durationText.trim());
|
||||
if (!matcher.find()) {
|
||||
return defaultMinutes;
|
||||
}
|
||||
BigDecimal amount = new BigDecimal(matcher.group(1));
|
||||
if (durationText.contains("小时") || durationText.toLowerCase().contains("hour")) {
|
||||
amount = amount.multiply(BigDecimal.valueOf(60));
|
||||
}
|
||||
int minutes = amount.setScale(0, RoundingMode.HALF_UP).intValue();
|
||||
return minutes > 0 ? minutes : defaultMinutes;
|
||||
}
|
||||
|
||||
public static String resolveDayStatus(int totalCount, boolean hasWorkingSchedule, boolean allWorkingArtistsBusy) {
|
||||
if (!hasWorkingSchedule) {
|
||||
return "rest";
|
||||
}
|
||||
if (totalCount <= 0) {
|
||||
return "free";
|
||||
}
|
||||
if (allWorkingArtistsBusy) {
|
||||
return "full";
|
||||
}
|
||||
return "working";
|
||||
}
|
||||
|
||||
public record BusinessHours(LocalTime start, LocalTime end) {
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,24 @@ public class CheckoutPreviewVO {
|
||||
|
||||
private List<CheckoutCouponPreviewVO> unavailableCoupons = new ArrayList<>();
|
||||
|
||||
private Boolean bookingAvailable;
|
||||
|
||||
private List<CheckoutIssueVO> bookingIssues = new ArrayList<>();
|
||||
|
||||
private String vipTip;
|
||||
|
||||
private String summaryText;
|
||||
|
||||
@Data
|
||||
public static class CheckoutIssueVO {
|
||||
private String code;
|
||||
|
||||
private String message;
|
||||
|
||||
private Long itemId;
|
||||
|
||||
private Long productId;
|
||||
|
||||
private String productTitle;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,9 @@ public class OrderItemVO {
|
||||
* Field `price` (BigDecimal): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled.
|
||||
*/
|
||||
private BigDecimal price;
|
||||
private BigDecimal referencePrice;
|
||||
private BigDecimal quotedPrice;
|
||||
private BigDecimal confirmedPrice;
|
||||
/**
|
||||
* Field `totalPrice` (BigDecimal): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.xiaowang.yuminailcore.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class OrderQuoteItemVO {
|
||||
private Long orderItemId;
|
||||
private Long productId;
|
||||
private String productTitle;
|
||||
private Integer quantity;
|
||||
private BigDecimal referencePrice;
|
||||
private BigDecimal quotedPrice;
|
||||
private BigDecimal confirmedPrice;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.xiaowang.yuminailcore.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class OrderQuoteMessageVO {
|
||||
private Long id;
|
||||
private Long orderId;
|
||||
private Long actorId;
|
||||
private String actorType;
|
||||
private String actorTypeText;
|
||||
private String action;
|
||||
private String actionText;
|
||||
private String remark;
|
||||
private List<OrderQuoteItemVO> items;
|
||||
private LocalDateTime createTime;
|
||||
}
|
||||
@@ -64,6 +64,14 @@ public class OrderVO {
|
||||
private String paymentMethod;
|
||||
private String paymentOrderNo;
|
||||
private String refundStatus;
|
||||
private String customerRemark;
|
||||
private String quoteStatus;
|
||||
private String quoteStatusText;
|
||||
private Boolean quoteUserConfirmed;
|
||||
private Boolean quoteShopConfirmed;
|
||||
private LocalDateTime quoteExpireTime;
|
||||
private LocalDateTime quoteConfirmedTime;
|
||||
private List<OrderQuoteMessageVO> quoteMessages;
|
||||
/**
|
||||
* Field `customerNickname` (String): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.xiaowang.yuminailcore.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class PlanningAppointmentVO {
|
||||
private Long orderId;
|
||||
private String orderNo;
|
||||
private Long orderItemId;
|
||||
private Long customerId;
|
||||
private String customerName;
|
||||
private String customerPhone;
|
||||
private Long productId;
|
||||
private String productTitle;
|
||||
private Long artistId;
|
||||
private String artistName;
|
||||
private String artistColor;
|
||||
private String date;
|
||||
private String startTime;
|
||||
private String endTime;
|
||||
private Integer startMinute;
|
||||
private Integer durationMinutes;
|
||||
private Integer status;
|
||||
private String statusText;
|
||||
private BigDecimal amount;
|
||||
private String remark;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.xiaowang.yuminailcore.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PlanningArtistCountVO {
|
||||
private Long artistId;
|
||||
private String artistName;
|
||||
private String shortName;
|
||||
private String color;
|
||||
private Integer count;
|
||||
private String status;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.xiaowang.yuminailcore.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PlanningArtistVO {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String shortName;
|
||||
private String phone;
|
||||
private String avatar;
|
||||
private String color;
|
||||
private Integer status;
|
||||
private String statusText;
|
||||
private String workStartTime;
|
||||
private String workEndTime;
|
||||
private Integer rangeCount;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.xiaowang.yuminailcore.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class PlanningCalendarVO {
|
||||
private String businessStartTime;
|
||||
private String businessEndTime;
|
||||
private Integer slotMinutes;
|
||||
private List<PlanningArtistVO> artists;
|
||||
private List<PlanningScheduleVO> schedules;
|
||||
private List<PlanningAppointmentVO> appointments;
|
||||
private List<PlanningDaySummaryVO> daySummaries;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.xiaowang.yuminailcore.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class PlanningDaySummaryVO {
|
||||
private String date;
|
||||
private Integer totalCount;
|
||||
private List<PlanningArtistCountVO> artistCounts;
|
||||
private String dayStatus;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.xiaowang.yuminailcore.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PlanningScheduleVO {
|
||||
private Long id;
|
||||
private Long artistId;
|
||||
private String artistName;
|
||||
private String date;
|
||||
private String startTime;
|
||||
private String endTime;
|
||||
private Integer capacity;
|
||||
private Integer status;
|
||||
private String statusText;
|
||||
private String remark;
|
||||
}
|
||||
@@ -1684,6 +1684,36 @@ ON DUPLICATE KEY UPDATE
|
||||
is_delete = 0,
|
||||
update_time = NOW();
|
||||
|
||||
CALL sp_add_column_if_not_exists('t_order', 'customer_remark', 'varchar(500) NULL COMMENT ''用户询价预约备注''');
|
||||
CALL sp_add_column_if_not_exists('t_order', 'quote_status', 'varchar(32) NULL COMMENT ''报价状态:CONFIRMING/CONFIRMED/EXPIRED''');
|
||||
CALL sp_add_column_if_not_exists('t_order', 'quote_user_confirmed', 'tinyint unsigned NOT NULL DEFAULT 0 COMMENT ''用户是否确认当前报价''');
|
||||
CALL sp_add_column_if_not_exists('t_order', 'quote_shop_confirmed', 'tinyint unsigned NOT NULL DEFAULT 0 COMMENT ''店长是否确认当前报价''');
|
||||
CALL sp_add_column_if_not_exists('t_order', 'quote_expire_time', 'datetime NULL COMMENT ''询价报价过期时间''');
|
||||
CALL sp_add_column_if_not_exists('t_order', 'quote_confirmed_time', 'datetime NULL COMMENT ''双方确认报价时间''');
|
||||
CALL sp_add_index_if_not_exists('t_order', 'idx_t_order_quote_status_expire', '(`quote_status`, `quote_expire_time`)');
|
||||
|
||||
CALL sp_add_column_if_not_exists('t_order_item', 'reference_price', 'decimal(10,2) NULL COMMENT ''作品参考价快照''');
|
||||
CALL sp_add_column_if_not_exists('t_order_item', 'quoted_price', 'decimal(10,2) NULL COMMENT ''当前报价''');
|
||||
CALL sp_add_column_if_not_exists('t_order_item', 'confirmed_price', 'decimal(10,2) NULL COMMENT ''最终确认价''');
|
||||
|
||||
CREATE TABLE IF NOT EXISTS t_order_quote_message
|
||||
(
|
||||
id bigint unsigned auto_increment comment '报价交互消息主键'
|
||||
primary key,
|
||||
order_id bigint unsigned not null comment '订单ID',
|
||||
actor_id bigint unsigned null comment '操作人ID',
|
||||
actor_type varchar(32) not null comment '操作人类型:USER/SHOP/SYSTEM',
|
||||
action varchar(32) not null comment '动作:CREATE/SHOP_QUOTE/USER_REPLY/USER_CONFIRM/SHOP_CONFIRM/SYSTEM_CONFIRM/SYSTEM_EXPIRE',
|
||||
remark varchar(500) null comment '备注',
|
||||
items_snapshot text null comment '订单项报价快照JSON',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删'
|
||||
)
|
||||
comment '订单询价报价交互消息表';
|
||||
|
||||
CALL sp_add_index_if_not_exists('t_order_quote_message', 'idx_order_quote_message_order_id', '(`order_id`, `is_delete`, `create_time`)');
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `t_messagehub_push_config` (
|
||||
`id` bigint unsigned NOT NULL COMMENT '主键ID',
|
||||
`scene_code` varchar(80) NOT NULL COMMENT '业务场景编码',
|
||||
|
||||
+97
-1
@@ -1,16 +1,22 @@
|
||||
package com.xiaowang.yuminailcore.service.impl;
|
||||
|
||||
import com.xiaowang.yuminailcore.common.BusinessException;
|
||||
import com.xiaowang.yuminailcore.dto.CheckoutPreviewDTO;
|
||||
import com.xiaowang.yuminailcore.dto.OrderItemDTO;
|
||||
import com.xiaowang.yuminailcore.entity.CartDO;
|
||||
import com.xiaowang.yuminailcore.entity.CouponDO;
|
||||
import com.xiaowang.yuminailcore.entity.ShopDO;
|
||||
import com.xiaowang.yuminailcore.entity.ProductDO;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.mapper.CartMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.CouponMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.OrderItemMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.ProductMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.ShopMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.UserMapper;
|
||||
import com.xiaowang.yuminailcore.service.AppointmentCapacityService;
|
||||
import com.xiaowang.yuminailcore.service.CouponService;
|
||||
import com.xiaowang.yuminailcore.support.BookableArtistSupport;
|
||||
import com.xiaowang.yuminailcore.support.UserShopBindingSupport;
|
||||
import com.xiaowang.yuminailcore.vo.CheckoutPreviewVO;
|
||||
import com.xiaowang.yuminailcore.vo.UserCouponVO;
|
||||
@@ -25,7 +31,9 @@ import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class OrderServiceImplCheckoutPreviewTest {
|
||||
@@ -37,11 +45,19 @@ class OrderServiceImplCheckoutPreviewTest {
|
||||
@Mock
|
||||
private CouponMapper couponMapper;
|
||||
@Mock
|
||||
private OrderItemMapper orderItemMapper;
|
||||
@Mock
|
||||
private UserMapper userMapper;
|
||||
@Mock
|
||||
private ShopMapper shopMapper;
|
||||
@Mock
|
||||
private CouponService couponService;
|
||||
@Mock
|
||||
private BookableArtistSupport bookableArtistSupport;
|
||||
@Mock
|
||||
private UserShopBindingSupport userShopBindingSupport;
|
||||
@Mock
|
||||
private AppointmentCapacityService appointmentCapacityService;
|
||||
|
||||
private OrderServiceImpl service;
|
||||
|
||||
@@ -52,9 +68,13 @@ class OrderServiceImplCheckoutPreviewTest {
|
||||
ReflectionTestUtils.setField(service, "productMapper", productMapper);
|
||||
ReflectionTestUtils.setField(service, "cartMapper", cartMapper);
|
||||
ReflectionTestUtils.setField(service, "couponMapper", couponMapper);
|
||||
ReflectionTestUtils.setField(service, "orderItemMapper", orderItemMapper);
|
||||
ReflectionTestUtils.setField(service, "userMapper", userMapper);
|
||||
ReflectionTestUtils.setField(service, "shopMapper", shopMapper);
|
||||
ReflectionTestUtils.setField(service, "couponService", couponService);
|
||||
ReflectionTestUtils.setField(service, "bookableArtistSupport", bookableArtistSupport);
|
||||
ReflectionTestUtils.setField(service, "userShopBindingSupport", userShopBindingSupport);
|
||||
ReflectionTestUtils.setField(service, "appointmentCapacityService", appointmentCapacityService);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -67,7 +87,10 @@ class OrderServiceImplCheckoutPreviewTest {
|
||||
when(productMapper.selectById(100L)).thenReturn(product);
|
||||
when(cartMapper.selectByUserIdAndProductId(20L, 100L)).thenReturn(cartItem);
|
||||
when(userMapper.selectById(20L)).thenReturn(user("黄金"));
|
||||
when(userMapper.selectById(30L)).thenReturn(artist(30L));
|
||||
when(bookableArtistSupport.isBookableServiceUser(any(UserDO.class))).thenReturn(true);
|
||||
when(userShopBindingSupport.canUserAccessShop(20L, 9L, false, null)).thenReturn(true);
|
||||
when(userShopBindingSupport.isUserAccessibleInShop(30L, 9L)).thenReturn(true);
|
||||
when(couponService.getAvailableCoupons(20L, "法式,通勤", 200.0, 9L)).thenReturn(List.of(userCoupon, vipCoupon));
|
||||
when(couponMapper.selectById(300L)).thenReturn(coupon(300L, "黄金VIP自动90折券", 1, new BigDecimal("9.0"), null, null, 9L));
|
||||
when(couponMapper.selectById(400L)).thenReturn(coupon(400L, "满150减30", 2, null, new BigDecimal("150.00"), new BigDecimal("30.00"), 9L));
|
||||
@@ -89,13 +112,70 @@ class OrderServiceImplCheckoutPreviewTest {
|
||||
assertThat(preview.getUnavailableCoupons()).extracting("unavailableReason")
|
||||
.containsExactly("还差 ¥100.00 可用", "仅限其他门店使用");
|
||||
assertThat(preview.getVipTip()).isEqualTo("黄金VIP本单可省 ¥20.00,已为你计算。");
|
||||
assertThat(preview.getSummaryText()).isEqualTo("商品小计 ¥200.00,已省 ¥30.00,到手价 ¥170.00。");
|
||||
assertThat(preview.getSummaryText()).isEqualTo("参考价小计 ¥200.00,预估优惠 ¥30.00,预估应付 ¥170.00。");
|
||||
assertThat(ReflectionTestUtils.getField(preview, "bookingAvailable")).isEqualTo(true);
|
||||
assertThat((List<?>) ReflectionTestUtils.getField(preview, "bookingIssues")).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkoutPreviewReportsBookingIssuesWithoutReservingCapacity() {
|
||||
ProductDO product = product(100L, "夜间款", "通勤", new BigDecimal("80.00"));
|
||||
product.setApproximateDuration("60分钟");
|
||||
product.setBookableArtists("77");
|
||||
CartDO cartItem = cartItem(100L, 1);
|
||||
LocalDateTime appointmentTime = LocalDateTime.now().plusDays(1)
|
||||
.withHour(17)
|
||||
.withMinute(30)
|
||||
.withSecond(0)
|
||||
.withNano(0);
|
||||
|
||||
when(productMapper.selectById(100L)).thenReturn(product);
|
||||
when(cartMapper.selectByUserIdAndProductId(20L, 100L)).thenReturn(cartItem);
|
||||
when(userMapper.selectById(77L)).thenReturn(artist(77L));
|
||||
when(bookableArtistSupport.isBookableServiceUser(any(UserDO.class))).thenReturn(true);
|
||||
when(userShopBindingSupport.canUserAccessShop(20L, 9L, false, null)).thenReturn(true);
|
||||
when(userShopBindingSupport.isUserAccessibleInShop(77L, 9L)).thenReturn(true);
|
||||
when(shopMapper.selectById(9L)).thenReturn(shop("09:00-18:00"));
|
||||
when(couponService.getAvailableCoupons(20L, "通勤", 80.0, 9L)).thenReturn(List.of());
|
||||
when(couponMapper.selectList(any())).thenReturn(List.of());
|
||||
|
||||
CheckoutPreviewVO preview = service.checkoutPreview(20L, order(100L, 1, 77L, appointmentTime));
|
||||
|
||||
assertThat(preview.getSubtotalAmount()).isEqualByComparingTo("80.00");
|
||||
assertThat(ReflectionTestUtils.getField(preview, "bookingAvailable")).isEqualTo(false);
|
||||
List<?> bookingIssues = (List<?>) ReflectionTestUtils.getField(preview, "bookingIssues");
|
||||
assertThat(bookingIssues).hasSize(1);
|
||||
Object issue = bookingIssues.get(0);
|
||||
assertThat(ReflectionTestUtils.getField(issue, "code")).isEqualTo("BUSINESS_HOURS");
|
||||
assertThat(ReflectionTestUtils.getField(issue, "message").toString()).contains("营业时间");
|
||||
assertThat(ReflectionTestUtils.getField(issue, "productId")).isEqualTo(100L);
|
||||
assertThat(ReflectionTestUtils.getField(issue, "productTitle")).isEqualTo("夜间款");
|
||||
verifyNoInteractions(appointmentCapacityService);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createOrderReturnsBusinessCodeForBookingValidationBeforeLocking() {
|
||||
assertThatThrownBy(() -> service.createOrder(20L, null))
|
||||
.isInstanceOfSatisfying(BusinessException.class, exception -> {
|
||||
assertThat(exception.getCode()).isEqualTo(409);
|
||||
assertThat(exception.getMessage()).isEqualTo("订单项不能为空");
|
||||
});
|
||||
}
|
||||
|
||||
private CheckoutPreviewDTO order(Long productId, Integer quantity) {
|
||||
return order(productId, quantity, 30L, LocalDateTime.now().plusDays(1)
|
||||
.withHour(10)
|
||||
.withMinute(0)
|
||||
.withSecond(0)
|
||||
.withNano(0));
|
||||
}
|
||||
|
||||
private CheckoutPreviewDTO order(Long productId, Integer quantity, Long artistId, LocalDateTime appointmentTime) {
|
||||
OrderItemDTO item = new OrderItemDTO();
|
||||
item.setProductId(productId);
|
||||
item.setQuantity(quantity);
|
||||
item.setArtistId(artistId);
|
||||
item.setAppointmentTime(appointmentTime.toString());
|
||||
|
||||
CheckoutPreviewDTO dto = new CheckoutPreviewDTO();
|
||||
dto.setItems(List.of(item));
|
||||
@@ -113,6 +193,14 @@ class OrderServiceImplCheckoutPreviewTest {
|
||||
return product;
|
||||
}
|
||||
|
||||
private ShopDO shop(String businessHours) {
|
||||
ShopDO shop = new ShopDO();
|
||||
shop.setId(9L);
|
||||
shop.setBusinessHours(businessHours);
|
||||
shop.setIsDelete(0);
|
||||
return shop;
|
||||
}
|
||||
|
||||
private CartDO cartItem(Long productId, Integer quantity) {
|
||||
CartDO item = new CartDO();
|
||||
item.setUserId(20L);
|
||||
@@ -130,6 +218,14 @@ class OrderServiceImplCheckoutPreviewTest {
|
||||
return user;
|
||||
}
|
||||
|
||||
private UserDO artist(Long id) {
|
||||
UserDO artist = new UserDO();
|
||||
artist.setId(id);
|
||||
artist.setStatus(1);
|
||||
artist.setIsDelete(0);
|
||||
return artist;
|
||||
}
|
||||
|
||||
private CouponDO coupon(Long id, String name, Integer type, BigDecimal discountValue, BigDecimal minAmount, BigDecimal reduceAmount, Long shopId) {
|
||||
CouponDO coupon = new CouponDO();
|
||||
coupon.setId(id);
|
||||
|
||||
+11
@@ -14,7 +14,9 @@ import com.xiaowang.yuminailcore.mapper.TagMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.UserCouponMapper;
|
||||
import com.xiaowang.yuminailcore.service.CouponService;
|
||||
import com.xiaowang.yuminailcore.service.MapService;
|
||||
import com.xiaowang.yuminailcore.service.NailArtistInfoService;
|
||||
import com.xiaowang.yuminailcore.service.ObjectStorageFileService;
|
||||
import com.xiaowang.yuminailcore.support.ObjectStorageUrlSupport;
|
||||
import com.xiaowang.yuminailcore.support.UserShopBindingSupport;
|
||||
import com.xiaowang.yuminailcore.support.cache.MultiLevelCacheService;
|
||||
import com.xiaowang.yuminailcore.vo.ObjectStorageFileVO;
|
||||
@@ -32,6 +34,7 @@ import java.util.Map;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
@@ -57,8 +60,12 @@ class ShopServiceImplTest {
|
||||
@Mock
|
||||
private ObjectStorageFileService objectStorageFileService;
|
||||
@Mock
|
||||
private ObjectStorageUrlSupport objectStorageUrlSupport;
|
||||
@Mock
|
||||
private UserShopBindingSupport userShopBindingSupport;
|
||||
@Mock
|
||||
private NailArtistInfoService nailArtistInfoService;
|
||||
@Mock
|
||||
private MultiLevelCacheService multiLevelCacheService;
|
||||
@Mock
|
||||
private AppCacheProperties appCacheProperties;
|
||||
@@ -80,11 +87,15 @@ class ShopServiceImplTest {
|
||||
userCouponMapper,
|
||||
orderArtistReviewMapper,
|
||||
objectStorageFileService,
|
||||
objectStorageUrlSupport,
|
||||
userShopBindingSupport,
|
||||
nailArtistInfoService,
|
||||
multiLevelCacheService,
|
||||
appCacheProperties,
|
||||
mapService
|
||||
);
|
||||
when(objectStorageUrlSupport.toAccessibleUrl(anyString()))
|
||||
.thenAnswer(invocation -> invocation.getArgument(0, String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+7
@@ -7,6 +7,13 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
class OrderStateMachineTest {
|
||||
|
||||
@Test
|
||||
void allowsPriceConfirmingOrderToBecomePendingServiceOrCancelled() {
|
||||
assertThat(OrderStateMachine.isAllowedTransition(0, 1)).isTrue();
|
||||
assertThat(OrderStateMachine.isAllowedTransition(0, 3)).isTrue();
|
||||
assertThat(OrderStateMachine.isAllowedTransition(0, 2)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void allowsPendingOrderToCompleteOrCancel() {
|
||||
assertThat(OrderStateMachine.isAllowedTransition(1, 2)).isTrue();
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package com.xiaowang.yuminailcore.support;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.LocalTime;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class PlanningCalendarSupportTest {
|
||||
|
||||
@Test
|
||||
void shortNameUsesReadableSingleCharacterForDenseMonthCells() {
|
||||
assertEquals("王", PlanningCalendarSupport.shortName("小王"));
|
||||
assertEquals("李", PlanningCalendarSupport.shortName("李老师"));
|
||||
assertEquals("A", PlanningCalendarSupport.shortName("Alice"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void businessHoursFallbackToShopManagerPlanningDefaults() {
|
||||
PlanningCalendarSupport.BusinessHours hours = PlanningCalendarSupport.parseBusinessHours("10:00-22:00");
|
||||
assertEquals(LocalTime.of(10, 0), hours.start());
|
||||
assertEquals(LocalTime.of(22, 0), hours.end());
|
||||
|
||||
PlanningCalendarSupport.BusinessHours fallback = PlanningCalendarSupport.parseBusinessHours(null);
|
||||
assertEquals(LocalTime.of(10, 0), fallback.start());
|
||||
assertEquals(LocalTime.of(22, 0), fallback.end());
|
||||
}
|
||||
|
||||
@Test
|
||||
void durationParserSupportsChineseHourAndMinuteText() {
|
||||
assertEquals(90, PlanningCalendarSupport.parseDurationMinutes("1.5小时", 60));
|
||||
assertEquals(120, PlanningCalendarSupport.parseDurationMinutes("约120分钟", 60));
|
||||
assertEquals(60, PlanningCalendarSupport.parseDurationMinutes("", 60));
|
||||
}
|
||||
|
||||
@Test
|
||||
void dayStatusKeepsMonthViewOperationalAtAGlance() {
|
||||
assertEquals("rest", PlanningCalendarSupport.resolveDayStatus(0, false, false));
|
||||
assertEquals("free", PlanningCalendarSupport.resolveDayStatus(0, true, false));
|
||||
assertEquals("working", PlanningCalendarSupport.resolveDayStatus(2, true, false));
|
||||
assertEquals("full", PlanningCalendarSupport.resolveDayStatus(6, true, true));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user