Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Pig
提交
4ed31d35
P
Pig
项目概览
int
/
Pig
上一次同步 12 个月
通知
8
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Pig
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4ed31d35
编写于
3月 14, 2020
作者:
pig_冷冷
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
♻
Refactoring code. 代码生成支持动态数据源维护
上级
f0c530ee
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
28 addition
and
103 deletion
+28
-103
db/pig_codegen.sql
db/pig_codegen.sql
+0
-20
db/pig_config.sql
db/pig_config.sql
+0
-18
pig-codegen/src/main/java/com/pig4cloud/pig/codegen/entity/GenDatasourceConf.java
...a/com/pig4cloud/pig/codegen/entity/GenDatasourceConf.java
+0
-5
pig-codegen/src/main/java/com/pig4cloud/pig/codegen/entity/GenFormConf.java
...in/java/com/pig4cloud/pig/codegen/entity/GenFormConf.java
+0
-5
pig-codegen/src/main/java/com/pig4cloud/pig/codegen/service/impl/GenDatasourceConfServiceImpl.java
...ig/codegen/service/impl/GenDatasourceConfServiceImpl.java
+2
-0
pig-codegen/src/main/java/com/pig4cloud/pig/codegen/util/CodeGenUtils.java
...ain/java/com/pig4cloud/pig/codegen/util/CodeGenUtils.java
+2
-8
pig-codegen/src/main/resources/generator.properties
pig-codegen/src/main/resources/generator.properties
+1
-4
pig-codegen/src/main/resources/mapper/GenFormConfMapper.xml
pig-codegen/src/main/resources/mapper/GenFormConfMapper.xml
+0
-1
pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/mybatis/SqlFilterArgumentResolver.java
...ud/pig/common/core/mybatis/SqlFilterArgumentResolver.java
+23
-42
未找到文件。
db/pig_codegen.sql
浏览文件 @
4ed31d35
...
...
@@ -7,24 +7,6 @@ SET FOREIGN_KEY_CHECKS = 0;
USE
`pig_codegen`
;
/*
*
* * Copyright (c) 2019-2020, 冷冷 (wangiegie@gmail.com).
* * <p>
* * Licensed under the GNU Lesser General Public License 3.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* * <p>
* * https://www.gnu.org/licenses/lgpl.html
* * <p>
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
*
*/
-- ----------------------------
-- Table structure for gen_datasource_conf
-- ----------------------------
...
...
@@ -38,7 +20,6 @@ CREATE TABLE `gen_datasource_conf` (
`create_date`
datetime
DEFAULT
CURRENT_TIMESTAMP
COMMENT
'创建时间'
,
`update_date`
datetime
DEFAULT
CURRENT_TIMESTAMP
ON
UPDATE
CURRENT_TIMESTAMP
COMMENT
'更新'
,
`del_flag`
char
(
1
)
DEFAULT
'0'
,
`tenant_id`
int
(
11
)
DEFAULT
NULL
COMMENT
'租户ID'
,
PRIMARY
KEY
(
`id`
)
USING
BTREE
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
9
DEFAULT
CHARSET
=
utf8mb4
COMMENT
=
'数据源表'
;
...
...
@@ -53,7 +34,6 @@ CREATE TABLE `gen_form_conf` (
`create_time`
timestamp
NULL
DEFAULT
CURRENT_TIMESTAMP
COMMENT
'创建时间'
,
`update_time`
timestamp
NULL
DEFAULT
CURRENT_TIMESTAMP
ON
UPDATE
CURRENT_TIMESTAMP
COMMENT
'修改时间'
,
`del_flag`
char
(
1
)
DEFAULT
'0'
,
`tenant_id`
int
(
11
)
DEFAULT
NULL
COMMENT
'所属租户'
,
PRIMARY
KEY
(
`id`
)
USING
BTREE
,
KEY
`table_name`
(
`table_name`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb4
COMMENT
=
'表单配置'
;
...
...
db/pig_config.sql
浏览文件 @
4ed31d35
...
...
@@ -189,24 +189,6 @@ CREATE TABLE `tenant_capacity` (
UNIQUE
KEY
`uk_tenant_id`
(
`tenant_id`
)
USING
BTREE
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb4
COMMENT
=
'租户容量信息表'
;
/*
*
* * Copyright (c) 2019-2020, 冷冷 (wangiegie@gmail.com).
* * <p>
* * Licensed under the GNU Lesser General Public License 3.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* * <p>
* * https://www.gnu.org/licenses/lgpl.html
* * <p>
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
*
*/
-- ----------------------------
-- Table structure for tenant_info
-- ----------------------------
...
...
pig-codegen/src/main/java/com/pig4cloud/pig/codegen/entity/GenDatasourceConf.java
浏览文件 @
4ed31d35
...
...
@@ -72,9 +72,4 @@ public class GenDatasourceConf extends Model<GenDatasourceConf> {
*/
@TableLogic
private
String
delFlag
;
/**
* 租户ID
*/
private
Integer
tenantId
;
}
pig-codegen/src/main/java/com/pig4cloud/pig/codegen/entity/GenFormConf.java
浏览文件 @
4ed31d35
...
...
@@ -72,9 +72,4 @@ public class GenFormConf extends Model<GenFormConf> {
*/
@ApiModelProperty
(
value
=
"删除标记"
)
private
String
delFlag
;
/**
* 所属租户
*/
@ApiModelProperty
(
value
=
"所属租户"
,
hidden
=
true
)
private
Integer
tenantId
;
}
pig-codegen/src/main/java/com/pig4cloud/pig/codegen/service/impl/GenDatasourceConfServiceImpl.java
浏览文件 @
4ed31d35
...
...
@@ -25,6 +25,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import
com.pig4cloud.pig.codegen.service.GenDatasourceConfService
;
import
com.pig4cloud.pig.codegen.entity.GenDatasourceConf
;
import
com.pig4cloud.pig.codegen.mapper.GenDatasourceConfMapper
;
import
com.pig4cloud.pig.common.datasource.support.DataSourceConstants
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.jasypt.encryption.StringEncryptor
;
...
...
@@ -123,6 +124,7 @@ public class GenDatasourceConfServiceImpl extends ServiceImpl<GenDatasourceConfM
dataSourceProperty
.
setUrl
(
conf
.
getUrl
());
dataSourceProperty
.
setUsername
(
conf
.
getUsername
());
dataSourceProperty
.
setPassword
(
conf
.
getPassword
());
dataSourceProperty
.
setDriverClassName
(
DataSourceConstants
.
DS_DRIVER
);
DataSource
dataSource
=
dataSourceCreator
.
createDataSource
(
dataSourceProperty
);
dynamicRoutingDataSource
.
addDataSource
(
dataSourceProperty
.
getPollName
(),
dataSource
);
}
...
...
pig-codegen/src/main/java/com/pig4cloud/pig/codegen/util/CodeGenUtils.java
浏览文件 @
4ed31d35
...
...
@@ -120,8 +120,7 @@ public class CodeGenUtils {
String
className
=
tableToJava
(
tableEntity
.
getTableName
(),
tablePrefix
);
tableEntity
.
setCaseClassName
(
className
);
tableEntity
.
setLowerClassName
(
StringUtils
.
uncapitalize
(
className
));
//获取需要在swagger文档中隐藏的属性字段
List
<
Object
>
hiddenColumns
=
config
.
getList
(
"hiddenColumn"
);
//列信息
List
<
ColumnEntity
>
columnList
=
new
ArrayList
<>();
for
(
Map
<
String
,
String
>
column
:
columns
)
{
...
...
@@ -132,12 +131,7 @@ public class CodeGenUtils {
columnEntity
.
setExtra
(
column
.
get
(
"extra"
));
columnEntity
.
setNullable
(
"NO"
.
equals
(
column
.
get
(
"isNullable"
)));
columnEntity
.
setColumnType
(
column
.
get
(
"columnType"
));
//隐藏不需要的在接口文档中展示的字段
if
(
hiddenColumns
.
contains
(
column
.
get
(
"columnName"
)))
{
columnEntity
.
setHidden
(
Boolean
.
TRUE
);
}
else
{
columnEntity
.
setHidden
(
Boolean
.
FALSE
);
}
columnEntity
.
setHidden
(
Boolean
.
FALSE
);
//列名转换成Java属性名
String
attrName
=
columnToJava
(
columnEntity
.
getColumnName
());
columnEntity
.
setCaseAttrName
(
attrName
);
...
...
pig-codegen/src/main/resources/generator.properties
浏览文件 @
4ed31d35
...
...
@@ -26,7 +26,7 @@ moduleName=generator
author
=
pig code generator
#\u8868\u524D\u7F00(\u7C7B\u540D\u4E0D\u4F1A\u5305\u542B\u8868\u524D\u7F00)
tablePrefix
=
t
b
_
tablePrefix
=
t
able
_
#\u7C7B\u578B\u8F6C\u6362\uFF0C\u914D\u7F6E\u4FE1\u606F
tinyint
=
Integer
...
...
@@ -50,6 +50,3 @@ longtext=String
date
=
LocalDateTime
datetime
=
LocalDateTime
timestamp
=
LocalDateTime
# hidden columns in Swagger Models
hiddenColumn
=
tenant_id
pig-codegen/src/main/resources/mapper/GenFormConfMapper.xml
浏览文件 @
4ed31d35
...
...
@@ -29,6 +29,5 @@
<result
property=
"createTime"
column=
"create_time"
/>
<result
property=
"updateTime"
column=
"update_time"
/>
<result
property=
"delFlag"
column=
"del_flag"
/>
<result
property=
"tenantId"
column=
"tenant_id"
/>
</resultMap>
</mapper>
pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/mybatis/SqlFilterArgumentResolver.java
浏览文件 @
4ed31d35
...
...
@@ -18,11 +18,9 @@
package
com.pig4cloud.pig.common.core.mybatis
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.baomidou.mybatisplus.core.metadata.OrderItem
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.pig4cloud.pig.common.core.exception.CheckedException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.core.MethodParameter
;
import
org.springframework.web.bind.support.WebDataBinderFactory
;
...
...
@@ -32,7 +30,11 @@ import org.springframework.web.method.support.ModelAndViewContainer;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.function.Predicate
;
import
java.util.stream.Collectors
;
/**
* @author lengleng
...
...
@@ -71,8 +73,8 @@ public class SqlFilterArgumentResolver implements HandlerMethodArgumentResolver
HttpServletRequest
request
=
webRequest
.
getNativeRequest
(
HttpServletRequest
.
class
);
String
ascs
=
request
.
getParameter
(
"ascs"
);
String
descs
=
request
.
getParameter
(
"descs"
);
String
[]
ascs
=
request
.
getParameterValues
(
"ascs"
);
String
[]
descs
=
request
.
getParameterValues
(
"descs"
);
String
current
=
request
.
getParameter
(
"current"
);
String
size
=
request
.
getParameter
(
"size"
);
...
...
@@ -85,52 +87,31 @@ public class SqlFilterArgumentResolver implements HandlerMethodArgumentResolver
page
.
setSize
(
Long
.
parseLong
(
size
));
}
// 过滤 asc 条件
List
<
OrderItem
>
ascList
=
sqlInject
(
ascs
,
"asc"
);
// 过滤 desc条件
List
<
OrderItem
>
descList
=
sqlInject
(
descs
,
"desc"
);
List
<
OrderItem
>
orderItemList
=
new
ArrayList
<>();
if
(
CollUtil
.
isNotEmpty
(
ascList
))
{
orderItemList
.
addAll
(
ascList
);
}
Optional
.
ofNullable
(
ascs
).
ifPresent
(
s
->
orderItemList
.
addAll
(
Arrays
.
stream
(
s
)
.
filter
(
sqlInjectPredicate
())
.
map
(
OrderItem:
:
asc
).
collect
(
Collectors
.
toList
())));
Optional
.
ofNullable
(
descs
).
ifPresent
(
s
->
orderItemList
.
addAll
(
Arrays
.
stream
(
s
)
.
filter
(
sqlInjectPredicate
())
.
map
(
OrderItem:
:
desc
).
collect
(
Collectors
.
toList
())));
page
.
addOrder
(
orderItemList
);
if
(
CollUtil
.
isNotEmpty
(
descList
))
{
orderItemList
.
addAll
(
descList
);
}
page
.
setOrders
(
orderItemList
);
return
page
;
}
/**
*
SQL注入过滤
*
判断用户输入里面有没有关键字
*
* @param str 待验证的字符串
* @return 返回标准的order 属性
* @return Predicate
*/
private
static
List
<
OrderItem
>
sqlInject
(
String
str
,
String
type
)
{
if
(
StrUtil
.
isBlank
(
str
))
{
return
null
;
}
//转换成小写
String
inStr
=
str
.
toLowerCase
();
//判断是否包含非法字符
for
(
String
keyword
:
KEYWORDS
)
{
if
(
inStr
.
contains
(
keyword
))
{
log
.
error
(
"查询包含非法字符 {}"
,
keyword
);
throw
new
CheckedException
(
keyword
+
"包含非法字符"
);
private
Predicate
<
String
>
sqlInjectPredicate
()
{
return
sql
->
{
for
(
String
keyword
:
KEYWORDS
)
{
if
(
StrUtil
.
containsIgnoreCase
(
sql
,
keyword
))
{
return
false
;
}
}
}
List
<
OrderItem
>
orderItemList
=
new
ArrayList
<>();
for
(
String
in
:
str
.
split
(
StrUtil
.
COMMA
))
{
if
(
"asc"
.
equals
(
type
))
{
orderItemList
.
add
(
OrderItem
.
asc
(
in
));
}
else
{
orderItemList
.
add
(
OrderItem
.
desc
(
in
));
}
}
return
orderItemList
;
return
true
;
};
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录