mirror of https://gitee.com/stylefeng/roses
【7.0.3】整理规范
parent
a793f6a5ad
commit
743a922052
|
@ -2,17 +2,19 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>cn.stylefeng.roses</groupId>
|
<groupId>cn.stylefeng.roses</groupId>
|
||||||
<artifactId>roses-kernel</artifactId>
|
<artifactId>roses-kernel</artifactId>
|
||||||
<version>7.0.3</version>
|
<version>7.0.3</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>kernel-d-seata</artifactId>
|
<artifactId>kernel-d-seata</artifactId>
|
||||||
|
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>seata-demo-wallet-api</module>
|
<module>seata-demo-wallet-api</module>
|
||||||
<module>seata-demo-storage-api</module>
|
<module>seata-demo-storage-api</module>
|
||||||
|
|
|
@ -14,28 +14,41 @@
|
||||||
|
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
<!--feign远程调用-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-openfeign-core</artifactId>
|
<artifactId>spring-cloud-openfeign-core</artifactId>
|
||||||
<version>2.2.6.RELEASE</version>
|
<version>2.2.6.RELEASE</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!--demo业务-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.stylefeng.roses</groupId>
|
<groupId>cn.stylefeng.roses</groupId>
|
||||||
<artifactId>seata-demo-storage-api</artifactId>
|
<artifactId>seata-demo-storage-api</artifactId>
|
||||||
<version>7.0.3</version>
|
<version>7.0.3</version>
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.stylefeng.roses</groupId>
|
<groupId>cn.stylefeng.roses</groupId>
|
||||||
<artifactId>seata-demo-wallet-api</artifactId>
|
<artifactId>seata-demo-wallet-api</artifactId>
|
||||||
<version>7.0.3</version>
|
<version>7.0.3</version>
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!--seata分布式事务-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.seata</groupId>
|
<groupId>io.seata</groupId>
|
||||||
<artifactId>seata-all</artifactId>
|
<artifactId>seata-all</artifactId>
|
||||||
<version>1.3.0</version>
|
<version>1.3.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!--资源api模块-->
|
||||||
|
<!--用在资源控制器,资源扫描上-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.stylefeng.roses</groupId>
|
||||||
|
<artifactId>scanner-api</artifactId>
|
||||||
|
<version>7.0.3</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
package cn.stylefeng.roses.kernel.seata.order.controller;
|
package cn.stylefeng.roses.kernel.seata.order.controller;
|
||||||
|
|
||||||
|
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
|
||||||
|
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
|
||||||
import cn.stylefeng.roses.kernel.seata.order.entity.Order;
|
import cn.stylefeng.roses.kernel.seata.order.entity.Order;
|
||||||
import cn.stylefeng.roses.kernel.seata.order.service.OrderService;
|
import cn.stylefeng.roses.kernel.seata.order.service.OrderService;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
@ -13,6 +14,7 @@ import javax.annotation.Resource;
|
||||||
* @author wangyl
|
* @author wangyl
|
||||||
* @date 2021/04/10 16:42
|
* @date 2021/04/10 16:42
|
||||||
*/
|
*/
|
||||||
|
@ApiResource(name = "订单接口(测试seata)")
|
||||||
public class OrderController {
|
public class OrderController {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
|
@ -24,9 +26,9 @@ public class OrderController {
|
||||||
* @author wangyl
|
* @author wangyl
|
||||||
* @date 2021/4/20 20:11
|
* @date 2021/4/20 20:11
|
||||||
*/
|
*/
|
||||||
@GetMapping("/create")
|
@GetResource(name = "创建订单", path = "/order/create", requiredPermission = false, requiredLogin = false)
|
||||||
public Order create(@RequestParam("userId") String userId, @RequestParam("commodityCode") String commodityCode, @RequestParam("orderCount") Integer orderCount){
|
public Order create(@RequestParam("userId") String userId, @RequestParam("commodityCode") String commodityCode, @RequestParam("orderCount") Integer orderCount) {
|
||||||
return orderService.create(userId,commodityCode,orderCount);
|
return orderService.create(userId, commodityCode, orderCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,14 +12,19 @@ public interface OrderMapper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增订单
|
* 新增订单
|
||||||
|
*
|
||||||
* @param order 订单
|
* @param order 订单
|
||||||
|
* @author wangyl
|
||||||
|
* @date 2021/4/21 9:43
|
||||||
*/
|
*/
|
||||||
void insertOrder(Order order);
|
void insertOrder(Order order);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据ID查询订单
|
* 根据ID查询订单
|
||||||
* @param orderId 订单ID
|
*
|
||||||
* @return
|
* @param orderId 订单id
|
||||||
|
* @author wangyl
|
||||||
|
* @date 2021/4/21 9:43
|
||||||
*/
|
*/
|
||||||
Order selectById(Long orderId);
|
Order selectById(Long orderId);
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,8 @@
|
||||||
|
|
||||||
<!-- 根据ID查询订单 -->
|
<!-- 根据ID查询订单 -->
|
||||||
<select id="selectById" resultType="cn.stylefeng.roses.kernel.seata.order.entity.Order">
|
<select id="selectById" resultType="cn.stylefeng.roses.kernel.seata.order.entity.Order">
|
||||||
select * from order
|
select *
|
||||||
|
from order
|
||||||
where order_id = #{orderId}
|
where order_id = #{orderId}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
|
@ -12,10 +12,12 @@ public interface OrderService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建订单
|
* 创建订单
|
||||||
|
*
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @param commodityCode 商品编码
|
* @param commodityCode 商品编码
|
||||||
* @param orderCount 购买数量
|
* @param orderCount 购买数量
|
||||||
* @return
|
* @author wangyl
|
||||||
|
* @date 2021/4/21 9:43
|
||||||
*/
|
*/
|
||||||
Order create(String userId, String commodityCode, int orderCount);
|
Order create(String userId, String commodityCode, int orderCount);
|
||||||
|
|
||||||
|
|
|
@ -21,29 +21,28 @@ public class OrderServiceImpl implements OrderService {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private StorageConsumer storageConsumer;
|
private StorageConsumer storageConsumer;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private WalletConsumer walletConsumer;
|
private WalletConsumer walletConsumer;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private OrderMapper orderMapper;
|
private OrderMapper orderMapper;
|
||||||
|
|
||||||
/**
|
|
||||||
* 分布式事务跨库操作
|
|
||||||
* @param userId 用户ID
|
|
||||||
* @param commodityCode 商品编码
|
|
||||||
* @param orderCount 购买数量
|
|
||||||
* @GlobalTransactional 修饰分布式事务起始方法
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@GlobalTransactional(rollbackFor = Exception.class)
|
@GlobalTransactional(rollbackFor = Exception.class)
|
||||||
@Override
|
@Override
|
||||||
public Order create(String userId, String commodityCode, int orderCount) {
|
public Order create(String userId, String commodityCode, int orderCount) {
|
||||||
Order order = new Order();
|
Order order = new Order();
|
||||||
|
|
||||||
//保存订单
|
//保存订单
|
||||||
orderMapper.insertOrder(order);
|
orderMapper.insertOrder(order);
|
||||||
|
|
||||||
//扣减商品库存
|
//扣减商品库存
|
||||||
storageConsumer.deduct(commodityCode,orderCount);
|
storageConsumer.deduct(commodityCode, orderCount);
|
||||||
|
|
||||||
//扣用户钱
|
//扣用户钱
|
||||||
walletConsumer.debit(userId,order.getTotalAmount());
|
walletConsumer.debit(userId, order.getTotalAmount());
|
||||||
|
|
||||||
return order;
|
return order;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,11 @@ public interface StorageApi {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 扣除存储数量
|
* 扣除存储数量
|
||||||
|
*
|
||||||
* @param commodityCode 商品编码
|
* @param commodityCode 商品编码
|
||||||
* @param count 购买数量
|
* @param count 购买数量
|
||||||
|
* @author wangyl
|
||||||
|
* @date 2021/4/21 9:44
|
||||||
*/
|
*/
|
||||||
void deduct(String commodityCode, Integer count);
|
void deduct(String commodityCode, Integer count);
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,11 @@ public interface WalletApi {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从用户账户中扣除余额
|
* 从用户账户中扣除余额
|
||||||
|
*
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @param money 消费金额
|
* @param money 消费金额
|
||||||
|
* @author wangyl
|
||||||
|
* @date 2021/4/21 9:44
|
||||||
*/
|
*/
|
||||||
void debit(String userId, Integer money);
|
void debit(String userId, Integer money);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue