Skip to content

Commit

Permalink
m
Browse files Browse the repository at this point in the history
  • Loading branch information
lenve committed May 22, 2022
1 parent e69ac1e commit c1590a1
Show file tree
Hide file tree
Showing 49 changed files with 1,832 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public void before(JoinPoint jp, DataScope dataScope) {
for (Role role : roles) {
if (role.getDataScope().equals("1")) {
} else if (role.getDataScope().equals("2")) {
sql.append(" and "+dataScope.deptAlias()+".dept_id in(select dept_id from sys_role_dept srd where srd.role_id="+role.getRoleId()+")");
sql.append(String.format(" and %s.dept_id in(select dept_id from sys_role_dept srd where srd.role_id=%d)", dataScope.deptAlias(), role.getRoleId()));
} else if (role.getDataScope().equals("3")) {
sql.append(" and "+dataScope.deptAlias()+".dept_id =" + user.getDeptId());
sql.append(String.format(" and %s.dept_id=%d", dataScope.deptAlias(), user.getDeptId()));
} else if (role.getDataScope().equals("4")) {
sql.append(" and "+dataScope.deptAlias()+".dept_id in(select dept_id from sys_dept where sys_dept.dept_id=" + user.getDeptId() + " or find_in_set(" + user.getDeptId() + ",ancestors));");
sql.append(String.format(" and %s.dept_id in(select dept_id from sys_dept where sys_dept.dept_id=%d or find_in_set(%d,ancestors))", dataScope.deptAlias(), user.getDeptId(), user.getDeptId()));
} else if (role.getDataScope().equals("5")) {
if (!dataScope.userAlias().equals("")) {
sql.append(" and " + dataScope.userAlias() + ".user_id=" + user.getUserId());
}else{
sql.append(String.format(" and %s.user_id=%d", dataScope.userAlias(), user.getDeptId()));
} else {
sql.append(" and 1=0");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
@SpringBootTest
class DataScopeApplicationTests {

@Test
void test01() {
String format = String.format("aaa%sbbb%s", "1", "2");
System.out.println("format = " + format);
}

@Test
void contextLoads() {
FastAutoGenerator.create("jdbc:mysql:///test06?serverTimezone=Asia/Shanghai&useSSL=false", "root", "123")
Expand Down
112 changes: 112 additions & 0 deletions seata-at/account/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.javaboy</groupId>
<artifactId>account</artifactId>
<version>0.0.1-SNAPSHOT</version>

<description>Demo project for Spring Boot</description>

<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-boot.version>2.3.7.RELEASE</spring-boot.version>
<spring-cloud-alibaba.version>2.2.2.RELEASE</spring-cloud-alibaba.version>
<spring-cloud.version>Hoxton.SR9</spring-cloud.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<artifactId>common</artifactId>
<groupId>org.javaboy</groupId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${spring-cloud-alibaba.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.7.RELEASE</version>
</plugin>
</plugins>
</build>


</project>
15 changes: 15 additions & 0 deletions seata-at/account/src/main/java/org/javaboy/AccountApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.javaboy;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

@SpringBootApplication
@EnableEurekaClient
public class AccountApplication {

public static void main(String[] args) {
SpringApplication.run(AccountApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.javaboy.account.controller;

import org.javaboy.account.service.AccountService;
import org.javaboy.common.RespBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
* @author 江南一点雨
* @微信公众号 江南一点雨
* @网站 http://www.itboyhub.com
* @国际站 http://www.javaboy.org
* @微信 a_java_boy
* @GitHub https://github.com/lenve
* @Gitee https://gitee.com/lenve
*/
@RestController
public class AccountController {

@Autowired
AccountService accountService;

@PostMapping("/deductAccount")
public RespBean deductAccount(String account, Double money) {
if (accountService.deductAccount(account, money)) {
return RespBean.ok("扣款成功");
}
return RespBean.error("扣款失败");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.javaboy.account.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
* @author 江南一点雨
* @微信公众号 江南一点雨
* @网站 http://www.itboyhub.com
* @国际站 http://www.javaboy.org
* @微信 a_java_boy
* @GitHub https://github.com/lenve
* @Gitee https://gitee.com/lenve
*/
@Mapper
public interface AccountMapper {
@Update("update account_tbl set money=money-#{money} where user_id=#{account}")
int updateAccount(@Param("account") String account, @Param("money") Double money);

@Select("select money from account_tbl where user_id=#{account}")
Double getMoneyByAccount(String account);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.javaboy.account.service;

import org.javaboy.account.mapper.AccountMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 江南一点雨
* @微信公众号 江南一点雨
* @网站 http://www.itboyhub.com
* @国际站 http://www.javaboy.org
* @微信 a_java_boy
* @GitHub https://github.com/lenve
* @Gitee https://gitee.com/lenve
*/
@Service
public class AccountService {

@Autowired
AccountMapper accountMapper;

public boolean deductAccount(String account, Double money) {
accountMapper.updateAccount(account, money);
Double m = accountMapper.getMoneyByAccount(account);
if (m >= 0) {
return true;
}else{
throw new RuntimeException("账户余额不足");
}
}
}
9 changes: 9 additions & 0 deletions seata-at/account/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
server.port=1111
spring.application.name=account
eureka.client.service-url.defaultZone=http://localhost:8761/eureka

spring.datasource.username=root
spring.datasource.password=123
spring.datasource.url=jdbc:mysql:///account?serverTimezone=Asia/Shanghai&useSSL=false

spring.cloud.alibaba.seata.tx-service-group=my_test_tx_group
66 changes: 66 additions & 0 deletions seata-at/account/src/main/resources/file.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
transport {
# tcp udt unix-domain-socket
type = "TCP"
#NIO NATIVE
server = "NIO"
#enable heartbeat
heartbeat = true
# the client batch send request enable
enableClientBatchSendRequest = true
#thread factory for netty
threadFactory {
bossThreadPrefix = "NettyBoss"
workerThreadPrefix = "NettyServerNIOWorker"
serverExecutorThread-prefix = "NettyServerBizHandler"
shareBossWorker = false
clientSelectorThreadPrefix = "NettyClientSelector"
clientSelectorThreadSize = 1
clientWorkerThreadPrefix = "NettyClientWorkerThread"
# netty boss thread size,will not be used for UDT
bossThreadSize = 1
#auto default pin or 8
workerThreadSize = "default"
}
shutdown {
# when destroy server, wait seconds
wait = 3
}
serialization = "seata"
compressor = "none"
}
service {
#transaction service group mapping
vgroupMapping.my_test_tx_group = "default"
#only support when registry.type=file, please don't set multiple addresses
default.grouplist = "127.0.0.1:8091"
#degrade, current not support
enableDegrade = false
#disable seata
disableGlobalTransaction = false
}

client {
rm {
asyncCommitBufferLimit = 10000
lock {
retryInterval = 10
retryTimes = 30
retryPolicyBranchRollbackOnConflict = true
}
reportRetryCount = 5
tableMetaCheckEnable = false
reportSuccessEnable = false
}
tm {
commitRetryCount = 5
rollbackRetryCount = 5
}
undo {
dataValidation = true
logSerialization = "jackson"
logTable = "undo_log"
}
log {
exceptionRate = 100
}
}
Loading

0 comments on commit c1590a1

Please sign in to comment.