Compare commits
No commits in common. "b41919f218a8ca934fe018790959a0525c441cfe" and "579365293c75d323d611276d21c254a505435ac8" have entirely different histories.
b41919f218
...
579365293c
|
@ -1,17 +0,0 @@
|
||||||
package com.atguigu.anno;
|
|
||||||
|
|
||||||
import com.atguigu.interceptor.feign.UserTokenFeignInterceptor;
|
|
||||||
import org.springframework.context.annotation.Import;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
// com.atguigu.spzx.common.anno;
|
|
||||||
@Retention(value = RetentionPolicy.RUNTIME)
|
|
||||||
@Target(value = ElementType.TYPE)
|
|
||||||
@Import(value = UserTokenFeignInterceptor.class)
|
|
||||||
public @interface EnableUserTokenFeignInterceptor {
|
|
||||||
|
|
||||||
}
|
|
|
@ -3,6 +3,7 @@ package com.atguigu.interceptor;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.atguigu.context.BaseContext;
|
import com.atguigu.context.BaseContext;
|
||||||
import com.atguigu.spzx.model.entity.user.UserInfo;
|
import com.atguigu.spzx.model.entity.user.UserInfo;
|
||||||
|
import com.atguigu.utils.EmptyUtil;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
@ -19,6 +20,8 @@ import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
public class UserLoginAuthInterceptor implements HandlerInterceptor {
|
public class UserLoginAuthInterceptor implements HandlerInterceptor {
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisTemplate<String, Object> redisTemplate;
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
|
@Autowired
|
||||||
|
private EmptyUtil emptyUtil;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean preHandle(HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull Object handler) throws Exception {
|
public boolean preHandle(HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull Object handler) throws Exception {
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
package com.atguigu.interceptor.feign;
|
|
||||||
|
|
||||||
import feign.RequestInterceptor;
|
|
||||||
import feign.RequestTemplate;
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
|
||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
||||||
|
|
||||||
public class UserTokenFeignInterceptor implements RequestInterceptor {
|
|
||||||
@Override
|
|
||||||
public void apply(RequestTemplate requestTemplate) {
|
|
||||||
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
|
||||||
assert requestAttributes != null;
|
|
||||||
HttpServletRequest request = requestAttributes.getRequest();
|
|
||||||
String token = request.getHeader("token");
|
|
||||||
requestTemplate.header("token", token);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.atguigu;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hello world!
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class App
|
||||||
|
{
|
||||||
|
public static void main( String[] args )
|
||||||
|
{
|
||||||
|
System.out.println( "Hello World!" );
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,14 +0,0 @@
|
||||||
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();
|
|
||||||
}
|
|
|
@ -7,8 +7,8 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
|
||||||
// 排除数据库的自动化配置,Cart微服务不需要访问数据库
|
// 排除数据库的自动化配置,Cart微服务不需要访问数据库
|
||||||
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
|
|
||||||
@ComponentScan("com.atguigu")
|
@ComponentScan("com.atguigu")
|
||||||
|
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
|
||||||
@EnableFeignClients(basePackages = {"com.atguigu"})
|
@EnableFeignClients(basePackages = {"com.atguigu"})
|
||||||
public class CartApplication {
|
public class CartApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
|
@ -62,11 +62,4 @@ public class CartController {
|
||||||
cartService.clearCart();
|
cartService.clearCart();
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "选中的购物车")
|
|
||||||
@GetMapping(value = "/auth/getAllCkecked")
|
|
||||||
public Result<List<CartInfo>> getAllChecked() {
|
|
||||||
List<CartInfo> cartInfoList = cartService.getAllChecked();
|
|
||||||
return Result.success(cartInfoList);
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -46,11 +46,4 @@ public interface CartService {
|
||||||
* 清空购物车
|
* 清空购物车
|
||||||
*/
|
*/
|
||||||
void clearCart();
|
void clearCart();
|
||||||
|
|
||||||
/**
|
|
||||||
* 选中的购物车
|
|
||||||
*
|
|
||||||
* @return CartInfo列表
|
|
||||||
*/
|
|
||||||
List<CartInfo> getAllChecked();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,27 +157,4 @@ public class CartServiceImpl implements CartService {
|
||||||
String cartKey = RedisUtils.getCartKey(userId);
|
String cartKey = RedisUtils.getCartKey(userId);
|
||||||
redisTemplate.delete(cartKey);
|
redisTemplate.delete(cartKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 选中的购物车
|
|
||||||
*
|
|
||||||
* @return CartInfo列表
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<CartInfo> getAllChecked() {
|
|
||||||
// 获取用户id
|
|
||||||
Long userId = BaseContext.getUserInfo().getId();
|
|
||||||
String cartKey = RedisUtils.getCartKey(userId);
|
|
||||||
|
|
||||||
// 根据key获取购物车所有商品
|
|
||||||
List<Object> objectList = redisTemplate.opsForHash().values(cartKey);
|
|
||||||
|
|
||||||
if (!CollectionUtils.isEmpty(objectList)) {
|
|
||||||
return objectList.stream()
|
|
||||||
.map(object -> JSON.parseObject(JSON.toJSONString(object), CartInfo.class))
|
|
||||||
.filter(cartInfo -> cartInfo.getIsChecked() == 1)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,10 +18,6 @@
|
||||||
</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,14 +1,10 @@
|
||||||
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,26 +0,0 @@
|
||||||
package com.atguigu.order.controller;
|
|
||||||
|
|
||||||
import com.atguigu.order.service.OrderInfoService;
|
|
||||||
import com.atguigu.spzx.model.vo.h5.TradeVo;
|
|
||||||
import com.atguigu.spzx.model.vo.result.Result;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@Tag(name = "订单管理")
|
|
||||||
@RestController
|
|
||||||
@RequestMapping(value = "/api/order/orderInfo")
|
|
||||||
public class OrderInfoController {
|
|
||||||
@Autowired
|
|
||||||
private OrderInfoService orderInfoService;
|
|
||||||
|
|
||||||
@Operation(summary = "确认下单")
|
|
||||||
@GetMapping("auth/trade")
|
|
||||||
public Result<TradeVo> trade() {
|
|
||||||
TradeVo tradeVo = orderInfoService.getTrade();
|
|
||||||
return Result.success(tradeVo);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
package com.atguigu.order.mapper;
|
|
||||||
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface OrderInfoMapper {
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package com.atguigu.order.service;
|
|
||||||
|
|
||||||
import com.atguigu.spzx.model.vo.h5.TradeVo;
|
|
||||||
|
|
||||||
public interface OrderInfoService {
|
|
||||||
/**
|
|
||||||
* 确认下单
|
|
||||||
*
|
|
||||||
* @return 结算实体类
|
|
||||||
*/
|
|
||||||
TradeVo getTrade();
|
|
||||||
}
|
|
|
@ -1,41 +0,0 @@
|
||||||
package com.atguigu.order.service.impl;
|
|
||||||
|
|
||||||
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 org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@Slf4j
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,18 +1,7 @@
|
||||||
bunny:
|
bunny:
|
||||||
nacos:
|
|
||||||
server-addr: z-bunny.cn:8848
|
|
||||||
discovery:
|
|
||||||
namespace: spzx
|
|
||||||
|
|
||||||
datasource:
|
datasource:
|
||||||
host: 106.15.251.123
|
host: 106.15.251.123
|
||||||
port: 3305
|
port: 3305
|
||||||
sqlData: db_spzx
|
sqlData: db_spzx
|
||||||
username: root
|
username: root
|
||||||
password: "02120212"
|
|
||||||
|
|
||||||
redis:
|
|
||||||
host: 47.120.65.66
|
|
||||||
port: 6379
|
|
||||||
database: 2
|
|
||||||
password: "02120212"
|
password: "02120212"
|
|
@ -22,13 +22,6 @@ spring:
|
||||||
username: ${bunny.datasource.username}
|
username: ${bunny.datasource.username}
|
||||||
password: "${bunny.datasource.password}"
|
password: "${bunny.datasource.password}"
|
||||||
|
|
||||||
data:
|
|
||||||
redis:
|
|
||||||
host: ${bunny.redis.host}
|
|
||||||
port: ${bunny.redis.port}
|
|
||||||
database: ${bunny.redis.database}
|
|
||||||
password: ${bunny.redis.password}
|
|
||||||
|
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
com.atguigu.spzx.order.mapper: debug
|
com.atguigu.spzx.order.mapper: debug
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
|
||||||
<mapper namespace="com.atguigu.order.mapper.OrderInfoMapper">
|
|
||||||
|
|
||||||
</mapper>
|
|
|
@ -1,30 +0,0 @@
|
||||||
package com.atguigu.user.controller;
|
|
||||||
|
|
||||||
import com.atguigu.spzx.model.entity.user.UserAddress;
|
|
||||||
import com.atguigu.spzx.model.vo.result.Result;
|
|
||||||
import com.atguigu.user.service.UserAddressService;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Tag(name = "用户地址接口")
|
|
||||||
@RestController
|
|
||||||
@RequestMapping(value = "/api/user/userAddress")
|
|
||||||
@Slf4j
|
|
||||||
public class UserAddressController {
|
|
||||||
@Autowired
|
|
||||||
private UserAddressService userAddressService;
|
|
||||||
|
|
||||||
@Operation(summary = "获取用户地址列表")
|
|
||||||
@GetMapping("auth/findUserAddressList")
|
|
||||||
public Result<List<UserAddress>> findUserAddressList() {
|
|
||||||
List<UserAddress> list = userAddressService.findUserAddressList();
|
|
||||||
return Result.success(list);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
package com.atguigu.user.mapper;
|
|
||||||
|
|
||||||
import com.atguigu.spzx.model.entity.user.UserAddress;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface UserAddressMapper {
|
|
||||||
/**
|
|
||||||
* 查询用户地址栏
|
|
||||||
*
|
|
||||||
* @param userId 用户id
|
|
||||||
* @return 地址列表
|
|
||||||
*/
|
|
||||||
List<UserAddress> selectByUserId(Long userId);
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
package com.atguigu.user.service;
|
|
||||||
|
|
||||||
import com.atguigu.spzx.model.entity.user.UserAddress;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface UserAddressService {
|
|
||||||
/**
|
|
||||||
* 获取用户地址列表
|
|
||||||
*
|
|
||||||
* @return 用户地址列表
|
|
||||||
*/
|
|
||||||
List<UserAddress> findUserAddressList();
|
|
||||||
}
|
|
|
@ -1,35 +0,0 @@
|
||||||
package com.atguigu.user.service.impl;
|
|
||||||
|
|
||||||
import com.atguigu.constant.MessageConstant;
|
|
||||||
import com.atguigu.context.BaseContext;
|
|
||||||
import com.atguigu.exception.BunnyException;
|
|
||||||
import com.atguigu.spzx.model.entity.user.UserAddress;
|
|
||||||
import com.atguigu.user.mapper.UserAddressMapper;
|
|
||||||
import com.atguigu.user.service.UserAddressService;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@Slf4j
|
|
||||||
public class UserAddressServiceImpl implements UserAddressService {
|
|
||||||
@Autowired
|
|
||||||
private UserAddressMapper userAddressMapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取用户地址列表
|
|
||||||
*
|
|
||||||
* @return 用户地址列表
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<UserAddress> findUserAddressList() {
|
|
||||||
// 查询用户地址栏
|
|
||||||
Long userId = BaseContext.getUserInfo().getId();
|
|
||||||
if (userId != null) {
|
|
||||||
return userAddressMapper.selectByUserId(userId);
|
|
||||||
}
|
|
||||||
throw new BunnyException(MessageConstant.FIND_ID_IS_NOT_EMPTY);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
|
||||||
<mapper namespace="com.atguigu.user.mapper.UserAddressMapper">
|
|
||||||
|
|
||||||
<!-- 查询用户地址栏 -->
|
|
||||||
<select id="selectByUserId" resultType="com.atguigu.spzx.model.entity.user.UserAddress">
|
|
||||||
select *
|
|
||||||
from user_address
|
|
||||||
where user_id = #{userId}
|
|
||||||
</select>
|
|
||||||
</mapper>
|
|
Loading…
Reference in New Issue