优化组织架构,修复无法修改机构属性问题

This commit is contained in:
zhouhao
2017-06-16 22:50:14 +08:00
parent ff61335c49
commit 5c50018e96
24 changed files with 169 additions and 82 deletions

View File

@@ -36,6 +36,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-system-organizational-entity</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

View File

@@ -2,8 +2,7 @@ package org.hswebframework.web.organizational.authorization;
import org.hswebframework.web.ThreadLocalUtils;
import org.hswebframework.web.authorization.Authentication;
import org.hswebframework.web.authorization.AuthenticationSupplier;
import org.hswebframework.web.organizational.authorization.entity.PersonAttachEntity;
import org.hswebframework.web.entity.organizational.authorization.PersonAttachEntity;
import java.util.Objects;

View File

@@ -30,7 +30,7 @@ public interface DataAccessType extends Serializable {
*/
String PERSON_SCOPE = "PERSON_SCOPE";
/**
* 只能查看自己
* 仅限本人
*/
String SCOPE_TYPE_ONLY_SELF = "ONLY_SELF";
/**

View File

@@ -1,20 +1,22 @@
package org.hswebframework.web.organizational.authorization.simple.handler;
import org.hsweb.ezorm.core.param.Term;
import org.hswebframework.utils.ClassUtils;
import org.hswebframework.web.authorization.Permission;
import org.hswebframework.web.authorization.access.DataAccessConfig;
import org.hswebframework.web.authorization.access.DataAccessHandler;
import org.hswebframework.web.authorization.access.ScopeDataAccessConfig;
import org.hswebframework.web.authorization.annotation.RequiresDataAccess;
import org.hswebframework.web.boost.aop.context.MethodInterceptorHolder;
import org.hswebframework.web.boost.aop.context.MethodInterceptorParamContext;
import org.hswebframework.web.commons.entity.Entity;
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
import org.hswebframework.web.controller.QueryController;
import org.hswebframework.web.entity.organizational.OrganizationalEntity;
import org.hswebframework.web.entity.organizational.authorization.OrgAttachEntity;
import org.hswebframework.web.organizational.authorization.PersonnelAuthorization;
import org.hswebframework.web.organizational.authorization.access.DataAccessType;
import org.hswebframework.web.organizational.authorization.entity.OrgAttachEntity;
import org.hswebframework.web.service.QueryService;
import org.hswebframework.utils.ClassUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,6 +41,8 @@ public abstract class AbstractScopeDataAccessHandler<E> implements DataAccessHan
protected abstract String getOperationScope(E entity);
protected abstract void applyScopeProperty(E entity, String value);
protected abstract Term createQueryTerm(Set<String> scope);
protected abstract Set<String> getTryOperationScope(String scopeType, PersonnelAuthorization authorization);
@@ -83,9 +87,9 @@ public abstract class AbstractScopeDataAccessHandler<E> implements DataAccessHan
if (scope != null) {
String finalScopeId = scope;
context.getParams().values().stream()
.filter(OrgAttachEntity.class::isInstance)
.map(OrgAttachEntity.class::cast)
.forEach(entity -> entity.setOrgId(finalScopeId));
.filter(getEntityClass()::isInstance)
.map(getEntityClass()::cast)
.forEach(entity -> applyScopeProperty(entity, finalScopeId));
} else {
logger.warn("scope is null!");
}
@@ -164,4 +168,10 @@ public abstract class AbstractScopeDataAccessHandler<E> implements DataAccessHan
}
return true;
}
protected boolean genericTypeInstanceOf(Class type) {
MethodInterceptorHolder holder = MethodInterceptorHolder.current();
Class entity = ClassUtils.getGenericType(holder.getTarget().getClass());
return null != entity && ClassUtils.instanceOf(entity, type);
}
}

View File

@@ -2,8 +2,8 @@ package org.hswebframework.web.organizational.authorization.simple.handler;
import org.hsweb.ezorm.core.param.Term;
import org.hsweb.ezorm.core.param.TermType;
import org.hswebframework.web.entity.organizational.authorization.AreaAttachEntity;
import org.hswebframework.web.organizational.authorization.PersonnelAuthorization;
import org.hswebframework.web.organizational.authorization.entity.AreaAttachEntity;
import java.util.Collections;
import java.util.Set;
@@ -31,6 +31,11 @@ public class AreaScopeDataAccessHandler extends AbstractScopeDataAccessHandler<A
return entity.getAreaId();
}
@Override
protected void applyScopeProperty(AreaAttachEntity entity, String value) {
entity.setAreaId(value);
}
@Override
protected Set<String> getTryOperationScope(String scopeType, PersonnelAuthorization authorization) {
switch (scopeType) {

View File

@@ -2,9 +2,12 @@ package org.hswebframework.web.organizational.authorization.simple.handler;
import org.hsweb.ezorm.core.param.Term;
import org.hsweb.ezorm.core.param.TermType;
import org.hswebframework.web.entity.organizational.DepartmentEntity;
import org.hswebframework.web.entity.organizational.OrganizationalEntity;
import org.hswebframework.web.entity.organizational.authorization.DepartmentAttachEntity;
import org.hswebframework.web.entity.organizational.authorization.OrgAttachEntity;
import org.hswebframework.web.organizational.authorization.PersonnelAuthorization;
import org.hswebframework.web.organizational.authorization.access.DataAccessType;
import org.hswebframework.web.organizational.authorization.entity.DepartmentAttachEntity;
import java.util.Collections;
import java.util.Set;
@@ -23,6 +26,11 @@ public class DepartmentScopeDataAccessHandler extends AbstractScopeDataAccessHan
return DepartmentAttachEntity.class;
}
@Override
protected void applyScopeProperty(DepartmentAttachEntity entity, String value) {
entity.setDepartmentId(value);
}
@Override
protected String getSupportScope() {
return DataAccessType.DEPARTMENT_SCOPE;
@@ -48,7 +56,11 @@ public class DepartmentScopeDataAccessHandler extends AbstractScopeDataAccessHan
@Override
protected Term createQueryTerm(Set<String> scope) {
Term term = new Term();
term.setColumn(DepartmentAttachEntity.departmentId);
if (genericTypeInstanceOf(DepartmentEntity.class)) {
term.setColumn(DepartmentEntity.id);
} else {
term.setColumn(DepartmentAttachEntity.departmentId);
}
term.setTermType(TermType.in);
term.setValue(scope);
term.setType(Term.Type.and);

View File

@@ -2,9 +2,14 @@ package org.hswebframework.web.organizational.authorization.simple.handler;
import org.hsweb.ezorm.core.param.Term;
import org.hsweb.ezorm.core.param.TermType;
import org.hswebframework.utils.ClassUtils;
import org.hswebframework.web.boost.aop.context.MethodInterceptorHolder;
import org.hswebframework.web.boost.aop.context.MethodInterceptorParamContext;
import org.hswebframework.web.entity.organizational.OrganizationalEntity;
import org.hswebframework.web.entity.organizational.SimpleOrganizationalEntity;
import org.hswebframework.web.entity.organizational.authorization.OrgAttachEntity;
import org.hswebframework.web.organizational.authorization.PersonnelAuthorization;
import org.hswebframework.web.organizational.authorization.access.DataAccessType;
import org.hswebframework.web.organizational.authorization.entity.OrgAttachEntity;
import java.util.Collections;
import java.util.Set;
@@ -28,6 +33,11 @@ public class OrgScopeDataAccessHandler extends AbstractScopeDataAccessHandler<Or
return DataAccessType.ORG_SCOPE;
}
@Override
protected void applyScopeProperty(OrgAttachEntity entity, String value) {
entity.setOrgId(value);
}
@Override
protected Set<String> getTryOperationScope(String scopeType, PersonnelAuthorization authorization) {
switch (scopeType) {
@@ -48,7 +58,11 @@ public class OrgScopeDataAccessHandler extends AbstractScopeDataAccessHandler<Or
@Override
protected Term createQueryTerm(Set<String> scope) {
Term term = new Term();
term.setColumn(OrgAttachEntity.orgId);
if (genericTypeInstanceOf(OrganizationalEntity.class)) {
term.setColumn(OrganizationalEntity.id);
} else {
term.setColumn(OrgAttachEntity.orgId);
}
term.setTermType(TermType.in);
term.setValue(scope);
term.setType(Term.Type.and);

View File

@@ -2,9 +2,9 @@ package org.hswebframework.web.organizational.authorization.simple.handler;
import org.hsweb.ezorm.core.param.Term;
import org.hsweb.ezorm.core.param.TermType;
import org.hswebframework.web.entity.organizational.authorization.PersonAttachEntity;
import org.hswebframework.web.organizational.authorization.PersonnelAuthorization;
import org.hswebframework.web.organizational.authorization.access.DataAccessType;
import org.hswebframework.web.organizational.authorization.entity.PersonAttachEntity;
import java.util.Collections;
import java.util.Set;
@@ -40,6 +40,11 @@ public class PersonScopeDataAccessHandler extends AbstractScopeDataAccessHandler
}
}
@Override
protected void applyScopeProperty(PersonAttachEntity entity, String value) {
entity.setPersonId(value);
}
@Override
protected String getOperationScope(PersonAttachEntity entity) {
return entity.getPersonId();

View File

@@ -2,9 +2,10 @@ package org.hswebframework.web.organizational.authorization.simple.handler;
import org.hsweb.ezorm.core.param.Term;
import org.hsweb.ezorm.core.param.TermType;
import org.hswebframework.web.entity.organizational.PositionEntity;
import org.hswebframework.web.entity.organizational.authorization.PositionAttachEntity;
import org.hswebframework.web.organizational.authorization.PersonnelAuthorization;
import org.hswebframework.web.organizational.authorization.access.DataAccessType;
import org.hswebframework.web.organizational.authorization.entity.PositionAttachEntity;
import java.util.Collections;
import java.util.Set;
@@ -40,6 +41,11 @@ public class PositionScopeDataAccessHandler extends AbstractScopeDataAccessHandl
}
}
@Override
protected void applyScopeProperty(PositionAttachEntity entity, String value) {
entity.setPositionId(value);
}
@Override
protected String getOperationScope(PositionAttachEntity entity) {
return entity.getPositionId();
@@ -48,7 +54,11 @@ public class PositionScopeDataAccessHandler extends AbstractScopeDataAccessHandl
@Override
protected Term createQueryTerm(Set<String> scope) {
Term term = new Term();
term.setColumn(PositionAttachEntity.positionId);
if (genericTypeInstanceOf(PositionEntity.class)) {
term.setColumn(PositionEntity.id);
} else {
term.setColumn(PositionAttachEntity.positionId);
}
term.setTermType(TermType.in);
term.setValue(scope);
term.setType(Term.Type.and);

View File

@@ -18,8 +18,9 @@
package org.hswebframework.web.controller.organizational;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.authorization.annotation.RequiresDataAccess;
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
import org.hswebframework.web.controller.GenericEntityController;
import org.hswebframework.web.controller.SimpleGenericEntityController;
import org.hswebframework.web.entity.organizational.DepartmentEntity;
import org.hswebframework.web.logging.AccessLogger;
import org.hswebframework.web.service.organizational.DepartmentService;
@@ -28,15 +29,16 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 部门
* 部门
*
* @author hsweb-generator-online
*/
@RestController
@RequestMapping("${hsweb.web.mappings.department:department}")
@Authorize(permission = "department")
@RequiresDataAccess
@AccessLogger("部门管理")
public class DepartmentController implements GenericEntityController<DepartmentEntity, String, QueryParamEntity,DepartmentEntity> {
public class DepartmentController implements SimpleGenericEntityController<DepartmentEntity, String, QueryParamEntity> {
private DepartmentService departmentService;
@@ -49,4 +51,5 @@ public class DepartmentController implements GenericEntityController<DepartmentE
public DepartmentService getService() {
return departmentService;
}
}

View File

@@ -17,11 +17,17 @@
package org.hswebframework.web.controller.organizational;
import org.hswebframework.web.authorization.Permission;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.authorization.annotation.RequiresDataAccess;
import org.hswebframework.web.commons.entity.PagerResult;
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
import org.hswebframework.web.controller.GenericEntityController;
import org.hswebframework.web.controller.SimpleGenericEntityController;
import org.hswebframework.web.controller.message.ResponseMessage;
import org.hswebframework.web.entity.organizational.DepartmentEntity;
import org.hswebframework.web.entity.organizational.OrganizationalEntity;
import org.hswebframework.web.entity.organizational.PersonEntity;
import org.hswebframework.web.logging.AccessLogger;
import org.hswebframework.web.service.organizational.OrganizationalService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -36,8 +42,9 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("${hsweb.web.mappings.organizational:organizational}")
@Authorize(permission = "organizational")
@RequiresDataAccess
@AccessLogger("组织管理")
public class OrganizationalController implements GenericEntityController<OrganizationalEntity, String, QueryParamEntity,DepartmentEntity> {
public class OrganizationalController implements SimpleGenericEntityController<OrganizationalEntity, String, QueryParamEntity> {
private OrganizationalService organizationalService;
@@ -50,4 +57,5 @@ public class OrganizationalController implements GenericEntityController<Organiz
public OrganizationalService getService() {
return organizationalService;
}
}

View File

@@ -17,11 +17,17 @@
package org.hswebframework.web.controller.organizational;
import org.hswebframework.web.authorization.Permission;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.authorization.annotation.RequiresDataAccess;
import org.hswebframework.web.commons.entity.PagerResult;
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
import org.hswebframework.web.controller.GenericEntityController;
import org.hswebframework.web.controller.SimpleGenericEntityController;
import org.hswebframework.web.controller.message.ResponseMessage;
import org.hswebframework.web.entity.organizational.DepartmentEntity;
import org.hswebframework.web.entity.organizational.PersonEntity;
import org.hswebframework.web.entity.organizational.PositionEntity;
import org.hswebframework.web.logging.AccessLogger;
import org.hswebframework.web.service.organizational.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -29,7 +35,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 人员
* 人员
*
* @author hsweb-generator-online
*/
@@ -37,7 +43,7 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("${hsweb.web.mappings.person:person}")
@Authorize(permission = "person")
@AccessLogger("人员")
public class PersonController implements GenericEntityController<PersonEntity, String, QueryParamEntity,DepartmentEntity> {
public class PersonController implements SimpleGenericEntityController<PersonEntity, String, QueryParamEntity> {
private PersonService personService;
@@ -51,5 +57,10 @@ public class PersonController implements GenericEntityController<PersonEntity, S
return personService;
}
@Override
@RequiresDataAccess(permission = "person", action = Permission.ACTION_QUERY)
public ResponseMessage<PagerResult<PersonEntity>> list(QueryParamEntity param) {
return SimpleGenericEntityController.super.list(param);
}
}

View File

@@ -20,8 +20,10 @@ package org.hswebframework.web.controller.organizational;
import org.hswebframework.web.authorization.Permission;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.authorization.annotation.RequiresDataAccess;
import org.hswebframework.web.commons.entity.PagerResult;
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
import org.hswebframework.web.controller.GenericEntityController;
import org.hswebframework.web.controller.SimpleGenericEntityController;
import org.hswebframework.web.controller.message.ResponseMessage;
import org.hswebframework.web.entity.organizational.DepartmentEntity;
import org.hswebframework.web.entity.organizational.PositionEntity;
@@ -39,8 +41,9 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("${hsweb.web.mappings.position:position}")
@Authorize(permission = "position")
@RequiresDataAccess
@AccessLogger("职位管理")
public class PositionController implements GenericEntityController<PositionEntity, String, QueryParamEntity,DepartmentEntity> {
public class PositionController implements SimpleGenericEntityController<PositionEntity, String, QueryParamEntity> {
private PositionService positionService;
@@ -54,11 +57,4 @@ public class PositionController implements GenericEntityController<PositionEntit
return positionService;
}
@Override
@RequiresDataAccess(permission = "position", action = Permission.ACTION_QUERY)
public ResponseMessage list(QueryParamEntity param) {
return GenericEntityController.super.list(param);
}
}

View File

@@ -17,6 +17,8 @@
package org.hswebframework.web.entity.organizational;
import org.hswebframework.web.commons.entity.TreeSortSupportEntity;
import org.hswebframework.web.entity.organizational.authorization.DepartmentAttachEntity;
import org.hswebframework.web.entity.organizational.authorization.OrgAttachEntity;
import java.util.List;
@@ -25,7 +27,7 @@ import java.util.List;
*
* @author hsweb-generator-online
*/
public interface DepartmentEntity extends TreeSortSupportEntity<String> {
public interface DepartmentEntity extends TreeSortSupportEntity<String>, OrgAttachEntity, DepartmentAttachEntity {
/*-------------------------------------------
| 属性名常量 |
===========================================*/
@@ -36,7 +38,7 @@ public interface DepartmentEntity extends TreeSortSupportEntity<String> {
/**
* 所在组织id
*/
String orgid = "orgid";
String orgId = "orgId";
/**
* 部门编码
*/
@@ -72,16 +74,6 @@ public interface DepartmentEntity extends TreeSortSupportEntity<String> {
*/
void setName(String name);
/**
* @return 所在组织id
*/
String getOrgId();
/**
* 设置 所在组织id
*/
void setOrgId(String orgId);
/**
* @return 部门编码
*/
@@ -103,4 +95,14 @@ public interface DepartmentEntity extends TreeSortSupportEntity<String> {
void setStatus(Byte status);
void setChildren(List<DepartmentEntity> children);
@Override
default String getDepartmentId() {
return getId();
}
@Override
default void setDepartmentId(String departmentId) {
setId(departmentId);
}
}

View File

@@ -17,6 +17,8 @@
package org.hswebframework.web.entity.organizational;
import org.hswebframework.web.commons.entity.TreeSortSupportEntity;
import org.hswebframework.web.entity.organizational.authorization.AreaAttachEntity;
import org.hswebframework.web.entity.organizational.authorization.OrgAttachEntity;
import java.util.List;
@@ -25,7 +27,7 @@ import java.util.List;
*
* @author hsweb-generator-online
*/
public interface OrganizationalEntity extends TreeSortSupportEntity<String> {
public interface OrganizationalEntity extends TreeSortSupportEntity<String>, AreaAttachEntity, OrgAttachEntity {
/*-------------------------------------------
| 属性名常量 |
===========================================*/
@@ -60,7 +62,7 @@ public interface OrganizationalEntity extends TreeSortSupportEntity<String> {
/**
* 状态
*/
String status = "status";
String status = "status";
/**
* 级别
*/
@@ -112,5 +114,12 @@ public interface OrganizationalEntity extends TreeSortSupportEntity<String> {
void setStatus(Byte status);
default String getOrgId() {
return getId();
}
@Override
default void setOrgId(String orgId) {
setId(orgId);
}
}

View File

@@ -17,6 +17,7 @@
package org.hswebframework.web.entity.organizational;
import org.hswebframework.web.commons.entity.GenericEntity;
import org.hswebframework.web.entity.organizational.authorization.PositionAttachEntity;
import java.util.Set;

View File

@@ -17,13 +17,15 @@
package org.hswebframework.web.entity.organizational;
import org.hswebframework.web.commons.entity.Entity;
import org.hswebframework.web.entity.organizational.authorization.PersonAttachEntity;
import org.hswebframework.web.entity.organizational.authorization.PositionAttachEntity;
/**
* 人员职位关联 实体
*
* @author hsweb-generator-online
*/
public interface PersonPositionEntity extends Entity {
public interface PersonPositionEntity extends PersonAttachEntity, PositionAttachEntity {
/*-------------------------------------------
| 属性名常量 |
===========================================*/
@@ -36,24 +38,4 @@ public interface PersonPositionEntity extends Entity {
*/
String positionId = "positionId";
/**
* @return 人员id
*/
String getPersonId();
/**
* 设置 人员id
*/
void setPersonId(String personId);
/**
* @return 职位id
*/
String getPositionId();
/**
* 设置 职位id
*/
void setPositionId(String positionId);
}

View File

@@ -17,7 +17,8 @@
package org.hswebframework.web.entity.organizational;
import org.hswebframework.web.commons.entity.TreeSortSupportEntity;
import org.hswebframework.web.commons.entity.TreeSupportEntity;
import org.hswebframework.web.entity.organizational.authorization.DepartmentAttachEntity;
import org.hswebframework.web.entity.organizational.authorization.PositionAttachEntity;
import java.util.List;
@@ -26,7 +27,7 @@ import java.util.List;
*
* @author hsweb-generator-online
*/
public interface PositionEntity extends TreeSortSupportEntity<String> {
public interface PositionEntity extends TreeSortSupportEntity<String>, DepartmentAttachEntity, PositionAttachEntity {
/*-------------------------------------------
| 属性名常量 |
===========================================*/
@@ -73,16 +74,6 @@ public interface PositionEntity extends TreeSortSupportEntity<String> {
*/
void setName(String name);
/**
* @return 部门id
*/
String getDepartmentId();
/**
* 设置 部门id
*/
void setDepartmentId(String departmentId);
/**
* @return 持有的角色
*/
@@ -105,4 +96,12 @@ public interface PositionEntity extends TreeSortSupportEntity<String> {
void setChildren(List<PositionEntity> children);
@Override
default String getPositionId() {
return getId();
}
default void setPositionId(String positionId) {
setId(positionId);
}
}

View File

@@ -39,6 +39,18 @@ public class SimpleOrganizationalEntity extends SimpleTreeSortSupportEntity<Stri
//子级组织
private List<OrganizationalEntity> children;
private String areaId;
@Override
public String getAreaId() {
return areaId;
}
@Override
public void setAreaId(String areaId) {
this.areaId = areaId;
}
/**
* @return 名称
*/

View File

@@ -1,9 +1,12 @@
package org.hswebframework.web.organizational.authorization.entity;
package org.hswebframework.web.entity.organizational.authorization;
import org.hswebframework.web.commons.entity.Entity;
/**
* 关联机构信息实体,实现该接口,表示实体与机构进行关联,在进行权限控制时,将会使用到该接口
*
* @author zhouhao
* @since 3.0
*/
public interface OrgAttachEntity extends Entity {
String orgId = "orgId";

View File

@@ -1,8 +1,9 @@
package org.hswebframework.web.organizational.authorization.entity;
package org.hswebframework.web.entity.organizational.authorization;
import org.hswebframework.web.commons.entity.Entity;
/**
* 关联人员信息实体,实现该接口,表示实体与机构进行关联,在进行权限控制时,将会使用到该接口
* @author zhouhao
*/
public interface PersonAttachEntity extends Entity {