代码优化

This commit is contained in:
yu199195 2017-12-29 10:47:57 +08:00
parent 3a248e690f
commit 7b2697e5a2
77 changed files with 465 additions and 673 deletions

View File

@ -23,7 +23,7 @@
<parent>
<artifactId>happylifeplat-tcc</artifactId>
<groupId>com.happylifeplat.tcc</groupId>
<version>1.1.0-RELEASE</version>
<version>1.1.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -58,8 +58,6 @@ public class SwaggerConfig {
.contact(new Contact("xiaoyu", "", "549477611@qq.com"))
.build();
}
// swagger
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))

View File

@ -37,9 +37,7 @@ import java.io.IOException;
* @version 1.0
* @date 2017/10/23 17:57
* @since JDK 1.8
*//*
*/
*/
@Component
public class CorsFilter implements Filter {

View File

@ -23,7 +23,7 @@
<parent>
<artifactId>happylifeplat-tcc</artifactId>
<groupId>com.happylifeplat.tcc</groupId>
<version>1.1.0-RELEASE</version>
<version>1.1.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>happylifeplat-tcc</artifactId>
<groupId>com.happylifeplat.tcc</groupId>
<version>1.1.0-RELEASE</version>
<version>1.1.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -26,12 +26,15 @@ import lombok.Data;
@Data
public class TccConfig {
/**
* 应用名称
*/
private String appName;
/**
* 资源后缀 此参数请填写 关于是事务存储路径
* 1 如果是表存储 这个就是表名后缀其他方式存储一样
* 2 如果此参数不填写那么会默认获取应用的applicationName
*/
private String repositorySuffix;
/**
* 提供不同的序列化对象 {@linkplain SerializeEnum}
*/

View File

@ -23,12 +23,16 @@ import java.util.Optional;
/**
* The enum Tcc action enum.
*
* @author xiaoyu
*/
public enum TccActionEnum {
/**
* Pre try tcc action enum.
*/
PRE_TRY(0,"开始执行try"),

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>happylifeplat-tcc</artifactId>
<groupId>com.happylifeplat.tcc</groupId>
<version>1.1.0-RELEASE</version>
<version>1.1.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -21,16 +21,15 @@ package com.happylifeplat.tcc.core.coordinator.impl;
import com.google.common.collect.Lists;
import com.happylifeplat.tcc.annotation.TccPatternEnum;
import com.happylifeplat.tcc.common.config.TccConfig;
import com.happylifeplat.tcc.common.enums.CoordinatorActionEnum;
import com.happylifeplat.tcc.common.enums.TccActionEnum;
import com.happylifeplat.tcc.common.enums.TccRoleEnum;
import com.happylifeplat.tcc.common.exception.TccRuntimeException;
import com.happylifeplat.tcc.common.utils.LogUtil;
import com.happylifeplat.tcc.common.bean.context.TccTransactionContext;
import com.happylifeplat.tcc.common.bean.entity.Participant;
import com.happylifeplat.tcc.common.bean.entity.TccInvocation;
import com.happylifeplat.tcc.common.bean.entity.TccTransaction;
import com.happylifeplat.tcc.common.config.TccConfig;
import com.happylifeplat.tcc.common.enums.CoordinatorActionEnum;
import com.happylifeplat.tcc.common.enums.TccActionEnum;
import com.happylifeplat.tcc.common.enums.TccRoleEnum;
import com.happylifeplat.tcc.common.utils.LogUtil;
import com.happylifeplat.tcc.core.concurrent.threadlocal.TransactionContextLocal;
import com.happylifeplat.tcc.core.concurrent.threadpool.TccTransactionThreadFactory;
import com.happylifeplat.tcc.core.concurrent.threadpool.TccTransactionThreadPool;
@ -40,6 +39,7 @@ import com.happylifeplat.tcc.core.helper.SpringBeanUtils;
import com.happylifeplat.tcc.core.service.ApplicationService;
import com.happylifeplat.tcc.core.spi.CoordinatorRepository;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.reflect.MethodUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -57,7 +57,6 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
* @author xiaoyu
@ -100,10 +99,12 @@ public class CoordinatorServiceImpl implements CoordinatorService {
@Override
public void start(TccConfig tccConfig) throws Exception {
this.tccConfig = tccConfig;
final String appName = applicationService.acquireName();
coordinatorRepository = SpringBeanUtils.getInstance().getBean(CoordinatorRepository.class);
final String repositorySuffix =
buildRepositorySuffix(tccConfig.getRepositorySuffix());
coordinatorRepository = SpringBeanUtils.getInstance()
.getBean(CoordinatorRepository.class);
//初始化spi 协调资源存储
coordinatorRepository.init(appName, tccConfig);
coordinatorRepository.init(repositorySuffix, tccConfig);
//初始化 协调资源线程池
initCoordinatorPool();
//定时执行补偿
@ -382,7 +383,17 @@ public class CoordinatorServiceImpl implements CoordinatorService {
private Date acquireData() {
return new Date(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() - (tccConfig.getRecoverDelayTime() * 1000));
return new Date(LocalDateTime.now().atZone(ZoneId.systemDefault())
.toInstant().toEpochMilli() - (tccConfig.getRecoverDelayTime() * 1000));
}
private String buildRepositorySuffix(String repositorySuffix) {
if (StringUtils.isNoneBlank(repositorySuffix)) {
return repositorySuffix;
} else {
return applicationService.acquireName();
}
}

View File

@ -27,71 +27,77 @@ public class SqlHelper {
public static String buildCreateTableSql(String driverClassName, String tableName) {
String createTableSql;
StringBuilder createTableSql = new StringBuilder();
String dbType = DbTypeUtils.buildByDriverClassName(driverClassName);
switch (dbType) {
case "mysql": {
createTableSql = "CREATE TABLE `" + tableName + "` (\n" +
" `trans_id` varchar(64) NOT NULL,\n" +
" `target_class` varchar(256) ,\n" +
" `target_method` varchar(128) ,\n" +
" `confirm_method` varchar(128) ,\n" +
" `cancel_method` varchar(128) ,\n" +
" `retried_count` int(3) NOT NULL,\n" +
" `create_time` datetime NOT NULL,\n" +
" `last_time` datetime NOT NULL,\n" +
" `version` int(6) NOT NULL,\n" +
" `status` int(2) NOT NULL,\n" +
" `invocation` longblob,\n" +
" `role` int(2) NOT NULL,\n" +
" `pattern` int(2),\n" +
" PRIMARY KEY (`trans_id`)\n" +
")";
createTableSql
.append("CREATE TABLE `")
.append(tableName)
.append("` (")
.append(" `trans_id` varchar(64) NOT NULL,")
.append(" `target_class` varchar(256) ,")
.append(" `target_method` varchar(128) ,")
.append(" `confirm_method` varchar(128) ,")
.append(" `cancel_method` varchar(128) ,")
.append(" `retried_count` int(3) NOT NULL,")
.append(" `create_time` datetime NOT NULL,")
.append(" `last_time` datetime NOT NULL,")
.append(" `version` int(6) NOT NULL,")
.append(" `status` int(2) NOT NULL,")
.append(" `invocation` longblob,")
.append(" `role` int(2) NOT NULL,")
.append(" `pattern` int(2),")
.append(" PRIMARY KEY (`trans_id`))");
break;
}
case "oracle": {
createTableSql = "CREATE TABLE `" + tableName + "` (\n" +
" `trans_id` varchar(64) NOT NULL,\n" +
" `target_class` varchar(256) ,\n" +
" `target_method` varchar(128) ,\n" +
" `confirm_method` varchar(128) ,\n" +
" `cancel_method` varchar(128) ,\n" +
" `retried_count` int(3) NOT NULL,\n" +
" `create_time` date NOT NULL,\n" +
" `last_time` date NOT NULL,\n" +
" `version` int(6) NOT NULL,\n" +
" `status` int(2) NOT NULL,\n" +
" `invocation` BLOB ,\n" +
" `role` int(2) NOT NULL,\n" +
" `pattern` int(2),\n" +
" PRIMARY KEY (`trans_id`)\n" +
")";
createTableSql
.append("CREATE TABLE `")
.append(tableName)
.append("` (")
.append(" `trans_id` varchar(64) NOT NULL,")
.append(" `target_class` varchar(256) ,")
.append(" `target_method` varchar(128) ,")
.append(" `confirm_method` varchar(128) ,")
.append(" `cancel_method` varchar(128) ,")
.append(" `retried_count` int(3) NOT NULL,")
.append(" `create_time` date NOT NULL,")
.append(" `last_time` date NOT NULL,")
.append(" `version` int(6) NOT NULL,")
.append(" `status` int(2) NOT NULL,")
.append(" `invocation` BLOB ,")
.append(" `role` int(2) NOT NULL,")
.append(" `pattern` int(2),")
.append(" PRIMARY KEY (`trans_id`))");
break;
}
case "sqlserver": {
createTableSql = "CREATE TABLE `" + tableName + "` (\n" +
" `trans_id` varchar(64) NOT NULL,\n" +
" `target_class` varchar(256) ,\n" +
" `target_method` varchar(128) ,\n" +
" `confirm_method` varchar(128) ,\n" +
" `cancel_method` varchar(128) ,\n" +
" `retried_count` int(3) NOT NULL,\n" +
" `create_time` datetime NOT NULL,\n" +
" `last_time` datetime NOT NULL,\n" +
" `version` int(6) NOT NULL,\n" +
" `status` int(2) NOT NULL,\n" +
" `invocation` varbinary ,\n" +
" `role` int(2) NOT NULL,\n" +
" `pattern` int(2),\n" +
" PRIMARY KEY (`trans_id`)\n" +
")";
createTableSql
.append("CREATE TABLE `")
.append(tableName)
.append("` (")
.append(" `trans_id` varchar(64) NOT NULL,")
.append(" `target_class` varchar(256) ,")
.append(" `target_method` varchar(128) ,")
.append(" `confirm_method` varchar(128) ,")
.append(" `cancel_method` varchar(128) ,")
.append(" `retried_count` int(3) NOT NULL,")
.append(" `create_time` datetime NOT NULL,")
.append(" `last_time` datetime NOT NULL,")
.append(" `version` int(6) NOT NULL,")
.append(" `status` int(2) NOT NULL,")
.append(" `invocation` varbinary ,")
.append(" `role` int(2) NOT NULL,")
.append(" `pattern` int(2),")
.append(" PRIMARY KEY (`trans_id`))");
break;
}
default: {
throw new RuntimeException("dbType类型不支持,目前仅支持mysql oracle sqlserver.");
}
}
return createTableSql;
return createTableSql.toString();
}

View File

@ -301,7 +301,6 @@ public class JdbcCoordinatorRepository implements CoordinatorRepository {
}
return ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
logger.error("executeUpdate-> " + e.getMessage());
} finally {
close(connection, ps, null);

View File

@ -23,7 +23,7 @@
<parent>
<artifactId>happylifeplat-tcc-demo-dubbo</artifactId>
<groupId>com.happylifeplat.tcc</groupId>
<version>1.1.0-RELEASE</version>
<version>1.1.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -35,6 +35,10 @@
<groupId>com.happylifeplat.tcc</groupId>
<artifactId>happylifeplat-tcc-annotation</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -18,19 +18,22 @@
package com.happylifeplat.tcc.demo.dubbo.account.api.dto;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* @author xiaoyu
*/
@Data
public class AccountDTO implements Serializable {
private static final long serialVersionUID = 7223470850578998427L;
/**
* 用户id
*/
private Integer userId;
private String userId;
/**
* 扣款金额
@ -38,28 +41,4 @@ public class AccountDTO implements Serializable {
private BigDecimal amount;
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public BigDecimal getAmount() {
return amount;
}
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
@Override
public String toString() {
return "AccountDTO{" +
"userId=" + userId +
", amount=" + amount +
'}';
}
}

View File

@ -18,6 +18,8 @@
package com.happylifeplat.tcc.demo.dubbo.account.api.entity;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
@ -25,12 +27,14 @@ import java.util.Date;
/**
* @author xiaoyu
*/
@Data
public class AccountDO implements Serializable {
private static final long serialVersionUID = -81849676368907419L;
private Integer id;
private Integer userId;
private String userId;
private BigDecimal balance;
@ -41,63 +45,4 @@ public class AccountDO implements Serializable {
private Date updateTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public BigDecimal getBalance() {
return balance;
}
public void setBalance(BigDecimal balance) {
this.balance = balance;
}
public BigDecimal getFreezeAmount() {
return freezeAmount;
}
public void setFreezeAmount(BigDecimal freezeAmount) {
this.freezeAmount = freezeAmount;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
@Override
public String toString() {
return "AccountDO{" +
"id=" + id +
", userId=" + userId +
", balance=" + balance +
", freezeAmount=" + freezeAmount +
", createTime=" + createTime +
", updateTime=" + updateTime +
'}';
}
}

View File

@ -20,6 +20,7 @@ package com.happylifeplat.tcc.demo.dubbo.account.api.service;
import com.happylifeplat.tcc.annotation.Tcc;
import com.happylifeplat.tcc.demo.dubbo.account.api.dto.AccountDTO;
import com.happylifeplat.tcc.demo.dubbo.account.api.entity.AccountDO;
/**
* @author xiaoyu
@ -35,4 +36,12 @@ public interface AccountService {
*/
@Tcc
boolean payment(AccountDTO accountDTO);
/**
* 获取用户账户信息
* @param userId 用户id
* @return AccountDO
*/
AccountDO findByUserId(String userId);
}

View File

@ -23,7 +23,7 @@
<parent>
<artifactId>happylifeplat-tcc-demo-dubbo</artifactId>
<groupId>com.happylifeplat.tcc</groupId>
<version>1.1.0-RELEASE</version>
<version>1.1.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>happylifeplat-tcc-demo-dubbo-account</artifactId>

View File

@ -29,9 +29,9 @@ import org.springframework.context.annotation.ImportResource;
@SpringBootApplication
@ImportResource({"classpath:applicationContext.xml"})
@MapperScan("com.happylifeplat.tcc.demo.dubbo.account.mapper")
public class AccountApplication {
public class DubboTccAccountApplication {
public static void main(String[] args) {
SpringApplication.run(AccountApplication.class, args);
SpringApplication.run(DubboTccAccountApplication.class, args);
}

View File

@ -70,5 +70,5 @@ public interface AccountMapper {
* @return AccountDO
*/
@Select("select * from account where user_id =#{userId}")
AccountDO findByUserId(Integer userId);
AccountDO findByUserId(String userId);
}

View File

@ -46,7 +46,7 @@ public class AccountServiceImpl implements AccountService {
private final AccountMapper accountMapper;
@Autowired
@Autowired(required = false)
public AccountServiceImpl(AccountMapper accountMapper) {
this.accountMapper = accountMapper;
}
@ -71,9 +71,20 @@ public class AccountServiceImpl implements AccountService {
return Boolean.TRUE;
}
/**
* 获取用户账户信息
*
* @param userId 用户id
* @return AccountDO
*/
@Override
public AccountDO findByUserId(String userId) {
return accountMapper.findByUserId(userId);
}
public boolean confirm(AccountDTO accountDTO) {
LOGGER.debug("============执行确认付款接口===============");
LOGGER.debug("============dubbo tcc 执行确认付款接口===============");
final AccountDO accountDO = accountMapper.findByUserId(accountDTO.getUserId());
accountDO.setFreezeAmount(accountDO.getFreezeAmount().subtract(accountDTO.getAmount()));
@ -88,7 +99,7 @@ public class AccountServiceImpl implements AccountService {
public boolean cancel(AccountDTO accountDTO) {
LOGGER.debug("============执行取消付款接口===============");
LOGGER.debug("============ dubbo tcc 执行取消付款接口===============");
final AccountDO accountDO = accountMapper.findByUserId(accountDTO.getUserId());
accountDO.setBalance(accountDO.getBalance().add(accountDTO.getAmount()));
accountDO.setFreezeAmount(accountDO.getFreezeAmount().subtract(accountDTO.getAmount()));

View File

@ -6,7 +6,7 @@ server:
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.1.68:3306/account?useUnicode=true&characterEncoding=utf8
url: jdbc:mysql://192.168.1.68:3306/tcc_account?useUnicode=true&characterEncoding=utf8
username: xiaoyu
password: Wgj@555888
@ -20,9 +20,9 @@ logging:
root: error
org.springframework.web: info
org.apache.ibatis: info
com.happylifeplat.bonuspoint: info
com.happylifeplat.lottery: debug
com.happylifeplat: debug
com.happylifeplat.tcc.bonuspoint: info
com.happylifeplat.tcc.lottery: debug
com.happylifeplat.tcc: debug
io.netty: info
path: "./logs"

View File

@ -25,9 +25,9 @@
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="account"/>
<dubbo:application name="account_service"/>
<dubbo:registry protocol="zookeeper" address="192.168.1.143:2181"/>
<dubbo:registry protocol="zookeeper" address="192.168.1.148:2181"/>
<dubbo:protocol accesslog="true" name="dubbo" port="20884"/>

View File

@ -23,7 +23,7 @@
<parent>
<artifactId>happylifeplat-tcc-demo-dubbo</artifactId>
<groupId>com.happylifeplat.tcc</groupId>
<version>1.1.0-RELEASE</version>
<version>1.1.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -34,6 +34,10 @@
<groupId>com.happylifeplat.tcc</groupId>
<artifactId>happylifeplat-tcc-annotation</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -18,18 +18,23 @@
package com.happylifeplat.tcc.demo.dubbo.inventory.api.dto;
import lombok.Data;
import java.io.Serializable;
/**
* @author xiaoyu
*/
@Data
public class InventoryDTO implements Serializable {
private static final long serialVersionUID = 8229355519336565493L;
/**
* 商品id
*/
private Integer productId;
private String productId;
/**
@ -37,27 +42,5 @@ public class InventoryDTO implements Serializable {
*/
private Integer count;
public Integer getProductId() {
return productId;
}
public void setProductId(Integer productId) {
this.productId = productId;
}
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
@Override
public String toString() {
return "InventoryDTO{" +
"productId=" + productId +
", count=" + count +
'}';
}
}

View File

@ -18,12 +18,15 @@
package com.happylifeplat.tcc.demo.dubbo.inventory.api.entity;
import lombok.Data;
import java.io.Serializable;
/**
* @author xiaoyu
*/
public class Inventory implements Serializable {
@Data
public class InventoryDO implements Serializable {
private static final long serialVersionUID = 6957734749389133832L;
private Integer id;
@ -31,7 +34,7 @@ public class Inventory implements Serializable {
/**
* 商品id
*/
private Integer productId;
private String productId;
/**
* 总库存
@ -43,35 +46,4 @@ public class Inventory implements Serializable {
*/
private Integer lockInventory;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getProductId() {
return productId;
}
public void setProductId(Integer productId) {
this.productId = productId;
}
public Integer getTotalInventory() {
return totalInventory;
}
public void setTotalInventory(Integer totalInventory) {
this.totalInventory = totalInventory;
}
public Integer getLockInventory() {
return lockInventory;
}
public void setLockInventory(Integer lockInventory) {
this.lockInventory = lockInventory;
}
}

View File

@ -20,7 +20,7 @@ package com.happylifeplat.tcc.demo.dubbo.inventory.api.service;
import com.happylifeplat.tcc.annotation.Tcc;
import com.happylifeplat.tcc.demo.dubbo.inventory.api.dto.InventoryDTO;
import com.happylifeplat.tcc.demo.dubbo.inventory.api.entity.Inventory;
import com.happylifeplat.tcc.demo.dubbo.inventory.api.entity.InventoryDO;
/**
* @author xiaoyu
@ -39,6 +39,14 @@ public interface InventoryService {
Boolean decrease(InventoryDTO inventoryDTO);
/**
* 获取商品库存信息
* @param productId 商品id
* @return InventoryDO
*/
InventoryDO findByProductId(String productId);
/**
* mock扣减库存异常
*

View File

@ -23,7 +23,7 @@
<parent>
<artifactId>happylifeplat-tcc-demo-dubbo</artifactId>
<groupId>com.happylifeplat.tcc</groupId>
<version>1.1.0-RELEASE</version>
<version>1.1.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -29,9 +29,9 @@ import org.springframework.context.annotation.ImportResource;
@SpringBootApplication
@ImportResource({"classpath:applicationContext.xml"})
@MapperScan("com.happylifeplat.tcc.demo.dubbo.inventory.mapper")
public class InventoryApplication {
public class DubboTccInventoryApplication {
public static void main(String[] args) {
SpringApplication.run(InventoryApplication.class, args);
SpringApplication.run(DubboTccInventoryApplication.class, args);
}

View File

@ -18,7 +18,7 @@
package com.happylifeplat.tcc.demo.dubbo.inventory.mapper;
import com.happylifeplat.tcc.demo.dubbo.inventory.api.entity.Inventory;
import com.happylifeplat.tcc.demo.dubbo.inventory.api.entity.InventoryDO;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
@ -38,7 +38,7 @@ public interface InventoryMapper {
@Update("update inventory set total_inventory =#{totalInventory}," +
" lock_inventory= #{lockInventory} " +
" where product_id =#{productId} and total_inventory >0 ")
int decrease(Inventory inventory);
int decrease(InventoryDO inventory);
/**
@ -50,7 +50,7 @@ public interface InventoryMapper {
@Update("update inventory set " +
" lock_inventory= #{lockInventory} " +
" where product_id =#{productId} and lock_inventory >0 ")
int confirm(Inventory inventory);
int confirm(InventoryDO inventory);
/**
@ -62,7 +62,7 @@ public interface InventoryMapper {
@Update("update inventory set total_inventory =#{totalInventory}," +
" lock_inventory= #{lockInventory} " +
" where product_id =#{productId} and lock_inventory >0 ")
int cancel(Inventory inventory);
int cancel(InventoryDO inventory);
/**
* 根据商品id找到库存信息
@ -71,5 +71,5 @@ public interface InventoryMapper {
* @return Inventory
*/
@Select("select * from inventory where product_id =#{productId}")
Inventory findByProductId(Integer productId);
InventoryDO findByProductId(String productId);
}

View File

@ -21,7 +21,7 @@ package com.happylifeplat.tcc.demo.dubbo.inventory.service;
import com.happylifeplat.tcc.annotation.Tcc;
import com.happylifeplat.tcc.common.exception.TccRuntimeException;
import com.happylifeplat.tcc.demo.dubbo.inventory.api.dto.InventoryDTO;
import com.happylifeplat.tcc.demo.dubbo.inventory.api.entity.Inventory;
import com.happylifeplat.tcc.demo.dubbo.inventory.api.entity.InventoryDO;
import com.happylifeplat.tcc.demo.dubbo.inventory.api.service.InventoryService;
import com.happylifeplat.tcc.demo.dubbo.inventory.mapper.InventoryMapper;
import org.slf4j.Logger;
@ -45,7 +45,7 @@ public class InventoryServiceImpl implements InventoryService {
private final InventoryMapper inventoryMapper;
@Autowired
@Autowired(required = false)
public InventoryServiceImpl(InventoryMapper inventoryMapper) {
this.inventoryMapper = inventoryMapper;
}
@ -61,7 +61,7 @@ public class InventoryServiceImpl implements InventoryService {
@Override
@Tcc(confirmMethod = "confirmMethod", cancelMethod = "cancelMethod")
public Boolean decrease(InventoryDTO inventoryDTO) {
final Inventory entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
final InventoryDO entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
entity.setTotalInventory(entity.getTotalInventory() - inventoryDTO.getCount());
entity.setLockInventory(entity.getLockInventory() + inventoryDTO.getCount());
final int decrease = inventoryMapper.decrease(entity);
@ -71,6 +71,17 @@ public class InventoryServiceImpl implements InventoryService {
return true;
}
/**
* 获取商品库存信息
*
* @param productId 商品id
* @return InventoryDO
*/
@Override
public InventoryDO findByProductId(String productId) {
return inventoryMapper.findByProductId(productId);
}
@Override
@Tcc(confirmMethod = "confirmMethod", cancelMethod = "cancelMethod")
public String mockWithTryException(InventoryDTO inventoryDTO) {
@ -89,7 +100,7 @@ public class InventoryServiceImpl implements InventoryService {
} catch (InterruptedException e) {
e.printStackTrace();
}
final Inventory entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
final InventoryDO entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
entity.setTotalInventory(entity.getTotalInventory() - inventoryDTO.getCount());
entity.setLockInventory(entity.getLockInventory() + inventoryDTO.getCount());
final int decrease = inventoryMapper.decrease(entity);
@ -103,7 +114,7 @@ public class InventoryServiceImpl implements InventoryService {
@Tcc(confirmMethod = "confirmMethodException", cancelMethod = "cancelMethod")
@Transactional(rollbackFor = Exception.class)
public String mockWithConfirmException(InventoryDTO inventoryDTO) {
final Inventory entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
final InventoryDO entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
entity.setTotalInventory(entity.getTotalInventory() - inventoryDTO.getCount());
entity.setLockInventory(entity.getLockInventory() + inventoryDTO.getCount());
final int decrease = inventoryMapper.decrease(entity);
@ -119,7 +130,7 @@ public class InventoryServiceImpl implements InventoryService {
@Transactional(rollbackFor = Exception.class)
public Boolean mockWithConfirmTimeout(InventoryDTO inventoryDTO) {
LOGGER.info("==========调用扣减库存确认方法mockWithConfirmTimeout===========");
final Inventory entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
final InventoryDO entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
entity.setTotalInventory(entity.getTotalInventory() - inventoryDTO.getCount());
entity.setLockInventory(entity.getLockInventory() + inventoryDTO.getCount());
final int decrease = inventoryMapper.decrease(entity);
@ -141,7 +152,7 @@ public class InventoryServiceImpl implements InventoryService {
}
LOGGER.info("==========调用扣减库存确认方法===========");
final Inventory entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
final InventoryDO entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
entity.setLockInventory(entity.getLockInventory() - inventoryDTO.getCount());
inventoryMapper.decrease(entity);
@ -156,7 +167,7 @@ public class InventoryServiceImpl implements InventoryService {
LOGGER.info("==========调用扣减库存确认方法===========");
final Inventory entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
final InventoryDO entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
entity.setLockInventory(entity.getLockInventory() - inventoryDTO.getCount());
final int decrease = inventoryMapper.decrease(entity);
@ -177,7 +188,7 @@ public class InventoryServiceImpl implements InventoryService {
LOGGER.info("==========调用扣减库存确认方法===========");
final Inventory entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
final InventoryDO entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
entity.setLockInventory(entity.getLockInventory() - inventoryDTO.getCount());
@ -199,13 +210,13 @@ public class InventoryServiceImpl implements InventoryService {
LOGGER.info("==========调用扣减库存取消方法===========");
final Inventory entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
final InventoryDO entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
entity.setTotalInventory(entity.getTotalInventory() + inventoryDTO.getCount());
entity.setLockInventory(entity.getLockInventory() - inventoryDTO.getCount());
int rows= inventoryMapper.cancel(entity);
int rows = inventoryMapper.cancel(entity);
if (rows != 1) {

View File

@ -6,7 +6,7 @@ server:
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.1.68:3306/stock?useUnicode=true&characterEncoding=utf8
url: jdbc:mysql://192.168.1.68:3306/tcc_stock?useUnicode=true&characterEncoding=utf8
username: xiaoyu
password: Wgj@555888

View File

@ -25,9 +25,9 @@
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="inventory"/>
<dubbo:application name="inventory_service"/>
<dubbo:registry protocol="zookeeper" address="192.168.1.143:2181"/>
<dubbo:registry protocol="zookeeper" address="192.168.1.148:2181"/>
<dubbo:protocol accesslog="true" name="dubbo" port="20885"/>

View File

@ -23,7 +23,7 @@
<parent>
<artifactId>happylifeplat-tcc-demo-dubbo</artifactId>
<groupId>com.happylifeplat.tcc</groupId>
<version>1.1.0-RELEASE</version>
<version>1.1.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -166,7 +166,7 @@
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.happylifeplat.tcc.demo.dubbo.order.OrderApplication</mainClass>
<mainClass>com.happylifeplat.tcc.demo.dubbo.order.DubboTccOrderApplication</mainClass>
<executable>true</executable>
</configuration>
</plugin>

View File

@ -29,9 +29,9 @@ import org.springframework.context.annotation.ImportResource;
@SpringBootApplication
@ImportResource({"classpath:applicationContext.xml"})
@MapperScan("com.happylifeplat.tcc.demo.dubbo.order.mapper")
public class OrderApplication {
public class DubboTccOrderApplication {
public static void main(String[] args) {
SpringApplication.run(OrderApplication.class, args);
SpringApplication.run(DubboTccOrderApplication.class, args);
}

View File

@ -59,7 +59,6 @@ public class SwaggerConfig {
.build();
}
// swagger
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))

View File

@ -18,6 +18,8 @@
package com.happylifeplat.tcc.demo.dubbo.order.entity;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
@ -25,6 +27,7 @@ import java.util.Date;
/**
* @author xiaoyu
*/
@Data
public class Order implements Serializable {
private static final long serialVersionUID = -8551347266419380333L;
@ -49,7 +52,7 @@ public class Order implements Serializable {
/**
* 商品id
*/
private Integer productId;
private String productId;
/**
* 付款金额
@ -64,70 +67,7 @@ public class Order implements Serializable {
/**
* 购买人
*/
private Integer userId;
private String userId;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Integer getProductId() {
return productId;
}
public void setProductId(Integer productId) {
this.productId = productId;
}
public BigDecimal getTotalAmount() {
return totalAmount;
}
public void setTotalAmount(BigDecimal totalAmount) {
this.totalAmount = totalAmount;
}
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
}

View File

@ -23,6 +23,7 @@ import com.happylifeplat.tcc.demo.dubbo.order.entity.Order;
import com.happylifeplat.tcc.demo.dubbo.order.enums.OrderStatusEnum;
import com.happylifeplat.tcc.demo.dubbo.order.mapper.OrderMapper;
import com.happylifeplat.tcc.demo.dubbo.order.service.OrderService;
import com.happylifeplat.tcc.demo.dubbo.order.service.PaymentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -47,12 +48,13 @@ public class OrderServiceImpl implements OrderService {
private final OrderMapper orderMapper;
private final PaymentServiceImpl paymentServiceImpl;
private final PaymentService paymentService;
@Autowired
public OrderServiceImpl(OrderMapper orderMapper, PaymentServiceImpl paymentServiceImpl) {
@Autowired(required = false)
public OrderServiceImpl(OrderMapper orderMapper,
PaymentService paymentService) {
this.orderMapper = orderMapper;
this.paymentServiceImpl = paymentServiceImpl;
this.paymentService = paymentService;
}
@ -62,10 +64,9 @@ public class OrderServiceImpl implements OrderService {
final int rows = orderMapper.save(order);
if (rows > 0) {
paymentServiceImpl.makePayment(order);
paymentService.makePayment(order);
}
return "success";
}
@ -82,7 +83,7 @@ public class OrderServiceImpl implements OrderService {
final int rows = orderMapper.save(order);
if (rows > 0) {
paymentServiceImpl.mockPaymentInventoryWithTryException(order);
paymentService.mockPaymentInventoryWithTryException(order);
}
@ -102,7 +103,7 @@ public class OrderServiceImpl implements OrderService {
final int rows = orderMapper.save(order);
if (rows > 0) {
paymentServiceImpl.mockPaymentInventoryWithTryTimeout(order);
paymentService.mockPaymentInventoryWithTryTimeout(order);
}
@ -122,7 +123,7 @@ public class OrderServiceImpl implements OrderService {
final int rows = orderMapper.save(order);
if (rows > 0) {
paymentServiceImpl.mockPaymentInventoryWithConfirmException(order);
paymentService.mockPaymentInventoryWithConfirmException(order);
}
@ -142,7 +143,7 @@ public class OrderServiceImpl implements OrderService {
final int rows = orderMapper.save(order);
if (rows > 0) {
paymentServiceImpl.mockPaymentInventoryWithConfirmTimeout(order);
paymentService.mockPaymentInventoryWithConfirmTimeout(order);
}
@ -160,12 +161,12 @@ public class OrderServiceImpl implements OrderService {
order.setCreateTime(new Date());
order.setNumber(IdWorkerUtils.getInstance().buildPartNumber());
//demo中的表里只有商品id为1的数据
order.setProductId(1);
order.setProductId("1");
order.setStatus(OrderStatusEnum.NOT_PAY.getCode());
order.setTotalAmount(amount);
order.setCount(count);
//demo中 表里面存的用户id为10000
order.setUserId(10000);
order.setUserId("10000");
return order;
}
}

View File

@ -21,8 +21,10 @@ package com.happylifeplat.tcc.demo.dubbo.order.service.impl;
import com.happylifeplat.tcc.annotation.Tcc;
import com.happylifeplat.tcc.demo.dubbo.account.api.dto.AccountDTO;
import com.happylifeplat.tcc.demo.dubbo.account.api.entity.AccountDO;
import com.happylifeplat.tcc.demo.dubbo.account.api.service.AccountService;
import com.happylifeplat.tcc.demo.dubbo.inventory.api.dto.InventoryDTO;
import com.happylifeplat.tcc.demo.dubbo.inventory.api.entity.InventoryDO;
import com.happylifeplat.tcc.demo.dubbo.inventory.api.service.InventoryService;
import com.happylifeplat.tcc.demo.dubbo.order.entity.Order;
import com.happylifeplat.tcc.demo.dubbo.order.enums.OrderStatusEnum;
@ -53,8 +55,10 @@ public class PaymentServiceImpl implements PaymentService {
private final InventoryService inventoryService;
@Autowired
public PaymentServiceImpl(OrderMapper orderMapper, AccountService accountService, InventoryService inventoryService) {
@Autowired(required = false)
public PaymentServiceImpl(OrderMapper orderMapper,
AccountService accountService,
InventoryService inventoryService) {
this.orderMapper = orderMapper;
this.accountService = accountService;
this.inventoryService = inventoryService;
@ -64,6 +68,19 @@ public class PaymentServiceImpl implements PaymentService {
@Override
@Tcc(confirmMethod = "confirmOrderStatus", cancelMethod = "cancelOrderStatus")
public void makePayment(Order order) {
//做库存和资金账户的检验工作 这里只是demo
final AccountDO accountDO = accountService.findByUserId(order.getUserId());
if (accountDO.getBalance().compareTo(order.getTotalAmount()) <= 0) {
return;
}
final InventoryDO inventory = inventoryService.findByProductId(order.getProductId());
if (inventory.getTotalInventory() < order.getCount()) {
return;
}
order.setStatus(OrderStatusEnum.PAYING.getCode());
orderMapper.update(order);
//扣除用户余额

View File

@ -6,7 +6,7 @@ server:
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.1.68:3306/order?useUnicode=true&characterEncoding=utf8
url: jdbc:mysql://192.168.1.68:3306/tcc_order?useUnicode=true&characterEncoding=utf8
username: xiaoyu
password: Wgj@555888
@ -20,7 +20,7 @@ logging:
root: error
org.springframework.web: info
org.apache.ibatis: info
com.happylifeplat.bonuspoint: info
com.happylifeplat.bonuspoint: debug
com.happylifeplat.lottery: debug
com.happylifeplat: debug
io.netty: info

View File

@ -25,10 +25,10 @@
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="order"/>
<dubbo:application name="order_service"/>
<dubbo:registry protocol="zookeeper" address="192.168.1.143:2181"/>
<dubbo:registry protocol="zookeeper" address="192.168.1.148:2181"/>
<dubbo:protocol accesslog="true" name="dubbo" port="20886"/>

View File

@ -23,7 +23,7 @@
<parent>
<artifactId>happylifeplat-tcc-demo</artifactId>
<groupId>com.happylifeplat.tcc</groupId>
<version>1.1.0-RELEASE</version>
<version>1.1.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -23,7 +23,7 @@
<parent>
<artifactId>happylifeplat-tcc-demo-springcloud</artifactId>
<groupId>com.happylifeplat.tcc</groupId>
<version>1.1.0-RELEASE</version>
<version>1.1.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -34,6 +34,10 @@
<groupId>com.happylifeplat.tcc</groupId>
<artifactId>happylifeplat-tcc-springcloud</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>

View File

@ -19,7 +19,6 @@ package com.happylifeplat.tcc.demo.springcloud.account;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
@ -35,10 +34,10 @@ import org.springframework.context.annotation.ImportResource;
@EnableFeignClients
@ImportResource({"classpath:applicationContext.xml"})
@MapperScan("com.happylifeplat.tcc.demo.springcloud.account.mapper")
public class AccountApplication {
public class SpringcloudTccAccountApplication {
public static void main(String[] args) {
SpringApplication.run(AccountApplication.class, args);
SpringApplication.run(SpringcloudTccAccountApplication.class, args);
}

View File

@ -23,8 +23,11 @@ import com.happylifeplat.tcc.demo.springcloud.account.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
/**
* @author xiaoyu
*/
@ -46,4 +49,12 @@ public class AccountController {
}
@RequestMapping("/findByUserId")
public BigDecimal findByUserId(@RequestParam("userId") String userId) {
return accountService.findByUserId(userId).getBalance();
}
}

View File

@ -18,19 +18,22 @@
package com.happylifeplat.tcc.demo.springcloud.account.dto;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* @author xiaoyu
*/
@Data
public class AccountDTO implements Serializable {
private static final long serialVersionUID = 7223470850578998427L;
/**
* 用户id
*/
private Integer userId;
private String userId;
/**
* 扣款金额
@ -38,28 +41,4 @@ public class AccountDTO implements Serializable {
private BigDecimal amount;
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public BigDecimal getAmount() {
return amount;
}
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
@Override
public String toString() {
return "AccountDTO{" +
"userId=" + userId +
", amount=" + amount +
'}';
}
}

View File

@ -18,6 +18,8 @@
package com.happylifeplat.tcc.demo.springcloud.account.entity;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
@ -25,12 +27,13 @@ import java.util.Date;
/**
* @author xiaoyu
*/
@Data
public class AccountDO implements Serializable {
private static final long serialVersionUID = -81849676368907419L;
private Integer id;
private Integer userId;
private String userId;
private BigDecimal balance;
@ -40,64 +43,4 @@ public class AccountDO implements Serializable {
private Date updateTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public BigDecimal getBalance() {
return balance;
}
public void setBalance(BigDecimal balance) {
this.balance = balance;
}
public BigDecimal getFreezeAmount() {
return freezeAmount;
}
public void setFreezeAmount(BigDecimal freezeAmount) {
this.freezeAmount = freezeAmount;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
@Override
public String toString() {
return "AccountDO{" +
"id=" + id +
", userId=" + userId +
", balance=" + balance +
", freezeAmount=" + freezeAmount +
", createTime=" + createTime +
", updateTime=" + updateTime +
'}';
}
}

View File

@ -71,5 +71,5 @@ public interface AccountMapper {
* @return AccountDO
*/
@Select("select * from account where user_id =#{userId}")
AccountDO findByUserId(Integer userId);
AccountDO findByUserId(String userId);
}

View File

@ -20,6 +20,7 @@ package com.happylifeplat.tcc.demo.springcloud.account.service;
import com.happylifeplat.tcc.annotation.Tcc;
import com.happylifeplat.tcc.demo.springcloud.account.dto.AccountDTO;
import com.happylifeplat.tcc.demo.springcloud.account.entity.AccountDO;
/**
* @author xiaoyu
@ -35,4 +36,12 @@ public interface AccountService {
*/
@Tcc
boolean payment(AccountDTO accountDTO);
/**
* 获取用户账户信息
* @param userId 用户id
* @return AccountDO
*/
AccountDO findByUserId(String userId);
}

View File

@ -46,7 +46,7 @@ public class AccountServiceImpl implements AccountService {
private final AccountMapper accountMapper;
@Autowired
@Autowired(required = false)
public AccountServiceImpl(AccountMapper accountMapper) {
this.accountMapper = accountMapper;
}
@ -72,9 +72,20 @@ public class AccountServiceImpl implements AccountService {
return Boolean.TRUE;
}
/**
* 获取用户账户信息
*
* @param userId 用户id
* @return AccountDO
*/
@Override
public AccountDO findByUserId(String userId) {
return accountMapper.findByUserId(userId);
}
public boolean confirm(AccountDTO accountDTO) {
LOGGER.debug("============springcloud执行确认付款接口===============");
LOGGER.debug("============springcloud tcc 执行确认付款接口===============");
final AccountDO accountDO = accountMapper.findByUserId(accountDTO.getUserId());
accountDO.setFreezeAmount(accountDO.getFreezeAmount().subtract(accountDTO.getAmount()));
@ -89,7 +100,7 @@ public class AccountServiceImpl implements AccountService {
public boolean cancel(AccountDTO accountDTO) {
LOGGER.debug("============springcloud执行取消付款接口===============");
LOGGER.debug("============springcloud tcc 执行取消付款接口===============");
final AccountDO accountDO = accountMapper.findByUserId(accountDTO.getUserId());
accountDO.setBalance(accountDO.getBalance().add(accountDTO.getAmount()));
accountDO.setFreezeAmount(accountDO.getFreezeAmount().subtract(accountDTO.getAmount()));

View File

@ -7,7 +7,7 @@ server:
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.1.68:3306/account?useUnicode=true&characterEncoding=utf8
url: jdbc:mysql://192.168.1.68:3306/tcc_account?useUnicode=true&characterEncoding=utf8
username: xiaoyu
password: Wgj@555888
initialSize: 20

View File

@ -23,7 +23,7 @@
<parent>
<artifactId>happylifeplat-tcc-demo-springcloud</artifactId>
<groupId>com.happylifeplat.tcc</groupId>
<version>1.1.0-RELEASE</version>
<version>1.1.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -23,7 +23,7 @@
<parent>
<artifactId>happylifeplat-tcc-demo-springcloud</artifactId>
<groupId>com.happylifeplat.tcc</groupId>
<version>1.1.0-RELEASE</version>
<version>1.1.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -35,6 +35,11 @@
<artifactId>happylifeplat-tcc-springcloud</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>

View File

@ -19,7 +19,6 @@ package com.happylifeplat.tcc.demo.springcloud.inventory;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
@ -35,10 +34,10 @@ import org.springframework.context.annotation.ImportResource;
@EnableFeignClients
@ImportResource({"classpath:applicationContext.xml"})
@MapperScan("com.happylifeplat.tcc.demo.springcloud.inventory.mapper")
public class InventoryApplication {
public class SpringCloudTccInventoryApplication {
public static void main(String[] args) {
SpringApplication.run(InventoryApplication.class, args);
SpringApplication.run(SpringCloudTccInventoryApplication.class, args);
}

View File

@ -23,6 +23,7 @@ import com.happylifeplat.tcc.demo.springcloud.inventory.service.InventoryService
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
@ -46,6 +47,13 @@ public class InventoryController {
}
@RequestMapping("/findByProductId")
public Integer findByProductId(@RequestParam("productId") String productId) {
return inventoryService.findByProductId(productId).getTotalInventory();
}
@RequestMapping("/mockWithTryException")
public Boolean mockWithTryException(@RequestBody InventoryDTO inventoryDTO) {
return inventoryService.mockWithTryException(inventoryDTO);

View File

@ -18,18 +18,22 @@
package com.happylifeplat.tcc.demo.springcloud.inventory.dto;
import lombok.Data;
import java.io.Serializable;
/**
* @author xiaoyu
*/
@Data
public class InventoryDTO implements Serializable {
private static final long serialVersionUID = 8229355519336565493L;
/**
* 商品id
*/
private Integer productId;
private String productId;
/**
@ -37,27 +41,4 @@ public class InventoryDTO implements Serializable {
*/
private Integer count;
public Integer getProductId() {
return productId;
}
public void setProductId(Integer productId) {
this.productId = productId;
}
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
@Override
public String toString() {
return "InventoryDTO{" +
"productId=" + productId +
", count=" + count +
'}';
}
}

View File

@ -18,12 +18,15 @@
package com.happylifeplat.tcc.demo.springcloud.inventory.entity;
import lombok.Data;
import java.io.Serializable;
/**
* @author xiaoyu
*/
public class Inventory implements Serializable {
@Data
public class InventoryDO implements Serializable {
private static final long serialVersionUID = 6957734749389133832L;
private Integer id;
@ -31,7 +34,7 @@ public class Inventory implements Serializable {
/**
* 商品id
*/
private Integer productId;
private String productId;
/**
* 总库存
@ -43,35 +46,4 @@ public class Inventory implements Serializable {
*/
private Integer lockInventory;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getProductId() {
return productId;
}
public void setProductId(Integer productId) {
this.productId = productId;
}
public Integer getTotalInventory() {
return totalInventory;
}
public void setTotalInventory(Integer totalInventory) {
this.totalInventory = totalInventory;
}
public Integer getLockInventory() {
return lockInventory;
}
public void setLockInventory(Integer lockInventory) {
this.lockInventory = lockInventory;
}
}

View File

@ -18,7 +18,7 @@
package com.happylifeplat.tcc.demo.springcloud.inventory.mapper;
import com.happylifeplat.tcc.demo.springcloud.inventory.entity.Inventory;
import com.happylifeplat.tcc.demo.springcloud.inventory.entity.InventoryDO;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
@ -37,7 +37,7 @@ public interface InventoryMapper {
@Update("update inventory set total_inventory =#{totalInventory}," +
" lock_inventory= #{lockInventory} " +
" where product_id =#{productId} and total_inventory >0 ")
int decrease(Inventory inventory);
int decrease(InventoryDO inventory);
/**
@ -49,7 +49,7 @@ public interface InventoryMapper {
@Update("update inventory set " +
" lock_inventory= #{lockInventory} " +
" where product_id =#{productId} and lock_inventory >0 ")
int confirm(Inventory inventory);
int confirm(InventoryDO inventory);
/**
@ -61,7 +61,7 @@ public interface InventoryMapper {
@Update("update inventory set total_inventory =#{totalInventory}," +
" lock_inventory= #{lockInventory} " +
" where product_id =#{productId} and lock_inventory >0 ")
int cancel(Inventory inventory);
int cancel(InventoryDO inventory);
/**
@ -71,5 +71,5 @@ public interface InventoryMapper {
* @return Inventory
*/
@Select("select * from inventory where product_id =#{productId}")
Inventory findByProductId(Integer productId);
InventoryDO findByProductId(String productId);
}

View File

@ -20,6 +20,7 @@ package com.happylifeplat.tcc.demo.springcloud.inventory.service;
import com.happylifeplat.tcc.annotation.Tcc;
import com.happylifeplat.tcc.demo.springcloud.inventory.dto.InventoryDTO;
import com.happylifeplat.tcc.demo.springcloud.inventory.entity.InventoryDO;
/**
@ -39,6 +40,14 @@ public interface InventoryService {
Boolean decrease(InventoryDTO inventoryDTO);
/**
* 获取商品库存信息
* @param productId 商品id
* @return InventoryDO
*/
InventoryDO findByProductId(String productId);
/**
* mock 库存扣减try阶段异常
*

View File

@ -22,7 +22,7 @@ import com.happylifeplat.tcc.annotation.Tcc;
import com.happylifeplat.tcc.common.exception.TccRuntimeException;
import com.happylifeplat.tcc.demo.springcloud.inventory.dto.InventoryDTO;
import com.happylifeplat.tcc.demo.springcloud.inventory.entity.Inventory;
import com.happylifeplat.tcc.demo.springcloud.inventory.entity.InventoryDO;
import com.happylifeplat.tcc.demo.springcloud.inventory.mapper.InventoryMapper;
import com.happylifeplat.tcc.demo.springcloud.inventory.service.InventoryService;
import org.slf4j.Logger;
@ -46,7 +46,7 @@ public class InventoryServiceImpl implements InventoryService {
private final InventoryMapper inventoryMapper;
@Autowired
@Autowired(required = false)
public InventoryServiceImpl(InventoryMapper inventoryMapper) {
this.inventoryMapper = inventoryMapper;
}
@ -63,7 +63,7 @@ public class InventoryServiceImpl implements InventoryService {
@Tcc(confirmMethod = "confirmMethod", cancelMethod = "cancelMethod")
public Boolean decrease(InventoryDTO inventoryDTO) {
LOGGER.info("==========springcloud调用扣减库存decrease===========");
final Inventory entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
final InventoryDO entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
entity.setTotalInventory(entity.getTotalInventory() - inventoryDTO.getCount());
entity.setLockInventory(entity.getLockInventory() + inventoryDTO.getCount());
final int decrease = inventoryMapper.decrease(entity);
@ -73,6 +73,17 @@ public class InventoryServiceImpl implements InventoryService {
return true;
}
/**
* 获取商品库存信息
*
* @param productId 商品id
* @return InventoryDO
*/
@Override
public InventoryDO findByProductId(String productId) {
return inventoryMapper.findByProductId(productId);
}
@Override
@Tcc(confirmMethod = "confirmMethod", cancelMethod = "cancelMethod")
public Boolean mockWithTryException(InventoryDTO inventoryDTO) {
@ -92,7 +103,7 @@ public class InventoryServiceImpl implements InventoryService {
e.printStackTrace();
}
LOGGER.info("==========springcloud调用扣减库存mockWithTryTimeout===========");
final Inventory entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
final InventoryDO entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
entity.setTotalInventory(entity.getTotalInventory() - inventoryDTO.getCount());
entity.setLockInventory(entity.getLockInventory() + inventoryDTO.getCount());
final int decrease = inventoryMapper.decrease(entity);
@ -114,7 +125,7 @@ public class InventoryServiceImpl implements InventoryService {
}
LOGGER.info("==========Springcloud调用扣减库存确认方法===========");
final Inventory entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
final InventoryDO entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
entity.setLockInventory(entity.getLockInventory() - inventoryDTO.getCount());
inventoryMapper.decrease(entity);
@ -129,7 +140,7 @@ public class InventoryServiceImpl implements InventoryService {
LOGGER.info("==========Springcloud调用扣减库存确认方法===========");
final Inventory entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
final InventoryDO entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
entity.setLockInventory(entity.getLockInventory() - inventoryDTO.getCount());
final int decrease = inventoryMapper.decrease(entity);
@ -149,7 +160,7 @@ public class InventoryServiceImpl implements InventoryService {
LOGGER.info("==========Springcloud调用扣减库存确认方法===========");
final Inventory entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
final InventoryDO entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
entity.setLockInventory(entity.getLockInventory() - inventoryDTO.getCount());
@ -169,7 +180,7 @@ public class InventoryServiceImpl implements InventoryService {
LOGGER.info("==========Springcloud调用扣减库存取消方法===========");
final Inventory entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
final InventoryDO entity = inventoryMapper.findByProductId(inventoryDTO.getProductId());
entity.setTotalInventory(entity.getTotalInventory() + inventoryDTO.getCount());

View File

@ -6,7 +6,7 @@ server:
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.1.68:3306/stock?useUnicode=true&characterEncoding=utf8
url: jdbc:mysql://192.168.1.68:3306/tcc_stock?useUnicode=true&characterEncoding=utf8
username: xiaoyu
password: Wgj@555888
platform: mysql

View File

@ -23,7 +23,7 @@
<parent>
<artifactId>happylifeplat-tcc-demo-springcloud</artifactId>
<groupId>com.happylifeplat.tcc</groupId>
<version>1.1.0-RELEASE</version>
<version>1.1.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -19,7 +19,6 @@ package com.happylifeplat.tcc.demo.springcloud.order;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
@ -35,10 +34,10 @@ import org.springframework.context.annotation.ImportResource;
@EnableFeignClients
@ImportResource({"classpath:applicationContext.xml"})
@MapperScan("com.happylifeplat.tcc.demo.springcloud.order.mapper")
public class OrderApplication {
public class SpringCloudTccOrderApplication {
public static void main(String[] args) {
SpringApplication.run(OrderApplication.class, args);
SpringApplication.run(SpringCloudTccOrderApplication.class, args);
}

View File

@ -24,6 +24,9 @@ import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.math.BigDecimal;
/**
* @author xiaoyu
@ -41,4 +44,15 @@ public interface AccountClient {
@Tcc
Boolean payment(@RequestBody AccountDTO accountDO);
/**
* 获取用户账户信息
*
* @param userId 用户id
* @return AccountDO
*/
@PostMapping("/account-service/account/findByUserId")
BigDecimal findByUserId(@RequestParam("userId") String userId);
}

View File

@ -23,6 +23,7 @@ import com.happylifeplat.tcc.demo.springcloud.order.dto.InventoryDTO;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @author xiaoyu
@ -40,6 +41,18 @@ public interface InventoryClient {
@RequestMapping("/inventory-service/inventory/decrease")
Boolean decrease(@RequestBody InventoryDTO inventoryDTO);
/**
* 获取商品库存
*
* @param productId 商品id
* @return InventoryDO
*/
@RequestMapping("/inventory-service/inventory/findByProductId")
Integer findByProductId(@RequestParam("productId") String productId);
/**
* 模拟库存扣减异常
*

View File

@ -59,7 +59,6 @@ public class SwaggerConfig {
.build();
}
// swagger
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))

View File

@ -18,19 +18,22 @@
package com.happylifeplat.tcc.demo.springcloud.order.dto;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* @author xiaoyu
*/
@Data
public class AccountDTO implements Serializable {
private static final long serialVersionUID = 7223470850578998427L;
/**
* 用户id
*/
private Integer userId;
private String userId;
/**
* 扣款金额
@ -38,28 +41,4 @@ public class AccountDTO implements Serializable {
private BigDecimal amount;
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public BigDecimal getAmount() {
return amount;
}
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
@Override
public String toString() {
return "AccountDTO{" +
"userId=" + userId +
", amount=" + amount +
'}';
}
}

View File

@ -18,18 +18,22 @@
package com.happylifeplat.tcc.demo.springcloud.order.dto;
import lombok.Data;
import java.io.Serializable;
/**
* @author xiaoyu
*/
@Data
public class InventoryDTO implements Serializable {
private static final long serialVersionUID = 8229355519336565493L;
/**
* 商品id
*/
private Integer productId;
private String productId;
/**
@ -37,27 +41,4 @@ public class InventoryDTO implements Serializable {
*/
private Integer count;
public Integer getProductId() {
return productId;
}
public void setProductId(Integer productId) {
this.productId = productId;
}
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
@Override
public String toString() {
return "InventoryDTO{" +
"productId=" + productId +
", count=" + count +
'}';
}
}

View File

@ -18,6 +18,8 @@
package com.happylifeplat.tcc.demo.springcloud.order.entity;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
@ -25,9 +27,11 @@ import java.util.Date;
/**
* @author xiaoyu
*/
@Data
public class Order implements Serializable {
private static final long serialVersionUID = -8551347266419380333L;
private Integer id;
/**
@ -49,7 +53,7 @@ public class Order implements Serializable {
/**
* 商品id
*/
private Integer productId;
private String productId;
/**
* 付款金额
@ -64,70 +68,6 @@ public class Order implements Serializable {
/**
* 购买人
*/
private Integer userId;
private String userId;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Integer getProductId() {
return productId;
}
public void setProductId(Integer productId) {
this.productId = productId;
}
public BigDecimal getTotalAmount() {
return totalAmount;
}
public void setTotalAmount(BigDecimal totalAmount) {
this.totalAmount = totalAmount;
}
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
}

View File

@ -23,6 +23,7 @@ import com.happylifeplat.tcc.demo.springcloud.order.entity.Order;
import com.happylifeplat.tcc.demo.springcloud.order.enums.OrderStatusEnum;
import com.happylifeplat.tcc.demo.springcloud.order.mapper.OrderMapper;
import com.happylifeplat.tcc.demo.springcloud.order.service.OrderService;
import com.happylifeplat.tcc.demo.springcloud.order.service.PaymentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -47,12 +48,12 @@ public class OrderServiceImpl implements OrderService {
private final OrderMapper orderMapper;
private final PaymentServiceImpl paymentServiceImpl;
private final PaymentService paymentService;
@Autowired
public OrderServiceImpl(OrderMapper orderMapper, PaymentServiceImpl paymentServiceImpl) {
@Autowired(required = false)
public OrderServiceImpl(OrderMapper orderMapper, PaymentService paymentService) {
this.orderMapper = orderMapper;
this.paymentServiceImpl = paymentServiceImpl;
this.paymentService = paymentService;
}
@ -62,7 +63,7 @@ public class OrderServiceImpl implements OrderService {
final int rows = orderMapper.save(order);
if (rows > 0) {
paymentServiceImpl.makePayment(order);
paymentService.makePayment(order);
}
@ -82,7 +83,7 @@ public class OrderServiceImpl implements OrderService {
final int rows = orderMapper.save(order);
if (rows > 0) {
paymentServiceImpl.mockPaymentInventoryWithTryException(order);
paymentService.mockPaymentInventoryWithTryException(order);
}
@ -102,7 +103,7 @@ public class OrderServiceImpl implements OrderService {
final int rows = orderMapper.save(order);
if (rows > 0) {
paymentServiceImpl.mockPaymentInventoryWithTryTimeout(order);
paymentService.mockPaymentInventoryWithTryTimeout(order);
}
@ -121,12 +122,12 @@ public class OrderServiceImpl implements OrderService {
order.setCreateTime(new Date());
order.setNumber(IdWorkerUtils.getInstance().buildPartNumber());
//demo中的表里只有商品id为 1的数据
order.setProductId(1);
order.setProductId("1");
order.setStatus(OrderStatusEnum.NOT_PAY.getCode());
order.setTotalAmount(amount);
order.setCount(count);
//demo中 表里面存的用户id为10000
order.setUserId(10000);
order.setUserId("10000");
return order;
}
}

View File

@ -33,6 +33,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
/**
* @author xiaoyu
*/
@ -52,8 +54,10 @@ public class PaymentServiceImpl implements PaymentService {
private final InventoryClient inventoryClient;
@Autowired
public PaymentServiceImpl(OrderMapper orderMapper, AccountClient accountClient, InventoryClient inventoryClient) {
@Autowired(required = false)
public PaymentServiceImpl(OrderMapper orderMapper,
AccountClient accountClient,
InventoryClient inventoryClient) {
this.orderMapper = orderMapper;
this.accountClient = accountClient;
this.inventoryClient = inventoryClient;
@ -63,6 +67,22 @@ public class PaymentServiceImpl implements PaymentService {
@Override
@Tcc(confirmMethod = "confirmOrderStatus", cancelMethod = "cancelOrderStatus")
public void makePayment(Order order) {
//检查数据
final BigDecimal accountInfo = accountClient.findByUserId(order.getUserId());
final Integer inventoryInfo= inventoryClient.findByProductId(order.getProductId());
if (accountInfo.compareTo(order.getTotalAmount()) <= 0) {
return;
}
if (inventoryInfo < order.getCount()) {
return;
}
order.setStatus(OrderStatusEnum.PAYING.getCode());
orderMapper.update(order);
//扣除用户余额

View File

@ -7,7 +7,7 @@ server:
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.1.68:3306/order?useUnicode=true&characterEncoding=utf8
url: jdbc:mysql://192.168.1.68:3306/tcc_order?useUnicode=true&characterEncoding=utf8
username: xiaoyu
password: Wgj@555888
initialSize: 20

View File

@ -23,7 +23,7 @@
<parent>
<artifactId>happylifeplat-tcc-demo</artifactId>
<groupId>com.happylifeplat.tcc</groupId>
<version>1.1.0-RELEASE</version>
<version>1.1.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>happylifeplat-tcc</artifactId>
<groupId>com.happylifeplat.tcc</groupId>
<version>1.1.0-RELEASE</version>
<version>1.1.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,9 +5,9 @@ MySQL - 5.7.19-0ubuntu0.16.04.1 : Database - account
*/
CREATE DATABASE /*!32312 IF NOT EXISTS*/`account` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`tcc_account` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin */;
USE `account`;
USE `tcc_account`;
/*Table structure for table `account` */
@ -15,7 +15,7 @@ DROP TABLE IF EXISTS `account`;
CREATE TABLE `account` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) NOT NULL,
`user_id` varchar(128) NOT NULL,
`balance` decimal(10,0) NOT NULL COMMENT '用户余额',
`freeze_amount` decimal(10,0) NOT NULL COMMENT '冻结金额,扣款暂存余额',
`create_time` datetime NOT NULL,
@ -27,13 +27,13 @@ CREATE TABLE `account` (
insert into `account`(`id`,`user_id`,`balance`,`freeze_amount`,`create_time`,`update_time`) values
(1,10000,10000,0,'2017-09-18 14:54:22',NULL);
(1,'10000',10000,0,'2017-09-18 14:54:22',NULL);
CREATE DATABASE /*!32312 IF NOT EXISTS*/`stock` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`tcc_stock` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;
USE `stock`;
USE `tcc_stock`;
/*Table structure for table `inventory` */
@ -41,7 +41,7 @@ DROP TABLE IF EXISTS `inventory`;
CREATE TABLE `inventory` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`product_id` bigint(20) NOT NULL,
`product_id` VARCHAR(128) NOT NULL,
`total_inventory` int(10) NOT NULL COMMENT '总库存',
`lock_inventory` int(10) NOT NULL COMMENT '锁定库存',
PRIMARY KEY (`id`)
@ -51,12 +51,12 @@ CREATE TABLE `inventory` (
insert into `inventory`(`id`,`product_id`,`total_inventory`,`lock_inventory`) values
(1,1,10,0);
(1,'1',1000,0);
CREATE DATABASE /*!32312 IF NOT EXISTS*/`order` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`tcc_order` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;
USE `order`;
USE `tcc_order`;
DROP TABLE IF EXISTS `order`;
CREATE TABLE `order` (
@ -64,10 +64,10 @@ CREATE TABLE `order` (
`create_time` datetime NOT NULL,
`number` varchar(20) COLLATE utf8mb4_bin NOT NULL,
`status` tinyint(4) NOT NULL,
`product_id` bigint(20) NOT NULL,
`product_id` varchar(128) NOT NULL,
`total_amount` decimal(10,0) NOT NULL,
`count` int(4) NOT NULL,
`user_id` bigint(10) NOT NULL,
`user_id` varchar(128) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>happylifeplat-tcc</artifactId>
<groupId>com.happylifeplat.tcc</groupId>
<version>1.1.0-RELEASE</version>
<version>1.1.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>happylifeplat-tcc</artifactId>
<groupId>com.happylifeplat.tcc</groupId>
<version>1.1.0-RELEASE</version>
<version>1.1.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>happylifeplat-tcc</artifactId>
<groupId>com.happylifeplat.tcc</groupId>
<version>1.1.0-RELEASE</version>
<version>1.1.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>

21
pom.xml
View File

@ -7,7 +7,7 @@
<groupId>com.happylifeplat.tcc</groupId>
<artifactId>happylifeplat-tcc</artifactId>
<packaging>pom</packaging>
<version>1.1.0-RELEASE</version>
<version>1.1.1-SNAPSHOT</version>
<name>happylifeplat-tcc</name>
<modules>
<module>happylifeplat-tcc-common</module>
@ -30,13 +30,6 @@
<url>https://github.com/yu199195/happylifeplat-tcc.git</url>
</scm>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
</parent>
<developers>
<developer>
<id>xiaoyu</id>
@ -54,7 +47,7 @@
<jdk.version>1.8</jdk.version>
<spring.version>4.3.9.RELEASE</spring.version>
<spring-cloud.version>Dalston.SR1</spring-cloud.version>
<dubbo.version>2.5.3</dubbo.version>
<dubbo.version>2.5.8</dubbo.version>
<mongo.driver.version>3.5.0</mongo.driver.version>
<mysql-connector-java>5.1.40</mysql-connector-java>
<commons-lang3.version>3.3.2</commons-lang3.version>
@ -78,6 +71,16 @@
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.5.9.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.happylifeplat.tcc</groupId>
<artifactId>happylifeplat-tcc-admin</artifactId>