Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
T
test
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
邬友楠
test
Commits
b34ad564
Commit
b34ad564
authored
Dec 25, 2019
by
雍欢
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
treeview支持切换SQL方言
parent
7a83fd3f
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
119 additions
and
55 deletions
+119
-55
EasySearchManager.java
.../huigou/uasp/bmp/common/easysearch/EasySearchManager.java
+0
-3
EasySearchLoadInterface.java
...bmp/common/easysearch/domain/EasySearchLoadInterface.java
+3
-0
EasySearchMappingModel.java
...ommon/easysearch/domain/model/EasySearchMappingModel.java
+1
-0
TreeViewManager.java
.../com/huigou/uasp/bmp/common/treeview/TreeViewManager.java
+66
-32
TreeViewLoadInterface.java
...asp/bmp/common/treeview/domain/TreeViewLoadInterface.java
+15
-3
TreeViewMappingModel.java
...mp/common/treeview/domain/model/TreeViewMappingModel.java
+31
-16
spring-system.xml
huigou-xt/src/main/resources/config/spring/spring-system.xml
+3
-1
No files found.
huigou-uasp/src/main/java/com/huigou/uasp/bmp/common/easysearch/EasySearchManager.java
View file @
b34ad564
...
...
@@ -41,9 +41,6 @@ public class EasySearchManager extends ResourceLoadManager<EasySearchMappingMode
this
.
sqlDialect
=
sqlDialect
;
}
/**
* 加载配置文件
*/
@Override
public
EasySearchMappingModel
loadConfigFile
(
String
type
)
throws
NotFoundException
{
List
<
String
>
paths
=
new
ArrayList
<>(
2
);
...
...
huigou-uasp/src/main/java/com/huigou/uasp/bmp/common/easysearch/domain/EasySearchLoadInterface.java
View file @
b34ad564
...
...
@@ -22,5 +22,8 @@ public interface EasySearchLoadInterface {
String
DIALECT_XML_PATH
=
String
.
join
(
"/"
,
XML_BASE_DIRECTORY
,
"%s"
,
"easy-search-%s.xml"
);
/**
* 加载配置文件
*/
EasySearchMappingModel
loadConfigFile
(
String
path
)
throws
ResourceLoadException
;
}
huigou-uasp/src/main/java/com/huigou/uasp/bmp/common/easysearch/domain/model/EasySearchMappingModel.java
View file @
b34ad564
...
...
@@ -81,6 +81,7 @@ public class EasySearchMappingModel implements Serializable, ConfigFileVersion {
public
QuerySchemeModel
getQuerySchemeModel
(
String
name
)
{
return
querySchemes
.
stream
()
.
map
(
queryScheme
->
queryScheme
.
get
(
name
))
.
filter
(
Objects:
:
nonNull
)
.
findFirst
()
.
get
();
}
...
...
huigou-uasp/src/main/java/com/huigou/uasp/bmp/common/treeview/TreeViewManager.java
View file @
b34ad564
package
com
.
huigou
.
uasp
.
bmp
.
common
.
treeview
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
org.springframework.core.io.ClassPathResource
;
import
com.huigou.exception.ApplicationException
;
import
com.huigou.exception.NotFoundException
;
import
com.huigou.exception.ResourceLoadException
;
import
com.huigou.uasp.bmp.common.treeview.domain.TreeViewLoadInterface
;
import
com.huigou.uasp.bmp.common.treeview.domain.model.TreeViewMappingModel
;
import
com.huigou.uasp.bmp.treeview.TreeMappingsDocument
;
import
com.huigou.util.ResourceLoadManager
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.xmlbeans.XmlException
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.core.io.Resource
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* 树配置管理
* @author Gerald
*
* @author Gerald
*/
public
class
TreeViewManager
extends
ResourceLoadManager
<
TreeViewMappingModel
>
implements
TreeViewLoadInterface
{
/**
*
加载配置文件
*
* @
Title: loadConfigFile
*
@author
* @Description: TODO
* @param @param fileName
* @param @return
*
@param @throws Exception
*
@return Domain
* @
throws
*
SQL 方言。
*
* @
since 1.1.3
*
/
private
String
sqlDialect
;
/**
*
设置SQL方言。
*
* @
since 1.1.3
*/
public
void
setSqlDialect
(
String
sqlDialect
)
{
this
.
sqlDialect
=
sqlDialect
;
}
@Override
public
TreeViewMappingModel
loadConfigFile
(
String
type
)
throws
NotFoundException
{
InputStream
inputStream
=
null
;
String
path
=
String
.
format
(
XML_PATH
,
type
);
List
<
String
>
paths
=
new
ArrayList
<>(
2
);
// 方言xml放在最前面,从而达到优先使用方言xml的目的
if
(
StringUtils
.
isNotBlank
(
sqlDialect
))
{
paths
.
add
(
String
.
format
(
DIALECT_XML_PATH
,
sqlDialect
,
type
));
}
String
defaultPath
=
String
.
format
(
XML_PATH
,
type
);
paths
.
add
(
defaultPath
);
List
<
InputStream
>
xmlStreams
=
Collections
.
emptyList
();
try
{
ClassPathResource
resource
=
getResource
(
path
);
inputStream
=
resource
.
getInputStream
();
TreeMappingsDocument
doc
=
TreeMappingsDocument
.
Factory
.
parse
(
inputStream
);
TreeViewMappingModel
mappingModel
=
new
TreeViewMappingModel
(
doc
.
getTreeMappings
());
mappingModel
.
setVersions
(
resource
.
lastModified
());
mappingModel
.
setConfigFilePath
(
path
);
List
<
Resource
>
resources
=
paths
.
stream
()
.
map
(
ClassPathResource:
:
new
)
.
filter
(
Resource:
:
exists
)
.
collect
(
Collectors
.
toList
());
xmlStreams
=
resources
.
stream
()
.
map
(
xml
->
{
try
{
return
xml
.
getInputStream
();
}
catch
(
IOException
ioe
)
{
throw
new
ApplicationException
(
ioe
);
}
})
.
collect
(
Collectors
.
toList
());
List
<
TreeMappingsDocument
.
TreeMappings
>
mappings
=
xmlStreams
.
stream
().
map
(
is
->
{
try
{
return
TreeMappingsDocument
.
Factory
.
parse
(
is
).
getTreeMappings
();
}
catch
(
XmlException
|
IOException
e
)
{
throw
new
ApplicationException
(
e
);
}
}).
collect
(
Collectors
.
toList
());
TreeViewMappingModel
mappingModel
=
new
TreeViewMappingModel
(
mappings
);
mappingModel
.
setVersions
(
maxLastModified
(
resources
));
mappingModel
.
setConfigFilePaths
(
paths
);
return
mappingModel
;
}
catch
(
Exception
e
)
{
throw
new
NotFoundException
(
"读取配置文件失败:"
+
e
.
getMessage
(
));
throw
new
ResourceLoadException
(
String
.
format
(
"读取配置文件[%s]失败:%s"
,
defaultPath
,
e
.
getMessage
()
));
}
finally
{
if
(
inputStream
!=
null
)
{
try
{
inputStream
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
xmlStreams
.
forEach
(
IOUtils:
:
closeQuietly
);
}
}
}
\ No newline at end of file
huigou-uasp/src/main/java/com/huigou/uasp/bmp/common/treeview/domain/TreeViewLoadInterface.java
View file @
b34ad564
...
...
@@ -6,14 +6,26 @@ import com.huigou.uasp.bmp.common.treeview.domain.model.TreeViewMappingModel;
/**
* 快捷查询调用解析接口
*
*
* @author xx
*/
public
interface
TreeViewLoadInterface
{
/**
* @since 1.1.3
*/
String
XML_BASE_DIRECTORY
=
"config/content/treeview"
;
/**
* 配置文件默认路径
*/
public
final
static
String
XML_PATH
=
"config/content/treeview/tree-view-%s.xml"
;
String
XML_PATH
=
String
.
join
(
"/"
,
XML_BASE_DIRECTORY
,
"tree-view-%s.xml"
);
/**
* 方言配置文件路径
*
* @since 1.1.3
*/
String
DIALECT_XML_PATH
=
String
.
join
(
"/"
,
XML_BASE_DIRECTORY
,
"%s"
,
"tree-view-%s.xml"
);
public
TreeViewMappingModel
loadConfigFile
(
String
path
)
throws
ResourceLoadException
;
TreeViewMappingModel
loadConfigFile
(
String
path
)
throws
ResourceLoadException
;
}
huigou-uasp/src/main/java/com/huigou/uasp/bmp/common/treeview/domain/model/TreeViewMappingModel.java
View file @
b34ad564
package
com
.
huigou
.
uasp
.
bmp
.
common
.
treeview
.
domain
.
model
;
import
java.io.Serializable
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
com.huigou.data.query.XMLParseUtil
;
import
com.huigou.data.query.parser.model.ConditionModel
;
...
...
@@ -28,17 +26,26 @@ public class TreeViewMappingModel implements Serializable, ConfigFileVersion {
private
static
final
long
serialVersionUID
=
173704882069216812L
;
private
Map
<
String
,
TreeModel
>
trees
;
// 包含查询配置文件
/**
* 包含查询配置文件
*/
private
final
List
<
Map
<
String
,
TreeModel
>>
trees
;
private
Long
version
;
private
List
<
String
>
configFilePaths
;
public
TreeViewMappingModel
(
TreeMappings
mapping
)
{
trees
=
new
HashMap
<>(
mapping
.
getTreeArray
().
length
);
for
(
Tree
tree
:
mapping
.
getTreeArray
())
{
trees
.
put
(
tree
.
getName
(),
parseTreeModel
(
tree
));
}
this
(
Arrays
.
asList
(
mapping
));
}
/**
* @since 1.1.3
*/
public
TreeViewMappingModel
(
List
<
TreeMappings
>
mappings
)
{
trees
=
mappings
.
stream
()
.
map
(
mapping
->
Arrays
.
stream
(
mapping
.
getTreeArray
()).
collect
(
Collectors
.
toMap
(
Tree:
:
getName
,
this
::
parseTreeModel
)))
.
collect
(
Collectors
.
toList
());
}
/**
...
...
@@ -63,7 +70,8 @@ public class TreeViewMappingModel implements Serializable, ConfigFileVersion {
model
.
setDefaultCondition
(
dataModel
.
getDefaultCondition
());
model
.
setOrderby
(
dataModel
.
getOrderby
());
model
.
setOrder
(
dataModel
.
getOrder
());
for
(
Condition
condition
:
dataModel
.
getConditionArray
())
{
// 根据查询条件定义组合查询语句
for
(
Condition
condition
:
dataModel
.
getConditionArray
())
{
// 根据查询条件定义组合查询语句
ConditionModel
conditionModel
=
ConditionModel
.
newInstance
(
condition
);
conditionModel
.
setFormula
(
XMLParseUtil
.
getNodeTextValue
(
condition
));
model
.
addConditions
(
conditionModel
);
...
...
@@ -72,7 +80,11 @@ public class TreeViewMappingModel implements Serializable, ConfigFileVersion {
}
public
TreeModel
getTreeModel
(
String
name
)
{
return
trees
.
get
(
name
);
return
trees
.
stream
()
.
map
(
queryScheme
->
queryScheme
.
get
(
name
))
.
filter
(
Objects:
:
nonNull
)
.
findFirst
()
.
get
();
}
@Override
...
...
@@ -89,6 +101,14 @@ public class TreeViewMappingModel implements Serializable, ConfigFileVersion {
return
configFilePaths
.
get
(
0
);
}
/**
* @deprecated 已被 {@link #setConfigFilePaths(List)} 替代。
*/
@Deprecated
public
void
setConfigFilePath
(
String
configFilePath
)
{
this
.
configFilePaths
=
Collections
.
singletonList
(
configFilePath
);
}
public
void
setConfigFilePaths
(
List
<
String
>
configFilePaths
)
{
this
.
configFilePaths
=
configFilePaths
;
}
...
...
@@ -97,9 +117,4 @@ public class TreeViewMappingModel implements Serializable, ConfigFileVersion {
public
List
<
String
>
getFilePaths
()
{
return
configFilePaths
;
}
public
void
setConfigFilePath
(
String
configFilePath
)
{
this
.
configFilePaths
=
Collections
.
singletonList
(
configFilePath
);
}
}
huigou-xt/src/main/resources/config/spring/spring-system.xml
View file @
b34ad564
...
...
@@ -24,7 +24,9 @@
<property
name=
"sqlDialect"
value=
"${sqlDialect}"
/>
</bean>
<!-- 快捷树查询配置 -->
<bean
id=
"treeViewManager"
class=
"com.huigou.uasp.bmp.common.treeview.TreeViewManager"
/>
<bean
id=
"treeViewManager"
class=
"com.huigou.uasp.bmp.common.treeview.TreeViewManager"
>
<property
name=
"sqlDialect"
value=
"${sqlDialect}"
/>
</bean>
<bean
id=
"treeViewApplication"
class=
"com.huigou.uasp.bmp.common.treeview.application.impl.TreeViewApplicationImpl"
>
<property
name=
"jdbcDao"
ref=
"jdbcDao"
/>
<property
name=
"permissionBuilder"
ref=
"queryPermissionBuilder"
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment