Commit 819be5cb authored by neo's avatar neo

[DEL] delete permission service interface

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