Commit b34ad564 authored by 雍欢's avatar 雍欢

treeview支持切换SQL方言

parent 7a83fd3f
......@@ -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);
......
......@@ -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;
}
......@@ -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();
}
......
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
......@@ -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;
}
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);
}
}
......@@ -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"/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment