Commit 10ed975e by zhangkb

修改标签管理维度标签和个人标签根据当前登录用户过滤

parent 3ff544a8
...@@ -30,14 +30,20 @@ public class TagCtrl { ...@@ -30,14 +30,20 @@ public class TagCtrl {
@Autowired @Autowired
private TagService tagService; private TagService tagService;
//author:zhangkb time:2020-1-6 desc:修改标签相关接口
@ApiOperation(value = "新增或更新标签", notes = "新增或更新标签") @ApiOperation(value = "新增或更新标签", notes = "新增或更新标签")
@PostMapping(value = "/addOrUpdateTag") @PostMapping(value = "/addOrUpdateTag")
public Tag addTag(@RequestParam(value = "parentId", required = false) String parentId, public Tag addTag(@RequestParam(value = "parentId", required = false) String parentId,
@RequestBody Tag tag) throws Exception { @RequestBody Tag tag) throws Exception {
//获取当前登录用户名和id
String userName = UserInfoUtils.getUserName(); String userName = UserInfoUtils.getUserName();
String userId = UserInfoUtils.getUserId();
//获取当前登录用户所属机构
String org = UserInfoUtils.getDataRoleOrg();
tag.setCreator(userName); tag.setCreator(userName);
tag.setDept(UserInfoUtils.getUserCompanyIdPath()); tag.setTagUser(userId);
tag.setDept(org);
//调用新增或者修改标签接口
return tagService.addOrUpdateTag(parentId, tag, userName); return tagService.addOrUpdateTag(parentId, tag, userName);
} }
...@@ -55,21 +61,13 @@ public class TagCtrl { ...@@ -55,21 +61,13 @@ public class TagCtrl {
return tagService.hasChild(tagId, userName); return tagService.hasChild(tagId, userName);
} }
@ApiOperation(value = "获取维度标签树", notes = "获取维度标签树")
// @PreAuthorize("principal.authorities.?[authority.startsWith('ROLE_tagmanager_admin')].size() > 0")
@ApiOperation(value = "查询系统标签树", notes = "查询系统标签树")
@GetMapping(value = "/querySystemTagAsTree")
public JsonNode[] querySystemTagAsTree(@RequestParam(value = "parentId", required = false) String parentId) throws TagNotExistException {
return tagService.querySystemTagAsTree(parentId);
}
@ApiOperation(value = "查询维度标签树", notes = "查询维度标签树")
@GetMapping(value = "/queryDimensionTagAsTree") @GetMapping(value = "/queryDimensionTagAsTree")
public JsonNode[] queryDimensionTagAsTree( public JsonNode[] queryDimensionTagAsTree(
@RequestParam(value = "parentId", required = false) String parentId, @RequestParam(value = "parentId", required = false) String parentId,
@RequestParam(required = false) String deptIdPath) throws TagNotExistException { @RequestParam(required = false) String deptIdPath) throws TagNotExistException {
if (StringUtils.isBlank(deptIdPath)) //获取当前登录用户机构
deptIdPath = UserInfoUtils.getUserCompanyIdPath(); deptIdPath = UserInfoUtils.getDataRoleOrg();
return tagService.queryDimensionTagAsTree(deptIdPath, parentId); return tagService.queryDimensionTagAsTree(deptIdPath, parentId);
} }
...@@ -78,35 +76,12 @@ public class TagCtrl { ...@@ -78,35 +76,12 @@ public class TagCtrl {
public JsonNode[] queryPersonalTagAsTree( public JsonNode[] queryPersonalTagAsTree(
@RequestParam(value = "parentId", required = false) String parentId, @RequestParam(value = "parentId", required = false) String parentId,
@RequestParam(required = false) String deptIdPath) throws TagNotExistException { @RequestParam(required = false) String deptIdPath) throws TagNotExistException {
if (StringUtils.isBlank(deptIdPath)) //获取当前登录用户机构id
deptIdPath = UserInfoUtils.getUserCompanyIdPath(); deptIdPath = UserInfoUtils.getDataRoleOrg();
String userName = UserInfoUtils.getUserName(); //获取当前登录用户id
return tagService.queryPersonalTagAsTree(parentId, userName, deptIdPath); String userId = UserInfoUtils.getUserId();
} return tagService.queryPersonalTagAsTree(parentId, userId, deptIdPath);
@ApiOperation(value = "查询个人标签树不包括分享的标签", notes = "查询个人标签树不包括分享的标签")
@GetMapping(value = "/queryPersonalTagExcludeOpenTypeAsTree")
public JsonNode[] queryPersonalTagExcludeOpenTypeAsTree(
@RequestParam(value = "parentId", required = false) String parentId,
@RequestParam(required = false) String deptIdPath) throws TagNotExistException {
String userName = UserInfoUtils.getUserName();
if (StringUtils.isBlank(deptIdPath))
deptIdPath = UserInfoUtils.getUserCompanyIdPath();
return tagService.queryPersonalTagExcludeOpenTypeAsTree(parentId, userName, deptIdPath);
}
@ApiOperation(value = "搜索系統标签", notes = "搜索系統标签")
@GetMapping(value = "/searchSystemTagByPage")
public Page searchSystemTagByPage(@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.searchSystemTagByPage(userName, keyword, path, domain, new Page(pageSize, pageNo));
} }
@ApiOperation(value = "搜索维度标签里面的个人标签", notes = "搜索维度标签里面的个人标签") @ApiOperation(value = "搜索维度标签里面的个人标签", notes = "搜索维度标签里面的个人标签")
@GetMapping(value = "/searchPersonalDimensionTagByPage") @GetMapping(value = "/searchPersonalDimensionTagByPage")
public Page searchPersonalDimensionTagByPage( public Page searchPersonalDimensionTagByPage(
...@@ -116,10 +91,10 @@ public class TagCtrl { ...@@ -116,10 +91,10 @@ public class TagCtrl {
@RequestParam(required = false , value = "path") String path, @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.getUserId();
if (StringUtils.isBlank(deptIdPath)) deptIdPath = UserInfoUtils.getDataRoleOrg();
deptIdPath = UserInfoUtils.getUserCompanyIdPath(); return tagService.searchPersonalDimensionTagByPage(userName, deptIdPath, keyword,
return tagService.searchPersonalDimensionTagByPage(userName, deptIdPath, keyword, path, domain, new Page(pageSize, pageNo)); path, domain, new Page(pageSize, pageNo));
} }
@ApiOperation(value = "搜索个人标签", notes = "搜索个人标签") @ApiOperation(value = "搜索个人标签", notes = "搜索个人标签")
...@@ -130,12 +105,51 @@ public class TagCtrl { ...@@ -130,12 +105,51 @@ public class TagCtrl {
@RequestParam(required = false , value = "deptIdPath") String deptIdPath, @RequestParam(required = false , value = "deptIdPath") String deptIdPath,
@RequestParam("pageNo") Integer pageNo, @RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize) { @RequestParam("pageSize") Integer pageSize) {
String userName = UserInfoUtils.getUserName(); String userName = UserInfoUtils.getUserId();
if (StringUtils.isBlank(deptIdPath)) deptIdPath = UserInfoUtils.getDataRoleOrg();
deptIdPath = UserInfoUtils.getUserCompanyIdPath();
return tagService.searchPersonalTagByPage(userName, deptIdPath, keyword, path, domain, new Page(pageSize, pageNo)); return tagService.searchPersonalTagByPage(userName, deptIdPath, keyword, path, domain, new Page(pageSize, pageNo));
} }
// @PreAuthorize("principal.authorities.?[authority.startsWith('ROLE_tagmanager_admin')].size() > 0")
@ApiOperation(value = "查询系统标签树", notes = "查询系统标签树")
@GetMapping(value = "/querySystemTagAsTree")
public JsonNode[] querySystemTagAsTree(@RequestParam(value = "parentId", required = false) String parentId) throws TagNotExistException {
return tagService.querySystemTagAsTree(parentId);
}
@ApiOperation(value = "搜索系統标签", notes = "搜索系統标签")
@GetMapping(value = "/searchSystemTagByPage")
public Page searchSystemTagByPage(@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.getUserId();
return tagService.searchSystemTagByPage(userName, keyword, path, domain, new Page(pageSize, pageNo));
}
@ApiOperation(value = "查询个人标签树不包括分享的标签", notes = "查询个人标签树不包括分享的标签")
@GetMapping(value = "/queryPersonalTagExcludeOpenTypeAsTree")
public JsonNode[] queryPersonalTagExcludeOpenTypeAsTree(
@RequestParam(value = "parentId", required = false) String parentId,
@RequestParam(required = false) String deptIdPath) throws TagNotExistException {
String userName = UserInfoUtils.getUserId();
deptIdPath = UserInfoUtils.getDataRoleOrg();
return tagService.queryPersonalTagExcludeOpenTypeAsTree(parentId, userName, deptIdPath);
}
@ApiOperation(value = "分享标签", notes = "分享标签") @ApiOperation(value = "分享标签", notes = "分享标签")
@PostMapping(value = "/shareTags") @PostMapping(value = "/shareTags")
public void shareTags(@RequestBody List<String> tagIds) throws Exception { public void shareTags(@RequestBody List<String> tagIds) throws Exception {
......
...@@ -27,9 +27,7 @@ public class TagFileCtrl { ...@@ -27,9 +27,7 @@ public class TagFileCtrl {
@GetMapping("/exportTag") @GetMapping("/exportTag")
public int export(HttpServletResponse response, @RequestParam(required = false , value = "deptIdPath") String deptIdPath) { public int export(HttpServletResponse response, @RequestParam(required = false , value = "deptIdPath") String deptIdPath) {
if (StringUtils.isBlank(deptIdPath)) { deptIdPath = UserInfoUtils.getDataRoleOrg();
deptIdPath = UserInfoUtils.getUserCompanyIdPath();
}
return tagExportService.exportExcel(deptIdPath, response); return tagExportService.exportExcel(deptIdPath, response);
} }
...@@ -37,10 +35,9 @@ public class TagFileCtrl { ...@@ -37,10 +35,9 @@ public class TagFileCtrl {
public String importExcel(MultipartFile file, HttpServletResponse response, public String importExcel(MultipartFile file, HttpServletResponse response,
@RequestParam(required = false , value = "deptIdPath") String deptIdPath) throws Exception { @RequestParam(required = false , value = "deptIdPath") String deptIdPath) throws Exception {
String userName = UserInfoUtils.getUserName(); String userName = UserInfoUtils.getUserName();
if (StringUtils.isBlank(deptIdPath)) { String userId = UserInfoUtils.getUserId();
deptIdPath = UserInfoUtils.getUserCompanyIdPath(); deptIdPath = UserInfoUtils.getDataRoleOrg();
} return tagExportService.importExcel(userName, userId, deptIdPath, file);
return tagExportService.importExcel(userName, deptIdPath, file);
} }
@ApiOperation(value = "分页获取导入日志", notes = "分页获取导入日志") @ApiOperation(value = "分页获取导入日志", notes = "分页获取导入日志")
......
...@@ -52,6 +52,9 @@ public class Tag implements Serializable, IExcelModel, IExcelDataModel{ ...@@ -52,6 +52,9 @@ public class Tag implements Serializable, IExcelModel, IExcelDataModel{
private String dept;// 部门 private String dept;// 部门
private String importId;//记录导入的Id,后面撤销用到 private String importId;//记录导入的Id,后面撤销用到
//author:zhangkb time:2020-1-6 desc:添加标签创建对应的用户id,普通用户创建自定义标签有用到
private String tagUser;
public Tag() {} public Tag() {}
public Tag(String name, String desc) { public Tag(String name, String desc) {
...@@ -246,4 +249,12 @@ public class Tag implements Serializable, IExcelModel, IExcelDataModel{ ...@@ -246,4 +249,12 @@ public class Tag implements Serializable, IExcelModel, IExcelDataModel{
this.excelRowNum = rowNum; this.excelRowNum = rowNum;
} }
public String getTagUser() {
return tagUser;
}
public void setTagUser(String tagUser) {
this.tagUser = tagUser;
}
} }
package com.keymobile.tagmanager.model.authService;
/**
* author:zhangkb time:2020-1-6 desc:定义用于接收结构信息实体
*/
public class Org {
private Long id;
private String fullName;
public void setId(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
}
package com.keymobile.tagmanager.remote;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import com.keymobile.tagmanager.model.authService.Org;
@FeignClient(name = "authService")
public interface AuthServiceClient {
@GetMapping(value = "/orgs/{orgId}")
public Org getOrgs(@PathVariable("orgId") String orgId);
@GetMapping(value = "/orgs/findByFullName")
public Org findByFullName(@RequestParam("orgFullName") String orgFullName);
}
...@@ -51,12 +51,12 @@ public class TagFileService { ...@@ -51,12 +51,12 @@ public class TagFileService {
return toExportTags.size(); return toExportTags.size();
} }
public String importExcel(String userName, String dept, MultipartFile file) throws Exception { public String importExcel(String userName, String userId, String dept, MultipartFile file) throws Exception {
ImportLog importLog = new ImportLog(UUID.randomUUID().toString()); ImportLog importLog = new ImportLog(UUID.randomUUID().toString());
importLog.setCreator(userName); importLog.setCreator(userName);
importLog.setDept(dept); importLog.setDept(dept);
mongoOperations.save(importLog); mongoOperations.save(importLog);
new Thread(new ExcelImportExecutor(userName, dept, file, importLog)).start(); new Thread(new ExcelImportExecutor(userName, userId, dept, file, importLog)).start();
return "ok"; return "ok";
} }
...@@ -145,8 +145,11 @@ public class TagFileService { ...@@ -145,8 +145,11 @@ public class TagFileService {
private MultipartFile file; private MultipartFile file;
private ImportLog importLog; private ImportLog importLog;
private String userName; private String userName;
public ExcelImportExecutor(String userName, String dept, MultipartFile file, ImportLog importLog) { private String userId;
public ExcelImportExecutor(String userName, String userId, String dept,
MultipartFile file, ImportLog importLog) {
this.userName = userName; this.userName = userName;
this.userId = userId;
this.dept = dept; this.dept = dept;
this.file = file; this.file = file;
this.importLog = importLog; this.importLog = importLog;
...@@ -195,6 +198,7 @@ public class TagFileService { ...@@ -195,6 +198,7 @@ public class TagFileService {
t.setIdPath(parentIdPath + Constants.TAG_PATH_SEPARATOR + t.getId()); t.setIdPath(parentIdPath + Constants.TAG_PATH_SEPARATOR + t.getId());
t.setLevel(t.getPath().split(",").length); t.setLevel(t.getPath().split(",").length);
t.setCreator(userName); t.setCreator(userName);
t.setTagUser(userId);
t.setDept(dept); t.setDept(dept);
t.setDimensionType(Constants.TAG_DIMENSION_TRUE); t.setDimensionType(Constants.TAG_DIMENSION_TRUE);
t.setCreateDate(DateUtils.formatDate(new Date(), "yyyy-MM-dd")); t.setCreateDate(DateUtils.formatDate(new Date(), "yyyy-MM-dd"));
......
...@@ -24,7 +24,9 @@ import com.keymobile.tagmanager.model.ExtTag; ...@@ -24,7 +24,9 @@ import com.keymobile.tagmanager.model.ExtTag;
import com.keymobile.tagmanager.model.Page; import com.keymobile.tagmanager.model.Page;
import com.keymobile.tagmanager.model.SysTag; import com.keymobile.tagmanager.model.SysTag;
import com.keymobile.tagmanager.model.Tag; import com.keymobile.tagmanager.model.Tag;
import com.keymobile.tagmanager.model.authService.Org;
import com.keymobile.tagmanager.persistence.TagRepository; import com.keymobile.tagmanager.persistence.TagRepository;
import com.keymobile.tagmanager.remote.AuthServiceClient;
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;
...@@ -36,23 +38,28 @@ public class TagService { ...@@ -36,23 +38,28 @@ public class TagService {
private MongoOperations mongoOperations; private MongoOperations mongoOperations;
@Autowired @Autowired
private TagRepository tagRepository; private TagRepository tagRepository;
@Autowired
private AuthServiceClient authService;
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 {
//定义保存原来的id
String originId = tag.getId(); String originId = tag.getId();
if (StringUtils.isNotBlank(parentId)) { if (StringUtils.isNotBlank(parentId)) {//如果新增子节点
Tag parent = getTagById(parentId); //根据父节点id获取对应的父标签
String parentIdPath = parent.getIdPath(); Tag parentTag = getTagById(parentId);
//设置新增标签的idpath和path
String tagId = StringUtils.isNotBlank(originId) ? originId : UUID.randomUUID().toString(); String tagId = StringUtils.isNotBlank(originId) ? originId : UUID.randomUUID().toString();
tag.setId(tagId); tag.setId(tagId);
tag.setIdPath(parentIdPath + Constants.TAG_PATH_SEPARATOR + tagId); tag.setIdPath(parentTag.getIdPath() + Constants.TAG_PATH_SEPARATOR + tagId);
tag.setPath(parent.getPath() + Constants.TAG_PATH_SEPARATOR + tag.getName()); tag.setPath(parentTag.getPath() + Constants.TAG_PATH_SEPARATOR + tag.getName());
} else { }else {//如果是新增根目录
tag.setPath(tag.getName());
String tagId = StringUtils.isNotBlank(originId) ? originId : UUID.randomUUID().toString(); String tagId = StringUtils.isNotBlank(originId) ? originId : UUID.randomUUID().toString();
tag.setId(tagId); tag.setId(tagId);
tag.setIdPath(tagId); tag.setIdPath(tagId);
tag.setPath(tag.getName());
} }
changeNameToAvoidConflict(tag, userName); changeNameToAvoidConflict(tag, userName);
checkTagValid(tag, userName); checkTagValid(tag, userName);
...@@ -72,26 +79,32 @@ public class TagService { ...@@ -72,26 +79,32 @@ public class TagService {
return tagRepository.save(tag); return tagRepository.save(tag);
} }
private void changeNameToAvoidConflict(Tag tag, String userName) { //删除标签
Tag t = mongoOperations.findOne(Query.query(Criteria.where("path").is(tag.getPath()) public void deleteTag(String tagId, String userName) throws TagException {
.and("dept").is(tag.getDept()) Optional<Tag> optional = tagRepository.findById(tagId);
.and("creator").ne(userName)), Tag.class); if (optional.isPresent()) {
if (t != null) { Tag parentTag = optional.get();
String changeName = String.format("%s(%s)", t.getName(), userName); List<Tag> childs = mongoOperations.find(Query.query(createRelationNamepathCriteria(userName,
logger.info(String.format("other creator has create same name in target, change tagName to %s", changeName)); parentTag)), Tag.class);
tag.setName(changeName); if (!childs.isEmpty()) {
tag.setPath(t.getPath().substring(0, t.getPath().lastIndexOf(Constants.TAG_PATH_SEPARATOR)) + t.getName()); throw new TagException("存在子节点,不允许删除!");
}
tagRepository.deleteById(tagId);
} }
} }
private Criteria createRelationNamepathCriteria(String userName, Tag origin) { //判断标签是否有子节点
if (Constants.TAG_DIMENSION_TRUE.equals(origin.getDimensionType())) { public boolean hasChild(String tagId, String userName) throws TagException {
return Criteria.where("path").regex("^" + origin.getPath() + Constants.TAG_PATH_SEPARATOR).and("dept").is(origin.getDept()); Optional<Tag> optional = tagRepository.findById(tagId);
if (optional.isPresent()) {
Tag parentTag = optional.get();
List<Tag> childs = mongoOperations.find(Query.query(createRelationNamepathCriteria(userName, parentTag)), Tag.class);
return !childs.isEmpty();
} }
return Criteria.where("path").regex("^" + origin.getPath() + Constants.TAG_PATH_SEPARATOR) return false;
.and("creator").is(userName);
} }
//根据标签id获取标签
public Tag getTagById(String tagId) throws TagNotExistException { public Tag getTagById(String tagId) throws TagNotExistException {
Tag t = mongoOperations.findOne(Query.query(Criteria.where("_id").is(tagId)), Tag.class); Tag t = mongoOperations.findOne(Query.query(Criteria.where("_id").is(tagId)), Tag.class);
if (t == null) if (t == null)
...@@ -99,101 +112,106 @@ public class TagService { ...@@ -99,101 +112,106 @@ public class TagService {
return t; return t;
} }
//获取维度标签树
private void checkTagValid(Tag tag, String userName) throws TagDuplicateException, TagException { public JsonNode[] queryDimensionTagAsTree(String dept, String parentId) throws TagNotExistException {
if (!Constants.TAG_PERSONAL_TYPE.equals(tag.getTagType())
&& !Constants.TAG_SYSTEM_TYPE.equals(tag.getTagType())) {
throw new TagException(String.format("No such tagType %s", tag.getTagType()));
}
Tag t = mongoOperations.findOne(Query.query(Criteria.where("path").is(tag.getPath())
.and("creator").is(userName)), Tag.class);
if (t != null && !t.getId().equals(tag.getId()))
throw new TagDuplicateException("标签 [" + tag.getName() + "] 已经存在!");
}
public JsonNode[] queryPersonalTagAsTree(String parentId, String userName, String dept) throws TagNotExistException {
List<Tag> tags = new ArrayList<>(); List<Tag> tags = new ArrayList<>();
if (StringUtils.isEmpty(parentId)) { if (StringUtils.isEmpty(parentId)) {//从根节点开始获取
tags = mongoOperations.find(createPersonalTagQuery(userName, dept), Tag.class); tags = mongoOperations.find(createDimensionTagQuery(dept), Tag.class);
} else { } else {
Tag parentTag = getTagById(parentId); Tag parentTag = getTagById(parentId);
tags = getPersonSubTag(parentTag, userName); //获取父节点标签下的所有子标签
tags.forEach(tag -> tag.setPath(tag.getPath().replaceAll(parentTag.getPath(), parentTag.getName()))); tags = getDimensionSubTag(parentTag);
//tags.forEach(tag -> tag.setPath(tag.getPath().replaceAll(parentTag.getPath(), parentTag.getName())));
} }
List<JsonNode> nodes = new ArrayList<>(); List<JsonNode> nodes = new ArrayList<>();
tags.forEach(p -> { tags.forEach(p -> {
JsonNode node = new JsonNode(p.getPath(), p.getId(), p.getPath(), p.getIdPath()); JsonNode node = new JsonNode(p.getPath(), p.getId(), p.getPath(), p.getIdPath());
nodes.add(node); nodes.add(node);
}); });
//自定拼接成树结构
JsonNode root = JsonTreeHelper.toJsonTree(nodes, Constants.TAG_PATH_SEPARATOR); JsonNode root = JsonTreeHelper.toJsonTree(nodes, Constants.TAG_PATH_SEPARATOR);
if (root.children != null) if (root.children != null) {
return root.children; return root.children;
else }
else {
return new JsonNode[] {}; return new JsonNode[] {};
} }
private Query createPersonalTagQuery(String userName, String dept, Criteria... serachCriterias) {
return Query.query(
createPersonalTagCriteria(userName, dept, null))
.with(Sort.by(getDefaultTagOrders()));
} }
private Criteria createPersonalTagCriteria(String userName, String dept, String path) { //获取个人标签树
Criteria criteria = Criteria.where("tagType").is(Constants.TAG_PERSONAL_TYPE) public JsonNode[] queryPersonalTagAsTree(String parentId, String userId,
.and("dept").is(dept); String dept)
if (StringUtils.isNotBlank(path)) { throws TagNotExistException{
criteria = criteria.and("path").regex("^"+path);; List<Tag> tags = new ArrayList<>();
} //根据用户机构id获取机构信息
return criteria.orOperator( Org org = authService.getOrgs(dept);
Criteria.where("dimensionType").is(Constants.TAG_DIMENSION_TRUE), if(org==null) {
Criteria.where("isOpen").is(Constants.TAG_OPEN_STATUS), throw new TagNotExistException("get org by id error;");
Criteria.where("creator").is(userName)); }
//获取机构fullname
String fullname = org.getFullName();
//分隔fullname
String[] fullnames = fullname.split(",");
//如果fullname没有两层结构
if(fullnames.length<2) {
throw new TagNotExistException("get org by id the fullname:"+fullname+" at least 2 level;");
}
String companyPath = fullnames[0]+Constants.TAG_PATH_SEPARATOR+fullnames[1];
//根据companyPath获取机构信息
Org companyOrg = authService.findByFullName(companyPath);
if(companyOrg==null) {
throw new TagNotExistException("get company org by fullname is null;");
}
String companyOrgId = String.valueOf(companyOrg.getId());
if (StringUtils.isEmpty(parentId)) {//从根目录开始查找
//
tags = mongoOperations.find(this.createNewPersonalTagQuery(userId, dept, companyOrgId), Tag.class);
}else {
Tag parentTag = getTagById(parentId);
tags = this.getNewPersonSubTag(parentTag, userId, dept, companyOrgId);
} }
List<JsonNode> nodes = new ArrayList<>();
private Criteria createSystemTagCriteria(String path) { tags.forEach(p -> {
Criteria criteria = Criteria.where("tagType").is(Constants.TAG_SYSTEM_TYPE); JsonNode node = new JsonNode(p.getPath(), p.getId(), p.getPath(), p.getIdPath());
if (StringUtils.isNotBlank(path)) { nodes.add(node);
return criteria.and("path").regex("^"+path); });
JsonNode root = JsonTreeHelper.toJsonTree(nodes, Constants.TAG_PATH_SEPARATOR);
if (root.children != null) {
return root.children;
}else {
return new JsonNode[] {};
} }
return criteria;
} }
private Criteria createPersonalDimensionTagCriteria(String userName, String dept) { //根据关键字查询维度标签数据
return Criteria.where("tagType").is(Constants.TAG_PERSONAL_TYPE) public Page searchPersonalDimensionTagByPage(String userName, String dept, String keyword, String path, Integer domain, Page page) {
.and("dept").is(dept).and("dimensionType").is(Constants.TAG_DIMENSION_TRUE); Criteria andCriterias = createPersonalDimensionTagCriteria(userName, dept);
if (StringUtils.isNotBlank(keyword) && !"*".equals(keyword)) {
andCriterias.andOperator(createKeywordRegexQuery(Arrays.asList("name", "nameEn", "desc"), keyword));
} }
Query q = createPageQuery(page, andCriterias);
List<Tag> tags = mongoOperations.find(q, Tag.class);
private Query createPersonalExcludeOpenTypeTagQuery(String userName, String dept) { long count = mongoOperations.count(q, Tag.class);
return Query.query(Criteria.where("tagType").is(Constants.TAG_PERSONAL_TYPE) page.setData(decoratorToExtTag(tags, userName));
.and("dept").is(dept) page.setTotal(count);
.orOperator( return page;
Criteria.where("dimensionType").is(Constants.TAG_DIMENSION_TRUE),
Criteria.where("creator").is(userName)))
.with(Sort.by(getDefaultTagOrders()));
} }
private List<Order> getDefaultTagOrders() { //根据关键字查找系统标签
List<Order> orders = new ArrayList<>(); public Page searchSystemTagByPage(String userName, String keyword, String path, Integer domain, Page page) {
orders.add(new Order(Direction.ASC, "level")); Criteria andCriterias = createSystemTagCriteria(path);
orders.add(new Order(Direction.DESC, "order")); if (StringUtils.isNotBlank(keyword) && !"*".equals(keyword)) {
return orders; andCriterias.andOperator(createKeywordRegexQuery(Arrays.asList("name", "nameEn", "desc"), keyword));
} }
Query q = createPageQuery(page, andCriterias);
public List<Tag> getPersonSubTag(Tag parentTag, String userName) { List<Tag> tags = mongoOperations.find(q, Tag.class);
List<Tag> dirs = mongoOperations.find(new Query().addCriteria(Criteria.where("path") long count = mongoOperations.count(q, Tag.class);
.regex("^"+parentTag.getPath() + Constants.TAG_PATH_SEPARATOR) page.setData(decoratorToExtTag(tags, userName));
.and("tagType").is(Constants.TAG_PERSONAL_TYPE) page.setTotal(count);
.orOperator( return page;
Criteria.where("openStatus").is(Constants.TAG_OPEN_STATUS),
Criteria.where("creator").is(userName)))
.with(Sort.by(getDefaultTagOrders())), Tag.class);
dirs.add(parentTag);
return dirs;
} }
//根据关键字查找个人标签
public Page searchPersonalTagByPage(String userName, String dept, String keyword, String path, Integer domain, Page page) { public Page searchPersonalTagByPage(String userName, String dept, String keyword, String path, Integer domain, Page page) {
Criteria andCriterias = createPersonalTagCriteria(userName, dept, path); Criteria andCriterias = createPersonalTagCriteria(userName, dept, path);
if (StringUtils.isNotBlank(keyword) && !"*".equals(keyword)) { if (StringUtils.isNotBlank(keyword) && !"*".equals(keyword)) {
...@@ -202,26 +220,14 @@ public class TagService { ...@@ -202,26 +220,14 @@ public class TagService {
Query q = new Query(andCriterias); Query q = new Query(andCriterias);
q.skip(page.getOffset()); q.skip(page.getOffset());
q.limit(page.getPageSize()); q.limit(page.getPageSize());
List<Tag> tags = mongoOperations List<Tag> tags = mongoOperations.find(q, Tag.class);
.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));
page.setTotal(count); page.setTotal(count);
return page; return page;
}
private Criteria createKeywordRegexQuery(List<String> asList, String keyword) {
Criteria criteriaSearch = new Criteria();
return criteriaSearch.orOperator(asList.stream().map(col -> {
return Criteria.where(col).regex(keyword, "i");
}).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)) {
...@@ -230,7 +236,7 @@ public class TagService { ...@@ -230,7 +236,7 @@ public class TagService {
} else { } else {
Tag parentTag = getTagById(parentId); Tag parentTag = getTagById(parentId);
tags = getSystemSubTag(parentTag); tags = getSystemSubTag(parentTag);
tags.forEach(tag -> tag.setPath(tag.getPath().replaceAll(parentTag.getPath(), parentTag.getName()))); //tags.forEach(tag -> tag.setPath(tag.getPath().replaceAll(parentTag.getPath(), parentTag.getName())));
} }
List<JsonNode> nodes = new ArrayList<>(); List<JsonNode> nodes = new ArrayList<>();
tags.forEach(p -> { tags.forEach(p -> {
...@@ -244,19 +250,155 @@ public class TagService { ...@@ -244,19 +250,155 @@ public class TagService {
return new JsonNode[] {}; return new JsonNode[] {};
} }
public Page searchSystemTagByPage(String userName, String keyword, String path, Integer domain, Page page) { //获取新增个人标签加载上级标签树接口
Criteria andCriterias = createSystemTagCriteria(path); public JsonNode[] queryPersonalTagExcludeOpenTypeAsTree(String parentId, String userName, String dept) throws TagNotExistException {
if (StringUtils.isNotBlank(keyword) && !"*".equals(keyword)) { List<Tag> tags = new ArrayList<>();
andCriterias.andOperator(createKeywordRegexQuery(Arrays.asList("name", "nameEn", "desc"), keyword)); //根据普通用户机构id获取机构信息
Org org = authService.getOrgs(dept);
if(org==null) {
throw new TagNotExistException("get org by id error;");
}
//获取机构fullname
String fullname = org.getFullName();
//分隔fullname
String[] fullnames = fullname.split(",");
//如果fullname没有两层结构
if(fullnames.length<2) {
throw new TagNotExistException("get org by id the fullname:"+fullname+" at least 2 level;");
}
String companyPath = fullnames[0]+Constants.TAG_PATH_SEPARATOR+fullnames[1];
//根据companyPath获取机构信息
Org companyOrg = authService.findByFullName(companyPath);
if(companyOrg==null) {
throw new TagNotExistException("get company org by fullname is null;");
}
String companyOrgId = String.valueOf(companyOrg.getId());
if (StringUtils.isEmpty(parentId)) {
tags = mongoOperations.find(createPersonalExcludeOpenTypeTagQuery(userName, companyOrgId), Tag.class);
} }
Query q = createPageQuery(page, andCriterias); /**else {
List<Tag> tags = mongoOperations.find(q, Tag.class); Tag parentTag = getTagById(parentId);
long count = mongoOperations.count(q, Tag.class); tags = getPersonSubTag(parentTag, userName);
page.setData(decoratorToExtTag(tags, userName)); //tags.forEach(tag -> tag.setPath(tag.getPath().replaceAll(parentTag.getPath(), parentTag.getName())));
page.setTotal(count); }*/
return page; List<JsonNode> nodes = new ArrayList<>();
tags.forEach(p -> {
JsonNode node = new JsonNode(p.getPath(), p.getId(), p.getPath(), p.getIdPath());
nodes.add(node);
});
JsonNode root = JsonTreeHelper.toJsonTree(nodes, Constants.TAG_PATH_SEPARATOR);
if (root.children != null) {
return root.children;
}
else {
return new JsonNode[] {};
}
}
//如果标签存在冲突,修改当前标签名字和路径
private void changeNameToAvoidConflict(Tag tag, String userName) {
Tag t = mongoOperations.findOne(Query.query(Criteria.where("path").is(tag.getPath())
.and("dept").is(tag.getDept())
.and("creator").ne(userName)), Tag.class);
if (t != null) {
String changeName = String.format("%s(%s)", t.getName(), userName);
logger.info(String.format("other creator has create same name in target, change tagName to %s", changeName));
tag.setName(changeName);
tag.setPath(t.getPath().substring(0, t.getPath().lastIndexOf(Constants.TAG_PATH_SEPARATOR)) + t.getName());
}
}
//拼接path和username的查询条件
private Criteria createRelationNamepathCriteria(String userName, Tag origin) {
if (Constants.TAG_DIMENSION_TRUE.equals(origin.getDimensionType())) {
return Criteria.where("path").regex("^" + origin.getPath() + Constants.TAG_PATH_SEPARATOR).and("dept").is(origin.getDept());
}
return Criteria.where("path").regex("^" + origin.getPath() + Constants.TAG_PATH_SEPARATOR)
.and("creator").is(userName);
}
//判断标签是否已经存在
private void checkTagValid(Tag tag, String userName) throws TagDuplicateException, TagException {
if (!Constants.TAG_PERSONAL_TYPE.equals(tag.getTagType())
&& !Constants.TAG_SYSTEM_TYPE.equals(tag.getTagType())) {
throw new TagException(String.format("No such tagType %s", tag.getTagType()));
} }
Tag t = mongoOperations.findOne(Query.query(Criteria.where("path").is(tag.getPath())
.and("creator").is(userName)), Tag.class);
if (t != null && !t.getId().equals(tag.getId()))
throw new TagDuplicateException("标签 [" + tag.getName() + "] 已经存在!");
}
//拼接个人维度标签树查询条件
private Query createDimensionTagQuery(String dept) {
return Query.query(Criteria.where("dimensionType").is(Constants.TAG_DIMENSION_TRUE)
.and("tagType").is(Constants.TAG_PERSONAL_TYPE)
.and("dept").is(dept))
.with(Sort.by(getDefaultTagOrders()));
}
//根据机构获取当前维度标签的所有子标签
private List<Tag> getDimensionSubTag(Tag parentTag) {
List<Tag> dirs = mongoOperations.find(new Query().addCriteria(Criteria.where("path")
.regex("^"+parentTag.getPath() + Constants.TAG_PATH_SEPARATOR)
.and("dimensionType").is(Constants.TAG_DIMENSION_TRUE)
.and("dept").is(parentTag.getDept()))
.with(Sort.by(getDefaultTagOrders())), Tag.class);
dirs.add(parentTag);
return dirs;
}
//拼接默认配许条件
private List<Order> getDefaultTagOrders() {
List<Order> orders = new ArrayList<>();
orders.add(new Order(Direction.ASC, "level"));
orders.add(new Order(Direction.DESC, "order"));
return orders;
}
//拼接查找个人标签条件
private Query createNewPersonalTagQuery(String userId,String deptId,
String companyId) {
Criteria criteria = Criteria.where("tagType").is("1");//获取自定义标签
criteria.orOperator(
Criteria.where("dept").is(companyId),//标签是维度管理员机构的
Criteria.where("dept").is(deptId).and("tagUser").is(userId)//标签是普通用户结构且普通用户名创建
/**,Criteria.where("path").regex("^"+companyPath + Constants.TAG_PATH_SEPARATOR)
.and("isOpen").is(Constants.TAG_OPEN_STATUS)*/);//标签是维度标签路径下的
return Query.query(criteria)
.with(Sort.by(getDefaultTagOrders()));
}
//根据父标签查找子标签
private List<Tag> getNewPersonSubTag(Tag parentTag, String userId,String deptId,
String companyId) {
List<Tag> dirs = mongoOperations.find(new Query().addCriteria(Criteria.where("path")
.regex("^"+parentTag.getPath() + Constants.TAG_PATH_SEPARATOR)
.and("tagType").is(Constants.TAG_PERSONAL_TYPE)
.orOperator(
Criteria.where("dept").is(companyId),//标签是维度管理员机构的
Criteria.where("dept").is(deptId).and("tagUser").is(userId)//标签是普通用户结构且普通用户名创建
)).with(Sort.by(getDefaultTagOrders())), Tag.class);
dirs.add(parentTag);
return dirs;
}
//拼接关键子查询字段
private Criteria createKeywordRegexQuery(List<String> asList, String keyword) {
Criteria criteriaSearch = new Criteria();
return criteriaSearch.orOperator(asList.stream().map(col -> {
return Criteria.where(col).regex(keyword, "i");
}).collect(Collectors.toList()).toArray(new Criteria[0]));
}
//拼接根据机构id查询个人维度标签
private Criteria createPersonalDimensionTagCriteria(String userName, String dept) {
return Criteria.where("tagType").is(Constants.TAG_PERSONAL_TYPE)
.and("dept").is(dept).and("dimensionType").is(Constants.TAG_DIMENSION_TRUE);
}
//拼接查找系统标签条件
private Criteria createSystemTagCriteria(String path) {
Criteria criteria = Criteria.where("tagType").is(Constants.TAG_SYSTEM_TYPE);
if (StringUtils.isNotBlank(path)) {
return criteria.and("path").regex("^"+path);
}
return criteria;
}
//拼接分页查找条件
private Query createPageQuery(Page page, Criteria andCriterias) { private Query createPageQuery(Page page, Criteria andCriterias) {
Query q = new Query(andCriterias); Query q = new Query(andCriterias);
q.skip(page.getOffset()); q.skip(page.getOffset());
...@@ -264,14 +406,26 @@ public class TagService { ...@@ -264,14 +406,26 @@ public class TagService {
q.with(Sort.by(getDefaultTagOrders())); q.with(Sort.by(getDefaultTagOrders()));
return q; return q;
} }
//根据用户id标识该标签能否被操作
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()*/t.getTagUser().equals(userName) ?
Constants.TAG_OPERABLE_FALSE); Constants.TAG_OPERABLE_TRUE : Constants.TAG_OPERABLE_FALSE);
}).collect(Collectors.toList()); }).collect(Collectors.toList());
} }
//拼接个人标签查询条件
private Criteria createPersonalTagCriteria(String userName, String dept, String path) {
Criteria criteria = Criteria.where("tagType").is(Constants.TAG_PERSONAL_TYPE)
.and("dept").is(dept).and("tagUser").is(userName);
if (StringUtils.isNotBlank(path)) {
criteria = criteria.and("path").regex("^"+path);;
}
return criteria/**.orOperator(
Criteria.where("dimensionType").is(Constants.TAG_DIMENSION_TRUE),
Criteria.where("isOpen").is(Constants.TAG_OPEN_STATUS),
Criteria.where("creator").is(userName))*/;
}
//拼接查询当前系统标签子标签条件
private List<Tag> getSystemSubTag(Tag parentTag) { private List<Tag> getSystemSubTag(Tag parentTag) {
List<Tag> dirs = mongoOperations.find(new Query().addCriteria(Criteria.where("path") List<Tag> dirs = mongoOperations.find(new Query().addCriteria(Criteria.where("path")
.regex("^"+parentTag.getPath() + Constants.TAG_PATH_SEPARATOR) .regex("^"+parentTag.getPath() + Constants.TAG_PATH_SEPARATOR)
...@@ -280,111 +434,95 @@ public class TagService { ...@@ -280,111 +434,95 @@ public class TagService {
dirs.add(parentTag); dirs.add(parentTag);
return dirs; return dirs;
} }
//拼接获取维度标签条件
public void deleteTag(String tagId, String userName) throws TagException { private Query createPersonalExcludeOpenTypeTagQuery(String userName, String dept) {
Optional<Tag> optional = tagRepository.findById(tagId); return Query.query(Criteria.where("tagType").is(Constants.TAG_PERSONAL_TYPE)
if (optional.isPresent()) { .and("dept").is(dept).and("dimensionType").is(Constants.TAG_DIMENSION_TRUE))
Tag parentTag = optional.get(); .with(Sort.by(getDefaultTagOrders()));
List<Tag> childs = mongoOperations.find(Query.query(createRelationNamepathCriteria(userName, parentTag)), Tag.class);
if (!childs.isEmpty()) {
throw new TagException("存在子节点,不允许删除!");
}
tagRepository.deleteById(tagId);
}
} }
public boolean hasChild(String tagId, String userName) throws TagException {
Optional<Tag> optional = tagRepository.findById(tagId);
if (optional.isPresent()) {
Tag parentTag = optional.get();
List<Tag> childs = mongoOperations.find(Query.query(createRelationNamepathCriteria(userName, parentTag)), Tag.class);
return !childs.isEmpty();
}
return false;
}
public void shareTags(List<String> tagIds) {
Iterable<Tag> tags = tagRepository.findAllById(tagIds);
tags.forEach(t -> {
t.setIsOpen(Constants.TAG_OPEN_STATUS);
});
tagRepository.saveAll(tags);
}
public JsonNode[] queryDimensionTagAsTree(String dept, String parentId) throws TagNotExistException {
List<Tag> tags = new ArrayList<>();
if (StringUtils.isEmpty(parentId)) {
tags = mongoOperations.find(createDimensionTagQuery(dept), Tag.class);
} else {
Tag parentTag = getTagById(parentId);
tags = getDimensionSubTag(parentTag); // public JsonNode[] queryPersonalTagAsTree(String parentId, String userName, String dept) throws TagNotExistException {
tags.forEach(tag -> tag.setPath(tag.getPath().replaceAll(parentTag.getPath(), parentTag.getName()))); // List<Tag> tags = new ArrayList<>();
} // if (StringUtils.isEmpty(parentId)) {
List<JsonNode> nodes = new ArrayList<>(); // tags = mongoOperations.find(createPersonalTagQuery(userName, dept), Tag.class);
tags.forEach(p -> { // } else {
JsonNode node = new JsonNode(p.getPath(), p.getId(), p.getPath(), p.getIdPath()); // Tag parentTag = getTagById(parentId);
nodes.add(node); // tags = getPersonSubTag(parentTag, userName);
}); // tags.forEach(tag -> tag.setPath(tag.getPath().replaceAll(parentTag.getPath(), parentTag.getName())));
JsonNode root = JsonTreeHelper.toJsonTree(nodes, Constants.TAG_PATH_SEPARATOR); // }
if (root.children != null) // List<JsonNode> nodes = new ArrayList<>();
return root.children; // tags.forEach(p -> {
else // JsonNode node = new JsonNode(p.getPath(), p.getId(), p.getPath(), p.getIdPath());
return new JsonNode[] {}; // nodes.add(node);
// });
// JsonNode root = JsonTreeHelper.toJsonTree(nodes, Constants.TAG_PATH_SEPARATOR);
// if (root.children != null)
// return root.children;
// else
// return new JsonNode[] {};
// }
private Query createPersonalTagQuery(String userName, String dept, Criteria... serachCriterias) {
return Query.query(
createPersonalTagCriteria(userName, dept, null))
.with(Sort.by(getDefaultTagOrders()));
} }
private List<Tag> getDimensionSubTag(Tag parentTag) {
public List<Tag> getPersonSubTag(Tag parentTag, String userName) {
List<Tag> dirs = mongoOperations.find(new Query().addCriteria(Criteria.where("path") List<Tag> dirs = mongoOperations.find(new Query().addCriteria(Criteria.where("path")
.regex("^"+parentTag.getPath() + Constants.TAG_PATH_SEPARATOR) .regex("^"+parentTag.getPath() + Constants.TAG_PATH_SEPARATOR)
.and("dimensionType").is(Constants.TAG_DIMENSION_TRUE) .and("tagType").is(Constants.TAG_PERSONAL_TYPE)
.and("dept").is(parentTag.getDept())) .orOperator(
Criteria.where("openStatus").is(Constants.TAG_OPEN_STATUS),
Criteria.where("creator").is(userName)))
.with(Sort.by(getDefaultTagOrders())), Tag.class); .with(Sort.by(getDefaultTagOrders())), Tag.class);
dirs.add(parentTag); dirs.add(parentTag);
return dirs; return dirs;
} }
private Query createDimensionTagQuery(String dept) {
return Query.query(Criteria.where("dimensionType").is(Constants.TAG_DIMENSION_TRUE)
.and("tagType").is(Constants.TAG_PERSONAL_TYPE)
.and("dept").is(dept))
.with(Sort.by(getDefaultTagOrders()));
}
public JsonNode[] queryPersonalTagExcludeOpenTypeAsTree(String parentId, String userName, String dept) throws TagNotExistException {
List<Tag> tags = new ArrayList<>();
if (StringUtils.isEmpty(parentId)) {
tags = mongoOperations.find(createPersonalExcludeOpenTypeTagQuery(userName, dept), Tag.class);
} else {
Tag parentTag = getTagById(parentId);
tags = getPersonSubTag(parentTag, userName);
tags.forEach(tag -> tag.setPath(tag.getPath().replaceAll(parentTag.getPath(), parentTag.getName())));
}
List<JsonNode> nodes = new ArrayList<>();
tags.forEach(p -> {
JsonNode node = new JsonNode(p.getPath(), p.getId(), p.getPath(), p.getIdPath());
nodes.add(node);
});
JsonNode root = JsonTreeHelper.toJsonTree(nodes, Constants.TAG_PATH_SEPARATOR);
if (root.children != null)
return root.children;
else
return new JsonNode[] {};
}
public Page searchPersonalDimensionTagByPage(String userName, String dept, String keyword, String path, Integer domain, Page page) { private Criteria createPathRegexQuery(String path) {
Criteria andCriterias = createPersonalDimensionTagCriteria(userName, dept); return Criteria.where("path").regex("^"+path);
if (StringUtils.isNotBlank(keyword) && !"*".equals(keyword)) {
andCriterias.andOperator(createKeywordRegexQuery(Arrays.asList("name", "nameEn", "desc"), keyword));
} }
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;
public void shareTags(List<String> tagIds) {
Iterable<Tag> tags = tagRepository.findAllById(tagIds);
tags.forEach(t -> {
t.setIsOpen(Constants.TAG_OPEN_STATUS);
});
tagRepository.saveAll(tags);
} }
public List<SysTag> listSysTags() { public List<SysTag> listSysTags() {
return mongoOperations.findAll(SysTag.class); return mongoOperations.findAll(SysTag.class);
} }
......
package com.keymobile.tagmanager.util; package com.keymobile.tagmanager.util;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
...@@ -38,10 +43,6 @@ public class UserInfoUtils { ...@@ -38,10 +43,6 @@ public class UserInfoUtils {
return domainIds; return domainIds;
} }
public static String getUserName() {
return SecurityContextHolder.getContext().getAuthentication().getName().split(":")[0];
}
public static String getUserCompanyIdPath() { public static String getUserCompanyIdPath() {
if (SecurityContextHolder.getContext().getAuthentication().getName().split(":").length > 5) { if (SecurityContextHolder.getContext().getAuthentication().getName().split(":").length > 5) {
String deptIdPath = SecurityContextHolder.getContext().getAuthentication().getName().split(":")[5]; String deptIdPath = SecurityContextHolder.getContext().getAuthentication().getName().split(":")[5];
...@@ -67,8 +68,34 @@ public class UserInfoUtils { ...@@ -67,8 +68,34 @@ public class UserInfoUtils {
// return SecurityContextHolder.getContext().getAuthentication().getName().split(":")[5]; // return SecurityContextHolder.getContext().getAuthentication().getName().split(":")[5];
// } // }
public static Integer getUserId() { //author:zhangkb time:2020-1-6 desc:添加标签用到获取session属性接口
return Integer.valueOf(SecurityContextHolder.getContext().getAuthentication().getName().split(":")[1]); public static String getUserName() {
return SecurityContextHolder.getContext().getAuthentication().getName().split(":")[0];
}
public static String getUserId() {
return SecurityContextHolder.getContext().getAuthentication().getName().split(":")[1];
}
//获取当前用户所属机构(id:name)
public static String[] getUserOrg() {
GrantedAuthority userOrg = SecurityContextHolder.getContext().getAuthentication().getAuthorities().stream()
.filter(auth -> auth.getAuthority().contains("USER_ORG_")).findFirst().get();
if (userOrg == null) {
return null;
} else {
String[] userOrgParts = userOrg.getAuthority().split(":");
return new String[] { userOrgParts[0].substring("USER_ORG_".length()), userOrgParts[1] };
}
} }
public static String getDataRoleOrg() {
GrantedAuthority dataRoleOrg = SecurityContextHolder.getContext().getAuthentication().getAuthorities().stream()
.filter(auth -> auth.getAuthority().contains("USER_DATA_ROLE_ORG_")).findFirst().get();
if (dataRoleOrg == null) {
return null;
} else {
return dataRoleOrg.getAuthority().substring("USER_DATA_ROLE_ORG_".length());
}
}
} }
mongodb:
database: tagManagerCGN_dev
uri: dev-vm-00:27017
username: root
password: dataPlatform
maxConnectionIdleTime: 120000
eureka:
client:
registryFetchIntervalSeconds: 5
region: default
serviceUrl:
defaultZone: http://dev-vm-22:8081/eureka/
instance:
prefer-ip-address: false
hostname: 192.168.0.109
spring:
application:
name: tagManager
session:
store-type: redis
redis:
namespace: cgn2
redis:
host: dev-vm-00
port: 6379
datasource:
url: jdbc:mysql://dev-vm-00:3306/cgn2_dev?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8
username: test
password: test
hikari:
maximum-pool-size: 3
server:
port: 8072
#security permit true :permitAll ;flase:authenticated
security:
authUser: root
authPwd: pwd
permit: false
feign:
client:
config:
default:
ReadTimeout: 30000
ConnectTimeout: 30000
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