Pārlūkot izejas kodu

Merge remote-tracking branch 'origin/master'

zhouhao 7 gadi atpakaļ
vecāks
revīzija
6a9efc52e6
33 mainītis faili ar 362 papildinājumiem un 78 dzēšanām
  1. 20 6
      hsweb-authorization/hsweb-authorization-basic/src/test/java/org/hswebframework/web/authorization/AuthorizeTests.java
  2. 13 6
      hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/mapper/EnumDicInTermTypeMapper.java
  3. 1 0
      hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/DataStatusEnum.java
  4. 5 2
      hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/AbstractTreeSortService.java
  5. 30 2
      hsweb-commons/hsweb-commons-utils/src/main/java/org/hswebframework/web/AopUtils.java
  6. 16 4
      hsweb-core/src/main/java/org/hswebframework/web/BusinessException.java
  7. 6 1
      hsweb-core/src/main/java/org/hswebframework/web/dict/EnumDict.java
  8. 2 0
      hsweb-core/src/test/java/org/hswebframework/web/bean/Color.java
  9. 6 1
      hsweb-datasource/hsweb-datasource-jta/src/main/java/org/hswebframework/web/datasource/jta/AtomikosDataSourceAutoConfiguration.java
  10. 1 1
      hsweb-starter/hsweb-spring-boot-starter/src/main/java/org/hswebframework/web/starter/RestControllerExceptionTranslator.java
  11. 6 0
      hsweb-system/hsweb-system-authorization/hsweb-system-authorization-controller/src/main/java/org/hswebframework/web/controller/authorization/UserController.java
  12. 7 2
      hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/events/UserPasswordModifiedEvent.java
  13. 1 1
      hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleAuthorizationSettingService.java
  14. 12 9
      hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleUserService.java
  15. 6 4
      hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/main/java/org/hswebframework/web/authorization/starter/AutoSyncPermission.java
  16. 1 1
      hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/main/resources/hsweb-starter.js
  17. 15 0
      hsweb-system/hsweb-system-calendar/hsweb-system-calendar-api/pom.xml
  18. 5 0
      hsweb-system/hsweb-system-calendar/hsweb-system-calendar-api/src/main/java/org/hswebframework/web/calendar/api/Calendar.java
  19. 4 0
      hsweb-system/hsweb-system-calendar/hsweb-system-calendar-api/src/main/java/org/hswebframework/web/calendar/api/CalendarEvent.java
  20. 6 0
      hsweb-system/hsweb-system-calendar/hsweb-system-calendar-api/src/main/java/org/hswebframework/web/calendar/api/CalendarService.java
  21. 15 0
      hsweb-system/hsweb-system-calendar/hsweb-system-calendar-cluster/pom.xml
  22. 15 0
      hsweb-system/hsweb-system-calendar/hsweb-system-calendar-local/pom.xml
  23. 21 0
      hsweb-system/hsweb-system-calendar/pom.xml
  24. 5 0
      hsweb-system/hsweb-system-organizational/hsweb-system-organizational-authorization/pom.xml
  25. 1 9
      hsweb-system/hsweb-system-organizational/hsweb-system-organizational-authorization/src/main/java/org/hswebframework/web/organizational/authorization/DefaultPersonnelAuthorizationSupplier.java
  26. 6 2
      hsweb-system/hsweb-system-organizational/hsweb-system-organizational-authorization/src/main/java/org/hswebframework/web/organizational/authorization/OrganizationalAuthorizationAutoConfiguration.java
  27. 65 0
      hsweb-system/hsweb-system-organizational/hsweb-system-organizational-authorization/src/main/java/org/hswebframework/web/organizational/authorization/PersonnelAuthorizationSettingTypeSupplier.java
  28. 17 0
      hsweb-system/hsweb-system-organizational/hsweb-system-organizational-service/hsweb-system-organizational-service-simple/src/main/java/org/hswebframework/web/service/organizational/simple/SimpleDepartmentService.java
  29. 14 1
      hsweb-system/hsweb-system-organizational/hsweb-system-organizational-service/hsweb-system-organizational-service-simple/src/main/java/org/hswebframework/web/service/organizational/simple/SimpleDistrictService.java
  30. 18 0
      hsweb-system/hsweb-system-organizational/hsweb-system-organizational-service/hsweb-system-organizational-service-simple/src/main/java/org/hswebframework/web/service/organizational/simple/SimpleOrganizationalService.java
  31. 7 26
      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
  32. 14 0
      hsweb-system/hsweb-system-organizational/hsweb-system-organizational-service/hsweb-system-organizational-service-simple/src/main/java/org/hswebframework/web/service/organizational/simple/SimplePositionService.java
  33. 1 0
      hsweb-system/pom.xml

+ 20 - 6
hsweb-authorization/hsweb-authorization-basic/src/test/java/org/hswebframework/web/authorization/AuthorizeTests.java

