zhouhao преди 8 години
родител
ревизия
ce27e70c53

+ 14 - 0
hsweb-system/hsweb-system-organizational/hsweb-system-organizational-authorization/src/main/java/org/hswebframework/web/organizational/authorization/simple/SimpleScopeDataAccessConfig.java

@@ -16,6 +16,20 @@ public class SimpleScopeDataAccessConfig extends AbstractDataAccessConfig implem
     private Set<Object> scope;
     private String      type;
 
+    public SimpleScopeDataAccessConfig() {
+    }
+
+    public SimpleScopeDataAccessConfig(String scopeType, String type) {
+        this.scopeType = scopeType;
+        this.type = type;
+    }
+
+    public SimpleScopeDataAccessConfig(String scopeType, String type, Set<Object> scope) {
+        this.scopeType = scopeType;
+        this.scope = scope;
+        this.type = type;
+    }
+
     @Override
     public String getScopeType() {
         return scopeType;

+ 6 - 0
hsweb-system/hsweb-system-organizational/hsweb-system-organizational-entity/src/main/java/org/hswebframework/web/entity/organizational/PersonEntity.java

@@ -18,6 +18,8 @@ package org.hswebframework.web.entity.organizational;
 
 import org.hswebframework.web.commons.entity.GenericEntity;
 
+import java.util.Set;
+
 /**
  * 人员 实体
  *
@@ -140,4 +142,8 @@ public interface PersonEntity extends GenericEntity<String> {
      */
     void setRemark(String remark);
 
+    Set<String> getPositionIds();
+
+    void setPositionIds(Set<String> positionIds);
+
 }

+ 14 - 0
hsweb-system/hsweb-system-organizational/hsweb-system-organizational-entity/src/main/java/org/hswebframework/web/entity/organizational/SimplePersonEntity.java

@@ -20,6 +20,8 @@ import org.hibernate.validator.constraints.Email;
 import org.hibernate.validator.constraints.NotBlank;
 import org.hswebframework.web.commons.entity.SimpleGenericEntity;
 
+import java.util.Set;
+
 /**
  * 人员
  *
@@ -45,6 +47,8 @@ public class SimplePersonEntity extends SimpleGenericEntity<String> implements P
     //备注
     private String remark;
 
+    private Set<String> positionIds;
+
     /**
      * @return 姓名
      */
@@ -156,4 +160,14 @@ public class SimplePersonEntity extends SimpleGenericEntity<String> implements P
     public void setRemark(String remark) {
         this.remark = remark;
     }
+
+    @Override
+    public Set<String> getPositionIds() {
+        return positionIds;
+    }
+
+    @Override
+    public void setPositionIds(Set<String> positionIds) {
+        this.positionIds = positionIds;
+    }
 }

+ 36 - 32
hsweb-system/hsweb-system-organizational/hsweb-system-organizational-entity/src/main/java/org/hswebframework/web/entity/organizational/SimplePersonPositionEntity.java

@@ -15,42 +15,46 @@
  *  
  */
 package org.hswebframework.web.entity.organizational;
