Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
workflow
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
2
议题
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄夏豪
workflow
Commits
4bc4738e
提交
4bc4738e
authored
3月 29, 2021
作者:
ww1xhqc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[数据模型] 新增了批量查询的方法,修改了缓存配置
上级
90346b4f
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
124 行增加
和
16 行删除
+124
-16
pom.xml
pom.xml
+10
-2
MyCacheConfig.java
...m/tykj/workflowcore/model_layer/config/MyCacheConfig.java
+43
-3
ModelController.java
.../workflowcore/model_layer/controller/ModelController.java
+4
-5
TableAndColumnInfoVO.java
...kflowcore/model_layer/entity/vo/TableAndColumnInfoVO.java
+22
-0
ModelService.java
...m/tykj/workflowcore/model_layer/service/ModelService.java
+8
-0
ModelImpl.java
...tykj/workflowcore/model_layer/service/impl/ModelImpl.java
+16
-0
WorkflowCoreApplicationTests.java
...a/com/tykj/workflowcore/WorkflowCoreApplicationTests.java
+21
-6
没有找到文件。
pom.xml
浏览文件 @
4bc4738e
...
...
@@ -105,8 +105,16 @@
<artifactId>
junit
</artifactId>
<scope>
test
</scope>
</dependency>
<!-- caffeine缓存 -->
<dependency>
<groupId>
com.github.ben-manes.caffeine
</groupId>
<artifactId>
caffeine
</artifactId>
<version>
2.7.0
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-cache
</artifactId>
</dependency>
</dependencies>
<build>
...
...
src/main/java/com/tykj/workflowcore/model_layer/config/MyCacheConfig.java
浏览文件 @
4bc4738e
package
com
.
tykj
.
workflowcore
.
model_layer
.
config
;
import
com.github.benmanes.caffeine.cache.CacheLoader
;
import
com.github.benmanes.caffeine.cache.Caffeine
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.cache.caffeine.CaffeineCacheManager
;
import
org.springframework.cache.concurrent.ConcurrentMapCache
;
import
org.springframework.cache.support.SimpleCacheManager
;
import
org.springframework.context.annotation.Bean
;
...
...
@@ -10,6 +13,7 @@ import org.springframework.context.annotation.Configuration;
import
java.util.Collections
;
import
java.util.concurrent.TimeUnit
;
/**
...
...
@@ -23,9 +27,45 @@ import java.util.Collections;
public
class
MyCacheConfig
{
@Bean
public
CacheManager
cacheManager
()
{
SimpleCacheManager
cacheManager
=
new
SimpleCacheManager
();
cacheManager
.
setCaches
(
Collections
.
singletonList
(
new
ConcurrentMapCache
(
"tableInfos"
)));
public
CaffeineCacheManager
cacheManager
()
{
//api + cache spring cache + hashmap
//mycode + redis
//spring cache + caffeine
// SimpleCacheManager cacheManager = new SimpleCacheManager();
CaffeineCacheManager
cacheManager
=
new
CaffeineCacheManager
();
Caffeine
caffeine
=
Caffeine
.
newBuilder
()
//cache的初始容量值
.
initialCapacity
(
100
)
//maximumSize用来控制cache的最大缓存数量,maximumSize和maximumWeight(最大权重)不可以同时使用,
.
maximumSize
(
1000
)
//最后一次写入或者访问后过久过期
.
expireAfterAccess
(
500
,
TimeUnit
.
SECONDS
)
//创建或更新之后多久刷新,需要设置cacheLoader
.
refreshAfterWrite
(
10
,
TimeUnit
.
SECONDS
);
cacheManager
.
setCaffeine
(
caffeine
);
cacheManager
.
setCacheLoader
(
cacheLoader
());
// cacheManager.setCacheNames();//根据名字可以创建多个cache,但是多个cache使用相同的策略
cacheManager
.
setAllowNullValues
(
false
);
//是否允许值为空
// cacheManager.setCaches(Collections.singletonList(new ConcurrentMapCache("tableInfos")));
return
cacheManager
;
}
@Bean
public
CacheLoader
<
Object
,
Object
>
cacheLoader
()
{
return
new
CacheLoader
<
Object
,
Object
>()
{
@Override
public
Object
load
(
Object
key
)
throws
Exception
{
return
null
;
}
// 重写这个方法将oldValue值返回回去,进而刷新缓存
@Override
public
Object
reload
(
Object
key
,
Object
oldValue
)
throws
Exception
{
System
.
out
.
println
(
"--refresh--:"
+
key
);
return
oldValue
;
}
};
}
}
src/main/java/com/tykj/workflowcore/model_layer/controller/ModelController.java
浏览文件 @
4bc4738e
...
...
@@ -11,7 +11,6 @@ import io.swagger.annotations.ApiOperation;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -85,7 +84,7 @@ public class ModelController {
}
}
modelService
.
newTable
(
tableVO
);
return
ResultUtil
.
success
(
""
,
"新建成功"
);
return
ResultUtil
.
success
(
""
,
"新建成功
!
"
);
}
...
...
@@ -123,7 +122,7 @@ public class ModelController {
}
catch
(
SQLException
throwables
)
{
throwables
.
printStackTrace
();
}
return
ResultUtil
.
success
(
null
,
"获取失败"
);
return
ResultUtil
.
success
(
null
,
"获取失败
!
"
);
}
/**
* @param tableName
...
...
@@ -149,7 +148,7 @@ public class ModelController {
if
(
i
==
1
){
return
ResultUtil
.
success
(
""
,
"修改成功!"
);
}
return
ResultUtil
.
success
(
"
未找到该表信息或者
业务类型不支持修改!"
);
return
ResultUtil
.
success
(
"业务类型不支持修改!"
);
}
@ApiOperation
(
"删除操作"
)
@DeleteMapping
(
"/delete"
)
...
...
@@ -159,6 +158,6 @@ public class ModelController {
if
(
i
==
1
){
return
ResultUtil
.
success
(
""
,
"删除成功!"
);
}
return
ResultUtil
.
success
(
"
未找到该id的表信息或者
业务类型不支持删除!"
);
return
ResultUtil
.
success
(
"业务类型不支持删除!"
);
}
}
src/main/java/com/tykj/workflowcore/model_layer/entity/vo/TableAndColumnInfoVO.java
0 → 100644
浏览文件 @
4bc4738e
package
com
.
tykj
.
workflowcore
.
model_layer
.
entity
.
vo
;
import
com.tykj.workflowcore.model_layer.entity.ColumnInfo
;
import
com.tykj.workflowcore.model_layer.entity.TableInfo
;
import
lombok.Data
;
import
java.util.List
;
/**
* @ClassName TableAndColumnInfoVO
* @Description TODO
* @Author WWW
* @Date 2021/3/29 9:59
* @Version 1.0
*/
@Data
public
class
TableAndColumnInfoVO
{
private
List
<
TableInfo
>
tableInfos
;
private
List
<
ColumnInfo
>
columnInfos
;
}
src/main/java/com/tykj/workflowcore/model_layer/service/ModelService.java
浏览文件 @
4bc4738e
...
...
@@ -108,4 +108,12 @@ public interface ModelService {
int
delTable
(
DelTableVO
delTableVO
);
/**
* 根据id批量查询所有tableInfo和ColumnInfo
* @param ids
* @return
*/
TableAndColumnInfoVO
getTableInfoAndColumnInfoByBatch
(
Integer
[]
ids
);
}
src/main/java/com/tykj/workflowcore/model_layer/service/impl/ModelImpl.java
浏览文件 @
4bc4738e
...
...
@@ -571,4 +571,20 @@ public class ModelImpl implements ModelService {
return
0
;
}
@Override
public
TableAndColumnInfoVO
getTableInfoAndColumnInfoByBatch
(
Integer
[]
ids
)
{
TableAndColumnInfoVO
tableAndColumnInfoVO
=
new
TableAndColumnInfoVO
();
PredicateBuilder
<
TableInfo
>
builder1
=
Specifications
.
and
();
builder1
.
in
(
ids
!=
null
,
"id"
,
ids
);
List
<
TableInfo
>
allTableInfos
=
tableInfoDao
.
findAll
(
builder1
.
build
());
PredicateBuilder
<
ColumnInfo
>
builder2
=
Specifications
.
and
();
builder2
.
in
(
ids
!=
null
,
"dbId"
,
ids
);
List
<
ColumnInfo
>
allColumnInfos
=
columnInfoDao
.
findAll
(
builder2
.
build
());
tableAndColumnInfoVO
.
setTableInfos
(
allTableInfos
);
tableAndColumnInfoVO
.
setColumnInfos
(
allColumnInfos
);
return
tableAndColumnInfoVO
;
}
}
src/main/test/java/com/tykj/workflowcore/WorkflowCoreApplicationTests.java
浏览文件 @
4bc4738e
...
...
@@ -3,6 +3,7 @@ package com.tykj.workflowcore;
import
com.tykj.workflowcore.model_layer.controller.ModelController
;
import
com.tykj.workflowcore.model_layer.dao.TableInfoDao
;
import
com.tykj.workflowcore.model_layer.entity.vo.TableAndColumnInfoVO
;
import
com.tykj.workflowcore.model_layer.myEnum.ModelType
;
import
com.tykj.workflowcore.model_layer.service.ModelService
;
import
org.aspectj.lang.annotation.Before
;
...
...
@@ -63,6 +64,7 @@ class WorkflowCoreApplicationTests {
/**
* 测试表的条件查询
*
* @throws Exception
*/
@Test
...
...
@@ -87,6 +89,7 @@ class WorkflowCoreApplicationTests {
/**
* 测试列条件查询
*
* @throws Exception
*/
@Test
...
...
@@ -113,6 +116,7 @@ class WorkflowCoreApplicationTests {
/**
* 测试新增对象
*
* @throws Exception
*/
@Test
...
...
@@ -144,11 +148,12 @@ class WorkflowCoreApplicationTests {
/**
* 测试插入数据
*
* @throws Exception
*/
@Test
public
void
insertValuesByTableName
()
throws
Exception
{
String
values_json
=
"{\"techer\":{\"name\": \"zhangsan\",\"age\" :\"20\"}}"
;
public
void
insertValuesByTableName
()
throws
Exception
{
String
values_json
=
"{\"techer\":{\"name\": \"zhangsan\",\"age\" :\"20\"}}"
;
request
=
post
(
"/model/insertValues/"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
...
...
@@ -165,12 +170,13 @@ class WorkflowCoreApplicationTests {
/**
* 测试查询全部
*
* @throws Exception
*/
@Test
public
void
findAllByTableName
()
throws
Exception
{
request
=
get
(
"/model/getAll/"
)
.
param
(
"tableName"
,
"techer"
)
request
=
get
(
"/model/getAll/"
)
.
param
(
"tableName"
,
"techer"
)
.
accept
(
MediaType
.
APPLICATION_JSON_UTF8_VALUE
);
mockMvc
.
perform
(
request
)
...
...
@@ -186,10 +192,10 @@ class WorkflowCoreApplicationTests {
*/
@Test
public
void
testDelTable
()
throws
Exception
{
String
delete_JSON
=
"{\n"
+
String
delete_JSON
=
"{\n"
+
"\"dbName\":\"testentity\"\n"
+
"}"
;
request
=
delete
(
"/model/delete/"
)
request
=
delete
(
"/model/delete/"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
delete_JSON
)
.
accept
(
MediaType
.
APPLICATION_JSON_UTF8_VALUE
);
...
...
@@ -198,4 +204,13 @@ class WorkflowCoreApplicationTests {
.
andExpect
(
content
().
string
(
not
(
""
)))
.
andDo
(
print
());
}
@Test
public
void
testAll
()
{
Integer
[]
ids
=
{
2
,
3
,
22
};
TableAndColumnInfoVO
all
=
modelService
.
getTableInfoAndColumnInfoByBatch
(
ids
);
System
.
out
.
println
(
all
);
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论