|
|
|
@ -7,11 +7,15 @@ import com.daqing.financial.hrms.dao.RolePermissionDao; |
|
|
|
|
import com.daqing.financial.hrms.service.PermissionService; |
|
|
|
|
import com.daqing.framework.domain.hrms.PermissionEntity; |
|
|
|
|
import com.daqing.framework.domain.hrms.RolePermissionEntity; |
|
|
|
|
import com.daqing.framework.model.response.ResponseResult; |
|
|
|
|
import com.fasterxml.jackson.core.type.TypeReference; |
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
|
import org.apache.commons.beanutils.ConvertUtils; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import java.util.Comparator; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -21,7 +25,9 @@ public class PermissionServiceImpl extends ServiceImpl<PermissionDao, Permission |
|
|
|
|
@Resource |
|
|
|
|
PermissionDao permissionMapper; |
|
|
|
|
@Resource |
|
|
|
|
RolePermissionDao rolePermissionMapper; |
|
|
|
|
RolePermissionDao rolePermissionDao; |
|
|
|
|
@Resource |
|
|
|
|
PermissionService permissionService; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<PermissionEntity> listWithTree() { |
|
|
|
@ -44,8 +50,77 @@ public class PermissionServiceImpl extends ServiceImpl<PermissionDao, Permission |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<RolePermissionEntity> queryRolePermissionList(Long id) { |
|
|
|
|
List<RolePermissionEntity> permissionEntityList = rolePermissionMapper.selectList(new QueryWrapper<RolePermissionEntity>().eq("permission_id",id)); |
|
|
|
|
List<RolePermissionEntity> permissionEntityList = rolePermissionDao.selectList(new QueryWrapper<RolePermissionEntity>().eq("permission_id",id)); |
|
|
|
|
return permissionEntityList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* @Override |
|
|
|
|
public List<RolePermissionEntity> queryPermissionsByRoleIds(List<Long> ids) { |
|
|
|
|
List<RolePermissionEntity> permissionEntityList = rolePermissionDao.queryPermissionsByRoleIds(ids); |
|
|
|
|
return permissionEntityList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<PermissionEntity> queryPermissionsByIds(List<Integer> ids) { |
|
|
|
|
List<PermissionEntity> permissionEntityList = permissionMapper.queryPermissionsByIds(ids); |
|
|
|
|
return permissionEntityList; |
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List getPermission(String roleIds) { |
|
|
|
|
|
|
|
|
|
//截取字符串
|
|
|
|
|
String[] strArr = roleIds.split(","); |
|
|
|
|
//转换long类型的数组
|
|
|
|
|
Long[] strArrNum = (Long[]) ConvertUtils.convert(strArr,Long.class); |
|
|
|
|
|
|
|
|
|
//根据角色id查询对应的权限id
|
|
|
|
|
List<RolePermissionEntity> rolePermissionList = rolePermissionDao.queryPermissionsByRoleIds(Arrays.asList(strArrNum)); |
|
|
|
|
List<Long> permissionList = new ArrayList(); |
|
|
|
|
for(RolePermissionEntity res : rolePermissionList){ |
|
|
|
|
permissionList.add(res.getPermissionId()); |
|
|
|
|
} |
|
|
|
|
/* ResponseResult responseResult = hrmsFeignService.queryPermissionsByRoleIds(strArrNum); |
|
|
|
|
List<Integer> permissionList = new ArrayList(); |
|
|
|
|
|
|
|
|
|
List<LinkedHashMap> employeeMessage = null; |
|
|
|
|
if(responseResult.getData() != null){ |
|
|
|
|
employeeMessage = (List<LinkedHashMap>) responseResult.getData(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for(LinkedHashMap res : employeeMessage){ |
|
|
|
|
permissionList.add((Integer) res.get("permissionId")); |
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
Long[] permissionIds = permissionList.toArray(new Long[permissionList.size()]); |
|
|
|
|
//根据权限ids查询对应权限
|
|
|
|
|
List<PermissionEntity> permissionEntityList = permissionMapper.queryPermissionsByIds(Arrays.asList(permissionIds)); |
|
|
|
|
/* |
|
|
|
|
ResponseResult responseResult2 = hrmsFeignService.queryPermissionsByIds(permissionIds); |
|
|
|
|
List<LinkedHashMap> perList = (List<LinkedHashMap>) responseResult2.getData(); |
|
|
|
|
//LinkedHashMap转对象
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
|
List<PermissionEntity> permissionEntityList = mapper.convertValue(perList, new TypeReference<List<PermissionEntity>>() { }); |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
return getListDepartmentAndEmployeeTree(permissionEntityList, 0L); |
|
|
|
|
/* |
|
|
|
|
List list = new ArrayList(); |
|
|
|
|
list.add(permissionEntityList); |
|
|
|
|
list.add(roleIds);*/ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private List<PermissionEntity> getListDepartmentAndEmployeeTree(List<PermissionEntity> list, Long parentId) { |
|
|
|
|
return list.stream() |
|
|
|
|
.filter(dept -> parentId.equals(dept.getParentId())) // 过滤出部门id为所选id的部门信息(也为递归的结果条件,找不到所对应的部门id)
|
|
|
|
|
.peek(dept -> { |
|
|
|
|
dept.setChildren(getListDepartmentAndEmployeeTree(list, dept.getId())); // 设置该部门的子部门:递归调用
|
|
|
|
|
|
|
|
|
|
PermissionEntity permission = permissionService.getById(dept.getId()); |
|
|
|
|
}) |
|
|
|
|
.sorted(Comparator.comparingInt(menu -> (menu.getSort() == null ? 0 : menu.getSort()))) // 根据所选排序信息进行排序
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |