dev-v2 #3
|
@ -1,13 +0,0 @@
|
||||||
package com.atguigu;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hello world!
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class App
|
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
|
||||||
{
|
|
||||||
System.out.println( "Hello World!" );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.atguigu.feign.cart;
|
||||||
|
|
||||||
|
import com.atguigu.spzx.model.entity.h5.CartInfo;
|
||||||
|
import com.atguigu.spzx.model.vo.result.Result;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@FeignClient(value = "service-cart", path = "/api/order/cart")
|
||||||
|
public interface CartFeignClient {
|
||||||
|
@GetMapping(value = "/auth/getAllCkecked")
|
||||||
|
Result<List<CartInfo>> getAllChecked();
|
||||||
|
}
|
|
@ -18,6 +18,10 @@
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.atguigu</groupId>
|
||||||
|
<artifactId>service-user-client</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
package com.atguigu.order;
|
package com.atguigu.order;
|
||||||
|
|
||||||
|
import com.atguigu.anno.EnableUserTokenFeignInterceptor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@EnableFeignClients(basePackages = {"com.atguigu.feign.cart"})
|
||||||
|
@EnableUserTokenFeignInterceptor
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class OrderApplication {
|
public class OrderApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
|
@ -1,4 +1,12 @@
|
||||||
package com.atguigu.order.service;
|
package com.atguigu.order.service;
|
||||||
|
|
||||||
|
import com.atguigu.spzx.model.vo.h5.TradeVo;
|
||||||
|
|
||||||
public interface OrderInfoService {
|
public interface OrderInfoService {
|
||||||
|
/**
|
||||||
|
* 确认下单
|
||||||
|
*
|
||||||
|
* @return 结算实体类
|
||||||
|
*/
|
||||||
|
TradeVo getTrade();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,41 @@
|
||||||
package com.atguigu.order.service.impl;
|
package com.atguigu.order.service.impl;
|
||||||
|
|
||||||
import com.atguigu.order.service.OrderInfoService;
|
import com.atguigu.order.service.OrderInfoService;
|
||||||
|
import com.atguigu.order.service.module.OrderInfoServiceModule;
|
||||||
|
import com.atguigu.spzx.model.entity.order.OrderItem;
|
||||||
|
import com.atguigu.spzx.model.vo.h5.TradeVo;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class OrderInfoServiceImpl implements OrderInfoService {
|
public class OrderInfoServiceImpl implements OrderInfoService {
|
||||||
|
@Autowired
|
||||||
|
private OrderInfoServiceModule orderInfoServiceModule;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 确认下单
|
||||||
|
*
|
||||||
|
* @return 结算实体类
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public TradeVo getTrade() {
|
||||||
|
// 远程调用获取购物车中商品列表
|
||||||
|
ArrayList<OrderItem> orderItems = orderInfoServiceModule.getOrderItems();
|
||||||
|
// 计算总金额
|
||||||
|
BigDecimal totalAmount;
|
||||||
|
totalAmount = orderItems.stream()
|
||||||
|
.map(orderItem -> orderItem.getSkuPrice().multiply(new BigDecimal(orderItem.getSkuNum())))
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
|
||||||
|
TradeVo tradeVo = new TradeVo();
|
||||||
|
tradeVo.setOrderItemList(orderItems);
|
||||||
|
tradeVo.setTotalAmount(totalAmount);
|
||||||
|
|
||||||
|
return tradeVo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.atguigu.order.service.module;
|
||||||
|
|
||||||
|
import com.atguigu.feign.cart.CartFeignClient;
|
||||||
|
import com.atguigu.spzx.model.entity.h5.CartInfo;
|
||||||
|
import com.atguigu.spzx.model.entity.order.OrderItem;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class OrderInfoServiceModule {
|
||||||
|
@Autowired
|
||||||
|
private CartFeignClient cartFeignClient;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public ArrayList<OrderItem> getOrderItems() {
|
||||||
|
List<CartInfo> cartInfoList = cartFeignClient.getAllChecked().getData();
|
||||||
|
// 创建LIst集合封装订单项
|
||||||
|
ArrayList<OrderItem> orderItems = new ArrayList<>();
|
||||||
|
cartInfoList.forEach(cartInfo -> {
|
||||||
|
OrderItem orderItem = new OrderItem();
|
||||||
|
orderItem.setSkuId(cartInfo.getSkuId());
|
||||||
|
orderItem.setSkuName(cartInfo.getSkuName());
|
||||||
|
orderItem.setSkuNum(cartInfo.getSkuNum());
|
||||||
|
orderItem.setSkuPrice(cartInfo.getCartPrice());
|
||||||
|
orderItem.setThumbImg(cartInfo.getImgUrl());
|
||||||
|
orderItems.add(orderItem);
|
||||||
|
});
|
||||||
|
return orderItems;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue