From ebc7688451b6b69605050bf481ff25e5814e2e12 Mon Sep 17 00:00:00 2001 From: chen-xin-zhi <3588068430@qq.com> Date: Sat, 9 Nov 2024 19:33:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E4=BA=86=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/order/OrderController.java | 61 ------------------- .../model/dto/order/OrderAddRequest.java | 7 +++ .../model/dto/order/OrderItemAddRequest.java | 14 +++++ .../model/dto/order/OrderQueryRequest.java | 7 +++ .../capital/OrderItemMainInfoAddRequest.java | 13 ++++ .../capital/OrderMainInfoAddRequest.java | 7 +++ .../cultural/heritage/model/entity/Order.java | 5 ++ .../heritage/model/entity/OrderItems.java | 13 ++++ .../service/order/impl/OrderServiceImpl.java | 28 +++++++-- src/main/resources/application.yml | 2 + .../java/com/cultural/heritage/test/Test.java | 24 +++----- 11 files changed, 99 insertions(+), 82 deletions(-) diff --git a/src/main/java/com/cultural/heritage/controller/order/OrderController.java b/src/main/java/com/cultural/heritage/controller/order/OrderController.java index 92bd743..b766a64 100644 --- a/src/main/java/com/cultural/heritage/controller/order/OrderController.java +++ b/src/main/java/com/cultural/heritage/controller/order/OrderController.java @@ -49,47 +49,6 @@ public class OrderController { @Resource private OrderItemService orderItemService; -// -// /** -// * 用户创建订单 -// * @param orderAddRequest 订单创建请求体 -// * @return 是否创建成功 -// */ -// @PostMapping("/add") -// @Operation(summary = "小程序端创建用户订单", description = "参数:订单创建请求体,权限:所有人,方法名:addOrder") -// public BaseResponse addOrder(@RequestBody OrderAddRequest orderAddRequest) { -// if (orderAddRequest == null) { -// throw new BusinessException(ErrorCode.PARAMS_ERROR); -// } -// Order order = new Order(); -// BeanUtils.copyProperties(orderAddRequest, order); -// boolean save = orderService.save(order); -// ThrowUtils.throwIf(!save, ErrorCode.OPERATION_ERROR); -// return ResultUtils.success(order.getId()); -// } -// -// -// /** -// * 用户添加订单明细 -// * @param orderItemAddRequestList 订单明细添加请求体 -// * @return 是否添加成功 -// */ -// @PostMapping("/add/item") -// @Operation(summary = "小程序端批量添加用户订单明细", description = "参数:订单明细添加请求体,权限:所有人,方法名:addOrderItem") -// public BaseResponse addOrderItem(@RequestBody List orderItemAddRequestList) { -// if (CollectionUtils.isEmpty(orderItemAddRequestList)) { -// throw new BusinessException(ErrorCode.PARAMS_ERROR); -// } -// List orderItems = orderItemAddRequestList.stream().map(orderItemAddRequest -> { -// OrderItem orderItem = new OrderItem(); -// BeanUtils.copyProperties(orderItemAddRequest, orderItem); -// return orderItem; -// }).toList(); -// boolean result = orderItemService.saveBatch(orderItems); -// ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR); -// return ResultUtils.success(true, "添加订单明细成功"); -// } - /** * 用户创建订单 @@ -168,26 +127,6 @@ public class OrderController { } -// -// /** -// * 查询当前订单的订单明细 -// * @param orderIdRequest 订单编号请求体 -// * @return 订单明细列表信息 -// */ -// @PostMapping("/list/item") -// @Operation(summary = "Web端管理员查询订单明细", description = "参数:订单编号请求体,权限:管理员(admin, boss),方法名:listOrderItem") -// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) -// public BaseResponse> listOrderItem(@RequestBody CommonRequest orderIdRequest) { -// if (orderIdRequest == null || orderIdRequest.getId() <= 0) { -// throw new BusinessException(ErrorCode.PARAMS_ERROR); -// } -// Long id = orderIdRequest.getId(); -// QueryWrapper queryWrapper = new QueryWrapper<>(); -// queryWrapper.eq("orderId", id); -// List list = orderItemService.list(queryWrapper); -// return ResultUtils.success(list); -// } -// /** * 小程序端用户查询订单 diff --git a/src/main/java/com/cultural/heritage/model/dto/order/OrderAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/order/OrderAddRequest.java index 615c6d7..45e047a 100644 --- a/src/main/java/com/cultural/heritage/model/dto/order/OrderAddRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/order/OrderAddRequest.java @@ -16,6 +16,13 @@ import java.util.List; public class OrderAddRequest implements Serializable { + /** + * 订单类别 + */ + @Schema(description = "订单类别", example = "product") + private String orderType; + + /** * 用户id */ diff --git a/src/main/java/com/cultural/heritage/model/dto/order/OrderItemAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/order/OrderItemAddRequest.java index eaae0d6..a36322f 100644 --- a/src/main/java/com/cultural/heritage/model/dto/order/OrderItemAddRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/order/OrderItemAddRequest.java @@ -47,6 +47,20 @@ public class OrderItemAddRequest implements Serializable { private Double itemTotalAmount; + /** + * 预约日期 + */ + @Schema(description = "预约日期", example = "2024-11-09") + private String reservationDate; + + + /** + * 预约的具体时间段 + */ + @Schema(description = "预约的具体时间段", example = "8:00-12:00") + private String timeSlot; + + @Serial private static final long serialVersionUID = 1L; } diff --git a/src/main/java/com/cultural/heritage/model/dto/order/OrderQueryRequest.java b/src/main/java/com/cultural/heritage/model/dto/order/OrderQueryRequest.java index 991466c..d70068f 100644 --- a/src/main/java/com/cultural/heritage/model/dto/order/OrderQueryRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/order/OrderQueryRequest.java @@ -14,6 +14,13 @@ import java.util.Date; public class OrderQueryRequest extends PageRequest implements Serializable { + /** + * 订单类别 + */ + @Schema(description = "订单类别", example = "product") + private String orderType; + + /** * 用户id */ diff --git a/src/main/java/com/cultural/heritage/model/dto/order/capital/OrderItemMainInfoAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/order/capital/OrderItemMainInfoAddRequest.java index 5dfae5f..8d781d8 100644 --- a/src/main/java/com/cultural/heritage/model/dto/order/capital/OrderItemMainInfoAddRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/order/capital/OrderItemMainInfoAddRequest.java @@ -25,6 +25,19 @@ public class OrderItemMainInfoAddRequest implements Serializable { private Integer quantity; + /** + * 预约日期 + */ + @Schema(description = "预约日期", example = "2024-11-09") + private String reservationDate; + + + /** + * 预约的具体时间段 + */ + @Schema(description = "预约的具体时间段", example = "8:00-12:00") + private String timeSlot; + @Serial private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/cultural/heritage/model/dto/order/capital/OrderMainInfoAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/order/capital/OrderMainInfoAddRequest.java index d7196d5..ba612d5 100644 --- a/src/main/java/com/cultural/heritage/model/dto/order/capital/OrderMainInfoAddRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/order/capital/OrderMainInfoAddRequest.java @@ -20,6 +20,13 @@ public class OrderMainInfoAddRequest implements Serializable { private Long userId; + /** + * 订单类别 + */ + @Schema(description = "订单类别", example = "product") + private String orderType; + + /** * 用户昵称 */ diff --git a/src/main/java/com/cultural/heritage/model/entity/Order.java b/src/main/java/com/cultural/heritage/model/entity/Order.java index 6c5851c..d72ee77 100644 --- a/src/main/java/com/cultural/heritage/model/entity/Order.java +++ b/src/main/java/com/cultural/heritage/model/entity/Order.java @@ -32,6 +32,11 @@ public class Order implements Serializable { @TableId(type = IdType.AUTO) private Long id; + /** + * 订单类别 + */ + private String orderType; + /** * 订单编号 */ diff --git a/src/main/java/com/cultural/heritage/model/entity/OrderItems.java b/src/main/java/com/cultural/heritage/model/entity/OrderItems.java index 76426b0..c9279cc 100644 --- a/src/main/java/com/cultural/heritage/model/entity/OrderItems.java +++ b/src/main/java/com/cultural/heritage/model/entity/OrderItems.java @@ -63,6 +63,19 @@ public class OrderItems implements Serializable { @Schema(description = "订单项金额(单价 * 数量)", example = "55.00") private Double itemTotalAmount; + /** + * 预约日期 + */ + @Schema(description = "预约日期", example = "2024-11-09") + private String reservationDate; + + + /** + * 预约的具体时间段 + */ + @Schema(description = "预约的具体时间段", example = "8:00-12:00") + private String timeSlot; + @Serial private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/cultural/heritage/service/order/impl/OrderServiceImpl.java b/src/main/java/com/cultural/heritage/service/order/impl/OrderServiceImpl.java index cc0a643..e6af81e 100644 --- a/src/main/java/com/cultural/heritage/service/order/impl/OrderServiceImpl.java +++ b/src/main/java/com/cultural/heritage/service/order/impl/OrderServiceImpl.java @@ -17,7 +17,8 @@ import com.cultural.heritage.model.dto.snapshot.AddressSnapshot; import com.cultural.heritage.model.dto.snapshot.ContactsSnapshot; import com.cultural.heritage.model.dto.snapshot.CouponSnapshot; import com.cultural.heritage.model.dto.snapshot.GoodSnapshot; -import com.cultural.heritage.model.entity.*; +import com.cultural.heritage.model.entity.Order; +import com.cultural.heritage.model.enums.GoodTypeEnum; import com.cultural.heritage.service.order.OrderService; import com.cultural.heritage.utils.SqlUtils; import jakarta.annotation.Resource; @@ -68,12 +69,15 @@ public class OrderServiceImpl extends ServiceImpl implements Date endTime = orderQueryRequest.getEndTime(); String sortOrder = orderQueryRequest.getSortOrder(); String sortField = orderQueryRequest.getSortField(); + String orderType = orderQueryRequest.getOrderType(); + QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq(ObjectUtils.isNotEmpty(userId), "userId", userId); queryWrapper.eq(ObjectUtils.isNotEmpty(orderId), "id", orderId); queryWrapper.ge(ObjectUtils.isNotEmpty(minTotalAmount), "totalAmount", minTotalAmount); queryWrapper.le(ObjectUtils.isNotEmpty(maxTotalAmount), "totalAmount", maxTotalAmount); queryWrapper.eq(StringUtils.isNotBlank(orderStatus), "orderStatus", orderStatus); + queryWrapper.eq(StringUtils.isNotBlank(orderType), "orderType", orderType); queryWrapper.between(startTime != null && endTime != null, "createTime", startTime, endTime); queryWrapper.eq(StringUtils.isNotBlank(orderNumber), "orderNumber", orderNumber); queryWrapper.orderBy(SqlUtils.validSortField(sortField), sortOrder.equals(CommonConstant.SORT_ORDER_ASC), @@ -92,18 +96,27 @@ public class OrderServiceImpl extends ServiceImpl implements Long addressId = orderMainInfoAddRequest.getAddressId(); Long contactsId = orderMainInfoAddRequest.getContactsId(); Long couponId = orderMainInfoAddRequest.getCouponId(); + String orderType = orderMainInfoAddRequest.getOrderType(); String orderNumber = orderMainInfoAddRequest.getOrderNumber(); String orderStatus = orderMainInfoAddRequest.getOrderStatus(); String note = orderMainInfoAddRequest.getNote(); Double totalAmount = orderMainInfoAddRequest.getTotalAmount(); List orderItemMainInfoAddRequestList = orderMainInfoAddRequest.getOrderItemMainInfoAddRequestList(); + + GoodTypeEnum orderTypeEnum = GoodTypeEnum.getEnumByValue(orderType); + ThrowUtils.throwIf(orderTypeEnum == null, ErrorCode.PARAMS_ERROR); + AddressSnapshot addressSnapshot = null; + ContactsSnapshot contactsSnapshot = null; + // 获取订单地址信息 - AddressSnapshot addressSnapshot = getSnapshot(addressId, addressMapper, AddressSnapshot.class); - + if (orderTypeEnum.equals(GoodTypeEnum.PRODUCT)) { + addressSnapshot = getSnapshot(addressId, addressMapper, AddressSnapshot.class); + } // 获取订单联系人信息 - ContactsSnapshot contactsSnapshot = getSnapshot(contactsId, contactsMapper, ContactsSnapshot.class); - + if (orderTypeEnum.equals(GoodTypeEnum.SERVICE)) { + contactsSnapshot = getSnapshot(contactsId, contactsMapper, ContactsSnapshot.class); + } // 获取订单优惠券信息 CouponSnapshot couponSnapshot = getSnapshot(couponId, couponMapper, CouponSnapshot.class); @@ -111,6 +124,8 @@ public class OrderServiceImpl extends ServiceImpl implements List orderItemAddRequestList = orderItemMainInfoAddRequestList.stream().map(orderItemMainInfoAddRequest -> { Long goodId = orderItemMainInfoAddRequest.getGoodId(); Integer quantity = orderItemMainInfoAddRequest.getQuantity(); + String reservationDate = orderItemMainInfoAddRequest.getReservationDate(); + String timeSlot = orderItemMainInfoAddRequest.getTimeSlot(); OrderItemAddRequest orderItemAddRequest = new OrderItemAddRequest(); // 获取订单商品信息 GoodSnapshot goodSnapshot = getSnapshot(goodId, goodMapper, GoodSnapshot.class); @@ -119,6 +134,8 @@ public class OrderServiceImpl extends ServiceImpl implements orderItemAddRequest.setPriceSnapshot(goodSnapshot.getPrice()); orderItemAddRequest.setQuantity(quantity); orderItemAddRequest.setItemTotalAmount(goodSnapshot.getPrice() * quantity); + orderItemAddRequest.setReservationDate(reservationDate); + orderItemAddRequest.setTimeSlot(timeSlot); return orderItemAddRequest; }).toList(); @@ -128,6 +145,7 @@ public class OrderServiceImpl extends ServiceImpl implements orderAddRequest.setUserName(userName); orderAddRequest.setOrderNumber(orderNumber); orderAddRequest.setOrderStatus(orderStatus); + orderAddRequest.setOrderType(orderType); orderAddRequest.setNote(note); orderAddRequest.setTotalAmount(totalAmount); orderAddRequest.setAddressSnapshot(addressSnapshot); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 7e8a39f..7be0d24 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -4,6 +4,8 @@ spring: url: jdbc:mysql://154.8.193.216:3306/feiyi?serverTimezone=Asia/Shanghai username: feiyi password: 123456asd + hikari: + max-lifetime: 120000 data: redis: port: 6379 diff --git a/src/test/java/com/cultural/heritage/test/Test.java b/src/test/java/com/cultural/heritage/test/Test.java index 6790bbe..c9df267 100644 --- a/src/test/java/com/cultural/heritage/test/Test.java +++ b/src/test/java/com/cultural/heritage/test/Test.java @@ -1,28 +1,20 @@ package com.cultural.heritage.test; -import com.cultural.heritage.model.entity.Order; -import org.apache.commons.lang3.ObjectUtils; -import org.springframework.beans.BeanUtils; - -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.List; - public class Test { public static void main(String[] args) { // Date date = new Date(); // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // String format = sdf.format(date); // System.out.println(format); +// +// List list = new ArrayList<>(); +// System.out.println(ObjectUtils.isEmpty(list)); +// Date date = new Date(); +// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); +// String format = sdf.format(date); +// System.out.println(format); - List list = new ArrayList<>(); - System.out.println(ObjectUtils.isEmpty(list)); - Date date = new Date(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - String format = sdf.format(date); - System.out.println(format); +// System.out.println(StringUtils.isBlank(null)); } }