diff --git a/common/common-service/src/main/java/cn/bunny/App.java b/common/common-service/src/main/java/cn/bunny/App.java
deleted file mode 100644
index d56e7f2..0000000
--- a/common/common-service/src/main/java/cn/bunny/App.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package cn.bunny;
-
-/**
- * Hello world!
- *
- */
-public class App
-{
- public static void main( String[] args )
- {
- System.out.println( "Hello World!" );
- }
-}
diff --git a/service/cloud-demo1/src/main/java/cn/bunny/config/Knife4jConfig.java b/common/common-service/src/main/java/cn/bunny/config/Knife4jConfig.java
similarity index 97%
rename from service/cloud-demo1/src/main/java/cn/bunny/config/Knife4jConfig.java
rename to common/common-service/src/main/java/cn/bunny/config/Knife4jConfig.java
index acf29df..1985a69 100644
--- a/service/cloud-demo1/src/main/java/cn/bunny/config/Knife4jConfig.java
+++ b/common/common-service/src/main/java/cn/bunny/config/Knife4jConfig.java
@@ -28,6 +28,6 @@ public class Knife4jConfig {
// 管理员相关分类接口
@Bean
public GroupedOpenApi groupedOpenAdminApi() {
- return GroupedOpenApi.builder().group("默认请求接口").pathsToMatch("/api/**").build();
+ return GroupedOpenApi.builder().group("默认请求接口").pathsToMatch("/**").build();
}
}
diff --git a/mysql.sql b/mysql.sql
new file mode 100644
index 0000000..0bd9426
--- /dev/null
+++ b/mysql.sql
@@ -0,0 +1,99 @@
+CREATE DATABASE IF NOT EXISTS `storage_db`;
+USE `storage_db`;
+DROP TABLE IF EXISTS `storage_tbl`;
+CREATE TABLE `storage_tbl`
+(
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `commodity_code` varchar(255) DEFAULT NULL,
+ `count` int(11) DEFAULT 0,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY (`commodity_code`)
+) ENGINE = InnoDB
+ DEFAULT CHARSET = utf8;
+INSERT INTO storage_tbl (commodity_code, count)
+VALUES ('P0001', 100);
+INSERT INTO storage_tbl (commodity_code, count)
+VALUES ('B1234', 10);
+
+-- 注意此处0.3.0+ 增加唯一索引 ux_undo_log
+DROP TABLE IF EXISTS `undo_log`;
+CREATE TABLE `undo_log`
+(
+ `id` bigint(20) NOT NULL AUTO_INCREMENT,
+ `branch_id` bigint(20) NOT NULL,
+ `xid` varchar(100) NOT NULL,
+ `context` varchar(128) NOT NULL,
+ `rollback_info` longblob NOT NULL,
+ `log_status` int(11) NOT NULL,
+ `log_created` datetime NOT NULL,
+ `log_modified` datetime NOT NULL,
+ `ext` varchar(100) DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`)
+) ENGINE = InnoDB
+ AUTO_INCREMENT = 1
+ DEFAULT CHARSET = utf8;
+
+CREATE DATABASE IF NOT EXISTS `order_db`;
+USE `order_db`;
+DROP TABLE IF EXISTS `order_tbl`;
+CREATE TABLE `order_tbl`
+(
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `user_id` varchar(255) DEFAULT NULL,
+ `commodity_code` varchar(255) DEFAULT NULL,
+ `count` int(11) DEFAULT 0,
+ `money` int(11) DEFAULT 0,
+ PRIMARY KEY (`id`)
+) ENGINE = InnoDB
+ DEFAULT CHARSET = utf8;
+-- 注意此处0.3.0+ 增加唯一索引 ux_undo_log
+DROP TABLE IF EXISTS `undo_log`;
+CREATE TABLE `undo_log`
+(
+ `id` bigint(20) NOT NULL AUTO_INCREMENT,
+ `branch_id` bigint(20) NOT NULL,
+ `xid` varchar(100) NOT NULL,
+ `context` varchar(128) NOT NULL,
+ `rollback_info` longblob NOT NULL,
+ `log_status` int(11) NOT NULL,
+ `log_created` datetime NOT NULL,
+ `log_modified` datetime NOT NULL,
+ `ext` varchar(100) DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`)
+) ENGINE = InnoDB
+ AUTO_INCREMENT = 1
+ DEFAULT CHARSET = utf8;
+
+CREATE DATABASE IF NOT EXISTS `account_db`;
+USE `account_db`;
+DROP TABLE IF EXISTS `account_tbl`;
+CREATE TABLE `account_tbl`
+(
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `user_id` varchar(255) DEFAULT NULL,
+ `money` int(11) DEFAULT 0,
+ PRIMARY KEY (`id`)
+) ENGINE = InnoDB
+ DEFAULT CHARSET = utf8;
+INSERT INTO account_tbl (user_id, money)
+VALUES ('1', 10000);
+-- 注意此处0.3.0+ 增加唯一索引 ux_undo_log
+DROP TABLE IF EXISTS `undo_log`;
+CREATE TABLE `undo_log`
+(
+ `id` bigint(20) NOT NULL AUTO_INCREMENT,
+ `branch_id` bigint(20) NOT NULL,
+ `xid` varchar(100) NOT NULL,
+ `context` varchar(128) NOT NULL,
+ `rollback_info` longblob NOT NULL,
+ `log_status` int(11) NOT NULL,
+ `log_created` datetime NOT NULL,
+ `log_modified` datetime NOT NULL,
+ `ext` varchar(100) DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`)
+) ENGINE = InnoDB
+ AUTO_INCREMENT = 1
+ DEFAULT CHARSET = utf8;
\ No newline at end of file
diff --git a/service/cloud-demo2/src/main/java/cn/bunny/config/Knife4jConfig.java b/service/cloud-demo2/src/main/java/cn/bunny/config/Knife4jConfig.java
deleted file mode 100644
index acf29df..0000000
--- a/service/cloud-demo2/src/main/java/cn/bunny/config/Knife4jConfig.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package cn.bunny.config;
-
-import io.swagger.v3.oas.models.ExternalDocumentation;
-import io.swagger.v3.oas.models.OpenAPI;
-import io.swagger.v3.oas.models.info.Contact;
-import io.swagger.v3.oas.models.info.Info;
-import io.swagger.v3.oas.models.info.License;
-import lombok.extern.slf4j.Slf4j;
-import org.springdoc.core.models.GroupedOpenApi;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-@Slf4j
-public class Knife4jConfig {
- @Bean
- public OpenAPI openAPI() {
- // 作者等信息
- Contact contact = new Contact().name("Bunny").email("1319900154@qq.com").url("http://z-bunny.cn");
- // 使用协议
- License license = new License().name("MIT").url("https://MUT.com");
- // 相关信息
- Info info = new Info().title("Bunny-Order").description("权限管理模板").version("v1.0.0").contact(contact).license(license).termsOfService("MIT");
-
- return new OpenAPI().info(info).externalDocs(new ExternalDocumentation());
- }
-
- // 管理员相关分类接口
- @Bean
- public GroupedOpenApi groupedOpenAdminApi() {
- return GroupedOpenApi.builder().group("默认请求接口").pathsToMatch("/api/**").build();
- }
-}
diff --git a/service/pom.xml b/service/pom.xml
index 1380247..a771dcb 100644
--- a/service/pom.xml
+++ b/service/pom.xml
@@ -12,6 +12,10 @@
cloud-demo1
cloud-demo2
+ seata-account
+ seata-business
+ seata-order
+ seata-storage
service
https://maven.apache.org
diff --git a/service/seata-account/pom.xml b/service/seata-account/pom.xml
new file mode 100644
index 0000000..38f68d9
--- /dev/null
+++ b/service/seata-account/pom.xml
@@ -0,0 +1,50 @@
+
+
+ 4.0.0
+
+ cn.bunny
+ service
+ 0.0.1-SNAPSHOT
+
+
+ seata-account
+
+
+ 17
+ 17
+ UTF-8
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ org.springframework.cloud
+ spring-cloud-starter-loadbalancer
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.mybatis.spring.boot
+ mybatis-spring-boot-starter
+ 3.0.4
+
+
+ com.mysql
+ mysql-connector-j
+ runtime
+
+
+
+
+
\ No newline at end of file
diff --git a/service/seata-account/src/main/java/com/atguigu/account/SeataAccountMainApplication.java b/service/seata-account/src/main/java/com/atguigu/account/SeataAccountMainApplication.java
new file mode 100644
index 0000000..a7f5b35
--- /dev/null
+++ b/service/seata-account/src/main/java/com/atguigu/account/SeataAccountMainApplication.java
@@ -0,0 +1,19 @@
+package com.atguigu.account;
+
+
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+
+
+
+@MapperScan("com.atguigu.account.mapper")
+@EnableDiscoveryClient
+@SpringBootApplication
+public class SeataAccountMainApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(SeataAccountMainApplication.class, args);
+ }
+}
diff --git a/service/seata-account/src/main/java/com/atguigu/account/bean/AccountTbl.java b/service/seata-account/src/main/java/com/atguigu/account/bean/AccountTbl.java
new file mode 100644
index 0000000..6ed56cc
--- /dev/null
+++ b/service/seata-account/src/main/java/com/atguigu/account/bean/AccountTbl.java
@@ -0,0 +1,20 @@
+package com.atguigu.account.bean;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ *
+ * @TableName account_tbl
+ */
+@Data
+public class AccountTbl implements Serializable {
+
+ private Integer id;
+
+ private String userId;
+
+ private Integer money;
+
+}
\ No newline at end of file
diff --git a/service/seata-account/src/main/java/com/atguigu/account/controller/AccountRestController.java b/service/seata-account/src/main/java/com/atguigu/account/controller/AccountRestController.java
new file mode 100644
index 0000000..02fed0f
--- /dev/null
+++ b/service/seata-account/src/main/java/com/atguigu/account/controller/AccountRestController.java
@@ -0,0 +1,25 @@
+package com.atguigu.account.controller;
+
+import com.atguigu.account.service.AccountService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class AccountRestController {
+
+
+ @Autowired
+ AccountService accountService;
+ /**
+ * 扣减账户余额
+ * @return
+ */
+ @GetMapping("/debit")
+ public String debit(@RequestParam("userId") String userId,
+ @RequestParam("money") int money){
+ accountService.debit(userId, money);
+ return "account debit success";
+ }
+}
diff --git a/service/seata-account/src/main/java/com/atguigu/account/mapper/AccountTblMapper.java b/service/seata-account/src/main/java/com/atguigu/account/mapper/AccountTblMapper.java
new file mode 100644
index 0000000..5e4239a
--- /dev/null
+++ b/service/seata-account/src/main/java/com/atguigu/account/mapper/AccountTblMapper.java
@@ -0,0 +1,26 @@
+package com.atguigu.account.mapper;
+
+import com.atguigu.account.bean.AccountTbl;
+
+/**
+* @author lfy
+* @description 针对表【account_tbl】的数据库操作Mapper
+* @createDate 2025-01-08 18:32:50
+* @Entity com.atguigu.account.bean.AccountTbl
+*/
+public interface AccountTblMapper {
+
+ int deleteByPrimaryKey(Long id);
+
+ int insert(AccountTbl record);
+
+ int insertSelective(AccountTbl record);
+
+ AccountTbl selectByPrimaryKey(Long id);
+
+ int updateByPrimaryKeySelective(AccountTbl record);
+
+ int updateByPrimaryKey(AccountTbl record);
+
+ void debit(String userId, int money);
+}
diff --git a/service/seata-account/src/main/java/com/atguigu/account/service/AccountService.java b/service/seata-account/src/main/java/com/atguigu/account/service/AccountService.java
new file mode 100644
index 0000000..6154585
--- /dev/null
+++ b/service/seata-account/src/main/java/com/atguigu/account/service/AccountService.java
@@ -0,0 +1,11 @@
+package com.atguigu.account.service;
+
+public interface AccountService {
+
+ /**
+ * 从用户账户中扣减
+ * @param userId 用户id
+ * @param money 扣减金额
+ */
+ void debit(String userId, int money);
+}
diff --git a/service/seata-account/src/main/java/com/atguigu/account/service/impl/AccountServiceImpl.java b/service/seata-account/src/main/java/com/atguigu/account/service/impl/AccountServiceImpl.java
new file mode 100644
index 0000000..82c70b0
--- /dev/null
+++ b/service/seata-account/src/main/java/com/atguigu/account/service/impl/AccountServiceImpl.java
@@ -0,0 +1,18 @@
+package com.atguigu.account.service.impl;
+
+import com.atguigu.account.mapper.AccountTblMapper;
+import com.atguigu.account.service.AccountService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class AccountServiceImpl implements AccountService {
+
+ @Autowired
+ AccountTblMapper accountTblMapper;
+ @Override
+ public void debit(String userId, int money) {
+ // 扣减账户余额
+ accountTblMapper.debit(userId,money);
+ }
+}
diff --git a/service/seata-account/src/main/resources/application.yml b/service/seata-account/src/main/resources/application.yml
new file mode 100644
index 0000000..2356df0
--- /dev/null
+++ b/service/seata-account/src/main/resources/application.yml
@@ -0,0 +1,20 @@
+spring:
+ application:
+ name: seata-account
+ datasource:
+ url: jdbc:mysql://192.168.3.133:3306/account_db?useUnicode=true&characterEncoding=utf-8&useSSL=false
+ username: root
+ password: "123456"
+ driver-class-name: com.mysql.cj.jdbc.Driver
+ cloud:
+ nacos:
+ server-addr: 192.168.3.132:8848
+ config:
+ import-check:
+ enabled: false
+server:
+ port: 10000
+
+mybatis:
+ mapper-locations: classpath:mapper/*.xml
+
diff --git a/service/seata-account/src/main/resources/mapper/AccountTblMapper.xml b/service/seata-account/src/main/resources/mapper/AccountTblMapper.xml
new file mode 100644
index 0000000..1c28f71
--- /dev/null
+++ b/service/seata-account/src/main/resources/mapper/AccountTblMapper.xml
@@ -0,0 +1,72 @@
+
+
+
+
+
+
+
+
+
+
+
+ id,user_id,money
+
+
+
+
+
+ delete from account_tbl
+ where id = #{id,jdbcType=INTEGER}
+
+
+ insert into account_tbl
+ ( id,user_id,money
+ )
+ values (#{id,jdbcType=INTEGER},#{userId,jdbcType=VARCHAR},#{money,jdbcType=INTEGER}
+ )
+
+
+ insert into account_tbl
+
+ id,
+ user_id,
+ money,
+
+
+ #{id,jdbcType=INTEGER},
+ #{userId,jdbcType=VARCHAR},
+ #{money,jdbcType=INTEGER},
+
+
+
+ update account_tbl
+
+
+ user_id = #{userId,jdbcType=VARCHAR},
+
+
+ money = #{money,jdbcType=INTEGER},
+
+
+ where id = #{id,jdbcType=INTEGER}
+
+
+ update account_tbl
+ set
+ user_id = #{userId,jdbcType=VARCHAR},
+ money = #{money,jdbcType=INTEGER}
+ where id = #{id,jdbcType=INTEGER}
+
+
+ update account_tbl
+ set money = money - #{money,jdbcType=INTEGER}
+ where user_id = #{userId,jdbcType=VARCHAR}
+
+
diff --git a/service/seata-business/pom.xml b/service/seata-business/pom.xml
new file mode 100644
index 0000000..cfb7ace
--- /dev/null
+++ b/service/seata-business/pom.xml
@@ -0,0 +1,40 @@
+
+
+ 4.0.0
+
+ cn.bunny
+ service
+ 0.0.1-SNAPSHOT
+
+
+ seata-business
+
+
+ 17
+ 17
+ UTF-8
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ org.springframework.cloud
+ spring-cloud-starter-loadbalancer
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+
+
+
\ No newline at end of file
diff --git a/service/seata-business/src/main/java/com/atguigu/business/SeataBusinessMainApplication.java b/service/seata-business/src/main/java/com/atguigu/business/SeataBusinessMainApplication.java
new file mode 100644
index 0000000..6f78f84
--- /dev/null
+++ b/service/seata-business/src/main/java/com/atguigu/business/SeataBusinessMainApplication.java
@@ -0,0 +1,15 @@
+package com.atguigu.business;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+
+
+@EnableDiscoveryClient
+@SpringBootApplication
+public class SeataBusinessMainApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(SeataBusinessMainApplication.class, args);
+ }
+}
diff --git a/service/seata-business/src/main/java/com/atguigu/business/controller/PurchaseRestController.java b/service/seata-business/src/main/java/com/atguigu/business/controller/PurchaseRestController.java
new file mode 100644
index 0000000..c0a4049
--- /dev/null
+++ b/service/seata-business/src/main/java/com/atguigu/business/controller/PurchaseRestController.java
@@ -0,0 +1,30 @@
+package com.atguigu.business.controller;
+
+import com.atguigu.business.service.BusinessService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class PurchaseRestController {
+
+ @Autowired
+ BusinessService businessService;
+
+
+ /**
+ * 购买
+ * @param userId 用户ID
+ * @param commodityCode 商品编码
+ * @param orderCount 数量
+ * @return
+ */
+ @GetMapping("/purchase")
+ public String purchase(@RequestParam("userId") String userId,
+ @RequestParam("commodityCode") String commodityCode,
+ @RequestParam("count") int orderCount){
+ businessService.purchase(userId, commodityCode, orderCount);
+ return "business purchase success";
+ }
+}
diff --git a/service/seata-business/src/main/java/com/atguigu/business/service/BusinessService.java b/service/seata-business/src/main/java/com/atguigu/business/service/BusinessService.java
new file mode 100644
index 0000000..08d323e
--- /dev/null
+++ b/service/seata-business/src/main/java/com/atguigu/business/service/BusinessService.java
@@ -0,0 +1,12 @@
+package com.atguigu.business.service;
+
+public interface BusinessService {
+
+ /**
+ * 采购
+ * @param userId 用户id
+ * @param commodityCode 商品编号
+ * @param orderCount 购买数量
+ */
+ void purchase(String userId, String commodityCode, int orderCount);
+}
diff --git a/service/seata-business/src/main/java/com/atguigu/business/service/impl/BusinessServiceImpl.java b/service/seata-business/src/main/java/com/atguigu/business/service/impl/BusinessServiceImpl.java
new file mode 100644
index 0000000..99ec9b4
--- /dev/null
+++ b/service/seata-business/src/main/java/com/atguigu/business/service/impl/BusinessServiceImpl.java
@@ -0,0 +1,15 @@
+package com.atguigu.business.service.impl;
+
+import com.atguigu.business.service.BusinessService;
+import org.springframework.stereotype.Service;
+
+
+@Service
+public class BusinessServiceImpl implements BusinessService {
+ @Override
+ public void purchase(String userId, String commodityCode, int orderCount) {
+ //TODO 1. 扣减库存
+
+ //TODO 2. 创建订单
+ }
+}
diff --git a/service/seata-business/src/main/resources/application.yml b/service/seata-business/src/main/resources/application.yml
new file mode 100644
index 0000000..0679dbf
--- /dev/null
+++ b/service/seata-business/src/main/resources/application.yml
@@ -0,0 +1,12 @@
+spring:
+ application:
+ name: seata-business
+ cloud:
+ nacos:
+ server-addr: 192.168.3.132:8848
+ config:
+ import-check:
+ enabled: false
+server:
+ port: 11000
+
diff --git a/service/seata-order/pom.xml b/service/seata-order/pom.xml
new file mode 100644
index 0000000..21739b1
--- /dev/null
+++ b/service/seata-order/pom.xml
@@ -0,0 +1,50 @@
+
+
+ 4.0.0
+
+ cn.bunny
+ service
+ 0.0.1-SNAPSHOT
+
+
+ seata-order
+
+
+ 17
+ 17
+ UTF-8
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ org.springframework.cloud
+ spring-cloud-starter-loadbalancer
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.mybatis.spring.boot
+ mybatis-spring-boot-starter
+ 3.0.4
+
+
+ com.mysql
+ mysql-connector-j
+ runtime
+
+
+
+
+
\ No newline at end of file
diff --git a/service/seata-order/src/main/java/com/atguigu/order/SeataOrderMainApplication.java b/service/seata-order/src/main/java/com/atguigu/order/SeataOrderMainApplication.java
new file mode 100644
index 0000000..621eaf2
--- /dev/null
+++ b/service/seata-order/src/main/java/com/atguigu/order/SeataOrderMainApplication.java
@@ -0,0 +1,19 @@
+package com.atguigu.order;
+
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+
+
+@MapperScan("com.atguigu.order.mapper")
+@EnableDiscoveryClient
+@SpringBootApplication
+public class SeataOrderMainApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(SeataOrderMainApplication.class, args);
+ }
+
+
+}
diff --git a/service/seata-order/src/main/java/com/atguigu/order/bean/OrderTbl.java b/service/seata-order/src/main/java/com/atguigu/order/bean/OrderTbl.java
new file mode 100644
index 0000000..98d3208
--- /dev/null
+++ b/service/seata-order/src/main/java/com/atguigu/order/bean/OrderTbl.java
@@ -0,0 +1,22 @@
+package com.atguigu.order.bean;
+
+import java.io.Serializable;
+import lombok.Data;
+
+/**
+ * @TableName order_tbl
+ */
+@Data
+public class OrderTbl implements Serializable {
+ private Integer id;
+
+ private String userId;
+
+ private String commodityCode;
+
+ private Integer count;
+
+ private Integer money;
+
+ private static final long serialVersionUID = 1L;
+}
\ No newline at end of file
diff --git a/service/seata-order/src/main/java/com/atguigu/order/controller/OrderRestController.java b/service/seata-order/src/main/java/com/atguigu/order/controller/OrderRestController.java
new file mode 100644
index 0000000..aa60ae0
--- /dev/null
+++ b/service/seata-order/src/main/java/com/atguigu/order/controller/OrderRestController.java
@@ -0,0 +1,34 @@
+package com.atguigu.order.controller;
+
+
+import com.atguigu.order.bean.OrderTbl;
+import com.atguigu.order.service.OrderService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class OrderRestController {
+
+ @Autowired
+ OrderService orderService;
+
+
+ /**
+ * 创建订单
+ * @param userId
+ * @param commodityCode
+ * @param orderCount
+ * @return
+ */
+ @GetMapping("/create")
+ public String create(@RequestParam("userId") String userId,
+ @RequestParam("commodityCode") String commodityCode,
+ @RequestParam("count") int orderCount)
+ {
+ OrderTbl tbl = orderService.create(userId, commodityCode, orderCount);
+ return "order create success = 订单id:【"+tbl.getId()+"】";
+ }
+
+}
diff --git a/service/seata-order/src/main/java/com/atguigu/order/mapper/OrderTblMapper.java b/service/seata-order/src/main/java/com/atguigu/order/mapper/OrderTblMapper.java
new file mode 100644
index 0000000..4ac5803
--- /dev/null
+++ b/service/seata-order/src/main/java/com/atguigu/order/mapper/OrderTblMapper.java
@@ -0,0 +1,25 @@
+package com.atguigu.order.mapper;
+
+import com.atguigu.order.bean.OrderTbl;
+
+/**
+* @author lfy
+* @description 针对表【order_tbl】的数据库操作Mapper
+* @createDate 2025-01-08 18:34:18
+* @Entity com.atguigu.order.bean.OrderTbl
+*/
+public interface OrderTblMapper {
+
+ int deleteByPrimaryKey(Long id);
+
+ int insert(OrderTbl record);
+
+ int insertSelective(OrderTbl record);
+
+ OrderTbl selectByPrimaryKey(Long id);
+
+ int updateByPrimaryKeySelective(OrderTbl record);
+
+ int updateByPrimaryKey(OrderTbl record);
+
+}
diff --git a/service/seata-order/src/main/java/com/atguigu/order/service/OrderService.java b/service/seata-order/src/main/java/com/atguigu/order/service/OrderService.java
new file mode 100644
index 0000000..694bf38
--- /dev/null
+++ b/service/seata-order/src/main/java/com/atguigu/order/service/OrderService.java
@@ -0,0 +1,13 @@
+package com.atguigu.order.service;
+
+import com.atguigu.order.bean.OrderTbl;
+
+public interface OrderService {
+ /**
+ * 创建订单
+ * @param userId 用户id
+ * @param commodityCode 商品编码
+ * @param orderCount 商品数量
+ */
+ OrderTbl create(String userId, String commodityCode, int orderCount);
+}
diff --git a/service/seata-order/src/main/java/com/atguigu/order/service/impl/OrderServiceImpl.java b/service/seata-order/src/main/java/com/atguigu/order/service/impl/OrderServiceImpl.java
new file mode 100644
index 0000000..de7bc2f
--- /dev/null
+++ b/service/seata-order/src/main/java/com/atguigu/order/service/impl/OrderServiceImpl.java
@@ -0,0 +1,38 @@
+package com.atguigu.order.service.impl;
+
+import com.atguigu.order.bean.OrderTbl;
+import com.atguigu.order.mapper.OrderTblMapper;
+import com.atguigu.order.service.OrderService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class OrderServiceImpl implements OrderService {
+
+ @Autowired
+ OrderTblMapper orderTblMapper;
+
+ @Override
+ public OrderTbl create(String userId, String commodityCode, int orderCount) {
+ //1、计算订单价格
+ int orderMoney = calculate(commodityCode, orderCount);
+
+ //TODO 2、扣减账户余额
+
+ //3、保存订单
+ OrderTbl orderTbl = new OrderTbl();
+ orderTbl.setUserId(userId);
+ orderTbl.setCommodityCode(commodityCode);
+ orderTbl.setCount(orderCount);
+ orderTbl.setMoney(orderMoney);
+
+ orderTblMapper.insert(orderTbl);
+
+ return orderTbl;
+ }
+
+ // 计算价格
+ private int calculate(String commodityCode, int orderCount) {
+ return 9*orderCount;
+ }
+}
diff --git a/service/seata-order/src/main/resources/application.yml b/service/seata-order/src/main/resources/application.yml
new file mode 100644
index 0000000..cbfe097
--- /dev/null
+++ b/service/seata-order/src/main/resources/application.yml
@@ -0,0 +1,19 @@
+spring:
+ application:
+ name: seata-order
+ datasource:
+ url: jdbc:mysql://192.168.3.133:3306/order_db?useUnicode=true&characterEncoding=utf-8&useSSL=false
+ username: root
+ password: 123456
+ driver-class-name: com.mysql.cj.jdbc.Driver
+ cloud:
+ nacos:
+ server-addr: 192.168.3.132:8848
+ config:
+ import-check:
+ enabled: false
+
+server:
+ port: 12000
+mybatis:
+ mapper-locations: classpath:mapper/*.xml
diff --git a/service/seata-order/src/main/resources/mapper/OrderTblMapper.xml b/service/seata-order/src/main/resources/mapper/OrderTblMapper.xml
new file mode 100644
index 0000000..eb2db06
--- /dev/null
+++ b/service/seata-order/src/main/resources/mapper/OrderTblMapper.xml
@@ -0,0 +1,83 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ id,user_id,commodity_code,
+ count,money
+
+
+
+
+
+ delete from order_tbl
+ where id = #{id,jdbcType=INTEGER}
+
+
+ insert into order_tbl
+ ( id,user_id,commodity_code
+ ,count,money)
+ values (#{id,jdbcType=INTEGER},#{userId,jdbcType=VARCHAR},#{commodityCode,jdbcType=VARCHAR}
+ ,#{count,jdbcType=INTEGER},#{money,jdbcType=INTEGER})
+
+
+ insert into order_tbl
+
+ id,
+ user_id,
+ commodity_code,
+ count,
+ money,
+
+
+ #{id,jdbcType=INTEGER},
+ #{userId,jdbcType=VARCHAR},
+ #{commodityCode,jdbcType=VARCHAR},
+ #{count,jdbcType=INTEGER},
+ #{money,jdbcType=INTEGER},
+
+
+
+ update order_tbl
+
+
+ user_id = #{userId,jdbcType=VARCHAR},
+
+
+ commodity_code = #{commodityCode,jdbcType=VARCHAR},
+
+
+ count = #{count,jdbcType=INTEGER},
+
+
+ money = #{money,jdbcType=INTEGER},
+
+
+ where id = #{id,jdbcType=INTEGER}
+
+
+ update order_tbl
+ set
+ user_id = #{userId,jdbcType=VARCHAR},
+ commodity_code = #{commodityCode,jdbcType=VARCHAR},
+ count = #{count,jdbcType=INTEGER},
+ money = #{money,jdbcType=INTEGER}
+ where id = #{id,jdbcType=INTEGER}
+
+
diff --git a/service/seata-storage/pom.xml b/service/seata-storage/pom.xml
new file mode 100644
index 0000000..4aa6d4e
--- /dev/null
+++ b/service/seata-storage/pom.xml
@@ -0,0 +1,49 @@
+
+
+ 4.0.0
+
+ cn.bunny
+ service
+ 0.0.1-SNAPSHOT
+
+
+ seata-storage
+
+
+ 17
+ 17
+ UTF-8
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ org.springframework.cloud
+ spring-cloud-starter-loadbalancer
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.mybatis.spring.boot
+ mybatis-spring-boot-starter
+ 3.0.4
+
+
+ com.mysql
+ mysql-connector-j
+ runtime
+
+
+
+
+
\ No newline at end of file
diff --git a/service/seata-storage/src/main/java/com/atguigu/storage/SeataStorageMainApplication.java b/service/seata-storage/src/main/java/com/atguigu/storage/SeataStorageMainApplication.java
new file mode 100644
index 0000000..e8a6541
--- /dev/null
+++ b/service/seata-storage/src/main/java/com/atguigu/storage/SeataStorageMainApplication.java
@@ -0,0 +1,16 @@
+package com.atguigu.storage;
+
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+
+@MapperScan("com.atguigu.storage.mapper")
+@EnableDiscoveryClient
+@SpringBootApplication
+public class SeataStorageMainApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(SeataStorageMainApplication.class, args);
+ }
+}
diff --git a/service/seata-storage/src/main/java/com/atguigu/storage/bean/StorageTbl.java b/service/seata-storage/src/main/java/com/atguigu/storage/bean/StorageTbl.java
new file mode 100644
index 0000000..1e2fbdf
--- /dev/null
+++ b/service/seata-storage/src/main/java/com/atguigu/storage/bean/StorageTbl.java
@@ -0,0 +1,18 @@
+package com.atguigu.storage.bean;
+
+import java.io.Serializable;
+import lombok.Data;
+
+/**
+ * @TableName storage_tbl
+ */
+@Data
+public class StorageTbl implements Serializable {
+ private Integer id;
+
+ private String commodityCode;
+
+ private Integer count;
+
+ private static final long serialVersionUID = 1L;
+}
\ No newline at end of file
diff --git a/service/seata-storage/src/main/java/com/atguigu/storage/controller/StorageRestController.java b/service/seata-storage/src/main/java/com/atguigu/storage/controller/StorageRestController.java
new file mode 100644
index 0000000..6a512e6
--- /dev/null
+++ b/service/seata-storage/src/main/java/com/atguigu/storage/controller/StorageRestController.java
@@ -0,0 +1,23 @@
+package com.atguigu.storage.controller;
+
+
+import com.atguigu.storage.service.StorageService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class StorageRestController {
+
+ @Autowired
+ StorageService storageService;
+
+ @GetMapping("/deduct")
+ public String deduct(@RequestParam("commodityCode") String commodityCode,
+ @RequestParam("count") Integer count) {
+
+ storageService.deduct(commodityCode, count);
+ return "storage deduct success";
+ }
+}
diff --git a/service/seata-storage/src/main/java/com/atguigu/storage/mapper/StorageTblMapper.java b/service/seata-storage/src/main/java/com/atguigu/storage/mapper/StorageTblMapper.java
new file mode 100644
index 0000000..c86e765
--- /dev/null
+++ b/service/seata-storage/src/main/java/com/atguigu/storage/mapper/StorageTblMapper.java
@@ -0,0 +1,26 @@
+package com.atguigu.storage.mapper;
+
+import com.atguigu.storage.bean.StorageTbl;
+
+/**
+* @author lfy
+* @description 针对表【storage_tbl】的数据库操作Mapper
+* @createDate 2025-01-08 18:35:07
+* @Entity com.atguigu.storage.bean.StorageTbl
+*/
+public interface StorageTblMapper {
+
+ int deleteByPrimaryKey(Long id);
+
+ int insert(StorageTbl record);
+
+ int insertSelective(StorageTbl record);
+
+ StorageTbl selectByPrimaryKey(Long id);
+
+ int updateByPrimaryKeySelective(StorageTbl record);
+
+ int updateByPrimaryKey(StorageTbl record);
+
+ void deduct(String commodityCode, int count);
+}
diff --git a/service/seata-storage/src/main/java/com/atguigu/storage/service/StorageService.java b/service/seata-storage/src/main/java/com/atguigu/storage/service/StorageService.java
new file mode 100644
index 0000000..ffbddce
--- /dev/null
+++ b/service/seata-storage/src/main/java/com/atguigu/storage/service/StorageService.java
@@ -0,0 +1,12 @@
+package com.atguigu.storage.service;
+
+public interface StorageService {
+
+
+ /**
+ * 扣除存储数量
+ * @param commodityCode 商品编码
+ * @param count 数量
+ */
+ void deduct(String commodityCode, int count);
+}
diff --git a/service/seata-storage/src/main/java/com/atguigu/storage/service/impl/StorageServiceImpl.java b/service/seata-storage/src/main/java/com/atguigu/storage/service/impl/StorageServiceImpl.java
new file mode 100644
index 0000000..91e5f5c
--- /dev/null
+++ b/service/seata-storage/src/main/java/com/atguigu/storage/service/impl/StorageServiceImpl.java
@@ -0,0 +1,18 @@
+package com.atguigu.storage.service.impl;
+
+import com.atguigu.storage.mapper.StorageTblMapper;
+import com.atguigu.storage.service.StorageService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class StorageServiceImpl implements StorageService {
+
+ @Autowired
+ StorageTblMapper storageTblMapper;
+
+ @Override
+ public void deduct(String commodityCode, int count) {
+ storageTblMapper.deduct(commodityCode, count);
+ }
+}
diff --git a/service/seata-storage/src/main/resources/application.yml b/service/seata-storage/src/main/resources/application.yml
new file mode 100644
index 0000000..6bac74d
--- /dev/null
+++ b/service/seata-storage/src/main/resources/application.yml
@@ -0,0 +1,19 @@
+spring:
+ application:
+ name: seata-storage
+ datasource:
+ url: jdbc:mysql://192.168.3.133:3306/storage_db?useUnicode=true&characterEncoding=utf-8&useSSL=false
+ username: root
+ password: 123456
+ driver-class-name: com.mysql.cj.jdbc.Driver
+ cloud:
+ nacos:
+ server-addr: 192.168.3.132:8848
+ config:
+ import-check:
+ enabled: false
+server:
+ port: 13000
+
+mybatis:
+ mapper-locations: classpath:mapper/*.xml
diff --git a/service/seata-storage/src/main/resources/mapper/StorageTblMapper.xml b/service/seata-storage/src/main/resources/mapper/StorageTblMapper.xml
new file mode 100644
index 0000000..5059402
--- /dev/null
+++ b/service/seata-storage/src/main/resources/mapper/StorageTblMapper.xml
@@ -0,0 +1,72 @@
+
+
+
+
+
+
+
+
+
+
+
+ id,commodity_code,count
+
+
+
+
+
+ delete from storage_tbl
+ where id = #{id,jdbcType=INTEGER}
+
+
+ insert into storage_tbl
+ ( id,commodity_code,count
+ )
+ values (#{id,jdbcType=INTEGER},#{commodityCode,jdbcType=VARCHAR},#{count,jdbcType=INTEGER}
+ )
+
+
+ insert into storage_tbl
+
+ id,
+ commodity_code,
+ count,
+
+
+ #{id,jdbcType=INTEGER},
+ #{commodityCode,jdbcType=VARCHAR},
+ #{count,jdbcType=INTEGER},
+
+
+
+ update storage_tbl
+
+
+ commodity_code = #{commodityCode,jdbcType=VARCHAR},
+
+
+ count = #{count,jdbcType=INTEGER},
+
+
+ where id = #{id,jdbcType=INTEGER}
+
+
+ update storage_tbl
+ set
+ commodity_code = #{commodityCode,jdbcType=VARCHAR},
+ count = #{count,jdbcType=INTEGER}
+ where id = #{id,jdbcType=INTEGER}
+
+
+ update storage_tbl
+ set count = count - #{count}
+ where commodity_code = #{commodityCode}
+
+