feat:订单提交优化

This commit is contained in:
haoxr 2021-03-17 20:18:16 +08:00
parent 5f6f6ba768
commit 905d21999c
64 changed files with 452 additions and 968 deletions

View File

@ -39,7 +39,7 @@ public class OmsOrderItem extends BaseEntity {
/** /**
* 商品sku名字 * 商品sku名字
*/ */
private String skuName; private String title;
/** /**
* 商品sku图片 * 商品sku图片
*/ */

View File

@ -0,0 +1,21 @@
package com.youlai.mall.oms.pojo.dto;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
/**
* @author huawei
* @desc 订单提交实体类
* @email huawei_code@163.com
* @date 2021/1/16
*/
@Data
public class OrderConfirmDTO {
private Long skuId;
private Integer count;
}

View File

@ -1,22 +1,25 @@
package com.youlai.mall.oms.pojo.dto; package com.youlai.mall.oms.pojo.dto;
import com.youlai.mall.oms.pojo.vo.OrderItemVO;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import java.util.List;
/** /**
* @author huawei * @author huawei
* @desc 订单提交实体类 * @desc 订单提交
* @email huawei_code@163.com * @email huawei_code@163.com
* @date 2021/1/16 * @date 2021/1/16
*/ */
@Data @Data
public class OrderSubmitDTO { public class OrderSubmitDTO {
private Long skuId; // 提交订单确认页面签发的令牌
private String orderToken;
private Integer skuNum; private List<OrderItemVO> orderItems;
private Long payAmount; private Long payAmount;

View File

@ -1,21 +0,0 @@
package com.youlai.mall.oms.pojo.dto;
import lombok.Data;
/**
* 支付结果回调接收类
*/
@Data
public class ResultPayDTO {
private String code;
private String msg;
private String otherinfo;
private String orderId;
private String price;
private String name;
private String thirduid;
private String paytype;
private String remarks;
private String originalprice;
}

View File

@ -1,42 +0,0 @@
package com.youlai.mall.oms.pojo.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* 购物车项目项实体类
*/
@NoArgsConstructor
@AllArgsConstructor
@ToString
@Data
@Accessors(chain = true)
public class CartItemVO implements Serializable {
private Long skuId;
private String skuPic;
private String skuName;
private Integer inventory;
private Integer count;
private Long price;
private Long coupon;
private Long subtotal;
private boolean hasInventory;
private boolean checked;
}

View File

@ -12,45 +12,27 @@ import java.util.List;
@AllArgsConstructor @AllArgsConstructor
@ToString @ToString
@Builder @Builder
@Data
public class CartVO implements Serializable { public class CartVO implements Serializable {
private List<CartItemVO> items; private List<CartItem> items;
private Integer totalNum; @Data
public static class CartItem {
private Long totalPrice; private Long skuId;
private Long totalCoupon; private String title; // 标题
public List<CartItemVO> getItems() { private String pic;
return items;
}
public void setItems(List<CartItemVO> items) { private Integer count;
this.items = items;
}
public Integer getTotalNum() { private Long price;
int total = 0;
if (items != null && items.size() > 0) {
total = items.stream().filter(CartItemVO::isChecked).mapToInt(CartItemVO::getNum).sum();
}
return total;
}
public void setTotalNum(Integer totalNum) { private Long coupon;
this.totalNum = totalNum;
}
public Long getTotalPrice() { private boolean checked;
long total = 0L;
if (items != null && items.size() > 0) {
total = items.stream().filter(CartItemVO::isChecked).mapToLong(CartItemVO::getSubtotal).sum();
}
return total;
}
public void setTotalPrice(Long totalPrice) {
this.totalPrice = totalPrice;
} }
} }

View File

@ -1,18 +0,0 @@
package com.youlai.mall.oms.pojo.vo;
import com.youlai.common.base.BaseVO;
import lombok.Data;
/**
* @author huawei
* @desc 优惠券信息
* @email huawei_code@163.com
* @date 2021/1/13
*/
@Data
public class CouponVO extends BaseVO {
private String title;
private Long price;
}

View File

@ -14,11 +14,8 @@ import lombok.Setter;
public class OrderItemVO extends BaseVO { public class OrderItemVO extends BaseVO {
private Long skuId; private Long skuId;
private String skuImg;
private String skuName;
private Integer count; private Integer count;
private String skuPic;
private String title;
private Long price; private Long price;
private Long coupon;
} }

View File

@ -53,7 +53,7 @@ public class OrderListVO extends BaseVO {
private String skuPic; private String skuPic;
private Integer skuQuantity; private Integer skuQuantity;
private Long skuTotalPrice; private Long skuTotalPrice;
private String skuName; private String title;
private Long price; private Long price;
private String image; private String image;
private Integer number; private Integer number;

View File

@ -10,7 +10,7 @@ import lombok.Data;
* @date 2021/1/21 * @date 2021/1/21
*/ */
@Data @Data
public class OrderSubmitResultVO extends BaseVO { public class OrderSubmitVO extends BaseVO {
/** /**
* 订单ID * 订单ID
*/ */

View File

@ -1,9 +1,8 @@
package com.youlai.mall.oms; package com.youlai.mall.oms;
import com.youlai.mall.pms.api.app.InventoryFeignService; import com.youlai.mall.pms.api.app.PmsSkuFeignService;
import com.youlai.mall.ums.api.app.MemberFeignService; import com.youlai.mall.ums.api.app.UmsMemberFeignService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.amqp.rabbit.annotation.EnableRabbit; import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@ -13,8 +12,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class) @SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@EnableDiscoveryClient @EnableDiscoveryClient
@EnableFeignClients(basePackageClasses = { MemberFeignService.class, InventoryFeignService.class}) @EnableFeignClients(basePackageClasses = { UmsMemberFeignService.class, PmsSkuFeignService.class})
@MapperScan({ "com.youlai.mall.oms.mapper","com.youlai.mall.oms.dao"})
@EnableRabbit @EnableRabbit
public class OmsApplication { public class OmsApplication {

View File

@ -1,10 +1,8 @@
package com.youlai.mall.oms.config; package com.youlai.mall.oms.config;
import com.youlai.mall.oms.constant.OmsConstants;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.*; import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -15,8 +13,7 @@ import java.util.Map;
* @author huawei * @author huawei
* @email huawei_code@163.com * @email huawei_code@163.com
* @date 2021/1/17 * @date 2021/1/17
* @desc rabbitmq 业务相关配置类 * @desc 业务描述
* 订单相关业务统一使用 order-event-exchange 交换机
* 1. 订单创建成功发送消息到创建订单的路由 * 1. 订单创建成功发送消息到创建订单的路由
* 2. 创建订单的路由转发消息给延时队列延时队列的延时时间就是订单从创建到支付过程允许的最大等待时间延时队列不能有消费者即消息不能被消费 * 2. 创建订单的路由转发消息给延时队列延时队列的延时时间就是订单从创建到支付过程允许的最大等待时间延时队列不能有消费者即消息不能被消费
* 3. 延时时间一到消息被转入DLX死信路由 * 3. 延时时间一到消息被转入DLX死信路由
@ -28,16 +25,13 @@ import java.util.Map;
@AllArgsConstructor @AllArgsConstructor
public class RabbitMQConfig { public class RabbitMQConfig {
private RabbitTemplate rabbitTemplate;
/** /**
* 定义交换机 * 定义交换机订单业务统一使用 order-exchange 交换机
*/ */
@Bean @Bean
public Exchange exchange() { public Exchange exchange() {
return new TopicExchange("order_event_exchange", true, false); return new TopicExchange("order-exchange", true, false);
} }
/** /**
* 延时队列 * 延时队列
*/ */
@ -45,7 +39,7 @@ public class RabbitMQConfig {
public Queue delayQueue() { public Queue delayQueue() {
// 延时队列的消息过期了会自动触发消息的转发根据routingKey发送到指定的exchange中exchange路由到死信队列 // 延时队列的消息过期了会自动触发消息的转发根据routingKey发送到指定的exchange中exchange路由到死信队列
Map<String, Object> args = new HashMap<>(); Map<String, Object> args = new HashMap<>();
args.put("x-dead-letter-exchange", "order_event_exchange"); args.put("x-dead-letter-exchange", "order-exchange");
args.put("x-dead-letter-routing-key", "order:close"); // 死信路由Key args.put("x-dead-letter-routing-key", "order:close"); // 死信路由Key
args.put("x-message-ttl", 60000); // 单位毫秒配置1分钟测试使用 args.put("x-message-ttl", 60000); // 单位毫秒配置1分钟测试使用
return new Queue("order.delay.queue", true, false, false, args); return new Queue("order.delay.queue", true, false, false, args);
@ -58,7 +52,7 @@ public class RabbitMQConfig {
*/ */
@Bean @Bean
public Binding delayQueueBinding() { public Binding delayQueueBinding() {
return new Binding("order.delay.queue", Binding.DestinationType.QUEUE,"order_event_exchange","order.create",null); return new Binding("order.delay.queue", Binding.DestinationType.QUEUE,"order-exchange","order.create",null);
} }
/** /**
@ -75,7 +69,7 @@ public class RabbitMQConfig {
*/ */
@Bean @Bean
public Binding closeOrderQueueBinding() { public Binding closeOrderQueueBinding() {
return new Binding("order.close.queue", Binding.DestinationType.QUEUE,"order_event_exchange","order:close",null); return new Binding("order.close.queue", Binding.DestinationType.QUEUE,"order-exchange","order:close",null);
} }
} }

View File

@ -0,0 +1,21 @@
package com.youlai.mall.oms.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* 线程池配置
*/
@Configuration
public class ThreadPoolConfig {
@Bean
public ThreadPoolExecutor threadPoolExecutor() {
return new ThreadPoolExecutor(50,500,30, TimeUnit.SECONDS,new ArrayBlockingQueue<>(10000));
}
}

View File

@ -1,42 +0,0 @@
//package com.youlai.mall.oms.config.thread;
//
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.task.AsyncTaskExecutor;
//import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
//
//import java.util.concurrent.ThreadPoolExecutor;
//
///**
// * @author huawei
// * @desc 异步任务线程配置
// * @email huawei_code@163.com
// * @date 2021/1/16
// */
//@Configuration
//@Slf4j
//public class AsyncConfig {
//
// @Bean("asyncTaskExecutor")
// public AsyncTaskExecutor asyncTaskExecutor(ThreadPoolProperties properties) {
// log.info("loading asyncTaskExecutor ...");
// ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
// //配置核心线程数
// executor.setCorePoolSize(properties.getCorePoolSize());
// //配置最大线程数
// executor.setMaxPoolSize(properties.getMaxPoolSize());
// //配置队列大小
// executor.setQueueCapacity(properties.getQueueCapacity());
// executor.setKeepAliveSeconds(properties.getKeepAliveSeconds());
// //配置线程池中的线程的名称前缀
// executor.setThreadNamePrefix("async-service-");
//
// // 设置拒绝策略当pool已经达到max size的时候如何处理新任务
// // CALLER_RUNS不在新线程中执行任务而是有调用者所在的线程来执行
// executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// //执行初始化
// executor.initialize();
// return executor;
// }
//}

View File

@ -1,23 +0,0 @@
//package com.youlai.mall.oms.config.thread;
//
//import lombok.Data;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//
///**
// * @author huawei
// * @desc 线程池配置属性类
// * @email huawei_code@163.com
// * @date 2021/1/16
// */
//@Data
//@ConfigurationProperties(prefix = "task.pool")
//public class ThreadPoolProperties {
//
// private Integer corePoolSize;
//
// private Integer maxPoolSize;
//
// private Integer queueCapacity;
//
// private Integer keepAliveSeconds;
//}

View File

@ -1,31 +0,0 @@
package com.youlai.mall.oms.config.token;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author huawei
* @desc Token 幂等性校验接口注解
* 幂等性方案注解 + 拦截器
* 注解@TokenVerify 注解该注解有两个属性generate clean
* generate属性为true是表示请求该方法会生成一个uuid token同时放入redis中和用户请求中用于用户下一次请求校验默认为false
* clean如果属性为true表示请求该方法需要校验token唯一性并且在校验通过后清除redis中的token
* 拦截器TokenVerifyHandler
* 实现原理拦截所有的请求如果该请求被 @TokenVerify 注解标识首先判断该注解属性 generate 是否为true然后校验属性 clean 是否为true
* 最后 WebMvcConfig 配置中配置拦截器
* @email huawei_code@163.com
* @date 2021/1/21
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface TokenVerify {
// 是否生成校验token
boolean generate() default false;
// 是否校验token
boolean verify() default false;
}

View File

@ -1,45 +0,0 @@
package com.youlai.mall.oms.config.token;
import com.youlai.mall.oms.service.TokenService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author huawei
* @desc
* @email huawei_code@163.com
* @date 2021/1/21
*/
@Component
@AllArgsConstructor
@Slf4j
public class TokenVerifyHandler extends HandlerInterceptorAdapter {
@Autowired
private TokenService tokenService;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (!(handler instanceof HandlerMethod)) {
return true;
}
HandlerMethod method = (HandlerMethod) handler;
TokenVerify tokenVerify = method.getMethodAnnotation(TokenVerify.class);
if (tokenVerify != null) {
log.debug("请求:{} 使用 @TokenVerify 注解,被拦截器拦截", request.getRequestURI());
// 校验token判断是否重复提交
tokenService.checkToken(request);
}
return true;
}
}

View File

@ -5,11 +5,10 @@ package com.youlai.mall.oms.constant;
* @date 2021-03-16 * @date 2021-03-16
*/ */
public interface OmsConstants { public interface OmsConstants {
Long REDIS_KEY_TIME_OUT = 3600 * 24L;
String CART_KEY = "cart:"; String CART_PREFIX = "mall:cart:";
String TOKEN_VERIFY = "token_verify:"; String ORDER_TOKEN_PREFIX = "mall:order:token:";
String BUSINESS_NO_PREFIX = "businessno:"; String BUSINESS_NO_PREFIX = "businessno:";

View File

@ -11,8 +11,6 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
/** /**
* 购物车
*
* @author huawei * @author huawei
* @email huawei_code@163.com * @email huawei_code@163.com
* @date 2020-12-30 22:31:10 * @date 2020-12-30 22:31:10
@ -27,9 +25,9 @@ public class CartController {
private ICartService cartService; private ICartService cartService;
@ApiOperation(value = "查询购物车", httpMethod = "GET") @ApiOperation(value = "查询用户购物车", httpMethod = "GET")
@GetMapping @GetMapping
public Result getCart() { public Result get() {
CartVO cart = cartService.getCart(); CartVO cart = cartService.getCart();
return Result.success(cart); return Result.success(cart);
} }
@ -42,37 +40,33 @@ public class CartController {
return Result.success(); return Result.success();
} }
@ApiOperation(value = "局部更新购物车商品", httpMethod = "PUT") @ApiOperation(value = "更新购物车商品", httpMethod = "PUT")
@PutMapping("/skuId/{skuId}") @PutMapping("/skuId/{skuId}")
public Result updateCartItem( public Result updateCartItem(@RequestBody CartVO.CartItem cartItem) {
@PathVariable Long skuId, boolean result = cartService.updateCartItem(cartItem);
Integer num, return Result.judge(result);
Boolean checked
) {
cartService.updateCartItem(skuId, num, checked);
return Result.success();
} }
@ApiOperation(value = "全选/全不选择购物车商品", httpMethod = "PUT") @ApiOperation(value = "全选/全不选择购物车商品", httpMethod = "PUT")
@ApiImplicitParam(name = "checked", value = "全选/全不选", required = true, paramType = "param", dataType = "Boolean") @ApiImplicitParam(name = "checked", value = "全选/全不选", required = true, paramType = "param", dataType = "Boolean")
@PatchMapping("/batch") @PatchMapping("/batch")
public Result checkAll(Boolean checked) { public Result checkAll(boolean checked) {
cartService.checkAll(checked); boolean result = cartService.checkAll(checked);
return Result.success(); return Result.judge(result);
} }
@ApiOperation(value = "删除购物车商品", httpMethod = "DELETE") @ApiOperation(value = "删除购物车商品", httpMethod = "DELETE")
@ApiImplicitParam(name = "skuId", value = "SKU ID集合", required = true, paramType = "param", dataType = "Long") @ApiImplicitParam(name = "skuId", value = "SKU ID", required = true, paramType = "param", dataType = "Long")
@DeleteMapping("/skuId/{skuId}") @DeleteMapping("/skuId/{skuId}")
public Result deleteCartItem(@PathVariable Long skuId) { public Result removeCartItem(@PathVariable Long skuId) {
cartService.deleteCartItem(skuId); boolean result = cartService.removeCartItem(skuId);
return Result.success(); return Result.judge(result);
} }
@ApiOperation(value = "清空购物车", httpMethod = "DELETE") @ApiOperation(value = "清空购物车", httpMethod = "DELETE")
@DeleteMapping @DeleteMapping
public Result deleteCart() { public Result deleteCart() {
cartService.deleteCart(); boolean result = cartService.deleteCart();
return Result.success(); return Result.judge(result);
} }
} }

View File

@ -1,9 +1,10 @@
package com.youlai.mall.oms.controller.app; package com.youlai.mall.oms.controller.app;
import com.youlai.common.result.Result; import com.youlai.common.result.Result;
import com.youlai.mall.oms.pojo.dto.OrderConfirmDTO;
import com.youlai.mall.oms.pojo.vo.OrderConfirmVO; import com.youlai.mall.oms.pojo.vo.OrderConfirmVO;
import com.youlai.mall.oms.pojo.vo.OrderListVO; import com.youlai.mall.oms.pojo.vo.OrderListVO;
import com.youlai.mall.oms.pojo.vo.OrderSubmitResultVO; import com.youlai.mall.oms.pojo.vo.OrderSubmitVO;
import com.youlai.mall.oms.pojo.dto.OrderSubmitDTO; import com.youlai.mall.oms.pojo.dto.OrderSubmitDTO;
import com.youlai.mall.oms.service.IOrderService; import com.youlai.mall.oms.service.IOrderService;
import io.swagger.annotations.*; import io.swagger.annotations.*;
@ -29,42 +30,22 @@ public class OrderController {
private IOrderService orderService; private IOrderService orderService;
/** @ApiOperation(value = "确认订单", httpMethod = "POST")
* 订单确认信息生成订单 @ApiImplicitParam(name = "orderConfirm",value = "确认订单信息",required = true, paramType = "body", dataType = "OrderConfirmDTO")
* 如果入参传了skuId则以当前skuId为准商品数量默认为1
* 如果没有传则从购物车中获取数据
* 如果购物车中没有数据则返回为空
*/
@ApiOperation(value = "订单确认信息", httpMethod = "POST")
@ApiImplicitParams({
@ApiImplicitParam(name = "skuId", value = "商品ID", required = true, paramType = "query", dataType = "Long"),
@ApiImplicitParam(name = "num", value = "商品数量", required = true, defaultValue = "1", paramType = "query", dataType = "Integer")
})
@PostMapping("/_confirm") @PostMapping("/_confirm")
public Result<OrderConfirmVO> confirm( public Result<OrderConfirmVO> confirm(@RequestBody OrderConfirmDTO orderConfirm) {
Long skuId, OrderConfirmVO result = orderService.confirm(orderConfirm);
Integer num return Result.success(result);
) { }
OrderConfirmVO confirm = orderService.confirm(skuId, num);
return Result.success(confirm); @ApiOperation(value = "提交订单", httpMethod = "POST")
} @ApiImplicitParam(name = "orderSubmitDTO", value = "提交订单信息", required = true, paramType = "body", dataType = "orderSubmitDTO")
@PostMapping("/_submit")
@ApiOperation(value = "提交订单", httpMethod = "POST") public Result submit(@Valid @RequestBody OrderSubmitDTO orderSubmitDTO) {
@ApiImplicitParam(name = "orderSubmitInfoDTO", value = "提交订单信息", required = true, paramType = "body", dataType = "OrderSubmitInfoDTO") OrderSubmitVO result = orderService.submit(orderSubmitDTO);
@PostMapping("/_submit")
public Result submit(@Valid @RequestBody OrderSubmitDTO orderSubmitDTO) {
OrderSubmitResultVO result = orderService.submit(orderSubmitDTO);
return Result.success(result); return Result.success(result);
} }
/**
* 根据订单状态查询订单列表
* 步骤
* 1入参 status 表示订单状态
* 2status = 0 表示查询所有订单
* 3已删除订单无法查询
*/
@ApiOperation("订单列表查询") @ApiOperation("订单列表查询")
@GetMapping("/list") @GetMapping("/list")
public Result<List<OrderListVO>> list( public Result<List<OrderListVO>> list(

View File

@ -15,8 +15,6 @@ import org.springframework.web.bind.annotation.*;
/** /**
* 订单支付服务
*
* @author huawei * @author huawei
* @email huawei_code@163.com * @email huawei_code@163.com
* @date 2020-12-30 22:31:10 * @date 2020-12-30 22:31:10
@ -26,7 +24,7 @@ import org.springframework.web.bind.annotation.*;
@RequestMapping("/api.app/v1/payments") @RequestMapping("/api.app/v1/payments")
@Slf4j @Slf4j
@AllArgsConstructor @AllArgsConstructor
public class PaymentController { public class PayController {
private IOrderPayService orderPayService; private IOrderPayService orderPayService;

View File

@ -4,7 +4,7 @@ import com.rabbitmq.client.Channel;
import com.youlai.mall.oms.pojo.domain.OmsOrderItem; import com.youlai.mall.oms.pojo.domain.OmsOrderItem;
import com.youlai.mall.oms.service.IOrderItemService; import com.youlai.mall.oms.service.IOrderItemService;
import com.youlai.mall.oms.service.IOrderService; import com.youlai.mall.oms.service.IOrderService;
import com.youlai.mall.pms.api.app.InventoryFeignService; import com.youlai.mall.pms.api.app.PmsSkuFeignService;
import com.youlai.mall.pms.pojo.dto.InventoryDTO; import com.youlai.mall.pms.pojo.dto.InventoryDTO;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -23,7 +23,7 @@ import java.util.stream.Collectors;
* @date 2021-03-16 * @date 2021-03-16
*/ */
//@Component @Component
@AllArgsConstructor @AllArgsConstructor
@Slf4j @Slf4j
public class RabbitMQListener { public class RabbitMQListener {
@ -32,7 +32,7 @@ public class RabbitMQListener {
IOrderItemService orderItemService; IOrderItemService orderItemService;
InventoryFeignService inventoryFeignService; PmsSkuFeignService inventoryFeignService;
RabbitTemplate rabbitTemplate; RabbitTemplate rabbitTemplate;

View File

@ -1,4 +1,4 @@
package com.youlai.mall.oms.dao; package com.youlai.mall.oms.mapper;
import com.youlai.mall.oms.pojo.domain.OmsOrderDelivery; import com.youlai.mall.oms.pojo.domain.OmsOrderDelivery;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@ -12,6 +12,6 @@ import org.apache.ibatis.annotations.Mapper;
* @date 2020-12-30 22:31:10 * @date 2020-12-30 22:31:10
*/ */
@Mapper @Mapper
public interface OrderDeliveryDao extends BaseMapper<OmsOrderDelivery> { public interface OrderDeliveryMapper extends BaseMapper<OmsOrderDelivery> {
} }

View File

@ -1,4 +1,4 @@
package com.youlai.mall.oms.dao; package com.youlai.mall.oms.mapper;
import com.youlai.mall.oms.pojo.domain.OmsOrderItem; import com.youlai.mall.oms.pojo.domain.OmsOrderItem;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@ -12,6 +12,6 @@ import org.apache.ibatis.annotations.Mapper;
* @date 2020-12-30 22:31:10 * @date 2020-12-30 22:31:10
*/ */
@Mapper @Mapper
public interface OrderItemDao extends BaseMapper<OmsOrderItem> { public interface OrderItemMapper extends BaseMapper<OmsOrderItem> {
} }

View File

@ -1,4 +1,4 @@
package com.youlai.mall.oms.dao; package com.youlai.mall.oms.mapper;
import com.youlai.mall.oms.pojo.domain.OmsOrderLog; import com.youlai.mall.oms.pojo.domain.OmsOrderLog;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@ -12,6 +12,6 @@ import org.apache.ibatis.annotations.Mapper;
* @date 2020-12-30 22:31:10 * @date 2020-12-30 22:31:10
*/ */
@Mapper @Mapper
public interface OrderLogDao extends BaseMapper<OmsOrderLog> { public interface OrderLogMapper extends BaseMapper<OmsOrderLog> {
} }

View File

@ -1,4 +1,4 @@
package com.youlai.mall.oms.dao; package com.youlai.mall.oms.mapper;
import com.youlai.mall.oms.pojo.domain.OmsOrder; import com.youlai.mall.oms.pojo.domain.OmsOrder;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@ -12,6 +12,6 @@ import org.apache.ibatis.annotations.Mapper;
* @date 2020-12-30 22:31:10 * @date 2020-12-30 22:31:10
*/ */
@Mapper @Mapper
public interface OrderDao extends BaseMapper<OmsOrder> { public interface OrderMapper extends BaseMapper<OmsOrder> {
} }

View File

@ -1,4 +1,4 @@
package com.youlai.mall.oms.dao; package com.youlai.mall.oms.mapper;
import com.youlai.mall.oms.pojo.domain.OmsOrderPay; import com.youlai.mall.oms.pojo.domain.OmsOrderPay;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@ -12,6 +12,6 @@ import org.apache.ibatis.annotations.Mapper;
* @date 2020-12-30 22:31:10 * @date 2020-12-30 22:31:10
*/ */
@Mapper @Mapper
public interface OrderPayDao extends BaseMapper<OmsOrderPay> { public interface OrderPayMapper extends BaseMapper<OmsOrderPay> {
} }

View File

@ -1,4 +1,4 @@
package com.youlai.mall.oms.dao; package com.youlai.mall.oms.mapper;
import com.youlai.mall.oms.pojo.domain.OmsOrderSetting; import com.youlai.mall.oms.pojo.domain.OmsOrderSetting;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@ -12,6 +12,6 @@ import org.apache.ibatis.annotations.Mapper;
* @date 2020-12-30 22:31:10 * @date 2020-12-30 22:31:10
*/ */
@Mapper @Mapper
public interface OrderSettingDao extends BaseMapper<OmsOrderSetting> { public interface OrderSettingMapper extends BaseMapper<OmsOrderSetting> {
} }

View File

@ -2,46 +2,28 @@ package com.youlai.mall.oms.service;
import com.youlai.mall.oms.pojo.vo.CartVO; import com.youlai.mall.oms.pojo.vo.CartVO;
import java.util.List;
/** /**
* 购物车业务接口 * 购物车业务接口
*/ */
public interface ICartService { public interface ICartService {
/**
* 添加商品到购物车
*/
void addCartItem(Long skuId);
/**
* 修改购物车商品数量
*/
void updateCartItem(Long skuId,Integer num,Boolean checked);
/**
* 全选/全不选购物车
*/
void checkAll(Boolean checked);
/**
* 批量删除购物车中的商品
*/
void deleteCartItem(Long skuId);
/**
* 查询购物车详情
*/
CartVO getCart(); CartVO getCart();
/** List<CartVO.CartItem> getCartItems();
* 清空购物车
*/
void deleteCart();
/** boolean deleteCart();
* 清空购物车中已选择商品
*/
void deleteSelectedItem();
boolean addCartItem(Long skuId);
boolean updateCartItem(CartVO.CartItem cartItem);
boolean removeCartItem(Long skuId);
boolean removeCheckedItem();
boolean checkAll(boolean checked);
} }

View File

@ -3,9 +3,10 @@ package com.youlai.mall.oms.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.mall.oms.pojo.domain.OmsOrder; import com.youlai.mall.oms.pojo.domain.OmsOrder;
import com.youlai.mall.oms.pojo.dto.OrderConfirmDTO;
import com.youlai.mall.oms.pojo.vo.OrderConfirmVO; import com.youlai.mall.oms.pojo.vo.OrderConfirmVO;
import com.youlai.mall.oms.pojo.vo.OrderListVO; import com.youlai.mall.oms.pojo.vo.OrderListVO;
import com.youlai.mall.oms.pojo.vo.OrderSubmitResultVO; import com.youlai.mall.oms.pojo.vo.OrderSubmitVO;
import com.youlai.mall.oms.pojo.dto.OrderSubmitDTO; import com.youlai.mall.oms.pojo.dto.OrderSubmitDTO;
import java.util.List; import java.util.List;
@ -20,58 +21,40 @@ import java.util.List;
public interface IOrderService extends IService<OmsOrder> { public interface IOrderService extends IService<OmsOrder> {
/** /**
* 订单确认页信息 * 订单确认
*
* @param skuId 商品id非必填参数
* @param num 商品数量
* @return
*/ */
OrderConfirmVO confirm(Long skuId, Integer num); OrderConfirmVO confirm(OrderConfirmDTO orderConfirmDTO);
/** /**
* 提交订单 * 提交订单
*
* @param orderSubmitDTO 提交订单信息
*/ */
OrderSubmitResultVO submit(OrderSubmitDTO orderSubmitDTO) ; OrderSubmitVO submit(OrderSubmitDTO orderSubmitDTO) ;
/** /**
* 系统关闭订单 * 系统关闭订单
*
* @param orderSn 订单号
*/ */
boolean closeOrder(Long orderId); boolean closeOrder(Long orderId);
/** /**
* 取消订单接口 * 取消订单接口
*
* @param id 订单ID
* @return 是否取消成功
*/ */
boolean cancelOrder(Long id); boolean cancelOrder(Long id);
/** /**
* 删除订单 * 删除订单
*
* @param id 订单ID
* @return 是否删除成功
*/ */
boolean deleteOrder(Long id); boolean deleteOrder(Long id);
/** /**
* 订单列表查询 * 订单列表查询
*
* @param status 订单状态
* @return 订单列表
*/ */
List<OrderListVO> list(Integer status); List<OrderListVO> list(Integer status);
/** /**
* 根据订单ID获取订单信息 * 根据订单ID获取订单信息
*
* @param id 订单ID
* @return 订单信息
*/ */
OmsOrder getByOrderId(Long id); OmsOrder getByOrderId(Long id);
} }

View File

@ -1,25 +0,0 @@
package com.youlai.mall.oms.service;
import javax.servlet.http.HttpServletRequest;
/**
* @author huawei
* @desc
* @email huawei_code@163.com
* @date 2021/1/21
*/
public interface TokenService {
/**
* 为当前用户请求生成Token
*
* @return token
*/
String generateToken();
/**
* 校验 Token 是否正确
* @param request 当前请求
*/
void checkToken(HttpServletRequest request);
}

View File

@ -1,14 +1,12 @@
package com.youlai.mall.oms.service.impl; package com.youlai.mall.oms.service.impl;
import com.youlai.common.result.Result;
import com.youlai.common.web.util.RequestUtils; import com.youlai.common.web.util.RequestUtils;
import com.youlai.mall.pms.api.app.InventoryFeignService; import com.youlai.mall.oms.constant.OmsConstants;
import com.youlai.mall.pms.pojo.dto.SkuDTO;
import com.youlai.mall.oms.pojo.vo.CartItemVO;
import com.youlai.mall.oms.pojo.vo.CartVO; import com.youlai.mall.oms.pojo.vo.CartVO;
import com.youlai.mall.oms.service.ICartService; import com.youlai.mall.oms.service.ICartService;
import com.youlai.mall.pms.api.app.PmsSkuFeignService;
import com.youlai.mall.pms.pojo.domain.PmsSku;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.BoundHashOperations; import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
@ -17,133 +15,151 @@ import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import static com.youlai.mall.oms.constant.OmsConstants.CART_KEY;
/** /**
* 购物车模块搭建步骤 * 购物车模块
* 1用户登录后才能操作购物车 * <p>
* *********添加购物车************* * 技术点BoundHashOperations
* 1获取当前登录用户 * 数据格式
* 2添加商品到购物车 * -- key <----> 购物车
* 2.1如果购物车中已经有该商品的相关数据 * -- hKey:value <----> 购物车商品1
* 2.1.1修改购物车商品数量 * -- hKey:value <----> 购物车商品2
* 2.2如果购物车中没有该商品新增该商品 * -- hKey:value <----> 购物车商品3
* 2.2.1调用商品服务查询商品sku详情
* 2.2.2封装CartItem实体类
* *********修改购物车*************
* *********删除购物车*************
* *********查询购物车*************
*/ */
@Service @Service
@Slf4j @Slf4j
@AllArgsConstructor @AllArgsConstructor
public class CartServiceImpl implements ICartService { public class CartServiceImpl implements ICartService {
private RedisTemplate redisTemplate; private RedisTemplate redisTemplate;
private PmsSkuFeignService skuFeignService;
private InventoryFeignService inventoryFeignService; /**
* 获取用户购物车
@Override */
@SneakyThrows
public void addCartItem(Long skuId) {
BoundHashOperations cartHashOpts = getCartHashOpts();
String hKey = skuId.toString(); // redis hash key
if (cartHashOpts.get(hKey) != null) {
CartItemVO cartItem = (CartItemVO) cartHashOpts.get(hKey);
cartItem.setNum(cartItem.getNum() + 1);
cartItem.setSubtotal(cartItem.getPrice() * cartItem.getNum());
cartHashOpts.put(hKey, cartItem);
return;
}
CartItemVO cartItem = new CartItemVO();
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
// 远程查询商品详情
Result<SkuDTO> result = inventoryFeignService.getSkuById(skuId);
SkuDTO sku = result.getData();
cartItem.setSkuId(skuId)
.setChecked(true)
.setSkuName(sku.getName())
.setSkuPic(sku.getPic())
.setNum(1)
.setPrice(sku.getPrice())
.setInventory(sku.getInventory())
.setSubtotal(1 * sku.getPrice());
});
CompletableFuture<Void> allOf = CompletableFuture.allOf(future);
allOf.get();
cartHashOpts.put(hKey, cartItem);
}
@Override
public void updateCartItem(Long skuId, Integer num, Boolean checked) {
BoundHashOperations cartHashOpts = getCartHashOpts();
String hKey = skuId + "";
CartItemVO cartItem = (CartItemVO) cartHashOpts.get(hKey);
if (cartItem != null) {
if (num != null) {
cartItem.setNum(num);
cartItem.setSubtotal(num * cartItem.getPrice());
}
if (checked != null) {
cartItem.setChecked(checked);
}
cartHashOpts.put(hKey, cartItem);
}
}
@Override
public void checkAll(Boolean checked) {
BoundHashOperations cartHashOpts = getCartHashOpts();
for (Object value : cartHashOpts.values()) {
CartItemVO cartItem = (CartItemVO) value;
cartItem.setChecked(checked);
String hKey = cartItem.getSkuId() + "";
cartHashOpts.put(hKey, cartItem);
}
}
@Override
public void deleteCartItem(Long skuId) {
BoundHashOperations cartHashOpts = getCartHashOpts();
String hKey = skuId.toString();
cartHashOpts.delete(hKey);
}
@Override @Override
public CartVO getCart() { public CartVO getCart() {
BoundHashOperations cartHashOpts = getCartHashOpts(); CartVO cart = new CartVO();
List<CartItemVO> items = cartHashOpts.values(); BoundHashOperations cartHashOperations = getCartHashOperations();
CartVO cartVo = new CartVO(); List<CartVO.CartItem> cartItems = cartHashOperations.values();
cartVo.setItems(items); cart.setItems(cartItems);
return cartVo; return cart;
} }
@Override @Override
public void deleteCart() { public List<CartVO.CartItem> getCartItems() {
Long userId = RequestUtils.getUserId(); BoundHashOperations cartHashOperations = getCartHashOperations();
String key = CART_KEY + userId; List<CartVO.CartItem> cartItems = cartHashOperations.values();
return cartItems;
}
/**
* 删除用户购物车(清空购物车)
*/
@Override
public boolean deleteCart() {
String key = OmsConstants.CART_PREFIX + RequestUtils.getUserId();
redisTemplate.delete(key); redisTemplate.delete(key);
return true;
} }
/**
* 添加商品至购物车
*/
@Override @Override
public void deleteSelectedItem() { public boolean addCartItem(Long skuId) {
log.info("清空购物车中已选择商品"); BoundHashOperations cartHashOperations = getCartHashOperations();
BoundHashOperations cartHashOpts = getCartHashOpts(); String hKey = skuId + "";
for (Object value : cartHashOpts.values()) {
CartItemVO cartItem = (CartItemVO) value; CartVO.CartItem cartItem;
if (cartItem.isChecked()) { // 购物车已存在该商品更新商品数量
log.info("清空购物车中商品商品id{} | 名称:{}", cartItem.getSkuId(), cartItem.getSkuName()); if (cartHashOperations.get(hKey) != null) {
cartHashOpts.delete(cartItem.getSkuId().toString()); cartItem = (CartVO.CartItem) cartHashOperations.get(hKey);
cartItem.setCount(cartItem.getCount() + 1); // 点击一次加入购物车数量+1
cartHashOperations.put(hKey, cartItem);
return true;
} }
// 购物车不存在该商品添加商品至购物车
cartItem = new CartVO.CartItem();
CompletableFuture<Void> cartItemCompletableFuture = CompletableFuture.runAsync(() -> {
PmsSku sku = skuFeignService.getSkuById(skuId).getData();
if (sku != null) {
cartItem.setSkuId(sku.getId());
cartItem.setCount(1);
cartItem.setPrice(sku.getPrice());
cartItem.setPic(sku.getPic());
cartItem.setSkuId(sku.getId());
cartItem.setTitle(sku.getTitle());
} }
});
CompletableFuture.allOf(cartItemCompletableFuture).join();
return true;
} }
private BoundHashOperations getCartHashOpts() { /**
* 更新购物车总商品数量选中状态
*/
@Override
public boolean updateCartItem(CartVO.CartItem cartItem) {
BoundHashOperations cartHashOperations = getCartHashOperations();
String hKey = cartItem.getSkuId() + "";
if (cartHashOperations.get(hKey) != null) {
cartHashOperations.put(hKey, cartItem);
}
return true;
}
/**
* 移除购物车的商品
*/
@Override
public boolean removeCartItem(Long skuId) {
BoundHashOperations cartHashOperations = getCartHashOperations();
String hKey = skuId + "";
cartHashOperations.delete(hKey);
return true;
}
/**
* 设置商品全选
*/
@Override
public boolean checkAll(boolean checked) {
BoundHashOperations cartHashOperations = getCartHashOperations();
for (Object value : cartHashOperations.values()) {
CartVO.CartItem cartItem = (CartVO.CartItem) value;
cartItem.setChecked(checked);
String hKey = cartItem.getSkuId() + "";
cartHashOperations.put(hKey, cartItem);
}
return true;
}
/**
* 移除购物车选中的商品
* 场景支付后删除购物车的商品
*/
@Override
public boolean removeCheckedItem() {
BoundHashOperations cartHashOperations = getCartHashOperations();
for (Object value : cartHashOperations.values()) {
CartVO.CartItem cartItem = (CartVO.CartItem) value;
if (cartItem.isChecked()) {
cartHashOperations.delete(cartItem.getSkuId()+"");
}
}
return true;
}
/**
* 获取第一层即某个用户的购物车
*/
private BoundHashOperations getCartHashOperations() {
Long userId = RequestUtils.getUserId(); Long userId = RequestUtils.getUserId();
String cartKey = CART_KEY + userId; String cartKey = OmsConstants.CART_PREFIX + userId;
BoundHashOperations operations = redisTemplate.boundHashOps(cartKey); BoundHashOperations operations = redisTemplate.boundHashOps(cartKey);
return operations; return operations;
} }

View File

@ -1,12 +1,12 @@
package com.youlai.mall.oms.service.impl; package com.youlai.mall.oms.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;;
import com.youlai.mall.oms.dao.OrderDeliveryDao; import com.youlai.mall.oms.mapper.OrderDeliveryMapper;
import com.youlai.mall.oms.pojo.domain.OmsOrderDelivery; import com.youlai.mall.oms.pojo.domain.OmsOrderDelivery;
import com.youlai.mall.oms.service.IOrderDeliveryService; import com.youlai.mall.oms.service.IOrderDeliveryService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service("orderDeliveryService") @Service("orderDeliveryService")
public class OrderDeliveryServiceImpl extends ServiceImpl<OrderDeliveryDao, OmsOrderDelivery> implements IOrderDeliveryService { public class OrderDeliveryServiceImpl extends ServiceImpl<OrderDeliveryMapper, OmsOrderDelivery> implements IOrderDeliveryService {
} }

View File

@ -3,7 +3,7 @@ package com.youlai.mall.oms.service.impl;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.mall.oms.dao.OrderItemDao; import com.youlai.mall.oms.mapper.OrderItemMapper;
import com.youlai.mall.oms.pojo.domain.OmsOrderItem; import com.youlai.mall.oms.pojo.domain.OmsOrderItem;
import com.youlai.mall.oms.service.IOrderItemService; import com.youlai.mall.oms.service.IOrderItemService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -17,7 +17,7 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
@Service @Service
public class OrderItemServiceImpl extends ServiceImpl<OrderItemDao, OmsOrderItem> implements IOrderItemService { public class OrderItemServiceImpl extends ServiceImpl<OrderItemMapper, OmsOrderItem> implements IOrderItemService {
@Override @Override

View File

@ -2,7 +2,7 @@ package com.youlai.mall.oms.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.common.web.util.RequestUtils; import com.youlai.common.web.util.RequestUtils;
import com.youlai.mall.oms.dao.OrderLogDao; import com.youlai.mall.oms.mapper.OrderLogMapper;
import com.youlai.mall.oms.pojo.domain.OmsOrderLog; import com.youlai.mall.oms.pojo.domain.OmsOrderLog;
import com.youlai.mall.oms.service.IOrderLogService; import com.youlai.mall.oms.service.IOrderLogService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -10,7 +10,7 @@ import org.springframework.stereotype.Service;
@Slf4j @Slf4j
@Service @Service
public class OrderLogServiceImpl extends ServiceImpl<OrderLogDao, OmsOrderLog> implements IOrderLogService { public class OrderLogServiceImpl extends ServiceImpl<OrderLogMapper, OmsOrderLog> implements IOrderLogService {
@Override @Override
public void addOrderLogs(Long orderId, Integer orderStatus, String user, String detail) { public void addOrderLogs(Long orderId, Integer orderStatus, String user, String detail) {
log.info("添加订单操作日志orderId={}detail={}", orderId, detail); log.info("添加订单操作日志orderId={}detail={}", orderId, detail);

View File

@ -3,7 +3,7 @@ package com.youlai.mall.oms.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.common.web.exception.BizException; import com.youlai.common.web.exception.BizException;
import com.youlai.common.web.util.RequestUtils; import com.youlai.common.web.util.RequestUtils;
import com.youlai.mall.oms.dao.OrderPayDao; import com.youlai.mall.oms.mapper.OrderPayMapper;
import com.youlai.mall.oms.enums.OrderStatusEnum; import com.youlai.mall.oms.enums.OrderStatusEnum;
import com.youlai.mall.oms.enums.PayTypeEnum; import com.youlai.mall.oms.enums.PayTypeEnum;
import com.youlai.mall.oms.pojo.domain.OmsOrder; import com.youlai.mall.oms.pojo.domain.OmsOrder;
@ -11,16 +11,14 @@ import com.youlai.mall.oms.pojo.domain.OmsOrderItem;
import com.youlai.mall.oms.pojo.domain.OmsOrderPay; import com.youlai.mall.oms.pojo.domain.OmsOrderPay;
import com.youlai.mall.oms.pojo.vo.PayInfoVO; import com.youlai.mall.oms.pojo.vo.PayInfoVO;
import com.youlai.mall.oms.service.IOrderItemService; import com.youlai.mall.oms.service.IOrderItemService;
import com.youlai.mall.oms.service.IOrderLogService;
import com.youlai.mall.oms.service.IOrderPayService; import com.youlai.mall.oms.service.IOrderPayService;
import com.youlai.mall.oms.service.IOrderService; import com.youlai.mall.oms.service.IOrderService;
import com.youlai.mall.pms.api.app.InventoryFeignService; import com.youlai.mall.pms.api.app.PmsSkuFeignService;
import com.youlai.mall.pms.pojo.dto.InventoryDTO; import com.youlai.mall.pms.pojo.dto.InventoryDTO;
import com.youlai.mall.ums.api.app.MemberFeignService; import com.youlai.mall.ums.api.app.UmsMemberFeignService;
import io.seata.spring.annotation.GlobalTransactional; import io.seata.spring.annotation.GlobalTransactional;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Date; import java.util.Date;
@ -31,14 +29,14 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
@Service @Service
@AllArgsConstructor @AllArgsConstructor
public class OrderPayServiceImpl extends ServiceImpl<OrderPayDao, OmsOrderPay> implements IOrderPayService { public class OrderPayServiceImpl extends ServiceImpl<OrderPayMapper, OmsOrderPay> implements IOrderPayService {
private IOrderService orderService; private IOrderService orderService;
private MemberFeignService memberFeignService; private UmsMemberFeignService memberFeignService;
private IOrderItemService orderItemService; private IOrderItemService orderItemService;
private InventoryFeignService inventoryFeignService; private PmsSkuFeignService inventoryFeignService;
@Override @Override
@GlobalTransactional(rollbackFor = Exception.class) @GlobalTransactional(rollbackFor = Exception.class)

View File

@ -2,6 +2,7 @@ package com.youlai.mall.oms.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -13,27 +14,34 @@ import com.youlai.common.result.ResultCode;
import com.youlai.common.web.exception.BizException; import com.youlai.common.web.exception.BizException;
import com.youlai.common.web.util.BeanMapperUtils; import com.youlai.common.web.util.BeanMapperUtils;
import com.youlai.common.web.util.RequestUtils; import com.youlai.common.web.util.RequestUtils;
import com.youlai.mall.oms.dao.OrderDao; import com.youlai.mall.oms.constant.OmsConstants;
import com.youlai.mall.oms.mapper.OrderMapper;
import com.youlai.mall.oms.enums.OrderStatusEnum; import com.youlai.mall.oms.enums.OrderStatusEnum;
import com.youlai.mall.oms.enums.OrderTypeEnum; import com.youlai.mall.oms.enums.OrderTypeEnum;
import com.youlai.mall.oms.pojo.bo.app.OrderBO; import com.youlai.mall.oms.pojo.bo.app.OrderBO;
import com.youlai.mall.oms.pojo.domain.OmsOrder; import com.youlai.mall.oms.pojo.domain.OmsOrder;
import com.youlai.mall.oms.pojo.domain.OmsOrderDelivery; import com.youlai.mall.oms.pojo.domain.OmsOrderDelivery;
import com.youlai.mall.oms.pojo.domain.OmsOrderItem; import com.youlai.mall.oms.pojo.domain.OmsOrderItem;
import com.youlai.mall.oms.pojo.dto.OrderConfirmDTO;
import com.youlai.mall.oms.pojo.dto.OrderSubmitDTO; import com.youlai.mall.oms.pojo.dto.OrderSubmitDTO;
import com.youlai.mall.oms.pojo.vo.*; import com.youlai.mall.oms.pojo.vo.*;
import com.youlai.mall.oms.service.*; import com.youlai.mall.oms.service.*;
import com.youlai.mall.pms.api.app.InventoryFeignService; import com.youlai.mall.pms.api.app.PmsSkuFeignService;
import com.youlai.mall.pms.pojo.domain.PmsSku;
import com.youlai.mall.pms.pojo.dto.InventoryDTO; import com.youlai.mall.pms.pojo.dto.InventoryDTO;
import com.youlai.mall.pms.pojo.dto.SkuDTO; import com.youlai.mall.pms.pojo.dto.SkuDTO;
import com.youlai.mall.ums.api.app.MemberFeignService; import com.youlai.mall.ums.api.app.UmsAddressFeignService;
import com.youlai.mall.ums.pojo.dto.UmsAddressDTO; import com.youlai.mall.ums.api.app.UmsMemberFeignService;
import com.youlai.mall.ums.pojo.domain.UmsAddress;
import io.netty.util.concurrent.CompleteFuture;
import io.seata.spring.annotation.GlobalTransactional; import io.seata.spring.annotation.GlobalTransactional;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.AsyncTaskExecutor; import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestAttributes;
@ -44,20 +52,23 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@AllArgsConstructor @AllArgsConstructor
@Slf4j @Slf4j
@Service @Service
public class OrderServiceImpl extends ServiceImpl<OrderDao, OmsOrder> implements IOrderService { public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> implements IOrderService {
private static final ThreadLocal<OrderSubmitDTO> threadLocal = new ThreadLocal<>(); private static final ThreadLocal<OrderSubmitDTO> threadLocal = new ThreadLocal<>();
private ICartService cartService; private ICartService cartService;
private InventoryFeignService inventoryFeignService; private PmsSkuFeignService skuFeignService;
private MemberFeignService memberFeignService; private UmsMemberFeignService memberFeignService;
private UmsAddressFeignService addressFeignService;
private AsyncTaskExecutor executor; private AsyncTaskExecutor executor;
@ -69,38 +80,71 @@ public class OrderServiceImpl extends ServiceImpl<OrderDao, OmsOrder> implements
private RabbitTemplate rabbitTemplate; private RabbitTemplate rabbitTemplate;
private RedisTemplate redisTemplate;
private ThreadPoolExecutor threadPoolExecutor;
@Override @Override
public OrderConfirmVO confirm(Long skuId, Integer count) { public OrderConfirmVO confirm(OrderConfirmDTO orderConfirmDTO) {
OrderConfirmVO orderConfirmVO = new OrderConfirmVO(); OrderConfirmVO orderConfirmVO = new OrderConfirmVO();
// 获取购买商品信息
CompletableFuture<Void> orderItemsCompletableFuture = CompletableFuture.runAsync(() -> {
List<OrderItemVO> orderItems = new ArrayList<>();
if (orderConfirmDTO.getSkuId() != null) { // 直接购买商品结算
OrderItemVO orderItemVO = OrderItemVO.builder()
.skuId(orderConfirmDTO.getSkuId())
.count(orderConfirmDTO.getCount())
.build();
PmsSku sku = skuFeignService.getSkuById(orderConfirmDTO.getSkuId()).getData();
orderItemVO.setPrice(sku.getPrice());
orderItemVO.setSkuPic(sku.getPic());
orderItemVO.setTitle(sku.getTitle());
orderItems.add(orderItemVO);
} else { // 购物车中商品结算
List<CartVO.CartItem> cartItems = cartService.getCartItems();
List<OrderItemVO> items = cartItems.stream()
.filter(CartVO.CartItem::isChecked)
.map(cartItem -> OrderItemVO.builder()
.skuId(cartItem.getSkuId())
.count(cartItem.getCount())
.price(cartItem.getPrice())
.title(cartItem.getTitle())
.skuPic(cartItem.getPic())
.build())
.collect(Collectors.toList());
orderItems.addAll(items);
}
orderConfirmVO.setOrderItems(orderItems);
}, threadPoolExecutor);
List<OrderItemVO> orderItems = getOrderItems(skuId, count); // 获取会员地址列表
if (CollectionUtil.isEmpty(orderItems)) { CompletableFuture<Void> addressesCompletableFuture = CompletableFuture.runAsync(() -> {
List<UmsAddress> addresses = addressFeignService.list().getData();
orderConfirmVO.setAddresses(addresses);
}, threadPoolExecutor);
// 生成唯一标识防止订单重复提交
CompletableFuture<Void> orderTokenCompletableFuture = CompletableFuture.runAsync(() -> {
String orderToken = IdUtil.randomUUID();
orderConfirmVO.setOrderToken(orderToken);
redisTemplate.opsForValue().set(OmsConstants.ORDER_TOKEN_PREFIX + orderToken, orderToken);
}, threadPoolExecutor);
CompletableFuture.allOf(orderItemsCompletableFuture, addressesCompletableFuture, orderTokenCompletableFuture);
return orderConfirmVO; return orderConfirmVO;
} }
// 远程获取商品信息填充订单商品属性
List<Long> skuIds = orderItems.stream().map(item -> item.getSkuId()).collect(Collectors.toList());
List<SkuDTO> skus = inventoryFeignService.listBySkuIds(skuIds).getData();
for (OrderItemVO orderItem : orderItems) {
skus.stream().filter(sku -> sku.getId().equals(orderItem.getSkuId())).findFirst()
.ifPresent(skuItem -> {
orderItem.setPrice(skuItem.getPrice());
orderItem.setSkuImg(skuItem.getPic());
orderItem.setSkuName(skuItem.getName());
});
}
OrderConfirmVO confirmVO = new OrderConfirmVO();
confirmVO.setOrderItems(orderItems);
return confirmVO;
}
@Override @Override
@GlobalTransactional @GlobalTransactional
@SneakyThrows public OrderSubmitVO submit(OrderSubmitDTO submitDTO) {
public OrderSubmitResultVO submit(OrderSubmitDTO submitInfoDTO) {
submitDTO.
log.info("开始创建订单:{}", submitInfoDTO); log.info("开始创建订单:{}", submitInfoDTO);
threadLocal.set(submitInfoDTO); threadLocal.set(submitInfoDTO);
RequestAttributes attributes = RequestContextHolder.getRequestAttributes(); RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
@ -262,9 +306,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderDao, OmsOrder> implements
} }
// 将订单放入延时队列超时未支付系统自动关单 // 将订单放入延时队列超时未支付系统自动关单
rabbitTemplate.convertAndSend("order_event_exchange", "order:create", orderId); rabbitTemplate.convertAndSend("order-exchange", "order:create", orderId);
OrderSubmitResultVO result = new OrderSubmitResultVO(); OrderSubmitVO result = new OrderSubmitVO();
result.setId(orderId); result.setId(orderId);
result.setOrderSn(order.getOrderSn()); result.setOrderSn(order.getOrderSn());
return result; return result;

View File

@ -1,13 +1,13 @@
package com.youlai.mall.oms.service.impl; package com.youlai.mall.oms.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.mall.oms.dao.OrderSettingDao; import com.youlai.mall.oms.mapper.OrderSettingMapper;
import com.youlai.mall.oms.pojo.domain.OmsOrderSetting; import com.youlai.mall.oms.pojo.domain.OmsOrderSetting;
import com.youlai.mall.oms.service.IOrderSettingService; import com.youlai.mall.oms.service.IOrderSettingService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
public class OrderSettingServiceImpl extends ServiceImpl<OrderSettingDao, OmsOrderSetting> implements IOrderSettingService { public class OrderSettingServiceImpl extends ServiceImpl<OrderSettingMapper, OmsOrderSetting> implements IOrderSettingService {
} }

View File

@ -1,74 +0,0 @@
package com.youlai.mall.oms.service.impl;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.youlai.common.web.exception.BizException;
import com.youlai.common.web.util.RequestUtils;
import com.youlai.mall.oms.service.TokenService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import static com.youlai.mall.oms.constant.OmsConstants.REDIS_KEY_TIME_OUT;
import static com.youlai.mall.oms.constant.OmsConstants.TOKEN_VERIFY;
/**
* @author huawei
* @desc Token 服务
* @email huawei_code@163.com
* @date 2021/1/21
*/
@Service
@AllArgsConstructor
@Slf4j
public class TokenServiceImpl implements TokenService {
private static final String TOKEN = "token";
private RedisTemplate redisTemplate;
@Override
public String generateToken() {
StringBuffer sb = new StringBuffer();
String userId = RequestUtils.getUserId().toString();
//生成UUID
String token = IdUtil.randomUUID();
//前缀 + 用户ID + UUID组成 token
String key = sb.append(TOKEN_VERIFY).append(userId).append(':').append(token).toString();
//将token写入redis并设置过期时间
redisTemplate.opsForValue().set(key, key, REDIS_KEY_TIME_OUT);
//redis写入成功则设置token成功
return token;
}
@Override
public void checkToken(HttpServletRequest request) {
String token = request.getHeader(TOKEN);
if (StringUtils.isBlank(token)) {
token = request.getParameter(TOKEN);
if (StringUtils.isBlank(token)) {
throw new BizException("请勿重复提交");
}
}
StringBuilder sb = new StringBuilder();
String userId = RequestUtils.getUserId().toString();
String key = sb.append(TOKEN_VERIFY).append(userId).append(':').append(token).toString();
// 2校验token是否存在
if (!StrUtil.equals(redisTemplate.opsForValue().get(key).toString(), key)) {
log.debug("请求:{} 使用 token{} 校验幂等性,缓存中不存在", request.getRequestURI(), token);
throw new BizException("请勿重复提交");
}
// 3校验token是否删除成功
if (!redisTemplate.delete(key)) {
log.debug("请求:{} 使用 token{} 校验幂等性,删除缓存数据失败", request.getRequestURI(), token);
throw new BizException("请勿重复提交");
}
}
}

View File

@ -1,31 +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.youlai.mall.oms.dao.OrderDao">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.youlai.mall.oms.pojo.domain.OmsOrder" id="orderMap">
<result property="id" column="id"/>
<result property="orderSn" column="order_sn"/>
<result property="totalAmount" column="total_amount"/>
<result property="totalQuantity" column="total_quantity"/>
<result property="sourceType" column="source_type"/>
<result property="status" column="status"/>
<result property="remark" column="remark"/>
<result property="memberId" column="member_id"/>
<result property="couponId" column="coupon_id"/>
<result property="couponAmount" column="coupon_amount"/>
<result property="freightAmount" column="freight_amount"/>
<result property="payAmount" column="pay_amount"/>
<result property="payTime" column="pay_time"/>
<result property="payType" column="pay_type"/>
<result property="deliveryTime" column="delivery_time"/>
<result property="receiveTime" column="receive_time"/>
<result property="commentTime" column="comment_time"/>
<result property="deleted" column="deleted"/>
<result property="gmtCreate" column="gmt_create"/>
<result property="gmtModified" column="gmt_modified"/>
</resultMap>
</mapper>

View File

@ -1,29 +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.youlai.mall.oms.dao.OrderDeliveryDao">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.youlai.mall.oms.pojo.domain.OmsOrderDelivery" id="orderDeliveryMap">
<result property="id" column="id"/>
<result property="orderId" column="order_id"/>
<result property="deliveryCompany" column="delivery_company"/>
<result property="deliverySn" column="delivery_sn"/>
<result property="receiverName" column="receiver_name"/>
<result property="receiverPhone" column="receiver_phone"/>
<result property="receiverPostCode" column="receiver_post_code"/>
<result property="receiverProvince" column="receiver_province"/>
<result property="receiverCity" column="receiver_city"/>
<result property="receiverRegion" column="receiver_region"/>
<result property="receiverDetailAddress" column="receiver_detail_address"/>
<result property="remark" column="remark"/>
<result property="deliveryStatus" column="delivery_status"/>
<result property="deliveryTime" column="delivery_time"/>
<result property="receiveTime" column="receive_time"/>
<result property="deleted" column="deleted"/>
<result property="gmtCreate" column="gmt_create"/>
<result property="gmtModified" column="gmt_modified"/>
</resultMap>
</mapper>

View File

@ -1,30 +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.youlai.mall.oms.dao.OrderItemDao">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.youlai.mall.oms.pojo.domain.OmsOrderItem" id="orderGoodsMap">
<result property="id" column="id"/>
<result property="orderId" column="order_id"/>
<result property="skuId" column="sku_id"/>
<result property="skuCode" column="sku_code"/>
<result property="skuName" column="sku_name"/>
<result property="skuPic" column="sku_pic"/>
<result property="skuPrice" column="sku_price"/>
<result property="skuQuantity" column="sku_quantity"/>
<result property="skuTotalPrice" column="sku_total_price"/>
<result property="spuId" column="spu_id"/>
<result property="spuName" column="spu_name"/>
<result property="spuPic" column="spu_pic"/>
<result property="brandId" column="brand_id"/>
<result property="brandName" column="brand_name"/>
<result property="categoryId" column="category_id"/>
<result property="categoryName" column="category_name"/>
<result property="deleted" column="deleted"/>
<result property="gmtCreate" column="gmt_create"/>
<result property="gmtModified" column="gmt_modified"/>
</resultMap>
</mapper>

View File

@ -1,20 +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.youlai.mall.oms.dao.OrderLogDao">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.youlai.mall.oms.pojo.domain.OmsOrderLog" id="orderLogsMap">
<result property="id" column="id"/>
<result property="orderId" column="order_id"/>
<result property="user" column="user"/>
<result property="detail" column="detail"/>
<result property="orderStatus" column="order_status"/>
<result property="remark" column="remark"/>
<result property="deleted" column="deleted"/>
<result property="gmtCreate" column="gmt_create"/>
<result property="gmtModified" column="gmt_modified"/>
</resultMap>
</mapper>

View File

@ -1,25 +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.youlai.mall.oms.dao.OrderPayDao">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.youlai.mall.oms.pojo.domain.OmsOrderPay" id="orderPayMap">
<result property="id" column="id"/>
<result property="orderId" column="order_id"/>
<result property="paySn" column="pay_sn"/>
<result property="payAmount" column="pay_amount"/>
<result property="payTime" column="pay_time"/>
<result property="payType" column="pay_type"/>
<result property="payStatus" column="pay_status"/>
<result property="confirmTime" column="confirm_time"/>
<result property="callbackContent" column="callback_content"/>
<result property="callbackTime" column="callback_time"/>
<result property="paySubject" column="pay_subject"/>
<result property="deleted" column="deleted"/>
<result property="gmtCreate" column="gmt_create"/>
<result property="gmtModified" column="gmt_modified"/>
</resultMap>
</mapper>

View File

@ -1,21 +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.youlai.mall.oms.dao.OrderSettingDao">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.youlai.mall.oms.pojo.domain.OmsOrderSetting" id="orderSettingMap">
<result property="id" column="id"/>
<result property="flashOrderOvertime" column="flash_order_overtime"/>
<result property="normalOrderOvertime" column="normal_order_overtime"/>
<result property="confirmOvertime" column="confirm_overtime"/>
<result property="finishOvertime" column="finish_overtime"/>
<result property="commentOvertime" column="comment_overtime"/>
<result property="memberLevel" column="member_level"/>
<result property="deleted" column="deleted"/>
<result property="gmtCreate" column="gmt_create"/>
<result property="gmtModified" column="gmt_modified"/>
</resultMap>
</mapper>

View File

@ -1,6 +1,7 @@
package com.youlai.mall.pms.api.app; package com.youlai.mall.pms.api.app;
import com.youlai.common.result.Result; import com.youlai.common.result.Result;
import com.youlai.mall.pms.pojo.domain.PmsSku;
import com.youlai.mall.pms.pojo.dto.SkuDTO; import com.youlai.mall.pms.pojo.dto.SkuDTO;
import com.youlai.mall.pms.pojo.dto.InventoryDTO; import com.youlai.mall.pms.pojo.dto.InventoryDTO;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
@ -9,7 +10,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
@FeignClient(value = "mall-pms") @FeignClient(value = "mall-pms")
public interface InventoryFeignService { public interface PmsSkuFeignService {
/** /**
* 获取库存列表 * 获取库存列表
@ -21,7 +22,7 @@ public interface InventoryFeignService {
* 获取库存信息 * 获取库存信息
*/ */
@GetMapping("/api.app/v1/skus/{id}") @GetMapping("/api.app/v1/skus/{id}")
Result<SkuDTO> getSkuById(@PathVariable Long id); Result<PmsSku> getSkuById(@PathVariable Long id);
/** /**
* 锁定库存 * 锁定库存

View File

@ -11,7 +11,7 @@ public class PmsSku extends BaseEntity {
@TableId(type = IdType.AUTO) @TableId(type = IdType.AUTO)
private Long id; private Long id;
private Long spuId; private Long spuId;
private String name; private String title;
private String code; private String code;
private String pic; private String pic;
private Long originPrice; private Long originPrice;

View File

@ -15,28 +15,14 @@ public class SkuDTO {
private String code; private String code;
private String name; private String title;
private String pic; private String pic;
private Long originPrice;
private Long price; private Long price;
private Integer inventory;
private Long spuId; private Long spuId;
private String productName;
private String productPic;
private Long brandId;
private String brandName;
private Long categoryId;
private String categoryName;
} }

View File

@ -30,7 +30,7 @@ public class OrderItemVO extends BaseVO {
*/ */
@Getter @Getter
@Setter @Setter
private String skuName; private String title;
/** /**
* 商品数量 * 商品数量

View File

@ -25,11 +25,9 @@ public class SkuController {
@ApiOperation(value = "商品库存详情", httpMethod = "GET") @ApiOperation(value = "商品库存详情", httpMethod = "GET")
@ApiImplicitParam(name = "id", value = "商品库存ID", required = true, paramType = "path", dataType = "Long") @ApiImplicitParam(name = "id", value = "商品库存ID", required = true, paramType = "path", dataType = "Long")
@GetMapping("/{id}") @GetMapping("/{id}")
public Result<SkuDTO> detail(@PathVariable Long id) { public Result detail(@PathVariable Long id) {
PmsSku sku = iPmsSkuService.getById(id); PmsSku sku = iPmsSkuService.getById(id);
SkuDTO SkuDTO = new SkuDTO(); return Result.success(sku);
BeanUtil.copyProperties(sku, SkuDTO);
return Result.success(SkuDTO);
} }
@ApiOperation("获取商品的库存数量") @ApiOperation("获取商品的库存数量")

View File

@ -1,18 +0,0 @@
package com.youlai.mall.ums.api.admin;
import com.youlai.common.result.Result;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
@FeignClient(value = "mall-ums",contextId = "AdminMemberFeignService")
public interface MemberFeignService {
/**
* 扣减会员余额
*/
@PatchMapping("/api.admin/v1/users/{id}/balance/_deduct")
Result deductBalance(@PathVariable Long id, @RequestParam Long amount);
}

View File

@ -0,0 +1,28 @@
package com.youlai.mall.ums.api.app;
import com.youlai.common.result.Result;
import com.youlai.mall.ums.pojo.domain.UmsAddress;
import com.youlai.mall.ums.pojo.domain.UmsMember;
import com.youlai.mall.ums.pojo.dto.AuthMemberDTO;
import com.youlai.mall.ums.pojo.dto.MemberDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@FeignClient(value = "mall-ums")
public interface UmsAddressFeignService {
/**
* 获取地址详情
*/
@GetMapping("/api.app/v1/addresses/{id}")
Result<UmsAddress> getById(@PathVariable("id") Long id);
@GetMapping("/api.app/v1/addresses")
Result<List<UmsAddress>> list();
}

View File

@ -1,62 +1,52 @@
package com.youlai.mall.ums.api.app; package com.youlai.mall.ums.api.app;
import com.youlai.common.result.Result; import com.youlai.common.result.Result;
import com.youlai.mall.ums.pojo.domain.UmsUser; import com.youlai.mall.ums.pojo.domain.UmsMember;
import com.youlai.mall.ums.pojo.dto.AuthMemberDTO; import com.youlai.mall.ums.pojo.dto.AuthMemberDTO;
import com.youlai.mall.ums.pojo.dto.MemberDTO; import com.youlai.mall.ums.pojo.dto.MemberDTO;
import com.youlai.mall.ums.pojo.dto.UmsAddressDTO;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@FeignClient(value = "mall-ums") @FeignClient(value = "mall-ums")
public interface MemberFeignService { public interface UmsMemberFeignService {
@PostMapping("/api.app/v1/users") @PostMapping("/api.app/v1/users")
Result add(@RequestBody UmsUser user); Result add(@RequestBody UmsMember user);
/** /**
* 获取会员信息 * 获取会员信息
*/ */
@GetMapping("/api.app/v1/users/{id}") @GetMapping("/api.app/v1/members/{id}")
Result<MemberDTO> getUserById(@PathVariable Long id); Result<MemberDTO> getUserById(@PathVariable Long id);
/** /**
* 获取认证会员信息 * 获取认证会员信息
*/ */
@GetMapping("/api.app/v1/users/openid/{openid}") @GetMapping("/api.app/v1/members/openid/{openid}")
Result<AuthMemberDTO> getUserByOpenid(@PathVariable String openid); Result<AuthMemberDTO> getUserByOpenid(@PathVariable String openid);
/** /**
* 修改会员积分 * 修改会员积分
*/ */
@PutMapping("/api.admin/v1/users/{id}/point") @PutMapping("/api.admin/v1/members/{id}/point")
Result updatePoint(@PathVariable Long id, @RequestParam Integer num); Result updatePoint(@PathVariable Long id, @RequestParam Integer num);
/**
* 获取地址详情
*
* @param id 地址id
* @return 地址详情
*/
@GetMapping("/api.app/v1/addresses/{id}")
Result<UmsAddressDTO> getAddressById(@PathVariable("id") String id);
/** /**
* 修改会员余额 * 修改会员余额
*/ */
@PutMapping("/api.app/v1/users/{id}/balance") @PutMapping("/api.app/v1/members/{id}/balances")
Result updateBalance(@PathVariable Long id, @RequestParam Long balance); Result updateBalance(@PathVariable Long id, @RequestParam Long balance);
/** /**
* 获取会员余额 * 获取会员余额
*/ */
@GetMapping("/api.app/v1/users/{id}/balance") @GetMapping("/api.app/v1/members/{id}/balances")
Result<Long> getBalance(@PathVariable Long id); Result<Long> getBalance(@PathVariable Long id);
} }

View File

@ -13,7 +13,7 @@ import java.util.List;
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
public class UmsUser extends BaseEntity { public class UmsMember extends BaseEntity {
@TableId(type = IdType.AUTO) @TableId(type = IdType.AUTO)
private Long id; private Long id;

View File

@ -1,33 +0,0 @@
package com.youlai.mall.ums.pojo.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
@Data
@Accessors(chain = true)
public class UmsAddressDTO implements Serializable {
private Long id;
private Long userId;
private String name;
private String mobile;
private String province;
private String city;
private String area;
private String address;
private String zipCode;
private Integer defaulted;
}

View File

@ -8,7 +8,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youlai.common.constant.GlobalConstants; import com.youlai.common.constant.GlobalConstants;
import com.youlai.common.enums.QueryModeEnum; import com.youlai.common.enums.QueryModeEnum;
import com.youlai.common.result.Result; import com.youlai.common.result.Result;
import com.youlai.mall.ums.pojo.domain.UmsUser; import com.youlai.mall.ums.pojo.domain.UmsMember;
import com.youlai.mall.ums.service.IUmsUserService; import com.youlai.mall.ums.service.IUmsUserService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
@ -16,7 +16,6 @@ import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Arrays; import java.util.Arrays;
@ -26,7 +25,7 @@ import java.util.Arrays;
@RequestMapping("/api.admin/v1/users") @RequestMapping("/api.admin/v1/users")
@Slf4j @Slf4j
@AllArgsConstructor @AllArgsConstructor
public class UserController { public class MemberController {
private IUmsUserService iUmsUserService; private IUmsUserService iUmsUserService;
@ -45,12 +44,12 @@ public class UserController {
String nickname String nickname
) { ) {
QueryModeEnum queryModeEnum = QueryModeEnum.getValue(queryMode); QueryModeEnum queryModeEnum = QueryModeEnum.getValue(queryMode);
LambdaQueryWrapper<UmsUser> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<UmsMember> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.ne(UmsUser::getDeleted, GlobalConstants.DELETED_VALUE); queryWrapper.ne(UmsMember::getDeleted, GlobalConstants.DELETED_VALUE);
switch (queryModeEnum) { switch (queryModeEnum) {
default: // PAGE default: // PAGE
queryWrapper.like(StrUtil.isNotBlank(nickname), UmsUser::getNickname, nickname); queryWrapper.like(StrUtil.isNotBlank(nickname), UmsMember::getNickname, nickname);
IPage<UmsUser> result = iUmsUserService.list(new Page<>(page, limit), new UmsUser().setNickname(nickname)); IPage<UmsMember> result = iUmsUserService.list(new Page<>(page, limit), new UmsMember().setNickname(nickname));
return Result.success(result.getRecords(), result.getTotal()); return Result.success(result.getRecords(), result.getTotal());
} }
} }
@ -61,7 +60,7 @@ public class UserController {
public Result getMemberById( public Result getMemberById(
@PathVariable Long id @PathVariable Long id
) { ) {
UmsUser user = iUmsUserService.getById(id); UmsMember user = iUmsUserService.getById(id);
return Result.success(user); return Result.success(user);
} }
@ -73,7 +72,7 @@ public class UserController {
@PutMapping(value = "/{id}") @PutMapping(value = "/{id}")
public Result update( public Result update(
@PathVariable Integer id, @PathVariable Integer id,
@RequestBody UmsUser user) { @RequestBody UmsMember user) {
boolean status = iUmsUserService.updateById(user); boolean status = iUmsUserService.updateById(user);
return Result.judge(status); return Result.judge(status);
} }
@ -84,9 +83,9 @@ public class UserController {
@ApiImplicitParam(name = "member", value = "实体JSON对象", required = true, paramType = "body", dataType = "UmsMember") @ApiImplicitParam(name = "member", value = "实体JSON对象", required = true, paramType = "body", dataType = "UmsMember")
}) })
@PatchMapping("/{id}") @PatchMapping("/{id}")
public Result patch(@PathVariable Long id, @RequestBody UmsUser user) { public Result patch(@PathVariable Long id, @RequestBody UmsMember user) {
LambdaUpdateWrapper<UmsUser> updateWrapper = new LambdaUpdateWrapper<UmsUser>().eq(UmsUser::getId, id); LambdaUpdateWrapper<UmsMember> updateWrapper = new LambdaUpdateWrapper<UmsMember>().eq(UmsMember::getId, id);
updateWrapper.set(user.getStatus() != null, UmsUser::getStatus, user.getStatus()); updateWrapper.set(user.getStatus() != null, UmsMember::getStatus, user.getStatus());
boolean status = iUmsUserService.update(updateWrapper); boolean status = iUmsUserService.update(updateWrapper);
return Result.judge(status); return Result.judge(status);
} }
@ -95,9 +94,9 @@ public class UserController {
@ApiImplicitParam(name = "ids", value = "id集合", required = true, paramType = "query", dataType = "String") @ApiImplicitParam(name = "ids", value = "id集合", required = true, paramType = "query", dataType = "String")
@DeleteMapping("/{ids}") @DeleteMapping("/{ids}")
public Result delete(@PathVariable String ids) { public Result delete(@PathVariable String ids) {
boolean status = iUmsUserService.update(new LambdaUpdateWrapper<UmsUser>() boolean status = iUmsUserService.update(new LambdaUpdateWrapper<UmsMember>()
.in(UmsUser::getId, Arrays.asList(ids.split(","))) .in(UmsMember::getId, Arrays.asList(ids.split(",")))
.set(UmsUser::getDeleted, GlobalConstants.DELETED_VALUE)); .set(UmsMember::getDeleted, GlobalConstants.DELETED_VALUE));
return Result.judge(status); return Result.judge(status);
} }
@ -108,9 +107,9 @@ public class UserController {
}) })
@PatchMapping("/{id}/balance/_deduct") @PatchMapping("/{id}/balance/_deduct")
public Result deductBalance(@PathVariable Long id, @RequestParam Long amount) { public Result deductBalance(@PathVariable Long id, @RequestParam Long amount) {
LambdaUpdateWrapper<UmsUser> updateWrapper = new LambdaUpdateWrapper<UmsUser>().eq(UmsUser::getId, id); LambdaUpdateWrapper<UmsMember> updateWrapper = new LambdaUpdateWrapper<UmsMember>().eq(UmsMember::getId, id);
updateWrapper.setSql(" balance = balance - " + amount); updateWrapper.setSql(" balance = balance - " + amount);
updateWrapper.gt(UmsUser::getBalance, amount); updateWrapper.gt(UmsMember::getBalance, amount);
boolean result = iUmsUserService.update(updateWrapper); boolean result = iUmsUserService.update(updateWrapper);
return Result.judge(result); return Result.judge(result);
} }

View File

@ -3,7 +3,7 @@ package com.youlai.mall.ums.controller.admin;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.youlai.common.result.Result; import com.youlai.common.result.Result;
import com.youlai.mall.ums.pojo.domain.UmsUser; import com.youlai.mall.ums.pojo.domain.UmsMember;
import com.youlai.mall.ums.pojo.dto.RechargeDTO; import com.youlai.mall.ums.pojo.dto.RechargeDTO;
import com.youlai.mall.ums.pojo.dto.ResultPayDTO; import com.youlai.mall.ums.pojo.dto.ResultPayDTO;
import com.youlai.mall.ums.service.IUmsUserService; import com.youlai.mall.ums.service.IUmsUserService;
@ -113,7 +113,7 @@ public class RechargeController {
//处理自己的业务逻辑 //处理自己的业务逻辑
//例如开通会员用户充值等等 //例如开通会员用户充值等等
String thirduid = resultPay.getThirduid(); String thirduid = resultPay.getThirduid();
UmsUser user = iUmsUserService.getById(thirduid); UmsMember user = iUmsUserService.getById(thirduid);
if (user != null) { if (user != null) {
user.setBalance((long) (user.getBalance() + Float.valueOf(resultPay.getPrice()) * 100 * 10000)); user.setBalance((long) (user.getBalance() + Float.valueOf(resultPay.getPrice()) * 100 * 10000));
} }

View File

@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.youlai.common.result.Result; import com.youlai.common.result.Result;
import com.youlai.common.result.ResultCode; import com.youlai.common.result.ResultCode;
import com.youlai.common.web.util.RequestUtils; import com.youlai.common.web.util.RequestUtils;
import com.youlai.mall.ums.pojo.domain.UmsUser; import com.youlai.mall.ums.pojo.domain.UmsMember;
import com.youlai.mall.ums.pojo.dto.AuthMemberDTO; import com.youlai.mall.ums.pojo.dto.AuthMemberDTO;
import com.youlai.mall.ums.pojo.dto.MemberDTO; import com.youlai.mall.ums.pojo.dto.MemberDTO;
import com.youlai.mall.ums.pojo.vo.MemberVO; import com.youlai.mall.ums.pojo.vo.MemberVO;
@ -20,10 +20,10 @@ import org.springframework.web.bind.annotation.*;
@Api(tags = "【移动端】会员服务") @Api(tags = "【移动端】会员服务")
@RestController @RestController
@RequestMapping("/api.app/v1/users") @RequestMapping("/api.app/v1/members")
@Slf4j @Slf4j
@AllArgsConstructor @AllArgsConstructor
public class UserController { public class MemberController {
private IUmsUserService iUmsUserService; private IUmsUserService iUmsUserService;
@ -34,10 +34,10 @@ public class UserController {
@PathVariable Long id @PathVariable Long id
) { ) {
MemberDTO memberDTO = new MemberDTO(); MemberDTO memberDTO = new MemberDTO();
UmsUser user = iUmsUserService.getOne( UmsMember user = iUmsUserService.getOne(
new LambdaQueryWrapper<UmsUser>() new LambdaQueryWrapper<UmsMember>()
.select(UmsUser::getId, UmsUser::getNickname, UmsUser::getMobile, UmsUser::getBalance) .select(UmsMember::getId, UmsMember::getNickname, UmsMember::getMobile, UmsMember::getBalance)
.eq(UmsUser::getId, id) .eq(UmsMember::getId, id)
); );
if (user != null) { if (user != null) {
BeanUtil.copyProperties(user, memberDTO); BeanUtil.copyProperties(user, memberDTO);
@ -51,8 +51,8 @@ public class UserController {
public Result getMemberByOpenid( public Result getMemberByOpenid(
@PathVariable String openid @PathVariable String openid
) { ) {
UmsUser user = iUmsUserService.getOne(new LambdaQueryWrapper<UmsUser>() UmsMember user = iUmsUserService.getOne(new LambdaQueryWrapper<UmsMember>()
.eq(UmsUser::getOpenid, openid)); .eq(UmsMember::getOpenid, openid));
if (user == null) { if (user == null) {
return Result.failed(ResultCode.USER_NOT_EXIST); return Result.failed(ResultCode.USER_NOT_EXIST);
} }
@ -64,7 +64,7 @@ public class UserController {
@ApiOperation(value = "新增会员", httpMethod = "POST") @ApiOperation(value = "新增会员", httpMethod = "POST")
@ApiImplicitParam(name = "member", value = "实体JSON对象", required = true, paramType = "body", dataType = "UmsMember") @ApiImplicitParam(name = "member", value = "实体JSON对象", required = true, paramType = "body", dataType = "UmsMember")
@PostMapping @PostMapping
public Result add(@RequestBody UmsUser user) { public Result add(@RequestBody UmsMember user) {
boolean status = iUmsUserService.save(user); boolean status = iUmsUserService.save(user);
return Result.judge(status); return Result.judge(status);
} }
@ -73,7 +73,7 @@ public class UserController {
@GetMapping("/me") @GetMapping("/me")
public Result getMemberInfo() { public Result getMemberInfo() {
Long userId = RequestUtils.getUserId(); Long userId = RequestUtils.getUserId();
UmsUser user = iUmsUserService.getById(userId); UmsMember user = iUmsUserService.getById(userId);
if (user == null) { if (user == null) {
return Result.failed(ResultCode.USER_NOT_EXIST); return Result.failed(ResultCode.USER_NOT_EXIST);
} }
@ -88,9 +88,9 @@ public class UserController {
@ApiImplicitParam(name = "id", value = "会员ID", required = true, paramType = "path", dataType = "Long"), @ApiImplicitParam(name = "id", value = "会员ID", required = true, paramType = "path", dataType = "Long"),
@ApiImplicitParam(name = "num", value = "积分数量", required = true, paramType = "query", dataType = "Integer") @ApiImplicitParam(name = "num", value = "积分数量", required = true, paramType = "query", dataType = "Integer")
}) })
@PutMapping("/{id}/point") @PutMapping("/{id}/points")
public Result updatePoint(@PathVariable Long id, @RequestParam Integer num) { public Result updatePoint(@PathVariable Long id, @RequestParam Integer num) {
UmsUser user = iUmsUserService.getById(id); UmsMember user = iUmsUserService.getById(id);
user.setPoint(user.getPoint() + num); user.setPoint(user.getPoint() + num);
boolean result = iUmsUserService.updateById(user); boolean result = iUmsUserService.updateById(user);
return Result.judge(result); return Result.judge(result);
@ -101,9 +101,9 @@ public class UserController {
@ApiImplicitParam(name = "id", value = "会员ID", required = true, paramType = "path", dataType = "Long"), @ApiImplicitParam(name = "id", value = "会员ID", required = true, paramType = "path", dataType = "Long"),
@ApiImplicitParam(name = "balance", value = "会员余额", required = true, paramType = "query", dataType = "Long") @ApiImplicitParam(name = "balance", value = "会员余额", required = true, paramType = "query", dataType = "Long")
}) })
@PutMapping("/{id}/balance") @PutMapping("/{id}/balances")
public Result updateBalance(@PathVariable Long id, @RequestParam Long balance) { public Result updateBalance(@PathVariable Long id, @RequestParam Long balance) {
UmsUser user = iUmsUserService.getById(id); UmsMember user = iUmsUserService.getById(id);
user.setBalance(user.getBalance() - balance); user.setBalance(user.getBalance() - balance);
boolean result = iUmsUserService.updateById(user); boolean result = iUmsUserService.updateById(user);
return Result.judge(result); return Result.judge(result);
@ -111,10 +111,10 @@ public class UserController {
@ApiOperation(value = "获取会员余额", httpMethod = "GET") @ApiOperation(value = "获取会员余额", httpMethod = "GET")
@ApiImplicitParam(name = "id", value = "会员ID", required = true, paramType = "path", dataType = "Long") @ApiImplicitParam(name = "id", value = "会员ID", required = true, paramType = "path", dataType = "Long")
@GetMapping("/{id}/balance") @GetMapping("/{id}/balances")
public Result<Long> updateBalance(@PathVariable Long id) { public Result<Long> updateBalance(@PathVariable Long id) {
Long balance = 0l; Long balance = 0l;
UmsUser user = iUmsUserService.getById(id); UmsMember user = iUmsUserService.getById(id);
if (user != null) { if (user != null) {
balance = user.getBalance(); balance = user.getBalance();
} }

View File

@ -2,7 +2,7 @@ package com.youlai.mall.ums.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youlai.mall.ums.pojo.domain.UmsUser; import com.youlai.mall.ums.pojo.domain.UmsMember;
import org.apache.ibatis.annotations.Many; import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result; import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results; import org.apache.ibatis.annotations.Results;
@ -13,7 +13,7 @@ import java.util.List;
@Mapper @Mapper
public interface UmsUserMapper extends BaseMapper<UmsUser> { public interface UmsUserMapper extends BaseMapper<UmsMember> {
@Select("<script>" + @Select("<script>" +
@ -27,7 +27,7 @@ public interface UmsUserMapper extends BaseMapper<UmsUser> {
@Result(id = true, column = "id", property = "id"), @Result(id = true, column = "id", property = "id"),
@Result(property = "addressList", column = "id", many = @Many(select = "com.youlai.mall.ums.mapper.UmsAddressMapper.listByUserId")) @Result(property = "addressList", column = "id", many = @Many(select = "com.youlai.mall.ums.mapper.UmsAddressMapper.listByUserId"))
}) })
List<UmsUser> list(Page<UmsUser> page, UmsUser user); List<UmsMember> list(Page<UmsMember> page, UmsMember user);
} }

View File

@ -4,9 +4,9 @@ package com.youlai.mall.ums.service;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.mall.ums.pojo.domain.UmsUser; import com.youlai.mall.ums.pojo.domain.UmsMember;
public interface IUmsUserService extends IService<UmsUser> { public interface IUmsUserService extends IService<UmsMember> {
IPage<UmsUser> list(Page<UmsUser> page, UmsUser user); IPage<UmsMember> list(Page<UmsMember> page, UmsMember user);
} }

View File

@ -3,7 +3,7 @@ package com.youlai.mall.ums.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
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;
import com.youlai.mall.ums.pojo.domain.UmsUser; import com.youlai.mall.ums.pojo.domain.UmsMember;
import com.youlai.mall.ums.mapper.UmsUserMapper; import com.youlai.mall.ums.mapper.UmsUserMapper;
import com.youlai.mall.ums.service.IUmsUserService; import com.youlai.mall.ums.service.IUmsUserService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -11,12 +11,12 @@ import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@Service @Service
public class UmsUserServiceImpl extends ServiceImpl<UmsUserMapper, UmsUser> implements IUmsUserService { public class UmsUserServiceImpl extends ServiceImpl<UmsUserMapper, UmsMember> implements IUmsUserService {
@Override @Override
public IPage<UmsUser> list(Page<UmsUser> page, UmsUser spu) { public IPage<UmsMember> list(Page<UmsMember> page, UmsMember spu) {
List<UmsUser> list = this.baseMapper.list(page, spu); List<UmsMember> list = this.baseMapper.list(page, spu);
page.setRecords(list); page.setRecords(list);
return page; return page;
} }

View File

@ -1,13 +1,13 @@
package com.youlai.auth; package com.youlai.auth;
import com.youlai.admin.api.UserFeignService; import com.youlai.admin.api.UserFeignService;
import com.youlai.mall.ums.api.app.MemberFeignService; import com.youlai.mall.ums.api.app.UmsMemberFeignService;
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.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.EnableFeignClients;
@EnableFeignClients(basePackageClasses = {UserFeignService.class, MemberFeignService.class}) @EnableFeignClients(basePackageClasses = {UserFeignService.class, UmsMemberFeignService.class})
@SpringBootApplication @SpringBootApplication
@EnableDiscoveryClient @EnableDiscoveryClient
public class AuthApplication { public class AuthApplication {

View File

@ -10,8 +10,8 @@ import com.youlai.common.result.Result;
import com.youlai.common.result.ResultCode; import com.youlai.common.result.ResultCode;
import com.youlai.common.web.exception.BizException; import com.youlai.common.web.exception.BizException;
import com.youlai.common.web.util.RequestUtils; import com.youlai.common.web.util.RequestUtils;
import com.youlai.mall.ums.api.app.MemberFeignService; import com.youlai.mall.ums.api.app.UmsMemberFeignService;
import com.youlai.mall.ums.pojo.domain.UmsUser; import com.youlai.mall.ums.pojo.domain.UmsMember;
import com.youlai.mall.ums.pojo.dto.AuthMemberDTO; import com.youlai.mall.ums.pojo.dto.AuthMemberDTO;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
@ -23,7 +23,6 @@ import me.chanjar.weixin.common.error.WxErrorException;
import org.apache.logging.log4j.util.Strings; import org.apache.logging.log4j.util.Strings;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.common.OAuth2AccessToken; import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.provider.endpoint.TokenEndpoint; import org.springframework.security.oauth2.provider.endpoint.TokenEndpoint;
import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@ -86,7 +85,7 @@ public class AuthController {
private WxMaService wxService; private WxMaService wxService;
private MemberFeignService memberFeignService; private UmsMemberFeignService memberFeignService;
private PasswordEncoder passwordEncoder; private PasswordEncoder passwordEncoder;
public OAuth2AccessToken handleForWxAuth(Principal principal, Map<String, String> parameters) throws HttpRequestMethodNotSupportedException { public OAuth2AccessToken handleForWxAuth(Principal principal, Map<String, String> parameters) throws HttpRequestMethodNotSupportedException {
@ -116,7 +115,7 @@ public class AuthController {
if (userInfo == null) { if (userInfo == null) {
throw new BizException("获取用户信息失败"); throw new BizException("获取用户信息失败");
} }
UmsUser user = new UmsUser() UmsMember user = new UmsMember()
.setNickname(userInfo.getNickName()) .setNickname(userInfo.getNickName())
.setAvatar(userInfo.getAvatarUrl()) .setAvatar(userInfo.getAvatarUrl())
.setGender(Integer.valueOf(userInfo.getGender())) .setGender(Integer.valueOf(userInfo.getGender()))

View File

@ -8,7 +8,7 @@ import com.youlai.common.result.Result;
import com.youlai.common.result.ResultCode; import com.youlai.common.result.ResultCode;
import com.youlai.common.web.util.RequestUtils; import com.youlai.common.web.util.RequestUtils;
import com.youlai.mall.ums.pojo.dto.AuthMemberDTO; import com.youlai.mall.ums.pojo.dto.AuthMemberDTO;
import com.youlai.mall.ums.api.app.MemberFeignService; import com.youlai.mall.ums.api.app.UmsMemberFeignService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.security.authentication.AccountExpiredException; import org.springframework.security.authentication.AccountExpiredException;
import org.springframework.security.authentication.DisabledException; import org.springframework.security.authentication.DisabledException;
@ -27,7 +27,7 @@ import org.springframework.stereotype.Service;
public class UserDetailsServiceImpl implements UserDetailsService { public class UserDetailsServiceImpl implements UserDetailsService {
private UserFeignService userFeignService; private UserFeignService userFeignService;
private MemberFeignService memberFeignService; private UmsMemberFeignService memberFeignService;
@Override @Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {