Commit 10ed975e by zhangkb

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

parent 3ff544a8
......@@ -30,14 +30,20 @@ public class TagCtrl {
@Autowired
private TagService tagService;
//author:zhangkb time:2020-1-6 desc:修改标签相关接口
@ApiOperation(value = "新增或更新标签", notes = "新增或更新标签")
@PostMapping(value = "/addOrUpdateTag")
public Tag addTag(@RequestParam(value = "parentId", required = false) String parentId,
@RequestBody Tag tag) throws Exception {
//获取当前登录用户名和id
String userName = UserInfoUtils.getUserName();
String userId = UserInfoUtils.getUserId();
//获取当前登录用户所属机构
String org = UserInfoUtils.getDataRoleOrg();
tag.setCreator(userName);
tag.setDept(UserInfoUtils.getUserCompanyIdPath());
tag.setTagUser(userId);
tag.setDept(org);
//调用新增或者修改标签接口
return tagService.addOrUpdateTag(parentId, tag, userName);
}
......@@ -55,21 +61,13 @@ public class TagCtrl {
return tagService.hasChild(tagId, userName);
}
// @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 = "查询维度标签树")
@ApiOperation(value = "获取维度标签树", notes = "获取维度标签树")
@GetMapping(value = "/queryDimensionTagAsTree")
public JsonNode[] queryDimensionTagAsTree(
@RequestParam(value = "parentId", required = false) String parentId,
@RequestParam(required = false) String deptIdPath) throws TagNotExistException {
if (StringUtils.isBlank(deptIdPath))
deptIdPath = UserInfoUtils.getUserCompanyIdPath();
//获取当前登录用户机构
deptIdPath = UserInfoUtils.getDataRoleOrg();
return tagService.queryDimensionTagAsTree(deptIdPath, parentId);
}
......@@ -78,35 +76,12 @@ public class TagCtrl {
public JsonNode[] queryPersonalTagAsTree(
@RequestParam(value = "parentId", required = false) String parentId,
@RequestParam(required = false) String deptIdPath) throws TagNotExistException {
if (StringUtils.isBlank(deptIdPath))
deptIdPath = UserInfoUtils.getUserCompanyIdPath();
String userName = UserInfoUtils.getUserName();
return tagService.queryPersonalTagAsTree(parentId, userName, 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));
//获取当前登录用户机构id
deptIdPath = UserInfoUtils.getDataRoleOrg();
//获取当前登录用户id
String userId = UserInfoUtils.getUserId();
return tagService.queryPersonalTagAsTree(parentId, userId, deptIdPath);
}
@ApiOperation(value = "搜索维度标签里面的个人标签", notes = "搜索维度标签里面的个人标签")
@GetMapping(value = "/searchPersonalDimensionTagByPage")
public Page searchPersonalDimensionTagByPage(
......@@ -116,10 +91,10 @@ public class TagCtrl {
@RequestParam(required = false , value = "path") String path,
@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize) {
String userName = UserInfoUtils.getUserName();
if (StringUtils.isBlank(deptIdPath))
deptIdPath = UserInfoUtils.getUserCompanyIdPath();
return tagService.searchPersonalDimensionTagByPage(userName, deptIdPath, keyword, path, domain, new Page(pageSize, pageNo));
String userName = UserInfoUtils.getUserId();
deptIdPath = UserInfoUtils.getDataRoleOrg();
return tagService.searchPersonalDimensionTagByPage(userName, deptIdPath, keyword,
path, domain, new Page(pageSize, pageNo));
}
@ApiOperation(value = "搜索个人标签", notes = "搜索个人标签")
......@@ -130,12 +105,51 @@ public class TagCtrl {
@RequestParam(required = false , value = "deptIdPath") String deptIdPath,
@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize) {
String userName = UserInfoUtils.getUserName();
if (StringUtils.isBlank(deptIdPath))
deptIdPath = UserInfoUtils.getUserCompanyIdPath();
String userName = UserInfoUtils.getUserId();
deptIdPath = UserInfoUtils.getDataRoleOrg();
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 = "分享标签")
@PostMapping(value = "/shareTags")
public void shareTags(@RequestBody List<String> tagIds) throws Exception {
......
......@@ -27,9 +27,7 @@ public class TagFileCtrl {
@GetMapping("/exportTag")
public int export(HttpServletResponse response, @RequestParam(required = false , value = "deptIdPath") String deptIdPath) {
if (StringUtils.isBlank(deptIdPath)) {
deptIdPath = UserInfoUtils.getUserCompanyIdPath();
}
deptIdPath = UserInfoUtils.getDataRoleOrg();
return tagExportService.exportExcel(deptIdPath, response);
}
......@@ -37,10 +35,9 @@ public class TagFileCtrl {
public String importExcel(MultipartFile file, HttpServletResponse response,
@RequestParam(required = false , value = "deptIdPath") String deptIdPath) throws Exception {
String userName = UserInfoUtils.getUserName();
if (StringUtils.isBlank(deptIdPath)) {
deptIdPath = UserInfoUtils.getUserCompanyIdPath();
}
return tagExportService.importExcel(userName, deptIdPath, file);
String userId = UserInfoUtils.getUserId();
deptIdPath = UserInfoUtils.getDataRoleOrg();
return tagExportService.importExcel(userName, userId, deptIdPath, file);
}
@ApiOperation(value = "分页获取导入日志", notes = "分页获取导入日志")
......
......@@ -52,6 +52,9 @@ public class Tag implements Serializable, IExcelModel, IExcelDataModel{
private String dept;// 部门
private String importId;//记录导入的Id,后面撤销用到
//author:zhangkb time:2020-1-6 desc:添加标签创建对应的用户id,普通用户创建自定义标签有用到
private String tagUser;
public Tag() {}
public Tag(String name, String desc) {
......@@ -246,4 +249,12 @@ public class Tag implements Serializable, IExcelModel, IExcelDataModel{
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 {
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.setCreator(userName);
importLog.setDept(dept);
mongoOperations.save(importLog);
new Thread(new ExcelImportExecutor(userName, dept, file, importLog)).start();
new Thread(new ExcelImportExecutor(userName, userId, dept, file, importLog)).start();
return "ok";
}
......@@ -145,8 +145,11 @@ public class TagFileService {
private MultipartFile file;
private ImportLog importLog;
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.userId = userId;
this.dept = dept;
this.file = file;
this.importLog = importLog;
......@@ -195,6 +198,7 @@ public class TagFileService {
t.setIdPath(parentIdPath + Constants.TAG_PATH_SEPARATOR + t.getId());
t.setLevel(t.getPath().split(",").length);
t.setCreator(userName);
t.setTagUser(userId);
t.setDept(dept);
t.setDimensionType(Constants.TAG_DIMENSION_TRUE);
t.setCreateDate(DateUtils.formatDate(new Date(), "yyyy-MM-dd"));
......
package com.keymobile.tagmanager.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
......@@ -38,10 +43,6 @@ public class UserInfoUtils {
return domainIds;
}
public static String getUserName() {
return SecurityContextHolder.getContext().getAuthentication().getName().split(":")[0];
}
public static String getUserCompanyIdPath() {
if (SecurityContextHolder.getContext().getAuthentication().getName().split(":").length > 5) {
String deptIdPath = SecurityContextHolder.getContext().getAuthentication().getName().split(":")[5];
......@@ -67,8 +68,34 @@ public class UserInfoUtils {
// return SecurityContextHolder.getContext().getAuthentication().getName().split(":")[5];
// }
public static Integer getUserId() {
return Integer.valueOf(SecurityContextHolder.getContext().getAuthentication().getName().split(":")[1]);
//author:zhangkb time:2020-1-6 desc:添加标签用到获取session属性接口
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