@@ -91,7 +91,7 @@ public class AuthorizeTests {
 
     @Test
     public void testParseAuthorizeDefinition() {
-        AuthorizeDefinition definition = parser.parse(queryById.getTarget().getClass(),queryById.getMethod());
+        AuthorizeDefinition definition = parser.parse(queryById.getTarget().getClass(), queryById.getMethod());
 
         Assert.assertNotNull(definition);
         Assert.assertEquals(definition.getPermissions().size(), 1);
@@ -103,7 +103,7 @@ public class AuthorizeTests {
     public void testAuthorizingHandler() {
         DefaultAuthorizingHandler handler = new DefaultAuthorizingHandler();
 
-        AuthorizeDefinition definition = parser.parse(queryById.getTarget().getClass(),queryById.getMethod());
+        AuthorizeDefinition definition = parser.parse(queryById.getTarget().getClass(), queryById.getMethod());
 
         AuthorizingContext authorizingContext = new AuthorizingContext();
         authorizingContext.setAuthentication(authentication);
@@ -126,7 +126,7 @@ public class AuthorizeTests {
         handler.setDataAccessController(controller);
 
 
-        AuthorizeDefinition definition = parser.parse(dynamicQuery.getTarget().getClass(),dynamicQuery.getMethod());
+        AuthorizeDefinition definition = parser.parse(dynamicQuery.getTarget().getClass(), dynamicQuery.getMethod());
 
         //获取到请求参数
         QueryParamEntity entity = dynamicQuery.<QueryParamEntity>getParameter("paramEntity").orElseThrow(NullPointerException::new);
@@ -157,7 +157,7 @@ public class AuthorizeTests {
         handler.setDataAccessController(controller);
 
 
-        AuthorizeDefinition definition = parser.parse(queryById.getTarget().getClass(),queryById.getMethod());
+        AuthorizeDefinition definition = parser.parse(queryById.getTarget().getClass(), queryById.getMethod());
 
         //响应结果
         Object response = queryById.getInvokeResult();
@@ -178,9 +178,8 @@ public class AuthorizeTests {
     }
 
     @Authorize(permission = "test")
-    public static class TestClass {
+    public static class TestClass implements TestClassSuper {
 
-        @Authorize(action = Permission.ACTION_QUERY, phased = Phased.after, dataAccess = @RequiresDataAccess)
         public ResponseMessage<User> queryById(String id) {
             return ResponseMessage.ok();
         }
@@ -193,6 +192,21 @@ public class AuthorizeTests {
 
     }
 
+    public interface TestClassSuper {
+
+        @Authorize(action = Permission.ACTION_QUERY, phased = Phased.after, dataAccess = @RequiresDataAccess)
+        default ResponseMessage<User> queryById(String id) {
+            return ResponseMessage.ok();
+        }
+
+        @Authorize(action = Permission.ACTION_QUERY)
+        @RequiresDataAccess
+        default void dynamicQuery(QueryParamEntity paramEntity) {
+            System.out.println(JSON.toJSON(paramEntity));
+        }
+
+    }
+
     @Getter
     @Setter
     @Builder

+ 13 - 6
hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/mapper/EnumDicInTermTypeMapper.java

@@ -40,12 +40,19 @@ public abstract class EnumDicInTermTypeMapper implements TermTypeMapper {
         if (type.isArray()) {
             Class componentType = type.getComponentType();
             if (support(column)) {
-                EnumDict[] newValue = param2list(value)
-                        .stream().map(v -> EnumDict.find(componentType, v).orElse(null))
-                        .filter(Objects::nonNull)
-                        .toArray(EnumDict[]::new);
-                long bit = EnumDict.toBit(newValue);
-                term.setValue(bit);
+                if(componentType.getEnumConstants().length<64){
+                    EnumDict[] newValue = param2list(value)
+                            .stream().map(v -> EnumDict.find(componentType, v).orElse(null))
+                            .filter(Objects::nonNull)
+                            .toArray(EnumDict[]::new);
+                    long bit = EnumDict.toBit(newValue);
+                    term.setValue(bit);
+                }else{
+                    //枚举数量大于等于64,无法使用位运算
+                    // TODO: 2018/4/25 尝试查询字典中间表
+                    buildNotSupport(wherePrefix,term,column,tableAlias);
+                }
+
             } else {
                 return buildNotSupport(wherePrefix, term, column, tableAlias);
             }

+ 1 - 0
hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/DataStatusEnum.java

@@ -15,4 +15,5 @@ public enum DataStatusEnum implements EnumDict<Byte> {
     private Byte value;
 
     private String text;
+
 }

+ 5 - 2
hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/AbstractTreeSortService.java

@@ -64,7 +64,10 @@ public abstract class AbstractTreeSortService<E extends TreeSortSupportEntity<PK
     }
 
     protected void applyPath(E entity) {
-        if (!StringUtils.isEmpty(entity.getParentId())) {
+        if (StringUtils.isEmpty(entity.getParentId())) {
+            entity.setSortIndex(0L);
+            entity.setParentId(createParentIdOnExists());
+            entity.setPath(RandomUtil.randomChar(4));
             return;
         }
         if (!StringUtils.isEmpty(entity.getPath())) {
@@ -125,11 +128,11 @@ public abstract class AbstractTreeSortService<E extends TreeSortSupportEntity<PK
     public PK saveOrUpdateForSingle(E entity) {
         assertNotNull(entity);
         PK id = entity.getId();
-        applyPath(entity);
         if (null == id || this.selectByPk(id) == null) {
             if (null == id) {
                 entity.setId(getIDGenerator().generate());
             }
+            applyPath(entity);
             return super.insert(entity);
         }
         super.updateByPk(entity);

+ 30 - 2
hsweb-commons/hsweb-commons-utils/src/main/java/org/hswebframework/web/AopUtils.java

@@ -21,11 +21,12 @@ import org.aspectj.lang.JoinPoint;
 import org.aspectj.lang.reflect.MethodSignature;
 import org.springframework.core.annotation.AnnotationUtils;
 import org.springframework.util.ClassUtils;
+import org.springframework.util.ReflectionUtils;
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
-import java.util.LinkedHashMap;
-import java.util.Map;
+import java.util.*;
+import java.util.stream.Stream;
 
 public final class AopUtils {
 
@@ -40,6 +41,33 @@ public final class AopUtils {
         }
         m = ClassUtils.getMostSpecificMethod(m, targetClass);
         a = AnnotationUtils.findAnnotation(m, annClass);
+        if (a == null) {
+            List<Class> supers = new ArrayList<>();
+            supers.addAll(Arrays.asList(targetClass.getInterfaces()));
+            if (targetClass.getSuperclass() != Object.class) {
+                supers.add(targetClass.getSuperclass());
+            }
+
+            for (Class aClass : supers) {
+                if(aClass==null){
+                    continue;
+                }
+                Method ims[] = new Method[1];
+
+                ReflectionUtils.doWithMethods(aClass, im -> {
+                    if (im.getName().equals(method.getName()) && im.getParameterCount() == method.getParameterCount()) {
+                        ims[0] = im;
+                    }
+                });
+
+                if (ims[0] != null) {
+                    a = findMethodAnnotation(aClass, ims[0], annClass);
+                    if (a != null) {
+                        return a;
+                    }
+                }
+            }
+        }
         return a;
     }
 

+ 16 - 4
hsweb-core/src/main/java/org/hswebframework/web/BusinessException.java

@@ -18,6 +18,8 @@
 
 package org.hswebframework.web;
 
+import lombok.Getter;
+
 /**
  * 业务异常
  *
@@ -27,12 +29,26 @@ package org.hswebframework.web;
 public class BusinessException extends RuntimeException {
     private static final long serialVersionUID = 5441923856899380112L;
 
+    @Getter
     private int status = 500;
 
+    @Getter
+    private String code;
+
     public BusinessException(String message) {
         this(message, 500);
     }
 
+    public BusinessException(String message, String code) {
+        this(message, code, 500);
+    }
+
+    public BusinessException(String message, String code, int status) {
+        super(message);
+        this.code = code;
+        this.status = status;
+    }
+
     public BusinessException(String message, int status) {
         super(message);
         this.status = status;
@@ -46,8 +62,4 @@ public class BusinessException extends RuntimeException {
         super(message, cause);
         this.status = status;
     }
-
-    public int getStatus() {
-        return status;
-    }
 }

+ 6 - 1
hsweb-core/src/main/java/org/hswebframework/web/dict/EnumDict.java

@@ -9,6 +9,7 @@ import java.util.function.Predicate;
  * 枚举字典,使用枚举来实现数据字典,可通过集成此接口来实现一些有趣的功能.
  * ⚠️:如果使用了位运算来判断枚举,枚举数量不要超过64个,且顺序不要随意变动!
  * 如果枚举数量大于64,你应该使用{@link org.hswebframework.web.dict.apply.DictApply}来处理
+ *
  * @author zhouhao
  * @see 3.0
  */
@@ -36,8 +37,12 @@ public interface EnumDict<V> {
      */
     int ordinal();
 
+    default long index() {
+        return ordinal();
+    }
+
     default long getBit() {
-        return 1L << (long) ordinal();
+        return 1L << index();
     }
 
     /**

+ 2 - 0
hsweb-core/src/test/java/org/hswebframework/web/bean/Color.java

@@ -14,4 +14,6 @@ public enum Color implements EnumDict<Integer> {
 
     private String text;
 
+
+
 }

+ 6 - 1
hsweb-datasource/hsweb-datasource-jta/src/main/java/org/hswebframework/web/datasource/jta/AtomikosDataSourceAutoConfiguration.java

@@ -1,6 +1,9 @@
 package org.hswebframework.web.datasource.jta;
 
+import org.hswebframework.web.datasource.DynamicDataSourceAutoConfiguration;
+import org.hswebframework.web.datasource.DynamicDataSourceService;
 import org.hswebframework.web.datasource.config.DynamicDataSourceConfigRepository;
+import org.springframework.boot.autoconfigure.AutoConfigureBefore;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
 import org.springframework.boot.jta.atomikos.AtomikosDataSourceBean;
 import org.springframework.context.annotation.Bean;
@@ -14,6 +17,7 @@ import java.sql.SQLException;
  * @author zhouhao
  */
 @Configuration
+@AutoConfigureBefore(DynamicDataSourceAutoConfiguration.class)
 public class AtomikosDataSourceAutoConfiguration {
 
     //默认数据源
@@ -30,7 +34,8 @@ public class AtomikosDataSourceAutoConfiguration {
     }
 
     @Bean
-    public JtaDynamicDataSourceService jtaDynamicDataSourceService(DynamicDataSourceConfigRepository<AtomikosDataSourceConfig> repository
+    @Primary
+    public DynamicDataSourceService jtaDynamicDataSourceService(DynamicDataSourceConfigRepository<AtomikosDataSourceConfig> repository
             , DataSource dataSource) throws SQLException {
         return new JtaDynamicDataSourceService(repository, dataSource);
     }

+ 1 - 1
hsweb-starter/hsweb-spring-boot-starter/src/main/java/org/hswebframework/web/starter/RestControllerExceptionTranslator.java

@@ -75,7 +75,7 @@ public class RestControllerExceptionTranslator {
         if (exception.getCause() != null) {
             logger.error("{}:{}", exception.getMessage(), exception.getStatus(), exception.getCause());
         }
-        return ResponseMessage.error(exception.getStatus(), exception.getMessage());
+        return ResponseMessage.error(exception.getStatus(), exception.getMessage()).result(exception.getCode());
     }
 
     @ExceptionHandler(UnAuthorizedException.class)

+ 6 - 0
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-controller/src/main/java/org/hswebframework/web/controller/authorization/UserController.java

@@ -19,6 +19,7 @@ package org.hswebframework.web.controller.authorization;
 
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import org.hswebframework.web.AopUtils;
 import org.hswebframework.web.authorization.Authentication;
 import org.hswebframework.web.authorization.Permission;
 import org.hswebframework.web.authorization.annotation.Authorize;
@@ -77,6 +78,11 @@ public class UserController implements
                 .exclude(UserEntity.class, "password", "salt");
     }
 
+    public static void main(String[] args) throws NoSuchMethodException {
+        System.out.println(AopUtils
+                .findMethodAnnotation(UserController.class,UserController.class.getMethod("list",QueryParamEntity.class),Authorize.class));
+    }
+
     @Override
     @SuppressWarnings("all")
     public ResponseMessage<UserEntity> getByPrimaryKey(@PathVariable String id) {

+ 7 - 2
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/events/UserPasswordModifiedEvent.java

@@ -2,6 +2,7 @@ package org.hswebframework.web.service.authorization.events;
 
 import lombok.AllArgsConstructor;
 import lombok.Getter;
+import org.hswebframework.web.entity.authorization.UserEntity;
 
 /**
  * 用户密码发生修改时事件
@@ -13,6 +14,10 @@ import lombok.Getter;
  */
 @AllArgsConstructor
 @Getter
-public class UserPasswordModifiedEvent {
-    private String userId;
+public class UserModifiedEvent {
+    private UserEntity userEntity;
+
+    private boolean passwordModified;
+
+    private boolean roleModified;
 }

+ 1 - 1
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleAuthorizationSettingService.java

@@ -374,7 +374,7 @@ public class SimpleAuthorizationSettingService extends GenericEntityService<Auth
             Collections.sort(details);
             for (AuthorizationSettingDetailEntity detail : details) {
                 //如果指定不合并相同的配置,则清空之前的配置
-                if (!Boolean.TRUE.equals(detail.getMerge())) {
+                if (Boolean.FALSE.equals(detail.getMerge())) {
                     actions.clear();
                     dataAccessConfigs.clear();
                 }

+ 12 - 9
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleUserService.java

@@ -15,7 +15,7 @@ import org.hswebframework.web.service.AbstractService;
 import org.hswebframework.web.service.DefaultDSLQueryService;
 import org.hswebframework.web.service.DefaultDSLUpdateService;
 import org.hswebframework.web.service.authorization.*;
-import org.hswebframework.web.service.authorization.events.UserPasswordModifiedEvent;
+import org.hswebframework.web.service.authorization.events.UserModifiedEvent;
 import org.hswebframework.web.validate.ValidationException;
 import org.hswebframework.utils.ListUtils;
 import org.hswebframework.web.validator.group.CreateGroup;
@@ -25,13 +25,13 @@ import org.springframework.cache.annotation.Caching;
 import org.springframework.context.ApplicationEventPublisher;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.Assert;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 
 import java.util.*;
 import java.util.stream.Collectors;
 
+import static org.hswebframework.web.service.DefaultDSLUpdateService.*;
 import static org.hswebframework.web.service.authorization.simple.CacheConstants.USER_AUTH_CACHE_NAME;
 import static org.hswebframework.web.service.authorization.simple.CacheConstants.USER_CACHE_NAME;
 
@@ -172,6 +172,8 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
         userEntity.setId(userId);
         UserEntity oldUser = selectByPk(userId);
         assertNotNull(oldUser);
+        boolean roleModified = false;
+        boolean passwordModified = false;
         //判断用户是否存在
         boolean userExists = createQuery().where()
                 .is(UserEntity.username, userEntity.getUsername())
@@ -186,10 +188,10 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
             //密码MD5
             userEntity.setPassword(encodePassword(userEntity.getPassword(), oldUser.getSalt()));
             updateProperties.add(UserEntity.password);
-
+            passwordModified = true;
         }
         //修改数据
-        DefaultDSLUpdateService.createUpdate(getDao(), userEntity)
+        createUpdate(getDao(), userEntity)
                 .includes(updateProperties.toArray(new String[updateProperties.size()]))
                 .where(GenericEntity.id, userEntity.getId())
                 .exec();
@@ -199,15 +201,16 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
             userRoleDao.deleteByUserId(bindRoleUserEntity.getId());
             //同步角色信息
             trySyncUserRole(userEntity.getId(), bindRoleUserEntity.getRoles());
+            roleModified = true;
         }
         if (updateProperties.contains(UserEntity.password)) {
-            publisher.publishEvent(new UserPasswordModifiedEvent(userId));
+            publisher.publishEvent(new UserModifiedEvent(userEntity, passwordModified, roleModified));
         }
     }
 
     @Override
     public boolean enable(String userId) {
-        return DefaultDSLUpdateService.createUpdate(getDao())
+        return createUpdate(getDao())
                 .set(UserEntity.status, DataStatus.STATUS_ENABLED)
                 .where(GenericEntity.id, userId)
                 .exec() > 0;
@@ -215,7 +218,7 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
 
     @Override
     public boolean disable(String userId) {
-        return DefaultDSLUpdateService.createUpdate(getDao())
+        return createUpdate(getDao())
                 .set(UserEntity.status, DataStatus.STATUS_DISABLED)
                 .where(GenericEntity.id, userId)
                 .exec() > 0;
@@ -232,11 +235,11 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
         tryValidateProperty(passwordStrengthValidator, UserEntity.password, newPassword);
 
         newPassword = encodePassword(newPassword, userEntity.getSalt());
-        DefaultDSLUpdateService.createUpdate(getDao())
+        createUpdate(getDao())
                 .set(UserEntity.password, newPassword)
                 .where(GenericEntity.id, userId)
                 .exec();
-        publisher.publishEvent(new UserPasswordModifiedEvent(userId));
+        publisher.publishEvent(new UserModifiedEvent(userEntity, true, false));
     }
 
 

+ 6 - 4
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/main/java/org/hswebframework/web/authorization/starter/AutoSyncPermission.java

@@ -9,8 +9,6 @@ import org.hswebframework.web.authorization.define.AuthorizeDefinition;
 import org.hswebframework.web.authorization.define.AuthorizeDefinitionInitializedEvent;
 import org.hswebframework.web.commons.entity.DataStatus;
 import org.hswebframework.web.commons.entity.factory.EntityFactory;
-import org.hswebframework.web.controller.GenericEntityController;
-import org.hswebframework.web.controller.authorization.UserController;
 import org.hswebframework.web.entity.authorization.ActionEntity;
 import org.hswebframework.web.entity.authorization.OptionalField;
 import org.hswebframework.web.entity.authorization.PermissionEntity;
@@ -20,6 +18,8 @@ import org.springframework.context.ApplicationListener;
 import org.springframework.util.ReflectionUtils;
 
 import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Modifier;
 import java.util.*;
 import java.util.function.Function;
 import java.util.stream.Collectors;
@@ -116,8 +116,10 @@ public class AutoSyncPermission implements ApplicationListener<AuthorizeDefiniti
                 List<OptionalField> optionalFields = new ArrayList<>();
                 entity.setOptionalFields(optionalFields);
                 if (genType != Object.class) {
-                    List<Field> fields=new ArrayList<>();
-                    ReflectionUtils.doWithFields(genType, fields::add);
+                    List<Field> fields = new ArrayList<>();
+
+                    ReflectionUtils.doWithFields(genType, fields::add, field -> field.getModifiers() != Modifier.STATIC);
+
                     for (Field field : fields) {
                         if ("id".equals(field.getName())) {
                             continue;

+ 1 - 1
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/main/resources/hsweb-starter.js

@@ -161,7 +161,7 @@ function install(context) {
         .addColumn().name("setting_id").varchar(32).notNull().comment("自定义配置id").commit()
         .addColumn().name("create_time").datetime().notNull().comment("创建时间").commit()
         .addColumn().name("update_time").datetime().comment("创建时间").commit()
-        .comment("角色表").commit();
+        .comment("用户设置表").commit();
 }
 
 //设置依赖

+ 15 - 0
hsweb-system/hsweb-system-calendar/hsweb-system-calendar-api/pom.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>hsweb-system-calendar</artifactId>
+        <groupId>org.hswebframework.web</groupId>
+        <version>3.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>hsweb-system-calendar-api</artifactId>
+
+
+</project>

+ 5 - 0
hsweb-system/hsweb-system-calendar/hsweb-system-calendar-api/src/main/java/org/hswebframework/web/calendar/api/Calendar.java

@@ -0,0 +1,5 @@
+package org.hswebframework.web.calendar.api;
+
+public interface Calendar {
+
+}

+ 4 - 0
hsweb-system/hsweb-system-calendar/hsweb-system-calendar-api/src/main/java/org/hswebframework/web/calendar/api/CalendarEvent.java

@@ -0,0 +1,4 @@
+package org.hswebframework.web.calendar.api;
+
+public interface CalendarEvent {
+}

+ 6 - 0
hsweb-system/hsweb-system-calendar/hsweb-system-calendar-api/src/main/java/org/hswebframework/web/calendar/api/CalendarService.java

@@ -0,0 +1,6 @@
+package org.hswebframework.web.calendar.api;
+
+public class CalendarService {
+
+
+}

+ 15 - 0
hsweb-system/hsweb-system-calendar/hsweb-system-calendar-cluster/pom.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>hsweb-system-calendar</artifactId>
+        <groupId>org.hswebframework.web</groupId>
+        <version>3.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>hsweb-system-calendar-cluster</artifactId>
+
+
+</project>

+ 15 - 0
hsweb-system/hsweb-system-calendar/hsweb-system-calendar-local/pom.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>hsweb-system-calendar</artifactId>
+        <groupId>org.hswebframework.web</groupId>
+        <version>3.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>hsweb-system-calendar-local</artifactId>
+
+
+</project>

+ 21 - 0
hsweb-system/hsweb-system-calendar/pom.xml

@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>hsweb-system</artifactId>
+        <groupId>org.hswebframework.web</groupId>
+        <version>3.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>hsweb-system-calendar</artifactId>
+    <packaging>pom</packaging>
+    <modules>
+        <module>hsweb-system-calendar-api</module>
+        <module>hsweb-system-calendar-local</module>
+        <module>hsweb-system-calendar-cluster</module>
+    </modules>
+
+
+</project>

+ 5 - 0
hsweb-system/hsweb-system-organizational/hsweb-system-organizational-authorization/pom.xml

@@ -41,6 +41,11 @@
             <artifactId>hsweb-system-organizational-entity</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.hswebframework.web</groupId>
+            <artifactId>hsweb-system-authorization-service-api</artifactId>
+            <version>${project.version}</version>
+        </dependency>
     </dependencies>
 
 

+ 1 - 9
hsweb-system/hsweb-system-organizational/hsweb-system-organizational-authorization/src/main/java/org/hswebframework/web/organizational/authorization/DefaultPersonnelAuthorizationSupplier.java

@@ -34,17 +34,9 @@ public class DefaultPersonnelAuthorizationSupplier implements PersonnelAuthoriza
 
     @Override
     public PersonnelAuthorization get() {
-        /*
-            获取逻辑: 优先获取登录用户的权限信息中Authentication的personId属性;
-            如果不存在,则根据用户id获取.如果还不存在则返回null
-         */
         //TreadLocal Cache
         return ThreadLocalUtils.get(threadLocalCacheKey, () ->
-                Authentication.current().map(authentication ->
-                        authentication.getAttribute(PersonAttachEntity.personId)
-                                .map(String::valueOf)
-                                .map(this::getByPersonId)
-                                .orElseGet(() -> getByUserId(authentication.getUser().getId())))
+                Authentication.current().map(authentication -> getByUserId(authentication.getUser().getId()))
                         .orElse(null));
     }
 }

+ 6 - 2
hsweb-system/hsweb-system-organizational/hsweb-system-organizational-authorization/src/main/java/org/hswebframework/web/organizational/authorization/OrganizationalAuthorizationAutoConfiguration.java

@@ -11,8 +11,6 @@ import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
 /**
- * TODO 完成注释
- *
  * @author zhouhao
  */
 @Configuration
@@ -88,9 +86,15 @@ public class OrganizationalAuthorizationAutoConfiguration implements BeanPostPro
     @Configuration
     @ConditionalOnBean(PersonnelAuthorizationManager.class)
     public static class PersonnelAuthorizationSupplierAutoConfiguration {
+
         @Bean
         public DefaultPersonnelAuthorizationSupplier personnelAuthorizationManager(PersonnelAuthorizationManager personnelAuthorizationManager) {
             return new DefaultPersonnelAuthorizationSupplier(personnelAuthorizationManager);
         }
+
+        @Bean
+        public PersonnelAuthorizationSettingTypeSupplier personnelAuthorizationSettingTypeSupplier() {
+            return new PersonnelAuthorizationSettingTypeSupplier();
+        }
     }
 }

+ 65 - 0
hsweb-system/hsweb-system-organizational/hsweb-system-organizational-authorization/src/main/java/org/hswebframework/web/organizational/authorization/PersonnelAuthorizationSettingTypeSupplier.java

@@ -0,0 +1,65 @@
+package org.hswebframework.web.organizational.authorization;
+
+import org.hswebframework.web.service.authorization.AuthorizationSettingTypeSupplier;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+public class PersonnelAuthorizationSettingTypeSupplier implements AuthorizationSettingTypeSupplier {
+    public static final String SETTING_TYPE_PERSON = "person";
+
+    public static final String SETTING_TYPE_DEPARTMENT = "department";
+
+    public static final String SETTING_TYPE_ORG = "org";
+
+    public static final String SETTING_TYPE_DISTRICT = "district";
+
+    public static final String SETTING_TYPE_POSITION = "position";
+
+    @Autowired
+    private PersonnelAuthorizationManager personnelAuthorizationManager;
+
+    @Override
+    public Set<SettingInfo> get(String userId) {
+        //支持职位和人员 设置权限
+        PersonnelAuthorization authorization = personnelAuthorizationManager.getPersonnelAuthorizationByUserId(userId);
+        if (authorization == null) {
+            return new HashSet<>();
+        }
+        Set<SettingInfo> settingInfo = new HashSet<>();
+
+
+        //人员
+        SettingInfo personSetting = new SettingInfo(SETTING_TYPE_PERSON, authorization.getPersonnel().getId());
+        settingInfo.add(personSetting);
+
+        //岗位
+        settingInfo.addAll(authorization.getAllPositionId()
+                .stream()
+                .map(id -> new SettingInfo(SETTING_TYPE_POSITION, id))
+                .collect(Collectors.toSet()));
+
+        //部门
+        settingInfo.addAll(authorization.getAllDepartmentId()
+                .stream()
+                .map(id -> new SettingInfo(SETTING_TYPE_DEPARTMENT, id))
+                .collect(Collectors.toSet()));
+
+        //机构
+        settingInfo.addAll(authorization.getAllOrgId()
+                .stream()
+                .map(id -> new SettingInfo(SETTING_TYPE_ORG, id))
+                .collect(Collectors.toSet()));
+
+        //行政区域
+        settingInfo.addAll(authorization.getAllDistrictId()
+                .stream()
+                .map(id -> new SettingInfo(SETTING_TYPE_DISTRICT, id))
+                .collect(Collectors.toSet()));
+
+        return settingInfo;
+    }
+}

+ 17 - 0
hsweb-system/hsweb-system-organizational/hsweb-system-organizational-service/hsweb-system-organizational-service-simple/src/main/java/org/hswebframework/web/service/organizational/simple/SimpleDepartmentService.java

@@ -16,10 +16,14 @@
  */
 package org.hswebframework.web.service.organizational.simple;
 
+import org.hswebframework.web.BusinessException;
 import org.hswebframework.web.dao.organizational.DepartmentDao;
+import org.hswebframework.web.dao.organizational.PositionDao;
 import org.hswebframework.web.entity.organizational.DepartmentEntity;
+import org.hswebframework.web.entity.organizational.PositionEntity;
 import org.hswebframework.web.id.IDGenerator;
 import org.hswebframework.web.service.AbstractTreeSortService;
+import org.hswebframework.web.service.DefaultDSLQueryService;
 import org.hswebframework.web.service.EnableCacheAllEvictTreeSortService;
 import org.hswebframework.web.service.GenericEntityService;
 import org.hswebframework.web.service.organizational.DepartmentService;
@@ -45,6 +49,9 @@ public class SimpleDepartmentService
     @Autowired
     private DepartmentDao departmentDao;
 
+    @Autowired
+    protected PositionDao positionDao;
+
     @Override
     public DepartmentDao getDao() {
         return departmentDao;
@@ -72,4 +79,14 @@ public class SimpleDepartmentService
     public DepartmentEntity selectByCode(String code) {
         return createQuery().where(DepartmentEntity.code, code).single();
     }
+
+    @Override
+    public int deleteByPk(String id) {
+        if (DefaultDSLQueryService.createQuery(positionDao)
+                .where(PositionEntity.departmentId, id)
+                .total() > 0) {
+            throw new BusinessException("部门下存在职位信息,无法删除!");
+        }
+        return super.deleteByPk(id);
+    }
 }

+ 14 - 1
hsweb-system/hsweb-system-organizational/hsweb-system-organizational-service/hsweb-system-organizational-service-simple/src/main/java/org/hswebframework/web/service/organizational/simple/SimpleDistrictService.java

@@ -1,11 +1,14 @@
 package org.hswebframework.web.service.organizational.simple;
 
+import org.hswebframework.web.BusinessException;
 import org.hswebframework.web.commons.entity.DataStatus;
 import org.hswebframework.web.commons.entity.Entity;
 import org.hswebframework.web.dao.organizational.DistrictDao;
+import org.hswebframework.web.dao.organizational.OrganizationalDao;
 import org.hswebframework.web.entity.organizational.DistrictEntity;
 import org.hswebframework.web.entity.organizational.OrganizationalEntity;
 import org.hswebframework.web.service.AbstractTreeSortService;
+import org.hswebframework.web.service.DefaultDSLQueryService;
 import org.hswebframework.web.service.GenericEntityService;
 import org.hswebframework.web.id.IDGenerator;
 import org.hswebframework.web.service.organizational.DistrictService;
@@ -20,6 +23,8 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Objects;
 
+import static org.hswebframework.web.service.DefaultDSLQueryService.*;
+
 /**
  * 默认的服务实现
  *
@@ -32,6 +37,9 @@ public class SimpleDistrictService extends AbstractTreeSortService<DistrictEntit
     @Autowired
     private DistrictDao districtDao;
 
+    @Autowired
+    private OrganizationalDao organizationalDao;
+
     @Override
     protected IDGenerator<String> getIDGenerator() {
         return IDGenerator.MD5;
@@ -69,6 +77,11 @@ public class SimpleDistrictService extends AbstractTreeSortService<DistrictEntit
     @Override
     @CacheEvict(allEntries = true)
     public int deleteByPk(String id) {
+        if (DefaultDSLQueryService.createQuery(organizationalDao)
+                .where(OrganizationalEntity.orgId, id)
+                .total() > 0) {
+            throw new BusinessException("行政区域下存在机构信息,无法删除!");
+        }
         return super.deleteByPk(id);
     }
 
@@ -87,7 +100,7 @@ public class SimpleDistrictService extends AbstractTreeSortService<DistrictEntit
     @Override
     @Cacheable(key = "'all'")
     public List<DistrictEntity> select() {
-        return  createQuery().where().orderByAsc(DistrictEntity.sortIndex).listNoPaging();
+        return createQuery().where().orderByAsc(DistrictEntity.sortIndex).listNoPaging();
     }
 
     @Override

+ 18 - 0
hsweb-system/hsweb-system-organizational/hsweb-system-organizational-service/hsweb-system-organizational-service-simple/src/main/java/org/hswebframework/web/service/organizational/simple/SimpleOrganizationalService.java

@@ -16,10 +16,14 @@
  */
 package org.hswebframework.web.service.organizational.simple;
 
+import org.hswebframework.web.BusinessException;
 import org.hswebframework.web.commons.entity.DataStatus;
+import org.hswebframework.web.dao.organizational.DepartmentDao;
 import org.hswebframework.web.dao.organizational.OrganizationalDao;
+import org.hswebframework.web.entity.organizational.DepartmentEntity;
 import org.hswebframework.web.entity.organizational.OrganizationalEntity;
 import org.hswebframework.web.id.IDGenerator;
+import org.hswebframework.web.service.DefaultDSLQueryService;
 import org.hswebframework.web.service.EnableCacheAllEvictTreeSortService;
 import org.hswebframework.web.service.organizational.OrganizationalService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -44,6 +48,9 @@ public class SimpleOrganizationalService extends EnableCacheAllEvictTreeSortServ
     @Autowired
     private OrganizationalDao organizationalDao;
 
+    @Autowired
+    private DepartmentDao departmentDao;
+
     @Override
     public OrganizationalDao getDao() {
         return organizationalDao;
@@ -54,6 +61,17 @@ public class SimpleOrganizationalService extends EnableCacheAllEvictTreeSortServ
         return IDGenerator.MD5;
     }
 
+    @Override
+    public int deleteByPk(String id) {
+        if (DefaultDSLQueryService.createQuery(departmentDao)
+                .where(DepartmentEntity.orgId, id)
+                .total() > 0) {
+            throw new BusinessException("机构下存在部门信息,无法删除");
+        }
+
+        return super.deleteByPk(id);
+    }
+
     @Override
     @CacheEvict(allEntries = true)
     public String insert(OrganizationalEntity entity) {

+ 7 - 26
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

@@ -60,10 +60,8 @@ import static org.springframework.util.StringUtils.isEmpty;
 @Service("personService")
 @CacheConfig(cacheNames = "person")
 public class SimplePersonService extends GenericEntityService<PersonEntity, String>
-        implements PersonService, PersonnelAuthorizationManager, AuthorizationSettingTypeSupplier {
+        implements PersonService, PersonnelAuthorizationManager {
 
-    private static String SETTING_TYPE_PERSON   = "person";
-    private static String SETTING_TYPE_POSITION = "position";
 
     @Autowired
     private PersonDao personDao;
@@ -406,9 +404,13 @@ public class SimplePersonService extends GenericEntityService<PersonEntity, Stri
                                                                                             Set<String> rootIds,
                                                                                             BiConsumer<T, List<T>> childAccepter,
                                                                                             Consumer<List<T>> rootConsumer) {
+        if (rootIds.isEmpty()) {
+            return Collections.emptyList();
+        }
         //获取根节点
         List<T> root = DefaultDSLQueryService.createQuery(dao)
-                .where().in(TreeSupportEntity.id, rootIds)
+                .where()
+                .in(TreeSupportEntity.id, rootIds)
                 .listNoPaging();
         //节点不存在?
         if (!root.isEmpty()) {
@@ -457,26 +459,5 @@ public class SimplePersonService extends GenericEntityService<PersonEntity, Stri
         return getPersonnelAuthorizationByPersonId(entity.getId());
     }
 
-    @Override
-    public Set<SettingInfo> get(String userId) {
-        //支持职位和人员 设置权限
-        PersonEntity entity = createQuery().where(PersonEntity.userId, userId).single();
-        if (entity == null) {
-            return new HashSet<>();
-        }
-        Set<SettingInfo> settingInfo = new HashSet<>();
-        //岗位设置
-        //TODO 2017/06/08 是否将子级岗位的设置也放进来??
-        DefaultDSLQueryService.createQuery(personPositionDao)
-                .where(PersonPositionEntity.personId, entity.getId())
-                .listNoPaging()
-                .stream()
-                .map(position -> new SettingInfo(SETTING_TYPE_POSITION, position.getPositionId()))
-                .forEach(settingInfo::add);
-        //其他设置支持?
-
-        //人员配置
-        settingInfo.add(new SettingInfo(SETTING_TYPE_PERSON, entity.getId()));
-        return settingInfo;
-    }
+
 }

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

@@ -16,6 +16,8 @@
  */
 package org.hswebframework.web.service.organizational.simple;
 
+import org.hswebframework.web.BusinessException;
+import org.hswebframework.web.dao.organizational.PersonDao;
 import org.hswebframework.web.dao.organizational.PositionDao;
 import org.hswebframework.web.entity.organizational.PositionEntity;
 import org.hswebframework.web.id.IDGenerator;
@@ -23,6 +25,7 @@ import org.hswebframework.web.service.AbstractTreeSortService;
 import org.hswebframework.web.service.organizational.PositionService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 
 /**
  * 默认的服务实现
@@ -35,6 +38,9 @@ public class SimplePositionService extends AbstractTreeSortService<PositionEntit
     @Autowired
     private PositionDao positionDao;
 
+    @Autowired
+    private PersonDao personDao;
+
     @Override
     public PositionDao getDao() {
         return positionDao;
@@ -44,4 +50,12 @@ public class SimplePositionService extends AbstractTreeSortService<PositionEntit
     protected IDGenerator<String> getIDGenerator() {
         return IDGenerator.MD5;
     }
+
+    @Override
+    public int deleteByPk(String id) {
+        if(!CollectionUtils.isEmpty(personDao.selectByPositionId(id))){
+            throw new BusinessException("岗位中还有人员,无法删除!");
+        }
+        return super.deleteByPk(id);
+    }
 }

+ 1 - 0
hsweb-system/pom.xml

@@ -29,6 +29,7 @@
         <module>hsweb-system-dictionary</module>
         <module>hsweb-system-oauth2-server</module>
         <module>hsweb-system-oauth2-client</module>
+        <module>hsweb-system-calendar</module>
     </modules>
     <artifactId>hsweb-system</artifactId>