【7.0.3】整理规范

pull/13/head
fengshuonan 2021-04-21 09:45:30 +08:00
parent a793f6a5ad
commit 743a922052
9 changed files with 66 additions and 36 deletions

View File

@ -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>

View File

@ -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>

View File

@ -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);
} }
} }

View File

@ -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);

View File

@ -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>

View File

@ -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);

View File

@ -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;
} }
} }

View File

@ -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);

View File

@ -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);