提交 0d96e549 编写于 作者: O o2sword

系统设计搜索返回内容增加匹配结果

上级 0dc9b7fb
......@@ -4,10 +4,7 @@ import com.x.base.core.entity.enums.DesignerType;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.gson.GsonPropertyObject;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
public class WrapDesigner extends GsonPropertyObject {
......@@ -93,7 +90,13 @@ public class WrapDesigner extends GsonPropertyObject {
for (String key : map.keySet()){
DesignerPattern pattern = new DesignerPattern();
pattern.setProperty(key);
pattern.setPropertyValue(map.get(key));
String propertyValue = map.get(key);
if(!DesignerType.script.toString().equals(this.getDesignerType())) {
if (propertyValue != null && propertyValue.length() > 255) {
propertyValue = propertyValue.substring(0, 255);
}
}
pattern.setPropertyValue(propertyValue);
patternList.add(pattern);
}
this.patternList = patternList;
......@@ -106,7 +109,13 @@ public class WrapDesigner extends GsonPropertyObject {
DesignerPattern pattern = new DesignerPattern();
pattern.setElementType(elementType);
pattern.setProperty(key);
pattern.setPropertyValue(map.get(key));
String propertyValue = map.get(key);
if(!DesignerType.script.toString().equals(this.getDesignerType())) {
if (propertyValue != null && propertyValue.length() > 255) {
propertyValue = propertyValue.substring(0, 255);
}
}
pattern.setPropertyValue(propertyValue);
this.patternList.add(pattern);
}
}
......@@ -120,7 +129,13 @@ public class WrapDesigner extends GsonPropertyObject {
pattern.setElementId(elementId);
pattern.setElementName(elementName);
pattern.setProperty(key);
pattern.setPropertyValue(map.get(key));
String propertyValue = map.get(key);
if(!DesignerType.script.toString().equals(this.getDesignerType())) {
if (propertyValue != null && propertyValue.length() > 255) {
propertyValue = propertyValue.substring(0, 255);
}
}
pattern.setPropertyValue(propertyValue);
this.patternList.add(pattern);
}
}
......@@ -138,12 +153,8 @@ public class WrapDesigner extends GsonPropertyObject {
for (DesignerPattern pattern : this.patternList){
if ("text".equals(pattern.getProperty())){
designerPattern = pattern;
}else{
pattern.setPropertyValue(null);
}
}
}else{
this.clearPatternValue();
}
return designerPattern;
}
......@@ -160,11 +171,27 @@ public class WrapDesigner extends GsonPropertyObject {
@FieldDescribe("设计属性.")
private String property;
@FieldDescribe("设计属性.")
@FieldDescribe("设计属性.")
private String propertyValue;
@FieldDescribe("匹配行")
private List<Integer> lines;
@FieldDescribe("script匹配行")
private List<PatternLine> lines;
public void setLines(Map<Integer, String> map){
if(map!=null){
List<PatternLine> lines = new ArrayList<>();
Iterator<Map.Entry<Integer, String>> iterator = map.entrySet().iterator();
while (iterator.hasNext()){
Map.Entry<Integer, String> entry = iterator.next();
PatternLine patternLine = new PatternLine();
patternLine.setLine(entry.getKey());
patternLine.setLineValue(entry.getValue());
lines.add(patternLine);
}
this.lines = lines;
map.clear();
}
}
public String getElementType() {
return elementType;
......@@ -198,11 +225,11 @@ public class WrapDesigner extends GsonPropertyObject {
this.property = property;
}
public List<Integer> getLines() {
public List<PatternLine> getLines() {
return lines;
}
public void setLines(List<Integer> lines) {
public void setLines(List<PatternLine> lines) {
this.lines = lines;
}
......@@ -215,4 +242,27 @@ public class WrapDesigner extends GsonPropertyObject {
}
}
public class PatternLine extends GsonPropertyObject {
@FieldDescribe("第几行匹配到")
private Integer line;
@FieldDescribe("匹配行内容")
private String lineValue;
public Integer getLine() {
return line;
}
public void setLine(Integer line) {
this.line = line;
}
public String getLineValue() {
return lineValue;
}
public void setLineValue(String lineValue) {
this.lineValue = lineValue;
}
}
}
......@@ -37,7 +37,7 @@ class ActionSearch extends BaseAction {
throw new ExceptionAccessDenied(effectivePerson);
}
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
logger.info("{}开始内容管理设计搜索,关键字:{}", effectivePerson.getDistinguishedName(), wi.getKeyword());
logger.debug("{}开始内容管理设计搜索,关键字:{}", effectivePerson.getDistinguishedName(), wi.getKeyword());
if(StringUtils.isBlank(wi.getKeyword())){
throw new ExceptionFieldEmpty("keyword");
}
......
......@@ -38,7 +38,7 @@ class ActionSearch extends BaseAction {
throw new ExceptionAccessDenied(effectivePerson);
}
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
logger.info("{}开始门户设计搜索,关键字:{}", effectivePerson.getDistinguishedName(), wi.getKeyword());
logger.debug("{}开始门户设计搜索,关键字:{}", effectivePerson.getDistinguishedName(), wi.getKeyword());
if(StringUtils.isBlank(wi.getKeyword())){
throw new ExceptionFieldEmpty("keyword");
}
......
......@@ -39,7 +39,7 @@ class ActionSearch extends BaseAction {
throw new ExceptionAccessDenied(effectivePerson);
}
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
logger.info("{}开始流程平台设计搜索,关键字:{}", effectivePerson.getDistinguishedName(), wi.getKeyword());
logger.debug("{}开始流程平台设计搜索,关键字:{}", effectivePerson.getDistinguishedName(), wi.getKeyword());
if(StringUtils.isBlank(wi.getKeyword())){
throw new ExceptionFieldEmpty("keyword");
}
......
......@@ -35,7 +35,7 @@ class ActionSearch extends BaseAction {
throw new ExceptionAccessDenied(effectivePerson);
}
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
logger.info("{}开始服务管理设计搜索,关键字:{}", effectivePerson.getDistinguishedName(), wi.getKeyword());
logger.debug("{}开始服务管理设计搜索,关键字:{}", effectivePerson.getDistinguishedName(), wi.getKeyword());
if(StringUtils.isBlank(wi.getKeyword())){
throw new ExceptionFieldEmpty("keyword");
}
......
......@@ -38,7 +38,7 @@ class ActionSearch extends BaseAction {
throw new ExceptionAccessDenied(effectivePerson);
}
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
logger.info("{}开始数据中心设计搜索,关键字:{}", effectivePerson.getDistinguishedName(), wi.getKeyword());
logger.debug("{}开始数据中心设计搜索,关键字:{}", effectivePerson.getDistinguishedName(), wi.getKeyword());
if(StringUtils.isBlank(wi.getKeyword())){
throw new ExceptionFieldEmpty("keyword");
}
......
......@@ -19,10 +19,12 @@ import org.apache.commons.lang3.StringUtils;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.locks.ReentrantLock;
class ActionSearch extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionSearch.class);
private static ReentrantLock lock = new ReentrantLock();
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement)
throws Exception {
......@@ -31,8 +33,17 @@ class ActionSearch extends BaseAction {
if(StringUtils.isBlank(wi.getKeyword())){
throw new ExceptionFieldEmpty("keyword");
}
logger.print("{}搜索全局设计:{}", effectivePerson.getDistinguishedName(), wi);
result.setData(search(wi));
logger.info("{}搜索全局设计:{}", effectivePerson.getDistinguishedName(), wi);
if (ListTools.isEmpty(wi.getModuleList())) {
result.setData(search(wi));
}else{
lock.lock();
try {
result.setData(search(wi));
} finally {
lock.unlock();
}
}
return result;
}
......@@ -132,7 +143,7 @@ class ActionSearch extends BaseAction {
for (WrapDesigner designer : designerList) {
WrapDesigner.DesignerPattern pattern = designer.getScriptDesigner();
if(pattern!=null) {
List<Integer> lines = patternLines(designer.getDesignerId() + "-" + designer.getUpdateTime().getTime(),
Map<Integer, String> lines = patternLines(designer.getDesignerId() + "-" + designer.getUpdateTime().getTime(),
wi.getKeyword(), pattern.getPropertyValue(), wi.getCaseSensitive(), wi.getMatchWholeWord(), wi.getMatchRegExp());
pattern.setLines(lines);
pattern.setPropertyValue(null);
......
......@@ -2,24 +2,21 @@ package com.x.query.service.processing.jaxrs.design;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.jaxrs.WrapDesigner;
import com.x.base.core.project.tools.DefaultCharset;
import com.x.base.core.project.tools.FileTools;
import com.x.base.core.project.tools.StringTools;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.*;
abstract class BaseAction extends StandardJaxrsAction {
protected List<Integer> patternLines(String id, String keyword, String content, Boolean caseSensitive, Boolean matchWholeWord, Boolean matchRegExp){
List<Integer> list = new ArrayList<>();
protected Map<Integer, String> patternLines(String id, String keyword, String content, Boolean caseSensitive, Boolean matchWholeWord, Boolean matchRegExp){
Map<Integer, String> map = new LinkedHashMap<>();
File file = readFile(id, content);
if (file!=null){
try (RandomAccessFile randomFile = new RandomAccessFile(file, "r")) {
......@@ -31,7 +28,10 @@ abstract class BaseAction extends StandardJaxrsAction {
String lineStr = new String(bytes);
if(StringUtils.isNotBlank(lineStr) && lineStr.length()>=keyword.length()){
if(StringTools.matchKeyword(keyword, lineStr, caseSensitive, matchWholeWord, matchRegExp)){
list.add(curReadLine);
if(lineStr.length()>500){
lineStr = lineStr.substring(0, 500);
}
map.put(curReadLine, lineStr);
}
}
}
......@@ -39,7 +39,7 @@ abstract class BaseAction extends StandardJaxrsAction {
e.printStackTrace();
}
}
return list;
return map;
}
private synchronized File readFile(String id, String content){
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册