- * Description: - *
- * - * @author zhangjianwei - * @version 1.0 - * @date 2019/8/28 4:05 PM - */ -@RestController -@RequestMapping("order") -public class OrderController { - - @Resource - private OrderService orderService; - @Resource - private StockFeignClient stockFeignClient; - - /** - * 下单:插入订单表、扣减库存,模拟回滚 - * - * @return - */ - @RequestMapping("/placeOrder/commit") - public Boolean placeOrderCommit() { - - orderService.placeOrder("1", "product-1", 1); - return true; - } - - /** - * 下单:插入订单表、扣减库存,模拟回滚 - * - * @return - */ - @RequestMapping("/placeOrder/rollback") - public Boolean placeOrderRollback() { - // product-2 扣库存时模拟了一个业务异常, - orderService.placeOrder("1", "product-2", 1); - return true; - } - - @RequestMapping("/placeOrder") - public Boolean placeOrder(String userId, String commodityCode, Integer count) { - orderService.placeOrder(userId, commodityCode, count); - return true; - } -} diff --git a/springcloud-nacos-seata/order-service/src/main/java/com/work/order/model/Order.java b/springcloud-nacos-seata/order-service/src/main/java/com/work/order/model/Order.java deleted file mode 100644 index abfdd0d6c..000000000 --- a/springcloud-nacos-seata/order-service/src/main/java/com/work/order/model/Order.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.work.order.model; - -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.math.BigDecimal; - -/** - * Program Name: springcloud-nacos-seata - *
- * Description: - *
- * - * @author zhangjianwei - * @version 1.0 - * @date 2019/8/28 4:05 PM - */ -@Data -@Accessors(chain = true) -@TableName("order_tbl") -public class Order { - - @TableId(type = IdType.AUTO) - private Integer id; - private String userId; - private String commodityCode; - private Integer count; - private BigDecimal money; - -} diff --git a/springcloud-nacos-seata/order-service/src/main/java/com/work/order/repository/OrderDAO.java b/springcloud-nacos-seata/order-service/src/main/java/com/work/order/repository/OrderDAO.java deleted file mode 100644 index 2a37bb111..000000000 --- a/springcloud-nacos-seata/order-service/src/main/java/com/work/order/repository/OrderDAO.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.work.order.repository; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.work.order.model.Order; -import org.apache.ibatis.annotations.Mapper; -import org.springframework.stereotype.Repository; - -/** - * Program Name: springcloud-nacos-seata - *
- * Description: - *
- *
- * @author zhangjianwei
- * @version 1.0
- * @date 2019/8/28 4:05 PM
- */
-@Mapper
-@Repository
-public interface OrderDAO extends BaseMapper
- * Description:
- *
- *
- * @author zhangjianwei
- * @version 1.0
- * @date 2019/8/28 4:05 PM
- */
-@Service
-public class OrderService {
-
- @Resource
- private AccountFeignClient accountFeignClient;
- @Resource
- private StockFeignClient stockFeignClient;
- @Resource
- private OrderDAO orderDAO;
-
- /**
- * 下单:创建订单、减库存,涉及到两个服务
- *
- * @param userId
- * @param commodityCode
- * @param count
- */
- @GlobalTransactional
- @Transactional(rollbackFor = Exception.class)
- public void placeOrder(String userId, String commodityCode, Integer count) {
- BigDecimal orderMoney = new BigDecimal(count).multiply(new BigDecimal(5));
- Order order = new Order().setUserId(userId).setCommodityCode(commodityCode).setCount(count).setMoney(
- orderMoney);
- orderDAO.insert(order);
- stockFeignClient.deduct(commodityCode, count);
-
- }
-
- @Transactional(rollbackFor = Exception.class)
- public void create(String userId, String commodityCode, Integer count) {
-
- BigDecimal orderMoney = new BigDecimal(count).multiply(new BigDecimal(5));
-
- Order order = new Order().setUserId(userId).setCommodityCode(commodityCode).setCount(count).setMoney(
- orderMoney);
- orderDAO.insert(order);
-
- accountFeignClient.reduce(userId, orderMoney);
-
- }
-
-}
diff --git a/springcloud-nacos-seata/order-service/src/main/resources/application.properties b/springcloud-nacos-seata/order-service/src/main/resources/application.properties
deleted file mode 100644
index 64afb8422..000000000
--- a/springcloud-nacos-seata/order-service/src/main/resources/application.properties
+++ /dev/null
@@ -1,12 +0,0 @@
-spring.application.name=order-service
-server.port=9091
-# Nacos 注册中心地址
-spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
-# seata 服务分组,要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应
-spring.cloud.alibaba.seata.tx-service-group=my_test_tx_group
-logging.level.io.seata=debug
-# 数据源配置
-spring.datasource.url=jdbc:mysql://localhost:3306/seata_order?allowMultiQueries=true
-spring.datasource.driverClassName=com.mysql.jdbc.Driver
-spring.datasource.username=root
-spring.datasource.password=123456
\ No newline at end of file
diff --git a/springcloud-nacos-seata/order-service/src/main/resources/registry.conf b/springcloud-nacos-seata/order-service/src/main/resources/registry.conf
deleted file mode 100644
index 0c46e26a1..000000000
--- a/springcloud-nacos-seata/order-service/src/main/resources/registry.conf
+++ /dev/null
@@ -1,89 +0,0 @@
-registry {
- # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
- type = "nacos"
-
- nacos {
- application = "seata-server"
- serverAddr = "127.0.0.1:8848"
- group = "SEATA_GROUP"
- namespace = ""
- cluster = "default"
- username = "nacos"
- password = "nacos"
- }
- eureka {
- serviceUrl = "http://localhost:8761/eureka"
- application = "default"
- weight = "1"
- }
- redis {
- serverAddr = "localhost:6379"
- db = 0
- password = ""
- cluster = "default"
- timeout = 0
- }
- zk {
- cluster = "default"
- serverAddr = "127.0.0.1:2181"
- sessionTimeout = 6000
- connectTimeout = 2000
- username = ""
- password = ""
- }
- consul {
- cluster = "default"
- serverAddr = "127.0.0.1:8500"
- }
- etcd3 {
- cluster = "default"
- serverAddr = "http://localhost:2379"
- }
- sofa {
- serverAddr = "127.0.0.1:9603"
- application = "default"
- region = "DEFAULT_ZONE"
- datacenter = "DefaultDataCenter"
- cluster = "default"
- group = "SEATA_GROUP"
- addressWaitTime = "3000"
- }
- file {
- name = "file.conf"
- }
-}
-
-config {
- # file、nacos 、apollo、zk、consul、etcd3
- type = "nacos"
-
- nacos {
- serverAddr = "127.0.0.1:8848"
- namespace = ""
- group = "SEATA_GROUP"
- username = "nacos"
- password = "nacos"
- dataId = "seataServer.properties"
- }
- consul {
- serverAddr = "127.0.0.1:8500"
- }
- apollo {
- appId = "seata-server"
- apolloMeta = "http://192.168.1.204:8801"
- namespace = "application"
- }
- zk {
- serverAddr = "127.0.0.1:2181"
- sessionTimeout = 6000
- connectTimeout = 2000
- username = ""
- password = ""
- }
- etcd3 {
- serverAddr = "http://localhost:2379"
- }
- file {
- name = "file.conf"
- }
-}
diff --git a/springcloud-nacos-seata/pom.xml b/springcloud-nacos-seata/pom.xml
deleted file mode 100644
index 0451df4c0..000000000
--- a/springcloud-nacos-seata/pom.xml
+++ /dev/null
@@ -1,184 +0,0 @@
-
-
- * Description:
- *
- *
- * @author zhangjianwei
- * @version 1.0
- * @date 2019/8/28 4:05 PM
- */
-@RestController
-@RequestMapping("stock")
-public class StockController {
-
- @Resource
- private StockService stockService;
-
- /**
- * 减库存
- *
- * @param commodityCode 商品代码
- * @param count 数量
- * @return
- */
- @RequestMapping(path = "/deduct")
- public Boolean deduct(String commodityCode, Integer count) {
- stockService.deduct(commodityCode, count);
- return true;
- }
-
-}
diff --git a/springcloud-nacos-seata/stock-service/src/main/java/com/work/stock/entity/Stock.java b/springcloud-nacos-seata/stock-service/src/main/java/com/work/stock/entity/Stock.java
deleted file mode 100644
index d7fea2ff8..000000000
--- a/springcloud-nacos-seata/stock-service/src/main/java/com/work/stock/entity/Stock.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 1999-2021 Seata.io Group.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.work.stock.entity;
-
-import com.baomidou.mybatisplus.annotation.TableName;
-import lombok.Data;
-import lombok.experimental.Accessors;
-
-/**
- * Program Name: springcloud-nacos-seata
- *
- * Description:
- *
- *
- * @author zhangjianwei
- * @version 1.0
- * @date 2019/8/28 4:05 PM
- */
-@Data
-@Accessors(chain = true)
-@TableName("stock_tbl")
-public class Stock {
-
- private Long id;
- private String commodityCode;
- private Long count;
-
-}
diff --git a/springcloud-nacos-seata/stock-service/src/main/java/com/work/stock/service/StockService.java b/springcloud-nacos-seata/stock-service/src/main/java/com/work/stock/service/StockService.java
deleted file mode 100644
index 89fb964a8..000000000
--- a/springcloud-nacos-seata/stock-service/src/main/java/com/work/stock/service/StockService.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright 1999-2021 Seata.io Group.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.work.stock.service;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.work.stock.entity.Stock;
-import com.work.stock.repository.StockDAO;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-import javax.annotation.Resource;
-
-/**
- * Program Name: springcloud-nacos-seata
- *
- * Description:
- *
- *
- * @author zhangjianwei
- * @version 1.0
- * @date 2019/8/28 4:05 PM
- */
-@Service
-public class StockService {
-
- @Resource
- private StockDAO stockDAO;
-
- /**
- * 减库存
- *
- * @param commodityCode
- * @param count
- */
- @Transactional(rollbackFor = Exception.class)
- public void deduct(String commodityCode, int count) {
- if (commodityCode.equals("product-2")) {
- throw new RuntimeException("异常:模拟业务异常:stock branch exception");
- }
-
- QueryWrapper