Merge pull request 'Dev' (#99) from dev into sit
自动发布测试环境 Nacos 配置 / publish (push) Successful in 30s
自动发布测试环境 Nacos 配置 / publish (push) Successful in 30s
Reviewed-on: http://wcsrv.top:3000/xiaowang/JayuCloud/pulls/99
This commit was merged in pull request #99.
This commit is contained in:
@@ -110,6 +110,15 @@
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<!-- Spring Boot manages the Flyway version; migrations run against the Nacos-configured datasource. -->
|
||||
<dependency>
|
||||
<groupId>org.flywaydb</groupId>
|
||||
<artifactId>flyway-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.flywaydb</groupId>
|
||||
<artifactId>flyway-mysql</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
|
||||
-1
@@ -25,7 +25,6 @@ import org.springframework.context.annotation.Configuration;
|
||||
"com.xiaowang.jayucloud.artlist.core.modules.content.mapper",
|
||||
"com.xiaowang.jayucloud.artlist.core.modules.file.mapper",
|
||||
"com.xiaowang.jayucloud.artlist.core.modules.integration.mapper",
|
||||
"com.xiaowang.jayucloud.artlist.core.modules.inventory.mapper",
|
||||
"com.xiaowang.jayucloud.artlist.core.modules.marketing.mapper",
|
||||
"com.xiaowang.jayucloud.artlist.core.modules.message.mapper",
|
||||
"com.xiaowang.jayucloud.artlist.core.modules.order.mapper",
|
||||
|
||||
-450
@@ -1,450 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.analytics.controller.front;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.xiaowang.jayucloud.artlist.core.annotation.RequirePermission;
|
||||
import com.xiaowang.jayucloud.artlist.core.common.Result;
|
||||
import com.xiaowang.jayucloud.artlist.core.config.AppCacheProperties;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.content.entity.CommentDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.entity.OrderDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.entity.OrderItemDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.product.entity.ProductDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.user.entity.UserDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.content.mapper.CommentMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.mapper.OrderItemMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.mapper.OrderMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.product.mapper.ProductMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.shop.mapper.ShopMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.user.mapper.UserMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.analytics.service.OperationsAnalyticsService;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.security.support.AdminScopeHelper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.support.OrderStatus;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.shop.support.UserShopBindingSupport;
|
||||
import com.xiaowang.jayucloud.artlist.core.support.cache.MultiLevelCacheService;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.analytics.vo.DashboardStatsVO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.product.vo.HotProductVO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.analytics.vo.OperationsAnalyticsVO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.analytics.vo.RecentActivityVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/dashboard")
|
||||
@RequiredArgsConstructor
|
||||
/**
|
||||
* DashboardController exposes HTTP endpoints. Start here to learn the request path, parameter names, and which service method is called.
|
||||
* Beginner guide: follow the call chain Controller -> Service -> ServiceImpl -> Mapper/support class.
|
||||
*/
|
||||
public class DashboardController {
|
||||
/**
|
||||
* Variable `userMapper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
*/
|
||||
private final UserMapper userMapper;
|
||||
/**
|
||||
* Variable `productMapper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
*/
|
||||
private final ProductMapper productMapper;
|
||||
/**
|
||||
* Variable `shopMapper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
*/
|
||||
private final ShopMapper shopMapper;
|
||||
/**
|
||||
* Variable `commentMapper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
*/
|
||||
private final CommentMapper commentMapper;
|
||||
/**
|
||||
* Variable `orderMapper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
*/
|
||||
private final OrderMapper orderMapper;
|
||||
/**
|
||||
* Variable `orderItemMapper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
*/
|
||||
private final OrderItemMapper orderItemMapper;
|
||||
/**
|
||||
* Variable `adminScopeHelper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
*/
|
||||
private final AdminScopeHelper adminScopeHelper;
|
||||
/**
|
||||
* Variable `userShopBindingSupport`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
*/
|
||||
private final UserShopBindingSupport userShopBindingSupport;
|
||||
/**
|
||||
* Variable `multiLevelCacheService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
*/
|
||||
private final MultiLevelCacheService multiLevelCacheService;
|
||||
/**
|
||||
* Variable `appCacheProperties`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
*/
|
||||
private final AppCacheProperties appCacheProperties;
|
||||
private final OperationsAnalyticsService operationsAnalyticsService;
|
||||
|
||||
@GetMapping("/stats")
|
||||
@RequirePermission("dashboard:view")
|
||||
/**
|
||||
* Load data by the supplied parameter.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
* @param request parameter `request` supplied by the caller
|
||||
* @return Result<DashboardStatsVO> result consumed by the caller or returned to the frontend
|
||||
*/
|
||||
public Result<DashboardStatsVO> getDashboardStats(HttpServletRequest request) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
Long shopIdScope = resolveShopScope(currentUser);
|
||||
String cacheScope = currentUser == null ? "anonymous" : (shopIdScope == null ? "admin" : "shop:" + shopIdScope);
|
||||
AppCacheProperties.CacheSpec cacheSpec = appCacheProperties.getDashboard();
|
||||
DashboardStatsVO stats = multiLevelCacheService.getOrLoad(
|
||||
"cache:dashboard:stats:" + cacheScope,
|
||||
Duration.ofSeconds(cacheSpec.getLocalTtlSeconds()),
|
||||
Duration.ofSeconds(cacheSpec.getRedisTtlSeconds()),
|
||||
new TypeReference<DashboardStatsVO>() {
|
||||
},
|
||||
() -> buildDashboardStats(currentUser, shopIdScope)
|
||||
);
|
||||
return Result.success(stats);
|
||||
}
|
||||
|
||||
@GetMapping("/analytics")
|
||||
@RequirePermission("analytics:view")
|
||||
public Result<OperationsAnalyticsVO> getAnalytics(HttpServletRequest request) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
Long shopIdScope = resolveShopScope(currentUser);
|
||||
Long artistScope = currentUser != null && Integer.valueOf(3).equals(currentUser.getType()) ? currentUser.getId() : null;
|
||||
return Result.success(operationsAnalyticsService.getDashboardAnalytics(shopIdScope, artistScope));
|
||||
}
|
||||
|
||||
/**
|
||||
* Run business method `buildDashboardStats`.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
* @param currentUser parameter `currentUser` supplied by the caller
|
||||
* @param shopIdScope parameter `shopIdScope` supplied by the caller
|
||||
* @return private DashboardStatsVO result consumed by the caller or returned to the frontend
|
||||
*/
|
||||
private DashboardStatsVO buildDashboardStats(UserDO currentUser, Long shopIdScope) {
|
||||
DashboardStatsVO stats = new DashboardStatsVO();
|
||||
Long artistScope = currentUser != null && Integer.valueOf(3).equals(currentUser.getType()) ? currentUser.getId() : null;
|
||||
|
||||
if (currentUser != null) {
|
||||
// 根据用户类型显示不同的数据
|
||||
if (currentUser.getType() == 4) { // 管理员
|
||||
stats.setTotalUsers(userMapper.selectCount(null));
|
||||
stats.setTotalProducts(productMapper.selectCount(null));
|
||||
stats.setTotalShops(shopMapper.selectCount(null));
|
||||
stats.setTodayOrders(getTodayOrders(null));
|
||||
stats.setTotalCustomers(countUsers(null, 0, null, null));
|
||||
stats.setTotalArtists(countUsers(null, 3, null, null));
|
||||
} else { // 店长或美甲师
|
||||
Long shopId = currentUser.getShopId();
|
||||
if (shopId != null) {
|
||||
shopIdScope = shopId;
|
||||
// 只显示当前店铺的数据
|
||||
stats.setTotalUsers(userShopBindingSupport.countUsersByShopId(shopId, false));
|
||||
stats.setTotalProducts(productMapper.selectCount(new LambdaQueryWrapper<ProductDO>().eq(ProductDO::getShopId, shopId)));
|
||||
stats.setTotalShops(0L); // 非管理员不显示店铺数量
|
||||
stats.setTodayOrders(getTodayOrders(shopId));
|
||||
stats.setTotalCustomers(countUsers(shopId, 0, null, null));
|
||||
stats.setTotalArtists(countUsers(shopId, 3, null, null));
|
||||
} else {
|
||||
// 没有店铺ID的情况
|
||||
stats.setTotalUsers(0L);
|
||||
stats.setTotalProducts(0L);
|
||||
stats.setTotalShops(0L);
|
||||
stats.setTodayOrders(0L);
|
||||
stats.setTotalCustomers(0L);
|
||||
stats.setTotalArtists(0L);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 无法获取用户信息的情况
|
||||
stats.setTotalUsers(0L);
|
||||
stats.setTotalProducts(0L);
|
||||
stats.setTotalShops(0L);
|
||||
stats.setTodayOrders(0L);
|
||||
stats.setTotalCustomers(0L);
|
||||
stats.setTotalArtists(0L);
|
||||
}
|
||||
|
||||
LocalDateTime todayStart = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0).withNano(0);
|
||||
LocalDateTime weekStart = todayStart.minusDays(6);
|
||||
stats.setTotalOrderAmount(sumOrderAmount(shopIdScope, artistScope, null, null));
|
||||
stats.setTodayOrderAmount(sumOrderAmount(shopIdScope, artistScope, todayStart, null));
|
||||
stats.setWeekOrderAmount(sumOrderAmount(shopIdScope, artistScope, weekStart, null));
|
||||
stats.setNewCustomersToday(countUsers(shopIdScope, 0, todayStart, null));
|
||||
stats.setNewCustomers7Days(countUsers(shopIdScope, 0, weekStart, null));
|
||||
stats.setNewOrders7Days(countOrders(shopIdScope, artistScope, null, weekStart, 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));
|
||||
|
||||
return stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run business method `resolveShopScope`.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
* @param currentUser parameter `currentUser` supplied by the caller
|
||||
* @return private Long result consumed by the caller or returned to the frontend
|
||||
*/
|
||||
private Long resolveShopScope(UserDO currentUser) {
|
||||
if (currentUser == null || currentUser.getType() == 4) {
|
||||
return null;
|
||||
}
|
||||
return currentUser.getShopId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: countUsers supports DashboardController.java by holding or executing the count users business role.
|
||||
* Usage: reference this method from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
private Long countUsers(Long shopId, Integer type, LocalDateTime from, LocalDateTime to) {
|
||||
LambdaQueryWrapper<UserDO> wrapper = new LambdaQueryWrapper<>();
|
||||
if (type != null) {
|
||||
wrapper.eq(UserDO::getType, type);
|
||||
}
|
||||
if (from != null) {
|
||||
wrapper.ge(UserDO::getCreateTime, from);
|
||||
}
|
||||
if (to != null) {
|
||||
wrapper.le(UserDO::getCreateTime, to);
|
||||
}
|
||||
if (shopId != null) {
|
||||
List<Long> userIds = userShopBindingSupport.listUserIdsByShopId(shopId, false);
|
||||
if (userIds.isEmpty()) {
|
||||
return 0L;
|
||||
}
|
||||
wrapper.in(UserDO::getId, userIds);
|
||||
}
|
||||
return userMapper.selectCount(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: countOrders supports DashboardController.java by holding or executing the count orders business role.
|
||||
* Usage: reference this method from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
private Long countOrders(Long shopId, Long artistId, Integer status, LocalDateTime from, LocalDateTime to) {
|
||||
return (long) listScopedOrders(shopId, artistId, status, from, to).size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: sumOrderAmount supports DashboardController.java by holding or executing the sum order amount business role.
|
||||
* Usage: reference this method from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
private BigDecimal sumOrderAmount(Long shopId, Long artistId, LocalDateTime from, LocalDateTime to) {
|
||||
return listScopedOrders(shopId, artistId, null, from, to).stream()
|
||||
.map(order -> order.getActualAmount() != null ? order.getActualAmount() : order.getTotalAmount())
|
||||
.filter(amount -> amount != null)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: listScopedOrders supports DashboardController.java by holding or executing the list scoped orders business role.
|
||||
* Usage: reference this method from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
private List<OrderDO> listScopedOrders(Long shopId, Long artistId, Integer status, LocalDateTime from, LocalDateTime to) {
|
||||
LambdaQueryWrapper<OrderDO> wrapper = new LambdaQueryWrapper<>();
|
||||
if (shopId != null) {
|
||||
wrapper.eq(OrderDO::getShopId, shopId);
|
||||
}
|
||||
if (status != null) {
|
||||
wrapper.eq(OrderDO::getStatus, status);
|
||||
}
|
||||
if (from != null) {
|
||||
wrapper.ge(OrderDO::getCreateTime, from);
|
||||
}
|
||||
if (to != null) {
|
||||
wrapper.le(OrderDO::getCreateTime, to);
|
||||
}
|
||||
if (artistId != null) {
|
||||
Set<Long> orderIds = listOrderIdsByArtist(artistId);
|
||||
if (orderIds.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
wrapper.in(OrderDO::getId, orderIds);
|
||||
}
|
||||
return orderMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: listOrderIdsByArtist supports DashboardController.java by holding or executing the list order ids by artist business role.
|
||||
* Usage: reference this method from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
private Set<Long> listOrderIdsByArtist(Long artistId) {
|
||||
List<OrderItemDO> items = orderItemMapper.selectList(new LambdaQueryWrapper<OrderItemDO>()
|
||||
.select(OrderItemDO::getOrderId)
|
||||
.eq(OrderItemDO::getArtistId, artistId));
|
||||
return items.stream()
|
||||
.map(OrderItemDO::getOrderId)
|
||||
.filter(id -> id != null)
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
}
|
||||
|
||||
/**
|
||||
* Load data by the supplied parameter.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
* @param shopId parameter `shopId` supplied by the caller
|
||||
* @return private Long result consumed by the caller or returned to the frontend
|
||||
*/
|
||||
private Long getTodayOrders(Long shopId) {
|
||||
// 获取今天的开始时间
|
||||
LocalDateTime todayStart = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0).withNano(0);
|
||||
String todayStartStr = todayStart.format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
|
||||
if (shopId != null) {
|
||||
// 非管理员只查询自己店铺的订单,通过订单商品关联到商品,再关联到店铺
|
||||
java.util.Map<String, Object> result = orderItemMapper.countTodayOrdersByShopId(shopId, todayStartStr);
|
||||
return result != null && result.get("count") != null ? Long.valueOf(result.get("count").toString()) : 0L;
|
||||
} else {
|
||||
// 管理员查询所有订单
|
||||
java.util.Map<String, Object> result = orderItemMapper.countTodayOrders(todayStartStr);
|
||||
return result != null && result.get("count") != null ? Long.valueOf(result.get("count").toString()) : 0L;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load data by the supplied parameter.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
* @param shopId parameter `shopId` supplied by the caller
|
||||
* @return private List<HotProductVO> result consumed by the caller or returned to the frontend
|
||||
*/
|
||||
private List<HotProductVO> getHotProducts(Long shopId) {
|
||||
// 通过订单商品表统计每个商品的订单数量,按订单数量排序
|
||||
// 使用SQL查询获取商品及其订单数量
|
||||
List<Map<String, Object>> productOrderCounts = orderItemMapper.selectMaps(
|
||||
new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<OrderItemDO>()
|
||||
.select("product_id, COUNT(*) as order_count")
|
||||
.groupBy("product_id")
|
||||
.orderByDesc("order_count")
|
||||
.last("LIMIT 5")
|
||||
);
|
||||
|
||||
List<HotProductVO> hotProducts = new ArrayList<>();
|
||||
|
||||
// 遍历查询结果,获取商品详情
|
||||
for (Map<String, Object> map : productOrderCounts) {
|
||||
Long productId = Long.valueOf(map.get("product_id").toString());
|
||||
ProductDO product = productMapper.selectById(productId);
|
||||
|
||||
if (product != null && (shopId == null || shopId.equals(product.getShopId()))) {
|
||||
HotProductVO vo = new HotProductVO();
|
||||
BeanUtils.copyProperties(product, vo);
|
||||
vo.setLikeCount(product.getLikeCount() != null ? product.getLikeCount() : 0);
|
||||
hotProducts.add(vo);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果按订单数量查询没有结果,使用点赞数作为备选
|
||||
if (hotProducts.isEmpty()) {
|
||||
LambdaQueryWrapper<ProductDO> wrapper = new LambdaQueryWrapper<>();
|
||||
if (shopId != null) {
|
||||
wrapper.eq(ProductDO::getShopId, shopId);
|
||||
}
|
||||
wrapper.orderByDesc(ProductDO::getLikeCount)
|
||||
.last("LIMIT 5");
|
||||
List<ProductDO> products = productMapper.selectList(wrapper);
|
||||
|
||||
hotProducts = products.stream().map(product -> {
|
||||
HotProductVO vo = new HotProductVO();
|
||||
BeanUtils.copyProperties(product, vo);
|
||||
vo.setLikeCount(product.getLikeCount() != null ? product.getLikeCount() : 0);
|
||||
return vo;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return hotProducts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load data by the supplied parameter.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
* @param shopId parameter `shopId` supplied by the caller
|
||||
* @return private List<RecentActivityVO> result consumed by the caller or returned to the frontend
|
||||
*/
|
||||
private List<RecentActivityVO> getRecentActivities(Long shopId) {
|
||||
List<RecentActivityVO> activities = new ArrayList<>();
|
||||
|
||||
LambdaQueryWrapper<UserDO> userWrapper = new LambdaQueryWrapper<>();
|
||||
if (shopId != null) {
|
||||
List<Long> userIds = userShopBindingSupport.listUserIdsByShopId(shopId, false);
|
||||
if (userIds.isEmpty()) {
|
||||
userWrapper.eq(UserDO::getId, -1L);
|
||||
} else {
|
||||
userWrapper.in(UserDO::getId, userIds);
|
||||
}
|
||||
}
|
||||
userWrapper.orderByDesc(UserDO::getCreateTime)
|
||||
.last("LIMIT 3");
|
||||
List<UserDO> recentUsers = userMapper.selectList(userWrapper);
|
||||
|
||||
for (UserDO user : recentUsers) {
|
||||
RecentActivityVO vo = new RecentActivityVO();
|
||||
vo.setId(user.getId());
|
||||
vo.setType("user");
|
||||
vo.setTitle("新用户注册");
|
||||
vo.setDescription("用户\"" + user.getNickname() + "\"注册成功");
|
||||
vo.setTime(user.getCreateTime());
|
||||
vo.setColor("");
|
||||
activities.add(vo);
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<ProductDO> productWrapper = new LambdaQueryWrapper<>();
|
||||
if (shopId != null) {
|
||||
productWrapper.eq(ProductDO::getShopId, shopId);
|
||||
}
|
||||
productWrapper.orderByDesc(ProductDO::getCreateTime)
|
||||
.last("LIMIT 2");
|
||||
List<ProductDO> recentProducts = productMapper.selectList(productWrapper);
|
||||
|
||||
for (ProductDO product : recentProducts) {
|
||||
RecentActivityVO vo = new RecentActivityVO();
|
||||
vo.setId(product.getId());
|
||||
vo.setType("product");
|
||||
vo.setTitle("新品上架");
|
||||
vo.setDescription("新品\"" + product.getTitle() + "\"已上架");
|
||||
vo.setTime(product.getCreateTime());
|
||||
vo.setColor("blue");
|
||||
activities.add(vo);
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<CommentDO> commentWrapper = new LambdaQueryWrapper<>();
|
||||
if (shopId != null) {
|
||||
commentWrapper.eq(CommentDO::getShopId, shopId);
|
||||
}
|
||||
commentWrapper.orderByDesc(CommentDO::getCreateTime)
|
||||
.last("LIMIT 2");
|
||||
List<CommentDO> recentComments = commentMapper.selectList(commentWrapper);
|
||||
|
||||
for (CommentDO comment : recentComments) {
|
||||
RecentActivityVO vo = new RecentActivityVO();
|
||||
vo.setId(comment.getId());
|
||||
vo.setType("comment");
|
||||
vo.setTitle("用户评论");
|
||||
String content = comment.getCommentContent();
|
||||
if (content != null && content.length() > 20) {
|
||||
content = content.substring(0, 20) + "...";
|
||||
}
|
||||
vo.setDescription(content != null ? content : "用户发表了评论");
|
||||
vo.setTime(comment.getCreateTime());
|
||||
vo.setColor("green");
|
||||
activities.add(vo);
|
||||
}
|
||||
|
||||
activities.sort((a, b) -> b.getTime().compareTo(a.getTime()));
|
||||
|
||||
return activities.stream().limit(5).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.analytics.service;
|
||||
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.analytics.vo.OperationsAnalyticsVO;
|
||||
|
||||
public interface OperationsAnalyticsService {
|
||||
OperationsAnalyticsVO getDashboardAnalytics(Long shopId, Long artistId);
|
||||
}
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.analytics.service;
|
||||
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.analytics.vo.StoreWorkbenchVO;
|
||||
|
||||
public interface WorkbenchService {
|
||||
StoreWorkbenchVO getWorkbench(Long shopId, Long artistId);
|
||||
}
|
||||
-66
@@ -1,66 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.analytics.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.entity.OrderDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.entity.OrderItemDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.product.entity.ProductDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.user.entity.UserGrowthRecordDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.mapper.OrderItemMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.mapper.OrderMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.product.mapper.ProductMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.user.mapper.UserGrowthRecordMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.analytics.service.OperationsAnalyticsService;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.analytics.vo.OperationsAnalyticsVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class OperationsAnalyticsServiceImpl implements OperationsAnalyticsService {
|
||||
|
||||
private final OrderMapper orderMapper;
|
||||
private final OrderItemMapper orderItemMapper;
|
||||
private final ProductMapper productMapper;
|
||||
private final UserGrowthRecordMapper userGrowthRecordMapper;
|
||||
|
||||
@Override
|
||||
public OperationsAnalyticsVO getDashboardAnalytics(Long shopId, Long artistId) {
|
||||
List<OrderDO> orders = orderMapper.selectList(new LambdaQueryWrapper<OrderDO>()
|
||||
.eq(shopId != null, OrderDO::getShopId, shopId)
|
||||
.eq(OrderDO::getIsDelete, 0));
|
||||
if (artistId != null) {
|
||||
Set<Long> orderIds = new HashSet<>();
|
||||
orderItemMapper.selectList(new LambdaQueryWrapper<OrderItemDO>()
|
||||
.eq(OrderItemDO::getArtistId, artistId)
|
||||
.eq(OrderItemDO::getIsDelete, 0))
|
||||
.forEach(item -> orderIds.add(item.getOrderId()));
|
||||
orders = orders.stream().filter(order -> orderIds.contains(order.getId())).toList();
|
||||
}
|
||||
OperationsAnalyticsVO vo = new OperationsAnalyticsVO();
|
||||
vo.setViewCount(productMapper.selectList(new LambdaQueryWrapper<ProductDO>()
|
||||
.eq(shopId != null, ProductDO::getShopId, shopId)
|
||||
.eq(ProductDO::getIsDelete, 0))
|
||||
.stream().map(ProductDO::getLikeCount).filter(v -> v != null).mapToLong(Integer::longValue).sum());
|
||||
vo.setFavoriteCount(productMapper.selectList(new LambdaQueryWrapper<ProductDO>()
|
||||
.eq(shopId != null, ProductDO::getShopId, shopId)
|
||||
.eq(ProductDO::getIsDelete, 0))
|
||||
.stream().map(ProductDO::getCollectCount).filter(v -> v != null).mapToLong(Integer::longValue).sum());
|
||||
vo.setCartCount(0L);
|
||||
vo.setOrderCount((long) orders.size());
|
||||
vo.setPaidOrderCount(orders.stream().filter(order -> "PAID".equals(order.getPaymentStatus())).count());
|
||||
vo.setCompletedOrderCount(orders.stream().filter(order -> Integer.valueOf(2).equals(order.getStatus())).count());
|
||||
vo.setReviewCount(userGrowthRecordMapper.selectCount(new LambdaQueryWrapper<UserGrowthRecordDO>()
|
||||
.eq(UserGrowthRecordDO::getSourceType, "REVIEW")));
|
||||
vo.setRebookCount(userGrowthRecordMapper.selectCount(new LambdaQueryWrapper<UserGrowthRecordDO>()
|
||||
.eq(UserGrowthRecordDO::getSourceType, "REBOOK")));
|
||||
vo.setTotalAmount(orders.stream()
|
||||
.map(order -> order.getActualAmount() == null ? BigDecimal.ZERO : order.getActualAmount())
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add));
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
-145
@@ -1,145 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.analytics.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.entity.AfterSaleDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.entity.ArtistScheduleDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.inventory.entity.InventoryItemDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.entity.OrderArtistChangeRequestDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.entity.OrderDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.entity.OrderItemDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.mapper.AfterSaleMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.mapper.ArtistScheduleMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.inventory.mapper.InventoryItemMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.mapper.OrderArtistChangeRequestMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.mapper.OrderArtistReviewMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.mapper.OrderItemMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.mapper.OrderMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.analytics.service.WorkbenchService;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.support.OrderStatus;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.analytics.vo.StoreWorkbenchVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class WorkbenchServiceImpl implements WorkbenchService {
|
||||
|
||||
private final OrderMapper orderMapper;
|
||||
private final OrderItemMapper orderItemMapper;
|
||||
private final AfterSaleMapper afterSaleMapper;
|
||||
private final OrderArtistChangeRequestMapper orderArtistChangeRequestMapper;
|
||||
private final InventoryItemMapper inventoryItemMapper;
|
||||
private final ArtistScheduleMapper artistScheduleMapper;
|
||||
private final OrderArtistReviewMapper orderArtistReviewMapper;
|
||||
|
||||
@Override
|
||||
public StoreWorkbenchVO getWorkbench(Long shopId, Long artistId) {
|
||||
LocalDateTime todayStart = LocalDate.now().atStartOfDay();
|
||||
LocalDateTime tomorrowStart = todayStart.plusDays(1);
|
||||
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(this::isActionableOrder).count());
|
||||
vo.setPendingAfterSaleCount(countAfterSales(shopId));
|
||||
vo.setPendingArtistChangeCount(countArtistChanges(shopId, artistId));
|
||||
vo.setLowStockItemCount(countLowStock(shopId));
|
||||
vo.setScheduleReminderCount(countMissingSchedules(shopId, artistId, todayStart.toLocalDate()));
|
||||
vo.setTodayServiceCount(countTodayServices(artistId, todayStart, tomorrowStart));
|
||||
vo.setCompletedServiceCount(orders.stream().filter(order -> Integer.valueOf(2).equals(order.getStatus())).count());
|
||||
vo.setServiceAmount(orders.stream()
|
||||
.map(order -> order.getActualAmount() == null ? BigDecimal.ZERO : order.getActualAmount())
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add));
|
||||
vo.setAverageRating(resolveRating(artistId));
|
||||
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)
|
||||
.eq(OrderDO::getIsDelete, 0));
|
||||
if (artistId == null) {
|
||||
return orders;
|
||||
}
|
||||
Set<Long> orderIds = new HashSet<>();
|
||||
orderItemMapper.selectList(new LambdaQueryWrapper<OrderItemDO>()
|
||||
.eq(OrderItemDO::getArtistId, artistId)
|
||||
.eq(OrderItemDO::getIsDelete, 0))
|
||||
.forEach(item -> orderIds.add(item.getOrderId()));
|
||||
return orders.stream().filter(order -> orderIds.contains(order.getId())).toList();
|
||||
}
|
||||
|
||||
private long countAfterSales(Long shopId) {
|
||||
return afterSaleMapper.selectCount(new LambdaQueryWrapper<AfterSaleDO>()
|
||||
.eq(shopId != null, AfterSaleDO::getShopId, shopId)
|
||||
.eq(AfterSaleDO::getStatus, "PENDING")
|
||||
.eq(AfterSaleDO::getIsDelete, 0));
|
||||
}
|
||||
|
||||
private long countArtistChanges(Long shopId, Long artistId) {
|
||||
return orderArtistChangeRequestMapper.selectCount(new LambdaQueryWrapper<OrderArtistChangeRequestDO>()
|
||||
.eq(shopId != null, OrderArtistChangeRequestDO::getShopId, shopId)
|
||||
.eq(artistId != null, OrderArtistChangeRequestDO::getRequesterId, artistId)
|
||||
.eq(OrderArtistChangeRequestDO::getStatus, "PENDING")
|
||||
.eq(OrderArtistChangeRequestDO::getIsDelete, 0));
|
||||
}
|
||||
|
||||
private long countLowStock(Long shopId) {
|
||||
return inventoryItemMapper.selectList(new LambdaQueryWrapper<InventoryItemDO>()
|
||||
.eq(shopId != null, InventoryItemDO::getShopId, shopId)
|
||||
.eq(InventoryItemDO::getIsDelete, 0))
|
||||
.stream()
|
||||
.filter(item -> item.getStockQuantity() != null
|
||||
&& item.getWarningThreshold() != null
|
||||
&& item.getStockQuantity().compareTo(item.getWarningThreshold()) <= 0)
|
||||
.count();
|
||||
}
|
||||
|
||||
private long countMissingSchedules(Long shopId, Long artistId, LocalDate today) {
|
||||
return artistScheduleMapper.selectCount(new LambdaQueryWrapper<ArtistScheduleDO>()
|
||||
.eq(shopId != null, ArtistScheduleDO::getShopId, shopId)
|
||||
.eq(artistId != null, ArtistScheduleDO::getArtistId, artistId)
|
||||
.ge(ArtistScheduleDO::getWorkDate, today)
|
||||
.lt(ArtistScheduleDO::getWorkDate, today.plusDays(3))
|
||||
.eq(ArtistScheduleDO::getIsDelete, 0));
|
||||
}
|
||||
|
||||
private long countTodayServices(Long artistId, LocalDateTime todayStart, LocalDateTime tomorrowStart) {
|
||||
if (artistId == null) {
|
||||
return 0L;
|
||||
}
|
||||
return orderItemMapper.selectList(new LambdaQueryWrapper<OrderItemDO>()
|
||||
.eq(OrderItemDO::getArtistId, artistId)
|
||||
.ge(OrderItemDO::getAppointmentTime, todayStart)
|
||||
.lt(OrderItemDO::getAppointmentTime, tomorrowStart)
|
||||
.eq(OrderItemDO::getIsDelete, 0))
|
||||
.size();
|
||||
}
|
||||
|
||||
private BigDecimal resolveRating(Long artistId) {
|
||||
if (artistId == null) {
|
||||
return BigDecimal.ZERO.setScale(1, RoundingMode.HALF_UP);
|
||||
}
|
||||
BigDecimal rating = orderArtistReviewMapper.selectAverageSubmittedRatingByArtistId(artistId);
|
||||
return (rating == null ? BigDecimal.ZERO : rating).setScale(1, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
private boolean between(LocalDateTime value, LocalDateTime start, LocalDateTime end) {
|
||||
return value != null && !value.isBefore(start) && value.isBefore(end);
|
||||
}
|
||||
}
|
||||
-89
@@ -1,89 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.analytics.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.product.vo.HotProductVO;
|
||||
@Data
|
||||
/**
|
||||
* DashboardStatsVO is a response VO. Services build it and controllers return it to the frontend.
|
||||
* Field and parameter names are kept consistent with the frontend/API payload to make tracing easier.
|
||||
*/
|
||||
public class DashboardStatsVO {
|
||||
/**
|
||||
* Field `totalUsers` (Long): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled.
|
||||
*/
|
||||
private Long totalUsers;
|
||||
/**
|
||||
* Field `totalProducts` (Long): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled.
|
||||
*/
|
||||
private Long totalProducts;
|
||||
/**
|
||||
* Field `totalShops` (Long): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled.
|
||||
*/
|
||||
private Long totalShops;
|
||||
/**
|
||||
* Field `todayOrders` (Long): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled.
|
||||
*/
|
||||
private Long todayOrders;
|
||||
/**
|
||||
* Purpose: totalOrderAmount supports DashboardStatsVO.java by holding or executing the total order amount business role.
|
||||
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
private BigDecimal totalOrderAmount;
|
||||
/**
|
||||
* Purpose: todayOrderAmount supports DashboardStatsVO.java by holding or executing the today order amount business role.
|
||||
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
private BigDecimal todayOrderAmount;
|
||||
/**
|
||||
* Purpose: weekOrderAmount supports DashboardStatsVO.java by holding or executing the week order amount business role.
|
||||
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
private BigDecimal weekOrderAmount;
|
||||
/**
|
||||
* Purpose: totalCustomers supports DashboardStatsVO.java by holding or executing the total customers business role.
|
||||
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
private Long totalCustomers;
|
||||
/**
|
||||
* Purpose: totalArtists supports DashboardStatsVO.java by holding or executing the total artists business role.
|
||||
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
private Long totalArtists;
|
||||
/**
|
||||
* Purpose: newCustomersToday supports DashboardStatsVO.java by holding or executing the new customers today business role.
|
||||
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
private Long newCustomersToday;
|
||||
/**
|
||||
* Purpose: newCustomers7Days supports DashboardStatsVO.java by holding or executing the new customers7 days business role.
|
||||
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
private Long newCustomers7Days;
|
||||
/**
|
||||
* Purpose: newOrders7Days supports DashboardStatsVO.java by holding or executing the new orders7 days business role.
|
||||
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
private Long newOrders7Days;
|
||||
/**
|
||||
* Purpose: pendingOrders supports DashboardStatsVO.java by holding or executing the pending orders business role.
|
||||
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
private Long pendingOrders;
|
||||
/**
|
||||
* Purpose: completedOrders supports DashboardStatsVO.java by holding or executing the completed orders business role.
|
||||
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
private Long completedOrders;
|
||||
/**
|
||||
* Field `hotProducts` (List<HotProductVO>): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled.
|
||||
*/
|
||||
private List<HotProductVO> hotProducts;
|
||||
/**
|
||||
* Field `recentActivities` (List<RecentActivityVO>): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled.
|
||||
*/
|
||||
private List<RecentActivityVO> recentActivities;
|
||||
}
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.analytics.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class OperationsAnalyticsVO {
|
||||
private Long viewCount;
|
||||
private Long favoriteCount;
|
||||
private Long cartCount;
|
||||
private Long orderCount;
|
||||
private Long paidOrderCount;
|
||||
private Long completedOrderCount;
|
||||
private Long reviewCount;
|
||||
private Long rebookCount;
|
||||
private BigDecimal totalAmount;
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.analytics.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
/**
|
||||
* RecentActivityVO is a response VO. Services build it and controllers return it to the frontend.
|
||||
* Field and parameter names are kept consistent with the frontend/API payload to make tracing easier.
|
||||
*/
|
||||
public class RecentActivityVO {
|
||||
/**
|
||||
* Field `id` (Long): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled.
|
||||
*/
|
||||
private Long id;
|
||||
/**
|
||||
* Field `type` (String): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled.
|
||||
*/
|
||||
private String type;
|
||||
/**
|
||||
* Field `title` (String): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled.
|
||||
*/
|
||||
private String title;
|
||||
/**
|
||||
* Field `description` (String): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled.
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* Field `time` (LocalDateTime): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled.
|
||||
*/
|
||||
private LocalDateTime time;
|
||||
/**
|
||||
* Field `color` (String): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled.
|
||||
*/
|
||||
private String color;
|
||||
}
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.analytics.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class StoreWorkbenchVO {
|
||||
private Long todayOrderCount;
|
||||
private Long pendingOrderCount;
|
||||
private Long pendingAfterSaleCount;
|
||||
private Long pendingArtistChangeCount;
|
||||
private Long lowStockItemCount;
|
||||
private Long scheduleReminderCount;
|
||||
private Long todayServiceCount;
|
||||
private Long completedServiceCount;
|
||||
private BigDecimal serviceAmount;
|
||||
private BigDecimal averageRating;
|
||||
}
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.artist.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
|
||||
@Data
|
||||
public class ArtistScheduleDTO {
|
||||
private Long shopId;
|
||||
private Long artistId;
|
||||
private LocalDate workDate;
|
||||
private LocalTime startTime;
|
||||
private LocalTime endTime;
|
||||
private Integer slotMinutes;
|
||||
private Integer capacity;
|
||||
private Integer status;
|
||||
private String remark;
|
||||
}
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.artist.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
|
||||
@Data
|
||||
public class ArtistScheduleExceptionDTO {
|
||||
private Long shopId;
|
||||
private Long artistId;
|
||||
private LocalDate workDate;
|
||||
private String exceptionType;
|
||||
private LocalTime startTime;
|
||||
private LocalTime endTime;
|
||||
private String remark;
|
||||
}
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.artist.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ArtistScheduleRuleDTO {
|
||||
private Long shopId;
|
||||
private Long artistId;
|
||||
private String presetType;
|
||||
private List<Integer> workDays;
|
||||
private LocalTime startTime;
|
||||
private LocalTime endTime;
|
||||
private Integer status;
|
||||
private String remark;
|
||||
}
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.artist.service;
|
||||
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.dto.ArtistScheduleDTO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.dto.ArtistScheduleExceptionDTO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.dto.ArtistScheduleRuleDTO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.vo.ArtistScheduleExceptionVO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.vo.ArtistScheduleRuleSettingVO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.vo.ArtistScheduleRuleVO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.vo.ArtistScheduleVO;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
public interface ArtistScheduleService {
|
||||
ArtistScheduleVO saveSchedule(ArtistScheduleDTO dto);
|
||||
|
||||
List<ArtistScheduleVO> listSchedules(Long shopId, Long artistId, LocalDate startDate, LocalDate endDate);
|
||||
|
||||
ArtistScheduleRuleSettingVO getRuleSetting(Long shopId, Long artistId);
|
||||
|
||||
ArtistScheduleRuleVO saveRule(ArtistScheduleRuleDTO dto);
|
||||
|
||||
ArtistScheduleExceptionVO saveException(ArtistScheduleExceptionDTO dto);
|
||||
}
|
||||
-423
@@ -1,423 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.artist.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.dto.ArtistScheduleDTO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.dto.ArtistScheduleExceptionDTO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.dto.ArtistScheduleRuleDTO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.entity.ArtistScheduleExceptionDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.entity.ArtistScheduleDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.entity.ArtistScheduleRuleDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.mapper.ArtistScheduleExceptionMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.mapper.ArtistScheduleMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.mapper.ArtistScheduleRuleMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.service.ArtistScheduleService;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.vo.ArtistScheduleExceptionVO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.vo.ArtistScheduleRuleSettingVO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.vo.ArtistScheduleRuleVO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.vo.ArtistScheduleVO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.planning.mapper.AppointmentReservationMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ArtistScheduleServiceImpl implements ArtistScheduleService {
|
||||
|
||||
private static final int GENERATED_DAYS = 60;
|
||||
private static final int DEFAULT_SLOT_MINUTES = 60;
|
||||
private static final int DEFAULT_CAPACITY = 1;
|
||||
private static final String PRESET_SINGLE_REST = "SINGLE_REST";
|
||||
private static final String PRESET_DOUBLE_REST = "DOUBLE_REST";
|
||||
private static final String PRESET_NINE_TO_FIVE = "NINE_TO_FIVE";
|
||||
private static final String PRESET_LATE_SHIFT = "LATE_SHIFT";
|
||||
private static final String PRESET_CUSTOM = "CUSTOM";
|
||||
private static final String EXCEPTION_REST = "REST";
|
||||
private static final String EXCEPTION_EXTRA_WORK = "EXTRA_WORK";
|
||||
private static final String EXCEPTION_CHANGE_SHIFT = "CHANGE_SHIFT";
|
||||
|
||||
private final ArtistScheduleMapper artistScheduleMapper;
|
||||
private final ArtistScheduleRuleMapper ruleMapper;
|
||||
private final ArtistScheduleExceptionMapper exceptionMapper;
|
||||
private final AppointmentReservationMapper reservationMapper;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public ArtistScheduleVO saveSchedule(ArtistScheduleDTO dto) {
|
||||
if (dto == null || dto.getShopId() == null || dto.getArtistId() == null || dto.getWorkDate() == null
|
||||
|| dto.getStartTime() == null || dto.getEndTime() == null) {
|
||||
throw new RuntimeException("排班信息不完整");
|
||||
}
|
||||
ArtistScheduleDO schedule = new ArtistScheduleDO();
|
||||
BeanUtils.copyProperties(dto, schedule);
|
||||
schedule.setSlotMinutes(dto.getSlotMinutes() == null ? 60 : dto.getSlotMinutes());
|
||||
schedule.setCapacity(dto.getCapacity() == null || dto.getCapacity() < 1 ? 1 : dto.getCapacity());
|
||||
schedule.setStatus(dto.getStatus() == null ? 1 : dto.getStatus());
|
||||
schedule.setIsDelete(0);
|
||||
ArtistScheduleDO existing = artistScheduleMapper.selectSlotScheduleForUpdate(dto.getShopId(), dto.getArtistId(), dto.getWorkDate(), dto.getStartTime());
|
||||
if (existing == null) {
|
||||
artistScheduleMapper.insert(schedule);
|
||||
} else {
|
||||
schedule.setId(existing.getId());
|
||||
artistScheduleMapper.updateGeneratedSchedule(existing.getId(), schedule.getStartTime(), schedule.getEndTime(),
|
||||
schedule.getSlotMinutes(), schedule.getCapacity(), schedule.getStatus(), schedule.getRemark());
|
||||
}
|
||||
return toVO(schedule);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ArtistScheduleVO> listSchedules(Long shopId, Long artistId, LocalDate startDate, LocalDate endDate) {
|
||||
LambdaQueryWrapper<ArtistScheduleDO> wrapper = new LambdaQueryWrapper<ArtistScheduleDO>()
|
||||
.eq(ArtistScheduleDO::getIsDelete, 0)
|
||||
.orderByAsc(ArtistScheduleDO::getWorkDate)
|
||||
.orderByAsc(ArtistScheduleDO::getStartTime);
|
||||
if (shopId != null) {
|
||||
wrapper.eq(ArtistScheduleDO::getShopId, shopId);
|
||||
}
|
||||
if (artistId != null) {
|
||||
wrapper.eq(ArtistScheduleDO::getArtistId, artistId);
|
||||
}
|
||||
if (startDate != null) {
|
||||
wrapper.ge(ArtistScheduleDO::getWorkDate, startDate);
|
||||
}
|
||||
if (endDate != null) {
|
||||
wrapper.le(ArtistScheduleDO::getWorkDate, endDate);
|
||||
}
|
||||
return artistScheduleMapper.selectList(wrapper).stream().map(this::toVO).toList();
|
||||
}
|
||||
|
||||
private ArtistScheduleVO toVO(ArtistScheduleDO schedule) {
|
||||
ArtistScheduleVO vo = new ArtistScheduleVO();
|
||||
BeanUtils.copyProperties(schedule, vo);
|
||||
return vo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArtistScheduleRuleSettingVO getRuleSetting(Long shopId, Long artistId) {
|
||||
if (shopId == null || artistId == null) {
|
||||
throw new RuntimeException("排班规则查询参数不完整");
|
||||
}
|
||||
ArtistScheduleRuleSettingVO setting = new ArtistScheduleRuleSettingVO();
|
||||
ArtistScheduleRuleDO rule = selectRule(shopId, artistId);
|
||||
setting.setRule(rule == null ? defaultRuleVO(shopId, artistId) : toRuleVO(rule));
|
||||
setting.setExceptions(listExceptions(shopId, artistId, LocalDate.now(), LocalDate.now().plusDays(GENERATED_DAYS - 1L))
|
||||
.stream()
|
||||
.map(this::toExceptionVO)
|
||||
.toList());
|
||||
return setting;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public ArtistScheduleRuleVO saveRule(ArtistScheduleRuleDTO dto) {
|
||||
ArtistScheduleRuleDO normalized = normalizeRule(dto);
|
||||
ArtistScheduleRuleDO existing = selectRule(normalized.getShopId(), normalized.getArtistId());
|
||||
if (existing == null) {
|
||||
ruleMapper.insert(normalized);
|
||||
} else {
|
||||
normalized.setId(existing.getId());
|
||||
ruleMapper.updateById(normalized);
|
||||
}
|
||||
refreshGeneratedSchedules(normalized);
|
||||
return toRuleVO(normalized);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public ArtistScheduleExceptionVO saveException(ArtistScheduleExceptionDTO dto) {
|
||||
ArtistScheduleExceptionDO normalized = normalizeException(dto);
|
||||
ArtistScheduleRuleDO rule = selectRule(normalized.getShopId(), normalized.getArtistId());
|
||||
if (rule == null) {
|
||||
rule = defaultRule(normalized.getShopId(), normalized.getArtistId());
|
||||
}
|
||||
ArtistScheduleExceptionDO existing = selectException(normalized.getShopId(), normalized.getArtistId(), normalized.getWorkDate());
|
||||
if (existing == null) {
|
||||
exceptionMapper.insert(normalized);
|
||||
} else {
|
||||
normalized.setId(existing.getId());
|
||||
exceptionMapper.updateById(normalized);
|
||||
}
|
||||
refreshScheduleForDate(rule, normalized, normalized.getWorkDate());
|
||||
return toExceptionVO(normalized);
|
||||
}
|
||||
|
||||
private ArtistScheduleRuleDO normalizeRule(ArtistScheduleRuleDTO dto) {
|
||||
if (dto == null || dto.getShopId() == null || dto.getArtistId() == null) {
|
||||
throw new RuntimeException("排班规则信息不完整");
|
||||
}
|
||||
String presetType = normalizePresetType(dto.getPresetType());
|
||||
LocalTime startTime = dto.getStartTime() == null ? presetStartTime(presetType) : dto.getStartTime();
|
||||
LocalTime endTime = dto.getEndTime() == null ? presetEndTime(presetType) : dto.getEndTime();
|
||||
validateTimeRange(startTime, endTime);
|
||||
ArtistScheduleRuleDO rule = new ArtistScheduleRuleDO();
|
||||
rule.setShopId(dto.getShopId());
|
||||
rule.setArtistId(dto.getArtistId());
|
||||
rule.setPresetType(presetType);
|
||||
rule.setWorkDays(encodeWorkDays(resolveWorkDays(dto.getWorkDays(), presetType)));
|
||||
rule.setStartTime(startTime);
|
||||
rule.setEndTime(endTime);
|
||||
rule.setSlotMinutes(DEFAULT_SLOT_MINUTES);
|
||||
rule.setCapacity(DEFAULT_CAPACITY);
|
||||
rule.setStatus(dto.getStatus() == null ? 1 : dto.getStatus());
|
||||
rule.setRemark(trimText(dto.getRemark()));
|
||||
rule.setIsDelete(0);
|
||||
return rule;
|
||||
}
|
||||
|
||||
private ArtistScheduleExceptionDO normalizeException(ArtistScheduleExceptionDTO dto) {
|
||||
if (dto == null || dto.getShopId() == null || dto.getArtistId() == null || dto.getWorkDate() == null) {
|
||||
throw new RuntimeException("排班例外信息不完整");
|
||||
}
|
||||
String exceptionType = normalizeExceptionType(dto.getExceptionType());
|
||||
LocalTime startTime = dto.getStartTime();
|
||||
LocalTime endTime = dto.getEndTime();
|
||||
if (!EXCEPTION_REST.equals(exceptionType)) {
|
||||
if (startTime == null || endTime == null) {
|
||||
throw new RuntimeException("临时上班或改班必须填写开始和结束时间");
|
||||
}
|
||||
validateTimeRange(startTime, endTime);
|
||||
}
|
||||
ArtistScheduleExceptionDO exception = new ArtistScheduleExceptionDO();
|
||||
exception.setShopId(dto.getShopId());
|
||||
exception.setArtistId(dto.getArtistId());
|
||||
exception.setWorkDate(dto.getWorkDate());
|
||||
exception.setExceptionType(exceptionType);
|
||||
exception.setStartTime(startTime);
|
||||
exception.setEndTime(endTime);
|
||||
exception.setSlotMinutes(DEFAULT_SLOT_MINUTES);
|
||||
exception.setCapacity(DEFAULT_CAPACITY);
|
||||
exception.setRemark(trimText(dto.getRemark()));
|
||||
exception.setIsDelete(0);
|
||||
return exception;
|
||||
}
|
||||
|
||||
private ArtistScheduleRuleDO selectRule(Long shopId, Long artistId) {
|
||||
return ruleMapper.selectOne(new LambdaQueryWrapper<ArtistScheduleRuleDO>()
|
||||
.eq(ArtistScheduleRuleDO::getShopId, shopId)
|
||||
.eq(ArtistScheduleRuleDO::getArtistId, artistId)
|
||||
.eq(ArtistScheduleRuleDO::getIsDelete, 0)
|
||||
.last("LIMIT 1"));
|
||||
}
|
||||
|
||||
private ArtistScheduleExceptionDO selectException(Long shopId, Long artistId, LocalDate workDate) {
|
||||
return exceptionMapper.selectOne(new LambdaQueryWrapper<ArtistScheduleExceptionDO>()
|
||||
.eq(ArtistScheduleExceptionDO::getShopId, shopId)
|
||||
.eq(ArtistScheduleExceptionDO::getArtistId, artistId)
|
||||
.eq(ArtistScheduleExceptionDO::getWorkDate, workDate)
|
||||
.eq(ArtistScheduleExceptionDO::getIsDelete, 0)
|
||||
.last("LIMIT 1"));
|
||||
}
|
||||
|
||||
private List<ArtistScheduleExceptionDO> listExceptions(Long shopId, Long artistId, LocalDate start, LocalDate end) {
|
||||
return exceptionMapper.selectList(new LambdaQueryWrapper<ArtistScheduleExceptionDO>()
|
||||
.eq(ArtistScheduleExceptionDO::getShopId, shopId)
|
||||
.eq(ArtistScheduleExceptionDO::getArtistId, artistId)
|
||||
.eq(ArtistScheduleExceptionDO::getIsDelete, 0)
|
||||
.between(ArtistScheduleExceptionDO::getWorkDate, start, end)
|
||||
.orderByAsc(ArtistScheduleExceptionDO::getWorkDate));
|
||||
}
|
||||
|
||||
private void refreshGeneratedSchedules(ArtistScheduleRuleDO rule) {
|
||||
LocalDate start = LocalDate.now();
|
||||
LocalDate end = start.plusDays(GENERATED_DAYS - 1L);
|
||||
Map<LocalDate, ArtistScheduleExceptionDO> exceptionByDate = listExceptions(rule.getShopId(), rule.getArtistId(), start, end)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(ArtistScheduleExceptionDO::getWorkDate, Function.identity(), (a, b) -> a));
|
||||
LocalDate cursor = start;
|
||||
while (!cursor.isAfter(end)) {
|
||||
refreshScheduleForDate(rule, exceptionByDate.get(cursor), cursor);
|
||||
cursor = cursor.plusDays(1L);
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshScheduleForDate(ArtistScheduleRuleDO rule, ArtistScheduleExceptionDO exception, LocalDate workDate) {
|
||||
GeneratedSchedule generated = resolveGeneratedSchedule(rule, exception, workDate);
|
||||
if (!generated.working()) {
|
||||
assertNoActiveReservations(rule.getShopId(), rule.getArtistId(), workDate);
|
||||
upsertGeneratedSchedule(rule, workDate, rule.getStartTime(), rule.getEndTime(), rule.getSlotMinutes(), rule.getCapacity(), 0, generated.remark());
|
||||
return;
|
||||
}
|
||||
assertNoReservationsOutsideSchedule(rule.getShopId(), rule.getArtistId(), workDate, generated.startTime(), generated.endTime());
|
||||
upsertGeneratedSchedule(rule, workDate, generated.startTime(), generated.endTime(), generated.slotMinutes(), generated.capacity(), 1, generated.remark());
|
||||
}
|
||||
|
||||
private GeneratedSchedule resolveGeneratedSchedule(ArtistScheduleRuleDO rule, ArtistScheduleExceptionDO exception, LocalDate workDate) {
|
||||
if (exception != null) {
|
||||
if (EXCEPTION_REST.equals(exception.getExceptionType())) {
|
||||
return new GeneratedSchedule(false, rule.getStartTime(), rule.getEndTime(), rule.getSlotMinutes(), rule.getCapacity(), exceptionRemark(exception));
|
||||
}
|
||||
if (EXCEPTION_EXTRA_WORK.equals(exception.getExceptionType()) || EXCEPTION_CHANGE_SHIFT.equals(exception.getExceptionType())) {
|
||||
return new GeneratedSchedule(true, exception.getStartTime(), exception.getEndTime(), exception.getSlotMinutes(), exception.getCapacity(), exceptionRemark(exception));
|
||||
}
|
||||
}
|
||||
boolean workingDay = Integer.valueOf(1).equals(rule.getStatus()) && decodeWorkDays(rule.getWorkDays()).contains(workDate.getDayOfWeek().getValue());
|
||||
return new GeneratedSchedule(workingDay, rule.getStartTime(), rule.getEndTime(), rule.getSlotMinutes(), rule.getCapacity(), "规则生成排班");
|
||||
}
|
||||
|
||||
private void upsertGeneratedSchedule(ArtistScheduleRuleDO rule, LocalDate workDate, LocalTime startTime, LocalTime endTime,
|
||||
Integer slotMinutes, Integer capacity, Integer status, String remark) {
|
||||
ArtistScheduleDO schedule = artistScheduleMapper.selectDayScheduleForUpdate(rule.getShopId(), rule.getArtistId(), workDate);
|
||||
if (schedule == null) {
|
||||
schedule = new ArtistScheduleDO();
|
||||
schedule.setShopId(rule.getShopId());
|
||||
schedule.setArtistId(rule.getArtistId());
|
||||
schedule.setWorkDate(workDate);
|
||||
schedule.setStartTime(startTime);
|
||||
schedule.setEndTime(endTime);
|
||||
schedule.setSlotMinutes(slotMinutes);
|
||||
schedule.setCapacity(capacity);
|
||||
schedule.setStatus(status);
|
||||
schedule.setRemark(remark);
|
||||
schedule.setIsDelete(0);
|
||||
artistScheduleMapper.insert(schedule);
|
||||
return;
|
||||
}
|
||||
artistScheduleMapper.updateGeneratedSchedule(schedule.getId(), startTime, endTime, slotMinutes, capacity, status, remark);
|
||||
}
|
||||
|
||||
private void assertNoActiveReservations(Long shopId, Long artistId, LocalDate workDate) {
|
||||
int count = reservationMapper.countActiveByArtistAndDateForUpdate(shopId, artistId, workDate);
|
||||
if (count > 0) {
|
||||
throw new RuntimeException("该日期已有预约,不能设置为休假:" + workDate + ",预约数:" + count);
|
||||
}
|
||||
}
|
||||
|
||||
private void assertNoReservationsOutsideSchedule(Long shopId, Long artistId, LocalDate workDate, LocalTime startTime, LocalTime endTime) {
|
||||
int count = reservationMapper.countActiveOutsideScheduleForUpdate(shopId, artistId, workDate, startTime, endTime);
|
||||
if (count > 0) {
|
||||
throw new RuntimeException("该日期已有预约超出新的排班时间:" + workDate + ",冲突预约数:" + count);
|
||||
}
|
||||
}
|
||||
|
||||
private ArtistScheduleRuleVO defaultRuleVO(Long shopId, Long artistId) {
|
||||
return toRuleVO(defaultRule(shopId, artistId));
|
||||
}
|
||||
|
||||
private ArtistScheduleRuleDO defaultRule(Long shopId, Long artistId) {
|
||||
ArtistScheduleRuleDO rule = new ArtistScheduleRuleDO();
|
||||
rule.setShopId(shopId);
|
||||
rule.setArtistId(artistId);
|
||||
rule.setPresetType(PRESET_DOUBLE_REST);
|
||||
rule.setWorkDays(encodeWorkDays(List.of(1, 2, 3, 4, 5)));
|
||||
rule.setStartTime(LocalTime.of(9, 0));
|
||||
rule.setEndTime(LocalTime.of(17, 0));
|
||||
rule.setSlotMinutes(DEFAULT_SLOT_MINUTES);
|
||||
rule.setCapacity(DEFAULT_CAPACITY);
|
||||
rule.setStatus(1);
|
||||
rule.setIsDelete(0);
|
||||
return rule;
|
||||
}
|
||||
|
||||
private ArtistScheduleRuleVO toRuleVO(ArtistScheduleRuleDO rule) {
|
||||
ArtistScheduleRuleVO vo = new ArtistScheduleRuleVO();
|
||||
BeanUtils.copyProperties(rule, vo);
|
||||
vo.setWorkDays(decodeWorkDays(rule.getWorkDays()));
|
||||
return vo;
|
||||
}
|
||||
|
||||
private ArtistScheduleExceptionVO toExceptionVO(ArtistScheduleExceptionDO exception) {
|
||||
ArtistScheduleExceptionVO vo = new ArtistScheduleExceptionVO();
|
||||
BeanUtils.copyProperties(exception, vo);
|
||||
return vo;
|
||||
}
|
||||
|
||||
private String normalizePresetType(String presetType) {
|
||||
String value = trimText(presetType);
|
||||
if (value == null || value.isBlank()) {
|
||||
return PRESET_CUSTOM;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private String normalizeExceptionType(String exceptionType) {
|
||||
String value = trimText(exceptionType);
|
||||
if (EXCEPTION_REST.equals(value) || EXCEPTION_EXTRA_WORK.equals(value) || EXCEPTION_CHANGE_SHIFT.equals(value)) {
|
||||
return value;
|
||||
}
|
||||
throw new RuntimeException("不支持的排班例外类型:" + value);
|
||||
}
|
||||
|
||||
private List<Integer> resolveWorkDays(List<Integer> inputWorkDays, String presetType) {
|
||||
List<Integer> presetDays = switch (presetType) {
|
||||
case PRESET_DOUBLE_REST, PRESET_NINE_TO_FIVE -> List.of(1, 2, 3, 4, 5);
|
||||
case PRESET_SINGLE_REST, PRESET_LATE_SHIFT -> List.of(1, 2, 3, 4, 5, 6);
|
||||
default -> inputWorkDays;
|
||||
};
|
||||
Set<Integer> normalized = new LinkedHashSet<>();
|
||||
for (Integer day : presetDays == null ? List.<Integer>of() : presetDays) {
|
||||
if (day != null && day >= DayOfWeek.MONDAY.getValue() && day <= DayOfWeek.SUNDAY.getValue()) {
|
||||
normalized.add(day);
|
||||
}
|
||||
}
|
||||
if (normalized.isEmpty()) {
|
||||
throw new RuntimeException("请至少选择一个工作日");
|
||||
}
|
||||
return normalized.stream().sorted().toList();
|
||||
}
|
||||
|
||||
private String encodeWorkDays(List<Integer> workDays) {
|
||||
return workDays.stream()
|
||||
.sorted()
|
||||
.map(String::valueOf)
|
||||
.collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
private List<Integer> decodeWorkDays(String workDays) {
|
||||
if (workDays == null || workDays.isBlank()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return List.of(workDays.split(",")).stream()
|
||||
.map(String::trim)
|
||||
.filter(value -> !value.isBlank())
|
||||
.map(Integer::valueOf)
|
||||
.sorted()
|
||||
.toList();
|
||||
}
|
||||
|
||||
private LocalTime presetStartTime(String presetType) {
|
||||
if (PRESET_NINE_TO_FIVE.equals(presetType)) {
|
||||
return LocalTime.of(9, 0);
|
||||
}
|
||||
return LocalTime.of(10, 0);
|
||||
}
|
||||
|
||||
private LocalTime presetEndTime(String presetType) {
|
||||
if (PRESET_NINE_TO_FIVE.equals(presetType)) {
|
||||
return LocalTime.of(17, 0);
|
||||
}
|
||||
return LocalTime.of(22, 0);
|
||||
}
|
||||
|
||||
private void validateTimeRange(LocalTime startTime, LocalTime endTime) {
|
||||
if (startTime == null || endTime == null || !startTime.isBefore(endTime)) {
|
||||
throw new RuntimeException("排班开始时间必须早于结束时间");
|
||||
}
|
||||
}
|
||||
|
||||
private String trimText(String value) {
|
||||
return value == null ? null : value.trim();
|
||||
}
|
||||
|
||||
private String exceptionRemark(ArtistScheduleExceptionDO exception) {
|
||||
if (exception.getRemark() != null && !exception.getRemark().isBlank()) {
|
||||
return exception.getRemark();
|
||||
}
|
||||
return "例外排班:" + exception.getExceptionType();
|
||||
}
|
||||
|
||||
private record GeneratedSchedule(boolean working, LocalTime startTime, LocalTime endTime, Integer slotMinutes,
|
||||
Integer capacity, String remark) {
|
||||
}
|
||||
}
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.artist.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
|
||||
@Data
|
||||
public class ArtistScheduleExceptionVO {
|
||||
private Long id;
|
||||
private Long shopId;
|
||||
private Long artistId;
|
||||
private LocalDate workDate;
|
||||
private String exceptionType;
|
||||
private LocalTime startTime;
|
||||
private LocalTime endTime;
|
||||
private String remark;
|
||||
private LocalDateTime createTime;
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.artist.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ArtistScheduleRuleSettingVO {
|
||||
private ArtistScheduleRuleVO rule;
|
||||
private List<ArtistScheduleExceptionVO> exceptions;
|
||||
}
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.artist.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ArtistScheduleRuleVO {
|
||||
private Long id;
|
||||
private Long shopId;
|
||||
private Long artistId;
|
||||
private String presetType;
|
||||
private List<Integer> workDays;
|
||||
private LocalTime startTime;
|
||||
private LocalTime endTime;
|
||||
private Integer status;
|
||||
private String remark;
|
||||
private LocalDateTime createTime;
|
||||
}
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.artist.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
|
||||
@Data
|
||||
public class ArtistScheduleVO {
|
||||
private Long id;
|
||||
private Long shopId;
|
||||
private Long artistId;
|
||||
private LocalDate workDate;
|
||||
private LocalTime startTime;
|
||||
private LocalTime endTime;
|
||||
private Integer slotMinutes;
|
||||
private Integer capacity;
|
||||
private Integer status;
|
||||
private String remark;
|
||||
private LocalDateTime createTime;
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.inventory.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class InventoryAdjustDTO {
|
||||
private String changeType;
|
||||
private BigDecimal changeQuantity;
|
||||
private String remark;
|
||||
}
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.inventory.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class InventoryItemDTO {
|
||||
private Long shopId;
|
||||
private String category;
|
||||
private String itemName;
|
||||
private String unit;
|
||||
private BigDecimal stockQuantity;
|
||||
private BigDecimal warningThreshold;
|
||||
private Integer status;
|
||||
}
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.inventory.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import com.xiaowang.jayucloud.artlist.core.common.entity.BaseEntity;
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("t_inventory_item")
|
||||
public class InventoryItemDO extends BaseEntity {
|
||||
@TableField("shop_id")
|
||||
private Long shopId;
|
||||
@TableField("category")
|
||||
private String category;
|
||||
@TableField("item_name")
|
||||
private String itemName;
|
||||
@TableField("unit")
|
||||
private String unit;
|
||||
@TableField("stock_quantity")
|
||||
private BigDecimal stockQuantity;
|
||||
@TableField("warning_threshold")
|
||||
private BigDecimal warningThreshold;
|
||||
@TableField("status")
|
||||
private Integer status;
|
||||
@TableField("is_delete")
|
||||
@TableLogic
|
||||
private Integer isDelete;
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.inventory.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import com.xiaowang.jayucloud.artlist.core.common.entity.BaseEntity;
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("t_inventory_record")
|
||||
public class InventoryRecordDO extends BaseEntity {
|
||||
@TableField("inventory_item_id")
|
||||
private Long inventoryItemId;
|
||||
@TableField("shop_id")
|
||||
private Long shopId;
|
||||
@TableField("change_type")
|
||||
private String changeType;
|
||||
@TableField("change_quantity")
|
||||
private BigDecimal changeQuantity;
|
||||
@TableField("before_quantity")
|
||||
private BigDecimal beforeQuantity;
|
||||
@TableField("after_quantity")
|
||||
private BigDecimal afterQuantity;
|
||||
@TableField("operator_id")
|
||||
private Long operatorId;
|
||||
@TableField("remark")
|
||||
private String remark;
|
||||
}
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.inventory.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.inventory.entity.InventoryItemDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface InventoryItemMapper extends BaseMapper<InventoryItemDO> {
|
||||
}
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.inventory.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.inventory.entity.InventoryRecordDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface InventoryRecordMapper extends BaseMapper<InventoryRecordDO> {
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.inventory.service;
|
||||
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.inventory.dto.InventoryAdjustDTO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.inventory.dto.InventoryItemDTO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.inventory.vo.InventoryItemVO;
|
||||
import com.xiaowang.jayucloud.artlist.core.common.vo.PageResultVO;
|
||||
|
||||
public interface InventoryService {
|
||||
InventoryItemVO saveItem(InventoryItemDTO dto);
|
||||
|
||||
InventoryItemVO adjustStock(Long operatorId, Long itemId, InventoryAdjustDTO dto);
|
||||
|
||||
PageResultVO<InventoryItemVO> listItems(Long shopId, Integer page, Integer size);
|
||||
}
|
||||
-99
@@ -1,99 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.inventory.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.inventory.dto.InventoryAdjustDTO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.inventory.dto.InventoryItemDTO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.inventory.entity.InventoryItemDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.inventory.entity.InventoryRecordDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.inventory.mapper.InventoryItemMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.inventory.mapper.InventoryRecordMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.inventory.service.InventoryService;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.inventory.vo.InventoryItemVO;
|
||||
import com.xiaowang.jayucloud.artlist.core.common.vo.PageResultVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class InventoryServiceImpl implements InventoryService {
|
||||
|
||||
private final InventoryItemMapper inventoryItemMapper;
|
||||
private final InventoryRecordMapper inventoryRecordMapper;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public InventoryItemVO saveItem(InventoryItemDTO dto) {
|
||||
if (dto == null || dto.getShopId() == null || dto.getItemName() == null || dto.getItemName().isBlank()) {
|
||||
throw new RuntimeException("库存物料信息不完整");
|
||||
}
|
||||
InventoryItemDO item = new InventoryItemDO();
|
||||
BeanUtils.copyProperties(dto, item);
|
||||
item.setStockQuantity(dto.getStockQuantity() == null ? BigDecimal.ZERO : dto.getStockQuantity());
|
||||
item.setWarningThreshold(dto.getWarningThreshold() == null ? BigDecimal.ZERO : dto.getWarningThreshold());
|
||||
item.setStatus(dto.getStatus() == null ? 1 : dto.getStatus());
|
||||
item.setIsDelete(0);
|
||||
inventoryItemMapper.insert(item);
|
||||
return toVO(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public InventoryItemVO adjustStock(Long operatorId, Long itemId, InventoryAdjustDTO dto) {
|
||||
InventoryItemDO item = inventoryItemMapper.selectById(itemId);
|
||||
if (item == null || Integer.valueOf(1).equals(item.getIsDelete())) {
|
||||
throw new RuntimeException("库存物料不存在");
|
||||
}
|
||||
BigDecimal before = item.getStockQuantity() == null ? BigDecimal.ZERO : item.getStockQuantity();
|
||||
BigDecimal delta = dto == null || dto.getChangeQuantity() == null ? BigDecimal.ZERO : dto.getChangeQuantity();
|
||||
BigDecimal after = before.add(delta);
|
||||
if (after.compareTo(BigDecimal.ZERO) < 0) {
|
||||
throw new RuntimeException("库存不能小于 0");
|
||||
}
|
||||
item.setStockQuantity(after);
|
||||
inventoryItemMapper.updateById(item);
|
||||
InventoryRecordDO record = new InventoryRecordDO();
|
||||
record.setInventoryItemId(item.getId());
|
||||
record.setShopId(item.getShopId());
|
||||
record.setChangeType(dto == null ? null : dto.getChangeType());
|
||||
record.setChangeQuantity(delta);
|
||||
record.setBeforeQuantity(before);
|
||||
record.setAfterQuantity(after);
|
||||
record.setOperatorId(operatorId);
|
||||
record.setRemark(dto == null ? null : dto.getRemark());
|
||||
inventoryRecordMapper.insert(record);
|
||||
return toVO(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResultVO<InventoryItemVO> listItems(Long shopId, Integer page, Integer size) {
|
||||
int current = page == null || page < 1 ? 1 : page;
|
||||
int pageSize = size == null || size < 1 ? 10 : size;
|
||||
LambdaQueryWrapper<InventoryItemDO> wrapper = new LambdaQueryWrapper<InventoryItemDO>()
|
||||
.eq(InventoryItemDO::getIsDelete, 0)
|
||||
.orderByDesc(InventoryItemDO::getCreateTime);
|
||||
if (shopId != null) {
|
||||
wrapper.eq(InventoryItemDO::getShopId, shopId);
|
||||
}
|
||||
Page<InventoryItemDO> result = inventoryItemMapper.selectPage(new Page<>(current, pageSize), wrapper);
|
||||
PageResultVO<InventoryItemVO> vo = new PageResultVO<>();
|
||||
vo.setList(result.getRecords().stream().map(this::toVO).toList());
|
||||
vo.setTotal(result.getTotal());
|
||||
vo.setPage(current);
|
||||
vo.setSize(pageSize);
|
||||
return vo;
|
||||
}
|
||||
|
||||
private InventoryItemVO toVO(InventoryItemDO item) {
|
||||
InventoryItemVO vo = new InventoryItemVO();
|
||||
BeanUtils.copyProperties(item, vo);
|
||||
BigDecimal stock = item.getStockQuantity() == null ? BigDecimal.ZERO : item.getStockQuantity();
|
||||
BigDecimal warning = item.getWarningThreshold() == null ? BigDecimal.ZERO : item.getWarningThreshold();
|
||||
vo.setWarning(stock.compareTo(warning) <= 0);
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.inventory.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class InventoryItemVO {
|
||||
private Long id;
|
||||
private Long shopId;
|
||||
private String category;
|
||||
private String itemName;
|
||||
private String unit;
|
||||
private BigDecimal stockQuantity;
|
||||
private BigDecimal warningThreshold;
|
||||
private Boolean warning;
|
||||
private Integer status;
|
||||
}
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.manager.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
@Data
|
||||
public class ManagerCustomerCreateDTO {
|
||||
|
||||
@NotBlank(message = "客户姓名不能为空")
|
||||
private String nickname;
|
||||
|
||||
@NotBlank(message = "手机号不能为空")
|
||||
@Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
|
||||
private String phone;
|
||||
}
|
||||
-6
@@ -23,10 +23,4 @@ public class PaymentController {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
return Result.success(paymentService.prepareOrderPayment(userId, orderId));
|
||||
}
|
||||
|
||||
@PostMapping("/order/{orderId}/mock-success")
|
||||
public Result<PaymentOrderVO> mockSuccess(HttpServletRequest request, @PathVariable Long orderId) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
return Result.success(paymentService.manualConfirmOrderPaid(userId, orderId, "mock-success"));
|
||||
}
|
||||
}
|
||||
|
||||
-2
@@ -6,7 +6,5 @@ import com.xiaowang.jayucloud.artlist.core.modules.payment.vo.RefundOrderVO;
|
||||
public interface PaymentService {
|
||||
PaymentOrderVO prepareOrderPayment(Long userId, Long orderId);
|
||||
|
||||
PaymentOrderVO manualConfirmOrderPaid(Long operatorId, Long orderId, String remark);
|
||||
|
||||
RefundOrderVO manualRefundOrder(Long operatorId, Long orderId, Long afterSaleId, String remark);
|
||||
}
|
||||
|
||||
-28
@@ -60,34 +60,6 @@ public class PaymentServiceImpl implements PaymentService {
|
||||
return toVO(payment);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public PaymentOrderVO manualConfirmOrderPaid(Long operatorId, Long orderId, String remark) {
|
||||
OrderDO order = requirePayableOrder(null, orderId);
|
||||
PaymentOrderDO payment = paymentOrderMapper.selectLatestByOrderId(orderId);
|
||||
if (payment == null) {
|
||||
prepareOrderPayment(order.getUserId(), orderId);
|
||||
payment = paymentOrderMapper.selectLatestByOrderId(orderId);
|
||||
}
|
||||
if (payment == null) {
|
||||
throw new RuntimeException("支付单创建失败");
|
||||
}
|
||||
payment.setStatus(STATUS_PAID);
|
||||
payment.setPaidAmount(payment.getPayAmount());
|
||||
payment.setPayTime(LocalDateTime.now());
|
||||
payment.setOperatorId(operatorId);
|
||||
payment.setRemark(remark);
|
||||
paymentOrderMapper.updateById(payment);
|
||||
|
||||
order.setPaymentStatus(STATUS_PAID);
|
||||
order.setPaidAmount(payment.getPayAmount());
|
||||
order.setPayTime(payment.getPayTime());
|
||||
order.setPaymentMethod(payment.getChannel());
|
||||
order.setPaymentOrderNo(payment.getPayNo());
|
||||
orderMapper.updateById(order);
|
||||
return toVO(payment);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public RefundOrderVO manualRefundOrder(Long operatorId, Long orderId, Long afterSaleId, String remark) {
|
||||
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.planning.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@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 manualProductTitle;
|
||||
private BigDecimal manualProductPrice;
|
||||
private String manualProductDescription;
|
||||
private String manualProductTags;
|
||||
private String manualProductTargetAudience;
|
||||
private String manualProductPrecautions;
|
||||
private String manualProductImageFileIds;
|
||||
private String remark;
|
||||
private String clientRequestId;
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.planning.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PlanningAppointmentMoveDTO {
|
||||
private Long artistId;
|
||||
private String appointmentDate;
|
||||
private String appointmentTime;
|
||||
private String appointmentStartTime;
|
||||
private Integer durationMinutes;
|
||||
private String clientRequestId;
|
||||
}
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.planning.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PlanningAppointmentStatusDTO {
|
||||
private Integer status;
|
||||
}
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.planning.service;
|
||||
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.planning.dto.PlanningAppointmentCreateDTO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.planning.dto.PlanningAppointmentMoveDTO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.planning.dto.PlanningAppointmentStatusDTO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.user.entity.UserDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.planning.vo.PlanningAppointmentVO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.planning.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);
|
||||
}
|
||||
-901
@@ -1,901 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.planning.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.planning.dto.PlanningAppointmentCreateDTO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.planning.dto.PlanningAppointmentMoveDTO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.planning.dto.PlanningAppointmentStatusDTO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.planning.entity.AppointmentReservationDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.entity.ArtistScheduleDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.entity.NailArtistInfoDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.entity.OrderDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.entity.OrderItemDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.product.entity.ProductDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.shop.entity.ShopDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.user.entity.UserDO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.planning.mapper.AppointmentReservationMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.mapper.ArtistScheduleMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.artist.mapper.NailArtistInfoMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.mapper.OrderItemMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.mapper.OrderMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.product.mapper.ProductMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.shop.mapper.ShopMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.user.mapper.UserMapper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.planning.service.AppointmentCapacityService;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.service.OrderService;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.planning.service.PlanningService;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.security.support.AdminScopeHelper;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.support.OrderStatus;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.planning.support.PlanningCalendarSupport;
|
||||
import com.xiaowang.jayucloud.artlist.core.support.id.TimeOrderedSnowflakeIdGenerator;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.planning.vo.PlanningAppointmentVO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.planning.vo.PlanningArtistCountVO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.planning.vo.PlanningArtistVO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.planning.vo.PlanningCalendarVO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.planning.vo.PlanningDaySummaryVO;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.planning.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.HashSet;
|
||||
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 int MONTH_AVAILABLE_MINUTES = 90;
|
||||
private static final String RESERVATION_PENDING_QUOTE = "PENDING_QUOTE";
|
||||
private static final String RESERVATION_CONFIRMED = "CONFIRMED";
|
||||
private static final String PRODUCT_SOURCE_TYPE_MANAGER_APPOINTMENT = "MANAGER_APPOINTMENT";
|
||||
private static final String ENCODED_UNSET_PASSWORD = "$2a$10$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW";
|
||||
private static final List<String> ACTIVE_RESERVATION_STATUS = List.of("LOCKED", RESERVATION_PENDING_QUOTE, 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("预约信息不能为空");
|
||||
}
|
||||
if (Integer.valueOf(3).equals(currentUser.getType())) {
|
||||
throw new RuntimeException("美甲师账号只能查看预约,不能新建预约");
|
||||
}
|
||||
Long shopId = requirePlanningShopId(currentUser);
|
||||
requireAppointmentDuration(dto.getDurationMinutes());
|
||||
ProductDO product = resolveAppointmentProduct(dto, 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.reserveConfirmedOrThrow(
|
||||
order.getId(),
|
||||
item.getId(),
|
||||
shopId,
|
||||
artist.getId(),
|
||||
product.getTitle(),
|
||||
startTime,
|
||||
endTime,
|
||||
trimToNull(dto.getClientRequestId())
|
||||
);
|
||||
|
||||
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()));
|
||||
String occupancyStatus = resolveOccupancyStatus(reservation, order);
|
||||
vo.setOccupancyStatus(occupancyStatus);
|
||||
vo.setCanEdit(canEditAppointment(order, occupancyStatus));
|
||||
vo.setCanCancel(canCancelAppointment(order, occupancyStatus));
|
||||
vo.setConflictReason(resolveAppointmentConflictReason(occupancyStatus));
|
||||
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 fullWorkingArtistCount = 0;
|
||||
for (PlanningArtistVO artist : artists) {
|
||||
int count = countByArtist.getOrDefault(artist.getId(), 0L).intValue();
|
||||
ArtistScheduleDO schedule = scheduleByArtist.get(artist.getId());
|
||||
List<PlanningAppointmentVO> artistAppointments = dayAppointments.stream()
|
||||
.filter(appointment -> Objects.equals(appointment.getArtistId(), artist.getId()))
|
||||
.toList();
|
||||
String artistStatus = resolveArtistDayStatus(artist, schedule, artistAppointments);
|
||||
if (!"rest".equals(artistStatus)) {
|
||||
workingArtistCount++;
|
||||
if ("full".equals(artistStatus)) {
|
||||
fullWorkingArtistCount++;
|
||||
}
|
||||
}
|
||||
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 allFull = workingArtistCount > 0 && fullWorkingArtistCount == workingArtistCount;
|
||||
|
||||
PlanningDaySummaryVO summary = new PlanningDaySummaryVO();
|
||||
summary.setDate(date);
|
||||
summary.setTotalCount(total);
|
||||
summary.setArtistCounts(artistCounts);
|
||||
summary.setDayStatus(PlanningCalendarSupport.resolveDayStatus(total, hasWorkingSchedule, allFull));
|
||||
summaries.add(summary);
|
||||
cursor = cursor.plusDays(1);
|
||||
}
|
||||
return summaries;
|
||||
}
|
||||
|
||||
private String resolveArtistDayStatus(PlanningArtistVO artist, ArtistScheduleDO schedule, List<PlanningAppointmentVO> appointments) {
|
||||
if (schedule != null && !Integer.valueOf(1).equals(schedule.getStatus())) {
|
||||
return "rest";
|
||||
}
|
||||
if (schedule == null || Integer.valueOf(0).equals(artist.getStatus())) {
|
||||
return "rest";
|
||||
}
|
||||
if (hasContinuousFreeWindow(schedule, appointments, MONTH_AVAILABLE_MINUTES)) {
|
||||
return appointments.isEmpty() ? "free" : "working";
|
||||
}
|
||||
return "full";
|
||||
}
|
||||
|
||||
private boolean hasContinuousFreeWindow(ArtistScheduleDO schedule, List<PlanningAppointmentVO> appointments, int requiredMinutes) {
|
||||
if (schedule == null || schedule.getStartTime() == null || schedule.getEndTime() == null || requiredMinutes <= 0) {
|
||||
return false;
|
||||
}
|
||||
int startMinute = schedule.getStartTime().toSecondOfDay() / 60;
|
||||
int endMinute = schedule.getEndTime().toSecondOfDay() / 60;
|
||||
if (endMinute - startMinute < requiredMinutes) {
|
||||
return false;
|
||||
}
|
||||
int cursor = startMinute;
|
||||
List<TimeRange> ranges = appointments.stream()
|
||||
.map(this::toTimeRange)
|
||||
.filter(Objects::nonNull)
|
||||
.filter(range -> range.endMinute() > startMinute && range.startMinute() < endMinute)
|
||||
.map(range -> new TimeRange(Math.max(range.startMinute(), startMinute), Math.min(range.endMinute(), endMinute)))
|
||||
.sorted(Comparator.comparing(TimeRange::startMinute).thenComparing(TimeRange::endMinute))
|
||||
.toList();
|
||||
for (TimeRange range : ranges) {
|
||||
if (range.startMinute() - cursor >= requiredMinutes) {
|
||||
return true;
|
||||
}
|
||||
cursor = Math.max(cursor, range.endMinute());
|
||||
}
|
||||
return endMinute - cursor >= requiredMinutes;
|
||||
}
|
||||
|
||||
private TimeRange toTimeRange(PlanningAppointmentVO appointment) {
|
||||
if (appointment == null) {
|
||||
return null;
|
||||
}
|
||||
Integer startMinute = appointment.getStartMinute();
|
||||
Integer durationMinutes = appointment.getDurationMinutes();
|
||||
if (startMinute == null || durationMinutes == null || durationMinutes <= 0) {
|
||||
return null;
|
||||
}
|
||||
return new TimeRange(startMinute, startMinute + durationMinutes);
|
||||
}
|
||||
|
||||
private record TimeRange(int startMinute, int endMinute) {
|
||||
}
|
||||
|
||||
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 ProductDO resolveAppointmentProduct(PlanningAppointmentCreateDTO dto, Long shopId) {
|
||||
if (dto.getProductId() != null) {
|
||||
return requireActiveProduct(dto.getProductId(), shopId);
|
||||
}
|
||||
return createManualAppointmentProduct(dto, shopId);
|
||||
}
|
||||
|
||||
private ProductDO createManualAppointmentProduct(PlanningAppointmentCreateDTO dto, Long shopId) {
|
||||
String title = trimToNull(dto.getManualProductTitle());
|
||||
if (!hasText(title)) {
|
||||
throw new RuntimeException("请选择预约作品或填写手动作品名称");
|
||||
}
|
||||
BigDecimal price = dto.getManualProductPrice();
|
||||
if (price == null || price.compareTo(BigDecimal.ZERO) < 0) {
|
||||
throw new RuntimeException("手动作品价格不能小于0");
|
||||
}
|
||||
int durationMinutes = requireAppointmentDuration(dto.getDurationMinutes());
|
||||
ProductDO product = new ProductDO();
|
||||
product.setShopId(shopId);
|
||||
product.setTitle(title);
|
||||
product.setDescription(trimToNull(dto.getManualProductDescription()));
|
||||
product.setTags(trimToNull(dto.getManualProductTags()));
|
||||
product.setTargetAudience(trimToNull(dto.getManualProductTargetAudience()));
|
||||
product.setPrecautions(trimToNull(dto.getManualProductPrecautions()));
|
||||
product.setImageFileIds(trimToNull(dto.getManualProductImageFileIds()));
|
||||
product.setPrice(price);
|
||||
product.setLikeCount(0);
|
||||
product.setCollectCount(0);
|
||||
product.setApproximateDuration(durationMinutes + "分钟");
|
||||
product.setBookableArtists(dto.getArtistId() == null ? null : String.valueOf(dto.getArtistId()));
|
||||
product.setFrontVisible(0);
|
||||
product.setSourceType(PRODUCT_SOURCE_TYPE_MANAGER_APPOINTMENT);
|
||||
product.setIsDelete(0);
|
||||
productMapper.insert(product);
|
||||
return product;
|
||||
}
|
||||
|
||||
private int requireAppointmentDuration(Integer durationMinutes) {
|
||||
if (durationMinutes == null || durationMinutes <= 0) {
|
||||
throw new RuntimeException("预约时长不能为空且必须大于0分钟");
|
||||
}
|
||||
return durationMinutes;
|
||||
}
|
||||
|
||||
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.setPassword(ENCODED_UNSET_PASSWORD);
|
||||
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 String resolveOccupancyStatus(AppointmentReservationDO reservation, OrderDO order) {
|
||||
if (reservation != null && hasText(reservation.getStatus())) {
|
||||
return reservation.getStatus();
|
||||
}
|
||||
if (order != null && Integer.valueOf(OrderStatus.PRICE_CONFIRMING.getCode()).equals(order.getStatus())) {
|
||||
return RESERVATION_PENDING_QUOTE;
|
||||
}
|
||||
if (order != null && Integer.valueOf(OrderStatus.PENDING_SERVICE.getCode()).equals(order.getStatus())) {
|
||||
return RESERVATION_CONFIRMED;
|
||||
}
|
||||
if (order != null && Integer.valueOf(OrderStatus.CANCELLED.getCode()).equals(order.getStatus())) {
|
||||
return "CANCELLED";
|
||||
}
|
||||
if (order != null && Integer.valueOf(OrderStatus.COMPLETED.getCode()).equals(order.getStatus())) {
|
||||
return "COMPLETED";
|
||||
}
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
private Boolean canEditAppointment(OrderDO order, String occupancyStatus) {
|
||||
return order != null
|
||||
&& (RESERVATION_PENDING_QUOTE.equals(occupancyStatus) || RESERVATION_CONFIRMED.equals(occupancyStatus))
|
||||
&& !Integer.valueOf(OrderStatus.COMPLETED.getCode()).equals(order.getStatus())
|
||||
&& !Integer.valueOf(OrderStatus.CANCELLED.getCode()).equals(order.getStatus());
|
||||
}
|
||||
|
||||
private Boolean canCancelAppointment(OrderDO order, String occupancyStatus) {
|
||||
return order != null
|
||||
&& (RESERVATION_PENDING_QUOTE.equals(occupancyStatus) || RESERVATION_CONFIRMED.equals(occupancyStatus))
|
||||
&& !Integer.valueOf(OrderStatus.COMPLETED.getCode()).equals(order.getStatus())
|
||||
&& !Integer.valueOf(OrderStatus.CANCELLED.getCode()).equals(order.getStatus());
|
||||
}
|
||||
|
||||
private String resolveAppointmentConflictReason(String occupancyStatus) {
|
||||
if (RESERVATION_PENDING_QUOTE.equals(occupancyStatus)) {
|
||||
return "该时段已有待报价预约占用";
|
||||
}
|
||||
if (RESERVATION_CONFIRMED.equals(occupancyStatus)) {
|
||||
return "该时段已有已确认预约占用";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
-83
@@ -1,83 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.planning.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 (allWorkingArtistsBusy) {
|
||||
return "full";
|
||||
}
|
||||
if (totalCount <= 0) {
|
||||
return "free";
|
||||
}
|
||||
return "working";
|
||||
}
|
||||
|
||||
public record BusinessHours(LocalTime start, LocalTime end) {
|
||||
}
|
||||
}
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.planning.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 String occupancyStatus;
|
||||
private Boolean canEdit;
|
||||
private Boolean canCancel;
|
||||
private String conflictReason;
|
||||
private BigDecimal amount;
|
||||
private String remark;
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.planning.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;
|
||||
}
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.planning.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;
|
||||
}
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.planning.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;
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.planning.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;
|
||||
}
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
package com.xiaowang.jayucloud.artlist.core.modules.planning.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;
|
||||
}
|
||||
-1
@@ -9,7 +9,6 @@ import com.xiaowang.jayucloud.artlist.core.modules.auth.dto.*;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.content.dto.*;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.file.dto.*;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.integration.dto.*;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.inventory.dto.*;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.marketing.dto.*;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.message.dto.*;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.dto.*;
|
||||
|
||||
-1
@@ -12,7 +12,6 @@ import com.xiaowang.jayucloud.artlist.core.modules.auth.dto.*;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.content.dto.*;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.file.dto.*;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.integration.dto.*;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.inventory.dto.*;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.marketing.dto.*;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.message.dto.*;
|
||||
import com.xiaowang.jayucloud.artlist.core.modules.order.dto.*;
|
||||
|
||||
+2
-2
@@ -28,12 +28,12 @@ public class UserSessionService {
|
||||
* Purpose: SESSION_KEY_PREFIX supports UserSessionService.java by holding or executing the session key prefix business role.
|
||||
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
private static final String SESSION_KEY_PREFIX = "auth:session:";
|
||||
private static final String SESSION_KEY_PREFIX = "artlist:auth:session:";
|
||||
/**
|
||||
* Purpose: USER_SESSION_SET_PREFIX supports UserSessionService.java by holding or executing the user session set prefix business role.
|
||||
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
private static final String USER_SESSION_SET_PREFIX = "auth:user:sessions:";
|
||||
private static final String USER_SESSION_SET_PREFIX = "artlist:auth:user:sessions:";
|
||||
|
||||
/**
|
||||
* Purpose: stringRedisTemplate supports UserSessionService.java by holding or executing the string redis template business role.
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -158,9 +158,6 @@ export interface GrowthSummaryVO {
|
||||
export const paymentApi = {
|
||||
prepareOrderPayment: async (orderId: IdType): Promise<PaymentOrderVO> => {
|
||||
return await api.post<PaymentOrderVO>(`/payment/order/${orderId}/prepare`) as unknown as PaymentOrderVO
|
||||
},
|
||||
mockSuccess: async (orderId: IdType): Promise<PaymentOrderVO> => {
|
||||
return await api.post<PaymentOrderVO>(`/payment/order/${orderId}/mock-success`) as unknown as PaymentOrderVO
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,6 @@ const isQuoteConfirming = computed(() => isQuoteStatus(order.value?.status))
|
||||
const statusClass = (status?: number) => isQuoteStatus(status) ? 'quote' : status === 2 ? 'done' : status === 3 ? 'cancelled' : 'pending'
|
||||
const isOrderPaid = (target: any) => String(target?.paymentStatus || '').toUpperCase() === 'PAID'
|
||||
const canPreparePayment = computed(() => !isQuoteConfirming.value && Number(order.value?.status) === 1 && !isOrderPaid(order.value))
|
||||
const canMockPay = computed(() => !isQuoteConfirming.value && Number(order.value?.status) === 1 && String(order.value?.paymentStatus || '').toUpperCase() === 'PAYING')
|
||||
const canApplyAfterSale = computed(() => !isQuoteConfirming.value && (Number(order.value?.status) === 2 || isOrderPaid(order.value)))
|
||||
|
||||
const timeline = computed(() => {
|
||||
@@ -206,15 +205,6 @@ const preparePayment = async () => {
|
||||
message.success('支付单已准备')
|
||||
}
|
||||
|
||||
const mockPay = async () => {
|
||||
if (!order.value?.id) return
|
||||
await runWithGlobalLoading(async () => {
|
||||
await paymentApi.mockSuccess(order.value.id)
|
||||
await loadOrder()
|
||||
})
|
||||
message.success('模拟支付成功')
|
||||
}
|
||||
|
||||
const cancelOrder = () => {
|
||||
if (!order.value?.id) return
|
||||
Modal.confirm({
|
||||
@@ -358,7 +348,6 @@ onMounted(loadOrder)
|
||||
|
||||
<section class="action-bar">
|
||||
<a-button v-if="canPreparePayment" @click="preparePayment">准备支付</a-button>
|
||||
<a-button v-if="canMockPay" type="primary" @click="mockPay">模拟支付</a-button>
|
||||
<a-button v-if="canApplyAfterSale" @click="router.push({ path: '/after-sale/apply', query: { orderId } })">申请售后</a-button>
|
||||
<a-button v-if="order.status === 1" danger @click="cancelOrder">取消订单</a-button>
|
||||
</section>
|
||||
|
||||
@@ -201,7 +201,6 @@
|
||||
<div class="order-card__actions">
|
||||
<button v-if="orderNeedsReview(order)" type="button" class="order-action order-action--primary" @click="openReviewModal(firstPendingReview(order))">去评价</button>
|
||||
<button v-if="canPreparePayment(order)" type="button" class="order-action order-action--primary" @click="preparePayment(order)">立即支付</button>
|
||||
<button v-if="canMockPay(order)" type="button" class="order-action order-action--primary" @click="mockPay(order)">立即支付</button>
|
||||
<button type="button" class="order-action" @click="router.push(`/orders/${order.id}`)">查看详情</button>
|
||||
<button v-if="canApplyAfterSale(order)" type="button" class="order-action" @click="openAfterSaleModal(order)">申请售后</button>
|
||||
<button v-if="hasRebookableItems(order)" type="button" class="order-action order-action--primary" @click="rebookOrder(order)">复刻同款</button>
|
||||
@@ -471,7 +470,6 @@ const orderPaymentStatus = (order: any) => String(order.paymentStatus || order.p
|
||||
const isOrderPaid = (order: any) => orderPaymentStatus(order) === 'PAID'
|
||||
const orderNeedsPayment = (order: any) => Number(order.status) === 1 && !isOrderPaid(order)
|
||||
const canPreparePayment = (order: any) => orderNeedsPayment(order) && orderPaymentStatus(order) !== 'PAYING'
|
||||
const canMockPay = (order: any) => Number(order.status) === 1 && orderPaymentStatus(order) === 'PAYING'
|
||||
const canApplyAfterSale = (order: any) => !isQuoteConfirming(order) && (Number(order.status) === 2 || isOrderPaid(order))
|
||||
|
||||
/**
|
||||
@@ -779,18 +777,6 @@ const preparePayment = async (order: any) => {
|
||||
}
|
||||
}
|
||||
|
||||
const mockPay = async (order: any) => {
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
await paymentApi.mockSuccess(order.id)
|
||||
await loadOrders()
|
||||
})
|
||||
message.success('支付成功')
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '支付失败')
|
||||
}
|
||||
}
|
||||
|
||||
const submitQuoteReply = async (order: any) => {
|
||||
const key = quoteOrderKey(order)
|
||||
const remark = String(quoteReplyForms[key] || '').trim()
|
||||
|
||||
@@ -7,13 +7,5 @@ module.exports = {
|
||||
method: 'POST',
|
||||
data: {}
|
||||
})
|
||||
},
|
||||
|
||||
mockOrderPaymentSuccess(orderId) {
|
||||
return request({
|
||||
url: `/payment/order/${orderId}/mock-success`,
|
||||
method: 'POST',
|
||||
data: {}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ const afterSaleApi = require('./after-sale')
|
||||
const growthApi = require('./growth')
|
||||
|
||||
paymentApi.prepareOrderPayment(12)
|
||||
paymentApi.mockOrderPaymentSuccess(12)
|
||||
afterSaleApi.applyAfterSale({ orderId: 12, reason: 'need refund' })
|
||||
afterSaleApi.getMyAfterSales({ page: 2, size: 5 })
|
||||
growthApi.getGrowthSummary()
|
||||
@@ -32,19 +31,14 @@ assert.deepStrictEqual(calls[0], {
|
||||
data: {}
|
||||
})
|
||||
assert.deepStrictEqual(calls[1], {
|
||||
url: '/payment/order/12/mock-success',
|
||||
method: 'POST',
|
||||
data: {}
|
||||
})
|
||||
assert.deepStrictEqual(calls[2], {
|
||||
url: '/after-sale/apply',
|
||||
method: 'POST',
|
||||
data: { orderId: 12, reason: 'need refund' }
|
||||
})
|
||||
assert.deepStrictEqual(calls[3], {
|
||||
assert.deepStrictEqual(calls[2], {
|
||||
url: '/after-sale/my',
|
||||
params: { page: 2, size: 5 }
|
||||
})
|
||||
assert.deepStrictEqual(calls[4], {
|
||||
assert.deepStrictEqual(calls[3], {
|
||||
url: '/growth/summary'
|
||||
})
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
"pages/profile/index",
|
||||
"pages/auth/index",
|
||||
"pages/product-detail/index",
|
||||
"pages/artist-profile/index",
|
||||
"pages/shop-detail/index",
|
||||
"pages/orders/index",
|
||||
"pages/order-detail/index",
|
||||
@@ -15,8 +14,6 @@
|
||||
"pages/after-sale-apply/index",
|
||||
"pages/service-progress/index",
|
||||
"pages/help/index",
|
||||
"pages/artist-orders/index",
|
||||
"pages/artist-calendar/index",
|
||||
"pages/account-settings/index",
|
||||
"pages/password-settings/index",
|
||||
"pages/wishlist/index",
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
const orderApi = require('../../api/order')
|
||||
const auth = require('../../utils/auth')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const theme = require('../../utils/theme')
|
||||
const { formatDateTime, formatPrice } = require('../../utils/format')
|
||||
const { runWithLoading } = require('../../utils/loading')
|
||||
|
||||
function safeList(value) {
|
||||
return Array.isArray(value) ? value : []
|
||||
}
|
||||
|
||||
function formatClock(value) {
|
||||
return value ? String(value).replace('T', ' ').slice(11, 16) : '--'
|
||||
}
|
||||
|
||||
function formatAppointment(item) {
|
||||
return {
|
||||
...item,
|
||||
dayText: String(item.appointmentStartTime || '').slice(5, 10),
|
||||
timeText: `${formatClock(item.appointmentStartTime)}-${formatClock(item.appointmentEndTime)}`,
|
||||
amountText: `¥${formatPrice(item.actualAmount || item.totalAmount)}`,
|
||||
dateTimeText: formatDateTime(item.appointmentStartTime)
|
||||
}
|
||||
}
|
||||
|
||||
Page({
|
||||
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
|
||||
loading: false,
|
||||
isLoggedIn: false,
|
||||
appointments: []
|
||||
}),
|
||||
|
||||
onShow() {
|
||||
this.loadAppointments()
|
||||
},
|
||||
|
||||
handleBack() {
|
||||
navigation.goBack('/pages/artist-orders/index')
|
||||
},
|
||||
|
||||
async loadAppointments() {
|
||||
const isLoggedIn = auth.isLoggedIn()
|
||||
this.setData({ isLoggedIn })
|
||||
if (!isLoggedIn) {
|
||||
navigation.openAuth(navigation.getCurrentPageUrl())
|
||||
return
|
||||
}
|
||||
this.setData({ loading: true })
|
||||
try {
|
||||
const list = safeList(await orderApi.getArtistCalendarRecent(7))
|
||||
this.setData({
|
||||
appointments: list.map(formatAppointment)
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '预约日历加载失败', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ loading: false })
|
||||
}
|
||||
},
|
||||
|
||||
openArtistOrders() {
|
||||
navigation.navigate('/pages/artist-orders/index')
|
||||
},
|
||||
|
||||
async completeOrder(event) {
|
||||
const orderId = event.currentTarget.dataset.orderId
|
||||
if (!orderId) return
|
||||
try {
|
||||
await runWithLoading(() => orderApi.completeArtistOrder(orderId))
|
||||
wx.showToast({ title: '服务已完成', icon: 'none' })
|
||||
await this.loadAppointments()
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '完成服务失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
<navigation-bar title="预约日历" showBack="{{true}}" fallbackPath="/pages/artist-orders/index" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
|
||||
|
||||
<view class="page-shell" style="{{themeVars}}">
|
||||
<view class="page-content">
|
||||
<view class="page-hero">
|
||||
<text class="hero-kicker">未来 7 天</text>
|
||||
<text class="hero-title">{{appointments.length}} 个预约</text>
|
||||
<text class="hero-desc">按时间查看即将服务的客户与项目</text>
|
||||
<view class="hero-action-row">
|
||||
<view class="hero-action secondary" bindtap="openArtistOrders">订单列表</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{loading}}" class="page-card empty-card">
|
||||
<text class="empty-title">正在加载日历</text>
|
||||
</view>
|
||||
|
||||
<view wx:elif="{{appointments.length}}">
|
||||
<view wx:for="{{appointments}}" wx:key="orderItemId" class="page-card appointment-card">
|
||||
<view class="day-box">
|
||||
<text>{{item.dayText}}</text>
|
||||
<text>{{item.timeText}}</text>
|
||||
</view>
|
||||
<view class="appointment-main">
|
||||
<text class="appointment-title">{{item.customerNickname || '客户'}} · {{item.productTitle}}</text>
|
||||
<text class="appointment-line">{{item.orderStatusText}} · {{item.shopName || '门店'}}</text>
|
||||
<text class="appointment-line">{{item.amountText}}</text>
|
||||
<view wx:if="{{item.orderStatus == 1}}" class="ghost-btn" data-order-id="{{item.orderId}}" bindtap="completeOrder">完成服务</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:else class="page-card empty-card">
|
||||
<text class="empty-title">未来 7 天暂无预约</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -1,49 +0,0 @@
|
||||
.appointment-card {
|
||||
display: flex;
|
||||
gap: 18rpx;
|
||||
margin-top: 22rpx;
|
||||
padding: 24rpx;
|
||||
}
|
||||
|
||||
.day-box {
|
||||
width: 136rpx;
|
||||
flex: 0 0 auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
gap: 8rpx;
|
||||
padding: 20rpx 12rpx;
|
||||
border-radius: 24rpx;
|
||||
background: var(--theme-primary-soft);
|
||||
color: var(--theme-primary);
|
||||
text-align: center;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.appointment-main {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.appointment-title,
|
||||
.appointment-line {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.appointment-title {
|
||||
color: var(--text-primary);
|
||||
font-size: 29rpx;
|
||||
font-weight: 800;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
.appointment-line {
|
||||
margin-top: 8rpx;
|
||||
color: #504444;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.ghost-btn {
|
||||
margin-top: 16rpx;
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
const orderApi = require('../../api/order')
|
||||
const auth = require('../../utils/auth')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const theme = require('../../utils/theme')
|
||||
const { resolveLegacyImage } = require('../../utils/file')
|
||||
const { formatDateTime, formatPrice, getOrderStatusClass, getOrderStatusText } = require('../../utils/format')
|
||||
const { runWithLoading } = require('../../utils/loading')
|
||||
|
||||
function safeList(value) {
|
||||
return Array.isArray(value) ? value : []
|
||||
}
|
||||
|
||||
async function formatOrder(order) {
|
||||
return {
|
||||
...order,
|
||||
statusText: getOrderStatusText(order),
|
||||
statusClass: getOrderStatusClass(order),
|
||||
amountText: `¥${formatPrice(order && order.actualAmount)}`,
|
||||
items: await Promise.all(safeList(order && order.items).map(async item => ({
|
||||
...item,
|
||||
productImageUrl: await resolveLegacyImage(item.productImage),
|
||||
priceText: `¥${formatPrice(item.price)}`,
|
||||
appointmentText: formatDateTime(item.appointmentTime)
|
||||
})))
|
||||
}
|
||||
}
|
||||
|
||||
Page({
|
||||
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
|
||||
loading: false,
|
||||
isLoggedIn: false,
|
||||
orders: [],
|
||||
focusOrderId: ''
|
||||
}),
|
||||
|
||||
onLoad(options) {
|
||||
this.setData({
|
||||
focusOrderId: (options && options.orderId) || ''
|
||||
})
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.loadOrders()
|
||||
},
|
||||
|
||||
handleBack() {
|
||||
navigation.goBack('/pages/profile/index')
|
||||
},
|
||||
|
||||
async loadOrders() {
|
||||
const isLoggedIn = auth.isLoggedIn()
|
||||
this.setData({ isLoggedIn })
|
||||
if (!isLoggedIn) {
|
||||
navigation.openAuth(navigation.getCurrentPageUrl())
|
||||
return
|
||||
}
|
||||
this.setData({ loading: true })
|
||||
try {
|
||||
const list = safeList(await orderApi.getArtistOrders())
|
||||
const orders = await Promise.all(list.map(formatOrder))
|
||||
this.setData({ orders })
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '美甲师订单加载失败', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ loading: false })
|
||||
}
|
||||
},
|
||||
|
||||
openCalendar() {
|
||||
navigation.navigate('/pages/artist-calendar/index')
|
||||
},
|
||||
|
||||
async completeOrder(event) {
|
||||
const orderId = event.currentTarget.dataset.orderId
|
||||
if (!orderId) return
|
||||
const confirmed = await new Promise(resolve => {
|
||||
wx.showModal({
|
||||
title: '完成服务',
|
||||
content: '确认这笔订单已经完成服务吗?',
|
||||
success: res => resolve(Boolean(res.confirm))
|
||||
})
|
||||
})
|
||||
if (!confirmed) return
|
||||
try {
|
||||
await runWithLoading(() => orderApi.completeArtistOrder(orderId))
|
||||
wx.showToast({ title: '服务已完成', icon: 'none' })
|
||||
await this.loadOrders()
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '完成订单失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
<navigation-bar title="美甲师订单" showBack="{{true}}" fallbackPath="/pages/profile/index" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
|
||||
|
||||
<view class="page-shell" style="{{themeVars}}">
|
||||
<view class="page-content">
|
||||
<view class="page-hero">
|
||||
<text class="hero-kicker">服务订单</text>
|
||||
<text class="hero-title">{{orders.length}} 笔相关订单</text>
|
||||
<text class="hero-desc">查看客户预约、项目和服务完成状态</text>
|
||||
<view class="hero-action-row">
|
||||
<view class="hero-action secondary" bindtap="openCalendar">预约日历</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{loading}}" class="page-card empty-card">
|
||||
<text class="empty-title">正在加载订单</text>
|
||||
</view>
|
||||
|
||||
<view wx:elif="{{orders.length}}">
|
||||
<view wx:for="{{orders}}" wx:key="id" class="page-card order-card {{item.id == focusOrderId ? 'focus-target' : ''}}">
|
||||
<view class="order-head">
|
||||
<view>
|
||||
<text class="order-no">{{item.orderNo}}</text>
|
||||
<text class="order-line">{{item.customerNickname || '客户'}} {{item.customerPhoneMasked || ''}}</text>
|
||||
</view>
|
||||
<text class="chip">{{item.statusText}}</text>
|
||||
</view>
|
||||
<view wx:for="{{item.items}}" wx:key="id" wx:for-item="orderItem" class="item-row">
|
||||
<image class="item-thumb" src="{{orderItem.productImageUrl}}" mode="aspectFill"></image>
|
||||
<view class="item-main">
|
||||
<text class="item-title">{{orderItem.productTitle}}</text>
|
||||
<text class="item-line">{{orderItem.priceText}} x {{orderItem.quantity}}</text>
|
||||
<text wx:if="{{orderItem.appointmentText}}" class="item-line">预约:{{orderItem.appointmentText}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="order-foot">
|
||||
<text class="order-amount">{{item.amountText}}</text>
|
||||
<view wx:if="{{item.status == 1}}" class="ghost-btn" data-order-id="{{item.id}}" bindtap="completeOrder">完成服务</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:else class="page-card empty-card">
|
||||
<text class="empty-title">暂无相关订单</text>
|
||||
<text class="empty-desc">有客户预约你服务的项目后会出现在这里</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -1,70 +0,0 @@
|
||||
.order-card {
|
||||
margin-top: 22rpx;
|
||||
padding: 26rpx;
|
||||
}
|
||||
|
||||
.order-card.focus-target {
|
||||
border-color: var(--theme-primary);
|
||||
}
|
||||
|
||||
.order-head,
|
||||
.order-foot {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 18rpx;
|
||||
}
|
||||
|
||||
.order-no,
|
||||
.order-line,
|
||||
.order-amount {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.order-no {
|
||||
color: var(--text-primary);
|
||||
font-size: 28rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.order-line {
|
||||
margin-top: 8rpx;
|
||||
color: #504444;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.item-row {
|
||||
display: flex;
|
||||
gap: 18rpx;
|
||||
margin-top: 22rpx;
|
||||
}
|
||||
|
||||
.item-thumb {
|
||||
width: 116rpx;
|
||||
height: 116rpx;
|
||||
border-radius: 22rpx;
|
||||
background: var(--theme-primary-soft);
|
||||
}
|
||||
|
||||
.item-main {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.item-title {
|
||||
display: block;
|
||||
color: var(--text-primary);
|
||||
font-size: 28rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.order-foot {
|
||||
margin-top: 24rpx;
|
||||
}
|
||||
|
||||
.order-amount {
|
||||
color: var(--text-primary);
|
||||
font-size: 28rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
const nailArtistApi = require('../../api/nail-artist')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const { DEFAULT_PRODUCT_IMAGE } = require('../../utils/config')
|
||||
|
||||
function formatPrice(price) {
|
||||
const value = Number(price || 0)
|
||||
return value > 0 ? `¥${value.toFixed(2)}` : '到店确认'
|
||||
}
|
||||
|
||||
function formatDateTime(value) {
|
||||
if (!value) {
|
||||
return ''
|
||||
}
|
||||
return String(value).replace('T', ' ').slice(0, 16)
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
loading: true,
|
||||
loadError: '',
|
||||
artistId: '',
|
||||
profile: null,
|
||||
works: [],
|
||||
reviews: [],
|
||||
availability: [],
|
||||
heroImage: DEFAULT_PRODUCT_IMAGE,
|
||||
artistName: '美甲师',
|
||||
artistDesc: '专注细节与稳定出品',
|
||||
shopName: '门店待确认',
|
||||
styleTags: [],
|
||||
ratingText: '0.0',
|
||||
serviceCountText: '0',
|
||||
workTimeText: '到店确认'
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
this.setData({
|
||||
artistId: options && options.id ? options.id : ''
|
||||
})
|
||||
this.loadArtistProfile()
|
||||
},
|
||||
|
||||
async onPullDownRefresh() {
|
||||
await this.loadArtistProfile()
|
||||
wx.stopPullDownRefresh()
|
||||
},
|
||||
|
||||
async loadArtistProfile() {
|
||||
if (!this.data.artistId) {
|
||||
this.setData({
|
||||
loading: false,
|
||||
loadError: '缺少美甲师信息'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({
|
||||
loading: true,
|
||||
loadError: ''
|
||||
})
|
||||
|
||||
try {
|
||||
const [profile, availability, reviews] = await Promise.all([
|
||||
nailArtistApi.getPublicProfile(this.data.artistId),
|
||||
nailArtistApi.getAvailability(this.data.artistId),
|
||||
nailArtistApi.listReviews(this.data.artistId)
|
||||
])
|
||||
const works = (profile.works || []).map(work => ({
|
||||
...work,
|
||||
title: work.title || '美甲作品',
|
||||
coverImageUrl: work.coverImageUrl || DEFAULT_PRODUCT_IMAGE,
|
||||
priceText: formatPrice(work.price)
|
||||
}))
|
||||
const formattedReviews = (reviews || profile.reviews || []).map(review => ({
|
||||
...review,
|
||||
customerName: review.customerName || '匿名用户',
|
||||
content: review.content || '这位用户没有填写文字评价',
|
||||
submittedAtText: formatDateTime(review.submittedAt),
|
||||
ratingText: Number(review.rating || 0).toFixed(1)
|
||||
}))
|
||||
const start = profile.workStartTime ? String(profile.workStartTime).slice(0, 5) : ''
|
||||
const end = profile.workEndTime ? String(profile.workEndTime).slice(0, 5) : ''
|
||||
|
||||
this.setData({
|
||||
profile,
|
||||
works,
|
||||
reviews: formattedReviews,
|
||||
availability: availability || profile.availability || [],
|
||||
heroImage: (works.find(work => work.coverImageUrl) || {}).coverImageUrl || DEFAULT_PRODUCT_IMAGE,
|
||||
artistName: profile.artistName || '美甲师',
|
||||
artistDesc: profile.identity || profile.signature || '专注细节与稳定出品',
|
||||
shopName: profile.shopName || '门店待确认',
|
||||
styleTags: (profile.styleTags || []).filter(Boolean),
|
||||
ratingText: Number(profile.rating || 0).toFixed(1),
|
||||
serviceCountText: String(profile.serviceCount || 0),
|
||||
workTimeText: start && end ? `${start}-${end}` : '到店确认'
|
||||
})
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
loadError: error.message || '美甲师个人页加载失败'
|
||||
})
|
||||
} finally {
|
||||
this.setData({
|
||||
loading: false
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleBack() {
|
||||
navigation.goBack('/pages/home/index')
|
||||
},
|
||||
|
||||
handleRetry() {
|
||||
this.loadArtistProfile()
|
||||
},
|
||||
|
||||
handleOpenShop() {
|
||||
const profile = this.data.profile
|
||||
if (!profile || !profile.shopId) {
|
||||
return
|
||||
}
|
||||
wx.navigateTo({
|
||||
url: `/pages/shop-detail/index?id=${profile.shopId}`
|
||||
})
|
||||
},
|
||||
|
||||
handleOpenWork(event) {
|
||||
const id = event.currentTarget.dataset.id
|
||||
if (!id) {
|
||||
return
|
||||
}
|
||||
wx.navigateTo({
|
||||
url: `/pages/product-detail/index?id=${id}`
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"navigationStyle": "custom",
|
||||
"usingComponents": {}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
<view class="artist-page">
|
||||
<view class="page-header">
|
||||
<view class="back-btn" bindtap="handleBack">‹</view>
|
||||
<text class="page-title">{{artistName}}</text>
|
||||
<view class="header-spacer"></view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{loading}}" class="state-box">
|
||||
<text>加载中...</text>
|
||||
</view>
|
||||
|
||||
<view wx:elif="{{loadError}}" class="state-box">
|
||||
<text class="state-title">暂时无法查看个人页</text>
|
||||
<text class="state-desc">{{loadError}}</text>
|
||||
<view class="primary-btn" bindtap="handleRetry">重试</view>
|
||||
</view>
|
||||
|
||||
<scroll-view wx:else scroll-y class="content-scroll">
|
||||
<view class="hero">
|
||||
<image class="hero-image" src="{{heroImage}}" mode="aspectFill"></image>
|
||||
<view class="hero-mask"></view>
|
||||
<view class="artist-card">
|
||||
<image wx:if="{{profile.avatar}}" class="avatar" src="{{profile.avatar}}" mode="aspectFill"></image>
|
||||
<view wx:else class="avatar placeholder">艺</view>
|
||||
<view class="artist-main">
|
||||
<text class="artist-name">{{artistName}}</text>
|
||||
<text class="artist-desc">{{artistDesc}}</text>
|
||||
<view class="shop-link" bindtap="handleOpenShop">{{shopName}}</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="metrics">
|
||||
<view class="metric-item">
|
||||
<text>评分</text>
|
||||
<text class="metric-value">{{ratingText}}</text>
|
||||
</view>
|
||||
<view class="metric-item">
|
||||
<text>服务</text>
|
||||
<text class="metric-value">{{serviceCountText}}</text>
|
||||
</view>
|
||||
<view class="metric-item">
|
||||
<text>工时</text>
|
||||
<text class="metric-value">{{workTimeText}}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<view class="section-head">擅长风格</view>
|
||||
<view class="tag-list" wx:if="{{styleTags.length}}">
|
||||
<text class="tag" wx:for="{{styleTags}}" wx:key="*this">{{item}}</text>
|
||||
</view>
|
||||
<text wx:else class="empty-text">暂未设置风格标签</text>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<view class="section-head">近期可预约</view>
|
||||
<view class="slot-grid" wx:if="{{availability.length}}">
|
||||
<view class="slot" wx:for="{{availability}}" wx:key="startTime">
|
||||
<text>{{item.dateText}}</text>
|
||||
<text class="slot-time">{{item.timeText}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<text wx:else class="empty-text">近期暂未放出可预约时间</text>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<view class="section-head">作品</view>
|
||||
<view class="work-grid" wx:if="{{works.length}}">
|
||||
<view class="work-card" wx:for="{{works}}" wx:key="id" data-id="{{item.id}}" bindtap="handleOpenWork">
|
||||
<image src="{{item.coverImageUrl}}" mode="aspectFill"></image>
|
||||
<text class="work-title">{{item.title}}</text>
|
||||
<text class="work-price">{{item.priceText}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<text wx:else class="empty-text">作品正在整理中</text>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<view class="section-head">评价 {{reviews.length}}</view>
|
||||
<view class="review-list" wx:if="{{reviews.length}}">
|
||||
<view class="review-card" wx:for="{{reviews}}" wx:key="id">
|
||||
<view class="review-top">
|
||||
<image wx:if="{{item.customerAvatar}}" class="review-avatar" src="{{item.customerAvatar}}" mode="aspectFill"></image>
|
||||
<view wx:else class="review-avatar placeholder">客</view>
|
||||
<view class="review-meta">
|
||||
<text>{{item.customerName}}</text>
|
||||
<text>{{item.submittedAtText}}</text>
|
||||
</view>
|
||||
<text class="review-score">{{item.ratingText}}</text>
|
||||
</view>
|
||||
<text class="review-content">{{item.content}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<text wx:else class="empty-text">还没有公开评价</text>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
@@ -1,336 +0,0 @@
|
||||
.artist-page {
|
||||
min-height: 100vh;
|
||||
background: #f6f7fb;
|
||||
color: #1f2933;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 5;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
height: 96rpx;
|
||||
padding: 0 24rpx;
|
||||
background: rgba(255, 255, 255, 0.95);
|
||||
border-bottom: 1rpx solid #e6e9ef;
|
||||
}
|
||||
|
||||
.back-btn,
|
||||
.header-spacer {
|
||||
width: 64rpx;
|
||||
height: 64rpx;
|
||||
line-height: 58rpx;
|
||||
text-align: center;
|
||||
font-size: 48rpx;
|
||||
}
|
||||
|
||||
.page-title {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
text-align: center;
|
||||
font-size: 32rpx;
|
||||
font-weight: 700;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.content-scroll {
|
||||
height: calc(100vh - 96rpx);
|
||||
}
|
||||
|
||||
.state-box {
|
||||
display: flex;
|
||||
min-height: 60vh;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 20rpx;
|
||||
padding: 40rpx;
|
||||
color: #65717f;
|
||||
}
|
||||
|
||||
.state-title {
|
||||
color: #1f2933;
|
||||
font-size: 34rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.state-desc {
|
||||
text-align: center;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.primary-btn {
|
||||
padding: 18rpx 36rpx;
|
||||
color: #fff;
|
||||
background: var(--theme-primary-action);
|
||||
border-radius: 12rpx;
|
||||
}
|
||||
|
||||
.hero {
|
||||
position: relative;
|
||||
height: 520rpx;
|
||||
margin: 20rpx;
|
||||
overflow: hidden;
|
||||
background: #222831;
|
||||
border-radius: 16rpx;
|
||||
}
|
||||
|
||||
.hero-image,
|
||||
.hero-mask {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.hero-mask {
|
||||
background: linear-gradient(180deg, rgba(10, 14, 20, 0.08), rgba(10, 14, 20, 0.72));
|
||||
}
|
||||
|
||||
.artist-card {
|
||||
position: absolute;
|
||||
right: 28rpx;
|
||||
bottom: 28rpx;
|
||||
left: 28rpx;
|
||||
display: flex;
|
||||
gap: 22rpx;
|
||||
align-items: center;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 112rpx;
|
||||
height: 112rpx;
|
||||
flex: 0 0 auto;
|
||||
overflow: hidden;
|
||||
border: 3rpx solid rgba(255, 255, 255, 0.8);
|
||||
border-radius: 56rpx;
|
||||
}
|
||||
|
||||
.placeholder {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #d8dde6;
|
||||
color: #5f6b7a;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.artist-main {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.artist-name,
|
||||
.artist-desc,
|
||||
.shop-link {
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.artist-name {
|
||||
font-size: 44rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.artist-desc {
|
||||
margin-top: 10rpx;
|
||||
color: rgba(255, 255, 255, 0.88);
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.shop-link {
|
||||
max-width: 440rpx;
|
||||
margin-top: 16rpx;
|
||||
padding: 12rpx 18rpx;
|
||||
background: rgba(255, 255, 255, 0.18);
|
||||
border: 1rpx solid rgba(255, 255, 255, 0.28);
|
||||
border-radius: 12rpx;
|
||||
}
|
||||
|
||||
.metrics {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 16rpx;
|
||||
margin: 0 20rpx 20rpx;
|
||||
}
|
||||
|
||||
.metric-item {
|
||||
display: flex;
|
||||
min-height: 132rpx;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
gap: 10rpx;
|
||||
padding: 20rpx;
|
||||
background: #fff;
|
||||
border: 1rpx solid #e6e9ef;
|
||||
border-radius: 16rpx;
|
||||
}
|
||||
|
||||
.metric-item text:first-child {
|
||||
color: #65717f;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.metric-value {
|
||||
overflow-wrap: anywhere;
|
||||
font-size: 34rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.section {
|
||||
margin: 20rpx;
|
||||
padding: 28rpx;
|
||||
background: #fff;
|
||||
border: 1rpx solid #e6e9ef;
|
||||
border-radius: 16rpx;
|
||||
}
|
||||
|
||||
.section-head {
|
||||
margin-bottom: 20rpx;
|
||||
font-size: 32rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.tag-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 14rpx;
|
||||
}
|
||||
|
||||
.tag {
|
||||
padding: 10rpx 18rpx;
|
||||
color: #394554;
|
||||
background: #eef1f5;
|
||||
border-radius: 999rpx;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
color: #7b8794;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.slot-grid,
|
||||
.work-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
.slot {
|
||||
display: flex;
|
||||
min-height: 104rpx;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
gap: 8rpx;
|
||||
padding: 18rpx;
|
||||
background: #f6f7fb;
|
||||
border: 1rpx solid #dfe4ea;
|
||||
border-radius: 14rpx;
|
||||
}
|
||||
|
||||
.slot text:first-child {
|
||||
color: #65717f;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.slot-time {
|
||||
font-size: 32rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.work-card {
|
||||
overflow: hidden;
|
||||
background: #fff;
|
||||
border: 1rpx solid #e6e9ef;
|
||||
border-radius: 14rpx;
|
||||
}
|
||||
|
||||
.work-card image {
|
||||
width: 100%;
|
||||
height: 210rpx;
|
||||
background: #eef1f5;
|
||||
}
|
||||
|
||||
.work-title,
|
||||
.work-price {
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
padding: 0 16rpx;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.work-title {
|
||||
margin-top: 14rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.work-price {
|
||||
margin: 8rpx 0 16rpx;
|
||||
color: var(--theme-primary-action);
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.review-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18rpx;
|
||||
}
|
||||
|
||||
.review-card {
|
||||
padding: 22rpx;
|
||||
background: #f8fafc;
|
||||
border: 1rpx solid #e6e9ef;
|
||||
border-radius: 14rpx;
|
||||
}
|
||||
|
||||
.review-top {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
.review-avatar {
|
||||
width: 72rpx;
|
||||
height: 72rpx;
|
||||
border-radius: 36rpx;
|
||||
}
|
||||
|
||||
.review-meta {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.review-meta text {
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.review-meta text:last-child {
|
||||
margin-top: 4rpx;
|
||||
color: #7b8794;
|
||||
font-size: 22rpx;
|
||||
}
|
||||
|
||||
.review-score {
|
||||
color: var(--theme-primary-action);
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.review-content {
|
||||
display: block;
|
||||
margin-top: 18rpx;
|
||||
color: #3f4a56;
|
||||
line-height: 1.7;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
@@ -862,23 +862,8 @@ Page({
|
||||
await runWithLoading(() => paymentApi.prepareOrderPayment(orderId), {
|
||||
title: '准备支付'
|
||||
})
|
||||
const confirmed = await new Promise(resolve => {
|
||||
wx.showModal({
|
||||
title: '模拟支付',
|
||||
content: `本次需支付 ${order.paymentInfo.amountText},确认模拟支付成功吗?`,
|
||||
confirmText: '确认支付',
|
||||
success: res => resolve(Boolean(res.confirm)),
|
||||
fail: () => resolve(false)
|
||||
})
|
||||
})
|
||||
if (!confirmed) {
|
||||
return
|
||||
}
|
||||
await runWithLoading(() => paymentApi.mockOrderPaymentSuccess(orderId), {
|
||||
title: '确认支付'
|
||||
})
|
||||
wx.showToast({
|
||||
title: '支付已确认',
|
||||
title: '支付单已准备,请完成支付',
|
||||
icon: 'none'
|
||||
})
|
||||
await this.loadOrders()
|
||||
|
||||
@@ -113,14 +113,6 @@ function normalizeActionPath(value) {
|
||||
return `/pages/help/index${query}`
|
||||
}
|
||||
|
||||
if (pathOnly === '/artist-orders') {
|
||||
return `/pages/artist-orders/index${query}`
|
||||
}
|
||||
|
||||
if (pathOnly === '/artist-calendar') {
|
||||
return `/pages/artist-calendar/index${query}`
|
||||
}
|
||||
|
||||
if (pathOnly === '/settings/account') {
|
||||
return `/pages/account-settings/index${query}`
|
||||
}
|
||||
|
||||
+19
@@ -3,6 +3,8 @@ package com.xiaowang.jayucloud.salon.core.modules.order.controller.admin;
|
||||
import com.xiaowang.jayucloud.salon.core.annotation.RequirePermission;
|
||||
import com.xiaowang.jayucloud.salon.core.annotation.OperationGuard;
|
||||
import com.xiaowang.jayucloud.salon.core.common.Result;
|
||||
import com.xiaowang.jayucloud.salon.core.common.BusinessException;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderOfflinePaymentDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderQuoteSubmitDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.entity.UserDO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.service.OrderService;
|
||||
@@ -160,4 +162,21 @@ public class AdminOrderController {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
return Result.success(orderService.confirmShopQuote(id, currentUser.getId(), currentUser.getType()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 店长登记线下收款。当前仅支持 payMethod=OFFLINE,实收金额必须等于订单应付金额。
|
||||
*/
|
||||
@PostMapping("/{orderId}/offline-payment")
|
||||
@RequirePermission("order:process")
|
||||
@OperationGuard(action = "admin-order-offline-payment", ttlSeconds = 10, message = "收款登记处理中,请勿重复提交")
|
||||
public Result<OrderVO> registerOfflinePayment(HttpServletRequest request,
|
||||
@PathVariable Long orderId,
|
||||
@RequestBody OrderOfflinePaymentDTO dto) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
if (Integer.valueOf(3).equals(currentUser.getType())) {
|
||||
throw new BusinessException(403, "美甲师账号不能登记线下收款");
|
||||
}
|
||||
Long scopedShopId = adminScopeHelper.resolveShopScope(currentUser, null);
|
||||
return Result.success(orderService.registerOfflinePayment(orderId, currentUser.getId(), scopedShopId, dto));
|
||||
}
|
||||
}
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.xiaowang.jayucloud.salon.core.modules.order.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 线下收款登记入参。
|
||||
* 当前仅支持 payMethod=OFFLINE,paidAmount 必须与订单应付金额一致。
|
||||
*/
|
||||
@Data
|
||||
public class OrderOfflinePaymentDTO {
|
||||
private String payMethod;
|
||||
private BigDecimal paidAmount;
|
||||
private LocalDateTime paidAt;
|
||||
private String paidRemark;
|
||||
}
|
||||
+3
@@ -56,6 +56,9 @@ public class OrderDO extends BaseEntity {
|
||||
private String paymentMethod;
|
||||
private String paymentOrderNo;
|
||||
private String refundStatus;
|
||||
private Long paidBy;
|
||||
private String paidByType;
|
||||
private String paidRemark;
|
||||
private String customerRemark;
|
||||
private String cancelReason;
|
||||
private String customerNameSnapshot;
|
||||
|
||||
+3
@@ -21,6 +21,9 @@ public interface OrderMapper extends BaseMapper<OrderDO> {
|
||||
@Select("SELECT * FROM t_order WHERE order_no = #{orderNo}")
|
||||
OrderDO selectByOrderNo(@Param("orderNo") String orderNo);
|
||||
|
||||
@Select("SELECT * FROM t_order WHERE id = #{orderId} FOR UPDATE")
|
||||
OrderDO selectByIdForUpdate(@Param("orderId") Long orderId);
|
||||
|
||||
@Select("SELECT DISTINCT o.* FROM t_order o " +
|
||||
"INNER JOIN t_order_item oi ON o.id = oi.order_id " +
|
||||
"WHERE oi.artist_id = #{artistId} AND o.is_delete = 0 " +
|
||||
|
||||
+6
@@ -4,6 +4,7 @@ import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderArtistChangeRejectDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderArtistChangeRequestDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderArtistReviewSubmitDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderOfflinePaymentDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderQuoteReplyDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderQuoteSubmitDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.artist.vo.ArtistCalendarAppointmentVO;
|
||||
@@ -130,6 +131,11 @@ public interface OrderService {
|
||||
|
||||
OrderVO confirmShopQuote(Long orderId, Long operatorId, Integer operatorType);
|
||||
|
||||
/**
|
||||
* 登记线下收款。operatorShopId 为当前操作人的门店作用域,为空表示平台管理员。
|
||||
*/
|
||||
OrderVO registerOfflinePayment(Long orderId, Long operatorId, Long operatorShopId, OrderOfflinePaymentDTO dto);
|
||||
|
||||
OrderVO replyQuote(Long orderId, Long userId, OrderQuoteReplyDTO dto);
|
||||
|
||||
OrderVO confirmUserQuote(Long orderId, Long userId);
|
||||
|
||||
+95
-1
@@ -9,6 +9,7 @@ import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderArtistChangeReje
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderArtistChangeRequestDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderArtistReviewSubmitDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderItemDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderOfflinePaymentDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderQuoteItemDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderQuoteReplyDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderQuoteSubmitDTO;
|
||||
@@ -133,6 +134,10 @@ public class OrderServiceImpl implements OrderService {
|
||||
*/
|
||||
private static final String COUPON_SOURCE_SYSTEM_VIP = "SYSTEM_VIP";
|
||||
private static final int BOOKING_UNAVAILABLE_CODE = 409;
|
||||
private static final String PAYMENT_STATUS_UNPAID = "UNPAID";
|
||||
private static final String PAYMENT_STATUS_PAID = "PAID";
|
||||
private static final String PAYMENT_METHOD_OFFLINE = "OFFLINE";
|
||||
private static final String PAID_BY_TYPE_SHOP_MANAGER = "SHOP_MANAGER";
|
||||
private static final String ISSUE_ORDER_ITEM = "ORDER_ITEM";
|
||||
private static final String ISSUE_PRODUCT_UNAVAILABLE = "PRODUCT_UNAVAILABLE";
|
||||
private static final String ISSUE_SHOP_MISMATCH = "SHOP_MISMATCH";
|
||||
@@ -1454,6 +1459,9 @@ public class OrderServiceImpl implements OrderService {
|
||||
&& !"HISTORICAL_BACKFILL".equals(order.getOrderSource())) {
|
||||
throw new RuntimeException("普通预约不能进入服务中状态");
|
||||
}
|
||||
if (targetStatus == OrderStatus.COMPLETED) {
|
||||
ensurePaidBeforeCompletion(order);
|
||||
}
|
||||
if (!Integer.valueOf(OrderStatus.PENDING_SERVICE.getCode()).equals(order.getStatus())
|
||||
&& !(Integer.valueOf(OrderStatus.IN_SERVICE.getCode()).equals(order.getStatus())
|
||||
&& (status == OrderStatus.COMPLETED.getCode() || status == OrderStatus.CANCELLED.getCode()))
|
||||
@@ -1534,6 +1542,7 @@ public class OrderServiceImpl implements OrderService {
|
||||
*/
|
||||
throw new RuntimeException("当前订单状态不允许完成");
|
||||
}
|
||||
ensurePaidBeforeCompletion(order);
|
||||
|
||||
List<OrderItemDO> activeItems = orderItemMapper.selectByOrderId(orderId).stream()
|
||||
.filter(item -> !Integer.valueOf(1).equals(item.getIsDelete()))
|
||||
@@ -1808,6 +1817,75 @@ public class OrderServiceImpl implements OrderService {
|
||||
return buildOrderVO(orderMapper.selectById(order.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public OrderVO registerOfflinePayment(Long orderId, Long operatorId, Long operatorShopId, OrderOfflinePaymentDTO dto) {
|
||||
if (orderId == null) {
|
||||
throw new RuntimeException("订单ID不能为空");
|
||||
}
|
||||
if (dto == null) {
|
||||
throw new RuntimeException("收款登记信息不能为空");
|
||||
}
|
||||
String payMethod = dto.getPayMethod() == null ? "" : dto.getPayMethod().trim().toUpperCase();
|
||||
if (!PAYMENT_METHOD_OFFLINE.equals(payMethod)) {
|
||||
throw new RuntimeException("当前仅支持线下收款,payMethod 只能为 OFFLINE");
|
||||
}
|
||||
if (dto.getPaidAmount() == null) {
|
||||
throw new RuntimeException("实收金额不能为空");
|
||||
}
|
||||
if (dto.getPaidAmount().compareTo(BigDecimal.ZERO) < 0) {
|
||||
throw new RuntimeException("实收金额不能小于0");
|
||||
}
|
||||
String paidRemark = trimToNull(dto.getPaidRemark());
|
||||
if (paidRemark != null && paidRemark.length() > 500) {
|
||||
throw new RuntimeException("收款备注不能超过500个字符");
|
||||
}
|
||||
|
||||
OrderDO order = orderMapper.selectByIdForUpdate(orderId);
|
||||
if (order == null || Integer.valueOf(1).equals(order.getIsDelete())) {
|
||||
throw new RuntimeException("订单不存在");
|
||||
}
|
||||
if (operatorShopId != null && !operatorShopId.equals(order.getShopId())) {
|
||||
throw new BusinessException(403, "无权处理其他店铺订单");
|
||||
}
|
||||
if (Integer.valueOf(OrderStatus.CANCELLED.getCode()).equals(order.getStatus())) {
|
||||
throw new RuntimeException("订单已取消,不能登记收款");
|
||||
}
|
||||
|
||||
BigDecimal expectedAmount = order.getPayAmount() == null ? order.getActualAmount() : order.getPayAmount();
|
||||
if (expectedAmount == null) {
|
||||
expectedAmount = BigDecimal.ZERO;
|
||||
}
|
||||
if (dto.getPaidAmount().compareTo(expectedAmount) != 0) {
|
||||
throw new RuntimeException("实收金额必须等于订单应付金额 "
|
||||
+ expectedAmount.stripTrailingZeros().toPlainString() + " 元");
|
||||
}
|
||||
|
||||
LocalDateTime paidAt = (dto.getPaidAt() == null ? LocalDateTime.now() : dto.getPaidAt()).withNano(0);
|
||||
if (PAYMENT_STATUS_PAID.equals(order.getPaymentStatus())) {
|
||||
boolean sameMethod = PAYMENT_METHOD_OFFLINE.equals(order.getPaymentMethod());
|
||||
boolean sameAmount = order.getPaidAmount() != null && order.getPaidAmount().compareTo(dto.getPaidAmount()) == 0;
|
||||
boolean sameTime = order.getPayTime() != null && order.getPayTime().withNano(0).equals(paidAt);
|
||||
if (sameMethod && sameAmount && sameTime) {
|
||||
return buildOrderVO(order);
|
||||
}
|
||||
throw new RuntimeException("该订单已登记线下收款,金额或收款时间与首次登记不一致,不能重复登记");
|
||||
}
|
||||
if (order.getPaymentStatus() != null && !PAYMENT_STATUS_UNPAID.equals(order.getPaymentStatus())) {
|
||||
throw new RuntimeException("订单当前支付状态为 " + order.getPaymentStatus() + ",不能登记线下收款");
|
||||
}
|
||||
|
||||
order.setPaymentStatus(PAYMENT_STATUS_PAID);
|
||||
order.setPaymentMethod(PAYMENT_METHOD_OFFLINE);
|
||||
order.setPaidAmount(dto.getPaidAmount());
|
||||
order.setPayTime(paidAt);
|
||||
order.setPaidBy(operatorId);
|
||||
order.setPaidByType(PAID_BY_TYPE_SHOP_MANAGER);
|
||||
order.setPaidRemark(paidRemark);
|
||||
orderMapper.updateById(order);
|
||||
return buildOrderVO(order);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public OrderVO replyQuote(Long orderId, Long userId, OrderQuoteReplyDTO dto) {
|
||||
@@ -2258,9 +2336,18 @@ public class OrderServiceImpl implements OrderService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: trimToNull supports OrderServiceImpl.java by holding or executing the trim to null business role.
|
||||
* 完成订单前强制校验收款状态:未收款不得完成,不设任何豁免。
|
||||
* Usage: reference this method from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
/**
|
||||
* 完成订单前强制校验收款状态:未收款不得完成,不设任何豁免。
|
||||
*/
|
||||
private void ensurePaidBeforeCompletion(OrderDO order) {
|
||||
if (!PAYMENT_STATUS_PAID.equals(order.getPaymentStatus())) {
|
||||
throw new RuntimeException("订单未收款,不能完成;请先登记线下收款");
|
||||
}
|
||||
}
|
||||
|
||||
private String trimToNull(String value) {
|
||||
if (!StringUtils.hasText(value)) {
|
||||
return null;
|
||||
@@ -3284,6 +3371,13 @@ public class OrderServiceImpl implements OrderService {
|
||||
orderVO.setPaymentMethod(order.getPaymentMethod());
|
||||
orderVO.setPaymentOrderNo(order.getPaymentOrderNo());
|
||||
orderVO.setRefundStatus(order.getRefundStatus());
|
||||
orderVO.setPaidBy(order.getPaidBy());
|
||||
orderVO.setPaidByType(order.getPaidByType());
|
||||
orderVO.setPaidRemark(order.getPaidRemark());
|
||||
if (order.getPaidBy() != null) {
|
||||
UserDO payer = getUserFromCache(order.getPaidBy(), userCache);
|
||||
orderVO.setPaidByName(payer == null ? null : payer.getNickname());
|
||||
}
|
||||
orderVO.setCustomerRemark(order.getCustomerRemark());
|
||||
orderVO.setQuoteStatus(order.getQuoteStatus());
|
||||
orderVO.setQuoteStatusText(resolveQuoteStatusText(order.getQuoteStatus(), order.getStatus()));
|
||||
|
||||
+4
@@ -64,6 +64,10 @@ public class OrderVO {
|
||||
private String paymentMethod;
|
||||
private String paymentOrderNo;
|
||||
private String refundStatus;
|
||||
private Long paidBy;
|
||||
private String paidByName;
|
||||
private String paidByType;
|
||||
private String paidRemark;
|
||||
private String customerRemark;
|
||||
private String quoteStatus;
|
||||
private String orderSource;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
-- 订单线下收款登记:记录收款人、收款人类型与收款备注
|
||||
-- 说明:pay_time、payment_method、paid_amount、payment_status 已存在,本次不重复新增。
|
||||
|
||||
SET @column_exists = (
|
||||
SELECT COUNT(1) FROM information_schema.columns
|
||||
WHERE table_schema = DATABASE() AND table_name = 't_order' AND column_name = 'paid_by'
|
||||
);
|
||||
SET @migration_sql = IF(
|
||||
@column_exists = 0,
|
||||
'ALTER TABLE t_order ADD COLUMN paid_by BIGINT UNSIGNED NULL COMMENT ''收款登记人用户ID'' AFTER refund_status',
|
||||
'SELECT 1'
|
||||
);
|
||||
PREPARE migration_statement FROM @migration_sql;
|
||||
EXECUTE migration_statement;
|
||||
DEALLOCATE PREPARE migration_statement;
|
||||
|
||||
SET @column_exists = (
|
||||
SELECT COUNT(1) FROM information_schema.columns
|
||||
WHERE table_schema = DATABASE() AND table_name = 't_order' AND column_name = 'paid_by_type'
|
||||
);
|
||||
SET @migration_sql = IF(
|
||||
@column_exists = 0,
|
||||
'ALTER TABLE t_order ADD COLUMN paid_by_type VARCHAR(20) NULL COMMENT ''收款登记人类型,线下收款固定为 SHOP_MANAGER'' AFTER paid_by',
|
||||
'SELECT 1'
|
||||
);
|
||||
PREPARE migration_statement FROM @migration_sql;
|
||||
EXECUTE migration_statement;
|
||||
DEALLOCATE PREPARE migration_statement;
|
||||
|
||||
SET @column_exists = (
|
||||
SELECT COUNT(1) FROM information_schema.columns
|
||||
WHERE table_schema = DATABASE() AND table_name = 't_order' AND column_name = 'paid_remark'
|
||||
);
|
||||
SET @migration_sql = IF(
|
||||
@column_exists = 0,
|
||||
'ALTER TABLE t_order ADD COLUMN paid_remark VARCHAR(500) NULL COMMENT ''收款登记备注'' AFTER paid_by_type',
|
||||
'SELECT 1'
|
||||
);
|
||||
PREPARE migration_statement FROM @migration_sql;
|
||||
EXECUTE migration_statement;
|
||||
DEALLOCATE PREPARE migration_statement;
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
package com.xiaowang.jayucloud.salon.core.modules.order.service.impl;
|
||||
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderOfflinePaymentDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.entity.OrderDO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.mapper.OrderMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.support.OrderStatus;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class OrderServiceImplOfflinePaymentTest {
|
||||
|
||||
@Mock
|
||||
private OrderMapper orderMapper;
|
||||
|
||||
@InjectMocks
|
||||
private OrderServiceImpl service;
|
||||
|
||||
@Test
|
||||
void rejectsNonOfflinePaymentMethod() {
|
||||
OrderOfflinePaymentDTO dto = offlinePayment(new BigDecimal("100"), LocalDateTime.now());
|
||||
dto.setPayMethod("WECHAT");
|
||||
|
||||
RuntimeException error = assertThrows(RuntimeException.class,
|
||||
() -> service.registerOfflinePayment(1L, 9L, 2L, dto));
|
||||
|
||||
assertEquals("当前仅支持线下收款,payMethod 只能为 OFFLINE", error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsAmountMismatch() {
|
||||
OrderDO order = order(1L, OrderStatus.PENDING_SERVICE.getCode(), "UNPAID");
|
||||
order.setPayAmount(new BigDecimal("100.00"));
|
||||
when(orderMapper.selectByIdForUpdate(1L)).thenReturn(order);
|
||||
OrderOfflinePaymentDTO dto = offlinePayment(new BigDecimal("90"), LocalDateTime.now());
|
||||
|
||||
RuntimeException error = assertThrows(RuntimeException.class,
|
||||
() -> service.registerOfflinePayment(1L, 9L, 2L, dto));
|
||||
|
||||
assertEquals("实收金额必须等于订单应付金额 100 元", error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsCancelledOrder() {
|
||||
OrderDO order = order(1L, OrderStatus.CANCELLED.getCode(), "UNPAID");
|
||||
order.setPayAmount(new BigDecimal("100"));
|
||||
when(orderMapper.selectByIdForUpdate(1L)).thenReturn(order);
|
||||
OrderOfflinePaymentDTO dto = offlinePayment(new BigDecimal("100"), LocalDateTime.now());
|
||||
|
||||
RuntimeException error = assertThrows(RuntimeException.class,
|
||||
() -> service.registerOfflinePayment(1L, 9L, 2L, dto));
|
||||
|
||||
assertEquals("订单已取消,不能登记收款", error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsRepeatedRegistrationWithDifferentTime() {
|
||||
OrderDO order = order(1L, OrderStatus.PENDING_SERVICE.getCode(), "PAID");
|
||||
order.setPayAmount(new BigDecimal("100"));
|
||||
order.setPaymentMethod("OFFLINE");
|
||||
order.setPaidAmount(new BigDecimal("100"));
|
||||
order.setPayTime(LocalDateTime.of(2026, 11, 4, 10, 0, 0));
|
||||
when(orderMapper.selectByIdForUpdate(1L)).thenReturn(order);
|
||||
OrderOfflinePaymentDTO dto = offlinePayment(new BigDecimal("100"), LocalDateTime.of(2026, 11, 4, 11, 0, 0));
|
||||
|
||||
RuntimeException error = assertThrows(RuntimeException.class,
|
||||
() -> service.registerOfflinePayment(1L, 9L, 2L, dto));
|
||||
|
||||
assertEquals("该订单已登记线下收款,金额或收款时间与首次登记不一致,不能重复登记", error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsCompletingUnpaidOrder() {
|
||||
OrderDO order = order(1L, OrderStatus.PENDING_SERVICE.getCode(), "UNPAID");
|
||||
order.setOrderSource("NORMAL");
|
||||
when(orderMapper.selectById(1L)).thenReturn(order);
|
||||
|
||||
RuntimeException error = assertThrows(RuntimeException.class,
|
||||
() -> service.processOrder(1L, OrderStatus.COMPLETED.getCode()));
|
||||
|
||||
assertEquals("订单未收款,不能完成;请先登记线下收款", error.getMessage());
|
||||
}
|
||||
|
||||
private OrderOfflinePaymentDTO offlinePayment(BigDecimal amount, LocalDateTime paidAt) {
|
||||
OrderOfflinePaymentDTO dto = new OrderOfflinePaymentDTO();
|
||||
dto.setPayMethod("OFFLINE");
|
||||
dto.setPaidAmount(amount);
|
||||
dto.setPaidAt(paidAt);
|
||||
return dto;
|
||||
}
|
||||
|
||||
private OrderDO order(Long id, Integer status, String paymentStatus) {
|
||||
OrderDO order = new OrderDO();
|
||||
order.setId(id);
|
||||
order.setShopId(2L);
|
||||
order.setStatus(status);
|
||||
order.setPaymentStatus(paymentStatus);
|
||||
order.setIsDelete(0);
|
||||
return order;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,16 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://192.168.5.15:3306/jayucloud_artlist?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
||||
flyway:
|
||||
enabled: true
|
||||
locations: classpath:db/migration
|
||||
schemas: [jayucloud_artlist]
|
||||
default-schema: jayucloud_artlist
|
||||
create-schemas: false
|
||||
baseline-on-migrate: false
|
||||
validate-on-migrate: true
|
||||
clean-disabled: true
|
||||
out-of-order: false
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 5MB
|
||||
|
||||
@@ -2,7 +2,7 @@ spring:
|
||||
redis:
|
||||
host: 192.168.5.15
|
||||
port: 6379
|
||||
database: 0
|
||||
database: 1
|
||||
rabbitmq:
|
||||
addresses: 192.168.5.15:5672
|
||||
virtual-host: /jayucloud-artlist-dev
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://192.168.10.200:6033/jayucloud_artlist?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
||||
flyway:
|
||||
enabled: true
|
||||
locations: classpath:db/migration
|
||||
schemas: [jayucloud_artlist]
|
||||
default-schema: jayucloud_artlist
|
||||
create-schemas: false
|
||||
baseline-on-migrate: false
|
||||
validate-on-migrate: true
|
||||
clean-disabled: true
|
||||
out-of-order: false
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 5MB
|
||||
|
||||
@@ -3,7 +3,7 @@ spring:
|
||||
sentinel:
|
||||
master: mymaster
|
||||
nodes: 192.168.10.17:26379,192.168.10.18:26379,192.168.10.19:26379,192.168.20.13:26379,10.66.0.4:26379
|
||||
database: 0
|
||||
database: 1
|
||||
rabbitmq:
|
||||
addresses: mq-prod.internal:5672
|
||||
virtual-host: /jayucloud-artlist
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://192.168.10.11:3306/jayucloud_artlist?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
||||
flyway:
|
||||
enabled: true
|
||||
locations: classpath:db/migration
|
||||
schemas: [jayucloud_artlist]
|
||||
default-schema: jayucloud_artlist
|
||||
create-schemas: false
|
||||
baseline-on-migrate: false
|
||||
validate-on-migrate: true
|
||||
clean-disabled: true
|
||||
out-of-order: false
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 5MB
|
||||
|
||||
@@ -2,7 +2,7 @@ spring:
|
||||
redis:
|
||||
host: 192.168.10.12
|
||||
port: 6379
|
||||
database: 0
|
||||
database: 1
|
||||
rabbitmq:
|
||||
addresses: 192.168.10.13:5672
|
||||
virtual-host: /jayucloud-artlist-sit
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
# ArtList 数据迁移与会话隔离配置说明
|
||||
|
||||
- 日期:2026-11-04
|
||||
- 范围:`JC-ArtList-Core` 的 Flyway 数据库迁移接入、Redis 会话库隔离
|
||||
- 涉及配置:`nacos/namespaces/{dev,sit,prod}/jayucloud-artlist/DEFAULT_GROUP/core.yaml`、同目录 `infra.yaml`
|
||||
|
||||
## 一、本次改了什么
|
||||
|
||||
1. **接入 Flyway(dev/sit/prod 三环境一致)**
|
||||
- `JC-ArtList-Core/pom.xml` 增加 `flyway-core`、`flyway-mysql`,版本由 Spring Boot 2.7.18 统一管理(与 `JC-Salon-Core` 相同,不单独指定版本)。
|
||||
- `core.yaml` 新增 `spring.flyway`:
|
||||
- `enabled=true`、`locations=classpath:db/migration`
|
||||
- `schemas=[jayucloud_artlist]`、`default-schema=jayucloud_artlist`、`create-schemas=false`
|
||||
- `baseline-on-migrate=false`(**不使用 baseline**,空库直接从 `V1` 全量执行;不再配置 `baseline-version`,该属性仅在 baseline 时生效,保留只会误导后来人)
|
||||
- `validate-on-migrate=true`、`clean-disabled=true`、`out-of-order=false`
|
||||
- 新增迁移 `JC-ArtList-Core/src/main/resources/db/migration/V1__ArtList基线冻结_20261104.sql`,由 `docs/scripts/sql/init/jayucloud-artlist.sql` 规范化而来:建表 `IF NOT EXISTS`、索引经幂等存储过程创建、种子数据可重复执行、删除重复 DDL。**`V1` 即空库初始化脚本,后续结构/数据变更一律以版本化增量文件(`V2`、`V3`…)追加,不得修改或删除已执行的迁移文件。**
|
||||
|
||||
> **口径:不做数据迁移,空库从 V1 全量初始化。** 三个环境均按此口径执行,不存在“把存量库 baseline 到 V1”的场景。
|
||||
|
||||
2. **Redis 会话库迁移**
|
||||
- ArtList 的 `spring.redis.database` 从 `0` 改为 `1`,与 Salon 的 `0` 分开,避免两者会话 key 空间互相干扰。
|
||||
- 会话 key 前缀统一为 `artlist:auth:session:` 与 `artlist:auth:user:sessions:`,覆盖登录校验、刷新令牌、踢下线等全部读写路径。
|
||||
|
||||
## 二、三环境配置差异与同步状态
|
||||
|
||||
| 环境 | Flyway 配置 | Redis database | 同步状态 |
|
||||
| --- | --- | --- | --- |
|
||||
| dev | 已配置,`baseline-on-migrate=false`(空库从 V1 初始化) | 1(本机 Redis,单机) | 已同步 |
|
||||
| sit | 已配置,`baseline-on-migrate=false`(空库从 V1 初始化) | 1(本机 Redis,单机) | 已同步 |
|
||||
| prod | 已配置,`baseline-on-migrate=false`(空库从 V1 初始化) | 1(Sentinel 集群,仅库号变化) | 已同步 |
|
||||
|
||||
结构差异说明:dev/sit 的 Redis 为 `host + port` 单机配置,prod 为 `sentinel` 哨兵配置;本次仅改 `database` 数值,未改动连接方式与其他项。三个环境均无第二处 Redis 库号配置(`secret.yaml` 中只有账号密码,不涉及库号)。
|
||||
|
||||
## 三、上线影响
|
||||
|
||||
1. **Flyway 采用“空库初始化”口径**
|
||||
- 空库(schema 存在但无表、无 `flyway_schema_history`):启动后从 `V1` 全量执行建表与种子数据,并创建 `flyway_schema_history`。
|
||||
- **指向“已有表但没有 `flyway_schema_history`”的库**:`baseline-on-migrate=false` 时 Flyway 会做校验并发现 V1 与库中现状不一致,**validate 失败并拒绝启动**。这是预期行为,不是故障,也不代表配置写错。
|
||||
- 出现上述拒绝启动时,**正确做法是先清空/重建 `jayucloud_artlist` 再启动**(步骤见第四节),不要通过改回 baseline、删 `flyway_schema_history` 或手工填 history 来绕过。
|
||||
- `create-schemas=false`:schema 必须事先存在;`clean-disabled=true` 已禁止 Flyway 通过命令清库;`validate-on-migrate=true` 会在校验和不一致时阻止启动。
|
||||
|
||||
2. **Redis 换库会导致所有已登录用户掉线**
|
||||
- 切换后旧库(db 0)中的会话不再被读取,已登录用户需重新登录。
|
||||
- 本地 Caffeine 缓存随换库冷启动,首屏可能出现一次回源延迟。
|
||||
- 旧库中的历史会话 key 不会被自动清理,可按需手工清理。
|
||||
|
||||
## 四、dev 环境清库初始化步骤(操作建议,需人工执行)
|
||||
|
||||
> 本节仅为文档化操作建议,不会由任何流水线自动执行;执行前请确认目标实例与环境,避免误连 sit/prod。
|
||||
|
||||
1. **备份(不迁移数据,但建议留一份兜底)**
|
||||
```bash
|
||||
mysqldump -h <dev-mysql-host> -P <port> -u <user> -p \
|
||||
--single-transaction --routines --triggers --no-data \
|
||||
jayucloud_artlist > jayucloud_artlist_dev_struct_20261104.sql
|
||||
mysqldump -h <dev-mysql-host> -P <port> -u <user> -p \
|
||||
--single-transaction jayucloud_artlist > jayucloud_artlist_dev_full_20261104.sql
|
||||
```
|
||||
|
||||
2. **清空并重建 schema**
|
||||
```sql
|
||||
DROP DATABASE IF EXISTS jayucloud_artlist;
|
||||
CREATE DATABASE jayucloud_artlist
|
||||
DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
|
||||
```
|
||||
说明:`create-schemas=false`,Flyway 不会自动建库,必须先手工创建空 schema。
|
||||
|
||||
3. **发布配置并重启 `JC-ArtList-Core`**
|
||||
- 确认 Nacos 中 dev 的 `core.yaml` 已是 `baseline-on-migrate: false` 且不含 `baseline-version`。
|
||||
- 重启后 Flyway 从 `V1` 全量初始化。
|
||||
|
||||
4. **重启后确认**
|
||||
```sql
|
||||
SHOW TABLES FROM jayucloud_artlist LIKE 'flyway_schema_history';
|
||||
SELECT installed_rank, version, description, type, success
|
||||
FROM jayucloud_artlist.flyway_schema_history ORDER BY installed_rank;
|
||||
SELECT COUNT(*) FROM information_schema.tables
|
||||
WHERE table_schema = 'jayucloud_artlist' AND table_type = 'BASE TABLE';
|
||||
```
|
||||
预期:`flyway_schema_history` 存在;其中 `V1` 一条且 `success = 1`;业务表数量与 V1 建表数一致(表总数 = 业务表 + `flyway_schema_history`)。
|
||||
|
||||
## 五、回退方式
|
||||
|
||||
1. **数据库**:应用回退不会自动回滚数据库。如需撤销已执行的迁移,必须新增向前兼容的补偿迁移(新增 `V{n}` 脚本),禁止依赖 Flyway `clean`、重新 baseline 或重跑初始化脚本。
|
||||
2. **Redis**:将 `spring.redis.database` 改回 `0` 即可回退到旧库;回退同样会造成一次全员掉线(新库中的会话不再被读取)。
|
||||
3. **配置回退**:dev/sit/prod 的 Nacos 配置可通过仓库内各自的 Nacos 回退工作流恢复到上一个快照。
|
||||
|
||||
## 六、验证步骤
|
||||
|
||||
1. 推送配置后确认 Nacos 中对应环境的 `core.yaml`:`baseline-on-migrate=false`、无 `baseline-version`,其余 Flyway 项与本文第一节一致;`infra.yaml` 的 `database` 为 `1`。
|
||||
2. 在测试环境使用临时空库验证 `V1` 可完整执行(参考做法:新建临时库,以 `locations=classpath:db/migration` 运行 Flyway,确认建表数量与种子数据后删除临时库)。
|
||||
3. 启动 `JC-ArtList-Core`,检查日志中 Flyway 迁移记录与 `flyway_schema_history` 内容。
|
||||
4. 重新登录一次,确认会话写入 Redis `db 1`(`INFO keyspace` 或 `KEYS artlist:auth:session:*` 使用 `-n 1`)。
|
||||
5. 验证旧登录态确实失效(使用旧 token 请求应返回未登录)。
|
||||
Reference in New Issue
Block a user