Skip to content

Commit

Permalink
feature: 商城 BFF 层开发根据用户 ID 查询订单列表 (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
magestacks committed Apr 18, 2023
1 parent 8bbe05f commit d456eb7
Show file tree
Hide file tree
Showing 10 changed files with 530 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.opengoofy.congomall.bff.biz.dto.resp.adapter;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.util.Date;
import java.util.List;

/**
* 订单适配返回对象
*
* @author chen.ma
* @github <a href="https://github.com/opengoofy" />
* @公众号 马丁玩编程,关注回复:资料,领取后端技术专家成长手册
*/
@Data
public class OrderAdapterRespDTO {

private String orderId;

private String orderStatus;

private Integer orderTotal;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
private Date payDate;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
private Date closeDate;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
private Date createDate;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
private Date finishDate;

private List<OrderGoodsAdapterRespDTO> goodsList;

private OrderAddressAdapterRespDTO addressInfo;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.opengoofy.congomall.bff.biz.dto.resp.adapter;

import lombok.Data;

/**
* 订单地址适配返回对象
*
* @author chen.ma
* @github <a href="https://github.com/opengoofy" />
* @公众号 马丁玩编程,关注回复:资料,领取后端技术专家成长手册
*/
@Data
public class OrderAddressAdapterRespDTO {

private String addressId;

private Integer isDefault;

private String streetName;

private String tel;

private String userId;

private String userName;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.opengoofy.congomall.bff.biz.dto.resp.adapter;

import lombok.Data;

/**
* 订单商品适配返回对象
*
* @author chen.ma
* @github <a href="https://github.com/opengoofy" />
* @公众号 马丁玩编程,关注回复:资料,领取后端技术专家成长手册
*/
@Data
public class OrderGoodsAdapterRespDTO {

private Integer checked;

private Integer limitNum;

private String productId;

private String productImg;

private String productName;

private Integer productNum;

private Integer salePrice;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.opengoofy.congomall.bff.biz.dto.resp.adapter;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
* 订单返回包装适配返回
*
* @author chen.ma
* @github <a href="https://github.com/opengoofy" />
* @公众号 马丁玩编程,关注回复:资料,领取后端技术专家成长手册
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class OrderResultAdapterRespDTO {

private Integer total;

private List<OrderAdapterRespDTO> data;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.opengoofy.congomall.bff.biz.service;

import org.opengoofy.congomall.bff.biz.dto.req.adapter.OrderCreateAdapterReqDTO;
import org.opengoofy.congomall.bff.biz.dto.resp.adapter.OrderResultAdapterRespDTO;

/**
* 订单接口
Expand All @@ -35,4 +36,14 @@ public interface OrderService {
* @return 订单号
*/
String addOrder(OrderCreateAdapterReqDTO requestParam);

/**
* 订单列表查看
*
* @param page 当前页
* @param size 每页多少条
* @param userId 用户 ID
* @return 订单列表返回数据
*/
OrderResultAdapterRespDTO listOrder(Integer page, Integer size, String userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,23 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.opengoofy.congomall.bff.biz.dto.req.adapter.OrderCreateAdapterReqDTO;
import org.opengoofy.congomall.bff.biz.dto.resp.adapter.OrderAdapterRespDTO;
import org.opengoofy.congomall.bff.biz.dto.resp.adapter.OrderAddressAdapterRespDTO;
import org.opengoofy.congomall.bff.biz.dto.resp.adapter.OrderGoodsAdapterRespDTO;
import org.opengoofy.congomall.bff.biz.dto.resp.adapter.OrderResultAdapterRespDTO;
import org.opengoofy.congomall.bff.biz.service.OrderService;
import org.opengoofy.congomall.bff.remote.OrderRemoteService;
import org.opengoofy.congomall.bff.remote.ProductCartRemoteService;
import org.opengoofy.congomall.bff.remote.req.OrderCreateCommand;
import org.opengoofy.congomall.bff.remote.resp.CartItemQuerySelectRespDTO;
import org.opengoofy.congomall.bff.remote.resp.OrderProductRespDTO;
import org.opengoofy.congomall.bff.remote.resp.OrderRespDTO;
import org.opengoofy.congomall.springboot.starter.convention.exception.ServiceException;
import org.opengoofy.congomall.springboot.starter.convention.result.Result;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
Expand All @@ -50,7 +57,7 @@ public class OrderServiceImpl implements OrderService {
@Override
public String addOrder(OrderCreateAdapterReqDTO requestParam) {
List<CartItemQuerySelectRespDTO> userCartList;
Result<List<CartItemQuerySelectRespDTO>> selectCartListResult = null;
Result<List<CartItemQuerySelectRespDTO>> selectCartListResult;
try {
selectCartListResult = productCartRemoteService.querySelectCartByCustomerUserId(requestParam.getUserId());
if (!selectCartListResult.isSuccess() || selectCartListResult.getData() == null) {
Expand Down Expand Up @@ -89,4 +96,48 @@ public String addOrder(OrderCreateAdapterReqDTO requestParam) {
}
return orderCreateRemoteResult.getData();
}

@Override
public OrderResultAdapterRespDTO listOrder(Integer page, Integer size, String userId) {
Result<List<OrderRespDTO>> orderListRemoteResult;
List<OrderRespDTO> orderList;
try {
// TODO 订单服务需提供分页查询接口
orderListRemoteResult = orderRemoteService.getOrderByCustomerUserId(userId);
if (!orderListRemoteResult.isSuccess() || orderListRemoteResult.getData() == null) {
throw new ServiceException("调用订单服务查询订单失败");
}
orderList = orderListRemoteResult.getData();
} catch (Throwable ex) {
log.error("调用订单服务查询订单失败", ex);
throw ex;
}
List<OrderAdapterRespDTO> orderListResult = new ArrayList<>();
for (OrderRespDTO each : orderList) {
OrderAdapterRespDTO orderAdapter = new OrderAdapterRespDTO();
orderAdapter.setOrderId(each.getOrderSn());
orderAdapter.setOrderTotal(each.getTotalAmount().intValue());
orderAdapter.setOrderStatus(String.valueOf(each.getStatus()));
orderAdapter.setFinishDate(each.getReceiveTime());
orderAdapter.setCreateDate(each.getCreateTime());
OrderAddressAdapterRespDTO addressInfo = new OrderAddressAdapterRespDTO();
addressInfo.setTel(each.getCneePhone());
addressInfo.setStreetName(each.getCneeDetailAddress());
addressInfo.setUserName(each.getCneeName());
orderAdapter.setAddressInfo(addressInfo);
List<OrderGoodsAdapterRespDTO> goodsList = new ArrayList<>();
for (OrderProductRespDTO item : each.getOrderProducts()) {
OrderGoodsAdapterRespDTO goods = new OrderGoodsAdapterRespDTO();
goods.setProductId(item.getProductId());
goods.setProductImg(item.getProductPic());
goods.setProductName(item.getProductName());
goods.setProductNum(item.getProductQuantity());
goods.setSalePrice(item.getProductPrice().intValue());
goodsList.add(goods);
}
orderAdapter.setGoodsList(goodsList);
orderListResult.add(orderAdapter);
}
return new OrderResultAdapterRespDTO(orderListResult.size(), orderListResult);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@
package org.opengoofy.congomall.bff.remote;

import org.opengoofy.congomall.bff.remote.req.OrderCreateCommand;
import org.opengoofy.congomall.bff.remote.resp.OrderRespDTO;
import org.opengoofy.congomall.springboot.starter.convention.result.Result;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
* 订单远程调用服务
*
Expand All @@ -38,4 +43,10 @@ public interface OrderRemoteService {
*/
@PostMapping("/api/order")
Result<String> createOrder(@RequestBody OrderCreateCommand requestParam);

/**
* 根据用户ID查询订单信息
*/
@GetMapping("/api/order/customer-user/{customerUserId}")
Result<List<OrderRespDTO>> getOrderByCustomerUserId(@PathVariable("customerUserId") String customerUserId);
}
Loading

0 comments on commit d456eb7

Please sign in to comment.