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 {
@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 {
......
package com.keymobile.tagmanager.api;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.keymobile.tagmanager.model.Page;
import com.keymobile.tagmanager.service.TagFileService;
import com.keymobile.tagmanager.util.UserInfoUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@Api(value = "文件", tags = "文件")
@RestController
@RequestMapping(value = "/file")
public class TagFileCtrl {
@Autowired
private TagFileService tagExportService;
@GetMapping("/exportTag")
public int export(HttpServletResponse response, @RequestParam(required = false , value = "deptIdPath") String deptIdPath) {
if (StringUtils.isBlank(deptIdPath)) {
deptIdPath = UserInfoUtils.getUserCompanyIdPath();
}
return tagExportService.exportExcel(deptIdPath, response);
}
@PostMapping("/importTag")
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);
}
@ApiOperation(value = "分页获取导入日志", notes = "分页获取导入日志")
@GetMapping(value = "/listImportTagLogByPage")
public Page searchPersonalDimensionTagByPage(
@RequestParam(required = false , value = "deptIdPath") String deptIdPath,
@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize) {
if (StringUtils.isBlank(deptIdPath)) {
deptIdPath = UserInfoUtils.getUserCompanyIdPath();
}
return tagExportService.listImportlogByPage(deptIdPath, new Page(pageSize, pageNo));
}
@ApiOperation(value = "撤销导入", notes = "撤销导入")
@PostMapping(value = "/undoImportTag")
public void undoImportExcel(@RequestParam("importlogId") String importlogId) {
tagExportService.undoImportExcel(importlogId);
}
//----------------------以下为导入系统的时候
@PostMapping("/importSystem")
public String importSystem(MultipartFile file, HttpServletResponse response) throws Exception {
String userName = UserInfoUtils.getUserName();
return tagExportService.importSystem(userName, file);
}
}
package com.keymobile.tagmanager.api;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.keymobile.tagmanager.model.Page;
import com.keymobile.tagmanager.service.TagFileService;
import com.keymobile.tagmanager.util.UserInfoUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@Api(value = "文件", tags = "文件")
@RestController
@RequestMapping(value = "/file")
public class TagFileCtrl {
@Autowired
private TagFileService tagExportService;
@GetMapping("/exportTag")
public int export(HttpServletResponse response, @RequestParam(required = false , value = "deptIdPath") String deptIdPath) {
deptIdPath = UserInfoUtils.getDataRoleOrg();
return tagExportService.exportExcel(deptIdPath, response);
}
@PostMapping("/importTag")
public String importExcel(MultipartFile file, HttpServletResponse response,
@RequestParam(required = false , value = "deptIdPath") String deptIdPath) throws Exception {
String userName = UserInfoUtils.getUserName();
String userId = UserInfoUtils.getUserId();
deptIdPath = UserInfoUtils.getDataRoleOrg();
return tagExportService.importExcel(userName, userId, deptIdPath, file);
}
@ApiOperation(value = "分页获取导入日志", notes = "分页获取导入日志")
@GetMapping(value = "/listImportTagLogByPage")
public Page searchPersonalDimensionTagByPage(
@RequestParam(required = false , value = "deptIdPath") String deptIdPath,
@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize) {
if (StringUtils.isBlank(deptIdPath)) {
deptIdPath = UserInfoUtils.getUserCompanyIdPath();
}
return tagExportService.listImportlogByPage(deptIdPath, new Page(pageSize, pageNo));
}
@ApiOperation(value = "撤销导入", notes = "撤销导入")
@PostMapping(value = "/undoImportTag")
public void undoImportExcel(@RequestParam("importlogId") String importlogId) {
tagExportService.undoImportExcel(importlogId);
}
//----------------------以下为导入系统的时候
@PostMapping("/importSystem")
public String importSystem(MultipartFile file, HttpServletResponse response) throws Exception {
String userName = UserInfoUtils.getUserName();
return tagExportService.importSystem(userName, file);
}
}
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);
}
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