【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"
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>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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