Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
workflow
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
2
议题
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄夏豪
workflow
Commits
ef3ededa
提交
ef3ededa
authored
3月 26, 2021
作者:
ww1xhqc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[数据模型] 优化返回信息,增加了逻辑类型判断,增加了缓存。
上级
e0888e6e
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
195 行增加
和
94 行删除
+195
-94
MyCacheConfig.java
...m/tykj/workflowcore/model_layer/config/MyCacheConfig.java
+31
-0
ModelController.java
.../workflowcore/model_layer/controller/ModelController.java
+23
-14
ModelService.java
...m/tykj/workflowcore/model_layer/service/ModelService.java
+13
-4
ModelImpl.java
...tykj/workflowcore/model_layer/service/impl/ModelImpl.java
+84
-62
WorkflowCoreApplicationTests.java
...a/com/tykj/workflowcore/WorkflowCoreApplicationTests.java
+44
-14
没有找到文件。
src/main/java/com/tykj/workflowcore/model_layer/config/MyCacheConfig.java
0 → 100644
浏览文件 @
ef3ededa
package
com
.
tykj
.
workflowcore
.
model_layer
.
config
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.cache.concurrent.ConcurrentMapCache
;
import
org.springframework.cache.support.SimpleCacheManager
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
java.util.Collections
;
/**
* @Author WWW
* @Description
* @Date 10:47 2021/3/26
* @return
**/
@Configuration
@EnableCaching
public
class
MyCacheConfig
{
@Bean
public
CacheManager
cacheManager
()
{
SimpleCacheManager
cacheManager
=
new
SimpleCacheManager
();
cacheManager
.
setCaches
(
Collections
.
singletonList
(
new
ConcurrentMapCache
(
"tableInfos"
)));
return
cacheManager
;
}
}
src/main/java/com/tykj/workflowcore/model_layer/controller/ModelController.java
浏览文件 @
ef3ededa
...
@@ -11,6 +11,7 @@ import io.swagger.annotations.ApiOperation;
...
@@ -11,6 +11,7 @@ import io.swagger.annotations.ApiOperation;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Page
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
...
@@ -44,13 +45,13 @@ public class ModelController {
...
@@ -44,13 +45,13 @@ public class ModelController {
@ApiOperation
(
"得到所有数据表信息"
)
@ApiOperation
(
"得到所有数据表信息"
)
@PostMapping
(
"/getAllEntity"
)
@PostMapping
(
"/getAllEntity"
)
public
ResponseEntity
getAllEntity
(
@RequestBody
SearchTableInfoVo
searchTableInfoVo
)
{
public
ResponseEntity
getAllEntity
(
@RequestBody
SearchTableInfoVo
searchTableInfoVo
)
{
Page
<
TableInfo
>
tableInfos
=
null
;
Page
<
TableInfo
>
tableInfos
;
try
{
try
{
tableInfos
=
modelService
.
listAllEntities
(
searchTableInfoVo
);
tableInfos
=
modelService
.
listAllEntities
(
searchTableInfoVo
);
}
catch
(
SQLException
throwables
)
{
}
catch
(
SQLException
throwables
)
{
throwables
.
printStackTrace
();
return
ResultUtil
.
failed
(
"因为某些神秘原因,数据查询失败!"
);
}
}
return
ResultUtil
.
success
(
tableInfos
,
"数据查询成功!"
);
return
ResultUtil
.
success
(
tableInfos
,
"数据查询成功!"
);
}
}
...
@@ -99,8 +100,11 @@ public class ModelController {
...
@@ -99,8 +100,11 @@ public class ModelController {
@ApiOperation
(
value
=
"根据表名表插入数据"
)
@ApiOperation
(
value
=
"根据表名表插入数据"
)
@PostMapping
(
"/insertValues"
)
@PostMapping
(
"/insertValues"
)
public
ResponseEntity
insertValues
(
@RequestBody
Map
<
String
,
Object
>
map
)
{
public
ResponseEntity
insertValues
(
@RequestBody
Map
<
String
,
Object
>
map
)
{
modelService
.
putValueByEntityName
(
map
);
int
i
=
modelService
.
putValueByEntityName
(
map
);
return
ResultUtil
.
success
(
""
,
"数据插入成功"
);
if
(
i
==
0
){
return
ResultUtil
.
success
(
""
,
"数据插入成功!"
);
}
return
ResultUtil
.
success
(
""
,
"模型类型不支持插入数据!"
);
}
}
...
@@ -134,22 +138,27 @@ public class ModelController {
...
@@ -134,22 +138,27 @@ public class ModelController {
public
ResponseEntity
complexQuery
(
String
tableName
,
List
<
QueryCondition
>
queryConditions
)
{
public
ResponseEntity
complexQuery
(
String
tableName
,
List
<
QueryCondition
>
queryConditions
)
{
List
list
=
modelService
.
complexQuery
(
tableName
,
queryConditions
);
List
list
=
modelService
.
complexQuery
(
tableName
,
queryConditions
);
if
(
list
!=
null
)
{
if
(
list
!=
null
)
{
return
ResultUtil
.
success
(
list
,
"查询成功"
);
return
ResultUtil
.
success
(
list
,
"查询成功
!
"
);
}
}
return
ResultUtil
.
success
(
null
,
"没有数据"
);
return
ResultUtil
.
success
(
null
,
"没有数据
!
"
);
}
}
@ApiOperation
(
"编辑操作"
)
@ApiOperation
(
"编辑操作"
)
@PutMapping
(
"/update"
)
@PutMapping
(
"/update"
)
public
ResponseEntity
updateTable
(
@RequestBody
UpdateTableInfoVO
updateTableInfoVO
){
public
ResponseEntity
updateTable
(
@RequestBody
UpdateTableInfoVO
updateTableInfoVO
){
modelService
.
updateTable
(
updateTableInfoVO
);
int
i
=
modelService
.
updateTable
(
updateTableInfoVO
);
return
ResultUtil
.
success
(
""
,
"修改成功!"
);
if
(
i
==
1
){
return
ResultUtil
.
success
(
""
,
"修改成功!"
);
}
return
ResultUtil
.
success
(
"未找到该表信息或者业务类型不支持修改!"
);
}
}
@ApiOperation
(
"删除操作"
)
@ApiOperation
(
"删除操作"
)
@DeleteMapping
(
"/delete"
)
@DeleteMapping
(
"/delete"
)
public
ResponseEntity
delTable
(
DelTableVO
delTableVO
)
throws
SQLException
{
public
ResponseEntity
delTable
(
DelTableVO
delTableVO
)
{
modelService
.
delTable
(
delTableVO
);
return
ResultUtil
.
success
(
modelService
.
findAllByName
(
delTableVO
.
getDbName
()),
"删除成功!"
);
}
int
i
=
modelService
.
delTable
(
delTableVO
);
if
(
i
==
1
){
return
ResultUtil
.
success
(
""
,
"删除成功!"
);
}
return
ResultUtil
.
success
(
"未找到该id的表信息或者业务类型不支持删除!"
);
}
}
}
src/main/java/com/tykj/workflowcore/model_layer/service/ModelService.java
浏览文件 @
ef3ededa
...
@@ -4,10 +4,11 @@ package com.tykj.workflowcore.model_layer.service;
...
@@ -4,10 +4,11 @@ package com.tykj.workflowcore.model_layer.service;
import
com.tykj.workflowcore.model_layer.entity.ColumnInfo
;
import
com.tykj.workflowcore.model_layer.entity.ColumnInfo
;
import
com.tykj.workflowcore.model_layer.entity.TableInfo
;
import
com.tykj.workflowcore.model_layer.entity.TableInfo
;
import
com.tykj.workflowcore.model_layer.entity.vo.*
;
import
com.tykj.workflowcore.model_layer.entity.vo.*
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.CachePut
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Page
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -28,8 +29,10 @@ public interface ModelService {
...
@@ -28,8 +29,10 @@ public interface ModelService {
* @return
* @return
* @throws SQLException
* @throws SQLException
*/
*/
@Cacheable
(
cacheNames
=
"tableInfos"
,
key
=
"#searchTableInfoVo"
)
Page
<
TableInfo
>
listAllEntities
(
SearchTableInfoVo
searchTableInfoVo
)
throws
SQLException
;
Page
<
TableInfo
>
listAllEntities
(
SearchTableInfoVo
searchTableInfoVo
)
throws
SQLException
;
/**
/**
* 方法重载不分页查询
* 方法重载不分页查询
* @return
* @return
...
@@ -38,14 +41,17 @@ public interface ModelService {
...
@@ -38,14 +41,17 @@ public interface ModelService {
List
<
TableInfo
>
listAllEntities
()
throws
SQLException
;
List
<
TableInfo
>
listAllEntities
()
throws
SQLException
;
/**
/**
* 根据表名查询所有字段信息
* 根据表名查询所有字段信息
* @param searchColumnInfoVo
* @param searchColumnInfoVo
* @return
* @return
*/
*/
@Cacheable
(
cacheNames
=
"tableInfos"
,
key
=
"#searchColumnInfoVo"
)
List
<
ColumnInfo
>
showModelFields
(
SearchColumnInfoVo
searchColumnInfoVo
);
List
<
ColumnInfo
>
showModelFields
(
SearchColumnInfoVo
searchColumnInfoVo
);
/**
/**
* 新建模型
* 新建模型
* @param tableVO
* @param tableVO
...
@@ -88,14 +94,17 @@ public interface ModelService {
...
@@ -88,14 +94,17 @@ public interface ModelService {
* 更新表
* 更新表
* @param updateTableInfoVO
* @param updateTableInfoVO
*/
*/
void
updateTable
(
UpdateTableInfoVO
updateTableInfoVO
);
@CachePut
(
cacheNames
=
"tableInfos"
)
int
updateTable
(
UpdateTableInfoVO
updateTableInfoVO
);
/**
/**
* 删除表
* 删除表
* @param delTableVO
* @param delTableVO
* @return
*/
*/
void
delTable
(
DelTableVO
delTableVO
);
@CacheEvict
(
cacheNames
=
"tableInfos"
)
int
delTable
(
DelTableVO
delTableVO
);
}
}
src/main/java/com/tykj/workflowcore/model_layer/service/impl/ModelImpl.java
浏览文件 @
ef3ededa
...
@@ -2,6 +2,8 @@ package com.tykj.workflowcore.model_layer.service.impl;
...
@@ -2,6 +2,8 @@ package com.tykj.workflowcore.model_layer.service.impl;
import
com.github.wenhao.jpa.PredicateBuilder
;
import
com.github.wenhao.jpa.PredicateBuilder
;
import
com.github.wenhao.jpa.Specifications
;
import
com.github.wenhao.jpa.Specifications
;
import
com.tykj.workflowcore.base.result.ResultObj
;
import
com.tykj.workflowcore.base.result.ResultUtil
;
import
com.tykj.workflowcore.model_layer.annotations.WorkFlowCoreNoScan
;
import
com.tykj.workflowcore.model_layer.annotations.WorkFlowCoreNoScan
;
import
com.tykj.workflowcore.model_layer.dao.ColumnInfoDao
;
import
com.tykj.workflowcore.model_layer.dao.ColumnInfoDao
;
import
com.tykj.workflowcore.model_layer.dao.TableInfoDao
;
import
com.tykj.workflowcore.model_layer.dao.TableInfoDao
;
...
@@ -24,11 +26,13 @@ import org.hibernate.type.StringType;
...
@@ -24,11 +26,13 @@ import org.hibernate.type.StringType;
import
org.hibernate.type.TimestampType
;
import
org.hibernate.type.TimestampType
;
import
org.hibernate.type.Type
;
import
org.hibernate.type.Type
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.jpa.domain.Specification
;
import
org.springframework.data.jpa.domain.Specification
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.persistence.Entity
;
import
javax.persistence.Entity
;
import
javax.persistence.EntityManagerFactory
;
import
javax.persistence.EntityManagerFactory
;
...
@@ -37,6 +41,7 @@ import javax.persistence.EntityManagerFactory;
...
@@ -37,6 +41,7 @@ import javax.persistence.EntityManagerFactory;
import
javax.persistence.criteria.*
;
import
javax.persistence.criteria.*
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Field
;
import
java.sql.SQLException
;
import
java.text.ParseException
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.*
;
...
@@ -182,18 +187,24 @@ public class ModelImpl implements ModelService {
...
@@ -182,18 +187,24 @@ public class ModelImpl implements ModelService {
if
(
one
.
isPresent
())
{
if
(
one
.
isPresent
())
{
tableInfo
=
(
TableInfo
)
one
.
get
();
tableInfo
=
(
TableInfo
)
one
.
get
();
}
}
Integer
modelType
=
tableInfo
.
getModelType
();
Object
values
=
map
.
get
(
tableName
);
if
(
modelType
==
1
){
if
(
values
instanceof
Map
)
{
Object
values
=
map
.
get
(
tableName
);
//插入数据
if
(
values
instanceof
Map
)
{
insertValue
(
tableInfo
.
getModelName
(),
tableInfo
.
getXml
(),
(
Map
)
values
);
//插入数据
}
else
{
insertValue
(
tableInfo
.
getModelName
(),
tableInfo
.
getXml
(),
(
Map
)
values
);
//循环插入数据
}
else
{
List
valuesList
=
(
List
)
values
;
//循环插入数据
for
(
int
i
=
0
;
i
<
valuesList
.
size
();
i
++)
{
List
valuesList
=
(
List
)
values
;
insertValue
(
tableInfo
.
getModelName
(),
tableInfo
.
getXml
(),
(
Map
)
valuesList
.
get
(
i
));
for
(
int
i
=
0
;
i
<
valuesList
.
size
();
i
++)
{
insertValue
(
tableInfo
.
getModelName
(),
tableInfo
.
getXml
(),
(
Map
)
valuesList
.
get
(
i
));
}
}
}
}
}
else
{
return
1
;
}
}
}
return
0
;
return
0
;
}
}
...
@@ -238,7 +249,7 @@ public class ModelImpl implements ModelService {
...
@@ -238,7 +249,7 @@ public class ModelImpl implements ModelService {
map
.
put
(
propertyNames
[
i
],
value
);
map
.
put
(
propertyNames
[
i
],
value
);
}
}
}
}
newSession
.
save
(
tableName
,
map
);
newSession
.
save
(
tableName
,
map
);
newSession
.
getTransaction
().
begin
();
newSession
.
getTransaction
().
begin
();
newSession
.
getTransaction
().
commit
();
newSession
.
getTransaction
().
commit
();
newSession
.
close
();
newSession
.
close
();
...
@@ -246,6 +257,7 @@ public class ModelImpl implements ModelService {
...
@@ -246,6 +257,7 @@ public class ModelImpl implements ModelService {
/**
/**
* 扫描表
* 扫描表
*
* @param classList
* @param classList
*/
*/
@Override
@Override
...
@@ -346,7 +358,7 @@ public class ModelImpl implements ModelService {
...
@@ -346,7 +358,7 @@ public class ModelImpl implements ModelService {
* @Date 10:50 2021/3/11
* @Date 10:50 2021/3/11
**/
**/
public
boolean
checkRepeat
(
String
tableName
)
{
public
boolean
checkRepeat
(
String
tableName
)
{
Specification
spec
=
(
Specification
)
(
root
,
criteriaQuery
,
criteriaBuilder
)
->
{
Specification
spec
=
(
root
,
criteriaQuery
,
criteriaBuilder
)
->
{
Path
name
=
root
.
get
(
"modelName"
);
Path
name
=
root
.
get
(
"modelName"
);
Predicate
equal
=
criteriaBuilder
.
equal
(
name
,
tableName
);
Predicate
equal
=
criteriaBuilder
.
equal
(
name
,
tableName
);
return
equal
;
return
equal
;
...
@@ -390,59 +402,64 @@ public class ModelImpl implements ModelService {
...
@@ -390,59 +402,64 @@ public class ModelImpl implements ModelService {
@Override
@Override
public
List
<
TableInfo
>
listAllEntities
()
{
public
List
<
TableInfo
>
listAllEntities
()
{
System
.
out
.
println
(
"从数据库中取出的!"
);
return
tableInfoDao
.
findAll
();
return
tableInfoDao
.
findAll
();
}
}
@Override
@Override
public
void
updateTable
(
UpdateTableInfoVO
updateTableInfoVO
)
{
public
int
updateTable
(
UpdateTableInfoVO
updateTableInfoVO
)
{
//tableInfo和columnInfo变化
//tableInfo和columnInfo变化
//查询到TableInfo和ColumnInfo
//查询到TableInfo和ColumnInfo
TableVO
tableVO
=
updateTableInfoVO
.
getTableVO
();
TableVO
tableVO
=
updateTableInfoVO
.
getTableVO
();
Integer
dbId
=
updateTableInfoVO
.
getDbId
();
Integer
dbId
=
updateTableInfoVO
.
getDbId
();
TableInfo
tableInfo
=
tableInfoDao
.
findById
(
dbId
).
orElseThrow
(()
->
new
RuntimeException
(
"未找到该id的表信息"
));
TableInfo
tableInfo
=
tableInfoDao
.
findById
(
dbId
).
orElseThrow
(()
->
new
RuntimeException
(
"未找到该id的表信息"
));
tableInfo
.
setUpdatedTime
(
new
Date
());
Integer
modelType
=
tableInfo
.
getModelType
();
if
(
modelType
==
1
){
tableInfo
.
setDescription
(
tableVO
.
getDescription
());
tableInfo
.
setUpdatedTime
(
new
Date
());
tableInfo
.
setModelTitle
(
tableVO
.
getModelTitle
());
tableInfo
.
setModelType
(
tableVO
.
getModelType
());
tableInfo
.
setDescription
(
tableVO
.
getDescription
());
String
xml
=
createTable
(
tableVO
);
tableInfo
.
setModelTitle
(
tableVO
.
getModelTitle
());
//重新存xml
tableInfo
.
setModelType
(
tableVO
.
getModelType
());
tableInfo
.
setXml
(
xml
);
String
xml
=
createTable
(
tableVO
);
tableInfoDao
.
save
(
tableInfo
);
//重新存xml
tableInfo
.
setXml
(
xml
);
tableInfoDao
.
save
(
tableInfo
);
//原来的字段信息
Specification
spec
=
(
Specification
)
(
root
,
criteriaQuery
,
criteriaBuilder
)
->
{
Predicate
predicate
=
criteriaBuilder
.
equal
(
root
.
get
(
"dbId"
),
dbId
);
return
predicate
;
};
List
<
ColumnInfo
>
originalColumnInfos
=
columnInfoDao
.
findAll
(
spec
);
//新的字段信息
List
<
ColumnInfo
>
currentColumnInfos
=
tableVO
.
getDataList
().
stream
()
.
map
(
columnVO
->
columnInfo
(
tableInfo
.
getId
(),
tableInfo
.
getModelName
(),
columnVO
))
.
collect
(
Collectors
.
toList
());
//根据ColumnInfo集合得出表实际改动的sql语句集合
List
<
String
>
sqls
=
getTableSqls
(
tableInfo
.
getModelName
(),
originalColumnInfos
,
currentColumnInfos
);
//执行sql语句
for
(
String
sql
:
sqls
)
{
System
.
out
.
println
(
sql
);
jdbcTemplate
.
execute
(
sql
);
}
//原来的字段信息
//重新保存字段信息
Specification
spec
=
(
Specification
)
(
root
,
criteriaQuery
,
criteriaBuilder
)
->
{
List
<
ColumnInfo
>
columnsForAdd
=
getColumnsForAdd
(
originalColumnInfos
,
currentColumnInfos
);
Predicate
predicate
=
criteriaBuilder
.
equal
(
root
.
get
(
"dbId"
),
dbId
);
for
(
ColumnInfo
columnInfo
:
columnsForAdd
)
{
return
predicate
;
columnInfoDao
.
save
(
columnInfo
);
};
}
List
<
ColumnInfo
>
originalColumnInfos
=
columnInfoDao
.
findAll
(
spec
);
List
<
ColumnInfo
>
columnsForUpdate
=
getColumnsForUpdate
(
originalColumnInfos
,
currentColumnInfos
);
//新的字段信息
for
(
ColumnInfo
columnInfo
:
columnsForUpdate
)
{
List
<
ColumnInfo
>
currentColumnInfos
=
tableVO
.
getDataList
().
stream
()
columnInfoDao
.
save
(
columnInfo
);
.
map
(
columnVO
->
columnInfo
(
tableInfo
.
getId
(),
tableInfo
.
getModelName
(),
columnVO
))
}
.
collect
(
Collectors
.
toList
());
List
<
ColumnInfo
>
columnsFordDelete
=
getColumnsFordDelete
(
originalColumnInfos
,
currentColumnInfos
);
for
(
ColumnInfo
originColumnInfo
:
columnsFordDelete
)
{
//根据ColumnInfo集合得出表实际改动的sql语句集合
columnInfoDao
.
delete
(
originColumnInfo
);
List
<
String
>
sqls
=
getTableSqls
(
tableInfo
.
getModelName
(),
originalColumnInfos
,
currentColumnInfos
);
//执行sql语句
for
(
String
sql
:
sqls
)
{
System
.
out
.
println
(
sql
);
jdbcTemplate
.
execute
(
sql
);
}
}
//重新保存字段信息
List
<
ColumnInfo
>
columnsForAdd
=
getColumnsForAdd
(
originalColumnInfos
,
currentColumnInfos
);
for
(
ColumnInfo
columnInfo
:
columnsForAdd
)
{
columnInfoDao
.
save
(
columnInfo
);
}
List
<
ColumnInfo
>
columnsForUpdate
=
getColumnsForUpdate
(
originalColumnInfos
,
currentColumnInfos
);
for
(
ColumnInfo
columnInfo
:
columnsForUpdate
)
{
columnInfoDao
.
save
(
columnInfo
);
}
List
<
ColumnInfo
>
columnsFordDelete
=
getColumnsFordDelete
(
originalColumnInfos
,
currentColumnInfos
);
for
(
ColumnInfo
originColumnInfo
:
columnsFordDelete
)
{
columnInfoDao
.
delete
(
originColumnInfo
);
}
}
return
1
;
}
}
/**
/**
...
@@ -534,20 +551,25 @@ public class ModelImpl implements ModelService {
...
@@ -534,20 +551,25 @@ public class ModelImpl implements ModelService {
}
}
@Override
@Override
public
void
delTable
(
DelTableVO
delTableVO
)
{
public
int
delTable
(
DelTableVO
delTableVO
)
{
if
(
StringUtils
.
isNotEmpty
(
delTableVO
.
getDbName
()))
{
if
(
StringUtils
.
isNotEmpty
(
delTableVO
.
getDbName
()))
{
Optional
<
TableInfo
>
byId
=
tableInfoDao
.
findById
(
delTableVO
.
getId
());
Optional
<
TableInfo
>
byId
=
tableInfoDao
.
findById
(
delTableVO
.
getId
());
if
(
byId
.
isPresent
())
{
if
(
byId
.
isPresent
())
{
tableInfoDao
.
delete
(
byId
.
get
());
TableInfo
tableInfo
=
byId
.
get
();
List
<
ColumnInfo
>
allByDbId
=
columnInfoDao
.
findAllByDbId
(
delTableVO
.
getId
());
Integer
modelType
=
tableInfo
.
getModelType
();
columnInfoDao
.
deleteInBatch
(
allByDbId
);
if
(
modelType
==
1
)
{
tableInfoDao
.
delete
(
tableInfo
);
List
<
ColumnInfo
>
allByDbId
=
columnInfoDao
.
findAllByDbId
(
delTableVO
.
getId
());
columnInfoDao
.
deleteInBatch
(
allByDbId
);
jdbcTemplate
.
execute
(
"drop table "
+
delTableVO
.
getDbName
());
return
1
;
}
jdbcTemplate
.
execute
(
"truncate table "
+
delTableVO
.
getDbName
());
}
else
{
new
RuntimeException
(
"未找到该id的表信息"
);
}
}
}
}
return
0
;
}
}
}
}
src/main/test/java/com/tykj/workflowcore/WorkflowCoreApplicationTests.java
浏览文件 @
ef3ededa
...
@@ -3,7 +3,7 @@ package com.tykj.workflowcore;
...
@@ -3,7 +3,7 @@ package com.tykj.workflowcore;
import
com.tykj.workflowcore.model_layer.controller.ModelController
;
import
com.tykj.workflowcore.model_layer.controller.ModelController
;
import
com.tykj.workflowcore.model_layer.dao.TableInfoDao
;
import
com.tykj.workflowcore.model_layer.dao.TableInfoDao
;
import
com.tykj.workflowcore.model_layer.
entity.TableInfo
;
import
com.tykj.workflowcore.model_layer.
service.ModelService
;
import
org.aspectj.lang.annotation.Before
;
import
org.aspectj.lang.annotation.Before
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -17,6 +17,7 @@ import org.springframework.test.web.servlet.RequestBuilder;
...
@@ -17,6 +17,7 @@ import org.springframework.test.web.servlet.RequestBuilder;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.Optional
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
...
@@ -42,6 +43,9 @@ class WorkflowCoreApplicationTests {
...
@@ -42,6 +43,9 @@ class WorkflowCoreApplicationTests {
@Autowired
@Autowired
MockMvc
mockMvc
;
MockMvc
mockMvc
;
@Autowired
ModelService
modelService
;
@Before
(
""
)
@Before
(
""
)
public
void
setUp
()
{
public
void
setUp
()
{
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
modelController
).
build
();
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
modelController
).
build
();
...
@@ -56,11 +60,15 @@ class WorkflowCoreApplicationTests {
...
@@ -56,11 +60,15 @@ class WorkflowCoreApplicationTests {
RequestBuilder
request
;
RequestBuilder
request
;
/**
* 测试表的条件查询
* @throws Exception
*/
@Test
@Test
public
void
SearchTableVOTest
()
throws
Exception
{
public
void
SearchTableVOTest
()
throws
Exception
{
String
SearchTableinfo_Json
=
"{\n"
+
String
SearchTableinfo_Json
=
"{\n"
+
" \"modelName\":\"
peop
\",\n"
+
" \"modelName\":\"\",\n"
+
" \"modelTitle\":\"\",\n"
+
" \"modelTitle\":\"\",\n"
+
" \"modelType\":\"\"\n"
+
" \"modelType\":\"\"\n"
+
"}"
;
"}"
;
...
@@ -76,6 +84,10 @@ class WorkflowCoreApplicationTests {
...
@@ -76,6 +84,10 @@ class WorkflowCoreApplicationTests {
}
}
/**
* 测试列条件查询
* @throws Exception
*/
@Test
@Test
public
void
testSearchColumnVO
()
throws
Exception
{
public
void
testSearchColumnVO
()
throws
Exception
{
...
@@ -84,7 +96,7 @@ class WorkflowCoreApplicationTests {
...
@@ -84,7 +96,7 @@ class WorkflowCoreApplicationTests {
"}"
;
"}"
;
String
searchColumnV0_json2
=
"{\n"
+
String
searchColumnV0_json2
=
"{\n"
+
"\"dbName\":\"
tech
er\"\n"
+
"\"dbName\":\"
sy_ord
er\"\n"
+
"}"
;
"}"
;
request
=
post
(
"/model/getAllField/"
)
request
=
post
(
"/model/getAllField/"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
...
@@ -98,6 +110,10 @@ class WorkflowCoreApplicationTests {
...
@@ -98,6 +110,10 @@ class WorkflowCoreApplicationTests {
.
andDo
(
print
());
//打印输出结果
.
andDo
(
print
());
//打印输出结果
}
}
/**
* 测试新增对象
* @throws Exception
*/
@Test
@Test
public
void
addModelTest
()
throws
Exception
{
public
void
addModelTest
()
throws
Exception
{
...
@@ -125,8 +141,12 @@ class WorkflowCoreApplicationTests {
...
@@ -125,8 +141,12 @@ class WorkflowCoreApplicationTests {
.
andDo
(
print
());
//打印输出结果
.
andDo
(
print
());
//打印输出结果
}
}
/**
* 测试插入数据
* @throws Exception
*/
@Test
@Test
public
void
inserValuesByTableName
()
throws
Exception
{
public
void
inser
t
ValuesByTableName
()
throws
Exception
{
String
values_json
=
"{\"techer\":{\"name\": \"zhangsan\",\"age\" :\"20\"}}"
;
String
values_json
=
"{\"techer\":{\"name\": \"zhangsan\",\"age\" :\"20\"}}"
;
request
=
post
(
"/model/insertValues/"
)
request
=
post
(
"/model/insertValues/"
)
...
@@ -142,8 +162,12 @@ class WorkflowCoreApplicationTests {
...
@@ -142,8 +162,12 @@ class WorkflowCoreApplicationTests {
.
andDo
(
print
());
//打印输出结果
.
andDo
(
print
());
//打印输出结果
}
}
/**
* 测试查询全部
* @throws Exception
*/
@Test
@Test
public
void
findAll
b
yTableName
()
throws
Exception
{
public
void
findAll
B
yTableName
()
throws
Exception
{
request
=
get
(
"/model/getAll/"
)
request
=
get
(
"/model/getAll/"
)
.
param
(
"tableName"
,
"techer"
)
.
param
(
"tableName"
,
"techer"
)
.
accept
(
MediaType
.
APPLICATION_JSON_UTF8_VALUE
);
.
accept
(
MediaType
.
APPLICATION_JSON_UTF8_VALUE
);
...
@@ -156,15 +180,21 @@ class WorkflowCoreApplicationTests {
...
@@ -156,15 +180,21 @@ class WorkflowCoreApplicationTests {
}
}
/**
* 测试删除表
*/
@Test
@Test
public
void
testDelTable
(){
public
void
testDelTable
()
throws
Exception
{
// jdbcTemplate.execute("drop table if exists test"); ok
String
delete_JSON
=
"{\n"
+
Optional
<
TableInfo
>
byId
=
tableInfoDao
.
findById
(
12
);
"\"dbName\":\"testentity\"\n"
+
if
(
byId
.
isPresent
()){
"}"
;
TableInfo
tableInfo
=
byId
.
get
();
request
=
delete
(
"/model/delete/"
)
System
.
out
.
println
(
tableInfo
);
.
contentType
(
MediaType
.
APPLICATION_JSON
)
tableInfoDao
.
delete
(
tableInfo
);
.
content
(
delete_JSON
)
}
.
accept
(
MediaType
.
APPLICATION_JSON_UTF8_VALUE
);
mockMvc
.
perform
(
request
)
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
string
(
not
(
""
)))
.
andDo
(
print
());
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论