Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
D
dataDeclaration
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄夏豪
dataDeclaration
Commits
944ce68f
提交
944ce68f
authored
5月 18, 2021
作者:
ww1xhqc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[数据模型] 新增自定义SQL语句查询接口
上级
f3b18506
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
53 行增加
和
13 行删除
+53
-13
WebMvcConfig.java
src/main/java/com/tykj/base/config/WebMvcConfig.java
+1
-1
ModelController.java
...java/com/tykj/model_layer/controller/ModelController.java
+12
-0
ModelService.java
src/main/java/com/tykj/model_layer/service/ModelService.java
+1
-1
QuoteService.java
src/main/java/com/tykj/model_layer/service/QuoteService.java
+5
-1
ModelImpl.java
...ain/java/com/tykj/model_layer/service/impl/ModelImpl.java
+14
-6
QuoteServiceImpl.java
...a/com/tykj/model_layer/service/impl/QuoteServiceImpl.java
+15
-2
SessionUtil.java
src/main/java/com/tykj/model_layer/utils/SessionUtil.java
+5
-2
没有找到文件。
src/main/java/com/tykj/base/config/WebMvcConfig.java
浏览文件 @
944ce68f
...
...
@@ -55,7 +55,7 @@ public class WebMvcConfig {
private
ApiInfo
apiInfo
()
{
return
new
ApiInfoBuilder
()
.
title
(
"excel->
操作
表"
)
.
title
(
"excel->表"
)
.
description
(
"excel 转化的实体类"
)
.
version
(
"1.0"
)
.
build
();
...
...
src/main/java/com/tykj/model_layer/controller/ModelController.java
浏览文件 @
944ce68f
...
...
@@ -178,4 +178,16 @@ public class ModelController {
"获得example成功!"
);
}
@ApiOperation
(
"自定义SQL查询"
)
@PostMapping
(
"/sql"
)
public
ResponseEntity
executeSql
(
String
sql
){
try
{
return
ResultUtil
.
success
(
modelService
.
executeQuery
(
sql
),
"查询成功!"
);
}
catch
(
SQLException
throwables
)
{
throwables
.
printStackTrace
();
}
return
ResultUtil
.
failed
(
"SQL错误,查询失败!"
);
}
}
src/main/java/com/tykj/model_layer/service/ModelService.java
浏览文件 @
944ce68f
...
...
@@ -104,5 +104,5 @@ public interface ModelService {
*/
TableAndColumnInfoVO
getTableInfoAndColumnInfoByBatch
(
Integer
[]
ids
);
List
<
Map
<
String
,
Object
>>
executeQuery
(
String
sql
)
throws
SQLException
;
}
src/main/java/com/tykj/model_layer/service/QuoteService.java
浏览文件 @
944ce68f
...
...
@@ -17,6 +17,10 @@ public interface QuoteService {
*/
void
updateQuote
(
Integer
id
);
List
<
Quote
>
getAll
();
List
<
Quote
>
getAllQuote
();
Quote
saveQuote
(
Quote
quote
);
void
delQuote
(
Integer
id
);
}
src/main/java/com/tykj/model_layer/service/impl/ModelImpl.java
浏览文件 @
944ce68f
...
...
@@ -36,7 +36,6 @@ import org.springframework.jdbc.core.JdbcTemplate;
import
org.springframework.stereotype.Service
;
import
javax.persistence.criteria.Path
;
import
javax.persistence.criteria.Predicate
;
import
java.lang.reflect.Field
;
...
...
@@ -119,7 +118,7 @@ public class ModelImpl implements ModelService {
* @Date 16:15 2021/3/5
**/
@Override
public
List
<
ColumnInfo
>
showModelFields
(
SearchColumnInfoVo
searchColumnInfoVo
)
{
public
List
<
ColumnInfo
>
showModelFields
(
SearchColumnInfoVo
searchColumnInfoVo
)
{
PredicateBuilder
<
ColumnInfo
>
and
=
Specifications
.
and
();
and
.
eq
(
searchColumnInfoVo
.
getDbId
()
!=
null
,
"dbId"
,
searchColumnInfoVo
.
getDbId
());
and
.
eq
(
searchColumnInfoVo
.
getDbName
()
!=
null
&&
StringUtils
.
isNotEmpty
(
searchColumnInfoVo
.
getDbName
()),
"dbName"
,
searchColumnInfoVo
.
getDbName
());
...
...
@@ -154,7 +153,7 @@ public class ModelImpl implements ModelService {
.
stream
()
.
map
(
TableInfo:
:
getModelName
)
.
collect
(
Collectors
.
toList
());
if
(
collect
.
contains
(
tableVO
.
getModelName
())){
if
(
collect
.
contains
(
tableVO
.
getModelName
()))
{
throw
new
ApiException
(
"表名已经存在!"
);
}
TableInfo
tableInfo
=
new
TableInfo
();
...
...
@@ -166,7 +165,7 @@ public class ModelImpl implements ModelService {
tableInfo
.
setParentTable
(
parentTable
);
tableInfoDao
.
save
(
tableInfo
);
//默认存储ID字段
if
(
tableInfo
.
getModelType
().
equals
(
ModelType
.
VIRTUAL
)){
if
(
tableInfo
.
getModelType
().
equals
(
ModelType
.
VIRTUAL
))
{
ColumnInfo
cId
=
new
ColumnInfo
(
0
,
"id"
,
"主键"
,
"java.lang.Integer"
,
11
,
tableInfo
.
getModelName
(),
tableInfo
.
getId
(),
"主键"
);
columnInfoDao
.
save
(
cId
);
}
...
...
@@ -281,7 +280,6 @@ public class ModelImpl implements ModelService {
}
/**
* @param tableName
* @return boolean
...
...
@@ -297,7 +295,7 @@ public class ModelImpl implements ModelService {
};
List
<
TableInfo
>
all
=
tableInfoDao
.
findAll
(
spec
);
if
(
all
!=
null
&&
all
.
size
()>
0
)
{
if
(
all
!=
null
&&
all
.
size
()
>
0
)
{
return
all
.
get
(
0
);
}
return
null
;
...
...
@@ -544,4 +542,14 @@ public class ModelImpl implements ModelService {
}
}
@Override
public
List
<
Map
<
String
,
Object
>>
executeQuery
(
String
sql
)
{
try
{
return
jdbcTemplate
.
queryForList
(
sql
);
}
catch
(
ApiException
e
)
{
throw
new
ApiException
(
"sql语法错误!"
);
}
}
}
src/main/java/com/tykj/model_layer/service/impl/QuoteServiceImpl.java
浏览文件 @
944ce68f
package
com
.
tykj
.
model_layer
.
service
.
impl
;
import
com.tykj.base.result.ApiException
;
import
com.tykj.model_layer.dao.QuoteDao
;
import
com.tykj.model_layer.entity.Quote
;
import
com.tykj.model_layer.service.QuoteService
;
...
...
@@ -25,11 +26,23 @@ public class QuoteServiceImpl implements QuoteService {
}
@Override
public
List
<
Quote
>
getAll
()
{
public
List
<
Quote
>
getAll
Quote
()
{
return
quoteDao
.
findAll
();
}
public
boolean
existValue
(
Integer
cId
,
String
value
){
@Override
public
Quote
saveQuote
(
Quote
quote
)
{
return
quoteDao
.
save
(
quote
);
}
@Override
public
void
delQuote
(
Integer
id
)
{
quoteDao
.
deleteById
(
id
);
}
public
boolean
existValue
(
Integer
cId
,
String
value
){
List
<
String
>
collect
=
quoteDao
.
findAllByColumnId
(
cId
)
.
stream
()
.
map
(
Quote:
:
getValue
)
...
...
src/main/java/com/tykj/model_layer/utils/SessionUtil.java
浏览文件 @
944ce68f
...
...
@@ -9,11 +9,14 @@ import org.hibernate.SessionFactory;
import
org.hibernate.boot.Metadata
;
import
org.hibernate.boot.MetadataSources
;
import
org.hibernate.boot.registry.StandardServiceRegistry
;
import
org.hibernate.tool.hbm2ddl.SchemaUpdate
;
import
org.hibernate.tool.schema.TargetType
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
javax.persistence.EntityManagerFactory
;
import
java.io.ByteArrayInputStream
;
import
java.util.EnumSet
;
import
java.util.List
;
/**
...
...
@@ -59,8 +62,8 @@ public class SessionUtil {
metadataSources
.
addInputStream
(
new
ByteArrayInputStream
(
xmlStr
.
getBytes
()));
Metadata
metadata
=
metadataSources
.
buildMetadata
();
//更新数据库Schema,如果不存在就创建表,存在就更新字段,不会影响已有数据
//
SchemaUpdate schemaUpdate = new SchemaUpdate();
//
schemaUpdate.execute(EnumSet.of(TargetType.DATABASE), metadata, serviceRegistry);
SchemaUpdate
schemaUpdate
=
new
SchemaUpdate
();
schemaUpdate
.
execute
(
EnumSet
.
of
(
TargetType
.
DATABASE
),
metadata
,
serviceRegistry
);
}
public
Session
getSession
(){
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论