Commit 819be5cb authored by neo's avatar neo

[DEL] delete permission service interface

parent a6b39d64
package pwc.taxtech.atms.controller; package pwc.taxtech.atms.controller;
import java.util.List; import io.swagger.annotations.ApiOperation;
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;
...@@ -11,11 +10,11 @@ import org.springframework.web.bind.annotation.RequestMethod; ...@@ -11,11 +10,11 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.ApiOperation;
import pwc.taxtech.atms.dto.navtree.DevTreeDto; import pwc.taxtech.atms.dto.navtree.DevTreeDto;
import pwc.taxtech.atms.dto.navtree.RolePermissionDisplayDto; import pwc.taxtech.atms.dto.navtree.RolePermissionDisplayDto;
import pwc.taxtech.atms.service.PermissionService; import pwc.taxtech.atms.service.impl.PermissionServiceImpl;
import java.util.List;
@RestController @RestController
@RequestMapping("/api/v1/permission/") @RequestMapping("/api/v1/permission/")
...@@ -24,11 +23,12 @@ public class PermissionController { ...@@ -24,11 +23,12 @@ public class PermissionController {
private static Logger logger = LoggerFactory.getLogger(PermissionController.class); private static Logger logger = LoggerFactory.getLogger(PermissionController.class);
@Autowired @Autowired
private PermissionService permissionService; private PermissionServiceImpl permissionService;
@ApiOperation(value = "Active or Deactive the specific area.") @ApiOperation(value = "Active or Deactive the specific area.")
@RequestMapping(value = "getIvhTreePermissionsByRoleID", method = RequestMethod.GET) @RequestMapping(value = "getIvhTreePermissionsByRoleID", method = RequestMethod.GET)
public @ResponseBody RolePermissionDisplayDto getIvhTreePermissionsByRoleId(@RequestParam String roleID, public @ResponseBody
RolePermissionDisplayDto getIvhTreePermissionsByRoleId(@RequestParam String roleID,
@RequestParam String serviceType) { @RequestParam String serviceType) {
logger.info("getIvhTreePermissionsByRoleId: roleId={}, serviceType={}.", roleID, serviceType); logger.info("getIvhTreePermissionsByRoleId: roleId={}, serviceType={}.", roleID, serviceType);
return permissionService.getIvhTreePermissionsByRoleId(roleID, serviceType); return permissionService.getIvhTreePermissionsByRoleId(roleID, serviceType);
...@@ -36,14 +36,16 @@ public class PermissionController { ...@@ -36,14 +36,16 @@ public class PermissionController {
@ApiOperation(value = "通过传入的角色Id列表获取树形结构权限") @ApiOperation(value = "通过传入的角色Id列表获取树形结构权限")
@RequestMapping(value = "getIvhTreePermissionsByRoleIDList", method = RequestMethod.POST) @RequestMapping(value = "getIvhTreePermissionsByRoleIDList", method = RequestMethod.POST)
public @ResponseBody List<DevTreeDto> getIvhTreePermissionsByRoleIdList(@RequestBody List<String> roleIdList, public @ResponseBody
List<DevTreeDto> getIvhTreePermissionsByRoleIdList(@RequestBody List<String> roleIdList,
@RequestParam String serviceType) { @RequestParam String serviceType) {
return permissionService.getIvhTreePermissionsByRoleIdList(roleIdList, serviceType); return permissionService.getIvhTreePermissionsByRoleIdList(roleIdList, serviceType);
} }
@ApiOperation(value = "获取所有权限树形结构列表") @ApiOperation(value = "获取所有权限树形结构列表")
@RequestMapping(value = "getAllPermissions", method = RequestMethod.GET) @RequestMapping(value = "getAllPermissions", method = RequestMethod.GET)
public @ResponseBody List<DevTreeDto> getAllPermissions(@RequestParam String serviceType) { public @ResponseBody
List<DevTreeDto> getAllPermissions(@RequestParam String serviceType) {
return permissionService.getAllPermissions(serviceType); return permissionService.getAllPermissions(serviceType);
} }
} }
package pwc.taxtech.atms.service;
import java.util.List;
import pwc.taxtech.atms.dto.navtree.DevTreeDto;
import pwc.taxtech.atms.dto.navtree.RolePermissionDisplayDto;
public interface PermissionService {
RolePermissionDisplayDto getIvhTreePermissionsByRoleId(String roleId, String serviceType);
@SuppressWarnings("rawtypes")
List<DevTreeDto> getIvhTreePermissionsByRoleIdList(List<String> roleIdList, String serviceType);
@SuppressWarnings("rawtypes")
List<DevTreeDto> getAllPermissions(String serviceType);
}
package pwc.taxtech.atms.service.impl; package pwc.taxtech.atms.service.impl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import pwc.taxtech.atms.common.CommonConstants; import pwc.taxtech.atms.common.CommonConstants;
import pwc.taxtech.atms.common.CommonUtils; import pwc.taxtech.atms.common.CommonUtils;
import pwc.taxtech.atms.dto.navtree.DevTreeDto; import pwc.taxtech.atms.dto.navtree.DevTreeDto;
...@@ -18,21 +10,26 @@ import pwc.taxtech.atms.dto.permission.RolePermissionDto; ...@@ -18,21 +10,26 @@ import pwc.taxtech.atms.dto.permission.RolePermissionDto;
import pwc.taxtech.atms.entity.Permission; import pwc.taxtech.atms.entity.Permission;
import pwc.taxtech.atms.entity.PermissionExample; import pwc.taxtech.atms.entity.PermissionExample;
import pwc.taxtech.atms.entity.RolePermission; import pwc.taxtech.atms.entity.RolePermission;
import pwc.taxtech.atms.service.PermissionService;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@Service @Service
public class PermissionServiceImpl extends AbstractService implements PermissionService { public class PermissionServiceImpl extends AbstractService {
/* (non-Javadoc) /* (non-Javadoc)
* @see pwc.taxtech.atms.service.PermissionService#getIvhTreePermissionsByRoleId(java.lang.String, java.lang.String) * @see pwc.taxtech.atms.service.PermissionService#getIvhTreePermissionsByRoleId(java.lang.String, java.lang.String)
*/ */
@Override
public RolePermissionDisplayDto getIvhTreePermissionsByRoleId(String roleId, String serviceType) { public RolePermissionDisplayDto getIvhTreePermissionsByRoleId(String roleId, String serviceType) {
RolePermissionDisplayDto rolePermissionDisplayDto = new RolePermissionDisplayDto(); RolePermissionDisplayDto rolePermissionDisplayDto = new RolePermissionDisplayDto();
List<RolePermission> rolePermissionList = rolePermissionMapper.selectByRoleAndServiceTypeWithAssociation(roleId, serviceType); List<RolePermission> rolePermissionList = rolePermissionMapper.selectByRoleAndServiceTypeWithAssociation(roleId, serviceType);
if(rolePermissionList == null || rolePermissionList.isEmpty() ) { if (rolePermissionList == null || rolePermissionList.isEmpty()) {
return rolePermissionDisplayDto; return rolePermissionDisplayDto;
} }
List<RolePermissionDto> rolePermissionDtoList = new ArrayList<>(); List<RolePermissionDto> rolePermissionDtoList = new ArrayList<>();
...@@ -51,7 +48,7 @@ public class PermissionServiceImpl extends AbstractService implements Permission ...@@ -51,7 +48,7 @@ public class PermissionServiceImpl extends AbstractService implements Permission
rolePermissionDtoList.add(rolePermissionDto); rolePermissionDtoList.add(rolePermissionDto);
}); });
rolePermissionDisplayDto.setRolePermissionList(rolePermissionDtoList); rolePermissionDisplayDto.setRolePermissionList(rolePermissionDtoList);
if(rolePermissionDtoList.isEmpty()) { if (rolePermissionDtoList.isEmpty()) {
return rolePermissionDisplayDto; return rolePermissionDisplayDto;
} }
...@@ -60,20 +57,17 @@ public class PermissionServiceImpl extends AbstractService implements Permission ...@@ -60,20 +57,17 @@ public class PermissionServiceImpl extends AbstractService implements Permission
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see pwc.taxtech.atms.service.PermissionService#getIvhTreePermissionsByRoleIdList(java.util.List, java.lang.String) * @see pwc.taxtech.atms.service.PermissionService#getIvhTreePermissionsByRoleIdList(java.util.List, java.lang.String)
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Override
public List<DevTreeDto> getIvhTreePermissionsByRoleIdList(List<String> roleList, String serviceType) { public List<DevTreeDto> getIvhTreePermissionsByRoleIdList(List<String> roleList, String serviceType) {
if(roleList == null || roleList.isEmpty() ) { if (roleList == null || roleList.isEmpty()) {
return new ArrayList<DevTreeDto>(); return new ArrayList<DevTreeDto>();
} }
List<RolePermission> rolePermissionList = rolePermissionMapper.selectByRoleListAndServiceTypeWithAssociation(roleList, serviceType); List<RolePermission> rolePermissionList = rolePermissionMapper.selectByRoleListAndServiceTypeWithAssociation(roleList, serviceType);
if(rolePermissionList == null || rolePermissionList.isEmpty() ) { if (rolePermissionList == null || rolePermissionList.isEmpty()) {
return new ArrayList<DevTreeDto>(); return new ArrayList<DevTreeDto>();
} }
List<RolePermissionDto> rolePermissionDtoListTemp = new ArrayList<>(); List<RolePermissionDto> rolePermissionDtoListTemp = new ArrayList<>();
...@@ -96,7 +90,6 @@ public class PermissionServiceImpl extends AbstractService implements Permission ...@@ -96,7 +90,6 @@ public class PermissionServiceImpl extends AbstractService implements Permission
* @see pwc.taxtech.atms.service.PermissionService#getAllPermissions(java.lang.String) * @see pwc.taxtech.atms.service.PermissionService#getAllPermissions(java.lang.String)
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Override
public List<DevTreeDto> getAllPermissions(String serviceType) { public List<DevTreeDto> getAllPermissions(String serviceType) {
PermissionExample permissionExample = new PermissionExample(); PermissionExample permissionExample = new PermissionExample();
...@@ -131,15 +124,14 @@ public class PermissionServiceImpl extends AbstractService implements Permission ...@@ -131,15 +124,14 @@ public class PermissionServiceImpl extends AbstractService implements Permission
//get all permission list //get all permission list
List<Permission> allPermissionList = permissionMapper.selectByExample(null); List<Permission> allPermissionList = permissionMapper.selectByExample(null);
if(outputRolePermissionDtoList.size() != allPermissionList.size()) { if (outputRolePermissionDtoList.size() != allPermissionList.size()) {
Collections.copy(outputRolePermissionDtoList, rolePermissionDtoList); Collections.copy(outputRolePermissionDtoList, rolePermissionDtoList);
for(RolePermissionDto rolePermissionDto: rolePermissionDtoList) { for (RolePermissionDto rolePermissionDto : rolePermissionDtoList) {
addParentPermissionToListRecursive(rolePermissionDto, allPermissionList, outputRolePermissionDtoList); addParentPermissionToListRecursive(rolePermissionDto, allPermissionList, outputRolePermissionDtoList);
} }
} } else {
else {
outputRolePermissionDtoList = new ArrayList<>(); outputRolePermissionDtoList = new ArrayList<>();
for(Permission permission: allPermissionList) { for (Permission permission : allPermissionList) {
RolePermissionDto rolePermissionDto = new RolePermissionDto(); RolePermissionDto rolePermissionDto = new RolePermissionDto();
CommonUtils.copyProperties(permission, rolePermissionDto); CommonUtils.copyProperties(permission, rolePermissionDto);
rolePermissionDto.setId(null); rolePermissionDto.setId(null);
...@@ -153,7 +145,7 @@ public class PermissionServiceImpl extends AbstractService implements Permission ...@@ -153,7 +145,7 @@ public class PermissionServiceImpl extends AbstractService implements Permission
//根据resultList中情况生成ivhtree //根据resultList中情况生成ivhtree
List<RolePermissionDto> topList = outputRolePermissionDtoList.stream() List<RolePermissionDto> topList = outputRolePermissionDtoList.stream()
.filter(rPermissionDto -> StringUtils.isEmpty(rPermissionDto.getParentId())) .filter(rPermissionDto -> StringUtils.isEmpty(rPermissionDto.getParentId()))
.sorted(Comparator.comparing(RolePermissionDto :: getCode)) .sorted(Comparator.comparing(RolePermissionDto::getCode))
.collect(Collectors.toList()); .collect(Collectors.toList());
List<DevTreeDto> permissionDevTreeList = new ArrayList<>(); List<DevTreeDto> permissionDevTreeList = new ArrayList<>();
for (RolePermissionDto topRolePermissionDto : topList) { for (RolePermissionDto topRolePermissionDto : topList) {
...@@ -173,7 +165,7 @@ public class PermissionServiceImpl extends AbstractService implements Permission ...@@ -173,7 +165,7 @@ public class PermissionServiceImpl extends AbstractService implements Permission
Optional<Permission> optional = allPermissionList.stream(). Optional<Permission> optional = allPermissionList.stream().
filter(p -> p.getId().equals(rolePermissionDto.getParentId())).findFirst(); filter(p -> p.getId().equals(rolePermissionDto.getParentId())).findFirst();
if(optional.isPresent()) { if (optional.isPresent()) {
Permission parentPermission = optional.get(); Permission parentPermission = optional.get();
RolePermissionDto parentRolePermissionDto = new RolePermissionDto(); RolePermissionDto parentRolePermissionDto = new RolePermissionDto();
CommonUtils.copyProperties(parentPermission, parentRolePermissionDto); CommonUtils.copyProperties(parentPermission, parentRolePermissionDto);
...@@ -182,23 +174,23 @@ public class PermissionServiceImpl extends AbstractService implements Permission ...@@ -182,23 +174,23 @@ public class PermissionServiceImpl extends AbstractService implements Permission
parentRolePermissionDto.setPermissionName(parentPermission.getName()); parentRolePermissionDto.setPermissionName(parentPermission.getName());
parentRolePermissionDto.setServiceType(parentPermission.getServiceTypeId()); parentRolePermissionDto.setServiceType(parentPermission.getServiceTypeId());
if(outputRolePermissionDtoList.stream() if (outputRolePermissionDtoList.stream()
.filter(rpDto -> rpDto.getPermissionId().equals(parentPermission.getId())).count()==0) { .filter(rpDto -> rpDto.getPermissionId().equals(parentPermission.getId())).count() == 0) {
outputRolePermissionDtoList.add(parentRolePermissionDto); outputRolePermissionDtoList.add(parentRolePermissionDto);
} }
addParentPermissionToListRecursive(parentRolePermissionDto, allPermissionList, outputRolePermissionDtoList); addParentPermissionToListRecursive(parentRolePermissionDto, allPermissionList, outputRolePermissionDtoList);
} }
} }
@SuppressWarnings({ "rawtypes", "unchecked" }) @SuppressWarnings({"rawtypes", "unchecked"})
private void setSubRolePermissionListRecursive(DevTreeDto currentNode, List<RolePermissionDto> allRolePermissionDtoList) { private void setSubRolePermissionListRecursive(DevTreeDto currentNode, List<RolePermissionDto> allRolePermissionDtoList) {
List<RolePermissionDto> subRolePermissionDtoList = allRolePermissionDtoList.stream() List<RolePermissionDto> subRolePermissionDtoList = allRolePermissionDtoList.stream()
.filter(rPermissionDto -> currentNode.getId().equals(rPermissionDto.getParentId())).collect(Collectors.toList()); .filter(rPermissionDto -> currentNode.getId().equals(rPermissionDto.getParentId())).collect(Collectors.toList());
if(subRolePermissionDtoList!=null && !subRolePermissionDtoList.isEmpty()) { if (subRolePermissionDtoList != null && !subRolePermissionDtoList.isEmpty()) {
currentNode.setExpanded(true); currentNode.setExpanded(true);
currentNode.setItems(new ArrayList<>()); currentNode.setItems(new ArrayList<>());
for(RolePermissionDto rolePermissionDto : subRolePermissionDtoList) { for (RolePermissionDto rolePermissionDto : subRolePermissionDtoList) {
DevTreeDto subNode = new DevTreeDto(); DevTreeDto subNode = new DevTreeDto();
subNode.setId(rolePermissionDto.getPermissionId()); subNode.setId(rolePermissionDto.getPermissionId());
subNode.setText(rolePermissionDto.getPermissionName()); subNode.setText(rolePermissionDto.getPermissionName());
...@@ -207,22 +199,21 @@ public class PermissionServiceImpl extends AbstractService implements Permission ...@@ -207,22 +199,21 @@ public class PermissionServiceImpl extends AbstractService implements Permission
currentNode.getItems().add(subNode); currentNode.getItems().add(subNode);
setSubRolePermissionListRecursive(subNode, allRolePermissionDtoList); setSubRolePermissionListRecursive(subNode, allRolePermissionDtoList);
} }
} } else {
else {
currentNode.setExpanded(false); currentNode.setExpanded(false);
currentNode.setItems(new ArrayList<>()); currentNode.setItems(new ArrayList<>());
} }
} }
@SuppressWarnings({ "rawtypes", "unchecked" }) @SuppressWarnings({"rawtypes", "unchecked"})
private void setSubPermissionListRecursive(DevTreeDto currentNode, List<Permission> allPermissionList) { private void setSubPermissionListRecursive(DevTreeDto currentNode, List<Permission> allPermissionList) {
List<Permission> subPermissionList = allPermissionList.stream() List<Permission> subPermissionList = allPermissionList.stream()
.filter(permission -> currentNode.getId().equals(permission.getParentId())).collect(Collectors.toList()); .filter(permission -> currentNode.getId().equals(permission.getParentId())).collect(Collectors.toList());
if(subPermissionList!=null && !subPermissionList.isEmpty()) { if (subPermissionList != null && !subPermissionList.isEmpty()) {
currentNode.setExpanded(true); currentNode.setExpanded(true);
currentNode.setItems(new ArrayList<>()); currentNode.setItems(new ArrayList<>());
for(Permission permission : subPermissionList) { for (Permission permission : subPermissionList) {
DevTreeDto subNode = new DevTreeDto(); DevTreeDto subNode = new DevTreeDto();
subNode.setId(permission.getId()); subNode.setId(permission.getId());
subNode.setText(permission.getName()); subNode.setText(permission.getName());
...@@ -232,8 +223,7 @@ public class PermissionServiceImpl extends AbstractService implements Permission ...@@ -232,8 +223,7 @@ public class PermissionServiceImpl extends AbstractService implements Permission
currentNode.getItems().add(subNode); currentNode.getItems().add(subNode);
setSubPermissionListRecursive(subNode, allPermissionList); setSubPermissionListRecursive(subNode, allPermissionList);
} }
} } else {
else {
currentNode.setExpanded(false); currentNode.setExpanded(false);
currentNode.setItems(new ArrayList<>()); currentNode.setItems(new ArrayList<>());
} }
......
...@@ -45,7 +45,6 @@ import pwc.taxtech.atms.entity.*; ...@@ -45,7 +45,6 @@ import pwc.taxtech.atms.entity.*;
import pwc.taxtech.atms.entity.UserRoleExample.Criteria; import pwc.taxtech.atms.entity.UserRoleExample.Criteria;
import pwc.taxtech.atms.exception.ApplicationException; import pwc.taxtech.atms.exception.ApplicationException;
import pwc.taxtech.atms.service.OrganizationService; import pwc.taxtech.atms.service.OrganizationService;
import pwc.taxtech.atms.service.PermissionService;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -58,7 +57,7 @@ import java.util.stream.Collectors; ...@@ -58,7 +57,7 @@ import java.util.stream.Collectors;
public class UserRoleServiceImpl extends AbstractService { public class UserRoleServiceImpl extends AbstractService {
@Autowired @Autowired
private PermissionService permissionService; private PermissionServiceImpl permissionService;
@Autowired @Autowired
private OrganizationService organizationService; private OrganizationService organizationService;
......
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