+
 import org.hswebframework.web.commons.entity.SimpleGenericEntity;
 
 /**
-* 人员职位关联
-* @author hsweb-generator-online
-*/
-public class SimplePersonPositionEntity extends SimpleGenericEntity<String> implements PersonPositionEntity{
-  		//人员id
-        private String personId;
-  		//职位id
-        private String positionId;
+ * 人员职位关联
+ *
+ * @author hsweb-generator-online
+ */
+public class SimplePersonPositionEntity extends SimpleGenericEntity<String> implements PersonPositionEntity {
+    //人员id
+    private String personId;
+    //职位id
+    private String positionId;
+
+    /**
+     * @return 人员id
+     */
+    public String getPersonId() {
+        return this.personId;
+    }
+
+    /**
+     * 设置 人员id
+     */
+    public void setPersonId(String personId) {
+        this.personId = personId;
+    }
 
-        /**
-        * @return  人员id
-        */
-        public String getPersonId(){
-			return this.personId;
-        }
+    /**
+     * @return 职位id
+     */
+    public String getPositionId() {
+        return this.positionId;
+    }
 
-        /**
-        * 设置 人员id
-        */
-        public void setPersonId(String personId){
-        	this.personId=personId;
-        }
-        /**
-        * @return  职位id
-        */
-        public String getPositionId(){
-			return this.positionId;
-        }
+    /**
+     * 设置 职位id
+     */
+    public void setPositionId(String positionId) {
+        this.positionId = positionId;
+    }
 
-        /**
-        * 设置 职位id
-        */
-        public void setPositionId(String positionId){
-        	this.positionId=positionId;
-        }
 }

+ 39 - 2
hsweb-system/hsweb-system-organizational/hsweb-system-organizational-service/hsweb-system-organizational-service-simple/src/main/java/org/hswebframework/web/service/organizational/simple/SimplePersonService.java

@@ -27,9 +27,13 @@ import org.hswebframework.web.organizational.authorization.TreeNode;
 import org.hswebframework.web.organizational.authorization.simple.SimplePersonnel;
 import org.hswebframework.web.organizational.authorization.simple.SimplePersonnelAuthorization;
 import org.hswebframework.web.service.DefaultDSLQueryService;
+import org.hswebframework.web.service.EnableCacheGernericEntityService;
 import org.hswebframework.web.service.GenericEntityService;
 import org.hswebframework.web.service.organizational.PersonService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheConfig;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 
 import java.util.Collections;
@@ -47,7 +51,8 @@ import java.util.stream.Collectors;
  * @author hsweb-generator-online
  */
 @Service("personService")
-public class SimplePersonService extends GenericEntityService<PersonEntity, String>
+@CacheConfig(cacheNames = "person")
+public class SimplePersonService extends EnableCacheGernericEntityService<PersonEntity, String>
         implements PersonService, PersonnelAuthorizationManager {
     @Autowired
     private PersonDao personDao;
@@ -76,10 +81,40 @@ public class SimplePersonService extends GenericEntityService<PersonEntity, Stri
 
     @Override
     public String insert(PersonEntity entity) {
-        return super.insert(entity);
+        String id = super.insert(entity);
+        if (entity.getPositionIds() != null) {
+            syncPositionInfo(id, entity.getPositionIds());
+        }
+        return id;
+    }
+
+    protected void syncPositionInfo(String personId, Set<String> positionIds) {
+        for (String positionId : positionIds) {
+            PersonPositionEntity positionEntity = entityFactory.newInstance(PersonPositionEntity.class);
+            positionEntity.setPersonId(personId);
+            positionEntity.setPositionId(positionId);
+            this.personPositionDao.insert(positionEntity);
+        }
+    }
+
+    @Override
+    protected int updateByPk(PersonEntity entity) {
+        int size = super.updateByPk(entity);
+        if (entity.getPositionIds() != null) {
+            personPositionDao.deleteByPersonId(entity.getId());
+            syncPositionInfo(entity.getId(), entity.getPositionIds());
+        }
+        return size;
+    }
+
+    @Override
+    public int deleteByPk(String id) {
+        personPositionDao.deleteByPersonId(id);
+        return super.deleteByPk(id);
     }
 
     @Override
+    @Cacheable(key = "'auth:persion-id'+#personId")
     public PersonnelAuthorization getPersonnelAuthorizationByPersonId(String personId) {
         SimplePersonnelAuthorization authorization = new SimplePersonnelAuthorization();
         PersonEntity entity = selectByPk(personId);
@@ -111,6 +146,7 @@ public class SimplePersonService extends GenericEntityService<PersonEntity, Stri
                         List<OrganizationalEntity> orgEntities = getAllChildrenAndReturnRootNode(organizationalDao, orgIds, OrganizationalEntity::setChildren, rootOrgList -> {
                             //根据机构获取地区
                             // TODO: 17-5-25
+
                         });
                         authorization.setOrgIds(transformationTreeNode(null, orgEntities));
                     }
@@ -178,6 +214,7 @@ public class SimplePersonService extends GenericEntityService<PersonEntity, Stri
     }
 
     @Override
+    @Cacheable(cacheNames = "person", key = "'auth:user-id'+#userId")
     public PersonnelAuthorization getPersonnelAuthorizationByUserId(String userId) {
         PersonEntity entity = createQuery().where(PersonEntity.userId, userId).single();
         assertNotNull(entity);

+ 0 - 2
hsweb-system/hsweb-system-organizational/hsweb-system-organizational-starter/src/test/java/org/hswebframework/web/starter/organizational/PersonTests.java

@@ -21,12 +21,10 @@ package org.hswebframework.web.starter.organizational;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import org.hswebframework.web.entity.organizational.PersonEntity;
-import org.hswebframework.web.entity.organizational.SimplePersonEntity;
 import org.hswebframework.web.starter.convert.FastJsonHttpMessageConverter;
 import org.hswebframework.web.tests.SimpleWebApplicationTests;
 import org.junit.Assert;
 import org.junit.Test;
-import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.MediaType;