Commit f31033d6 authored by neo's avatar neo

[BUG] bug fiex db cannot creat when add project

parent 69146937
...@@ -273,6 +273,14 @@ public class ProjectServiceImpl implements ProjectService { ...@@ -273,6 +273,14 @@ public class ProjectServiceImpl implements ProjectService {
return result; return result;
} }
static class DbName {
String dbName;
public DbName(String dbName) {
this.dbName = dbName;
}
}
private String generateDatabase(Project project, String accsetid) {//TODO: should be impl future(neo) private String generateDatabase(Project project, String accsetid) {//TODO: should be impl future(neo)
String maxDbName = projectMapper.maxDbName(project.getYear()); String maxDbName = projectMapper.maxDbName(project.getYear());
String dbName = ""; String dbName = "";
...@@ -282,12 +290,14 @@ public class ProjectServiceImpl implements ProjectService { ...@@ -282,12 +290,14 @@ public class ProjectServiceImpl implements ProjectService {
} else { } else {
dbName = generateProjectDbName(dbName, project.getYear() + ""); dbName = generateProjectDbName(dbName, project.getYear() + "");
} }
DbName sbDbName = new DbName(dbName);
createDatabaseByName(dbName, project); createDatabaseByName(sbDbName, project);
ShardingContextHolder.setDataSourceKey(dbName); ShardingContextHolder.setDataSourceKey(sbDbName.dbName);
try (SqlSession sqlSession = dynamicSqlSessionTemplate.getSqlSessionFactory().openSession(); try (SqlSession sqlSession = dynamicSqlSessionTemplate.getSqlSessionFactory().openSession();
BufferedReader bufferedReader = new BufferedReader(prepareRunScriptReader(DB_MYSQL_PATH, dbName, project, accsetid));) { BufferedReader bufferedReader = new BufferedReader(prepareRunScriptReader(DB_MYSQL_PATH, sbDbName.dbName,
project, accsetid));) {
ScriptRunner scriptRunner = new ScriptRunner(sqlSession.getConnection());//only support mysql ScriptRunner scriptRunner = new ScriptRunner(sqlSession.getConnection());//only support mysql
scriptRunner.setAutoCommit(true); scriptRunner.setAutoCommit(true);
...@@ -298,7 +308,7 @@ public class ProjectServiceImpl implements ProjectService { ...@@ -298,7 +308,7 @@ public class ProjectServiceImpl implements ProjectService {
} }
initStandardAccount(project.getIndustryID()); initStandardAccount(project.getIndustryID());
return dbName; return sbDbName.toString();
} }
...@@ -328,7 +338,7 @@ public class ProjectServiceImpl implements ProjectService { ...@@ -328,7 +338,7 @@ public class ProjectServiceImpl implements ProjectService {
} }
} }
prepareAccount.forEach(m->vatStandardAccountMapper.insert(m)); prepareAccount.forEach(m -> vatStandardAccountMapper.insert(m));
} }
...@@ -395,11 +405,11 @@ public class ProjectServiceImpl implements ProjectService { ...@@ -395,11 +405,11 @@ public class ProjectServiceImpl implements ProjectService {
} }
private void createDatabaseByName(String dbName, Project project) { private void createDatabaseByName(DbName dbName, Project project) {
int result = databaseAgent.createDatabase(dbName); int result = databaseAgent.createDatabase(dbName.dbName);
if (result == Constant.CREATE_DB_EXISTS) { if (result == Constant.CREATE_DB_EXISTS) {
dbName = generateProjectDbName(dbName, project.getYear() + ""); dbName.dbName = generateProjectDbName(dbName.dbName, project.getYear() + "");
createDatabaseByName(dbName, project); createDatabaseByName(dbName, project);
} else if (result == Constant.CREATE_DB_FAILED) { } else if (result == Constant.CREATE_DB_FAILED) {
LOGGER.debug("should throws biz exception");//TODO: should shrow biz exception in futrue(neo) LOGGER.debug("should throws biz exception");//TODO: should shrow biz exception in futrue(neo)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment