Просмотр исходного кода

Merge remote-tracking branch 'origin/master'

zhou-hao 7 лет назад
Родитель
Сommit
7fac9f51ba
23 измененных файлов с 406 добавлено и 141 удалено
  1. 3 5
      hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/DefaultUserTokenManager.java
  2. 12 0
      hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/exception/UnCheckException.java
  3. 7 0
      hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/request/SimpleOAuth2Request.java
  4. 2 1
      hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/request/SimpleOAuth2Response.java
  5. 10 7
      hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/request/UnCheck.java
  6. 8 0
      hsweb-system/hsweb-system-authorization/hsweb-system-authorization-controller/src/main/java/org/hswebframework/web/controller/authorization/UserTokenInfoController.java
  7. 2 0
      hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/CacheConstants.java
  8. 12 11
      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
  9. 25 25
      hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleMenuService.java
  10. 1 1
      hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-controller/src/main/java/org/hswebframework/web/authorization/oauth2/controller/OAuth2ClientConfigController.java
  11. 4 4
      hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-starter/src/main/java/org/hswebframework/web/oauth2/OAuth2AuthorizationAutoConfiguration.java
  12. 1 1
      hsweb-system/hsweb-system-script/hsweb-system-script-controller/src/main/java/org/hswebframework/web/controller/script/ScriptController.java
  13. 91 83
      hsweb-system/hsweb-system-script/hsweb-system-script-entity/src/main/java/org/hswebframework/web/entity/script/ScriptEntity.java
  14. 0 1
      hsweb-system/hsweb-system-script/hsweb-system-script-service/hsweb-system-script-service-api/src/main/java/org/hswebframework/web/service/script/ScriptExecutorService.java
  15. 6 0
      hsweb-system/hsweb-system-script/hsweb-system-script-service/hsweb-system-script-service-simple/pom.xml
  16. 7 2
      hsweb-system/hsweb-system-script/hsweb-system-script-service/hsweb-system-script-service-simple/src/main/java/org/hswebframework/web/service/script/simple/DefaultScriptExecutorService.java
  17. 139 0
      hsweb-system/hsweb-system-script/hsweb-system-script-service/hsweb-system-script-service-simple/src/main/java/org/hswebframework/web/service/script/simple/MessagerScriptExecutorService.java
  18. 25 0
      hsweb-system/hsweb-system-script/hsweb-system-script-service/hsweb-system-script-service-simple/src/main/java/org/hswebframework/web/service/script/simple/ScriptExecutorMessage.java
  19. 17 0
      hsweb-system/hsweb-system-script/hsweb-system-script-service/hsweb-system-script-service-simple/src/main/java/org/hswebframework/web/service/script/simple/ScriptExecutorResultMessage.java
  20. 7 0
      hsweb-system/hsweb-system-script/hsweb-system-script-starter/pom.xml
  21. 23 0
      hsweb-system/hsweb-system-script/hsweb-system-script-starter/src/main/java/org/hswebframework/web/service/dynamic/script/DynamicScriptAutoConfiguration.java
  22. 3 0
      hsweb-system/hsweb-system-script/hsweb-system-script-starter/src/main/resources/META-INF/spring.factories
  23. 1 0
      hsweb-system/hsweb-system-script/hsweb-system-script-starter/src/test/java/org/hswebframework/web/workflow/flowable/ControllerTest.java

+ 3 - 5
hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/DefaultUserTokenManager.java

@@ -178,10 +178,9 @@ public class DefaultUserTokenManager implements UserTokenManager {
             String userId = tokenObject.getUserId();
             if (removeUserToken) {
                 Set<String> tokens = getUserToken(userId);
-                if (tokens.size() > 0) {
+                if (!tokens.isEmpty()) {
                     tokens.remove(token);
-                }
-                if (tokens.size() == 0) {
+                } else {
                     userStorage.remove(tokenObject.getUserId());
                 }
             }
@@ -264,8 +263,7 @@ public class DefaultUserTokenManager implements UserTokenManager {
     @Override
     public void checkExpiredToken() {
         for (SimpleUserToken token : tokenStorage.values()) {
-            checkTimeout(token);
-            if (token!=null&&token.isExpired()) {
+            if (token != null && checkTimeout(token).isExpired()) {
                 signOutByToken(token.getToken());
             }
         }

+ 12 - 0
hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/exception/UnCheckException.java

@@ -0,0 +1,12 @@
+package org.hswebframework.web.authorization.oauth2.client.exception;
+
+/**
+ *
+ * @author zhouhao
+ * @since 3.0
+ */
+public class UnCheckException extends RuntimeException {
+    public UnCheckException(Throwable cause) {
+        super(cause);
+    }
+}

+ 7 - 0
hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/request/SimpleOAuth2Request.java

@@ -140,6 +140,13 @@ public class SimpleOAuth2Request implements OAuth2Request {
             });
         }
         if (null != refreshTokenExpiredCallBack) {
+            //判定token是否有效,无效的token将重新申请token
+            auth2Response.judgeError(ErrorType.INVALID_TOKEN,() -> {
+                //调用回调,并指定重试的操作(重新请求)
+                refreshTokenExpiredCallBack.call(() -> createNativeResponse(responseSupplier));
+                //返回重试后的response
+                return auth2Response;
+            });
             //判定refresh_token是否过期,过期后先执行回调进行操作如更新token,并尝试重新请求
             auth2Response.judgeError(ErrorType.EXPIRED_REFRESH_TOKEN,() -> {
                 //调用回调,并指定重试的操作(重新请求)

+ 2 - 1
hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/request/SimpleOAuth2Response.java

@@ -64,7 +64,8 @@ public class SimpleOAuth2Response implements OAuth2Response {
 
                 if (type == ifError) {
                     //重试后依然是相同的错误,可能是错误类型判断错误或者服务端的问题?
-                    logger.error("still error [{}], maybe judge error or auth server error! ",ifError);
+                    logger.error("still error [{}], maybe judge error or auth server error! response:{}"
+                            ,ifError,retryResponse.asString());
                 } else {
                     errorType = type;
                 }

+ 10 - 7
hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/request/UnCheck.java

@@ -18,14 +18,17 @@
 
 package org.hswebframework.web.authorization.oauth2.client.simple.request;
 
+import org.hswebframework.web.authorization.oauth2.client.exception.UnCheckException;
+
 interface UnCheck<T> {
-        T call() throws Exception;
+    @SuppressWarnings("all")
+    T call() throws Exception;
 
-        static <T> T unCheck(UnCheck<T> unCheck) {
-            try {
-                return unCheck.call();
-            } catch (Exception e) {
-                throw new RuntimeException(e);
-            }
+    static <T> T unCheck(UnCheck<T> unCheck) {
+        try {
+            return unCheck.call();
+        } catch (Exception e) {
+            throw new UnCheckException(e);
         }
     }
+}

+ 8 - 0
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-controller/src/main/java/org/hswebframework/web/controller/authorization/UserTokenInfoController.java

@@ -74,4 +74,12 @@ public class UserTokenInfoController {
         return ResponseMessage.ok();
     }
 
+    @PutMapping("/check")
+    @ApiOperation("检查所有已过期的token并移除")
+    @Authorize(action = Permission.ACTION_UPDATE)
+    public ResponseMessage<Void> checkExpiredToken() {
+        userTokenManager.checkExpiredToken();
+        return ResponseMessage.ok();
+    }
+
 }

+ 2 - 0
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/CacheConstants.java

@@ -28,6 +28,8 @@ import org.hswebframework.web.authorization.AuthenticationManager;
 public interface CacheConstants {
     String MENU_CACHE_NAME = "hsweb-menu-";
 
+    String USER_MENU_CACHE_NAME = "hsweb-user-menu-";
+
     String USER_CACHE_NAME = "user-";
 
     String USER_AUTH_CACHE_NAME = AuthenticationManager.USER_AUTH_CACHE_NAME;

+ 12 - 11
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

@@ -39,6 +39,7 @@ 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.cache.annotation.Caching;
 import org.springframework.stereotype.Service;
 
 import java.util.*;
@@ -53,7 +54,9 @@ import static org.hswebframework.web.commons.entity.DataStatus.STATUS_ENABLED;
 import static org.hswebframework.web.entity.authorization.AuthorizationSettingDetailEntity.*;
 import static org.hswebframework.web.entity.authorization.AuthorizationSettingEntity.settingFor;
 import static org.hswebframework.web.entity.authorization.AuthorizationSettingEntity.type;
+import static org.hswebframework.web.service.authorization.simple.CacheConstants.MENU_CACHE_NAME;
 import static org.hswebframework.web.service.authorization.simple.CacheConstants.USER_AUTH_CACHE_NAME;
+import static org.hswebframework.web.service.authorization.simple.CacheConstants.USER_MENU_CACHE_NAME;
 
 /**
  * 默认的服务实现
@@ -61,7 +64,6 @@ import static org.hswebframework.web.service.authorization.simple.CacheConstants
  * @author hsweb-generator-online
  */
 @Service("authorizationSettingService")
-@CacheConfig(cacheNames = USER_AUTH_CACHE_NAME)
 public class SimpleAuthorizationSettingService extends GenericEntityService<AuthorizationSettingEntity, String>
         implements AuthorizationSettingService, AuthenticationInitializeService, UserMenuManagerService {
 
@@ -81,7 +83,6 @@ public class SimpleAuthorizationSettingService extends GenericEntityService<Auth
 
     private DataAccessFactory dataAccessFactory;
 
-
     @Override
     protected IDGenerator<String> getIDGenerator() {
         return IDGenerator.MD5;
@@ -102,7 +103,7 @@ public class SimpleAuthorizationSettingService extends GenericEntityService<Auth
     }
 
     @Override
-    @CacheEvict(allEntries = true)
+    @CacheEvict(cacheNames = {CacheConstants.USER_AUTH_CACHE_NAME,CacheConstants.USER_MENU_CACHE_NAME}, allEntries = true)
     public String saveOrUpdate(AuthorizationSettingEntity entity) {
         AuthorizationSettingEntity old = select(entity.getType(), entity.getSettingFor());
         if (old != null) {
@@ -113,7 +114,7 @@ public class SimpleAuthorizationSettingService extends GenericEntityService<Auth
     }
 
     @Override
-    @CacheEvict(allEntries = true)
+    @CacheEvict(cacheNames = {CacheConstants.USER_AUTH_CACHE_NAME,CacheConstants.USER_MENU_CACHE_NAME}, allEntries = true)
     public String insert(AuthorizationSettingEntity entity) {
         tryValidateProperty(select(entity.getType(), entity.getSettingFor()) == null, AuthorizationSettingEntity.settingFor, "存在相同的配置!");
         entity.setStatus(STATUS_ENABLED);
@@ -138,7 +139,7 @@ public class SimpleAuthorizationSettingService extends GenericEntityService<Auth
     }
 
     @Override
-    @CacheEvict(allEntries = true)
+    @CacheEvict(cacheNames = {CacheConstants.USER_AUTH_CACHE_NAME,CacheConstants.USER_MENU_CACHE_NAME}, allEntries = true)
     public int updateByPk(String id, AuthorizationSettingEntity entity) {
         int size = super.updateByPk(id, entity);
         if (entity.getMenus() != null) {
@@ -166,7 +167,7 @@ public class SimpleAuthorizationSettingService extends GenericEntityService<Auth
     }
 
     @Override
-    @CacheEvict(allEntries = true)
+    @CacheEvict(cacheNames = {CacheConstants.USER_AUTH_CACHE_NAME,CacheConstants.USER_MENU_CACHE_NAME}, allEntries = true)
     public int deleteByPk(String id) {
         Objects.requireNonNull(id, "id can not be null");
         authorizationSettingMenuService.deleteBySettingId(id);
@@ -184,7 +185,7 @@ public class SimpleAuthorizationSettingService extends GenericEntityService<Auth
         Stream<Map.Entry<String, List<SettingInfo>>> settingInfoStream = settingInfo.entrySet().stream();
         //大于1 使用并行处理
         if (settingInfo.size() > 1) {
-            settingInfoStream.parallel();
+            settingInfoStream = settingInfoStream.parallel();
         }
         return settingInfoStream
                 .map(entry ->
@@ -199,14 +200,14 @@ public class SimpleAuthorizationSettingService extends GenericEntityService<Auth
     }
 
     @Override
-    @Cacheable(key = "'user-menu-list:'+#userId")
+    @Cacheable(cacheNames = USER_MENU_CACHE_NAME, key = "'user-menu-list:'+#userId")
     public List<UserMenuEntity> getUserMenuAsList(String userId) {
         if (null == userId) {
-            return null;
+            return Collections.emptyList();
         }
         UserEntity userEntity = userService.selectByPk(userId);
         if (userEntity == null) {
-            return null;
+            return Collections.emptyList();
         }
         List<AuthorizationSettingEntity> entities = getUserSetting(userId);
         if (entities.isEmpty()) {
@@ -262,7 +263,7 @@ public class SimpleAuthorizationSettingService extends GenericEntityService<Auth
     }
 
     @Override
-    @Cacheable(key = "'menu-tree:'+#userId")
+    @Cacheable(cacheNames = USER_MENU_CACHE_NAME, key = "'menu-tree:'+#userId")
     public List<UserMenuEntity> getUserMenuAsTree(String userId) {
         return TreeSupportEntity.list2tree(getUserMenuAsList(userId), UserMenuEntity::setChildren,
                 (Predicate<UserMenuEntity>) menuEntity ->

+ 25 - 25
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleMenuService.java

@@ -30,15 +30,13 @@ import org.springframework.cache.annotation.Cacheable;
 import org.springframework.cache.annotation.Caching;
 import org.springframework.stereotype.Service;
 
+import java.util.Collection;
 import java.util.List;
 
 /**
- * TODO 完成注释
- *
  * @author zhouhao
  */
 @Service("menuService")
-@CacheConfig(cacheNames = CacheConstants.MENU_CACHE_NAME)
 public class SimpleMenuService
         extends AbstractTreeSortService<MenuEntity, String>
         implements MenuService {
@@ -61,29 +59,36 @@ public class SimpleMenuService
     }
 
     @Override
-    @Caching(
-            evict = {
-                    @CacheEvict(allEntries = true),
-                    @CacheEvict(cacheNames = CacheConstants.MENU_CACHE_NAME, allEntries = true)
-            }
-    )
+    @CacheEvict(cacheNames ={CacheConstants.MENU_CACHE_NAME,CacheConstants.USER_MENU_CACHE_NAME}, allEntries = true)
+    public int updateByPk(MenuEntity entity) {
+        return super.updateByPk(entity);
+    }
+
+    @Override
+    @CacheEvict(cacheNames ={CacheConstants.MENU_CACHE_NAME,CacheConstants.USER_MENU_CACHE_NAME}, allEntries = true)
+    public String saveOrUpdate(MenuEntity entity) {
+        return super.saveOrUpdate(entity);
+    }
+    @Override
+    @CacheEvict(cacheNames ={CacheConstants.MENU_CACHE_NAME,CacheConstants.USER_MENU_CACHE_NAME}, allEntries = true)
+    public int updateBatch(Collection<MenuEntity> data) {
+        return super.updateBatch(data);
+    }
+
+    @Override
+    @CacheEvict(cacheNames ={CacheConstants.MENU_CACHE_NAME,CacheConstants.USER_MENU_CACHE_NAME}, allEntries = true)
     public int updateByPk(String id, MenuEntity entity) {
         return super.updateByPk(id, entity);
     }
 
     @Override
-    @Caching(
-            evict = {
-                    @CacheEvict(allEntries = true),
-                    @CacheEvict(cacheNames = CacheConstants.MENU_CACHE_NAME, allEntries = true)
-            }
-    )
+    @CacheEvict(cacheNames ={CacheConstants.MENU_CACHE_NAME,CacheConstants.USER_MENU_CACHE_NAME}, allEntries = true)
     public int updateByPk(List<MenuEntity> data) {
         return super.updateByPk(data);
     }
 
     @Override
-    @CacheEvict(allEntries = true)
+    @CacheEvict(cacheNames ={CacheConstants.MENU_CACHE_NAME,CacheConstants.USER_MENU_CACHE_NAME}, allEntries = true)
     public String insert(MenuEntity entity) {
         if (entity.getStatus() == null) {
             entity.setStatus((byte) 1);
@@ -92,30 +97,25 @@ public class SimpleMenuService
     }
 
     @Override
-    @Cacheable(key = "'ids:'+(#id==null?'0':#id.hashCode())")
+    @Cacheable(cacheNames =CacheConstants.MENU_CACHE_NAME,key = "'ids:'+(#id==null?'0':#id.hashCode())")
     public List<MenuEntity> selectByPk(List<String> id) {
         return super.selectByPk(id);
     }
 
     @Override
-    @Caching(
-            evict = {
-                    @CacheEvict(allEntries = true),
-                    @CacheEvict(cacheNames = CacheConstants.MENU_CACHE_NAME, allEntries = true)
-            }
-    )
+    @CacheEvict(cacheNames ={CacheConstants.MENU_CACHE_NAME,CacheConstants.USER_MENU_CACHE_NAME}, allEntries = true)
     public int deleteByPk(String id) {
         return super.deleteByPk(id);
     }
 
     @Override
-    @Cacheable(key = "'permission-ids:'+(#permissionId==null?'0':#permissionId.hashCode())")
+    @Cacheable(cacheNames =CacheConstants.MENU_CACHE_NAME,key = "'permission-ids:'+(#permissionId==null?'0':#permissionId.hashCode())")
     public List<MenuEntity> getByPermissionId(List<String> permissionId) {
         return createQuery().noPaging().where().in("permissionId", permissionId).list();
     }
 
     @Override
-    @Cacheable(key = "'permission-id:'+#permissionId")
+    @Cacheable(cacheNames =CacheConstants.MENU_CACHE_NAME,key = "'permission-id:'+#permissionId")
     public MenuEntity getByPermissionId(String permissionId) {
         return createQuery().noPaging().where().is("permissionId", permissionId).single();
     }

+ 1 - 1
hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-controller/src/main/java/org/hswebframework/web/authorization/oauth2/controller/OAuth2ClientConfigController.java

@@ -16,7 +16,7 @@ import org.springframework.web.bind.annotation.*;
 import java.util.List;
 
 @RestController
-@RequestMapping("/oauth2/client/config")
+@RequestMapping("/oauth2-client-config")
 @Api(tags = "OAuth2.0-服务-客户端管理", value = "OAuth2.0-服务-客户端管理")
 @Authorize(permission = "oauth2-client-config", description = "OAuth2.0-服务-客户端管理")
 public class OAuth2ClientConfigController {

+ 4 - 4
hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-starter/src/main/java/org/hswebframework/web/oauth2/OAuth2AuthorizationAutoConfiguration.java

@@ -8,12 +8,12 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
-@ConditionalOnClass(UserTokenParser.class)
-@Configuration
-@AutoConfigureAfter(OAuth2GranterAutoConfiguration.class)
+//@ConditionalOnClass(UserTokenParser.class)
+//@Configuration
+//@AutoConfigureAfter(OAuth2GranterAutoConfiguration.class)
 public class OAuth2AuthorizationAutoConfiguration {
 
-    @Bean
+//    @Bean
     public OAuth2UserTokenParser oAuth2UserTokenParser(AccessTokenService accessTokenService) {
         return new OAuth2UserTokenParser(accessTokenService);
     }

+ 1 - 1
hsweb-system/hsweb-system-script/hsweb-system-script-controller/src/main/java/org/hswebframework/web/controller/script/ScriptController.java

@@ -24,7 +24,7 @@ import java.util.Map;
 @RestController
 @RequestMapping("${hsweb.web.mappings.script:script}")
 @Authorize(permission = "script", description = "动态脚本管理")
-@Api("动态脚本")
+@Api(value = "动态脚本",tags = "动态脚本管理")
 public class ScriptController implements SimpleGenericEntityController<ScriptEntity, String, QueryParamEntity> {
 
     private ScriptService scriptService;

+ 91 - 83
hsweb-system/hsweb-system-script/hsweb-system-script-entity/src/main/java/org/hswebframework/web/entity/script/ScriptEntity.java

@@ -1,105 +1,113 @@
 package org.hswebframework.web.entity.script;
+
 import org.hswebframework.web.commons.entity.GenericEntity;
 
 /**
-* 动态脚本 实体
-* @author hsweb-generator-online
-*/
-public interface ScriptEntity extends GenericEntity<String>{
+ * 动态脚本 实体
+ *
+ * @author hsweb-generator-online
+ */
+public interface ScriptEntity extends GenericEntity<String> {
  /*-------------------------------------------
     |               属性名常量               |
     ===========================================*/
-     /**
+    /**
      * 脚本名称
      */
-     String name="name";
-     /**
+    String name     = "name";
+    /**
      * 类型
      */
-     String type="type";
-     /**
+    String type     = "type";
+    /**
      * 脚本内容
      */
-     String script="script";
-     /**
+    String script   = "script";
+    /**
      * 脚本语言
      */
-     String language="language";
-     /**
+    String language = "language";
+    /**
      * 备注
      */
-     String remark="remark";
-     /**
+    String remark   = "remark";
+    /**
      * 状态
      */
-     String status="status";
-     /**
+    String status   = "status";
+    /**
      * 脚本标签
      */
-     String tag="tag";
-    
-        /**
-        * @return 脚本名称
-        */
-        String getName();
-
-        /**
-        * @param  name  脚本名称
-        */
-        void setName(String name);
-        /**
-        * @return 类型
-        */
-        String getType();
-
-        /**
-        * @param  type  类型
-        */
-        void setType(String type);
-        /**
-        * @return 脚本内容
-        */
-        String getScript();
-
-        /**
-        * @param  script  脚本内容
-        */
-        void setScript(String script);
-        /**
-        * @return 脚本语言
-        */
-        String getLanguage();
-
-        /**
-        * @param  language  脚本语言
-        */
-        void setLanguage(String language);
-        /**
-        * @return 备注
-        */
-        String getRemark();
-
-        /**
-        * @param  remark  备注
-        */
-        void setRemark(String remark);
-        /**
-        * @return 状态
-        */
-        Long getStatus();
-
-        /**
-        * @param  status  状态
-        */
-        void setStatus(Long status);
-        /**
-        * @return 脚本标签
-        */
-        String getTag();
-
-        /**
-        * @param  tag  脚本标签
-        */
-        void setTag(String tag);
-      
+    String tag      = "tag";
+
+    /**
+     * @return 脚本名称
+     */
+    String getName();
+
+    /**
+     * @param name 脚本名称
+     */
+    void setName(String name);
+
+    /**
+     * @return 类型
+     */
+    String getType();
+
+    /**
+     * @param type 类型
+     */
+    void setType(String type);
+
+    /**
+     * @return 脚本内容
+     */
+    String getScript();
+
+    /**
+     * @param script 脚本内容
+     */
+    void setScript(String script);
+
+    /**
+     * @return 脚本语言
+     */
+    String getLanguage();
+
+    /**
+     * @param language 脚本语言
+     */
+    void setLanguage(String language);
+
+    /**
+     * @return 备注
+     */
+    String getRemark();
+
+    /**
+     * @param remark 备注
+     */
+    void setRemark(String remark);
+
+    /**
+     * @return 状态
+     */
+    Long getStatus();
+
+    /**
+     * @param status 状态
+     */
+    void setStatus(Long status);
+
+    /**
+     * @return 脚本标签
+     */
+    String getTag();
+
+    /**
+     * @param tag 脚本标签
+     */
+    void setTag(String tag);
+
 }

+ 0 - 1
hsweb-system/hsweb-system-script/hsweb-system-script-service/hsweb-system-script-service-api/src/main/java/org/hswebframework/web/service/script/ScriptExecutorService.java

@@ -3,7 +3,6 @@ package org.hswebframework.web.service.script;
 import java.util.Map;
 
 /**
- * TODO 完成注释
  *
  * @author zhouhao
  */

+ 6 - 0
hsweb-system/hsweb-system-script/hsweb-system-script-service/hsweb-system-script-service-simple/pom.xml

@@ -22,5 +22,11 @@
             <artifactId>hsweb-system-script-service-api</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.hswebframework.web</groupId>
+            <artifactId>hsweb-message-api</artifactId>
+            <version>${project.version}</version>
+            <optional>true</optional>
+        </dependency>
     </dependencies>
 </project>

+ 7 - 2
hsweb-system/hsweb-system-script/hsweb-system-script-service/hsweb-system-script-service-simple/src/main/java/org/hswebframework/web/service/script/simple/DefaultScriptExecutorService.java

@@ -16,17 +16,22 @@ import java.util.Map;
 /**
  * @author zhouhao
  */
-@Service("scriptExecutorService")
 public class DefaultScriptExecutorService implements ScriptExecutorService {
 
     @Autowired
     private ScriptService scriptService;
 
+    public void setScriptService(ScriptService scriptService) {
+        this.scriptService = scriptService;
+    }
+
     @Override
     @Transactional(rollbackFor = Throwable.class)
     public Object execute(String id, Map<String, Object> parameters) throws Exception {
         ScriptEntity scriptEntity = scriptService.selectByPk(id);
-
+        if (scriptEntity==null){
+            return null;
+        }
         DynamicScriptEngine engine = DynamicScriptEngineFactory.getEngine(scriptEntity.getLanguage());
 
         String scriptId = "dynamicScript-" + id;

+ 139 - 0
hsweb-system/hsweb-system-script/hsweb-system-script-service/hsweb-system-script-service-simple/src/main/java/org/hswebframework/web/service/script/simple/MessagerScriptExecutorService.java

@@ -0,0 +1,139 @@
+package org.hswebframework.web.service.script.simple;
+
+import lombok.extern.slf4j.Slf4j;
+import org.hswebframework.web.entity.script.ScriptEntity;
+import org.hswebframework.web.id.IDGenerator;
+import org.hswebframework.web.message.MessageSubscribe;
+import org.hswebframework.web.message.Messager;
+import org.hswebframework.web.message.builder.StaticMessageSubjectBuilder;
+import org.hswebframework.web.service.script.ScriptExecutorService;
+import org.hswebframework.web.service.script.ScriptService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.StringUtils;
+
+import javax.annotation.PostConstruct;
+import java.util.Map;
+import java.util.Random;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import static org.hswebframework.web.message.builder.StaticMessageSubjectBuilder.*;
+import static org.springframework.beans.factory.wiring.BeanWiringInfo.AUTOWIRE_BY_TYPE;
+
+/**
+ * @author zhouhao
+ * @since 3.0
+ */
+@Slf4j
+public class MessagerScriptExecutorService implements ScriptExecutorService {
+
+    @Autowired
+    private Messager messager;
+
+    private String tag;
+
+    private String all = "all";
+
+    private ScriptExecutorService defaultScriptExecutorService;
+
+    @Autowired
+    private ScriptService scriptService;
+
+    @Autowired
+    private ApplicationContext applicationContext;
+
+    @Autowired
+    public void setScriptService(ScriptService scriptService) {
+        this.scriptService = scriptService;
+    }
+
+    public void setTag(String tag) {
+        this.tag = tag;
+    }
+
+    private void initSubscribe(String topic) {
+        messager.subscribe(queue(topic))
+                .onMessage(message -> {
+                    ScriptExecutorMessage msg = ((ScriptExecutorMessage) message);
+                    Object result;
+                    try {
+                        result = execute(msg.getScriptId(), msg.getParameter());
+
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                        log.error("execute script {} error", msg, e);
+                        result = e.getMessage();
+                    }
+                    messager.publish(ScriptExecutorResultMessage.builder().result(result).build())
+                            .to(queue(topic + msg.getCallback()))
+                            .send();
+                });
+    }
+
+    @PostConstruct
+    public void subscribe() {
+        defaultScriptExecutorService = (DefaultScriptExecutorService) applicationContext.getAutowireCapableBeanFactory()
+                .autowire(DefaultScriptExecutorService.class, AUTOWIRE_BY_TYPE, false);
+
+        if (tag != null) {
+            String[] tags = tag.split(",");
+            for (String tag : tags) {
+                initSubscribe(tag);
+            }
+        } else {
+            initSubscribe(all);
+        }
+    }
+
+    public Object doExecute(String id, Map<String, Object> parameters) throws Exception {
+        return defaultScriptExecutorService.execute(id, parameters);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Throwable.class)
+    public Object execute(String id, Map<String, Object> parameters) throws Exception {
+        ScriptEntity scriptEntity = scriptService.selectByPk(id);
+        if (scriptEntity == null) {
+            return null;
+        }
+        String configTag = scriptEntity.getTag();
+        String callBack = IDGenerator.MD5.generate();
+
+        String topic;
+
+        if (StringUtils.isEmpty(configTag)) {
+            topic = all;
+        } else {
+            String[] tags = configTag.split(",");
+            topic = tags[new Random().nextInt(tags.length)];
+        }
+        Object[] result = new Object[1];
+        CountDownLatch latch = new CountDownLatch(1);
+
+        MessageSubscribe<ScriptExecutorResultMessage> subscribe =
+                messager.<ScriptExecutorResultMessage>subscribe(queue(topic + callBack))
+                        .onMessage(msg -> {
+                            result[0] = msg.getResult();
+                            latch.countDown();
+                        });
+
+        messager.publish(ScriptExecutorMessage.builder()
+                .callback(callBack)
+                .parameter(parameters)
+                .scriptId(id)
+                .build())
+                .to(queue(topic)).send();
+
+        boolean success = latch.await(30, TimeUnit.SECONDS);
+        if (!success) {
+            log.error("await script execute error");
+        }
+        subscribe.cancel();
+
+        return result[1];
+    }
+
+
+}

+ 25 - 0
hsweb-system/hsweb-system-script/hsweb-system-script-service/hsweb-system-script-service-simple/src/main/java/org/hswebframework/web/service/script/simple/ScriptExecutorMessage.java

@@ -0,0 +1,25 @@
+package org.hswebframework.web.service.script.simple;
+
+import lombok.*;
+import org.hswebframework.web.message.Message;
+
+import java.util.Map;
+
+/**
+ *
+ * @author zhouhao
+ * @since 3.0
+ */
+@Getter
+@Setter
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+@ToString
+public class ScriptExecutorMessage implements Message{
+    private String scriptId;
+
+    private Map<String,Object> parameter;
+
+    private String callback;
+}

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

@@ -0,0 +1,17 @@
+package org.hswebframework.web.service.script.simple;
+
+import lombok.*;
+import org.hswebframework.web.message.Message;
+
+/**
+ * @author zhouhao
+ * @since 3.0
+ */
+@Getter
+@Setter
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class ScriptExecutorResultMessage implements Message{
+    private Object result;
+}

+ 7 - 0
hsweb-system/hsweb-system-script/hsweb-system-script-starter/pom.xml

@@ -73,6 +73,13 @@
             <version>2.5</version>
             <scope>test</scope>
         </dependency>
+
+        <dependency>
+            <groupId>org.hswebframework.web</groupId>
+            <artifactId>hsweb-message-api</artifactId>
+            <version>${project.version}</version>
+            <optional>true</optional>
+        </dependency>
       
     </dependencies>
 </project>

+ 23 - 0
hsweb-system/hsweb-system-script/hsweb-system-script-starter/src/main/java/org/hswebframework/web/service/dynamic/script/DynamicScriptAutoConfiguration.java

@@ -0,0 +1,23 @@
+package org.hswebframework.web.service.dynamic.script;
+
+import org.hswebframework.web.service.script.simple.DefaultScriptExecutorService;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @author zhouhao
+ * @since 3.0
+ */
+@Configuration
+@ComponentScan({
+        "org.hswebframework.web.service.script",
+        "org.hswebframework.web.controller.script"
+})
+public class DynamicScriptAutoConfiguration {
+
+    @Bean
+    public DefaultScriptExecutorService defaultScriptExecutorService() {
+        return new DefaultScriptExecutorService();
+    }
+}

+ 3 - 0
hsweb-system/hsweb-system-script/hsweb-system-script-starter/src/main/resources/META-INF/spring.factories

@@ -0,0 +1,3 @@
+# Auto Configure
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+org.hswebframework.web.service.dynamic.script.DynamicScriptAutoConfiguration

+ 1 - 0
hsweb-system/hsweb-system-script/hsweb-system-script-starter/src/test/java/org/hswebframework/web/workflow/flowable/ControllerTest.java

@@ -30,4 +30,5 @@ public class ControllerTest extends SimpleWebApplicationTests {
         Assert.assertEquals(jsonObject.get("result"), "success");
     }
 
+
 }