mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2024-12-23 05:00:25 +08:00
feat:订单提交优化
This commit is contained in:
parent
5f6f6ba768
commit
905d21999c
@ -39,7 +39,7 @@ public class OmsOrderItem extends BaseEntity {
|
||||
/**
|
||||
* 商品sku名字
|
||||
*/
|
||||
private String skuName;
|
||||
private String title;
|
||||
/**
|
||||
* 商品sku图片
|
||||
*/
|
||||
|
@ -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;
|
||||
|
||||
}
|
@ -1,22 +1,25 @@
|
||||
package com.youlai.mall.oms.pojo.dto;
|
||||
|
||||
import com.youlai.mall.oms.pojo.vo.OrderItemVO;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author huawei
|
||||
* @desc 订单提交实体类
|
||||
* @desc 订单提交
|
||||
* @email huawei_code@163.com
|
||||
* @date 2021/1/16
|
||||
*/
|
||||
@Data
|
||||
public class OrderSubmitDTO {
|
||||
|
||||
private Long skuId;
|
||||
// 提交订单确认页面签发的令牌
|
||||
private String orderToken;
|
||||
|
||||
private Integer skuNum;
|
||||
private List<OrderItemVO> orderItems;
|
||||
|
||||
private Long payAmount;
|
||||
|
||||
|
@ -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;
|
||||
}
|
@ -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;
|
||||
|
||||
}
|
@ -12,45 +12,27 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
@ToString
|
||||
@Builder
|
||||
@Data
|
||||
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() {
|
||||
return items;
|
||||
}
|
||||
private String pic;
|
||||
|
||||
public void setItems(List<CartItemVO> items) {
|
||||
this.items = items;
|
||||
}
|
||||
private Integer count;
|
||||
|
||||
public Integer getTotalNum() {
|
||||
int total = 0;
|
||||
if (items != null && items.size() > 0) {
|
||||
total = items.stream().filter(CartItemVO::isChecked).mapToInt(CartItemVO::getNum).sum();
|
||||
}
|
||||
return total;
|
||||
}
|
||||
private Long price;
|
||||
|
||||
public void setTotalNum(Integer totalNum) {
|
||||
this.totalNum = totalNum;
|
||||
}
|
||||
private Long coupon;
|
||||
|
||||
public Long getTotalPrice() {
|
||||
long total = 0L;
|
||||
if (items != null && items.size() > 0) {
|
||||
total = items.stream().filter(CartItemVO::isChecked).mapToLong(CartItemVO::getSubtotal).sum();
|
||||
}
|
||||
return total;
|
||||
}
|
||||
private boolean checked;
|
||||
|
||||
public void setTotalPrice(Long totalPrice) {
|
||||
this.totalPrice = totalPrice;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
@ -14,11 +14,8 @@ import lombok.Setter;
|
||||
public class OrderItemVO extends BaseVO {
|
||||
|
||||
private Long skuId;
|
||||
private String skuImg;
|
||||
private String skuName;
|
||||
private Integer count;
|
||||
private String skuPic;
|
||||
private String title;
|
||||
private Long price;
|
||||
private Long coupon;
|
||||
|
||||
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ public class OrderListVO extends BaseVO {
|
||||
private String skuPic;
|
||||
private Integer skuQuantity;
|
||||
private Long skuTotalPrice;
|
||||
private String skuName;
|
||||
private String title;
|
||||
private Long price;
|
||||
private String image;
|
||||
private Integer number;
|
||||
|
@ -10,7 +10,7 @@ import lombok.Data;
|
||||
* @date 2021/1/21
|
||||
*/
|
||||
@Data
|
||||
public class OrderSubmitResultVO extends BaseVO {
|
||||
public class OrderSubmitVO extends BaseVO {
|
||||
/**
|
||||
* 订单ID
|
||||
*/
|
@ -1,9 +1,8 @@
|
||||
package com.youlai.mall.oms;
|
||||
|
||||
|
||||
import com.youlai.mall.pms.api.app.InventoryFeignService;
|
||||
import com.youlai.mall.ums.api.app.MemberFeignService;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import com.youlai.mall.pms.api.app.PmsSkuFeignService;
|
||||
import com.youlai.mall.ums.api.app.UmsMemberFeignService;
|
||||
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
@ -13,8 +12,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
|
||||
@EnableDiscoveryClient
|
||||
@EnableFeignClients(basePackageClasses = { MemberFeignService.class, InventoryFeignService.class})
|
||||
@MapperScan({ "com.youlai.mall.oms.mapper","com.youlai.mall.oms.dao"})
|
||||
@EnableFeignClients(basePackageClasses = { UmsMemberFeignService.class, PmsSkuFeignService.class})
|
||||
@EnableRabbit
|
||||
public class OmsApplication {
|
||||
|
||||
|
@ -1,10 +1,8 @@
|
||||
package com.youlai.mall.oms.config;
|
||||
|
||||
import com.youlai.mall.oms.constant.OmsConstants;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.*;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@ -15,8 +13,7 @@ import java.util.Map;
|
||||
* @author huawei
|
||||
* @email huawei_code@163.com
|
||||
* @date 2021/1/17
|
||||
* @desc rabbitmq 业务相关配置类
|
||||
* 订单相关业务统一使用 order-event-exchange 交换机
|
||||
* @desc 业务描述
|
||||
* 1. 订单创建成功,发送消息到创建订单的路由
|
||||
* 2. 创建订单的路由转发消息给延时队列,延时队列的延时时间就是订单从创建到支付过程,允许的最大等待时间。延时队列不能有消费者(即消息不能被消费)
|
||||
* 3. 延时时间一到,消息被转入DLX(死信路由)
|
||||
@ -28,16 +25,13 @@ import java.util.Map;
|
||||
@AllArgsConstructor
|
||||
public class RabbitMQConfig {
|
||||
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
/**
|
||||
* 定义交换机
|
||||
* 定义交换机,订单业务统一使用 order-exchange 交换机
|
||||
*/
|
||||
@Bean
|
||||
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() {
|
||||
// 延时队列的消息过期了,会自动触发消息的转发,根据routingKey发送到指定的exchange中,exchange路由到死信队列
|
||||
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-message-ttl", 60000); // 单位:毫秒,配置1分钟测试使用
|
||||
return new Queue("order.delay.queue", true, false, false, args);
|
||||
@ -58,7 +52,7 @@ public class RabbitMQConfig {
|
||||
*/
|
||||
@Bean
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
@ -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;
|
||||
// }
|
||||
//}
|
@ -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;
|
||||
//}
|
@ -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;
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -5,11 +5,10 @@ package com.youlai.mall.oms.constant;
|
||||
* @date 2021-03-16
|
||||
*/
|
||||
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:";
|
||||
|
||||
|
@ -11,8 +11,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 购物车
|
||||
*
|
||||
* @author huawei
|
||||
* @email huawei_code@163.com
|
||||
* @date 2020-12-30 22:31:10
|
||||
@ -27,9 +25,9 @@ public class CartController {
|
||||
|
||||
private ICartService cartService;
|
||||
|
||||
@ApiOperation(value = "查询购物车", httpMethod = "GET")
|
||||
@ApiOperation(value = "查询用户购物车", httpMethod = "GET")
|
||||
@GetMapping
|
||||
public Result getCart() {
|
||||
public Result get() {
|
||||
CartVO cart = cartService.getCart();
|
||||
return Result.success(cart);
|
||||
}
|
||||
@ -42,37 +40,33 @@ public class CartController {
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "局部更新购物车商品", httpMethod = "PUT")
|
||||
@ApiOperation(value = "更新购物车商品", httpMethod = "PUT")
|
||||
@PutMapping("/skuId/{skuId}")
|
||||
public Result updateCartItem(
|
||||
@PathVariable Long skuId,
|
||||
Integer num,
|
||||
Boolean checked
|
||||
) {
|
||||
cartService.updateCartItem(skuId, num, checked);
|
||||
return Result.success();
|
||||
public Result updateCartItem(@RequestBody CartVO.CartItem cartItem) {
|
||||
boolean result = cartService.updateCartItem(cartItem);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "全选/全不选择购物车商品", httpMethod = "PUT")
|
||||
@ApiImplicitParam(name = "checked", value = "全选/全不选", required = true, paramType = "param", dataType = "Boolean")
|
||||
@PatchMapping("/batch")
|
||||
public Result checkAll(Boolean checked) {
|
||||
cartService.checkAll(checked);
|
||||
return Result.success();
|
||||
public Result checkAll(boolean checked) {
|
||||
boolean result = cartService.checkAll(checked);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@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}")
|
||||
public Result deleteCartItem(@PathVariable Long skuId) {
|
||||
cartService.deleteCartItem(skuId);
|
||||
return Result.success();
|
||||
public Result removeCartItem(@PathVariable Long skuId) {
|
||||
boolean result = cartService.removeCartItem(skuId);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "清空购物车", httpMethod = "DELETE")
|
||||
@DeleteMapping
|
||||
public Result deleteCart() {
|
||||
cartService.deleteCart();
|
||||
return Result.success();
|
||||
boolean result = cartService.deleteCart();
|
||||
return Result.judge(result);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
package com.youlai.mall.oms.controller.app;
|
||||
|
||||
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.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.service.IOrderService;
|
||||
import io.swagger.annotations.*;
|
||||
@ -29,42 +30,22 @@ public class OrderController {
|
||||
|
||||
private IOrderService orderService;
|
||||
|
||||
/**
|
||||
* 订单确认信息,生成订单
|
||||
* 如果入参传了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")
|
||||
|
||||
})
|
||||
@ApiOperation(value = "确认订单", httpMethod = "POST")
|
||||
@ApiImplicitParam(name = "orderConfirm",value = "确认订单信息",required = true, paramType = "body", dataType = "OrderConfirmDTO")
|
||||
@PostMapping("/_confirm")
|
||||
public Result<OrderConfirmVO> confirm(
|
||||
Long skuId,
|
||||
Integer num
|
||||
) {
|
||||
OrderConfirmVO confirm = orderService.confirm(skuId, num);
|
||||
return Result.success(confirm);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "提交订单", httpMethod = "POST")
|
||||
@ApiImplicitParam(name = "orderSubmitInfoDTO", value = "提交订单信息", required = true, paramType = "body", dataType = "OrderSubmitInfoDTO")
|
||||
@PostMapping("/_submit")
|
||||
public Result submit(@Valid @RequestBody OrderSubmitDTO orderSubmitDTO) {
|
||||
OrderSubmitResultVO result = orderService.submit(orderSubmitDTO);
|
||||
public Result<OrderConfirmVO> confirm(@RequestBody OrderConfirmDTO orderConfirm) {
|
||||
OrderConfirmVO result = orderService.confirm(orderConfirm);
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "提交订单", httpMethod = "POST")
|
||||
@ApiImplicitParam(name = "orderSubmitDTO", value = "提交订单信息", required = true, paramType = "body", dataType = "orderSubmitDTO")
|
||||
@PostMapping("/_submit")
|
||||
public Result submit(@Valid @RequestBody OrderSubmitDTO orderSubmitDTO) {
|
||||
OrderSubmitVO result = orderService.submit(orderSubmitDTO);
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据订单状态查询订单列表
|
||||
* 步骤:
|
||||
* 1、入参 status 表示订单状态
|
||||
* 2、status = 0 表示查询所有订单
|
||||
* 3、已删除订单无法查询
|
||||
*/
|
||||
@ApiOperation("订单列表查询")
|
||||
@GetMapping("/list")
|
||||
public Result<List<OrderListVO>> list(
|
||||
|
@ -15,8 +15,6 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
||||
/**
|
||||
* 订单支付服务
|
||||
*
|
||||
* @author huawei
|
||||
* @email huawei_code@163.com
|
||||
* @date 2020-12-30 22:31:10
|
||||
@ -26,7 +24,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
@RequestMapping("/api.app/v1/payments")
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class PaymentController {
|
||||
public class PayController {
|
||||
|
||||
private IOrderPayService orderPayService;
|
||||
|
@ -4,7 +4,7 @@ import com.rabbitmq.client.Channel;
|
||||
import com.youlai.mall.oms.pojo.domain.OmsOrderItem;
|
||||
import com.youlai.mall.oms.service.IOrderItemService;
|
||||
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 lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -23,7 +23,7 @@ import java.util.stream.Collectors;
|
||||
* @date 2021-03-16
|
||||
*/
|
||||
|
||||
//@Component
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
@Slf4j
|
||||
public class RabbitMQListener {
|
||||
@ -32,7 +32,7 @@ public class RabbitMQListener {
|
||||
|
||||
IOrderItemService orderItemService;
|
||||
|
||||
InventoryFeignService inventoryFeignService;
|
||||
PmsSkuFeignService inventoryFeignService;
|
||||
|
||||
RabbitTemplate rabbitTemplate;
|
||||
|
||||
|
@ -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.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
@ -12,6 +12,6 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
* @date 2020-12-30 22:31:10
|
||||
*/
|
||||
@Mapper
|
||||
public interface OrderDeliveryDao extends BaseMapper<OmsOrderDelivery> {
|
||||
public interface OrderDeliveryMapper extends BaseMapper<OmsOrderDelivery> {
|
||||
|
||||
}
|
@ -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.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
@ -12,6 +12,6 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
* @date 2020-12-30 22:31:10
|
||||
*/
|
||||
@Mapper
|
||||
public interface OrderItemDao extends BaseMapper<OmsOrderItem> {
|
||||
public interface OrderItemMapper extends BaseMapper<OmsOrderItem> {
|
||||
|
||||
}
|
@ -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.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
@ -12,6 +12,6 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
* @date 2020-12-30 22:31:10
|
||||
*/
|
||||
@Mapper
|
||||
public interface OrderLogDao extends BaseMapper<OmsOrderLog> {
|
||||
public interface OrderLogMapper extends BaseMapper<OmsOrderLog> {
|
||||
|
||||
}
|
@ -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.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
@ -12,6 +12,6 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
* @date 2020-12-30 22:31:10
|
||||
*/
|
||||
@Mapper
|
||||
public interface OrderDao extends BaseMapper<OmsOrder> {
|
||||
public interface OrderMapper extends BaseMapper<OmsOrder> {
|
||||
|
||||
}
|
@ -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.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
@ -12,6 +12,6 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
* @date 2020-12-30 22:31:10
|
||||
*/
|
||||
@Mapper
|
||||
public interface OrderPayDao extends BaseMapper<OmsOrderPay> {
|
||||
public interface OrderPayMapper extends BaseMapper<OmsOrderPay> {
|
||||
|
||||
}
|
@ -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.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
@ -12,6 +12,6 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
* @date 2020-12-30 22:31:10
|
||||
*/
|
||||
@Mapper
|
||||
public interface OrderSettingDao extends BaseMapper<OmsOrderSetting> {
|
||||
public interface OrderSettingMapper extends BaseMapper<OmsOrderSetting> {
|
||||
|
||||
}
|
@ -2,46 +2,28 @@ package com.youlai.mall.oms.service;
|
||||
|
||||
import com.youlai.mall.oms.pojo.vo.CartVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 购物车业务接口
|
||||
*/
|
||||
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();
|
||||
|
||||
/**
|
||||
* 清空购物车
|
||||
*/
|
||||
void deleteCart();
|
||||
List<CartVO.CartItem> getCartItems();
|
||||
|
||||
/**
|
||||
* 清空购物车中已选择商品
|
||||
*/
|
||||
void deleteSelectedItem();
|
||||
boolean deleteCart();
|
||||
|
||||
boolean addCartItem(Long skuId);
|
||||
|
||||
boolean updateCartItem(CartVO.CartItem cartItem);
|
||||
|
||||
boolean removeCartItem(Long skuId);
|
||||
|
||||
boolean removeCheckedItem();
|
||||
|
||||
boolean checkAll(boolean checked);
|
||||
|
||||
}
|
||||
|
@ -3,9 +3,10 @@ package com.youlai.mall.oms.service;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
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.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 java.util.List;
|
||||
@ -20,58 +21,40 @@ import java.util.List;
|
||||
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);
|
||||
|
||||
/**
|
||||
* 取消订单接口
|
||||
*
|
||||
* @param id 订单ID
|
||||
* @return 是否取消成功
|
||||
*/
|
||||
boolean cancelOrder(Long id);
|
||||
|
||||
/**
|
||||
* 删除订单
|
||||
*
|
||||
* @param id 订单ID
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
boolean deleteOrder(Long id);
|
||||
|
||||
/**
|
||||
* 订单列表查询
|
||||
*
|
||||
* @param status 订单状态
|
||||
* @return 订单列表
|
||||
*/
|
||||
List<OrderListVO> list(Integer status);
|
||||
|
||||
/**
|
||||
* 根据订单ID获取订单信息
|
||||
*
|
||||
* @param id 订单ID
|
||||
* @return 订单信息
|
||||
*/
|
||||
OmsOrder getByOrderId(Long id);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
@ -1,14 +1,12 @@
|
||||
package com.youlai.mall.oms.service.impl;
|
||||
|
||||
import com.youlai.common.result.Result;
|
||||
import com.youlai.common.web.util.RequestUtils;
|
||||
import com.youlai.mall.pms.api.app.InventoryFeignService;
|
||||
import com.youlai.mall.pms.pojo.dto.SkuDTO;
|
||||
import com.youlai.mall.oms.pojo.vo.CartItemVO;
|
||||
import com.youlai.mall.oms.constant.OmsConstants;
|
||||
import com.youlai.mall.oms.pojo.vo.CartVO;
|
||||
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.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.redis.core.BoundHashOperations;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
@ -17,133 +15,151 @@ import org.springframework.stereotype.Service;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static com.youlai.mall.oms.constant.OmsConstants.CART_KEY;
|
||||
|
||||
|
||||
/**
|
||||
* 购物车模块搭建步骤
|
||||
* 1、用户登录后才能操作购物车
|
||||
* *********添加购物车*************
|
||||
* 1、获取当前登录用户
|
||||
* 2、添加商品到购物车
|
||||
* 2.1、如果购物车中已经有该商品的相关数据
|
||||
* 2.1.1、修改购物车商品数量
|
||||
* 2.2、如果购物车中没有该商品,新增该商品
|
||||
* 2.2.1、调用商品服务查询商品sku详情
|
||||
* 2.2.2、封装CartItem实体类
|
||||
* *********修改购物车*************
|
||||
* *********删除购物车*************
|
||||
* *********查询购物车*************
|
||||
* 购物车模块
|
||||
* <p>
|
||||
* 技术点:BoundHashOperations
|
||||
* 数据格式:
|
||||
* -- key <----> 购物车
|
||||
* -- hKey:value <----> 购物车商品1
|
||||
* -- hKey:value <----> 购物车商品2
|
||||
* -- hKey:value <----> 购物车商品3
|
||||
*/
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class CartServiceImpl implements ICartService {
|
||||
|
||||
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
|
||||
public CartVO getCart() {
|
||||
BoundHashOperations cartHashOpts = getCartHashOpts();
|
||||
List<CartItemVO> items = cartHashOpts.values();
|
||||
CartVO cartVo = new CartVO();
|
||||
cartVo.setItems(items);
|
||||
return cartVo;
|
||||
CartVO cart = new CartVO();
|
||||
BoundHashOperations cartHashOperations = getCartHashOperations();
|
||||
List<CartVO.CartItem> cartItems = cartHashOperations.values();
|
||||
cart.setItems(cartItems);
|
||||
return cart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteCart() {
|
||||
Long userId = RequestUtils.getUserId();
|
||||
String key = CART_KEY + userId;
|
||||
public List<CartVO.CartItem> getCartItems() {
|
||||
BoundHashOperations cartHashOperations = getCartHashOperations();
|
||||
List<CartVO.CartItem> cartItems = cartHashOperations.values();
|
||||
return cartItems;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除用户购物车(清空购物车)
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteCart() {
|
||||
String key = OmsConstants.CART_PREFIX + RequestUtils.getUserId();
|
||||
redisTemplate.delete(key);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加商品至购物车
|
||||
*/
|
||||
@Override
|
||||
public void deleteSelectedItem() {
|
||||
log.info("清空购物车中已选择商品");
|
||||
BoundHashOperations cartHashOpts = getCartHashOpts();
|
||||
for (Object value : cartHashOpts.values()) {
|
||||
CartItemVO cartItem = (CartItemVO) value;
|
||||
public boolean addCartItem(Long skuId) {
|
||||
BoundHashOperations cartHashOperations = getCartHashOperations();
|
||||
String hKey = skuId + "";
|
||||
|
||||
CartVO.CartItem cartItem;
|
||||
// 购物车已存在该商品,更新商品数量
|
||||
if (cartHashOperations.get(hKey) != null) {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新购物车总商品数量、选中状态
|
||||
*/
|
||||
@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()) {
|
||||
log.info("清空购物车中商品,商品id:{} | 名称:{}", cartItem.getSkuId(), cartItem.getSkuName());
|
||||
cartHashOpts.delete(cartItem.getSkuId().toString());
|
||||
cartHashOperations.delete(cartItem.getSkuId()+"");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private BoundHashOperations getCartHashOpts() {
|
||||
/**
|
||||
* 获取第一层,即某个用户的购物车
|
||||
*/
|
||||
private BoundHashOperations getCartHashOperations() {
|
||||
Long userId = RequestUtils.getUserId();
|
||||
String cartKey = CART_KEY + userId;
|
||||
String cartKey = OmsConstants.CART_PREFIX + userId;
|
||||
BoundHashOperations operations = redisTemplate.boundHashOps(cartKey);
|
||||
return operations;
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
package com.youlai.mall.oms.service.impl;
|
||||
|
||||
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.service.IOrderDeliveryService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service("orderDeliveryService")
|
||||
public class OrderDeliveryServiceImpl extends ServiceImpl<OrderDeliveryDao, OmsOrderDelivery> implements IOrderDeliveryService {
|
||||
public class OrderDeliveryServiceImpl extends ServiceImpl<OrderDeliveryMapper, OmsOrderDelivery> implements IOrderDeliveryService {
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package com.youlai.mall.oms.service.impl;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
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.service.IOrderItemService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -17,7 +17,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class OrderItemServiceImpl extends ServiceImpl<OrderItemDao, OmsOrderItem> implements IOrderItemService {
|
||||
public class OrderItemServiceImpl extends ServiceImpl<OrderItemMapper, OmsOrderItem> implements IOrderItemService {
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -2,7 +2,7 @@ package com.youlai.mall.oms.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
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.service.IOrderLogService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -10,7 +10,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class OrderLogServiceImpl extends ServiceImpl<OrderLogDao, OmsOrderLog> implements IOrderLogService {
|
||||
public class OrderLogServiceImpl extends ServiceImpl<OrderLogMapper, OmsOrderLog> implements IOrderLogService {
|
||||
@Override
|
||||
public void addOrderLogs(Long orderId, Integer orderStatus, String user, String detail) {
|
||||
log.info("添加订单操作日志,orderId={},detail={}", orderId, detail);
|
||||
|
@ -3,7 +3,7 @@ package com.youlai.mall.oms.service.impl;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.youlai.common.web.exception.BizException;
|
||||
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.PayTypeEnum;
|
||||
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.vo.PayInfoVO;
|
||||
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.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.ums.api.app.MemberFeignService;
|
||||
import com.youlai.mall.ums.api.app.UmsMemberFeignService;
|
||||
import io.seata.spring.annotation.GlobalTransactional;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
@ -31,14 +29,14 @@ import java.util.stream.Collectors;
|
||||
@Slf4j
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class OrderPayServiceImpl extends ServiceImpl<OrderPayDao, OmsOrderPay> implements IOrderPayService {
|
||||
public class OrderPayServiceImpl extends ServiceImpl<OrderPayMapper, OmsOrderPay> implements IOrderPayService {
|
||||
|
||||
private IOrderService orderService;
|
||||
private MemberFeignService memberFeignService;
|
||||
private UmsMemberFeignService memberFeignService;
|
||||
|
||||
private IOrderItemService orderItemService;
|
||||
|
||||
private InventoryFeignService inventoryFeignService;
|
||||
private PmsSkuFeignService inventoryFeignService;
|
||||
|
||||
@Override
|
||||
@GlobalTransactional(rollbackFor = Exception.class)
|
||||
|
@ -2,6 +2,7 @@ package com.youlai.mall.oms.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
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.util.BeanMapperUtils;
|
||||
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.OrderTypeEnum;
|
||||
import com.youlai.mall.oms.pojo.bo.app.OrderBO;
|
||||
import com.youlai.mall.oms.pojo.domain.OmsOrder;
|
||||
import com.youlai.mall.oms.pojo.domain.OmsOrderDelivery;
|
||||
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.vo.*;
|
||||
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.SkuDTO;
|
||||
import com.youlai.mall.ums.api.app.MemberFeignService;
|
||||
import com.youlai.mall.ums.pojo.dto.UmsAddressDTO;
|
||||
import com.youlai.mall.ums.api.app.UmsAddressFeignService;
|
||||
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 lombok.AllArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.task.AsyncTaskExecutor;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
@ -44,20 +52,23 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Slf4j
|
||||
@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 ICartService cartService;
|
||||
|
||||
private InventoryFeignService inventoryFeignService;
|
||||
private PmsSkuFeignService skuFeignService;
|
||||
|
||||
private MemberFeignService memberFeignService;
|
||||
private UmsMemberFeignService memberFeignService;
|
||||
|
||||
private UmsAddressFeignService addressFeignService;
|
||||
|
||||
private AsyncTaskExecutor executor;
|
||||
|
||||
@ -69,38 +80,71 @@ public class OrderServiceImpl extends ServiceImpl<OrderDao, OmsOrder> implements
|
||||
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
private ThreadPoolExecutor threadPoolExecutor;
|
||||
|
||||
|
||||
@Override
|
||||
public OrderConfirmVO confirm(Long skuId, Integer count) {
|
||||
public OrderConfirmVO confirm(OrderConfirmDTO orderConfirmDTO) {
|
||||
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);
|
||||
|
||||
OrderConfirmVO orderConfirmVO=new OrderConfirmVO();
|
||||
// 获取会员地址列表
|
||||
CompletableFuture<Void> addressesCompletableFuture = CompletableFuture.runAsync(() -> {
|
||||
List<UmsAddress> addresses = addressFeignService.list().getData();
|
||||
orderConfirmVO.setAddresses(addresses);
|
||||
}, threadPoolExecutor);
|
||||
|
||||
List<OrderItemVO> orderItems = getOrderItems(skuId, count);
|
||||
if (CollectionUtil.isEmpty(orderItems)) {
|
||||
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());
|
||||
});
|
||||
}
|
||||
// 生成唯一标识,防止订单重复提交
|
||||
CompletableFuture<Void> orderTokenCompletableFuture = CompletableFuture.runAsync(() -> {
|
||||
String orderToken = IdUtil.randomUUID();
|
||||
orderConfirmVO.setOrderToken(orderToken);
|
||||
redisTemplate.opsForValue().set(OmsConstants.ORDER_TOKEN_PREFIX + orderToken, orderToken);
|
||||
}, threadPoolExecutor);
|
||||
|
||||
OrderConfirmVO confirmVO = new OrderConfirmVO();
|
||||
confirmVO.setOrderItems(orderItems);
|
||||
return confirmVO;
|
||||
CompletableFuture.allOf(orderItemsCompletableFuture, addressesCompletableFuture, orderTokenCompletableFuture);
|
||||
return orderConfirmVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
@GlobalTransactional
|
||||
@SneakyThrows
|
||||
public OrderSubmitResultVO submit(OrderSubmitDTO submitInfoDTO) {
|
||||
public OrderSubmitVO submit(OrderSubmitDTO submitDTO) {
|
||||
|
||||
submitDTO.
|
||||
|
||||
|
||||
|
||||
|
||||
log.info("开始创建订单:{}", submitInfoDTO);
|
||||
threadLocal.set(submitInfoDTO);
|
||||
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.setOrderSn(order.getOrderSn());
|
||||
return result;
|
||||
|
@ -1,13 +1,13 @@
|
||||
package com.youlai.mall.oms.service.impl;
|
||||
|
||||
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.service.IOrderSettingService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
@Service
|
||||
public class OrderSettingServiceImpl extends ServiceImpl<OrderSettingDao, OmsOrderSetting> implements IOrderSettingService {
|
||||
public class OrderSettingServiceImpl extends ServiceImpl<OrderSettingMapper, OmsOrderSetting> implements IOrderSettingService {
|
||||
|
||||
}
|
||||
|
@ -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("请勿重复提交");
|
||||
}
|
||||
}
|
||||
}
|
@ -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>
|
@ -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>
|
@ -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>
|
@ -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>
|
@ -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>
|
@ -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>
|
@ -1,6 +1,7 @@
|
||||
package com.youlai.mall.pms.api.app;
|
||||
|
||||
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.InventoryDTO;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
@ -9,7 +10,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
@FeignClient(value = "mall-pms")
|
||||
public interface InventoryFeignService {
|
||||
public interface PmsSkuFeignService {
|
||||
|
||||
/**
|
||||
* 获取库存列表
|
||||
@ -21,7 +22,7 @@ public interface InventoryFeignService {
|
||||
* 获取库存信息
|
||||
*/
|
||||
@GetMapping("/api.app/v1/skus/{id}")
|
||||
Result<SkuDTO> getSkuById(@PathVariable Long id);
|
||||
Result<PmsSku> getSkuById(@PathVariable Long id);
|
||||
|
||||
/**
|
||||
* 锁定库存
|
@ -11,7 +11,7 @@ public class PmsSku extends BaseEntity {
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
private Long spuId;
|
||||
private String name;
|
||||
private String title;
|
||||
private String code;
|
||||
private String pic;
|
||||
private Long originPrice;
|
||||
|
@ -15,28 +15,14 @@ public class SkuDTO {
|
||||
|
||||
private String code;
|
||||
|
||||
private String name;
|
||||
private String title;
|
||||
|
||||
private String pic;
|
||||
|
||||
private Long originPrice;
|
||||
|
||||
private Long price;
|
||||
|
||||
private Integer inventory;
|
||||
|
||||
private Long spuId;
|
||||
|
||||
private String productName;
|
||||
|
||||
private String productPic;
|
||||
|
||||
private Long brandId;
|
||||
|
||||
private String brandName;
|
||||
|
||||
private Long categoryId;
|
||||
|
||||
private String categoryName;
|
||||
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public class OrderItemVO extends BaseVO {
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
private String skuName;
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 商品数量
|
||||
|
@ -25,11 +25,9 @@ public class SkuController {
|
||||
@ApiOperation(value = "商品库存详情", httpMethod = "GET")
|
||||
@ApiImplicitParam(name = "id", value = "商品库存ID", required = true, paramType = "path", dataType = "Long")
|
||||
@GetMapping("/{id}")
|
||||
public Result<SkuDTO> detail(@PathVariable Long id) {
|
||||
public Result detail(@PathVariable Long id) {
|
||||
PmsSku sku = iPmsSkuService.getById(id);
|
||||
SkuDTO SkuDTO = new SkuDTO();
|
||||
BeanUtil.copyProperties(sku, SkuDTO);
|
||||
return Result.success(SkuDTO);
|
||||
return Result.success(sku);
|
||||
}
|
||||
|
||||
@ApiOperation("获取商品的库存数量")
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,62 +1,52 @@
|
||||
package com.youlai.mall.ums.api.app;
|
||||
|
||||
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.MemberDTO;
|
||||
import com.youlai.mall.ums.pojo.dto.UmsAddressDTO;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@FeignClient(value = "mall-ums")
|
||||
public interface MemberFeignService {
|
||||
public interface UmsMemberFeignService {
|
||||
|
||||
@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);
|
||||
|
||||
|
||||
/**
|
||||
* 获取认证会员信息
|
||||
*/
|
||||
@GetMapping("/api.app/v1/users/openid/{openid}")
|
||||
@GetMapping("/api.app/v1/members/openid/{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);
|
||||
|
||||
/**
|
||||
* 获取地址详情
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* 获取会员余额
|
||||
*/
|
||||
@GetMapping("/api.app/v1/users/{id}/balance")
|
||||
@GetMapping("/api.app/v1/members/{id}/balances")
|
||||
Result<Long> getBalance(@PathVariable Long id);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ import java.util.List;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class UmsUser extends BaseEntity {
|
||||
public class UmsMember extends BaseEntity {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
@ -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;
|
||||
}
|
@ -8,7 +8,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.youlai.common.constant.GlobalConstants;
|
||||
import com.youlai.common.enums.QueryModeEnum;
|
||||
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 io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
@ -16,7 +16,6 @@ import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -26,7 +25,7 @@ import java.util.Arrays;
|
||||
@RequestMapping("/api.admin/v1/users")
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class UserController {
|
||||
public class MemberController {
|
||||
|
||||
private IUmsUserService iUmsUserService;
|
||||
|
||||
@ -45,12 +44,12 @@ public class UserController {
|
||||
String nickname
|
||||
) {
|
||||
QueryModeEnum queryModeEnum = QueryModeEnum.getValue(queryMode);
|
||||
LambdaQueryWrapper<UmsUser> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.ne(UmsUser::getDeleted, GlobalConstants.DELETED_VALUE);
|
||||
LambdaQueryWrapper<UmsMember> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.ne(UmsMember::getDeleted, GlobalConstants.DELETED_VALUE);
|
||||
switch (queryModeEnum) {
|
||||
default: // PAGE
|
||||
queryWrapper.like(StrUtil.isNotBlank(nickname), UmsUser::getNickname, nickname);
|
||||
IPage<UmsUser> result = iUmsUserService.list(new Page<>(page, limit), new UmsUser().setNickname(nickname));
|
||||
queryWrapper.like(StrUtil.isNotBlank(nickname), UmsMember::getNickname, nickname);
|
||||
IPage<UmsMember> result = iUmsUserService.list(new Page<>(page, limit), new UmsMember().setNickname(nickname));
|
||||
return Result.success(result.getRecords(), result.getTotal());
|
||||
}
|
||||
}
|
||||
@ -61,7 +60,7 @@ public class UserController {
|
||||
public Result getMemberById(
|
||||
@PathVariable Long id
|
||||
) {
|
||||
UmsUser user = iUmsUserService.getById(id);
|
||||
UmsMember user = iUmsUserService.getById(id);
|
||||
return Result.success(user);
|
||||
}
|
||||
|
||||
@ -73,7 +72,7 @@ public class UserController {
|
||||
@PutMapping(value = "/{id}")
|
||||
public Result update(
|
||||
@PathVariable Integer id,
|
||||
@RequestBody UmsUser user) {
|
||||
@RequestBody UmsMember user) {
|
||||
boolean status = iUmsUserService.updateById(user);
|
||||
return Result.judge(status);
|
||||
}
|
||||
@ -84,9 +83,9 @@ public class UserController {
|
||||
@ApiImplicitParam(name = "member", value = "实体JSON对象", required = true, paramType = "body", dataType = "UmsMember")
|
||||
})
|
||||
@PatchMapping("/{id}")
|
||||
public Result patch(@PathVariable Long id, @RequestBody UmsUser user) {
|
||||
LambdaUpdateWrapper<UmsUser> updateWrapper = new LambdaUpdateWrapper<UmsUser>().eq(UmsUser::getId, id);
|
||||
updateWrapper.set(user.getStatus() != null, UmsUser::getStatus, user.getStatus());
|
||||
public Result patch(@PathVariable Long id, @RequestBody UmsMember user) {
|
||||
LambdaUpdateWrapper<UmsMember> updateWrapper = new LambdaUpdateWrapper<UmsMember>().eq(UmsMember::getId, id);
|
||||
updateWrapper.set(user.getStatus() != null, UmsMember::getStatus, user.getStatus());
|
||||
boolean status = iUmsUserService.update(updateWrapper);
|
||||
return Result.judge(status);
|
||||
}
|
||||
@ -95,9 +94,9 @@ public class UserController {
|
||||
@ApiImplicitParam(name = "ids", value = "id集合", required = true, paramType = "query", dataType = "String")
|
||||
@DeleteMapping("/{ids}")
|
||||
public Result delete(@PathVariable String ids) {
|
||||
boolean status = iUmsUserService.update(new LambdaUpdateWrapper<UmsUser>()
|
||||
.in(UmsUser::getId, Arrays.asList(ids.split(",")))
|
||||
.set(UmsUser::getDeleted, GlobalConstants.DELETED_VALUE));
|
||||
boolean status = iUmsUserService.update(new LambdaUpdateWrapper<UmsMember>()
|
||||
.in(UmsMember::getId, Arrays.asList(ids.split(",")))
|
||||
.set(UmsMember::getDeleted, GlobalConstants.DELETED_VALUE));
|
||||
return Result.judge(status);
|
||||
}
|
||||
|
||||
@ -108,9 +107,9 @@ public class UserController {
|
||||
})
|
||||
@PatchMapping("/{id}/balance/_deduct")
|
||||
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.gt(UmsUser::getBalance, amount);
|
||||
updateWrapper.gt(UmsMember::getBalance, amount);
|
||||
boolean result = iUmsUserService.update(updateWrapper);
|
||||
return Result.judge(result);
|
||||
}
|
@ -3,7 +3,7 @@ package com.youlai.mall.ums.controller.admin;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
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.ResultPayDTO;
|
||||
import com.youlai.mall.ums.service.IUmsUserService;
|
||||
@ -113,7 +113,7 @@ public class RechargeController {
|
||||
//处理自己的业务逻辑
|
||||
//例如开通会员、用户充值等等。。。
|
||||
String thirduid = resultPay.getThirduid();
|
||||
UmsUser user = iUmsUserService.getById(thirduid);
|
||||
UmsMember user = iUmsUserService.getById(thirduid);
|
||||
if (user != null) {
|
||||
user.setBalance((long) (user.getBalance() + Float.valueOf(resultPay.getPrice()) * 100 * 10000));
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.youlai.common.result.Result;
|
||||
import com.youlai.common.result.ResultCode;
|
||||
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.MemberDTO;
|
||||
import com.youlai.mall.ums.pojo.vo.MemberVO;
|
||||
@ -20,10 +20,10 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Api(tags = "【移动端】会员服务")
|
||||
@RestController
|
||||
@RequestMapping("/api.app/v1/users")
|
||||
@RequestMapping("/api.app/v1/members")
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class UserController {
|
||||
public class MemberController {
|
||||
|
||||
private IUmsUserService iUmsUserService;
|
||||
|
||||
@ -34,10 +34,10 @@ public class UserController {
|
||||
@PathVariable Long id
|
||||
) {
|
||||
MemberDTO memberDTO = new MemberDTO();
|
||||
UmsUser user = iUmsUserService.getOne(
|
||||
new LambdaQueryWrapper<UmsUser>()
|
||||
.select(UmsUser::getId, UmsUser::getNickname, UmsUser::getMobile, UmsUser::getBalance)
|
||||
.eq(UmsUser::getId, id)
|
||||
UmsMember user = iUmsUserService.getOne(
|
||||
new LambdaQueryWrapper<UmsMember>()
|
||||
.select(UmsMember::getId, UmsMember::getNickname, UmsMember::getMobile, UmsMember::getBalance)
|
||||
.eq(UmsMember::getId, id)
|
||||
);
|
||||
if (user != null) {
|
||||
BeanUtil.copyProperties(user, memberDTO);
|
||||
@ -51,8 +51,8 @@ public class UserController {
|
||||
public Result getMemberByOpenid(
|
||||
@PathVariable String openid
|
||||
) {
|
||||
UmsUser user = iUmsUserService.getOne(new LambdaQueryWrapper<UmsUser>()
|
||||
.eq(UmsUser::getOpenid, openid));
|
||||
UmsMember user = iUmsUserService.getOne(new LambdaQueryWrapper<UmsMember>()
|
||||
.eq(UmsMember::getOpenid, openid));
|
||||
if (user == null) {
|
||||
return Result.failed(ResultCode.USER_NOT_EXIST);
|
||||
}
|
||||
@ -64,7 +64,7 @@ public class UserController {
|
||||
@ApiOperation(value = "新增会员", httpMethod = "POST")
|
||||
@ApiImplicitParam(name = "member", value = "实体JSON对象", required = true, paramType = "body", dataType = "UmsMember")
|
||||
@PostMapping
|
||||
public Result add(@RequestBody UmsUser user) {
|
||||
public Result add(@RequestBody UmsMember user) {
|
||||
boolean status = iUmsUserService.save(user);
|
||||
return Result.judge(status);
|
||||
}
|
||||
@ -73,7 +73,7 @@ public class UserController {
|
||||
@GetMapping("/me")
|
||||
public Result getMemberInfo() {
|
||||
Long userId = RequestUtils.getUserId();
|
||||
UmsUser user = iUmsUserService.getById(userId);
|
||||
UmsMember user = iUmsUserService.getById(userId);
|
||||
if (user == null) {
|
||||
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 = "num", value = "积分数量", required = true, paramType = "query", dataType = "Integer")
|
||||
})
|
||||
@PutMapping("/{id}/point")
|
||||
@PutMapping("/{id}/points")
|
||||
public Result updatePoint(@PathVariable Long id, @RequestParam Integer num) {
|
||||
UmsUser user = iUmsUserService.getById(id);
|
||||
UmsMember user = iUmsUserService.getById(id);
|
||||
user.setPoint(user.getPoint() + num);
|
||||
boolean result = iUmsUserService.updateById(user);
|
||||
return Result.judge(result);
|
||||
@ -101,9 +101,9 @@ public class UserController {
|
||||
@ApiImplicitParam(name = "id", value = "会员ID", required = true, paramType = "path", 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) {
|
||||
UmsUser user = iUmsUserService.getById(id);
|
||||
UmsMember user = iUmsUserService.getById(id);
|
||||
user.setBalance(user.getBalance() - balance);
|
||||
boolean result = iUmsUserService.updateById(user);
|
||||
return Result.judge(result);
|
||||
@ -111,10 +111,10 @@ public class UserController {
|
||||
|
||||
@ApiOperation(value = "获取会员余额", httpMethod = "GET")
|
||||
@ApiImplicitParam(name = "id", value = "会员ID", required = true, paramType = "path", dataType = "Long")
|
||||
@GetMapping("/{id}/balance")
|
||||
@GetMapping("/{id}/balances")
|
||||
public Result<Long> updateBalance(@PathVariable Long id) {
|
||||
Long balance = 0l;
|
||||
UmsUser user = iUmsUserService.getById(id);
|
||||
UmsMember user = iUmsUserService.getById(id);
|
||||
if (user != null) {
|
||||
balance = user.getBalance();
|
||||
}
|
@ -2,7 +2,7 @@ package com.youlai.mall.ums.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
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.Result;
|
||||
import org.apache.ibatis.annotations.Results;
|
||||
@ -13,7 +13,7 @@ import java.util.List;
|
||||
|
||||
|
||||
@Mapper
|
||||
public interface UmsUserMapper extends BaseMapper<UmsUser> {
|
||||
public interface UmsUserMapper extends BaseMapper<UmsMember> {
|
||||
|
||||
|
||||
@Select("<script>" +
|
||||
@ -27,7 +27,7 @@ public interface UmsUserMapper extends BaseMapper<UmsUser> {
|
||||
@Result(id = true, column = "id", property = "id"),
|
||||
@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);
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,9 +4,9 @@ package com.youlai.mall.ums.service;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
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);
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package com.youlai.mall.ums.service.impl;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
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.service.IUmsUserService;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -11,12 +11,12 @@ import org.springframework.stereotype.Service;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class UmsUserServiceImpl extends ServiceImpl<UmsUserMapper, UmsUser> implements IUmsUserService {
|
||||
public class UmsUserServiceImpl extends ServiceImpl<UmsUserMapper, UmsMember> implements IUmsUserService {
|
||||
|
||||
|
||||
@Override
|
||||
public IPage<UmsUser> list(Page<UmsUser> page, UmsUser spu) {
|
||||
List<UmsUser> list = this.baseMapper.list(page, spu);
|
||||
public IPage<UmsMember> list(Page<UmsMember> page, UmsMember spu) {
|
||||
List<UmsMember> list = this.baseMapper.list(page, spu);
|
||||
page.setRecords(list);
|
||||
return page;
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package com.youlai.auth;
|
||||
|
||||
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.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
@EnableFeignClients(basePackageClasses = {UserFeignService.class, MemberFeignService.class})
|
||||
@EnableFeignClients(basePackageClasses = {UserFeignService.class, UmsMemberFeignService.class})
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
public class AuthApplication {
|
||||
|
@ -10,8 +10,8 @@ import com.youlai.common.result.Result;
|
||||
import com.youlai.common.result.ResultCode;
|
||||
import com.youlai.common.web.exception.BizException;
|
||||
import com.youlai.common.web.util.RequestUtils;
|
||||
import com.youlai.mall.ums.api.app.MemberFeignService;
|
||||
import com.youlai.mall.ums.pojo.domain.UmsUser;
|
||||
import com.youlai.mall.ums.api.app.UmsMemberFeignService;
|
||||
import com.youlai.mall.ums.pojo.domain.UmsMember;
|
||||
import com.youlai.mall.ums.pojo.dto.AuthMemberDTO;
|
||||
import io.swagger.annotations.Api;
|
||||
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.springframework.security.crypto.password.PasswordEncoder;
|
||||
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.web.HttpRequestMethodNotSupportedException;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@ -86,7 +85,7 @@ public class AuthController {
|
||||
|
||||
|
||||
private WxMaService wxService;
|
||||
private MemberFeignService memberFeignService;
|
||||
private UmsMemberFeignService memberFeignService;
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
public OAuth2AccessToken handleForWxAuth(Principal principal, Map<String, String> parameters) throws HttpRequestMethodNotSupportedException {
|
||||
@ -116,7 +115,7 @@ public class AuthController {
|
||||
if (userInfo == null) {
|
||||
throw new BizException("获取用户信息失败");
|
||||
}
|
||||
UmsUser user = new UmsUser()
|
||||
UmsMember user = new UmsMember()
|
||||
.setNickname(userInfo.getNickName())
|
||||
.setAvatar(userInfo.getAvatarUrl())
|
||||
.setGender(Integer.valueOf(userInfo.getGender()))
|
||||
|
@ -8,7 +8,7 @@ import com.youlai.common.result.Result;
|
||||
import com.youlai.common.result.ResultCode;
|
||||
import com.youlai.common.web.util.RequestUtils;
|
||||
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 org.springframework.security.authentication.AccountExpiredException;
|
||||
import org.springframework.security.authentication.DisabledException;
|
||||
@ -27,7 +27,7 @@ import org.springframework.stereotype.Service;
|
||||
public class UserDetailsServiceImpl implements UserDetailsService {
|
||||
|
||||
private UserFeignService userFeignService;
|
||||
private MemberFeignService memberFeignService;
|
||||
private UmsMemberFeignService memberFeignService;
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
|
Loading…
Reference in New Issue
Block a user