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"
|
||||
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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>roses-kernel</artifactId>
|
||||
<version>7.0.3</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>kernel-d-seata</artifactId>
|
||||
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>seata-demo-wallet-api</module>
|
||||
<module>seata-demo-storage-api</module>
|
||||
|
|
|
@ -14,28 +14,41 @@
|
|||
|
||||
<packaging>jar</packaging>
|
||||
<dependencies>
|
||||
|
||||
<!--feign远程调用-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-openfeign-core</artifactId>
|
||||
<version>2.2.6.RELEASE</version>
|
||||
</dependency>
|
||||
|
||||
<!--demo业务-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>seata-demo-storage-api</artifactId>
|
||||
<version>7.0.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>seata-demo-wallet-api</artifactId>
|
||||
<version>7.0.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!--seata分布式事务-->
|
||||
<dependency>
|
||||
<groupId>io.seata</groupId>
|
||||
<artifactId>seata-all</artifactId>
|
||||
<version>1.3.0</version>
|
||||
</dependency>
|
||||
|
||||
<!--资源api模块-->
|
||||
<!--用在资源控制器,资源扫描上-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>scanner-api</artifactId>
|
||||
<version>7.0.3</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
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.service.OrderService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
@ -13,6 +14,7 @@ import javax.annotation.Resource;
|
|||
* @author wangyl
|
||||
* @date 2021/04/10 16:42
|
||||
*/
|
||||
@ApiResource(name = "订单接口(测试seata)")
|
||||
public class OrderController {
|
||||
|
||||
@Resource
|
||||
|
@ -24,9 +26,9 @@ public class OrderController {
|
|||
* @author wangyl
|
||||
* @date 2021/4/20 20:11
|
||||
*/
|
||||
@GetMapping("/create")
|
||||
public Order create(@RequestParam("userId") String userId, @RequestParam("commodityCode") String commodityCode, @RequestParam("orderCount") Integer orderCount){
|
||||
return orderService.create(userId,commodityCode,orderCount);
|
||||
@GetResource(name = "创建订单", path = "/order/create", requiredPermission = false, requiredLogin = false)
|
||||
public Order create(@RequestParam("userId") String userId, @RequestParam("commodityCode") String commodityCode, @RequestParam("orderCount") Integer orderCount) {
|
||||
return orderService.create(userId, commodityCode, orderCount);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,14 +12,19 @@ public interface OrderMapper {
|
|||
|
||||
/**
|
||||
* 新增订单
|
||||
*
|
||||
* @param order 订单
|
||||
* @author wangyl
|
||||
* @date 2021/4/21 9:43
|
||||
*/
|
||||
void insertOrder(Order order);
|
||||
|
||||
/**
|
||||
* 根据ID查询订单
|
||||
* @param orderId 订单ID
|
||||
* @return
|
||||
*
|
||||
* @param orderId 订单id
|
||||
* @author wangyl
|
||||
* @date 2021/4/21 9:43
|
||||
*/
|
||||
Order selectById(Long orderId);
|
||||
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.stylefeng.roses.kernel.seata.order.mapper.OrderMapper">
|
||||
|
||||
<!-- 新增订单 -->
|
||||
<insert id="insertOrder" parameterType="cn.stylefeng.roses.kernel.seata.order.entity.Order">
|
||||
insert into order(
|
||||
<if test="productId != null and productId != ''">product_id,</if>
|
||||
<!-- 新增订单 -->
|
||||
<insert id="insertOrder" parameterType="cn.stylefeng.roses.kernel.seata.order.entity.Order">
|
||||
insert into order(
|
||||
<if test="productId != null and productId != ''">product_id,</if>
|
||||
<if test="userId != null and userId != ''">user_id,</if>
|
||||
<if test="prodPrice != null and prodPrice != ''">prod_price,</if>
|
||||
<if test="prodNumber != null and prodNumber != ''">prod_number,</if>
|
||||
|
@ -16,7 +16,7 @@
|
|||
<if test="updateUser != null and updateUser != ''">update_user,</if>
|
||||
<if test="updateTime != null and updateTime != ''">update_time,</if>
|
||||
<if test="remark != null and remark != ''">remark,</if>
|
||||
)values(
|
||||
)values(
|
||||
<if test="productId != null and productId != ''">#{productId},</if>
|
||||
<if test="userId != null and userId != ''">#{userId},</if>
|
||||
<if test="prodPrice != null and prodPrice != ''">#{prodPrice},</if>
|
||||
|
@ -28,13 +28,14 @@
|
|||
<if test="updateUser != null and updateUser != ''">#{updateUser},</if>
|
||||
<if test="updateTime != null and updateTime != ''">#{updateTime},</if>
|
||||
<if test="remark != null and remark != ''">#{remark},</if>
|
||||
)
|
||||
</insert>
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- 根据ID查询订单 -->
|
||||
<select id="selectById" resultType="cn.stylefeng.roses.kernel.seata.order.entity.Order">
|
||||
select * from order
|
||||
where order_id = #{orderId}
|
||||
</select>
|
||||
<!-- 根据ID查询订单 -->
|
||||
<select id="selectById" resultType="cn.stylefeng.roses.kernel.seata.order.entity.Order">
|
||||
select *
|
||||
from order
|
||||
where order_id = #{orderId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
|
@ -12,10 +12,12 @@ public interface OrderService {
|
|||
|
||||
/**
|
||||
* 创建订单
|
||||
* @param userId 用户ID
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param commodityCode 商品编码
|
||||
* @param orderCount 购买数量
|
||||
* @return
|
||||
* @param orderCount 购买数量
|
||||
* @author wangyl
|
||||
* @date 2021/4/21 9:43
|
||||
*/
|
||||
Order create(String userId, String commodityCode, int orderCount);
|
||||
|
||||
|
|
|
@ -21,29 +21,28 @@ public class OrderServiceImpl implements OrderService {
|
|||
|
||||
@Resource
|
||||
private StorageConsumer storageConsumer;
|
||||
|
||||
@Resource
|
||||
private WalletConsumer walletConsumer;
|
||||
|
||||
@Resource
|
||||
private OrderMapper orderMapper;
|
||||
|
||||
/**
|
||||
* 分布式事务跨库操作
|
||||
* @param userId 用户ID
|
||||
* @param commodityCode 商品编码
|
||||
* @param orderCount 购买数量
|
||||
* @GlobalTransactional 修饰分布式事务起始方法
|
||||
* @return
|
||||
*/
|
||||
@GlobalTransactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public Order create(String userId, String commodityCode, int orderCount) {
|
||||
Order order = new Order();
|
||||
|
||||
//保存订单
|
||||
orderMapper.insertOrder(order);
|
||||
|
||||
//扣减商品库存
|
||||
storageConsumer.deduct(commodityCode,orderCount);
|
||||
storageConsumer.deduct(commodityCode, orderCount);
|
||||
|
||||
//扣用户钱
|
||||
walletConsumer.debit(userId,order.getTotalAmount());
|
||||
walletConsumer.debit(userId, order.getTotalAmount());
|
||||
|
||||
return order;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,8 +10,11 @@ public interface StorageApi {
|
|||
|
||||
/**
|
||||
* 扣除存储数量
|
||||
*
|
||||
* @param commodityCode 商品编码
|
||||
* @param count 购买数量
|
||||
* @param count 购买数量
|
||||
* @author wangyl
|
||||
* @date 2021/4/21 9:44
|
||||
*/
|
||||
void deduct(String commodityCode, Integer count);
|
||||
|
||||
|
|
|
@ -10,8 +10,11 @@ public interface WalletApi {
|
|||
|
||||
/**
|
||||
* 从用户账户中扣除余额
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param money 消费金额
|
||||
* @param money 消费金额
|
||||
* @author wangyl
|
||||
* @date 2021/4/21 9:44
|
||||
*/
|
||||
void debit(String userId, Integer money);
|
||||
|
||||
|
|
Loading…
Reference in New Issue