mirror of https://gitee.com/stylefeng/roses
规范注释
parent
f8107854ba
commit
a793f6a5ad
|
@ -3,6 +3,7 @@ package cn.stylefeng.roses.kernel.seata.order.controller;
|
|||
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;
|
||||
|
||||
|
@ -24,7 +25,7 @@ public class OrderController {
|
|||
* @date 2021/4/20 20:11
|
||||
*/
|
||||
@GetMapping("/create")
|
||||
public Order create(String userId, String commodityCode, int orderCount) {
|
||||
public Order create(@RequestParam("userId") String userId, @RequestParam("commodityCode") String commodityCode, @RequestParam("orderCount") Integer orderCount){
|
||||
return orderService.create(userId,commodityCode,orderCount);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,19 +3,72 @@ package cn.stylefeng.roses.kernel.seata.order.entity;
|
|||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 订单 实体类
|
||||
*
|
||||
* @author wangyl
|
||||
* @date 2021/04/21 08:33
|
||||
*/
|
||||
public class Order implements Serializable {
|
||||
|
||||
/**
|
||||
* 订单ID
|
||||
*/
|
||||
private Long orderId;
|
||||
|
||||
/**
|
||||
* 商品ID
|
||||
*/
|
||||
private Long productId;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 商品单价
|
||||
*/
|
||||
private Integer prodPrice;
|
||||
|
||||
/**
|
||||
* 商品数量
|
||||
*/
|
||||
private Integer prodNumber;
|
||||
|
||||
/**
|
||||
* 总价
|
||||
*/
|
||||
private Integer totalAmount;
|
||||
|
||||
/**
|
||||
* 支付状态:1待支付,2已支付,3支付失败,已取消
|
||||
*/
|
||||
private Integer payStatus;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
private Long createUser;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新者
|
||||
*/
|
||||
private Long updateUser;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
public Long getOrderId() {
|
||||
|
|
|
@ -3,14 +3,24 @@ package cn.stylefeng.roses.kernel.seata.order.mapper;
|
|||
import cn.stylefeng.roses.kernel.seata.order.entity.Order;
|
||||
|
||||
/**
|
||||
* 数据层
|
||||
* 订单 数据层
|
||||
*
|
||||
* @author wangyl
|
||||
* @date 2021/04/21 08:33
|
||||
*/
|
||||
public interface OrderMapper {
|
||||
|
||||
/**
|
||||
* 新增订单
|
||||
* @param order 订单
|
||||
*/
|
||||
void insertOrder(Order order);
|
||||
|
||||
/**
|
||||
* 根据ID查询订单
|
||||
* @param orderId 订单ID
|
||||
* @return
|
||||
*/
|
||||
Order selectById(Long orderId);
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
<!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>
|
||||
|
@ -30,6 +31,7 @@
|
|||
)
|
||||
</insert>
|
||||
|
||||
<!-- 根据ID查询订单 -->
|
||||
<select id="selectById" resultType="cn.stylefeng.roses.kernel.seata.order.entity.Order">
|
||||
select * from order
|
||||
where order_id = #{orderId}
|
||||
|
|
|
@ -2,8 +2,21 @@ package cn.stylefeng.roses.kernel.seata.order.service;
|
|||
|
||||
import cn.stylefeng.roses.kernel.seata.order.entity.Order;
|
||||
|
||||
/**
|
||||
* 订单 业务层
|
||||
*
|
||||
* @author wangyl
|
||||
* @date 2021/04/21 08:33
|
||||
*/
|
||||
public interface OrderService {
|
||||
|
||||
/**
|
||||
* 创建订单
|
||||
* @param userId 用户ID
|
||||
* @param commodityCode 商品编码
|
||||
* @param orderCount 购买数量
|
||||
* @return
|
||||
*/
|
||||
Order create(String userId, String commodityCode, int orderCount);
|
||||
|
||||
}
|
||||
|
|
|
@ -6,24 +6,32 @@ import cn.stylefeng.roses.kernel.seata.order.entity.Order;
|
|||
import cn.stylefeng.roses.kernel.seata.order.mapper.OrderMapper;
|
||||
import cn.stylefeng.roses.kernel.seata.order.service.OrderService;
|
||||
import io.seata.spring.annotation.GlobalTransactional;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 订单 业务层
|
||||
*
|
||||
* @author wangyl
|
||||
* @date 2021/04/21 08:33
|
||||
*/
|
||||
@Service
|
||||
public class OrderServiceImpl implements OrderService {
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private StorageConsumer storageConsumer;
|
||||
@Autowired
|
||||
@Resource
|
||||
private WalletConsumer walletConsumer;
|
||||
@Autowired
|
||||
@Resource
|
||||
private OrderMapper orderMapper;
|
||||
|
||||
/**
|
||||
* 分布式事务跨库操作,起始位置,使用@GlobalTransactional注解修饰
|
||||
* @param userId
|
||||
* @param commodityCode
|
||||
* @param orderCount
|
||||
* 分布式事务跨库操作
|
||||
* @param userId 用户ID
|
||||
* @param commodityCode 商品编码
|
||||
* @param orderCount 购买数量
|
||||
* @GlobalTransactional 修饰分布式事务起始方法
|
||||
* @return
|
||||
*/
|
||||
@GlobalTransactional(rollbackFor = Exception.class)
|
||||
|
|
|
@ -10,7 +10,9 @@ public interface StorageApi {
|
|||
|
||||
/**
|
||||
* 扣除存储数量
|
||||
* @param commodityCode 商品编码
|
||||
* @param count 购买数量
|
||||
*/
|
||||
void deduct(String commodityCode, int count);
|
||||
void deduct(String commodityCode, Integer count);
|
||||
|
||||
}
|
||||
|
|
|
@ -9,8 +9,10 @@ package cn.stylefeng.roses.kernel.seata.wallet.api;
|
|||
public interface WalletApi {
|
||||
|
||||
/**
|
||||
* 从用户账户中借出
|
||||
* 从用户账户中扣除余额
|
||||
* @param userId 用户ID
|
||||
* @param money 消费金额
|
||||
*/
|
||||
void debit(String userId, int money);
|
||||
void debit(String userId, Integer money);
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue