Commit bb9badd9 by lanmw

add path parameter

parent 5764cf3a
...@@ -83,20 +83,33 @@ public class TagCtrl { ...@@ -83,20 +83,33 @@ public class TagCtrl {
@GetMapping(value = "/searchSystemTagByPage") @GetMapping(value = "/searchSystemTagByPage")
public Page searchSystemTagByPage(@RequestParam(required = false, value = "keyword") String keyword, public Page searchSystemTagByPage(@RequestParam(required = false, value = "keyword") String keyword,
@RequestParam(required = false, value = "domain") Integer domain, @RequestParam(required = false, value = "domain") Integer domain,
@RequestParam(required = false , value = "path") String path,
@RequestParam("pageNo") Integer pageNo, @RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize) { @RequestParam("pageSize") Integer pageSize) {
String userName = UserInfoUtils.getUserName(); String userName = UserInfoUtils.getUserName();
return tagService.searchSystemTagByPage(userName, keyword, domain, new Page(pageSize, pageNo)); return tagService.searchSystemTagByPage(userName, keyword, path, domain, new Page(pageSize, pageNo));
}
@ApiOperation(value = "搜索维度标签里面的个人标签", notes = "搜索维度标签里面的个人标签")
@GetMapping(value = "/searchPersonalDimensionTagByPage")
public Page searchPersonalDimensionTagByPage(@RequestParam(required = false, value = "keyword") String keyword,
@RequestParam(required = false , value = "domain") Integer domain,
@RequestParam(required = false , value = "path") String path,
@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize) {
String userName = UserInfoUtils.getUserName();
return tagService.searchPersonalDimensionTagByPage(userName, keyword, path, domain, new Page(pageSize, pageNo));
} }
@ApiOperation(value = "搜索个人标签", notes = "搜索个人标签") @ApiOperation(value = "搜索个人标签", notes = "搜索个人标签")
@GetMapping(value = "/searchPersonalTagByPage") @GetMapping(value = "/searchPersonalTagByPage")
public Page searchPersonalTagByPage(@RequestParam(required = false, value = "keyword") String keyword, public Page searchPersonalTagByPage(@RequestParam(required = false, value = "keyword") String keyword,
@RequestParam(required = false , value = "domain") Integer domain, @RequestParam(required = false , value = "domain") Integer domain,
@RequestParam(required = false , value = "path") String path,
@RequestParam("pageNo") Integer pageNo, @RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize) { @RequestParam("pageSize") Integer pageSize) {
String userName = UserInfoUtils.getUserName(); String userName = UserInfoUtils.getUserName();
return tagService.searchPersonalTagByPage(userName, keyword, domain, new Page(pageSize, pageNo)); return tagService.searchPersonalTagByPage(userName, keyword, path, domain, new Page(pageSize, pageNo));
} }
@ApiOperation(value = "分享标签", notes = "分享标签") @ApiOperation(value = "分享标签", notes = "分享标签")
......
package com.keymobile.tagmanager.service; package com.keymobile.tagmanager.service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -16,7 +16,6 @@ import org.springframework.data.mongodb.core.MongoOperations; ...@@ -16,7 +16,6 @@ import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import com.keymobile.tagmanager.exception.TagDuplicateException; import com.keymobile.tagmanager.exception.TagDuplicateException;
import com.keymobile.tagmanager.exception.TagException; import com.keymobile.tagmanager.exception.TagException;
import com.keymobile.tagmanager.exception.TagNotExistException; import com.keymobile.tagmanager.exception.TagNotExistException;
...@@ -27,7 +26,6 @@ import com.keymobile.tagmanager.persistence.TagRepository; ...@@ -27,7 +26,6 @@ import com.keymobile.tagmanager.persistence.TagRepository;
import com.keymobile.tagmanager.util.Constants; import com.keymobile.tagmanager.util.Constants;
import com.keymobile.tagmanager.util.JsonTreeHelper; import com.keymobile.tagmanager.util.JsonTreeHelper;
import com.keymobile.tagmanager.util.JsonTreeHelper.JsonNode; import com.keymobile.tagmanager.util.JsonTreeHelper.JsonNode;
import com.keymobile.tagmanager.util.MongoOperationsUtil;
@Service @Service
public class TagService { public class TagService {
...@@ -40,7 +38,7 @@ public class TagService { ...@@ -40,7 +38,7 @@ public class TagService {
private Logger logger = LoggerFactory.getLogger(TagService.class); private Logger logger = LoggerFactory.getLogger(TagService.class);
public Tag addOrUpdateTag(String parentId, Tag tag, String userName) throws TagNotExistException, TagDuplicateException, TagException { public Tag addOrUpdateTag(String parentId, Tag tag, String userName) throws TagNotExistException, TagDuplicateException, TagException {
if (!StringUtils.isEmpty(parentId)) { if (StringUtils.isNotBlank(parentId)) {
Tag parent = getTagById(parentId); Tag parent = getTagById(parentId);
tag.setPath(parent.getPath() + Constants.TAG_PATH_SEPARATOR + tag.getName()); tag.setPath(parent.getPath() + Constants.TAG_PATH_SEPARATOR + tag.getName());
} else { } else {
...@@ -48,7 +46,7 @@ public class TagService { ...@@ -48,7 +46,7 @@ public class TagService {
} }
changeNameToAvoidConflict(tag, userName); changeNameToAvoidConflict(tag, userName);
checkTagValid(tag, userName); checkTagValid(tag, userName);
if (!StringUtils.isEmpty(tag.getId())) { if (StringUtils.isNotBlank(tag.getId())) {
Tag origin = mongoOperations.findOne(Query.query(Criteria.where("_id").is(tag.getId())), Tag.class); Tag origin = mongoOperations.findOne(Query.query(Criteria.where("_id").is(tag.getId())), Tag.class);
List<Tag> relationTags = mongoOperations.find( List<Tag> relationTags = mongoOperations.find(
Query.query(createRelationCriteria(userName, origin)), Tag.class); Query.query(createRelationCriteria(userName, origin)), Tag.class);
...@@ -135,6 +133,16 @@ public class TagService { ...@@ -135,6 +133,16 @@ public class TagService {
Criteria.where("creator").is(userName)); Criteria.where("creator").is(userName));
} }
private Criteria createSystemTagCriteria() {
return Criteria.where("tagType").is(Constants.TAG_SYSTEM_TYPE);
}
private Criteria createPersonalDimensionTagCriteria(String userName) {
return Criteria.where("tagType").is(Constants.TAG_PERSONAL_TYPE)
.and("dimensionType").is(Constants.TAG_DIMENSION_TRUE);
}
private Query createPersonalExcludeOpenTypeTagQuery(String userName) { private Query createPersonalExcludeOpenTypeTagQuery(String userName) {
return Query.query(Criteria.where("tagType").is(Constants.TAG_PERSONAL_TYPE) return Query.query(Criteria.where("tagType").is(Constants.TAG_PERSONAL_TYPE)
.orOperator( .orOperator(
...@@ -163,10 +171,13 @@ public class TagService { ...@@ -163,10 +171,13 @@ public class TagService {
} }
public Page searchPersonalTagByPage(String userName, String keyword, Integer domain, Page page) { public Page searchPersonalTagByPage(String userName, String keyword, String path, Integer domain, Page page) {
Criteria andCriterias = createPersonalTagCriteria(userName); Criteria andCriterias = createPersonalTagCriteria(userName);
if (org.apache.commons.lang.StringUtils.isNotBlank(keyword) && !"*".equals(keyword)) { if (StringUtils.isNotBlank(keyword) && !"*".equals(keyword)) {
andCriterias.andOperator(createRegexQuery(Arrays.asList("name", "nameEn", "desc"), keyword)); andCriterias.andOperator(createKeywordRegexQuery(Arrays.asList("name", "nameEn", "desc"), keyword));
}
if (StringUtils.isNotBlank(path)) {
andCriterias.andOperator(createPathRegexQuery(path));
} }
Query q = new Query(andCriterias); Query q = new Query(andCriterias);
q.skip(page.getOffset()); q.skip(page.getOffset());
...@@ -180,13 +191,17 @@ public class TagService { ...@@ -180,13 +191,17 @@ public class TagService {
} }
private Criteria createRegexQuery(List<String> asList, String keyword) { private Criteria createKeywordRegexQuery(List<String> asList, String keyword) {
Criteria criteriaSearch = new Criteria(); Criteria criteriaSearch = new Criteria();
return criteriaSearch.orOperator(asList.stream().map(col -> { return criteriaSearch.orOperator(asList.stream().map(col -> {
return Criteria.where(col).regex(keyword, "i"); return Criteria.where(col).regex(keyword, "i");
}).collect(Collectors.toList()).toArray(new Criteria[0])); }).collect(Collectors.toList()).toArray(new Criteria[0]));
} }
private Criteria createPathRegexQuery(String path) {
return Criteria.where("path").regex("^"+path);
}
public JsonNode[] querySystemTagAsTree(String parentId) throws TagNotExistException { public JsonNode[] querySystemTagAsTree(String parentId) throws TagNotExistException {
List<Tag> tags = new ArrayList<>(); List<Tag> tags = new ArrayList<>();
if (StringUtils.isEmpty(parentId)) { if (StringUtils.isEmpty(parentId)) {
...@@ -209,13 +224,15 @@ public class TagService { ...@@ -209,13 +224,15 @@ public class TagService {
return new JsonNode[] {}; return new JsonNode[] {};
} }
public Page searchSystemTagByPage(String userName, String keyword, Integer domain, Page page) { public Page searchSystemTagByPage(String userName, String keyword, String path, Integer domain, Page page) {
Map<String, Object> condition = new HashMap<>(); Criteria andCriterias = createSystemTagCriteria();
if (org.apache.commons.lang.StringUtils.isNotBlank(keyword) && !"*".equals(keyword)) { if (StringUtils.isNotBlank(keyword) && !"*".equals(keyword)) {
MongoOperationsUtil.addSearchCriteria(Arrays.asList("name", "nameEn", "desc"), keyword, condition); andCriterias.andOperator(createKeywordRegexQuery(Arrays.asList("name", "nameEn", "desc"), keyword));
}
if (StringUtils.isNotBlank(path)) {
andCriterias.andOperator(createPathRegexQuery(path));
} }
condition.put("tagType", Constants.TAG_SYSTEM_TYPE); Query q = createPageQuery(page, andCriterias);
Query q = MongoOperationsUtil.createQueryWithSpecifiedField(condition, page, getDefaultTagOrders());
List<Tag> tags = mongoOperations.find(q, Tag.class); List<Tag> tags = mongoOperations.find(q, Tag.class);
long count = mongoOperations.count(q, Tag.class); long count = mongoOperations.count(q, Tag.class);
page.setData(decoratorToExtTag(tags, userName)); page.setData(decoratorToExtTag(tags, userName));
...@@ -223,6 +240,14 @@ public class TagService { ...@@ -223,6 +240,14 @@ public class TagService {
return page; return page;
} }
private Query createPageQuery(Page page, Criteria andCriterias) {
Query q = new Query(andCriterias);
q.skip(page.getOffset());
q.limit(page.getPageSize());
q.with(Sort.by(getDefaultTagOrders()));
return q;
}
private List<ExtTag> decoratorToExtTag(List<Tag> tags, String userName) { private List<ExtTag> decoratorToExtTag(List<Tag> tags, String userName) {
return tags.stream().map(t -> { return tags.stream().map(t -> {
return new ExtTag(t, t.getCreator().equals(userName) ? Constants.TAG_OPERABLE_TRUE : return new ExtTag(t, t.getCreator().equals(userName) ? Constants.TAG_OPERABLE_TRUE :
...@@ -327,4 +352,22 @@ public class TagService { ...@@ -327,4 +352,22 @@ public class TagService {
} }
public Page searchPersonalDimensionTagByPage(String userName, String keyword, String path, Integer domain, Page page) {
Criteria andCriterias = createPersonalDimensionTagCriteria(userName);
if (StringUtils.isNotBlank(keyword) && !"*".equals(keyword)) {
andCriterias.andOperator(createKeywordRegexQuery(Arrays.asList("name", "nameEn", "desc"), keyword));
}
if (StringUtils.isNotBlank(path)) {
andCriterias.andOperator(createPathRegexQuery(path));
}
Query q = createPageQuery(page, andCriterias);
List<Tag> tags = mongoOperations
.find(q, Tag.class);
long count = mongoOperations.count(q, Tag.class);
page.setData(decoratorToExtTag(tags, userName));
page.setTotal(count);
return page;
}
} }
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