|
@@ -2,6 +2,7 @@ package com.ylx.order.service.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -20,19 +21,26 @@ import com.ylx.massage.service.IMaTechnicianService;
|
|
|
import com.ylx.massage.service.TAddressService;
|
|
import com.ylx.massage.service.TAddressService;
|
|
|
import com.ylx.massage.utils.OrderNumberGenerator;
|
|
import com.ylx.massage.utils.OrderNumberGenerator;
|
|
|
import com.ylx.order.domain.TOrder;
|
|
import com.ylx.order.domain.TOrder;
|
|
|
|
|
+import com.ylx.order.domain.dto.OrderDateQueryDTO;
|
|
|
import com.ylx.order.domain.dto.OrderSubmitDTO;
|
|
import com.ylx.order.domain.dto.OrderSubmitDTO;
|
|
|
|
|
+import com.ylx.order.domain.vo.OrderDateQueryVo;
|
|
|
|
|
+import com.ylx.order.enums.OrderStatusEnum;
|
|
|
import com.ylx.order.mapper.TOrderMapper;
|
|
import com.ylx.order.mapper.TOrderMapper;
|
|
|
import com.ylx.order.service.TOrderService;
|
|
import com.ylx.order.service.TOrderService;
|
|
|
import com.ylx.project.domain.Project;
|
|
import com.ylx.project.domain.Project;
|
|
|
import com.ylx.project.service.ProjectService;
|
|
import com.ylx.project.service.ProjectService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
|
|
+import java.time.LocalTime;
|
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -42,6 +50,8 @@ import java.util.*;
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements TOrderService {
|
|
public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements TOrderService {
|
|
|
|
|
|
|
|
|
|
+ private final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("M月d日");
|
|
|
|
|
+ private final DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm");
|
|
|
@Resource
|
|
@Resource
|
|
|
private ProjectService projectService;
|
|
private ProjectService projectService;
|
|
|
@Resource
|
|
@Resource
|
|
@@ -292,4 +302,114 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
|
|
|
throw new ServiceException("添加订单失败");
|
|
throw new ServiceException("添加订单失败");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 用户端订单列表
|
|
|
|
|
+ * @param dto
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Page<OrderDateQueryVo> queryOrderList(OrderDateQueryDTO dto) {
|
|
|
|
|
+ // 1. 构造分页对象
|
|
|
|
|
+ Page<TOrder> page = new Page<>(dto.getPageNum(), dto.getPageSize());
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 构造查询条件
|
|
|
|
|
+ LambdaQueryWrapper<TOrder> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ if (dto.getStartDate() != null) {
|
|
|
|
|
+ LocalDateTime start = dto.getStartDate().atStartOfDay();
|
|
|
|
|
+ wrapper.ge(TOrder::getCreateTime, start);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (dto.getEndDate() != null) {
|
|
|
|
|
+ LocalDateTime end = dto.getEndDate().atTime(LocalTime.MAX);
|
|
|
|
|
+ wrapper.le(TOrder::getCreateTime, end);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StrUtil.isNotBlank(dto.getProjectName())) {
|
|
|
|
|
+ wrapper.like(TOrder::getProjectName, dto.getProjectName());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StrUtil.isNotBlank(dto.getMerchantNickName())) {
|
|
|
|
|
+ wrapper.like(TOrder::getMerchantNickName, dto.getMerchantNickName());
|
|
|
|
|
+ }
|
|
|
|
|
+ wrapper.eq(TOrder::getIsDelete, 0);
|
|
|
|
|
+ wrapper.orderByDesc(TOrder::getCreateTime);
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 执行分页查询
|
|
|
|
|
+ Page<TOrder> orderPage = baseMapper.selectPage(page, wrapper);
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 转换 VO
|
|
|
|
|
+ List<OrderDateQueryVo> voList = orderPage.getRecords().stream()
|
|
|
|
|
+ .map(this::convertToVo)
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 返回分页结果
|
|
|
|
|
+
|
|
|
|
|
+ Page<OrderDateQueryVo> voPage = new Page<>(orderPage.getCurrent(), orderPage.getSize(), orderPage.getTotal());
|
|
|
|
|
+ voPage.setRecords(voList);
|
|
|
|
|
+
|
|
|
|
|
+ return voPage;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 用户端逻辑删除
|
|
|
|
|
+ * @param orderId
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void logicDeleteOrder(Long orderId) {
|
|
|
|
|
+ // 1. 查询订单是否存在
|
|
|
|
|
+ TOrder order = getById(orderId);
|
|
|
|
|
+ if (order == null) {
|
|
|
|
|
+ throw new ServiceException("订单不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 如果已经是删除状态,可提示或直接返回
|
|
|
|
|
+ if (Integer.valueOf(1).equals(order.getIsDelete())) {
|
|
|
|
|
+ throw new ServiceException("订单已在回收站中");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 执行逻辑删除
|
|
|
|
|
+ order.setIsDelete(1);
|
|
|
|
|
+ order.setDeletedTime(LocalDateTime.now());
|
|
|
|
|
+ boolean updated = updateById(order);
|
|
|
|
|
+ if (!updated) {
|
|
|
|
|
+ throw new ServiceException("删除失败,请稍后重试");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 5. 事务成功,返回(Controller中会返回 success 信息)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 将 TOrder 转换为 OrderDateQueryVo,并处理 serviceTime 字段
|
|
|
|
|
+ */
|
|
|
|
|
+ private OrderDateQueryVo convertToVo(TOrder order) {
|
|
|
|
|
+ OrderDateQueryVo vo = new OrderDateQueryVo();
|
|
|
|
|
+ // 拷贝相同字段
|
|
|
|
|
+ BeanUtils.copyProperties(order, vo);
|
|
|
|
|
+ // 手动设置字段名不一致或需要特殊处理的
|
|
|
|
|
+ vo.setOrderStatus(order.getStatus());
|
|
|
|
|
+ vo.setOrderStatusName(getOrderStatusName(order.getStatus()));
|
|
|
|
|
+ // 服务时间范围:预约开始时间 + 项目时长(分钟)
|
|
|
|
|
+ // 使用 startTime 和 completedTime 构建服务时间展示
|
|
|
|
|
+ String serviceTime = buildServiceTime(order.getStartTime(), order.getCompletedTime());
|
|
|
|
|
+ vo.setServiceTime(serviceTime);
|
|
|
|
|
+
|
|
|
|
|
+ return vo;
|
|
|
|
|
+ }
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 订单状态码 -> 中文描述
|
|
|
|
|
+ */
|
|
|
|
|
+ private String getOrderStatusName(Integer status) {
|
|
|
|
|
+ return OrderStatusEnum.getInfoByCode(status);
|
|
|
|
|
+ }
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 拼接服务时间字符串,例如 “2026-06-08 14:30 (90分钟)”
|
|
|
|
|
+ */
|
|
|
|
|
+ private String buildServiceTime(LocalDateTime startTime, LocalDateTime completedTime) {
|
|
|
|
|
+ if (startTime == null || completedTime == null) {
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+ String date = startTime.format(dateFormatter);
|
|
|
|
|
+ String start = startTime.format(timeFormatter);
|
|
|
|
|
+ String end = completedTime.format(timeFormatter);
|
|
|
|
|
+ return date + " " + start + "-" + end;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|